Control.cs 75 KB

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