Control.cs 75 KB

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