Control.cs 58 KB

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