Control.cs 58 KB

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