Control.cs 56 KB

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