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 , IBindableComponent, IDropTarget
67 #region Local Variables
70 internal Rectangle bounds; // bounding rectangle for control (client area + decorations)
71 Rectangle explicit_bounds; // explicitly set bounds
72 internal object creator_thread; // thread that created the control
73 internal ControlNativeWindow window; // object for native window handle
74 string name; // for object naming
77 bool is_created; // true if OnCreateControl has been sent
78 internal bool has_focus; // true if control has focus
79 internal bool is_visible; // true if control is visible
80 internal bool is_entered; // is the mouse inside the control?
81 internal bool is_enabled; // true if control is enabled (usable/not grayed out)
82 bool is_accessible; // true if the control is visible to accessibility applications
83 bool is_captured; // tracks if the control has captured the mouse
84 internal bool is_toplevel; // tracks if the control is a toplevel window
85 bool is_recreating; // tracks if the handle for the control is being recreated
86 bool causes_validation; // tracks if validation is executed on changes
87 bool is_focusing; // tracks if Focus has been called on the control and has not yet finished
88 bool container_selected; // true if Select() or Focus() is called on a container, to prevent child controls from raising their GotFocus event
89 int tab_index; // position in tab order of siblings
90 bool tab_stop; // is the control a tab stop?
91 bool is_disposed; // has the window already been disposed?
92 Size client_size; // size of the client area (window excluding decorations)
93 Rectangle client_rect; // rectangle with the client area (window excluding decorations)
94 ControlStyles control_style; // rather win32-specific, style bits for control
96 bool layout_pending; // true if our parent needs to re-layout us
97 object control_tag; // object that contains data about our control
98 internal int mouse_clicks; // Counter for mouse clicks
99 Cursor cursor; // Cursor for the window
100 internal bool allow_drop; // true if the control accepts droping objects on it
101 Region clip_region; // User-specified clip region for the window
104 internal Color foreground_color; // foreground color for control
105 internal Color background_color; // background color for control
106 Image background_image; // background image for control
107 internal Font font; // font for control
108 string text; // window/title text for control
109 internal BorderStyle border_style; // Border style of control
112 int layout_suspended;
113 internal AnchorStyles anchor_style; // anchoring requirements for our control
114 internal DockStyle dock_style; // docking requirements for our control (supercedes anchoring)
116 // Please leave the next 4 as internal until DefaultLayout (2.0) is rewritten
117 internal int dist_left; // distance to the left border of the parent
118 internal int dist_top; // distance to the top border of the parent
119 internal int dist_right; // distance to the right border of the parent
120 internal int dist_bottom; // distance to the bottom border of the parent
122 // to be categorized...
123 ControlCollection child_controls; // our children
124 Control parent; // our parent control
125 AccessibleObject accessibility_object; // object that contains accessibility information about our control
126 BindingContext binding_context;
127 RightToLeft right_to_left; // drawing direction for control
128 ContextMenu context_menu; // Context menu associated with the control
131 Graphics backbuffer_dc;
133 Region invalid_region;
135 ControlBindingsCollection data_bindings;
138 internal bool use_compatible_text_rendering;
139 static bool verify_thread_handle;
141 ImageLayout backgroundimage_layout;
146 Layout.LayoutEngine layout_engine;
147 private ContextMenuStrip context_menu_strip;
150 #endregion // Local Variables
152 #region Private Classes
153 // This helper class allows us to dispatch messages to Control.WndProc
154 internal class ControlNativeWindow : NativeWindow {
155 private Control owner;
157 public ControlNativeWindow(Control control) : base() {
162 public Control Owner {
168 static internal Control ControlFromHandle(IntPtr hWnd) {
169 ControlNativeWindow window;
171 window = (ControlNativeWindow)window_collection[hWnd];
172 if (window != null) {
179 static internal Control ControlFromChildHandle (IntPtr handle) {
180 ControlNativeWindow window;
182 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
183 while (hwnd != null) {
184 window = (ControlNativeWindow)window_collection[hwnd.Handle];
185 if (window != null) {
194 protected override void WndProc(ref Message m) {
195 owner.WndProc(ref m);
200 #region Public Classes
202 public class ControlAccessibleObject : AccessibleObject {
205 #region ControlAccessibleObject Constructors
206 public ControlAccessibleObject(Control ownerControl)
207 : base (ownerControl)
209 this.owner = ownerControl;
211 #endregion // ControlAccessibleObject Constructors
213 #region ControlAccessibleObject Public Instance Properties
214 public override string DefaultAction {
216 return base.DefaultAction;
220 public override string Description {
222 return base.Description;
226 public IntPtr Handle {
232 // We don't want to let them set it
236 public override string Help {
242 public override string KeyboardShortcut {
244 return base.KeyboardShortcut;
248 public override string Name {
258 public Control Owner {
264 public override AccessibleObject Parent {
271 public override AccessibleRole Role {
276 #endregion // ControlAccessibleObject Public Instance Properties
278 #region ControlAccessibleObject Public Instance Methods
279 public override int GetHelpTopic(out string FileName) {
280 return base.GetHelpTopic (out FileName);
283 [MonoTODO("Implement this and tie it into Control.AccessibilityNotifyClients")]
284 public void NotifyClients(AccessibleEvents accEvent) {
285 throw new NotImplementedException();
288 [MonoTODO("Implement this and tie it into Control.AccessibilityNotifyClients")]
289 public void NotifyClients(AccessibleEvents accEvent, int childID) {
290 throw new NotImplementedException();
293 public override string ToString() {
294 return "ControlAccessibleObject: Owner = " + owner.ToString() + ", Text: " + owner.text;
297 #endregion // ControlAccessibleObject Public Instance Methods
303 [DesignerSerializer("System.Windows.Forms.Design.ControlCollectionCodeDomSerializer, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
305 [ListBindable(false)]
306 public class ControlCollection : IList, ICollection, ICloneable, IEnumerable {
307 #region ControlCollection Local Variables
310 Control[] all_controls;
312 #endregion // ControlCollection Local Variables
314 #region ControlCollection Public Constructor
315 public ControlCollection(Control owner) {
317 this.list=new ArrayList();
321 #region ControlCollection Public Instance Properties
328 public bool IsReadOnly {
330 return list.IsReadOnly;
334 public virtual Control this[int index] {
336 if (index < 0 || index >= list.Count) {
337 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
339 return (Control)list[index];
342 #endregion // ControlCollection Public Instance Properties
344 #region ControlCollection Private Instance Methods
345 public virtual void Add (Control value)
350 if (Contains (value)) {
351 owner.PerformLayout();
355 if (value.tab_index == -1) {
361 end = owner.child_controls.Count;
362 for (int i = 0; i < end; i++) {
363 index = owner.child_controls[i].tab_index;
368 value.tab_index = use;
371 if (value.parent != null) {
372 value.parent.Controls.Remove(value);
378 value.ChangeParent(owner);
382 owner.UpdateChildrenZOrder();
383 owner.PerformLayout(value, "Parent");
384 owner.OnControlAdded(new ControlEventArgs(value));
387 internal void AddToList (Control c)
393 internal virtual void AddImplicit (Control control)
395 if (impl_list == null)
396 impl_list = new ArrayList ();
398 if (AllContains (control))
402 impl_list.Add (control);
404 control.ChangeParent (owner);
405 control.InitLayout ();
406 owner.UpdateChildrenZOrder ();
407 owner.PerformLayout (control, "Parent");
408 owner.OnControlAdded (new ControlEventArgs (control));
411 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
413 public virtual void AddRange (Control[] controls)
415 if (controls == null)
416 throw new ArgumentNullException ("controls");
418 owner.SuspendLayout ();
421 for (int i = 0; i < controls.Length; i++)
424 owner.ResumeLayout ();
428 internal virtual void AddRangeImplicit (Control [] controls)
430 if (controls == null)
431 throw new ArgumentNullException ("controls");
433 owner.SuspendLayout ();
436 for (int i = 0; i < controls.Length; i++)
437 AddImplicit (controls [i]);
439 owner.ResumeLayout ();
443 public virtual void Clear ()
447 // MS sends remove events in reverse order
448 while (list.Count > 0) {
449 Remove((Control)list[list.Count - 1]);
453 internal virtual void ClearImplicit ()
455 if (impl_list == null)
461 public bool Contains (Control value)
463 for (int i = list.Count; i > 0; ) {
466 if (list [i] == value) {
467 // Do we need to do anything here?
474 internal bool ImplicitContains (Control value)
476 if (impl_list == null)
479 for (int i = impl_list.Count; i > 0; ) {
482 if (impl_list [i] == value) {
483 // Do we need to do anything here?
490 internal bool AllContains (Control value)
492 return Contains (value) || ImplicitContains (value);
495 public void CopyTo (Array array, int index)
497 list.CopyTo(array, index);
500 public override bool Equals(object other) {
501 if (other is ControlCollection && (((ControlCollection)other).owner==this.owner)) {
508 public int GetChildIndex(Control child) {
509 return GetChildIndex(child, false);
512 public int GetChildIndex(Control child, bool throwException) {
515 index=list.IndexOf(child);
517 if (index==-1 && throwException) {
518 throw new ArgumentException("Not a child control", "child");
523 public IEnumerator GetEnumerator() {
524 return list.GetEnumerator();
527 internal IEnumerator GetAllEnumerator ()
529 Control [] res = GetAllControls ();
530 return res.GetEnumerator ();
533 internal Control [] GetAllControls ()
535 if (all_controls != null)
538 if (impl_list == null) {
539 all_controls = (Control []) list.ToArray (typeof (Control));
543 all_controls = new Control [list.Count + impl_list.Count];
544 impl_list.CopyTo (all_controls);
545 list.CopyTo (all_controls, impl_list.Count);
550 public override int GetHashCode() {
551 return base.GetHashCode();
554 public int IndexOf(Control control) {
555 return list.IndexOf(control);
558 public virtual void Remove(Control value) {
562 owner.PerformLayout(value, "Parent");
563 owner.OnControlRemoved(new ControlEventArgs(value));
568 value.ChangeParent(null);
570 owner.UpdateChildrenZOrder();
573 internal virtual void RemoveImplicit (Control control)
575 if (impl_list != null) {
577 owner.PerformLayout (control, "Parent");
578 owner.OnControlRemoved (new ControlEventArgs (control));
579 impl_list.Remove (control);
581 control.ChangeParent (null);
582 owner.UpdateChildrenZOrder ();
585 public void RemoveAt(int index) {
586 if (index < 0 || index >= list.Count) {
587 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
589 Remove ((Control)list[index]);
592 public void SetChildIndex(Control child, int newIndex) {
594 throw new ArgumentNullException ("child");
598 old_index=list.IndexOf(child);
600 throw new ArgumentException("Not a child control", "child");
603 if (old_index==newIndex) {
608 list.RemoveAt(old_index);
610 if (newIndex>list.Count) {
613 list.Insert(newIndex, child);
615 child.UpdateZOrder();
616 owner.PerformLayout();
618 #endregion // ControlCollection Private Instance Methods
620 #region ControlCollection Interface Properties
621 object IList.this[int index] {
623 if (index<0 || index>=list.Count) {
624 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
630 if (!(value is Control)) {
631 throw new ArgumentException("Object of type Control required", "value");
635 Control ctrl = (Control) value;
638 ctrl.ChangeParent(owner);
642 owner.UpdateChildrenZOrder();
643 owner.PerformLayout(ctrl, "Parent");
647 bool IList.IsFixedSize {
653 bool ICollection.IsSynchronized {
655 return list.IsSynchronized;
659 object ICollection.SyncRoot {
661 return list.SyncRoot;
664 #endregion // ControlCollection Interface Properties
666 #region ControlCollection Interface Methods
667 int IList.Add(object value) {
669 throw new ArgumentNullException("value", "Cannot add null controls");
672 if (!(value is Control)) {
673 throw new ArgumentException("Object of type Control required", "value");
676 return list.Add(value);
679 bool IList.Contains(object value) {
680 if (!(value is Control)) {
681 throw new ArgumentException("Object of type Control required", "value");
684 return this.Contains((Control) value);
687 int IList.IndexOf(object value) {
688 if (!(value is Control)) {
689 throw new ArgumentException("Object of type Control required", "value");
692 return this.IndexOf((Control) value);
695 void IList.Insert(int index, object value) {
696 if (!(value is Control)) {
697 throw new ArgumentException("Object of type Control required", "value");
700 list.Insert(index, value);
703 void IList.Remove(object value) {
704 if (!(value is Control)) {
705 throw new ArgumentException("Object of type Control required", "value");
711 Object ICloneable.Clone() {
712 ControlCollection clone = new ControlCollection(this.owner);
713 clone.list=(ArrayList)list.Clone(); // FIXME: Do we need this?
716 #endregion // ControlCollection Interface Methods
718 #endregion // ControlCollection Class
720 #region Public Constructors
723 anchor_style = AnchorStyles.Top | AnchorStyles.Left;
731 layout_pending = false;
733 causes_validation = true;
735 layout_suspended = 0;
739 right_to_left = RightToLeft.Inherit;
740 border_style = BorderStyle.None;
741 background_color = Color.Empty;
747 ime_mode = ImeMode.Inherit;
750 backgroundimage_layout = ImageLayout.Tile;
751 use_compatible_text_rendering = Application.use_compatible_text_rendering;
752 padding = new Padding(0);
753 maximum_size = new Size();
754 minimum_size = new Size();
755 preferred_size = this.DefaultSize;
756 margin = this.DefaultMargin;
757 layout_engine = this.LayoutEngine;
760 control_style = ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint |
761 ControlStyles.Selectable | ControlStyles.StandardClick |
762 ControlStyles.StandardDoubleClick;
764 control_style |= ControlStyles.UseTextForAccessibility;
768 background_image = null;
772 window = new ControlNativeWindow(this);
773 child_controls = CreateControlsInstance();
774 client_size = new Size(DefaultSize.Width, DefaultSize.Height);
775 client_rect = new Rectangle(0, 0, DefaultSize.Width, DefaultSize.Height);
776 XplatUI.CalculateWindowRect(ref client_rect, CreateParams.Style, CreateParams.ExStyle, null, out bounds);
777 if ((CreateParams.Style & (int)WindowStyles.WS_CHILD) == 0) {
783 public Control(Control parent, string text) : this() {
788 public Control(Control parent, string text, int left, int top, int width, int height) : this() {
793 bounds.Height=height;
794 SetBounds(left, top, width, height, BoundsSpecified.All);
798 public Control(string text) : this() {
802 public Control(string text, int left, int top, int width, int height) : this() {
806 bounds.Height=height;
807 SetBounds(left, top, width, height, BoundsSpecified.All);
811 private delegate void RemoveDelegate(object c);
813 protected override void Dispose(bool disposing) {
814 if (!is_disposed && disposing) {
817 DisposeBackBuffer ();
819 if (invalid_region!=null) {
820 invalid_region.Dispose();
823 if (this.InvokeRequired) {
824 if (Application.MessageLoop) {
825 this.BeginInvokeInternal(new MethodInvoker(DestroyHandle), null, true);
831 if (parent != null) {
832 parent.Controls.Remove(this);
835 Control [] children = child_controls.GetAllControls ();
836 for (int i=0; i<children.Length; i++) {
837 children[i].parent = null; // Need to set to null or our child will try and remove from ourselves and crash
838 children[i].Dispose();
843 base.Dispose(disposing);
845 #endregion // Public Constructors
847 #region Internal Properties
848 internal BorderStyle InternalBorderStyle {
854 if (!Enum.IsDefined (typeof (BorderStyle), value))
855 throw new InvalidEnumArgumentException (string.Format("Enum argument value '{0}' is not valid for BorderStyle", value));
857 if (border_style != value) {
858 border_style = value;
860 if (IsHandleCreated) {
861 XplatUI.SetBorderStyle(window.Handle, (FormBorderStyle)border_style);
867 #endregion // Internal Properties
869 #region Private & Internal Methods
872 void IDropTarget.OnDragDrop (DragEventArgs e)
877 void IDropTarget.OnDragEnter (DragEventArgs e)
882 void IDropTarget.OnDragLeave (EventArgs e)
887 void IDropTarget.OnDragOver (DragEventArgs e)
893 internal IAsyncResult BeginInvokeInternal (Delegate method, object [] args, bool disposing) {
894 AsyncMethodResult result;
895 AsyncMethodData data;
900 if (!p.IsHandleCreated) {
901 throw new InvalidOperationException("Cannot call Invoke or InvokeAsync on a control until the window handle is created");
907 result = new AsyncMethodResult ();
908 data = new AsyncMethodData ();
910 data.Handle = window.Handle;
911 data.Method = method;
913 data.Result = result;
916 if (!ExecutionContext.IsFlowSuppressed ()) {
917 data.Context = ExecutionContext.Capture ();
920 #if !MWF_ON_MSRUNTIME
921 if (SecurityManager.SecurityEnabled) {
922 data.Stack = CompressedStack.GetCompressedStack ();
927 XplatUI.SendAsyncMethod (data);
932 internal void PointToClient (ref int x, ref int y)
934 XplatUI.ScreenToClient (Handle, ref x, ref y);
937 internal void PointToScreen (ref int x, ref int y)
939 XplatUI.ClientToScreen (Handle, ref x, ref y);
942 internal bool IsRecreating {
944 return is_recreating;
948 internal Graphics DeviceContext {
949 get { return Hwnd.bmp_g; }
952 private void InvalidateBackBuffer ()
954 if (invalid_region != null)
955 invalid_region.Dispose();
956 invalid_region = new Region (ClientRectangle);
959 private void CreateBackBuffer ()
961 if (backbuffer != null)
967 if (width < 1) width = 1;
968 if (height < 1) height = 1;
970 XplatUI.CreateOffscreenDrawable (Handle, width, height, out backbuffer, out backbuffer_dc);
971 InvalidateBackBuffer ();
974 private void DisposeBackBuffer ()
976 if (backbuffer == null)
979 XplatUI.DestroyOffscreenDrawable (backbuffer, backbuffer_dc);
981 backbuffer_dc = null;
984 if (invalid_region != null)
985 invalid_region.Dispose ();
986 invalid_region = null;
989 internal static void SetChildColor(Control parent) {
992 for (int i=0; i < parent.child_controls.Count; i++) {
993 child=parent.child_controls[i];
994 if (child.child_controls.Count>0) {
995 SetChildColor(child);
1000 internal bool Select(Control control) {
1001 IContainerControl container;
1003 if (control == null) {
1007 container = GetContainerControl();
1008 if (container != null) {
1009 container.ActiveControl = control;
1011 if (control.IsHandleCreated) {
1012 XplatUI.SetFocus(control.window.Handle);
1017 internal void SelectChild (Control control)
1019 if (control.IsHandleCreated)
1020 XplatUI.SetFocus (control.window.Handle);
1023 internal virtual void DoDefaultAction() {
1024 // Only here to be overriden by our actual controls; this is needed by the accessibility class
1027 internal static IntPtr MakeParam (int low, int high){
1028 return new IntPtr (high << 16 | low & 0xffff);
1031 internal static int LowOrder (int param) {
1032 return ((int)(short)(param & 0xffff));
1035 internal static int HighOrder (int param) {
1036 return ((int)(short)(param >> 16));
1039 // This method exists so controls overriding OnPaintBackground can have default background painting done
1040 internal virtual void PaintControlBackground (PaintEventArgs pevent)
1042 if (GetStyle(ControlStyles.SupportsTransparentBackColor) && (BackColor.A != 0xff)) {
1043 if (parent != null) {
1044 PaintEventArgs parent_pe;
1045 GraphicsState state;
1047 parent_pe = new PaintEventArgs(pevent.Graphics, new Rectangle(pevent.ClipRectangle.X + Left, pevent.ClipRectangle.Y + Top, pevent.ClipRectangle.Width, pevent.ClipRectangle.Height));
1049 state = parent_pe.Graphics.Save();
1050 parent_pe.Graphics.TranslateTransform(-Left, -Top);
1051 parent.OnPaintBackground(parent_pe);
1052 parent_pe.Graphics.Restore(state);
1054 state = parent_pe.Graphics.Save();
1055 parent_pe.Graphics.TranslateTransform(-Left, -Top);
1056 parent.OnPaint(parent_pe);
1057 parent_pe.Graphics.Restore(state);
1058 parent_pe.SetGraphics(null);
1062 if ((clip_region != null) && (XplatUI.UserClipWontExposeParent)) {
1063 if (parent != null) {
1064 PaintEventArgs parent_pe;
1066 GraphicsState state;
1069 hwnd = Hwnd.ObjectFromHandle(Handle);
1072 parent_pe = new PaintEventArgs(pevent.Graphics, new Rectangle(pevent.ClipRectangle.X + Left, pevent.ClipRectangle.Y + Top, pevent.ClipRectangle.Width, pevent.ClipRectangle.Height));
1074 region = new Region ();
1076 region.Union(ClientRectangle);
1078 foreach (Rectangle r in hwnd.ClipRectangles) {
1082 state = parent_pe.Graphics.Save();
1083 parent_pe.Graphics.Clip = region;
1085 parent_pe.Graphics.TranslateTransform(-Left, -Top);
1086 parent.OnPaintBackground(parent_pe);
1087 parent_pe.Graphics.Restore(state);
1089 state = parent_pe.Graphics.Save();
1090 parent_pe.Graphics.Clip = region;
1092 parent_pe.Graphics.TranslateTransform(-Left, -Top);
1093 parent.OnPaint(parent_pe);
1094 parent_pe.Graphics.Restore(state);
1095 parent_pe.SetGraphics(null);
1097 region.Intersect(clip_region);
1098 pevent.Graphics.Clip = region;
1103 if (background_image == null) {
1104 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));
1108 DrawBackgroundImage (pevent.Graphics);
1111 void DrawBackgroundImage (Graphics g)
1114 Rectangle drawing_rectangle = new Rectangle ();
1115 g.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (BackColor), ClientRectangle);
1117 switch (backgroundimage_layout)
1119 case ImageLayout.Tile:
1120 using (TextureBrush b = new TextureBrush (background_image, WrapMode.Tile)) {
1121 g.FillRectangle (b, ClientRectangle);
1124 case ImageLayout.Center:
1125 drawing_rectangle.Location = new Point (ClientSize.Width / 2 - background_image.Width / 2, ClientSize.Height / 2 - background_image.Height / 2);
1126 drawing_rectangle.Size = background_image.Size;
1128 case ImageLayout.None:
1129 drawing_rectangle.Location = Point.Empty;
1130 drawing_rectangle.Size = background_image.Size;
1132 case ImageLayout.Stretch:
1133 drawing_rectangle = ClientRectangle;
1135 case ImageLayout.Zoom:
1136 drawing_rectangle = ClientRectangle;
1137 if ((float)background_image.Width / (float)background_image.Height < (float)drawing_rectangle.Width / (float) drawing_rectangle.Height) {
1138 drawing_rectangle.Width = (int) (background_image.Width * ((float)drawing_rectangle.Height / (float)background_image.Height));
1139 drawing_rectangle.X = (ClientRectangle.Width - drawing_rectangle.Width) / 2;
1141 drawing_rectangle.Height = (int) (background_image.Height * ((float)drawing_rectangle.Width / (float)background_image.Width));
1142 drawing_rectangle.Y = (ClientRectangle.Height - drawing_rectangle.Height) / 2;
1149 g.DrawImage (background_image, drawing_rectangle);
1152 using (TextureBrush b = new TextureBrush (background_image, WrapMode.Tile)) {
1153 g.FillRectangle (b, ClientRectangle);
1158 internal virtual void DndEnter (DragEventArgs e)
1165 internal virtual void DndOver (DragEventArgs e)
1172 internal virtual void DndDrop (DragEventArgs e)
1176 } catch (Exception exc) {
1177 Console.Error.WriteLine ("MWF: Exception while dropping:");
1178 Console.Error.WriteLine (exc);
1182 internal virtual void DndLeave (EventArgs e)
1189 internal virtual void DndFeedback(GiveFeedbackEventArgs e)
1196 internal virtual void DndContinueDrag(QueryContinueDragEventArgs e)
1199 OnQueryContinueDrag(e);
1203 internal static MouseButtons FromParamToMouseButtons (int param) {
1204 MouseButtons buttons = MouseButtons.None;
1206 if ((param & (int) MsgButtons.MK_LBUTTON) != 0)
1207 buttons |= MouseButtons.Left;
1209 if ((param & (int) MsgButtons.MK_MBUTTON) != 0)
1210 buttons |= MouseButtons.Middle;
1212 if ((param & (int) MsgButtons.MK_RBUTTON) != 0)
1213 buttons |= MouseButtons.Right;
1219 internal void FireEnter ()
1221 OnEnter (EventArgs.Empty);
1224 internal void FireLeave ()
1226 OnLeave (EventArgs.Empty);
1229 internal void FireValidating (CancelEventArgs ce)
1234 internal void FireValidated ()
1236 OnValidated (EventArgs.Empty);
1239 internal virtual bool ProcessControlMnemonic(char charCode) {
1240 return ProcessMnemonic(charCode);
1243 private static Control FindFlatForward(Control container, Control start) {
1249 end = container.child_controls.Count;
1251 if (start != null) {
1252 index = start.tab_index;
1257 for (int i = 0, pos = -1; i < end; i++) {
1258 if (start == container.child_controls[i]) {
1263 if (found == null) {
1264 if (container.child_controls[i].tab_index > index || (pos > -1 && pos < i && container.child_controls[i].tab_index == index)) {
1265 found = container.child_controls[i];
1267 } else if (found.tab_index > container.child_controls[i].tab_index) {
1268 if (container.child_controls[i].tab_index > index) {
1269 found = container.child_controls[i];
1276 private static Control FindControlForward(Control container, Control start) {
1281 if (start == null) {
1282 return FindFlatForward(container, start);
1285 if (start.child_controls != null && start.child_controls.Count > 0 &&
1286 (start == container || !((start is IContainerControl) && start.GetStyle(ControlStyles.ContainerControl)))) {
1287 return FindControlForward(start, null);
1290 while (start != container) {
1291 found = FindFlatForward(start.parent, start);
1292 if (found != null) {
1295 start = start.parent;
1301 private static Control FindFlatBackward(Control container, Control start) {
1307 end = container.child_controls.Count;
1309 if (start != null) {
1310 index = start.tab_index;
1312 // FIXME: Possible speed-up: Keep the highest taborder index in the container
1314 for (int i = 0; i < end; i++) {
1315 if (container.child_controls[i].tab_index > index) {
1316 index = container.child_controls[i].tab_index;
1324 for (int i = end - 1; i >= 0; i--) {
1325 if (start == container.child_controls[i]) {
1330 if (found == null || found.tab_index < container.child_controls[i].tab_index) {
1331 if (container.child_controls[i].tab_index < index || (hit && container.child_controls[i].tab_index == index))
1332 found = container.child_controls[i];
1339 private static Control FindControlBackward(Control container, Control start) {
1341 Control found = null;
1343 if (start == null) {
1344 found = FindFlatBackward(container, start);
1346 else if (start != container) {
1347 if (start.parent != null) {
1348 found = FindFlatBackward(start.parent, start);
1350 if (found == null) {
1351 if (start.parent != container)
1352 return start.parent;
1358 if (found == null || start.parent == null)
1361 while (found != null && (found == container || (!((found is IContainerControl) && found.GetStyle(ControlStyles.ContainerControl))) &&
1362 found.child_controls != null && found.child_controls.Count > 0)) {
1363 // while (ctl.child_controls != null && ctl.child_controls.Count > 0 &&
1364 // (ctl == this || (!((ctl is IContainerControl) && ctl.GetStyle(ControlStyles.ContainerControl))))) {
1365 found = FindFlatBackward(found, null);
1375 if (start != null) {
1376 found = FindFlatBackward(start.parent, start);
1377 if (found == null) {
1378 if (start.parent != container) {
1379 return start.parent;
1383 if (found == null) {
1384 found = FindFlatBackward(container, start);
1387 if (container != start) {
1388 while ((found != null) && (!found.Contains(start)) && found.child_controls != null && found.child_controls.Count > 0 && !(found is IContainerControl)) {// || found.GetStyle(ControlStyles.ContainerControl))) {
1389 found = FindControlBackward(found, null);
1390 if (found != null) {
1399 internal virtual void HandleClick(int clicks, MouseEventArgs me) {
1400 if (GetStyle(ControlStyles.StandardClick)) {
1401 if ((clicks > 1) && GetStyle(ControlStyles.StandardDoubleClick)) {
1403 OnDoubleClick(EventArgs.Empty);
1405 OnClick(EventArgs.Empty);
1415 internal void CaptureWithConfine (Control ConfineWindow)
1417 if (this.IsHandleCreated && !is_captured) {
1419 XplatUI.GrabWindow (this.window.Handle, ConfineWindow.Handle);
1423 private void CheckDataBindings ()
1425 if (data_bindings == null)
1428 BindingContext binding_context = BindingContext;
1429 foreach (Binding binding in data_bindings) {
1430 binding.Check (binding_context);
1434 private void ChangeParent(Control new_parent) {
1438 Color pre_fore_color;
1439 Color pre_back_color;
1440 RightToLeft pre_rtl;
1442 // These properties are inherited from our parent
1443 // Get them pre parent-change and then send events
1444 // if they are changed after we have our new parent
1445 pre_enabled = Enabled;
1446 pre_visible = Visible;
1448 pre_fore_color = ForeColor;
1449 pre_back_color = BackColor;
1450 pre_rtl = RightToLeft;
1451 // MS doesn't seem to send a CursorChangedEvent
1453 parent = new_parent;
1455 if (IsHandleCreated)
1456 XplatUI.SetParent(Handle,
1457 (new_parent == null || !new_parent.IsHandleCreated) ? IntPtr.Zero : new_parent.Handle);
1459 OnParentChanged(EventArgs.Empty);
1461 if (pre_enabled != Enabled) {
1462 OnEnabledChanged(EventArgs.Empty);
1465 if (pre_visible != Visible) {
1466 OnVisibleChanged(EventArgs.Empty);
1469 if (pre_font != Font) {
1470 OnFontChanged(EventArgs.Empty);
1473 if (pre_fore_color != ForeColor) {
1474 OnForeColorChanged(EventArgs.Empty);
1477 if (pre_back_color != BackColor) {
1478 OnBackColorChanged(EventArgs.Empty);
1481 if (pre_rtl != RightToLeft) {
1482 // MS sneaks a OnCreateControl and OnHandleCreated in here, I guess
1483 // because when RTL changes they have to recreate the win32 control
1484 // We don't really need that (until someone runs into compatibility issues)
1485 OnRightToLeftChanged(EventArgs.Empty);
1488 if ((new_parent != null) && new_parent.Created && !Created) {
1492 if ((binding_context == null) && Created) {
1493 OnBindingContextChanged(EventArgs.Empty);
1497 private void UpdateDistances() {
1498 if (parent != null) {
1499 dist_left = bounds.X;
1500 dist_top = bounds.Y;
1501 dist_right = parent.ClientSize.Width - bounds.X - bounds.Width;
1502 dist_bottom = parent.ClientSize.Height - bounds.Y - bounds.Height;
1505 #endregion // Private & Internal Methods
1507 #region Public Static Properties
1508 public static Color DefaultBackColor {
1510 return ThemeEngine.Current.DefaultControlBackColor;
1514 public static Font DefaultFont {
1516 return ThemeEngine.Current.DefaultFont;
1520 public static Color DefaultForeColor {
1522 return ThemeEngine.Current.DefaultControlForeColor;
1526 public static Keys ModifierKeys {
1528 return XplatUI.State.ModifierKeys;
1532 public static MouseButtons MouseButtons {
1534 return XplatUI.State.MouseButtons;
1538 public static Point MousePosition {
1540 return Cursor.Position;
1545 [EditorBrowsable (EditorBrowsableState.Advanced)]
1546 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
1549 public static bool CheckForIllegalCrossThreadCalls
1552 return verify_thread_handle;
1556 verify_thread_handle = value;
1560 #endregion // Public Static Properties
1562 #region Public Instance Properties
1563 [EditorBrowsable(EditorBrowsableState.Advanced)]
1565 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1566 public AccessibleObject AccessibilityObject {
1568 if (accessibility_object==null) {
1569 accessibility_object=CreateAccessibilityInstance();
1571 return accessibility_object;
1575 [EditorBrowsable(EditorBrowsableState.Advanced)]
1577 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1578 public string AccessibleDefaultActionDescription {
1580 return AccessibilityObject.default_action;
1584 AccessibilityObject.default_action=value;
1589 [DefaultValue(null)]
1590 [MWFCategory("Accessibility")]
1591 public string AccessibleDescription {
1593 return AccessibilityObject.description;
1597 AccessibilityObject.description=value;
1602 [DefaultValue(null)]
1603 [MWFCategory("Accessibility")]
1604 public string AccessibleName {
1606 return AccessibilityObject.Name;
1610 AccessibilityObject.Name=value;
1614 [DefaultValue(AccessibleRole.Default)]
1615 [MWFDescription("Role of the control"), MWFCategory("Accessibility")]
1616 public AccessibleRole AccessibleRole {
1618 return AccessibilityObject.role;
1622 AccessibilityObject.role=value;
1626 [DefaultValue(false)]
1627 [MWFCategory("Behavior")]
1628 public virtual bool AllowDrop {
1634 if (allow_drop == value)
1637 if (IsHandleCreated) {
1639 XplatUI.SetAllowDrop (Handle, value);
1645 [RefreshProperties(RefreshProperties.Repaint)]
1646 [DefaultValue(AnchorStyles.Top | AnchorStyles.Left)]
1647 [MWFCategory("Layout")]
1648 public virtual AnchorStyles Anchor {
1650 return anchor_style;
1656 if (parent != null) {
1657 parent.PerformLayout(this, "Parent");
1663 // XXX: Implement me!
1666 [RefreshProperties (RefreshProperties.All)]
1667 [Localizable (true)]
1668 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
1670 [EditorBrowsable (EditorBrowsableState.Never)]
1671 [DefaultValue (false)]
1672 public virtual bool AutoSize {
1674 //Console.Error.WriteLine("Unimplemented: Control::get_AutoSize()");
1678 Console.Error.WriteLine("Unimplemented: Control::set_AutoSize(bool)");
1683 [AmbientValue (typeof(Size), "0, 0")]
1684 public virtual Size MaximumSize {
1686 return maximum_size;
1689 maximum_size = value;
1693 public virtual Size MinimumSize {
1695 return minimum_size;
1698 minimum_size = value;
1704 [MWFCategory("Appearance")]
1705 public virtual Color BackColor {
1707 if (background_color.IsEmpty) {
1709 Color pcolor = parent.BackColor;
1710 if (pcolor.A == 0xff || GetStyle(ControlStyles.SupportsTransparentBackColor))
1713 return DefaultBackColor;
1715 return background_color;
1719 if (!value.IsEmpty && (value.A != 0xff) && !GetStyle(ControlStyles.SupportsTransparentBackColor)) {
1720 throw new ArgumentException("Transparent background colors are not supported on this control");
1723 if (background_color != value) {
1724 background_color=value;
1725 SetChildColor(this);
1726 OnBackColorChanged(EventArgs.Empty);
1733 [DefaultValue(null)]
1734 [MWFCategory("Appearance")]
1735 public virtual Image BackgroundImage {
1737 return background_image;
1741 if (background_image!=value) {
1742 background_image=value;
1743 OnBackgroundImageChanged(EventArgs.Empty);
1750 [DefaultValue (ImageLayout.Tile)]
1751 [Localizable (true)]
1752 public virtual ImageLayout BackgroundImageLayout {
1754 return backgroundimage_layout;
1757 if (Array.IndexOf (Enum.GetValues (typeof (ImageLayout)), value) == -1)
1758 throw new InvalidEnumArgumentException ("value", (int) value, typeof(ImageLayout));
1760 if (value != backgroundimage_layout) {
1761 backgroundimage_layout = value;
1768 [EditorBrowsable(EditorBrowsableState.Advanced)]
1770 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1771 public virtual BindingContext BindingContext {
1773 if (binding_context != null)
1774 return binding_context;
1777 binding_context = Parent.BindingContext;
1778 return binding_context;
1781 if (binding_context != value) {
1782 binding_context = value;
1783 OnBindingContextChanged(EventArgs.Empty);
1788 [EditorBrowsable(EditorBrowsableState.Advanced)]
1790 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1793 return bounds.Y+bounds.Height;
1797 [EditorBrowsable(EditorBrowsableState.Advanced)]
1799 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1800 public Rectangle Bounds {
1806 SetBounds(value.Left, value.Top, value.Width, value.Height, BoundsSpecified.All);
1810 [EditorBrowsable(EditorBrowsableState.Advanced)]
1812 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1813 public bool CanFocus {
1815 if (IsHandleCreated && Visible && Enabled) {
1822 [EditorBrowsable(EditorBrowsableState.Advanced)]
1824 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1825 public bool CanSelect {
1829 if (!GetStyle(ControlStyles.Selectable)) {
1834 while (parent != null) {
1835 if (!parent.is_visible || !parent.is_enabled) {
1839 parent = parent.parent;
1845 internal virtual bool InternalCapture {
1855 [EditorBrowsable(EditorBrowsableState.Advanced)]
1857 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1858 public bool Capture {
1860 return this.is_captured;
1864 if (this.IsHandleCreated && value != is_captured) {
1867 XplatUI.GrabWindow(this.window.Handle, IntPtr.Zero);
1869 XplatUI.UngrabWindow(this.window.Handle);
1870 is_captured = false;
1876 [DefaultValue(true)]
1877 [MWFCategory("Focus")]
1878 public bool CausesValidation {
1880 return this.causes_validation;
1884 if (this.causes_validation != value) {
1885 causes_validation = value;
1886 OnCausesValidationChanged(EventArgs.Empty);
1891 [EditorBrowsable(EditorBrowsableState.Advanced)]
1893 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1894 public Rectangle ClientRectangle {
1896 client_rect.Width = client_size.Width;
1897 client_rect.Height = client_size.Height;
1902 [EditorBrowsable(EditorBrowsableState.Advanced)]
1904 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1905 public Size ClientSize {
1908 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1909 return ((Form)this).form_parent_window.ClientSize;
1917 this.SetClientSizeCore(value.Width, value.Height);
1921 [EditorBrowsable(EditorBrowsableState.Advanced)]
1923 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1924 [DescriptionAttribute("ControlCompanyNameDescr")]
1925 public String CompanyName {
1927 return "Mono Project, Novell, Inc.";
1931 internal bool ContainerSelected {
1932 get { return container_selected; }
1933 set { container_selected = value; }
1936 [EditorBrowsable(EditorBrowsableState.Advanced)]
1938 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1939 public bool ContainsFocus {
1941 IntPtr focused_window;
1943 focused_window = XplatUI.GetFocus();
1944 if (IsHandleCreated) {
1945 if (focused_window == Handle) {
1949 for (int i=0; i < child_controls.Count; i++) {
1950 if (child_controls[i].ContainsFocus) {
1961 [DefaultValue(null)]
1962 [MWFCategory("Behavior")]
1963 public virtual ContextMenu ContextMenu {
1965 return GetContextMenuInternal ();
1969 if (context_menu != value) {
1970 context_menu = value;
1971 OnContextMenuChanged(EventArgs.Empty);
1976 internal virtual ContextMenu GetContextMenuInternal ()
1978 return context_menu;
1982 public virtual ContextMenuStrip ContextMenuStrip {
1983 get { return this.context_menu_strip; }
1985 if (this.context_menu_strip != value) {
1986 this.context_menu_strip = value;
1987 OnContextMenuStripChanged (EventArgs.Empty);
1994 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
1995 public ControlCollection Controls {
1997 return this.child_controls;
2001 [EditorBrowsable(EditorBrowsableState.Advanced)]
2003 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2004 public bool Created {
2006 return (!is_disposed && is_created);
2010 [AmbientValue(null)]
2011 [MWFCategory("Appearance")]
2012 public virtual Cursor Cursor {
2014 if (cursor != null) {
2018 if (parent != null) {
2019 return parent.Cursor;
2022 return Cursors.Default;
2026 if (cursor != value) {
2031 if (IsHandleCreated) {
2032 pt = Cursor.Position;
2034 if (bounds.Contains(pt) || Capture) {
2035 if (GetChildAtPoint(pt) == null) {
2036 if (cursor != null) {
2037 XplatUI.SetCursor(window.Handle, cursor.handle);
2039 if (parent != null) {
2040 XplatUI.SetCursor(window.Handle, parent.Cursor.handle);
2042 XplatUI.SetCursor(window.Handle, Cursors.Default.handle);
2049 OnCursorChanged(EventArgs.Empty);
2055 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
2056 [ParenthesizePropertyName(true)]
2057 [RefreshProperties(RefreshProperties.All)]
2058 [MWFCategory("Data")]
2059 public ControlBindingsCollection DataBindings {
2061 if (data_bindings == null)
2062 data_bindings = new ControlBindingsCollection (this);
2063 return data_bindings;
2067 [EditorBrowsable(EditorBrowsableState.Advanced)]
2069 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2070 public virtual Rectangle DisplayRectangle {
2072 return ClientRectangle;
2076 [EditorBrowsable(EditorBrowsableState.Advanced)]
2078 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2079 public bool Disposing {
2086 [RefreshProperties(RefreshProperties.Repaint)]
2087 [DefaultValue(DockStyle.None)]
2088 [MWFCategory("Layout")]
2089 public virtual DockStyle Dock {
2095 if (dock_style == value) {
2099 if (!Enum.IsDefined (typeof (DockStyle), value)) {
2100 throw new InvalidEnumArgumentException ("value", (int) value,
2101 typeof (DockStyle));
2106 if (dock_style == DockStyle.None) {
2107 if (explicit_bounds == Rectangle.Empty)
2108 Bounds = new Rectangle (new Point (0, 0), DefaultSize);
2110 Bounds = explicit_bounds;
2113 if (parent != null) {
2114 parent.PerformLayout(this, "Parent");
2117 OnDockChanged(EventArgs.Empty);
2122 protected virtual bool DoubleBuffered {
2124 return (control_style & ControlStyles.DoubleBuffer) != 0;
2128 SetStyle (ControlStyles.DoubleBuffer, value);
2135 [MWFCategory("Behavior")]
2136 public bool Enabled {
2142 if (parent != null) {
2143 return parent.Enabled;
2151 bool old_value = is_enabled;
2154 if (old_value != value && !value && this.has_focus)
2155 SelectNextControl(this, true, true, true, true);
2157 OnEnabledChanged (EventArgs.Empty);
2161 [EditorBrowsable(EditorBrowsableState.Advanced)]
2163 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2164 public virtual bool Focused {
2166 return this.has_focus;
2171 [AmbientValue(null)]
2173 [MWFCategory("Appearance")]
2174 public virtual Font Font {
2180 if (Parent != null && Parent.Font != null) {
2187 [param:MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Font))]
2189 if (font != null && font.Equals (value)) {
2195 OnFontChanged (EventArgs.Empty);
2200 [MWFCategory("Appearance")]
2201 public virtual Color ForeColor {
2203 if (foreground_color.IsEmpty) {
2205 return parent.ForeColor;
2207 return DefaultForeColor;
2209 return foreground_color;
2213 if (foreground_color != value) {
2214 foreground_color=value;
2216 OnForeColorChanged(EventArgs.Empty);
2223 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2224 public IntPtr Handle { // IWin32Window
2227 if (verify_thread_handle) {
2228 if (this.InvokeRequired) {
2229 throw new InvalidOperationException("Cross-thread access of handle detected. Handle access only valid on thread that created the control");
2233 if (!IsHandleCreated) {
2236 return window.Handle;
2240 [EditorBrowsable(EditorBrowsableState.Advanced)]
2242 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2243 public bool HasChildren {
2245 if (this.child_controls.Count>0) {
2252 [EditorBrowsable(EditorBrowsableState.Always)]
2254 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2257 return this.bounds.Height;
2261 SetBounds(bounds.X, bounds.Y, bounds.Width, value, BoundsSpecified.Height);
2265 [AmbientValue(ImeMode.Inherit)]
2267 [MWFCategory("Behavior")]
2268 public ImeMode ImeMode {
2270 if (ime_mode == ImeMode.Inherit) {
2272 return parent.ImeMode;
2274 return ImeMode.NoControl; // default value
2280 if (ime_mode != value) {
2283 OnImeModeChanged(EventArgs.Empty);
2288 [EditorBrowsable(EditorBrowsableState.Advanced)]
2290 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2291 public bool InvokeRequired { // ISynchronizeInvoke
2293 if (creator_thread != null && creator_thread!=Thread.CurrentThread) {
2300 [EditorBrowsable(EditorBrowsableState.Advanced)]
2302 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2303 public bool IsAccessible {
2305 return is_accessible;
2309 is_accessible = value;
2313 [EditorBrowsable(EditorBrowsableState.Advanced)]
2315 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2316 public bool IsDisposed {
2318 return this.is_disposed;
2322 [EditorBrowsable(EditorBrowsableState.Advanced)]
2324 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2325 public bool IsHandleCreated {
2327 if ((window != null) && (window.Handle != IntPtr.Zero)) {
2328 Hwnd hwnd = Hwnd.ObjectFromHandle (window.Handle);
2329 if (hwnd != null && !hwnd.zombie)
2339 [EditorBrowsable (EditorBrowsableState.Advanced)]
2340 public virtual Layout.LayoutEngine LayoutEngine {
2341 get { return new Layout.DefaultLayout (); }
2345 [EditorBrowsable(EditorBrowsableState.Always)]
2347 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2350 return this.bounds.X;
2354 SetBounds(value, bounds.Y, bounds.Width, bounds.Height, BoundsSpecified.X);
2359 [MWFCategory("Layout")]
2360 public Point Location {
2362 return new Point(bounds.X, bounds.Y);
2366 SetBounds(value.X, value.Y, bounds.Width, bounds.Height, BoundsSpecified.Location);
2371 [Localizable (true)]
2372 public Padding Margin {
2373 get { return this.margin; }
2374 set { this.margin = value; }
2379 public string Name {
2391 public Padding Padding {
2398 OnPaddingChanged (EventArgs.Empty);
2404 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2405 public Control Parent {
2411 if (value == this) {
2412 throw new ArgumentException("A circular control reference has been made. A control cannot be owned or parented to itself.");
2415 if (parent!=value) {
2417 parent.Controls.Remove(this);
2422 value.Controls.Add(this);
2427 [EditorBrowsable(EditorBrowsableState.Advanced)]
2429 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2430 public string ProductName {
2432 Type t = typeof (AssemblyProductAttribute);
2433 Assembly assembly = GetType().Module.Assembly;
2434 object [] attrs = assembly.GetCustomAttributes (t, false);
2435 AssemblyProductAttribute a = null;
2436 // On MS we get a NullRefException if product attribute is not
2438 if (attrs != null && attrs.Length > 0)
2439 a = (AssemblyProductAttribute) attrs [0];
2444 [EditorBrowsable(EditorBrowsableState.Advanced)]
2446 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2447 public string ProductVersion {
2449 Type t = typeof (AssemblyVersionAttribute);
2450 Assembly assembly = GetType().Module.Assembly;
2451 object [] attrs = assembly.GetCustomAttributes (t, false);
2452 if (attrs == null || attrs.Length < 1)
2454 return ((AssemblyVersionAttribute)attrs [0]).Version;
2458 [EditorBrowsable(EditorBrowsableState.Advanced)]
2460 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2461 public bool RecreatingHandle {
2463 return is_recreating;
2467 [EditorBrowsable(EditorBrowsableState.Advanced)]
2469 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2470 public Region Region {
2476 if (value != null && IsHandleCreated) {
2477 XplatUI.SetClipRegion(Handle, value);
2479 clip_region = value;
2483 [EditorBrowsable(EditorBrowsableState.Advanced)]
2485 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2488 return this.bounds.X+this.bounds.Width;
2492 [AmbientValue(RightToLeft.Inherit)]
2494 [MWFCategory("Appearance")]
2495 public virtual RightToLeft RightToLeft {
2497 if (right_to_left == RightToLeft.Inherit) {
2499 return parent.RightToLeft;
2501 return RightToLeft.No; // default value
2503 return right_to_left;
2507 if (value != right_to_left) {
2508 right_to_left = value;
2509 OnRightToLeftChanged(EventArgs.Empty);
2514 [EditorBrowsable(EditorBrowsableState.Advanced)]
2515 public override ISite Site {
2523 if (value != null) {
2524 AmbientProperties ap = (AmbientProperties) value.GetService (typeof (AmbientProperties));
2526 BackColor = ap.BackColor;
2527 ForeColor = ap.ForeColor;
2536 [MWFCategory("Layout")]
2539 return new Size(Width, Height);
2543 SetBounds(bounds.X, bounds.Y, value.Width, value.Height, BoundsSpecified.Size);
2548 [MergableProperty(false)]
2549 [MWFCategory("Behavior")]
2550 public int TabIndex {
2552 if (tab_index != -1) {
2559 if (tab_index != value) {
2561 OnTabIndexChanged(EventArgs.Empty);
2567 [DefaultValue(true)]
2568 [MWFCategory("Behavior")]
2569 public bool TabStop {
2575 if (tab_stop != value) {
2577 OnTabStopChanged(EventArgs.Empty);
2582 [Localizable(false)]
2584 [TypeConverter(typeof(StringConverter))]
2585 [DefaultValue(null)]
2586 [MWFCategory("Data")]
2593 control_tag = value;
2599 [BindableAttribute(true)]
2600 [MWFCategory("Appearance")]
2601 public virtual string Text {
2603 // Our implementation ignores ControlStyles.CacheText - we always cache
2608 if (value == null) {
2609 value = String.Empty;
2614 if (IsHandleCreated) {
2615 /* we need to call .SetWindowStyle here instead of just .Text
2616 because the presence/absence of Text (== "" or not) can cause
2617 other window style things to appear/disappear */
2618 XplatUI.SetWindowStyle(window.Handle, CreateParams);
2619 XplatUI.Text(Handle, text);
2621 OnTextChanged (EventArgs.Empty);
2626 [EditorBrowsable(EditorBrowsableState.Always)]
2628 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2631 return this.bounds.Y;
2635 SetBounds(bounds.X, value, bounds.Width, bounds.Height, BoundsSpecified.Y);
2639 [EditorBrowsable(EditorBrowsableState.Advanced)]
2641 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2642 public Control TopLevelControl {
2646 while (p.parent != null) {
2650 return p is Form ? p : null;
2655 [MWFCategory("Behavior")]
2656 public bool Visible {
2660 } else if (parent != null) {
2661 return parent.Visible;
2668 SetVisibleCore(value);
2672 [EditorBrowsable(EditorBrowsableState.Always)]
2674 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2677 return this.bounds.Width;
2681 SetBounds(bounds.X, bounds.Y, value, bounds.Height, BoundsSpecified.Width);
2685 [EditorBrowsable(EditorBrowsableState.Never)]
2687 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2688 public IWindowTarget WindowTarget {
2697 #endregion // Public Instance Properties
2699 #region Protected Instance Properties
2700 protected virtual CreateParams CreateParams {
2702 CreateParams create_params = new CreateParams();
2705 create_params.Caption = Text;
2708 create_params.Caption = text;
2712 create_params.X = Left;
2715 create_params.X = this.bounds.X;
2719 create_params.Y = Top;
2722 create_params.Y = this.bounds.Y;
2726 create_params.Width = Width;
2729 create_params.Width = this.bounds.Width;
2733 create_params.Height = Height;
2736 create_params.Height = this.bounds.Height;
2740 create_params.ClassName = XplatUI.DefaultClassName;
2741 create_params.ClassStyle = 0;
2742 create_params.ExStyle = 0;
2743 create_params.Param = 0;
2746 create_params.ExStyle |= (int)WindowExStyles.WS_EX_ACCEPTFILES;
2749 if ((parent!=null) && (parent.IsHandleCreated)) {
2750 create_params.Parent = parent.Handle;
2753 create_params.Style = (int)WindowStyles.WS_CHILD | (int)WindowStyles.WS_CLIPCHILDREN | (int)WindowStyles.WS_CLIPSIBLINGS;
2756 create_params.Style |= (int)WindowStyles.WS_VISIBLE;
2760 create_params.Style |= (int)WindowStyles.WS_DISABLED;
2763 switch (border_style) {
2764 case BorderStyle.FixedSingle:
2765 create_params.Style |= (int) WindowStyles.WS_BORDER;
2767 case BorderStyle.Fixed3D:
2768 create_params.ExStyle |= (int) WindowExStyles.WS_EX_CLIENTEDGE;
2772 return create_params;
2776 protected virtual ImeMode DefaultImeMode {
2778 return ImeMode.Inherit;
2783 protected virtual Padding DefaultMargin {
2784 get { return new Padding (3); }
2788 protected virtual Size DefaultSize {
2790 return new Size(0, 0);
2794 protected int FontHeight {
2806 protected bool RenderRightToLeft {
2808 return (this.right_to_left == RightToLeft.Yes);
2812 protected bool ResizeRedraw {
2814 return GetStyle(ControlStyles.ResizeRedraw);
2818 SetStyle(ControlStyles.ResizeRedraw, value);
2822 [EditorBrowsable(EditorBrowsableState.Advanced)]
2824 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2825 protected virtual bool ShowFocusCues {
2831 [EditorBrowsable(EditorBrowsableState.Advanced)]
2833 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2835 protected internal virtual bool ShowKeyboardCues {
2837 protected bool ShowKeyboardCues {
2844 #endregion // Protected Instance Properties
2846 #region Public Static Methods
2847 [EditorBrowsable(EditorBrowsableState.Advanced)]
2848 public static Control FromChildHandle(IntPtr handle) {
2849 return Control.ControlNativeWindow.ControlFromChildHandle (handle);
2852 [EditorBrowsable(EditorBrowsableState.Advanced)]
2853 public static Control FromHandle(IntPtr handle) {
2854 return Control.ControlNativeWindow.ControlFromHandle(handle);
2857 public static bool IsMnemonic(char charCode, string text) {
2860 amp = text.IndexOf('&');
2863 if (amp + 1 < text.Length) {
2864 if (text[amp + 1] != '&') {
2865 if (Char.ToUpper(charCode) == Char.ToUpper(text.ToCharArray(amp + 1, 1)[0])) {
2875 #region Protected Static Methods
2876 [EditorBrowsable(EditorBrowsableState.Advanced)]
2877 protected static bool ReflectMessage(IntPtr hWnd, ref Message m) {
2880 c = Control.FromHandle(hWnd);
2890 #region Public Instance Methods
2891 [EditorBrowsable(EditorBrowsableState.Advanced)]
2892 public IAsyncResult BeginInvoke(Delegate method) {
2893 object [] prms = null;
2894 if (method is EventHandler)
2895 prms = new object [] { this, EventArgs.Empty };
2896 return BeginInvokeInternal(method, prms, false);
2899 [EditorBrowsable(EditorBrowsableState.Advanced)]
2900 public IAsyncResult BeginInvoke (Delegate method, object[] args) {
2901 return BeginInvokeInternal (method, args, false);
2904 public void BringToFront() {
2905 if (parent != null) {
2906 parent.child_controls.SetChildIndex(this, 0);
2909 XplatUI.SetZOrder(Handle, IntPtr.Zero, false, false);
2913 public bool Contains(Control ctl) {
2914 while (ctl != null) {
2923 public void CreateControl() {
2925 throw new ObjectDisposedException(GetType().FullName.ToString());
2931 if (!IsHandleCreated) {
2939 Control [] controls = child_controls.GetAllControls ();
2940 for (int i=0; i<controls.Length; i++) {
2941 controls [i].CreateControl ();
2944 UpdateChildrenZOrder();
2946 if (binding_context == null) { // seem to be sent whenever it's null?
2947 OnBindingContextChanged(EventArgs.Empty);
2953 public Graphics CreateGraphics() {
2954 if (!IsHandleCreated) {
2955 this.CreateHandle();
2957 return Graphics.FromHwnd(this.window.Handle);
2960 public DragDropEffects DoDragDrop(object data, DragDropEffects allowedEffects) {
2961 return XplatUI.StartDrag(this.window.Handle, data, allowedEffects);
2964 [EditorBrowsable(EditorBrowsableState.Advanced)]
2965 public object EndInvoke (IAsyncResult async_result) {
2966 AsyncMethodResult result = (AsyncMethodResult) async_result;
2967 return result.EndInvoke ();
2970 public Form FindForm() {
2983 [EditorBrowsable (EditorBrowsableState.Advanced)]
2985 public bool Focus() {
2986 if (CanFocus && IsHandleCreated && !has_focus && !is_focusing) {
2989 is_focusing = false;
2994 public Control GetChildAtPoint(Point pt) {
2995 // Microsoft's version of this function doesn't seem to work, so I can't check
2996 // if we only consider children or also grandchildren, etc.
2997 // I'm gonna say 'children only'
2998 for (int i=0; i<child_controls.Count; i++) {
2999 if (child_controls[i].Bounds.Contains(pt)) {
3000 return child_controls[i];
3006 public IContainerControl GetContainerControl() {
3007 Control current = this;
3009 while (current!=null) {
3010 if ((current is IContainerControl) && ((current.control_style & ControlStyles.ContainerControl)!=0)) {
3011 return (IContainerControl)current;
3013 current = current.parent;
3018 public Control GetNextControl(Control ctl, bool forward) {
3020 if (!this.Contains(ctl)) {
3025 ctl = FindControlForward(this, ctl);
3028 ctl = FindControlBackward(this, ctl);
3038 [EditorBrowsable (EditorBrowsableState.Advanced)]
3039 public virtual Size GetPreferredSize (Size proposedSize) {
3040 return preferred_size;
3044 public void Hide() {
3045 this.Visible = false;
3048 public void Invalidate() {
3049 Invalidate(ClientRectangle, false);
3052 public void Invalidate(bool invalidateChildren) {
3053 Invalidate(ClientRectangle, invalidateChildren);
3056 public void Invalidate(System.Drawing.Rectangle rc) {
3057 Invalidate(rc, false);
3060 public void Invalidate(System.Drawing.Rectangle rc, bool invalidateChildren) {
3061 if (!IsHandleCreated || !Visible || rc.Width == 0 || rc.Height == 0) {
3065 NotifyInvalidate(rc);
3067 XplatUI.Invalidate(Handle, rc, false);
3069 if (invalidateChildren) {
3070 Control [] controls = child_controls.GetAllControls ();
3071 for (int i=0; i<controls.Length; i++)
3072 controls [i].Invalidate ();
3074 OnInvalidated(new InvalidateEventArgs(rc));
3077 public void Invalidate(System.Drawing.Region region) {
3078 Invalidate(region, false);
3081 public void Invalidate(System.Drawing.Region region, bool invalidateChildren) {
3082 RectangleF bounds = region.GetBounds (CreateGraphics ());
3083 Invalidate (new Rectangle ((int) bounds.X, (int) bounds.Y, (int) bounds.Width, (int) bounds.Height),
3084 invalidateChildren);
3087 public object Invoke (Delegate method) {
3088 object [] prms = null;
3089 if (method is EventHandler)
3090 prms = new object [] { this, EventArgs.Empty };
3092 return Invoke(method, prms);
3095 public object Invoke (Delegate method, object[] args) {
3096 if (!this.InvokeRequired) {
3097 return method.DynamicInvoke(args);
3100 IAsyncResult result = BeginInvoke (method, args);
3101 return EndInvoke(result);
3104 internal object InvokeInternal (Delegate method, bool disposing) {
3105 return InvokeInternal(method, null, disposing);
3108 internal object InvokeInternal (Delegate method, object[] args, bool disposing) {
3109 if (!this.InvokeRequired) {
3110 return method.DynamicInvoke(args);
3113 IAsyncResult result = BeginInvokeInternal (method, args, disposing);
3114 return EndInvoke(result);
3117 [EditorBrowsable(EditorBrowsableState.Advanced)]
3118 public void PerformLayout() {
3119 PerformLayout(null, null);
3123 private void SetImplicitBounds (int x, int y, int width, int height)
3125 Rectangle saved_bounds = explicit_bounds;
3126 SetBounds (x, y, width, height);
3127 explicit_bounds = saved_bounds;
3131 [EditorBrowsable(EditorBrowsableState.Advanced)]
3132 public void PerformLayout(Control affectedControl, string affectedProperty) {
3133 LayoutEventArgs levent = new LayoutEventArgs(affectedControl, affectedProperty);
3135 if (layout_suspended > 0) {
3136 layout_pending = true;
3140 layout_pending = false;
3142 // Prevent us from getting messed up
3145 // Perform all Dock and Anchor calculations
3149 if (this.layout_engine != null)
3150 this.layout_engine.Layout(this, levent);
3152 // This has been moved to Layout/DefaultLayout.cs for 2.0, please duplicate any changes/fixes there.
3154 AnchorStyles anchor;
3157 space = DisplayRectangle;
3159 // Deal with docking; go through in reverse, MS docs say that lowest Z-order is closest to edge
3160 Control [] controls = child_controls.GetAllControls ();
3161 for (int i = controls.Length - 1; i >= 0; i--) {
3162 child = controls [i];
3164 if (!child.Visible) {
3168 switch (child.Dock) {
3169 case DockStyle.None: {
3174 case DockStyle.Left: {
3175 child.SetImplicitBounds(space.Left, space.Y, child.Width, space.Height);
3176 space.X+=child.Width;
3177 space.Width-=child.Width;
3181 case DockStyle.Top: {
3182 child.SetImplicitBounds(space.Left, space.Y, space.Width, child.Height);
3183 space.Y+=child.Height;
3184 space.Height-=child.Height;
3188 case DockStyle.Right: {
3189 child.SetImplicitBounds(space.Right-child.Width, space.Y, child.Width, space.Height);
3190 space.Width-=child.Width;
3194 case DockStyle.Bottom: {
3195 child.SetImplicitBounds(space.Left, space.Bottom-child.Height, space.Width, child.Height);
3196 space.Height-=child.Height;
3202 for (int i = controls.Length - 1; i >= 0; i--) {
3205 //if (child.Visible && (child.Dock == DockStyle.Fill)) {
3206 if (child.Dock == DockStyle.Fill) {
3207 child.SetImplicitBounds(space.Left, space.Top, space.Width, space.Height);
3211 space = DisplayRectangle;
3213 for (int i=0; i < controls.Length; i++) {
3219 child = controls[i];
3221 // If the control is docked we don't need to do anything
3222 if (child.Dock != DockStyle.None) {
3226 anchor = child.Anchor;
3230 width = child.Width;
3231 height = child.Height;
3233 if ((anchor & AnchorStyles.Left) !=0 ) {
3234 if ((anchor & AnchorStyles.Right) != 0) {
3235 width = space.Width - child.dist_right - left;
3237 ; // Left anchored only, nothing to be done
3239 } else if ((anchor & AnchorStyles.Right) != 0) {
3240 left = space.Width - child.dist_right - width;
3242 // left+=diff_width/2 will introduce rounding errors (diff_width removed from svn after r51780)
3243 // This calculates from scratch every time:
3244 left = child.dist_left + (space.Width - (child.dist_left + width + child.dist_right)) / 2;
3247 if ((anchor & AnchorStyles.Top) !=0 ) {
3248 if ((anchor & AnchorStyles.Bottom) != 0) {
3249 height = space.Height - child.dist_bottom - top;
3251 ; // Top anchored only, nothing to be done
3253 } else if ((anchor & AnchorStyles.Bottom) != 0) {
3254 top = space.Height - child.dist_bottom - height;
3256 // top += diff_height/2 will introduce rounding errors (diff_height removed from after r51780)
3257 // This calculates from scratch every time:
3258 top = child.dist_top + (space.Height - (child.dist_top + height + child.dist_bottom)) / 2;
3270 child.SetImplicitBounds(left, top, width, height);
3274 // Let everyone know
3278 // Need to make sure we decremend layout_suspended
3284 public Point PointToClient (Point p) {
3288 XplatUI.ScreenToClient (Handle, ref x, ref y);
3290 return new Point (x, y);
3293 public Point PointToScreen(Point p) {
3297 XplatUI.ClientToScreen(Handle, ref x, ref y);
3299 return new Point(x, y);
3302 public virtual bool PreProcessMessage(ref Message msg) {
3303 return InternalPreProcessMessage (ref msg);
3306 internal virtual bool InternalPreProcessMessage (ref Message msg) {
3309 if ((msg.Msg == (int)Msg.WM_KEYDOWN) || (msg.Msg == (int)Msg.WM_SYSKEYDOWN)) {
3310 key_data = (Keys)msg.WParam.ToInt32() | XplatUI.State.ModifierKeys;
3312 if (!ProcessCmdKey(ref msg, key_data)) {
3313 if (IsInputKey(key_data)) {
3317 return ProcessDialogKey(key_data);
3321 } else if (msg.Msg == (int)Msg.WM_CHAR) {
3322 if (IsInputChar((char)msg.WParam)) {
3325 return ProcessDialogChar((char)msg.WParam);
3326 } else if (msg.Msg == (int)Msg.WM_SYSCHAR) {
3327 return ProcessDialogChar((char)msg.WParam);
3332 public Rectangle RectangleToClient(Rectangle r) {
3333 return new Rectangle(PointToClient(r.Location), r.Size);
3336 public Rectangle RectangleToScreen(Rectangle r) {
3337 return new Rectangle(PointToScreen(r.Location), r.Size);
3340 public virtual void Refresh() {
3341 if (IsHandleCreated == true) {
3343 XplatUI.UpdateWindow(window.Handle);
3345 Control [] controls = child_controls.GetAllControls ();
3346 for (int i=0; i < controls.Length; i++) {
3347 controls[i].Refresh();
3353 [EditorBrowsable(EditorBrowsableState.Never)]
3354 public virtual void ResetBackColor() {
3355 BackColor = Color.Empty;
3358 [EditorBrowsable(EditorBrowsableState.Never)]
3359 public void ResetBindings() {
3360 data_bindings.Clear();
3363 [EditorBrowsable(EditorBrowsableState.Never)]
3364 public virtual void ResetCursor() {
3368 [EditorBrowsable(EditorBrowsableState.Never)]
3369 public virtual void ResetFont() {
3373 [EditorBrowsable(EditorBrowsableState.Never)]
3374 public virtual void ResetForeColor() {
3375 foreground_color = Color.Empty;
3378 [EditorBrowsable(EditorBrowsableState.Never)]
3379 public void ResetImeMode() {
3380 ime_mode = DefaultImeMode;
3383 [EditorBrowsable(EditorBrowsableState.Never)]
3384 public virtual void ResetRightToLeft() {
3385 right_to_left = RightToLeft.Inherit;
3388 public virtual void ResetText() {
3389 text = String.Empty;
3392 public void ResumeLayout() {
3393 ResumeLayout (true);
3396 public void ResumeLayout(bool performLayout) {
3397 if (layout_suspended > 0) {
3401 if (layout_suspended == 0) {
3402 Control [] controls = child_controls.GetAllControls ();
3403 if (performLayout && layout_pending) {
3409 [EditorBrowsable (EditorBrowsableState.Never)]
3412 public void Scale(float ratio) {
3413 ScaleCore(ratio, ratio);
3417 [EditorBrowsable (EditorBrowsableState.Never)]
3420 public void Scale(float dx, float dy) {
3425 [EditorBrowsable (EditorBrowsableState.Advanced)]
3426 public void Scale(SizeF factor) {
3427 ScaleCore(factor.Width, factor.Height);
3431 public void Select() {
3432 if (this is ContainerControl)
3433 ContainerSelected = true;
3435 Control c = this.Parent;
3437 c.ContainerSelected = false;
3441 Select(false, false);
3445 private void printTree(Control c, string t) {
3446 foreach(Control i in c.child_controls) {
3447 Console.WriteLine("{2}{0}.TabIndex={1}", i, i.tab_index, t);
3448 printTree(i, t+"\t");
3452 public bool SelectNextControl(Control ctl, bool forward, bool tabStopOnly, bool nested, bool wrap) {
3456 Console.WriteLine("{0}", this.FindForm());
3457 printTree(this, "\t");
3460 if (!this.Contains(ctl) || (!nested && (ctl.parent != this))) {
3465 c = GetNextControl(c, forward);
3474 if (c.CanSelect && ((c.parent == this) || nested) && (c.tab_stop || !tabStopOnly)) {
3475 c.Select (true, true);
3478 } while (c != ctl); // If we wrap back to ourselves we stop
3483 public void SendToBack() {
3484 if (parent != null) {
3485 parent.child_controls.SetChildIndex(this, parent.child_controls.Count);
3489 public void SetBounds(int x, int y, int width, int height) {
3490 SetBounds(x, y, width, height, BoundsSpecified.All);
3493 public void SetBounds(int x, int y, int width, int height, BoundsSpecified specified) {
3494 if ((specified & BoundsSpecified.X) != BoundsSpecified.X) {
3498 if ((specified & BoundsSpecified.Y) != BoundsSpecified.Y) {
3502 if ((specified & BoundsSpecified.Width) != BoundsSpecified.Width) {
3506 if ((specified & BoundsSpecified.Height) != BoundsSpecified.Height) {
3510 SetBoundsCore(x, y, width, height, specified);
3511 if (parent != null) {
3512 parent.PerformLayout(this, "Bounds");
3516 public void Show() {
3518 this.CreateControl();
3524 public void SuspendLayout() {
3528 public void Update() {
3529 if (IsHandleCreated) {
3530 XplatUI.UpdateWindow(window.Handle);
3533 #endregion // Public Instance Methods
3535 #region Protected Instance Methods
3536 [EditorBrowsable(EditorBrowsableState.Advanced)]
3537 [MonoTODO("Implement this and tie it into Control.ControlAccessibleObject.NotifyClients")]
3538 protected void AccessibilityNotifyClients(AccessibleEvents accEvent, int childID) {
3539 throw new NotImplementedException();
3542 [EditorBrowsable(EditorBrowsableState.Advanced)]
3543 protected virtual AccessibleObject CreateAccessibilityInstance() {
3544 return new Control.ControlAccessibleObject(this);
3547 [EditorBrowsable(EditorBrowsableState.Advanced)]
3548 protected virtual ControlCollection CreateControlsInstance() {
3549 return new ControlCollection(this);
3552 [EditorBrowsable(EditorBrowsableState.Advanced)]
3553 protected virtual void CreateHandle() {
3555 throw new ObjectDisposedException(GetType().FullName.ToString());
3558 if (IsHandleCreated && !is_recreating) {
3562 window.CreateHandle(CreateParams);
3564 if (window.Handle != IntPtr.Zero) {
3565 creator_thread = Thread.CurrentThread;
3567 XplatUI.EnableWindow(window.Handle, is_enabled);
3568 XplatUI.SetVisible(window.Handle, is_visible, true);
3570 if (clip_region != null) {
3571 XplatUI.SetClipRegion(Handle, clip_region);
3574 // Set our handle with our parent
3575 if ((parent != null) && (parent.IsHandleCreated)) {
3576 XplatUI.SetParent(window.Handle, parent.Handle);
3579 // Set our handle as parent for our children
3580 Control [] children;
3582 children = child_controls.GetAllControls ();
3583 for (int i = 0; i < children.Length; i++ ) {
3584 if (!children[i].RecreatingHandle)
3585 XplatUI.SetParent(children[i].Handle, window.Handle);
3589 XplatUI.SetAllowDrop (Handle, allow_drop);
3591 // Find out where the window manager placed us
3592 if ((CreateParams.Style & (int)WindowStyles.WS_CHILD) != 0) {
3593 XplatUI.SetBorderStyle(window.Handle, (FormBorderStyle)border_style);
3597 OnHandleCreated(EventArgs.Empty);
3601 [EditorBrowsable(EditorBrowsableState.Advanced)]
3602 protected virtual void DefWndProc(ref Message m) {
3603 window.DefWndProc(ref m);
3606 [EditorBrowsable(EditorBrowsableState.Advanced)]
3607 protected virtual void DestroyHandle() {
3608 if (IsHandleCreated) {
3609 if (window != null) {
3610 window.DestroyHandle();
3615 protected internal bool GetStyle(ControlStyles flag) {
3616 return (control_style & flag) != 0;
3619 protected bool GetTopLevel() {
3623 [EditorBrowsable(EditorBrowsableState.Advanced)]
3624 protected virtual void InitLayout() {
3628 [EditorBrowsable(EditorBrowsableState.Advanced)]
3629 protected void InvokeGotFocus(Control toInvoke, EventArgs e) {
3630 toInvoke.OnGotFocus(e);
3633 [EditorBrowsable(EditorBrowsableState.Advanced)]
3634 protected void InvokeLostFocus(Control toInvoke, EventArgs e) {
3635 toInvoke.OnLostFocus(e);
3638 [EditorBrowsable(EditorBrowsableState.Advanced)]
3639 protected void InvokeOnClick(Control toInvoke, EventArgs e) {
3640 toInvoke.OnClick(e);
3643 protected void InvokePaint(Control toInvoke, PaintEventArgs e) {
3644 toInvoke.OnPaint(e);
3647 protected void InvokePaintBackground(Control toInvoke, PaintEventArgs e) {
3648 toInvoke.OnPaintBackground(e);
3651 protected virtual bool IsInputChar (char charCode) {
3655 protected virtual bool IsInputKey (Keys keyData) {
3656 // Doc says this one calls IsInputChar; not sure what to do with that
3660 [EditorBrowsable(EditorBrowsableState.Advanced)]
3661 protected virtual void NotifyInvalidate(Rectangle invalidatedArea) {
3665 protected virtual bool ProcessCmdKey(ref Message msg, Keys keyData) {
3666 if ((context_menu != null) && context_menu.ProcessCmdKey(ref msg, keyData)) {
3670 if (parent != null) {
3671 return parent.ProcessCmdKey(ref msg, keyData);
3677 protected virtual bool ProcessDialogChar(char charCode) {
3678 if (parent != null) {
3679 return parent.ProcessDialogChar (charCode);
3685 protected virtual bool ProcessDialogKey (Keys keyData) {
3686 if (parent != null) {
3687 return parent.ProcessDialogKey (keyData);
3693 protected virtual bool ProcessKeyEventArgs (ref Message msg)
3695 KeyEventArgs key_event;
3698 case (int)Msg.WM_SYSKEYDOWN:
3699 case (int)Msg.WM_KEYDOWN: {
3700 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
3701 OnKeyDown (key_event);
3702 return key_event.Handled;
3705 case (int)Msg.WM_SYSKEYUP:
3706 case (int)Msg.WM_KEYUP: {
3707 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
3708 OnKeyUp (key_event);
3709 return key_event.Handled;
3712 case (int)Msg.WM_SYSCHAR:
3713 case (int)Msg.WM_CHAR: {
3714 KeyPressEventArgs key_press_event;
3716 key_press_event = new KeyPressEventArgs((char)msg.WParam);
3717 OnKeyPress(key_press_event);
3719 msg.WParam = (IntPtr)key_press_event.KeyChar;
3721 return key_press_event.Handled;
3732 protected internal virtual bool ProcessKeyMessage(ref Message msg) {
3733 if (parent != null) {
3734 if (parent.ProcessKeyPreview(ref msg)) {
3739 return ProcessKeyEventArgs(ref msg);
3742 protected virtual bool ProcessKeyPreview(ref Message msg) {
3743 if (parent != null) {
3744 return parent.ProcessKeyPreview(ref msg);
3750 protected virtual bool ProcessMnemonic(char charCode) {
3755 [EditorBrowsable(EditorBrowsableState.Advanced)]
3756 protected void RaiseDragEvent(object key, DragEventArgs e) {
3760 [EditorBrowsable(EditorBrowsableState.Advanced)]
3761 protected void RaiseKeyEvent(object key, KeyEventArgs e) {
3765 [EditorBrowsable(EditorBrowsableState.Advanced)]
3766 protected void RaiseMouseEvent(object key, MouseEventArgs e) {
3770 [EditorBrowsable(EditorBrowsableState.Advanced)]
3771 protected void RaisePaintEvent(object key, PaintEventArgs e) {
3775 private void SetIsRecreating ()
3779 foreach (Control c in Controls.GetAllControls()) {
3780 c.SetIsRecreating ();
3784 [EditorBrowsable(EditorBrowsableState.Advanced)]
3785 protected void RecreateHandle() {
3787 Console.WriteLine("Recreating control {0}", XplatUI.Window(window.Handle));
3792 if (IsHandleCreated) {
3794 Console.WriteLine(" + handle is created, destroying it.");
3797 // WM_DESTROY will CreateHandle for us
3800 Console.WriteLine(" + handle is not created, creating it.");
3808 is_recreating = false;
3810 Console.WriteLine (" + new handle = {0:X}", Handle.ToInt32());
3816 [EditorBrowsable(EditorBrowsableState.Advanced)]
3817 protected void ResetMouseEventArgs() {
3821 [EditorBrowsable(EditorBrowsableState.Advanced)]
3822 protected ContentAlignment RtlTranslateAlignment(ContentAlignment align) {
3823 if (right_to_left == RightToLeft.No) {
3828 case ContentAlignment.TopLeft: {
3829 return ContentAlignment.TopRight;
3832 case ContentAlignment.TopRight: {
3833 return ContentAlignment.TopLeft;
3836 case ContentAlignment.MiddleLeft: {
3837 return ContentAlignment.MiddleRight;
3840 case ContentAlignment.MiddleRight: {
3841 return ContentAlignment.MiddleLeft;
3844 case ContentAlignment.BottomLeft: {
3845 return ContentAlignment.BottomRight;
3848 case ContentAlignment.BottomRight: {
3849 return ContentAlignment.BottomLeft;
3853 // if it's center it doesn't change
3859 [EditorBrowsable(EditorBrowsableState.Advanced)]
3860 protected HorizontalAlignment RtlTranslateAlignment(HorizontalAlignment align) {
3861 if ((right_to_left == RightToLeft.No) || (align == HorizontalAlignment.Center)) {
3865 if (align == HorizontalAlignment.Left) {
3866 return HorizontalAlignment.Right;
3869 // align must be HorizontalAlignment.Right
3870 return HorizontalAlignment.Left;
3873 [EditorBrowsable(EditorBrowsableState.Advanced)]
3874 protected LeftRightAlignment RtlTranslateAlignment(LeftRightAlignment align) {
3875 if (right_to_left == RightToLeft.No) {
3879 if (align == LeftRightAlignment.Left) {
3880 return LeftRightAlignment.Right;
3883 // align must be LeftRightAlignment.Right;
3884 return LeftRightAlignment.Left;
3887 [EditorBrowsable(EditorBrowsableState.Advanced)]
3888 protected ContentAlignment RtlTranslateContent(ContentAlignment align) {
3889 return RtlTranslateAlignment(align);
3892 [EditorBrowsable(EditorBrowsableState.Advanced)]
3893 protected HorizontalAlignment RtlTranslateHorizontal(HorizontalAlignment align) {
3894 return RtlTranslateAlignment(align);
3897 [EditorBrowsable(EditorBrowsableState.Advanced)]
3898 protected LeftRightAlignment RtlTranslateLeftRight(LeftRightAlignment align) {
3899 return RtlTranslateAlignment(align);
3903 [EditorBrowsable (EditorBrowsableState.Never)]
3905 [EditorBrowsable(EditorBrowsableState.Advanced)]
3907 protected virtual void ScaleCore(float dx, float dy) {
3913 location = new Point((int)(Left * dx), (int)(Top * dy));
3914 size = this.ClientSize;
3916 if (!GetStyle(ControlStyles.FixedWidth)) {
3917 size.Width = (int)(size.Width * dx);
3920 if (!GetStyle(ControlStyles.FixedHeight)) {
3921 size.Height = (int)(size.Height * dy);
3924 SetBounds(location.X, location.Y, size.Width, size.Height, BoundsSpecified.All);
3926 /* Now scale our children */
3927 Control [] controls = child_controls.GetAllControls ();
3928 for (int i=0; i < controls.Length; i++) {
3929 controls[i].Scale(dx, dy);
3935 protected virtual void Select(bool directed, bool forward) {
3936 IContainerControl container;
3938 container = GetContainerControl();
3939 if (container != null)
3940 container.ActiveControl = this;
3943 [EditorBrowsable(EditorBrowsableState.Advanced)]
3944 protected virtual void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
3945 // SetBoundsCore updates the Win32 control itself. UpdateBounds updates the controls variables and fires events, I'm guessing - pdb
3946 if (IsHandleCreated) {
3947 XplatUI.SetWindowPos(Handle, x, y, width, height);
3949 // Win32 automatically changes negative width/height to 0.
3950 // The control has already been sent a WM_WINDOWPOSCHANGED message and it has the correct
3951 // data, but it'll be overwritten when we call UpdateBounds unless we get the updated
3953 if (width < 0 || height < 0) {
3955 XplatUI.GetWindowPos(Handle, this is Form, out ix, out iy, out width, out height, out cw, out ch);
3959 UpdateBounds(x, y, width, height);
3964 [EditorBrowsable(EditorBrowsableState.Advanced)]
3965 protected virtual void SetClientSizeCore(int x, int y) {
3966 // Calculate the actual window size from the client size (it usually stays the same or grows)
3967 Rectangle ClientRect;
3968 Rectangle WindowRect;
3971 ClientRect = new Rectangle(0, 0, x, y);
3972 cp = this.CreateParams;
3974 if (XplatUI.CalculateWindowRect(ref ClientRect, cp.Style, cp.ExStyle, null, out WindowRect)==false) {
3978 SetBounds(bounds.X, bounds.Y, WindowRect.Width, WindowRect.Height, BoundsSpecified.Size);
3981 [EditorBrowsable(EditorBrowsableState.Advanced)]
3982 protected internal void SetStyle(ControlStyles flag, bool value) {
3984 control_style |= flag;
3986 control_style &= ~flag;
3990 protected void SetTopLevel(bool value) {
3991 if ((GetTopLevel() != value) && (parent != null)) {
3992 throw new Exception();
3996 if (value == true) {
4006 is_toplevel = value;
4009 protected virtual void SetVisibleCore(bool value) {
4010 if (value!=is_visible) {
4011 if (value && (window.Handle == IntPtr.Zero) || !is_created) {
4017 if (IsHandleCreated) {
4018 XplatUI.SetVisible(Handle, value, true);
4019 // Explicitly move Toplevel windows to where we want them;
4020 // apparently moving unmapped toplevel windows doesn't work
4021 if (is_visible && (this is Form)) {
4022 XplatUI.SetWindowPos(window.Handle, bounds.X, bounds.Y, bounds.Width, bounds.Height);
4026 OnVisibleChanged(EventArgs.Empty);
4028 if (value == false && parent != null && Focused) {
4031 // Need to start at parent, GetContainerControl might return ourselves if we're a container
4032 container = (Control)parent.GetContainerControl();
4033 if (container != null) {
4034 container.SelectNextControl(this, true, true, true, true);
4038 if (parent != null) {
4039 parent.PerformLayout(this, "visible");
4041 PerformLayout(this, "visible");
4046 [EditorBrowsable(EditorBrowsableState.Advanced)]
4047 protected void UpdateBounds() {
4055 if (!IsHandleCreated) {
4059 XplatUI.GetWindowPos(this.Handle, this is Form, out x, out y, out width, out height, out client_width, out client_height);
4061 UpdateBounds(x, y, width, height, client_width, client_height);
4064 [EditorBrowsable(EditorBrowsableState.Advanced)]
4065 protected void UpdateBounds(int x, int y, int width, int height) {
4069 // Calculate client rectangle
4070 rect = new Rectangle(0, 0, 0, 0);
4073 XplatUI.CalculateWindowRect(ref rect, cp.Style, cp.ExStyle, cp.menu, out rect);
4074 UpdateBounds(x, y, width, height, width - (rect.Right - rect.Left), height - (rect.Bottom - rect.Top));
4077 [EditorBrowsable(EditorBrowsableState.Advanced)]
4078 protected void UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) {
4079 // UpdateBounds only seems to set our sizes and fire events but not update the GUI window to match
4081 bool resized = false;
4083 // Needed to generate required notifications
4084 if ((this.bounds.X!=x) || (this.bounds.Y!=y)) {
4088 if ((this.Bounds.Width!=width) || (this.Bounds.Height!=height)) {
4095 bounds.Height=height;
4097 // Assume explicit bounds set. SetImplicitBounds will restore old bounds
4098 explicit_bounds = bounds;
4100 client_size.Width=clientWidth;
4101 client_size.Height=clientHeight;
4104 OnLocationChanged(EventArgs.Empty);
4108 OnSizeChanged(EventArgs.Empty);
4112 [EditorBrowsable(EditorBrowsableState.Advanced)]
4113 protected void UpdateStyles() {
4114 if (!IsHandleCreated) {
4118 XplatUI.SetWindowStyle(window.Handle, CreateParams);
4119 OnStyleChanged(EventArgs.Empty);
4122 private void UpdateZOrderOfChild(Control child) {
4123 if (IsHandleCreated && child.IsHandleCreated && (child.parent == this)) {
4126 index = child_controls.IndexOf(child);
4129 XplatUI.SetZOrder(child.Handle, child_controls[index - 1].Handle, false, false);
4131 IntPtr after = AfterTopMostControl ();
4132 if (after != IntPtr.Zero)
4133 XplatUI.SetZOrder (child.Handle, after, false, false);
4135 XplatUI.SetZOrder (child.Handle, IntPtr.Zero, true, false);
4140 // Override this if there is a control that shall always remain on
4141 // top of other controls (such as scrollbars). If there are several
4142 // of these controls, the bottom-most should be returned.
4143 internal virtual IntPtr AfterTopMostControl ()
4148 private void UpdateChildrenZOrder() {
4149 Control [] controls;
4151 if (!IsHandleCreated) {
4155 controls = child_controls.GetAllControls ();
4156 for (int i = 1; i < controls.Length; i++ ) {
4157 XplatUI.SetZOrder(controls[i].Handle, controls[i-1].Handle, false, false);
4161 [EditorBrowsable(EditorBrowsableState.Advanced)]
4162 protected void UpdateZOrder() {
4163 if (parent != null) {
4164 parent.UpdateZOrderOfChild(this);
4168 protected virtual void WndProc(ref Message m) {
4170 Console.WriteLine("Control {0} received message {1}", window.Handle == IntPtr.Zero ? this.Text : XplatUI.Window(window.Handle), m.ToString ());
4172 if ((this.control_style & ControlStyles.EnableNotifyMessage) != 0) {
4176 switch((Msg)m.Msg) {
4177 case Msg.WM_DESTROY: {
4178 OnHandleDestroyed(EventArgs.Empty);
4180 IntPtr handle = window.Handle;
4182 window.InvalidateHandle();
4184 if (is_recreating) {
4186 Console.WriteLine ("Creating handle for {0:X}", handle.ToInt32());
4190 Console.WriteLine (" + new handle = {0:X}", Handle.ToInt32());
4192 is_recreating = false;
4197 case Msg.WM_WINDOWPOSCHANGED: {
4199 Rectangle save_bounds = explicit_bounds;
4201 explicit_bounds = save_bounds;
4202 if (GetStyle(ControlStyles.ResizeRedraw)) {
4209 // Nice description of what should happen when handling WM_PAINT
4210 // can be found here: http://pluralsight.com/wiki/default.aspx/Craig/FlickerFreeControlDrawing.html
4211 // and here http://msdn.microsoft.com/msdnmag/issues/06/03/WindowsFormsPerformance/
4212 case Msg.WM_PAINT: {
4213 PaintEventArgs paint_event;
4215 paint_event = XplatUI.PaintEventStart(Handle, true);
4217 if (paint_event == null) {
4221 if (invalid_region != null && !invalid_region.IsVisible (paint_event.ClipRectangle)) {
4223 // Just blit the previous image
4224 XplatUI.BlitFromOffscreen (Handle, paint_event.Graphics, backbuffer, backbuffer_dc, paint_event.ClipRectangle);
4225 XplatUI.PaintEventEnd (Handle, true);
4230 Graphics back_dc = null;
4232 if (ThemeEngine.Current.DoubleBufferingSupported) {
4233 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
4234 CreateBackBuffer ();
4236 back_dc = backbuffer_dc;
4237 dc = paint_event.SetGraphics (back_dc);
4241 if (!GetStyle(ControlStyles.Opaque)) {
4242 OnPaintBackground(paint_event);
4245 // Button-derived controls choose to ignore their Opaque style, give them a chance to draw their background anyways
4246 OnPaintBackgroundInternal(paint_event);
4248 OnPaintInternal(paint_event);
4249 if (!paint_event.Handled) {
4250 OnPaint(paint_event);
4253 if (ThemeEngine.Current.DoubleBufferingSupported)
4254 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
4255 XplatUI.BlitFromOffscreen (Handle, dc, back, back_dc, paint_event.ClipRectangle);
4256 paint_event.SetGraphics (dc);
4257 invalid_region.Exclude (paint_event.ClipRectangle);
4259 if (back != backbuffer)
4260 XplatUI.DestroyOffscreenDrawable (back, back_dc);
4263 XplatUI.PaintEventEnd(Handle, true);
4268 case Msg.WM_ERASEBKGND: {
4269 // The DefWndProc will never have to handle this, we always paint the background in managed code
4270 // In theory this code would look at ControlStyles.AllPaintingInWmPaint and and call OnPaintBackground
4271 // here but it just makes things more complicated...
4272 m.Result = (IntPtr)1;
4276 case Msg.WM_LBUTTONUP: {
4279 me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Left,
4281 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4284 HandleClick(mouse_clicks, me);
4287 if (InternalCapture) {
4288 InternalCapture = false;
4291 if (mouse_clicks > 1) {
4297 case Msg.WM_LBUTTONDOWN: {
4299 Select (true, true);
4301 InternalCapture = true;
4302 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4303 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4309 case Msg.WM_LBUTTONDBLCLK: {
4310 InternalCapture = true;
4312 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4313 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4318 case Msg.WM_MBUTTONUP: {
4321 me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Middle,
4323 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4326 HandleClick(mouse_clicks, me);
4328 if (InternalCapture) {
4329 InternalCapture = false;
4331 if (mouse_clicks > 1) {
4337 case Msg.WM_MBUTTONDOWN: {
4338 InternalCapture = true;
4339 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4340 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4345 case Msg.WM_MBUTTONDBLCLK: {
4346 InternalCapture = true;
4348 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4349 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4354 case Msg.WM_RBUTTONUP: {
4358 pt = new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()));
4359 pt = PointToScreen(pt);
4361 XplatUI.SendMessage(m.HWnd, Msg.WM_CONTEXTMENU, m.HWnd, (IntPtr)(pt.X + (pt.Y << 16)));
4363 me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Right,
4365 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4368 HandleClick(mouse_clicks, me);
4371 if (InternalCapture) {
4372 InternalCapture = false;
4375 if (mouse_clicks > 1) {
4381 case Msg.WM_RBUTTONDOWN: {
4382 InternalCapture = true;
4383 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4384 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4389 case Msg.WM_RBUTTONDBLCLK: {
4390 InternalCapture = true;
4392 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4393 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4398 case Msg.WM_CONTEXTMENU: {
4399 if (context_menu != null) {
4402 pt = new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()));
4404 if (pt.X == -1 || pt.Y == -1) {
4405 pt.X = (this.Width / 2) + this.Left;
4406 pt.Y = (this.Height / 2) + this.Top;
4407 pt = this.PointToScreen (pt);
4410 context_menu.Show (this, PointToClient (pt));
4415 // If there isn't a regular context menu, show the Strip version
4416 if (context_menu == null && context_menu_strip != null) {
4419 pt = new Point (LowOrder ((int)m.LParam.ToInt32 ()), HighOrder ((int)m.LParam.ToInt32 ()));
4421 if (pt.X == -1 || pt.Y == -1) {
4422 pt.X = (this.Width / 2) + this.Left;
4423 pt.Y = (this.Height /2) + this.Top;
4424 pt = this.PointToScreen (pt);
4427 context_menu_strip.Show (this, PointToClient (pt));
4435 case Msg.WM_MOUSEWHEEL: {
4437 OnMouseWheel (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4438 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4439 HighOrder(m.WParam.ToInt32())));
4444 case Msg.WM_MOUSEMOVE: {
4445 OnMouseMove (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4447 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4452 case Msg.WM_MOUSE_ENTER: {
4457 OnMouseEnter(EventArgs.Empty);
4461 case Msg.WM_MOUSE_LEAVE: {
4463 OnMouseLeave(EventArgs.Empty);
4467 case Msg.WM_MOUSEHOVER: {
4468 OnMouseHover(EventArgs.Empty);
4472 case Msg.WM_SYSKEYUP: {
4473 if (ProcessKeyMessage(ref m)) {
4474 m.Result = IntPtr.Zero;
4478 if ((m.WParam.ToInt32() & (int)Keys.KeyCode) == (int)Keys.Menu) {
4482 if (form != null && form.ActiveMenu != null) {
4483 form.ActiveMenu.ProcessCmdKey(ref m, (Keys)m.WParam.ToInt32());
4491 case Msg.WM_SYSKEYDOWN:
4492 case Msg.WM_KEYDOWN:
4494 case Msg.WM_SYSCHAR:
4496 if (ProcessKeyMessage(ref m)) {
4497 m.Result = IntPtr.Zero;
4506 if (m.LParam != IntPtr.Zero) {
4509 hi = new HELPINFO();
4511 hi = (HELPINFO) Marshal.PtrToStructure (m.LParam, typeof (HELPINFO));
4512 mouse_pos = new Point(hi.MousePos.x, hi.MousePos.y);
4514 mouse_pos = Control.MousePosition;
4516 OnHelpRequested(new HelpEventArgs(mouse_pos));
4517 m.Result = (IntPtr)1;
4521 case Msg.WM_KILLFOCUS: {
4522 this.has_focus = false;
4523 OnLostFocusInternal (EventArgs.Empty);
4527 case Msg.WM_SETFOCUS: {
4529 this.has_focus = true;
4530 if (this.Parent != null && this.Parent.ContainerSelected)
4532 OnGotFocusInternal (EventArgs.Empty);
4537 case Msg.WM_SYSCOLORCHANGE: {
4538 ThemeEngine.Current.ResetDefaults();
4539 OnSystemColorsChanged(EventArgs.Empty);
4543 case Msg.WM_SETCURSOR: {
4544 if ((cursor == null) || ((HitTest)(m.LParam.ToInt32() & 0xffff) != HitTest.HTCLIENT)) {
4549 XplatUI.SetCursor(window.Handle, cursor.handle);
4550 m.Result = (IntPtr)1;
4560 #endregion // Public Instance Methods
4562 #region OnXXX methods
4563 [EditorBrowsable(EditorBrowsableState.Advanced)]
4564 protected virtual void OnBackColorChanged(EventArgs e) {
4565 EventHandler eh = (EventHandler)(Events [BackColorChangedEvent]);
4568 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackColorChanged(e);
4571 [EditorBrowsable(EditorBrowsableState.Advanced)]
4572 protected virtual void OnBackgroundImageChanged(EventArgs e) {
4573 EventHandler eh = (EventHandler)(Events [BackgroundImageChangedEvent]);
4576 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackgroundImageChanged(e);
4579 [EditorBrowsable(EditorBrowsableState.Advanced)]
4580 protected virtual void OnBindingContextChanged(EventArgs e) {
4581 CheckDataBindings ();
4582 EventHandler eh = (EventHandler)(Events [BindingContextChangedEvent]);
4585 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBindingContextChanged(e);
4588 [EditorBrowsable(EditorBrowsableState.Advanced)]
4589 protected virtual void OnCausesValidationChanged(EventArgs e) {
4590 EventHandler eh = (EventHandler)(Events [CausesValidationChangedEvent]);
4595 [EditorBrowsable(EditorBrowsableState.Advanced)]
4596 protected virtual void OnChangeUICues(UICuesEventArgs e) {
4597 UICuesEventHandler eh = (UICuesEventHandler)(Events [ChangeUICuesEvent]);
4602 [EditorBrowsable(EditorBrowsableState.Advanced)]
4603 protected virtual void OnClick(EventArgs e) {
4604 EventHandler eh = (EventHandler)(Events [ClickEvent]);
4609 [EditorBrowsable(EditorBrowsableState.Advanced)]
4610 protected virtual void OnContextMenuChanged(EventArgs e) {
4611 EventHandler eh = (EventHandler)(Events [ContextMenuChangedEvent]);
4617 [EditorBrowsable (EditorBrowsableState.Advanced)]
4618 protected virtual void OnContextMenuStripChanged (EventArgs e) {
4619 EventHandler eh = (EventHandler)(Events [ContextMenuStripChangedEvent]);
4625 [EditorBrowsable(EditorBrowsableState.Advanced)]
4626 protected virtual void OnControlAdded(ControlEventArgs e) {
4627 ControlEventHandler eh = (ControlEventHandler)(Events [ControlAddedEvent]);
4632 [EditorBrowsable(EditorBrowsableState.Advanced)]
4633 protected virtual void OnControlRemoved(ControlEventArgs e) {
4634 ControlEventHandler eh = (ControlEventHandler)(Events [ControlRemovedEvent]);
4639 [EditorBrowsable(EditorBrowsableState.Advanced)]
4640 protected virtual void OnCreateControl() {
4644 [EditorBrowsable(EditorBrowsableState.Advanced)]
4645 protected virtual void OnCursorChanged(EventArgs e) {
4646 EventHandler eh = (EventHandler)(Events [CursorChangedEvent]);
4651 [EditorBrowsable(EditorBrowsableState.Advanced)]
4652 protected virtual void OnDockChanged(EventArgs e) {
4653 EventHandler eh = (EventHandler)(Events [DockChangedEvent]);
4658 [EditorBrowsable(EditorBrowsableState.Advanced)]
4659 protected virtual void OnDoubleClick(EventArgs e) {
4660 EventHandler eh = (EventHandler)(Events [DoubleClickEvent]);
4665 [EditorBrowsable(EditorBrowsableState.Advanced)]
4666 protected virtual void OnDragDrop(DragEventArgs drgevent) {
4667 DragEventHandler eh = (DragEventHandler)(Events [DragDropEvent]);
4669 eh (this, drgevent);
4672 [EditorBrowsable(EditorBrowsableState.Advanced)]
4673 protected virtual void OnDragEnter(DragEventArgs drgevent) {
4674 DragEventHandler eh = (DragEventHandler)(Events [DragEnterEvent]);
4676 eh (this, drgevent);
4679 [EditorBrowsable(EditorBrowsableState.Advanced)]
4680 protected virtual void OnDragLeave(EventArgs e) {
4681 EventHandler eh = (EventHandler)(Events [DragLeaveEvent]);
4686 [EditorBrowsable(EditorBrowsableState.Advanced)]
4687 protected virtual void OnDragOver(DragEventArgs drgevent) {
4688 DragEventHandler eh = (DragEventHandler)(Events [DragOverEvent]);
4690 eh (this, drgevent);
4693 [EditorBrowsable(EditorBrowsableState.Advanced)]
4694 protected virtual void OnEnabledChanged(EventArgs e) {
4695 if (IsHandleCreated) {
4697 if (((Form)this).context == null) {
4698 XplatUI.EnableWindow(window.Handle, Enabled);
4701 XplatUI.EnableWindow(window.Handle, Enabled);
4706 EventHandler eh = (EventHandler)(Events [EnabledChangedEvent]);
4710 for (int i=0; i<child_controls.Count; i++) {
4711 child_controls[i].OnParentEnabledChanged(e);
4715 [EditorBrowsable(EditorBrowsableState.Advanced)]
4716 protected virtual void OnEnter(EventArgs e) {
4717 EventHandler eh = (EventHandler)(Events [EnterEvent]);
4722 [EditorBrowsable(EditorBrowsableState.Advanced)]
4723 protected virtual void OnFontChanged(EventArgs e) {
4724 EventHandler eh = (EventHandler)(Events [FontChangedEvent]);
4727 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentFontChanged(e);
4730 [EditorBrowsable(EditorBrowsableState.Advanced)]
4731 protected virtual void OnForeColorChanged(EventArgs e) {
4732 EventHandler eh = (EventHandler)(Events [ForeColorChangedEvent]);
4735 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentForeColorChanged(e);
4738 [EditorBrowsable(EditorBrowsableState.Advanced)]
4739 protected virtual void OnGiveFeedback(GiveFeedbackEventArgs gfbevent) {
4740 GiveFeedbackEventHandler eh = (GiveFeedbackEventHandler)(Events [GiveFeedbackEvent]);
4742 eh (this, gfbevent);
4745 [EditorBrowsable(EditorBrowsableState.Advanced)]
4746 protected virtual void OnGotFocus(EventArgs e) {
4747 EventHandler eh = (EventHandler)(Events [GotFocusEvent]);
4752 [EditorBrowsable(EditorBrowsableState.Advanced)]
4753 protected virtual void OnHandleCreated(EventArgs e) {
4754 EventHandler eh = (EventHandler)(Events [HandleCreatedEvent]);
4759 [EditorBrowsable(EditorBrowsableState.Advanced)]
4760 protected virtual void OnHandleDestroyed(EventArgs e) {
4761 EventHandler eh = (EventHandler)(Events [HandleDestroyedEvent]);
4766 [EditorBrowsable(EditorBrowsableState.Advanced)]
4767 protected virtual void OnHelpRequested(HelpEventArgs hevent) {
4768 HelpEventHandler eh = (HelpEventHandler)(Events [HelpRequestedEvent]);
4773 protected virtual void OnImeModeChanged(EventArgs e) {
4774 EventHandler eh = (EventHandler)(Events [ImeModeChangedEvent]);
4779 [EditorBrowsable(EditorBrowsableState.Advanced)]
4780 protected virtual void OnInvalidated(InvalidateEventArgs e) {
4781 if (ThemeEngine.Current.DoubleBufferingSupported)
4782 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
4783 // should this block be here? seems like it
4784 // would be more at home in
4785 // NotifyInvalidated..
4786 if (e.InvalidRect == ClientRectangle) {
4787 InvalidateBackBuffer ();
4790 // we need this Inflate call here so
4791 // that the border of the rectangle is
4792 // considered Visible (the
4793 // invalid_region.IsVisible call) in
4794 // the WM_PAINT handling below.
4795 Rectangle r = Rectangle.Inflate(e.InvalidRect, 1,1);
4796 if (invalid_region == null)
4797 invalid_region = new Region (r);
4799 invalid_region.Union (r);
4803 InvalidateEventHandler eh = (InvalidateEventHandler)(Events [InvalidatedEvent]);
4808 [EditorBrowsable(EditorBrowsableState.Advanced)]
4809 protected virtual void OnKeyDown(KeyEventArgs e) {
4810 KeyEventHandler eh = (KeyEventHandler)(Events [KeyDownEvent]);
4815 [EditorBrowsable(EditorBrowsableState.Advanced)]
4816 protected virtual void OnKeyPress(KeyPressEventArgs e) {
4817 KeyPressEventHandler eh = (KeyPressEventHandler)(Events [KeyPressEvent]);
4822 [EditorBrowsable(EditorBrowsableState.Advanced)]
4823 protected virtual void OnKeyUp(KeyEventArgs e) {
4824 KeyEventHandler eh = (KeyEventHandler)(Events [KeyUpEvent]);
4829 [EditorBrowsable(EditorBrowsableState.Advanced)]
4830 protected virtual void OnLayout(LayoutEventArgs levent) {
4831 LayoutEventHandler eh = (LayoutEventHandler)(Events [LayoutEvent]);
4836 [EditorBrowsable(EditorBrowsableState.Advanced)]
4837 protected virtual void OnLeave(EventArgs e) {
4838 EventHandler eh = (EventHandler)(Events [LeaveEvent]);
4843 [EditorBrowsable(EditorBrowsableState.Advanced)]
4844 protected virtual void OnLocationChanged(EventArgs e) {
4846 EventHandler eh = (EventHandler)(Events [LocationChangedEvent]);
4851 [EditorBrowsable(EditorBrowsableState.Advanced)]
4852 protected virtual void OnLostFocus(EventArgs e) {
4853 EventHandler eh = (EventHandler)(Events [LostFocusEvent]);
4858 [EditorBrowsable(EditorBrowsableState.Advanced)]
4859 protected virtual void OnMouseDown(MouseEventArgs e) {
4860 MouseEventHandler eh = (MouseEventHandler)(Events [MouseDownEvent]);
4865 [EditorBrowsable(EditorBrowsableState.Advanced)]
4866 protected virtual void OnMouseEnter(EventArgs e) {
4867 EventHandler eh = (EventHandler)(Events [MouseEnterEvent]);
4872 [EditorBrowsable(EditorBrowsableState.Advanced)]
4873 protected virtual void OnMouseHover(EventArgs e) {
4874 EventHandler eh = (EventHandler)(Events [MouseHoverEvent]);
4879 [EditorBrowsable(EditorBrowsableState.Advanced)]
4880 protected virtual void OnMouseLeave(EventArgs e) {
4881 EventHandler eh = (EventHandler)(Events [MouseLeaveEvent]);
4886 [EditorBrowsable(EditorBrowsableState.Advanced)]
4887 protected virtual void OnMouseMove(MouseEventArgs e) {
4888 MouseEventHandler eh = (MouseEventHandler)(Events [MouseMoveEvent]);
4893 [EditorBrowsable(EditorBrowsableState.Advanced)]
4894 protected virtual void OnMouseUp(MouseEventArgs e) {
4895 MouseEventHandler eh = (MouseEventHandler)(Events [MouseUpEvent]);
4900 [EditorBrowsable(EditorBrowsableState.Advanced)]
4901 protected virtual void OnMouseWheel(MouseEventArgs e) {
4902 MouseEventHandler eh = (MouseEventHandler)(Events [MouseWheelEvent]);
4907 [EditorBrowsable(EditorBrowsableState.Advanced)]
4908 protected virtual void OnMove(EventArgs e) {
4909 EventHandler eh = (EventHandler)(Events [MoveEvent]);
4914 [EditorBrowsable(EditorBrowsableState.Advanced)]
4915 protected virtual void OnNotifyMessage(Message m) {
4920 protected virtual void OnPaddingChanged (EventArgs e) {
4921 EventHandler eh = (EventHandler) (Events [PaddingChangedEvent]);
4927 [EditorBrowsable(EditorBrowsableState.Advanced)]
4928 protected virtual void OnPaint(PaintEventArgs e) {
4929 PaintEventHandler eh = (PaintEventHandler)(Events [PaintEvent]);
4934 internal virtual void OnPaintBackgroundInternal(PaintEventArgs e) {
4938 internal virtual void OnPaintInternal(PaintEventArgs e) {
4942 internal virtual void OnGotFocusInternal (EventArgs e)
4947 internal virtual void OnLostFocusInternal (EventArgs e)
4952 [EditorBrowsable(EditorBrowsableState.Advanced)]
4953 protected virtual void OnPaintBackground(PaintEventArgs pevent) {
4954 PaintControlBackground (pevent);
4957 [EditorBrowsable(EditorBrowsableState.Advanced)]
4958 protected virtual void OnParentBackColorChanged(EventArgs e) {
4959 if (background_color.IsEmpty && background_image==null) {
4961 OnBackColorChanged(e);
4965 [EditorBrowsable(EditorBrowsableState.Advanced)]
4966 protected virtual void OnParentBackgroundImageChanged(EventArgs e) {
4967 if (background_color.IsEmpty && background_image==null) {
4969 OnBackgroundImageChanged(e);
4973 [EditorBrowsable(EditorBrowsableState.Advanced)]
4974 protected virtual void OnParentBindingContextChanged(EventArgs e) {
4975 if (binding_context==null) {
4976 binding_context=Parent.binding_context;
4977 OnBindingContextChanged(e);
4981 [EditorBrowsable(EditorBrowsableState.Advanced)]
4982 protected virtual void OnParentChanged(EventArgs e) {
4983 EventHandler eh = (EventHandler)(Events [ParentChangedEvent]);
4988 [EditorBrowsable(EditorBrowsableState.Advanced)]
4989 protected virtual void OnParentEnabledChanged(EventArgs e) {
4991 OnEnabledChanged(e);
4995 [EditorBrowsable(EditorBrowsableState.Advanced)]
4996 protected virtual void OnParentFontChanged(EventArgs e) {
5003 [EditorBrowsable(EditorBrowsableState.Advanced)]
5004 protected virtual void OnParentForeColorChanged(EventArgs e) {
5005 if (foreground_color.IsEmpty) {
5007 OnForeColorChanged(e);
5011 [EditorBrowsable(EditorBrowsableState.Advanced)]
5012 protected virtual void OnParentRightToLeftChanged(EventArgs e) {
5013 if (right_to_left==RightToLeft.Inherit) {
5015 OnRightToLeftChanged(e);
5019 [EditorBrowsable(EditorBrowsableState.Advanced)]
5020 protected virtual void OnParentVisibleChanged(EventArgs e) {
5022 OnVisibleChanged(e);
5026 [EditorBrowsable(EditorBrowsableState.Advanced)]
5027 protected virtual void OnQueryContinueDrag(QueryContinueDragEventArgs e) {
5028 QueryContinueDragEventHandler eh = (QueryContinueDragEventHandler)(Events [QueryContinueDragEvent]);
5033 [EditorBrowsable(EditorBrowsableState.Advanced)]
5034 protected virtual void OnResize(EventArgs e) {
5035 EventHandler eh = (EventHandler)(Events [ResizeEvent]);
5039 PerformLayout(this, "bounds");
5041 if (parent != null) {
5042 parent.PerformLayout();
5046 [EditorBrowsable(EditorBrowsableState.Advanced)]
5047 protected virtual void OnRightToLeftChanged(EventArgs e) {
5048 EventHandler eh = (EventHandler)(Events [RightToLeftChangedEvent]);
5051 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentRightToLeftChanged(e);
5054 [EditorBrowsable(EditorBrowsableState.Advanced)]
5055 protected virtual void OnSizeChanged(EventArgs e) {
5056 DisposeBackBuffer ();
5058 EventHandler eh = (EventHandler)(Events [SizeChangedEvent]);
5063 [EditorBrowsable(EditorBrowsableState.Advanced)]
5064 protected virtual void OnStyleChanged(EventArgs e) {
5065 EventHandler eh = (EventHandler)(Events [StyleChangedEvent]);
5070 [EditorBrowsable(EditorBrowsableState.Advanced)]
5071 protected virtual void OnSystemColorsChanged(EventArgs e) {
5072 EventHandler eh = (EventHandler)(Events [SystemColorsChangedEvent]);
5077 [EditorBrowsable(EditorBrowsableState.Advanced)]
5078 protected virtual void OnTabIndexChanged(EventArgs e) {
5079 EventHandler eh = (EventHandler)(Events [TabIndexChangedEvent]);
5084 [EditorBrowsable(EditorBrowsableState.Advanced)]
5085 protected virtual void OnTabStopChanged(EventArgs e) {
5086 EventHandler eh = (EventHandler)(Events [TabStopChangedEvent]);
5091 [EditorBrowsable(EditorBrowsableState.Advanced)]
5092 protected virtual void OnTextChanged(EventArgs e) {
5093 EventHandler eh = (EventHandler)(Events [TextChangedEvent]);
5098 [EditorBrowsable(EditorBrowsableState.Advanced)]
5099 protected virtual void OnValidated(EventArgs e) {
5100 EventHandler eh = (EventHandler)(Events [ValidatedEvent]);
5105 [EditorBrowsable(EditorBrowsableState.Advanced)]
5106 protected virtual void OnValidating(System.ComponentModel.CancelEventArgs e) {
5107 CancelEventHandler eh = (CancelEventHandler)(Events [ValidatingEvent]);
5112 [EditorBrowsable(EditorBrowsableState.Advanced)]
5113 protected virtual void OnVisibleChanged(EventArgs e) {
5114 if ((parent != null) && !Created && Visible) {
5121 EventHandler eh = (EventHandler)(Events [VisibleChangedEvent]);
5125 // We need to tell our kids
5126 for (int i=0; i<child_controls.Count; i++) {
5127 if (child_controls[i].Visible) {
5128 child_controls[i].OnParentVisibleChanged(e);
5132 #endregion // OnXXX methods
5136 static object AutoSizeChangedEvent = new object ();
5138 static object BackColorChangedEvent = new object ();
5139 static object BackgroundImageChangedEvent = new object ();
5141 static object BackgroundImageLayoutChangedEvent = new object ();
5143 static object BindingContextChangedEvent = new object ();
5144 static object CausesValidationChangedEvent = new object ();
5145 static object ChangeUICuesEvent = new object ();
5146 static object ClickEvent = new object ();
5148 static object ClientSizeChangedEvent = new object ();
5150 static object ContextMenuChangedEvent = new object ();
5152 static object ContextMenuStripChangedEvent = new object ();
5154 static object ControlAddedEvent = new object ();
5155 static object ControlRemovedEvent = new object ();
5156 static object CursorChangedEvent = new object ();
5157 static object DockChangedEvent = new object ();
5158 static object DoubleClickEvent = new object ();
5159 static object DragDropEvent = new object ();
5160 static object DragEnterEvent = new object ();
5161 static object DragLeaveEvent = new object ();
5162 static object DragOverEvent = new object ();
5163 static object EnabledChangedEvent = new object ();
5164 static object EnterEvent = new object ();
5165 static object FontChangedEvent = new object ();
5166 static object ForeColorChangedEvent = new object ();
5167 static object GiveFeedbackEvent = new object ();
5168 static object GotFocusEvent = new object ();
5169 static object HandleCreatedEvent = new object ();
5170 static object HandleDestroyedEvent = new object ();
5171 static object HelpRequestedEvent = new object ();
5172 static object ImeModeChangedEvent = new object ();
5173 static object InvalidatedEvent = new object ();
5174 static object KeyDownEvent = new object ();
5175 static object KeyPressEvent = new object ();
5176 static object KeyUpEvent = new object ();
5177 static object LayoutEvent = new object ();
5178 static object LeaveEvent = new object ();
5179 static object LocationChangedEvent = new object ();
5180 static object LostFocusEvent = new object ();
5182 static object MarginChangedEvent = new object ();
5183 static object MouseCaptureChangedEvent = new object ();
5184 static object MouseClickEvent = new object ();
5185 static object MouseDoubleClickEvent = new object ();
5187 static object MouseDownEvent = new object ();
5188 static object MouseEnterEvent = new object ();
5189 static object MouseHoverEvent = new object ();
5190 static object MouseLeaveEvent = new object ();
5191 static object MouseMoveEvent = new object ();
5192 static object MouseUpEvent = new object ();
5193 static object MouseWheelEvent = new object ();
5194 static object MoveEvent = new object ();
5196 static object PaddingChangedEvent = new object ();
5198 static object PaintEvent = new object ();
5199 static object ParentChangedEvent = new object ();
5201 static object PreviewKeyDownEvent = new object ();
5203 static object QueryAccessibilityHelpEvent = new object ();
5204 static object QueryContinueDragEvent = new object ();
5206 static object RegionChangedEvent = new object ();
5208 static object ResizeEvent = new object ();
5209 static object RightToLeftChangedEvent = new object ();
5210 static object SizeChangedEvent = new object ();
5211 static object StyleChangedEvent = new object ();
5212 static object SystemColorsChangedEvent = new object ();
5213 static object TabIndexChangedEvent = new object ();
5214 static object TabStopChangedEvent = new object ();
5215 static object TextChangedEvent = new object ();
5216 static object ValidatedEvent = new object ();
5217 static object ValidatingEvent = new object ();
5218 static object VisibleChangedEvent = new object ();
5221 public event EventHandler AutoSizeChanged {
5222 add { Events.AddHandler (AutoSizeChangedEvent, value);}
5223 remove {Events.RemoveHandler (AutoSizeChangedEvent, value);}
5226 public event EventHandler BackColorChanged {
5227 add { Events.AddHandler (BackColorChangedEvent, value); }
5228 remove { Events.RemoveHandler (BackColorChangedEvent, value); }
5231 public event EventHandler BackgroundImageChanged {
5232 add { Events.AddHandler (BackgroundImageChangedEvent, value); }
5233 remove { Events.RemoveHandler (BackgroundImageChangedEvent, value); }
5237 public event EventHandler BackgroundImageLayoutChanged {
5238 add {Events.AddHandler (BackgroundImageLayoutChangedEvent, value);}
5239 remove {Events.RemoveHandler (BackgroundImageLayoutChangedEvent, value);}
5243 public event EventHandler BindingContextChanged {
5244 add { Events.AddHandler (BindingContextChangedEvent, value); }
5245 remove { Events.RemoveHandler (BindingContextChangedEvent, value); }
5248 public event EventHandler CausesValidationChanged {
5249 add { Events.AddHandler (CausesValidationChangedEvent, value); }
5250 remove { Events.RemoveHandler (CausesValidationChangedEvent, value); }
5253 public event UICuesEventHandler ChangeUICues {
5254 add { Events.AddHandler (ChangeUICuesEvent, value); }
5255 remove { Events.RemoveHandler (ChangeUICuesEvent, value); }
5258 public event EventHandler Click {
5259 add { Events.AddHandler (ClickEvent, value); }
5260 remove { Events.RemoveHandler (ClickEvent, value); }
5264 public event EventHandler ClientSizeChanged {
5265 add {Events.AddHandler (ClientSizeChangedEvent, value);}
5266 remove {Events.RemoveHandler (ClientSizeChangedEvent, value);}
5273 public event EventHandler ContextMenuChanged {
5274 add { Events.AddHandler (ContextMenuChangedEvent, value); }
5275 remove { Events.RemoveHandler (ContextMenuChangedEvent, value); }
5279 public event EventHandler ContextMenuStripChanged {
5280 add { Events.AddHandler (ContextMenuStripChangedEvent, value); }
5281 remove { Events.RemoveHandler (ContextMenuStripChangedEvent, value);}
5286 [EditorBrowsable(EditorBrowsableState.Advanced)]
5292 public event ControlEventHandler ControlAdded {
5293 add { Events.AddHandler (ControlAddedEvent, value); }
5294 remove { Events.RemoveHandler (ControlAddedEvent, value); }
5297 [EditorBrowsable(EditorBrowsableState.Advanced)]
5303 public event ControlEventHandler ControlRemoved {
5304 add { Events.AddHandler (ControlRemovedEvent, value); }
5305 remove { Events.RemoveHandler (ControlRemovedEvent, value); }
5308 [MWFDescription("Fired when the cursor for the control has been changed"), MWFCategory("PropertyChanged")]
5309 public event EventHandler CursorChanged {
5310 add { Events.AddHandler (CursorChangedEvent, value); }
5311 remove { Events.RemoveHandler (CursorChangedEvent, value); }
5313 public event EventHandler DockChanged {
5314 add { Events.AddHandler (DockChangedEvent, value); }
5315 remove { Events.RemoveHandler (DockChangedEvent, value); }
5318 public event EventHandler DoubleClick {
5319 add { Events.AddHandler (DoubleClickEvent, value); }
5320 remove { Events.RemoveHandler (DoubleClickEvent, value); }
5323 public event DragEventHandler DragDrop {
5324 add { Events.AddHandler (DragDropEvent, value); }
5325 remove { Events.RemoveHandler (DragDropEvent, value); }
5328 public event DragEventHandler DragEnter {
5329 add { Events.AddHandler (DragEnterEvent, value); }
5330 remove { Events.RemoveHandler (DragEnterEvent, value); }
5333 public event EventHandler DragLeave {
5334 add { Events.AddHandler (DragLeaveEvent, value); }
5335 remove { Events.RemoveHandler (DragLeaveEvent, value); }
5338 public event DragEventHandler DragOver {
5339 add { Events.AddHandler (DragOverEvent, value); }
5340 remove { Events.RemoveHandler (DragOverEvent, value); }
5343 public event EventHandler EnabledChanged {
5344 add { Events.AddHandler (EnabledChangedEvent, value); }
5345 remove { Events.RemoveHandler (EnabledChangedEvent, value); }
5348 public event EventHandler Enter {
5349 add { Events.AddHandler (EnterEvent, value); }
5350 remove { Events.RemoveHandler (EnterEvent, value); }
5353 public event EventHandler FontChanged {
5354 add { Events.AddHandler (FontChangedEvent, value); }
5355 remove { Events.RemoveHandler (FontChangedEvent, value); }
5358 public event EventHandler ForeColorChanged {
5359 add { Events.AddHandler (ForeColorChangedEvent, value); }
5360 remove { Events.RemoveHandler (ForeColorChangedEvent, value); }
5363 public event GiveFeedbackEventHandler GiveFeedback {
5364 add { Events.AddHandler (GiveFeedbackEvent, value); }
5365 remove { Events.RemoveHandler (GiveFeedbackEvent, value); }
5368 [EditorBrowsable(EditorBrowsableState.Advanced)]
5370 public event EventHandler GotFocus {
5371 add { Events.AddHandler (GotFocusEvent, value); }
5372 remove { Events.RemoveHandler (GotFocusEvent, value); }
5376 [EditorBrowsable(EditorBrowsableState.Advanced)]
5378 public event EventHandler HandleCreated {
5379 add { Events.AddHandler (HandleCreatedEvent, value); }
5380 remove { Events.RemoveHandler (HandleCreatedEvent, value); }
5383 [EditorBrowsable(EditorBrowsableState.Advanced)]
5385 public event EventHandler HandleDestroyed {
5386 add { Events.AddHandler (HandleDestroyedEvent, value); }
5387 remove { Events.RemoveHandler (HandleDestroyedEvent, value); }
5390 public event HelpEventHandler HelpRequested {
5391 add { Events.AddHandler (HelpRequestedEvent, value); }
5392 remove { Events.RemoveHandler (HelpRequestedEvent, value); }
5395 public event EventHandler ImeModeChanged {
5396 add { Events.AddHandler (ImeModeChangedEvent, value); }
5397 remove { Events.RemoveHandler (ImeModeChangedEvent, value); }
5400 [EditorBrowsable(EditorBrowsableState.Advanced)]
5402 public event InvalidateEventHandler Invalidated {
5403 add { Events.AddHandler (InvalidatedEvent, value); }
5404 remove { Events.RemoveHandler (InvalidatedEvent, value); }
5407 public event KeyEventHandler KeyDown {
5408 add { Events.AddHandler (KeyDownEvent, value); }
5409 remove { Events.RemoveHandler (KeyDownEvent, value); }
5412 public event KeyPressEventHandler KeyPress {
5413 add { Events.AddHandler (KeyPressEvent, value); }
5414 remove { Events.RemoveHandler (KeyPressEvent, value); }
5417 public event KeyEventHandler KeyUp {
5418 add { Events.AddHandler (KeyUpEvent, value); }
5419 remove { Events.RemoveHandler (KeyUpEvent, value); }
5422 public event LayoutEventHandler Layout {
5423 add { Events.AddHandler (LayoutEvent, value); }
5424 remove { Events.RemoveHandler (LayoutEvent, value); }
5427 public event EventHandler Leave {
5428 add { Events.AddHandler (LeaveEvent, value); }
5429 remove { Events.RemoveHandler (LeaveEvent, value); }
5432 public event EventHandler LocationChanged {
5433 add { Events.AddHandler (LocationChangedEvent, value); }
5434 remove { Events.RemoveHandler (LocationChangedEvent, value); }
5437 [EditorBrowsable(EditorBrowsableState.Advanced)]
5439 public event EventHandler LostFocus {
5440 add { Events.AddHandler (LostFocusEvent, value); }
5441 remove { Events.RemoveHandler (LostFocusEvent, value); }
5445 public event EventHandler MarginChanged {
5446 add { Events.AddHandler (MarginChangedEvent, value); }
5447 remove {Events.RemoveHandler (MarginChangedEvent, value); }
5450 public event EventHandler MouseCaptureChanged {
5451 add { Events.AddHandler (MouseCaptureChangedEvent, value); }
5452 remove { Events.RemoveHandler (MouseCaptureChangedEvent, value); }
5455 public event MouseEventHandler MouseClick
5457 add { Events.AddHandler (MouseClickEvent, value); }
5458 remove { Events.RemoveHandler (MouseClickEvent, value); }
5460 public event MouseEventHandler MouseDoubleClick
5462 add { Events.AddHandler (MouseDoubleClickEvent, value); }
5463 remove { Events.RemoveHandler (MouseDoubleClickEvent, value); }
5466 public event MouseEventHandler MouseDown {
5467 add { Events.AddHandler (MouseDownEvent, value); }
5468 remove { Events.RemoveHandler (MouseDownEvent, value); }
5471 public event EventHandler MouseEnter {
5472 add { Events.AddHandler (MouseEnterEvent, value); }
5473 remove { Events.RemoveHandler (MouseEnterEvent, value); }
5476 public event EventHandler MouseHover {
5477 add { Events.AddHandler (MouseHoverEvent, value); }
5478 remove { Events.RemoveHandler (MouseHoverEvent, value); }
5481 public event EventHandler MouseLeave {
5482 add { Events.AddHandler (MouseLeaveEvent, value); }
5483 remove { Events.RemoveHandler (MouseLeaveEvent, value); }
5486 public event MouseEventHandler MouseMove {
5487 add { Events.AddHandler (MouseMoveEvent, value); }
5488 remove { Events.RemoveHandler (MouseMoveEvent, value); }
5491 public event MouseEventHandler MouseUp {
5492 add { Events.AddHandler (MouseUpEvent, value); }
5493 remove { Events.RemoveHandler (MouseUpEvent, value); }
5496 [EditorBrowsable(EditorBrowsableState.Advanced)]
5498 public event MouseEventHandler MouseWheel {
5499 add { Events.AddHandler (MouseWheelEvent, value); }
5500 remove { Events.RemoveHandler (MouseWheelEvent, value); }
5503 public event EventHandler Move {
5504 add { Events.AddHandler (MoveEvent, value); }
5505 remove { Events.RemoveHandler (MoveEvent, value); }
5508 public event EventHandler PaddingChanged
5510 add { Events.AddHandler (PaddingChangedEvent, value); }
5511 remove { Events.RemoveHandler (PaddingChangedEvent, value); }
5514 public event PaintEventHandler Paint {
5515 add { Events.AddHandler (PaintEvent, value); }
5516 remove { Events.RemoveHandler (PaintEvent, value); }
5519 public event EventHandler ParentChanged {
5520 add { Events.AddHandler (ParentChangedEvent, value); }
5521 remove { Events.RemoveHandler (ParentChangedEvent, value); }
5525 public event EventHandler PreviewKeyDown {
5526 add { Events.AddHandler (PreviewKeyDownEvent, value); }
5527 remove { Events.RemoveHandler (PreviewKeyDownEvent, value); }
5531 public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp {
5532 add { Events.AddHandler (QueryAccessibilityHelpEvent, value); }
5533 remove { Events.RemoveHandler (QueryAccessibilityHelpEvent, value); }
5536 public event QueryContinueDragEventHandler QueryContinueDrag {
5537 add { Events.AddHandler (QueryContinueDragEvent, value); }
5538 remove { Events.RemoveHandler (QueryContinueDragEvent, value); }
5542 public event EventHandler RegionChanged {
5543 add { Events.AddHandler (RegionChangedEvent, value); }
5544 remove { Events.RemoveHandler (RegionChangedEvent, value); }
5549 [EditorBrowsable (EditorBrowsableState.Advanced)]
5551 public event EventHandler Resize {
5552 add { Events.AddHandler (ResizeEvent, value); }
5553 remove { Events.RemoveHandler (ResizeEvent, value); }
5556 public event EventHandler RightToLeftChanged {
5557 add { Events.AddHandler (RightToLeftChangedEvent, value); }
5558 remove { Events.RemoveHandler (RightToLeftChangedEvent, value); }
5561 public event EventHandler SizeChanged {
5562 add { Events.AddHandler (SizeChangedEvent, value); }
5563 remove { Events.RemoveHandler (SizeChangedEvent, value); }
5566 public event EventHandler StyleChanged {
5567 add { Events.AddHandler (StyleChangedEvent, value); }
5568 remove { Events.RemoveHandler (StyleChangedEvent, value); }
5571 public event EventHandler SystemColorsChanged {
5572 add { Events.AddHandler (SystemColorsChangedEvent, value); }
5573 remove { Events.RemoveHandler (SystemColorsChangedEvent, value); }
5576 public event EventHandler TabIndexChanged {
5577 add { Events.AddHandler (TabIndexChangedEvent, value); }
5578 remove { Events.RemoveHandler (TabIndexChangedEvent, value); }
5581 public event EventHandler TabStopChanged {
5582 add { Events.AddHandler (TabStopChangedEvent, value); }
5583 remove { Events.RemoveHandler (TabStopChangedEvent, value); }
5586 public event EventHandler TextChanged {
5587 add { Events.AddHandler (TextChangedEvent, value); }
5588 remove { Events.RemoveHandler (TextChangedEvent, value); }
5591 public event EventHandler Validated {
5592 add { Events.AddHandler (ValidatedEvent, value); }
5593 remove { Events.RemoveHandler (ValidatedEvent, value); }
5596 public event CancelEventHandler Validating {
5597 add { Events.AddHandler (ValidatingEvent, value); }
5598 remove { Events.RemoveHandler (ValidatingEvent, value); }
5601 public event EventHandler VisibleChanged {
5602 add { Events.AddHandler (VisibleChangedEvent, value); }
5603 remove { Events.RemoveHandler (VisibleChangedEvent, value); }
5606 #endregion // Events