Control.cs 63 KB

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