Control.cs 54 KB

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