Control.cs 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914
  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.11 $
  33. // $Modtime: $
  34. // $Log: Control.cs,v $
  35. // Revision 1.11 2004/08/06 21:30:56 pbartok
  36. // - Fixed recursive loop when resizing
  37. // - Improved/fixed redrawing on expose messages
  38. //
  39. // Revision 1.10 2004/08/06 15:53:39 jordi
  40. // X11 keyboard navigation
  41. //
  42. // Revision 1.9 2004/08/04 21:14:26 pbartok
  43. // - Fixed Invalidation bug (calculated wrong client area)
  44. // - Added ClientSize setter
  45. //
  46. // Revision 1.8 2004/08/04 20:11:24 pbartok
  47. // - Added Invalidate handling
  48. //
  49. // Revision 1.7 2004/07/27 10:38:17 jordi
  50. // changes to be able to run winforms samples
  51. //
  52. // Revision 1.6 2004/07/19 19:09:42 jordi
  53. // label control re-written: added missing functionlity, events, and properties
  54. //
  55. // Revision 1.5 2004/07/19 16:49:23 jordi
  56. // fixes SetBounds logic
  57. //
  58. // Revision 1.4 2004/07/19 07:29:35 jordi
  59. // Call RefreshWindow only if the window has created
  60. //
  61. // Revision 1.3 2004/07/15 17:03:35 jordi
  62. // added basic mouse handeling events
  63. //
  64. // Revision 1.2 2004/07/13 15:31:45 jordi
  65. // commit: new properties and fixes form size problems
  66. //
  67. // Revision 1.1 2004/07/09 05:21:25 pbartok
  68. // - Initial check-in
  69. //
  70. //
  71. // NOT COMPLETE
  72. using System;
  73. using System.Drawing;
  74. using System.ComponentModel;
  75. using System.Collections;
  76. using System.Diagnostics;
  77. using System.Threading;
  78. using System.Runtime.InteropServices;
  79. namespace System.Windows.Forms
  80. {
  81. public class Control : Component, ISynchronizeInvoke, IWin32Window
  82. {
  83. #region Local Variables
  84. // Basic
  85. internal Rectangle bounds; // bounding rectangle for control
  86. internal object creator_thread; // thread that created the control
  87. internal ControlNativeWindow window; // object for native window handle
  88. internal string name; // for object naming
  89. // State
  90. internal bool has_focus; // true if control has focus
  91. internal bool is_visible; // true if control is visible
  92. internal bool is_enabled; // true if control is enabled (usable/not grayed out)
  93. internal int tab_index; // position in tab order of siblings
  94. internal bool is_disposed; // has the window already been disposed?
  95. internal Size window_size; // size of the window (including decorations)
  96. internal Size client_size; // size of the client area (window excluding decorations)
  97. internal ControlStyles control_style; // win32-specific, style bits for control
  98. // Visuals
  99. internal Color foreground_color; // foreground color for control
  100. internal Color background_color; // background color for control
  101. internal Image background_image; // background image for control
  102. internal Font font; // font for control
  103. internal string text; // window/title text for control
  104. // to be categorized...
  105. static internal Hashtable controls; // All of the applications controls, in a flat list
  106. internal ControlCollection child_controls; // our children
  107. internal Control parent; // our parent control
  108. internal int num_of_children; // number of children the control has
  109. internal Control[] children; // our children
  110. internal AccessibleObject accessibility_object; // object that contains accessibility information about our control
  111. internal AnchorStyles anchor_style; // TODO
  112. internal DockStyle dock_style; // TODO
  113. internal BindingContext binding_context; // TODO
  114. internal RightToLeft right_to_left; // drawing direction for control
  115. internal int layout_suspended;
  116. #endregion // Local Variables
  117. #region Private Classes
  118. // This helper class allows us to dispatch messages to Control.WndProc
  119. internal class ControlNativeWindow : NativeWindow {
  120. private Control control;
  121. public ControlNativeWindow(Control control) : base() {
  122. this.control=control;
  123. }
  124. protected override void WndProc(ref Message m) {
  125. control.WndProc(ref m);
  126. }
  127. }
  128. #endregion
  129. #region Public Classes
  130. public class ControlCollection : IList, ICollection, ICloneable, IEnumerable {
  131. private class Enumerator : IEnumerator {
  132. private Control owner;
  133. private int current;
  134. public Enumerator(Control owner) {
  135. this.owner=owner;
  136. this.current=-1;
  137. }
  138. public bool MoveNext() {
  139. current++;
  140. if (current>=owner.num_of_children) {
  141. return false;
  142. }
  143. return true;
  144. }
  145. public void Reset() {
  146. current=-1;
  147. }
  148. public object Current {
  149. get {
  150. if (current>=0 && current<owner.num_of_children) {
  151. return owner.children[current];
  152. } else {
  153. throw new InvalidOperationException("enumerator out of range");
  154. }
  155. }
  156. }
  157. }
  158. protected Control owner;
  159. #region ControlCollection Public Constructor
  160. public ControlCollection(Control owner) {
  161. this.owner=owner;
  162. }
  163. #endregion
  164. #region ControlCollection Public Instance Properties
  165. public int Count {
  166. get {
  167. return owner.num_of_children;
  168. }
  169. }
  170. public bool IsReadOnly {
  171. get {
  172. return false;
  173. }
  174. }
  175. public virtual Control this [int index] {
  176. get {
  177. if ((uint)index>=owner.num_of_children) {
  178. throw new ArgumentOutOfRangeException();
  179. }
  180. return owner.children[index];
  181. }
  182. }
  183. #endregion // ControlCollection Public Instance Properties
  184. #region ControlCollection Public Instance Methods
  185. public virtual void Add(Control value) {
  186. // Don't add it if we already have it
  187. for (int i=0; i<owner.num_of_children; i++) {
  188. if (value==owner.child_controls[i]) {
  189. return;
  190. }
  191. }
  192. value.Parent=owner;
  193. owner.OnControlAdded(new ControlEventArgs(value));
  194. }
  195. public virtual void AddRange(Control[] controls) {
  196. for (int i=0; i<controls.Length; i++) {
  197. Add(controls[i]);
  198. }
  199. }
  200. public virtual void Clear() {
  201. owner.SuspendLayout();
  202. for (int i=0; i<owner.num_of_children; i++) {
  203. Remove(owner.children[i]);
  204. }
  205. owner.ResumeLayout();
  206. }
  207. public bool Contains(Control control) {
  208. for (int i=0; i<owner.num_of_children; i++) {
  209. if (owner.children[i]==control) {
  210. return true;
  211. }
  212. }
  213. return false;
  214. }
  215. public void CopyTo(Array dest, int index) {
  216. if (owner.num_of_children>0) {
  217. Array.Copy(owner.children, 0, dest, index, owner.num_of_children);
  218. }
  219. }
  220. public override bool Equals(object other) {
  221. if (other is ControlCollection && (((ControlCollection)other).owner==this.owner)) {
  222. return(true);
  223. } else {
  224. return(false);
  225. }
  226. }
  227. public int GetChildIndex(Control child) {
  228. return GetChildIndex(child, false);
  229. }
  230. public int GetChildIndex(Control child, bool throwException) {
  231. int index;
  232. index=IndexOf(child);
  233. if (index==-1 && throwException) {
  234. throw new ArgumentException("Not a child control", "child");
  235. }
  236. return index;
  237. }
  238. public IEnumerator GetEnumerator() {
  239. return new ControlCollection.Enumerator(this.owner);
  240. }
  241. public override int GetHashCode() {
  242. return base.GetHashCode();
  243. }
  244. public int IndexOf(Control control) {
  245. int index;
  246. for (index=0; index<owner.num_of_children; index++) {
  247. if (owner.children[index] == control) {
  248. return index;
  249. }
  250. }
  251. return -1;
  252. }
  253. public virtual void Remove(Control value) {
  254. for (int i=0; i<owner.num_of_children; i++) {
  255. if (owner.children[i]==value) {
  256. RemoveAt(i);
  257. }
  258. }
  259. }
  260. public void RemoveAt(int index) {
  261. for (int i=index; i<owner.num_of_children; i++) {
  262. owner.children[i]=owner.children[i+1];
  263. }
  264. }
  265. public void SetChildIndex(Control child, int new_index) {
  266. int old_index;
  267. old_index=IndexOf(child);
  268. if (old_index==-1) {
  269. throw new ArgumentException("Not a child control", "child");
  270. }
  271. if (old_index==new_index) {
  272. return;
  273. }
  274. RemoveAt(old_index);
  275. if (new_index>owner.num_of_children) {
  276. Add(child);
  277. } else {
  278. for (int i=owner.num_of_children-1;i>new_index; i--) {
  279. owner.children[i+1]=owner.children[i];
  280. }
  281. owner.children[new_index]=(Control)child;
  282. }
  283. }
  284. #endregion // ControlCollection Public Instance Methods
  285. #region ControlCollection Interface Methods
  286. #if nodef
  287. int IList.Add(Control value) {
  288. Add(value);
  289. }
  290. #endif
  291. int IList.Add(object value) {
  292. if (!(value is Control)) {
  293. throw new ArgumentException("Not of type Control", "value");
  294. }
  295. Add((Control)value);
  296. // Assumes the element was added to the end of the list
  297. return owner.num_of_children;
  298. }
  299. void IList.Clear() {
  300. this.Clear();
  301. }
  302. bool IList.Contains(object value) {
  303. if (!(value is Control)) {
  304. throw new ArgumentException("Not of type Control", "value");
  305. }
  306. return this.Contains((Control)value);
  307. }
  308. int IList.IndexOf(object value) {
  309. if (!(value is Control)) {
  310. throw new ArgumentException("Not of type Control", "value");
  311. }
  312. for (int i=0; i<owner.num_of_children; i++) {
  313. if (owner.children[i]==(Control)value) {
  314. return i;
  315. }
  316. }
  317. return -1;
  318. }
  319. void IList.Insert(int index, object value) {
  320. if (!(value is Control)) {
  321. throw new ArgumentException("Not of type Control", "value");
  322. }
  323. if (index>owner.num_of_children) {
  324. throw new ArgumentOutOfRangeException("index");
  325. }
  326. for (int i=owner.num_of_children-1;i>index; i--) {
  327. owner.children[i+1]=owner.children[i];
  328. }
  329. owner.children[index]=(Control)value;
  330. }
  331. void IList.Remove(object value) {
  332. if (!(value is Control)) {
  333. throw new ArgumentException("Not of type Control", "value");
  334. }
  335. this.Remove((Control)value);
  336. }
  337. object IList.this [int index] {
  338. get {
  339. return owner.children[index];
  340. }
  341. set {
  342. }
  343. }
  344. bool IList.IsFixedSize {
  345. get {
  346. return false;
  347. }
  348. }
  349. object ICollection.SyncRoot {
  350. get {
  351. return this;
  352. }
  353. }
  354. bool ICollection.IsSynchronized {
  355. get {
  356. return false;
  357. }
  358. }
  359. Object ICloneable.Clone() {
  360. ControlCollection clone = new ControlCollection(this.owner);
  361. return clone;
  362. }
  363. #endregion // ControlCollection Interface Methods
  364. class ControlComparer : IComparer {
  365. int IComparer.Compare(object x, object y) {
  366. int tab_index_x;
  367. int tab_index_y;
  368. tab_index_x=((Control)x).tab_index;
  369. tab_index_y=((Control)y).tab_index;
  370. if (tab_index_x<tab_index_y) {
  371. return -1;
  372. } else if (tab_index_x>tab_index_y) {
  373. return 1;
  374. }
  375. return 0;
  376. }
  377. }
  378. }
  379. #endregion // ControlCollection Class
  380. #region Public Constructors
  381. public Control() {
  382. creator_thread = Thread.CurrentThread;
  383. controls = new Hashtable();
  384. child_controls = CreateControlsInstance();
  385. bounds = new Rectangle(0, 0, DefaultSize.Width, DefaultSize.Height);
  386. window_size = new Size(DefaultSize.Width, DefaultSize.Height);
  387. client_size = new Size(DefaultSize.Width, DefaultSize.Height);
  388. is_visible = true;
  389. is_disposed = false;
  390. is_enabled = true;
  391. has_focus = false;
  392. layout_suspended = 0;
  393. parent = null;
  394. background_image = null;
  395. }
  396. public Control(Control parent, string text) : this() {
  397. Text=text;
  398. Parent=parent;
  399. }
  400. public Control(Control parent, string text, int left, int top, int width, int height) : this() {
  401. Parent=parent;
  402. Left=left;
  403. Top=top;
  404. Width=width;
  405. Height=height;
  406. Text=text;
  407. }
  408. public Control(string text) : this() {
  409. Text=text;
  410. }
  411. public Control(string text, int left, int top, int width, int height) : this() {
  412. Left=left;
  413. Top=top;
  414. Width=width;
  415. Height=height;
  416. Text=text;
  417. }
  418. #endregion // Public Constructors
  419. #region Public Static Properties
  420. public static Color DefaultBackColor {
  421. get {
  422. return XplatUI.Defaults.BackColor;
  423. }
  424. }
  425. public static Font DefaultFont {
  426. get {
  427. return XplatUI.Defaults.Font;
  428. }
  429. }
  430. public static Color DefaultForeColor {
  431. get {
  432. return XplatUI.Defaults.ForeColor;
  433. }
  434. }
  435. public static Keys ModifierKeys {
  436. get {
  437. return XplatUI.State.ModifierKeys;
  438. }
  439. }
  440. public static MouseButtons MouseButtons {
  441. get {
  442. return XplatUI.State.MouseButtons;
  443. }
  444. }
  445. public static Point MousePosition {
  446. get {
  447. return XplatUI.State.MousePosition;
  448. }
  449. }
  450. #endregion // Public Static Properties
  451. #region Public Instance Properties
  452. public AccessibleObject AccessibilityObject {
  453. get {
  454. if (accessibility_object==null) {
  455. accessibility_object=CreateAccessibilityInstance();
  456. }
  457. return accessibility_object;
  458. }
  459. }
  460. public string AccessibleDefaultActionDescription {
  461. get {
  462. return AccessibilityObject.default_action;
  463. }
  464. set {
  465. AccessibilityObject.default_action=value;
  466. }
  467. }
  468. public string AccessibleDescription {
  469. get {
  470. return AccessibilityObject.description;
  471. }
  472. set {
  473. AccessibilityObject.description=value;
  474. }
  475. }
  476. public string AccessibleName {
  477. get {
  478. return AccessibilityObject.Name;
  479. }
  480. set {
  481. AccessibilityObject.Name=value;
  482. }
  483. }
  484. public AccessibleRole AccessibleRole {
  485. get {
  486. return AccessibilityObject.role;
  487. }
  488. set {
  489. AccessibilityObject.role=value;
  490. }
  491. }
  492. public virtual bool AllowDrop {
  493. get {
  494. return XplatUI.State.DropTarget;
  495. }
  496. set {
  497. XplatUI.State.DropTarget=value;
  498. }
  499. }
  500. public virtual AnchorStyles Anchor {
  501. get {
  502. return anchor_style;
  503. }
  504. set {
  505. anchor_style=value;
  506. }
  507. }
  508. public virtual Color BackColor {
  509. get {
  510. if (background_color.IsEmpty) {
  511. if (parent!=null) {
  512. return parent.BackColor;
  513. }
  514. return DefaultBackColor;
  515. }
  516. return background_color;
  517. }
  518. set {
  519. background_color=value;
  520. Refresh();
  521. }
  522. }
  523. public virtual Image BackgroundImage {
  524. get {
  525. return background_image;
  526. }
  527. set {
  528. if (background_image!=value) {
  529. background_image=value;
  530. OnBackgroundImageChanged(EventArgs.Empty);
  531. }
  532. }
  533. }
  534. public virtual BindingContext BindingContext {
  535. get {
  536. throw new NotImplementedException();
  537. }
  538. set {
  539. throw new NotImplementedException();
  540. }
  541. }
  542. public int Bottom {
  543. get {
  544. return bounds.Y+bounds.Height;
  545. }
  546. }
  547. public Rectangle Bounds {
  548. get {
  549. return this.bounds;
  550. }
  551. set {
  552. SetBounds(value.Left, value.Top, value.Width, value.Height, BoundsSpecified.All);
  553. }
  554. }
  555. public bool CanFocus {
  556. get {
  557. throw new NotImplementedException();
  558. }
  559. }
  560. public bool CanSelect {
  561. get {
  562. throw new NotImplementedException();
  563. }
  564. }
  565. public bool Capture {
  566. get {
  567. throw new NotImplementedException();
  568. }
  569. set {
  570. throw new NotImplementedException();
  571. }
  572. }
  573. public bool CausesValidation {
  574. get {
  575. throw new NotImplementedException();
  576. }
  577. set {
  578. throw new NotImplementedException();
  579. }
  580. }
  581. public Rectangle ClientRectangle {
  582. get {
  583. return new Rectangle(0, 0, client_size.Width, client_size.Height);
  584. }
  585. }
  586. public Size ClientSize {
  587. get {
  588. return client_size;
  589. }
  590. set {
  591. this.SetClientSizeCore(value.Width, value.Height);
  592. }
  593. }
  594. public String CompanyName {
  595. get {
  596. return "Mono Project, Novell, Inc.";
  597. }
  598. }
  599. public bool ContainsFocus {
  600. get {
  601. throw new NotImplementedException();
  602. }
  603. }
  604. #if notdef
  605. public virtual ContextMenu ContextMenu {
  606. get {
  607. throw new NotImplementedException();
  608. }
  609. set {
  610. throw new NotImplementedException();
  611. }
  612. }
  613. #endif
  614. public ControlCollection Controls {
  615. get {
  616. return CreateControlsInstance();
  617. }
  618. }
  619. public bool Created {
  620. get {
  621. throw new NotImplementedException();
  622. }
  623. }
  624. #if notdef
  625. public virtual Cursor Cursor {
  626. get {
  627. throw new NotImplementedException();
  628. }
  629. set {
  630. throw new NotImplementedException();
  631. }
  632. }
  633. public ControlBidingsCollection DataBindings {
  634. get {
  635. throw new NotImplementedException();
  636. }
  637. }
  638. #endif
  639. public virtual Rectangle DisplayRectangle {
  640. get {
  641. return ClientRectangle;
  642. }
  643. }
  644. public bool Disposing {
  645. get {
  646. throw new NotImplementedException();
  647. }
  648. }
  649. public virtual DockStyle Dock {
  650. get { return dock_style;}
  651. set {
  652. if (dock_style == value)
  653. return;
  654. dock_style = value;
  655. }
  656. }
  657. public bool Enabled {
  658. get {
  659. return is_enabled;
  660. }
  661. set {
  662. is_enabled = value;
  663. }
  664. }
  665. public virtual bool Focused {
  666. get {
  667. return this.has_focus;
  668. }
  669. set {
  670. throw new NotImplementedException();
  671. }
  672. }
  673. public virtual Font Font {
  674. get {
  675. if (font != null) {
  676. return font;
  677. }
  678. if (Parent != null && Parent.Font != null) {
  679. return Parent.Font;
  680. }
  681. return DefaultFont;
  682. }
  683. set {
  684. font=value;
  685. Refresh();
  686. }
  687. }
  688. public virtual Color ForeColor {
  689. get {
  690. if (foreground_color.IsEmpty) {
  691. if (parent!=null) {
  692. return parent.ForeColor;
  693. }
  694. return DefaultForeColor;
  695. }
  696. return foreground_color;
  697. }
  698. set {
  699. foreground_color=value;
  700. Refresh();
  701. }
  702. }
  703. public bool IsDisposed {
  704. get {
  705. return this.is_disposed;
  706. }
  707. }
  708. public bool IsHandleCreated {
  709. get {
  710. if ((window!=null) && (window.Handle!=IntPtr.Zero)) {
  711. return true;
  712. }
  713. return false;
  714. }
  715. }
  716. public string Name {
  717. get {
  718. return this.name;
  719. }
  720. set {
  721. this.name=value;
  722. }
  723. }
  724. public Control Parent {
  725. get {
  726. return this.parent;
  727. }
  728. set {
  729. if (parent!=value) {
  730. if (parent!=null) {
  731. parent.Controls.Remove(this);
  732. }
  733. parent=value;
  734. if (!parent.Controls.Contains(this)) {
  735. parent.Controls.Add(this);
  736. }
  737. XplatUI.SetParent(Handle, value.Handle);
  738. }
  739. }
  740. }
  741. public IntPtr Handle { // IWin32Window
  742. get
  743. {
  744. if (!IsHandleCreated) {
  745. CreateHandle();
  746. }
  747. return window.Handle;
  748. }
  749. }
  750. public bool InvokeRequired { // ISynchronizeInvoke
  751. get {
  752. if (creator_thread!=Thread.CurrentThread) {
  753. return true;
  754. }
  755. return false;
  756. }
  757. }
  758. public bool Visible {
  759. get {
  760. return this.is_visible;
  761. }
  762. set {
  763. if (value!=is_visible) {
  764. is_visible=value;
  765. XplatUI.SetVisible(Handle, value);
  766. }
  767. }
  768. }
  769. public virtual string Text {
  770. get {
  771. return this.text;
  772. }
  773. set {
  774. if (text!=value) {
  775. text=value;
  776. XplatUI.Text(Handle, text);
  777. }
  778. }
  779. }
  780. public int Left {
  781. get {
  782. return this.bounds.X;
  783. }
  784. set {
  785. SetBounds(value, bounds.Y, bounds.Width, bounds.Height, BoundsSpecified.X);
  786. }
  787. }
  788. public int Top {
  789. get {
  790. return this.bounds.Y;
  791. }
  792. set {
  793. SetBounds(bounds.X, value, bounds.Width, bounds.Height, BoundsSpecified.Y);
  794. }
  795. }
  796. public int Width {
  797. get {
  798. return this.bounds.Width;
  799. }
  800. set {
  801. SetBounds(bounds.X, bounds.Y, value, bounds.Height, BoundsSpecified.Width);
  802. }
  803. }
  804. public int Height {
  805. get {
  806. return this.bounds.Height;
  807. }
  808. set {
  809. SetBounds(bounds.X, bounds.Y, bounds.Width, value, BoundsSpecified.Height);
  810. }
  811. }
  812. public Point Location {
  813. get {
  814. return new Point(bounds.X, bounds.Y);
  815. }
  816. set {
  817. SetBounds(value.X, value.Y, bounds.Width, bounds.Height, BoundsSpecified.Location);
  818. }
  819. }
  820. public Size Size {
  821. get {
  822. return new Size(Width, Height);
  823. }
  824. set {
  825. SetBounds(bounds.X, bounds.Y, value.Width, value.Height, BoundsSpecified.Size);
  826. }
  827. }
  828. public int TabIndex {
  829. get {
  830. return tab_index;
  831. }
  832. set {
  833. tab_index = value;
  834. }
  835. }
  836. #endregion // Public Instance Properties
  837. #region Protected Instance Properties
  838. protected virtual CreateParams CreateParams {
  839. get {
  840. CreateParams create_params = new CreateParams();
  841. create_params.Caption = Text;
  842. create_params.X = Left;
  843. create_params.Y = Top;
  844. create_params.Width = Width;
  845. create_params.Height = Height;
  846. create_params.ClassName = XplatUI.DefaultClassName;
  847. create_params.ClassStyle = 0;
  848. create_params.ExStyle = 0;
  849. create_params.Param = 0;
  850. if (parent!=null) {
  851. create_params.Parent = parent.Handle;
  852. }
  853. create_params.Style = (int)WindowStyles.WS_OVERLAPPED;
  854. if (is_visible) {
  855. create_params.Style |= (int)WindowStyles.WS_VISIBLE;
  856. }
  857. return create_params;
  858. }
  859. }
  860. protected virtual ImeMode DefaultImeMode {
  861. get {
  862. return ImeMode.Inherit;
  863. }
  864. }
  865. protected virtual Size DefaultSize {
  866. get {
  867. return new Size(100, 23);
  868. }
  869. }
  870. #endregion // Protected Instance Properties
  871. #region Public Instance Methods
  872. public bool Contains(Control ctl) {
  873. Control current;
  874. current=ctl;
  875. while (current!=null) {
  876. if (current==ctl) {
  877. return true;
  878. }
  879. current=current.parent;
  880. }
  881. return false;
  882. }
  883. public void CreateControl() {
  884. Control child;
  885. CreateHandle();
  886. for (int i=0; i<num_of_children; i++) {
  887. child_controls[i].CreateControl();
  888. }
  889. OnCreateControl();
  890. }
  891. public virtual void Refresh() {
  892. if (IsHandleCreated == true)
  893. XplatUI.RefreshWindow(window.Handle);
  894. }
  895. public void SetBounds(int x, int y, int width, int height) {
  896. SetBounds(x, y, width, height, BoundsSpecified.All);
  897. }
  898. public void SetBounds(int x, int y, int width, int height, BoundsSpecified bounds_specified) {
  899. if ((bounds_specified & BoundsSpecified.X) != BoundsSpecified.X) {
  900. x = Left;
  901. }
  902. if ((bounds_specified & BoundsSpecified.Y) != BoundsSpecified.Y) {
  903. y = Top;
  904. }
  905. if ((bounds_specified & BoundsSpecified.Width)!= BoundsSpecified.Width) {
  906. width = Width;
  907. }
  908. if ((bounds_specified & BoundsSpecified.Height) != BoundsSpecified.Height) {
  909. height = Height;
  910. }
  911. if (IsHandleCreated) {
  912. XplatUI.MoveWindow(Handle, x, y, width, height);
  913. }
  914. UpdateBounds(x, y, width, height);
  915. }
  916. public void Show() {
  917. if (!IsHandleCreated) {
  918. this.CreateHandle();
  919. }
  920. this.Visible=true;
  921. }
  922. public object Invoke(Delegate method) { // ISynchronizeInvoke
  923. return Invoke(method, null);
  924. }
  925. public object Invoke(Delegate method, object[] args) { // ISynchronizeInvoke
  926. IAsyncResult result;
  927. result=BeginInvoke(method, args);
  928. return EndInvoke(result);
  929. }
  930. public IAsyncResult BeginInvoke(Delegate method) { // ISynchronizeInvoke
  931. return BeginInvoke(method, null);
  932. }
  933. protected virtual AccessibleObject CreateAccessibilityInstance() {
  934. return new AccessibleObject(this);
  935. }
  936. protected virtual ControlCollection CreateControlsInstance() {
  937. return new ControlCollection(this);
  938. }
  939. protected void UpdateBounds() {
  940. UpdateBounds(bounds.X, bounds.Y, bounds.Width, bounds.Height);
  941. }
  942. protected void UpdateBounds(int x, int y, int width, int height) {
  943. bool moved = false;
  944. bool resized = false;
  945. // Generate required notifications
  946. if ((this.bounds.X!=x) || (this.bounds.Y!=y)) {
  947. moved=true;
  948. }
  949. if ((this.Bounds.Width!=width) || (this.Bounds.Height!=height)) {
  950. resized=true;
  951. }
  952. bounds.X=x;
  953. bounds.Y=y;
  954. bounds.Width=width;
  955. bounds.Height=height;
  956. #if notdef
  957. if (IsHandleCreated) {
  958. XplatUI.SetWindowPos(Handle, bounds);
  959. }
  960. #endif
  961. if (moved) {
  962. OnLocationChanged(EventArgs.Empty);
  963. }
  964. if (resized) {
  965. OnSizeChanged(EventArgs.Empty);
  966. }
  967. }
  968. protected void UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) {
  969. UpdateBounds(x, y, width, height);
  970. }
  971. public void Invalidate() {
  972. Invalidate(new Rectangle(0, 0, bounds.Width, bounds.Height), false);
  973. }
  974. public void Invalidate(bool invalidateChildren) {
  975. Invalidate(new Rectangle(0, 0, bounds.Width, bounds.Height), invalidateChildren);
  976. }
  977. public void Invalidate(System.Drawing.Rectangle rc) {
  978. Invalidate(rc, false);
  979. }
  980. public void Invalidate(System.Drawing.Rectangle rc, bool invalidateChildren) {
  981. if (!IsHandleCreated || !is_visible) {
  982. return;
  983. }
  984. XplatUI.Invalidate(Handle, rc, false);
  985. if (invalidateChildren) {
  986. for (int i=0; i<num_of_children; i++) children[i].Invalidate();
  987. }
  988. }
  989. public void Invalidate(System.Drawing.Region region) {
  990. Invalidate(region, false);
  991. }
  992. [MonoTODO]
  993. public void Invalidate(System.Drawing.Region region, bool invalidateChildren) {
  994. throw new NotImplementedException();
  995. // FIXME - should use the GetRegionScans function of the region to invalidate each area
  996. if (invalidateChildren) {
  997. for (int i=0; i<num_of_children; i++) children[i].Invalidate();
  998. }
  999. }
  1000. [MonoTODO("BeginInvoke() : Figure out a cross-platform way to handle this")]
  1001. public IAsyncResult BeginInvoke(Delegate method, object[] args) { // ISynchronizeInvoke
  1002. IAsyncResult result = null;
  1003. return result;
  1004. }
  1005. [MonoTODO]
  1006. public object EndInvoke(IAsyncResult async_result) { // ISynchronizeInvoke
  1007. object result = null;
  1008. return result;
  1009. }
  1010. public void ResumeLayout()
  1011. {
  1012. ResumeLayout (true);
  1013. }
  1014. [MonoTODO]
  1015. public void ResumeLayout(bool peformLayout)
  1016. {
  1017. layout_suspended--;
  1018. if (layout_suspended > 0 || peformLayout == false)
  1019. return;
  1020. // PerformLayout and fire event
  1021. }
  1022. public void SuspendLayout()
  1023. {
  1024. layout_suspended++;
  1025. }
  1026. [MonoTODO]
  1027. protected virtual void WndProc(ref Message m) {
  1028. EventArgs e = new EventArgs();
  1029. #if debug
  1030. Console.WriteLine("Received message {0}", m);
  1031. #endif
  1032. switch((Msg)m.Msg) {
  1033. #if notyet
  1034. // Mouse handling
  1035. case Msg.WM_LBUTTONDBLCLK: throw new NotImplementedException(); break;
  1036. case Msg.WM_RBUTTONDOWN: throw new NotImplementedException(); break;
  1037. case Msg.WM_RBUTTONUP: throw new NotImplementedException(); break;
  1038. case Msg.WM_RBUTTONDBLCLK: throw new NotImplementedException(); break;
  1039. case Msg.WM_MOUSEHOVER: throw new NotImplementedException(); break;
  1040. case Msg.WM_MOUSELEAVE: throw new NotImplementedException(); break;
  1041. // Keyboard handling
  1042. case Msg.WM_CHAR: throw new NotImplementedException(); break;
  1043. case Msg.WM_KEYDOWN: throw new NotImplementedException(); break;
  1044. case Msg.WM_KEYUP: throw new NotImplementedException(); break;
  1045. #endif
  1046. // Window management
  1047. case Msg.WM_PAINT: {
  1048. Rectangle rect;
  1049. PaintEventArgs paint_event;
  1050. paint_event = XplatUI.PaintEventStart(Handle);
  1051. OnPaint(paint_event);
  1052. XplatUI.PaintEventEnd(Handle);
  1053. DefWndProc(ref m);
  1054. break;
  1055. }
  1056. case Msg.WM_ERASEBKGND:{
  1057. if (GetStyle (ControlStyles.UserPaint)){
  1058. PaintEventArgs eraseEventArgs = new PaintEventArgs (Graphics.FromHdc (m.WParam), new Rectangle (new Point (0,0),Size));
  1059. OnPaintBackground (eraseEventArgs);
  1060. m.Result = (IntPtr)1;
  1061. }
  1062. else {
  1063. m.Result = (IntPtr)0;
  1064. DefWndProc (ref m);
  1065. }
  1066. break;
  1067. }
  1068. case Msg.WM_LBUTTONUP: {
  1069. int clicks = 1;
  1070. int delta = 1;
  1071. OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
  1072. clicks, LowOrder ((int) m.LParam.ToInt32 ()),
  1073. HighOrder ((int) m.LParam.ToInt32 ()), delta));
  1074. break;
  1075. }
  1076. case Msg.WM_LBUTTONDOWN: {
  1077. int clicks = 1;
  1078. int delta = 1;
  1079. OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
  1080. clicks, LowOrder ((int) m.LParam.ToInt32 ()),
  1081. HighOrder ((int) m.LParam.ToInt32 ()), delta));
  1082. break;
  1083. }
  1084. case Msg.WM_MOUSEMOVE: {
  1085. int clicks = 1;
  1086. int delta = 1;
  1087. OnMouseMove (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
  1088. clicks, LowOrder ((int) m.LParam.ToInt32 ()),
  1089. HighOrder ((int) m.LParam.ToInt32 ()), delta));
  1090. break;
  1091. }
  1092. case Msg.WM_SIZE: {
  1093. UpdateBounds (bounds.X, bounds.Y, LowOrder ((int) m.LParam.ToInt32 ()),
  1094. HighOrder ((int) m.LParam.ToInt32 ()));
  1095. DefWndProc(ref m);
  1096. break;
  1097. }
  1098. case Msg.WM_KEYDOWN: {
  1099. if (!ProcessKeyEventArgs (ref m))
  1100. DefWndProc (ref m);
  1101. break;
  1102. }
  1103. case Msg.WM_KEYUP: {
  1104. if (!ProcessKeyEventArgs (ref m))
  1105. DefWndProc (ref m);
  1106. break;
  1107. }
  1108. #if notyet
  1109. case Msg.WM_WINDOWPOSCHANGED: throw new NotImplementedException(); break;
  1110. case Msg.WM_SYSCOLORCHANGE: throw new NotImplementedException(); break;
  1111. #endif
  1112. default:
  1113. DefWndProc(ref m);
  1114. break;
  1115. }
  1116. }
  1117. #endregion // Public Instance Methods
  1118. #region // Protected Instance Methods
  1119. protected virtual void CreateHandle() {
  1120. if (IsDisposed) {
  1121. throw new ObjectDisposedException(Name);
  1122. }
  1123. if (IsHandleCreated) {
  1124. return;
  1125. }
  1126. if (window==null) {
  1127. window = new ControlNativeWindow(this);
  1128. window.CreateHandle(CreateParams);
  1129. }
  1130. if (window.Handle!=IntPtr.Zero) {
  1131. if (!controls.Contains(window.Handle)) {
  1132. controls.Add(window.Handle, this);
  1133. }
  1134. creator_thread = Thread.CurrentThread;
  1135. OnHandleCreated(EventArgs.Empty);
  1136. }
  1137. }
  1138. protected virtual void DefWndProc(ref Message m) {
  1139. window.DefWndProc(ref m);
  1140. }
  1141. protected virtual void DestroyHandle() {
  1142. if (IsHandleCreated) {
  1143. if (Handle != IntPtr.Zero) {
  1144. controls.Remove(Handle);
  1145. }
  1146. if (window != null) {
  1147. window.DestroyHandle();
  1148. }
  1149. }
  1150. }
  1151. protected virtual bool ProcessKeyEventArgs (ref Message msg)
  1152. {
  1153. KeyEventArgs key_event;
  1154. switch (msg.Msg) {
  1155. case (int)Msg.WM_KEYDOWN: {
  1156. key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
  1157. OnKeyDown (key_event);
  1158. return key_event.Handled;
  1159. }
  1160. case (int)Msg.WM_KEYUP: {
  1161. key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
  1162. OnKeyUp (key_event);
  1163. return key_event.Handled;
  1164. }
  1165. default:
  1166. break;
  1167. }
  1168. return false;
  1169. }
  1170. protected virtual bool IsInputKey (Keys keyData)
  1171. {
  1172. return false;
  1173. }
  1174. protected virtual bool ProcessDialogKey (Keys keyData)
  1175. {
  1176. if (parent != null)
  1177. return Parent.ProcessDialogKey (keyData);
  1178. return false;
  1179. }
  1180. protected bool GetStyle(ControlStyles flag) {
  1181. return (control_style & flag) != 0;
  1182. }
  1183. protected virtual bool ProcessDialogChar(char charCode) {
  1184. throw new NotImplementedException();
  1185. }
  1186. protected virtual bool ProcessMnemonic(char charCode) {
  1187. throw new NotImplementedException();
  1188. }
  1189. protected void RecreateHandle() {
  1190. IEnumerator child = child_controls.GetEnumerator();
  1191. if (IsHandleCreated) {
  1192. DestroyHandle();
  1193. CreateHandle();
  1194. // FIXME ZOrder?
  1195. while (child.MoveNext()) {
  1196. ((Control)child.Current).RecreateHandle();
  1197. }
  1198. }
  1199. }
  1200. protected virtual void ScaleCore(float dx, float dy) {
  1201. throw new NotImplementedException();
  1202. }
  1203. protected virtual void Select(bool directed, bool forward) {
  1204. throw new NotImplementedException();
  1205. }
  1206. protected virtual void SetClientSizeCore(int x, int y) {
  1207. bounds.Width=x;
  1208. bounds.Height=y;
  1209. XplatUI.SetWindowPos(Handle, bounds);
  1210. }
  1211. protected void SetStyle(ControlStyles flag, bool value) {
  1212. if (value) {
  1213. control_style |= flag;
  1214. } else {
  1215. control_style &= ~flag;
  1216. }
  1217. }
  1218. #endregion // Public Instance Methods
  1219. #region Private Instance Methods
  1220. #endregion // Private Instance Methods
  1221. #region Private Instance Methods
  1222. internal virtual void DoDefaultAction() {
  1223. // Only here to be overriden by our actual controls; this is needed by the accessibility class
  1224. }
  1225. #endregion // Private Instance Methods
  1226. #region OnXXX methods
  1227. protected virtual void OnBackColorChanged(EventArgs e) {
  1228. if (BackColorChanged!=null) BackColorChanged(this, e);
  1229. for (int i=0; i<num_of_children; i++) children[i].OnParentBackColorChanged(e);
  1230. }
  1231. protected virtual void OnBackgroundImageChanged(EventArgs e) {
  1232. if (BackgroundImageChanged!=null) BackgroundImageChanged(this, e);
  1233. for (int i=0; i<num_of_children; i++) children[i].OnParentBackgroundImageChanged(e);
  1234. }
  1235. protected virtual void OnBindingContextChanged(EventArgs e) {
  1236. if (BindingContextChanged!=null) BindingContextChanged(this, e);
  1237. for (int i=0; i<num_of_children; i++) children[i].OnParentBindingContextChanged(e);
  1238. }
  1239. protected virtual void OnCausesValidationChanged(EventArgs e) {
  1240. if (CausesValidationChanged!=null) CausesValidationChanged(this, e);
  1241. }
  1242. protected virtual void OnChangeUICues(UICuesEventArgs e) {
  1243. if (CausesValidationChanged!=null) CausesValidationChanged(this, e);
  1244. }
  1245. protected virtual void OnClick(EventArgs e) {
  1246. if (Click!=null) Click(this, e);
  1247. }
  1248. protected virtual void OnContextMenuChanged(EventArgs e) {
  1249. if (ContextMenuChanged!=null) ContextMenuChanged(this, e);
  1250. }
  1251. protected virtual void OnControlAdded(ControlEventArgs e) {
  1252. if (ControlAdded!=null) ControlAdded(this, e);
  1253. }
  1254. protected virtual void OnControlRemoved(ControlEventArgs e) {
  1255. if (ControlRemoved!=null) ControlRemoved(this, e);
  1256. }
  1257. protected virtual void OnCreateControl() {
  1258. }
  1259. protected virtual void OnCursorChanged(EventArgs e) {
  1260. if (CursorChanged!=null) CursorChanged(this, e);
  1261. }
  1262. protected virtual void OnDockChanged(EventArgs e) {
  1263. if (DockChanged!=null) DockChanged(this, e);
  1264. }
  1265. protected virtual void OnDoubleClick(EventArgs e) {
  1266. if (DoubleClick!=null) DoubleClick(this, e);
  1267. }
  1268. protected virtual void OnDragDrop(DragEventArgs drgevent) {
  1269. if (DragDrop!=null) DragDrop(this, drgevent);
  1270. }
  1271. protected virtual void OnDragEnter(DragEventArgs drgevent) {
  1272. if (DragEnter!=null) DragEnter(this, drgevent);
  1273. }
  1274. protected virtual void OnDragLeave(EventArgs e) {
  1275. if (DragLeave!=null) DragLeave(this, e);
  1276. }
  1277. protected virtual void OnDragOver(DragEventArgs drgevent) {
  1278. if (DragOver!=null) DragOver(this, drgevent);
  1279. }
  1280. protected virtual void OnEnabledChanged(EventArgs e) {
  1281. if (EnabledChanged!=null) EnabledChanged(this, e);
  1282. for (int i=0; i<num_of_children; i++) children[i].OnParentEnabledChanged(e);
  1283. }
  1284. protected virtual void OnEnter(EventArgs e) {
  1285. if (Enter!=null) Enter(this, e);
  1286. }
  1287. protected virtual void OnFontChanged(EventArgs e) {
  1288. if (FontChanged!=null) FontChanged(this, e);
  1289. }
  1290. protected virtual void OnForeColorChanged(EventArgs e) {
  1291. if (ForeColorChanged!=null) ForeColorChanged(this, e);
  1292. for (int i=0; i<num_of_children; i++) children[i].OnParentForeColorChanged(e);
  1293. }
  1294. protected virtual void OnGiveFeedback(GiveFeedbackEventArgs gfbevent) {
  1295. if (GiveFeedback!=null) GiveFeedback(this, gfbevent);
  1296. }
  1297. protected virtual void OnGotFocus(EventArgs e) {
  1298. if (GotFocus!=null) GotFocus(this, e);
  1299. }
  1300. protected virtual void OnHandleCreated(EventArgs e) {
  1301. if (HandleCreated!=null) HandleCreated(this, e);
  1302. }
  1303. protected virtual void OnHandleDestroyed(EventArgs e) {
  1304. if (HandleDestroyed!=null) HandleDestroyed(this, e);
  1305. }
  1306. protected virtual void OnHelpRequested(HelpEventArgs hevent) {
  1307. if (HelpRequested!=null) HelpRequested(this, hevent);
  1308. }
  1309. protected virtual void OnImeModeChanged(EventArgs e) {
  1310. if (ImeModeChanged!=null) ImeModeChanged(this, e);
  1311. }
  1312. protected virtual void OnInvalidated(InvalidateEventArgs e) {
  1313. if (Invalidated!=null) Invalidated(this, e);
  1314. }
  1315. protected virtual void OnKeyDown(KeyEventArgs e) {
  1316. if (KeyDown!=null) KeyDown(this, e);
  1317. }
  1318. protected virtual void OnKeyUp(KeyEventArgs e) {
  1319. if (KeyUp!=null) KeyUp(this, e);
  1320. }
  1321. protected virtual void OnLayout(LayoutEventArgs levent) {
  1322. if (Layout!=null) Layout(this, levent);
  1323. }
  1324. protected virtual void OnLeave(EventArgs e) {
  1325. if (Leave!=null) Leave(this, e);
  1326. }
  1327. protected virtual void OnLocationChanged(EventArgs e) {
  1328. if (LocationChanged!=null) LocationChanged(this, e);
  1329. }
  1330. protected virtual void OnLostFocus(EventArgs e) {
  1331. if (LostFocus!=null) LostFocus(this, e);
  1332. }
  1333. protected virtual void OnMouseDown(MouseEventArgs e) {
  1334. if (MouseDown!=null) MouseDown(this, e);
  1335. }
  1336. protected virtual void OnMouseEnter(EventArgs e) {
  1337. if (MouseEnter!=null) MouseEnter(this, e);
  1338. }
  1339. protected virtual void OnMouseHover(EventArgs e) {
  1340. if (MouseHover!=null) MouseHover(this, e);
  1341. }
  1342. protected virtual void OnMouseLeave(EventArgs e) {
  1343. if (MouseLeave!=null) MouseLeave(this, e);
  1344. }
  1345. protected virtual void OnMouseMove(MouseEventArgs e) {
  1346. if (MouseMove!=null) MouseMove(this, e);
  1347. }
  1348. protected virtual void OnMouseUp(MouseEventArgs e) {
  1349. if (MouseUp!=null) MouseUp(this, e);
  1350. }
  1351. protected virtual void OnMouseWheel(MouseEventArgs e) {
  1352. if (MouseWheel!=null) MouseWheel(this, e);
  1353. }
  1354. protected virtual void OnMove(EventArgs e) {
  1355. if (Move!=null) Move(this, e);
  1356. }
  1357. protected virtual void OnNotifyMessage(Message m) {
  1358. // Override me!
  1359. }
  1360. protected virtual void OnPaint(PaintEventArgs e) {
  1361. if (Paint!=null) Paint(this, e);
  1362. }
  1363. protected virtual void OnPaintBackground(PaintEventArgs pevent) {
  1364. // Override me!
  1365. }
  1366. protected virtual void OnParentBackColorChanged(EventArgs e) {
  1367. if (background_color.IsEmpty && background_image==null) {
  1368. Invalidate();
  1369. OnBackColorChanged(e);
  1370. }
  1371. }
  1372. protected virtual void OnParentBackgroundImageChanged(EventArgs e) {
  1373. if (background_color.IsEmpty && background_image==null) {
  1374. Invalidate();
  1375. OnBackgroundImageChanged(e);
  1376. }
  1377. }
  1378. protected virtual void OnParentBindingContextChanged(EventArgs e) {
  1379. if (binding_context==null) {
  1380. binding_context=Parent.binding_context;
  1381. OnBindingContextChanged(e);
  1382. }
  1383. }
  1384. protected virtual void OnParentChanged(EventArgs e) {
  1385. if (ParentChanged!=null) ParentChanged(this, e);
  1386. }
  1387. protected virtual void OnParentEnabledChanged(EventArgs e) {
  1388. if ((is_enabled && !Parent.is_enabled) || (!is_enabled && Parent.is_enabled)) {
  1389. is_enabled=false;
  1390. Invalidate();
  1391. EnabledChanged(this, e);
  1392. }
  1393. }
  1394. protected virtual void OnParentFontChanged(EventArgs e) {
  1395. if (font==null) {
  1396. Invalidate();
  1397. OnFontChanged(e);
  1398. }
  1399. }
  1400. protected virtual void OnParentForeColorChanged(EventArgs e) {
  1401. if (foreground_color.IsEmpty) {
  1402. Invalidate();
  1403. OnForeColorChanged(e);
  1404. }
  1405. }
  1406. protected virtual void OnParentRightToLeftChanged(EventArgs e) {
  1407. if (right_to_left==RightToLeft.Inherit) {
  1408. Invalidate();
  1409. OnRightToLeftChanged(e);
  1410. }
  1411. }
  1412. protected virtual void OnParentVisibleChanged(EventArgs e) {
  1413. if (is_visible!=Parent.is_visible) {
  1414. is_visible=false;
  1415. Invalidate();
  1416. OnVisibleChanged(e);
  1417. }
  1418. }
  1419. protected virtual void OnQueryContinueDrag(QueryContinueDragEventArgs e) {
  1420. if (QueryContinueDrag!=null) QueryContinueDrag(this, e);
  1421. }
  1422. protected virtual void OnResize(EventArgs e) {
  1423. if (Resize!=null) Resize(this, e);
  1424. }
  1425. protected virtual void OnRightToLeftChanged(EventArgs e) {
  1426. if (RightToLeftChanged!=null) RightToLeftChanged(this, e);
  1427. for (int i=0; i<num_of_children; i++) children[i].OnParentRightToLeftChanged(e);
  1428. }
  1429. protected virtual void OnSizeChanged(EventArgs e) {
  1430. OnResize(e);
  1431. if (SizeChanged!=null) SizeChanged(this, e);
  1432. }
  1433. protected virtual void OnStyleChanged(EventArgs e) {
  1434. if (StyleChanged!=null) StyleChanged(this, e);
  1435. }
  1436. protected virtual void OnSystemColorsChanged(EventArgs e) {
  1437. if (SystemColorsChanged!=null) SystemColorsChanged(this, e);
  1438. }
  1439. protected virtual void OnTabIndexChanged(EventArgs e) {
  1440. if (TabIndexChanged!=null) TabIndexChanged(this, e);
  1441. }
  1442. protected virtual void OnTabStopChanged(EventArgs e) {
  1443. if (TabStopChanged!=null) TabStopChanged(this, e);
  1444. }
  1445. protected virtual void OnTextChanged(EventArgs e) {
  1446. if (TextChanged!=null) TextChanged(this, e);
  1447. }
  1448. protected virtual void OnValidated(EventArgs e) {
  1449. if (Validated!=null) Validated(this, e);
  1450. }
  1451. protected virtual void OnValidating(System.ComponentModel.CancelEventArgs e) {
  1452. if (Validating!=null) Validating(this, e);
  1453. }
  1454. protected virtual void OnVisibleChanged(EventArgs e) {
  1455. if (VisibleChanged!=null) VisibleChanged(this, e);
  1456. }
  1457. #endregion // OnXXX methods
  1458. #region Events
  1459. public event EventHandler BackColorChanged;
  1460. public event EventHandler BackgroundImageChanged;
  1461. public event EventHandler BindingContextChanged;
  1462. public event EventHandler CausesValidationChanged;
  1463. public event UICuesEventHandler ChangeUICues;
  1464. public event EventHandler Click;
  1465. public event EventHandler ContextMenuChanged;
  1466. public event ControlEventHandler ControlAdded;
  1467. public event ControlEventHandler ControlRemoved;
  1468. public event EventHandler CursorChanged;
  1469. public event EventHandler DockChanged;
  1470. public event EventHandler DoubleClick;
  1471. public event DragEventHandler DragDrop;
  1472. public event DragEventHandler DragEnter;
  1473. public event EventHandler DragLeave;
  1474. public event DragEventHandler DragOver;
  1475. public event EventHandler EnabledChanged;
  1476. public event EventHandler Enter;
  1477. public event EventHandler FontChanged;
  1478. public event EventHandler ForeColorChanged;
  1479. public event GiveFeedbackEventHandler GiveFeedback;
  1480. public event EventHandler GotFocus;
  1481. public event EventHandler HandleCreated;
  1482. public event EventHandler HandleDestroyed;
  1483. public event HelpEventHandler HelpRequested;
  1484. public event EventHandler ImeModeChanged;
  1485. public event InvalidateEventHandler Invalidated;
  1486. public event KeyEventHandler KeyDown;
  1487. public event KeyPressEventHandler KeyPress;
  1488. public event KeyEventHandler KeyUp;
  1489. public event LayoutEventHandler Layout;
  1490. public event EventHandler Leave;
  1491. public event EventHandler LocationChanged;
  1492. public event EventHandler LostFocus;
  1493. public event MouseEventHandler MouseDown;
  1494. public event EventHandler MouseEnter;
  1495. public event EventHandler MouseHover;
  1496. public event EventHandler MouseLeave;
  1497. public event MouseEventHandler MouseMove;
  1498. public event MouseEventHandler MouseUp;
  1499. public event MouseEventHandler MouseWheel;
  1500. public event EventHandler Move;
  1501. public event PaintEventHandler Paint;
  1502. public event EventHandler ParentChanged;
  1503. public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp;
  1504. public event QueryContinueDragEventHandler QueryContinueDrag;
  1505. public event EventHandler Resize;
  1506. public event EventHandler RightToLeftChanged;
  1507. public event EventHandler SizeChanged;
  1508. public event EventHandler StyleChanged;
  1509. public event EventHandler SystemColorsChanged;
  1510. public event EventHandler TabIndexChanged;
  1511. public event EventHandler TabStopChanged;
  1512. public event EventHandler TextChanged;
  1513. public event EventHandler Validated;
  1514. public event CancelEventHandler Validating;
  1515. public event EventHandler VisibleChanged;
  1516. #endregion // Events
  1517. #region Private Methods
  1518. internal static int LowOrder (int param)
  1519. {
  1520. return (param & 0xffff);
  1521. }
  1522. internal static int HighOrder (int param)
  1523. {
  1524. return (param >> 16);
  1525. }
  1526. internal static MouseButtons FromParamToMouseButtons (int param)
  1527. {
  1528. MouseButtons buttons = MouseButtons.None;
  1529. if ((param & (int) MsgButtons.MK_LBUTTON) != 0)
  1530. buttons |= MouseButtons.Left;
  1531. if ((param & (int) MsgButtons.MK_MBUTTON) != 0)
  1532. buttons |= MouseButtons.Middle;
  1533. if ((param & (int) MsgButtons.MK_RBUTTON) != 0)
  1534. buttons |= MouseButtons.Right;
  1535. return buttons;
  1536. }
  1537. #endregion
  1538. }
  1539. }