Control.cs 57 KB

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