Control.cs 74 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214
  1. // Permission is hereby granted, free of charge, to any person obtaining
  2. // a copy of this software and associated documentation files (the
  3. // "Software"), to deal in the Software without restriction, including
  4. // without limitation the rights to use, copy, modify, merge, publish,
  5. // distribute, sublicense, and/or sell copies of the Software, and to
  6. // permit persons to whom the Software is furnished to do so, subject to
  7. // the following conditions:
  8. //
  9. // The above copyright notice and this permission notice shall be
  10. // included in all copies or substantial portions of the Software.
  11. //
  12. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  13. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  14. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  15. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  16. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  17. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  18. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  19. //
  20. // Copyright (c) 2004 Novell, Inc.
  21. //
  22. // Authors:
  23. // Peter Bartok [email protected]
  24. //
  25. // Based on work by:
  26. // Aleksey Ryabchuk [email protected]
  27. // Alexandre Pigolkine [email protected]
  28. // Dennis Hayes [email protected]
  29. // Jaak Simm [email protected]
  30. // John Sohn [email protected]
  31. //
  32. // $Revision: 1.66 $
  33. // $Modtime: $
  34. // $Log: Control.cs,v $
  35. // Revision 1.66 2004/10/02 19:02:56 pbartok
  36. // - Added private method to get the Control object from the window handle
  37. // - Implemented ContextMenu property
  38. // - Implemented PointToScreen
  39. // - Implemented PreProcessMessage
  40. // - Implemented IsInputChar
  41. // - Implemented IsInputKey
  42. // - Implemented ProcessCmdKey
  43. // - Completed ProcessKeyEventArgs
  44. // - Fixed message loop to call the proper chain of functions on key events
  45. // - Implemented ProcessDialogChar
  46. // - Implemented ProcessDialogKey
  47. // - Implemented ProcessKeyMessage
  48. // - Implemented ProcessKeyPreview
  49. // - Added RaiseDragEvent stub (MS internal method)
  50. // - Added RaiseKeyEvent stub (MS internal method)
  51. // - Added RaiseMouseEvent stub (MS Internal method)
  52. // - Added RaisePaintEvent stub (MS Internal method)
  53. // - Added ResetMouseEventArgs stub (MS Internal method)
  54. // - Implemented RtlTranslateAlignment
  55. // - Implemented RtlTranslateContent
  56. // - Implemented RtlTranslateHorizontal
  57. // - Implemented RtlTranslateLeftRight
  58. // - Added generation of KeyPress event
  59. //
  60. // Revision 1.65 2004/09/22 18:01:28 jackson
  61. // Text is never null
  62. //
  63. // Revision 1.64 2004/09/16 23:44:19 pbartok
  64. // - Added SendToBack and BringToFront methods
  65. //
  66. // Revision 1.63 2004/09/11 03:50:00 pbartok
  67. // - Added DoDragDrop() [incomplete]
  68. // - Properly implemented 'Visible' handling
  69. // - Added SetVisibleCore()
  70. // - Implemented FindChildAtPoint()
  71. // - Implemented GetContainerControl()
  72. // - Implemented Hide()
  73. //
  74. // Revision 1.62 2004/09/11 01:28:11 pbartok
  75. // - Moved methods into their appropriate #regions
  76. // - Reordered methods within regions alphabetically
  77. //
  78. // Revision 1.61 2004/09/11 00:56:33 pbartok
  79. // - Moved some internal functions into the internal region
  80. // - Implemented FontHeight
  81. // - Implemented RenderRightToLeft
  82. // - Implemented ResizeRedraw
  83. // - Implemented ShowFocusCues
  84. // - Implemented ShowKeyboardCues
  85. // - Implemented FromChildHandle
  86. // - Implemented FromHandle
  87. // - Implemented IsMnemonic
  88. // - Implemented ReflectMessage
  89. // - All public and protected Static Methods are now complete
  90. //
  91. // Revision 1.60 2004/09/10 22:54:52 pbartok
  92. // - Implemented remaining missing public instance properties
  93. // - Alphabetized some out of order properties
  94. //
  95. // Revision 1.59 2004/09/06 12:55:07 jordi
  96. // Caches ClientRectangle rectangle value
  97. //
  98. // Revision 1.58 2004/09/02 22:24:50 pbartok
  99. // - Added sanity check to creation of double buffer bitmap
  100. //
  101. // Revision 1.57 2004/09/02 20:26:21 pbartok
  102. // - Added missing Control.ControlAccessibleObject class
  103. // - Started to implement Select()ion mechanisms, still very incomplete
  104. //
  105. // Revision 1.56 2004/09/01 13:19:19 jordi
  106. // Init string variables with an empty object
  107. //
  108. // Revision 1.55 2004/09/01 10:20:57 jordi
  109. // fires OnFontChanged event
  110. //
  111. // Revision 1.54 2004/09/01 01:41:31 pbartok
  112. // - Added firing of BackColorChanged event
  113. // - Added TopLevelControl property
  114. // - Fixed handling of WM_ERASEBKGRND message
  115. //
  116. // Revision 1.53 2004/08/27 20:17:25 pbartok
  117. // - Removed unneeded stack vars
  118. // - First attempt to fix sizing issues when layout is suspended
  119. //
  120. // Revision 1.52 2004/08/25 19:20:47 pbartok
  121. // - Control now properly passes the ambient background color to child
  122. // controls
  123. //
  124. // Revision 1.51 2004/08/25 18:32:15 pbartok
  125. // - Fixed generation of MouseUp message
  126. //
  127. // Revision 1.50 2004/08/24 18:24:25 jordi
  128. // fire OnEnabledChanged event
  129. //
  130. // Revision 1.49 2004/08/23 21:22:53 pbartok
  131. // - Added InitLayout() method
  132. // - Added code to properly perform layout when Anchor or Dock property is
  133. // changed
  134. // - Changed 'interpretation' of ResumeLayout. MS seems to have a LAMESPEC,
  135. // tried to do it in a way that makes sense
  136. //
  137. // Revision 1.48 2004/08/23 19:55:08 pbartok
  138. // - Properly fixed Jordi's last fix
  139. // - Now uses Cursor's Position property instead of calling XplatUI directly
  140. //
  141. // Revision 1.47 2004/08/23 19:16:23 jordi
  142. // avoids null exception
  143. //
  144. // Revision 1.46 2004/08/22 21:10:30 pbartok
  145. // - Removed OverlappedWindow style from Control, instead it's default
  146. // now is child
  147. // - Made form windows OverlappedWindow by default
  148. //
  149. // Revision 1.45 2004/08/21 22:19:30 pbartok
  150. // - Signature fixes
  151. //
  152. // Revision 1.44 2004/08/21 20:53:13 pbartok
  153. // - Updated to match new GrabWindow signature
  154. //
  155. // Revision 1.43 2004/08/21 19:32:15 pbartok
  156. // - Implemented Created property
  157. //
  158. // Revision 1.42 2004/08/21 19:28:22 pbartok
  159. // - Implemented ContainsFocus
  160. //
  161. // Revision 1.41 2004/08/21 19:26:24 pbartok
  162. // - Implemented CausesValidation
  163. //
  164. // Revision 1.40 2004/08/21 19:21:50 pbartok
  165. // - Implemented CanFocus
  166. // - Implemented CanSelect
  167. // - Implemented Capture
  168. //
  169. // Revision 1.39 2004/08/21 16:54:11 jackson
  170. // Implement EndInvoke
  171. //
  172. // Revision 1.38 2004/08/20 23:38:54 ravindra
  173. // Made RightToLeft property virtual and removed a Console.WriteLine.
  174. //
  175. // Revision 1.37 2004/08/20 20:09:24 pbartok
  176. // - Added call to set window background color
  177. //
  178. // Revision 1.36 2004/08/20 19:18:30 jackson
  179. // Implement Begininvoke
  180. //
  181. // Revision 1.35 2004/08/20 01:17:24 pbartok
  182. // - Added handling of WM_MOUSEHOVER
  183. // - Worked around 'bug' in Win32 WM_MOUSE_ENTER/WM_MOUSE_LEAVE driver code
  184. //
  185. // Revision 1.34 2004/08/19 23:09:22 pbartok
  186. // - Added Right property
  187. // - Added RightToLeft property
  188. //
  189. // Revision 1.33 2004/08/19 22:25:31 jordi
  190. // theme enhancaments
  191. //
  192. // Revision 1.32 2004/08/17 21:25:12 pbartok
  193. // - Drawing improvement; don't call UpdateBounds if we are not visible (or
  194. // have been minimized)
  195. //
  196. // Revision 1.31 2004/08/17 20:25:28 pbartok
  197. // - Fixed broken handling of default window sizes
  198. //
  199. // Revision 1.30 2004/08/16 21:47:11 pbartok
  200. // - Added handling of WM_MOUSE_ENTER & WM_MOUSE_LEAVE to
  201. // support OnMouseEnter/Leave()
  202. // - Added WS_CLIPSIBLINGS and WS_CLIPCHILDREN window styles to improve
  203. // exposure handling
  204. //
  205. // Revision 1.29 2004/08/13 22:15:46 pbartok
  206. // - Fixed Anchor default
  207. //
  208. // Revision 1.28 2004/08/13 21:43:39 pbartok
  209. // - Changed GetCursorPos signature
  210. //
  211. // Revision 1.27 2004/08/13 19:00:15 jordi
  212. // implements PointToClient (ScreenToClient)
  213. //
  214. // Revision 1.26 2004/08/13 18:52:07 pbartok
  215. // - Added Dispose() and destructor
  216. // - Fixed resizing and bounds calculation
  217. // - Fixed Layout
  218. // - Added memory savings for invisible windows
  219. //
  220. // Revision 1.25 2004/08/12 19:31:19 pbartok
  221. // - Fixed Anchoring bugs
  222. //
  223. // Revision 1.24 2004/08/12 16:10:42 jackson
  224. // Add missing properties
  225. //
  226. // Revision 1.23 2004/08/11 22:20:59 pbartok
  227. // - Signature fixes
  228. //
  229. // Revision 1.22 2004/08/11 19:19:44 pbartok
  230. // - We had SetWindowPos and MoveWindow to set window positions and size,
  231. // removed MoveWindow. We have GetWindowPos, so it made sense to keep
  232. // SetWindowPos as matching counterpart
  233. // - Added some X11 sanity checking
  234. //
  235. // Revision 1.21 2004/08/11 18:59:45 pbartok
  236. // - Major cleanup of my SetBounds/SetBoundsCore/UpdateBounds mess
  237. // (It seems that SetBounds is just a front for SetBoundsCore and
  238. // SetBoundsCore updates the underlying window system and UpdateBounds is
  239. // responsible for updating the variables associated with the Control and
  240. // sending the events)
  241. // - Major cleanup of Size handling; we now have two sizes, client_size and
  242. // bounds. Bounds defines the window with decorations, client_size without
  243. // them.
  244. //
  245. // Revision 1.20 2004/08/11 15:13:32 pbartok
  246. // - Now properly reparents windows
  247. //
  248. // Revision 1.19 2004/08/11 14:37:11 pbartok
  249. // - Duh!
  250. //
  251. // Revision 1.18 2004/08/11 13:47:22 pbartok
  252. // - Rewrote the collection stuff. Might not be as fast now, not keeping
  253. // the number of children around and accessible directly, but it's more
  254. // straightforward
  255. //
  256. // Revision 1.17 2004/08/10 18:32:10 jordi
  257. // throw ontextchange event
  258. //
  259. // Revision 1.16 2004/08/10 17:43:04 pbartok
  260. // - Added more to the still unfinished Dock/Anchor layout code
  261. //
  262. // Revision 1.15 2004/08/10 15:08:05 jackson
  263. // Control will now handle the buffering code, so each control does not have to implement this.
  264. //
  265. // Revision 1.14 2004/08/09 22:11:25 pbartok
  266. // - Added incomplete dock layout code
  267. // - Added support for mouse wheel
  268. //
  269. // Revision 1.13 2004/08/09 17:25:56 jackson
  270. // Use new color names
  271. //
  272. // Revision 1.12 2004/08/09 15:54:51 jackson
  273. // Get default properties from the theme.
  274. //
  275. // Revision 1.11 2004/08/06 21:30:56 pbartok
  276. // - Fixed recursive loop when resizing
  277. // - Improved/fixed redrawing on expose messages
  278. //
  279. // Revision 1.10 2004/08/06 15:53:39 jordi
  280. // X11 keyboard navigation
  281. //
  282. // Revision 1.9 2004/08/04 21:14:26 pbartok
  283. // - Fixed Invalidation bug (calculated wrong client area)
  284. // - Added ClientSize setter
  285. //
  286. // Revision 1.8 2004/08/04 20:11:24 pbartok
  287. // - Added Invalidate handling
  288. //
  289. // Revision 1.7 2004/07/27 10:38:17 jordi
  290. // changes to be able to run winforms samples
  291. //
  292. // Revision 1.6 2004/07/19 19:09:42 jordi
  293. // label control re-written: added missing functionlity, events, and properties
  294. //
  295. // Revision 1.5 2004/07/19 16:49:23 jordi
  296. // fixes SetBounds logic
  297. //
  298. // Revision 1.4 2004/07/19 07:29:35 jordi
  299. // Call RefreshWindow only if the window has created
  300. //
  301. // Revision 1.3 2004/07/15 17:03:35 jordi
  302. // added basic mouse handeling events
  303. //
  304. // Revision 1.2 2004/07/13 15:31:45 jordi
  305. // commit: new properties and fixes form size problems
  306. //
  307. // Revision 1.1 2004/07/09 05:21:25 pbartok
  308. // - Initial check-in
  309. //
  310. //
  311. // NOT COMPLETE
  312. using System;
  313. using System.Drawing;
  314. using System.ComponentModel;
  315. using System.Collections;
  316. using System.Diagnostics;
  317. using System.Threading;
  318. using System.Runtime.InteropServices;
  319. namespace System.Windows.Forms
  320. {
  321. public class Control : Component, ISynchronizeInvoke, IWin32Window
  322. {
  323. #region Local Variables
  324. // Basic
  325. internal Rectangle bounds; // bounding rectangle for control (client area + decorations)
  326. internal object creator_thread; // thread that created the control
  327. internal ControlNativeWindow window; // object for native window handle
  328. internal string name; // for object naming
  329. // State
  330. internal bool has_focus; // true if control has focus
  331. internal bool is_visible; // true if control is visible
  332. internal bool is_entered; // is the mouse inside the control?
  333. internal bool is_enabled; // true if control is enabled (usable/not grayed out)
  334. internal bool is_selected; // true if control is selected
  335. internal bool is_accessible; // true if the control is visible to accessibility applications
  336. internal bool is_captured; // tracks if the control has captured the mouse
  337. internal bool is_recreating; // tracks if the handle for the control is being recreated
  338. internal bool causes_validation; // tracks if validation is executed on changes
  339. internal int tab_index; // position in tab order of siblings
  340. internal bool tab_stop = true; // is the control a tab stop?
  341. internal bool is_disposed; // has the window already been disposed?
  342. internal Size client_size; // size of the client area (window excluding decorations)
  343. internal Rectangle client_rect; // rectangle with the client area (window excluding decorations)
  344. internal ControlStyles control_style; // rather win32-specific, style bits for control
  345. internal ImeMode ime_mode = ImeMode.Inherit;
  346. internal bool layout_pending; // true if our parent needs to re-layout us
  347. internal object control_tag; // object that contains data about our control
  348. // Visuals
  349. internal Color foreground_color; // foreground color for control
  350. internal Color background_color; // background color for control
  351. internal Image background_image; // background image for control
  352. internal Font font; // font for control
  353. internal string text; // window/title text for control
  354. // Layout
  355. internal AnchorStyles anchor_style; // anchoring requirements for our control
  356. internal DockStyle dock_style; // docking requirements for our control (supercedes anchoring)
  357. internal int prev_width; // previous width of the control; required for anchoring
  358. internal int prev_height; // previous height of our control; required for anchoring
  359. internal Size prev_size;
  360. // to be categorized...
  361. static internal Hashtable controls; // All of the applications controls, in a flat list
  362. internal ControlCollection child_controls; // our children
  363. internal Control parent; // our parent control
  364. internal AccessibleObject accessibility_object; // object that contains accessibility information about our control
  365. internal BindingContext binding_context; // TODO
  366. internal RightToLeft right_to_left; // drawing direction for control
  367. internal int layout_suspended;
  368. internal bool double_buffering;
  369. internal ContextMenu context_menu; // Context menu associated with the control
  370. private Graphics dc_mem; // Graphics context for double buffering
  371. private Bitmap bmp_mem; // Bitmap for double buffering control
  372. #endregion // Local Variables
  373. #region Private Classes
  374. // This helper class allows us to dispatch messages to Control.WndProc
  375. internal class ControlNativeWindow : NativeWindow {
  376. private Control control;
  377. public ControlNativeWindow(Control control) : base() {
  378. this.control=control;
  379. }
  380. static internal Control ControlFromHandle(IntPtr hWnd) {
  381. ControlNativeWindow window;
  382. window = (ControlNativeWindow)window_collection[hWnd];
  383. return window.control;
  384. }
  385. protected override void WndProc(ref Message m) {
  386. control.WndProc(ref m);
  387. }
  388. }
  389. #endregion
  390. #region Public Classes
  391. public class ControlAccessibleObject : AccessibleObject {
  392. #region ControlAccessibleObject Local Variables
  393. private Control owner;
  394. #endregion // ControlAccessibleObject Local Variables
  395. #region ControlAccessibleObject Constructors
  396. public ControlAccessibleObject(Control ownerControl) {
  397. this.owner = ownerControl;
  398. }
  399. #endregion // ControlAccessibleObject Constructors
  400. #region ControlAccessibleObject Public Instance Properties
  401. public override string DefaultAction {
  402. get {
  403. return base.DefaultAction;
  404. }
  405. }
  406. public override string Description {
  407. get {
  408. return base.Description;
  409. }
  410. }
  411. public IntPtr Handle {
  412. get {
  413. return owner.Handle;
  414. }
  415. set {
  416. // We don't want to let them set it
  417. }
  418. }
  419. public override string Help {
  420. get {
  421. return base.Help;
  422. }
  423. }
  424. public override string KeyboardShortcut {
  425. get {
  426. return base.KeyboardShortcut;
  427. }
  428. }
  429. public override string Name {
  430. get {
  431. return base.Name;
  432. }
  433. set {
  434. base.Name = value;
  435. }
  436. }
  437. public Control Owner {
  438. get {
  439. return owner;
  440. }
  441. }
  442. public override AccessibleRole Role {
  443. get {
  444. return base.Role;
  445. }
  446. }
  447. #endregion // ControlAccessibleObject Public Instance Properties
  448. #region ControlAccessibleObject Public Instance Methods
  449. public override int GetHelpTopic(out string FileName) {
  450. return base.GetHelpTopic (out FileName);
  451. }
  452. #endregion // ControlAccessibleObject Public Instance Methods
  453. }
  454. public class ControlCollection : IList, ICollection, ICloneable, IEnumerable {
  455. #region ControlCollection Local Variables
  456. private ArrayList list;
  457. private Control owner;
  458. #endregion // ControlCollection Local Variables
  459. #region ControlCollection Public Constructor
  460. public ControlCollection(Control owner) {
  461. this.owner=owner;
  462. this.list=new ArrayList();
  463. }
  464. #endregion
  465. #region ControlCollection Public Instance Properties
  466. public int Count {
  467. get {
  468. return list.Count;
  469. }
  470. }
  471. public bool IsReadOnly {
  472. get {
  473. return list.IsReadOnly;
  474. }
  475. }
  476. public virtual Control this[int index] {
  477. get {
  478. if (index < 0 || index >= list.Count) {
  479. throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
  480. }
  481. return (Control)list[index];
  482. }
  483. }
  484. #endregion // ControlCollection Public Instance Properties
  485. #region ControlCollection Private Instance Methods
  486. public virtual void Add(Control value) {
  487. for (int i=0; i<list.Count; i++) {
  488. if (list[i]==value) {
  489. // Do we need to do anything here?
  490. return;
  491. }
  492. }
  493. list.Add(value);
  494. value.Parent=owner;
  495. }
  496. public virtual void AddRange(Control[] controls) {
  497. for (int i=0; i<controls.Length; i++) {
  498. Add(controls[i]);
  499. }
  500. }
  501. public virtual void Clear() {
  502. owner.SuspendLayout();
  503. list.Clear();
  504. owner.ResumeLayout();
  505. }
  506. public virtual bool Contains(Control value) {
  507. return list.Contains(value);
  508. }
  509. public void CopyTo(Array array, int index) {
  510. list.CopyTo(array, index);
  511. }
  512. public override bool Equals(object other) {
  513. if (other is ControlCollection && (((ControlCollection)other).owner==this.owner)) {
  514. return(true);
  515. } else {
  516. return(false);
  517. }
  518. }
  519. public int GetChildIndex(Control child) {
  520. return GetChildIndex(child, false);
  521. }
  522. public int GetChildIndex(Control child, bool throwException) {
  523. int index;
  524. index=list.IndexOf(child);
  525. if (index==-1 && throwException) {
  526. throw new ArgumentException("Not a child control", "child");
  527. }
  528. return index;
  529. }
  530. public IEnumerator GetEnumerator() {
  531. return list.GetEnumerator();
  532. }
  533. public override int GetHashCode() {
  534. return base.GetHashCode();
  535. }
  536. public int IndexOf(Control control) {
  537. return list.IndexOf(control);
  538. }
  539. public virtual void Remove(Control value) {
  540. list.Remove(value);
  541. }
  542. public void RemoveAt(int index) {
  543. if (index<0 || index>=list.Count) {
  544. throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
  545. }
  546. list.RemoveAt(index);
  547. }
  548. public void SetChildIndex(Control child, int newIndex) {
  549. int old_index;
  550. old_index=list.IndexOf(child);
  551. if (old_index==-1) {
  552. throw new ArgumentException("Not a child control", "child");
  553. }
  554. if (old_index==newIndex) {
  555. return;
  556. }
  557. RemoveAt(old_index);
  558. if (newIndex>list.Count) {
  559. list.Add(child);
  560. } else {
  561. list.Insert(newIndex, child);
  562. }
  563. }
  564. #endregion // ControlCollection Private Instance Methods
  565. #region ControlCollection Interface Properties
  566. object IList.this[int index] {
  567. get {
  568. if (index<0 || index>=list.Count) {
  569. throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
  570. }
  571. return this[index];
  572. }
  573. set {
  574. if (!(value is Control)) {
  575. throw new ArgumentException("Object of type Control required", "value");
  576. }
  577. list[index]=(Control)value;
  578. }
  579. }
  580. bool IList.IsFixedSize {
  581. get {
  582. return false;
  583. }
  584. }
  585. bool IList.IsReadOnly {
  586. get {
  587. return list.IsReadOnly;
  588. }
  589. }
  590. bool ICollection.IsSynchronized {
  591. get {
  592. return list.IsSynchronized;
  593. }
  594. }
  595. object ICollection.SyncRoot {
  596. get {
  597. return list.SyncRoot;
  598. }
  599. }
  600. #endregion // ControlCollection Interface Properties
  601. #region ControlCollection Interface Methods
  602. int IList.Add(object value) {
  603. if (value == null) {
  604. throw new ArgumentNullException("value", "Cannot add null controls");
  605. }
  606. if (!(value is Control)) {
  607. throw new ArgumentException("Object of type Control required", "value");
  608. }
  609. return list.Add(value);
  610. }
  611. bool IList.Contains(object value) {
  612. if (!(value is Control)) {
  613. throw new ArgumentException("Object of type Control required", "value");
  614. }
  615. return this.Contains((Control) value);
  616. }
  617. int IList.IndexOf(object value) {
  618. if (!(value is Control)) {
  619. throw new ArgumentException("Object of type Control required", "value");
  620. }
  621. return this.IndexOf((Control) value);
  622. }
  623. void IList.Insert(int index, object value) {
  624. if (!(value is Control)) {
  625. throw new ArgumentException("Object of type Control required", "value");
  626. }
  627. list.Insert(index, value);
  628. }
  629. void IList.Remove(object value) {
  630. if (!(value is Control)) {
  631. throw new ArgumentException("Object of type Control required", "value");
  632. }
  633. list.Remove(value);
  634. }
  635. void ICollection.CopyTo(Array array, int index) {
  636. if (list.Count>0) {
  637. list.CopyTo(array, index);
  638. }
  639. }
  640. Object ICloneable.Clone() {
  641. ControlCollection clone = new ControlCollection(this.owner);
  642. clone.list=(ArrayList)list.Clone(); // FIXME: Do we need this?
  643. return clone;
  644. }
  645. #endregion // ControlCollection Interface Methods
  646. }
  647. #endregion // ControlCollection Class
  648. #region Public Constructors
  649. public Control() {
  650. creator_thread = Thread.CurrentThread;
  651. controls = new Hashtable();
  652. child_controls = CreateControlsInstance();
  653. client_size = new Size(DefaultSize.Width, DefaultSize.Height);
  654. client_rect = new Rectangle(0, 0, DefaultSize.Width, DefaultSize.Height);
  655. XplatUI.CalculateWindowRect(IntPtr.Zero, ref client_rect, CreateParams.Style, false, out bounds);
  656. if ((CreateParams.Style & (int)WindowStyles.WS_CHILD) == 0) {
  657. bounds.X=-1;
  658. bounds.Y=-1;
  659. }
  660. prev_size = Size.Empty;
  661. anchor_style = AnchorStyles.Top | AnchorStyles.Left;
  662. is_visible = true;
  663. is_captured = false;
  664. is_disposed = false;
  665. is_enabled = true;
  666. is_entered = false;
  667. layout_pending = false;
  668. causes_validation = true;
  669. has_focus = false;
  670. layout_suspended = 0;
  671. double_buffering = true;
  672. parent = null;
  673. background_image = null;
  674. text = string.Empty;
  675. name = string.Empty;
  676. }
  677. public Control(Control parent, string text) : this() {
  678. Text=text;
  679. Parent=parent;
  680. }
  681. public Control(Control parent, string text, int left, int top, int width, int height) : this() {
  682. Parent=parent;
  683. bounds.X=left;
  684. bounds.Y=top;
  685. bounds.Width=width;
  686. bounds.Height=height;
  687. SetBoundsCore(left, top, width, height, BoundsSpecified.All);
  688. Text=text;
  689. }
  690. public Control(string text) : this() {
  691. Text=text;
  692. }
  693. public Control(string text, int left, int top, int width, int height) : this() {
  694. bounds.X=left;
  695. bounds.Y=top;
  696. bounds.Width=width;
  697. bounds.Height=height;
  698. SetBoundsCore(left, top, width, height, BoundsSpecified.All);
  699. Text=text;
  700. }
  701. protected override void Dispose(bool disposing) {
  702. is_disposed = true;
  703. if (dc_mem!=null) {
  704. dc_mem.Dispose();
  705. dc_mem=null;
  706. }
  707. if (bmp_mem!=null) {
  708. bmp_mem.Dispose();
  709. bmp_mem=null;
  710. }
  711. DestroyHandle();
  712. }
  713. #endregion // Public Constructors
  714. #region Internal Properties
  715. #endregion // Internal Properties
  716. #region Private & Internal Methods
  717. internal static IAsyncResult BeginInvokeInternal (Delegate method, object [] args) {
  718. AsyncMethodResult result = new AsyncMethodResult ();
  719. AsyncMethodData data = new AsyncMethodData ();
  720. data.Method = method;
  721. data.Args = args;
  722. data.Result = new WeakReference (result);
  723. XplatUI.SendAsyncMethod (data);
  724. return result;
  725. }
  726. internal Graphics DeviceContext {
  727. get {
  728. if (dc_mem==null) {
  729. CreateBuffers(this.Width, this.Height);
  730. }
  731. return dc_mem;
  732. }
  733. }
  734. internal Bitmap ImageBuffer {
  735. get {
  736. if (bmp_mem==null) {
  737. CreateBuffers(this.Width, this.Height);
  738. }
  739. return bmp_mem;
  740. }
  741. }
  742. internal void CreateBuffers (int width, int height) {
  743. if (double_buffering == false)
  744. return;
  745. if (dc_mem != null)
  746. dc_mem.Dispose ();
  747. if (bmp_mem != null)
  748. bmp_mem.Dispose ();
  749. if (width < 1) {
  750. width = 1;
  751. }
  752. if (height < 1) {
  753. height = 1;
  754. }
  755. bmp_mem = new Bitmap (width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
  756. dc_mem = Graphics.FromImage (bmp_mem);
  757. }
  758. internal static void SetChildColor(Control parent) {
  759. Control child;
  760. for (int i=0; i < parent.child_controls.Count; i++) {
  761. child=parent.child_controls[i];
  762. if (child.IsHandleCreated) {
  763. XplatUI.SetWindowBackground(child.window.Handle, child.BackColor);
  764. }
  765. if (child.child_controls.Count>0) {
  766. SetChildColor(child);
  767. }
  768. }
  769. }
  770. private bool Select(Control control) {
  771. Control parent;
  772. if (control == null) {
  773. return false;
  774. }
  775. parent = control.parent;
  776. if (((control.control_style & ControlStyles.Selectable) !=0) && (parent != null)) {
  777. while (parent != null) {
  778. if (!parent.is_visible || !parent.is_enabled) {
  779. return false;
  780. }
  781. }
  782. }
  783. control.is_selected = true;
  784. return true;
  785. }
  786. private Control FindTabStop(Control control, bool forward) {
  787. if (control == null) {
  788. return null;
  789. }
  790. return null;
  791. }
  792. internal virtual void DoDefaultAction() {
  793. // Only here to be overriden by our actual controls; this is needed by the accessibility class
  794. }
  795. internal static int LowOrder (int param) {
  796. return (param & 0xffff);
  797. }
  798. internal static int HighOrder (int param) {
  799. return (param >> 16);
  800. }
  801. internal static MouseButtons FromParamToMouseButtons (int param) {
  802. MouseButtons buttons = MouseButtons.None;
  803. if ((param & (int) MsgButtons.MK_LBUTTON) != 0)
  804. buttons |= MouseButtons.Left;
  805. if ((param & (int) MsgButtons.MK_MBUTTON) != 0)
  806. buttons |= MouseButtons.Middle;
  807. if ((param & (int) MsgButtons.MK_RBUTTON) != 0)
  808. buttons |= MouseButtons.Right;
  809. return buttons;
  810. }
  811. #endregion // Private & Internal Methods
  812. #region Public Static Properties
  813. public static Color DefaultBackColor {
  814. get {
  815. return ThemeEngine.Current.DefaultControlBackColor;
  816. }
  817. }
  818. public static Font DefaultFont {
  819. get {
  820. return ThemeEngine.Current.DefaultFont;
  821. }
  822. }
  823. public static Color DefaultForeColor {
  824. get {
  825. return ThemeEngine.Current.DefaultControlForeColor;
  826. }
  827. }
  828. public static Keys ModifierKeys {
  829. get {
  830. return XplatUI.State.ModifierKeys;
  831. }
  832. }
  833. public static MouseButtons MouseButtons {
  834. get {
  835. return XplatUI.State.MouseButtons;
  836. }
  837. }
  838. public static Point MousePosition {
  839. get {
  840. return Cursor.Position;
  841. }
  842. }
  843. #endregion // Public Static Properties
  844. #region Public Instance Properties
  845. public AccessibleObject AccessibilityObject {
  846. get {
  847. if (accessibility_object==null) {
  848. accessibility_object=CreateAccessibilityInstance();
  849. }
  850. return accessibility_object;
  851. }
  852. }
  853. public string AccessibleDefaultActionDescription {
  854. get {
  855. return AccessibilityObject.default_action;
  856. }
  857. set {
  858. AccessibilityObject.default_action=value;
  859. }
  860. }
  861. public string AccessibleDescription {
  862. get {
  863. return AccessibilityObject.description;
  864. }
  865. set {
  866. AccessibilityObject.description=value;
  867. }
  868. }
  869. public string AccessibleName {
  870. get {
  871. return AccessibilityObject.Name;
  872. }
  873. set {
  874. AccessibilityObject.Name=value;
  875. }
  876. }
  877. public AccessibleRole AccessibleRole {
  878. get {
  879. return AccessibilityObject.role;
  880. }
  881. set {
  882. AccessibilityObject.role=value;
  883. }
  884. }
  885. public virtual bool AllowDrop {
  886. get {
  887. return XplatUI.State.DropTarget;
  888. }
  889. set {
  890. XplatUI.State.DropTarget=value;
  891. }
  892. }
  893. public virtual AnchorStyles Anchor {
  894. get {
  895. return anchor_style;
  896. }
  897. set {
  898. anchor_style=value;
  899. if (parent != null) {
  900. parent.PerformLayout(this, "Parent");
  901. }
  902. }
  903. }
  904. public virtual Color BackColor {
  905. get {
  906. if (background_color.IsEmpty) {
  907. if (parent!=null) {
  908. return parent.BackColor;
  909. }
  910. return DefaultBackColor;
  911. }
  912. return background_color;
  913. }
  914. set {
  915. background_color=value;
  916. if (this.IsHandleCreated) {
  917. XplatUI.SetWindowBackground(this.window.Handle, value);
  918. }
  919. SetChildColor(this);
  920. OnBackColorChanged(EventArgs.Empty);
  921. Refresh();
  922. }
  923. }
  924. public virtual Image BackgroundImage {
  925. get {
  926. return background_image;
  927. }
  928. set {
  929. if (background_image!=value) {
  930. background_image=value;
  931. OnBackgroundImageChanged(EventArgs.Empty);
  932. }
  933. }
  934. }
  935. public virtual BindingContext BindingContext {
  936. get {
  937. throw new NotImplementedException();
  938. }
  939. set {
  940. throw new NotImplementedException();
  941. }
  942. }
  943. public int Bottom {
  944. get {
  945. return bounds.Y+bounds.Height;
  946. }
  947. }
  948. public Rectangle Bounds {
  949. get {
  950. return this.bounds;
  951. }
  952. set {
  953. SetBoundsCore(value.Left, value.Top, value.Width, value.Height, BoundsSpecified.All);
  954. }
  955. }
  956. public bool CanFocus {
  957. get {
  958. if (is_visible && is_enabled && GetStyle(ControlStyles.Selectable)) {
  959. return true;
  960. }
  961. return false;
  962. }
  963. }
  964. public bool CanSelect {
  965. get {
  966. Control parent;
  967. if (!GetStyle(ControlStyles.Selectable) || this.parent == null) {
  968. return false;
  969. }
  970. parent = this.parent;
  971. while (parent != null) {
  972. if (!parent.is_visible || !parent.is_enabled) {
  973. return false;
  974. }
  975. parent = parent.parent;
  976. }
  977. return true;
  978. }
  979. }
  980. public bool Capture {
  981. get {
  982. return this.is_captured;
  983. }
  984. set {
  985. if (this.IsHandleCreated) {
  986. if (value && !is_captured) {
  987. is_captured = true;
  988. XplatUI.GrabWindow(this.window.Handle, IntPtr.Zero);
  989. } else if (!value && is_captured) {
  990. XplatUI.ReleaseWindow(this.window.Handle);
  991. is_captured = false;
  992. }
  993. }
  994. }
  995. }
  996. public bool CausesValidation {
  997. get {
  998. return this.causes_validation;
  999. }
  1000. set {
  1001. if (this.causes_validation != value) {
  1002. causes_validation = value;
  1003. OnCausesValidationChanged(EventArgs.Empty);
  1004. }
  1005. }
  1006. }
  1007. public Rectangle ClientRectangle {
  1008. get {
  1009. client_rect.Width = client_size.Width;
  1010. client_rect.Height = client_size.Height;
  1011. return client_rect;
  1012. }
  1013. }
  1014. public Size ClientSize {
  1015. get {
  1016. return client_size;
  1017. }
  1018. set {
  1019. this.SetClientSizeCore(value.Width, value.Height);
  1020. }
  1021. }
  1022. public String CompanyName {
  1023. get {
  1024. return "Mono Project, Novell, Inc.";
  1025. }
  1026. }
  1027. public bool ContainsFocus {
  1028. get {
  1029. if (this.Focused) {
  1030. return true;
  1031. }
  1032. for (int i=0; i < child_controls.Count; i++) {
  1033. if (child_controls[i].Focused) {
  1034. return true;
  1035. }
  1036. }
  1037. return false;
  1038. }
  1039. }
  1040. public virtual ContextMenu ContextMenu {
  1041. get {
  1042. return context_menu;
  1043. }
  1044. set {
  1045. if (context_menu != value) {
  1046. context_menu = value;
  1047. OnContextMenuChanged(EventArgs.Empty);
  1048. }
  1049. }
  1050. }
  1051. public ControlCollection Controls {
  1052. get {
  1053. return this.child_controls;
  1054. }
  1055. }
  1056. public bool Created {
  1057. get {
  1058. if (!this.is_disposed && (this.window.Handle != IntPtr.Zero)) {
  1059. return true;
  1060. }
  1061. return false;
  1062. }
  1063. }
  1064. #if notdef
  1065. public virtual Cursor Cursor {
  1066. get {
  1067. throw new NotImplementedException();
  1068. }
  1069. set {
  1070. throw new NotImplementedException();
  1071. }
  1072. }
  1073. public ControlBidingsCollection DataBindings {
  1074. get {
  1075. throw new NotImplementedException();
  1076. }
  1077. }
  1078. #endif
  1079. public virtual Rectangle DisplayRectangle {
  1080. get {
  1081. return ClientRectangle;
  1082. }
  1083. }
  1084. public bool Disposing {
  1085. get {
  1086. return is_disposed;
  1087. }
  1088. }
  1089. public virtual DockStyle Dock {
  1090. get {
  1091. return dock_style;
  1092. }
  1093. set {
  1094. if (dock_style == value) {
  1095. return;
  1096. }
  1097. dock_style = value;
  1098. if (parent != null) {
  1099. parent.PerformLayout(this, "Parent");
  1100. }
  1101. OnDockChanged(EventArgs.Empty);
  1102. }
  1103. }
  1104. public bool Enabled {
  1105. get {
  1106. return is_enabled;
  1107. }
  1108. set {
  1109. if (is_enabled == value) {
  1110. return;
  1111. }
  1112. is_enabled = value;
  1113. Refresh();
  1114. OnEnabledChanged (EventArgs.Empty);
  1115. }
  1116. }
  1117. public virtual bool Focused {
  1118. get {
  1119. return this.has_focus;
  1120. }
  1121. }
  1122. public virtual Font Font {
  1123. get {
  1124. if (font != null) {
  1125. return font;
  1126. }
  1127. if (Parent != null && Parent.Font != null) {
  1128. return Parent.Font;
  1129. }
  1130. return DefaultFont;
  1131. }
  1132. set {
  1133. if (font == value) {
  1134. return;
  1135. }
  1136. font = value;
  1137. Refresh();
  1138. OnFontChanged (EventArgs.Empty);
  1139. }
  1140. }
  1141. public virtual Color ForeColor {
  1142. get {
  1143. if (foreground_color.IsEmpty) {
  1144. if (parent!=null) {
  1145. return parent.ForeColor;
  1146. }
  1147. return DefaultForeColor;
  1148. }
  1149. return foreground_color;
  1150. }
  1151. set {
  1152. foreground_color=value;
  1153. Refresh();
  1154. }
  1155. }
  1156. public IntPtr Handle { // IWin32Window
  1157. get {
  1158. if (!IsHandleCreated) {
  1159. CreateHandle();
  1160. }
  1161. return window.Handle;
  1162. }
  1163. }
  1164. public bool HasChildren {
  1165. get {
  1166. if (this.child_controls.Count>0) {
  1167. return true;
  1168. }
  1169. return false;
  1170. }
  1171. }
  1172. public int Height {
  1173. get {
  1174. return this.bounds.Height;
  1175. }
  1176. set {
  1177. SetBoundsCore(bounds.X, bounds.Y, bounds.Width, value, BoundsSpecified.Height);
  1178. }
  1179. }
  1180. public ImeMode ImeMode {
  1181. get {
  1182. return ime_mode;
  1183. }
  1184. set {
  1185. ime_mode = value;
  1186. }
  1187. }
  1188. public bool InvokeRequired { // ISynchronizeInvoke
  1189. get {
  1190. if (creator_thread!=Thread.CurrentThread) {
  1191. return true;
  1192. }
  1193. return false;
  1194. }
  1195. }
  1196. public bool IsAccessible {
  1197. get {
  1198. return is_accessible;
  1199. }
  1200. set {
  1201. is_accessible = value;
  1202. }
  1203. }
  1204. public bool IsDisposed {
  1205. get {
  1206. return this.is_disposed;
  1207. }
  1208. }
  1209. public bool IsHandleCreated {
  1210. get {
  1211. if ((window!=null) && (window.Handle!=IntPtr.Zero)) {
  1212. return true;
  1213. }
  1214. return false;
  1215. }
  1216. }
  1217. public int Left {
  1218. get {
  1219. return this.bounds.X;
  1220. }
  1221. set {
  1222. SetBoundsCore(value, bounds.Y, bounds.Width, bounds.Height, BoundsSpecified.X);
  1223. }
  1224. }
  1225. public Point Location {
  1226. get {
  1227. return new Point(bounds.X, bounds.Y);
  1228. }
  1229. set {
  1230. SetBoundsCore(value.X, value.Y, bounds.Width, bounds.Height, BoundsSpecified.Location);
  1231. }
  1232. }
  1233. public string Name {
  1234. get {
  1235. return this.name;
  1236. }
  1237. set {
  1238. this.name=value;
  1239. }
  1240. }
  1241. public Control Parent {
  1242. get {
  1243. return this.parent;
  1244. }
  1245. set {
  1246. if (parent!=value) {
  1247. if (parent!=null) {
  1248. parent.Controls.Remove(this);
  1249. }
  1250. parent=value;
  1251. if (!parent.Controls.Contains(this)) {
  1252. parent.Controls.Add(this);
  1253. }
  1254. XplatUI.SetParent(Handle, value.Handle);
  1255. InitLayout();
  1256. }
  1257. }
  1258. }
  1259. public string ProductName {
  1260. get {
  1261. return "Novell Mono .NET Framework";
  1262. }
  1263. }
  1264. public string ProductVersion {
  1265. get {
  1266. return "1.1.4322.573";
  1267. }
  1268. }
  1269. public bool RecreatingHandle {
  1270. get {
  1271. return is_recreating;
  1272. }
  1273. }
  1274. public Region Region {
  1275. get {
  1276. return new Region(this.bounds);
  1277. }
  1278. set {
  1279. Graphics g;
  1280. RectangleF r;
  1281. g = Graphics.FromHwnd(this.window.Handle);
  1282. r = value.GetBounds(g);
  1283. SetBounds((int)r.X, (int)r.Y, (int)r.Width, (int)r.Height);
  1284. g.Dispose();
  1285. }
  1286. }
  1287. public int Right {
  1288. get {
  1289. return this.bounds.X+this.bounds.Width;
  1290. }
  1291. }
  1292. public virtual RightToLeft RightToLeft {
  1293. get {
  1294. return right_to_left;
  1295. }
  1296. set {
  1297. if (value != right_to_left) {
  1298. right_to_left = value;
  1299. OnRightToLeftChanged(EventArgs.Empty);
  1300. }
  1301. }
  1302. }
  1303. public override ISite Site {
  1304. get {
  1305. return base.Site;
  1306. }
  1307. set {
  1308. base.Site = value;
  1309. }
  1310. }
  1311. public Size Size {
  1312. get {
  1313. return new Size(Width, Height);
  1314. }
  1315. set {
  1316. SetBoundsCore(bounds.X, bounds.Y, value.Width, value.Height, BoundsSpecified.Size);
  1317. }
  1318. }
  1319. public int TabIndex {
  1320. get {
  1321. return tab_index;
  1322. }
  1323. set {
  1324. tab_index = value;
  1325. }
  1326. }
  1327. public bool TabStop {
  1328. get {
  1329. return tab_stop;
  1330. }
  1331. set {
  1332. tab_stop = value;
  1333. }
  1334. }
  1335. public object Tag {
  1336. get {
  1337. return control_tag;
  1338. }
  1339. set {
  1340. control_tag = value;
  1341. }
  1342. }
  1343. public virtual string Text {
  1344. get {
  1345. return this.text;
  1346. }
  1347. set {
  1348. if (value == null) {
  1349. value = String.Empty;
  1350. }
  1351. if (text!=value) {
  1352. text=value;
  1353. XplatUI.Text(Handle, text);
  1354. // FIXME: Do we need a Refresh() here?
  1355. OnTextChanged (EventArgs.Empty);
  1356. }
  1357. }
  1358. }
  1359. public int Top {
  1360. get {
  1361. return this.bounds.Y;
  1362. }
  1363. set {
  1364. SetBoundsCore(bounds.X, value, bounds.Width, bounds.Height, BoundsSpecified.Y);
  1365. }
  1366. }
  1367. public Control TopLevelControl {
  1368. get {
  1369. Control p = this;
  1370. while (p.parent != null) {
  1371. p = p.parent;
  1372. }
  1373. return p;
  1374. }
  1375. }
  1376. public bool Visible {
  1377. get {
  1378. if (!is_visible) {
  1379. return false;
  1380. }
  1381. if (parent != null) {
  1382. return parent.Visible;
  1383. }
  1384. return true;
  1385. }
  1386. set {
  1387. SetVisibleCore(value);
  1388. }
  1389. }
  1390. public int Width {
  1391. get {
  1392. return this.bounds.Width;
  1393. }
  1394. set {
  1395. SetBoundsCore(bounds.X, bounds.Y, value, bounds.Height, BoundsSpecified.Width);
  1396. }
  1397. }
  1398. public IWindowTarget WindowTarget {
  1399. get {
  1400. return null;
  1401. }
  1402. set {
  1403. ;
  1404. }
  1405. }
  1406. #endregion // Public Instance Properties
  1407. #region Protected Instance Properties
  1408. protected virtual CreateParams CreateParams {
  1409. get {
  1410. CreateParams create_params = new CreateParams();
  1411. create_params.Caption = Text;
  1412. create_params.X = Left;
  1413. create_params.Y = Top;
  1414. create_params.Width = Width;
  1415. create_params.Height = Height;
  1416. create_params.ClassName = XplatUI.DefaultClassName;
  1417. create_params.ClassStyle = 0;
  1418. create_params.ExStyle = 0;
  1419. create_params.Param = 0;
  1420. if (parent!=null) {
  1421. create_params.Parent = parent.Handle;
  1422. }
  1423. create_params.Style = (int)WindowStyles.WS_CHILD | (int)WindowStyles.WS_CLIPCHILDREN | (int)WindowStyles.WS_CLIPSIBLINGS;
  1424. if (is_visible) {
  1425. create_params.Style |= (int)WindowStyles.WS_VISIBLE;
  1426. }
  1427. return create_params;
  1428. }
  1429. }
  1430. protected virtual ImeMode DefaultImeMode {
  1431. get {
  1432. return ImeMode.Inherit;
  1433. }
  1434. }
  1435. protected virtual Size DefaultSize {
  1436. get {
  1437. return new Size(100, 23);
  1438. }
  1439. }
  1440. protected int FontHeight {
  1441. get {
  1442. return Font.Height;
  1443. }
  1444. set {
  1445. ;; // Nothing to do
  1446. }
  1447. }
  1448. protected bool RenderRightToLeft {
  1449. get {
  1450. return (this.right_to_left == RightToLeft.Yes);
  1451. }
  1452. set {
  1453. ;; // Nothing to do?
  1454. }
  1455. }
  1456. protected bool ResizeRedraw {
  1457. get {
  1458. return GetStyle(ControlStyles.ResizeRedraw);
  1459. }
  1460. set {
  1461. SetStyle(ControlStyles.ResizeRedraw, value);
  1462. }
  1463. }
  1464. protected virtual bool ShowFocusCues {
  1465. get {
  1466. return true;
  1467. }
  1468. }
  1469. protected bool ShowKeyboardCues {
  1470. get {
  1471. return true;
  1472. }
  1473. }
  1474. #endregion // Protected Instance Properties
  1475. #region Public Static Methods
  1476. public static Control FromChildHandle(IntPtr handle) {
  1477. IEnumerator control = Control.controls.GetEnumerator();
  1478. while (control.MoveNext()) {
  1479. if (((Control)control.Current).window.Handle == handle) {
  1480. // Found it
  1481. if (((Control)control.Current).Parent != null) {
  1482. return ((Control)control.Current).Parent;
  1483. }
  1484. }
  1485. }
  1486. return null;
  1487. }
  1488. public static Control FromHandle(IntPtr handle) {
  1489. IEnumerator control = Control.controls.GetEnumerator();
  1490. while (control.MoveNext()) {
  1491. if (((Control)control.Current).window.Handle == handle) {
  1492. // Found it
  1493. return ((Control)control.Current);
  1494. }
  1495. }
  1496. return null;
  1497. }
  1498. public static bool IsMnemonic(char charCode, string text) {
  1499. int amp;
  1500. amp = text.IndexOf('&');
  1501. if (amp != -1) {
  1502. if (charCode == text.ToCharArray(amp, 1)[0]) {
  1503. return true;
  1504. }
  1505. }
  1506. return false;
  1507. }
  1508. #endregion
  1509. #region Protected Static Methods
  1510. protected static bool ReflectMessage(IntPtr hWnd, ref Message m) {
  1511. Control c;
  1512. c = Control.FromHandle(hWnd);
  1513. if (c != null) {
  1514. c.WndProc(ref m);
  1515. return true;
  1516. }
  1517. return false;
  1518. }
  1519. #endregion
  1520. #region Public Instance Methods
  1521. public IAsyncResult BeginInvoke(Delegate method) {
  1522. return BeginInvokeInternal(method, null);
  1523. }
  1524. public IAsyncResult BeginInvoke (Delegate method, object[] args) {
  1525. return BeginInvokeInternal (method, args);
  1526. }
  1527. public void BringToFront() {
  1528. if ((parent != null) && (parent.child_controls[0]!=this)) {
  1529. if (parent.child_controls.Contains(this)) {
  1530. parent.child_controls.SetChildIndex(this, 0);
  1531. }
  1532. }
  1533. XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, true, false);
  1534. if (parent != null) {
  1535. parent.Refresh();
  1536. }
  1537. }
  1538. public bool Contains(Control ctl) {
  1539. Control current;
  1540. current=ctl;
  1541. while (current!=null) {
  1542. if (current==ctl) {
  1543. return true;
  1544. }
  1545. current=current.parent;
  1546. }
  1547. return false;
  1548. }
  1549. public void CreateControl() {
  1550. Control child;
  1551. CreateHandle();
  1552. for (int i=0; i<child_controls.Count; i++) {
  1553. child_controls[i].CreateControl();
  1554. }
  1555. OnCreateControl();
  1556. }
  1557. public Graphics CreateGraphics() {
  1558. return Graphics.FromHwnd(this.window.Handle);
  1559. }
  1560. [MonoTODO("Come up with cross platform drag-drop driver interface")]
  1561. public DragDropEffects DoDragDrop(object data, DragDropEffects allowedEffects) {
  1562. return DragDropEffects.None;
  1563. }
  1564. public object EndInvoke (IAsyncResult async_result) {
  1565. AsyncMethodResult result = (AsyncMethodResult) async_result;
  1566. return result.EndInvoke ();
  1567. }
  1568. public Control GetChildAtPoint(Point pt) {
  1569. // Microsoft's version of this function doesn't seem to work, so I can't check
  1570. // if we only consider children or also grandchildren, etc.
  1571. // I'm gonna say 'children only'
  1572. for (int i=0; i<child_controls.Count; i++) {
  1573. if (child_controls[i].Bounds.Contains(pt)) {
  1574. return child_controls[i];
  1575. }
  1576. }
  1577. return null;
  1578. }
  1579. public IContainerControl GetContainerControl() {
  1580. Control current = this;
  1581. while (current!=null) {
  1582. if ((current.control_style & ControlStyles.ContainerControl)!=0) {
  1583. return (IContainerControl)current;
  1584. }
  1585. current = current.parent;
  1586. }
  1587. return null;
  1588. }
  1589. public void Hide() {
  1590. this.Visible = false;
  1591. }
  1592. public void Invalidate() {
  1593. Invalidate(ClientRectangle, false);
  1594. }
  1595. public void Invalidate(bool invalidateChildren) {
  1596. Invalidate(ClientRectangle, invalidateChildren);
  1597. }
  1598. public void Invalidate(System.Drawing.Rectangle rc) {
  1599. Invalidate(rc, false);
  1600. }
  1601. public void Invalidate(System.Drawing.Rectangle rc, bool invalidateChildren) {
  1602. if (!IsHandleCreated || !is_visible) {
  1603. return;
  1604. }
  1605. XplatUI.Invalidate(Handle, rc, false);
  1606. if (invalidateChildren) {
  1607. for (int i=0; i<child_controls.Count; i++) child_controls[i].Invalidate();
  1608. }
  1609. }
  1610. public void Invalidate(System.Drawing.Region region) {
  1611. Invalidate(region, false);
  1612. }
  1613. [MonoTODO("Figure out if GetRegionScans is usable")]
  1614. public void Invalidate(System.Drawing.Region region, bool invalidateChildren) {
  1615. throw new NotImplementedException();
  1616. // FIXME - should use the GetRegionScans function of the region to invalidate each area
  1617. if (invalidateChildren) {
  1618. for (int i=0; i<child_controls.Count; i++) child_controls[i].Invalidate();
  1619. }
  1620. }
  1621. public object Invoke (Delegate method) {
  1622. return Invoke(method, null);
  1623. }
  1624. public object Invoke (Delegate method, object[] args) {
  1625. IAsyncResult result = BeginInvoke (method, args);
  1626. return EndInvoke(result);
  1627. }
  1628. public void PerformLayout() {
  1629. PerformLayout(null, null);
  1630. }
  1631. public void PerformLayout(Control affectedControl, string affectedProperty) {
  1632. LayoutEventArgs levent = new LayoutEventArgs(affectedControl, affectedProperty);
  1633. if (layout_suspended>0) {
  1634. layout_pending = true;
  1635. return;
  1636. }
  1637. layout_pending = false;
  1638. // Prevent us from getting messed up
  1639. layout_suspended++;
  1640. // Perform all Dock and Anchor calculations
  1641. try {
  1642. Control child;
  1643. AnchorStyles anchor;
  1644. Rectangle space;
  1645. int diff_width;
  1646. int diff_height;
  1647. space=this.DisplayRectangle;
  1648. if (prev_size != Size.Empty) {
  1649. diff_width = space.Width - prev_size.Width;
  1650. diff_height = space.Height - prev_size.Height;
  1651. } else {
  1652. diff_width = 0;
  1653. diff_height = 0;
  1654. }
  1655. // Deal with docking
  1656. for (int i=0; i < child_controls.Count; i++) {
  1657. child=child_controls[i];
  1658. switch (child.Dock) {
  1659. case DockStyle.None: {
  1660. // Do nothing
  1661. break;
  1662. }
  1663. case DockStyle.Left: {
  1664. child.SetBounds(space.Left, space.Y, child.Width, space.Height);
  1665. space.X+=child.Width;
  1666. space.Width-=child.Width;
  1667. break;
  1668. }
  1669. case DockStyle.Top: {
  1670. child.SetBounds(space.Left, space.Y, space.Width, child.Height);
  1671. space.Y+=child.Height;
  1672. space.Height-=child.Height;
  1673. break;
  1674. }
  1675. case DockStyle.Right: {
  1676. child.SetBounds(space.Right-child.Width, space.Y, child.Width, space.Height);
  1677. space.Width-=child.Width;
  1678. break;
  1679. }
  1680. case DockStyle.Bottom: {
  1681. child.SetBounds(space.Left, space.Bottom-child.Height, space.Width, child.Height);
  1682. space.Height-=child.Height;
  1683. break;
  1684. }
  1685. case DockStyle.Fill: {
  1686. child.SetBounds(space.Left, space.Top, space.Width, space.Height);
  1687. space.Width=0;
  1688. space.Height=0;
  1689. break;
  1690. }
  1691. }
  1692. }
  1693. space=this.DisplayRectangle;
  1694. // Deal with anchoring
  1695. for (int i=0; i < child_controls.Count; i++) {
  1696. int left;
  1697. int top;
  1698. int width;
  1699. int height;
  1700. child=child_controls[i];
  1701. anchor=child.Anchor;
  1702. left=child.Left;
  1703. top=child.Top;
  1704. width=child.Width;
  1705. height=child.Height;
  1706. // If the control is docked we don't need to do anything
  1707. if (child.Dock != DockStyle.None) {
  1708. continue;
  1709. }
  1710. if ((anchor & AnchorStyles.Left) !=0 ) {
  1711. if ((anchor & AnchorStyles.Right) != 0) {
  1712. // Anchoring to left and right
  1713. width=width+diff_width;
  1714. } else {
  1715. ; // nothing to do
  1716. }
  1717. } else if ((anchor & AnchorStyles.Right) != 0) {
  1718. left+=diff_width;
  1719. } else {
  1720. left+=diff_width/2;
  1721. }
  1722. if ((anchor & AnchorStyles.Top) !=0 ) {
  1723. if ((anchor & AnchorStyles.Bottom) != 0) {
  1724. height+=diff_height;
  1725. } else {
  1726. ; // nothing to do
  1727. }
  1728. } else if ((anchor & AnchorStyles.Bottom) != 0) {
  1729. top+=diff_height;
  1730. } else {
  1731. top+=diff_height/2;
  1732. }
  1733. // Sanity
  1734. if (width < 0) {
  1735. width=0;
  1736. }
  1737. if (height < 0) {
  1738. height=0;
  1739. }
  1740. child.SetBounds(left, top, width, height);
  1741. }
  1742. // Let everyone know
  1743. OnLayout(levent);
  1744. }
  1745. // Need to make sure we decremend layout_suspended
  1746. finally {
  1747. layout_suspended--;
  1748. }
  1749. }
  1750. public Point PointToClient (Point p) {
  1751. int x = p.X;
  1752. int y = p.Y;
  1753. XplatUI.ScreenToClient (Handle, ref x, ref y);
  1754. return new Point (x, y);
  1755. }
  1756. public Point PointToScreen(Point p) {
  1757. int x = p.X;
  1758. int y = p.Y;
  1759. XplatUI.ClientToScreen(Handle, ref x, ref y);
  1760. return new Point(x, y);
  1761. }
  1762. public virtual bool PreProcessMessage(ref Message msg) {
  1763. Keys key_data;
  1764. if (msg.Msg == (int)Msg.WM_KEYDOWN) {
  1765. key_data = (Keys)msg.WParam.ToInt32();
  1766. if (!ProcessCmdKey(ref msg, key_data)) {
  1767. if (IsInputKey(key_data)) {
  1768. return false;
  1769. }
  1770. return ProcessDialogKey(key_data);
  1771. }
  1772. return true;
  1773. } else if (msg.Msg == (int)Msg.WM_CHAR) {
  1774. if (IsInputChar((char)msg.WParam)) {
  1775. return false;
  1776. }
  1777. return ProcessDialogChar((char)msg.WParam);
  1778. }
  1779. return false;
  1780. }
  1781. public virtual void Refresh() {
  1782. if (IsHandleCreated == true) {
  1783. XplatUI.RefreshWindow(window.Handle);
  1784. }
  1785. }
  1786. public void ResumeLayout() {
  1787. ResumeLayout (true);
  1788. }
  1789. public void ResumeLayout(bool performLayout) {
  1790. layout_suspended--;
  1791. if (layout_suspended > 0) {
  1792. return;
  1793. }
  1794. if (performLayout || layout_pending) {
  1795. PerformLayout();
  1796. }
  1797. }
  1798. public void Select() {
  1799. Select(false, false);
  1800. }
  1801. [MonoTODO("Finish")]
  1802. public bool SelectNextControl(Control ctl, bool forward, bool tabStopOnly, bool nested, bool wrap) {
  1803. return false;
  1804. }
  1805. public void SendToBack() {
  1806. if ((parent != null) && (parent.child_controls[parent.child_controls.Count-1]!=this)) {
  1807. if (parent.child_controls.Contains(this)) {
  1808. parent.child_controls.SetChildIndex(this, parent.child_controls.Count);
  1809. }
  1810. }
  1811. XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, false, true);
  1812. if (parent != null) {
  1813. parent.Refresh();
  1814. }
  1815. }
  1816. public void SetBounds(int x, int y, int width, int height) {
  1817. SetBoundsCore(x, y, width, height, BoundsSpecified.All);
  1818. }
  1819. public void SetBounds(int x, int y, int width, int height, BoundsSpecified specified) {
  1820. SetBoundsCore(x, y, width, height, specified);
  1821. }
  1822. public void Show() {
  1823. if (!IsHandleCreated) {
  1824. this.CreateHandle();
  1825. }
  1826. this.Visible=true;
  1827. }
  1828. public void SuspendLayout() {
  1829. layout_suspended++;
  1830. }
  1831. #endregion // Public Instance Methods
  1832. #region Protected Instance Methods
  1833. protected virtual AccessibleObject CreateAccessibilityInstance() {
  1834. return new AccessibleObject(this);
  1835. }
  1836. protected virtual ControlCollection CreateControlsInstance() {
  1837. return new ControlCollection(this);
  1838. }
  1839. protected virtual void CreateHandle() {
  1840. if (IsDisposed) {
  1841. throw new ObjectDisposedException(Name);
  1842. }
  1843. if (IsHandleCreated) {
  1844. return;
  1845. }
  1846. if (window==null) {
  1847. window = new ControlNativeWindow(this);
  1848. window.CreateHandle(CreateParams);
  1849. }
  1850. if (window.Handle!=IntPtr.Zero) {
  1851. if (!controls.Contains(window.Handle)) {
  1852. controls.Add(window.Handle, this);
  1853. }
  1854. creator_thread = Thread.CurrentThread;
  1855. XplatUI.SetWindowBackground(window.Handle, this.BackColor);
  1856. OnHandleCreated(EventArgs.Empty);
  1857. }
  1858. }
  1859. protected virtual void DefWndProc(ref Message m) {
  1860. window.DefWndProc(ref m);
  1861. }
  1862. protected virtual void DestroyHandle() {
  1863. if (IsHandleCreated) {
  1864. if (Handle != IntPtr.Zero) {
  1865. controls.Remove(Handle);
  1866. }
  1867. if (window != null) {
  1868. window.DestroyHandle();
  1869. }
  1870. }
  1871. }
  1872. protected bool GetStyle(ControlStyles flag) {
  1873. return (control_style & flag) != 0;
  1874. }
  1875. protected virtual void InitLayout() {
  1876. if (parent != null) {
  1877. parent.PerformLayout(this, "parent");
  1878. }
  1879. }
  1880. protected virtual bool IsInputChar (char charCode) {
  1881. if (parent != null) {
  1882. return parent.IsInputChar(charCode);
  1883. }
  1884. return true;
  1885. }
  1886. protected virtual bool IsInputKey (Keys keyData) {
  1887. // Doc says this one calls IsInputChar; not sure what to do with that
  1888. return false;
  1889. }
  1890. protected virtual bool ProcessCmdKey(ref Message msg, Keys keyData) {
  1891. if ((context_menu != null) && context_menu.ProcessCmdKey(ref msg, keyData)) {
  1892. return true;
  1893. }
  1894. if (parent != null) {
  1895. return parent.ProcessCmdKey(ref msg, keyData);
  1896. }
  1897. return false;
  1898. }
  1899. protected virtual bool ProcessDialogChar(char charCode) {
  1900. if (parent != null) {
  1901. return parent.ProcessDialogChar (charCode);
  1902. }
  1903. return false;
  1904. }
  1905. protected virtual bool ProcessDialogKey (Keys keyData) {
  1906. if (parent != null) {
  1907. return parent.ProcessDialogKey (keyData);
  1908. }
  1909. return false;
  1910. }
  1911. protected virtual bool ProcessKeyEventArgs (ref Message msg)
  1912. {
  1913. KeyEventArgs key_event;
  1914. switch (msg.Msg) {
  1915. case (int)Msg.WM_KEYDOWN: {
  1916. key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
  1917. OnKeyDown (key_event);
  1918. return key_event.Handled;
  1919. }
  1920. case (int)Msg.WM_KEYUP: {
  1921. key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
  1922. OnKeyUp (key_event);
  1923. return key_event.Handled;
  1924. }
  1925. case (int)Msg.WM_CHAR: {
  1926. KeyPressEventArgs key_press_event;
  1927. key_press_event = new KeyPressEventArgs((char)msg.WParam);
  1928. OnKeyPress(key_press_event);
  1929. return key_press_event.Handled;
  1930. }
  1931. default: {
  1932. break;
  1933. }
  1934. }
  1935. return false;
  1936. }
  1937. protected internal virtual bool ProcessKeyMessage(ref Message msg) {
  1938. if (parent != null) {
  1939. if (parent.ProcessKeyPreview(ref msg)) {
  1940. return true;
  1941. }
  1942. }
  1943. return ProcessKeyEventArgs(ref msg);
  1944. }
  1945. protected virtual bool ProcessKeyPreview(ref Message msg) {
  1946. if (parent != null) {
  1947. return parent.ProcessKeyPreview(ref msg);
  1948. }
  1949. return false;
  1950. }
  1951. protected virtual bool ProcessMnemonic(char charCode) {
  1952. // override me
  1953. return false;
  1954. }
  1955. protected void RaiseDragEvent(object key, DragEventArgs e) {
  1956. // MS Internal
  1957. }
  1958. protected void RaiseKeyEvent(object key, KeyEventArgs e) {
  1959. // MS Internal
  1960. }
  1961. protected void RaiseMouseEvent(object key, MouseEventArgs e) {
  1962. // MS Internal
  1963. }
  1964. protected void RaisePaintEvent(object key, PaintEventArgs e) {
  1965. // MS Internal
  1966. }
  1967. protected void RecreateHandle() {
  1968. IEnumerator child = child_controls.GetEnumerator();
  1969. is_recreating=true;
  1970. if (IsHandleCreated) {
  1971. DestroyHandle();
  1972. CreateHandle();
  1973. // FIXME ZOrder?
  1974. while (child.MoveNext()) {
  1975. ((Control)child.Current).RecreateHandle();
  1976. }
  1977. } else {
  1978. CreateHandle();
  1979. }
  1980. is_recreating = false;
  1981. }
  1982. protected void ResetMouseEventArgs() {
  1983. // MS Internal
  1984. }
  1985. protected ContentAlignment RtlTranslateAlignment(ContentAlignment align) {
  1986. if (right_to_left == RightToLeft.No) {
  1987. return align;
  1988. }
  1989. switch (align) {
  1990. case ContentAlignment.TopLeft: {
  1991. return ContentAlignment.TopRight;
  1992. }
  1993. case ContentAlignment.TopRight: {
  1994. return ContentAlignment.TopLeft;
  1995. }
  1996. case ContentAlignment.MiddleLeft: {
  1997. return ContentAlignment.MiddleRight;
  1998. }
  1999. case ContentAlignment.MiddleRight: {
  2000. return ContentAlignment.MiddleLeft;
  2001. }
  2002. case ContentAlignment.BottomLeft: {
  2003. return ContentAlignment.BottomRight;
  2004. }
  2005. case ContentAlignment.BottomRight: {
  2006. return ContentAlignment.BottomLeft;
  2007. }
  2008. default: {
  2009. // if it's center it doesn't change
  2010. return align;
  2011. }
  2012. }
  2013. }
  2014. protected HorizontalAlignment RtlTranslateAlignment(HorizontalAlignment align) {
  2015. if ((right_to_left == RightToLeft.No) || (align == HorizontalAlignment.Center)) {
  2016. return align;
  2017. }
  2018. if (align == HorizontalAlignment.Left) {
  2019. return HorizontalAlignment.Right;
  2020. }
  2021. // align must be HorizontalAlignment.Right
  2022. return HorizontalAlignment.Left;
  2023. }
  2024. protected LeftRightAlignment RtlTranslateAlignment(LeftRightAlignment align) {
  2025. if (right_to_left == RightToLeft.No) {
  2026. return align;
  2027. }
  2028. if (align == LeftRightAlignment.Left) {
  2029. return LeftRightAlignment.Right;
  2030. }
  2031. // align must be LeftRightAlignment.Right;
  2032. return LeftRightAlignment.Left;
  2033. }
  2034. protected ContentAlignment RtlTranslateContent(ContentAlignment align) {
  2035. return RtlTranslateAlignment(align);
  2036. }
  2037. protected HorizontalAlignment RtlTranslateHorizontal(HorizontalAlignment align) {
  2038. return RtlTranslateAlignment(align);
  2039. }
  2040. protected LeftRightAlignment RtlTranslateLeftRight(LeftRightAlignment align) {
  2041. return RtlTranslateAlignment(align);
  2042. }
  2043. protected virtual void ScaleCore(float dx, float dy) {
  2044. throw new NotImplementedException();
  2045. }
  2046. protected virtual void Select(bool directed, bool forward) {
  2047. int index;
  2048. bool result;
  2049. if (!directed) {
  2050. // Select this control
  2051. Select(this);
  2052. }
  2053. if (parent == null) {
  2054. return;
  2055. }
  2056. index = parent.child_controls.IndexOf(this);
  2057. result = false;
  2058. do {
  2059. if (forward) {
  2060. if ((index+1) < parent.child_controls.Count) {
  2061. index++;
  2062. } else {
  2063. index = 0;
  2064. }
  2065. } else {
  2066. if (index>0) {
  2067. index++;
  2068. } else {
  2069. index = parent.child_controls.Count-1;
  2070. }
  2071. }
  2072. result = Select(parent.child_controls[index]);
  2073. } while (!result && parent.child_controls[index] != this);
  2074. }
  2075. protected virtual void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
  2076. // SetBoundsCore updates the Win32 control itself. UpdateBounds updates the controls variables and fires events, I'm guessing - pdb
  2077. if ((specified & BoundsSpecified.X) != BoundsSpecified.X) {
  2078. x = Left;
  2079. }
  2080. if ((specified & BoundsSpecified.Y) != BoundsSpecified.Y) {
  2081. y = Top;
  2082. }
  2083. if ((specified & BoundsSpecified.Width)!= BoundsSpecified.Width) {
  2084. width = Width;
  2085. }
  2086. if ((specified & BoundsSpecified.Height) != BoundsSpecified.Height) {
  2087. height = Height;
  2088. }
  2089. if (IsHandleCreated) {
  2090. XplatUI.SetWindowPos(Handle, x, y, width, height);
  2091. }
  2092. UpdateBounds(x, y, width, height);
  2093. }
  2094. protected virtual void SetClientSizeCore(int x, int y) {
  2095. // Calculate the actual window size from the client size (it usually stays the same or grows)
  2096. Rectangle ClientRect;
  2097. Rectangle WindowRect;
  2098. CreateParams cp;
  2099. ClientRect = new Rectangle(0, 0, x, y);
  2100. cp = this.CreateParams;
  2101. if (XplatUI.CalculateWindowRect(Handle, ref ClientRect, cp.Style, false, out WindowRect)==false) {
  2102. return;
  2103. }
  2104. this.client_size = new Size(x, y);
  2105. SetBoundsCore(bounds.X, bounds.Y, WindowRect.Width, WindowRect.Height, BoundsSpecified.Size);
  2106. }
  2107. protected void SetStyle(ControlStyles flag, bool value) {
  2108. if (value) {
  2109. control_style |= flag;
  2110. } else {
  2111. control_style &= ~flag;
  2112. }
  2113. }
  2114. protected virtual void SetVisibleCore(bool value) {
  2115. if (value!=is_visible) {
  2116. is_visible=value;
  2117. XplatUI.SetVisible(Handle, value);
  2118. OnVisibleChanged(EventArgs.Empty);
  2119. if (!is_visible) {
  2120. if (dc_mem != null) {
  2121. dc_mem.Dispose();
  2122. dc_mem = null;
  2123. }
  2124. if (bmp_mem != null) {
  2125. bmp_mem.Dispose();
  2126. bmp_mem = null;
  2127. }
  2128. } else {
  2129. this.CreateBuffers(bounds.Width, bounds.Height);
  2130. }
  2131. // FIXME - deal with focus
  2132. if (parent != null) {
  2133. parent.PerformLayout(this, "visible");
  2134. } else {
  2135. PerformLayout(this, "visible");
  2136. }
  2137. }
  2138. }
  2139. protected void UpdateBounds() {
  2140. int x;
  2141. int y;
  2142. int width;
  2143. int height;
  2144. int client_width;
  2145. int client_height;
  2146. if (!IsHandleCreated) {
  2147. CreateHandle();
  2148. }
  2149. XplatUI.GetWindowPos(this.Handle, out x, out y, out width, out height, out client_width, out client_height);
  2150. UpdateBounds(x, y, width, height, client_width, client_height);
  2151. }
  2152. protected void UpdateBounds(int x, int y, int width, int height) {
  2153. // UpdateBounds only seems to set our sizes and fire events but not update the GUI window to match
  2154. bool moved = false;
  2155. bool resized = false;
  2156. int client_x_diff = this.bounds.Width-this.client_size.Width;
  2157. int client_y_diff = this.bounds.Height-this.client_size.Height;
  2158. // Needed to generate required notifications
  2159. if ((this.bounds.X!=x) || (this.bounds.Y!=y)) {
  2160. moved=true;
  2161. }
  2162. if ((this.Bounds.Width!=width) || (this.Bounds.Height!=height)) {
  2163. resized=true;
  2164. }
  2165. bounds.X=x;
  2166. bounds.Y=y;
  2167. bounds.Width=width;
  2168. bounds.Height=height;
  2169. // Update client rectangle as well
  2170. if (this.layout_suspended==0) {
  2171. prev_size.Width=client_size.Width;
  2172. prev_size.Height=client_size.Height;
  2173. }
  2174. client_size.Width=width-client_x_diff;
  2175. client_size.Height=height-client_y_diff;
  2176. if (moved) {
  2177. OnLocationChanged(EventArgs.Empty);
  2178. }
  2179. if (resized) {
  2180. OnSizeChanged(EventArgs.Empty);
  2181. }
  2182. }
  2183. protected void UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) {
  2184. UpdateBounds(x, y, width, height);
  2185. this.client_size.Width=clientWidth;
  2186. this.client_size.Height=clientHeight;
  2187. }
  2188. [MonoTODO]
  2189. protected virtual void WndProc(ref Message m) {
  2190. EventArgs e = new EventArgs();
  2191. #if debug
  2192. Console.WriteLine("Received message {0}", m);
  2193. #endif
  2194. switch((Msg)m.Msg) {
  2195. #if notyet
  2196. // Mouse handling
  2197. case Msg.WM_LBUTTONDBLCLK: throw new NotImplementedException(); break;
  2198. case Msg.WM_RBUTTONDOWN: throw new NotImplementedException(); break;
  2199. case Msg.WM_RBUTTONUP: throw new NotImplementedException(); break;
  2200. case Msg.WM_RBUTTONDBLCLK: throw new NotImplementedException(); break;
  2201. case Msg.WM_MOUSEHOVER: throw new NotImplementedException(); break;
  2202. case Msg.WM_MOUSELEAVE: throw new NotImplementedException(); break;
  2203. // Keyboard handling
  2204. case Msg.WM_CHAR: throw new NotImplementedException(); break;
  2205. case Msg.WM_KEYDOWN: throw new NotImplementedException(); break;
  2206. case Msg.WM_KEYUP: throw new NotImplementedException(); break;
  2207. #endif
  2208. // Window management
  2209. case Msg.WM_WINDOWPOSCHANGED: {
  2210. if (XplatUI.IsVisible(m.HWnd)) {
  2211. UpdateBounds();
  2212. }
  2213. DefWndProc(ref m);
  2214. break;
  2215. }
  2216. case Msg.WM_PAINT: {
  2217. Rectangle rect;
  2218. PaintEventArgs paint_event;
  2219. paint_event = XplatUI.PaintEventStart(Handle);
  2220. OnPaint(paint_event);
  2221. XplatUI.PaintEventEnd(Handle);
  2222. DefWndProc(ref m);
  2223. break;
  2224. }
  2225. case Msg.WM_ERASEBKGND:{
  2226. if (GetStyle (ControlStyles.UserPaint)){
  2227. if (!GetStyle(ControlStyles.AllPaintingInWmPaint)) {
  2228. PaintEventArgs eraseEventArgs = new PaintEventArgs (Graphics.FromHdc (m.WParam), new Rectangle (new Point (0,0),Size));
  2229. OnPaintBackground (eraseEventArgs);
  2230. }
  2231. m.Result = (IntPtr)1;
  2232. }
  2233. else {
  2234. #if notdef
  2235. SolidBrush sb = new SolidBrush(this.BackColor);
  2236. this.DeviceContext.FillRectangle(sb, this.ClientRectangle);
  2237. sb.Dispose();
  2238. #endif
  2239. m.Result = IntPtr.Zero;
  2240. DefWndProc (ref m);
  2241. }
  2242. break;
  2243. }
  2244. case Msg.WM_LBUTTONUP: {
  2245. int clicks = 1;
  2246. OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Left,
  2247. clicks,
  2248. LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
  2249. 0));
  2250. break;
  2251. }
  2252. case Msg.WM_LBUTTONDOWN: {
  2253. int clicks = 1;
  2254. OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
  2255. clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
  2256. 0));
  2257. break;
  2258. }
  2259. case Msg.WM_MOUSEWHEEL: {
  2260. int clicks = 1;
  2261. OnMouseWheel (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
  2262. clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
  2263. HighOrder(m.WParam.ToInt32())));
  2264. break;
  2265. }
  2266. case Msg.WM_MOUSEMOVE: {
  2267. int clicks = 1;
  2268. OnMouseMove (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
  2269. clicks,
  2270. LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
  2271. 0));
  2272. break;
  2273. }
  2274. case Msg.WM_MOUSE_ENTER: {
  2275. if (is_entered) {
  2276. return;
  2277. }
  2278. is_entered = true;
  2279. OnMouseEnter(EventArgs.Empty);
  2280. break;
  2281. }
  2282. case Msg.WM_MOUSE_LEAVE: {
  2283. is_entered=false;
  2284. OnMouseLeave(EventArgs.Empty);
  2285. break;
  2286. }
  2287. case Msg.WM_MOUSEHOVER: {
  2288. OnMouseHover(EventArgs.Empty);
  2289. break;
  2290. }
  2291. case Msg.WM_SIZE: {
  2292. if (GetStyle(ControlStyles.ResizeRedraw)) {
  2293. Invalidate();
  2294. }
  2295. DefWndProc(ref m);
  2296. break;
  2297. }
  2298. case Msg.WM_KEYDOWN: {
  2299. if (!ProcessKeyMessage(ref m)) {
  2300. DefWndProc (ref m);
  2301. }
  2302. break;
  2303. }
  2304. case Msg.WM_KEYUP: {
  2305. if (!ProcessKeyMessage(ref m)) {
  2306. DefWndProc (ref m);
  2307. }
  2308. break;
  2309. }
  2310. case Msg.WM_CHAR: {
  2311. if (!ProcessKeyMessage(ref m)) {
  2312. DefWndProc (ref m);
  2313. }
  2314. break;
  2315. }
  2316. #if notyet
  2317. case Msg.WM_WINDOWPOSCHANGED: throw new NotImplementedException(); break;
  2318. case Msg.WM_SYSCOLORCHANGE: throw new NotImplementedException(); break;
  2319. #endif
  2320. default:
  2321. DefWndProc(ref m);
  2322. break;
  2323. }
  2324. }
  2325. #endregion // Public Instance Methods
  2326. #region OnXXX methods
  2327. protected virtual void OnBackColorChanged(EventArgs e) {
  2328. if (BackColorChanged!=null) BackColorChanged(this, e);
  2329. for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackColorChanged(e);
  2330. }
  2331. protected virtual void OnBackgroundImageChanged(EventArgs e) {
  2332. if (BackgroundImageChanged!=null) BackgroundImageChanged(this, e);
  2333. for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackgroundImageChanged(e);
  2334. }
  2335. protected virtual void OnBindingContextChanged(EventArgs e) {
  2336. if (BindingContextChanged!=null) BindingContextChanged(this, e);
  2337. for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBindingContextChanged(e);
  2338. }
  2339. protected virtual void OnCausesValidationChanged(EventArgs e) {
  2340. if (CausesValidationChanged!=null) CausesValidationChanged(this, e);
  2341. }
  2342. protected virtual void OnChangeUICues(UICuesEventArgs e) {
  2343. if (CausesValidationChanged!=null) CausesValidationChanged(this, e);
  2344. }
  2345. protected virtual void OnClick(EventArgs e) {
  2346. if (Click!=null) Click(this, e);
  2347. }
  2348. protected virtual void OnContextMenuChanged(EventArgs e) {
  2349. if (ContextMenuChanged!=null) ContextMenuChanged(this, e);
  2350. }
  2351. protected virtual void OnControlAdded(ControlEventArgs e) {
  2352. if (ControlAdded!=null) ControlAdded(this, e);
  2353. }
  2354. protected virtual void OnControlRemoved(ControlEventArgs e) {
  2355. if (ControlRemoved!=null) ControlRemoved(this, e);
  2356. }
  2357. protected virtual void OnCreateControl() {
  2358. // Override me!
  2359. }
  2360. protected virtual void OnCursorChanged(EventArgs e) {
  2361. if (CursorChanged!=null) CursorChanged(this, e);
  2362. }
  2363. protected virtual void OnDockChanged(EventArgs e) {
  2364. if (DockChanged!=null) DockChanged(this, e);
  2365. }
  2366. protected virtual void OnDoubleClick(EventArgs e) {
  2367. if (DoubleClick!=null) DoubleClick(this, e);
  2368. }
  2369. protected virtual void OnDragDrop(DragEventArgs drgevent) {
  2370. if (DragDrop!=null) DragDrop(this, drgevent);
  2371. }
  2372. protected virtual void OnDragEnter(DragEventArgs drgevent) {
  2373. if (DragEnter!=null) DragEnter(this, drgevent);
  2374. }
  2375. protected virtual void OnDragLeave(EventArgs e) {
  2376. if (DragLeave!=null) DragLeave(this, e);
  2377. }
  2378. protected virtual void OnDragOver(DragEventArgs drgevent) {
  2379. if (DragOver!=null) DragOver(this, drgevent);
  2380. }
  2381. protected virtual void OnEnabledChanged(EventArgs e) {
  2382. if (EnabledChanged!=null) EnabledChanged(this, e);
  2383. for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentEnabledChanged(e);
  2384. }
  2385. protected virtual void OnEnter(EventArgs e) {
  2386. if (Enter!=null) Enter(this, e);
  2387. }
  2388. protected virtual void OnFontChanged(EventArgs e) {
  2389. if (FontChanged!=null) FontChanged(this, e);
  2390. }
  2391. protected virtual void OnForeColorChanged(EventArgs e) {
  2392. if (ForeColorChanged!=null) ForeColorChanged(this, e);
  2393. for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentForeColorChanged(e);
  2394. }
  2395. protected virtual void OnGiveFeedback(GiveFeedbackEventArgs gfbevent) {
  2396. if (GiveFeedback!=null) GiveFeedback(this, gfbevent);
  2397. }
  2398. protected virtual void OnGotFocus(EventArgs e) {
  2399. if (GotFocus!=null) GotFocus(this, e);
  2400. }
  2401. protected virtual void OnHandleCreated(EventArgs e) {
  2402. if (HandleCreated!=null) HandleCreated(this, e);
  2403. }
  2404. protected virtual void OnHandleDestroyed(EventArgs e) {
  2405. if (HandleDestroyed!=null) HandleDestroyed(this, e);
  2406. }
  2407. protected virtual void OnHelpRequested(HelpEventArgs hevent) {
  2408. if (HelpRequested!=null) HelpRequested(this, hevent);
  2409. }
  2410. protected virtual void OnImeModeChanged(EventArgs e) {
  2411. if (ImeModeChanged!=null) ImeModeChanged(this, e);
  2412. }
  2413. protected virtual void OnInvalidated(InvalidateEventArgs e) {
  2414. if (Invalidated!=null) Invalidated(this, e);
  2415. }
  2416. protected virtual void OnKeyDown(KeyEventArgs e) {
  2417. if (KeyDown!=null) KeyDown(this, e);
  2418. }
  2419. protected virtual void OnKeyPress(KeyPressEventArgs e) {
  2420. if (KeyPress!=null) KeyPress(this, e);
  2421. }
  2422. protected virtual void OnKeyUp(KeyEventArgs e) {
  2423. if (KeyUp!=null) KeyUp(this, e);
  2424. }
  2425. protected virtual void OnLayout(LayoutEventArgs levent) {
  2426. if (Layout!=null) Layout(this, levent);
  2427. }
  2428. protected virtual void OnLeave(EventArgs e) {
  2429. if (Leave!=null) Leave(this, e);
  2430. }
  2431. protected virtual void OnLocationChanged(EventArgs e) {
  2432. if (LocationChanged!=null) LocationChanged(this, e);
  2433. }
  2434. protected virtual void OnLostFocus(EventArgs e) {
  2435. if (LostFocus!=null) LostFocus(this, e);
  2436. }
  2437. protected virtual void OnMouseDown(MouseEventArgs e) {
  2438. if (MouseDown!=null) MouseDown(this, e);
  2439. }
  2440. protected virtual void OnMouseEnter(EventArgs e) {
  2441. if (MouseEnter!=null) MouseEnter(this, e);
  2442. }
  2443. protected virtual void OnMouseHover(EventArgs e) {
  2444. if (MouseHover!=null) MouseHover(this, e);
  2445. }
  2446. protected virtual void OnMouseLeave(EventArgs e) {
  2447. if (MouseLeave!=null) MouseLeave(this, e);
  2448. }
  2449. protected virtual void OnMouseMove(MouseEventArgs e) {
  2450. if (MouseMove!=null) MouseMove(this, e);
  2451. }
  2452. protected virtual void OnMouseUp(MouseEventArgs e) {
  2453. if (MouseUp!=null) MouseUp(this, e);
  2454. }
  2455. protected virtual void OnMouseWheel(MouseEventArgs e) {
  2456. if (MouseWheel!=null) MouseWheel(this, e);
  2457. }
  2458. protected virtual void OnMove(EventArgs e) {
  2459. if (Move!=null) Move(this, e);
  2460. }
  2461. protected virtual void OnNotifyMessage(Message m) {
  2462. // Override me!
  2463. }
  2464. protected virtual void OnPaint(PaintEventArgs e) {
  2465. if (Paint!=null) Paint(this, e);
  2466. }
  2467. protected virtual void OnPaintBackground(PaintEventArgs pevent) {
  2468. // Override me!
  2469. }
  2470. protected virtual void OnParentBackColorChanged(EventArgs e) {
  2471. if (background_color.IsEmpty && background_image==null) {
  2472. Invalidate();
  2473. OnBackColorChanged(e);
  2474. }
  2475. }
  2476. protected virtual void OnParentBackgroundImageChanged(EventArgs e) {
  2477. if (background_color.IsEmpty && background_image==null) {
  2478. Invalidate();
  2479. OnBackgroundImageChanged(e);
  2480. }
  2481. }
  2482. protected virtual void OnParentBindingContextChanged(EventArgs e) {
  2483. if (binding_context==null) {
  2484. binding_context=Parent.binding_context;
  2485. OnBindingContextChanged(e);
  2486. }
  2487. }
  2488. protected virtual void OnParentChanged(EventArgs e) {
  2489. if (ParentChanged!=null) ParentChanged(this, e);
  2490. }
  2491. protected virtual void OnParentEnabledChanged(EventArgs e) {
  2492. if ((is_enabled && !Parent.is_enabled) || (!is_enabled && Parent.is_enabled)) {
  2493. is_enabled=false;
  2494. Invalidate();
  2495. EnabledChanged(this, e);
  2496. }
  2497. }
  2498. protected virtual void OnParentFontChanged(EventArgs e) {
  2499. if (font==null) {
  2500. Invalidate();
  2501. OnFontChanged(e);
  2502. }
  2503. }
  2504. protected virtual void OnParentForeColorChanged(EventArgs e) {
  2505. if (foreground_color.IsEmpty) {
  2506. Invalidate();
  2507. OnForeColorChanged(e);
  2508. }
  2509. }
  2510. protected virtual void OnParentRightToLeftChanged(EventArgs e) {
  2511. if (right_to_left==RightToLeft.Inherit) {
  2512. Invalidate();
  2513. OnRightToLeftChanged(e);
  2514. }
  2515. }
  2516. protected virtual void OnParentVisibleChanged(EventArgs e) {
  2517. if (is_visible!=Parent.is_visible) {
  2518. is_visible=false;
  2519. Invalidate();
  2520. OnVisibleChanged(e);
  2521. }
  2522. }
  2523. protected virtual void OnQueryContinueDrag(QueryContinueDragEventArgs e) {
  2524. if (QueryContinueDrag!=null) QueryContinueDrag(this, e);
  2525. }
  2526. protected virtual void OnResize(EventArgs e) {
  2527. if (Resize!=null) Resize(this, e);
  2528. PerformLayout(this, "bounds");
  2529. if (parent != null) {
  2530. parent.PerformLayout();
  2531. }
  2532. }
  2533. protected virtual void OnRightToLeftChanged(EventArgs e) {
  2534. if (RightToLeftChanged!=null) RightToLeftChanged(this, e);
  2535. for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentRightToLeftChanged(e);
  2536. }
  2537. protected virtual void OnSizeChanged(EventArgs e) {
  2538. OnResize(e);
  2539. if (SizeChanged!=null) SizeChanged(this, e);
  2540. }
  2541. protected virtual void OnStyleChanged(EventArgs e) {
  2542. if (StyleChanged!=null) StyleChanged(this, e);
  2543. }
  2544. protected virtual void OnSystemColorsChanged(EventArgs e) {
  2545. if (SystemColorsChanged!=null) SystemColorsChanged(this, e);
  2546. }
  2547. protected virtual void OnTabIndexChanged(EventArgs e) {
  2548. if (TabIndexChanged!=null) TabIndexChanged(this, e);
  2549. }
  2550. protected virtual void OnTabStopChanged(EventArgs e) {
  2551. if (TabStopChanged!=null) TabStopChanged(this, e);
  2552. }
  2553. protected virtual void OnTextChanged(EventArgs e) {
  2554. if (TextChanged!=null) TextChanged(this, e);
  2555. }
  2556. protected virtual void OnValidated(EventArgs e) {
  2557. if (Validated!=null) Validated(this, e);
  2558. }
  2559. protected virtual void OnValidating(System.ComponentModel.CancelEventArgs e) {
  2560. if (Validating!=null) Validating(this, e);
  2561. }
  2562. protected virtual void OnVisibleChanged(EventArgs e) {
  2563. if (!is_visible) {
  2564. if (dc_mem!=null) {
  2565. dc_mem.Dispose ();
  2566. bmp_mem=null;
  2567. }
  2568. if (bmp_mem!=null) {
  2569. bmp_mem.Dispose();
  2570. bmp_mem=null;
  2571. }
  2572. } else {
  2573. if (!is_disposed) {
  2574. if (!this.IsHandleCreated) {
  2575. this.CreateHandle();
  2576. }
  2577. PerformLayout();
  2578. }
  2579. }
  2580. if (VisibleChanged!=null) VisibleChanged(this, e);
  2581. // We need to tell our kids
  2582. for (int i=0; i<child_controls.Count; i++) {
  2583. child_controls[i].OnParentVisibleChanged(e);
  2584. }
  2585. }
  2586. #endregion // OnXXX methods
  2587. #region Events
  2588. public event EventHandler BackColorChanged;
  2589. public event EventHandler BackgroundImageChanged;
  2590. public event EventHandler BindingContextChanged;
  2591. public event EventHandler CausesValidationChanged;
  2592. public event UICuesEventHandler ChangeUICues;
  2593. public event EventHandler Click;
  2594. public event EventHandler ContextMenuChanged;
  2595. public event ControlEventHandler ControlAdded;
  2596. public event ControlEventHandler ControlRemoved;
  2597. public event EventHandler CursorChanged;
  2598. public event EventHandler DockChanged;
  2599. public event EventHandler DoubleClick;
  2600. public event DragEventHandler DragDrop;
  2601. public event DragEventHandler DragEnter;
  2602. public event EventHandler DragLeave;
  2603. public event DragEventHandler DragOver;
  2604. public event EventHandler EnabledChanged;
  2605. public event EventHandler Enter;
  2606. public event EventHandler FontChanged;
  2607. public event EventHandler ForeColorChanged;
  2608. public event GiveFeedbackEventHandler GiveFeedback;
  2609. public event EventHandler GotFocus;
  2610. public event EventHandler HandleCreated;
  2611. public event EventHandler HandleDestroyed;
  2612. public event HelpEventHandler HelpRequested;
  2613. public event EventHandler ImeModeChanged;
  2614. public event InvalidateEventHandler Invalidated;
  2615. public event KeyEventHandler KeyDown;
  2616. public event KeyPressEventHandler KeyPress;
  2617. public event KeyEventHandler KeyUp;
  2618. public event LayoutEventHandler Layout;
  2619. public event EventHandler Leave;
  2620. public event EventHandler LocationChanged;
  2621. public event EventHandler LostFocus;
  2622. public event MouseEventHandler MouseDown;
  2623. public event EventHandler MouseEnter;
  2624. public event EventHandler MouseHover;
  2625. public event EventHandler MouseLeave;
  2626. public event MouseEventHandler MouseMove;
  2627. public event MouseEventHandler MouseUp;
  2628. public event MouseEventHandler MouseWheel;
  2629. public event EventHandler Move;
  2630. public event PaintEventHandler Paint;
  2631. public event EventHandler ParentChanged;
  2632. public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp;
  2633. public event QueryContinueDragEventHandler QueryContinueDrag;
  2634. public event EventHandler Resize;
  2635. public event EventHandler RightToLeftChanged;
  2636. public event EventHandler SizeChanged;
  2637. public event EventHandler StyleChanged;
  2638. public event EventHandler SystemColorsChanged;
  2639. public event EventHandler TabIndexChanged;
  2640. public event EventHandler TabStopChanged;
  2641. public event EventHandler TextChanged;
  2642. public event EventHandler Validated;
  2643. public event CancelEventHandler Validating;
  2644. public event EventHandler VisibleChanged;
  2645. #endregion // Events
  2646. }
  2647. }