Control.cs 79 KB

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