Control.cs 56 KB

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