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:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
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.
20 // Copyright (c) 2004-2006 Novell, Inc.
23 // Peter Bartok pbartok@novell.com
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
38 using System.ComponentModel;
39 using System.ComponentModel.Design;
40 using System.ComponentModel.Design.Serialization;
41 using System.Collections;
42 using System.Diagnostics;
44 using System.Drawing.Drawing2D;
45 using System.Reflection;
46 using System.Runtime.InteropServices;
47 using System.Security;
48 using System.Threading;
50 namespace System.Windows.Forms
54 [ClassInterface (ClassInterfaceType.AutoDispatch)]
56 [Designer("System.Windows.Forms.Design.ControlDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
57 [DefaultProperty("Text")]
58 [DefaultEvent("Click")]
59 [DesignerSerializer("System.Windows.Forms.Design.ControlCodeDomSerializer, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
60 [ToolboxItemFilter("System.Windows.Forms")]
61 public class Control : Component, ISynchronizeInvoke, IWin32Window
63 , IBindableComponent, IDropTarget, IBounds
66 #region Local Variables
69 internal Rectangle bounds; // bounding rectangle for control (client area + decorations)
70 Rectangle explicit_bounds; // explicitly set bounds
71 internal object creator_thread; // thread that created the control
72 internal ControlNativeWindow window; // object for native window handle
73 private IWindowTarget window_target;
74 string name; // for object naming
77 bool is_created; // true if OnCreateControl has been sent
78 internal bool has_focus; // true if control has focus
79 internal bool is_visible; // true if control is visible
80 internal bool is_entered; // is the mouse inside the control?
81 internal bool is_enabled; // true if control is enabled (usable/not grayed out)
82 bool is_accessible; // true if the control is visible to accessibility applications
83 bool is_captured; // tracks if the control has captured the mouse
84 internal bool is_toplevel; // tracks if the control is a toplevel window
85 bool is_recreating; // tracks if the handle for the control is being recreated
86 bool causes_validation; // tracks if validation is executed on changes
87 bool is_focusing; // tracks if Focus has been called on the control and has not yet finished
88 int tab_index; // position in tab order of siblings
89 bool tab_stop; // is the control a tab stop?
90 bool is_disposed; // has the window already been disposed?
91 bool is_disposing; // is the window getting disposed?
92 Size client_size; // size of the client area (window excluding decorations)
93 Rectangle client_rect; // rectangle with the client area (window excluding decorations)
94 ControlStyles control_style; // rather win32-specific, style bits for control
96 object control_tag; // object that contains data about our control
97 internal int mouse_clicks; // Counter for mouse clicks
98 Cursor cursor; // Cursor for the window
99 internal bool allow_drop; // true if the control accepts droping objects on it
100 Region clip_region; // User-specified clip region for the window
103 internal Color foreground_color; // foreground color for control
104 internal Color background_color; // background color for control
105 Image background_image; // background image for control
106 internal Font font; // font for control
107 string text; // window/title text for control
108 internal BorderStyle border_style; // Border style of control
109 bool show_keyboard_cues; // Current keyboard cues
110 internal bool show_focus_cues; // Current focus cues
111 internal bool force_double_buffer; // Always doublebuffer regardless of ControlStyle
114 internal enum LayoutType {
118 Layout.LayoutEngine layout_engine;
119 internal int layout_suspended;
120 bool layout_pending; // true if our parent needs to re-layout us
121 internal AnchorStyles anchor_style; // anchoring requirements for our control
122 internal DockStyle dock_style; // docking requirements for our control
123 LayoutType layout_type;
124 private bool recalculate_distances = true; // Delay anchor calculations
126 // Please leave the next 2 as internal until DefaultLayout (2.0) is rewritten
127 internal int dist_right; // distance to the right border of the parent
128 internal int dist_bottom; // distance to the bottom border of the parent
130 // to be categorized...
131 ControlCollection child_controls; // our children
132 Control parent; // our parent control
133 BindingContext binding_context;
134 RightToLeft right_to_left; // drawing direction for control
135 ContextMenu context_menu; // Context menu associated with the control
136 internal bool use_compatible_text_rendering;
137 private bool use_wait_cursor;
140 string accessible_name;
141 string accessible_description;
142 string accessible_default_action;
143 AccessibleRole accessible_role = AccessibleRole.Default;
144 AccessibleObject accessibility_object; // object that contains accessibility information about our control
147 DoubleBuffer backbuffer;
149 ControlBindingsCollection data_bindings;
152 static bool verify_thread_handle;
154 ImageLayout backgroundimage_layout;
158 private ContextMenuStrip context_menu_strip;
159 private bool nested_layout = false;
160 Point auto_scroll_offset;
161 private AutoSizeMode auto_size_mode;
162 private bool suppressing_key_press;
165 #endregion // Local Variables
167 #region Private Classes
168 // This helper class allows us to dispatch messages to Control.WndProc
169 internal class ControlNativeWindow : NativeWindow {
170 private Control owner;
172 public ControlNativeWindow(Control control) : base() {
177 public Control Owner {
183 protected override void OnHandleChange()
185 this.owner.WindowTarget.OnHandleChange(this.owner.Handle);
188 static internal Control ControlFromHandle(IntPtr hWnd) {
189 ControlNativeWindow window;
191 window = (ControlNativeWindow)NativeWindow.FromHandle (hWnd);
192 if (window != null) {
199 static internal Control ControlFromChildHandle (IntPtr handle) {
200 ControlNativeWindow window;
202 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
203 while (hwnd != null) {
204 window = (ControlNativeWindow)NativeWindow.FromHandle (handle);
205 if (window != null) {
214 protected override void WndProc(ref Message m) {
215 owner.WindowTarget.OnMessage(ref m);
219 private class ControlWindowTarget : IWindowTarget
221 private Control control;
223 public ControlWindowTarget(Control control)
225 this.control = control;
228 public void OnHandleChange(IntPtr newHandle)
232 public void OnMessage(ref Message m)
234 control.WndProc(ref m);
239 #region Public Classes
241 public class ControlAccessibleObject : AccessibleObject {
244 #region ControlAccessibleObject Constructors
245 public ControlAccessibleObject(Control ownerControl)
246 : base (ownerControl)
248 if (ownerControl == null)
249 throw new ArgumentNullException ("owner");
251 handle = ownerControl.Handle;
253 #endregion // ControlAccessibleObject Constructors
255 #region ControlAccessibleObject Public Instance Properties
256 public override string DefaultAction {
258 return base.DefaultAction;
262 public override string Description {
264 return base.Description;
268 public IntPtr Handle {
274 // We don't want to let them set it
278 public override string Help {
284 public override string KeyboardShortcut {
286 return base.KeyboardShortcut;
290 public override string Name {
300 public Control Owner {
306 public override AccessibleObject Parent {
313 public override AccessibleRole Role {
318 #endregion // ControlAccessibleObject Public Instance Properties
320 #region ControlAccessibleObject Public Instance Methods
321 public override int GetHelpTopic (out string fileName)
323 return base.GetHelpTopic (out fileName);
326 [MonoTODO ("Stub, does nothing")]
327 public void NotifyClients (AccessibleEvents accEvent)
331 [MonoTODO ("Stub, does nothing")]
332 public void NotifyClients (AccessibleEvents accEvent, int childID)
337 [MonoTODO ("Stub, does nothing")]
338 public void NotifyClients (AccessibleEvents accEvent, int objectID, int childID)
343 public override string ToString() {
344 return "ControlAccessibleObject: Owner = " + owner.ToString() + ", Text: " + owner.text;
347 #endregion // ControlAccessibleObject Public Instance Methods
350 private class DoubleBuffer : IDisposable
352 public Region InvalidRegion;
353 private Stack real_graphics;
354 private object back_buffer;
355 private Control parent;
356 private bool pending_disposal;
358 public DoubleBuffer (Control parent) {
359 this.parent = parent;
360 real_graphics = new Stack ();
361 int width = parent.Width;
362 int height = parent.Height;
364 if (width < 1) width = 1;
365 if (height < 1) height = 1;
367 XplatUI.CreateOffscreenDrawable (parent.Handle, width, height, out back_buffer);
371 public void Blit (PaintEventArgs pe) {
372 Graphics buffered_graphics;
373 buffered_graphics = XplatUI.GetOffscreenGraphics (back_buffer);
374 XplatUI.BlitFromOffscreen (parent.Handle, pe.Graphics, back_buffer, buffered_graphics, pe.ClipRectangle);
375 buffered_graphics.Dispose ();
378 public void Start (PaintEventArgs pe) {
379 // We need to get the graphics for every paint.
380 real_graphics.Push(pe.SetGraphics (XplatUI.GetOffscreenGraphics (back_buffer)));
383 public void End (PaintEventArgs pe) {
384 Graphics buffered_graphics;
385 buffered_graphics = pe.SetGraphics ((Graphics) real_graphics.Pop ());
387 if (pending_disposal)
390 XplatUI.BlitFromOffscreen (parent.Handle, pe.Graphics, back_buffer, buffered_graphics, pe.ClipRectangle);
391 InvalidRegion.Exclude (pe.ClipRectangle);
393 buffered_graphics.Dispose ();
396 public void Invalidate () {
397 if (InvalidRegion != null)
398 InvalidRegion.Dispose ();
399 InvalidRegion = new Region (parent.ClientRectangle);
402 public void Dispose () {
403 if (real_graphics.Count > 0) {
404 pending_disposal = true;
408 XplatUI.DestroyOffscreenDrawable (back_buffer);
410 if (InvalidRegion != null)
411 InvalidRegion.Dispose ();
412 InvalidRegion = null;
414 GC.SuppressFinalize (this);
417 #region IDisposable Members
418 void IDisposable.Dispose () {
428 [ListBindable (false)]
431 public class ControlCollection : Layout.ArrangedElementCollection, IList, ICollection, ICloneable, IEnumerable {
433 [DesignerSerializer("System.Windows.Forms.Design.ControlCollectionCodeDomSerializer, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
434 public class ControlCollection : IList, ICollection, ICloneable, IEnumerable {
436 #region ControlCollection Local Variables
441 Control [] all_controls;
443 #endregion // ControlCollection Local Variables
445 #region ControlCollection Public Constructor
446 public ControlCollection (Control owner)
450 this.list = new ArrayList();
455 #region ControlCollection Public Instance Properties
459 get { return list.Count; }
462 public bool IsReadOnly {
464 return list.IsReadOnly;
470 public Control Owner {
471 get { return this.owner; }
474 public virtual Control this[string key] {
476 int index = IndexOfKey (key);
487 public virtual Control this[int index] {
489 if (index < 0 || index >= list.Count) {
490 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
492 return (Control)list[index];
498 #endregion // ControlCollection Public Instance Properties
500 #region ControlCollection Instance Methods
502 public virtual void Add (Control value)
507 Form form_value = value as Form;
508 Form form_owner = owner as Form;
509 bool owner_permits_toplevels = (owner is MdiClient) || (form_owner != null && form_owner.IsMdiContainer);
510 bool child_is_toplevel = value.GetTopLevel();
511 bool child_is_mdichild = form_value != null && form_value.IsMdiChild;
513 if (child_is_toplevel && !(owner_permits_toplevels && child_is_mdichild))
514 throw new ArgumentException("Cannot add a top level control to a control.", "value");
516 if (child_is_mdichild && form_value.MdiParent != null && form_value.MdiParent != owner && form_value.MdiParent != owner.Parent) {
517 throw new ArgumentException ("Form cannot be added to the Controls collection that has a valid MDI parent.", "value");
520 value.recalculate_distances = true;
522 if (Contains (value)) {
523 owner.PerformLayout();
527 if (value.tab_index == -1) {
533 end = owner.child_controls.Count;
534 for (int i = 0; i < end; i++) {
535 index = owner.child_controls[i].tab_index;
540 value.tab_index = use;
543 if (value.parent != null) {
544 value.parent.Controls.Remove(value);
550 value.ChangeParent(owner);
555 owner.UpdateChildrenZOrder();
556 owner.PerformLayout(value, "Parent");
557 owner.OnControlAdded(new ControlEventArgs(value));
560 internal void AddToList (Control c)
566 internal virtual void AddImplicit (Control control)
568 if (impl_list == null)
569 impl_list = new ArrayList ();
571 if (AllContains (control)) {
572 owner.PerformLayout ();
576 if (control.parent != null) {
577 control.parent.Controls.Remove(control);
581 impl_list.Add (control);
583 control.ChangeParent (owner);
584 control.InitLayout ();
586 owner.UpdateChildrenZOrder ();
588 // If we are adding a new control that isn't
589 // visible, don't trigger a layout
590 if (control.VisibleInternal)
591 owner.PerformLayout (control, "Parent");
594 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
596 public virtual void AddRange (Control[] controls)
598 if (controls == null)
599 throw new ArgumentNullException ("controls");
601 owner.SuspendLayout ();
604 for (int i = 0; i < controls.Length; i++)
607 owner.ResumeLayout ();
611 internal virtual void AddRangeImplicit (Control [] controls)
613 if (controls == null)
614 throw new ArgumentNullException ("controls");
616 owner.SuspendLayout ();
619 for (int i = 0; i < controls.Length; i++)
620 AddImplicit (controls [i]);
622 owner.ResumeLayout (false);
629 public virtual void Clear ()
633 // MS sends remove events in reverse order
634 while (list.Count > 0) {
635 Remove((Control)list[list.Count - 1]);
639 internal virtual void ClearImplicit ()
641 if (impl_list == null)
647 public bool Contains (Control control)
649 return list.Contains (control);
652 internal bool ImplicitContains (Control value) {
653 if (impl_list == null)
656 return impl_list.Contains (value);
659 internal bool AllContains (Control value) {
660 return Contains (value) || ImplicitContains (value);
664 public virtual bool ContainsKey (string key)
666 return IndexOfKey (key) >= 0;
671 public void CopyTo (Array dest, int index)
673 list.CopyTo (dest, index);
676 public override bool Equals (object other)
678 if (other is ControlCollection && (((ControlCollection)other).owner==this.owner)) {
687 // LAMESPEC: MSDN says AE, MS implementation throws ANE
688 public Control[] Find (string key, bool searchAllChildren)
690 if (string.IsNullOrEmpty (key))
691 throw new ArgumentNullException ("key");
693 ArrayList al = new ArrayList ();
695 foreach (Control c in list) {
696 if (c.Name.Equals (key, StringComparison.CurrentCultureIgnoreCase))
699 if (searchAllChildren)
700 al.AddRange (c.Controls.Find (key, true));
703 return (Control[])al.ToArray (typeof (Control));
707 public int GetChildIndex(Control child) {
708 return GetChildIndex(child, false);
716 GetChildIndex(Control child, bool throwException) {
719 index=list.IndexOf(child);
721 if (index==-1 && throwException) {
722 throw new ArgumentException("Not a child control", "child");
728 public override IEnumerator
733 return new ControlCollectionEnumerator (list);
736 internal IEnumerator GetAllEnumerator () {
737 Control [] res = GetAllControls ();
738 return res.GetEnumerator ();
741 internal ArrayList ImplicitControls {
742 get { return impl_list; }
745 internal Control [] GetAllControls () {
746 if (all_controls != null)
749 if (impl_list == null) {
750 all_controls = (Control []) list.ToArray (typeof (Control));
754 all_controls = new Control [list.Count + impl_list.Count];
755 impl_list.CopyTo (all_controls);
756 list.CopyTo (all_controls, impl_list.Count);
762 public override int GetHashCode ()
764 return base.GetHashCode ();
768 public int IndexOf (Control control)
770 return list.IndexOf (control);
774 public virtual int IndexOfKey (string key)
776 if (string.IsNullOrEmpty (key))
779 for (int i = 0; i < list.Count; i++)
780 if (((Control)list[i]).Name.Equals (key, StringComparison.CurrentCultureIgnoreCase))
787 public virtual void Remove (Control value)
795 owner.PerformLayout(value, "Parent");
796 owner.OnControlRemoved(new ControlEventArgs(value));
798 ContainerControl container = owner.InternalGetContainerControl ();
799 if (container != null) {
800 // Inform any container controls about the loss of a child control
801 // so that they can update their active control
802 container.ChildControlRemoved (value);
805 value.ChangeParent(null);
807 owner.UpdateChildrenZOrder();
810 internal virtual void RemoveImplicit (Control control)
812 if (impl_list != null) {
814 impl_list.Remove (control);
815 owner.PerformLayout (control, "Parent");
816 owner.OnControlRemoved (new ControlEventArgs (control));
818 control.ChangeParent (null);
819 owner.UpdateChildrenZOrder ();
822 public void RemoveAt (int index)
824 if (index < 0 || index >= list.Count)
825 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
827 Remove ((Control) list [index]);
831 public virtual void RemoveByKey (string key)
833 int index = IndexOfKey (key);
845 SetChildIndex(Control child, int newIndex)
848 throw new ArgumentNullException ("child");
852 old_index=list.IndexOf(child);
854 throw new ArgumentException("Not a child control", "child");
857 if (old_index==newIndex) {
862 list.RemoveAt(old_index);
864 if (newIndex>list.Count) {
867 list.Insert(newIndex, child);
869 child.UpdateZOrder();
870 owner.PerformLayout();
873 #endregion // ControlCollection Private Instance Methods
875 #region ControlCollection Interface Properties
878 object IList.this [int index] {
880 if (index<0 || index>=list.Count) {
881 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
887 if (!(value is Control)) {
888 throw new ArgumentException("Object of type Control required", "value");
892 Control ctrl = (Control) value;
895 ctrl.ChangeParent(owner);
899 owner.UpdateChildrenZOrder();
900 owner.PerformLayout(ctrl, "Parent");
904 bool IList.IsFixedSize {
910 bool ICollection.IsSynchronized {
912 return list.IsSynchronized;
916 object ICollection.SyncRoot {
918 return list.SyncRoot;
923 #endregion // ControlCollection Interface Properties
925 #region ControlCollection Interface Methods
927 int IList.Add (object control)
929 if (!(control is Control))
930 throw new ArgumentException ("Object of type Control required", "control");
933 throw new ArgumentException ("control", "Cannot add null controls");
935 this.Add ((Control)control);
936 return this.IndexOf ((Control)control);
940 bool IList.Contains (object control)
942 if (!(control is Control))
943 throw new ArgumentException ("Object of type Control required", "control");
945 return this.Contains ((Control) control);
948 int IList.IndexOf (object control)
950 if (!(control is Control))
951 throw new ArgumentException ("Object of type Control required", "control");
953 return this.IndexOf ((Control) control);
956 void IList.Insert (int index, object value)
958 if (!(value is Control))
959 throw new ArgumentException("Object of type Control required", "value");
962 list.Insert (index, value);
966 void IList.Remove (object control)
968 if (!(control is Control))
969 throw new ArgumentException ("Object of type Control required", "control");
971 this.Remove ((Control)control);
974 Object ICloneable.Clone ()
976 ControlCollection clone = new ControlCollection (this.owner);
977 clone.list = (ArrayList)list.Clone (); // FIXME: Do we need this?
981 #endregion // ControlCollection Interface Methods
983 internal class ControlCollectionEnumerator : IEnumerator
985 private ArrayList list;
988 public ControlCollectionEnumerator (ArrayList collection)
993 #region IEnumerator Members
994 public object Current {
997 return list[position];
998 } catch (IndexOutOfRangeException) {
999 throw new InvalidOperationException ();
1004 public bool MoveNext ()
1007 return (position < list.Count);
1010 public void Reset ()
1018 #endregion // ControlCollection Class
1020 #region Public Constructors
1024 if (WindowsFormsSynchronizationContext.AutoInstall)
1025 if (!(SynchronizationContext.Current is WindowsFormsSynchronizationContext))
1026 SynchronizationContext.SetSynchronizationContext (new WindowsFormsSynchronizationContext ());
1029 layout_type = LayoutType.Anchor;
1030 anchor_style = AnchorStyles.Top | AnchorStyles.Left;
1034 is_captured = false;
1035 is_disposed = false;
1038 layout_pending = false;
1039 is_toplevel = false;
1040 causes_validation = true;
1042 layout_suspended = 0;
1046 right_to_left = RightToLeft.Inherit;
1047 border_style = BorderStyle.None;
1048 background_color = Color.Empty;
1052 ime_mode = ImeMode.Inherit;
1053 use_compatible_text_rendering = true;
1054 show_keyboard_cues = false;
1055 show_focus_cues = SystemInformation.MenuAccessKeysUnderlined;
1056 use_wait_cursor = false;
1059 backgroundimage_layout = ImageLayout.Tile;
1060 use_compatible_text_rendering = Application.use_compatible_text_rendering;
1061 padding = this.DefaultPadding;
1062 maximum_size = new Size();
1063 minimum_size = new Size();
1064 margin = this.DefaultMargin;
1065 auto_size_mode = AutoSizeMode.GrowOnly;
1068 control_style = ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint |
1069 ControlStyles.Selectable | ControlStyles.StandardClick |
1070 ControlStyles.StandardDoubleClick;
1072 control_style |= ControlStyles.UseTextForAccessibility;
1076 background_image = null;
1077 text = string.Empty;
1078 name = string.Empty;
1080 window_target = new ControlWindowTarget(this);
1081 window = new ControlNativeWindow(this);
1082 child_controls = CreateControlsInstance();
1084 bounds.Size = DefaultSize;
1085 client_size = ClientSizeFromSize (bounds.Size);
1086 client_rect = new Rectangle (Point.Empty, client_size);
1087 explicit_bounds = bounds;
1090 public Control (Control parent, string text) : this()
1096 public Control (Control parent, string text, int left, int top, int width, int height) : this()
1099 SetBounds(left, top, width, height, BoundsSpecified.All);
1103 public Control (string text) : this()
1108 public Control (string text, int left, int top, int width, int height) : this()
1110 SetBounds(left, top, width, height, BoundsSpecified.All);
1114 private delegate void RemoveDelegate(object c);
1116 protected override void Dispose (bool disposing)
1118 if (!is_disposed && disposing) {
1119 is_disposing = true;
1122 DisposeBackBuffer ();
1124 if (this.InvokeRequired) {
1125 if (Application.MessageLoop && IsHandleCreated) {
1126 this.BeginInvokeInternal(new MethodInvoker(DestroyHandle), null);
1133 parent.Controls.Remove(this);
1135 Control [] children = child_controls.GetAllControls ();
1136 for (int i=0; i<children.Length; i++) {
1137 children[i].parent = null; // Need to set to null or our child will try and remove from ourselves and crash
1138 children[i].Dispose();
1142 base.Dispose(disposing);
1144 #endregion // Public Constructors
1146 #region Internal Properties
1148 internal Rectangle PaddingClientRectangle
1152 return new Rectangle (
1153 ClientRectangle.Left + padding.Left,
1154 ClientRectangle.Top + padding.Top,
1155 ClientRectangle.Width - padding.Horizontal,
1156 ClientRectangle.Height - padding.Vertical);
1158 return ClientRectangle;
1163 private MenuTracker active_tracker;
1165 internal MenuTracker ActiveTracker {
1166 get { return active_tracker; }
1168 if (value == active_tracker)
1171 Capture = value != null;
1172 active_tracker = value;
1176 // Control is currently selected, like Focused, except maintains state
1177 // when Form loses focus
1178 internal bool InternalSelected {
1180 IContainerControl container;
1182 container = GetContainerControl();
1184 if (container != null && container.ActiveControl == this)
1191 // Looks for focus in child controls
1192 // and also in the implicit ones
1193 internal bool InternalContainsFocus {
1195 IntPtr focused_window;
1197 focused_window = XplatUI.GetFocus();
1198 if (IsHandleCreated) {
1199 if (focused_window == Handle)
1202 foreach (Control child_control in child_controls.GetAllControls ())
1203 if (child_control.InternalContainsFocus)
1211 // Mouse is currently within the control's bounds
1212 internal bool Entered {
1213 get { return this.is_entered; }
1216 internal bool VisibleInternal {
1217 get { return is_visible; }
1220 internal LayoutType ControlLayoutType {
1221 get { return layout_type; }
1224 internal BorderStyle InternalBorderStyle {
1226 return border_style;
1230 if (!Enum.IsDefined (typeof (BorderStyle), value))
1231 throw new InvalidEnumArgumentException (string.Format("Enum argument value '{0}' is not valid for BorderStyle", value));
1233 if (border_style != value) {
1234 border_style = value;
1236 if (IsHandleCreated) {
1237 XplatUI.SetBorderStyle (window.Handle, (FormBorderStyle)border_style);
1241 client_size = ClientSizeFromSize (bounds.Size);
1246 internal Size InternalClientSize { set { this.client_size = value; } }
1247 internal virtual bool ActivateOnShow { get { return true; } }
1248 internal Rectangle ExplicitBounds { get { return this.explicit_bounds; } set { this.explicit_bounds = value; } }
1250 internal bool ValidationFailed {
1252 ContainerControl c = InternalGetContainerControl ();
1254 return c.validation_failed;
1258 ContainerControl c = InternalGetContainerControl ();
1260 c.validation_failed = value;
1263 #endregion // Internal Properties
1265 #region Private & Internal Methods
1268 void IDropTarget.OnDragDrop (DragEventArgs drgEvent)
1270 OnDragDrop (drgEvent);
1273 void IDropTarget.OnDragEnter (DragEventArgs drgEvent)
1275 OnDragEnter (drgEvent);
1278 void IDropTarget.OnDragLeave (EventArgs e)
1283 void IDropTarget.OnDragOver (DragEventArgs drgEvent)
1285 OnDragOver (drgEvent);
1289 internal IAsyncResult BeginInvokeInternal (Delegate method, object [] args) {
1290 return BeginInvokeInternal (method, args, FindControlToInvokeOn ());
1293 internal IAsyncResult BeginInvokeInternal (Delegate method, object [] args, Control control) {
1294 AsyncMethodResult result;
1295 AsyncMethodData data;
1297 result = new AsyncMethodResult ();
1298 data = new AsyncMethodData ();
1300 data.Handle = control.GetInvokableHandle ();
1301 data.Method = method;
1303 data.Result = result;
1306 if (!ExecutionContext.IsFlowSuppressed ()) {
1307 data.Context = ExecutionContext.Capture ();
1310 #if !MWF_ON_MSRUNTIME
1311 if (SecurityManager.SecurityEnabled) {
1312 data.Stack = CompressedStack.GetCompressedStack ();
1317 XplatUI.SendAsyncMethod (data);
1321 // The CheckForIllegalCrossThreadCalls in the #if 2.0 of
1322 // Control.Handle throws an exception when we are trying
1323 // to get the Handle to properly invoke on. This avoids that.
1324 private IntPtr GetInvokableHandle ()
1326 if (!IsHandleCreated)
1329 return window.Handle;
1332 internal void PointToClient (ref int x, ref int y) {
1333 XplatUI.ScreenToClient (Handle, ref x, ref y);
1336 internal void PointToScreen (ref int x, ref int y) {
1337 XplatUI.ClientToScreen (Handle, ref x, ref y);
1340 internal bool IsRecreating {
1342 return is_recreating;
1346 internal Graphics DeviceContext {
1347 get { return Hwnd.GraphicsContext; }
1350 // An internal way to have a fixed height
1351 // Basically for DataTimePicker 2.0
1352 internal virtual int OverrideHeight (int height)
1357 private void ProcessActiveTracker (ref Message m)
1359 bool is_up = ((Msg) m.Msg == Msg.WM_LBUTTONUP) ||
1360 ((Msg) m.Msg == Msg.WM_RBUTTONUP);
1362 MouseButtons mb = FromParamToMouseButtons ((int) m.WParam.ToInt32 ());
1364 // We add in the button that was released (not sent in WParam)
1366 switch ((Msg)m.Msg) {
1367 case Msg.WM_LBUTTONUP:
1368 mb |= MouseButtons.Left;
1370 case Msg.WM_RBUTTONUP:
1371 mb |= MouseButtons.Right;
1376 MouseEventArgs args = new MouseEventArgs (
1379 Control.MousePosition.X,
1380 Control.MousePosition.Y,
1384 active_tracker.OnMouseUp (args);
1387 if (!active_tracker.OnMouseDown (args)) {
1388 Control control = GetRealChildAtPoint (Cursor.Position);
1389 if (control != null) {
1390 Point pt = control.PointToClient (Cursor.Position);
1391 XplatUI.SendMessage (control.Handle,
1394 MakeParam (pt.X, pt.Y));
1400 private Control FindControlToInvokeOn ()
1404 if (p.IsHandleCreated)
1407 } while (p != null);
1409 if (p == null || !p.IsHandleCreated)
1410 throw new InvalidOperationException ("Cannot call Invoke or BeginInvoke on a control until the window handle is created");
1415 private void InvalidateBackBuffer () {
1416 if (backbuffer != null)
1417 backbuffer.Invalidate ();
1420 private DoubleBuffer GetBackBuffer () {
1421 if (backbuffer == null)
1422 backbuffer = new DoubleBuffer (this);
1426 private void DisposeBackBuffer () {
1427 if (backbuffer != null) {
1428 backbuffer.Dispose ();
1433 internal static void SetChildColor(Control parent) {
1436 for (int i=0; i < parent.child_controls.Count; i++) {
1437 child=parent.child_controls[i];
1438 if (child.child_controls.Count>0) {
1439 SetChildColor(child);
1444 internal bool Select(Control control) {
1445 IContainerControl container;
1447 if (control == null) {
1451 container = GetContainerControl();
1452 if (container != null && (Control)container != control) {
1453 container.ActiveControl = control;
1454 if (container.ActiveControl == control && !control.has_focus && control.IsHandleCreated)
1455 XplatUI.SetFocus(control.window.Handle);
1457 else if (control.IsHandleCreated) {
1458 XplatUI.SetFocus(control.window.Handle);
1463 internal virtual void DoDefaultAction() {
1464 // Only here to be overriden by our actual controls; this is needed by the accessibility class
1467 internal static IntPtr MakeParam (int low, int high){
1468 return new IntPtr (high << 16 | low & 0xffff);
1471 internal static int LowOrder (int param) {
1472 return ((int)(short)(param & 0xffff));
1475 internal static int HighOrder (long param) {
1476 return ((int)(short)(param >> 16));
1479 // This method exists so controls overriding OnPaintBackground can have default background painting done
1480 internal virtual void PaintControlBackground (PaintEventArgs pevent) {
1482 bool tbstyle_flat = ((CreateParams.Style & (int) ToolBarStyles.TBSTYLE_FLAT) != 0);
1484 // If we have transparent background
1485 if (((BackColor.A != 0xff) && GetStyle(ControlStyles.SupportsTransparentBackColor)) || tbstyle_flat) {
1486 if (parent != null) {
1487 PaintEventArgs parent_pe;
1488 GraphicsState state;
1490 parent_pe = new PaintEventArgs(pevent.Graphics, new Rectangle(pevent.ClipRectangle.X + Left, pevent.ClipRectangle.Y + Top, pevent.ClipRectangle.Width, pevent.ClipRectangle.Height));
1492 state = parent_pe.Graphics.Save();
1493 parent_pe.Graphics.TranslateTransform(-Left, -Top);
1494 parent.OnPaintBackground(parent_pe);
1495 parent_pe.Graphics.Restore(state);
1497 state = parent_pe.Graphics.Save();
1498 parent_pe.Graphics.TranslateTransform(-Left, -Top);
1499 parent.OnPaint(parent_pe);
1500 parent_pe.Graphics.Restore(state);
1501 parent_pe.SetGraphics(null);
1505 if ((clip_region != null) && (XplatUI.UserClipWontExposeParent)) {
1506 if (parent != null) {
1507 PaintEventArgs parent_pe;
1509 GraphicsState state;
1512 hwnd = Hwnd.ObjectFromHandle(Handle);
1515 parent_pe = new PaintEventArgs(pevent.Graphics, new Rectangle(pevent.ClipRectangle.X + Left, pevent.ClipRectangle.Y + Top, pevent.ClipRectangle.Width, pevent.ClipRectangle.Height));
1517 region = new Region ();
1519 region.Union(ClientRectangle);
1521 foreach (Rectangle r in hwnd.ClipRectangles) {
1525 state = parent_pe.Graphics.Save();
1526 parent_pe.Graphics.Clip = region;
1528 parent_pe.Graphics.TranslateTransform(-Left, -Top);
1529 parent.OnPaintBackground(parent_pe);
1530 parent_pe.Graphics.Restore(state);
1532 state = parent_pe.Graphics.Save();
1533 parent_pe.Graphics.Clip = region;
1535 parent_pe.Graphics.TranslateTransform(-Left, -Top);
1536 parent.OnPaint(parent_pe);
1537 parent_pe.Graphics.Restore(state);
1538 parent_pe.SetGraphics(null);
1540 region.Intersect(clip_region);
1541 pevent.Graphics.Clip = region;
1546 if (background_image == null) {
1547 if (!tbstyle_flat) {
1548 Rectangle paintRect = new Rectangle(pevent.ClipRectangle.X, pevent.ClipRectangle.Y, pevent.ClipRectangle.Width, pevent.ClipRectangle.Height);
1549 Brush pen = ThemeEngine.Current.ResPool.GetSolidBrush(BackColor);
1550 pevent.Graphics.FillRectangle(pen, paintRect);
1555 DrawBackgroundImage (pevent.Graphics);
1558 void DrawBackgroundImage (Graphics g) {
1560 Rectangle drawing_rectangle = new Rectangle ();
1561 g.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (BackColor), ClientRectangle);
1563 switch (backgroundimage_layout)
1565 case ImageLayout.Tile:
1566 using (TextureBrush b = new TextureBrush (background_image, WrapMode.Tile)) {
1567 g.FillRectangle (b, ClientRectangle);
1570 case ImageLayout.Center:
1571 drawing_rectangle.Location = new Point (ClientSize.Width / 2 - background_image.Width / 2, ClientSize.Height / 2 - background_image.Height / 2);
1572 drawing_rectangle.Size = background_image.Size;
1574 case ImageLayout.None:
1575 drawing_rectangle.Location = Point.Empty;
1576 drawing_rectangle.Size = background_image.Size;
1578 case ImageLayout.Stretch:
1579 drawing_rectangle = ClientRectangle;
1581 case ImageLayout.Zoom:
1582 drawing_rectangle = ClientRectangle;
1583 if ((float)background_image.Width / (float)background_image.Height < (float)drawing_rectangle.Width / (float) drawing_rectangle.Height) {
1584 drawing_rectangle.Width = (int) (background_image.Width * ((float)drawing_rectangle.Height / (float)background_image.Height));
1585 drawing_rectangle.X = (ClientRectangle.Width - drawing_rectangle.Width) / 2;
1587 drawing_rectangle.Height = (int) (background_image.Height * ((float)drawing_rectangle.Width / (float)background_image.Width));
1588 drawing_rectangle.Y = (ClientRectangle.Height - drawing_rectangle.Height) / 2;
1595 g.DrawImage (background_image, drawing_rectangle);
1598 using (TextureBrush b = new TextureBrush (background_image, WrapMode.Tile)) {
1599 g.FillRectangle (b, ClientRectangle);
1604 internal virtual void DndEnter (DragEventArgs e) {
1610 internal virtual void DndOver (DragEventArgs e) {
1616 internal virtual void DndDrop (DragEventArgs e) {
1619 } catch (Exception exc) {
1620 Console.Error.WriteLine ("MWF: Exception while dropping:");
1621 Console.Error.WriteLine (exc);
1625 internal virtual void DndLeave (EventArgs e) {
1631 internal virtual void DndFeedback(GiveFeedbackEventArgs e) {
1637 internal virtual void DndContinueDrag(QueryContinueDragEventArgs e) {
1639 OnQueryContinueDrag(e);
1643 internal static MouseButtons FromParamToMouseButtons (long param) {
1644 MouseButtons buttons = MouseButtons.None;
1646 if ((param & (long) MsgButtons.MK_LBUTTON) != 0)
1647 buttons |= MouseButtons.Left;
1649 if ((param & (long)MsgButtons.MK_MBUTTON) != 0)
1650 buttons |= MouseButtons.Middle;
1652 if ((param & (long)MsgButtons.MK_RBUTTON) != 0)
1653 buttons |= MouseButtons.Right;
1658 internal virtual void FireEnter () {
1659 OnEnter (EventArgs.Empty);
1662 internal virtual void FireLeave () {
1663 OnLeave (EventArgs.Empty);
1666 internal virtual void FireValidating (CancelEventArgs ce) {
1670 internal virtual void FireValidated () {
1671 OnValidated (EventArgs.Empty);
1674 internal virtual bool ProcessControlMnemonic(char charCode) {
1675 return ProcessMnemonic(charCode);
1678 private static Control FindFlatForward(Control container, Control start) {
1685 end = container.child_controls.Count;
1688 if (start != null) {
1689 index = start.tab_index;
1694 for (int i = 0; i < end; i++) {
1695 if (start == container.child_controls[i]) {
1700 if (found == null || found.tab_index > container.child_controls[i].tab_index) {
1701 if (container.child_controls[i].tab_index > index || (hit && container.child_controls[i].tab_index == index)) {
1702 found = container.child_controls[i];
1709 private static Control FindControlForward(Control container, Control start) {
1714 if (start == null) {
1715 return FindFlatForward(container, start);
1718 if (start.child_controls != null && start.child_controls.Count > 0 &&
1719 (start == container || !((start is IContainerControl) && start.GetStyle(ControlStyles.ContainerControl)))) {
1720 return FindControlForward(start, null);
1723 while (start != container) {
1724 found = FindFlatForward(start.parent, start);
1725 if (found != null) {
1728 start = start.parent;
1734 private static Control FindFlatBackward(Control container, Control start) {
1741 end = container.child_controls.Count;
1744 if (start != null) {
1745 index = start.tab_index;
1747 index = int.MaxValue;
1750 for (int i = end - 1; i >= 0; i--) {
1751 if (start == container.child_controls[i]) {
1756 if (found == null || found.tab_index < container.child_controls[i].tab_index) {
1757 if (container.child_controls[i].tab_index < index || (hit && container.child_controls[i].tab_index == index))
1758 found = container.child_controls[i];
1765 private static Control FindControlBackward(Control container, Control start) {
1767 Control found = null;
1769 if (start == null) {
1770 found = FindFlatBackward(container, start);
1772 else if (start != container) {
1773 if (start.parent != null) {
1774 found = FindFlatBackward(start.parent, start);
1776 if (found == null) {
1777 if (start.parent != container)
1778 return start.parent;
1784 if (found == null || start.parent == null)
1787 while (found != null && (found == container || (!((found is IContainerControl) && found.GetStyle(ControlStyles.ContainerControl))) &&
1788 found.child_controls != null && found.child_controls.Count > 0)) {
1789 // while (ctl.child_controls != null && ctl.child_controls.Count > 0 &&
1790 // (ctl == this || (!((ctl is IContainerControl) && ctl.GetStyle(ControlStyles.ContainerControl))))) {
1791 found = FindFlatBackward(found, null);
1801 if (start != null) {
1802 found = FindFlatBackward(start.parent, start);
1803 if (found == null) {
1804 if (start.parent != container) {
1805 return start.parent;
1809 if (found == null) {
1810 found = FindFlatBackward(container, start);
1813 if (container != start) {
1814 while ((found != null) && (!found.Contains(start)) && found.child_controls != null && found.child_controls.Count > 0 && !(found is IContainerControl)) {// || found.GetStyle(ControlStyles.ContainerControl))) {
1815 found = FindControlBackward(found, null);
1816 if (found != null) {
1825 internal virtual void HandleClick(int clicks, MouseEventArgs me) {
1826 bool standardclick = GetStyle (ControlStyles.StandardClick);
1827 bool standardclickclick = GetStyle (ControlStyles.StandardDoubleClick);
1828 if ((clicks > 1) && standardclick && standardclickclick) {
1831 OnMouseDoubleClick (me);
1833 OnDoubleClick(EventArgs.Empty);
1835 } else if (clicks == 1 && standardclick && !ValidationFailed) {
1840 OnClick(EventArgs.Empty);
1845 internal void CaptureWithConfine (Control ConfineWindow) {
1846 if (this.IsHandleCreated && !is_captured) {
1848 XplatUI.GrabWindow (this.window.Handle, ConfineWindow.Handle);
1852 private void CheckDataBindings () {
1853 if (data_bindings == null)
1856 foreach (Binding binding in data_bindings) {
1861 private void ChangeParent(Control new_parent) {
1865 Color pre_fore_color;
1866 Color pre_back_color;
1867 RightToLeft pre_rtl;
1869 // These properties are inherited from our parent
1870 // Get them pre parent-change and then send events
1871 // if they are changed after we have our new parent
1872 pre_enabled = Enabled;
1873 pre_visible = Visible;
1875 pre_fore_color = ForeColor;
1876 pre_back_color = BackColor;
1877 pre_rtl = RightToLeft;
1878 // MS doesn't seem to send a CursorChangedEvent
1880 parent = new_parent;
1882 Form frm = this as Form;
1884 frm.ChangingParent (new_parent);
1885 } else if (IsHandleCreated) {
1886 IntPtr parent_handle = IntPtr.Zero;
1887 if (new_parent != null && new_parent.IsHandleCreated)
1888 parent_handle = new_parent.Handle;
1889 XplatUI.SetParent (Handle, parent_handle);
1892 OnParentChanged(EventArgs.Empty);
1894 if (pre_enabled != Enabled) {
1895 OnEnabledChanged(EventArgs.Empty);
1898 if (pre_visible != Visible) {
1899 OnVisibleChanged(EventArgs.Empty);
1902 if (pre_font != Font) {
1903 OnFontChanged(EventArgs.Empty);
1906 if (pre_fore_color != ForeColor) {
1907 OnForeColorChanged(EventArgs.Empty);
1910 if (pre_back_color != BackColor) {
1911 OnBackColorChanged(EventArgs.Empty);
1914 if (pre_rtl != RightToLeft) {
1915 // MS sneaks a OnCreateControl and OnHandleCreated in here, I guess
1916 // because when RTL changes they have to recreate the win32 control
1917 // We don't really need that (until someone runs into compatibility issues)
1918 OnRightToLeftChanged(EventArgs.Empty);
1921 if ((new_parent != null) && new_parent.Created && is_visible && !Created) {
1925 if ((binding_context == null) && Created) {
1926 OnBindingContextChanged(EventArgs.Empty);
1930 // Sometimes we need to do this calculation without it being virtual (constructor)
1931 internal Size InternalSizeFromClientSize (Size clientSize)
1933 Rectangle ClientRect;
1934 Rectangle WindowRect;
1937 ClientRect = new Rectangle (0, 0, clientSize.Width, clientSize.Height);
1938 cp = this.CreateParams;
1940 if (XplatUI.CalculateWindowRect (ref ClientRect, cp, null, out WindowRect))
1941 return new Size (WindowRect.Width, WindowRect.Height);
1946 internal Size ClientSizeFromSize (Size size)
1948 // Calling this gives us the difference in Size and ClientSize.
1949 // We just have to apply that difference to our given size.
1950 Size client_size = this.InternalSizeFromClientSize (size);
1952 if (client_size == Size.Empty)
1955 return new Size (size.Width - (client_size.Width - size.Width), size.Height - (client_size.Height - size.Height));
1958 internal CreateParams GetCreateParams ()
1960 return CreateParams;
1964 internal virtual Size GetPreferredSizeCore (Size proposedSize)
1966 return this.explicit_bounds.Size;
1970 private void UpdateDistances() {
1971 if (parent != null) {
1972 if (bounds.Width >= 0)
1973 dist_right = parent.ClientSize.Width - bounds.X - bounds.Width;
1974 if (bounds.Height >= 0)
1975 dist_bottom = parent.ClientSize.Height - bounds.Y - bounds.Height;
1977 recalculate_distances = false;
1981 private Cursor GetAvailableCursor ()
1983 if (Cursor != null && Enabled) {
1987 if (Parent != null) {
1988 return Parent.GetAvailableCursor ();
1991 return Cursors.Default;
1994 private void UpdateCursor ()
1996 if (!IsHandleCreated)
2000 XplatUI.SetCursor (window.Handle, GetAvailableCursor ().handle);
2004 Point pt = PointToClient (Cursor.Position);
2006 if (!bounds.Contains (pt) && !Capture)
2009 if (cursor != null || use_wait_cursor) {
2010 XplatUI.SetCursor (window.Handle, Cursor.handle);
2012 XplatUI.SetCursor (window.Handle, GetAvailableCursor ().handle);
2016 private bool UseDoubleBuffering {
2018 if (!ThemeEngine.Current.DoubleBufferingSupported)
2021 // Since many of .Net's controls are unmanaged, they are doublebuffered
2022 // even though their bits may not be set in managed land. This allows
2023 // us to doublebuffer as well without affecting public style bits.
2024 if (force_double_buffer)
2031 return (control_style & ControlStyles.DoubleBuffer) != 0;
2035 internal void OnSizeInitializedOrChanged ()
2037 Form form = this as Form;
2038 if (form != null && form.WindowManager != null)
2039 ThemeEngine.Current.ManagedWindowOnSizeInitializedOrChanged (form);
2041 #endregion // Private & Internal Methods
2043 #region Public Static Properties
2044 public static Color DefaultBackColor {
2046 return ThemeEngine.Current.DefaultControlBackColor;
2050 public static Font DefaultFont {
2052 return ThemeEngine.Current.DefaultFont;
2056 public static Color DefaultForeColor {
2058 return ThemeEngine.Current.DefaultControlForeColor;
2062 public static Keys ModifierKeys {
2064 return XplatUI.State.ModifierKeys;
2068 public static MouseButtons MouseButtons {
2070 return XplatUI.State.MouseButtons;
2074 public static Point MousePosition {
2076 return Cursor.Position;
2081 [EditorBrowsable (EditorBrowsableState.Advanced)]
2082 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
2084 [MonoTODO ("Stub, value is not used")]
2085 public static bool CheckForIllegalCrossThreadCalls
2088 return verify_thread_handle;
2092 verify_thread_handle = value;
2096 #endregion // Public Static Properties
2098 #region Public Instance Properties
2099 [EditorBrowsable(EditorBrowsableState.Advanced)]
2101 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2102 public AccessibleObject AccessibilityObject {
2104 if (accessibility_object==null) {
2105 accessibility_object=CreateAccessibilityInstance();
2107 return accessibility_object;
2111 [EditorBrowsable(EditorBrowsableState.Advanced)]
2113 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2114 public string AccessibleDefaultActionDescription {
2116 return accessible_default_action;
2120 accessible_default_action = value;
2125 [DefaultValue(null)]
2126 [MWFCategory("Accessibility")]
2127 public string AccessibleDescription {
2129 return accessible_description;
2133 accessible_description = value;
2138 [DefaultValue(null)]
2139 [MWFCategory("Accessibility")]
2140 public string AccessibleName {
2142 return accessible_name;
2146 accessible_name = value;
2150 [DefaultValue(AccessibleRole.Default)]
2151 [MWFDescription("Role of the control"), MWFCategory("Accessibility")]
2152 public AccessibleRole AccessibleRole {
2154 return accessible_role;
2158 accessible_role = value;
2162 [DefaultValue(false)]
2163 [MWFCategory("Behavior")]
2164 public virtual bool AllowDrop {
2170 if (allow_drop == value)
2173 if (IsHandleCreated) {
2175 XplatUI.SetAllowDrop (Handle, value);
2181 [RefreshProperties(RefreshProperties.Repaint)]
2182 [DefaultValue(AnchorStyles.Top | AnchorStyles.Left)]
2183 [MWFCategory("Layout")]
2184 public virtual AnchorStyles Anchor {
2186 return anchor_style;
2190 layout_type = LayoutType.Anchor;
2192 if (anchor_style == value)
2196 dock_style = DockStyle.None;
2201 parent.PerformLayout(this, "Anchor");
2207 [DefaultValue (typeof (Point), "0, 0")]
2208 [EditorBrowsable (EditorBrowsableState.Advanced)]
2209 public virtual Point AutoScrollOffset {
2211 return auto_scroll_offset;
2215 this.auto_scroll_offset = value;
2219 // XXX: Implement me!
2222 [RefreshProperties (RefreshProperties.All)]
2223 [Localizable (true)]
2224 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
2226 [EditorBrowsable (EditorBrowsableState.Never)]
2227 [DefaultValue (false)]
2228 public virtual bool AutoSize {
2229 get { return auto_size; }
2231 if (this.auto_size != value) {
2234 // If we're turning this off, reset our size
2236 Size = explicit_bounds.Size;
2239 Parent.PerformLayout (this, "AutoSize");
2242 OnAutoSizeChanged (EventArgs.Empty);
2248 [AmbientValue ("{Width=0, Height=0}")]
2250 [AmbientValue (typeof(Size), "0, 0")]
2252 [MWFCategory("Layout")]
2253 public virtual Size MaximumSize {
2255 return maximum_size;
2258 if (maximum_size != value) {
2259 maximum_size = value;
2260 Size = PreferredSize;
2265 internal bool ShouldSerializeMaximumSize ()
2267 return this.MaximumSize != DefaultMaximumSize;
2270 [MWFCategory("Layout")]
2271 public virtual Size MinimumSize {
2273 return minimum_size;
2276 if (minimum_size != value) {
2277 minimum_size = value;
2278 Size = PreferredSize;
2283 internal bool ShouldSerializeMinimumSize ()
2285 return this.MinimumSize != DefaultMinimumSize;
2290 [MWFCategory("Appearance")]
2291 public virtual Color BackColor {
2293 if (background_color.IsEmpty) {
2295 Color pcolor = parent.BackColor;
2296 if (pcolor.A == 0xff || GetStyle(ControlStyles.SupportsTransparentBackColor))
2299 return DefaultBackColor;
2301 return background_color;
2305 if (!value.IsEmpty && (value.A != 0xff) && !GetStyle(ControlStyles.SupportsTransparentBackColor)) {
2306 throw new ArgumentException("Transparent background colors are not supported on this control");
2309 if (background_color != value) {
2310 background_color=value;
2311 SetChildColor(this);
2312 OnBackColorChanged(EventArgs.Empty);
2318 internal bool ShouldSerializeBackColor ()
2320 return this.BackColor != DefaultBackColor;
2324 [DefaultValue(null)]
2325 [MWFCategory("Appearance")]
2326 public virtual Image BackgroundImage {
2328 return background_image;
2332 if (background_image!=value) {
2333 background_image=value;
2334 OnBackgroundImageChanged(EventArgs.Empty);
2341 [DefaultValue (ImageLayout.Tile)]
2342 [Localizable (true)]
2343 [MWFCategory("Appearance")]
2344 public virtual ImageLayout BackgroundImageLayout {
2346 return backgroundimage_layout;
2349 if (Array.IndexOf (Enum.GetValues (typeof (ImageLayout)), value) == -1)
2350 throw new InvalidEnumArgumentException ("value", (int) value, typeof(ImageLayout));
2352 if (value != backgroundimage_layout) {
2353 backgroundimage_layout = value;
2355 OnBackgroundImageLayoutChanged (EventArgs.Empty);
2361 [EditorBrowsable(EditorBrowsableState.Advanced)]
2363 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2364 public virtual BindingContext BindingContext {
2366 if (binding_context != null)
2367 return binding_context;
2370 binding_context = Parent.BindingContext;
2371 return binding_context;
2374 if (binding_context != value) {
2375 binding_context = value;
2376 OnBindingContextChanged(EventArgs.Empty);
2381 [EditorBrowsable(EditorBrowsableState.Advanced)]
2383 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2386 return bounds.Y+bounds.Height;
2390 [EditorBrowsable(EditorBrowsableState.Advanced)]
2392 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2393 public Rectangle Bounds {
2399 SetBounds(value.Left, value.Top, value.Width, value.Height, BoundsSpecified.All);
2403 [EditorBrowsable(EditorBrowsableState.Advanced)]
2405 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2406 public bool CanFocus {
2408 if (IsHandleCreated && Visible && Enabled) {
2415 [EditorBrowsable(EditorBrowsableState.Advanced)]
2417 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2418 public bool CanSelect {
2422 if (!GetStyle(ControlStyles.Selectable)) {
2427 while (parent != null) {
2428 if (!parent.is_visible || !parent.is_enabled) {
2432 parent = parent.parent;
2438 internal virtual bool InternalCapture {
2448 [EditorBrowsable(EditorBrowsableState.Advanced)]
2450 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2451 public bool Capture {
2453 return this.is_captured;
2457 // Call OnMouseCaptureChanged when we get WM_CAPTURECHANGED.
2458 if (value != is_captured) {
2461 XplatUI.GrabWindow(Handle, IntPtr.Zero);
2463 if (IsHandleCreated)
2464 XplatUI.UngrabWindow(Handle);
2465 is_captured = false;
2471 [DefaultValue(true)]
2472 [MWFCategory("Focus")]
2473 public bool CausesValidation {
2475 return this.causes_validation;
2479 if (this.causes_validation != value) {
2480 causes_validation = value;
2481 OnCausesValidationChanged(EventArgs.Empty);
2486 [EditorBrowsable(EditorBrowsableState.Advanced)]
2488 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2489 public Rectangle ClientRectangle {
2491 client_rect.Width = client_size.Width;
2492 client_rect.Height = client_size.Height;
2497 [EditorBrowsable(EditorBrowsableState.Advanced)]
2499 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2500 public Size ClientSize {
2503 if ((this is Form) && (((Form)this).form_parent_window != null)) {
2504 return ((Form)this).form_parent_window.ClientSize;
2512 this.SetClientSizeCore(value.Width, value.Height);
2514 this.OnClientSizeChanged (EventArgs.Empty);
2519 [EditorBrowsable(EditorBrowsableState.Advanced)]
2521 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2522 [DescriptionAttribute("ControlCompanyNameDescr")]
2523 public String CompanyName {
2525 return "Mono Project, Novell, Inc.";
2529 [EditorBrowsable(EditorBrowsableState.Advanced)]
2531 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2532 public bool ContainsFocus {
2534 IntPtr focused_window;
2536 focused_window = XplatUI.GetFocus();
2537 if (IsHandleCreated) {
2538 if (focused_window == Handle) {
2542 for (int i=0; i < child_controls.Count; i++) {
2543 if (child_controls[i].ContainsFocus) {
2554 [DefaultValue(null)]
2555 [MWFCategory("Behavior")]
2556 public virtual ContextMenu ContextMenu {
2558 return ContextMenuInternal;
2562 ContextMenuInternal = value;
2566 internal virtual ContextMenu ContextMenuInternal {
2568 return context_menu;
2571 if (context_menu != value) {
2572 context_menu = value;
2573 OnContextMenuChanged (EventArgs.Empty);
2579 [DefaultValue (null)]
2580 [MWFCategory("Behavior")]
2581 public virtual ContextMenuStrip ContextMenuStrip {
2582 get { return this.context_menu_strip; }
2584 if (this.context_menu_strip != value) {
2585 this.context_menu_strip = value;
2587 value.container = this;
2588 OnContextMenuStripChanged (EventArgs.Empty);
2595 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
2596 public ControlCollection Controls {
2598 return this.child_controls;
2602 [EditorBrowsable(EditorBrowsableState.Advanced)]
2604 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2605 public bool Created {
2607 return (!is_disposed && is_created);
2611 [AmbientValue(null)]
2612 [MWFCategory("Appearance")]
2613 public virtual Cursor Cursor {
2616 if (use_wait_cursor)
2617 return Cursors.WaitCursor;
2620 if (cursor != null) {
2624 if (parent != null) {
2625 return parent.Cursor;
2628 return Cursors.Default;
2632 if (cursor == value) {
2639 OnCursorChanged (EventArgs.Empty);
2643 internal bool ShouldSerializeCursor ()
2645 return this.Cursor != Cursors.Default;
2648 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
2649 [ParenthesizePropertyName(true)]
2650 [RefreshProperties(RefreshProperties.All)]
2651 [MWFCategory("Data")]
2652 public ControlBindingsCollection DataBindings {
2654 if (data_bindings == null)
2655 data_bindings = new ControlBindingsCollection (this);
2656 return data_bindings;
2660 [EditorBrowsable(EditorBrowsableState.Advanced)]
2662 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2663 public virtual Rectangle DisplayRectangle {
2665 return ClientRectangle;
2669 [EditorBrowsable(EditorBrowsableState.Advanced)]
2671 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2672 public bool Disposing {
2679 [RefreshProperties(RefreshProperties.Repaint)]
2680 [DefaultValue(DockStyle.None)]
2681 [MWFCategory("Layout")]
2682 public virtual DockStyle Dock {
2688 // If the user sets this to None, we need to still use Anchor layout
2689 if (value != DockStyle.None)
2690 layout_type = LayoutType.Dock;
2692 if (dock_style == value) {
2696 if (!Enum.IsDefined (typeof (DockStyle), value)) {
2697 throw new InvalidEnumArgumentException ("value", (int) value,
2698 typeof (DockStyle));
2702 anchor_style = AnchorStyles.Top | AnchorStyles.Left;
2704 if (dock_style == DockStyle.None) {
2705 bounds = explicit_bounds;
2706 layout_type = LayoutType.Anchor;
2710 parent.PerformLayout(this, "Dock");
2711 else if (Controls.Count > 0)
2714 OnDockChanged(EventArgs.Empty);
2719 protected virtual bool DoubleBuffered {
2721 return (control_style & ControlStyles.OptimizedDoubleBuffer) != 0;
2725 if (value == DoubleBuffered)
2728 SetStyle (ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);
2730 SetStyle (ControlStyles.OptimizedDoubleBuffer, false);
2736 public void DrawToBitmap (Bitmap bitmap, Rectangle targetBounds)
2738 Graphics g = Graphics.FromImage (bitmap);
2740 // Only draw within the target bouds, and up to the size of the control
2741 g.IntersectClip (targetBounds);
2742 g.IntersectClip (Bounds);
2744 // Logic copied from WmPaint
2745 PaintEventArgs pea = new PaintEventArgs (g, targetBounds);
2747 if (!GetStyle (ControlStyles.Opaque))
2748 OnPaintBackground (pea);
2750 OnPaintBackgroundInternal (pea);
2752 OnPaintInternal (pea);
2763 [MWFCategory("Behavior")]
2764 public bool Enabled {
2770 if (parent != null) {
2771 return parent.Enabled;
2778 if (this.is_enabled == value)
2781 bool old_value = is_enabled;
2788 if (old_value != value && !value && this.has_focus)
2789 SelectNextControl(this, true, true, true, true);
2791 OnEnabledChanged (EventArgs.Empty);
2795 internal bool ShouldSerializeEnabled ()
2797 return this.Enabled != true;
2800 [EditorBrowsable(EditorBrowsableState.Advanced)]
2802 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2803 public virtual bool Focused {
2805 return this.has_focus;
2810 [AmbientValue(null)]
2812 [MWFCategory("Appearance")]
2813 public virtual Font Font {
2815 [return: MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof (Font))]
2821 if (parent != null) {
2822 Font f = parent.Font;
2831 [param:MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Font))]
2833 if (font != null && font == value) {
2839 OnFontChanged (EventArgs.Empty);
2844 internal bool ShouldSerializeFont ()
2846 return !this.Font.Equals (DefaultFont);
2850 [MWFCategory("Appearance")]
2851 public virtual Color ForeColor {
2853 if (foreground_color.IsEmpty) {
2855 return parent.ForeColor;
2857 return DefaultForeColor;
2859 return foreground_color;
2863 if (foreground_color != value) {
2864 foreground_color=value;
2866 OnForeColorChanged(EventArgs.Empty);
2871 internal bool ShouldSerializeForeColor ()
2873 return this.ForeColor != DefaultForeColor;
2878 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2879 public IntPtr Handle { // IWin32Window
2882 if (verify_thread_handle) {
2883 if (this.InvokeRequired) {
2884 throw new InvalidOperationException("Cross-thread access of handle detected. Handle access only valid on thread that created the control");
2888 if (!IsHandleCreated) {
2891 return window.Handle;
2895 [EditorBrowsable(EditorBrowsableState.Advanced)]
2897 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2898 public bool HasChildren {
2900 if (this.child_controls.Count>0) {
2907 [EditorBrowsable(EditorBrowsableState.Always)]
2909 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2911 get { return this.bounds.Height; }
2912 set { SetBounds(bounds.X, bounds.Y, bounds.Width, value, BoundsSpecified.Height); }
2915 [AmbientValue(ImeMode.Inherit)]
2917 [MWFCategory("Behavior")]
2918 public ImeMode ImeMode {
2920 if (ime_mode == ImeMode.Inherit) {
2922 return parent.ImeMode;
2924 return ImeMode.NoControl; // default value
2930 if (ime_mode != value) {
2933 OnImeModeChanged(EventArgs.Empty);
2938 internal bool ShouldSerializeImeMode ()
2940 return this.ImeMode != ImeMode.NoControl;
2943 [EditorBrowsable(EditorBrowsableState.Advanced)]
2945 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2946 public bool InvokeRequired { // ISynchronizeInvoke
2948 if (creator_thread != null && creator_thread!=Thread.CurrentThread) {
2955 [EditorBrowsable(EditorBrowsableState.Advanced)]
2957 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2958 public bool IsAccessible {
2960 return is_accessible;
2964 is_accessible = value;
2968 [EditorBrowsable(EditorBrowsableState.Advanced)]
2970 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2971 public bool IsDisposed {
2973 return this.is_disposed;
2977 [EditorBrowsable(EditorBrowsableState.Advanced)]
2979 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2980 public bool IsHandleCreated {
2982 if (window == null || window.Handle == IntPtr.Zero)
2985 Hwnd hwnd = Hwnd.ObjectFromHandle (window.Handle);
2986 if (hwnd != null && hwnd.zombie)
2994 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2995 [EditorBrowsable(EditorBrowsableState.Advanced)]
2997 [MonoNotSupported ("RTL is not supported")]
2998 public bool IsMirrored {
2999 get { return false; }
3004 [EditorBrowsable (EditorBrowsableState.Advanced)]
3008 Layout.LayoutEngine LayoutEngine {
3010 if (layout_engine == null)
3011 layout_engine = new Layout.DefaultLayout ();
3012 return layout_engine;
3016 [EditorBrowsable(EditorBrowsableState.Always)]
3018 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
3021 return this.bounds.X;
3025 SetBounds(value, bounds.Y, bounds.Width, bounds.Height, BoundsSpecified.X);
3030 [MWFCategory("Layout")]
3031 public Point Location {
3033 return new Point(bounds.X, bounds.Y);
3037 SetBounds(value.X, value.Y, bounds.Width, bounds.Height, BoundsSpecified.Location);
3041 internal bool ShouldSerializeLocation ()
3043 return this.Location != new Point (0, 0);
3047 [Localizable (true)]
3048 [MWFCategory("Layout")]
3049 public Padding Margin {
3050 get { return this.margin; }
3052 if (this.margin != value) {
3053 this.margin = value;
3055 Parent.PerformLayout (this, "Margin");
3056 OnMarginChanged (EventArgs.Empty);
3061 internal bool ShouldSerializeMargin ()
3063 return this.Margin != DefaultMargin;
3068 public string Name {
3080 [MWFCategory("Layout")]
3081 public Padding Padding {
3087 if (padding != value) {
3089 OnPaddingChanged (EventArgs.Empty);
3091 // Changing padding generally requires a new size
3092 if (this.AutoSize && this.Parent != null)
3093 parent.PerformLayout (this, "Padding");
3095 PerformLayout (this, "Padding");
3100 internal bool ShouldSerializePadding ()
3102 return this.Padding != DefaultPadding;
3107 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
3108 public Control Parent {
3114 if (value == this) {
3115 throw new ArgumentException("A circular control reference has been made. A control cannot be owned or parented to itself.");
3118 if (parent!=value) {
3120 parent.Controls.Remove(this);
3125 value.Controls.Add(this);
3132 public Size PreferredSize {
3133 get { return this.GetPreferredSize (Size.Empty); }
3137 [EditorBrowsable(EditorBrowsableState.Advanced)]
3139 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
3140 public string ProductName {
3142 Type t = typeof (AssemblyProductAttribute);
3143 Assembly assembly = GetType().Module.Assembly;
3144 object [] attrs = assembly.GetCustomAttributes (t, false);
3145 AssemblyProductAttribute a = null;
3146 // On MS we get a NullRefException if product attribute is not
3148 if (attrs != null && attrs.Length > 0)
3149 a = (AssemblyProductAttribute) attrs [0];
3151 return GetType ().Namespace;
3157 [EditorBrowsable(EditorBrowsableState.Advanced)]
3159 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
3160 public string ProductVersion {
3162 Type t = typeof (AssemblyVersionAttribute);
3163 Assembly assembly = GetType().Module.Assembly;
3164 object [] attrs = assembly.GetCustomAttributes (t, false);
3165 if (attrs == null || attrs.Length < 1)
3167 return ((AssemblyVersionAttribute)attrs [0]).Version;
3171 [EditorBrowsable(EditorBrowsableState.Advanced)]
3173 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
3174 public bool RecreatingHandle {
3176 return is_recreating;
3180 [EditorBrowsable(EditorBrowsableState.Advanced)]
3182 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
3183 public Region Region {
3189 if (clip_region != value) {
3190 if (IsHandleCreated)
3191 XplatUI.SetClipRegion(Handle, value);
3193 clip_region = value;
3196 OnRegionChanged (EventArgs.Empty);
3202 [EditorBrowsable(EditorBrowsableState.Advanced)]
3204 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
3207 return this.bounds.X+this.bounds.Width;
3211 [AmbientValue(RightToLeft.Inherit)]
3213 [MWFCategory("Appearance")]
3214 public virtual RightToLeft RightToLeft {
3216 if (right_to_left == RightToLeft.Inherit) {
3218 return parent.RightToLeft;
3220 return RightToLeft.No; // default value
3222 return right_to_left;
3226 if (value != right_to_left) {
3227 right_to_left = value;
3228 OnRightToLeftChanged(EventArgs.Empty);
3234 internal bool ShouldSerializeRightToLeft ()
3236 return this.RightToLeft != RightToLeft.No;
3239 [EditorBrowsable(EditorBrowsableState.Advanced)]
3240 public override ISite Site {
3248 if (value != null) {
3249 AmbientProperties ap = (AmbientProperties) value.GetService (typeof (AmbientProperties));
3251 BackColor = ap.BackColor;
3252 ForeColor = ap.ForeColor;
3260 internal bool ShouldSerializeSite ()
3266 [MWFCategory("Layout")]
3269 return new Size(Width, Height);
3273 SetBounds(bounds.X, bounds.Y, value.Width, value.Height, BoundsSpecified.Size);
3277 internal virtual bool ShouldSerializeSize ()
3279 return this.Size != DefaultSize;
3283 [MergableProperty(false)]
3284 [MWFCategory("Behavior")]
3285 public int TabIndex {
3287 if (tab_index != -1) {
3294 if (tab_index != value) {
3296 OnTabIndexChanged(EventArgs.Empty);
3302 [DefaultValue(true)]
3303 [MWFCategory("Behavior")]
3304 public bool TabStop {
3310 if (tab_stop != value) {
3312 OnTabStopChanged(EventArgs.Empty);
3317 [Localizable(false)]
3319 [TypeConverter(typeof(StringConverter))]
3320 [DefaultValue(null)]
3321 [MWFCategory("Data")]
3328 control_tag = value;
3334 [BindableAttribute(true)]
3335 [MWFCategory("Appearance")]
3336 public virtual string Text {
3338 // Our implementation ignores ControlStyles.CacheText - we always cache
3343 if (value == null) {
3344 value = String.Empty;
3349 UpdateWindowText ();
3350 OnTextChanged (EventArgs.Empty);
3353 // Label has its own AutoSize implementation
3354 if (AutoSize && Parent != null && (!(this is Label)))
3355 Parent.PerformLayout (this, "Text");
3361 internal virtual void UpdateWindowText ()
3363 if (!IsHandleCreated) {
3366 XplatUI.Text (Handle, text);
3369 [EditorBrowsable(EditorBrowsableState.Always)]
3371 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
3374 return this.bounds.Y;
3378 SetBounds(bounds.X, value, bounds.Width, bounds.Height, BoundsSpecified.Y);
3382 [EditorBrowsable(EditorBrowsableState.Advanced)]
3384 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
3385 public Control TopLevelControl {
3389 while (p.parent != null) {
3393 return p is Form ? p : null;
3398 [EditorBrowsable(EditorBrowsableState.Always)]
3400 [DefaultValue (false)]
3401 [MWFCategory("Appearance")]
3402 public bool UseWaitCursor {
3403 get { return use_wait_cursor; }
3405 if (use_wait_cursor != value) {
3406 use_wait_cursor = value;
3408 OnCursorChanged (EventArgs.Empty);
3415 [MWFCategory("Behavior")]
3416 public bool Visible {
3420 } else if (parent != null) {
3421 return parent.Visible;
3428 if (this.is_visible != value) {
3429 SetVisibleCore(value);
3432 parent.PerformLayout (this, "Visible");
3437 internal bool ShouldSerializeVisible ()
3439 return this.Visible != true;
3442 [EditorBrowsable(EditorBrowsableState.Always)]
3444 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
3447 return this.bounds.Width;
3451 SetBounds(bounds.X, bounds.Y, value, bounds.Height, BoundsSpecified.Width);
3455 [EditorBrowsable(EditorBrowsableState.Never)]
3457 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
3458 public IWindowTarget WindowTarget {
3459 get { return window_target; }
3460 set { window_target = value; }
3462 #endregion // Public Instance Properties
3464 #region Protected Instance Properties
3466 protected virtual bool CanEnableIme {
3467 get { return false; }
3470 // Is only false in some ActiveX contexts
3471 protected override bool CanRaiseEvents {
3472 get { return true; }
3476 protected virtual CreateParams CreateParams {
3478 CreateParams create_params = new CreateParams();
3481 create_params.Caption = Text;
3484 create_params.Caption = text;
3488 create_params.X = Left;
3491 create_params.X = this.bounds.X;
3495 create_params.Y = Top;
3498 create_params.Y = this.bounds.Y;
3502 create_params.Width = Width;
3505 create_params.Width = this.bounds.Width;
3509 create_params.Height = Height;
3512 create_params.Height = this.bounds.Height;
3516 create_params.ClassName = XplatUI.DefaultClassName;
3517 create_params.ClassStyle = (int)(XplatUIWin32.ClassStyle.CS_OWNDC | XplatUIWin32.ClassStyle.CS_DBLCLKS);
3518 create_params.ExStyle = 0;
3519 create_params.Param = 0;
3522 create_params.ExStyle |= (int)WindowExStyles.WS_EX_ACCEPTFILES;
3525 if ((parent!=null) && (parent.IsHandleCreated)) {
3526 create_params.Parent = parent.Handle;
3529 create_params.Style = (int)WindowStyles.WS_CHILD | (int)WindowStyles.WS_CLIPCHILDREN | (int)WindowStyles.WS_CLIPSIBLINGS;
3532 create_params.Style |= (int)WindowStyles.WS_VISIBLE;
3536 create_params.Style |= (int)WindowStyles.WS_DISABLED;
3539 switch (border_style) {
3540 case BorderStyle.FixedSingle:
3541 create_params.Style |= (int) WindowStyles.WS_BORDER;
3543 case BorderStyle.Fixed3D:
3544 create_params.ExStyle |= (int) WindowExStyles.WS_EX_CLIENTEDGE;
3548 create_params.control = this;
3550 return create_params;
3555 protected virtual Cursor DefaultCursor { get { return Cursors.Default; } }
3558 protected virtual ImeMode DefaultImeMode {
3560 return ImeMode.Inherit;
3565 protected virtual Padding DefaultMargin {
3566 get { return new Padding (3); }
3569 protected virtual Size DefaultMaximumSize { get { return new Size (); } }
3570 protected virtual Size DefaultMinimumSize { get { return new Size (); } }
3571 protected virtual Padding DefaultPadding { get { return new Padding (); } }
3574 protected virtual Size DefaultSize {
3576 return new Size(0, 0);
3580 protected int FontHeight {
3592 protected bool RenderRightToLeft {
3594 return (this.right_to_left == RightToLeft.Yes);
3598 protected bool ResizeRedraw {
3600 return GetStyle(ControlStyles.ResizeRedraw);
3604 SetStyle(ControlStyles.ResizeRedraw, value);
3609 [EditorBrowsable (EditorBrowsableState.Advanced)]
3610 protected virtual bool ScaleChildren {
3611 get { return ScaleChildrenInternal; }
3615 internal virtual bool ScaleChildrenInternal {
3616 get { return true; }
3619 [EditorBrowsable(EditorBrowsableState.Advanced)]
3621 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
3622 protected internal virtual bool ShowFocusCues {
3625 return show_focus_cues;
3627 if (this.parent == null)
3630 Form f = this.FindForm ();
3633 return f.show_focus_cues;
3639 [EditorBrowsable(EditorBrowsableState.Advanced)]
3641 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
3645 protected bool ShowKeyboardCues {
3647 return ShowKeyboardCuesInternal;
3651 internal bool ShowKeyboardCuesInternal {
3653 if (SystemInformation.MenuAccessKeysUnderlined || DesignMode)
3656 return show_keyboard_cues;
3660 #endregion // Protected Instance Properties
3662 #region Public Static Methods
3663 [EditorBrowsable(EditorBrowsableState.Advanced)]
3664 public static Control FromChildHandle(IntPtr handle) {
3665 return Control.ControlNativeWindow.ControlFromChildHandle (handle);
3668 [EditorBrowsable(EditorBrowsableState.Advanced)]
3669 public static Control FromHandle(IntPtr handle) {
3670 return Control.ControlNativeWindow.ControlFromHandle(handle);
3674 [MonoTODO ("Only implemented for Win32, others always return false")]
3675 public static bool IsKeyLocked (Keys keyVal)
3681 return XplatUI.IsKeyLocked ((VirtualKeys)keyVal);
3683 throw new NotSupportedException ("keyVal must be CapsLock, NumLock, or ScrollLock");
3688 public static bool IsMnemonic(char charCode, string text) {
3691 amp = text.IndexOf('&');
3694 if (amp + 1 < text.Length) {
3695 if (text[amp + 1] != '&') {
3696 if (Char.ToUpper(charCode) == Char.ToUpper(text.ToCharArray(amp + 1, 1)[0])) {
3706 #region Protected Static Methods
3707 [EditorBrowsable(EditorBrowsableState.Advanced)]
3708 protected static bool ReflectMessage(IntPtr hWnd, ref Message m) {
3711 c = Control.FromHandle(hWnd);
3721 #region Public Instance Methods
3722 [EditorBrowsable(EditorBrowsableState.Advanced)]
3723 public IAsyncResult BeginInvoke(Delegate method) {
3724 object [] prms = null;
3725 if (method is EventHandler)
3726 prms = new object [] { this, EventArgs.Empty };
3727 return BeginInvokeInternal(method, prms);
3730 [EditorBrowsable(EditorBrowsableState.Advanced)]
3732 public IAsyncResult BeginInvoke (Delegate method, params object[] args)
3734 public IAsyncResult BeginInvoke (Delegate method, object[] args)
3737 return BeginInvokeInternal (method, args);
3740 public void BringToFront() {
3741 if (parent != null) {
3742 parent.child_controls.SetChildIndex(this, 0);
3744 else if (IsHandleCreated) {
3745 XplatUI.SetZOrder(Handle, IntPtr.Zero, false, false);
3749 public bool Contains(Control ctl) {
3750 while (ctl != null) {
3759 public void CreateControl () {
3772 if (parent != null && !parent.Created) {
3776 if (!IsHandleCreated) {
3783 // Create all of our children (implicit ones as well) when we are created.
3784 // The child should fire it's OnLoad before the parents, however
3785 // if the child checks Parent.Created in it's OnCreateControl, the
3786 // parent is already created.
3787 foreach (Control c in Controls.GetAllControls ())
3788 if (!c.Created && !c.IsDisposed)
3792 if (binding_context == null && parent != null) {
3793 OnBindingContextChanged(EventArgs.Empty);
3801 public Graphics CreateGraphics() {
3802 if (!IsHandleCreated) {
3803 this.CreateHandle();
3805 return Graphics.FromHwnd(this.window.Handle);
3808 public DragDropEffects DoDragDrop(object data, DragDropEffects allowedEffects) {
3809 DragDropEffects result = DragDropEffects.None;
3810 if (IsHandleCreated)
3811 result = XplatUI.StartDrag(Handle, data, allowedEffects);
3812 OnDragDropEnd (result);
3816 internal virtual void OnDragDropEnd (DragDropEffects effects)
3820 [EditorBrowsable(EditorBrowsableState.Advanced)]
3821 public object EndInvoke (IAsyncResult asyncResult) {
3822 AsyncMethodResult result = (AsyncMethodResult) asyncResult;
3823 return result.EndInvoke ();
3826 internal Control FindRootParent ()
3830 while (c.Parent != null)
3836 public Form FindForm() {
3849 [EditorBrowsable (EditorBrowsableState.Advanced)]
3851 public bool Focus() {
3852 return FocusInternal (false);
3855 internal virtual bool FocusInternal (bool skip_check) {
3856 if (skip_check || (CanFocus && IsHandleCreated && !has_focus && !is_focusing)) {
3859 is_focusing = false;
3864 internal Control GetRealChildAtPoint (Point pt) {
3865 if (!IsHandleCreated)
3868 foreach (Control control in child_controls.GetAllControls ()) {
3869 if (control.Bounds.Contains (PointToClient (pt))) {
3870 Control child = control.GetRealChildAtPoint (pt);
3881 public Control GetChildAtPoint(Point pt)
3883 return GetChildAtPoint (pt, GetChildAtPointSkip.None);
3889 Control GetChildAtPoint (Point pt, GetChildAtPointSkip skipValue)
3891 // MS's version causes the handle to be created. The stack trace shows that get_Handle is called here, but
3892 // we'll just call CreateHandle instead.
3893 if (!IsHandleCreated)
3896 // Microsoft's version of this function doesn't seem to work, so I can't check
3897 // if we only consider children or also grandchildren, etc.
3898 // I'm gonna say 'children only'
3899 foreach (Control child in Controls) {
3900 if ((skipValue & GetChildAtPointSkip.Disabled) == GetChildAtPointSkip.Disabled && !child.Enabled)
3902 else if ((skipValue & GetChildAtPointSkip.Invisible) == GetChildAtPointSkip.Invisible && !child.Visible)
3904 else if ((skipValue & GetChildAtPointSkip.Transparent) == GetChildAtPointSkip.Transparent && child.BackColor.A == 0x0)
3906 else if (child.Bounds.Contains (pt))
3913 public IContainerControl GetContainerControl() {
3914 Control current = this;
3916 while (current!=null) {
3917 if ((current is IContainerControl) && ((current.control_style & ControlStyles.ContainerControl)!=0)) {
3918 return (IContainerControl)current;
3920 current = current.parent;
3925 internal ContainerControl InternalGetContainerControl() {
3926 Control current = this;
3928 while (current!=null) {
3929 if ((current is ContainerControl) && ((current.control_style & ControlStyles.ContainerControl)!=0)) {
3930 return current as ContainerControl;
3932 current = current.parent;
3937 public Control GetNextControl(Control ctl, bool forward) {
3939 if (!this.Contains(ctl)) {
3944 ctl = FindControlForward(this, ctl);
3947 ctl = FindControlBackward(this, ctl);
3957 [EditorBrowsable (EditorBrowsableState.Advanced)]
3958 public virtual Size GetPreferredSize (Size proposedSize) {
3959 Size retsize = GetPreferredSizeCore (proposedSize);
3961 // If we're bigger than the MaximumSize, fix that
3962 if (this.maximum_size.Width != 0 && retsize.Width > this.maximum_size.Width)
3963 retsize.Width = this.maximum_size.Width;
3964 if (this.maximum_size.Height != 0 && retsize.Height > this.maximum_size.Height)
3965 retsize.Height = this.maximum_size.Height;
3967 // If we're smaller than the MinimumSize, fix that
3968 if (this.minimum_size.Width != 0 && retsize.Width < this.minimum_size.Width)
3969 retsize.Width = this.minimum_size.Width;
3970 if (this.minimum_size.Height != 0 && retsize.Height < this.minimum_size.Height)
3971 retsize.Height = this.minimum_size.Height;
3977 public void Hide() {
3978 this.Visible = false;
3981 public void Invalidate() {
3982 Invalidate(ClientRectangle, false);
3985 public void Invalidate(bool invalidateChildren) {
3986 Invalidate(ClientRectangle, invalidateChildren);
3989 public void Invalidate(System.Drawing.Rectangle rc) {
3990 Invalidate(rc, false);
3993 public void Invalidate(System.Drawing.Rectangle rc, bool invalidateChildren) {
3994 // Win32 invalidates control including when Width and Height is equal 0
3995 // or is not visible, only Paint event must be care about this.
3996 if (!IsHandleCreated)
3999 if (rc == Rectangle.Empty)
4000 rc = ClientRectangle;
4002 if (rc.Width > 0 && rc.Height > 0) {
4004 NotifyInvalidate(rc);
4006 XplatUI.Invalidate(Handle, rc, false);
4008 if (invalidateChildren) {
4009 Control [] controls = child_controls.GetAllControls ();
4010 for (int i=0; i<controls.Length; i++)
4011 controls [i].Invalidate ();
4013 // If any of our children are transparent, we
4014 // have to invalidate them anyways
4015 foreach (Control c in Controls)
4016 if (c.BackColor.A != 255)
4020 OnInvalidated(new InvalidateEventArgs(rc));
4023 public void Invalidate(System.Drawing.Region region) {
4024 Invalidate(region, false);
4027 public void Invalidate(System.Drawing.Region region, bool invalidateChildren) {
4028 RectangleF bounds = region.GetBounds (CreateGraphics ());
4029 Invalidate (new Rectangle ((int) bounds.X, (int) bounds.Y, (int) bounds.Width, (int) bounds.Height),
4030 invalidateChildren);
4033 public object Invoke (Delegate method) {
4034 object [] prms = null;
4035 if (method is EventHandler)
4036 prms = new object [] { this, EventArgs.Empty };
4038 return Invoke(method, prms);
4041 public object Invoke (Delegate method, params object [] args) {
4043 public object Invoke (Delegate method, object[] args) {
4045 Control control = FindControlToInvokeOn ();
4047 if (!this.InvokeRequired) {
4048 return method.DynamicInvoke(args);
4051 IAsyncResult result = BeginInvokeInternal (method, args, control);
4052 return EndInvoke(result);
4055 [EditorBrowsable(EditorBrowsableState.Advanced)]
4056 public void PerformLayout() {
4057 PerformLayout(null, null);
4060 [EditorBrowsable(EditorBrowsableState.Advanced)]
4061 public void PerformLayout(Control affectedControl, string affectedProperty) {
4062 LayoutEventArgs levent = new LayoutEventArgs(affectedControl, affectedProperty);
4064 foreach (Control c in Controls.GetAllControls ())
4065 if (c.recalculate_distances)
4066 c.UpdateDistances ();
4068 if (layout_suspended > 0) {
4069 layout_pending = true;
4073 layout_pending = false;
4075 // Prevent us from getting messed up
4078 // Perform all Dock and Anchor calculations
4083 // Need to make sure we decremend layout_suspended
4089 public Point PointToClient (Point p) {
4093 XplatUI.ScreenToClient (Handle, ref x, ref y);
4095 return new Point (x, y);
4098 public Point PointToScreen(Point p) {
4102 XplatUI.ClientToScreen(Handle, ref x, ref y);
4104 return new Point(x, y);
4108 [EditorBrowsable(EditorBrowsableState.Advanced)]
4109 public PreProcessControlState PreProcessControlMessage (ref Message msg)
4111 return PreProcessControlMessageInternal (ref msg);
4115 internal PreProcessControlState PreProcessControlMessageInternal (ref Message msg)
4117 switch ((Msg)msg.Msg) {
4118 case Msg.WM_KEYDOWN:
4119 case Msg.WM_SYSKEYDOWN:
4121 PreviewKeyDownEventArgs e = new PreviewKeyDownEventArgs ((Keys)msg.WParam.ToInt32 () | XplatUI.State.ModifierKeys);
4122 OnPreviewKeyDown (e);
4125 return PreProcessControlState.MessageNeeded;
4128 if (PreProcessMessage (ref msg))
4129 return PreProcessControlState.MessageProcessed;
4131 if (IsInputKey ((Keys)msg.WParam.ToInt32 () | XplatUI.State.ModifierKeys))
4132 return PreProcessControlState.MessageNeeded;
4136 case Msg.WM_SYSCHAR:
4137 if (PreProcessMessage (ref msg))
4138 return PreProcessControlState.MessageProcessed;
4140 if (IsInputChar ((char)msg.WParam))
4141 return PreProcessControlState.MessageNeeded;
4148 return PreProcessControlState.MessageNotNeeded;
4151 public virtual bool PreProcessMessage (ref Message msg)
4153 return InternalPreProcessMessage (ref msg);
4156 internal virtual bool InternalPreProcessMessage (ref Message msg) {
4159 if ((msg.Msg == (int)Msg.WM_KEYDOWN) || (msg.Msg == (int)Msg.WM_SYSKEYDOWN)) {
4160 key_data = (Keys)msg.WParam.ToInt32() | XplatUI.State.ModifierKeys;
4162 if (!ProcessCmdKey(ref msg, key_data)) {
4163 if (IsInputKey(key_data)) {
4167 return ProcessDialogKey(key_data);
4171 } else if (msg.Msg == (int)Msg.WM_CHAR) {
4172 if (IsInputChar((char)msg.WParam)) {
4175 return ProcessDialogChar((char)msg.WParam);
4176 } else if (msg.Msg == (int)Msg.WM_SYSCHAR) {
4177 if (ProcessDialogChar((char)msg.WParam))
4181 return ToolStripManager.ProcessMenuKey (ref msg);
4189 public Rectangle RectangleToClient(Rectangle r) {
4190 return new Rectangle(PointToClient(r.Location), r.Size);
4193 public Rectangle RectangleToScreen(Rectangle r) {
4194 return new Rectangle(PointToScreen(r.Location), r.Size);
4197 public virtual void Refresh() {
4198 if (IsHandleCreated && Visible) {
4204 [EditorBrowsable(EditorBrowsableState.Never)]
4205 public virtual void ResetBackColor() {
4206 BackColor = Color.Empty;
4209 [EditorBrowsable(EditorBrowsableState.Never)]
4210 public void ResetBindings() {
4211 if (data_bindings != null)
4212 data_bindings.Clear();
4215 [EditorBrowsable(EditorBrowsableState.Never)]
4216 public virtual void ResetCursor() {
4220 [EditorBrowsable(EditorBrowsableState.Never)]
4221 public virtual void ResetFont() {
4225 [EditorBrowsable(EditorBrowsableState.Never)]
4226 public virtual void ResetForeColor() {
4227 foreground_color = Color.Empty;
4230 [EditorBrowsable(EditorBrowsableState.Never)]
4231 public void ResetImeMode() {
4232 ime_mode = DefaultImeMode;
4235 [EditorBrowsable(EditorBrowsableState.Never)]
4236 public virtual void ResetRightToLeft() {
4237 right_to_left = RightToLeft.Inherit;
4240 public virtual void ResetText() {
4241 Text = String.Empty;
4244 public void ResumeLayout() {
4245 ResumeLayout (true);
4248 public void ResumeLayout(bool performLayout) {
4249 if (layout_suspended > 0) {
4253 if (layout_suspended == 0) {
4255 if (this is ContainerControl)
4256 (this as ContainerControl).PerformDelayedAutoScale();
4260 foreach (Control c in Controls.GetAllControls ())
4261 c.UpdateDistances ();
4263 if (performLayout && layout_pending) {
4269 [EditorBrowsable (EditorBrowsableState.Never)]
4272 public void Scale(float ratio) {
4273 ScaleCore(ratio, ratio);
4277 [EditorBrowsable (EditorBrowsableState.Never)]
4280 public void Scale(float dx, float dy) {
4285 [EditorBrowsable (EditorBrowsableState.Advanced)]
4286 public void Scale (SizeF factor)
4288 BoundsSpecified bounds_spec = BoundsSpecified.All;
4292 if (this is ContainerControl) {
4293 if ((this as ContainerControl).IsAutoScaling)
4294 bounds_spec = BoundsSpecified.Size;
4295 else if (IsContainerAutoScaling (this.Parent))
4296 bounds_spec = BoundsSpecified.Location;
4299 ScaleControl (factor, bounds_spec);
4302 if ((bounds_spec != BoundsSpecified.Location) && ScaleChildren) {
4303 foreach (Control c in Controls.GetAllControls ()) {
4305 if (c is ContainerControl) {
4306 ContainerControl cc = c as ContainerControl;
4307 if ((cc.AutoScaleMode == AutoScaleMode.Inherit) && IsContainerAutoScaling (this))
4308 cc.PerformAutoScale (true);
4316 internal ContainerControl FindContainer (Control c)
4318 while ((c != null) && !(c is ContainerControl))
4320 return c as ContainerControl;
4323 private bool IsContainerAutoScaling (Control c)
4325 ContainerControl cc = FindContainer (c);
4326 return (cc != null) && cc.IsAutoScaling;
4330 public void Select() {
4331 Select(false, false);
4335 private void printTree(Control c, string t) {
4336 foreach(Control i in c.child_controls) {
4337 Console.WriteLine ("{2}{0}.TabIndex={1}", i, i.tab_index, t);
4338 printTree (i, t+"\t");
4342 public bool SelectNextControl(Control ctl, bool forward, bool tabStopOnly, bool nested, bool wrap) {
4346 Console.WriteLine("{0}", this.FindForm());
4347 printTree(this, "\t");
4350 if (!this.Contains(ctl) || (!nested && (ctl.parent != this))) {
4355 c = GetNextControl(c, forward);
4365 Console.WriteLine("{0} {1}", c, c.CanSelect);
4367 if (c.CanSelect && ((c.parent == this) || nested) && (c.tab_stop || !tabStopOnly)) {
4368 c.Select (true, true);
4371 } while (c != ctl); // If we wrap back to ourselves we stop
4376 public void SendToBack() {
4377 if (parent != null) {
4378 parent.child_controls.SetChildIndex(this, parent.child_controls.Count);
4382 public void SetBounds(int x, int y, int width, int height) {
4383 SetBounds(x, y, width, height, BoundsSpecified.All);
4386 public void SetBounds(int x, int y, int width, int height, BoundsSpecified specified) {
4387 // Fill in the values that were not specified
4388 if ((specified & BoundsSpecified.X) == 0)
4390 if ((specified & BoundsSpecified.Y) == 0)
4392 if ((specified & BoundsSpecified.Width) == 0)
4394 if ((specified & BoundsSpecified.Height) == 0)
4397 SetBoundsInternal (x, y, width, height, specified);
4400 internal void SetBoundsInternal (int x, int y, int width, int height, BoundsSpecified specified)
4402 // SetBoundsCore is really expensive to call, so we want to avoid it if we can.
4403 // We can avoid it if:
4404 // - The requested dimensions are the same as our current dimensions
4406 // - Any BoundsSpecified is the same as our current explicit_size
4407 if (bounds.X != x || (explicit_bounds.X != x && (specified & BoundsSpecified.X) == BoundsSpecified.X))
4408 SetBoundsCore (x, y, width, height, specified);
4409 else if (bounds.Y != y || (explicit_bounds.Y != y && (specified & BoundsSpecified.Y) == BoundsSpecified.Y))
4410 SetBoundsCore (x, y, width, height, specified);
4411 else if (bounds.Width != width || (explicit_bounds.Width != width && (specified & BoundsSpecified.Width) == BoundsSpecified.Width))
4412 SetBoundsCore (x, y, width, height, specified);
4413 else if (bounds.Height != height || (explicit_bounds.Height != height && (specified & BoundsSpecified.Height) == BoundsSpecified.Height))
4414 SetBoundsCore (x, y, width, height, specified);
4418 // If the user explicitly moved or resized us, recalculate our anchor distances
4419 if (specified != BoundsSpecified.None)
4423 parent.PerformLayout(this, "Bounds");
4426 public void Show () {
4427 this.Visible = true;
4430 public void SuspendLayout() {
4434 public void Update() {
4435 if (IsHandleCreated) {
4436 XplatUI.UpdateWindow(window.Handle);
4439 #endregion // Public Instance Methods
4441 #region Protected Instance Methods
4442 [EditorBrowsable(EditorBrowsableState.Advanced)]
4443 protected void AccessibilityNotifyClients(AccessibleEvents accEvent, int childID) {
4444 // turns out this method causes handle
4445 // creation in 1.1. at first I thought this
4446 // would be accomplished just by using
4447 // get_AccessibilityObject, which would route
4448 // through CreateAccessibilityInstance, which
4449 // calls CreateControl. This isn't the case,
4450 // though (as overriding
4451 // CreateAccessibilityInstance and adding a
4452 // CWL shows nothing. So we fudge it and put
4453 // a CreateHandle here.
4459 if (accessibility_object != null && accessibility_object is ControlAccessibleObject)
4460 ((ControlAccessibleObject)accessibility_object).NotifyClients (accEvent, childID);
4464 [EditorBrowsable (EditorBrowsableState.Advanced)]
4465 protected void AccessibilityNotifyClients (AccessibleEvents accEvent, int objectID, int childID)
4467 if (accessibility_object != null && accessibility_object is ControlAccessibleObject)
4468 ((ControlAccessibleObject)accessibility_object).NotifyClients (accEvent, objectID, childID);
4472 [EditorBrowsable(EditorBrowsableState.Advanced)]
4473 protected virtual AccessibleObject CreateAccessibilityInstance() {
4475 return new Control.ControlAccessibleObject(this);
4478 [EditorBrowsable(EditorBrowsableState.Advanced)]
4479 protected virtual ControlCollection CreateControlsInstance() {
4480 return new ControlCollection(this);
4483 [EditorBrowsable(EditorBrowsableState.Advanced)]
4484 protected virtual void CreateHandle() {
4486 throw new ObjectDisposedException(GetType().FullName);
4489 if (IsHandleCreated && !is_recreating) {
4493 CreateParams create_params = CreateParams;
4494 window.CreateHandle(create_params);
4496 if (window.Handle != IntPtr.Zero) {
4497 creator_thread = Thread.CurrentThread;
4499 XplatUI.EnableWindow(window.Handle, is_enabled);
4501 if (clip_region != null) {
4502 XplatUI.SetClipRegion(window.Handle, clip_region);
4505 // Set our handle with our parent
4506 if ((parent != null) && (parent.IsHandleCreated)) {
4507 XplatUI.SetParent(window.Handle, parent.Handle);
4511 XplatUI.SetAllowDrop (window.Handle, allow_drop);
4513 // Find out where the window manager placed us
4514 if ((CreateParams.Style & (int)WindowStyles.WS_CHILD) != 0) {
4515 XplatUI.SetBorderStyle(window.Handle, (FormBorderStyle)border_style);
4518 Rectangle save_bounds = explicit_bounds;
4520 explicit_bounds = save_bounds;
4524 [EditorBrowsable(EditorBrowsableState.Advanced)]
4525 protected virtual void DefWndProc(ref Message m) {
4526 window.DefWndProc(ref m);
4529 [EditorBrowsable(EditorBrowsableState.Advanced)]
4530 protected virtual void DestroyHandle() {
4531 if (IsHandleCreated) {
4532 if (window != null) {
4533 window.DestroyHandle();
4539 protected virtual AccessibleObject GetAccessibilityObjectById (int objectId)
4541 // XXX need to implement this.
4545 protected internal AutoSizeMode GetAutoSizeMode ()
4547 return auto_size_mode;
4550 [EditorBrowsable (EditorBrowsableState.Advanced)]
4551 protected virtual Rectangle GetScaledBounds (Rectangle bounds, SizeF factor, BoundsSpecified specified)
4553 // Top level controls do not scale location
4555 if ((specified & BoundsSpecified.X) == BoundsSpecified.X)
4556 bounds.X = (int)Math.Round (bounds.X * factor.Width);
4557 if ((specified & BoundsSpecified.Y) == BoundsSpecified.Y)
4558 bounds.Y = (int)Math.Round (bounds.Y * factor.Height);
4561 if ((specified & BoundsSpecified.Width) == BoundsSpecified.Width && !GetStyle (ControlStyles.FixedWidth)) {
4562 int border = (this is ComboBox) ? (ThemeEngine.Current.Border3DSize.Width * 2) :
4563 (this.bounds.Width - this.client_size.Width);
4564 bounds.Width = (int)Math.Round ((bounds.Width - border) * factor.Width + border);
4566 if ((specified & BoundsSpecified.Height) == BoundsSpecified.Height && !GetStyle (ControlStyles.FixedHeight)) {
4567 int border = (this is ComboBox) ? (ThemeEngine.Current.Border3DSize.Height * 2) :
4568 (this.bounds.Height - this.client_size.Height);
4569 bounds.Height = (int)Math.Round ((bounds.Height - border) * factor.Height + border);
4576 private Rectangle GetScaledBoundsOld (Rectangle bounds, SizeF factor, BoundsSpecified specified)
4578 RectangleF new_bounds = new RectangleF(bounds.Location, bounds.Size);
4580 // Top level controls do not scale location
4582 if ((specified & BoundsSpecified.X) == BoundsSpecified.X)
4583 new_bounds.X *= factor.Width;
4584 if ((specified & BoundsSpecified.Y) == BoundsSpecified.Y)
4585 new_bounds.Y *= factor.Height;
4588 if ((specified & BoundsSpecified.Width) == BoundsSpecified.Width && !GetStyle (ControlStyles.FixedWidth)) {
4589 int border = (this is Form) ? (this.bounds.Width - this.client_size.Width) : 0;
4590 new_bounds.Width = ((new_bounds.Width - border) * factor.Width + border);
4592 if ((specified & BoundsSpecified.Height) == BoundsSpecified.Height && !GetStyle (ControlStyles.FixedHeight)) {
4593 int border = (this is Form) ? (this.bounds.Height - this.client_size.Height) : 0;
4594 new_bounds.Height = ((new_bounds.Height - border) * factor.Height + border);
4597 bounds.X = (int)Math.Round (new_bounds.X);
4598 bounds.Y = (int)Math.Round (new_bounds.Y);
4599 bounds.Width = (int)Math.Round (new_bounds.Right) - bounds.X;
4600 bounds.Height = (int)Math.Round (new_bounds.Bottom) - bounds.Y;
4605 protected internal bool GetStyle(ControlStyles flag) {
4606 return (control_style & flag) != 0;
4609 protected bool GetTopLevel() {
4613 [EditorBrowsable(EditorBrowsableState.Advanced)]
4614 protected virtual void InitLayout() {
4617 [EditorBrowsable(EditorBrowsableState.Advanced)]
4618 protected void InvokeGotFocus(Control toInvoke, EventArgs e) {
4619 toInvoke.OnGotFocus(e);
4622 [EditorBrowsable(EditorBrowsableState.Advanced)]
4623 protected void InvokeLostFocus(Control toInvoke, EventArgs e) {
4624 toInvoke.OnLostFocus(e);
4627 [EditorBrowsable(EditorBrowsableState.Advanced)]
4628 protected void InvokeOnClick(Control toInvoke, EventArgs e) {
4629 toInvoke.OnClick(e);
4632 protected void InvokePaint(Control c, PaintEventArgs e) {
4636 protected void InvokePaintBackground(Control c, PaintEventArgs e) {
4637 c.OnPaintBackground (e);
4640 protected virtual bool IsInputChar (char charCode) {
4641 // XXX on MS.NET this method causes the handle to be created..
4642 if (!IsHandleCreated)
4645 return IsInputCharInternal (charCode);
4648 internal virtual bool IsInputCharInternal (char charCode) {
4652 protected virtual bool IsInputKey (Keys keyData) {
4653 // Doc says this one calls IsInputChar; not sure what to do with that
4657 [EditorBrowsable(EditorBrowsableState.Advanced)]
4658 protected virtual void NotifyInvalidate(Rectangle invalidatedArea) {
4662 protected virtual bool ProcessCmdKey(ref Message msg, Keys keyData) {
4663 if ((context_menu != null) && context_menu.ProcessCmdKey(ref msg, keyData)) {
4667 if (parent != null) {
4668 return parent.ProcessCmdKey(ref msg, keyData);
4674 protected virtual bool ProcessDialogChar(char charCode) {
4675 if (parent != null) {
4676 return parent.ProcessDialogChar (charCode);
4682 protected virtual bool ProcessDialogKey (Keys keyData) {
4683 if (parent != null) {
4684 return parent.ProcessDialogKey (keyData);
4690 protected virtual bool ProcessKeyEventArgs (ref Message m)
4692 KeyEventArgs key_event;
4695 case (int)Msg.WM_SYSKEYDOWN:
4696 case (int)Msg.WM_KEYDOWN: {
4697 key_event = new KeyEventArgs ((Keys) m.WParam.ToInt32 ());
4698 OnKeyDown (key_event);
4700 suppressing_key_press = key_event.SuppressKeyPress;
4702 return key_event.Handled;
4705 case (int)Msg.WM_SYSKEYUP:
4706 case (int)Msg.WM_KEYUP: {
4707 key_event = new KeyEventArgs ((Keys) m.WParam.ToInt32 ());
4708 OnKeyUp (key_event);
4709 return key_event.Handled;
4712 case (int)Msg.WM_SYSCHAR:
4713 case (int)Msg.WM_CHAR: {
4715 if (suppressing_key_press)
4718 KeyPressEventArgs key_press_event;
4720 key_press_event = new KeyPressEventArgs ((char) m.WParam);
4721 OnKeyPress(key_press_event);
4723 m.WParam = (IntPtr) key_press_event.KeyChar;
4725 return key_press_event.Handled;
4736 protected internal virtual bool ProcessKeyMessage (ref Message m)
4738 if (parent != null) {
4739 if (parent.ProcessKeyPreview (ref m))
4743 return ProcessKeyEventArgs (ref m);
4746 protected virtual bool ProcessKeyPreview (ref Message m) {
4748 return parent.ProcessKeyPreview(ref m);
4753 protected virtual bool ProcessMnemonic(char charCode) {
4758 [EditorBrowsable(EditorBrowsableState.Advanced)]
4759 protected void RaiseDragEvent(object key, DragEventArgs e) {
4763 [EditorBrowsable(EditorBrowsableState.Advanced)]
4764 protected void RaiseKeyEvent(object key, KeyEventArgs e) {
4768 [EditorBrowsable(EditorBrowsableState.Advanced)]
4769 protected void RaiseMouseEvent(object key, MouseEventArgs e) {
4773 [EditorBrowsable(EditorBrowsableState.Advanced)]
4774 protected void RaisePaintEvent(object key, PaintEventArgs e) {
4778 private void SetIsRecreating () {
4781 foreach (Control c in Controls.GetAllControls()) {
4782 c.SetIsRecreating ();
4786 [EditorBrowsable(EditorBrowsableState.Advanced)]
4787 protected void RecreateHandle() {
4788 if (!IsHandleCreated)
4792 Console.WriteLine("Recreating control {0}", XplatUI.Window(window.Handle));
4797 if (IsHandleCreated) {
4799 Console.WriteLine(" + handle is created, destroying it.");
4802 // WM_DESTROY will CreateHandle for us
4805 Console.WriteLine(" + handle is not created, creating it.");
4813 is_recreating = false;
4815 Console.WriteLine (" + new handle = {0:X}", Handle.ToInt32());
4821 [EditorBrowsable(EditorBrowsableState.Advanced)]
4822 protected void ResetMouseEventArgs() {
4826 [EditorBrowsable(EditorBrowsableState.Advanced)]
4827 protected ContentAlignment RtlTranslateAlignment(ContentAlignment align) {
4828 if (right_to_left == RightToLeft.No) {
4833 case ContentAlignment.TopLeft: {
4834 return ContentAlignment.TopRight;
4837 case ContentAlignment.TopRight: {
4838 return ContentAlignment.TopLeft;
4841 case ContentAlignment.MiddleLeft: {
4842 return ContentAlignment.MiddleRight;
4845 case ContentAlignment.MiddleRight: {
4846 return ContentAlignment.MiddleLeft;
4849 case ContentAlignment.BottomLeft: {
4850 return ContentAlignment.BottomRight;
4853 case ContentAlignment.BottomRight: {
4854 return ContentAlignment.BottomLeft;
4858 // if it's center it doesn't change
4864 [EditorBrowsable(EditorBrowsableState.Advanced)]
4865 protected HorizontalAlignment RtlTranslateAlignment(HorizontalAlignment align) {
4866 if ((right_to_left == RightToLeft.No) || (align == HorizontalAlignment.Center)) {
4870 if (align == HorizontalAlignment.Left) {
4871 return HorizontalAlignment.Right;
4874 // align must be HorizontalAlignment.Right
4875 return HorizontalAlignment.Left;
4878 [EditorBrowsable(EditorBrowsableState.Advanced)]
4879 protected LeftRightAlignment RtlTranslateAlignment(LeftRightAlignment align) {
4880 if (right_to_left == RightToLeft.No) {
4884 if (align == LeftRightAlignment.Left) {
4885 return LeftRightAlignment.Right;
4888 // align must be LeftRightAlignment.Right;
4889 return LeftRightAlignment.Left;
4892 [EditorBrowsable(EditorBrowsableState.Advanced)]
4893 protected ContentAlignment RtlTranslateContent(ContentAlignment align) {
4894 return RtlTranslateAlignment(align);
4897 [EditorBrowsable(EditorBrowsableState.Advanced)]
4898 protected HorizontalAlignment RtlTranslateHorizontal(HorizontalAlignment align) {
4899 return RtlTranslateAlignment(align);
4902 [EditorBrowsable(EditorBrowsableState.Advanced)]
4903 protected LeftRightAlignment RtlTranslateLeftRight(LeftRightAlignment align) {
4904 return RtlTranslateAlignment(align);
4908 [EditorBrowsable (EditorBrowsableState.Advanced)]
4909 protected virtual void ScaleControl (SizeF factor, BoundsSpecified specified)
4911 Rectangle new_bounds = GetScaledBounds (bounds, factor, specified);
4913 SetBounds (new_bounds.X, new_bounds.Y, new_bounds.Width, new_bounds.Height, specified);
4918 [EditorBrowsable (EditorBrowsableState.Never)]
4920 [EditorBrowsable (EditorBrowsableState.Advanced)]
4922 protected virtual void ScaleCore (float dx, float dy)
4924 Rectangle new_bounds = GetScaledBoundsOld (bounds, new SizeF (dx, dy), BoundsSpecified.All);
4928 SetBounds (new_bounds.X, new_bounds.Y, new_bounds.Width, new_bounds.Height, BoundsSpecified.All);
4930 if (ScaleChildrenInternal)
4931 foreach (Control c in Controls.GetAllControls ())
4937 protected virtual void Select(bool directed, bool forward) {
4938 IContainerControl container;
4940 container = GetContainerControl();
4941 if (container != null && (Control)container != this)
4942 container.ActiveControl = this;
4946 protected void SetAutoSizeMode (AutoSizeMode mode)
4948 if (auto_size_mode != mode) {
4949 auto_size_mode = mode;
4950 PerformLayout (this, "AutoSizeMode");
4955 [EditorBrowsable(EditorBrowsableState.Advanced)]
4956 protected virtual void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
4957 SetBoundsCoreInternal (x, y, width, height, specified);
4960 internal virtual void SetBoundsCoreInternal(int x, int y, int width, int height, BoundsSpecified specified) {
4961 // Nasty hack for 2.0 DateTimePicker
4962 height = OverrideHeight (height);
4964 Rectangle old_explicit = explicit_bounds;
4965 Rectangle new_bounds = new Rectangle (x, y, width, height);
4967 // SetBoundsCore updates the Win32 control itself. UpdateBounds updates the controls variables and fires events, I'm guessing - pdb
4968 if (IsHandleCreated) {
4969 XplatUI.SetWindowPos(Handle, x, y, width, height);
4971 // Win32 automatically changes negative width/height to 0.
4972 // The control has already been sent a WM_WINDOWPOSCHANGED message and it has the correct
4973 // data, but it'll be overwritten when we call UpdateBounds unless we get the updated
4976 XplatUI.GetWindowPos(Handle, this is Form, out ix, out iy, out width, out height, out cw, out ch);
4979 // BoundsSpecified tells us which variables were programatic (user-set).
4980 // We need to store those in the explicit bounds
4981 if ((specified & BoundsSpecified.X) == BoundsSpecified.X)
4982 explicit_bounds.X = new_bounds.X;
4984 explicit_bounds.X = old_explicit.X;
4986 if ((specified & BoundsSpecified.Y) == BoundsSpecified.Y)
4987 explicit_bounds.Y = new_bounds.Y;
4989 explicit_bounds.Y = old_explicit.Y;
4991 if ((specified & BoundsSpecified.Width) == BoundsSpecified.Width)
4992 explicit_bounds.Width = new_bounds.Width;
4994 explicit_bounds.Width = old_explicit.Width;
4996 if ((specified & BoundsSpecified.Height) == BoundsSpecified.Height)
4997 explicit_bounds.Height = new_bounds.Height;
4999 explicit_bounds.Height = old_explicit.Height;
5001 // We need to store the explicit bounds because UpdateBounds is always going
5002 // to change it, and we have to fix it. However, UpdateBounds also calls
5003 // OnLocationChanged, OnSizeChanged, and OnClientSizeChanged. The user can
5004 // override those or use those events to change the size explicitly, and we
5005 // can't undo those changes. So if the bounds after calling UpdateBounds are
5006 // the same as the ones we sent it, we need to fix the explicit bounds. If
5007 // it's not the same as we sent UpdateBounds, then someone else changed it, and
5008 // we better not mess it up. Fun stuff.
5009 Rectangle stored_explicit_bounds = explicit_bounds;
5011 UpdateBounds(x, y, width, height);
5013 if (explicit_bounds.X == x)
5014 explicit_bounds.X = stored_explicit_bounds.X;
5016 if (explicit_bounds.Y == y)
5017 explicit_bounds.Y = stored_explicit_bounds.Y;
5019 if (explicit_bounds.Width == width)
5020 explicit_bounds.Width = stored_explicit_bounds.Width;
5022 if (explicit_bounds.Height == height)
5023 explicit_bounds.Height = stored_explicit_bounds.Height;
5026 [EditorBrowsable(EditorBrowsableState.Advanced)]
5027 protected virtual void SetClientSizeCore(int x, int y) {
5028 Size NewSize = InternalSizeFromClientSize (new Size (x, y));
5030 if (NewSize != Size.Empty)
5031 SetBounds (bounds.X, bounds.Y, NewSize.Width, NewSize.Height, BoundsSpecified.Size);
5034 [EditorBrowsable(EditorBrowsableState.Advanced)]
5035 protected internal void SetStyle(ControlStyles flag, bool value) {
5037 control_style |= flag;
5039 control_style &= ~flag;
5043 protected void SetTopLevel(bool value) {
5044 if ((GetTopLevel() != value) && (parent != null)) {
5045 throw new ArgumentException ("Cannot change toplevel style of a parented control.");
5049 if (IsHandleCreated && value != Visible) {
5053 // XXX MS.NET causes handle to be created here
5054 if (!IsHandleCreated)
5057 is_toplevel = value;
5060 protected virtual void SetVisibleCore(bool value) {
5061 if (value != is_visible) {
5064 if (is_visible && ((window.Handle == IntPtr.Zero) || !is_created)) {
5066 if (!(this is Form))
5070 if (IsHandleCreated) {
5071 XplatUI.SetVisible (Handle, is_visible, true);
5073 if (parent != null && parent.IsHandleCreated) {
5074 parent.Invalidate (bounds);
5079 } else if (is_visible && this is Form) {
5080 // If we are Min or Max, we won't get a WM_SHOWWINDOW from SetWindowState,
5081 // so we need to manually create our children, and set them visible
5082 // (This normally happens in WmShowWindow.)
5083 if ((this as Form).WindowState != FormWindowState.Normal)
5084 OnVisibleChanged (EventArgs.Empty);
5086 // Explicitly move Toplevel windows to where we want them;
5087 // apparently moving unmapped toplevel windows doesn't work
5088 XplatUI.SetWindowPos(window.Handle, bounds.X, bounds.Y, bounds.Width, bounds.Height);
5090 // If we are becoming visible, z-order may have changed while
5091 // we were invisible, so update our z-order position
5093 parent.UpdateZOrderOfChild (this);
5096 if (!(this is Form))
5097 OnVisibleChanged (EventArgs.Empty);
5100 OnVisibleChanged(EventArgs.Empty);
5105 [EditorBrowsable (EditorBrowsableState.Advanced)]
5111 virtual Size SizeFromClientSize (Size clientSize) {
5112 return InternalSizeFromClientSize (clientSize);
5115 [EditorBrowsable(EditorBrowsableState.Advanced)]
5116 protected void UpdateBounds() {
5117 if (!IsHandleCreated)
5127 XplatUI.GetWindowPos(this.Handle, this is Form, out x, out y, out width, out height, out client_width, out client_height);
5129 UpdateBounds(x, y, width, height, client_width, client_height);
5132 [EditorBrowsable(EditorBrowsableState.Advanced)]
5133 protected void UpdateBounds(int x, int y, int width, int height) {
5137 // Calculate client rectangle
5138 rect = new Rectangle(0, 0, 0, 0);
5141 XplatUI.CalculateWindowRect(ref rect, cp, cp.menu, out rect);
5142 UpdateBounds(x, y, width, height, width - (rect.Right - rect.Left), height - (rect.Bottom - rect.Top));
5145 [EditorBrowsable(EditorBrowsableState.Advanced)]
5146 protected void UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) {
5147 // UpdateBounds only seems to set our sizes and fire events but not update the GUI window to match
5149 bool resized = false;
5151 // Needed to generate required notifications
5152 if ((this.bounds.X!=x) || (this.bounds.Y!=y)) {
5156 if ((this.Bounds.Width!=width) || (this.Bounds.Height!=height)) {
5163 bounds.Height=height;
5165 // Assume explicit bounds set. SetBoundsCore will restore old bounds
5167 explicit_bounds = bounds;
5169 client_size.Width=clientWidth;
5170 client_size.Height=clientHeight;
5173 OnLocationChanged(EventArgs.Empty);
5175 if (!background_color.IsEmpty && background_color.A < byte.MaxValue)
5180 OnSizeInitializedOrChanged ();
5181 OnSizeChanged(EventArgs.Empty);
5183 OnClientSizeChanged (EventArgs.Empty);
5188 [EditorBrowsable(EditorBrowsableState.Advanced)]
5189 protected void UpdateStyles() {
5190 if (!IsHandleCreated) {
5194 XplatUI.SetWindowStyle(window.Handle, CreateParams);
5195 OnStyleChanged(EventArgs.Empty);
5198 private void UpdateZOrderOfChild(Control child) {
5199 if (IsHandleCreated && child.IsHandleCreated && (child.parent == this) && Hwnd.ObjectFromHandle(child.Handle).Mapped) {
5200 // Need to take into account all controls
5201 Control [] all_controls = child_controls.GetAllControls ();
5203 int index = Array.IndexOf (all_controls, child);
5205 for (; index > 0; index--) {
5206 if (!all_controls [index - 1].IsHandleCreated || !all_controls [index - 1].VisibleInternal || !Hwnd.ObjectFromHandle(all_controls [index - 1].Handle).Mapped)
5212 XplatUI.SetZOrder(child.Handle, all_controls [index - 1].Handle, false, false);
5214 IntPtr after = AfterTopMostControl ();
5215 if (after != IntPtr.Zero && after != child.Handle)
5216 XplatUI.SetZOrder (child.Handle, after, false, false);
5218 XplatUI.SetZOrder (child.Handle, IntPtr.Zero, true, false);
5223 // Override this if there is a control that shall always remain on
5224 // top of other controls (such as scrollbars). If there are several
5225 // of these controls, the bottom-most should be returned.
5226 internal virtual IntPtr AfterTopMostControl () {
5230 // internal because we need to call it from ScrollableControl.OnVisibleChanged
5231 internal void UpdateChildrenZOrder() {
5232 Control [] controls;
5234 if (!IsHandleCreated) {
5238 // XXX This code is severely broken. It leaks
5239 // the "zero_sized" abstraction out of the X11
5240 // backend and into Control.cs. It'll work on
5241 // windows simply by virtue of windows never
5242 // setting that field to true.
5244 // basically what we need to guard against is
5245 // calling XplatUI.SetZOrder on an hwnd that
5246 // corresponds to an unmapped X window.
5248 // Also, explicitly send implicit controls to the back.
5249 if (child_controls.ImplicitControls == null) {
5250 controls = new Control [child_controls.Count];
5251 child_controls.CopyTo (controls, 0);
5253 controls = new Control [child_controls.Count + child_controls.ImplicitControls.Count];
5254 child_controls.CopyTo (controls, 0);
5255 child_controls.ImplicitControls.CopyTo (controls, child_controls.Count);
5258 ArrayList children_to_order = new ArrayList ();
5260 for (int i = 0; i < controls.Length; i ++) {
5261 if (!controls[i].IsHandleCreated || !controls[i].VisibleInternal)
5264 Hwnd hwnd = Hwnd.ObjectFromHandle (controls[i].Handle);
5265 if (hwnd.zero_sized)
5268 children_to_order.Add (controls[i]);
5271 for (int i = 1; i < children_to_order.Count; i ++) {
5272 Control upper = (Control)children_to_order[i-1];
5273 Control lower = (Control)children_to_order[i];
5275 XplatUI.SetZOrder(lower.Handle, upper.Handle, false, false);
5279 [EditorBrowsable(EditorBrowsableState.Advanced)]
5280 protected void UpdateZOrder() {
5281 if (parent != null) {
5282 parent.UpdateZOrderOfChild(this);
5286 protected virtual void WndProc(ref Message m) {
5288 Console.WriteLine("Control {0} received message {1}", window.Handle == IntPtr.Zero ? this.Text : XplatUI.Window(window.Handle), m.ToString ());
5290 if ((this.control_style & ControlStyles.EnableNotifyMessage) != 0) {
5294 switch((Msg)m.Msg) {
5295 case Msg.WM_DESTROY: {
5300 case Msg.WM_WINDOWPOSCHANGED: {
5301 WmWindowPosChanged(ref m);
5305 // Nice description of what should happen when handling WM_PAINT
5306 // can be found here: http://pluralsight.com/wiki/default.aspx/Craig/FlickerFreeControlDrawing.html
5307 // and here http://msdn.microsoft.com/msdnmag/issues/06/03/WindowsFormsPerformance/
5308 case Msg.WM_PAINT: {
5313 // The DefWndProc will never have to handle this, we always paint the background in managed code
5314 // In theory this code would look at ControlStyles.AllPaintingInWmPaint and and call OnPaintBackground
5315 // here but it just makes things more complicated...
5316 case Msg.WM_ERASEBKGND: {
5317 WmEraseBackground (ref m);
5321 case Msg.WM_LBUTTONUP: {
5322 WmLButtonUp (ref m);
5326 case Msg.WM_LBUTTONDOWN: {
5327 WmLButtonDown (ref m);
5331 case Msg.WM_LBUTTONDBLCLK: {
5332 WmLButtonDblClick (ref m);
5336 case Msg.WM_MBUTTONUP: {
5337 WmMButtonUp (ref m);
5341 case Msg.WM_MBUTTONDOWN: {
5342 WmMButtonDown (ref m);
5346 case Msg.WM_MBUTTONDBLCLK: {
5347 WmMButtonDblClick (ref m);
5351 case Msg.WM_RBUTTONUP: {
5352 WmRButtonUp (ref m);
5356 case Msg.WM_RBUTTONDOWN: {
5357 WmRButtonDown (ref m);
5361 case Msg.WM_RBUTTONDBLCLK: {
5362 WmRButtonDblClick (ref m);
5366 case Msg.WM_CONTEXTMENU: {
5367 WmContextMenu (ref m);
5371 case Msg.WM_MOUSEWHEEL: {
5372 WmMouseWheel (ref m);
5376 case Msg.WM_MOUSEMOVE: {
5377 WmMouseMove (ref m);
5381 case Msg.WM_SHOWWINDOW: {
5382 WmShowWindow (ref m);
5386 case Msg.WM_CREATE: {
5391 case Msg.WM_MOUSE_ENTER: {
5392 WmMouseEnter (ref m);
5396 case Msg.WM_MOUSELEAVE: {
5397 WmMouseLeave (ref m);
5401 case Msg.WM_MOUSEHOVER: {
5402 WmMouseHover (ref m);
5406 case Msg.WM_SYSKEYUP: {
5411 case Msg.WM_SYSKEYDOWN:
5412 case Msg.WM_KEYDOWN:
5414 case Msg.WM_SYSCHAR:
5425 case Msg.WM_KILLFOCUS: {
5426 WmKillFocus (ref m);
5430 case Msg.WM_SETFOCUS: {
5435 case Msg.WM_SYSCOLORCHANGE: {
5436 WmSysColorChange (ref m);
5440 case Msg.WM_SETCURSOR: {
5441 WmSetCursor (ref m);
5445 case Msg.WM_CAPTURECHANGED: {
5446 WmCaptureChanged (ref m);
5450 case Msg.WM_CHANGEUISTATE: {
5451 WmChangeUIState (ref m);
5455 case Msg.WM_UPDATEUISTATE: {
5456 WmUpdateUIState (ref m);
5466 #endregion // Public Instance Methods
5470 private void WmDestroy (ref Message m) {
5471 OnHandleDestroyed(EventArgs.Empty);
5473 IntPtr handle = window.Handle;
5475 window.InvalidateHandle();
5478 if (is_recreating) {
5480 Console.WriteLine ("Creating handle for {0:X}", handle.ToInt32());
5484 Console.WriteLine (" + new handle = {0:X}", Handle.ToInt32());
5486 is_recreating = false;
5490 is_disposing = false;
5495 private void WmWindowPosChanged (ref Message m) {
5497 Rectangle save_bounds = explicit_bounds;
5499 explicit_bounds = save_bounds;
5500 if (GetStyle(ControlStyles.ResizeRedraw)) {
5507 // Nice description of what should happen when handling WM_PAINT
5508 // can be found here: http://pluralsight.com/wiki/default.aspx/Craig/FlickerFreeControlDrawing.html
5509 // and here http://msdn.microsoft.com/msdnmag/issues/06/03/WindowsFormsPerformance/
5510 private void WmPaint (ref Message m) {
5511 PaintEventArgs paint_event;
5513 IntPtr handle = Handle;
5515 paint_event = XplatUI.PaintEventStart (ref m, handle, true);
5517 if (paint_event == null)
5520 DoubleBuffer current_buffer = null;
5521 if (UseDoubleBuffering) {
5522 current_buffer = GetBackBuffer ();
5523 // This optimization doesn't work when the area is invalidated
5524 // during a paint operation because finishing the paint operation
5525 // clears the invalidated region and then this thing keeps the new
5526 // invalidate from working. To re-enable this, we would need a
5527 // mechanism to allow for nested invalidates (see bug #328681)
5528 //if (!current_buffer.InvalidRegion.IsVisible (paint_event.ClipRectangle)) {
5529 // // Just blit the previous image
5530 // current_buffer.Blit (paint_event);
5531 // XplatUI.PaintEventEnd (ref m, handle, true);
5534 current_buffer.Start (paint_event);
5537 // If using OptimizedDoubleBuffer, ensure the clip region gets set
5538 if (GetStyle (ControlStyles.OptimizedDoubleBuffer))
5539 paint_event.Graphics.SetClip (Rectangle.Intersect (paint_event.ClipRectangle, this.ClientRectangle));
5542 if (!GetStyle(ControlStyles.Opaque)) {
5543 OnPaintBackground (paint_event);
5546 // Button-derived controls choose to ignore their Opaque style, give them a chance to draw their background anyways
5547 OnPaintBackgroundInternal (paint_event);
5549 OnPaintInternal(paint_event);
5550 if (!paint_event.Handled) {
5551 OnPaint (paint_event);
5554 if (current_buffer != null) {
5555 current_buffer.End (paint_event);
5559 XplatUI.PaintEventEnd (ref m, handle, true);
5562 private void WmEraseBackground (ref Message m) {
5563 // The DefWndProc will never have to handle this, we always paint the background in managed code
5564 // In theory this code would look at ControlStyles.AllPaintingInWmPaint and and call OnPaintBackground
5565 // here but it just makes things more complicated...
5566 m.Result = (IntPtr)1;
5569 private void WmLButtonUp (ref Message m)
5572 if (XplatUI.IsEnabled (Handle) && active_tracker != null) {
5573 ProcessActiveTracker (ref m);
5579 me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Left,
5581 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
5584 HandleClick(mouse_clicks, me);
5587 if (InternalCapture) {
5588 InternalCapture = false;
5591 if (mouse_clicks > 1) {
5596 private void WmLButtonDown (ref Message m)
5599 if (XplatUI.IsEnabled (Handle) && active_tracker != null) {
5600 ProcessActiveTracker (ref m);
5604 ValidationFailed = false;
5606 Select (true, true);
5608 if (!ValidationFailed) {
5609 InternalCapture = true;
5610 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
5611 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
5616 private void WmLButtonDblClick (ref Message m) {
5617 InternalCapture = true;
5619 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
5620 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
5624 private void WmMButtonUp (ref Message m) {
5627 me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Middle,
5629 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
5632 HandleClick(mouse_clicks, me);
5634 if (InternalCapture) {
5635 InternalCapture = false;
5637 if (mouse_clicks > 1) {
5642 private void WmMButtonDown (ref Message m) {
5643 InternalCapture = true;
5644 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
5645 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
5649 private void WmMButtonDblClick (ref Message m) {
5650 InternalCapture = true;
5652 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
5653 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
5657 private void WmRButtonUp (ref Message m)
5660 if (XplatUI.IsEnabled (Handle) && active_tracker != null) {
5661 ProcessActiveTracker (ref m);
5668 pt = new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()));
5669 pt = PointToScreen(pt);
5671 me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Right,
5673 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
5676 HandleClick(mouse_clicks, me);
5678 XplatUI.SendMessage(m.HWnd, Msg.WM_CONTEXTMENU, m.HWnd, (IntPtr)(pt.X + (pt.Y << 16)));
5681 if (InternalCapture) {
5682 InternalCapture = false;
5685 if (mouse_clicks > 1) {
5690 private void WmRButtonDown (ref Message m)
5693 if (XplatUI.IsEnabled (Handle) && active_tracker != null) {
5694 ProcessActiveTracker (ref m);
5698 InternalCapture = true;
5699 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
5700 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
5704 private void WmRButtonDblClick (ref Message m) {
5705 InternalCapture = true;
5707 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
5708 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
5712 private void WmContextMenu (ref Message m) {
5713 if (context_menu != null) {
5716 pt = new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()));
5718 if (pt.X == -1 || pt.Y == -1) {
5719 pt.X = (this.Width / 2) + this.Left;
5720 pt.Y = (this.Height / 2) + this.Top;
5721 pt = this.PointToScreen (pt);
5724 context_menu.Show (this, PointToClient (pt));
5729 // If there isn't a regular context menu, show the Strip version
5730 if (context_menu == null && context_menu_strip != null) {
5733 pt = new Point (LowOrder ((int)m.LParam.ToInt32 ()), HighOrder ((int)m.LParam.ToInt32 ()));
5735 if (pt.X == -1 || pt.Y == -1) {
5736 pt.X = (this.Width / 2) + this.Left;
5737 pt.Y = (this.Height /2) + this.Top;
5738 pt = this.PointToScreen (pt);
5741 context_menu_strip.SetSourceControl (this);
5742 context_menu_strip.Show (this, PointToClient (pt));
5749 private void WmCreate (ref Message m) {
5750 OnHandleCreated(EventArgs.Empty);
5753 private void WmMouseWheel (ref Message m) {
5755 OnMouseWheel (new MouseEventArgs (FromParamToMouseButtons ((long) m.WParam),
5756 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
5757 HighOrder((long)m.WParam)));
5761 private void WmMouseMove (ref Message m) {
5762 if (XplatUI.IsEnabled (Handle) && active_tracker != null) {
5763 MouseEventArgs args = new MouseEventArgs (
5764 FromParamToMouseButtons ((int)m.WParam.ToInt32 ()),
5766 Control.MousePosition.X,
5767 Control.MousePosition.Y,
5770 active_tracker.OnMotion (args);
5774 OnMouseMove (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
5776 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
5780 private void WmMouseEnter (ref Message m) {
5785 OnMouseEnter(EventArgs.Empty);
5788 private void WmMouseLeave (ref Message m) {
5790 OnMouseLeave(EventArgs.Empty);
5793 private void WmMouseHover (ref Message m) {
5794 OnMouseHover(EventArgs.Empty);
5797 private void WmShowWindow (ref Message m) {
5801 Form frm = this as Form;
5802 if (m.WParam.ToInt32() != 0) {
5803 if (m.LParam.ToInt32 () == 0) {
5806 // Make sure all our children are properly parented to us
5807 Control [] controls = child_controls.GetAllControls ();
5808 // bool parented = false;
5809 for (int i=0; i<controls.Length; i++) {
5810 if (controls [i].is_visible && controls[i].IsHandleCreated)
5811 if (XplatUI.GetParent (controls[i].Handle) != window.Handle) {
5812 XplatUI.SetParent(controls[i].Handle, window.Handle);
5819 UpdateChildrenZOrder ();
5822 if (parent != null && Focused) {
5824 // Need to start at parent, GetContainerControl might return ourselves if we're a container
5825 container = (Control)parent.GetContainerControl();
5826 if (container != null && (frm == null || !frm.IsMdiChild)) {
5827 container.SelectNextControl(this, true, true, true, true);
5833 frm.waiting_showwindow = false;
5835 // If the form is Max/Min, it got its OnVisibleChanged in SetVisibleCore
5837 if (!IsRecreating && (frm.IsMdiChild || frm.WindowState == FormWindowState.Normal)) /* XXX make sure this works for mdi forms */
5838 OnVisibleChanged(EventArgs.Empty);
5839 } else if (is_toplevel)
5840 OnVisibleChanged(EventArgs.Empty);
5843 private void WmSysKeyUp (ref Message m) {
5844 if (ProcessKeyMessage(ref m)) {
5845 m.Result = IntPtr.Zero;
5849 if ((m.WParam.ToInt32() & (int)Keys.KeyCode) == (int)Keys.Menu) {
5853 if (form != null && form.ActiveMenu != null) {
5854 form.ActiveMenu.ProcessCmdKey(ref m, (Keys)m.WParam.ToInt32());
5858 if (ToolStripManager.ProcessMenuKey (ref m))
5866 private void WmKeys (ref Message m)
5868 if (ProcessKeyMessage(ref m)) {
5869 m.Result = IntPtr.Zero;
5875 private void WmHelp (ref Message m) {
5877 if (m.LParam != IntPtr.Zero) {
5880 hi = new HELPINFO();
5882 hi = (HELPINFO) Marshal.PtrToStructure (m.LParam, typeof (HELPINFO));
5883 mouse_pos = new Point(hi.MousePos.x, hi.MousePos.y);
5885 mouse_pos = Control.MousePosition;
5887 OnHelpRequested(new HelpEventArgs(mouse_pos));
5888 m.Result = (IntPtr)1;
5891 private void WmKillFocus (ref Message m) {
5892 this.has_focus = false;
5893 OnLostFocus (EventArgs.Empty);
5896 private void WmSetFocus (ref Message m) {
5898 this.has_focus = true;
5899 OnGotFocus (EventArgs.Empty);
5903 private void WmSysColorChange (ref Message m) {
5904 ThemeEngine.Current.ResetDefaults();
5905 OnSystemColorsChanged(EventArgs.Empty);
5908 private void WmSetCursor (ref Message m) {
5909 if ((cursor == null && use_wait_cursor == false) || ((HitTest)(m.LParam.ToInt32() & 0xffff) != HitTest.HTCLIENT)) {
5914 XplatUI.SetCursor(window.Handle, Cursor.handle);
5915 m.Result = (IntPtr)1;
5918 private void WmCaptureChanged (ref Message m) {
5919 is_captured = false;
5920 OnMouseCaptureChanged (EventArgs.Empty);
5921 m.Result = (IntPtr) 0;
5924 private void WmChangeUIState (ref Message m) {
5925 foreach (Control control in Controls) {
5926 XplatUI.SendMessage (control.Handle, Msg.WM_UPDATEUISTATE, m.WParam, m.LParam);
5930 private void WmUpdateUIState (ref Message m) {
5931 int action = LowOrder (m.WParam.ToInt32 ());
5932 int element = HighOrder (m.WParam.ToInt32 ());
5934 if (action == (int) MsgUIState.UIS_INITIALIZE)
5937 UICues cues = UICues.None;
5939 if ((element & (int) MsgUIState.UISF_HIDEACCEL) != 0) {
5940 if ((action == (int) MsgUIState.UIS_CLEAR) != show_keyboard_cues) {
5941 cues |= UICues.ChangeKeyboard;
5942 show_keyboard_cues = (action == (int) MsgUIState.UIS_CLEAR);
5946 if ((element & (int) MsgUIState.UISF_HIDEFOCUS) != 0) {
5947 if ((action == (int) MsgUIState.UIS_CLEAR) != show_focus_cues) {
5948 cues |= UICues.ChangeFocus;
5949 show_focus_cues = (action == (int) MsgUIState.UIS_CLEAR);
5953 if ((cues & UICues.Changed) != UICues.None) {
5954 OnChangeUICues (new UICuesEventArgs (cues));
5961 #region OnXXX methods
5963 protected virtual void OnAutoSizeChanged (EventArgs e)
5965 EventHandler eh = (EventHandler)(Events[AutoSizeChangedEvent]);
5971 [EditorBrowsable (EditorBrowsableState.Advanced)]
5972 protected virtual void OnBackColorChanged(EventArgs e) {
5973 EventHandler eh = (EventHandler)(Events [BackColorChangedEvent]);
5976 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackColorChanged(e);
5979 [EditorBrowsable(EditorBrowsableState.Advanced)]
5980 protected virtual void OnBackgroundImageChanged(EventArgs e) {
5981 EventHandler eh = (EventHandler)(Events [BackgroundImageChangedEvent]);
5984 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackgroundImageChanged(e);
5988 [EditorBrowsable (EditorBrowsableState.Advanced)]
5989 protected virtual void OnBackgroundImageLayoutChanged (EventArgs e)
5991 EventHandler eh = (EventHandler)(Events[BackgroundImageLayoutChangedEvent]);
5997 [EditorBrowsable(EditorBrowsableState.Advanced)]
5998 protected virtual void OnBindingContextChanged(EventArgs e) {
5999 CheckDataBindings ();
6000 EventHandler eh = (EventHandler)(Events [BindingContextChangedEvent]);
6003 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBindingContextChanged(e);
6006 [EditorBrowsable(EditorBrowsableState.Advanced)]
6007 protected virtual void OnCausesValidationChanged(EventArgs e) {
6008 EventHandler eh = (EventHandler)(Events [CausesValidationChangedEvent]);
6013 [EditorBrowsable(EditorBrowsableState.Advanced)]
6014 protected virtual void OnChangeUICues(UICuesEventArgs e) {
6015 UICuesEventHandler eh = (UICuesEventHandler)(Events [ChangeUICuesEvent]);
6020 [EditorBrowsable(EditorBrowsableState.Advanced)]
6021 protected virtual void OnClick(EventArgs e) {
6022 EventHandler eh = (EventHandler)(Events [ClickEvent]);
6028 [EditorBrowsable (EditorBrowsableState.Advanced)]
6029 protected virtual void OnClientSizeChanged (EventArgs e)
6031 EventHandler eh = (EventHandler)(Events[ClientSizeChangedEvent]);
6037 [EditorBrowsable(EditorBrowsableState.Advanced)]
6038 protected virtual void OnContextMenuChanged(EventArgs e) {
6039 EventHandler eh = (EventHandler)(Events [ContextMenuChangedEvent]);
6045 [EditorBrowsable (EditorBrowsableState.Advanced)]
6046 protected virtual void OnContextMenuStripChanged (EventArgs e) {
6047 EventHandler eh = (EventHandler)(Events [ContextMenuStripChangedEvent]);
6053 [EditorBrowsable(EditorBrowsableState.Advanced)]
6054 protected virtual void OnControlAdded(ControlEventArgs e) {
6055 ControlEventHandler eh = (ControlEventHandler)(Events [ControlAddedEvent]);
6060 [EditorBrowsable(EditorBrowsableState.Advanced)]
6061 protected virtual void OnControlRemoved(ControlEventArgs e) {
6062 ControlEventHandler eh = (ControlEventHandler)(Events [ControlRemovedEvent]);
6067 [EditorBrowsable(EditorBrowsableState.Advanced)]
6068 protected virtual void OnCreateControl() {
6072 [EditorBrowsable(EditorBrowsableState.Advanced)]
6073 protected virtual void OnCursorChanged(EventArgs e) {
6074 EventHandler eh = (EventHandler)(Events [CursorChangedEvent]);
6079 for (int i = 0; i < child_controls.Count; i++) child_controls[i].OnParentCursorChanged (e);
6083 [EditorBrowsable(EditorBrowsableState.Advanced)]
6084 protected virtual void OnDockChanged(EventArgs e) {
6085 EventHandler eh = (EventHandler)(Events [DockChangedEvent]);
6090 [EditorBrowsable(EditorBrowsableState.Advanced)]
6091 protected virtual void OnDoubleClick(EventArgs e) {
6092 EventHandler eh = (EventHandler)(Events [DoubleClickEvent]);
6097 [EditorBrowsable(EditorBrowsableState.Advanced)]
6098 protected virtual void OnDragDrop(DragEventArgs drgevent) {
6099 DragEventHandler eh = (DragEventHandler)(Events [DragDropEvent]);
6101 eh (this, drgevent);
6104 [EditorBrowsable(EditorBrowsableState.Advanced)]
6105 protected virtual void OnDragEnter(DragEventArgs drgevent) {
6106 DragEventHandler eh = (DragEventHandler)(Events [DragEnterEvent]);
6108 eh (this, drgevent);
6111 [EditorBrowsable(EditorBrowsableState.Advanced)]
6112 protected virtual void OnDragLeave(EventArgs e) {
6113 EventHandler eh = (EventHandler)(Events [DragLeaveEvent]);
6118 [EditorBrowsable(EditorBrowsableState.Advanced)]
6119 protected virtual void OnDragOver(DragEventArgs drgevent) {
6120 DragEventHandler eh = (DragEventHandler)(Events [DragOverEvent]);
6122 eh (this, drgevent);
6125 [EditorBrowsable(EditorBrowsableState.Advanced)]
6126 protected virtual void OnEnabledChanged(EventArgs e) {
6127 if (IsHandleCreated) {
6129 if (((Form)this).context == null) {
6130 XplatUI.EnableWindow(window.Handle, Enabled);
6133 XplatUI.EnableWindow(window.Handle, Enabled);
6138 EventHandler eh = (EventHandler)(Events [EnabledChangedEvent]);
6142 foreach (Control c in Controls.GetAllControls ())
6143 c.OnParentEnabledChanged (e);
6146 [EditorBrowsable(EditorBrowsableState.Advanced)]
6147 protected virtual void OnEnter(EventArgs e) {
6148 EventHandler eh = (EventHandler)(Events [EnterEvent]);
6153 [EditorBrowsable(EditorBrowsableState.Advanced)]
6154 protected virtual void OnFontChanged(EventArgs e) {
6155 EventHandler eh = (EventHandler)(Events [FontChangedEvent]);
6158 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentFontChanged(e);
6161 [EditorBrowsable(EditorBrowsableState.Advanced)]
6162 protected virtual void OnForeColorChanged(EventArgs e) {
6163 EventHandler eh = (EventHandler)(Events [ForeColorChangedEvent]);
6166 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentForeColorChanged(e);
6169 [EditorBrowsable(EditorBrowsableState.Advanced)]
6170 protected virtual void OnGiveFeedback(GiveFeedbackEventArgs gfbevent) {
6171 GiveFeedbackEventHandler eh = (GiveFeedbackEventHandler)(Events [GiveFeedbackEvent]);
6173 eh (this, gfbevent);
6176 [EditorBrowsable(EditorBrowsableState.Advanced)]
6177 protected virtual void OnGotFocus(EventArgs e) {
6178 EventHandler eh = (EventHandler)(Events [GotFocusEvent]);
6183 [EditorBrowsable(EditorBrowsableState.Advanced)]
6184 protected virtual void OnHandleCreated(EventArgs e) {
6185 EventHandler eh = (EventHandler)(Events [HandleCreatedEvent]);
6190 [EditorBrowsable(EditorBrowsableState.Advanced)]
6191 protected virtual void OnHandleDestroyed(EventArgs e) {
6192 EventHandler eh = (EventHandler)(Events [HandleDestroyedEvent]);
6197 internal void RaiseHelpRequested (HelpEventArgs hevent) {
6198 OnHelpRequested (hevent);
6201 [EditorBrowsable(EditorBrowsableState.Advanced)]
6202 protected virtual void OnHelpRequested(HelpEventArgs hevent) {
6203 HelpEventHandler eh = (HelpEventHandler)(Events [HelpRequestedEvent]);
6208 protected virtual void OnImeModeChanged(EventArgs e) {
6209 EventHandler eh = (EventHandler)(Events [ImeModeChangedEvent]);
6214 [EditorBrowsable(EditorBrowsableState.Advanced)]
6215 protected virtual void OnInvalidated(InvalidateEventArgs e) {
6216 if (UseDoubleBuffering) {
6217 // should this block be here? seems like it
6218 // would be more at home in
6219 // NotifyInvalidated..
6220 if (e.InvalidRect == ClientRectangle) {
6221 InvalidateBackBuffer ();
6222 } else if (backbuffer != null){
6223 // we need this Inflate call here so
6224 // that the border of the rectangle is
6225 // considered Visible (the
6226 // invalid_region.IsVisible call) in
6227 // the WM_PAINT handling below.
6228 Rectangle r = Rectangle.Inflate(e.InvalidRect, 1,1);
6229 backbuffer.InvalidRegion.Union (r);
6233 InvalidateEventHandler eh = (InvalidateEventHandler)(Events [InvalidatedEvent]);
6238 [EditorBrowsable(EditorBrowsableState.Advanced)]
6239 protected virtual void OnKeyDown(KeyEventArgs e) {
6240 KeyEventHandler eh = (KeyEventHandler)(Events [KeyDownEvent]);
6245 [EditorBrowsable(EditorBrowsableState.Advanced)]
6246 protected virtual void OnKeyPress(KeyPressEventArgs e) {
6247 KeyPressEventHandler eh = (KeyPressEventHandler)(Events [KeyPressEvent]);
6252 [EditorBrowsable(EditorBrowsableState.Advanced)]
6253 protected virtual void OnKeyUp(KeyEventArgs e) {
6254 KeyEventHandler eh = (KeyEventHandler)(Events [KeyUpEvent]);
6259 [EditorBrowsable(EditorBrowsableState.Advanced)]
6260 protected virtual void OnLayout(LayoutEventArgs levent) {
6261 LayoutEventHandler eh = (LayoutEventHandler)(Events [LayoutEvent]);
6268 // If our layout changed our PreferredSize, our parent
6269 // needs to re-lay us out. However, it's not always possible to
6270 // be our preferred size, so only try once so we don't loop forever.
6271 if (Parent != null && AutoSize && !nested_layout && PreferredSize != s) {
6272 nested_layout = true;
6273 Parent.PerformLayout ();
6274 nested_layout = false;
6278 LayoutEngine.Layout (this, levent);
6281 [EditorBrowsable(EditorBrowsableState.Advanced)]
6282 protected virtual void OnLeave(EventArgs e) {
6283 EventHandler eh = (EventHandler)(Events [LeaveEvent]);
6288 [EditorBrowsable(EditorBrowsableState.Advanced)]
6289 protected virtual void OnLocationChanged(EventArgs e) {
6291 EventHandler eh = (EventHandler)(Events [LocationChangedEvent]);
6296 [EditorBrowsable(EditorBrowsableState.Advanced)]
6297 protected virtual void OnLostFocus(EventArgs e) {
6298 EventHandler eh = (EventHandler)(Events [LostFocusEvent]);
6304 protected virtual void OnMarginChanged (EventArgs e)
6306 EventHandler eh = (EventHandler)(Events[MarginChangedEvent]);
6311 [EditorBrowsable (EditorBrowsableState.Advanced)]
6313 protected virtual void OnMouseCaptureChanged (EventArgs e)
6315 internal virtual void OnMouseCaptureChanged (EventArgs e)
6318 EventHandler eh = (EventHandler)(Events [MouseCaptureChangedEvent]);
6324 [EditorBrowsable (EditorBrowsableState.Advanced)]
6325 protected virtual void OnMouseClick (MouseEventArgs e)
6327 MouseEventHandler eh = (MouseEventHandler)(Events [MouseClickEvent]);
6332 [EditorBrowsable (EditorBrowsableState.Advanced)]
6333 protected virtual void OnMouseDoubleClick (MouseEventArgs e)
6335 MouseEventHandler eh = (MouseEventHandler)(Events [MouseDoubleClickEvent]);
6341 [EditorBrowsable(EditorBrowsableState.Advanced)]
6342 protected virtual void OnMouseDown(MouseEventArgs e) {
6343 MouseEventHandler eh = (MouseEventHandler)(Events [MouseDownEvent]);
6348 [EditorBrowsable(EditorBrowsableState.Advanced)]
6349 protected virtual void OnMouseEnter(EventArgs e) {
6350 EventHandler eh = (EventHandler)(Events [MouseEnterEvent]);
6355 [EditorBrowsable(EditorBrowsableState.Advanced)]
6356 protected virtual void OnMouseHover(EventArgs e) {
6357 EventHandler eh = (EventHandler)(Events [MouseHoverEvent]);
6362 [EditorBrowsable(EditorBrowsableState.Advanced)]
6363 protected virtual void OnMouseLeave(EventArgs e) {
6364 EventHandler eh = (EventHandler)(Events [MouseLeaveEvent]);
6369 [EditorBrowsable(EditorBrowsableState.Advanced)]
6370 protected virtual void OnMouseMove(MouseEventArgs e) {
6371 MouseEventHandler eh = (MouseEventHandler)(Events [MouseMoveEvent]);
6376 [EditorBrowsable(EditorBrowsableState.Advanced)]
6377 protected virtual void OnMouseUp(MouseEventArgs e) {
6378 MouseEventHandler eh = (MouseEventHandler)(Events [MouseUpEvent]);
6383 [EditorBrowsable(EditorBrowsableState.Advanced)]
6384 protected virtual void OnMouseWheel(MouseEventArgs e) {
6385 MouseEventHandler eh = (MouseEventHandler)(Events [MouseWheelEvent]);
6390 [EditorBrowsable(EditorBrowsableState.Advanced)]
6391 protected virtual void OnMove(EventArgs e) {
6392 EventHandler eh = (EventHandler)(Events [MoveEvent]);
6397 [EditorBrowsable(EditorBrowsableState.Advanced)]
6398 protected virtual void OnNotifyMessage(Message m) {
6403 protected virtual void OnPaddingChanged (EventArgs e) {
6404 EventHandler eh = (EventHandler) (Events [PaddingChangedEvent]);
6410 [EditorBrowsable(EditorBrowsableState.Advanced)]
6411 protected virtual void OnPaint(PaintEventArgs e) {
6412 PaintEventHandler eh = (PaintEventHandler)(Events [PaintEvent]);
6417 internal virtual void OnPaintBackgroundInternal(PaintEventArgs e) {
6421 internal virtual void OnPaintInternal(PaintEventArgs e) {
6425 [EditorBrowsable(EditorBrowsableState.Advanced)]
6426 protected virtual void OnPaintBackground(PaintEventArgs pevent) {
6427 PaintControlBackground (pevent);
6430 [EditorBrowsable(EditorBrowsableState.Advanced)]
6431 protected virtual void OnParentBackColorChanged(EventArgs e) {
6432 if (background_color.IsEmpty && background_image==null) {
6434 OnBackColorChanged(e);
6438 [EditorBrowsable(EditorBrowsableState.Advanced)]
6439 protected virtual void OnParentBackgroundImageChanged(EventArgs e) {
6441 OnBackgroundImageChanged(e);
6444 [EditorBrowsable(EditorBrowsableState.Advanced)]
6445 protected virtual void OnParentBindingContextChanged(EventArgs e) {
6446 if (binding_context==null && Parent != null) {
6447 binding_context=Parent.binding_context;
6448 OnBindingContextChanged(e);
6452 [EditorBrowsable(EditorBrowsableState.Advanced)]
6453 protected virtual void OnParentChanged(EventArgs e) {
6454 EventHandler eh = (EventHandler)(Events [ParentChangedEvent]);
6460 [EditorBrowsable (EditorBrowsableState.Advanced)]
6461 protected virtual void OnParentCursorChanged (EventArgs e)
6466 [EditorBrowsable (EditorBrowsableState.Advanced)]
6467 protected virtual void OnParentEnabledChanged(EventArgs e) {
6469 OnEnabledChanged(e);
6473 [EditorBrowsable(EditorBrowsableState.Advanced)]
6474 protected virtual void OnParentFontChanged(EventArgs e) {
6481 [EditorBrowsable(EditorBrowsableState.Advanced)]
6482 protected virtual void OnParentForeColorChanged(EventArgs e) {
6483 if (foreground_color.IsEmpty) {
6485 OnForeColorChanged(e);
6489 [EditorBrowsable(EditorBrowsableState.Advanced)]
6490 protected virtual void OnParentRightToLeftChanged(EventArgs e) {
6491 if (right_to_left==RightToLeft.Inherit) {
6493 OnRightToLeftChanged(e);
6497 [EditorBrowsable(EditorBrowsableState.Advanced)]
6498 protected virtual void OnParentVisibleChanged(EventArgs e) {
6500 OnVisibleChanged(e);
6504 [EditorBrowsable(EditorBrowsableState.Advanced)]
6505 protected virtual void OnQueryContinueDrag (QueryContinueDragEventArgs qcdevent)
6507 QueryContinueDragEventHandler eh = (QueryContinueDragEventHandler)(Events [QueryContinueDragEvent]);
6509 eh (this, qcdevent);
6513 [EditorBrowsable (EditorBrowsableState.Advanced)]
6514 protected virtual void OnPreviewKeyDown (PreviewKeyDownEventArgs e)
6516 PreviewKeyDownEventHandler eh = (PreviewKeyDownEventHandler)(Events[PreviewKeyDownEvent]);
6521 [EditorBrowsable (EditorBrowsableState.Advanced)]
6522 protected virtual void OnPrint (PaintEventArgs e)
6524 PaintEventHandler eh = (PaintEventHandler)(Events[PaintEvent]);
6529 [EditorBrowsable (EditorBrowsableState.Advanced)]
6530 protected virtual void OnRegionChanged (EventArgs e)
6532 EventHandler eh = (EventHandler)(Events[RegionChangedEvent]);
6538 [EditorBrowsable(EditorBrowsableState.Advanced)]
6539 protected virtual void OnResize(EventArgs e) {
6540 OnResizeInternal (e);
6543 internal virtual void OnResizeInternal (EventArgs e) {
6544 PerformLayout(this, "Bounds");
6546 EventHandler eh = (EventHandler)(Events [ResizeEvent]);
6551 [EditorBrowsable(EditorBrowsableState.Advanced)]
6552 protected virtual void OnRightToLeftChanged(EventArgs e) {
6553 EventHandler eh = (EventHandler)(Events [RightToLeftChangedEvent]);
6556 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentRightToLeftChanged(e);
6559 [EditorBrowsable(EditorBrowsableState.Advanced)]
6560 protected virtual void OnSizeChanged(EventArgs e) {
6561 DisposeBackBuffer ();
6563 EventHandler eh = (EventHandler)(Events [SizeChangedEvent]);
6568 [EditorBrowsable(EditorBrowsableState.Advanced)]
6569 protected virtual void OnStyleChanged(EventArgs e) {
6570 EventHandler eh = (EventHandler)(Events [StyleChangedEvent]);
6575 [EditorBrowsable(EditorBrowsableState.Advanced)]
6576 protected virtual void OnSystemColorsChanged(EventArgs e) {
6577 EventHandler eh = (EventHandler)(Events [SystemColorsChangedEvent]);
6582 [EditorBrowsable(EditorBrowsableState.Advanced)]
6583 protected virtual void OnTabIndexChanged(EventArgs e) {
6584 EventHandler eh = (EventHandler)(Events [TabIndexChangedEvent]);
6589 [EditorBrowsable(EditorBrowsableState.Advanced)]
6590 protected virtual void OnTabStopChanged(EventArgs e) {
6591 EventHandler eh = (EventHandler)(Events [TabStopChangedEvent]);
6596 [EditorBrowsable(EditorBrowsableState.Advanced)]
6597 protected virtual void OnTextChanged(EventArgs e) {
6598 EventHandler eh = (EventHandler)(Events [TextChangedEvent]);
6603 [EditorBrowsable(EditorBrowsableState.Advanced)]
6604 protected virtual void OnValidated(EventArgs e) {
6605 EventHandler eh = (EventHandler)(Events [ValidatedEvent]);
6610 [EditorBrowsable(EditorBrowsableState.Advanced)]
6611 protected virtual void OnValidating(System.ComponentModel.CancelEventArgs e) {
6612 CancelEventHandler eh = (CancelEventHandler)(Events [ValidatingEvent]);
6617 [EditorBrowsable(EditorBrowsableState.Advanced)]
6618 protected virtual void OnVisibleChanged(EventArgs e) {
6622 EventHandler eh = (EventHandler)(Events [VisibleChangedEvent]);
6626 // We need to tell our kids (including implicit ones)
6627 foreach (Control c in Controls.GetAllControls ())
6629 c.OnParentVisibleChanged (e);
6631 #endregion // OnXXX methods
6635 static object AutoSizeChangedEvent = new object ();
6637 static object BackColorChangedEvent = new object ();
6638 static object BackgroundImageChangedEvent = new object ();
6640 static object BackgroundImageLayoutChangedEvent = new object ();
6642 static object BindingContextChangedEvent = new object ();
6643 static object CausesValidationChangedEvent = new object ();
6644 static object ChangeUICuesEvent = new object ();
6645 static object ClickEvent = new object ();
6647 static object ClientSizeChangedEvent = new object ();
6649 static object ContextMenuChangedEvent = new object ();
6651 static object ContextMenuStripChangedEvent = new object ();
6653 static object ControlAddedEvent = new object ();
6654 static object ControlRemovedEvent = new object ();
6655 static object CursorChangedEvent = new object ();
6656 static object DockChangedEvent = new object ();
6657 static object DoubleClickEvent = new object ();
6658 static object DragDropEvent = new object ();
6659 static object DragEnterEvent = new object ();
6660 static object DragLeaveEvent = new object ();
6661 static object DragOverEvent = new object ();
6662 static object EnabledChangedEvent = new object ();
6663 static object EnterEvent = new object ();
6664 static object FontChangedEvent = new object ();
6665 static object ForeColorChangedEvent = new object ();
6666 static object GiveFeedbackEvent = new object ();
6667 static object GotFocusEvent = new object ();
6668 static object HandleCreatedEvent = new object ();
6669 static object HandleDestroyedEvent = new object ();
6670 static object HelpRequestedEvent = new object ();
6671 static object ImeModeChangedEvent = new object ();
6672 static object InvalidatedEvent = new object ();
6673 static object KeyDownEvent = new object ();
6674 static object KeyPressEvent = new object ();
6675 static object KeyUpEvent = new object ();
6676 static object LayoutEvent = new object ();
6677 static object LeaveEvent = new object ();
6678 static object LocationChangedEvent = new object ();
6679 static object LostFocusEvent = new object ();
6681 static object MarginChangedEvent = new object ();
6683 static object MouseCaptureChangedEvent = new object ();
6685 static object MouseClickEvent = new object ();
6686 static object MouseDoubleClickEvent = new object ();
6688 static object MouseDownEvent = new object ();
6689 static object MouseEnterEvent = new object ();
6690 static object MouseHoverEvent = new object ();
6691 static object MouseLeaveEvent = new object ();
6692 static object MouseMoveEvent = new object ();
6693 static object MouseUpEvent = new object ();
6694 static object MouseWheelEvent = new object ();
6695 static object MoveEvent = new object ();
6697 static object PaddingChangedEvent = new object ();
6699 static object PaintEvent = new object ();
6700 static object ParentChangedEvent = new object ();
6702 static object PreviewKeyDownEvent = new object ();
6704 static object QueryAccessibilityHelpEvent = new object ();
6705 static object QueryContinueDragEvent = new object ();
6707 static object RegionChangedEvent = new object ();
6709 static object ResizeEvent = new object ();
6710 static object RightToLeftChangedEvent = new object ();
6711 static object SizeChangedEvent = new object ();
6712 static object StyleChangedEvent = new object ();
6713 static object SystemColorsChangedEvent = new object ();
6714 static object TabIndexChangedEvent = new object ();
6715 static object TabStopChangedEvent = new object ();
6716 static object TextChangedEvent = new object ();
6717 static object ValidatedEvent = new object ();
6718 static object ValidatingEvent = new object ();
6719 static object VisibleChangedEvent = new object ();
6723 [EditorBrowsable (EditorBrowsableState.Never)]
6724 public event EventHandler AutoSizeChanged {
6725 add { Events.AddHandler (AutoSizeChangedEvent, value);}
6726 remove {Events.RemoveHandler (AutoSizeChangedEvent, value);}
6729 public event EventHandler BackColorChanged {
6730 add { Events.AddHandler (BackColorChangedEvent, value); }
6731 remove { Events.RemoveHandler (BackColorChangedEvent, value); }
6734 public event EventHandler BackgroundImageChanged {
6735 add { Events.AddHandler (BackgroundImageChangedEvent, value); }
6736 remove { Events.RemoveHandler (BackgroundImageChangedEvent, value); }
6740 public event EventHandler BackgroundImageLayoutChanged {
6741 add {Events.AddHandler (BackgroundImageLayoutChangedEvent, value);}
6742 remove {Events.RemoveHandler (BackgroundImageLayoutChangedEvent, value);}
6746 public event EventHandler BindingContextChanged {
6747 add { Events.AddHandler (BindingContextChangedEvent, value); }
6748 remove { Events.RemoveHandler (BindingContextChangedEvent, value); }
6751 public event EventHandler CausesValidationChanged {
6752 add { Events.AddHandler (CausesValidationChangedEvent, value); }
6753 remove { Events.RemoveHandler (CausesValidationChangedEvent, value); }
6756 public event UICuesEventHandler ChangeUICues {
6757 add { Events.AddHandler (ChangeUICuesEvent, value); }
6758 remove { Events.RemoveHandler (ChangeUICuesEvent, value); }
6761 public event EventHandler Click {
6762 add { Events.AddHandler (ClickEvent, value); }
6763 remove { Events.RemoveHandler (ClickEvent, value); }
6767 public event EventHandler ClientSizeChanged {
6768 add {Events.AddHandler (ClientSizeChangedEvent, value);}
6769 remove {Events.RemoveHandler (ClientSizeChangedEvent, value);}
6776 public event EventHandler ContextMenuChanged {
6777 add { Events.AddHandler (ContextMenuChangedEvent, value); }
6778 remove { Events.RemoveHandler (ContextMenuChangedEvent, value); }
6782 public event EventHandler ContextMenuStripChanged {
6783 add { Events.AddHandler (ContextMenuStripChangedEvent, value); }
6784 remove { Events.RemoveHandler (ContextMenuStripChangedEvent, value);}
6789 [EditorBrowsable(EditorBrowsableState.Advanced)]
6795 public event ControlEventHandler ControlAdded {
6796 add { Events.AddHandler (ControlAddedEvent, value); }
6797 remove { Events.RemoveHandler (ControlAddedEvent, value); }
6800 [EditorBrowsable(EditorBrowsableState.Advanced)]
6806 public event ControlEventHandler ControlRemoved {
6807 add { Events.AddHandler (ControlRemovedEvent, value); }
6808 remove { Events.RemoveHandler (ControlRemovedEvent, value); }
6811 [MWFDescription("Fired when the cursor for the control has been changed"), MWFCategory("PropertyChanged")]
6812 public event EventHandler CursorChanged {
6813 add { Events.AddHandler (CursorChangedEvent, value); }
6814 remove { Events.RemoveHandler (CursorChangedEvent, value); }
6816 public event EventHandler DockChanged {
6817 add { Events.AddHandler (DockChangedEvent, value); }
6818 remove { Events.RemoveHandler (DockChangedEvent, value); }
6821 public event EventHandler DoubleClick {
6822 add { Events.AddHandler (DoubleClickEvent, value); }
6823 remove { Events.RemoveHandler (DoubleClickEvent, value); }
6826 public event DragEventHandler DragDrop {
6827 add { Events.AddHandler (DragDropEvent, value); }
6828 remove { Events.RemoveHandler (DragDropEvent, value); }
6831 public event DragEventHandler DragEnter {
6832 add { Events.AddHandler (DragEnterEvent, value); }
6833 remove { Events.RemoveHandler (DragEnterEvent, value); }
6836 public event EventHandler DragLeave {
6837 add { Events.AddHandler (DragLeaveEvent, value); }
6838 remove { Events.RemoveHandler (DragLeaveEvent, value); }
6841 public event DragEventHandler DragOver {
6842 add { Events.AddHandler (DragOverEvent, value); }
6843 remove { Events.RemoveHandler (DragOverEvent, value); }
6846 public event EventHandler EnabledChanged {
6847 add { Events.AddHandler (EnabledChangedEvent, value); }
6848 remove { Events.RemoveHandler (EnabledChangedEvent, value); }
6851 public event EventHandler Enter {
6852 add { Events.AddHandler (EnterEvent, value); }
6853 remove { Events.RemoveHandler (EnterEvent, value); }
6856 public event EventHandler FontChanged {
6857 add { Events.AddHandler (FontChangedEvent, value); }
6858 remove { Events.RemoveHandler (FontChangedEvent, value); }
6861 public event EventHandler ForeColorChanged {
6862 add { Events.AddHandler (ForeColorChangedEvent, value); }
6863 remove { Events.RemoveHandler (ForeColorChangedEvent, value); }
6866 public event GiveFeedbackEventHandler GiveFeedback {
6867 add { Events.AddHandler (GiveFeedbackEvent, value); }
6868 remove { Events.RemoveHandler (GiveFeedbackEvent, value); }
6871 [EditorBrowsable(EditorBrowsableState.Advanced)]
6873 public event EventHandler GotFocus {
6874 add { Events.AddHandler (GotFocusEvent, value); }
6875 remove { Events.RemoveHandler (GotFocusEvent, value); }
6879 [EditorBrowsable(EditorBrowsableState.Advanced)]
6881 public event EventHandler HandleCreated {
6882 add { Events.AddHandler (HandleCreatedEvent, value); }
6883 remove { Events.RemoveHandler (HandleCreatedEvent, value); }
6886 [EditorBrowsable(EditorBrowsableState.Advanced)]
6888 public event EventHandler HandleDestroyed {
6889 add { Events.AddHandler (HandleDestroyedEvent, value); }
6890 remove { Events.RemoveHandler (HandleDestroyedEvent, value); }
6893 public event HelpEventHandler HelpRequested {
6894 add { Events.AddHandler (HelpRequestedEvent, value); }
6895 remove { Events.RemoveHandler (HelpRequestedEvent, value); }
6898 public event EventHandler ImeModeChanged {
6899 add { Events.AddHandler (ImeModeChangedEvent, value); }
6900 remove { Events.RemoveHandler (ImeModeChangedEvent, value); }
6903 [EditorBrowsable(EditorBrowsableState.Advanced)]
6905 public event InvalidateEventHandler Invalidated {
6906 add { Events.AddHandler (InvalidatedEvent, value); }
6907 remove { Events.RemoveHandler (InvalidatedEvent, value); }
6910 public event KeyEventHandler KeyDown {
6911 add { Events.AddHandler (KeyDownEvent, value); }
6912 remove { Events.RemoveHandler (KeyDownEvent, value); }
6915 public event KeyPressEventHandler KeyPress {
6916 add { Events.AddHandler (KeyPressEvent, value); }
6917 remove { Events.RemoveHandler (KeyPressEvent, value); }
6920 public event KeyEventHandler KeyUp {
6921 add { Events.AddHandler (KeyUpEvent, value); }
6922 remove { Events.RemoveHandler (KeyUpEvent, value); }
6925 public event LayoutEventHandler Layout {
6926 add { Events.AddHandler (LayoutEvent, value); }
6927 remove { Events.RemoveHandler (LayoutEvent, value); }
6930 public event EventHandler Leave {
6931 add { Events.AddHandler (LeaveEvent, value); }
6932 remove { Events.RemoveHandler (LeaveEvent, value); }
6935 public event EventHandler LocationChanged {
6936 add { Events.AddHandler (LocationChangedEvent, value); }
6937 remove { Events.RemoveHandler (LocationChangedEvent, value); }
6940 [EditorBrowsable(EditorBrowsableState.Advanced)]
6942 public event EventHandler LostFocus {
6943 add { Events.AddHandler (LostFocusEvent, value); }
6944 remove { Events.RemoveHandler (LostFocusEvent, value); }
6948 public event EventHandler MarginChanged {
6949 add { Events.AddHandler (MarginChangedEvent, value); }
6950 remove {Events.RemoveHandler (MarginChangedEvent, value); }
6954 public event EventHandler MouseCaptureChanged {
6956 internal event EventHandler MouseCaptureChanged {
6958 add { Events.AddHandler (MouseCaptureChangedEvent, value); }
6959 remove { Events.RemoveHandler (MouseCaptureChangedEvent, value); }
6962 public event MouseEventHandler MouseClick
6964 add { Events.AddHandler (MouseClickEvent, value); }
6965 remove { Events.RemoveHandler (MouseClickEvent, value); }
6967 public event MouseEventHandler MouseDoubleClick
6969 add { Events.AddHandler (MouseDoubleClickEvent, value); }
6970 remove { Events.RemoveHandler (MouseDoubleClickEvent, value); }
6973 public event MouseEventHandler MouseDown {
6974 add { Events.AddHandler (MouseDownEvent, value); }
6975 remove { Events.RemoveHandler (MouseDownEvent, value); }
6978 public event EventHandler MouseEnter {
6979 add { Events.AddHandler (MouseEnterEvent, value); }
6980 remove { Events.RemoveHandler (MouseEnterEvent, value); }
6983 public event EventHandler MouseHover {
6984 add { Events.AddHandler (MouseHoverEvent, value); }
6985 remove { Events.RemoveHandler (MouseHoverEvent, value); }
6988 public event EventHandler MouseLeave {
6989 add { Events.AddHandler (MouseLeaveEvent, value); }
6990 remove { Events.RemoveHandler (MouseLeaveEvent, value); }
6993 public event MouseEventHandler MouseMove {
6994 add { Events.AddHandler (MouseMoveEvent, value); }
6995 remove { Events.RemoveHandler (MouseMoveEvent, value); }
6998 public event MouseEventHandler MouseUp {
6999 add { Events.AddHandler (MouseUpEvent, value); }
7000 remove { Events.RemoveHandler (MouseUpEvent, value); }
7003 [EditorBrowsable(EditorBrowsableState.Advanced)]
7005 public event MouseEventHandler MouseWheel {
7006 add { Events.AddHandler (MouseWheelEvent, value); }
7007 remove { Events.RemoveHandler (MouseWheelEvent, value); }
7010 public event EventHandler Move {
7011 add { Events.AddHandler (MoveEvent, value); }
7012 remove { Events.RemoveHandler (MoveEvent, value); }
7015 public event EventHandler PaddingChanged
7017 add { Events.AddHandler (PaddingChangedEvent, value); }
7018 remove { Events.RemoveHandler (PaddingChangedEvent, value); }
7021 public event PaintEventHandler Paint {
7022 add { Events.AddHandler (PaintEvent, value); }
7023 remove { Events.RemoveHandler (PaintEvent, value); }
7026 public event EventHandler ParentChanged {
7027 add { Events.AddHandler (ParentChangedEvent, value); }
7028 remove { Events.RemoveHandler (ParentChangedEvent, value); }
7032 public event PreviewKeyDownEventHandler PreviewKeyDown {
7033 add { Events.AddHandler (PreviewKeyDownEvent, value); }
7034 remove { Events.RemoveHandler (PreviewKeyDownEvent, value); }
7038 public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp {
7039 add { Events.AddHandler (QueryAccessibilityHelpEvent, value); }
7040 remove { Events.RemoveHandler (QueryAccessibilityHelpEvent, value); }
7043 public event QueryContinueDragEventHandler QueryContinueDrag {
7044 add { Events.AddHandler (QueryContinueDragEvent, value); }
7045 remove { Events.RemoveHandler (QueryContinueDragEvent, value); }
7049 public event EventHandler RegionChanged {
7050 add { Events.AddHandler (RegionChangedEvent, value); }
7051 remove { Events.RemoveHandler (RegionChangedEvent, value); }
7056 [EditorBrowsable (EditorBrowsableState.Advanced)]
7058 public event EventHandler Resize {
7059 add { Events.AddHandler (ResizeEvent, value); }
7060 remove { Events.RemoveHandler (ResizeEvent, value); }
7063 public event EventHandler RightToLeftChanged {
7064 add { Events.AddHandler (RightToLeftChangedEvent, value); }
7065 remove { Events.RemoveHandler (RightToLeftChangedEvent, value); }
7068 public event EventHandler SizeChanged {
7069 add { Events.AddHandler (SizeChangedEvent, value); }
7070 remove { Events.RemoveHandler (SizeChangedEvent, value); }
7073 public event EventHandler StyleChanged {
7074 add { Events.AddHandler (StyleChangedEvent, value); }
7075 remove { Events.RemoveHandler (StyleChangedEvent, value); }
7078 public event EventHandler SystemColorsChanged {
7079 add { Events.AddHandler (SystemColorsChangedEvent, value); }
7080 remove { Events.RemoveHandler (SystemColorsChangedEvent, value); }
7083 public event EventHandler TabIndexChanged {
7084 add { Events.AddHandler (TabIndexChangedEvent, value); }
7085 remove { Events.RemoveHandler (TabIndexChangedEvent, value); }
7088 public event EventHandler TabStopChanged {
7089 add { Events.AddHandler (TabStopChangedEvent, value); }
7090 remove { Events.RemoveHandler (TabStopChangedEvent, value); }
7093 public event EventHandler TextChanged {
7094 add { Events.AddHandler (TextChangedEvent, value); }
7095 remove { Events.RemoveHandler (TextChangedEvent, value); }
7098 public event EventHandler Validated {
7099 add { Events.AddHandler (ValidatedEvent, value); }
7100 remove { Events.RemoveHandler (ValidatedEvent, value); }
7103 public event CancelEventHandler Validating {
7104 add { Events.AddHandler (ValidatingEvent, value); }
7105 remove { Events.RemoveHandler (ValidatingEvent, value); }
7108 public event EventHandler VisibleChanged {
7109 add { Events.AddHandler (VisibleChangedEvent, value); }
7110 remove { Events.RemoveHandler (VisibleChangedEvent, value); }
7113 #endregion // Events