Control.cs 56 KB

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