Control.cs 78 KB

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