Control.cs 57 KB

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