PageRenderTime 38ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 1ms

/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Control.cs

https://bitbucket.org/danipen/mono
C# | 6728 lines | 5302 code | 1158 blank | 268 comment | 1215 complexity | 78e5bdf745b8d860b07ccbff92d06a4c MD5 | raw file
Possible License(s): Unlicense, Apache-2.0, LGPL-2.0, MPL-2.0-no-copyleft-exception, CC-BY-SA-3.0, GPL-2.0
  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-2006 Novell, Inc.
  21. //
  22. // Authors:
  23. // Peter Bartok pbartok@novell.com
  24. //
  25. // Partially based on work by:
  26. // Aleksey Ryabchuk ryabchuk@yahoo.com
  27. // Alexandre Pigolkine pigolkine@gmx.de
  28. // Dennis Hayes dennish@raytek.com
  29. // Jaak Simm jaaksimm@firm.ee
  30. // John Sohn jsohn@columbus.rr.com
  31. //
  32. #undef DebugRecreate
  33. #undef DebugFocus
  34. #undef DebugMessages
  35. using System;
  36. using System.ComponentModel;
  37. using System.ComponentModel.Design;
  38. using System.ComponentModel.Design.Serialization;
  39. using System.Collections;
  40. using System.Diagnostics;
  41. using System.Drawing;
  42. using System.Drawing.Drawing2D;
  43. using System.Reflection;
  44. using System.Runtime.InteropServices;
  45. using System.Security;
  46. using System.Threading;
  47. namespace System.Windows.Forms
  48. {
  49. [ComVisible(true)]
  50. [ClassInterface (ClassInterfaceType.AutoDispatch)]
  51. [Designer("System.Windows.Forms.Design.ControlDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
  52. [DefaultProperty("Text")]
  53. [DefaultEvent("Click")]
  54. [DesignerSerializer("System.Windows.Forms.Design.ControlCodeDomSerializer, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
  55. [ToolboxItemFilter("System.Windows.Forms")]
  56. public class Control : Component, ISynchronizeInvoke, IWin32Window
  57. , IBindableComponent, IDropTarget, IBounds
  58. {
  59. #region Local Variables
  60. // Basic
  61. internal Rectangle bounds; // bounding rectangle for control (client area + decorations)
  62. Rectangle explicit_bounds; // explicitly set bounds
  63. internal object creator_thread; // thread that created the control
  64. internal ControlNativeWindow window; // object for native window handle
  65. private IWindowTarget window_target;
  66. string name; // for object naming
  67. // State
  68. bool is_created; // true if OnCreateControl has been sent
  69. internal bool has_focus; // true if control has focus
  70. internal bool is_visible; // true if control is visible
  71. internal bool is_entered; // is the mouse inside the control?
  72. internal bool is_enabled; // true if control is enabled (usable/not grayed out)
  73. bool is_accessible; // true if the control is visible to accessibility applications
  74. bool is_captured; // tracks if the control has captured the mouse
  75. internal bool is_toplevel; // tracks if the control is a toplevel window
  76. bool is_recreating; // tracks if the handle for the control is being recreated
  77. bool causes_validation; // tracks if validation is executed on changes
  78. bool is_focusing; // tracks if Focus has been called on the control and has not yet finished
  79. int tab_index; // position in tab order of siblings
  80. bool tab_stop; // is the control a tab stop?
  81. bool is_disposed; // has the window already been disposed?
  82. bool is_disposing; // is the window getting disposed?
  83. Size client_size; // size of the client area (window excluding decorations)
  84. Rectangle client_rect; // rectangle with the client area (window excluding decorations)
  85. ControlStyles control_style; // rather win32-specific, style bits for control
  86. ImeMode ime_mode;
  87. object control_tag; // object that contains data about our control
  88. internal int mouse_clicks; // Counter for mouse clicks
  89. Cursor cursor; // Cursor for the window
  90. internal bool allow_drop; // true if the control accepts droping objects on it
  91. Region clip_region; // User-specified clip region for the window
  92. // Visuals
  93. internal Color foreground_color; // foreground color for control
  94. internal Color background_color; // background color for control
  95. Image background_image; // background image for control
  96. internal Font font; // font for control
  97. string text; // window/title text for control
  98. internal BorderStyle border_style; // Border style of control
  99. bool show_keyboard_cues; // Current keyboard cues
  100. internal bool show_focus_cues; // Current focus cues
  101. internal bool force_double_buffer; // Always doublebuffer regardless of ControlStyle
  102. // Layout
  103. internal enum LayoutType {
  104. Anchor,
  105. Dock
  106. }
  107. Layout.LayoutEngine layout_engine;
  108. internal int layout_suspended;
  109. bool layout_pending; // true if our parent needs to re-layout us
  110. internal AnchorStyles anchor_style; // anchoring requirements for our control
  111. internal DockStyle dock_style; // docking requirements for our control
  112. LayoutType layout_type;
  113. private bool recalculate_distances = true; // Delay anchor calculations
  114. // Please leave the next 2 as internal until DefaultLayout (2.0) is rewritten
  115. internal int dist_right; // distance to the right border of the parent
  116. internal int dist_bottom; // distance to the bottom border of the parent
  117. // to be categorized...
  118. ControlCollection child_controls; // our children
  119. Control parent; // our parent control
  120. BindingContext binding_context;
  121. RightToLeft right_to_left; // drawing direction for control
  122. ContextMenu context_menu; // Context menu associated with the control
  123. internal bool use_compatible_text_rendering;
  124. private bool use_wait_cursor;
  125. //accessibility
  126. string accessible_name;
  127. string accessible_description;
  128. string accessible_default_action;
  129. AccessibleRole accessible_role = AccessibleRole.Default;
  130. AccessibleObject accessibility_object; // object that contains accessibility information about our control
  131. // double buffering
  132. DoubleBuffer backbuffer;
  133. ControlBindingsCollection data_bindings;
  134. static bool verify_thread_handle;
  135. Padding padding;
  136. ImageLayout backgroundimage_layout;
  137. Size maximum_size;
  138. Size minimum_size;
  139. Padding margin;
  140. private ContextMenuStrip context_menu_strip;
  141. private bool nested_layout = false;
  142. Point auto_scroll_offset;
  143. private AutoSizeMode auto_size_mode;
  144. private bool suppressing_key_press;
  145. #endregion // Local Variables
  146. #region Private Classes
  147. // This helper class allows us to dispatch messages to Control.WndProc
  148. internal class ControlNativeWindow : NativeWindow {
  149. private Control owner;
  150. public ControlNativeWindow(Control control) : base() {
  151. this.owner=control;
  152. }
  153. public Control Owner {
  154. get {
  155. return owner;
  156. }
  157. }
  158. protected override void OnHandleChange()
  159. {
  160. this.owner.WindowTarget.OnHandleChange(this.owner.Handle);
  161. }
  162. static internal Control ControlFromHandle(IntPtr hWnd) {
  163. ControlNativeWindow window;
  164. window = (ControlNativeWindow)NativeWindow.FromHandle (hWnd);
  165. if (window != null) {
  166. return window.owner;
  167. }
  168. return null;
  169. }
  170. static internal Control ControlFromChildHandle (IntPtr handle) {
  171. ControlNativeWindow window;
  172. Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
  173. while (hwnd != null) {
  174. window = (ControlNativeWindow)NativeWindow.FromHandle (handle);
  175. if (window != null) {
  176. return window.owner;
  177. }
  178. hwnd = hwnd.Parent;
  179. }
  180. return null;
  181. }
  182. protected override void WndProc(ref Message m) {
  183. owner.WindowTarget.OnMessage(ref m);
  184. }
  185. }
  186. private class ControlWindowTarget : IWindowTarget
  187. {
  188. private Control control;
  189. public ControlWindowTarget(Control control)
  190. {
  191. this.control = control;
  192. }
  193. public void OnHandleChange(IntPtr newHandle)
  194. {
  195. }
  196. public void OnMessage(ref Message m)
  197. {
  198. control.WndProc(ref m);
  199. }
  200. }
  201. #endregion
  202. #region Public Classes
  203. [ComVisible(true)]
  204. public class ControlAccessibleObject : AccessibleObject {
  205. IntPtr handle;
  206. #region ControlAccessibleObject Constructors
  207. public ControlAccessibleObject(Control ownerControl)
  208. : base (ownerControl)
  209. {
  210. if (ownerControl == null)
  211. throw new ArgumentNullException ("owner");
  212. handle = ownerControl.Handle;
  213. }
  214. #endregion // ControlAccessibleObject Constructors
  215. #region ControlAccessibleObject Public Instance Properties
  216. public override string DefaultAction {
  217. get {
  218. return base.DefaultAction;
  219. }
  220. }
  221. public override string Description {
  222. get {
  223. return base.Description;
  224. }
  225. }
  226. public IntPtr Handle {
  227. get {
  228. return handle;
  229. }
  230. set {
  231. // We don't want to let them set it
  232. }
  233. }
  234. public override string Help {
  235. get {
  236. return base.Help;
  237. }
  238. }
  239. public override string KeyboardShortcut {
  240. get {
  241. return base.KeyboardShortcut;
  242. }
  243. }
  244. public override string Name {
  245. get {
  246. return base.Name;
  247. }
  248. set {
  249. base.Name = value;
  250. }
  251. }
  252. public Control Owner {
  253. get {
  254. return base.owner;
  255. }
  256. }
  257. public override AccessibleObject Parent {
  258. get {
  259. return base.Parent;
  260. }
  261. }
  262. public override AccessibleRole Role {
  263. get {
  264. return base.Role;
  265. }
  266. }
  267. #endregion // ControlAccessibleObject Public Instance Properties
  268. #region ControlAccessibleObject Public Instance Methods
  269. public override int GetHelpTopic (out string fileName)
  270. {
  271. return base.GetHelpTopic (out fileName);
  272. }
  273. [MonoTODO ("Stub, does nothing")]
  274. public void NotifyClients (AccessibleEvents accEvent)
  275. {
  276. }
  277. [MonoTODO ("Stub, does nothing")]
  278. public void NotifyClients (AccessibleEvents accEvent, int childID)
  279. {
  280. }
  281. [MonoTODO ("Stub, does nothing")]
  282. public void NotifyClients (AccessibleEvents accEvent, int objectID, int childID)
  283. {
  284. }
  285. public override string ToString() {
  286. return "ControlAccessibleObject: Owner = " + owner.ToString() + ", Text: " + owner.text;
  287. }
  288. #endregion // ControlAccessibleObject Public Instance Methods
  289. }
  290. private class DoubleBuffer : IDisposable
  291. {
  292. public Region InvalidRegion;
  293. private Stack real_graphics;
  294. private object back_buffer;
  295. private Control parent;
  296. private bool pending_disposal;
  297. public DoubleBuffer (Control parent) {
  298. this.parent = parent;
  299. real_graphics = new Stack ();
  300. int width = parent.Width;
  301. int height = parent.Height;
  302. if (width < 1) width = 1;
  303. if (height < 1) height = 1;
  304. XplatUI.CreateOffscreenDrawable (parent.Handle, width, height, out back_buffer);
  305. Invalidate ();
  306. }
  307. public void Blit (PaintEventArgs pe) {
  308. Graphics buffered_graphics;
  309. buffered_graphics = XplatUI.GetOffscreenGraphics (back_buffer);
  310. XplatUI.BlitFromOffscreen (parent.Handle, pe.Graphics, back_buffer, buffered_graphics, pe.ClipRectangle);
  311. buffered_graphics.Dispose ();
  312. }
  313. public void Start (PaintEventArgs pe) {
  314. // We need to get the graphics for every paint.
  315. real_graphics.Push(pe.SetGraphics (XplatUI.GetOffscreenGraphics (back_buffer)));
  316. }
  317. public void End (PaintEventArgs pe) {
  318. Graphics buffered_graphics;
  319. buffered_graphics = pe.SetGraphics ((Graphics) real_graphics.Pop ());
  320. if (pending_disposal)
  321. Dispose ();
  322. else {
  323. XplatUI.BlitFromOffscreen (parent.Handle, pe.Graphics, back_buffer, buffered_graphics, pe.ClipRectangle);
  324. InvalidRegion.Exclude (pe.ClipRectangle);
  325. }
  326. buffered_graphics.Dispose ();
  327. }
  328. public void Invalidate ()
  329. {
  330. if (InvalidRegion != null)
  331. InvalidRegion.Dispose ();
  332. InvalidRegion = new Region (parent.ClientRectangle);
  333. }
  334. public void Dispose () {
  335. if (real_graphics.Count > 0) {
  336. pending_disposal = true;
  337. return;
  338. }
  339. XplatUI.DestroyOffscreenDrawable (back_buffer);
  340. if (InvalidRegion != null)
  341. InvalidRegion.Dispose ();
  342. InvalidRegion = null;
  343. back_buffer = null;
  344. GC.SuppressFinalize (this);
  345. }
  346. #region IDisposable Members
  347. void IDisposable.Dispose () {
  348. Dispose ();
  349. }
  350. #endregion
  351. ~DoubleBuffer () {
  352. Dispose ();
  353. }
  354. }
  355. [ListBindable (false)]
  356. [ComVisible (false)]
  357. public class ControlCollection : Layout.ArrangedElementCollection, IList, ICollection, ICloneable, IEnumerable {
  358. #region ControlCollection Local Variables
  359. ArrayList impl_list;
  360. Control [] all_controls;
  361. Control owner;
  362. #endregion // ControlCollection Local Variables
  363. #region ControlCollection Public Constructor
  364. public ControlCollection (Control owner)
  365. {
  366. this.owner = owner;
  367. }
  368. #endregion
  369. #region ControlCollection Public Instance Properties
  370. public Control Owner {
  371. get { return this.owner; }
  372. }
  373. public virtual Control this[string key] {
  374. get {
  375. int index = IndexOfKey (key);
  376. if (index >= 0)
  377. return this[index];
  378. return null;
  379. }
  380. }
  381. new public virtual Control this[int index] {
  382. get {
  383. if (index < 0 || index >= list.Count) {
  384. throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
  385. }
  386. return (Control)list[index];
  387. }
  388. }
  389. #endregion // ControlCollection Public Instance Properties
  390. #region ControlCollection Instance Methods
  391. public virtual void Add (Control value)
  392. {
  393. if (value == null)
  394. return;
  395. Form form_value = value as Form;
  396. Form form_owner = owner as Form;
  397. bool owner_permits_toplevels = (owner is MdiClient) || (form_owner != null && form_owner.IsMdiContainer);
  398. bool child_is_toplevel = value.GetTopLevel();
  399. bool child_is_mdichild = form_value != null && form_value.IsMdiChild;
  400. if (child_is_toplevel && !(owner_permits_toplevels && child_is_mdichild))
  401. throw new ArgumentException("Cannot add a top level control to a control.", "value");
  402. if (child_is_mdichild && form_value.MdiParent != null && form_value.MdiParent != owner && form_value.MdiParent != owner.Parent) {
  403. throw new ArgumentException ("Form cannot be added to the Controls collection that has a valid MDI parent.", "value");
  404. }
  405. value.recalculate_distances = true;
  406. if (Contains (value)) {
  407. owner.PerformLayout();
  408. return;
  409. }
  410. if (value.tab_index == -1) {
  411. int end;
  412. int index;
  413. int use;
  414. use = 0;
  415. end = owner.child_controls.Count;
  416. for (int i = 0; i < end; i++) {
  417. index = owner.child_controls[i].tab_index;
  418. if (index >= use) {
  419. use = index + 1;
  420. }
  421. }
  422. value.tab_index = use;
  423. }
  424. if (value.parent != null) {
  425. value.parent.Controls.Remove(value);
  426. }
  427. all_controls = null;
  428. list.Add (value);
  429. value.ChangeParent(owner);
  430. value.InitLayout();
  431. if (owner.Visible)
  432. owner.UpdateChildrenZOrder();
  433. owner.PerformLayout(value, "Parent");
  434. owner.OnControlAdded(new ControlEventArgs(value));
  435. }
  436. internal void AddToList (Control c)
  437. {
  438. all_controls = null;
  439. list.Add (c);
  440. }
  441. internal virtual void AddImplicit (Control control)
  442. {
  443. if (impl_list == null)
  444. impl_list = new ArrayList ();
  445. if (AllContains (control)) {
  446. owner.PerformLayout ();
  447. return;
  448. }
  449. if (control.parent != null) {
  450. control.parent.Controls.Remove(control);
  451. }
  452. all_controls = null;
  453. impl_list.Add (control);
  454. control.ChangeParent (owner);
  455. control.InitLayout ();
  456. if (owner.Visible)
  457. owner.UpdateChildrenZOrder ();
  458. // If we are adding a new control that isn't
  459. // visible, don't trigger a layout
  460. if (control.VisibleInternal)
  461. owner.PerformLayout (control, "Parent");
  462. }
  463. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  464. public virtual void AddRange (Control[] controls)
  465. {
  466. if (controls == null)
  467. throw new ArgumentNullException ("controls");
  468. owner.SuspendLayout ();
  469. try {
  470. for (int i = 0; i < controls.Length; i++)
  471. Add (controls[i]);
  472. } finally {
  473. owner.ResumeLayout ();
  474. }
  475. }
  476. internal virtual void AddRangeImplicit (Control [] controls)
  477. {
  478. if (controls == null)
  479. throw new ArgumentNullException ("controls");
  480. owner.SuspendLayout ();
  481. try {
  482. for (int i = 0; i < controls.Length; i++)
  483. AddImplicit (controls [i]);
  484. } finally {
  485. owner.ResumeLayout (false);
  486. }
  487. }
  488. new
  489. public virtual void Clear ()
  490. {
  491. all_controls = null;
  492. // MS sends remove events in reverse order
  493. while (list.Count > 0) {
  494. Remove((Control)list[list.Count - 1]);
  495. }
  496. }
  497. internal virtual void ClearImplicit ()
  498. {
  499. if (impl_list == null)
  500. return;
  501. all_controls = null;
  502. impl_list.Clear ();
  503. }
  504. public bool Contains (Control control)
  505. {
  506. return list.Contains (control);
  507. }
  508. internal bool ImplicitContains (Control value) {
  509. if (impl_list == null)
  510. return false;
  511. return impl_list.Contains (value);
  512. }
  513. internal bool AllContains (Control value) {
  514. return Contains (value) || ImplicitContains (value);
  515. }
  516. public virtual bool ContainsKey (string key)
  517. {
  518. return IndexOfKey (key) >= 0;
  519. }
  520. // LAMESPEC: MSDN says AE, MS implementation throws ANE
  521. public Control[] Find (string key, bool searchAllChildren)
  522. {
  523. if (string.IsNullOrEmpty (key))
  524. throw new ArgumentNullException ("key");
  525. ArrayList al = new ArrayList ();
  526. foreach (Control c in list) {
  527. if (c.Name.Equals (key, StringComparison.CurrentCultureIgnoreCase))
  528. al.Add (c);
  529. if (searchAllChildren)
  530. al.AddRange (c.Controls.Find (key, true));
  531. }
  532. return (Control[])al.ToArray (typeof (Control));
  533. }
  534. public int GetChildIndex(Control child) {
  535. return GetChildIndex(child, false);
  536. }
  537. public virtual int GetChildIndex(Control child, bool throwException) {
  538. int index;
  539. index=list.IndexOf(child);
  540. if (index==-1 && throwException) {
  541. throw new ArgumentException("Not a child control", "child");
  542. }
  543. return index;
  544. }
  545. public override IEnumerator
  546. GetEnumerator () {
  547. return new ControlCollectionEnumerator (list);
  548. }
  549. internal IEnumerator GetAllEnumerator () {
  550. Control [] res = GetAllControls ();
  551. return res.GetEnumerator ();
  552. }
  553. internal ArrayList ImplicitControls {
  554. get { return impl_list; }
  555. }
  556. internal Control [] GetAllControls () {
  557. if (all_controls != null)
  558. return all_controls;
  559. if (impl_list == null) {
  560. all_controls = (Control []) list.ToArray (typeof (Control));
  561. return all_controls;
  562. }
  563. all_controls = new Control [list.Count + impl_list.Count];
  564. impl_list.CopyTo (all_controls);
  565. list.CopyTo (all_controls, impl_list.Count);
  566. return all_controls;
  567. }
  568. public int IndexOf (Control control)
  569. {
  570. return list.IndexOf (control);
  571. }
  572. public virtual int IndexOfKey (string key)
  573. {
  574. if (string.IsNullOrEmpty (key))
  575. return -1;
  576. for (int i = 0; i < list.Count; i++)
  577. if (((Control)list[i]).Name.Equals (key, StringComparison.CurrentCultureIgnoreCase))
  578. return i;
  579. return -1;
  580. }
  581. public virtual void Remove (Control value)
  582. {
  583. if (value == null)
  584. return;
  585. all_controls = null;
  586. list.Remove(value);
  587. owner.PerformLayout(value, "Parent");
  588. owner.OnControlRemoved(new ControlEventArgs(value));
  589. ContainerControl container = owner.InternalGetContainerControl ();
  590. if (container != null) {
  591. // Inform any container controls about the loss of a child control
  592. // so that they can update their active control
  593. container.ChildControlRemoved (value);
  594. }
  595. value.ChangeParent(null);
  596. owner.UpdateChildrenZOrder();
  597. }
  598. internal virtual void RemoveImplicit (Control control)
  599. {
  600. if (impl_list != null) {
  601. all_controls = null;
  602. impl_list.Remove (control);
  603. owner.PerformLayout (control, "Parent");
  604. owner.OnControlRemoved (new ControlEventArgs (control));
  605. }
  606. control.ChangeParent (null);
  607. owner.UpdateChildrenZOrder ();
  608. }
  609. public void RemoveAt (int index)
  610. {
  611. if (index < 0 || index >= list.Count)
  612. throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
  613. Remove ((Control) list [index]);
  614. }
  615. public virtual void RemoveByKey (string key)
  616. {
  617. int index = IndexOfKey (key);
  618. if (index >= 0)
  619. RemoveAt (index);
  620. }
  621. public virtual void SetChildIndex(Control child, int newIndex)
  622. {
  623. if (child == null)
  624. throw new ArgumentNullException ("child");
  625. int old_index;
  626. old_index=list.IndexOf(child);
  627. if (old_index==-1) {
  628. throw new ArgumentException("Not a child control", "child");
  629. }
  630. if (old_index==newIndex) {
  631. return;
  632. }
  633. all_controls = null;
  634. list.RemoveAt(old_index);
  635. if (newIndex>list.Count) {
  636. list.Add(child);
  637. } else {
  638. list.Insert(newIndex, child);
  639. }
  640. child.UpdateZOrder();
  641. owner.PerformLayout();
  642. }
  643. #endregion // ControlCollection Private Instance Methods
  644. #region ControlCollection Interface Properties
  645. #endregion // ControlCollection Interface Properties
  646. #region ControlCollection Interface Methods
  647. int IList.Add (object control)
  648. {
  649. if (!(control is Control))
  650. throw new ArgumentException ("Object of type Control required", "control");
  651. if (control == null)
  652. throw new ArgumentException ("control", "Cannot add null controls");
  653. this.Add ((Control)control);
  654. return this.IndexOf ((Control)control);
  655. }
  656. void IList.Remove (object control)
  657. {
  658. if (!(control is Control))
  659. throw new ArgumentException ("Object of type Control required", "control");
  660. this.Remove ((Control)control);
  661. }
  662. Object ICloneable.Clone ()
  663. {
  664. ControlCollection clone = new ControlCollection (this.owner);
  665. clone.list = (ArrayList)list.Clone (); // FIXME: Do we need this?
  666. return clone;
  667. }
  668. #endregion // ControlCollection Interface Methods
  669. internal class ControlCollectionEnumerator : IEnumerator
  670. {
  671. private ArrayList list;
  672. int position = -1;
  673. public ControlCollectionEnumerator (ArrayList collection)
  674. {
  675. list = collection;
  676. }
  677. #region IEnumerator Members
  678. public object Current {
  679. get {
  680. try {
  681. return list[position];
  682. } catch (IndexOutOfRangeException) {
  683. throw new InvalidOperationException ();
  684. }
  685. }
  686. }
  687. public bool MoveNext ()
  688. {
  689. position++;
  690. return (position < list.Count);
  691. }
  692. public void Reset ()
  693. {
  694. position = -1;
  695. }
  696. #endregion
  697. }
  698. }
  699. #endregion // ControlCollection Class
  700. #region Public Constructors
  701. public Control ()
  702. {
  703. if (WindowsFormsSynchronizationContext.AutoInstall)
  704. if (!(SynchronizationContext.Current is WindowsFormsSynchronizationContext))
  705. SynchronizationContext.SetSynchronizationContext (new WindowsFormsSynchronizationContext ());
  706. layout_type = LayoutType.Anchor;
  707. anchor_style = AnchorStyles.Top | AnchorStyles.Left;
  708. is_created = false;
  709. is_visible = true;
  710. is_captured = false;
  711. is_disposed = false;
  712. is_enabled = true;
  713. is_entered = false;
  714. layout_pending = false;
  715. is_toplevel = false;
  716. causes_validation = true;
  717. has_focus = false;
  718. layout_suspended = 0;
  719. mouse_clicks = 1;
  720. tab_index = -1;
  721. cursor = null;
  722. right_to_left = RightToLeft.Inherit;
  723. border_style = BorderStyle.None;
  724. background_color = Color.Empty;
  725. dist_right = 0;
  726. dist_bottom = 0;
  727. tab_stop = true;
  728. ime_mode = ImeMode.Inherit;
  729. use_compatible_text_rendering = true;
  730. show_keyboard_cues = false;
  731. show_focus_cues = SystemInformation.MenuAccessKeysUnderlined;
  732. use_wait_cursor = false;
  733. backgroundimage_layout = ImageLayout.Tile;
  734. use_compatible_text_rendering = Application.use_compatible_text_rendering;
  735. padding = this.DefaultPadding;
  736. maximum_size = new Size();
  737. minimum_size = new Size();
  738. margin = this.DefaultMargin;
  739. auto_size_mode = AutoSizeMode.GrowOnly;
  740. control_style = ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint |
  741. ControlStyles.Selectable | ControlStyles.StandardClick |
  742. ControlStyles.StandardDoubleClick;
  743. control_style |= ControlStyles.UseTextForAccessibility;
  744. parent = null;
  745. background_image = null;
  746. text = string.Empty;
  747. name = string.Empty;
  748. window_target = new ControlWindowTarget(this);
  749. window = new ControlNativeWindow(this);
  750. child_controls = CreateControlsInstance();
  751. bounds.Size = DefaultSize;
  752. client_size = ClientSizeFromSize (bounds.Size);
  753. client_rect = new Rectangle (Point.Empty, client_size);
  754. explicit_bounds = bounds;
  755. }
  756. public Control (Control parent, string text) : this()
  757. {
  758. Text=text;
  759. Parent=parent;
  760. }
  761. public Control (Control parent, string text, int left, int top, int width, int height) : this()
  762. {
  763. Parent=parent;
  764. SetBounds(left, top, width, height, BoundsSpecified.All);
  765. Text=text;
  766. }
  767. public Control (string text) : this()
  768. {
  769. Text=text;
  770. }
  771. public Control (string text, int left, int top, int width, int height) : this()
  772. {
  773. SetBounds(left, top, width, height, BoundsSpecified.All);
  774. Text=text;
  775. }
  776. private delegate void RemoveDelegate(object c);
  777. protected override void Dispose (bool disposing)
  778. {
  779. if (!is_disposed && disposing) {
  780. is_disposing = true;
  781. Capture = false;
  782. DisposeBackBuffer ();
  783. if (this.InvokeRequired) {
  784. if (Application.MessageLoop && IsHandleCreated) {
  785. this.BeginInvokeInternal(new MethodInvoker(DestroyHandle), null);
  786. }
  787. } else {
  788. DestroyHandle();
  789. }
  790. if (parent != null)
  791. parent.Controls.Remove(this);
  792. Control [] children = child_controls.GetAllControls ();
  793. for (int i=0; i<children.Length; i++) {
  794. children[i].parent = null; // Need to set to null or our child will try and remove from ourselves and crash
  795. children[i].Dispose();
  796. }
  797. }
  798. is_disposed = true;
  799. base.Dispose(disposing);
  800. }
  801. #endregion // Public Constructors
  802. #region Internal Properties
  803. internal Rectangle PaddingClientRectangle
  804. {
  805. get {
  806. return new Rectangle (
  807. ClientRectangle.Left + padding.Left,
  808. ClientRectangle.Top + padding.Top,
  809. ClientRectangle.Width - padding.Horizontal,
  810. ClientRectangle.Height - padding.Vertical);
  811. }
  812. }
  813. private MenuTracker active_tracker;
  814. internal MenuTracker ActiveTracker {
  815. get { return active_tracker; }
  816. set {
  817. if (value == active_tracker)
  818. return;
  819. Capture = value != null;
  820. active_tracker = value;
  821. }
  822. }
  823. // Control is currently selected, like Focused, except maintains state
  824. // when Form loses focus
  825. internal bool InternalSelected {
  826. get {
  827. IContainerControl container;
  828. container = GetContainerControl();
  829. if (container != null && container.ActiveControl == this)
  830. return true;
  831. return false;
  832. }
  833. }
  834. // Looks for focus in child controls
  835. // and also in the implicit ones
  836. internal bool InternalContainsFocus {
  837. get {
  838. IntPtr focused_window;
  839. focused_window = XplatUI.GetFocus();
  840. if (IsHandleCreated) {
  841. if (focused_window == Handle)
  842. return true;
  843. foreach (Control child_control in child_controls.GetAllControls ())
  844. if (child_control.InternalContainsFocus)
  845. return true;
  846. }
  847. return false;
  848. }
  849. }
  850. // Mouse is currently within the control's bounds
  851. internal bool Entered {
  852. get { return this.is_entered; }
  853. }
  854. internal bool VisibleInternal {
  855. get { return is_visible; }
  856. }
  857. internal LayoutType ControlLayoutType {
  858. get { return layout_type; }
  859. }
  860. internal BorderStyle InternalBorderStyle {
  861. get {
  862. return border_style;
  863. }
  864. set {
  865. if (!Enum.IsDefined (typeof (BorderStyle), value))
  866. throw new InvalidEnumArgumentException (string.Format("Enum argument value '{0}' is not valid for BorderStyle", value));
  867. if (border_style != value) {
  868. border_style = value;
  869. if (IsHandleCreated) {
  870. XplatUI.SetBorderStyle (window.Handle, (FormBorderStyle)border_style);
  871. RecreateHandle ();
  872. Refresh ();
  873. } else
  874. client_size = ClientSizeFromSize (bounds.Size);
  875. }
  876. }
  877. }
  878. internal Size InternalClientSize { set { this.client_size = value; } }
  879. internal virtual bool ActivateOnShow { get { return true; } }
  880. internal Rectangle ExplicitBounds { get { return this.explicit_bounds; } set { this.explicit_bounds = value; } }
  881. internal bool ValidationFailed {
  882. get {
  883. ContainerControl c = InternalGetContainerControl ();
  884. if (c != null)
  885. return c.validation_failed;
  886. return false;
  887. }
  888. set {
  889. ContainerControl c = InternalGetContainerControl ();
  890. if (c != null)
  891. c.validation_failed = value;
  892. }
  893. }
  894. #endregion // Internal Properties
  895. #region Private & Internal Methods
  896. void IDropTarget.OnDragDrop (DragEventArgs drgEvent)
  897. {
  898. OnDragDrop (drgEvent);
  899. }
  900. void IDropTarget.OnDragEnter (DragEventArgs drgEvent)
  901. {
  902. OnDragEnter (drgEvent);
  903. }
  904. void IDropTarget.OnDragLeave (EventArgs e)
  905. {
  906. OnDragLeave (e);
  907. }
  908. void IDropTarget.OnDragOver (DragEventArgs drgEvent)
  909. {
  910. OnDragOver (drgEvent);
  911. }
  912. internal IAsyncResult BeginInvokeInternal (Delegate method, object [] args) {
  913. return BeginInvokeInternal (method, args, FindControlToInvokeOn ());
  914. }
  915. internal IAsyncResult BeginInvokeInternal (Delegate method, object [] args, Control control) {
  916. AsyncMethodResult result;
  917. AsyncMethodData data;
  918. result = new AsyncMethodResult ();
  919. data = new AsyncMethodData ();
  920. data.Handle = control.GetInvokableHandle ();
  921. data.Method = method;
  922. data.Args = args;
  923. data.Result = result;
  924. if (!ExecutionContext.IsFlowSuppressed ()) {
  925. data.Context = ExecutionContext.Capture ();
  926. }
  927. XplatUI.SendAsyncMethod (data);
  928. return result;
  929. }
  930. // The CheckForIllegalCrossThreadCalls in the #if 2.0 of
  931. // Control.Handle throws an exception when we are trying
  932. // to get the Handle to properly invoke on. This avoids that.
  933. private IntPtr GetInvokableHandle ()
  934. {
  935. if (!IsHandleCreated)
  936. CreateHandle ();
  937. return window.Handle;
  938. }
  939. internal void PointToClient (ref int x, ref int y) {
  940. XplatUI.ScreenToClient (Handle, ref x, ref y);
  941. }
  942. internal void PointToScreen (ref int x, ref int y) {
  943. XplatUI.ClientToScreen (Handle, ref x, ref y);
  944. }
  945. internal bool IsRecreating {
  946. get {
  947. return is_recreating;
  948. }
  949. }
  950. internal Graphics DeviceContext {
  951. get { return Hwnd.GraphicsContext; }
  952. }
  953. // An internal way to have a fixed height
  954. // Basically for DataTimePicker 2.0
  955. internal virtual int OverrideHeight (int height)
  956. {
  957. return height;
  958. }
  959. private void ProcessActiveTracker (ref Message m)
  960. {
  961. bool is_up = ((Msg) m.Msg == Msg.WM_LBUTTONUP) ||
  962. ((Msg) m.Msg == Msg.WM_RBUTTONUP);
  963. MouseButtons mb = FromParamToMouseButtons ((int) m.WParam.ToInt32 ());
  964. // We add in the button that was released (not sent in WParam)
  965. if (is_up) {
  966. switch ((Msg)m.Msg) {
  967. case Msg.WM_LBUTTONUP:
  968. mb |= MouseButtons.Left;
  969. break;
  970. case Msg.WM_RBUTTONUP:
  971. mb |= MouseButtons.Right;
  972. break;
  973. }
  974. }
  975. MouseEventArgs args = new MouseEventArgs (
  976. mb,
  977. mouse_clicks,
  978. Control.MousePosition.X,
  979. Control.MousePosition.Y,
  980. 0);
  981. if (is_up) {
  982. active_tracker.OnMouseUp (args);
  983. mouse_clicks = 1;
  984. } else {
  985. if (!active_tracker.OnMouseDown (args)) {
  986. Control control = GetRealChildAtPoint (Cursor.Position);
  987. if (control != null) {
  988. Point pt = control.PointToClient (Cursor.Position);
  989. XplatUI.SendMessage (control.Handle,
  990. (Msg)m.Msg,
  991. m.WParam,
  992. MakeParam (pt.X, pt.Y));
  993. }
  994. }
  995. }
  996. }
  997. private Control FindControlToInvokeOn ()
  998. {
  999. Control p = this;
  1000. do {
  1001. if (p.IsHandleCreated)
  1002. break;
  1003. p = p.parent;
  1004. } while (p != null);
  1005. if (p == null || !p.IsHandleCreated)
  1006. throw new InvalidOperationException ("Cannot call Invoke or BeginInvoke on a control until the window handle is created");
  1007. return p;
  1008. }
  1009. private void InvalidateBackBuffer () {
  1010. if (backbuffer != null)
  1011. backbuffer.Invalidate ();
  1012. }
  1013. private DoubleBuffer GetBackBuffer () {
  1014. if (backbuffer == null)
  1015. backbuffer = new DoubleBuffer (this);
  1016. return backbuffer;
  1017. }
  1018. private void DisposeBackBuffer () {
  1019. if (backbuffer != null) {
  1020. backbuffer.Dispose ();
  1021. backbuffer = null;
  1022. }
  1023. }
  1024. internal static void SetChildColor(Control parent) {
  1025. Control child;
  1026. for (int i=0; i < parent.child_controls.Count; i++) {
  1027. child=parent.child_controls[i];
  1028. if (child.child_controls.Count>0) {
  1029. SetChildColor(child);
  1030. }
  1031. }
  1032. }
  1033. internal bool Select(Control control) {
  1034. IContainerControl container;
  1035. if (control == null) {
  1036. return false;
  1037. }
  1038. container = GetContainerControl();
  1039. if (container != null && (Control)container != control) {
  1040. container.ActiveControl = control;
  1041. if (container.ActiveControl == control && !control.has_focus && control.IsHandleCreated)
  1042. XplatUI.SetFocus(control.window.Handle);
  1043. }
  1044. else if (control.IsHandleCreated) {
  1045. XplatUI.SetFocus(control.window.Handle);
  1046. }
  1047. return true;
  1048. }
  1049. internal virtual void DoDefaultAction() {
  1050. // Only here to be overriden by our actual controls; this is needed by the accessibility class
  1051. }
  1052. internal static IntPtr MakeParam (int low, int high){
  1053. return new IntPtr (high << 16 | low & 0xffff);
  1054. }
  1055. internal static int LowOrder (int param) {
  1056. return ((int)(short)(param & 0xffff));
  1057. }
  1058. internal static int HighOrder (long param) {
  1059. return ((int)(short)(param >> 16));
  1060. }
  1061. // This method exists so controls overriding OnPaintBackground can have default background painting done
  1062. internal virtual void PaintControlBackground (PaintEventArgs pevent) {
  1063. bool tbstyle_flat = ((CreateParams.Style & (int) ToolBarStyles.TBSTYLE_FLAT) != 0);
  1064. // If we have transparent background
  1065. if (((BackColor.A != 0xff) && GetStyle(ControlStyles.SupportsTransparentBackColor)) || tbstyle_flat) {
  1066. if (parent != null) {
  1067. PaintEventArgs parent_pe;
  1068. GraphicsState state;
  1069. parent_pe = new PaintEventArgs(pevent.Graphics, new Rectangle(pevent.ClipRectangle.X + Left, pevent.ClipRectangle.Y + Top, pevent.ClipRectangle.Width, pevent.ClipRectangle.Height));
  1070. state = parent_pe.Graphics.Save();
  1071. parent_pe.Graphics.TranslateTransform(-Left, -Top);
  1072. parent.OnPaintBackground(parent_pe);
  1073. parent_pe.Graphics.Restore(state);
  1074. state = parent_pe.Graphics.Save();
  1075. parent_pe.Graphics.TranslateTransform(-Left, -Top);
  1076. parent.OnPaint(parent_pe);
  1077. parent_pe.Graphics.Restore(state);
  1078. parent_pe.SetGraphics(null);
  1079. }
  1080. }
  1081. if ((clip_region != null) && (XplatUI.UserClipWontExposeParent)) {
  1082. if (parent != null) {
  1083. PaintEventArgs parent_pe;
  1084. Region region;
  1085. GraphicsState state;
  1086. Hwnd hwnd;
  1087. hwnd = Hwnd.ObjectFromHandle(Handle);
  1088. if (hwnd != null) {
  1089. parent_pe = new PaintEventArgs(pevent.Graphics, new Rectangle(pevent.ClipRectangle.X + Left, pevent.ClipRectangle.Y + Top, pevent.ClipRectangle.Width, pevent.ClipRectangle.Height));
  1090. region = new Region ();
  1091. region.MakeEmpty();
  1092. region.Union(ClientRectangle);
  1093. foreach (Rectangle r in hwnd.ClipRectangles) {
  1094. region.Union (r);
  1095. }
  1096. state = parent_pe.Graphics.Save();
  1097. parent_pe.Graphics.Clip = region;
  1098. parent_pe.Graphics.TranslateTransform(-Left, -Top);
  1099. parent.OnPaintBackground(parent_pe);
  1100. parent_pe.Graphics.Restore(state);
  1101. state = parent_pe.Graphics.Save();
  1102. parent_pe.Graphics.Clip = region;
  1103. parent_pe.Graphics.TranslateTransform(-Left, -Top);
  1104. parent.OnPaint(parent_pe);
  1105. parent_pe.Graphics.Restore(state);
  1106. parent_pe.SetGraphics(null);
  1107. region.Intersect(clip_region);
  1108. pevent.Graphics.Clip = region;
  1109. }
  1110. }
  1111. }
  1112. if (background_image == null) {
  1113. if (!tbstyle_flat) {
  1114. Rectangle paintRect = pevent.ClipRectangle;
  1115. Brush pen = ThemeEngine.Current.ResPool.GetSolidBrush(BackColor);
  1116. pevent.Graphics.FillRectangle(pen, paintRect);
  1117. }
  1118. return;
  1119. }
  1120. DrawBackgroundImage (pevent.Graphics);
  1121. }
  1122. void DrawBackgroundImage (Graphics g) {
  1123. Rectangle drawing_rectangle = new Rectangle ();
  1124. g.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (BackColor), ClientRectangle);
  1125. switch (backgroundimage_layout)
  1126. {
  1127. case ImageLayout.Tile:
  1128. using (TextureBrush b = new TextureBrush (background_image, WrapMode.Tile)) {
  1129. g.FillRectangle (b, ClientRectangle);
  1130. }
  1131. return;
  1132. case ImageLayout.Center:
  1133. drawing_rectangle.Location = new Point (ClientSize.Width / 2 - background_image.Width / 2, ClientSize.Height / 2 - background_image.Height / 2);
  1134. drawing_rectangle.Size = background_image.Size;
  1135. break;
  1136. case ImageLayout.None:
  1137. drawing_rectangle.Location = Point.Empty;
  1138. drawing_rectangle.Size = background_image.Size;
  1139. break;
  1140. case ImageLayout.Stretch:
  1141. drawing_rectangle = ClientRectangle;
  1142. break;
  1143. case ImageLayout.Zoom:
  1144. drawing_rectangle = ClientRectangle;
  1145. if ((float)background_image.Width / (float)background_image.Height < (float)drawing_rectangle.Width / (float) drawing_rectangle.Height) {
  1146. drawing_rectangle.Width = (int) (background_image.Width * ((float)drawing_rectangle.Height / (float)background_image.Height));
  1147. drawing_rectangle.X = (ClientRectangle.Width - drawing_rectangle.Width) / 2;
  1148. } else {
  1149. drawing_rectangle.Height = (int) (background_image.Height * ((float)drawing_rectangle.Width / (float)background_image.Width));
  1150. drawing_rectangle.Y = (ClientRectangle.Height - drawing_rectangle.Height) / 2;
  1151. }
  1152. break;
  1153. default:
  1154. return;
  1155. }
  1156. g.DrawImage (background_image, drawing_rectangle);
  1157. }
  1158. internal virtual void DndEnter (DragEventArgs e) {
  1159. try {
  1160. OnDragEnter (e);
  1161. } catch { }
  1162. }
  1163. internal virtual void DndOver (DragEventArgs e) {
  1164. try {
  1165. OnDragOver (e);
  1166. } catch { }
  1167. }
  1168. internal virtual void DndDrop (DragEventArgs e) {
  1169. try {
  1170. OnDragDrop (e);
  1171. } catch (Exception exc) {
  1172. Console.Error.WriteLine ("MWF: Exception while dropping:");
  1173. Console.Error.WriteLine (exc);
  1174. }
  1175. }
  1176. internal virtual void DndLeave (EventArgs e) {
  1177. try {
  1178. OnDragLeave (e);
  1179. } catch { }
  1180. }
  1181. internal virtual void DndFeedback(GiveFeedbackEventArgs e) {
  1182. try {
  1183. OnGiveFeedback(e);
  1184. } catch { }
  1185. }
  1186. internal virtual void DndContinueDrag(QueryContinueDragEventArgs e) {
  1187. try {
  1188. OnQueryContinueDrag(e);
  1189. } catch { }
  1190. }
  1191. internal static MouseButtons FromParamToMouseButtons (long param) {
  1192. MouseButtons buttons = MouseButtons.None;
  1193. if ((param & (long) MsgButtons.MK_LBUTTON) != 0)
  1194. buttons |= MouseButtons.Left;
  1195. if ((param & (long)MsgButtons.MK_MBUTTON) != 0)
  1196. buttons |= MouseButtons.Middle;
  1197. if ((param & (long)MsgButtons.MK_RBUTTON) != 0)
  1198. buttons |= MouseButtons.Right;
  1199. return buttons;
  1200. }
  1201. internal virtual void FireEnter () {
  1202. OnEnter (EventArgs.Empty);
  1203. }
  1204. internal virtual void FireLeave () {
  1205. OnLeave (EventArgs.Empty);
  1206. }
  1207. internal virtual void FireValidating (CancelEventArgs ce) {
  1208. OnValidating (ce);
  1209. }
  1210. internal virtual void FireValidated () {
  1211. OnValidated (EventArgs.Empty);
  1212. }
  1213. internal virtual bool ProcessControlMnemonic(char charCode) {
  1214. return ProcessMnemonic(charCode);
  1215. }
  1216. private static Control FindFlatForward(Control container, Control start) {
  1217. Control found;
  1218. int index;
  1219. int end;
  1220. bool hit;
  1221. found = null;
  1222. end = container.child_controls.Count;
  1223. hit = false;
  1224. if (start != null) {
  1225. index = start.tab_index;
  1226. } else {
  1227. index = -1;
  1228. }
  1229. for (int i = 0; i < end; i++) {
  1230. if (start == container.child_controls[i]) {
  1231. hit = true;
  1232. continue;
  1233. }
  1234. if (found == null || found.tab_index > container.child_controls[i].tab_index) {
  1235. if (container.child_controls[i].tab_index > index || (hit && container.child_controls[i].tab_index == index)) {
  1236. found = container.child_controls[i];
  1237. }
  1238. }
  1239. }
  1240. return found;
  1241. }
  1242. private static Control FindControlForward(Control container, Control start) {
  1243. Control found;
  1244. found = null;
  1245. if (start == null) {
  1246. return FindFlatForward(container, start);
  1247. }
  1248. if (start.child_controls != null && start.child_controls.Count > 0 &&
  1249. (start == container || !((start is IContainerControl) && start.GetStyle(ControlStyles.ContainerControl)))) {
  1250. return FindControlForward(start, null);
  1251. }
  1252. else {
  1253. while (start != container) {
  1254. found = FindFlatForward(start.parent, start);
  1255. if (found != null) {
  1256. return found;
  1257. }
  1258. start = start.parent;
  1259. }
  1260. }
  1261. return null;
  1262. }
  1263. private static Control FindFlatBackward(Control container, Control start) {
  1264. Control found;
  1265. int index;
  1266. int end;
  1267. bool hit;
  1268. found = null;
  1269. end = container.child_controls.Count;
  1270. hit = false;
  1271. if (start != null) {
  1272. index = start.tab_index;
  1273. } else {
  1274. index = int.MaxValue;
  1275. }
  1276. for (int i = end - 1; i >= 0; i--) {
  1277. if (start == container.child_controls[i]) {
  1278. hit = true;
  1279. continue;
  1280. }
  1281. if (found == null || found.tab_index < container.child_controls[i].tab_index) {
  1282. if (container.child_controls[i].tab_index < index || (hit && container.child_controls[i].tab_index == index))
  1283. found = container.child_controls[i];
  1284. }
  1285. }
  1286. return found;
  1287. }
  1288. private static Control FindControlBackward(Control container, Control start) {
  1289. Control found = null;
  1290. if (start == null) {
  1291. found = FindFlatBackward(container, start);
  1292. }
  1293. else if (start != container) {
  1294. if (start.parent != null) {
  1295. found = FindFlatBackward(start.parent, start);
  1296. if (found == null) {
  1297. if (start.parent != container)
  1298. return start.parent;
  1299. return null;
  1300. }
  1301. }
  1302. }
  1303. if (found == null || start.parent == null)
  1304. found = start;
  1305. while (found != null && (found == container || (!((found is IContainerControl) && found.GetStyle(ControlStyles.ContainerControl))) &&
  1306. found.child_controls != null && found.child_controls.Count > 0)) {
  1307. // while (ctl.child_controls != null && ctl.child_controls.Count > 0 &&
  1308. // (ctl == this || (!((ctl is IContainerControl) && ctl.GetStyle(ControlStyles.ContainerControl))))) {
  1309. found = FindFlatBackward(found, null);
  1310. }
  1311. return found;
  1312. /*
  1313. Control found;
  1314. found = null;
  1315. if (start != null) {
  1316. found = FindFlatBackward(start.parent, start);
  1317. if (found == null) {
  1318. if (start.parent != container) {
  1319. return start.parent;
  1320. }
  1321. }
  1322. }
  1323. if (found == null) {
  1324. found = FindFlatBackward(container, start);
  1325. }
  1326. if (container != start) {
  1327. while ((found != null) && (!found.Contains(start)) && found.child_controls != null && found.child_controls.Count > 0 && !(found is IContainerControl)) {// || found.GetStyle(ControlStyles.ContainerControl))) {
  1328. found = FindControlBackward(found, null);
  1329. if (found != null) {
  1330. return found;
  1331. }
  1332. }
  1333. }
  1334. return found;
  1335. */
  1336. }
  1337. internal virtual void HandleClick(int clicks, MouseEventArgs me) {
  1338. bool standardclick = GetStyle (ControlStyles.StandardClick);
  1339. bool standardclickclick = GetStyle (ControlStyles.StandardDoubleClick);
  1340. if ((clicks > 1) && standardclick && standardclickclick) {
  1341. OnDoubleClick (me);
  1342. OnMouseDoubleClick (me);
  1343. } else if (clicks == 1 && standardclick && !ValidationFailed) {
  1344. OnClick (me);
  1345. OnMouseClick (me);
  1346. }
  1347. }
  1348. internal void CaptureWithConfine (Control ConfineWindow) {
  1349. if (this.IsHandleCreated && !is_captured) {
  1350. is_captured = true;
  1351. XplatUI.GrabWindow (this.window.Handle, ConfineWindow.Handle);
  1352. }
  1353. }
  1354. private void CheckDataBindings () {
  1355. if (data_bindings == null)
  1356. return;
  1357. foreach (Binding binding in data_bindings) {
  1358. binding.Check ();
  1359. }
  1360. }
  1361. private void ChangeParent(Control new_parent) {
  1362. bool pre_enabled;
  1363. bool pre_visible;
  1364. Font pre_font;
  1365. Color pre_fore_color;
  1366. Color pre_back_color;
  1367. RightToLeft pre_rtl;
  1368. // These properties are inherited from our parent
  1369. // Get them pre parent-change and then send events
  1370. // if they are changed after we have our new parent
  1371. pre_enabled = Enabled;
  1372. pre_visible = Visible;
  1373. pre_font = Font;
  1374. pre_fore_color = ForeColor;
  1375. pre_back_color = BackColor;
  1376. pre_rtl = RightToLeft;
  1377. // MS doesn't seem to send a CursorChangedEvent
  1378. parent = new_parent;
  1379. Form frm = this as Form;
  1380. if (frm != null) {
  1381. frm.ChangingParent (new_parent);
  1382. } else if (IsHandleCreated) {
  1383. IntPtr parent_handle = IntPtr.Zero;
  1384. if (new_parent != null && new_parent.IsHandleCreated)
  1385. parent_handle = new_parent.Handle;
  1386. XplatUI.SetParent (Handle, parent_handle);
  1387. }
  1388. OnParentChanged(EventArgs.Empty);
  1389. if (pre_enabled != Enabled) {
  1390. OnEnabledChanged(EventArgs.Empty);
  1391. }
  1392. if (pre_visible != Visible) {
  1393. OnVisibleChanged(EventArgs.Empty);
  1394. }
  1395. if (pre_font != Font) {
  1396. OnFontChanged(EventArgs.Empty);
  1397. }
  1398. if (pre_fore_color != ForeColor) {
  1399. OnForeColorChanged(EventArgs.Empty);
  1400. }
  1401. if (pre_back_color != BackColor) {
  1402. OnBackColorChanged(EventArgs.Empty);
  1403. }
  1404. if (pre_rtl != RightToLeft) {
  1405. // MS sneaks a OnCreateControl and OnHandleCreated in here, I guess
  1406. // because when RTL changes they have to recreate the win32 control
  1407. // We don't really need that (until someone runs into compatibility issues)
  1408. OnRightToLeftChanged(EventArgs.Empty);
  1409. }
  1410. if ((new_parent != null) && new_parent.Created && is_visible && !Created) {
  1411. CreateControl();
  1412. }
  1413. if ((binding_context == null) && Created) {
  1414. OnBindingContextChanged(EventArgs.Empty);
  1415. }
  1416. }
  1417. // Sometimes we need to do this calculation without it being virtual (constructor)
  1418. internal Size InternalSizeFromClientSize (Size clientSize)
  1419. {
  1420. Rectangle ClientRect;
  1421. Rectangle WindowRect;
  1422. CreateParams cp;
  1423. ClientRect = new Rectangle (0, 0, clientSize.Width, clientSize.Height);
  1424. cp = this.CreateParams;
  1425. if (XplatUI.CalculateWindowRect (ref ClientRect, cp, null, out WindowRect))
  1426. return new Size (WindowRect.Width, WindowRect.Height);
  1427. return Size.Empty;
  1428. }
  1429. internal Size ClientSizeFromSize (Size size)
  1430. {
  1431. // Calling this gives us the difference in Size and ClientSize.
  1432. // We just have to apply that difference to our given size.
  1433. Size client_size = this.InternalSizeFromClientSize (size);
  1434. if (client_size == Size.Empty)
  1435. return Size.Empty;
  1436. return new Size (size.Width - (client_size.Width - size.Width), size.Height - (client_size.Height - size.Height));
  1437. }
  1438. internal CreateParams GetCreateParams ()
  1439. {
  1440. return CreateParams;
  1441. }
  1442. internal virtual Size GetPreferredSizeCore (Size proposedSize)
  1443. {
  1444. return this.explicit_bounds.Size;
  1445. }
  1446. private void UpdateDistances() {
  1447. if (parent != null) {
  1448. if (bounds.Width >= 0)
  1449. dist_right = parent.ClientSize.Width - bounds.X - bounds.Width;
  1450. if (bounds.Height >= 0)
  1451. dist_bottom = parent.ClientSize.Height - bounds.Y - bounds.Height;
  1452. recalculate_distances = false;
  1453. }
  1454. }
  1455. private Cursor GetAvailableCursor ()
  1456. {
  1457. if (Cursor != null && Enabled) {
  1458. return Cursor;
  1459. }
  1460. if (Parent != null) {
  1461. return Parent.GetAvailableCursor ();
  1462. }
  1463. return Cursors.Default;
  1464. }
  1465. private void UpdateCursor ()
  1466. {
  1467. if (!IsHandleCreated)
  1468. return;
  1469. if (!Enabled) {
  1470. XplatUI.SetCursor (window.Handle, GetAvailableCursor ().handle);
  1471. return;
  1472. }
  1473. Point pt = PointToClient (Cursor.Position);
  1474. if (!bounds.Contains (pt) && !Capture)
  1475. return;
  1476. if (cursor != null || use_wait_cursor) {
  1477. XplatUI.SetCursor (window.Handle, Cursor.handle);
  1478. } else {
  1479. XplatUI.SetCursor (window.Handle, GetAvailableCursor ().handle);
  1480. }
  1481. }
  1482. private bool UseDoubleBuffering {
  1483. get {
  1484. if (!ThemeEngine.Current.DoubleBufferingSupported)
  1485. return false;
  1486. // Since many of .Net's controls are unmanaged, they are doublebuffered
  1487. // even though their bits may not be set in managed land. This allows
  1488. // us to doublebuffer as well without affecting public style bits.
  1489. if (force_double_buffer)
  1490. return true;
  1491. if (DoubleBuffered)
  1492. return true;
  1493. return (control_style & ControlStyles.DoubleBuffer) != 0;
  1494. }
  1495. }
  1496. internal void OnSizeInitializedOrChanged ()
  1497. {
  1498. Form form = this as Form;
  1499. if (form != null && form.WindowManager != null)
  1500. ThemeEngine.Current.ManagedWindowOnSizeInitializedOrChanged (form);
  1501. }
  1502. #endregion // Private & Internal Methods
  1503. #region Public Static Properties
  1504. public static Color DefaultBackColor {
  1505. get {
  1506. return ThemeEngine.Current.DefaultControlBackColor;
  1507. }
  1508. }
  1509. public static Font DefaultFont {
  1510. get {
  1511. return ThemeEngine.Current.DefaultFont;
  1512. }
  1513. }
  1514. public static Color DefaultForeColor {
  1515. get {
  1516. return ThemeEngine.Current.DefaultControlForeColor;
  1517. }
  1518. }
  1519. public static Keys ModifierKeys {
  1520. get {
  1521. return XplatUI.State.ModifierKeys;
  1522. }
  1523. }
  1524. public static MouseButtons MouseButtons {
  1525. get {
  1526. return XplatUI.State.MouseButtons;
  1527. }
  1528. }
  1529. public static Point MousePosition {
  1530. get {
  1531. return Cursor.Position;
  1532. }
  1533. }
  1534. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1535. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  1536. [Browsable (false)]
  1537. [MonoTODO ("Stub, value is not used")]
  1538. public static bool CheckForIllegalCrossThreadCalls
  1539. {
  1540. get {
  1541. return verify_thread_handle;
  1542. }
  1543. set {
  1544. verify_thread_handle = value;
  1545. }
  1546. }
  1547. #endregion // Public Static Properties
  1548. #region Public Instance Properties
  1549. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1550. [Browsable(false)]
  1551. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1552. public AccessibleObject AccessibilityObject {
  1553. get {
  1554. if (accessibility_object==null) {
  1555. accessibility_object=CreateAccessibilityInstance();
  1556. }
  1557. return accessibility_object;
  1558. }
  1559. }
  1560. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1561. [Browsable(false)]
  1562. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1563. public string AccessibleDefaultActionDescription {
  1564. get {
  1565. return accessible_default_action;
  1566. }
  1567. set {
  1568. accessible_default_action = value;
  1569. }
  1570. }
  1571. [Localizable(true)]
  1572. [DefaultValue(null)]
  1573. [MWFCategory("Accessibility")]
  1574. public string AccessibleDescription {
  1575. get {
  1576. return accessible_description;
  1577. }
  1578. set {
  1579. accessible_description = value;
  1580. }
  1581. }
  1582. [Localizable(true)]
  1583. [DefaultValue(null)]
  1584. [MWFCategory("Accessibility")]
  1585. public string AccessibleName {
  1586. get {
  1587. return accessible_name;
  1588. }
  1589. set {
  1590. accessible_name = value;
  1591. }
  1592. }
  1593. [DefaultValue(AccessibleRole.Default)]
  1594. [MWFDescription("Role of the control"), MWFCategory("Accessibility")]
  1595. public AccessibleRole AccessibleRole {
  1596. get {
  1597. return accessible_role;
  1598. }
  1599. set {
  1600. accessible_role = value;
  1601. }
  1602. }
  1603. [DefaultValue(false)]
  1604. [MWFCategory("Behavior")]
  1605. public virtual bool AllowDrop {
  1606. get {
  1607. return allow_drop;
  1608. }
  1609. set {
  1610. if (allow_drop == value)
  1611. return;
  1612. allow_drop = value;
  1613. if (IsHandleCreated) {
  1614. UpdateStyles();
  1615. XplatUI.SetAllowDrop (Handle, value);
  1616. }
  1617. }
  1618. }
  1619. [Localizable(true)]
  1620. [RefreshProperties(RefreshProperties.Repaint)]
  1621. [DefaultValue(AnchorStyles.Top | AnchorStyles.Left)]
  1622. [MWFCategory("Layout")]
  1623. public virtual AnchorStyles Anchor {
  1624. get {
  1625. return anchor_style;
  1626. }
  1627. set {
  1628. layout_type = LayoutType.Anchor;
  1629. if (anchor_style == value)
  1630. return;
  1631. anchor_style=value;
  1632. dock_style = DockStyle.None;
  1633. UpdateDistances ();
  1634. if (parent != null)
  1635. parent.PerformLayout(this, "Anchor");
  1636. }
  1637. }
  1638. [Browsable (false)]
  1639. [DefaultValue (typeof (Point), "0, 0")]
  1640. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1641. public virtual Point AutoScrollOffset {
  1642. get {
  1643. return auto_scroll_offset;
  1644. }
  1645. set {
  1646. this.auto_scroll_offset = value;
  1647. }
  1648. }
  1649. // XXX: Implement me!
  1650. bool auto_size;
  1651. [RefreshProperties (RefreshProperties.All)]
  1652. [Localizable (true)]
  1653. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  1654. [Browsable (false)]
  1655. [EditorBrowsable (EditorBrowsableState.Never)]
  1656. [DefaultValue (false)]
  1657. public virtual bool AutoSize {
  1658. get { return auto_size; }
  1659. set {
  1660. if (this.auto_size != value) {
  1661. auto_size = value;
  1662. // If we're turning this off, reset our size
  1663. if (!value) {
  1664. Size = explicit_bounds.Size;
  1665. } else {
  1666. if (Parent != null)
  1667. Parent.PerformLayout (this, "AutoSize");
  1668. }
  1669. OnAutoSizeChanged (EventArgs.Empty);
  1670. }
  1671. }
  1672. }
  1673. [AmbientValue ("{Width=0, Height=0}")]
  1674. [MWFCategory("Layout")]
  1675. public virtual Size MaximumSize {
  1676. get {
  1677. return maximum_size;
  1678. }
  1679. set {
  1680. if (maximum_size != value) {
  1681. maximum_size = value;
  1682. Size = PreferredSize;
  1683. }
  1684. }
  1685. }
  1686. internal bool ShouldSerializeMaximumSize ()
  1687. {
  1688. return this.MaximumSize != DefaultMaximumSize;
  1689. }
  1690. [MWFCategory("Layout")]
  1691. public virtual Size MinimumSize {
  1692. get {
  1693. return minimum_size;
  1694. }
  1695. set {
  1696. if (minimum_size != value) {
  1697. minimum_size = value;
  1698. Size = PreferredSize;
  1699. }
  1700. }
  1701. }
  1702. internal bool ShouldSerializeMinimumSize ()
  1703. {
  1704. return this.MinimumSize != DefaultMinimumSize;
  1705. }
  1706. [DispId(-501)]
  1707. [MWFCategory("Appearance")]
  1708. public virtual Color BackColor {
  1709. get {
  1710. if (background_color.IsEmpty) {
  1711. if (parent!=null) {
  1712. Color pcolor = parent.BackColor;
  1713. if (pcolor.A == 0xff || GetStyle(ControlStyles.SupportsTransparentBackColor))
  1714. return pcolor;
  1715. }
  1716. return DefaultBackColor;
  1717. }
  1718. return background_color;
  1719. }
  1720. set {
  1721. if (!value.IsEmpty && (value.A != 0xff) && !GetStyle(ControlStyles.SupportsTransparentBackColor)) {
  1722. throw new ArgumentException("Transparent background colors are not supported on this control");
  1723. }
  1724. if (background_color != value) {
  1725. background_color=value;
  1726. SetChildColor(this);
  1727. OnBackColorChanged(EventArgs.Empty);
  1728. Invalidate();
  1729. }
  1730. }
  1731. }
  1732. internal bool ShouldSerializeBackColor ()
  1733. {
  1734. return this.BackColor != DefaultBackColor;
  1735. }
  1736. [Localizable(true)]
  1737. [DefaultValue(null)]
  1738. [MWFCategory("Appearance")]
  1739. public virtual Image BackgroundImage {
  1740. get {
  1741. return background_image;
  1742. }
  1743. set {
  1744. if (background_image!=value) {
  1745. background_image=value;
  1746. OnBackgroundImageChanged(EventArgs.Empty);
  1747. Invalidate ();
  1748. }
  1749. }
  1750. }
  1751. [DefaultValue (ImageLayout.Tile)]
  1752. [Localizable (true)]
  1753. [MWFCategory("Appearance")]
  1754. public virtual ImageLayout BackgroundImageLayout {
  1755. get {
  1756. return backgroundimage_layout;
  1757. }
  1758. set {
  1759. if (Array.IndexOf (Enum.GetValues (typeof (ImageLayout)), value) == -1)
  1760. throw new InvalidEnumArgumentException ("value", (int) value, typeof(ImageLayout));
  1761. if (value != backgroundimage_layout) {
  1762. backgroundimage_layout = value;
  1763. Invalidate ();
  1764. OnBackgroundImageLayoutChanged (EventArgs.Empty);
  1765. }
  1766. }
  1767. }
  1768. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1769. [Browsable(false)]
  1770. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1771. public virtual BindingContext BindingContext {
  1772. get {
  1773. if (binding_context != null)
  1774. return binding_context;
  1775. if (Parent == null)
  1776. return null;
  1777. binding_context = Parent.BindingContext;
  1778. return binding_context;
  1779. }
  1780. set {
  1781. if (binding_context != value) {
  1782. binding_context = value;
  1783. OnBindingContextChanged(EventArgs.Empty);
  1784. }
  1785. }
  1786. }
  1787. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1788. [Browsable(false)]
  1789. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1790. public int Bottom {
  1791. get {
  1792. return this.bounds.Bottom;
  1793. }
  1794. }
  1795. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1796. [Browsable(false)]
  1797. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1798. public Rectangle Bounds {
  1799. get {
  1800. return this.bounds;
  1801. }
  1802. set {
  1803. SetBounds(value.Left, value.Top, value.Width, value.Height, BoundsSpecified.All);
  1804. }
  1805. }
  1806. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1807. [Browsable(false)]
  1808. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1809. public bool CanFocus {
  1810. get {
  1811. if (IsHandleCreated && Visible && Enabled) {
  1812. return true;
  1813. }
  1814. return false;
  1815. }
  1816. }
  1817. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1818. [Browsable(false)]
  1819. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1820. public bool CanSelect {
  1821. get {
  1822. Control parent;
  1823. if (!GetStyle(ControlStyles.Selectable)) {
  1824. return false;
  1825. }
  1826. parent = this;
  1827. while (parent != null) {
  1828. if (!parent.is_visible || !parent.is_enabled) {
  1829. return false;
  1830. }
  1831. parent = parent.parent;
  1832. }
  1833. return true;
  1834. }
  1835. }
  1836. internal virtual bool InternalCapture {
  1837. get {
  1838. return Capture;
  1839. }
  1840. set {
  1841. Capture = value;
  1842. }
  1843. }
  1844. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1845. [Browsable(false)]
  1846. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1847. public bool Capture {
  1848. get {
  1849. return this.is_captured;
  1850. }
  1851. set {
  1852. // Call OnMouseCaptureChanged when we get WM_CAPTURECHANGED.
  1853. if (value != is_captured) {
  1854. if (value) {
  1855. is_captured = true;
  1856. XplatUI.GrabWindow(Handle, IntPtr.Zero);
  1857. } else {
  1858. if (IsHandleCreated)
  1859. XplatUI.UngrabWindow(Handle);
  1860. is_captured = false;
  1861. }
  1862. }
  1863. }
  1864. }
  1865. [DefaultValue(true)]
  1866. [MWFCategory("Focus")]
  1867. public bool CausesValidation {
  1868. get {
  1869. return this.causes_validation;
  1870. }
  1871. set {
  1872. if (this.causes_validation != value) {
  1873. causes_validation = value;
  1874. OnCausesValidationChanged(EventArgs.Empty);
  1875. }
  1876. }
  1877. }
  1878. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1879. [Browsable(false)]
  1880. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1881. public Rectangle ClientRectangle {
  1882. get {
  1883. client_rect.Width = client_size.Width;
  1884. client_rect.Height = client_size.Height;
  1885. return client_rect;
  1886. }
  1887. }
  1888. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1889. [Browsable(false)]
  1890. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1891. public Size ClientSize {
  1892. get {
  1893. #if notneeded
  1894. if ((this is Form) && (((Form)this).form_parent_window != null)) {
  1895. return ((Form)this).form_parent_window.ClientSize;
  1896. }
  1897. #endif
  1898. return client_size;
  1899. }
  1900. set {
  1901. this.SetClientSizeCore(value.Width, value.Height);
  1902. this.OnClientSizeChanged (EventArgs.Empty);
  1903. }
  1904. }
  1905. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1906. [Browsable(false)]
  1907. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1908. [DescriptionAttribute("ControlCompanyNameDescr")]
  1909. public String CompanyName {
  1910. get {
  1911. return "Mono Project, Novell, Inc.";
  1912. }
  1913. }
  1914. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1915. [Browsable(false)]
  1916. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1917. public bool ContainsFocus {
  1918. get {
  1919. IntPtr focused_window;
  1920. focused_window = XplatUI.GetFocus();
  1921. if (IsHandleCreated) {
  1922. if (focused_window == Handle) {
  1923. return true;
  1924. }
  1925. for (int i=0; i < child_controls.Count; i++) {
  1926. if (child_controls[i].ContainsFocus) {
  1927. return true;
  1928. }
  1929. }
  1930. }
  1931. return false;
  1932. }
  1933. }
  1934. [Browsable (false)]
  1935. [DefaultValue(null)]
  1936. [MWFCategory("Behavior")]
  1937. public virtual ContextMenu ContextMenu {
  1938. get {
  1939. return ContextMenuInternal;
  1940. }
  1941. set {
  1942. ContextMenuInternal = value;
  1943. }
  1944. }
  1945. internal virtual ContextMenu ContextMenuInternal {
  1946. get {
  1947. return context_menu;
  1948. }
  1949. set {
  1950. if (context_menu != value) {
  1951. context_menu = value;
  1952. OnContextMenuChanged (EventArgs.Empty);
  1953. }
  1954. }
  1955. }
  1956. [DefaultValue (null)]
  1957. [MWFCategory("Behavior")]
  1958. public virtual ContextMenuStrip ContextMenuStrip {
  1959. get { return this.context_menu_strip; }
  1960. set {
  1961. if (this.context_menu_strip != value) {
  1962. this.context_menu_strip = value;
  1963. if (value != null)
  1964. value.container = this;
  1965. OnContextMenuStripChanged (EventArgs.Empty);
  1966. }
  1967. }
  1968. }
  1969. [Browsable(false)]
  1970. [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
  1971. public ControlCollection Controls {
  1972. get {
  1973. return this.child_controls;
  1974. }
  1975. }
  1976. [EditorBrowsable(EditorBrowsableState.Advanced)]
  1977. [Browsable(false)]
  1978. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1979. public bool Created {
  1980. get {
  1981. return (!is_disposed && is_created);
  1982. }
  1983. }
  1984. [AmbientValue(null)]
  1985. [MWFCategory("Appearance")]
  1986. public virtual Cursor Cursor {
  1987. get {
  1988. if (use_wait_cursor)
  1989. return Cursors.WaitCursor;
  1990. if (cursor != null) {
  1991. return cursor;
  1992. }
  1993. if (parent != null) {
  1994. return parent.Cursor;
  1995. }
  1996. return Cursors.Default;
  1997. }
  1998. set {
  1999. if (cursor == value) {
  2000. return;
  2001. }
  2002. cursor = value;
  2003. UpdateCursor ();
  2004. OnCursorChanged (EventArgs.Empty);
  2005. }
  2006. }
  2007. internal bool ShouldSerializeCursor ()
  2008. {
  2009. return this.Cursor != Cursors.Default;
  2010. }
  2011. [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
  2012. [ParenthesizePropertyName(true)]
  2013. [RefreshProperties(RefreshProperties.All)]
  2014. [MWFCategory("Data")]
  2015. public ControlBindingsCollection DataBindings {
  2016. get {
  2017. if (data_bindings == null)
  2018. data_bindings = new ControlBindingsCollection (this);
  2019. return data_bindings;
  2020. }
  2021. }
  2022. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2023. [Browsable(false)]
  2024. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2025. public virtual Rectangle DisplayRectangle {
  2026. get {
  2027. // for the control class the DisplayRectangle == ClientRectangle
  2028. return ClientRectangle;
  2029. }
  2030. }
  2031. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2032. [Browsable(false)]
  2033. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2034. public bool Disposing {
  2035. get {
  2036. return is_disposed;
  2037. }
  2038. }
  2039. [Localizable(true)]
  2040. [RefreshProperties(RefreshProperties.Repaint)]
  2041. [DefaultValue(DockStyle.None)]
  2042. [MWFCategory("Layout")]
  2043. public virtual DockStyle Dock {
  2044. get {
  2045. return dock_style;
  2046. }
  2047. set {
  2048. // If the user sets this to None, we need to still use Anchor layout
  2049. if (value != DockStyle.None)
  2050. layout_type = LayoutType.Dock;
  2051. if (dock_style == value) {
  2052. return;
  2053. }
  2054. if (!Enum.IsDefined (typeof (DockStyle), value)) {
  2055. throw new InvalidEnumArgumentException ("value", (int) value,
  2056. typeof (DockStyle));
  2057. }
  2058. dock_style = value;
  2059. anchor_style = AnchorStyles.Top | AnchorStyles.Left;
  2060. if (dock_style == DockStyle.None) {
  2061. bounds = explicit_bounds;
  2062. layout_type = LayoutType.Anchor;
  2063. }
  2064. if (parent != null)
  2065. parent.PerformLayout(this, "Dock");
  2066. else if (Controls.Count > 0)
  2067. PerformLayout ();
  2068. OnDockChanged(EventArgs.Empty);
  2069. }
  2070. }
  2071. protected virtual bool DoubleBuffered {
  2072. get {
  2073. return (control_style & ControlStyles.OptimizedDoubleBuffer) != 0;
  2074. }
  2075. set {
  2076. if (value == DoubleBuffered)
  2077. return;
  2078. if (value) {
  2079. SetStyle (ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);
  2080. } else {
  2081. SetStyle (ControlStyles.OptimizedDoubleBuffer, false);
  2082. }
  2083. }
  2084. }
  2085. public void DrawToBitmap (Bitmap bitmap, Rectangle targetBounds)
  2086. {
  2087. Graphics g = Graphics.FromImage (bitmap);
  2088. // Only draw within the target bouds, and up to the size of the control
  2089. g.IntersectClip (targetBounds);
  2090. g.IntersectClip (Bounds);
  2091. // Logic copied from WmPaint
  2092. PaintEventArgs pea = new PaintEventArgs (g, targetBounds);
  2093. if (!GetStyle (ControlStyles.Opaque))
  2094. OnPaintBackground (pea);
  2095. OnPaintBackgroundInternal (pea);
  2096. OnPaintInternal (pea);
  2097. if (!pea.Handled)
  2098. OnPaint (pea);
  2099. g.Dispose ();
  2100. }
  2101. [DispId(-514)]
  2102. [Localizable(true)]
  2103. [MWFCategory("Behavior")]
  2104. public bool Enabled {
  2105. get {
  2106. if (!is_enabled) {
  2107. return false;
  2108. }
  2109. if (parent != null) {
  2110. return parent.Enabled;
  2111. }
  2112. return true;
  2113. }
  2114. set {
  2115. if (this.is_enabled == value)
  2116. return;
  2117. bool old_value = is_enabled;
  2118. is_enabled = value;
  2119. if (!value)
  2120. UpdateCursor ();
  2121. if (old_value != value && !value && this.has_focus)
  2122. SelectNextControl(this, true, true, true, true);
  2123. OnEnabledChanged (EventArgs.Empty);
  2124. }
  2125. }
  2126. internal bool ShouldSerializeEnabled ()
  2127. {
  2128. return this.Enabled != true;
  2129. }
  2130. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2131. [Browsable(false)]
  2132. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2133. public virtual bool Focused {
  2134. get {
  2135. return this.has_focus;
  2136. }
  2137. }
  2138. [DispId(-512)]
  2139. [AmbientValue(null)]
  2140. [Localizable(true)]
  2141. [MWFCategory("Appearance")]
  2142. public virtual Font Font {
  2143. [return: MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof (Font))]
  2144. get {
  2145. if (font != null)
  2146. return font;
  2147. if (parent != null) {
  2148. Font f = parent.Font;
  2149. if (f != null)
  2150. return f;
  2151. }
  2152. return DefaultFont;
  2153. }
  2154. [param:MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Font))]
  2155. set {
  2156. if (font != null && font == value) {
  2157. return;
  2158. }
  2159. font = value;
  2160. Invalidate();
  2161. OnFontChanged (EventArgs.Empty);
  2162. PerformLayout ();
  2163. }
  2164. }
  2165. internal bool ShouldSerializeFont ()
  2166. {
  2167. return !this.Font.Equals (DefaultFont);
  2168. }
  2169. [DispId(-513)]
  2170. [MWFCategory("Appearance")]
  2171. public virtual Color ForeColor {
  2172. get {
  2173. if (foreground_color.IsEmpty) {
  2174. if (parent!=null) {
  2175. return parent.ForeColor;
  2176. }
  2177. return DefaultForeColor;
  2178. }
  2179. return foreground_color;
  2180. }
  2181. set {
  2182. if (foreground_color != value) {
  2183. foreground_color=value;
  2184. Invalidate();
  2185. OnForeColorChanged(EventArgs.Empty);
  2186. }
  2187. }
  2188. }
  2189. internal bool ShouldSerializeForeColor ()
  2190. {
  2191. return this.ForeColor != DefaultForeColor;
  2192. }
  2193. [DispId(-515)]
  2194. [Browsable(false)]
  2195. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2196. public IntPtr Handle { // IWin32Window
  2197. get {
  2198. if (verify_thread_handle) {
  2199. if (this.InvokeRequired) {
  2200. throw new InvalidOperationException("Cross-thread access of handle detected. Handle access only valid on thread that created the control");
  2201. }
  2202. }
  2203. if (!IsHandleCreated) {
  2204. CreateHandle();
  2205. }
  2206. return window.Handle;
  2207. }
  2208. }
  2209. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2210. [Browsable(false)]
  2211. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2212. public bool HasChildren {
  2213. get {
  2214. if (this.child_controls.Count>0) {
  2215. return true;
  2216. }
  2217. return false;
  2218. }
  2219. }
  2220. [EditorBrowsable(EditorBrowsableState.Always)]
  2221. [Browsable(false)]
  2222. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2223. public int Height {
  2224. get { return this.bounds.Height; }
  2225. set { SetBounds(bounds.X, bounds.Y, bounds.Width, value, BoundsSpecified.Height); }
  2226. }
  2227. [AmbientValue(ImeMode.Inherit)]
  2228. [Localizable(true)]
  2229. [MWFCategory("Behavior")]
  2230. public ImeMode ImeMode {
  2231. get {
  2232. if (ime_mode == ImeMode.Inherit) {
  2233. if (parent != null)
  2234. return parent.ImeMode;
  2235. else
  2236. return ImeMode.NoControl; // default value
  2237. }
  2238. return ime_mode;
  2239. }
  2240. set {
  2241. if (ime_mode != value) {
  2242. ime_mode = value;
  2243. OnImeModeChanged(EventArgs.Empty);
  2244. }
  2245. }
  2246. }
  2247. internal bool ShouldSerializeImeMode ()
  2248. {
  2249. return this.ImeMode != ImeMode.NoControl;
  2250. }
  2251. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2252. [Browsable(false)]
  2253. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2254. public bool InvokeRequired { // ISynchronizeInvoke
  2255. get {
  2256. if (creator_thread != null && creator_thread!=Thread.CurrentThread) {
  2257. return true;
  2258. }
  2259. return false;
  2260. }
  2261. }
  2262. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2263. [Browsable(false)]
  2264. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2265. public bool IsAccessible {
  2266. get {
  2267. return is_accessible;
  2268. }
  2269. set {
  2270. is_accessible = value;
  2271. }
  2272. }
  2273. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2274. [Browsable(false)]
  2275. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2276. public bool IsDisposed {
  2277. get {
  2278. return this.is_disposed;
  2279. }
  2280. }
  2281. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2282. [Browsable(false)]
  2283. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2284. public bool IsHandleCreated {
  2285. get {
  2286. if (window == null || window.Handle == IntPtr.Zero)
  2287. return false;
  2288. Hwnd hwnd = Hwnd.ObjectFromHandle (window.Handle);
  2289. if (hwnd != null && hwnd.zombie)
  2290. return false;
  2291. return true;
  2292. }
  2293. }
  2294. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2295. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2296. [Browsable(false)]
  2297. [MonoNotSupported ("RTL is not supported")]
  2298. public bool IsMirrored {
  2299. get { return false; }
  2300. }
  2301. [Browsable (false)]
  2302. [EditorBrowsable (EditorBrowsableState.Advanced)]
  2303. public virtual Layout.LayoutEngine LayoutEngine {
  2304. get {
  2305. if (layout_engine == null)
  2306. layout_engine = new Layout.DefaultLayout ();
  2307. return layout_engine;
  2308. }
  2309. }
  2310. [EditorBrowsable(EditorBrowsableState.Always)]
  2311. [Browsable(false)]
  2312. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2313. public int Left {
  2314. get {
  2315. return this.bounds.Left;
  2316. }
  2317. set {
  2318. SetBounds(value, bounds.Y, bounds.Width, bounds.Height, BoundsSpecified.X);
  2319. }
  2320. }
  2321. [Localizable(true)]
  2322. [MWFCategory("Layout")]
  2323. public Point Location {
  2324. get {
  2325. return this.bounds.Location;
  2326. }
  2327. set {
  2328. SetBounds(value.X, value.Y, bounds.Width, bounds.Height, BoundsSpecified.Location);
  2329. }
  2330. }
  2331. internal bool ShouldSerializeLocation ()
  2332. {
  2333. return this.Location != new Point (0, 0);
  2334. }
  2335. [Localizable (true)]
  2336. [MWFCategory("Layout")]
  2337. public Padding Margin {
  2338. get { return this.margin; }
  2339. set {
  2340. if (this.margin != value) {
  2341. this.margin = value;
  2342. if (Parent != null)
  2343. Parent.PerformLayout (this, "Margin");
  2344. OnMarginChanged (EventArgs.Empty);
  2345. }
  2346. }
  2347. }
  2348. internal bool ShouldSerializeMargin ()
  2349. {
  2350. return this.Margin != DefaultMargin;
  2351. }
  2352. [Browsable(false)]
  2353. public string Name {
  2354. get {
  2355. return name;
  2356. }
  2357. set {
  2358. name = value;
  2359. }
  2360. }
  2361. [Localizable(true)]
  2362. [MWFCategory("Layout")]
  2363. public Padding Padding {
  2364. get {
  2365. return padding;
  2366. }
  2367. set {
  2368. if (padding != value) {
  2369. padding = value;
  2370. OnPaddingChanged (EventArgs.Empty);
  2371. // Changing padding generally requires a new size
  2372. if (this.AutoSize && this.Parent != null)
  2373. parent.PerformLayout (this, "Padding");
  2374. else
  2375. PerformLayout (this, "Padding");
  2376. }
  2377. }
  2378. }
  2379. internal bool ShouldSerializePadding ()
  2380. {
  2381. return this.Padding != DefaultPadding;
  2382. }
  2383. [Browsable(false)]
  2384. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2385. public Control Parent {
  2386. get {
  2387. return this.parent;
  2388. }
  2389. set {
  2390. if (value == this) {
  2391. throw new ArgumentException("A circular control reference has been made. A control cannot be owned or parented to itself.");
  2392. }
  2393. if (parent!=value) {
  2394. if (value==null) {
  2395. parent.Controls.Remove(this);
  2396. parent = null;
  2397. return;
  2398. }
  2399. value.Controls.Add(this);
  2400. }
  2401. }
  2402. }
  2403. [Browsable (false)]
  2404. public Size PreferredSize {
  2405. get { return this.GetPreferredSize (Size.Empty); }
  2406. }
  2407. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2408. [Browsable(false)]
  2409. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2410. public string ProductName {
  2411. get {
  2412. Type t = typeof (AssemblyProductAttribute);
  2413. Assembly assembly = GetType().Module.Assembly;
  2414. object [] attrs = assembly.GetCustomAttributes (t, false);
  2415. AssemblyProductAttribute a = null;
  2416. // On MS we get a NullRefException if product attribute is not
  2417. // set.
  2418. if (attrs != null && attrs.Length > 0)
  2419. a = (AssemblyProductAttribute) attrs [0];
  2420. if (a == null) {
  2421. return GetType ().Namespace;
  2422. }
  2423. return a.Product;
  2424. }
  2425. }
  2426. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2427. [Browsable(false)]
  2428. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2429. public string ProductVersion {
  2430. get {
  2431. Type t = typeof (AssemblyVersionAttribute);
  2432. Assembly assembly = GetType().Module.Assembly;
  2433. object [] attrs = assembly.GetCustomAttributes (t, false);
  2434. if (attrs == null || attrs.Length < 1)
  2435. return "1.0.0.0";
  2436. return ((AssemblyVersionAttribute)attrs [0]).Version;
  2437. }
  2438. }
  2439. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2440. [Browsable(false)]
  2441. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2442. public bool RecreatingHandle {
  2443. get {
  2444. return is_recreating;
  2445. }
  2446. }
  2447. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2448. [Browsable(false)]
  2449. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2450. public Region Region {
  2451. get {
  2452. return clip_region;
  2453. }
  2454. set {
  2455. if (clip_region != value) {
  2456. if (IsHandleCreated)
  2457. XplatUI.SetClipRegion(Handle, value);
  2458. clip_region = value;
  2459. OnRegionChanged (EventArgs.Empty);
  2460. }
  2461. }
  2462. }
  2463. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2464. [Browsable(false)]
  2465. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2466. public int Right {
  2467. get {
  2468. return this.bounds.Right;
  2469. }
  2470. }
  2471. [AmbientValue(RightToLeft.Inherit)]
  2472. [Localizable(true)]
  2473. [MWFCategory("Appearance")]
  2474. public virtual RightToLeft RightToLeft {
  2475. get {
  2476. if (right_to_left == RightToLeft.Inherit) {
  2477. if (parent != null)
  2478. return parent.RightToLeft;
  2479. else
  2480. return RightToLeft.No; // default value
  2481. }
  2482. return right_to_left;
  2483. }
  2484. set {
  2485. if (value != right_to_left) {
  2486. right_to_left = value;
  2487. OnRightToLeftChanged(EventArgs.Empty);
  2488. PerformLayout ();
  2489. }
  2490. }
  2491. }
  2492. internal bool ShouldSerializeRightToLeft ()
  2493. {
  2494. return this.RightToLeft != RightToLeft.No;
  2495. }
  2496. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2497. public override ISite Site {
  2498. get {
  2499. return base.Site;
  2500. }
  2501. set {
  2502. base.Site = value;
  2503. if (value != null) {
  2504. AmbientProperties ap = (AmbientProperties) value.GetService (typeof (AmbientProperties));
  2505. if (ap != null) {
  2506. BackColor = ap.BackColor;
  2507. ForeColor = ap.ForeColor;
  2508. Cursor = ap.Cursor;
  2509. Font = ap.Font;
  2510. }
  2511. }
  2512. }
  2513. }
  2514. internal bool ShouldSerializeSite ()
  2515. {
  2516. return false;
  2517. }
  2518. [Localizable(true)]
  2519. [MWFCategory("Layout")]
  2520. public Size Size {
  2521. get {
  2522. return new Size(Width, Height);
  2523. }
  2524. set {
  2525. SetBounds(bounds.X, bounds.Y, value.Width, value.Height, BoundsSpecified.Size);
  2526. }
  2527. }
  2528. internal virtual bool ShouldSerializeSize ()
  2529. {
  2530. return this.Size != DefaultSize;
  2531. }
  2532. [Localizable(true)]
  2533. [MergableProperty(false)]
  2534. [MWFCategory("Behavior")]
  2535. public int TabIndex {
  2536. get {
  2537. if (tab_index != -1) {
  2538. return tab_index;
  2539. }
  2540. return 0;
  2541. }
  2542. set {
  2543. if (tab_index != value) {
  2544. tab_index = value;
  2545. OnTabIndexChanged(EventArgs.Empty);
  2546. }
  2547. }
  2548. }
  2549. [DispId(-516)]
  2550. [DefaultValue(true)]
  2551. [MWFCategory("Behavior")]
  2552. public bool TabStop {
  2553. get {
  2554. return tab_stop;
  2555. }
  2556. set {
  2557. if (tab_stop != value) {
  2558. tab_stop = value;
  2559. OnTabStopChanged(EventArgs.Empty);
  2560. }
  2561. }
  2562. }
  2563. [Localizable(false)]
  2564. [Bindable(true)]
  2565. [TypeConverter(typeof(StringConverter))]
  2566. [DefaultValue(null)]
  2567. [MWFCategory("Data")]
  2568. public object Tag {
  2569. get {
  2570. return control_tag;
  2571. }
  2572. set {
  2573. control_tag = value;
  2574. }
  2575. }
  2576. [DispId(-517)]
  2577. [Localizable(true)]
  2578. [BindableAttribute(true)]
  2579. [MWFCategory("Appearance")]
  2580. public virtual string Text {
  2581. get {
  2582. // Our implementation ignores ControlStyles.CacheText - we always cache
  2583. return this.text;
  2584. }
  2585. set {
  2586. if (value == null) {
  2587. value = String.Empty;
  2588. }
  2589. if (text!=value) {
  2590. text=value;
  2591. UpdateWindowText ();
  2592. OnTextChanged (EventArgs.Empty);
  2593. // Label has its own AutoSize implementation
  2594. if (AutoSize && Parent != null && (!(this is Label)))
  2595. Parent.PerformLayout (this, "Text");
  2596. }
  2597. }
  2598. }
  2599. internal virtual void UpdateWindowText ()
  2600. {
  2601. if (!IsHandleCreated) {
  2602. return;
  2603. }
  2604. XplatUI.Text (Handle, text);
  2605. }
  2606. [EditorBrowsable(EditorBrowsableState.Always)]
  2607. [Browsable(false)]
  2608. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2609. public int Top {
  2610. get {
  2611. return this.bounds.Top;
  2612. }
  2613. set {
  2614. SetBounds(bounds.X, value, bounds.Width, bounds.Height, BoundsSpecified.Y);
  2615. }
  2616. }
  2617. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2618. [Browsable(false)]
  2619. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2620. public Control TopLevelControl {
  2621. get {
  2622. Control p = this;
  2623. while (p.parent != null) {
  2624. p = p.parent;
  2625. }
  2626. return p is Form ? p : null;
  2627. }
  2628. }
  2629. [EditorBrowsable(EditorBrowsableState.Always)]
  2630. [Browsable(true)]
  2631. [DefaultValue (false)]
  2632. [MWFCategory("Appearance")]
  2633. public bool UseWaitCursor {
  2634. get { return use_wait_cursor; }
  2635. set {
  2636. if (use_wait_cursor != value) {
  2637. use_wait_cursor = value;
  2638. UpdateCursor ();
  2639. OnCursorChanged (EventArgs.Empty);
  2640. }
  2641. }
  2642. }
  2643. [Localizable(true)]
  2644. [MWFCategory("Behavior")]
  2645. public bool Visible {
  2646. get {
  2647. if (!is_visible) {
  2648. return false;
  2649. } else if (parent != null) {
  2650. return parent.Visible;
  2651. }
  2652. return true;
  2653. }
  2654. set {
  2655. if (this.is_visible != value) {
  2656. SetVisibleCore(value);
  2657. if (parent != null)
  2658. parent.PerformLayout (this, "Visible");
  2659. }
  2660. }
  2661. }
  2662. internal bool ShouldSerializeVisible ()
  2663. {
  2664. return this.Visible != true;
  2665. }
  2666. [EditorBrowsable(EditorBrowsableState.Always)]
  2667. [Browsable(false)]
  2668. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2669. public int Width {
  2670. get {
  2671. return this.bounds.Width;
  2672. }
  2673. set {
  2674. SetBounds(bounds.X, bounds.Y, value, bounds.Height, BoundsSpecified.Width);
  2675. }
  2676. }
  2677. [EditorBrowsable(EditorBrowsableState.Never)]
  2678. [Browsable(false)]
  2679. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2680. public IWindowTarget WindowTarget {
  2681. get { return window_target; }
  2682. set { window_target = value; }
  2683. }
  2684. #endregion // Public Instance Properties
  2685. #region Protected Instance Properties
  2686. protected virtual bool CanEnableIme {
  2687. get { return false; }
  2688. }
  2689. // Is only false in some ActiveX contexts
  2690. protected override bool CanRaiseEvents {
  2691. get { return true; }
  2692. }
  2693. protected virtual CreateParams CreateParams {
  2694. get {
  2695. CreateParams create_params = new CreateParams();
  2696. try {
  2697. create_params.Caption = Text;
  2698. }
  2699. catch {
  2700. create_params.Caption = text;
  2701. }
  2702. try {
  2703. create_params.X = Left;
  2704. }
  2705. catch {
  2706. create_params.X = this.bounds.X;
  2707. }
  2708. try {
  2709. create_params.Y = Top;
  2710. }
  2711. catch {
  2712. create_params.Y = this.bounds.Y;
  2713. }
  2714. try {
  2715. create_params.Width = Width;
  2716. }
  2717. catch {
  2718. create_params.Width = this.bounds.Width;
  2719. }
  2720. try {
  2721. create_params.Height = Height;
  2722. }
  2723. catch {
  2724. create_params.Height = this.bounds.Height;
  2725. }
  2726. create_params.ClassName = XplatUI.GetDefaultClassName (GetType ());
  2727. create_params.ClassStyle = (int)(XplatUIWin32.ClassStyle.CS_OWNDC | XplatUIWin32.ClassStyle.CS_DBLCLKS);
  2728. create_params.ExStyle = 0;
  2729. create_params.Param = 0;
  2730. if (allow_drop) {
  2731. create_params.ExStyle |= (int)WindowExStyles.WS_EX_ACCEPTFILES;
  2732. }
  2733. if ((parent!=null) && (parent.IsHandleCreated)) {
  2734. create_params.Parent = parent.Handle;
  2735. }
  2736. create_params.Style = (int)WindowStyles.WS_CHILD | (int)WindowStyles.WS_CLIPCHILDREN | (int)WindowStyles.WS_CLIPSIBLINGS;
  2737. if (is_visible) {
  2738. create_params.Style |= (int)WindowStyles.WS_VISIBLE;
  2739. }
  2740. if (!is_enabled) {
  2741. create_params.Style |= (int)WindowStyles.WS_DISABLED;
  2742. }
  2743. switch (border_style) {
  2744. case BorderStyle.FixedSingle:
  2745. create_params.Style |= (int) WindowStyles.WS_BORDER;
  2746. break;
  2747. case BorderStyle.Fixed3D:
  2748. create_params.ExStyle |= (int) WindowExStyles.WS_EX_CLIENTEDGE;
  2749. break;
  2750. }
  2751. create_params.control = this;
  2752. return create_params;
  2753. }
  2754. }
  2755. protected virtual Cursor DefaultCursor { get { return Cursors.Default; } }
  2756. protected virtual ImeMode DefaultImeMode {
  2757. get {
  2758. return ImeMode.Inherit;
  2759. }
  2760. }
  2761. protected virtual Padding DefaultMargin {
  2762. get { return new Padding (3); }
  2763. }
  2764. protected virtual Size DefaultMaximumSize { get { return new Size (); } }
  2765. protected virtual Size DefaultMinimumSize { get { return new Size (); } }
  2766. protected virtual Padding DefaultPadding { get { return new Padding (); } }
  2767. protected virtual Size DefaultSize {
  2768. get {
  2769. return new Size(0, 0);
  2770. }
  2771. }
  2772. protected int FontHeight {
  2773. get {
  2774. return Font.Height;
  2775. }
  2776. set {
  2777. ;; // Nothing to do
  2778. }
  2779. }
  2780. [Obsolete ()]
  2781. protected bool RenderRightToLeft {
  2782. get {
  2783. return (this.right_to_left == RightToLeft.Yes);
  2784. }
  2785. }
  2786. protected bool ResizeRedraw {
  2787. get {
  2788. return GetStyle(ControlStyles.ResizeRedraw);
  2789. }
  2790. set {
  2791. SetStyle(ControlStyles.ResizeRedraw, value);
  2792. }
  2793. }
  2794. [EditorBrowsable (EditorBrowsableState.Advanced)]
  2795. protected virtual bool ScaleChildren {
  2796. get { return ScaleChildrenInternal; }
  2797. }
  2798. internal virtual bool ScaleChildrenInternal {
  2799. get { return true; }
  2800. }
  2801. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2802. [Browsable(false)]
  2803. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2804. protected internal virtual bool ShowFocusCues {
  2805. get {
  2806. if (this is Form)
  2807. return show_focus_cues;
  2808. if (this.parent == null)
  2809. return false;
  2810. Form f = this.FindForm ();
  2811. if (f != null)
  2812. return f.show_focus_cues;
  2813. return false;
  2814. }
  2815. }
  2816. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2817. [Browsable(false)]
  2818. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  2819. internal virtual protected bool ShowKeyboardCues {
  2820. get {
  2821. return ShowKeyboardCuesInternal;
  2822. }
  2823. }
  2824. internal bool ShowKeyboardCuesInternal {
  2825. get {
  2826. if (SystemInformation.MenuAccessKeysUnderlined || DesignMode)
  2827. return true;
  2828. return show_keyboard_cues;
  2829. }
  2830. }
  2831. #endregion // Protected Instance Properties
  2832. #region Public Static Methods
  2833. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2834. public static Control FromChildHandle(IntPtr handle) {
  2835. return Control.ControlNativeWindow.ControlFromChildHandle (handle);
  2836. }
  2837. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2838. public static Control FromHandle(IntPtr handle) {
  2839. return Control.ControlNativeWindow.ControlFromHandle(handle);
  2840. }
  2841. [MonoTODO ("Only implemented for Win32, others always return false")]
  2842. public static bool IsKeyLocked (Keys keyVal)
  2843. {
  2844. switch (keyVal) {
  2845. case Keys.CapsLock:
  2846. case Keys.NumLock:
  2847. case Keys.Scroll:
  2848. return XplatUI.IsKeyLocked ((VirtualKeys)keyVal);
  2849. default:
  2850. throw new NotSupportedException ("keyVal must be CapsLock, NumLock, or ScrollLock");
  2851. }
  2852. }
  2853. public static bool IsMnemonic(char charCode, string text) {
  2854. int amp;
  2855. amp = text.IndexOf('&');
  2856. if (amp != -1) {
  2857. if (amp + 1 < text.Length) {
  2858. if (text[amp + 1] != '&') {
  2859. if (Char.ToUpper(charCode) == Char.ToUpper(text.ToCharArray(amp + 1, 1)[0])) {
  2860. return true;
  2861. }
  2862. }
  2863. }
  2864. }
  2865. return false;
  2866. }
  2867. #endregion
  2868. #region Protected Static Methods
  2869. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2870. protected static bool ReflectMessage(IntPtr hWnd, ref Message m) {
  2871. Control c;
  2872. c = Control.FromHandle(hWnd);
  2873. if (c != null) {
  2874. c.WndProc(ref m);
  2875. return true;
  2876. }
  2877. return false;
  2878. }
  2879. #endregion
  2880. #region Public Instance Methods
  2881. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2882. public IAsyncResult BeginInvoke(Delegate method) {
  2883. object [] prms = null;
  2884. if (method is EventHandler)
  2885. prms = new object [] { this, EventArgs.Empty };
  2886. return BeginInvokeInternal(method, prms);
  2887. }
  2888. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2889. public IAsyncResult BeginInvoke (Delegate method, params object[] args)
  2890. {
  2891. return BeginInvokeInternal (method, args);
  2892. }
  2893. public void BringToFront() {
  2894. if (parent != null) {
  2895. parent.child_controls.SetChildIndex(this, 0);
  2896. }
  2897. else if (IsHandleCreated) {
  2898. XplatUI.SetZOrder(Handle, IntPtr.Zero, false, false);
  2899. }
  2900. }
  2901. public bool Contains(Control ctl) {
  2902. while (ctl != null) {
  2903. ctl = ctl.parent;
  2904. if (ctl == this) {
  2905. return true;
  2906. }
  2907. }
  2908. return false;
  2909. }
  2910. public void CreateControl () {
  2911. if (is_created) {
  2912. return;
  2913. }
  2914. if (is_disposing) {
  2915. return;
  2916. }
  2917. if (!is_visible) {
  2918. return;
  2919. }
  2920. if (parent != null && !parent.Created) {
  2921. return;
  2922. }
  2923. if (!IsHandleCreated) {
  2924. CreateHandle();
  2925. }
  2926. if (!is_created) {
  2927. is_created = true;
  2928. // Create all of our children (implicit ones as well) when we are created.
  2929. // The child should fire it's OnLoad before the parents, however
  2930. // if the child checks Parent.Created in it's OnCreateControl, the
  2931. // parent is already created.
  2932. foreach (Control c in Controls.GetAllControls ())
  2933. if (!c.Created && !c.IsDisposed)
  2934. c.CreateControl ();
  2935. OnCreateControl();
  2936. }
  2937. }
  2938. public Graphics CreateGraphics() {
  2939. if (!IsHandleCreated) {
  2940. this.CreateHandle();
  2941. }
  2942. return Graphics.FromHwnd(this.window.Handle);
  2943. }
  2944. public DragDropEffects DoDragDrop(object data, DragDropEffects allowedEffects) {
  2945. DragDropEffects result = DragDropEffects.None;
  2946. if (IsHandleCreated)
  2947. result = XplatUI.StartDrag(Handle, data, allowedEffects);
  2948. OnDragDropEnd (result);
  2949. return result;
  2950. }
  2951. internal virtual void OnDragDropEnd (DragDropEffects effects)
  2952. {
  2953. }
  2954. [EditorBrowsable(EditorBrowsableState.Advanced)]
  2955. public object EndInvoke (IAsyncResult asyncResult) {
  2956. AsyncMethodResult result = (AsyncMethodResult) asyncResult;
  2957. return result.EndInvoke ();
  2958. }
  2959. internal Control FindRootParent ()
  2960. {
  2961. Control c = this;
  2962. while (c.Parent != null)
  2963. c = c.Parent;
  2964. return c;
  2965. }
  2966. public Form FindForm() {
  2967. Control c;
  2968. c = this;
  2969. while (c != null) {
  2970. if (c is Form) {
  2971. return (Form)c;
  2972. }
  2973. c = c.Parent;
  2974. }
  2975. return null;
  2976. }
  2977. [EditorBrowsable (EditorBrowsableState.Advanced)]
  2978. public bool Focus() {
  2979. return FocusInternal (false);
  2980. }
  2981. internal virtual bool FocusInternal (bool skip_check) {
  2982. if (skip_check || (CanFocus && IsHandleCreated && !has_focus && !is_focusing)) {
  2983. is_focusing = true;
  2984. Select(this);
  2985. is_focusing = false;
  2986. }
  2987. return has_focus;
  2988. }
  2989. internal Control GetRealChildAtPoint (Point pt) {
  2990. if (!IsHandleCreated)
  2991. CreateHandle ();
  2992. foreach (Control control in child_controls.GetAllControls ()) {
  2993. if (control.Bounds.Contains (PointToClient (pt))) {
  2994. Control child = control.GetRealChildAtPoint (pt);
  2995. if (child == null)
  2996. return control;
  2997. else
  2998. return child;
  2999. }
  3000. }
  3001. return null;
  3002. }
  3003. public Control GetChildAtPoint(Point pt)
  3004. {
  3005. return GetChildAtPoint (pt, GetChildAtPointSkip.None);
  3006. }
  3007. public Control GetChildAtPoint (Point pt, GetChildAtPointSkip skipValue)
  3008. {
  3009. // MS's version causes the handle to be created. The stack trace shows that get_Handle is called here, but
  3010. // we'll just call CreateHandle instead.
  3011. if (!IsHandleCreated)
  3012. CreateHandle ();
  3013. // Microsoft's version of this function doesn't seem to work, so I can't check
  3014. // if we only consider children or also grandchildren, etc.
  3015. // I'm gonna say 'children only'
  3016. foreach (Control child in Controls) {
  3017. if ((skipValue & GetChildAtPointSkip.Disabled) == GetChildAtPointSkip.Disabled && !child.Enabled)
  3018. continue;
  3019. else if ((skipValue & GetChildAtPointSkip.Invisible) == GetChildAtPointSkip.Invisible && !child.Visible)
  3020. continue;
  3021. else if ((skipValue & GetChildAtPointSkip.Transparent) == GetChildAtPointSkip.Transparent && child.BackColor.A == 0x0)
  3022. continue;
  3023. else if (child.Bounds.Contains (pt))
  3024. return child;
  3025. }
  3026. return null;
  3027. }
  3028. public IContainerControl GetContainerControl() {
  3029. Control current = this;
  3030. while (current!=null) {
  3031. if ((current is IContainerControl) && ((current.control_style & ControlStyles.ContainerControl)!=0)) {
  3032. return (IContainerControl)current;
  3033. }
  3034. current = current.parent;
  3035. }
  3036. return null;
  3037. }
  3038. internal ContainerControl InternalGetContainerControl() {
  3039. Control current = this;
  3040. while (current!=null) {
  3041. if ((current is ContainerControl) && ((current.control_style & ControlStyles.ContainerControl)!=0)) {
  3042. return current as ContainerControl;
  3043. }
  3044. current = current.parent;
  3045. }
  3046. return null;
  3047. }
  3048. public Control GetNextControl(Control ctl, bool forward) {
  3049. if (!this.Contains(ctl)) {
  3050. ctl = this;
  3051. }
  3052. if (forward) {
  3053. ctl = FindControlForward(this, ctl);
  3054. }
  3055. else {
  3056. ctl = FindControlBackward(this, ctl);
  3057. }
  3058. if (ctl != this) {
  3059. return ctl;
  3060. }
  3061. return null;
  3062. }
  3063. [EditorBrowsable (EditorBrowsableState.Advanced)]
  3064. public virtual Size GetPreferredSize (Size proposedSize) {
  3065. Size retsize = GetPreferredSizeCore (proposedSize);
  3066. // If we're bigger than the MaximumSize, fix that
  3067. if (this.maximum_size.Width != 0 && retsize.Width > this.maximum_size.Width)
  3068. retsize.Width = this.maximum_size.Width;
  3069. if (this.maximum_size.Height != 0 && retsize.Height > this.maximum_size.Height)
  3070. retsize.Height = this.maximum_size.Height;
  3071. // If we're smaller than the MinimumSize, fix that
  3072. if (this.minimum_size.Width != 0 && retsize.Width < this.minimum_size.Width)
  3073. retsize.Width = this.minimum_size.Width;
  3074. if (this.minimum_size.Height != 0 && retsize.Height < this.minimum_size.Height)
  3075. retsize.Height = this.minimum_size.Height;
  3076. return retsize;
  3077. }
  3078. public void Hide() {
  3079. this.Visible = false;
  3080. }
  3081. public void Invalidate ()
  3082. {
  3083. Invalidate (ClientRectangle, false);
  3084. }
  3085. public void Invalidate (bool invalidateChildren)
  3086. {
  3087. Invalidate (ClientRectangle, invalidateChildren);
  3088. }
  3089. public void Invalidate (Rectangle rc)
  3090. {
  3091. Invalidate (rc, false);
  3092. }
  3093. public void Invalidate (Rectangle rc, bool invalidateChildren)
  3094. {
  3095. // Win32 invalidates control including when Width and Height is equal 0
  3096. // or is not visible, only Paint event must be care about this.
  3097. if (!IsHandleCreated)
  3098. return;
  3099. if (rc.IsEmpty)
  3100. rc = ClientRectangle;
  3101. if (rc.Width > 0 && rc.Height > 0) {
  3102. NotifyInvalidate(rc);
  3103. XplatUI.Invalidate(Handle, rc, false);
  3104. if (invalidateChildren) {
  3105. Control [] controls = child_controls.GetAllControls ();
  3106. for (int i=0; i<controls.Length; i++)
  3107. controls [i].Invalidate ();
  3108. } else {
  3109. // If any of our children are transparent, we
  3110. // have to invalidate them anyways
  3111. foreach (Control c in Controls)
  3112. if (c.BackColor.A != 255)
  3113. c.Invalidate ();
  3114. }
  3115. }
  3116. OnInvalidated(new InvalidateEventArgs(rc));
  3117. }
  3118. public void Invalidate (Region region)
  3119. {
  3120. Invalidate (region, false);
  3121. }
  3122. public void Invalidate (Region region, bool invalidateChildren)
  3123. {
  3124. using (Graphics g = CreateGraphics ()){
  3125. RectangleF bounds = region.GetBounds (g);
  3126. Invalidate (new Rectangle ((int) bounds.X, (int) bounds.Y, (int) bounds.Width, (int) bounds.Height), invalidateChildren);
  3127. }
  3128. }
  3129. public object Invoke (Delegate method) {
  3130. object [] prms = null;
  3131. if (method is EventHandler)
  3132. prms = new object [] { this, EventArgs.Empty };
  3133. return Invoke(method, prms);
  3134. }
  3135. public object Invoke (Delegate method, params object [] args) {
  3136. Control control = FindControlToInvokeOn ();
  3137. if (!this.InvokeRequired) {
  3138. return method.DynamicInvoke(args);
  3139. }
  3140. IAsyncResult result = BeginInvokeInternal (method, args, control);
  3141. return EndInvoke(result);
  3142. }
  3143. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3144. public void PerformLayout() {
  3145. PerformLayout(null, null);
  3146. }
  3147. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3148. public void PerformLayout(Control affectedControl, string affectedProperty) {
  3149. LayoutEventArgs levent = new LayoutEventArgs(affectedControl, affectedProperty);
  3150. foreach (Control c in Controls.GetAllControls ())
  3151. if (c.recalculate_distances)
  3152. c.UpdateDistances ();
  3153. if (layout_suspended > 0) {
  3154. layout_pending = true;
  3155. return;
  3156. }
  3157. layout_pending = false;
  3158. // Prevent us from getting messed up
  3159. layout_suspended++;
  3160. // Perform all Dock and Anchor calculations
  3161. try {
  3162. OnLayout(levent);
  3163. }
  3164. // Need to make sure we decremend layout_suspended
  3165. finally {
  3166. layout_suspended--;
  3167. }
  3168. }
  3169. public Point PointToClient (Point p) {
  3170. int x = p.X;
  3171. int y = p.Y;
  3172. XplatUI.ScreenToClient (Handle, ref x, ref y);
  3173. return new Point (x, y);
  3174. }
  3175. public Point PointToScreen(Point p) {
  3176. int x = p.X;
  3177. int y = p.Y;
  3178. XplatUI.ClientToScreen(Handle, ref x, ref y);
  3179. return new Point(x, y);
  3180. }
  3181. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3182. public PreProcessControlState PreProcessControlMessage (ref Message msg)
  3183. {
  3184. return PreProcessControlMessageInternal (ref msg);
  3185. }
  3186. internal PreProcessControlState PreProcessControlMessageInternal (ref Message msg)
  3187. {
  3188. switch ((Msg)msg.Msg) {
  3189. case Msg.WM_KEYDOWN:
  3190. case Msg.WM_SYSKEYDOWN:
  3191. PreviewKeyDownEventArgs e = new PreviewKeyDownEventArgs ((Keys)msg.WParam.ToInt32 () | XplatUI.State.ModifierKeys);
  3192. OnPreviewKeyDown (e);
  3193. if (e.IsInputKey)
  3194. return PreProcessControlState.MessageNeeded;
  3195. if (PreProcessMessage (ref msg))
  3196. return PreProcessControlState.MessageProcessed;
  3197. if (IsInputKey ((Keys)msg.WParam.ToInt32 () | XplatUI.State.ModifierKeys))
  3198. return PreProcessControlState.MessageNeeded;
  3199. break;
  3200. case Msg.WM_CHAR:
  3201. case Msg.WM_SYSCHAR:
  3202. if (PreProcessMessage (ref msg))
  3203. return PreProcessControlState.MessageProcessed;
  3204. if (IsInputChar ((char)msg.WParam))
  3205. return PreProcessControlState.MessageNeeded;
  3206. break;
  3207. default:
  3208. break;
  3209. }
  3210. return PreProcessControlState.MessageNotNeeded;
  3211. }
  3212. public virtual bool PreProcessMessage (ref Message msg)
  3213. {
  3214. return InternalPreProcessMessage (ref msg);
  3215. }
  3216. internal virtual bool InternalPreProcessMessage (ref Message msg) {
  3217. Keys key_data;
  3218. if ((msg.Msg == (int)Msg.WM_KEYDOWN) || (msg.Msg == (int)Msg.WM_SYSKEYDOWN)) {
  3219. key_data = (Keys)msg.WParam.ToInt32() | XplatUI.State.ModifierKeys;
  3220. if (!ProcessCmdKey(ref msg, key_data)) {
  3221. if (IsInputKey(key_data)) {
  3222. return false;
  3223. }
  3224. return ProcessDialogKey(key_data);
  3225. }
  3226. return true;
  3227. } else if (msg.Msg == (int)Msg.WM_CHAR) {
  3228. if (IsInputChar((char)msg.WParam)) {
  3229. return false;
  3230. }
  3231. return ProcessDialogChar((char)msg.WParam);
  3232. } else if (msg.Msg == (int)Msg.WM_SYSCHAR) {
  3233. if (ProcessDialogChar((char)msg.WParam))
  3234. return true;
  3235. else
  3236. return ToolStripManager.ProcessMenuKey (ref msg);
  3237. }
  3238. return false;
  3239. }
  3240. public Rectangle RectangleToClient(Rectangle r) {
  3241. return new Rectangle(PointToClient(r.Location), r.Size);
  3242. }
  3243. public Rectangle RectangleToScreen(Rectangle r) {
  3244. return new Rectangle(PointToScreen(r.Location), r.Size);
  3245. }
  3246. public virtual void Refresh() {
  3247. if (IsHandleCreated && Visible) {
  3248. Invalidate(true);
  3249. Update ();
  3250. }
  3251. }
  3252. [EditorBrowsable(EditorBrowsableState.Never)]
  3253. public virtual void ResetBackColor() {
  3254. BackColor = Color.Empty;
  3255. }
  3256. [EditorBrowsable(EditorBrowsableState.Never)]
  3257. public void ResetBindings() {
  3258. if (data_bindings != null)
  3259. data_bindings.Clear();
  3260. }
  3261. [EditorBrowsable(EditorBrowsableState.Never)]
  3262. public virtual void ResetCursor() {
  3263. Cursor = null;
  3264. }
  3265. [EditorBrowsable(EditorBrowsableState.Never)]
  3266. public virtual void ResetFont() {
  3267. font = null;
  3268. }
  3269. [EditorBrowsable(EditorBrowsableState.Never)]
  3270. public virtual void ResetForeColor() {
  3271. foreground_color = Color.Empty;
  3272. }
  3273. [EditorBrowsable(EditorBrowsableState.Never)]
  3274. public void ResetImeMode() {
  3275. ime_mode = DefaultImeMode;
  3276. }
  3277. [EditorBrowsable(EditorBrowsableState.Never)]
  3278. public virtual void ResetRightToLeft() {
  3279. right_to_left = RightToLeft.Inherit;
  3280. }
  3281. public virtual void ResetText() {
  3282. Text = String.Empty;
  3283. }
  3284. public void ResumeLayout() {
  3285. ResumeLayout (true);
  3286. }
  3287. public void ResumeLayout(bool performLayout) {
  3288. if (layout_suspended > 0) {
  3289. layout_suspended--;
  3290. }
  3291. if (layout_suspended == 0) {
  3292. if (this is ContainerControl)
  3293. (this as ContainerControl).PerformDelayedAutoScale();
  3294. if (!performLayout)
  3295. foreach (Control c in Controls.GetAllControls ())
  3296. c.UpdateDistances ();
  3297. if (performLayout && layout_pending) {
  3298. PerformLayout();
  3299. }
  3300. }
  3301. }
  3302. [EditorBrowsable (EditorBrowsableState.Never)]
  3303. [Obsolete ()]
  3304. public void Scale(float ratio) {
  3305. ScaleCore(ratio, ratio);
  3306. }
  3307. [EditorBrowsable (EditorBrowsableState.Never)]
  3308. [Obsolete ()]
  3309. public void Scale(float dx, float dy) {
  3310. ScaleCore(dx, dy);
  3311. }
  3312. [EditorBrowsable (EditorBrowsableState.Advanced)]
  3313. public void Scale (SizeF factor)
  3314. {
  3315. BoundsSpecified bounds_spec = BoundsSpecified.All;
  3316. SuspendLayout ();
  3317. if (this is ContainerControl) {
  3318. if ((this as ContainerControl).IsAutoScaling)
  3319. bounds_spec = BoundsSpecified.Size;
  3320. else if (IsContainerAutoScaling (this.Parent))
  3321. bounds_spec = BoundsSpecified.Location;
  3322. }
  3323. ScaleControl (factor, bounds_spec);
  3324. // Scale children
  3325. if ((bounds_spec != BoundsSpecified.Location) && ScaleChildren) {
  3326. foreach (Control c in Controls.GetAllControls ()) {
  3327. c.Scale (factor);
  3328. if (c is ContainerControl) {
  3329. ContainerControl cc = c as ContainerControl;
  3330. if ((cc.AutoScaleMode == AutoScaleMode.Inherit) && IsContainerAutoScaling (this))
  3331. cc.PerformAutoScale (true);
  3332. }
  3333. }
  3334. }
  3335. ResumeLayout ();
  3336. }
  3337. internal ContainerControl FindContainer (Control c)
  3338. {
  3339. while ((c != null) && !(c is ContainerControl))
  3340. c = c.Parent;
  3341. return c as ContainerControl;
  3342. }
  3343. private bool IsContainerAutoScaling (Control c)
  3344. {
  3345. ContainerControl cc = FindContainer (c);
  3346. return (cc != null) && cc.IsAutoScaling;
  3347. }
  3348. public void Select() {
  3349. Select(false, false);
  3350. }
  3351. #if DebugFocus
  3352. private void printTree(Control c, string t) {
  3353. foreach(Control i in c.child_controls) {
  3354. Console.WriteLine ("{2}{0}.TabIndex={1}", i, i.tab_index, t);
  3355. printTree (i, t+"\t");
  3356. }
  3357. }
  3358. #endif
  3359. public bool SelectNextControl(Control ctl, bool forward, bool tabStopOnly, bool nested, bool wrap) {
  3360. Control c;
  3361. #if DebugFocus
  3362. Console.WriteLine("{0}", this.FindForm());
  3363. printTree(this, "\t");
  3364. #endif
  3365. if (!this.Contains(ctl) || (!nested && (ctl.parent != this))) {
  3366. ctl = null;
  3367. }
  3368. c = ctl;
  3369. do {
  3370. c = GetNextControl(c, forward);
  3371. if (c == null) {
  3372. if (wrap) {
  3373. wrap = false;
  3374. continue;
  3375. }
  3376. break;
  3377. }
  3378. #if DebugFocus
  3379. Console.WriteLine("{0} {1}", c, c.CanSelect);
  3380. #endif
  3381. if (c.CanSelect && ((c.parent == this) || nested) && (c.tab_stop || !tabStopOnly)) {
  3382. c.Select (true, true);
  3383. return true;
  3384. }
  3385. } while (c != ctl); // If we wrap back to ourselves we stop
  3386. return false;
  3387. }
  3388. public void SendToBack() {
  3389. if (parent != null) {
  3390. parent.child_controls.SetChildIndex(this, parent.child_controls.Count);
  3391. }
  3392. }
  3393. public void SetBounds(int x, int y, int width, int height) {
  3394. SetBounds(x, y, width, height, BoundsSpecified.All);
  3395. }
  3396. public void SetBounds(int x, int y, int width, int height, BoundsSpecified specified) {
  3397. // Fill in the values that were not specified
  3398. if ((specified & BoundsSpecified.X) == 0)
  3399. x = Left;
  3400. if ((specified & BoundsSpecified.Y) == 0)
  3401. y = Top;
  3402. if ((specified & BoundsSpecified.Width) == 0)
  3403. width = Width;
  3404. if ((specified & BoundsSpecified.Height) == 0)
  3405. height = Height;
  3406. SetBoundsInternal (x, y, width, height, specified);
  3407. }
  3408. internal void SetBoundsInternal (int x, int y, int width, int height, BoundsSpecified specified)
  3409. {
  3410. // SetBoundsCore is really expensive to call, so we want to avoid it if we can.
  3411. // We can avoid it if:
  3412. // - The requested dimensions are the same as our current dimensions
  3413. // AND
  3414. // - Any BoundsSpecified is the same as our current explicit_size
  3415. if (bounds.X != x || (explicit_bounds.X != x && (specified & BoundsSpecified.X) == BoundsSpecified.X))
  3416. SetBoundsCore (x, y, width, height, specified);
  3417. else if (bounds.Y != y || (explicit_bounds.Y != y && (specified & BoundsSpecified.Y) == BoundsSpecified.Y))
  3418. SetBoundsCore (x, y, width, height, specified);
  3419. else if (bounds.Width != width || (explicit_bounds.Width != width && (specified & BoundsSpecified.Width) == BoundsSpecified.Width))
  3420. SetBoundsCore (x, y, width, height, specified);
  3421. else if (bounds.Height != height || (explicit_bounds.Height != height && (specified & BoundsSpecified.Height) == BoundsSpecified.Height))
  3422. SetBoundsCore (x, y, width, height, specified);
  3423. else
  3424. return;
  3425. // If the user explicitly moved or resized us, recalculate our anchor distances
  3426. if (specified != BoundsSpecified.None)
  3427. UpdateDistances ();
  3428. if (parent != null)
  3429. parent.PerformLayout(this, "Bounds");
  3430. }
  3431. public void Show () {
  3432. this.Visible = true;
  3433. }
  3434. public void SuspendLayout() {
  3435. layout_suspended++;
  3436. }
  3437. public void Update() {
  3438. if (IsHandleCreated) {
  3439. XplatUI.UpdateWindow(window.Handle);
  3440. }
  3441. }
  3442. #endregion // Public Instance Methods
  3443. #region Protected Instance Methods
  3444. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3445. protected void AccessibilityNotifyClients(AccessibleEvents accEvent, int childID) {
  3446. // turns out this method causes handle
  3447. // creation in 1.1. at first I thought this
  3448. // would be accomplished just by using
  3449. // get_AccessibilityObject, which would route
  3450. // through CreateAccessibilityInstance, which
  3451. // calls CreateControl. This isn't the case,
  3452. // though (as overriding
  3453. // CreateAccessibilityInstance and adding a
  3454. // CWL shows nothing. So we fudge it and put
  3455. // a CreateHandle here.
  3456. if (accessibility_object != null && accessibility_object is ControlAccessibleObject)
  3457. ((ControlAccessibleObject)accessibility_object).NotifyClients (accEvent, childID);
  3458. }
  3459. [EditorBrowsable (EditorBrowsableState.Advanced)]
  3460. protected void AccessibilityNotifyClients (AccessibleEvents accEvent, int objectID, int childID)
  3461. {
  3462. if (accessibility_object != null && accessibility_object is ControlAccessibleObject)
  3463. ((ControlAccessibleObject)accessibility_object).NotifyClients (accEvent, objectID, childID);
  3464. }
  3465. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3466. protected virtual AccessibleObject CreateAccessibilityInstance() {
  3467. CreateControl ();
  3468. return new Control.ControlAccessibleObject(this);
  3469. }
  3470. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3471. protected virtual ControlCollection CreateControlsInstance() {
  3472. return new ControlCollection(this);
  3473. }
  3474. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3475. protected virtual void CreateHandle() {
  3476. if (IsDisposed) {
  3477. throw new ObjectDisposedException(GetType().FullName);
  3478. }
  3479. if (IsHandleCreated && !is_recreating) {
  3480. return;
  3481. }
  3482. CreateParams create_params = CreateParams;
  3483. window.CreateHandle(create_params);
  3484. if (window.Handle != IntPtr.Zero) {
  3485. creator_thread = Thread.CurrentThread;
  3486. XplatUI.EnableWindow(window.Handle, is_enabled);
  3487. if (clip_region != null) {
  3488. XplatUI.SetClipRegion(window.Handle, clip_region);
  3489. }
  3490. // Set our handle with our parent
  3491. if ((parent != null) && (parent.IsHandleCreated)) {
  3492. XplatUI.SetParent(window.Handle, parent.Handle);
  3493. }
  3494. UpdateStyles();
  3495. XplatUI.SetAllowDrop (window.Handle, allow_drop);
  3496. // Find out where the window manager placed us
  3497. if ((CreateParams.Style & (int)WindowStyles.WS_CHILD) != 0) {
  3498. XplatUI.SetBorderStyle(window.Handle, (FormBorderStyle)border_style);
  3499. }
  3500. Rectangle save_bounds = explicit_bounds;
  3501. UpdateBounds ();
  3502. explicit_bounds = save_bounds;
  3503. }
  3504. }
  3505. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3506. protected virtual void DefWndProc(ref Message m) {
  3507. window.DefWndProc(ref m);
  3508. }
  3509. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3510. protected virtual void DestroyHandle() {
  3511. if (IsHandleCreated) {
  3512. if (window != null) {
  3513. window.DestroyHandle();
  3514. }
  3515. }
  3516. }
  3517. protected virtual AccessibleObject GetAccessibilityObjectById (int objectId)
  3518. {
  3519. // XXX need to implement this.
  3520. return null;
  3521. }
  3522. protected internal AutoSizeMode GetAutoSizeMode ()
  3523. {
  3524. return auto_size_mode;
  3525. }
  3526. [EditorBrowsable (EditorBrowsableState.Advanced)]
  3527. protected virtual Rectangle GetScaledBounds (Rectangle bounds, SizeF factor, BoundsSpecified specified)
  3528. {
  3529. // Top level controls do not scale location
  3530. if (!is_toplevel) {
  3531. if ((specified & BoundsSpecified.X) == BoundsSpecified.X)
  3532. bounds.X = (int)Math.Round (bounds.X * factor.Width);
  3533. if ((specified & BoundsSpecified.Y) == BoundsSpecified.Y)
  3534. bounds.Y = (int)Math.Round (bounds.Y * factor.Height);
  3535. }
  3536. if ((specified & BoundsSpecified.Width) == BoundsSpecified.Width && !GetStyle (ControlStyles.FixedWidth)) {
  3537. int border = (this is ComboBox) ? (ThemeEngine.Current.Border3DSize.Width * 2) :
  3538. (this.bounds.Width - this.client_size.Width);
  3539. bounds.Width = (int)Math.Round ((bounds.Width - border) * factor.Width + border);
  3540. }
  3541. if ((specified & BoundsSpecified.Height) == BoundsSpecified.Height && !GetStyle (ControlStyles.FixedHeight)) {
  3542. int border = (this is ComboBox) ? (ThemeEngine.Current.Border3DSize.Height * 2) :
  3543. (this.bounds.Height - this.client_size.Height);
  3544. bounds.Height = (int)Math.Round ((bounds.Height - border) * factor.Height + border);
  3545. }
  3546. return bounds;
  3547. }
  3548. private Rectangle GetScaledBoundsOld (Rectangle bounds, SizeF factor, BoundsSpecified specified)
  3549. {
  3550. RectangleF new_bounds = new RectangleF(bounds.Location, bounds.Size);
  3551. // Top level controls do not scale location
  3552. if (!is_toplevel) {
  3553. if ((specified & BoundsSpecified.X) == BoundsSpecified.X)
  3554. new_bounds.X *= factor.Width;
  3555. if ((specified & BoundsSpecified.Y) == BoundsSpecified.Y)
  3556. new_bounds.Y *= factor.Height;
  3557. }
  3558. if ((specified & BoundsSpecified.Width) == BoundsSpecified.Width && !GetStyle (ControlStyles.FixedWidth)) {
  3559. int border = (this is Form) ? (this.bounds.Width - this.client_size.Width) : 0;
  3560. new_bounds.Width = ((new_bounds.Width - border) * factor.Width + border);
  3561. }
  3562. if ((specified & BoundsSpecified.Height) == BoundsSpecified.Height && !GetStyle (ControlStyles.FixedHeight)) {
  3563. int border = (this is Form) ? (this.bounds.Height - this.client_size.Height) : 0;
  3564. new_bounds.Height = ((new_bounds.Height - border) * factor.Height + border);
  3565. }
  3566. bounds.X = (int)Math.Round (new_bounds.X);
  3567. bounds.Y = (int)Math.Round (new_bounds.Y);
  3568. bounds.Width = (int)Math.Round (new_bounds.Right) - bounds.X;
  3569. bounds.Height = (int)Math.Round (new_bounds.Bottom) - bounds.Y;
  3570. return bounds;
  3571. }
  3572. protected internal bool GetStyle(ControlStyles flag) {
  3573. return (control_style & flag) != 0;
  3574. }
  3575. protected bool GetTopLevel() {
  3576. return is_toplevel;
  3577. }
  3578. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3579. protected virtual void InitLayout() {
  3580. }
  3581. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3582. protected void InvokeGotFocus(Control toInvoke, EventArgs e) {
  3583. toInvoke.OnGotFocus(e);
  3584. }
  3585. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3586. protected void InvokeLostFocus(Control toInvoke, EventArgs e) {
  3587. toInvoke.OnLostFocus(e);
  3588. }
  3589. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3590. protected void InvokeOnClick(Control toInvoke, EventArgs e) {
  3591. toInvoke.OnClick(e);
  3592. }
  3593. protected void InvokePaint(Control c, PaintEventArgs e) {
  3594. c.OnPaint (e);
  3595. }
  3596. protected void InvokePaintBackground(Control c, PaintEventArgs e) {
  3597. c.OnPaintBackground (e);
  3598. }
  3599. protected virtual bool IsInputChar (char charCode) {
  3600. // XXX on MS.NET this method causes the handle to be created..
  3601. if (!IsHandleCreated)
  3602. CreateHandle ();
  3603. return IsInputCharInternal (charCode);
  3604. }
  3605. internal virtual bool IsInputCharInternal (char charCode) {
  3606. return false;
  3607. }
  3608. protected virtual bool IsInputKey (Keys keyData) {
  3609. // Doc says this one calls IsInputChar; not sure what to do with that
  3610. return false;
  3611. }
  3612. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3613. protected virtual void NotifyInvalidate(Rectangle invalidatedArea) {
  3614. // override me?
  3615. }
  3616. protected virtual bool ProcessCmdKey(ref Message msg, Keys keyData) {
  3617. if ((context_menu != null) && context_menu.ProcessCmdKey(ref msg, keyData)) {
  3618. return true;
  3619. }
  3620. if (parent != null) {
  3621. return parent.ProcessCmdKey(ref msg, keyData);
  3622. }
  3623. return false;
  3624. }
  3625. protected virtual bool ProcessDialogChar(char charCode) {
  3626. if (parent != null) {
  3627. return parent.ProcessDialogChar (charCode);
  3628. }
  3629. return false;
  3630. }
  3631. protected virtual bool ProcessDialogKey (Keys keyData) {
  3632. if (parent != null) {
  3633. return parent.ProcessDialogKey (keyData);
  3634. }
  3635. return false;
  3636. }
  3637. protected virtual bool ProcessKeyEventArgs (ref Message m)
  3638. {
  3639. KeyEventArgs key_event;
  3640. switch (m.Msg) {
  3641. case (int)Msg.WM_SYSKEYDOWN:
  3642. case (int)Msg.WM_KEYDOWN: {
  3643. key_event = new KeyEventArgs (((Keys) m.WParam.ToInt32 ()) | XplatUI.State.ModifierKeys);
  3644. OnKeyDown (key_event);
  3645. suppressing_key_press = key_event.SuppressKeyPress;
  3646. return key_event.Handled;
  3647. }
  3648. case (int)Msg.WM_SYSKEYUP:
  3649. case (int)Msg.WM_KEYUP: {
  3650. key_event = new KeyEventArgs (((Keys) m.WParam.ToInt32 ()) | XplatUI.State.ModifierKeys);
  3651. OnKeyUp (key_event);
  3652. return key_event.Handled;
  3653. }
  3654. case (int)Msg.WM_SYSCHAR:
  3655. case (int)Msg.WM_CHAR: {
  3656. if (suppressing_key_press)
  3657. return true;
  3658. KeyPressEventArgs key_press_event;
  3659. key_press_event = new KeyPressEventArgs ((char) m.WParam);
  3660. OnKeyPress(key_press_event);
  3661. m.WParam = (IntPtr) key_press_event.KeyChar;
  3662. return key_press_event.Handled;
  3663. }
  3664. default: {
  3665. break;
  3666. }
  3667. }
  3668. return false;
  3669. }
  3670. protected internal virtual bool ProcessKeyMessage (ref Message m)
  3671. {
  3672. if (parent != null) {
  3673. if (parent.ProcessKeyPreview (ref m))
  3674. return true;
  3675. }
  3676. return ProcessKeyEventArgs (ref m);
  3677. }
  3678. protected virtual bool ProcessKeyPreview (ref Message m) {
  3679. if (parent != null)
  3680. return parent.ProcessKeyPreview(ref m);
  3681. return false;
  3682. }
  3683. protected virtual bool ProcessMnemonic(char charCode) {
  3684. // override me
  3685. return false;
  3686. }
  3687. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3688. protected void RaiseDragEvent(object key, DragEventArgs e) {
  3689. // MS Internal
  3690. }
  3691. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3692. protected void RaiseKeyEvent(object key, KeyEventArgs e) {
  3693. // MS Internal
  3694. }
  3695. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3696. protected void RaiseMouseEvent(object key, MouseEventArgs e) {
  3697. // MS Internal
  3698. }
  3699. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3700. protected void RaisePaintEvent(object key, PaintEventArgs e) {
  3701. // MS Internal
  3702. }
  3703. private void SetIsRecreating () {
  3704. is_recreating=true;
  3705. foreach (Control c in Controls.GetAllControls()) {
  3706. c.SetIsRecreating ();
  3707. }
  3708. }
  3709. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3710. protected void RecreateHandle() {
  3711. if (!IsHandleCreated)
  3712. return;
  3713. #if DebugRecreate
  3714. Console.WriteLine("Recreating control {0}", XplatUI.Window(window.Handle));
  3715. #endif
  3716. SetIsRecreating ();
  3717. if (IsHandleCreated) {
  3718. #if DebugRecreate
  3719. Console.WriteLine(" + handle is created, destroying it.");
  3720. #endif
  3721. DestroyHandle();
  3722. // WM_DESTROY will CreateHandle for us
  3723. } else {
  3724. #if DebugRecreate
  3725. Console.WriteLine(" + handle is not created, creating it.");
  3726. #endif
  3727. if (!is_created) {
  3728. CreateControl();
  3729. } else {
  3730. CreateHandle();
  3731. }
  3732. is_recreating = false;
  3733. #if DebugRecreate
  3734. Console.WriteLine (" + new handle = {0:X}", Handle.ToInt32());
  3735. #endif
  3736. }
  3737. }
  3738. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3739. protected void ResetMouseEventArgs() {
  3740. // MS Internal
  3741. }
  3742. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3743. protected ContentAlignment RtlTranslateAlignment(ContentAlignment align) {
  3744. if (right_to_left == RightToLeft.No) {
  3745. return align;
  3746. }
  3747. switch (align) {
  3748. case ContentAlignment.TopLeft: {
  3749. return ContentAlignment.TopRight;
  3750. }
  3751. case ContentAlignment.TopRight: {
  3752. return ContentAlignment.TopLeft;
  3753. }
  3754. case ContentAlignment.MiddleLeft: {
  3755. return ContentAlignment.MiddleRight;
  3756. }
  3757. case ContentAlignment.MiddleRight: {
  3758. return ContentAlignment.MiddleLeft;
  3759. }
  3760. case ContentAlignment.BottomLeft: {
  3761. return ContentAlignment.BottomRight;
  3762. }
  3763. case ContentAlignment.BottomRight: {
  3764. return ContentAlignment.BottomLeft;
  3765. }
  3766. default: {
  3767. // if it's center it doesn't change
  3768. return align;
  3769. }
  3770. }
  3771. }
  3772. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3773. protected HorizontalAlignment RtlTranslateAlignment(HorizontalAlignment align) {
  3774. if ((right_to_left == RightToLeft.No) || (align == HorizontalAlignment.Center)) {
  3775. return align;
  3776. }
  3777. if (align == HorizontalAlignment.Left) {
  3778. return HorizontalAlignment.Right;
  3779. }
  3780. // align must be HorizontalAlignment.Right
  3781. return HorizontalAlignment.Left;
  3782. }
  3783. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3784. protected LeftRightAlignment RtlTranslateAlignment(LeftRightAlignment align) {
  3785. if (right_to_left == RightToLeft.No) {
  3786. return align;
  3787. }
  3788. if (align == LeftRightAlignment.Left) {
  3789. return LeftRightAlignment.Right;
  3790. }
  3791. // align must be LeftRightAlignment.Right;
  3792. return LeftRightAlignment.Left;
  3793. }
  3794. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3795. protected ContentAlignment RtlTranslateContent(ContentAlignment align) {
  3796. return RtlTranslateAlignment(align);
  3797. }
  3798. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3799. protected HorizontalAlignment RtlTranslateHorizontal(HorizontalAlignment align) {
  3800. return RtlTranslateAlignment(align);
  3801. }
  3802. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3803. protected LeftRightAlignment RtlTranslateLeftRight(LeftRightAlignment align) {
  3804. return RtlTranslateAlignment(align);
  3805. }
  3806. [EditorBrowsable (EditorBrowsableState.Advanced)]
  3807. protected virtual void ScaleControl (SizeF factor, BoundsSpecified specified)
  3808. {
  3809. Rectangle new_bounds = GetScaledBounds (bounds, factor, specified);
  3810. SetBounds (new_bounds.X, new_bounds.Y, new_bounds.Width, new_bounds.Height, specified);
  3811. }
  3812. [EditorBrowsable (EditorBrowsableState.Never)]
  3813. protected virtual void ScaleCore (float dx, float dy)
  3814. {
  3815. Rectangle new_bounds = GetScaledBoundsOld (bounds, new SizeF (dx, dy), BoundsSpecified.All);
  3816. SuspendLayout ();
  3817. SetBounds (new_bounds.X, new_bounds.Y, new_bounds.Width, new_bounds.Height, BoundsSpecified.All);
  3818. if (ScaleChildrenInternal)
  3819. foreach (Control c in Controls.GetAllControls ())
  3820. c.Scale (dx, dy);
  3821. ResumeLayout ();
  3822. }
  3823. protected virtual void Select(bool directed, bool forward) {
  3824. IContainerControl container;
  3825. container = GetContainerControl();
  3826. if (container != null && (Control)container != this)
  3827. container.ActiveControl = this;
  3828. }
  3829. protected void SetAutoSizeMode (AutoSizeMode mode)
  3830. {
  3831. if (auto_size_mode != mode) {
  3832. auto_size_mode = mode;
  3833. PerformLayout (this, "AutoSizeMode");
  3834. }
  3835. }
  3836. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3837. protected virtual void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
  3838. SetBoundsCoreInternal (x, y, width, height, specified);
  3839. }
  3840. internal virtual void SetBoundsCoreInternal(int x, int y, int width, int height, BoundsSpecified specified) {
  3841. // Nasty hack for 2.0 DateTimePicker
  3842. height = OverrideHeight (height);
  3843. Rectangle old_explicit = explicit_bounds;
  3844. Rectangle new_bounds = new Rectangle (x, y, width, height);
  3845. // SetBoundsCore updates the Win32 control itself. UpdateBounds updates the controls variables and fires events, I'm guessing - pdb
  3846. if (IsHandleCreated) {
  3847. XplatUI.SetWindowPos(Handle, x, y, width, height);
  3848. // Win32 automatically changes negative width/height to 0.
  3849. // The control has already been sent a WM_WINDOWPOSCHANGED message and it has the correct
  3850. // data, but it'll be overwritten when we call UpdateBounds unless we get the updated
  3851. // size.
  3852. int cw, ch, ix, iy;
  3853. XplatUI.GetWindowPos(Handle, this is Form, out ix, out iy, out width, out height, out cw, out ch);
  3854. }
  3855. // BoundsSpecified tells us which variables were programatic (user-set).
  3856. // We need to store those in the explicit bounds
  3857. if ((specified & BoundsSpecified.X) == BoundsSpecified.X)
  3858. explicit_bounds.X = new_bounds.X;
  3859. else
  3860. explicit_bounds.X = old_explicit.X;
  3861. if ((specified & BoundsSpecified.Y) == BoundsSpecified.Y)
  3862. explicit_bounds.Y = new_bounds.Y;
  3863. else
  3864. explicit_bounds.Y = old_explicit.Y;
  3865. if ((specified & BoundsSpecified.Width) == BoundsSpecified.Width)
  3866. explicit_bounds.Width = new_bounds.Width;
  3867. else
  3868. explicit_bounds.Width = old_explicit.Width;
  3869. if ((specified & BoundsSpecified.Height) == BoundsSpecified.Height)
  3870. explicit_bounds.Height = new_bounds.Height;
  3871. else
  3872. explicit_bounds.Height = old_explicit.Height;
  3873. // We need to store the explicit bounds because UpdateBounds is always going
  3874. // to change it, and we have to fix it. However, UpdateBounds also calls
  3875. // OnLocationChanged, OnSizeChanged, and OnClientSizeChanged. The user can
  3876. // override those or use those events to change the size explicitly, and we
  3877. // can't undo those changes. So if the bounds after calling UpdateBounds are
  3878. // the same as the ones we sent it, we need to fix the explicit bounds. If
  3879. // it's not the same as we sent UpdateBounds, then someone else changed it, and
  3880. // we better not mess it up. Fun stuff.
  3881. Rectangle stored_explicit_bounds = explicit_bounds;
  3882. UpdateBounds(x, y, width, height);
  3883. if (explicit_bounds.X == x)
  3884. explicit_bounds.X = stored_explicit_bounds.X;
  3885. if (explicit_bounds.Y == y)
  3886. explicit_bounds.Y = stored_explicit_bounds.Y;
  3887. if (explicit_bounds.Width == width)
  3888. explicit_bounds.Width = stored_explicit_bounds.Width;
  3889. if (explicit_bounds.Height == height)
  3890. explicit_bounds.Height = stored_explicit_bounds.Height;
  3891. }
  3892. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3893. protected virtual void SetClientSizeCore(int x, int y) {
  3894. Size NewSize = InternalSizeFromClientSize (new Size (x, y));
  3895. if (NewSize != Size.Empty)
  3896. SetBounds (bounds.X, bounds.Y, NewSize.Width, NewSize.Height, BoundsSpecified.Size);
  3897. }
  3898. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3899. protected internal void SetStyle(ControlStyles flag, bool value) {
  3900. if (value) {
  3901. control_style |= flag;
  3902. } else {
  3903. control_style &= ~flag;
  3904. }
  3905. }
  3906. protected void SetTopLevel(bool value) {
  3907. if ((GetTopLevel() != value) && (parent != null)) {
  3908. throw new ArgumentException ("Cannot change toplevel style of a parented control.");
  3909. }
  3910. if (this is Form) {
  3911. if (IsHandleCreated && value != Visible) {
  3912. Visible = value;
  3913. }
  3914. } else {
  3915. // XXX MS.NET causes handle to be created here
  3916. if (!IsHandleCreated)
  3917. CreateHandle ();
  3918. }
  3919. is_toplevel = value;
  3920. }
  3921. protected virtual void SetVisibleCore(bool value) {
  3922. if (value != is_visible) {
  3923. is_visible = value;
  3924. if (is_visible && ((window.Handle == IntPtr.Zero) || !is_created)) {
  3925. CreateControl();
  3926. if (!(this is Form))
  3927. UpdateZOrder ();
  3928. }
  3929. if (IsHandleCreated) {
  3930. XplatUI.SetVisible (Handle, is_visible, true);
  3931. if (!is_visible) {
  3932. if (parent != null && parent.IsHandleCreated) {
  3933. parent.Invalidate (bounds);
  3934. parent.Update ();
  3935. } else {
  3936. Refresh ();
  3937. }
  3938. } else if (is_visible && this is Form) {
  3939. // If we are Min or Max, we won't get a WM_SHOWWINDOW from SetWindowState,
  3940. // so we need to manually create our children, and set them visible
  3941. // (This normally happens in WmShowWindow.)
  3942. if ((this as Form).WindowState != FormWindowState.Normal)
  3943. OnVisibleChanged (EventArgs.Empty);
  3944. else
  3945. // Explicitly move Toplevel windows to where we want them;
  3946. // apparently moving unmapped toplevel windows doesn't work
  3947. XplatUI.SetWindowPos(window.Handle, bounds.X, bounds.Y, bounds.Width, bounds.Height);
  3948. } else {
  3949. // If we are becoming visible, z-order may have changed while
  3950. // we were invisible, so update our z-order position
  3951. if (parent != null)
  3952. parent.UpdateZOrderOfChild (this);
  3953. }
  3954. if (!(this is Form))
  3955. OnVisibleChanged (EventArgs.Empty);
  3956. }
  3957. else {
  3958. OnVisibleChanged(EventArgs.Empty);
  3959. }
  3960. }
  3961. }
  3962. [EditorBrowsable (EditorBrowsableState.Advanced)]
  3963. protected virtual Size SizeFromClientSize (Size clientSize) {
  3964. return InternalSizeFromClientSize (clientSize);
  3965. }
  3966. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3967. protected void UpdateBounds() {
  3968. if (!IsHandleCreated)
  3969. return;
  3970. int x;
  3971. int y;
  3972. int width;
  3973. int height;
  3974. int client_width;
  3975. int client_height;
  3976. XplatUI.GetWindowPos(this.Handle, this is Form, out x, out y, out width, out height, out client_width, out client_height);
  3977. UpdateBounds(x, y, width, height, client_width, client_height);
  3978. }
  3979. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3980. protected void UpdateBounds(int x, int y, int width, int height) {
  3981. CreateParams cp;
  3982. Rectangle rect;
  3983. // Calculate client rectangle
  3984. rect = new Rectangle(0, 0, 0, 0);
  3985. cp = CreateParams;
  3986. XplatUI.CalculateWindowRect(ref rect, cp, cp.menu, out rect);
  3987. UpdateBounds(x, y, width, height, width - (rect.Right - rect.Left), height - (rect.Bottom - rect.Top));
  3988. }
  3989. [EditorBrowsable(EditorBrowsableState.Advanced)]
  3990. protected void UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) {
  3991. // UpdateBounds only seems to set our sizes and fire events but not update the GUI window to match
  3992. bool moved = false;
  3993. bool resized = false;
  3994. // Needed to generate required notifications
  3995. if ((this.bounds.X!=x) || (this.bounds.Y!=y)) {
  3996. moved=true;
  3997. }
  3998. if ((this.Bounds.Width!=width) || (this.Bounds.Height!=height)) {
  3999. resized=true;
  4000. }
  4001. bounds.X=x;
  4002. bounds.Y=y;
  4003. bounds.Width=width;
  4004. bounds.Height=height;
  4005. // Assume explicit bounds set. SetBoundsCore will restore old bounds
  4006. // if needed.
  4007. explicit_bounds = bounds;
  4008. client_size.Width=clientWidth;
  4009. client_size.Height=clientHeight;
  4010. if (moved) {
  4011. OnLocationChanged(EventArgs.Empty);
  4012. if (!background_color.IsEmpty && background_color.A < byte.MaxValue)
  4013. Invalidate ();
  4014. }
  4015. if (resized) {
  4016. OnSizeInitializedOrChanged ();
  4017. OnSizeChanged(EventArgs.Empty);
  4018. OnClientSizeChanged (EventArgs.Empty);
  4019. }
  4020. }
  4021. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4022. protected void UpdateStyles() {
  4023. if (!IsHandleCreated) {
  4024. return;
  4025. }
  4026. XplatUI.SetWindowStyle(window.Handle, CreateParams);
  4027. OnStyleChanged(EventArgs.Empty);
  4028. }
  4029. private void UpdateZOrderOfChild(Control child) {
  4030. if (IsHandleCreated && child.IsHandleCreated && (child.parent == this) && Hwnd.ObjectFromHandle(child.Handle).Mapped) {
  4031. // Need to take into account all controls
  4032. Control [] all_controls = child_controls.GetAllControls ();
  4033. int index = Array.IndexOf (all_controls, child);
  4034. for (; index > 0; index--) {
  4035. if (!all_controls [index - 1].IsHandleCreated || !all_controls [index - 1].VisibleInternal || !Hwnd.ObjectFromHandle(all_controls [index - 1].Handle).Mapped)
  4036. continue;
  4037. break;
  4038. }
  4039. if (index > 0) {
  4040. XplatUI.SetZOrder(child.Handle, all_controls [index - 1].Handle, false, false);
  4041. } else {
  4042. IntPtr after = AfterTopMostControl ();
  4043. if (after != IntPtr.Zero && after != child.Handle)
  4044. XplatUI.SetZOrder (child.Handle, after, false, false);
  4045. else
  4046. XplatUI.SetZOrder (child.Handle, IntPtr.Zero, true, false);
  4047. }
  4048. }
  4049. }
  4050. // Override this if there is a control that shall always remain on
  4051. // top of other controls (such as scrollbars). If there are several
  4052. // of these controls, the bottom-most should be returned.
  4053. internal virtual IntPtr AfterTopMostControl () {
  4054. return IntPtr.Zero;
  4055. }
  4056. // internal because we need to call it from ScrollableControl.OnVisibleChanged
  4057. internal void UpdateChildrenZOrder() {
  4058. Control [] controls;
  4059. if (!IsHandleCreated) {
  4060. return;
  4061. }
  4062. // XXX This code is severely broken. It leaks
  4063. // the "zero_sized" abstraction out of the X11
  4064. // backend and into Control.cs. It'll work on
  4065. // windows simply by virtue of windows never
  4066. // setting that field to true.
  4067. //
  4068. // basically what we need to guard against is
  4069. // calling XplatUI.SetZOrder on an hwnd that
  4070. // corresponds to an unmapped X window.
  4071. //
  4072. // Also, explicitly send implicit controls to the back.
  4073. if (child_controls.ImplicitControls == null) {
  4074. controls = new Control [child_controls.Count];
  4075. child_controls.CopyTo (controls, 0);
  4076. } else {
  4077. controls = new Control [child_controls.Count + child_controls.ImplicitControls.Count];
  4078. child_controls.CopyTo (controls, 0);
  4079. child_controls.ImplicitControls.CopyTo (controls, child_controls.Count);
  4080. }
  4081. ArrayList children_to_order = new ArrayList ();
  4082. for (int i = 0; i < controls.Length; i ++) {
  4083. if (!controls[i].IsHandleCreated || !controls[i].VisibleInternal)
  4084. continue;
  4085. Hwnd hwnd = Hwnd.ObjectFromHandle (controls[i].Handle);
  4086. if (hwnd == null || hwnd.zero_sized)
  4087. continue;
  4088. children_to_order.Add (controls[i]);
  4089. }
  4090. for (int i = 1; i < children_to_order.Count; i ++) {
  4091. Control upper = (Control)children_to_order[i-1];
  4092. Control lower = (Control)children_to_order[i];
  4093. XplatUI.SetZOrder(lower.Handle, upper.Handle, false, false);
  4094. }
  4095. }
  4096. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4097. protected void UpdateZOrder() {
  4098. if (parent != null) {
  4099. parent.UpdateZOrderOfChild(this);
  4100. }
  4101. }
  4102. protected virtual void WndProc(ref Message m) {
  4103. #if DebugMessages
  4104. Console.WriteLine("Control {0} received message {1}", window.Handle == IntPtr.Zero ? this.Text : XplatUI.Window(window.Handle), m.ToString ());
  4105. #endif
  4106. if ((this.control_style & ControlStyles.EnableNotifyMessage) != 0) {
  4107. OnNotifyMessage(m);
  4108. }
  4109. switch((Msg)m.Msg) {
  4110. case Msg.WM_DESTROY: {
  4111. WmDestroy(ref m);
  4112. return;
  4113. }
  4114. case Msg.WM_WINDOWPOSCHANGED: {
  4115. WmWindowPosChanged(ref m);
  4116. return;
  4117. }
  4118. // Nice description of what should happen when handling WM_PAINT
  4119. // can be found here: http://pluralsight.com/wiki/default.aspx/Craig/FlickerFreeControlDrawing.html
  4120. // and here http://msdn.microsoft.com/msdnmag/issues/06/03/WindowsFormsPerformance/
  4121. case Msg.WM_PAINT: {
  4122. WmPaint (ref m);
  4123. return;
  4124. }
  4125. // The DefWndProc will never have to handle this, we always paint the background in managed code
  4126. // In theory this code would look at ControlStyles.AllPaintingInWmPaint and and call OnPaintBackground
  4127. // here but it just makes things more complicated...
  4128. case Msg.WM_ERASEBKGND: {
  4129. WmEraseBackground (ref m);
  4130. return;
  4131. }
  4132. case Msg.WM_LBUTTONUP: {
  4133. WmLButtonUp (ref m);
  4134. return;
  4135. }
  4136. case Msg.WM_LBUTTONDOWN: {
  4137. WmLButtonDown (ref m);
  4138. return;
  4139. }
  4140. case Msg.WM_LBUTTONDBLCLK: {
  4141. WmLButtonDblClick (ref m);
  4142. return;
  4143. }
  4144. case Msg.WM_MBUTTONUP: {
  4145. WmMButtonUp (ref m);
  4146. return;
  4147. }
  4148. case Msg.WM_MBUTTONDOWN: {
  4149. WmMButtonDown (ref m);
  4150. return;
  4151. }
  4152. case Msg.WM_MBUTTONDBLCLK: {
  4153. WmMButtonDblClick (ref m);
  4154. return;
  4155. }
  4156. case Msg.WM_RBUTTONUP: {
  4157. WmRButtonUp (ref m);
  4158. return;
  4159. }
  4160. case Msg.WM_RBUTTONDOWN: {
  4161. WmRButtonDown (ref m);
  4162. return;
  4163. }
  4164. case Msg.WM_RBUTTONDBLCLK: {
  4165. WmRButtonDblClick (ref m);
  4166. return;
  4167. }
  4168. case Msg.WM_CONTEXTMENU: {
  4169. WmContextMenu (ref m);
  4170. return;
  4171. }
  4172. case Msg.WM_MOUSEWHEEL: {
  4173. WmMouseWheel (ref m);
  4174. return;
  4175. }
  4176. case Msg.WM_MOUSEMOVE: {
  4177. WmMouseMove (ref m);
  4178. return;
  4179. }
  4180. case Msg.WM_SHOWWINDOW: {
  4181. WmShowWindow (ref m);
  4182. return;
  4183. }
  4184. case Msg.WM_CREATE: {
  4185. WmCreate (ref m);
  4186. return;
  4187. }
  4188. case Msg.WM_MOUSE_ENTER: {
  4189. WmMouseEnter (ref m);
  4190. return;
  4191. }
  4192. case Msg.WM_MOUSELEAVE: {
  4193. WmMouseLeave (ref m);
  4194. return;
  4195. }
  4196. case Msg.WM_MOUSEHOVER: {
  4197. WmMouseHover (ref m);
  4198. return;
  4199. }
  4200. case Msg.WM_SYSKEYUP: {
  4201. WmSysKeyUp (ref m);
  4202. return;
  4203. }
  4204. case Msg.WM_SYSKEYDOWN:
  4205. case Msg.WM_KEYDOWN:
  4206. case Msg.WM_KEYUP:
  4207. case Msg.WM_SYSCHAR:
  4208. case Msg.WM_CHAR: {
  4209. WmKeys (ref m);
  4210. return;
  4211. }
  4212. case Msg.WM_HELP: {
  4213. WmHelp (ref m);
  4214. return;
  4215. }
  4216. case Msg.WM_KILLFOCUS: {
  4217. WmKillFocus (ref m);
  4218. return;
  4219. }
  4220. case Msg.WM_SETFOCUS: {
  4221. WmSetFocus (ref m);
  4222. return;
  4223. }
  4224. case Msg.WM_SYSCOLORCHANGE: {
  4225. WmSysColorChange (ref m);
  4226. return;
  4227. }
  4228. case Msg.WM_SETCURSOR: {
  4229. WmSetCursor (ref m);
  4230. return;
  4231. }
  4232. case Msg.WM_CAPTURECHANGED: {
  4233. WmCaptureChanged (ref m);
  4234. return;
  4235. }
  4236. case Msg.WM_CHANGEUISTATE: {
  4237. WmChangeUIState (ref m);
  4238. return;
  4239. }
  4240. case Msg.WM_UPDATEUISTATE: {
  4241. WmUpdateUIState (ref m);
  4242. return;
  4243. }
  4244. default:
  4245. DefWndProc(ref m);
  4246. return;
  4247. }
  4248. }
  4249. #endregion // Public Instance Methods
  4250. #region WM methods
  4251. private void WmDestroy (ref Message m) {
  4252. OnHandleDestroyed(EventArgs.Empty);
  4253. #if DebugRecreate
  4254. IntPtr handle = window.Handle;
  4255. #endif
  4256. window.InvalidateHandle();
  4257. is_created = false;
  4258. if (is_recreating) {
  4259. #if DebugRecreate
  4260. Console.WriteLine ("Creating handle for {0:X}", handle.ToInt32());
  4261. #endif
  4262. CreateHandle();
  4263. #if DebugRecreate
  4264. Console.WriteLine (" + new handle = {0:X}", Handle.ToInt32());
  4265. #endif
  4266. is_recreating = false;
  4267. }
  4268. if (is_disposing) {
  4269. is_disposing = false;
  4270. is_visible = false;
  4271. }
  4272. }
  4273. private void WmWindowPosChanged (ref Message m) {
  4274. if (Visible) {
  4275. Rectangle save_bounds = explicit_bounds;
  4276. UpdateBounds();
  4277. explicit_bounds = save_bounds;
  4278. if (GetStyle(ControlStyles.ResizeRedraw)) {
  4279. Invalidate();
  4280. }
  4281. }
  4282. }
  4283. // Nice description of what should happen when handling WM_PAINT
  4284. // can be found here: http://pluralsight.com/wiki/default.aspx/Craig/FlickerFreeControlDrawing.html
  4285. // and here http://msdn.microsoft.com/msdnmag/issues/06/03/WindowsFormsPerformance/
  4286. private void WmPaint (ref Message m) {
  4287. IntPtr handle = Handle;
  4288. PaintEventArgs paint_event = XplatUI.PaintEventStart (ref m, handle, true);
  4289. if (paint_event == null)
  4290. return;
  4291. DoubleBuffer current_buffer = null;
  4292. if (UseDoubleBuffering) {
  4293. current_buffer = GetBackBuffer ();
  4294. // This optimization doesn't work when the area is invalidated
  4295. // during a paint operation because finishing the paint operation
  4296. // clears the invalidated region and then this thing keeps the new
  4297. // invalidate from working. To re-enable this, we would need a
  4298. // mechanism to allow for nested invalidates (see bug #328681)
  4299. //if (!current_buffer.InvalidRegion.IsVisible (paint_event.ClipRectangle)) {
  4300. // // Just blit the previous image
  4301. // current_buffer.Blit (paint_event);
  4302. // XplatUI.PaintEventEnd (ref m, handle, true);
  4303. // return;
  4304. //}
  4305. current_buffer.Start (paint_event);
  4306. }
  4307. // If using OptimizedDoubleBuffer, ensure the clip region gets set
  4308. if (GetStyle (ControlStyles.OptimizedDoubleBuffer))
  4309. paint_event.Graphics.SetClip (Rectangle.Intersect (paint_event.ClipRectangle, this.ClientRectangle));
  4310. if (!GetStyle(ControlStyles.Opaque)) {
  4311. OnPaintBackground (paint_event);
  4312. }
  4313. // Button-derived controls choose to ignore their Opaque style, give them a chance to draw their background anyways
  4314. OnPaintBackgroundInternal (paint_event);
  4315. OnPaintInternal(paint_event);
  4316. if (!paint_event.Handled) {
  4317. OnPaint (paint_event);
  4318. }
  4319. if (current_buffer != null) {
  4320. current_buffer.End (paint_event);
  4321. }
  4322. XplatUI.PaintEventEnd (ref m, handle, true);
  4323. }
  4324. private void WmEraseBackground (ref Message m) {
  4325. // The DefWndProc will never have to handle this, we always paint the background in managed code
  4326. // In theory this code would look at ControlStyles.AllPaintingInWmPaint and and call OnPaintBackground
  4327. // here but it just makes things more complicated...
  4328. m.Result = (IntPtr)1;
  4329. }
  4330. private void WmLButtonUp (ref Message m)
  4331. {
  4332. // Menu handle.
  4333. if (XplatUI.IsEnabled (Handle) && active_tracker != null) {
  4334. ProcessActiveTracker (ref m);
  4335. return;
  4336. }
  4337. MouseEventArgs me;
  4338. me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Left,
  4339. mouse_clicks,
  4340. LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
  4341. 0);
  4342. HandleClick(mouse_clicks, me);
  4343. OnMouseUp (me);
  4344. if (InternalCapture) {
  4345. InternalCapture = false;
  4346. }
  4347. if (mouse_clicks > 1) {
  4348. mouse_clicks = 1;
  4349. }
  4350. }
  4351. private void WmLButtonDown (ref Message m)
  4352. {
  4353. // Menu handle.
  4354. if (XplatUI.IsEnabled (Handle) && active_tracker != null) {
  4355. ProcessActiveTracker (ref m);
  4356. return;
  4357. }
  4358. ValidationFailed = false;
  4359. if (CanSelect) {
  4360. Select (true, true);
  4361. }
  4362. if (!ValidationFailed) {
  4363. InternalCapture = true;
  4364. OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
  4365. mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
  4366. 0));
  4367. }
  4368. }
  4369. private void WmLButtonDblClick (ref Message m) {
  4370. InternalCapture = true;
  4371. mouse_clicks++;
  4372. OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
  4373. mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
  4374. 0));
  4375. }
  4376. private void WmMButtonUp (ref Message m) {
  4377. MouseEventArgs me;
  4378. me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Middle,
  4379. mouse_clicks,
  4380. LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
  4381. 0);
  4382. HandleClick(mouse_clicks, me);
  4383. OnMouseUp (me);
  4384. if (InternalCapture) {
  4385. InternalCapture = false;
  4386. }
  4387. if (mouse_clicks > 1) {
  4388. mouse_clicks = 1;
  4389. }
  4390. }
  4391. private void WmMButtonDown (ref Message m) {
  4392. InternalCapture = true;
  4393. OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
  4394. mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
  4395. 0));
  4396. }
  4397. private void WmMButtonDblClick (ref Message m) {
  4398. InternalCapture = true;
  4399. mouse_clicks++;
  4400. OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
  4401. mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
  4402. 0));
  4403. }
  4404. private void WmRButtonUp (ref Message m)
  4405. {
  4406. // Menu handle.
  4407. if (XplatUI.IsEnabled (Handle) && active_tracker != null) {
  4408. ProcessActiveTracker (ref m);
  4409. return;
  4410. }
  4411. MouseEventArgs me;
  4412. Point pt;
  4413. pt = new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()));
  4414. pt = PointToScreen(pt);
  4415. me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Right,
  4416. mouse_clicks,
  4417. LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
  4418. 0);
  4419. HandleClick(mouse_clicks, me);
  4420. XplatUI.SendMessage(m.HWnd, Msg.WM_CONTEXTMENU, m.HWnd, (IntPtr)(pt.X + (pt.Y << 16)));
  4421. OnMouseUp (me);
  4422. if (InternalCapture) {
  4423. InternalCapture = false;
  4424. }
  4425. if (mouse_clicks > 1) {
  4426. mouse_clicks = 1;
  4427. }
  4428. }
  4429. private void WmRButtonDown (ref Message m)
  4430. {
  4431. // Menu handle.
  4432. if (XplatUI.IsEnabled (Handle) && active_tracker != null) {
  4433. ProcessActiveTracker (ref m);
  4434. return;
  4435. }
  4436. InternalCapture = true;
  4437. OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
  4438. mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
  4439. 0));
  4440. }
  4441. private void WmRButtonDblClick (ref Message m) {
  4442. InternalCapture = true;
  4443. mouse_clicks++;
  4444. OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
  4445. mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
  4446. 0));
  4447. }
  4448. private void WmContextMenu (ref Message m) {
  4449. if (context_menu != null) {
  4450. Point pt;
  4451. pt = new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()));
  4452. if (pt.X == -1 || pt.Y == -1) {
  4453. pt.X = (this.Width / 2) + this.Left;
  4454. pt.Y = (this.Height / 2) + this.Top;
  4455. pt = this.PointToScreen (pt);
  4456. }
  4457. context_menu.Show (this, PointToClient (pt));
  4458. return;
  4459. }
  4460. // If there isn't a regular context menu, show the Strip version
  4461. if (context_menu == null && context_menu_strip != null) {
  4462. Point pt;
  4463. pt = new Point (LowOrder ((int)m.LParam.ToInt32 ()), HighOrder ((int)m.LParam.ToInt32 ()));
  4464. if (pt.X == -1 || pt.Y == -1) {
  4465. pt.X = (this.Width / 2) + this.Left;
  4466. pt.Y = (this.Height /2) + this.Top;
  4467. pt = this.PointToScreen (pt);
  4468. }
  4469. context_menu_strip.SetSourceControl (this);
  4470. context_menu_strip.Show (this, PointToClient (pt));
  4471. return;
  4472. }
  4473. DefWndProc(ref m);
  4474. }
  4475. private void WmCreate (ref Message m) {
  4476. OnHandleCreated(EventArgs.Empty);
  4477. }
  4478. private void WmMouseWheel (ref Message m) {
  4479. DefWndProc(ref m);
  4480. OnMouseWheel (new MouseEventArgs (FromParamToMouseButtons ((long) m.WParam),
  4481. mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
  4482. HighOrder((long)m.WParam)));
  4483. }
  4484. private void WmMouseMove (ref Message m) {
  4485. if (XplatUI.IsEnabled (Handle) && active_tracker != null) {
  4486. MouseEventArgs args = new MouseEventArgs (
  4487. FromParamToMouseButtons ((int)m.WParam.ToInt32 ()),
  4488. mouse_clicks,
  4489. Control.MousePosition.X,
  4490. Control.MousePosition.Y,
  4491. 0);
  4492. active_tracker.OnMotion (args);
  4493. return;
  4494. }
  4495. OnMouseMove (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
  4496. mouse_clicks,
  4497. LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
  4498. 0));
  4499. }
  4500. private void WmMouseEnter (ref Message m) {
  4501. if (is_entered) {
  4502. return;
  4503. }
  4504. is_entered = true;
  4505. OnMouseEnter(EventArgs.Empty);
  4506. }
  4507. private void WmMouseLeave (ref Message m) {
  4508. is_entered=false;
  4509. OnMouseLeave(EventArgs.Empty);
  4510. }
  4511. private void WmMouseHover (ref Message m) {
  4512. OnMouseHover(EventArgs.Empty);
  4513. }
  4514. private void WmShowWindow (ref Message m) {
  4515. if (IsDisposed)
  4516. return;
  4517. Form frm = this as Form;
  4518. if (m.WParam.ToInt32() != 0) {
  4519. if (m.LParam.ToInt32 () == 0) {
  4520. CreateControl ();
  4521. // Make sure all our children are properly parented to us
  4522. Control [] controls = child_controls.GetAllControls ();
  4523. // bool parented = false;
  4524. for (int i=0; i<controls.Length; i++) {
  4525. if (controls [i].is_visible && controls[i].IsHandleCreated)
  4526. if (XplatUI.GetParent (controls[i].Handle) != window.Handle) {
  4527. XplatUI.SetParent(controls[i].Handle, window.Handle);
  4528. // parented = true;
  4529. }
  4530. }
  4531. //if (parented)
  4532. UpdateChildrenZOrder ();
  4533. }
  4534. } else {
  4535. if (parent != null && Focused) {
  4536. Control container;
  4537. // Need to start at parent, GetContainerControl might return ourselves if we're a container
  4538. container = (Control)parent.GetContainerControl();
  4539. if (container != null && (frm == null || !frm.IsMdiChild)) {
  4540. container.SelectNextControl(this, true, true, true, true);
  4541. }
  4542. }
  4543. }
  4544. if (frm != null)
  4545. frm.waiting_showwindow = false;
  4546. // If the form is Max/Min, it got its OnVisibleChanged in SetVisibleCore
  4547. if (frm != null) {
  4548. if (!IsRecreating && (frm.IsMdiChild || frm.WindowState == FormWindowState.Normal)) /* XXX make sure this works for mdi forms */
  4549. OnVisibleChanged(EventArgs.Empty);
  4550. } else if (is_toplevel)
  4551. OnVisibleChanged(EventArgs.Empty);
  4552. }
  4553. private void WmSysKeyUp (ref Message m) {
  4554. if (ProcessKeyMessage(ref m)) {
  4555. m.Result = IntPtr.Zero;
  4556. return;
  4557. }
  4558. if ((m.WParam.ToInt32() & (int)Keys.KeyCode) == (int)Keys.Menu) {
  4559. Form form;
  4560. form = FindForm();
  4561. if (form != null && form.ActiveMenu != null) {
  4562. form.ActiveMenu.ProcessCmdKey(ref m, (Keys)m.WParam.ToInt32());
  4563. }
  4564. else
  4565. if (ToolStripManager.ProcessMenuKey (ref m))
  4566. return;
  4567. }
  4568. DefWndProc (ref m);
  4569. }
  4570. private void WmKeys (ref Message m)
  4571. {
  4572. if (ProcessKeyMessage(ref m)) {
  4573. m.Result = IntPtr.Zero;
  4574. return;
  4575. }
  4576. DefWndProc (ref m);
  4577. }
  4578. private void WmHelp (ref Message m) {
  4579. Point mouse_pos;
  4580. if (m.LParam != IntPtr.Zero) {
  4581. HELPINFO hi;
  4582. hi = new HELPINFO();
  4583. hi = (HELPINFO) Marshal.PtrToStructure (m.LParam, typeof (HELPINFO));
  4584. mouse_pos = new Point(hi.MousePos.x, hi.MousePos.y);
  4585. } else {
  4586. mouse_pos = Control.MousePosition;
  4587. }
  4588. OnHelpRequested(new HelpEventArgs(mouse_pos));
  4589. m.Result = (IntPtr)1;
  4590. }
  4591. private void WmKillFocus (ref Message m) {
  4592. this.has_focus = false;
  4593. OnLostFocus (EventArgs.Empty);
  4594. }
  4595. private void WmSetFocus (ref Message m) {
  4596. if (!has_focus) {
  4597. this.has_focus = true;
  4598. OnGotFocus (EventArgs.Empty);
  4599. }
  4600. }
  4601. private void WmSysColorChange (ref Message m) {
  4602. ThemeEngine.Current.ResetDefaults();
  4603. OnSystemColorsChanged(EventArgs.Empty);
  4604. }
  4605. private void WmSetCursor (ref Message m) {
  4606. if ((cursor == null && use_wait_cursor == false) || ((HitTest)(m.LParam.ToInt32() & 0xffff) != HitTest.HTCLIENT)) {
  4607. DefWndProc(ref m);
  4608. return;
  4609. }
  4610. XplatUI.SetCursor(window.Handle, Cursor.handle);
  4611. m.Result = (IntPtr)1;
  4612. }
  4613. private void WmCaptureChanged (ref Message m) {
  4614. is_captured = false;
  4615. OnMouseCaptureChanged (EventArgs.Empty);
  4616. m.Result = (IntPtr) 0;
  4617. }
  4618. private void WmChangeUIState (ref Message m) {
  4619. foreach (Control control in Controls) {
  4620. XplatUI.SendMessage (control.Handle, Msg.WM_UPDATEUISTATE, m.WParam, m.LParam);
  4621. }
  4622. }
  4623. private void WmUpdateUIState (ref Message m) {
  4624. int action = LowOrder (m.WParam.ToInt32 ());
  4625. int element = HighOrder (m.WParam.ToInt32 ());
  4626. if (action == (int) MsgUIState.UIS_INITIALIZE)
  4627. return;
  4628. UICues cues = UICues.None;
  4629. if ((element & (int) MsgUIState.UISF_HIDEACCEL) != 0) {
  4630. if ((action == (int) MsgUIState.UIS_CLEAR) != show_keyboard_cues) {
  4631. cues |= UICues.ChangeKeyboard;
  4632. show_keyboard_cues = (action == (int) MsgUIState.UIS_CLEAR);
  4633. }
  4634. }
  4635. if ((element & (int) MsgUIState.UISF_HIDEFOCUS) != 0) {
  4636. if ((action == (int) MsgUIState.UIS_CLEAR) != show_focus_cues) {
  4637. cues |= UICues.ChangeFocus;
  4638. show_focus_cues = (action == (int) MsgUIState.UIS_CLEAR);
  4639. }
  4640. }
  4641. if ((cues & UICues.Changed) != UICues.None) {
  4642. OnChangeUICues (new UICuesEventArgs (cues));
  4643. Invalidate ();
  4644. }
  4645. }
  4646. #endregion
  4647. #region OnXXX methods
  4648. protected virtual void OnAutoSizeChanged (EventArgs e)
  4649. {
  4650. EventHandler eh = (EventHandler)(Events[AutoSizeChangedEvent]);
  4651. if (eh != null)
  4652. eh (this, e);
  4653. }
  4654. [EditorBrowsable (EditorBrowsableState.Advanced)]
  4655. protected virtual void OnBackColorChanged(EventArgs e) {
  4656. EventHandler eh = (EventHandler)(Events [BackColorChangedEvent]);
  4657. if (eh != null)
  4658. eh (this, e);
  4659. for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackColorChanged(e);
  4660. }
  4661. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4662. protected virtual void OnBackgroundImageChanged(EventArgs e) {
  4663. EventHandler eh = (EventHandler)(Events [BackgroundImageChangedEvent]);
  4664. if (eh != null)
  4665. eh (this, e);
  4666. for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackgroundImageChanged(e);
  4667. }
  4668. [EditorBrowsable (EditorBrowsableState.Advanced)]
  4669. protected virtual void OnBackgroundImageLayoutChanged (EventArgs e)
  4670. {
  4671. EventHandler eh = (EventHandler)(Events[BackgroundImageLayoutChangedEvent]);
  4672. if (eh != null)
  4673. eh (this, e);
  4674. }
  4675. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4676. protected virtual void OnBindingContextChanged(EventArgs e) {
  4677. CheckDataBindings ();
  4678. EventHandler eh = (EventHandler)(Events [BindingContextChangedEvent]);
  4679. if (eh != null)
  4680. eh (this, e);
  4681. for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBindingContextChanged(e);
  4682. }
  4683. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4684. protected virtual void OnCausesValidationChanged(EventArgs e) {
  4685. EventHandler eh = (EventHandler)(Events [CausesValidationChangedEvent]);
  4686. if (eh != null)
  4687. eh (this, e);
  4688. }
  4689. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4690. protected virtual void OnChangeUICues(UICuesEventArgs e) {
  4691. UICuesEventHandler eh = (UICuesEventHandler)(Events [ChangeUICuesEvent]);
  4692. if (eh != null)
  4693. eh (this, e);
  4694. }
  4695. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4696. protected virtual void OnClick(EventArgs e) {
  4697. EventHandler eh = (EventHandler)(Events [ClickEvent]);
  4698. if (eh != null)
  4699. eh (this, e);
  4700. }
  4701. [EditorBrowsable (EditorBrowsableState.Advanced)]
  4702. protected virtual void OnClientSizeChanged (EventArgs e)
  4703. {
  4704. EventHandler eh = (EventHandler)(Events[ClientSizeChangedEvent]);
  4705. if (eh != null)
  4706. eh (this, e);
  4707. }
  4708. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4709. protected virtual void OnContextMenuChanged(EventArgs e) {
  4710. EventHandler eh = (EventHandler)(Events [ContextMenuChangedEvent]);
  4711. if (eh != null)
  4712. eh (this, e);
  4713. }
  4714. [EditorBrowsable (EditorBrowsableState.Advanced)]
  4715. protected virtual void OnContextMenuStripChanged (EventArgs e) {
  4716. EventHandler eh = (EventHandler)(Events [ContextMenuStripChangedEvent]);
  4717. if (eh != null)
  4718. eh (this, e);
  4719. }
  4720. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4721. protected virtual void OnControlAdded(ControlEventArgs e) {
  4722. ControlEventHandler eh = (ControlEventHandler)(Events [ControlAddedEvent]);
  4723. if (eh != null)
  4724. eh (this, e);
  4725. }
  4726. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4727. protected virtual void OnControlRemoved(ControlEventArgs e) {
  4728. ControlEventHandler eh = (ControlEventHandler)(Events [ControlRemovedEvent]);
  4729. if (eh != null)
  4730. eh (this, e);
  4731. }
  4732. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4733. protected virtual void OnCreateControl() {
  4734. // Override me!
  4735. }
  4736. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4737. protected virtual void OnCursorChanged(EventArgs e) {
  4738. EventHandler eh = (EventHandler)(Events [CursorChangedEvent]);
  4739. if (eh != null)
  4740. eh (this, e);
  4741. for (int i = 0; i < child_controls.Count; i++) child_controls[i].OnParentCursorChanged (e);
  4742. }
  4743. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4744. protected virtual void OnDockChanged(EventArgs e) {
  4745. EventHandler eh = (EventHandler)(Events [DockChangedEvent]);
  4746. if (eh != null)
  4747. eh (this, e);
  4748. }
  4749. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4750. protected virtual void OnDoubleClick(EventArgs e) {
  4751. EventHandler eh = (EventHandler)(Events [DoubleClickEvent]);
  4752. if (eh != null)
  4753. eh (this, e);
  4754. }
  4755. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4756. protected virtual void OnDragDrop(DragEventArgs drgevent) {
  4757. DragEventHandler eh = (DragEventHandler)(Events [DragDropEvent]);
  4758. if (eh != null)
  4759. eh (this, drgevent);
  4760. }
  4761. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4762. protected virtual void OnDragEnter(DragEventArgs drgevent) {
  4763. DragEventHandler eh = (DragEventHandler)(Events [DragEnterEvent]);
  4764. if (eh != null)
  4765. eh (this, drgevent);
  4766. }
  4767. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4768. protected virtual void OnDragLeave(EventArgs e) {
  4769. EventHandler eh = (EventHandler)(Events [DragLeaveEvent]);
  4770. if (eh != null)
  4771. eh (this, e);
  4772. }
  4773. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4774. protected virtual void OnDragOver(DragEventArgs drgevent) {
  4775. DragEventHandler eh = (DragEventHandler)(Events [DragOverEvent]);
  4776. if (eh != null)
  4777. eh (this, drgevent);
  4778. }
  4779. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4780. protected virtual void OnEnabledChanged(EventArgs e) {
  4781. if (IsHandleCreated) {
  4782. if (this is Form) {
  4783. if (((Form)this).context == null) {
  4784. XplatUI.EnableWindow(window.Handle, Enabled);
  4785. }
  4786. } else {
  4787. XplatUI.EnableWindow(window.Handle, Enabled);
  4788. }
  4789. Refresh();
  4790. }
  4791. EventHandler eh = (EventHandler)(Events [EnabledChangedEvent]);
  4792. if (eh != null)
  4793. eh (this, e);
  4794. foreach (Control c in Controls.GetAllControls ())
  4795. c.OnParentEnabledChanged (e);
  4796. }
  4797. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4798. protected virtual void OnEnter(EventArgs e) {
  4799. EventHandler eh = (EventHandler)(Events [EnterEvent]);
  4800. if (eh != null)
  4801. eh (this, e);
  4802. }
  4803. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4804. protected virtual void OnFontChanged(EventArgs e) {
  4805. EventHandler eh = (EventHandler)(Events [FontChangedEvent]);
  4806. if (eh != null)
  4807. eh (this, e);
  4808. for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentFontChanged(e);
  4809. }
  4810. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4811. protected virtual void OnForeColorChanged(EventArgs e) {
  4812. EventHandler eh = (EventHandler)(Events [ForeColorChangedEvent]);
  4813. if (eh != null)
  4814. eh (this, e);
  4815. for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentForeColorChanged(e);
  4816. }
  4817. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4818. protected virtual void OnGiveFeedback(GiveFeedbackEventArgs gfbevent) {
  4819. GiveFeedbackEventHandler eh = (GiveFeedbackEventHandler)(Events [GiveFeedbackEvent]);
  4820. if (eh != null)
  4821. eh (this, gfbevent);
  4822. }
  4823. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4824. protected virtual void OnGotFocus(EventArgs e) {
  4825. EventHandler eh = (EventHandler)(Events [GotFocusEvent]);
  4826. if (eh != null)
  4827. eh (this, e);
  4828. }
  4829. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4830. protected virtual void OnHandleCreated(EventArgs e) {
  4831. EventHandler eh = (EventHandler)(Events [HandleCreatedEvent]);
  4832. if (eh != null)
  4833. eh (this, e);
  4834. }
  4835. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4836. protected virtual void OnHandleDestroyed(EventArgs e) {
  4837. EventHandler eh = (EventHandler)(Events [HandleDestroyedEvent]);
  4838. if (eh != null)
  4839. eh (this, e);
  4840. }
  4841. internal void RaiseHelpRequested (HelpEventArgs hevent) {
  4842. OnHelpRequested (hevent);
  4843. }
  4844. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4845. protected virtual void OnHelpRequested(HelpEventArgs hevent) {
  4846. HelpEventHandler eh = (HelpEventHandler)(Events [HelpRequestedEvent]);
  4847. if (eh != null)
  4848. eh (this, hevent);
  4849. }
  4850. protected virtual void OnImeModeChanged(EventArgs e) {
  4851. EventHandler eh = (EventHandler)(Events [ImeModeChangedEvent]);
  4852. if (eh != null)
  4853. eh (this, e);
  4854. }
  4855. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4856. protected virtual void OnInvalidated(InvalidateEventArgs e) {
  4857. if (UseDoubleBuffering) {
  4858. // should this block be here? seems like it
  4859. // would be more at home in
  4860. // NotifyInvalidated..
  4861. if (e.InvalidRect == ClientRectangle) {
  4862. InvalidateBackBuffer ();
  4863. } else if (backbuffer != null){
  4864. // we need this Inflate call here so
  4865. // that the border of the rectangle is
  4866. // considered Visible (the
  4867. // invalid_region.IsVisible call) in
  4868. // the WM_PAINT handling below.
  4869. Rectangle r = Rectangle.Inflate(e.InvalidRect, 1,1);
  4870. backbuffer.InvalidRegion.Union (r);
  4871. }
  4872. }
  4873. InvalidateEventHandler eh = (InvalidateEventHandler)(Events [InvalidatedEvent]);
  4874. if (eh != null)
  4875. eh (this, e);
  4876. }
  4877. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4878. protected virtual void OnKeyDown(KeyEventArgs e) {
  4879. KeyEventHandler eh = (KeyEventHandler)(Events [KeyDownEvent]);
  4880. if (eh != null)
  4881. eh (this, e);
  4882. }
  4883. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4884. protected virtual void OnKeyPress(KeyPressEventArgs e) {
  4885. KeyPressEventHandler eh = (KeyPressEventHandler)(Events [KeyPressEvent]);
  4886. if (eh != null)
  4887. eh (this, e);
  4888. }
  4889. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4890. protected virtual void OnKeyUp(KeyEventArgs e) {
  4891. KeyEventHandler eh = (KeyEventHandler)(Events [KeyUpEvent]);
  4892. if (eh != null)
  4893. eh (this, e);
  4894. }
  4895. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4896. protected virtual void OnLayout(LayoutEventArgs levent) {
  4897. LayoutEventHandler eh = (LayoutEventHandler)(Events [LayoutEvent]);
  4898. if (eh != null)
  4899. eh (this, levent);
  4900. Size s = Size;
  4901. // If our layout changed our PreferredSize, our parent
  4902. // needs to re-lay us out. However, it's not always possible to
  4903. // be our preferred size, so only try once so we don't loop forever.
  4904. if (Parent != null && AutoSize && !nested_layout && PreferredSize != s) {
  4905. nested_layout = true;
  4906. Parent.PerformLayout ();
  4907. nested_layout = false;
  4908. }
  4909. LayoutEngine.Layout (this, levent);
  4910. }
  4911. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4912. protected virtual void OnLeave(EventArgs e) {
  4913. EventHandler eh = (EventHandler)(Events [LeaveEvent]);
  4914. if (eh != null)
  4915. eh (this, e);
  4916. }
  4917. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4918. protected virtual void OnLocationChanged(EventArgs e) {
  4919. OnMove(e);
  4920. EventHandler eh = (EventHandler)(Events [LocationChangedEvent]);
  4921. if (eh != null)
  4922. eh (this, e);
  4923. }
  4924. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4925. protected virtual void OnLostFocus(EventArgs e) {
  4926. EventHandler eh = (EventHandler)(Events [LostFocusEvent]);
  4927. if (eh != null)
  4928. eh (this, e);
  4929. }
  4930. protected virtual void OnMarginChanged (EventArgs e)
  4931. {
  4932. EventHandler eh = (EventHandler)(Events[MarginChangedEvent]);
  4933. if (eh != null)
  4934. eh (this, e);
  4935. }
  4936. [EditorBrowsable (EditorBrowsableState.Advanced)]
  4937. protected virtual void OnMouseCaptureChanged (EventArgs e)
  4938. {
  4939. EventHandler eh = (EventHandler)(Events [MouseCaptureChangedEvent]);
  4940. if (eh != null)
  4941. eh (this, e);
  4942. }
  4943. [EditorBrowsable (EditorBrowsableState.Advanced)]
  4944. protected virtual void OnMouseClick (MouseEventArgs e)
  4945. {
  4946. MouseEventHandler eh = (MouseEventHandler)(Events [MouseClickEvent]);
  4947. if (eh != null)
  4948. eh (this, e);
  4949. }
  4950. [EditorBrowsable (EditorBrowsableState.Advanced)]
  4951. protected virtual void OnMouseDoubleClick (MouseEventArgs e)
  4952. {
  4953. MouseEventHandler eh = (MouseEventHandler)(Events [MouseDoubleClickEvent]);
  4954. if (eh != null)
  4955. eh (this, e);
  4956. }
  4957. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4958. protected virtual void OnMouseDown(MouseEventArgs e) {
  4959. MouseEventHandler eh = (MouseEventHandler)(Events [MouseDownEvent]);
  4960. if (eh != null)
  4961. eh (this, e);
  4962. }
  4963. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4964. protected virtual void OnMouseEnter(EventArgs e) {
  4965. EventHandler eh = (EventHandler)(Events [MouseEnterEvent]);
  4966. if (eh != null)
  4967. eh (this, e);
  4968. }
  4969. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4970. protected virtual void OnMouseHover(EventArgs e) {
  4971. EventHandler eh = (EventHandler)(Events [MouseHoverEvent]);
  4972. if (eh != null)
  4973. eh (this, e);
  4974. }
  4975. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4976. protected virtual void OnMouseLeave(EventArgs e) {
  4977. EventHandler eh = (EventHandler)(Events [MouseLeaveEvent]);
  4978. if (eh != null)
  4979. eh (this, e);
  4980. }
  4981. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4982. protected virtual void OnMouseMove(MouseEventArgs e) {
  4983. MouseEventHandler eh = (MouseEventHandler)(Events [MouseMoveEvent]);
  4984. if (eh != null)
  4985. eh (this, e);
  4986. }
  4987. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4988. protected virtual void OnMouseUp(MouseEventArgs e) {
  4989. MouseEventHandler eh = (MouseEventHandler)(Events [MouseUpEvent]);
  4990. if (eh != null)
  4991. eh (this, e);
  4992. }
  4993. [EditorBrowsable(EditorBrowsableState.Advanced)]
  4994. protected virtual void OnMouseWheel(MouseEventArgs e) {
  4995. MouseEventHandler eh = (MouseEventHandler)(Events [MouseWheelEvent]);
  4996. if (eh != null)
  4997. eh (this, e);
  4998. }
  4999. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5000. protected virtual void OnMove(EventArgs e) {
  5001. EventHandler eh = (EventHandler)(Events [MoveEvent]);
  5002. if (eh != null)
  5003. eh (this, e);
  5004. }
  5005. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5006. protected virtual void OnNotifyMessage(Message m) {
  5007. // Override me!
  5008. }
  5009. protected virtual void OnPaddingChanged (EventArgs e) {
  5010. EventHandler eh = (EventHandler) (Events [PaddingChangedEvent]);
  5011. if (eh != null)
  5012. eh (this, e);
  5013. }
  5014. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5015. protected virtual void OnPaint(PaintEventArgs e) {
  5016. PaintEventHandler eh = (PaintEventHandler)(Events [PaintEvent]);
  5017. if (eh != null)
  5018. eh (this, e);
  5019. }
  5020. internal virtual void OnPaintBackgroundInternal(PaintEventArgs e) {
  5021. // Override me
  5022. }
  5023. internal virtual void OnPaintInternal(PaintEventArgs e) {
  5024. // Override me
  5025. }
  5026. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5027. protected virtual void OnPaintBackground(PaintEventArgs pevent) {
  5028. PaintControlBackground (pevent);
  5029. }
  5030. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5031. protected virtual void OnParentBackColorChanged(EventArgs e) {
  5032. if (background_color.IsEmpty && background_image==null) {
  5033. Invalidate();
  5034. OnBackColorChanged(e);
  5035. }
  5036. }
  5037. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5038. protected virtual void OnParentBackgroundImageChanged(EventArgs e) {
  5039. Invalidate();
  5040. OnBackgroundImageChanged(e);
  5041. }
  5042. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5043. protected virtual void OnParentBindingContextChanged(EventArgs e) {
  5044. if (binding_context==null && Parent != null) {
  5045. binding_context=Parent.binding_context;
  5046. OnBindingContextChanged(e);
  5047. }
  5048. }
  5049. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5050. protected virtual void OnParentChanged(EventArgs e) {
  5051. EventHandler eh = (EventHandler)(Events [ParentChangedEvent]);
  5052. if (eh != null)
  5053. eh (this, e);
  5054. }
  5055. [EditorBrowsable (EditorBrowsableState.Advanced)]
  5056. protected virtual void OnParentCursorChanged (EventArgs e)
  5057. {
  5058. }
  5059. [EditorBrowsable (EditorBrowsableState.Advanced)]
  5060. protected virtual void OnParentEnabledChanged(EventArgs e) {
  5061. if (is_enabled) {
  5062. OnEnabledChanged(e);
  5063. }
  5064. }
  5065. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5066. protected virtual void OnParentFontChanged(EventArgs e) {
  5067. if (font==null) {
  5068. Invalidate();
  5069. OnFontChanged(e);
  5070. }
  5071. }
  5072. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5073. protected virtual void OnParentForeColorChanged(EventArgs e) {
  5074. if (foreground_color.IsEmpty) {
  5075. Invalidate();
  5076. OnForeColorChanged(e);
  5077. }
  5078. }
  5079. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5080. protected virtual void OnParentRightToLeftChanged(EventArgs e) {
  5081. if (right_to_left==RightToLeft.Inherit) {
  5082. Invalidate();
  5083. OnRightToLeftChanged(e);
  5084. }
  5085. }
  5086. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5087. protected virtual void OnParentVisibleChanged(EventArgs e) {
  5088. if (is_visible) {
  5089. OnVisibleChanged(e);
  5090. }
  5091. }
  5092. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5093. protected virtual void OnQueryContinueDrag (QueryContinueDragEventArgs qcdevent)
  5094. {
  5095. QueryContinueDragEventHandler eh = (QueryContinueDragEventHandler)(Events [QueryContinueDragEvent]);
  5096. if (eh != null)
  5097. eh (this, qcdevent);
  5098. }
  5099. [EditorBrowsable (EditorBrowsableState.Advanced)]
  5100. protected virtual void OnPreviewKeyDown (PreviewKeyDownEventArgs e)
  5101. {
  5102. PreviewKeyDownEventHandler eh = (PreviewKeyDownEventHandler)(Events[PreviewKeyDownEvent]);
  5103. if (eh != null)
  5104. eh (this, e);
  5105. }
  5106. [EditorBrowsable (EditorBrowsableState.Advanced)]
  5107. protected virtual void OnPrint (PaintEventArgs e)
  5108. {
  5109. PaintEventHandler eh = (PaintEventHandler)(Events[PaintEvent]);
  5110. if (eh != null)
  5111. eh (this, e);
  5112. }
  5113. [EditorBrowsable (EditorBrowsableState.Advanced)]
  5114. protected virtual void OnRegionChanged (EventArgs e)
  5115. {
  5116. EventHandler eh = (EventHandler)(Events[RegionChangedEvent]);
  5117. if (eh != null)
  5118. eh (this, e);
  5119. }
  5120. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5121. protected virtual void OnResize(EventArgs e) {
  5122. OnResizeInternal (e);
  5123. }
  5124. internal virtual void OnResizeInternal (EventArgs e) {
  5125. PerformLayout(this, "Bounds");
  5126. EventHandler eh = (EventHandler)(Events [ResizeEvent]);
  5127. if (eh != null)
  5128. eh (this, e);
  5129. }
  5130. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5131. protected virtual void OnRightToLeftChanged(EventArgs e) {
  5132. EventHandler eh = (EventHandler)(Events [RightToLeftChangedEvent]);
  5133. if (eh != null)
  5134. eh (this, e);
  5135. for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentRightToLeftChanged(e);
  5136. }
  5137. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5138. protected virtual void OnSizeChanged(EventArgs e) {
  5139. DisposeBackBuffer ();
  5140. OnResize(e);
  5141. EventHandler eh = (EventHandler)(Events [SizeChangedEvent]);
  5142. if (eh != null)
  5143. eh (this, e);
  5144. }
  5145. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5146. protected virtual void OnStyleChanged(EventArgs e) {
  5147. EventHandler eh = (EventHandler)(Events [StyleChangedEvent]);
  5148. if (eh != null)
  5149. eh (this, e);
  5150. }
  5151. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5152. protected virtual void OnSystemColorsChanged(EventArgs e) {
  5153. EventHandler eh = (EventHandler)(Events [SystemColorsChangedEvent]);
  5154. if (eh != null)
  5155. eh (this, e);
  5156. }
  5157. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5158. protected virtual void OnTabIndexChanged(EventArgs e) {
  5159. EventHandler eh = (EventHandler)(Events [TabIndexChangedEvent]);
  5160. if (eh != null)
  5161. eh (this, e);
  5162. }
  5163. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5164. protected virtual void OnTabStopChanged(EventArgs e) {
  5165. EventHandler eh = (EventHandler)(Events [TabStopChangedEvent]);
  5166. if (eh != null)
  5167. eh (this, e);
  5168. }
  5169. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5170. protected virtual void OnTextChanged(EventArgs e) {
  5171. EventHandler eh = (EventHandler)(Events [TextChangedEvent]);
  5172. if (eh != null)
  5173. eh (this, e);
  5174. }
  5175. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5176. protected virtual void OnValidated(EventArgs e) {
  5177. EventHandler eh = (EventHandler)(Events [ValidatedEvent]);
  5178. if (eh != null)
  5179. eh (this, e);
  5180. }
  5181. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5182. protected virtual void OnValidating(System.ComponentModel.CancelEventArgs e) {
  5183. CancelEventHandler eh = (CancelEventHandler)(Events [ValidatingEvent]);
  5184. if (eh != null)
  5185. eh (this, e);
  5186. }
  5187. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5188. protected virtual void OnVisibleChanged(EventArgs e) {
  5189. if (Visible)
  5190. CreateControl ();
  5191. EventHandler eh = (EventHandler)(Events [VisibleChangedEvent]);
  5192. if (eh != null)
  5193. eh (this, e);
  5194. // We need to tell our kids (including implicit ones)
  5195. foreach (Control c in Controls.GetAllControls ())
  5196. if (c.Visible)
  5197. c.OnParentVisibleChanged (e);
  5198. }
  5199. #endregion // OnXXX methods
  5200. #region Events
  5201. static object AutoSizeChangedEvent = new object ();
  5202. static object BackColorChangedEvent = new object ();
  5203. static object BackgroundImageChangedEvent = new object ();
  5204. static object BackgroundImageLayoutChangedEvent = new object ();
  5205. static object BindingContextChangedEvent = new object ();
  5206. static object CausesValidationChangedEvent = new object ();
  5207. static object ChangeUICuesEvent = new object ();
  5208. static object ClickEvent = new object ();
  5209. static object ClientSizeChangedEvent = new object ();
  5210. static object ContextMenuChangedEvent = new object ();
  5211. static object ContextMenuStripChangedEvent = new object ();
  5212. static object ControlAddedEvent = new object ();
  5213. static object ControlRemovedEvent = new object ();
  5214. static object CursorChangedEvent = new object ();
  5215. static object DockChangedEvent = new object ();
  5216. static object DoubleClickEvent = new object ();
  5217. static object DragDropEvent = new object ();
  5218. static object DragEnterEvent = new object ();
  5219. static object DragLeaveEvent = new object ();
  5220. static object DragOverEvent = new object ();
  5221. static object EnabledChangedEvent = new object ();
  5222. static object EnterEvent = new object ();
  5223. static object FontChangedEvent = new object ();
  5224. static object ForeColorChangedEvent = new object ();
  5225. static object GiveFeedbackEvent = new object ();
  5226. static object GotFocusEvent = new object ();
  5227. static object HandleCreatedEvent = new object ();
  5228. static object HandleDestroyedEvent = new object ();
  5229. static object HelpRequestedEvent = new object ();
  5230. static object ImeModeChangedEvent = new object ();
  5231. static object InvalidatedEvent = new object ();
  5232. static object KeyDownEvent = new object ();
  5233. static object KeyPressEvent = new object ();
  5234. static object KeyUpEvent = new object ();
  5235. static object LayoutEvent = new object ();
  5236. static object LeaveEvent = new object ();
  5237. static object LocationChangedEvent = new object ();
  5238. static object LostFocusEvent = new object ();
  5239. static object MarginChangedEvent = new object ();
  5240. static object MouseCaptureChangedEvent = new object ();
  5241. static object MouseClickEvent = new object ();
  5242. static object MouseDoubleClickEvent = new object ();
  5243. static object MouseDownEvent = new object ();
  5244. static object MouseEnterEvent = new object ();
  5245. static object MouseHoverEvent = new object ();
  5246. static object MouseLeaveEvent = new object ();
  5247. static object MouseMoveEvent = new object ();
  5248. static object MouseUpEvent = new object ();
  5249. static object MouseWheelEvent = new object ();
  5250. static object MoveEvent = new object ();
  5251. static object PaddingChangedEvent = new object ();
  5252. static object PaintEvent = new object ();
  5253. static object ParentChangedEvent = new object ();
  5254. static object PreviewKeyDownEvent = new object ();
  5255. static object QueryAccessibilityHelpEvent = new object ();
  5256. static object QueryContinueDragEvent = new object ();
  5257. static object RegionChangedEvent = new object ();
  5258. static object ResizeEvent = new object ();
  5259. static object RightToLeftChangedEvent = new object ();
  5260. static object SizeChangedEvent = new object ();
  5261. static object StyleChangedEvent = new object ();
  5262. static object SystemColorsChangedEvent = new object ();
  5263. static object TabIndexChangedEvent = new object ();
  5264. static object TabStopChangedEvent = new object ();
  5265. static object TextChangedEvent = new object ();
  5266. static object ValidatedEvent = new object ();
  5267. static object ValidatingEvent = new object ();
  5268. static object VisibleChangedEvent = new object ();
  5269. [Browsable (false)]
  5270. [EditorBrowsable (EditorBrowsableState.Never)]
  5271. public event EventHandler AutoSizeChanged {
  5272. add { Events.AddHandler (AutoSizeChangedEvent, value);}
  5273. remove {Events.RemoveHandler (AutoSizeChangedEvent, value);}
  5274. }
  5275. public event EventHandler BackColorChanged {
  5276. add { Events.AddHandler (BackColorChangedEvent, value); }
  5277. remove { Events.RemoveHandler (BackColorChangedEvent, value); }
  5278. }
  5279. public event EventHandler BackgroundImageChanged {
  5280. add { Events.AddHandler (BackgroundImageChangedEvent, value); }
  5281. remove { Events.RemoveHandler (BackgroundImageChangedEvent, value); }
  5282. }
  5283. public event EventHandler BackgroundImageLayoutChanged {
  5284. add {Events.AddHandler (BackgroundImageLayoutChangedEvent, value);}
  5285. remove {Events.RemoveHandler (BackgroundImageLayoutChangedEvent, value);}
  5286. }
  5287. public event EventHandler BindingContextChanged {
  5288. add { Events.AddHandler (BindingContextChangedEvent, value); }
  5289. remove { Events.RemoveHandler (BindingContextChangedEvent, value); }
  5290. }
  5291. public event EventHandler CausesValidationChanged {
  5292. add { Events.AddHandler (CausesValidationChangedEvent, value); }
  5293. remove { Events.RemoveHandler (CausesValidationChangedEvent, value); }
  5294. }
  5295. public event UICuesEventHandler ChangeUICues {
  5296. add { Events.AddHandler (ChangeUICuesEvent, value); }
  5297. remove { Events.RemoveHandler (ChangeUICuesEvent, value); }
  5298. }
  5299. public event EventHandler Click {
  5300. add { Events.AddHandler (ClickEvent, value); }
  5301. remove { Events.RemoveHandler (ClickEvent, value); }
  5302. }
  5303. public event EventHandler ClientSizeChanged {
  5304. add {Events.AddHandler (ClientSizeChangedEvent, value);}
  5305. remove {Events.RemoveHandler (ClientSizeChangedEvent, value);}
  5306. }
  5307. [Browsable (false)]
  5308. public event EventHandler ContextMenuChanged {
  5309. add { Events.AddHandler (ContextMenuChangedEvent, value); }
  5310. remove { Events.RemoveHandler (ContextMenuChangedEvent, value); }
  5311. }
  5312. public event EventHandler ContextMenuStripChanged {
  5313. add { Events.AddHandler (ContextMenuStripChangedEvent, value); }
  5314. remove { Events.RemoveHandler (ContextMenuStripChangedEvent, value);}
  5315. }
  5316. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5317. [Browsable(true)]
  5318. public event ControlEventHandler ControlAdded {
  5319. add { Events.AddHandler (ControlAddedEvent, value); }
  5320. remove { Events.RemoveHandler (ControlAddedEvent, value); }
  5321. }
  5322. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5323. [Browsable(true)]
  5324. public event ControlEventHandler ControlRemoved {
  5325. add { Events.AddHandler (ControlRemovedEvent, value); }
  5326. remove { Events.RemoveHandler (ControlRemovedEvent, value); }
  5327. }
  5328. [MWFDescription("Fired when the cursor for the control has been changed"), MWFCategory("PropertyChanged")]
  5329. public event EventHandler CursorChanged {
  5330. add { Events.AddHandler (CursorChangedEvent, value); }
  5331. remove { Events.RemoveHandler (CursorChangedEvent, value); }
  5332. }
  5333. public event EventHandler DockChanged {
  5334. add { Events.AddHandler (DockChangedEvent, value); }
  5335. remove { Events.RemoveHandler (DockChangedEvent, value); }
  5336. }
  5337. public event EventHandler DoubleClick {
  5338. add { Events.AddHandler (DoubleClickEvent, value); }
  5339. remove { Events.RemoveHandler (DoubleClickEvent, value); }
  5340. }
  5341. public event DragEventHandler DragDrop {
  5342. add { Events.AddHandler (DragDropEvent, value); }
  5343. remove { Events.RemoveHandler (DragDropEvent, value); }
  5344. }
  5345. public event DragEventHandler DragEnter {
  5346. add { Events.AddHandler (DragEnterEvent, value); }
  5347. remove { Events.RemoveHandler (DragEnterEvent, value); }
  5348. }
  5349. public event EventHandler DragLeave {
  5350. add { Events.AddHandler (DragLeaveEvent, value); }
  5351. remove { Events.RemoveHandler (DragLeaveEvent, value); }
  5352. }
  5353. public event DragEventHandler DragOver {
  5354. add { Events.AddHandler (DragOverEvent, value); }
  5355. remove { Events.RemoveHandler (DragOverEvent, value); }
  5356. }
  5357. public event EventHandler EnabledChanged {
  5358. add { Events.AddHandler (EnabledChangedEvent, value); }
  5359. remove { Events.RemoveHandler (EnabledChangedEvent, value); }
  5360. }
  5361. public event EventHandler Enter {
  5362. add { Events.AddHandler (EnterEvent, value); }
  5363. remove { Events.RemoveHandler (EnterEvent, value); }
  5364. }
  5365. public event EventHandler FontChanged {
  5366. add { Events.AddHandler (FontChangedEvent, value); }
  5367. remove { Events.RemoveHandler (FontChangedEvent, value); }
  5368. }
  5369. public event EventHandler ForeColorChanged {
  5370. add { Events.AddHandler (ForeColorChangedEvent, value); }
  5371. remove { Events.RemoveHandler (ForeColorChangedEvent, value); }
  5372. }
  5373. public event GiveFeedbackEventHandler GiveFeedback {
  5374. add { Events.AddHandler (GiveFeedbackEvent, value); }
  5375. remove { Events.RemoveHandler (GiveFeedbackEvent, value); }
  5376. }
  5377. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5378. [Browsable(false)]
  5379. public event EventHandler GotFocus {
  5380. add { Events.AddHandler (GotFocusEvent, value); }
  5381. remove { Events.RemoveHandler (GotFocusEvent, value); }
  5382. }
  5383. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5384. [Browsable(false)]
  5385. public event EventHandler HandleCreated {
  5386. add { Events.AddHandler (HandleCreatedEvent, value); }
  5387. remove { Events.RemoveHandler (HandleCreatedEvent, value); }
  5388. }
  5389. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5390. [Browsable(false)]
  5391. public event EventHandler HandleDestroyed {
  5392. add { Events.AddHandler (HandleDestroyedEvent, value); }
  5393. remove { Events.RemoveHandler (HandleDestroyedEvent, value); }
  5394. }
  5395. public event HelpEventHandler HelpRequested {
  5396. add { Events.AddHandler (HelpRequestedEvent, value); }
  5397. remove { Events.RemoveHandler (HelpRequestedEvent, value); }
  5398. }
  5399. public event EventHandler ImeModeChanged {
  5400. add { Events.AddHandler (ImeModeChangedEvent, value); }
  5401. remove { Events.RemoveHandler (ImeModeChangedEvent, value); }
  5402. }
  5403. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5404. [Browsable(false)]
  5405. public event InvalidateEventHandler Invalidated {
  5406. add { Events.AddHandler (InvalidatedEvent, value); }
  5407. remove { Events.RemoveHandler (InvalidatedEvent, value); }
  5408. }
  5409. public event KeyEventHandler KeyDown {
  5410. add { Events.AddHandler (KeyDownEvent, value); }
  5411. remove { Events.RemoveHandler (KeyDownEvent, value); }
  5412. }
  5413. public event KeyPressEventHandler KeyPress {
  5414. add { Events.AddHandler (KeyPressEvent, value); }
  5415. remove { Events.RemoveHandler (KeyPressEvent, value); }
  5416. }
  5417. public event KeyEventHandler KeyUp {
  5418. add { Events.AddHandler (KeyUpEvent, value); }
  5419. remove { Events.RemoveHandler (KeyUpEvent, value); }
  5420. }
  5421. public event LayoutEventHandler Layout {
  5422. add { Events.AddHandler (LayoutEvent, value); }
  5423. remove { Events.RemoveHandler (LayoutEvent, value); }
  5424. }
  5425. public event EventHandler Leave {
  5426. add { Events.AddHandler (LeaveEvent, value); }
  5427. remove { Events.RemoveHandler (LeaveEvent, value); }
  5428. }
  5429. public event EventHandler LocationChanged {
  5430. add { Events.AddHandler (LocationChangedEvent, value); }
  5431. remove { Events.RemoveHandler (LocationChangedEvent, value); }
  5432. }
  5433. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5434. [Browsable(false)]
  5435. public event EventHandler LostFocus {
  5436. add { Events.AddHandler (LostFocusEvent, value); }
  5437. remove { Events.RemoveHandler (LostFocusEvent, value); }
  5438. }
  5439. public event EventHandler MarginChanged {
  5440. add { Events.AddHandler (MarginChangedEvent, value); }
  5441. remove {Events.RemoveHandler (MarginChangedEvent, value); }
  5442. }
  5443. public event EventHandler MouseCaptureChanged {
  5444. add { Events.AddHandler (MouseCaptureChangedEvent, value); }
  5445. remove { Events.RemoveHandler (MouseCaptureChangedEvent, value); }
  5446. }
  5447. public event MouseEventHandler MouseClick
  5448. {
  5449. add { Events.AddHandler (MouseClickEvent, value); }
  5450. remove { Events.RemoveHandler (MouseClickEvent, value); }
  5451. }
  5452. public event MouseEventHandler MouseDoubleClick
  5453. {
  5454. add { Events.AddHandler (MouseDoubleClickEvent, value); }
  5455. remove { Events.RemoveHandler (MouseDoubleClickEvent, value); }
  5456. }
  5457. public event MouseEventHandler MouseDown {
  5458. add { Events.AddHandler (MouseDownEvent, value); }
  5459. remove { Events.RemoveHandler (MouseDownEvent, value); }
  5460. }
  5461. public event EventHandler MouseEnter {
  5462. add { Events.AddHandler (MouseEnterEvent, value); }
  5463. remove { Events.RemoveHandler (MouseEnterEvent, value); }
  5464. }
  5465. public event EventHandler MouseHover {
  5466. add { Events.AddHandler (MouseHoverEvent, value); }
  5467. remove { Events.RemoveHandler (MouseHoverEvent, value); }
  5468. }
  5469. public event EventHandler MouseLeave {
  5470. add { Events.AddHandler (MouseLeaveEvent, value); }
  5471. remove { Events.RemoveHandler (MouseLeaveEvent, value); }
  5472. }
  5473. public event MouseEventHandler MouseMove {
  5474. add { Events.AddHandler (MouseMoveEvent, value); }
  5475. remove { Events.RemoveHandler (MouseMoveEvent, value); }
  5476. }
  5477. public event MouseEventHandler MouseUp {
  5478. add { Events.AddHandler (MouseUpEvent, value); }
  5479. remove { Events.RemoveHandler (MouseUpEvent, value); }
  5480. }
  5481. [EditorBrowsable(EditorBrowsableState.Advanced)]
  5482. [Browsable(false)]
  5483. public event MouseEventHandler MouseWheel {
  5484. add { Events.AddHandler (MouseWheelEvent, value); }
  5485. remove { Events.RemoveHandler (MouseWheelEvent, value); }
  5486. }
  5487. public event EventHandler Move {
  5488. add { Events.AddHandler (MoveEvent, value); }
  5489. remove { Events.RemoveHandler (MoveEvent, value); }
  5490. }
  5491. public event EventHandler PaddingChanged
  5492. {
  5493. add { Events.AddHandler (PaddingChangedEvent, value); }
  5494. remove { Events.RemoveHandler (PaddingChangedEvent, value); }
  5495. }
  5496. public event PaintEventHandler Paint {
  5497. add { Events.AddHandler (PaintEvent, value); }
  5498. remove { Events.RemoveHandler (PaintEvent, value); }
  5499. }
  5500. public event EventHandler ParentChanged {
  5501. add { Events.AddHandler (ParentChangedEvent, value); }
  5502. remove { Events.RemoveHandler (ParentChangedEvent, value); }
  5503. }
  5504. public event PreviewKeyDownEventHandler PreviewKeyDown {
  5505. add { Events.AddHandler (PreviewKeyDownEvent, value); }
  5506. remove { Events.RemoveHandler (PreviewKeyDownEvent, value); }
  5507. }
  5508. public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp {
  5509. add { Events.AddHandler (QueryAccessibilityHelpEvent, value); }
  5510. remove { Events.RemoveHandler (QueryAccessibilityHelpEvent, value); }
  5511. }
  5512. public event QueryContinueDragEventHandler QueryContinueDrag {
  5513. add { Events.AddHandler (QueryContinueDragEvent, value); }
  5514. remove { Events.RemoveHandler (QueryContinueDragEvent, value); }
  5515. }
  5516. public event EventHandler RegionChanged {
  5517. add { Events.AddHandler (RegionChangedEvent, value); }
  5518. remove { Events.RemoveHandler (RegionChangedEvent, value); }
  5519. }
  5520. [EditorBrowsable (EditorBrowsableState.Advanced)]
  5521. public event EventHandler Resize {
  5522. add { Events.AddHandler (ResizeEvent, value); }
  5523. remove { Events.RemoveHandler (ResizeEvent, value); }
  5524. }
  5525. public event EventHandler RightToLeftChanged {
  5526. add { Events.AddHandler (RightToLeftChangedEvent, value); }
  5527. remove { Events.RemoveHandler (RightToLeftChangedEvent, value); }
  5528. }
  5529. public event EventHandler SizeChanged {
  5530. add { Events.AddHandler (SizeChangedEvent, value); }
  5531. remove { Events.RemoveHandler (SizeChangedEvent, value); }
  5532. }
  5533. public event EventHandler StyleChanged {
  5534. add { Events.AddHandler (StyleChangedEvent, value); }
  5535. remove { Events.RemoveHandler (StyleChangedEvent, value); }
  5536. }
  5537. public event EventHandler SystemColorsChanged {
  5538. add { Events.AddHandler (SystemColorsChangedEvent, value); }
  5539. remove { Events.RemoveHandler (SystemColorsChangedEvent, value); }
  5540. }
  5541. public event EventHandler TabIndexChanged {
  5542. add { Events.AddHandler (TabIndexChangedEvent, value); }
  5543. remove { Events.RemoveHandler (TabIndexChangedEvent, value); }
  5544. }
  5545. public event EventHandler TabStopChanged {
  5546. add { Events.AddHandler (TabStopChangedEvent, value); }
  5547. remove { Events.RemoveHandler (TabStopChangedEvent, value); }
  5548. }
  5549. public event EventHandler TextChanged {
  5550. add { Events.AddHandler (TextChangedEvent, value); }
  5551. remove { Events.RemoveHandler (TextChangedEvent, value); }
  5552. }
  5553. public event EventHandler Validated {
  5554. add { Events.AddHandler (ValidatedEvent, value); }
  5555. remove { Events.RemoveHandler (ValidatedEvent, value); }
  5556. }
  5557. public event CancelEventHandler Validating {
  5558. add { Events.AddHandler (ValidatingEvent, value); }
  5559. remove { Events.RemoveHandler (ValidatingEvent, value); }
  5560. }
  5561. public event EventHandler VisibleChanged {
  5562. add { Events.AddHandler (VisibleChangedEvent, value); }
  5563. remove { Events.RemoveHandler (VisibleChangedEvent, value); }
  5564. }
  5565. #endregion // Events
  5566. }
  5567. }