Control.cs 78 KB

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