Control.cs 80 KB

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