Control.cs 56 KB

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