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
39 using System.ComponentModel;
40 using System.ComponentModel.Design;
41 using System.ComponentModel.Design.Serialization;
42 using System.Collections;
43 using System.Diagnostics;
45 using System.Drawing.Drawing2D;
46 using System.Reflection;
47 using System.Runtime.InteropServices;
48 using System.Security;
49 using System.Threading;
51 namespace System.Windows.Forms
55 [ClassInterface (ClassInterfaceType.AutoDispatch)]
57 [Designer("System.Windows.Forms.Design.ControlDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
58 [DefaultProperty("Text")]
59 [DefaultEvent("Click")]
60 [DesignerSerializer("System.Windows.Forms.Design.ControlCodeDomSerializer, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
61 [ToolboxItemFilter("System.Windows.Forms")]
62 public class Control : Component, ISynchronizeInvoke, IWin32Window
64 #region Local Variables
67 internal Rectangle bounds; // bounding rectangle for control (client area + decorations)
68 Rectangle explicit_bounds; // explicitly set bounds
69 internal object creator_thread; // thread that created the control
70 internal ControlNativeWindow window; // object for native window handle
71 string name; // for object naming
74 bool is_created; // true if OnCreateControl has been sent
75 internal bool has_focus; // true if control has focus
76 internal bool is_visible; // true if control is visible
77 internal bool is_entered; // is the mouse inside the control?
78 internal bool is_enabled; // true if control is enabled (usable/not grayed out)
79 bool is_accessible; // true if the control is visible to accessibility applications
80 bool is_captured; // tracks if the control has captured the mouse
81 internal bool is_toplevel; // tracks if the control is a toplevel window
82 bool is_recreating; // tracks if the handle for the control is being recreated
83 bool causes_validation; // tracks if validation is executed on changes
84 bool is_focusing; // tracks if Focus has been called on the control and has not yet finished
85 int tab_index; // position in tab order of siblings
86 bool tab_stop; // is the control a tab stop?
87 bool is_disposed; // has the window already been disposed?
88 Size client_size; // size of the client area (window excluding decorations)
89 Rectangle client_rect; // rectangle with the client area (window excluding decorations)
90 ControlStyles control_style; // rather win32-specific, style bits for control
92 bool layout_pending; // true if our parent needs to re-layout us
93 object control_tag; // object that contains data about our control
94 internal int mouse_clicks; // Counter for mouse clicks
95 Cursor cursor; // Cursor for the window
96 internal bool allow_drop; // true if the control accepts droping objects on it
97 Region clip_region; // User-specified clip region for the window
100 internal Color foreground_color; // foreground color for control
101 internal Color background_color; // background color for control
102 Image background_image; // background image for control
103 internal Font font; // font for control
104 string text; // window/title text for control
105 internal BorderStyle border_style; // Border style of control
108 int layout_suspended;
109 internal AnchorStyles anchor_style; // anchoring requirements for our control
110 internal DockStyle dock_style; // docking requirements for our control (supercedes anchoring)
111 // Please leave the next 4 as internal until DefaultLayout (2.0) is rewritten
112 internal int dist_left; // distance to the left border of the parent
113 internal int dist_top; // distance to the top border of the parent
114 internal int dist_right; // distance to the right border of the parent
115 internal int dist_bottom; // distance to the bottom border of the parent
117 // to be categorized...
118 ControlCollection child_controls; // our children
119 Control parent; // our parent control
120 AccessibleObject accessibility_object; // object that contains accessibility information about our control
121 BindingContext binding_context;
122 RightToLeft right_to_left; // drawing direction for control
123 ContextMenu context_menu; // Context menu associated with the control
126 Graphics backbuffer_dc;
128 Region invalid_region;
130 ControlBindingsCollection data_bindings;
133 internal bool use_compatible_text_rendering;
134 static bool verify_thread_handle;
140 Layout.LayoutEngine layout_engine;
143 #endregion // Local Variables
145 #region Private Classes
146 // This helper class allows us to dispatch messages to Control.WndProc
147 internal class ControlNativeWindow : NativeWindow {
148 private Control owner;
150 public ControlNativeWindow(Control control) : base() {
155 public Control Owner {
161 static internal Control ControlFromHandle(IntPtr hWnd) {
162 ControlNativeWindow window;
164 window = (ControlNativeWindow)window_collection[hWnd];
165 if (window != null) {
172 static internal Control ControlFromChildHandle (IntPtr handle) {
173 ControlNativeWindow window;
175 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
176 while (hwnd != null) {
177 window = (ControlNativeWindow)window_collection[hwnd.Handle];
178 if (window != null) {
187 protected override void WndProc(ref Message m) {
188 owner.WndProc(ref m);
193 #region Public Classes
195 public class ControlAccessibleObject : AccessibleObject {
198 #region ControlAccessibleObject Constructors
199 public ControlAccessibleObject(Control ownerControl)
200 : base (ownerControl)
202 this.owner = ownerControl;
204 #endregion // ControlAccessibleObject Constructors
206 #region ControlAccessibleObject Public Instance Properties
207 public override string DefaultAction {
209 return base.DefaultAction;
213 public override string Description {
215 return base.Description;
219 public IntPtr Handle {
225 // We don't want to let them set it
229 public override string Help {
235 public override string KeyboardShortcut {
237 return base.KeyboardShortcut;
241 public override string Name {
251 public Control Owner {
257 public override AccessibleObject Parent {
264 public override AccessibleRole Role {
269 #endregion // ControlAccessibleObject Public Instance Properties
271 #region ControlAccessibleObject Public Instance Methods
272 public override int GetHelpTopic(out string FileName) {
273 return base.GetHelpTopic (out FileName);
276 [MonoTODO("Implement this and tie it into Control.AccessibilityNotifyClients")]
277 public void NotifyClients(AccessibleEvents accEvent) {
278 throw new NotImplementedException();
281 [MonoTODO("Implement this and tie it into Control.AccessibilityNotifyClients")]
282 public void NotifyClients(AccessibleEvents accEvent, int childID) {
283 throw new NotImplementedException();
286 public override string ToString() {
287 return "ControlAccessibleObject: Owner = " + owner.ToString() + ", Text: " + owner.text;
290 #endregion // ControlAccessibleObject Public Instance Methods
296 [DesignerSerializer("System.Windows.Forms.Design.ControlCollectionCodeDomSerializer, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
298 [ListBindable(false)]
299 public class ControlCollection : IList, ICollection, ICloneable, IEnumerable {
300 #region ControlCollection Local Variables
303 Control[] all_controls;
305 #endregion // ControlCollection Local Variables
307 #region ControlCollection Public Constructor
308 public ControlCollection(Control owner) {
310 this.list=new ArrayList();
314 #region ControlCollection Public Instance Properties
321 public bool IsReadOnly {
323 return list.IsReadOnly;
327 public virtual Control this[int index] {
329 if (index < 0 || index >= list.Count) {
330 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
332 return (Control)list[index];
335 #endregion // ControlCollection Public Instance Properties
337 #region ControlCollection Private Instance Methods
338 public virtual void Add (Control value)
343 if (Contains (value)) {
344 owner.PerformLayout();
348 if (value.tab_index == -1) {
354 end = owner.child_controls.Count;
355 for (int i = 0; i < end; i++) {
356 index = owner.child_controls[i].tab_index;
361 value.tab_index = use;
364 if (value.parent != null) {
365 value.parent.Controls.Remove(value);
371 value.ChangeParent(owner);
375 owner.UpdateChildrenZOrder();
376 owner.PerformLayout(value, "Parent");
377 owner.OnControlAdded(new ControlEventArgs(value));
380 internal void AddToList (Control c)
386 internal virtual void AddImplicit (Control control)
388 if (impl_list == null)
389 impl_list = new ArrayList ();
391 if (AllContains (control))
395 impl_list.Add (control);
397 control.ChangeParent (owner);
398 control.InitLayout ();
399 owner.UpdateChildrenZOrder ();
400 owner.PerformLayout (control, "Parent");
401 owner.OnControlAdded (new ControlEventArgs (control));
404 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
406 public virtual void AddRange (Control[] controls)
408 if (controls == null)
409 throw new ArgumentNullException ("controls");
411 owner.SuspendLayout ();
414 for (int i = 0; i < controls.Length; i++)
417 owner.ResumeLayout ();
421 internal virtual void AddRangeImplicit (Control [] controls)
423 if (controls == null)
424 throw new ArgumentNullException ("controls");
426 owner.SuspendLayout ();
429 for (int i = 0; i < controls.Length; i++)
430 AddImplicit (controls [i]);
432 owner.ResumeLayout ();
436 public virtual void Clear ()
440 // MS sends remove events in reverse order
441 while (list.Count > 0) {
442 Remove((Control)list[list.Count - 1]);
446 internal virtual void ClearImplicit ()
448 if (impl_list == null)
454 public bool Contains (Control value)
456 for (int i = list.Count; i > 0; ) {
459 if (list [i] == value) {
460 // Do we need to do anything here?
467 internal bool ImplicitContains (Control value)
469 if (impl_list == null)
472 for (int i = impl_list.Count; i > 0; ) {
475 if (impl_list [i] == value) {
476 // Do we need to do anything here?
483 internal bool AllContains (Control value)
485 return Contains (value) || ImplicitContains (value);
488 public void CopyTo (Array array, int index)
490 list.CopyTo(array, index);
493 public override bool Equals(object other) {
494 if (other is ControlCollection && (((ControlCollection)other).owner==this.owner)) {
501 public int GetChildIndex(Control child) {
502 return GetChildIndex(child, false);
505 public int GetChildIndex(Control child, bool throwException) {
508 index=list.IndexOf(child);
510 if (index==-1 && throwException) {
511 throw new ArgumentException("Not a child control", "child");
516 public IEnumerator GetEnumerator() {
517 return list.GetEnumerator();
520 internal IEnumerator GetAllEnumerator ()
522 Control [] res = GetAllControls ();
523 return res.GetEnumerator ();
526 internal Control [] GetAllControls ()
528 if (all_controls != null)
531 if (impl_list == null) {
532 all_controls = (Control []) list.ToArray (typeof (Control));
536 all_controls = new Control [list.Count + impl_list.Count];
537 impl_list.CopyTo (all_controls);
538 list.CopyTo (all_controls, impl_list.Count);
543 public override int GetHashCode() {
544 return base.GetHashCode();
547 public int IndexOf(Control control) {
548 return list.IndexOf(control);
551 public virtual void Remove(Control value) {
555 owner.PerformLayout(value, "Parent");
556 owner.OnControlRemoved(new ControlEventArgs(value));
561 value.ChangeParent(null);
563 owner.UpdateChildrenZOrder();
566 internal virtual void RemoveImplicit (Control control)
568 if (impl_list != null) {
570 owner.PerformLayout (control, "Parent");
571 owner.OnControlRemoved (new ControlEventArgs (control));
572 impl_list.Remove (control);
574 control.ChangeParent (null);
575 owner.UpdateChildrenZOrder ();
578 public void RemoveAt(int index) {
579 if (index < 0 || index >= list.Count) {
580 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
582 Remove ((Control)list[index]);
585 public void SetChildIndex(Control child, int newIndex) {
587 throw new ArgumentNullException ("child");
591 old_index=list.IndexOf(child);
593 throw new ArgumentException("Not a child control", "child");
596 if (old_index==newIndex) {
601 list.RemoveAt(old_index);
603 if (newIndex>list.Count) {
606 list.Insert(newIndex, child);
608 child.UpdateZOrder();
609 owner.PerformLayout();
611 #endregion // ControlCollection Private Instance Methods
613 #region ControlCollection Interface Properties
614 object IList.this[int index] {
616 if (index<0 || index>=list.Count) {
617 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
623 if (!(value is Control)) {
624 throw new ArgumentException("Object of type Control required", "value");
628 Control ctrl = (Control) value;
631 ctrl.ChangeParent(owner);
635 owner.UpdateChildrenZOrder();
636 owner.PerformLayout(ctrl, "Parent");
640 bool IList.IsFixedSize {
646 bool ICollection.IsSynchronized {
648 return list.IsSynchronized;
652 object ICollection.SyncRoot {
654 return list.SyncRoot;
657 #endregion // ControlCollection Interface Properties
659 #region ControlCollection Interface Methods
660 int IList.Add(object value) {
662 throw new ArgumentNullException("value", "Cannot add null controls");
665 if (!(value is Control)) {
666 throw new ArgumentException("Object of type Control required", "value");
669 return list.Add(value);
672 bool IList.Contains(object value) {
673 if (!(value is Control)) {
674 throw new ArgumentException("Object of type Control required", "value");
677 return this.Contains((Control) value);
680 int IList.IndexOf(object value) {
681 if (!(value is Control)) {
682 throw new ArgumentException("Object of type Control required", "value");
685 return this.IndexOf((Control) value);
688 void IList.Insert(int index, object value) {
689 if (!(value is Control)) {
690 throw new ArgumentException("Object of type Control required", "value");
693 list.Insert(index, value);
696 void IList.Remove(object value) {
697 if (!(value is Control)) {
698 throw new ArgumentException("Object of type Control required", "value");
704 Object ICloneable.Clone() {
705 ControlCollection clone = new ControlCollection(this.owner);
706 clone.list=(ArrayList)list.Clone(); // FIXME: Do we need this?
709 #endregion // ControlCollection Interface Methods
711 #endregion // ControlCollection Class
713 #region Public Constructors
716 anchor_style = AnchorStyles.Top | AnchorStyles.Left;
724 layout_pending = false;
726 causes_validation = true;
728 layout_suspended = 0;
732 right_to_left = RightToLeft.Inherit;
733 border_style = BorderStyle.None;
734 background_color = Color.Empty;
740 ime_mode = ImeMode.Inherit;
743 use_compatible_text_rendering = Application.use_compatible_text_rendering;
744 padding = new Padding(0);
745 maximum_size = new Size();
746 minimum_size = new Size();
747 preferred_size = new Size();
748 margin = this.DefaultMargin;
749 layout_engine = this.LayoutEngine;
752 control_style = ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint |
753 ControlStyles.Selectable | ControlStyles.StandardClick |
754 ControlStyles.StandardDoubleClick;
756 control_style |= ControlStyles.UseTextForAccessibility;
760 background_image = null;
764 window = new ControlNativeWindow(this);
765 child_controls = CreateControlsInstance();
766 client_size = new Size(DefaultSize.Width, DefaultSize.Height);
767 client_rect = new Rectangle(0, 0, DefaultSize.Width, DefaultSize.Height);
768 XplatUI.CalculateWindowRect(ref client_rect, CreateParams.Style, CreateParams.ExStyle, null, out bounds);
769 if ((CreateParams.Style & (int)WindowStyles.WS_CHILD) == 0) {
775 public Control(Control parent, string text) : this() {
780 public Control(Control parent, string text, int left, int top, int width, int height) : this() {
785 bounds.Height=height;
786 SetBounds(left, top, width, height, BoundsSpecified.All);
790 public Control(string text) : this() {
794 public Control(string text, int left, int top, int width, int height) : this() {
798 bounds.Height=height;
799 SetBounds(left, top, width, height, BoundsSpecified.All);
803 private delegate void RemoveDelegate(object c);
805 protected override void Dispose(bool disposing) {
806 if (!is_disposed && disposing) {
809 DisposeBackBuffer ();
811 if (invalid_region!=null) {
812 invalid_region.Dispose();
815 if (this.InvokeRequired) {
816 if (Application.MessageLoop) {
817 this.BeginInvokeInternal(new MethodInvoker(DestroyHandle), null, true);
823 if (parent != null) {
824 parent.Controls.Remove(this);
827 Control [] children = child_controls.GetAllControls ();
828 for (int i=0; i<children.Length; i++) {
829 children[i].parent = null; // Need to set to null or our child will try and remove from ourselves and crash
830 children[i].Dispose();
835 base.Dispose(disposing);
837 #endregion // Public Constructors
839 #region Internal Properties
840 internal BorderStyle InternalBorderStyle {
846 if (!Enum.IsDefined (typeof (BorderStyle), value))
847 throw new InvalidEnumArgumentException (string.Format("Enum argument value '{0}' is not valid for BorderStyle", value));
849 if (border_style != value) {
850 border_style = value;
852 if (IsHandleCreated) {
853 XplatUI.SetBorderStyle(window.Handle, (FormBorderStyle)border_style);
859 #endregion // Internal Properties
861 #region Private & Internal Methods
862 internal IAsyncResult BeginInvokeInternal (Delegate method, object [] args, bool disposing) {
863 AsyncMethodResult result;
864 AsyncMethodData data;
869 if (!p.IsHandleCreated) {
870 throw new InvalidOperationException("Cannot call Invoke or InvokeAsync on a control until the window handle is created");
876 result = new AsyncMethodResult ();
877 data = new AsyncMethodData ();
879 data.Handle = window.Handle;
880 data.Method = method;
882 data.Result = result;
885 if (!ExecutionContext.IsFlowSuppressed ()) {
886 data.Context = ExecutionContext.Capture ();
889 #if !MWF_ON_MSRUNTIME
890 if (SecurityManager.SecurityEnabled) {
891 data.Stack = CompressedStack.GetCompressedStack ();
896 XplatUI.SendAsyncMethod (data);
901 internal void PointToClient (ref int x, ref int y)
903 XplatUI.ScreenToClient (Handle, ref x, ref y);
906 internal void PointToScreen (ref int x, ref int y)
908 XplatUI.ClientToScreen (Handle, ref x, ref y);
911 internal bool IsRecreating {
913 return is_recreating;
917 internal Graphics DeviceContext {
918 get { return Hwnd.bmp_g; }
921 private void InvalidateBackBuffer ()
923 if (invalid_region != null)
924 invalid_region.Dispose();
925 invalid_region = new Region (ClientRectangle);
928 private void CreateBackBuffer ()
930 if (backbuffer != null)
936 if (width < 1) width = 1;
937 if (height < 1) height = 1;
939 XplatUI.CreateOffscreenDrawable (Handle, width, height, out backbuffer, out backbuffer_dc);
940 InvalidateBackBuffer ();
943 private void DisposeBackBuffer ()
945 if (backbuffer == null)
948 XplatUI.DestroyOffscreenDrawable (backbuffer, backbuffer_dc);
950 backbuffer_dc = null;
953 if (invalid_region != null)
954 invalid_region.Dispose ();
955 invalid_region = null;
958 internal static void SetChildColor(Control parent) {
961 for (int i=0; i < parent.child_controls.Count; i++) {
962 child=parent.child_controls[i];
963 if (child.child_controls.Count>0) {
964 SetChildColor(child);
969 internal bool Select(Control control) {
970 IContainerControl container;
972 if (control == null) {
976 container = GetContainerControl();
977 if (container != null) {
978 container.ActiveControl = control;
980 if (control.IsHandleCreated) {
981 XplatUI.SetFocus(control.window.Handle);
986 internal void SelectChild (Control control)
988 if (control.IsHandleCreated)
989 XplatUI.SetFocus (control.window.Handle);
992 internal virtual void DoDefaultAction() {
993 // Only here to be overriden by our actual controls; this is needed by the accessibility class
996 internal static IntPtr MakeParam (int low, int high){
997 return new IntPtr (high << 16 | low & 0xffff);
1000 internal static int LowOrder (int param) {
1001 return ((int)(short)(param & 0xffff));
1004 internal static int HighOrder (int param) {
1005 return ((int)(short)(param >> 16));
1008 // This method exists so controls overriding OnPaintBackground can have default background painting done
1009 internal virtual void PaintControlBackground (PaintEventArgs pevent)
1011 if (GetStyle(ControlStyles.SupportsTransparentBackColor) && (BackColor.A != 0xff)) {
1012 if (parent != null) {
1013 PaintEventArgs parent_pe;
1014 GraphicsState state;
1016 parent_pe = new PaintEventArgs(pevent.Graphics, new Rectangle(pevent.ClipRectangle.X + Left, pevent.ClipRectangle.Y + Top, pevent.ClipRectangle.Width, pevent.ClipRectangle.Height));
1018 state = parent_pe.Graphics.Save();
1019 parent_pe.Graphics.TranslateTransform(-Left, -Top);
1020 parent.OnPaintBackground(parent_pe);
1021 parent_pe.Graphics.Restore(state);
1023 state = parent_pe.Graphics.Save();
1024 parent_pe.Graphics.TranslateTransform(-Left, -Top);
1025 parent.OnPaint(parent_pe);
1026 parent_pe.Graphics.Restore(state);
1027 parent_pe.SetGraphics(null);
1031 if ((clip_region != null) && (XplatUI.UserClipWontExposeParent)) {
1032 if (parent != null) {
1033 PaintEventArgs parent_pe;
1035 GraphicsState state;
1038 hwnd = Hwnd.ObjectFromHandle(Handle);
1041 parent_pe = new PaintEventArgs(pevent.Graphics, new Rectangle(pevent.ClipRectangle.X + Left, pevent.ClipRectangle.Y + Top, pevent.ClipRectangle.Width, pevent.ClipRectangle.Height));
1043 region = new Region ();
1045 region.Union(ClientRectangle);
1047 foreach (Rectangle r in hwnd.ClipRectangles) {
1051 state = parent_pe.Graphics.Save();
1052 parent_pe.Graphics.Clip = region;
1054 parent_pe.Graphics.TranslateTransform(-Left, -Top);
1055 parent.OnPaintBackground(parent_pe);
1056 parent_pe.Graphics.Restore(state);
1058 state = parent_pe.Graphics.Save();
1059 parent_pe.Graphics.Clip = region;
1061 parent_pe.Graphics.TranslateTransform(-Left, -Top);
1062 parent.OnPaint(parent_pe);
1063 parent_pe.Graphics.Restore(state);
1064 parent_pe.SetGraphics(null);
1066 region.Intersect(clip_region);
1067 pevent.Graphics.Clip = region;
1072 if (background_image == null) {
1073 pevent.Graphics.FillRectangle(ThemeEngine.Current.ResPool.GetSolidBrush(BackColor), new Rectangle(pevent.ClipRectangle.X - 1, pevent.ClipRectangle.Y - 1, pevent.ClipRectangle.Width + 2, pevent.ClipRectangle.Height + 2));
1077 DrawBackgroundImage (pevent.Graphics);
1080 void DrawBackgroundImage (Graphics g)
1082 using (TextureBrush b = new TextureBrush (background_image, WrapMode.Tile)) {
1083 g.FillRectangle (b, ClientRectangle);
1087 internal virtual void DndEnter (DragEventArgs e)
1094 internal virtual void DndOver (DragEventArgs e)
1101 internal virtual void DndDrop (DragEventArgs e)
1105 } catch (Exception exc) {
1106 Console.Error.WriteLine ("MWF: Exception while dropping:");
1107 Console.Error.WriteLine (exc);
1111 internal virtual void DndLeave (EventArgs e)
1118 internal virtual void DndFeedback(GiveFeedbackEventArgs e)
1125 internal virtual void DndContinueDrag(QueryContinueDragEventArgs e)
1128 OnQueryContinueDrag(e);
1132 internal static MouseButtons FromParamToMouseButtons (int param) {
1133 MouseButtons buttons = MouseButtons.None;
1135 if ((param & (int) MsgButtons.MK_LBUTTON) != 0)
1136 buttons |= MouseButtons.Left;
1138 if ((param & (int) MsgButtons.MK_MBUTTON) != 0)
1139 buttons |= MouseButtons.Middle;
1141 if ((param & (int) MsgButtons.MK_RBUTTON) != 0)
1142 buttons |= MouseButtons.Right;
1148 internal void FireEnter ()
1150 OnEnter (EventArgs.Empty);
1153 internal void FireLeave ()
1155 OnLeave (EventArgs.Empty);
1158 internal void FireValidating (CancelEventArgs ce)
1163 internal void FireValidated ()
1165 OnValidated (EventArgs.Empty);
1168 internal virtual bool ProcessControlMnemonic(char charCode) {
1169 return ProcessMnemonic(charCode);
1172 private static Control FindFlatForward(Control container, Control start) {
1178 end = container.child_controls.Count;
1180 if (start != null) {
1181 index = start.tab_index;
1186 for (int i = 0, pos = -1; i < end; i++) {
1187 if (start == container.child_controls[i]) {
1192 if (found == null) {
1193 if (container.child_controls[i].tab_index > index || (pos > -1 && pos < i && container.child_controls[i].tab_index == index)) {
1194 found = container.child_controls[i];
1196 } else if (found.tab_index > container.child_controls[i].tab_index) {
1197 if (container.child_controls[i].tab_index > index) {
1198 found = container.child_controls[i];
1205 private static Control FindControlForward(Control container, Control start) {
1210 if (start == null) {
1211 return FindFlatForward(container, start);
1214 if (start.child_controls != null && start.child_controls.Count > 0 &&
1215 (start == container || !((start is IContainerControl) && start.GetStyle(ControlStyles.ContainerControl)))) {
1216 return FindControlForward(start, null);
1219 while (start != container) {
1220 found = FindFlatForward(start.parent, start);
1221 if (found != null) {
1224 start = start.parent;
1230 private static Control FindFlatBackward(Control container, Control start) {
1236 end = container.child_controls.Count;
1238 if (start != null) {
1239 index = start.tab_index;
1241 // FIXME: Possible speed-up: Keep the highest taborder index in the container
1243 for (int i = 0; i < end; i++) {
1244 if (container.child_controls[i].tab_index > index) {
1245 index = container.child_controls[i].tab_index;
1253 for (int i = end - 1; i >= 0; i--) {
1254 if (start == container.child_controls[i]) {
1259 if (found == null || found.tab_index < container.child_controls[i].tab_index) {
1260 if (container.child_controls[i].tab_index < index || (hit && container.child_controls[i].tab_index == index))
1261 found = container.child_controls[i];
1268 private static Control FindControlBackward(Control container, Control start) {
1270 Control found = null;
1272 if (start == null) {
1273 found = FindFlatBackward(container, start);
1275 else if (start != container) {
1276 if (start.parent != null) {
1277 found = FindFlatBackward(start.parent, start);
1279 if (found == null) {
1280 if (start.parent != container)
1281 return start.parent;
1287 if (found == null || start.parent == null)
1290 while (found != null && (found == container || (!((found is IContainerControl) && found.GetStyle(ControlStyles.ContainerControl))) &&
1291 found.child_controls != null && found.child_controls.Count > 0)) {
1292 // while (ctl.child_controls != null && ctl.child_controls.Count > 0 &&
1293 // (ctl == this || (!((ctl is IContainerControl) && ctl.GetStyle(ControlStyles.ContainerControl))))) {
1294 found = FindFlatBackward(found, null);
1304 if (start != null) {
1305 found = FindFlatBackward(start.parent, start);
1306 if (found == null) {
1307 if (start.parent != container) {
1308 return start.parent;
1312 if (found == null) {
1313 found = FindFlatBackward(container, start);
1316 if (container != start) {
1317 while ((found != null) && (!found.Contains(start)) && found.child_controls != null && found.child_controls.Count > 0 && !(found is IContainerControl)) {// || found.GetStyle(ControlStyles.ContainerControl))) {
1318 found = FindControlBackward(found, null);
1319 if (found != null) {
1328 internal virtual void HandleClick(int clicks, MouseEventArgs me) {
1329 if (GetStyle(ControlStyles.StandardClick)) {
1330 if ((clicks > 1) && GetStyle(ControlStyles.StandardDoubleClick)) {
1332 OnDoubleClick(EventArgs.Empty);
1334 OnClick(EventArgs.Empty);
1344 private void CheckDataBindings ()
1346 if (data_bindings == null)
1349 BindingContext binding_context = BindingContext;
1350 foreach (Binding binding in data_bindings) {
1351 binding.Check (binding_context);
1355 private void ChangeParent(Control new_parent) {
1359 Color pre_fore_color;
1360 Color pre_back_color;
1361 RightToLeft pre_rtl;
1363 // These properties are inherited from our parent
1364 // Get them pre parent-change and then send events
1365 // if they are changed after we have our new parent
1366 pre_enabled = Enabled;
1367 pre_visible = Visible;
1369 pre_fore_color = ForeColor;
1370 pre_back_color = BackColor;
1371 pre_rtl = RightToLeft;
1372 // MS doesn't seem to send a CursorChangedEvent
1374 parent = new_parent;
1376 if (IsHandleCreated)
1377 XplatUI.SetParent(Handle,
1378 (new_parent == null || !new_parent.IsHandleCreated) ? IntPtr.Zero : new_parent.Handle);
1380 OnParentChanged(EventArgs.Empty);
1382 if (pre_enabled != Enabled) {
1383 OnEnabledChanged(EventArgs.Empty);
1386 if (pre_visible != Visible) {
1387 OnVisibleChanged(EventArgs.Empty);
1390 if (pre_font != Font) {
1391 OnFontChanged(EventArgs.Empty);
1394 if (pre_fore_color != ForeColor) {
1395 OnForeColorChanged(EventArgs.Empty);
1398 if (pre_back_color != BackColor) {
1399 OnBackColorChanged(EventArgs.Empty);
1402 if (pre_rtl != RightToLeft) {
1403 // MS sneaks a OnCreateControl and OnHandleCreated in here, I guess
1404 // because when RTL changes they have to recreate the win32 control
1405 // We don't really need that (until someone runs into compatibility issues)
1406 OnRightToLeftChanged(EventArgs.Empty);
1409 if ((new_parent != null) && new_parent.Created && !Created) {
1413 if ((binding_context == null) && Created) {
1414 OnBindingContextChanged(EventArgs.Empty);
1418 private void UpdateDistances() {
1419 if ((parent != null) && (parent.layout_suspended == 0)) {
1420 dist_left = bounds.X;
1421 dist_top = bounds.Y;
1422 dist_right = parent.ClientSize.Width - bounds.X - bounds.Width;
1423 dist_bottom = parent.ClientSize.Height - bounds.Y - bounds.Height;
1426 #endregion // Private & Internal Methods
1428 #region Public Static Properties
1429 public static Color DefaultBackColor {
1431 return ThemeEngine.Current.DefaultControlBackColor;
1435 public static Font DefaultFont {
1437 return ThemeEngine.Current.DefaultFont;
1441 public static Color DefaultForeColor {
1443 return ThemeEngine.Current.DefaultControlForeColor;
1447 public static Keys ModifierKeys {
1449 return XplatUI.State.ModifierKeys;
1453 public static MouseButtons MouseButtons {
1455 return XplatUI.State.MouseButtons;
1459 public static Point MousePosition {
1461 return Cursor.Position;
1466 [EditorBrowsable (EditorBrowsableState.Advanced)]
1467 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
1470 public static bool CheckForIllegalCrossThreadCalls
1473 return verify_thread_handle;
1477 verify_thread_handle = value;
1481 #endregion // Public Static Properties
1483 #region Public Instance Properties
1484 [EditorBrowsable(EditorBrowsableState.Advanced)]
1486 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1487 public AccessibleObject AccessibilityObject {
1489 if (accessibility_object==null) {
1490 accessibility_object=CreateAccessibilityInstance();
1492 return accessibility_object;
1496 [EditorBrowsable(EditorBrowsableState.Advanced)]
1498 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1499 public string AccessibleDefaultActionDescription {
1501 return AccessibilityObject.default_action;
1505 AccessibilityObject.default_action=value;
1510 [DefaultValue(null)]
1511 [MWFCategory("Accessibility")]
1512 public string AccessibleDescription {
1514 return AccessibilityObject.description;
1518 AccessibilityObject.description=value;
1523 [DefaultValue(null)]
1524 [MWFCategory("Accessibility")]
1525 public string AccessibleName {
1527 return AccessibilityObject.Name;
1531 AccessibilityObject.Name=value;
1535 [DefaultValue(AccessibleRole.Default)]
1536 [MWFDescription("Role of the control"), MWFCategory("Accessibility")]
1537 public AccessibleRole AccessibleRole {
1539 return AccessibilityObject.role;
1543 AccessibilityObject.role=value;
1547 [DefaultValue(false)]
1548 [MWFCategory("Behavior")]
1549 public virtual bool AllowDrop {
1555 if (allow_drop == value)
1558 if (IsHandleCreated) {
1560 XplatUI.SetAllowDrop (Handle, value);
1566 [RefreshProperties(RefreshProperties.Repaint)]
1567 [DefaultValue(AnchorStyles.Top | AnchorStyles.Left)]
1568 [MWFCategory("Layout")]
1569 public virtual AnchorStyles Anchor {
1571 return anchor_style;
1577 if (parent != null) {
1578 parent.PerformLayout(this, "Parent");
1584 // XXX: Implement me!
1587 [RefreshProperties (RefreshProperties.All)]
1588 [Localizable (true)]
1589 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
1591 [EditorBrowsable (EditorBrowsableState.Never)]
1592 [DefaultValue (false)]
1593 public virtual bool AutoSize {
1595 //Console.Error.WriteLine("Unimplemented: Control::get_AutoSize()");
1599 Console.Error.WriteLine("Unimplemented: Control::set_AutoSize(bool)");
1604 [AmbientValue (typeof(Size), "0, 0")]
1605 public virtual Size MaximumSize {
1607 return maximum_size;
1610 maximum_size = value;
1614 public virtual Size MinimumSize {
1616 return minimum_size;
1619 minimum_size = value;
1625 [MWFCategory("Appearance")]
1626 public virtual Color BackColor {
1628 if (background_color.IsEmpty) {
1630 Color pcolor = parent.BackColor;
1631 if (pcolor.A == 0xff || GetStyle(ControlStyles.SupportsTransparentBackColor))
1634 return DefaultBackColor;
1636 return background_color;
1640 if (!value.IsEmpty && (value.A != 0xff) && !GetStyle(ControlStyles.SupportsTransparentBackColor)) {
1641 throw new ArgumentException("Transparent background colors are not supported on this control");
1644 if (background_color != value) {
1645 background_color=value;
1646 SetChildColor(this);
1647 OnBackColorChanged(EventArgs.Empty);
1654 [DefaultValue(null)]
1655 [MWFCategory("Appearance")]
1656 public virtual Image BackgroundImage {
1658 return background_image;
1662 if (background_image!=value) {
1663 background_image=value;
1664 OnBackgroundImageChanged(EventArgs.Empty);
1670 [EditorBrowsable(EditorBrowsableState.Advanced)]
1672 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1673 public virtual BindingContext BindingContext {
1675 if (binding_context != null)
1676 return binding_context;
1679 binding_context = Parent.BindingContext;
1680 return binding_context;
1683 if (binding_context != value) {
1684 binding_context = value;
1685 OnBindingContextChanged(EventArgs.Empty);
1690 [EditorBrowsable(EditorBrowsableState.Advanced)]
1692 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1695 return bounds.Y+bounds.Height;
1699 [EditorBrowsable(EditorBrowsableState.Advanced)]
1701 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1702 public Rectangle Bounds {
1708 SetBounds(value.Left, value.Top, value.Width, value.Height, BoundsSpecified.All);
1712 [EditorBrowsable(EditorBrowsableState.Advanced)]
1714 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1715 public bool CanFocus {
1717 if (IsHandleCreated && Visible && Enabled) {
1724 [EditorBrowsable(EditorBrowsableState.Advanced)]
1726 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1727 public bool CanSelect {
1731 if (!GetStyle(ControlStyles.Selectable)) {
1736 while (parent != null) {
1737 if (!parent.is_visible || !parent.is_enabled) {
1741 parent = parent.parent;
1747 internal virtual bool InternalCapture {
1757 [EditorBrowsable(EditorBrowsableState.Advanced)]
1759 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1760 public bool Capture {
1762 return this.is_captured;
1766 if (this.IsHandleCreated && value != is_captured) {
1769 XplatUI.GrabWindow(this.window.Handle, IntPtr.Zero);
1771 XplatUI.UngrabWindow(this.window.Handle);
1772 is_captured = false;
1778 [DefaultValue(true)]
1779 [MWFCategory("Focus")]
1780 public bool CausesValidation {
1782 return this.causes_validation;
1786 if (this.causes_validation != value) {
1787 causes_validation = value;
1788 OnCausesValidationChanged(EventArgs.Empty);
1793 [EditorBrowsable(EditorBrowsableState.Advanced)]
1795 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1796 public Rectangle ClientRectangle {
1798 client_rect.Width = client_size.Width;
1799 client_rect.Height = client_size.Height;
1804 [EditorBrowsable(EditorBrowsableState.Advanced)]
1806 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1807 public Size ClientSize {
1810 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1811 return ((Form)this).form_parent_window.ClientSize;
1819 this.SetClientSizeCore(value.Width, value.Height);
1823 [EditorBrowsable(EditorBrowsableState.Advanced)]
1825 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1826 [DescriptionAttribute("ControlCompanyNameDescr")]
1827 public String CompanyName {
1829 return "Mono Project, Novell, Inc.";
1833 [EditorBrowsable(EditorBrowsableState.Advanced)]
1835 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1836 public bool ContainsFocus {
1838 IntPtr focused_window;
1840 focused_window = XplatUI.GetFocus();
1841 if (IsHandleCreated) {
1842 if (focused_window == Handle) {
1846 for (int i=0; i < child_controls.Count; i++) {
1847 if (child_controls[i].ContainsFocus) {
1858 [DefaultValue(null)]
1859 [MWFCategory("Behavior")]
1860 public virtual ContextMenu ContextMenu {
1862 return GetContextMenuInternal ();
1866 if (context_menu != value) {
1867 context_menu = value;
1868 OnContextMenuChanged(EventArgs.Empty);
1873 internal virtual ContextMenu GetContextMenuInternal ()
1875 return context_menu;
1879 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
1880 public ControlCollection Controls {
1882 return this.child_controls;
1886 [EditorBrowsable(EditorBrowsableState.Advanced)]
1888 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1889 public bool Created {
1891 return (!is_disposed && is_created);
1895 [AmbientValue(null)]
1896 [MWFCategory("Appearance")]
1897 public virtual Cursor Cursor {
1899 if (cursor != null) {
1903 if (parent != null) {
1904 return parent.Cursor;
1907 return Cursors.Default;
1911 if (cursor != value) {
1916 if (IsHandleCreated) {
1917 pt = Cursor.Position;
1919 if (bounds.Contains(pt) || Capture) {
1920 if (GetChildAtPoint(pt) == null) {
1921 if (cursor != null) {
1922 XplatUI.SetCursor(window.Handle, cursor.handle);
1924 if (parent != null) {
1925 XplatUI.SetCursor(window.Handle, parent.Cursor.handle);
1927 XplatUI.SetCursor(window.Handle, Cursors.Default.handle);
1934 OnCursorChanged(EventArgs.Empty);
1940 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
1941 [ParenthesizePropertyName(true)]
1942 [RefreshProperties(RefreshProperties.All)]
1943 [MWFCategory("Data")]
1944 public ControlBindingsCollection DataBindings {
1946 if (data_bindings == null)
1947 data_bindings = new ControlBindingsCollection (this);
1948 return data_bindings;
1952 [EditorBrowsable(EditorBrowsableState.Advanced)]
1954 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1955 public virtual Rectangle DisplayRectangle {
1957 return ClientRectangle;
1961 [EditorBrowsable(EditorBrowsableState.Advanced)]
1963 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1964 public bool Disposing {
1971 [RefreshProperties(RefreshProperties.Repaint)]
1972 [DefaultValue(DockStyle.None)]
1973 [MWFCategory("Layout")]
1974 public virtual DockStyle Dock {
1980 if (dock_style == value) {
1984 if (!Enum.IsDefined (typeof (DockStyle), value)) {
1985 throw new InvalidEnumArgumentException ("value", (int) value,
1986 typeof (DockStyle));
1991 if (dock_style == DockStyle.None) {
1992 if (explicit_bounds == Rectangle.Empty)
1993 Bounds = new Rectangle (new Point (0, 0), DefaultSize);
1995 Bounds = explicit_bounds;
1998 if (parent != null) {
1999 parent.PerformLayout(this, "Parent");
2002 OnDockChanged(EventArgs.Empty);
2007 protected virtual bool DoubleBuffered {
2009 return (control_style & ControlStyles.DoubleBuffer) != 0;
2013 SetStyle (ControlStyles.DoubleBuffer, value);
2020 [MWFCategory("Behavior")]
2021 public bool Enabled {
2027 if (parent != null) {
2028 return parent.Enabled;
2036 bool old_value = is_enabled;
2039 if (old_value != value && !value && this.has_focus)
2040 SelectNextControl(this, true, true, true, true);
2042 OnEnabledChanged (EventArgs.Empty);
2046 [EditorBrowsable(EditorBrowsableState.Advanced)]
2048 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2049 public virtual bool Focused {
2051 return this.has_focus;
2056 [AmbientValue(null)]
2058 [MWFCategory("Appearance")]
2059 public virtual Font Font {
2065 if (Parent != null && Parent.Font != null) {
2072 [param:MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Font))]
2074 if (font != null && font.Equals (value)) {
2080 OnFontChanged (EventArgs.Empty);
2085 [MWFCategory("Appearance")]
2086 public virtual Color ForeColor {
2088 if (foreground_color.IsEmpty) {
2090 return parent.ForeColor;
2092 return DefaultForeColor;
2094 return foreground_color;
2098 if (foreground_color != value) {
2099 foreground_color=value;
2101 OnForeColorChanged(EventArgs.Empty);
2108 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2109 public IntPtr Handle { // IWin32Window
2112 if (verify_thread_handle) {
2113 if (this.InvokeRequired) {
2114 throw new InvalidOperationException("Cross-thread access of handle detected. Handle access only valid on thread that created the control");
2118 if (!IsHandleCreated) {
2121 return window.Handle;
2125 [EditorBrowsable(EditorBrowsableState.Advanced)]
2127 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2128 public bool HasChildren {
2130 if (this.child_controls.Count>0) {
2137 [EditorBrowsable(EditorBrowsableState.Always)]
2139 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2142 return this.bounds.Height;
2146 SetBounds(bounds.X, bounds.Y, bounds.Width, value, BoundsSpecified.Height);
2150 [AmbientValue(ImeMode.Inherit)]
2152 [MWFCategory("Behavior")]
2153 public ImeMode ImeMode {
2155 if (ime_mode == ImeMode.Inherit) {
2157 return parent.ImeMode;
2159 return ImeMode.NoControl; // default value
2165 if (ime_mode != value) {
2168 OnImeModeChanged(EventArgs.Empty);
2173 [EditorBrowsable(EditorBrowsableState.Advanced)]
2175 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2176 public bool InvokeRequired { // ISynchronizeInvoke
2178 if (creator_thread != null && creator_thread!=Thread.CurrentThread) {
2185 [EditorBrowsable(EditorBrowsableState.Advanced)]
2187 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2188 public bool IsAccessible {
2190 return is_accessible;
2194 is_accessible = value;
2198 [EditorBrowsable(EditorBrowsableState.Advanced)]
2200 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2201 public bool IsDisposed {
2203 return this.is_disposed;
2207 [EditorBrowsable(EditorBrowsableState.Advanced)]
2209 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2210 public bool IsHandleCreated {
2212 if ((window != null) && (window.Handle != IntPtr.Zero)) {
2213 Hwnd hwnd = Hwnd.ObjectFromHandle (window.Handle);
2214 if (hwnd != null && !hwnd.zombie)
2224 [EditorBrowsable (EditorBrowsableState.Advanced)]
2225 public virtual Layout.LayoutEngine LayoutEngine {
2226 get { return new Layout.DefaultLayout (); }
2230 [EditorBrowsable(EditorBrowsableState.Always)]
2232 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2235 return this.bounds.X;
2239 SetBounds(value, bounds.Y, bounds.Width, bounds.Height, BoundsSpecified.X);
2244 [MWFCategory("Layout")]
2245 public Point Location {
2247 return new Point(bounds.X, bounds.Y);
2251 SetBounds(value.X, value.Y, bounds.Width, bounds.Height, BoundsSpecified.Location);
2256 [Localizable (true)]
2257 public Padding Margin {
2258 get { return this.margin; }
2259 set { this.margin = value; }
2264 public string Name {
2276 public Padding Padding {
2288 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2289 public Control Parent {
2295 if (value == this) {
2296 throw new ArgumentException("A circular control reference has been made. A control cannot be owned or parented to itself.");
2299 if (parent!=value) {
2301 parent.Controls.Remove(this);
2306 value.Controls.Add(this);
2311 [EditorBrowsable(EditorBrowsableState.Advanced)]
2313 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2314 public string ProductName {
2316 Type t = typeof (AssemblyProductAttribute);
2317 Assembly assembly = GetType().Module.Assembly;
2318 object [] attrs = assembly.GetCustomAttributes (t, false);
2319 AssemblyProductAttribute a = null;
2320 // On MS we get a NullRefException if product attribute is not
2322 if (attrs != null && attrs.Length > 0)
2323 a = (AssemblyProductAttribute) attrs [0];
2328 [EditorBrowsable(EditorBrowsableState.Advanced)]
2330 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2331 public string ProductVersion {
2333 Type t = typeof (AssemblyVersionAttribute);
2334 Assembly assembly = GetType().Module.Assembly;
2335 object [] attrs = assembly.GetCustomAttributes (t, false);
2336 if (attrs == null || attrs.Length < 1)
2338 return ((AssemblyVersionAttribute)attrs [0]).Version;
2342 [EditorBrowsable(EditorBrowsableState.Advanced)]
2344 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2345 public bool RecreatingHandle {
2347 return is_recreating;
2351 [EditorBrowsable(EditorBrowsableState.Advanced)]
2353 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2354 public Region Region {
2360 if (value != null && IsHandleCreated) {
2361 XplatUI.SetClipRegion(Handle, value);
2363 clip_region = value;
2367 [EditorBrowsable(EditorBrowsableState.Advanced)]
2369 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2372 return this.bounds.X+this.bounds.Width;
2376 [AmbientValue(RightToLeft.Inherit)]
2378 [MWFCategory("Appearance")]
2379 public virtual RightToLeft RightToLeft {
2381 if (right_to_left == RightToLeft.Inherit) {
2383 return parent.RightToLeft;
2385 return RightToLeft.No; // default value
2387 return right_to_left;
2391 if (value != right_to_left) {
2392 right_to_left = value;
2393 OnRightToLeftChanged(EventArgs.Empty);
2398 [EditorBrowsable(EditorBrowsableState.Advanced)]
2399 public override ISite Site {
2407 if (value != null) {
2408 AmbientProperties ap = (AmbientProperties) value.GetService (typeof (AmbientProperties));
2410 BackColor = ap.BackColor;
2411 ForeColor = ap.ForeColor;
2420 [MWFCategory("Layout")]
2423 return new Size(Width, Height);
2427 SetBounds(bounds.X, bounds.Y, value.Width, value.Height, BoundsSpecified.Size);
2432 [MergableProperty(false)]
2433 [MWFCategory("Behavior")]
2434 public int TabIndex {
2436 if (tab_index != -1) {
2443 if (tab_index != value) {
2445 OnTabIndexChanged(EventArgs.Empty);
2451 [DefaultValue(true)]
2452 [MWFCategory("Behavior")]
2453 public bool TabStop {
2459 if (tab_stop != value) {
2461 OnTabStopChanged(EventArgs.Empty);
2466 [Localizable(false)]
2468 [TypeConverter(typeof(StringConverter))]
2469 [DefaultValue(null)]
2470 [MWFCategory("Data")]
2477 control_tag = value;
2483 [BindableAttribute(true)]
2484 [MWFCategory("Appearance")]
2485 public virtual string Text {
2487 // Our implementation ignores ControlStyles.CacheText - we always cache
2492 if (value == null) {
2493 value = String.Empty;
2498 if (IsHandleCreated) {
2499 /* we need to call .SetWindowStyle here instead of just .Text
2500 because the presence/absence of Text (== "" or not) can cause
2501 other window style things to appear/disappear */
2502 XplatUI.SetWindowStyle(window.Handle, CreateParams);
2503 XplatUI.Text(Handle, text);
2505 OnTextChanged (EventArgs.Empty);
2510 [EditorBrowsable(EditorBrowsableState.Always)]
2512 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2515 return this.bounds.Y;
2519 SetBounds(bounds.X, value, bounds.Width, bounds.Height, BoundsSpecified.Y);
2523 [EditorBrowsable(EditorBrowsableState.Advanced)]
2525 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2526 public Control TopLevelControl {
2530 while (p.parent != null) {
2534 return p is Form ? p : null;
2539 [MWFCategory("Behavior")]
2540 public bool Visible {
2544 } else if (parent != null) {
2545 return parent.Visible;
2552 SetVisibleCore(value);
2556 [EditorBrowsable(EditorBrowsableState.Always)]
2558 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2561 return this.bounds.Width;
2565 SetBounds(bounds.X, bounds.Y, value, bounds.Height, BoundsSpecified.Width);
2569 [EditorBrowsable(EditorBrowsableState.Never)]
2571 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2572 public IWindowTarget WindowTarget {
2581 #endregion // Public Instance Properties
2583 #region Protected Instance Properties
2584 protected virtual CreateParams CreateParams {
2586 CreateParams create_params = new CreateParams();
2589 create_params.Caption = Text;
2592 create_params.Caption = text;
2596 create_params.X = Left;
2599 create_params.X = this.bounds.X;
2603 create_params.Y = Top;
2606 create_params.Y = this.bounds.Y;
2610 create_params.Width = Width;
2613 create_params.Width = this.bounds.Width;
2617 create_params.Height = Height;
2620 create_params.Height = this.bounds.Height;
2624 create_params.ClassName = XplatUI.DefaultClassName;
2625 create_params.ClassStyle = 0;
2626 create_params.ExStyle = 0;
2627 create_params.Param = 0;
2630 create_params.ExStyle |= (int)WindowExStyles.WS_EX_ACCEPTFILES;
2633 if ((parent!=null) && (parent.IsHandleCreated)) {
2634 create_params.Parent = parent.Handle;
2637 create_params.Style = (int)WindowStyles.WS_CHILD | (int)WindowStyles.WS_CLIPCHILDREN | (int)WindowStyles.WS_CLIPSIBLINGS;
2640 create_params.Style |= (int)WindowStyles.WS_VISIBLE;
2644 create_params.Style |= (int)WindowStyles.WS_DISABLED;
2647 switch (border_style) {
2648 case BorderStyle.FixedSingle:
2649 create_params.Style |= (int) WindowStyles.WS_BORDER;
2651 case BorderStyle.Fixed3D:
2652 create_params.ExStyle |= (int) WindowExStyles.WS_EX_CLIENTEDGE;
2656 return create_params;
2660 protected virtual ImeMode DefaultImeMode {
2662 return ImeMode.Inherit;
2667 protected virtual Padding DefaultMargin {
2668 get { return new Padding (3); }
2672 protected virtual Size DefaultSize {
2674 return new Size(0, 0);
2678 protected int FontHeight {
2690 protected bool RenderRightToLeft {
2692 return (this.right_to_left == RightToLeft.Yes);
2696 protected bool ResizeRedraw {
2698 return GetStyle(ControlStyles.ResizeRedraw);
2702 SetStyle(ControlStyles.ResizeRedraw, value);
2706 [EditorBrowsable(EditorBrowsableState.Advanced)]
2708 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2709 protected virtual bool ShowFocusCues {
2715 [EditorBrowsable(EditorBrowsableState.Advanced)]
2717 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2718 protected bool ShowKeyboardCues {
2723 #endregion // Protected Instance Properties
2725 #region Public Static Methods
2726 [EditorBrowsable(EditorBrowsableState.Advanced)]
2727 public static Control FromChildHandle(IntPtr handle) {
2728 return Control.ControlNativeWindow.ControlFromChildHandle (handle);
2731 [EditorBrowsable(EditorBrowsableState.Advanced)]
2732 public static Control FromHandle(IntPtr handle) {
2733 return Control.ControlNativeWindow.ControlFromHandle(handle);
2736 public static bool IsMnemonic(char charCode, string text) {
2739 amp = text.IndexOf('&');
2742 if (amp + 1 < text.Length) {
2743 if (text[amp + 1] != '&') {
2744 if (Char.ToUpper(charCode) == Char.ToUpper(text.ToCharArray(amp + 1, 1)[0])) {
2754 #region Protected Static Methods
2755 [EditorBrowsable(EditorBrowsableState.Advanced)]
2756 protected static bool ReflectMessage(IntPtr hWnd, ref Message m) {
2759 c = Control.FromHandle(hWnd);
2769 #region Public Instance Methods
2770 [EditorBrowsable(EditorBrowsableState.Advanced)]
2771 public IAsyncResult BeginInvoke(Delegate method) {
2772 object [] prms = null;
2773 if (method is EventHandler)
2774 prms = new object [] { this, EventArgs.Empty };
2775 return BeginInvokeInternal(method, prms, false);
2778 [EditorBrowsable(EditorBrowsableState.Advanced)]
2779 public IAsyncResult BeginInvoke (Delegate method, object[] args) {
2780 return BeginInvokeInternal (method, args, false);
2783 public void BringToFront() {
2784 if (parent != null) {
2785 parent.child_controls.SetChildIndex(this, 0);
2788 XplatUI.SetZOrder(Handle, IntPtr.Zero, false, false);
2792 public bool Contains(Control ctl) {
2793 while (ctl != null) {
2802 public void CreateControl() {
2804 throw new ObjectDisposedException(GetType().FullName.ToString());
2810 if (!IsHandleCreated) {
2818 Control [] controls = child_controls.GetAllControls ();
2819 for (int i=0; i<controls.Length; i++) {
2820 controls [i].CreateControl ();
2823 UpdateChildrenZOrder();
2825 if (binding_context == null) { // seem to be sent whenever it's null?
2826 OnBindingContextChanged(EventArgs.Empty);
2832 public Graphics CreateGraphics() {
2833 if (!IsHandleCreated) {
2834 this.CreateHandle();
2836 return Graphics.FromHwnd(this.window.Handle);
2839 public DragDropEffects DoDragDrop(object data, DragDropEffects allowedEffects) {
2840 return XplatUI.StartDrag(this.window.Handle, data, allowedEffects);
2843 [EditorBrowsable(EditorBrowsableState.Advanced)]
2844 public object EndInvoke (IAsyncResult async_result) {
2845 AsyncMethodResult result = (AsyncMethodResult) async_result;
2846 return result.EndInvoke ();
2849 public Form FindForm() {
2862 [EditorBrowsable (EditorBrowsableState.Advanced)]
2864 public bool Focus() {
2865 if (CanFocus && IsHandleCreated && !has_focus && !is_focusing) {
2868 is_focusing = false;
2873 public Control GetChildAtPoint(Point pt) {
2874 // Microsoft's version of this function doesn't seem to work, so I can't check
2875 // if we only consider children or also grandchildren, etc.
2876 // I'm gonna say 'children only'
2877 for (int i=0; i<child_controls.Count; i++) {
2878 if (child_controls[i].Bounds.Contains(pt)) {
2879 return child_controls[i];
2885 public IContainerControl GetContainerControl() {
2886 Control current = this;
2888 while (current!=null) {
2889 if ((current is IContainerControl) && ((current.control_style & ControlStyles.ContainerControl)!=0)) {
2890 return (IContainerControl)current;
2892 current = current.parent;
2897 public Control GetNextControl(Control ctl, bool forward) {
2899 if (!this.Contains(ctl)) {
2904 ctl = FindControlForward(this, ctl);
2907 ctl = FindControlBackward(this, ctl);
2917 [EditorBrowsable (EditorBrowsableState.Advanced)]
2918 public virtual Size GetPreferredSize (Size proposedSize) {
2919 return preferred_size;
2923 public void Hide() {
2924 this.Visible = false;
2927 public void Invalidate() {
2928 Invalidate(ClientRectangle, false);
2931 public void Invalidate(bool invalidateChildren) {
2932 Invalidate(ClientRectangle, invalidateChildren);
2935 public void Invalidate(System.Drawing.Rectangle rc) {
2936 Invalidate(rc, false);
2939 public void Invalidate(System.Drawing.Rectangle rc, bool invalidateChildren) {
2940 if (!IsHandleCreated || !Visible || rc.Width == 0 || rc.Height == 0) {
2944 NotifyInvalidate(rc);
2946 XplatUI.Invalidate(Handle, rc, false);
2948 if (invalidateChildren) {
2949 Control [] controls = child_controls.GetAllControls ();
2950 for (int i=0; i<controls.Length; i++)
2951 controls [i].Invalidate ();
2953 OnInvalidated(new InvalidateEventArgs(rc));
2956 public void Invalidate(System.Drawing.Region region) {
2957 Invalidate(region, false);
2960 public void Invalidate(System.Drawing.Region region, bool invalidateChildren) {
2961 RectangleF bounds = region.GetBounds (CreateGraphics ());
2962 Invalidate (new Rectangle ((int) bounds.X, (int) bounds.Y, (int) bounds.Width, (int) bounds.Height),
2963 invalidateChildren);
2966 public object Invoke (Delegate method) {
2967 object [] prms = null;
2968 if (method is EventHandler)
2969 prms = new object [] { this, EventArgs.Empty };
2971 return Invoke(method, prms);
2974 public object Invoke (Delegate method, object[] args) {
2975 if (!this.InvokeRequired) {
2976 return method.DynamicInvoke(args);
2979 IAsyncResult result = BeginInvoke (method, args);
2980 return EndInvoke(result);
2983 internal object InvokeInternal (Delegate method, bool disposing) {
2984 return InvokeInternal(method, null, disposing);
2987 internal object InvokeInternal (Delegate method, object[] args, bool disposing) {
2988 if (!this.InvokeRequired) {
2989 return method.DynamicInvoke(args);
2992 IAsyncResult result = BeginInvokeInternal (method, args, disposing);
2993 return EndInvoke(result);
2996 [EditorBrowsable(EditorBrowsableState.Advanced)]
2997 public void PerformLayout() {
2998 PerformLayout(null, null);
3002 private void SetImplicitBounds (int x, int y, int width, int height)
3004 Rectangle saved_bounds = explicit_bounds;
3005 SetBounds (x, y, width, height);
3006 explicit_bounds = saved_bounds;
3010 [EditorBrowsable(EditorBrowsableState.Advanced)]
3011 public void PerformLayout(Control affectedControl, string affectedProperty) {
3012 LayoutEventArgs levent = new LayoutEventArgs(affectedControl, affectedProperty);
3014 if (layout_suspended > 0) {
3015 layout_pending = true;
3019 layout_pending = false;
3021 // Prevent us from getting messed up
3024 // Perform all Dock and Anchor calculations
3028 this.layout_engine.Layout(this, levent);
3030 // This has been moved to Layout/DefaultLayout.cs for 2.0, please duplicate any changes/fixes there.
3032 AnchorStyles anchor;
3035 space = DisplayRectangle;
3037 // Deal with docking; go through in reverse, MS docs say that lowest Z-order is closest to edge
3038 Control [] controls = child_controls.GetAllControls ();
3039 for (int i = controls.Length - 1; i >= 0; i--) {
3040 child = controls [i];
3042 if (!child.Visible) {
3046 switch (child.Dock) {
3047 case DockStyle.None: {
3052 case DockStyle.Left: {
3053 child.SetImplicitBounds(space.Left, space.Y, child.Width, space.Height);
3054 space.X+=child.Width;
3055 space.Width-=child.Width;
3059 case DockStyle.Top: {
3060 child.SetImplicitBounds(space.Left, space.Y, space.Width, child.Height);
3061 space.Y+=child.Height;
3062 space.Height-=child.Height;
3066 case DockStyle.Right: {
3067 child.SetImplicitBounds(space.Right-child.Width, space.Y, child.Width, space.Height);
3068 space.Width-=child.Width;
3072 case DockStyle.Bottom: {
3073 child.SetImplicitBounds(space.Left, space.Bottom-child.Height, space.Width, child.Height);
3074 space.Height-=child.Height;
3080 for (int i = controls.Length - 1; i >= 0; i--) {
3083 //if (child.Visible && (child.Dock == DockStyle.Fill)) {
3084 if (child.Dock == DockStyle.Fill) {
3085 child.SetImplicitBounds(space.Left, space.Top, space.Width, space.Height);
3089 space = DisplayRectangle;
3091 for (int i=0; i < controls.Length; i++) {
3097 child = controls[i];
3099 // If the control is docked we don't need to do anything
3100 if (child.Dock != DockStyle.None) {
3104 anchor = child.Anchor;
3108 width = child.Width;
3109 height = child.Height;
3111 if ((anchor & AnchorStyles.Left) !=0 ) {
3112 if ((anchor & AnchorStyles.Right) != 0) {
3113 width = space.Width - child.dist_right - left;
3115 ; // Left anchored only, nothing to be done
3117 } else if ((anchor & AnchorStyles.Right) != 0) {
3118 left = space.Width - child.dist_right - width;
3120 // left+=diff_width/2 will introduce rounding errors (diff_width removed from svn after r51780)
3121 // This calculates from scratch every time:
3122 left = child.dist_left + (space.Width - (child.dist_left + width + child.dist_right)) / 2;
3125 if ((anchor & AnchorStyles.Top) !=0 ) {
3126 if ((anchor & AnchorStyles.Bottom) != 0) {
3127 height = space.Height - child.dist_bottom - top;
3129 ; // Top anchored only, nothing to be done
3131 } else if ((anchor & AnchorStyles.Bottom) != 0) {
3132 top = space.Height - child.dist_bottom - height;
3134 // top += diff_height/2 will introduce rounding errors (diff_height removed from after r51780)
3135 // This calculates from scratch every time:
3136 top = child.dist_top + (space.Height - (child.dist_top + height + child.dist_bottom)) / 2;
3148 child.SetImplicitBounds(left, top, width, height);
3152 // Let everyone know
3156 // Need to make sure we decremend layout_suspended
3162 public Point PointToClient (Point p) {
3166 XplatUI.ScreenToClient (Handle, ref x, ref y);
3168 return new Point (x, y);
3171 public Point PointToScreen(Point p) {
3175 XplatUI.ClientToScreen(Handle, ref x, ref y);
3177 return new Point(x, y);
3180 public virtual bool PreProcessMessage(ref Message msg) {
3181 return InternalPreProcessMessage (ref msg);
3184 internal virtual bool InternalPreProcessMessage (ref Message msg) {
3187 if ((msg.Msg == (int)Msg.WM_KEYDOWN) || (msg.Msg == (int)Msg.WM_SYSKEYDOWN)) {
3188 key_data = (Keys)msg.WParam.ToInt32() | XplatUI.State.ModifierKeys;
3190 if (!ProcessCmdKey(ref msg, key_data)) {
3191 if (IsInputKey(key_data)) {
3195 return ProcessDialogKey(key_data);
3199 } else if (msg.Msg == (int)Msg.WM_CHAR) {
3200 if (IsInputChar((char)msg.WParam)) {
3203 return ProcessDialogChar((char)msg.WParam);
3204 } else if (msg.Msg == (int)Msg.WM_SYSCHAR) {
3205 return ProcessDialogChar((char)msg.WParam);
3210 public Rectangle RectangleToClient(Rectangle r) {
3211 return new Rectangle(PointToClient(r.Location), r.Size);
3214 public Rectangle RectangleToScreen(Rectangle r) {
3215 return new Rectangle(PointToScreen(r.Location), r.Size);
3218 public virtual void Refresh() {
3219 if (IsHandleCreated == true) {
3221 XplatUI.UpdateWindow(window.Handle);
3223 Control [] controls = child_controls.GetAllControls ();
3224 for (int i=0; i < controls.Length; i++) {
3225 controls[i].Refresh();
3231 [EditorBrowsable(EditorBrowsableState.Never)]
3232 public virtual void ResetBackColor() {
3233 BackColor = Color.Empty;
3236 [EditorBrowsable(EditorBrowsableState.Never)]
3237 public void ResetBindings() {
3238 data_bindings.Clear();
3241 [EditorBrowsable(EditorBrowsableState.Never)]
3242 public virtual void ResetCursor() {
3246 [EditorBrowsable(EditorBrowsableState.Never)]
3247 public virtual void ResetFont() {
3251 [EditorBrowsable(EditorBrowsableState.Never)]
3252 public virtual void ResetForeColor() {
3253 foreground_color = Color.Empty;
3256 [EditorBrowsable(EditorBrowsableState.Never)]
3257 public void ResetImeMode() {
3258 ime_mode = DefaultImeMode;
3261 [EditorBrowsable(EditorBrowsableState.Never)]
3262 public virtual void ResetRightToLeft() {
3263 right_to_left = RightToLeft.Inherit;
3266 public virtual void ResetText() {
3267 text = String.Empty;
3270 public void ResumeLayout() {
3271 ResumeLayout (true);
3274 public void ResumeLayout(bool performLayout) {
3275 if (layout_suspended > 0) {
3279 if (layout_suspended == 0) {
3280 Control [] controls = child_controls.GetAllControls ();
3281 for (int i=0; i<controls.Length; i++) {
3282 controls [i].UpdateDistances ();
3285 if (performLayout && layout_pending) {
3291 [EditorBrowsable (EditorBrowsableState.Never)]
3294 public void Scale(float ratio) {
3295 ScaleCore(ratio, ratio);
3299 [EditorBrowsable (EditorBrowsableState.Never)]
3302 public void Scale(float dx, float dy) {
3307 [EditorBrowsable (EditorBrowsableState.Advanced)]
3308 public void Scale(SizeF factor) {
3309 ScaleCore(factor.Width, factor.Height);
3313 public void Select() {
3314 Select(false, false);
3318 private void printTree(Control c, string t) {
3319 foreach(Control i in c.child_controls) {
3320 Console.WriteLine("{2}{0}.TabIndex={1}", i, i.tab_index, t);
3321 printTree(i, t+"\t");
3325 public bool SelectNextControl(Control ctl, bool forward, bool tabStopOnly, bool nested, bool wrap) {
3329 Console.WriteLine("{0}", this.FindForm());
3330 printTree(this, "\t");
3333 if (!this.Contains(ctl) || (!nested && (ctl.parent != this))) {
3338 c = GetNextControl(c, forward);
3347 if (c.CanSelect && ((c.parent == this) || nested) && (c.tab_stop || !tabStopOnly)) {
3348 c.Select (true, true);
3351 } while (c != ctl); // If we wrap back to ourselves we stop
3356 public void SendToBack() {
3357 if (parent != null) {
3358 parent.child_controls.SetChildIndex(this, parent.child_controls.Count);
3362 public void SetBounds(int x, int y, int width, int height) {
3363 SetBounds(x, y, width, height, BoundsSpecified.All);
3366 public void SetBounds(int x, int y, int width, int height, BoundsSpecified specified) {
3367 if ((specified & BoundsSpecified.X) != BoundsSpecified.X) {
3371 if ((specified & BoundsSpecified.Y) != BoundsSpecified.Y) {
3375 if ((specified & BoundsSpecified.Width) != BoundsSpecified.Width) {
3379 if ((specified & BoundsSpecified.Height) != BoundsSpecified.Height) {
3383 SetBoundsCore(x, y, width, height, specified);
3384 if (parent != null) {
3385 parent.PerformLayout(this, "Bounds");
3389 public void Show() {
3391 this.CreateControl();
3397 public void SuspendLayout() {
3401 public void Update() {
3402 if (IsHandleCreated) {
3403 XplatUI.UpdateWindow(window.Handle);
3406 #endregion // Public Instance Methods
3408 #region Protected Instance Methods
3409 [EditorBrowsable(EditorBrowsableState.Advanced)]
3410 [MonoTODO("Implement this and tie it into Control.ControlAccessibleObject.NotifyClients")]
3411 protected void AccessibilityNotifyClients(AccessibleEvents accEvent, int childID) {
3412 throw new NotImplementedException();
3415 [EditorBrowsable(EditorBrowsableState.Advanced)]
3416 protected virtual AccessibleObject CreateAccessibilityInstance() {
3417 return new Control.ControlAccessibleObject(this);
3420 [EditorBrowsable(EditorBrowsableState.Advanced)]
3421 protected virtual ControlCollection CreateControlsInstance() {
3422 return new ControlCollection(this);
3425 [EditorBrowsable(EditorBrowsableState.Advanced)]
3426 protected virtual void CreateHandle() {
3428 throw new ObjectDisposedException(GetType().FullName.ToString());
3431 if (IsHandleCreated && !is_recreating) {
3435 window.CreateHandle(CreateParams);
3437 if (window.Handle != IntPtr.Zero) {
3438 creator_thread = Thread.CurrentThread;
3440 XplatUI.EnableWindow(window.Handle, is_enabled);
3441 XplatUI.SetVisible(window.Handle, is_visible, true);
3443 if (clip_region != null) {
3444 XplatUI.SetClipRegion(Handle, clip_region);
3447 // Set our handle with our parent
3448 if ((parent != null) && (parent.IsHandleCreated)) {
3449 XplatUI.SetParent(window.Handle, parent.Handle);
3452 // Set our handle as parent for our children
3453 Control [] children;
3455 children = child_controls.GetAllControls ();
3456 for (int i = 0; i < children.Length; i++ ) {
3457 if (!children[i].RecreatingHandle)
3458 XplatUI.SetParent(children[i].Handle, window.Handle);
3462 XplatUI.SetAllowDrop (Handle, allow_drop);
3464 // Find out where the window manager placed us
3465 if ((CreateParams.Style & (int)WindowStyles.WS_CHILD) != 0) {
3466 XplatUI.SetBorderStyle(window.Handle, (FormBorderStyle)border_style);
3470 OnHandleCreated(EventArgs.Empty);
3474 [EditorBrowsable(EditorBrowsableState.Advanced)]
3475 protected virtual void DefWndProc(ref Message m) {
3476 window.DefWndProc(ref m);
3479 [EditorBrowsable(EditorBrowsableState.Advanced)]
3480 protected virtual void DestroyHandle() {
3481 if (IsHandleCreated) {
3482 if (window != null) {
3483 window.DestroyHandle();
3488 protected internal bool GetStyle(ControlStyles flag) {
3489 return (control_style & flag) != 0;
3492 protected bool GetTopLevel() {
3496 [EditorBrowsable(EditorBrowsableState.Advanced)]
3497 protected virtual void InitLayout() {
3501 [EditorBrowsable(EditorBrowsableState.Advanced)]
3502 protected void InvokeGotFocus(Control toInvoke, EventArgs e) {
3503 toInvoke.OnGotFocus(e);
3506 [EditorBrowsable(EditorBrowsableState.Advanced)]
3507 protected void InvokeLostFocus(Control toInvoke, EventArgs e) {
3508 toInvoke.OnLostFocus(e);
3511 [EditorBrowsable(EditorBrowsableState.Advanced)]
3512 protected void InvokeOnClick(Control toInvoke, EventArgs e) {
3513 toInvoke.OnClick(e);
3516 protected void InvokePaint(Control toInvoke, PaintEventArgs e) {
3517 toInvoke.OnPaint(e);
3520 protected void InvokePaintBackground(Control toInvoke, PaintEventArgs e) {
3521 toInvoke.OnPaintBackground(e);
3524 protected virtual bool IsInputChar (char charCode) {
3528 protected virtual bool IsInputKey (Keys keyData) {
3529 // Doc says this one calls IsInputChar; not sure what to do with that
3533 [EditorBrowsable(EditorBrowsableState.Advanced)]
3534 protected virtual void NotifyInvalidate(Rectangle invalidatedArea) {
3538 protected virtual bool ProcessCmdKey(ref Message msg, Keys keyData) {
3539 if ((context_menu != null) && context_menu.ProcessCmdKey(ref msg, keyData)) {
3543 if (parent != null) {
3544 return parent.ProcessCmdKey(ref msg, keyData);
3550 protected virtual bool ProcessDialogChar(char charCode) {
3551 if (parent != null) {
3552 return parent.ProcessDialogChar (charCode);
3558 protected virtual bool ProcessDialogKey (Keys keyData) {
3559 if (parent != null) {
3560 return parent.ProcessDialogKey (keyData);
3566 protected virtual bool ProcessKeyEventArgs (ref Message msg)
3568 KeyEventArgs key_event;
3571 case (int)Msg.WM_SYSKEYDOWN:
3572 case (int)Msg.WM_KEYDOWN: {
3573 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
3574 OnKeyDown (key_event);
3575 return key_event.Handled;
3578 case (int)Msg.WM_SYSKEYUP:
3579 case (int)Msg.WM_KEYUP: {
3580 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
3581 OnKeyUp (key_event);
3582 return key_event.Handled;
3585 case (int)Msg.WM_SYSCHAR:
3586 case (int)Msg.WM_CHAR: {
3587 KeyPressEventArgs key_press_event;
3589 key_press_event = new KeyPressEventArgs((char)msg.WParam);
3590 OnKeyPress(key_press_event);
3592 msg.WParam = (IntPtr)key_press_event.KeyChar;
3594 return key_press_event.Handled;
3605 protected internal virtual bool ProcessKeyMessage(ref Message msg) {
3606 if (parent != null) {
3607 if (parent.ProcessKeyPreview(ref msg)) {
3612 return ProcessKeyEventArgs(ref msg);
3615 protected virtual bool ProcessKeyPreview(ref Message msg) {
3616 if (parent != null) {
3617 return parent.ProcessKeyPreview(ref msg);
3623 protected virtual bool ProcessMnemonic(char charCode) {
3628 [EditorBrowsable(EditorBrowsableState.Advanced)]
3629 protected void RaiseDragEvent(object key, DragEventArgs e) {
3633 [EditorBrowsable(EditorBrowsableState.Advanced)]
3634 protected void RaiseKeyEvent(object key, KeyEventArgs e) {
3638 [EditorBrowsable(EditorBrowsableState.Advanced)]
3639 protected void RaiseMouseEvent(object key, MouseEventArgs e) {
3643 [EditorBrowsable(EditorBrowsableState.Advanced)]
3644 protected void RaisePaintEvent(object key, PaintEventArgs e) {
3648 private void SetIsRecreating ()
3652 foreach (Control c in Controls.GetAllControls()) {
3653 c.SetIsRecreating ();
3657 [EditorBrowsable(EditorBrowsableState.Advanced)]
3658 protected void RecreateHandle() {
3660 Console.WriteLine("Recreating control {0}", XplatUI.Window(window.Handle));
3665 if (IsHandleCreated) {
3667 Console.WriteLine(" + handle is created, destroying it.");
3670 // WM_DESTROY will CreateHandle for us
3673 Console.WriteLine(" + handle is not created, creating it.");
3681 is_recreating = false;
3683 Console.WriteLine (" + new handle = {0:X}", Handle.ToInt32());
3689 [EditorBrowsable(EditorBrowsableState.Advanced)]
3690 protected void ResetMouseEventArgs() {
3694 [EditorBrowsable(EditorBrowsableState.Advanced)]
3695 protected ContentAlignment RtlTranslateAlignment(ContentAlignment align) {
3696 if (right_to_left == RightToLeft.No) {
3701 case ContentAlignment.TopLeft: {
3702 return ContentAlignment.TopRight;
3705 case ContentAlignment.TopRight: {
3706 return ContentAlignment.TopLeft;
3709 case ContentAlignment.MiddleLeft: {
3710 return ContentAlignment.MiddleRight;
3713 case ContentAlignment.MiddleRight: {
3714 return ContentAlignment.MiddleLeft;
3717 case ContentAlignment.BottomLeft: {
3718 return ContentAlignment.BottomRight;
3721 case ContentAlignment.BottomRight: {
3722 return ContentAlignment.BottomLeft;
3726 // if it's center it doesn't change
3732 [EditorBrowsable(EditorBrowsableState.Advanced)]
3733 protected HorizontalAlignment RtlTranslateAlignment(HorizontalAlignment align) {
3734 if ((right_to_left == RightToLeft.No) || (align == HorizontalAlignment.Center)) {
3738 if (align == HorizontalAlignment.Left) {
3739 return HorizontalAlignment.Right;
3742 // align must be HorizontalAlignment.Right
3743 return HorizontalAlignment.Left;
3746 [EditorBrowsable(EditorBrowsableState.Advanced)]
3747 protected LeftRightAlignment RtlTranslateAlignment(LeftRightAlignment align) {
3748 if (right_to_left == RightToLeft.No) {
3752 if (align == LeftRightAlignment.Left) {
3753 return LeftRightAlignment.Right;
3756 // align must be LeftRightAlignment.Right;
3757 return LeftRightAlignment.Left;
3760 [EditorBrowsable(EditorBrowsableState.Advanced)]
3761 protected ContentAlignment RtlTranslateContent(ContentAlignment align) {
3762 return RtlTranslateAlignment(align);
3765 [EditorBrowsable(EditorBrowsableState.Advanced)]
3766 protected HorizontalAlignment RtlTranslateHorizontal(HorizontalAlignment align) {
3767 return RtlTranslateAlignment(align);
3770 [EditorBrowsable(EditorBrowsableState.Advanced)]
3771 protected LeftRightAlignment RtlTranslateLeftRight(LeftRightAlignment align) {
3772 return RtlTranslateAlignment(align);
3775 [EditorBrowsable(EditorBrowsableState.Advanced)]
3776 protected virtual void ScaleCore(float dx, float dy) {
3782 location = new Point((int)(Left * dx), (int)(Top * dy));
3783 size = this.ClientSize;
3785 if (!GetStyle(ControlStyles.FixedWidth)) {
3786 size.Width = (int)(size.Width * dx);
3789 if (!GetStyle(ControlStyles.FixedHeight)) {
3790 size.Height = (int)(size.Height * dy);
3793 SetBounds(location.X, location.Y, size.Width, size.Height, BoundsSpecified.All);
3795 /* Now scale our children */
3796 Control [] controls = child_controls.GetAllControls ();
3797 for (int i=0; i < controls.Length; i++) {
3798 controls[i].Scale(dx, dy);
3804 protected virtual void Select(bool directed, bool forward) {
3805 IContainerControl container;
3807 container = GetContainerControl();
3808 if (container != null)
3809 container.ActiveControl = this;
3812 [EditorBrowsable(EditorBrowsableState.Advanced)]
3813 protected virtual void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
3814 // SetBoundsCore updates the Win32 control itself. UpdateBounds updates the controls variables and fires events, I'm guessing - pdb
3815 if (IsHandleCreated) {
3816 XplatUI.SetWindowPos(Handle, x, y, width, height);
3818 // Win32 automatically changes negative width/height to 0.
3819 // The control has already been sent a WM_WINDOWPOSCHANGED message and it has the correct
3820 // data, but it'll be overwritten when we call UpdateBounds unless we get the updated
3822 if (width < 0 || height < 0) {
3824 XplatUI.GetWindowPos(Handle, this is Form, out ix, out iy, out width, out height, out cw, out ch);
3828 UpdateBounds(x, y, width, height);
3833 [EditorBrowsable(EditorBrowsableState.Advanced)]
3834 protected virtual void SetClientSizeCore(int x, int y) {
3835 // Calculate the actual window size from the client size (it usually stays the same or grows)
3836 Rectangle ClientRect;
3837 Rectangle WindowRect;
3840 ClientRect = new Rectangle(0, 0, x, y);
3841 cp = this.CreateParams;
3843 if (XplatUI.CalculateWindowRect(ref ClientRect, cp.Style, cp.ExStyle, null, out WindowRect)==false) {
3847 SetBounds(bounds.X, bounds.Y, WindowRect.Width, WindowRect.Height, BoundsSpecified.Size);
3850 [EditorBrowsable(EditorBrowsableState.Advanced)]
3851 protected internal void SetStyle(ControlStyles flag, bool value) {
3853 control_style |= flag;
3855 control_style &= ~flag;
3859 protected void SetTopLevel(bool value) {
3860 if ((GetTopLevel() != value) && (parent != null)) {
3861 throw new Exception();
3865 if (value == true) {
3875 is_toplevel = value;
3878 protected virtual void SetVisibleCore(bool value) {
3879 if (value!=is_visible) {
3880 if (value && (window.Handle == IntPtr.Zero) || !is_created) {
3886 if (IsHandleCreated) {
3887 XplatUI.SetVisible(Handle, value, true);
3888 // Explicitly move Toplevel windows to where we want them;
3889 // apparently moving unmapped toplevel windows doesn't work
3890 if (is_visible && (this is Form)) {
3891 XplatUI.SetWindowPos(window.Handle, bounds.X, bounds.Y, bounds.Width, bounds.Height);
3895 OnVisibleChanged(EventArgs.Empty);
3897 if (value == false && parent != null && Focused) {
3900 // Need to start at parent, GetContainerControl might return ourselves if we're a container
3901 container = (Control)parent.GetContainerControl();
3902 if (container != null) {
3903 container.SelectNextControl(this, true, true, true, true);
3907 if (parent != null) {
3908 parent.PerformLayout(this, "visible");
3910 PerformLayout(this, "visible");
3915 [EditorBrowsable(EditorBrowsableState.Advanced)]
3916 protected void UpdateBounds() {
3924 if (!IsHandleCreated) {
3928 XplatUI.GetWindowPos(this.Handle, this is Form, out x, out y, out width, out height, out client_width, out client_height);
3930 UpdateBounds(x, y, width, height, client_width, client_height);
3933 [EditorBrowsable(EditorBrowsableState.Advanced)]
3934 protected void UpdateBounds(int x, int y, int width, int height) {
3938 // Calculate client rectangle
3939 rect = new Rectangle(0, 0, 0, 0);
3942 XplatUI.CalculateWindowRect(ref rect, cp.Style, cp.ExStyle, cp.menu, out rect);
3943 UpdateBounds(x, y, width, height, width - (rect.Right - rect.Left), height - (rect.Bottom - rect.Top));
3946 [EditorBrowsable(EditorBrowsableState.Advanced)]
3947 protected void UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) {
3948 // UpdateBounds only seems to set our sizes and fire events but not update the GUI window to match
3950 bool resized = false;
3952 // Needed to generate required notifications
3953 if ((this.bounds.X!=x) || (this.bounds.Y!=y)) {
3957 if ((this.Bounds.Width!=width) || (this.Bounds.Height!=height)) {
3964 bounds.Height=height;
3966 // Assume explicit bounds set. SetImplicitBounds will restore old bounds
3967 explicit_bounds = bounds;
3969 client_size.Width=clientWidth;
3970 client_size.Height=clientHeight;
3973 OnLocationChanged(EventArgs.Empty);
3977 OnSizeChanged(EventArgs.Empty);
3981 [EditorBrowsable(EditorBrowsableState.Advanced)]
3982 protected void UpdateStyles() {
3983 if (!IsHandleCreated) {
3987 XplatUI.SetWindowStyle(window.Handle, CreateParams);
3988 OnStyleChanged(EventArgs.Empty);
3991 private void UpdateZOrderOfChild(Control child) {
3992 if (IsHandleCreated && child.IsHandleCreated && (child.parent == this)) {
3995 index = child_controls.IndexOf(child);
3998 XplatUI.SetZOrder(child.Handle, child_controls[index - 1].Handle, false, false);
4000 IntPtr after = AfterTopMostControl ();
4001 if (after != IntPtr.Zero)
4002 XplatUI.SetZOrder (child.Handle, after, false, false);
4004 XplatUI.SetZOrder (child.Handle, IntPtr.Zero, true, false);
4009 // Override this if there is a control that shall always remain on
4010 // top of other controls (such as scrollbars). If there are several
4011 // of these controls, the bottom-most should be returned.
4012 internal virtual IntPtr AfterTopMostControl ()
4017 private void UpdateChildrenZOrder() {
4018 Control [] controls;
4020 if (!IsHandleCreated) {
4024 controls = child_controls.GetAllControls ();
4025 for (int i = 1; i < controls.Length; i++ ) {
4026 XplatUI.SetZOrder(controls[i].Handle, controls[i-1].Handle, false, false);
4030 [EditorBrowsable(EditorBrowsableState.Advanced)]
4031 protected void UpdateZOrder() {
4032 if (parent != null) {
4033 parent.UpdateZOrderOfChild(this);
4037 protected virtual void WndProc(ref Message m) {
4039 Console.WriteLine("Control {0} received message {1}", window.Handle == IntPtr.Zero ? this.Text : XplatUI.Window(window.Handle), m.ToString ());
4041 if ((this.control_style & ControlStyles.EnableNotifyMessage) != 0) {
4045 switch((Msg)m.Msg) {
4046 case Msg.WM_DESTROY: {
4047 OnHandleDestroyed(EventArgs.Empty);
4049 IntPtr handle = window.Handle;
4051 window.InvalidateHandle();
4053 if (is_recreating) {
4055 Console.WriteLine ("Creating handle for {0:X}", handle.ToInt32());
4059 Console.WriteLine (" + new handle = {0:X}", Handle.ToInt32());
4061 is_recreating = false;
4066 case Msg.WM_WINDOWPOSCHANGED: {
4068 Rectangle save_bounds = explicit_bounds;
4070 explicit_bounds = save_bounds;
4071 if (GetStyle(ControlStyles.ResizeRedraw)) {
4078 // Nice description of what should happen when handling WM_PAINT
4079 // can be found here: http://pluralsight.com/wiki/default.aspx/Craig/FlickerFreeControlDrawing.html
4080 // and here http://msdn.microsoft.com/msdnmag/issues/06/03/WindowsFormsPerformance/
4081 case Msg.WM_PAINT: {
4082 PaintEventArgs paint_event;
4084 paint_event = XplatUI.PaintEventStart(Handle, true);
4086 if (paint_event == null) {
4090 if (invalid_region != null && !invalid_region.IsVisible (paint_event.ClipRectangle)) {
4092 // Just blit the previous image
4093 XplatUI.BlitFromOffscreen (Handle, paint_event.Graphics, backbuffer, backbuffer_dc, paint_event.ClipRectangle);
4094 XplatUI.PaintEventEnd (Handle, true);
4099 Graphics back_dc = null;
4101 if (ThemeEngine.Current.DoubleBufferingSupported) {
4102 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
4103 CreateBackBuffer ();
4105 back_dc = backbuffer_dc;
4106 dc = paint_event.SetGraphics (back_dc);
4110 if (!GetStyle(ControlStyles.Opaque)) {
4111 OnPaintBackground(paint_event);
4114 // Button-derived controls choose to ignore their Opaque style, give them a chance to draw their background anyways
4115 OnPaintBackgroundInternal(paint_event);
4117 OnPaintInternal(paint_event);
4118 if (!paint_event.Handled) {
4119 OnPaint(paint_event);
4122 if (ThemeEngine.Current.DoubleBufferingSupported)
4123 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
4124 XplatUI.BlitFromOffscreen (Handle, dc, back, back_dc, paint_event.ClipRectangle);
4125 paint_event.SetGraphics (dc);
4126 invalid_region.Exclude (paint_event.ClipRectangle);
4128 if (back != backbuffer)
4129 XplatUI.DestroyOffscreenDrawable (back, back_dc);
4132 XplatUI.PaintEventEnd(Handle, true);
4137 case Msg.WM_ERASEBKGND: {
4138 // The DefWndProc will never have to handle this, we always paint the background in managed code
4139 // In theory this code would look at ControlStyles.AllPaintingInWmPaint and and call OnPaintBackground
4140 // here but it just makes things more complicated...
4141 m.Result = (IntPtr)1;
4145 case Msg.WM_LBUTTONUP: {
4148 me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Left,
4150 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4153 HandleClick(mouse_clicks, me);
4156 if (InternalCapture) {
4157 InternalCapture = false;
4160 if (mouse_clicks > 1) {
4166 case Msg.WM_LBUTTONDOWN: {
4168 Select (true, true);
4170 InternalCapture = true;
4171 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4172 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4178 case Msg.WM_LBUTTONDBLCLK: {
4179 InternalCapture = true;
4181 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4182 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4187 case Msg.WM_MBUTTONUP: {
4190 me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Middle,
4192 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4195 HandleClick(mouse_clicks, me);
4197 if (InternalCapture) {
4198 InternalCapture = false;
4200 if (mouse_clicks > 1) {
4206 case Msg.WM_MBUTTONDOWN: {
4207 InternalCapture = true;
4208 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4209 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4214 case Msg.WM_MBUTTONDBLCLK: {
4215 InternalCapture = true;
4217 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4218 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4223 case Msg.WM_RBUTTONUP: {
4227 pt = new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()));
4228 pt = PointToScreen(pt);
4230 XplatUI.SendMessage(m.HWnd, Msg.WM_CONTEXTMENU, m.HWnd, (IntPtr)(pt.X + (pt.Y << 16)));
4232 me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Right,
4234 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4237 HandleClick(mouse_clicks, me);
4240 if (InternalCapture) {
4241 InternalCapture = false;
4244 if (mouse_clicks > 1) {
4250 case Msg.WM_RBUTTONDOWN: {
4251 InternalCapture = true;
4252 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4253 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4258 case Msg.WM_RBUTTONDBLCLK: {
4259 InternalCapture = true;
4261 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4262 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4267 case Msg.WM_CONTEXTMENU: {
4268 if (context_menu != null) {
4271 pt = new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()));
4272 context_menu.Show(this, PointToClient(pt));
4280 case Msg.WM_MOUSEWHEEL: {
4282 OnMouseWheel (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4283 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4284 HighOrder(m.WParam.ToInt32())));
4289 case Msg.WM_MOUSEMOVE: {
4290 OnMouseMove (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4292 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4297 case Msg.WM_MOUSE_ENTER: {
4302 OnMouseEnter(EventArgs.Empty);
4306 case Msg.WM_MOUSE_LEAVE: {
4308 OnMouseLeave(EventArgs.Empty);
4312 case Msg.WM_MOUSEHOVER: {
4313 OnMouseHover(EventArgs.Empty);
4317 case Msg.WM_SYSKEYUP: {
4318 if (ProcessKeyMessage(ref m)) {
4319 m.Result = IntPtr.Zero;
4323 if ((m.WParam.ToInt32() & (int)Keys.KeyCode) == (int)Keys.Menu) {
4327 if (form != null && form.ActiveMenu != null) {
4328 form.ActiveMenu.ProcessCmdKey(ref m, (Keys)m.WParam.ToInt32());
4336 case Msg.WM_SYSKEYDOWN:
4337 case Msg.WM_KEYDOWN:
4339 case Msg.WM_SYSCHAR:
4341 if (ProcessKeyMessage(ref m)) {
4342 m.Result = IntPtr.Zero;
4351 if (m.LParam != IntPtr.Zero) {
4354 hi = new HELPINFO();
4356 hi = (HELPINFO) Marshal.PtrToStructure (m.LParam, typeof (HELPINFO));
4357 mouse_pos = new Point(hi.MousePos.x, hi.MousePos.y);
4359 mouse_pos = Control.MousePosition;
4361 OnHelpRequested(new HelpEventArgs(mouse_pos));
4362 m.Result = (IntPtr)1;
4366 case Msg.WM_KILLFOCUS: {
4367 this.has_focus = false;
4368 OnLostFocusInternal (EventArgs.Empty);
4372 case Msg.WM_SETFOCUS: {
4374 this.has_focus = true;
4375 OnGotFocusInternal (EventArgs.Empty);
4380 case Msg.WM_SYSCOLORCHANGE: {
4381 ThemeEngine.Current.ResetDefaults();
4382 OnSystemColorsChanged(EventArgs.Empty);
4386 case Msg.WM_SETCURSOR: {
4387 if ((cursor == null) || ((HitTest)(m.LParam.ToInt32() & 0xffff) != HitTest.HTCLIENT)) {
4392 XplatUI.SetCursor(window.Handle, cursor.handle);
4393 m.Result = (IntPtr)1;
4403 #endregion // Public Instance Methods
4405 #region OnXXX methods
4406 [EditorBrowsable(EditorBrowsableState.Advanced)]
4407 protected virtual void OnBackColorChanged(EventArgs e) {
4408 EventHandler eh = (EventHandler)(Events [BackColorChangedEvent]);
4411 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackColorChanged(e);
4414 [EditorBrowsable(EditorBrowsableState.Advanced)]
4415 protected virtual void OnBackgroundImageChanged(EventArgs e) {
4416 EventHandler eh = (EventHandler)(Events [BackgroundImageChangedEvent]);
4419 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackgroundImageChanged(e);
4422 [EditorBrowsable(EditorBrowsableState.Advanced)]
4423 protected virtual void OnBindingContextChanged(EventArgs e) {
4424 CheckDataBindings ();
4425 EventHandler eh = (EventHandler)(Events [BindingContextChangedEvent]);
4428 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBindingContextChanged(e);
4431 [EditorBrowsable(EditorBrowsableState.Advanced)]
4432 protected virtual void OnCausesValidationChanged(EventArgs e) {
4433 EventHandler eh = (EventHandler)(Events [CausesValidationChangedEvent]);
4438 [EditorBrowsable(EditorBrowsableState.Advanced)]
4439 protected virtual void OnChangeUICues(UICuesEventArgs e) {
4440 UICuesEventHandler eh = (UICuesEventHandler)(Events [ChangeUICuesEvent]);
4445 [EditorBrowsable(EditorBrowsableState.Advanced)]
4446 protected virtual void OnClick(EventArgs e) {
4447 EventHandler eh = (EventHandler)(Events [ClickEvent]);
4452 [EditorBrowsable(EditorBrowsableState.Advanced)]
4453 protected virtual void OnContextMenuChanged(EventArgs e) {
4454 EventHandler eh = (EventHandler)(Events [ContextMenuChangedEvent]);
4459 [EditorBrowsable(EditorBrowsableState.Advanced)]
4460 protected virtual void OnControlAdded(ControlEventArgs e) {
4461 ControlEventHandler eh = (ControlEventHandler)(Events [ControlAddedEvent]);
4466 [EditorBrowsable(EditorBrowsableState.Advanced)]
4467 protected virtual void OnControlRemoved(ControlEventArgs e) {
4468 ControlEventHandler eh = (ControlEventHandler)(Events [ControlRemovedEvent]);
4473 [EditorBrowsable(EditorBrowsableState.Advanced)]
4474 protected virtual void OnCreateControl() {
4478 [EditorBrowsable(EditorBrowsableState.Advanced)]
4479 protected virtual void OnCursorChanged(EventArgs e) {
4480 EventHandler eh = (EventHandler)(Events [CursorChangedEvent]);
4485 [EditorBrowsable(EditorBrowsableState.Advanced)]
4486 protected virtual void OnDockChanged(EventArgs e) {
4487 EventHandler eh = (EventHandler)(Events [DockChangedEvent]);
4492 [EditorBrowsable(EditorBrowsableState.Advanced)]
4493 protected virtual void OnDoubleClick(EventArgs e) {
4494 EventHandler eh = (EventHandler)(Events [DoubleClickEvent]);
4499 [EditorBrowsable(EditorBrowsableState.Advanced)]
4500 protected virtual void OnDragDrop(DragEventArgs drgevent) {
4501 DragEventHandler eh = (DragEventHandler)(Events [DragDropEvent]);
4503 eh (this, drgevent);
4506 [EditorBrowsable(EditorBrowsableState.Advanced)]
4507 protected virtual void OnDragEnter(DragEventArgs drgevent) {
4508 DragEventHandler eh = (DragEventHandler)(Events [DragEnterEvent]);
4510 eh (this, drgevent);
4513 [EditorBrowsable(EditorBrowsableState.Advanced)]
4514 protected virtual void OnDragLeave(EventArgs e) {
4515 EventHandler eh = (EventHandler)(Events [DragLeaveEvent]);
4520 [EditorBrowsable(EditorBrowsableState.Advanced)]
4521 protected virtual void OnDragOver(DragEventArgs drgevent) {
4522 DragEventHandler eh = (DragEventHandler)(Events [DragOverEvent]);
4524 eh (this, drgevent);
4527 [EditorBrowsable(EditorBrowsableState.Advanced)]
4528 protected virtual void OnEnabledChanged(EventArgs e) {
4529 if (IsHandleCreated) {
4531 if (((Form)this).context == null) {
4532 XplatUI.EnableWindow(window.Handle, Enabled);
4535 XplatUI.EnableWindow(window.Handle, Enabled);
4540 EventHandler eh = (EventHandler)(Events [EnabledChangedEvent]);
4544 for (int i=0; i<child_controls.Count; i++) {
4545 child_controls[i].OnParentEnabledChanged(e);
4549 [EditorBrowsable(EditorBrowsableState.Advanced)]
4550 protected virtual void OnEnter(EventArgs e) {
4551 EventHandler eh = (EventHandler)(Events [EnterEvent]);
4556 [EditorBrowsable(EditorBrowsableState.Advanced)]
4557 protected virtual void OnFontChanged(EventArgs e) {
4558 EventHandler eh = (EventHandler)(Events [FontChangedEvent]);
4561 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentFontChanged(e);
4564 [EditorBrowsable(EditorBrowsableState.Advanced)]
4565 protected virtual void OnForeColorChanged(EventArgs e) {
4566 EventHandler eh = (EventHandler)(Events [ForeColorChangedEvent]);
4569 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentForeColorChanged(e);
4572 [EditorBrowsable(EditorBrowsableState.Advanced)]
4573 protected virtual void OnGiveFeedback(GiveFeedbackEventArgs gfbevent) {
4574 GiveFeedbackEventHandler eh = (GiveFeedbackEventHandler)(Events [GiveFeedbackEvent]);
4576 eh (this, gfbevent);
4579 [EditorBrowsable(EditorBrowsableState.Advanced)]
4580 protected virtual void OnGotFocus(EventArgs e) {
4581 EventHandler eh = (EventHandler)(Events [GotFocusEvent]);
4586 [EditorBrowsable(EditorBrowsableState.Advanced)]
4587 protected virtual void OnHandleCreated(EventArgs e) {
4588 EventHandler eh = (EventHandler)(Events [HandleCreatedEvent]);
4593 [EditorBrowsable(EditorBrowsableState.Advanced)]
4594 protected virtual void OnHandleDestroyed(EventArgs e) {
4595 EventHandler eh = (EventHandler)(Events [HandleDestroyedEvent]);
4600 [EditorBrowsable(EditorBrowsableState.Advanced)]
4601 protected virtual void OnHelpRequested(HelpEventArgs hevent) {
4602 HelpEventHandler eh = (HelpEventHandler)(Events [HelpRequestedEvent]);
4607 protected virtual void OnImeModeChanged(EventArgs e) {
4608 EventHandler eh = (EventHandler)(Events [ImeModeChangedEvent]);
4613 [EditorBrowsable(EditorBrowsableState.Advanced)]
4614 protected virtual void OnInvalidated(InvalidateEventArgs e) {
4615 if (ThemeEngine.Current.DoubleBufferingSupported)
4616 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
4617 // should this block be here? seems like it
4618 // would be more at home in
4619 // NotifyInvalidated..
4620 if (e.InvalidRect == ClientRectangle) {
4621 InvalidateBackBuffer ();
4624 // we need this Inflate call here so
4625 // that the border of the rectangle is
4626 // considered Visible (the
4627 // invalid_region.IsVisible call) in
4628 // the WM_PAINT handling below.
4629 Rectangle r = Rectangle.Inflate(e.InvalidRect, 1,1);
4630 if (invalid_region == null)
4631 invalid_region = new Region (r);
4633 invalid_region.Union (r);
4637 InvalidateEventHandler eh = (InvalidateEventHandler)(Events [InvalidatedEvent]);
4642 [EditorBrowsable(EditorBrowsableState.Advanced)]
4643 protected virtual void OnKeyDown(KeyEventArgs e) {
4644 KeyEventHandler eh = (KeyEventHandler)(Events [KeyDownEvent]);
4649 [EditorBrowsable(EditorBrowsableState.Advanced)]
4650 protected virtual void OnKeyPress(KeyPressEventArgs e) {
4651 KeyPressEventHandler eh = (KeyPressEventHandler)(Events [KeyPressEvent]);
4656 [EditorBrowsable(EditorBrowsableState.Advanced)]
4657 protected virtual void OnKeyUp(KeyEventArgs e) {
4658 KeyEventHandler eh = (KeyEventHandler)(Events [KeyUpEvent]);
4663 [EditorBrowsable(EditorBrowsableState.Advanced)]
4664 protected virtual void OnLayout(LayoutEventArgs levent) {
4665 LayoutEventHandler eh = (LayoutEventHandler)(Events [LayoutEvent]);
4670 [EditorBrowsable(EditorBrowsableState.Advanced)]
4671 protected virtual void OnLeave(EventArgs e) {
4672 EventHandler eh = (EventHandler)(Events [LeaveEvent]);
4677 [EditorBrowsable(EditorBrowsableState.Advanced)]
4678 protected virtual void OnLocationChanged(EventArgs e) {
4680 EventHandler eh = (EventHandler)(Events [LocationChangedEvent]);
4685 [EditorBrowsable(EditorBrowsableState.Advanced)]
4686 protected virtual void OnLostFocus(EventArgs e) {
4687 EventHandler eh = (EventHandler)(Events [LostFocusEvent]);
4692 [EditorBrowsable(EditorBrowsableState.Advanced)]
4693 protected virtual void OnMouseDown(MouseEventArgs e) {
4694 MouseEventHandler eh = (MouseEventHandler)(Events [MouseDownEvent]);
4699 [EditorBrowsable(EditorBrowsableState.Advanced)]
4700 protected virtual void OnMouseEnter(EventArgs e) {
4701 EventHandler eh = (EventHandler)(Events [MouseEnterEvent]);
4706 [EditorBrowsable(EditorBrowsableState.Advanced)]
4707 protected virtual void OnMouseHover(EventArgs e) {
4708 EventHandler eh = (EventHandler)(Events [MouseHoverEvent]);
4713 [EditorBrowsable(EditorBrowsableState.Advanced)]
4714 protected virtual void OnMouseLeave(EventArgs e) {
4715 EventHandler eh = (EventHandler)(Events [MouseLeaveEvent]);
4720 [EditorBrowsable(EditorBrowsableState.Advanced)]
4721 protected virtual void OnMouseMove(MouseEventArgs e) {
4722 MouseEventHandler eh = (MouseEventHandler)(Events [MouseMoveEvent]);
4727 [EditorBrowsable(EditorBrowsableState.Advanced)]
4728 protected virtual void OnMouseUp(MouseEventArgs e) {
4729 MouseEventHandler eh = (MouseEventHandler)(Events [MouseUpEvent]);
4734 [EditorBrowsable(EditorBrowsableState.Advanced)]
4735 protected virtual void OnMouseWheel(MouseEventArgs e) {
4736 MouseEventHandler eh = (MouseEventHandler)(Events [MouseWheelEvent]);
4741 [EditorBrowsable(EditorBrowsableState.Advanced)]
4742 protected virtual void OnMove(EventArgs e) {
4743 EventHandler eh = (EventHandler)(Events [MoveEvent]);
4748 [EditorBrowsable(EditorBrowsableState.Advanced)]
4749 protected virtual void OnNotifyMessage(Message m) {
4753 [EditorBrowsable(EditorBrowsableState.Advanced)]
4754 protected virtual void OnPaint(PaintEventArgs e) {
4755 PaintEventHandler eh = (PaintEventHandler)(Events [PaintEvent]);
4760 internal virtual void OnPaintBackgroundInternal(PaintEventArgs e) {
4764 internal virtual void OnPaintInternal(PaintEventArgs e) {
4768 internal virtual void OnGotFocusInternal (EventArgs e)
4773 internal virtual void OnLostFocusInternal (EventArgs e)
4778 [EditorBrowsable(EditorBrowsableState.Advanced)]
4779 protected virtual void OnPaintBackground(PaintEventArgs pevent) {
4780 PaintControlBackground (pevent);
4783 [EditorBrowsable(EditorBrowsableState.Advanced)]
4784 protected virtual void OnParentBackColorChanged(EventArgs e) {
4785 if (background_color.IsEmpty && background_image==null) {
4787 OnBackColorChanged(e);
4791 [EditorBrowsable(EditorBrowsableState.Advanced)]
4792 protected virtual void OnParentBackgroundImageChanged(EventArgs e) {
4793 if (background_color.IsEmpty && background_image==null) {
4795 OnBackgroundImageChanged(e);
4799 [EditorBrowsable(EditorBrowsableState.Advanced)]
4800 protected virtual void OnParentBindingContextChanged(EventArgs e) {
4801 if (binding_context==null) {
4802 binding_context=Parent.binding_context;
4803 OnBindingContextChanged(e);
4807 [EditorBrowsable(EditorBrowsableState.Advanced)]
4808 protected virtual void OnParentChanged(EventArgs e) {
4809 EventHandler eh = (EventHandler)(Events [ParentChangedEvent]);
4814 [EditorBrowsable(EditorBrowsableState.Advanced)]
4815 protected virtual void OnParentEnabledChanged(EventArgs e) {
4817 OnEnabledChanged(e);
4821 [EditorBrowsable(EditorBrowsableState.Advanced)]
4822 protected virtual void OnParentFontChanged(EventArgs e) {
4829 [EditorBrowsable(EditorBrowsableState.Advanced)]
4830 protected virtual void OnParentForeColorChanged(EventArgs e) {
4831 if (foreground_color.IsEmpty) {
4833 OnForeColorChanged(e);
4837 [EditorBrowsable(EditorBrowsableState.Advanced)]
4838 protected virtual void OnParentRightToLeftChanged(EventArgs e) {
4839 if (right_to_left==RightToLeft.Inherit) {
4841 OnRightToLeftChanged(e);
4845 [EditorBrowsable(EditorBrowsableState.Advanced)]
4846 protected virtual void OnParentVisibleChanged(EventArgs e) {
4848 OnVisibleChanged(e);
4852 [EditorBrowsable(EditorBrowsableState.Advanced)]
4853 protected virtual void OnQueryContinueDrag(QueryContinueDragEventArgs e) {
4854 QueryContinueDragEventHandler eh = (QueryContinueDragEventHandler)(Events [QueryContinueDragEvent]);
4859 [EditorBrowsable(EditorBrowsableState.Advanced)]
4860 protected virtual void OnResize(EventArgs e) {
4861 EventHandler eh = (EventHandler)(Events [ResizeEvent]);
4865 PerformLayout(this, "bounds");
4867 if (parent != null) {
4868 parent.PerformLayout();
4872 [EditorBrowsable(EditorBrowsableState.Advanced)]
4873 protected virtual void OnRightToLeftChanged(EventArgs e) {
4874 EventHandler eh = (EventHandler)(Events [RightToLeftChangedEvent]);
4877 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentRightToLeftChanged(e);
4880 [EditorBrowsable(EditorBrowsableState.Advanced)]
4881 protected virtual void OnSizeChanged(EventArgs e) {
4882 DisposeBackBuffer ();
4884 EventHandler eh = (EventHandler)(Events [SizeChangedEvent]);
4889 [EditorBrowsable(EditorBrowsableState.Advanced)]
4890 protected virtual void OnStyleChanged(EventArgs e) {
4891 EventHandler eh = (EventHandler)(Events [StyleChangedEvent]);
4896 [EditorBrowsable(EditorBrowsableState.Advanced)]
4897 protected virtual void OnSystemColorsChanged(EventArgs e) {
4898 EventHandler eh = (EventHandler)(Events [SystemColorsChangedEvent]);
4903 [EditorBrowsable(EditorBrowsableState.Advanced)]
4904 protected virtual void OnTabIndexChanged(EventArgs e) {
4905 EventHandler eh = (EventHandler)(Events [TabIndexChangedEvent]);
4910 [EditorBrowsable(EditorBrowsableState.Advanced)]
4911 protected virtual void OnTabStopChanged(EventArgs e) {
4912 EventHandler eh = (EventHandler)(Events [TabStopChangedEvent]);
4917 [EditorBrowsable(EditorBrowsableState.Advanced)]
4918 protected virtual void OnTextChanged(EventArgs e) {
4919 EventHandler eh = (EventHandler)(Events [TextChangedEvent]);
4924 [EditorBrowsable(EditorBrowsableState.Advanced)]
4925 protected virtual void OnValidated(EventArgs e) {
4926 EventHandler eh = (EventHandler)(Events [ValidatedEvent]);
4931 [EditorBrowsable(EditorBrowsableState.Advanced)]
4932 protected virtual void OnValidating(System.ComponentModel.CancelEventArgs e) {
4933 CancelEventHandler eh = (CancelEventHandler)(Events [ValidatingEvent]);
4938 [EditorBrowsable(EditorBrowsableState.Advanced)]
4939 protected virtual void OnVisibleChanged(EventArgs e) {
4940 if ((parent != null) && !Created && Visible) {
4947 EventHandler eh = (EventHandler)(Events [VisibleChangedEvent]);
4951 // We need to tell our kids
4952 for (int i=0; i<child_controls.Count; i++) {
4953 if (child_controls[i].Visible) {
4954 child_controls[i].OnParentVisibleChanged(e);
4958 #endregion // OnXXX methods
4961 static object BackColorChangedEvent = new object ();
4962 static object BackgroundImageChangedEvent = new object ();
4963 static object BindingContextChangedEvent = new object ();
4964 static object CausesValidationChangedEvent = new object ();
4965 static object ChangeUICuesEvent = new object ();
4966 static object ClickEvent = new object ();
4967 static object ContextMenuChangedEvent = new object ();
4968 static object ControlAddedEvent = new object ();
4969 static object ControlRemovedEvent = new object ();
4970 static object CursorChangedEvent = new object ();
4971 static object DockChangedEvent = new object ();
4972 static object DoubleClickEvent = new object ();
4973 static object DragDropEvent = new object ();
4974 static object DragEnterEvent = new object ();
4975 static object DragLeaveEvent = new object ();
4976 static object DragOverEvent = new object ();
4977 static object EnabledChangedEvent = new object ();
4978 static object EnterEvent = new object ();
4979 static object FontChangedEvent = new object ();
4980 static object ForeColorChangedEvent = new object ();
4981 static object GiveFeedbackEvent = new object ();
4982 static object GotFocusEvent = new object ();
4983 static object HandleCreatedEvent = new object ();
4984 static object HandleDestroyedEvent = new object ();
4985 static object HelpRequestedEvent = new object ();
4986 static object ImeModeChangedEvent = new object ();
4987 static object InvalidatedEvent = new object ();
4988 static object KeyDownEvent = new object ();
4989 static object KeyPressEvent = new object ();
4990 static object KeyUpEvent = new object ();
4991 static object LayoutEvent = new object ();
4992 static object LeaveEvent = new object ();
4993 static object LocationChangedEvent = new object ();
4994 static object LostFocusEvent = new object ();
4995 static object MouseDownEvent = new object ();
4996 static object MouseEnterEvent = new object ();
4997 static object MouseHoverEvent = new object ();
4998 static object MouseLeaveEvent = new object ();
4999 static object MouseMoveEvent = new object ();
5000 static object MouseUpEvent = new object ();
5001 static object MouseWheelEvent = new object ();
5002 static object MoveEvent = new object ();
5003 static object PaintEvent = new object ();
5004 static object ParentChangedEvent = new object ();
5005 static object QueryAccessibilityHelpEvent = new object ();
5006 static object QueryContinueDragEvent = new object ();
5007 static object ResizeEvent = new object ();
5008 static object RightToLeftChangedEvent = new object ();
5009 static object SizeChangedEvent = new object ();
5010 static object StyleChangedEvent = new object ();
5011 static object SystemColorsChangedEvent = new object ();
5012 static object TabIndexChangedEvent = new object ();
5013 static object TabStopChangedEvent = new object ();
5014 static object TextChangedEvent = new object ();
5015 static object ValidatedEvent = new object ();
5016 static object ValidatingEvent = new object ();
5017 static object VisibleChangedEvent = new object ();
5019 public event EventHandler BackColorChanged {
5020 add { Events.AddHandler (BackColorChangedEvent, value); }
5021 remove { Events.RemoveHandler (BackColorChangedEvent, value); }
5024 public event EventHandler BackgroundImageChanged {
5025 add { Events.AddHandler (BackgroundImageChangedEvent, value); }
5026 remove { Events.RemoveHandler (BackgroundImageChangedEvent, value); }
5029 public event EventHandler BindingContextChanged {
5030 add { Events.AddHandler (BindingContextChangedEvent, value); }
5031 remove { Events.RemoveHandler (BindingContextChangedEvent, value); }
5034 public event EventHandler CausesValidationChanged {
5035 add { Events.AddHandler (CausesValidationChangedEvent, value); }
5036 remove { Events.RemoveHandler (CausesValidationChangedEvent, value); }
5039 public event UICuesEventHandler ChangeUICues {
5040 add { Events.AddHandler (ChangeUICuesEvent, value); }
5041 remove { Events.RemoveHandler (ChangeUICuesEvent, value); }
5044 public event EventHandler Click {
5045 add { Events.AddHandler (ClickEvent, value); }
5046 remove { Events.RemoveHandler (ClickEvent, value); }
5051 public event EventHandler ContextMenuChanged {
5052 add { Events.AddHandler (ContextMenuChangedEvent, value); }
5053 remove { Events.RemoveHandler (ContextMenuChangedEvent, value); }
5056 [EditorBrowsable(EditorBrowsableState.Advanced)]
5062 public event ControlEventHandler ControlAdded {
5063 add { Events.AddHandler (ControlAddedEvent, value); }
5064 remove { Events.RemoveHandler (ControlAddedEvent, value); }
5067 [EditorBrowsable(EditorBrowsableState.Advanced)]
5073 public event ControlEventHandler ControlRemoved {
5074 add { Events.AddHandler (ControlRemovedEvent, value); }
5075 remove { Events.RemoveHandler (ControlRemovedEvent, value); }
5078 [MWFDescription("Fired when the cursor for the control has been changed"), MWFCategory("PropertyChanged")]
5079 public event EventHandler CursorChanged {
5080 add { Events.AddHandler (CursorChangedEvent, value); }
5081 remove { Events.RemoveHandler (CursorChangedEvent, value); }
5083 public event EventHandler DockChanged {
5084 add { Events.AddHandler (DockChangedEvent, value); }
5085 remove { Events.RemoveHandler (DockChangedEvent, value); }
5088 public event EventHandler DoubleClick {
5089 add { Events.AddHandler (DoubleClickEvent, value); }
5090 remove { Events.RemoveHandler (DoubleClickEvent, value); }
5093 public event DragEventHandler DragDrop {
5094 add { Events.AddHandler (DragDropEvent, value); }
5095 remove { Events.RemoveHandler (DragDropEvent, value); }
5098 public event DragEventHandler DragEnter {
5099 add { Events.AddHandler (DragEnterEvent, value); }
5100 remove { Events.RemoveHandler (DragEnterEvent, value); }
5103 public event EventHandler DragLeave {
5104 add { Events.AddHandler (DragLeaveEvent, value); }
5105 remove { Events.RemoveHandler (DragLeaveEvent, value); }
5108 public event DragEventHandler DragOver {
5109 add { Events.AddHandler (DragOverEvent, value); }
5110 remove { Events.RemoveHandler (DragOverEvent, value); }
5113 public event EventHandler EnabledChanged {
5114 add { Events.AddHandler (EnabledChangedEvent, value); }
5115 remove { Events.RemoveHandler (EnabledChangedEvent, value); }
5118 public event EventHandler Enter {
5119 add { Events.AddHandler (EnterEvent, value); }
5120 remove { Events.RemoveHandler (EnterEvent, value); }
5123 public event EventHandler FontChanged {
5124 add { Events.AddHandler (FontChangedEvent, value); }
5125 remove { Events.RemoveHandler (FontChangedEvent, value); }
5128 public event EventHandler ForeColorChanged {
5129 add { Events.AddHandler (ForeColorChangedEvent, value); }
5130 remove { Events.RemoveHandler (ForeColorChangedEvent, value); }
5133 public event GiveFeedbackEventHandler GiveFeedback {
5134 add { Events.AddHandler (GiveFeedbackEvent, value); }
5135 remove { Events.RemoveHandler (GiveFeedbackEvent, value); }
5138 [EditorBrowsable(EditorBrowsableState.Advanced)]
5140 public event EventHandler GotFocus {
5141 add { Events.AddHandler (GotFocusEvent, value); }
5142 remove { Events.RemoveHandler (GotFocusEvent, value); }
5146 [EditorBrowsable(EditorBrowsableState.Advanced)]
5148 public event EventHandler HandleCreated {
5149 add { Events.AddHandler (HandleCreatedEvent, value); }
5150 remove { Events.RemoveHandler (HandleCreatedEvent, value); }
5153 [EditorBrowsable(EditorBrowsableState.Advanced)]
5155 public event EventHandler HandleDestroyed {
5156 add { Events.AddHandler (HandleDestroyedEvent, value); }
5157 remove { Events.RemoveHandler (HandleDestroyedEvent, value); }
5160 public event HelpEventHandler HelpRequested {
5161 add { Events.AddHandler (HelpRequestedEvent, value); }
5162 remove { Events.RemoveHandler (HelpRequestedEvent, value); }
5165 public event EventHandler ImeModeChanged {
5166 add { Events.AddHandler (ImeModeChangedEvent, value); }
5167 remove { Events.RemoveHandler (ImeModeChangedEvent, value); }
5170 [EditorBrowsable(EditorBrowsableState.Advanced)]
5172 public event InvalidateEventHandler Invalidated {
5173 add { Events.AddHandler (InvalidatedEvent, value); }
5174 remove { Events.RemoveHandler (InvalidatedEvent, value); }
5177 public event KeyEventHandler KeyDown {
5178 add { Events.AddHandler (KeyDownEvent, value); }
5179 remove { Events.RemoveHandler (KeyDownEvent, value); }
5182 public event KeyPressEventHandler KeyPress {
5183 add { Events.AddHandler (KeyPressEvent, value); }
5184 remove { Events.RemoveHandler (KeyPressEvent, value); }
5187 public event KeyEventHandler KeyUp {
5188 add { Events.AddHandler (KeyUpEvent, value); }
5189 remove { Events.RemoveHandler (KeyUpEvent, value); }
5192 public event LayoutEventHandler Layout {
5193 add { Events.AddHandler (LayoutEvent, value); }
5194 remove { Events.RemoveHandler (LayoutEvent, value); }
5197 public event EventHandler Leave {
5198 add { Events.AddHandler (LeaveEvent, value); }
5199 remove { Events.RemoveHandler (LeaveEvent, value); }
5202 public event EventHandler LocationChanged {
5203 add { Events.AddHandler (LocationChangedEvent, value); }
5204 remove { Events.RemoveHandler (LocationChangedEvent, value); }
5207 [EditorBrowsable(EditorBrowsableState.Advanced)]
5209 public event EventHandler LostFocus {
5210 add { Events.AddHandler (LostFocusEvent, value); }
5211 remove { Events.RemoveHandler (LostFocusEvent, value); }
5214 public event MouseEventHandler MouseDown {
5215 add { Events.AddHandler (MouseDownEvent, value); }
5216 remove { Events.RemoveHandler (MouseDownEvent, value); }
5219 public event EventHandler MouseEnter {
5220 add { Events.AddHandler (MouseEnterEvent, value); }
5221 remove { Events.RemoveHandler (MouseEnterEvent, value); }
5224 public event EventHandler MouseHover {
5225 add { Events.AddHandler (MouseHoverEvent, value); }
5226 remove { Events.RemoveHandler (MouseHoverEvent, value); }
5229 public event EventHandler MouseLeave {
5230 add { Events.AddHandler (MouseLeaveEvent, value); }
5231 remove { Events.RemoveHandler (MouseLeaveEvent, value); }
5234 public event MouseEventHandler MouseMove {
5235 add { Events.AddHandler (MouseMoveEvent, value); }
5236 remove { Events.RemoveHandler (MouseMoveEvent, value); }
5239 public event MouseEventHandler MouseUp {
5240 add { Events.AddHandler (MouseUpEvent, value); }
5241 remove { Events.RemoveHandler (MouseUpEvent, value); }
5244 [EditorBrowsable(EditorBrowsableState.Advanced)]
5246 public event MouseEventHandler MouseWheel {
5247 add { Events.AddHandler (MouseWheelEvent, value); }
5248 remove { Events.RemoveHandler (MouseWheelEvent, value); }
5251 public event EventHandler Move {
5252 add { Events.AddHandler (MoveEvent, value); }
5253 remove { Events.RemoveHandler (MoveEvent, value); }
5256 public event PaintEventHandler Paint {
5257 add { Events.AddHandler (PaintEvent, value); }
5258 remove { Events.RemoveHandler (PaintEvent, value); }
5261 public event EventHandler ParentChanged {
5262 add { Events.AddHandler (ParentChangedEvent, value); }
5263 remove { Events.RemoveHandler (ParentChangedEvent, value); }
5266 public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp {
5267 add { Events.AddHandler (QueryAccessibilityHelpEvent, value); }
5268 remove { Events.RemoveHandler (QueryAccessibilityHelpEvent, value); }
5271 public event QueryContinueDragEventHandler QueryContinueDrag {
5272 add { Events.AddHandler (QueryContinueDragEvent, value); }
5273 remove { Events.RemoveHandler (QueryContinueDragEvent, value); }
5277 [EditorBrowsable (EditorBrowsableState.Advanced)]
5279 public event EventHandler Resize {
5280 add { Events.AddHandler (ResizeEvent, value); }
5281 remove { Events.RemoveHandler (ResizeEvent, value); }
5284 public event EventHandler RightToLeftChanged {
5285 add { Events.AddHandler (RightToLeftChangedEvent, value); }
5286 remove { Events.RemoveHandler (RightToLeftChangedEvent, value); }
5289 public event EventHandler SizeChanged {
5290 add { Events.AddHandler (SizeChangedEvent, value); }
5291 remove { Events.RemoveHandler (SizeChangedEvent, value); }
5294 public event EventHandler StyleChanged {
5295 add { Events.AddHandler (StyleChangedEvent, value); }
5296 remove { Events.RemoveHandler (StyleChangedEvent, value); }
5299 public event EventHandler SystemColorsChanged {
5300 add { Events.AddHandler (SystemColorsChangedEvent, value); }
5301 remove { Events.RemoveHandler (SystemColorsChangedEvent, value); }
5304 public event EventHandler TabIndexChanged {
5305 add { Events.AddHandler (TabIndexChangedEvent, value); }
5306 remove { Events.RemoveHandler (TabIndexChangedEvent, value); }
5309 public event EventHandler TabStopChanged {
5310 add { Events.AddHandler (TabStopChangedEvent, value); }
5311 remove { Events.RemoveHandler (TabStopChangedEvent, value); }
5314 public event EventHandler TextChanged {
5315 add { Events.AddHandler (TextChangedEvent, value); }
5316 remove { Events.RemoveHandler (TextChangedEvent, value); }
5319 public event EventHandler Validated {
5320 add { Events.AddHandler (ValidatedEvent, value); }
5321 remove { Events.RemoveHandler (ValidatedEvent, value); }
5324 public event CancelEventHandler Validating {
5325 add { Events.AddHandler (ValidatingEvent, value); }
5326 remove { Events.RemoveHandler (ValidatingEvent, value); }
5329 public event EventHandler VisibleChanged {
5330 add { Events.AddHandler (VisibleChangedEvent, value); }
5331 remove { Events.RemoveHandler (VisibleChangedEvent, value); }
5334 #endregion // Events