Control.cs 76 KB

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