Control.cs 54 KB

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