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 int tab_index; // position in tab order of siblings
89 bool tab_stop; // is the control a tab stop?
90 bool is_disposed; // has the window already been disposed?
91 Size client_size; // size of the client area (window excluding decorations)
92 Rectangle client_rect; // rectangle with the client area (window excluding decorations)
93 ControlStyles control_style; // rather win32-specific, style bits for control
95 bool layout_pending; // true if our parent needs to re-layout us
96 object control_tag; // object that contains data about our control
97 internal int mouse_clicks; // Counter for mouse clicks
98 Cursor cursor; // Cursor for the window
99 internal bool allow_drop; // true if the control accepts droping objects on it
100 Region clip_region; // User-specified clip region for the window
103 internal Color foreground_color; // foreground color for control
104 internal Color background_color; // background color for control
105 Image background_image; // background image for control
106 internal Font font; // font for control
107 string text; // window/title text for control
108 internal BorderStyle border_style; // Border style of control
111 int layout_suspended;
112 internal AnchorStyles anchor_style; // anchoring requirements for our control
113 internal DockStyle dock_style; // docking requirements for our control (supercedes anchoring)
114 // Please leave the next 4 as internal until DefaultLayout (2.0) is rewritten
115 internal int dist_left; // distance to the left border of the parent
116 internal int dist_top; // distance to the top border of the parent
117 internal int dist_right; // distance to the right border of the parent
118 internal int dist_bottom; // distance to the bottom border of the parent
120 // to be categorized...
121 ControlCollection child_controls; // our children
122 Control parent; // our parent control
123 AccessibleObject accessibility_object; // object that contains accessibility information about our control
124 BindingContext binding_context;
125 RightToLeft right_to_left; // drawing direction for control
126 ContextMenu context_menu; // Context menu associated with the control
129 Graphics backbuffer_dc;
131 Region invalid_region;
133 ControlBindingsCollection data_bindings;
136 internal bool use_compatible_text_rendering;
137 static bool verify_thread_handle;
139 ImageLayout backgroundimage_layout;
144 Layout.LayoutEngine layout_engine;
147 #endregion // Local Variables
149 #region Private Classes
150 // This helper class allows us to dispatch messages to Control.WndProc
151 internal class ControlNativeWindow : NativeWindow {
152 private Control owner;
154 public ControlNativeWindow(Control control) : base() {
159 public Control Owner {
165 static internal Control ControlFromHandle(IntPtr hWnd) {
166 ControlNativeWindow window;
168 window = (ControlNativeWindow)window_collection[hWnd];
169 if (window != null) {
176 static internal Control ControlFromChildHandle (IntPtr handle) {
177 ControlNativeWindow window;
179 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
180 while (hwnd != null) {
181 window = (ControlNativeWindow)window_collection[hwnd.Handle];
182 if (window != null) {
191 protected override void WndProc(ref Message m) {
192 owner.WndProc(ref m);
197 #region Public Classes
199 public class ControlAccessibleObject : AccessibleObject {
202 #region ControlAccessibleObject Constructors
203 public ControlAccessibleObject(Control ownerControl)
204 : base (ownerControl)
206 this.owner = ownerControl;
208 #endregion // ControlAccessibleObject Constructors
210 #region ControlAccessibleObject Public Instance Properties
211 public override string DefaultAction {
213 return base.DefaultAction;
217 public override string Description {
219 return base.Description;
223 public IntPtr Handle {
229 // We don't want to let them set it
233 public override string Help {
239 public override string KeyboardShortcut {
241 return base.KeyboardShortcut;
245 public override string Name {
255 public Control Owner {
261 public override AccessibleObject Parent {
268 public override AccessibleRole Role {
273 #endregion // ControlAccessibleObject Public Instance Properties
275 #region ControlAccessibleObject Public Instance Methods
276 public override int GetHelpTopic(out string FileName) {
277 return base.GetHelpTopic (out FileName);
280 [MonoTODO("Implement this and tie it into Control.AccessibilityNotifyClients")]
281 public void NotifyClients(AccessibleEvents accEvent) {
282 throw new NotImplementedException();
285 [MonoTODO("Implement this and tie it into Control.AccessibilityNotifyClients")]
286 public void NotifyClients(AccessibleEvents accEvent, int childID) {
287 throw new NotImplementedException();
290 public override string ToString() {
291 return "ControlAccessibleObject: Owner = " + owner.ToString() + ", Text: " + owner.text;
294 #endregion // ControlAccessibleObject Public Instance Methods
300 [DesignerSerializer("System.Windows.Forms.Design.ControlCollectionCodeDomSerializer, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
302 [ListBindable(false)]
303 public class ControlCollection : IList, ICollection, ICloneable, IEnumerable {
304 #region ControlCollection Local Variables
307 Control[] all_controls;
309 #endregion // ControlCollection Local Variables
311 #region ControlCollection Public Constructor
312 public ControlCollection(Control owner) {
314 this.list=new ArrayList();
318 #region ControlCollection Public Instance Properties
325 public bool IsReadOnly {
327 return list.IsReadOnly;
331 public virtual Control this[int index] {
333 if (index < 0 || index >= list.Count) {
334 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
336 return (Control)list[index];
339 #endregion // ControlCollection Public Instance Properties
341 #region ControlCollection Private Instance Methods
342 public virtual void Add (Control value)
347 if (Contains (value)) {
348 owner.PerformLayout();
352 if (value.tab_index == -1) {
358 end = owner.child_controls.Count;
359 for (int i = 0; i < end; i++) {
360 index = owner.child_controls[i].tab_index;
365 value.tab_index = use;
368 if (value.parent != null) {
369 value.parent.Controls.Remove(value);
375 value.ChangeParent(owner);
379 owner.UpdateChildrenZOrder();
380 owner.PerformLayout(value, "Parent");
381 owner.OnControlAdded(new ControlEventArgs(value));
384 internal void AddToList (Control c)
390 internal virtual void AddImplicit (Control control)
392 if (impl_list == null)
393 impl_list = new ArrayList ();
395 if (AllContains (control))
399 impl_list.Add (control);
401 control.ChangeParent (owner);
402 control.InitLayout ();
403 owner.UpdateChildrenZOrder ();
404 owner.PerformLayout (control, "Parent");
405 owner.OnControlAdded (new ControlEventArgs (control));
408 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
410 public virtual void AddRange (Control[] controls)
412 if (controls == null)
413 throw new ArgumentNullException ("controls");
415 owner.SuspendLayout ();
418 for (int i = 0; i < controls.Length; i++)
421 owner.ResumeLayout ();
425 internal virtual void AddRangeImplicit (Control [] controls)
427 if (controls == null)
428 throw new ArgumentNullException ("controls");
430 owner.SuspendLayout ();
433 for (int i = 0; i < controls.Length; i++)
434 AddImplicit (controls [i]);
436 owner.ResumeLayout ();
440 public virtual void Clear ()
444 // MS sends remove events in reverse order
445 while (list.Count > 0) {
446 Remove((Control)list[list.Count - 1]);
450 internal virtual void ClearImplicit ()
452 if (impl_list == null)
458 public bool Contains (Control value)
460 for (int i = list.Count; i > 0; ) {
463 if (list [i] == value) {
464 // Do we need to do anything here?
471 internal bool ImplicitContains (Control value)
473 if (impl_list == null)
476 for (int i = impl_list.Count; i > 0; ) {
479 if (impl_list [i] == value) {
480 // Do we need to do anything here?
487 internal bool AllContains (Control value)
489 return Contains (value) || ImplicitContains (value);
492 public void CopyTo (Array array, int index)
494 list.CopyTo(array, index);
497 public override bool Equals(object other) {
498 if (other is ControlCollection && (((ControlCollection)other).owner==this.owner)) {
505 public int GetChildIndex(Control child) {
506 return GetChildIndex(child, false);
509 public int GetChildIndex(Control child, bool throwException) {
512 index=list.IndexOf(child);
514 if (index==-1 && throwException) {
515 throw new ArgumentException("Not a child control", "child");
520 public IEnumerator GetEnumerator() {
521 return list.GetEnumerator();
524 internal IEnumerator GetAllEnumerator ()
526 Control [] res = GetAllControls ();
527 return res.GetEnumerator ();
530 internal Control [] GetAllControls ()
532 if (all_controls != null)
535 if (impl_list == null) {
536 all_controls = (Control []) list.ToArray (typeof (Control));
540 all_controls = new Control [list.Count + impl_list.Count];
541 impl_list.CopyTo (all_controls);
542 list.CopyTo (all_controls, impl_list.Count);
547 public override int GetHashCode() {
548 return base.GetHashCode();
551 public int IndexOf(Control control) {
552 return list.IndexOf(control);
555 public virtual void Remove(Control value) {
559 owner.PerformLayout(value, "Parent");
560 owner.OnControlRemoved(new ControlEventArgs(value));
565 value.ChangeParent(null);
567 owner.UpdateChildrenZOrder();
570 internal virtual void RemoveImplicit (Control control)
572 if (impl_list != null) {
574 owner.PerformLayout (control, "Parent");
575 owner.OnControlRemoved (new ControlEventArgs (control));
576 impl_list.Remove (control);
578 control.ChangeParent (null);
579 owner.UpdateChildrenZOrder ();
582 public void RemoveAt(int index) {
583 if (index < 0 || index >= list.Count) {
584 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
586 Remove ((Control)list[index]);
589 public void SetChildIndex(Control child, int newIndex) {
591 throw new ArgumentNullException ("child");
595 old_index=list.IndexOf(child);
597 throw new ArgumentException("Not a child control", "child");
600 if (old_index==newIndex) {
605 list.RemoveAt(old_index);
607 if (newIndex>list.Count) {
610 list.Insert(newIndex, child);
612 child.UpdateZOrder();
613 owner.PerformLayout();
615 #endregion // ControlCollection Private Instance Methods
617 #region ControlCollection Interface Properties
618 object IList.this[int index] {
620 if (index<0 || index>=list.Count) {
621 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
627 if (!(value is Control)) {
628 throw new ArgumentException("Object of type Control required", "value");
632 Control ctrl = (Control) value;
635 ctrl.ChangeParent(owner);
639 owner.UpdateChildrenZOrder();
640 owner.PerformLayout(ctrl, "Parent");
644 bool IList.IsFixedSize {
650 bool ICollection.IsSynchronized {
652 return list.IsSynchronized;
656 object ICollection.SyncRoot {
658 return list.SyncRoot;
661 #endregion // ControlCollection Interface Properties
663 #region ControlCollection Interface Methods
664 int IList.Add(object value) {
666 throw new ArgumentNullException("value", "Cannot add null controls");
669 if (!(value is Control)) {
670 throw new ArgumentException("Object of type Control required", "value");
673 return list.Add(value);
676 bool IList.Contains(object value) {
677 if (!(value is Control)) {
678 throw new ArgumentException("Object of type Control required", "value");
681 return this.Contains((Control) value);
684 int IList.IndexOf(object value) {
685 if (!(value is Control)) {
686 throw new ArgumentException("Object of type Control required", "value");
689 return this.IndexOf((Control) value);
692 void IList.Insert(int index, object value) {
693 if (!(value is Control)) {
694 throw new ArgumentException("Object of type Control required", "value");
697 list.Insert(index, value);
700 void IList.Remove(object value) {
701 if (!(value is Control)) {
702 throw new ArgumentException("Object of type Control required", "value");
708 Object ICloneable.Clone() {
709 ControlCollection clone = new ControlCollection(this.owner);
710 clone.list=(ArrayList)list.Clone(); // FIXME: Do we need this?
713 #endregion // ControlCollection Interface Methods
715 #endregion // ControlCollection Class
717 #region Public Constructors
720 anchor_style = AnchorStyles.Top | AnchorStyles.Left;
728 layout_pending = false;
730 causes_validation = true;
732 layout_suspended = 0;
736 right_to_left = RightToLeft.Inherit;
737 border_style = BorderStyle.None;
738 background_color = Color.Empty;
744 ime_mode = ImeMode.Inherit;
747 backgroundimage_layout = ImageLayout.Tile;
748 use_compatible_text_rendering = Application.use_compatible_text_rendering;
749 padding = new Padding(0);
750 maximum_size = new Size();
751 minimum_size = new Size();
752 preferred_size = new Size();
753 margin = this.DefaultMargin;
754 layout_engine = this.LayoutEngine;
757 control_style = ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint |
758 ControlStyles.Selectable | ControlStyles.StandardClick |
759 ControlStyles.StandardDoubleClick;
761 control_style |= ControlStyles.UseTextForAccessibility;
765 background_image = null;
769 window = new ControlNativeWindow(this);
770 child_controls = CreateControlsInstance();
771 client_size = new Size(DefaultSize.Width, DefaultSize.Height);
772 client_rect = new Rectangle(0, 0, DefaultSize.Width, DefaultSize.Height);
773 XplatUI.CalculateWindowRect(ref client_rect, CreateParams.Style, CreateParams.ExStyle, null, out bounds);
774 if ((CreateParams.Style & (int)WindowStyles.WS_CHILD) == 0) {
780 public Control(Control parent, string text) : this() {
785 public Control(Control parent, string text, int left, int top, int width, int height) : this() {
790 bounds.Height=height;
791 SetBounds(left, top, width, height, BoundsSpecified.All);
795 public Control(string text) : this() {
799 public Control(string text, int left, int top, int width, int height) : this() {
803 bounds.Height=height;
804 SetBounds(left, top, width, height, BoundsSpecified.All);
808 private delegate void RemoveDelegate(object c);
810 protected override void Dispose(bool disposing) {
811 if (!is_disposed && disposing) {
814 DisposeBackBuffer ();
816 if (invalid_region!=null) {
817 invalid_region.Dispose();
820 if (this.InvokeRequired) {
821 if (Application.MessageLoop) {
822 this.BeginInvokeInternal(new MethodInvoker(DestroyHandle), null, true);
828 if (parent != null) {
829 parent.Controls.Remove(this);
832 Control [] children = child_controls.GetAllControls ();
833 for (int i=0; i<children.Length; i++) {
834 children[i].parent = null; // Need to set to null or our child will try and remove from ourselves and crash
835 children[i].Dispose();
840 base.Dispose(disposing);
842 #endregion // Public Constructors
844 #region Internal Properties
845 internal BorderStyle InternalBorderStyle {
851 if (!Enum.IsDefined (typeof (BorderStyle), value))
852 throw new InvalidEnumArgumentException (string.Format("Enum argument value '{0}' is not valid for BorderStyle", value));
854 if (border_style != value) {
855 border_style = value;
857 if (IsHandleCreated) {
858 XplatUI.SetBorderStyle(window.Handle, (FormBorderStyle)border_style);
864 #endregion // Internal Properties
866 #region Private & Internal Methods
869 void IDropTarget.OnDragDrop (DragEventArgs e)
874 void IDropTarget.OnDragEnter (DragEventArgs e)
879 void IDropTarget.OnDragLeave (EventArgs e)
884 void IDropTarget.OnDragOver (DragEventArgs e)
890 internal IAsyncResult BeginInvokeInternal (Delegate method, object [] args, bool disposing) {
891 AsyncMethodResult result;
892 AsyncMethodData data;
897 if (!p.IsHandleCreated) {
898 throw new InvalidOperationException("Cannot call Invoke or InvokeAsync on a control until the window handle is created");
904 result = new AsyncMethodResult ();
905 data = new AsyncMethodData ();
907 data.Handle = window.Handle;
908 data.Method = method;
910 data.Result = result;
913 if (!ExecutionContext.IsFlowSuppressed ()) {
914 data.Context = ExecutionContext.Capture ();
917 #if !MWF_ON_MSRUNTIME
918 if (SecurityManager.SecurityEnabled) {
919 data.Stack = CompressedStack.GetCompressedStack ();
924 XplatUI.SendAsyncMethod (data);
929 internal void PointToClient (ref int x, ref int y)
931 XplatUI.ScreenToClient (Handle, ref x, ref y);
934 internal void PointToScreen (ref int x, ref int y)
936 XplatUI.ClientToScreen (Handle, ref x, ref y);
939 internal bool IsRecreating {
941 return is_recreating;
945 internal Graphics DeviceContext {
946 get { return Hwnd.bmp_g; }
949 private void InvalidateBackBuffer ()
951 if (invalid_region != null)
952 invalid_region.Dispose();
953 invalid_region = new Region (ClientRectangle);
956 private void CreateBackBuffer ()
958 if (backbuffer != null)
964 if (width < 1) width = 1;
965 if (height < 1) height = 1;
967 XplatUI.CreateOffscreenDrawable (Handle, width, height, out backbuffer, out backbuffer_dc);
968 InvalidateBackBuffer ();
971 private void DisposeBackBuffer ()
973 if (backbuffer == null)
976 XplatUI.DestroyOffscreenDrawable (backbuffer, backbuffer_dc);
978 backbuffer_dc = null;
981 if (invalid_region != null)
982 invalid_region.Dispose ();
983 invalid_region = null;
986 internal static void SetChildColor(Control parent) {
989 for (int i=0; i < parent.child_controls.Count; i++) {
990 child=parent.child_controls[i];
991 if (child.child_controls.Count>0) {
992 SetChildColor(child);
997 internal bool Select(Control control) {
998 IContainerControl container;
1000 if (control == null) {
1004 container = GetContainerControl();
1005 if (container != null) {
1006 container.ActiveControl = control;
1008 if (control.IsHandleCreated) {
1009 XplatUI.SetFocus(control.window.Handle);
1014 internal void SelectChild (Control control)
1016 if (control.IsHandleCreated)
1017 XplatUI.SetFocus (control.window.Handle);
1020 internal virtual void DoDefaultAction() {
1021 // Only here to be overriden by our actual controls; this is needed by the accessibility class
1024 internal static IntPtr MakeParam (int low, int high){
1025 return new IntPtr (high << 16 | low & 0xffff);
1028 internal static int LowOrder (int param) {
1029 return ((int)(short)(param & 0xffff));
1032 internal static int HighOrder (int param) {
1033 return ((int)(short)(param >> 16));
1036 // This method exists so controls overriding OnPaintBackground can have default background painting done
1037 internal virtual void PaintControlBackground (PaintEventArgs pevent)
1039 if (GetStyle(ControlStyles.SupportsTransparentBackColor) && (BackColor.A != 0xff)) {
1040 if (parent != null) {
1041 PaintEventArgs parent_pe;
1042 GraphicsState state;
1044 parent_pe = new PaintEventArgs(pevent.Graphics, new Rectangle(pevent.ClipRectangle.X + Left, pevent.ClipRectangle.Y + Top, pevent.ClipRectangle.Width, pevent.ClipRectangle.Height));
1046 state = parent_pe.Graphics.Save();
1047 parent_pe.Graphics.TranslateTransform(-Left, -Top);
1048 parent.OnPaintBackground(parent_pe);
1049 parent_pe.Graphics.Restore(state);
1051 state = parent_pe.Graphics.Save();
1052 parent_pe.Graphics.TranslateTransform(-Left, -Top);
1053 parent.OnPaint(parent_pe);
1054 parent_pe.Graphics.Restore(state);
1055 parent_pe.SetGraphics(null);
1059 if ((clip_region != null) && (XplatUI.UserClipWontExposeParent)) {
1060 if (parent != null) {
1061 PaintEventArgs parent_pe;
1063 GraphicsState state;
1066 hwnd = Hwnd.ObjectFromHandle(Handle);
1069 parent_pe = new PaintEventArgs(pevent.Graphics, new Rectangle(pevent.ClipRectangle.X + Left, pevent.ClipRectangle.Y + Top, pevent.ClipRectangle.Width, pevent.ClipRectangle.Height));
1071 region = new Region ();
1073 region.Union(ClientRectangle);
1075 foreach (Rectangle r in hwnd.ClipRectangles) {
1079 state = parent_pe.Graphics.Save();
1080 parent_pe.Graphics.Clip = region;
1082 parent_pe.Graphics.TranslateTransform(-Left, -Top);
1083 parent.OnPaintBackground(parent_pe);
1084 parent_pe.Graphics.Restore(state);
1086 state = parent_pe.Graphics.Save();
1087 parent_pe.Graphics.Clip = region;
1089 parent_pe.Graphics.TranslateTransform(-Left, -Top);
1090 parent.OnPaint(parent_pe);
1091 parent_pe.Graphics.Restore(state);
1092 parent_pe.SetGraphics(null);
1094 region.Intersect(clip_region);
1095 pevent.Graphics.Clip = region;
1100 if (background_image == null) {
1101 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));
1105 DrawBackgroundImage (pevent.Graphics);
1108 void DrawBackgroundImage (Graphics g)
1111 Rectangle drawing_rectangle = new Rectangle ();
1112 g.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (BackColor), ClientRectangle);
1114 switch (backgroundimage_layout)
1116 case ImageLayout.Tile:
1117 using (TextureBrush b = new TextureBrush (background_image, WrapMode.Tile)) {
1118 g.FillRectangle (b, ClientRectangle);
1121 case ImageLayout.Center:
1122 drawing_rectangle.Location = new Point (ClientSize.Width / 2 - background_image.Width / 2, ClientSize.Height / 2 - background_image.Height / 2);
1123 drawing_rectangle.Size = background_image.Size;
1125 case ImageLayout.None:
1126 drawing_rectangle.Location = Point.Empty;
1127 drawing_rectangle.Size = background_image.Size;
1129 case ImageLayout.Stretch:
1130 drawing_rectangle = ClientRectangle;
1132 case ImageLayout.Zoom:
1133 drawing_rectangle = ClientRectangle;
1134 if ((float)background_image.Width / (float)background_image.Height < (float)drawing_rectangle.Width / (float) drawing_rectangle.Height) {
1135 drawing_rectangle.Width = (int) (background_image.Width * ((float)drawing_rectangle.Height / (float)background_image.Height));
1136 drawing_rectangle.X = (ClientRectangle.Width - drawing_rectangle.Width) / 2;
1138 drawing_rectangle.Height = (int) (background_image.Height * ((float)drawing_rectangle.Width / (float)background_image.Width));
1139 drawing_rectangle.Y = (ClientRectangle.Height - drawing_rectangle.Height) / 2;
1146 g.DrawImage (background_image, drawing_rectangle);
1149 using (TextureBrush b = new TextureBrush (background_image, WrapMode.Tile)) {
1150 g.FillRectangle (b, ClientRectangle);
1155 internal virtual void DndEnter (DragEventArgs e)
1162 internal virtual void DndOver (DragEventArgs e)
1169 internal virtual void DndDrop (DragEventArgs e)
1173 } catch (Exception exc) {
1174 Console.Error.WriteLine ("MWF: Exception while dropping:");
1175 Console.Error.WriteLine (exc);
1179 internal virtual void DndLeave (EventArgs e)
1186 internal virtual void DndFeedback(GiveFeedbackEventArgs e)
1193 internal virtual void DndContinueDrag(QueryContinueDragEventArgs e)
1196 OnQueryContinueDrag(e);
1200 internal static MouseButtons FromParamToMouseButtons (int param) {
1201 MouseButtons buttons = MouseButtons.None;
1203 if ((param & (int) MsgButtons.MK_LBUTTON) != 0)
1204 buttons |= MouseButtons.Left;
1206 if ((param & (int) MsgButtons.MK_MBUTTON) != 0)
1207 buttons |= MouseButtons.Middle;
1209 if ((param & (int) MsgButtons.MK_RBUTTON) != 0)
1210 buttons |= MouseButtons.Right;
1216 internal void FireEnter ()
1218 OnEnter (EventArgs.Empty);
1221 internal void FireLeave ()
1223 OnLeave (EventArgs.Empty);
1226 internal void FireValidating (CancelEventArgs ce)
1231 internal void FireValidated ()
1233 OnValidated (EventArgs.Empty);
1236 internal virtual bool ProcessControlMnemonic(char charCode) {
1237 return ProcessMnemonic(charCode);
1240 private static Control FindFlatForward(Control container, Control start) {
1246 end = container.child_controls.Count;
1248 if (start != null) {
1249 index = start.tab_index;
1254 for (int i = 0, pos = -1; i < end; i++) {
1255 if (start == container.child_controls[i]) {
1260 if (found == null) {
1261 if (container.child_controls[i].tab_index > index || (pos > -1 && pos < i && container.child_controls[i].tab_index == index)) {
1262 found = container.child_controls[i];
1264 } else if (found.tab_index > container.child_controls[i].tab_index) {
1265 if (container.child_controls[i].tab_index > index) {
1266 found = container.child_controls[i];
1273 private static Control FindControlForward(Control container, Control start) {
1278 if (start == null) {
1279 return FindFlatForward(container, start);
1282 if (start.child_controls != null && start.child_controls.Count > 0 &&
1283 (start == container || !((start is IContainerControl) && start.GetStyle(ControlStyles.ContainerControl)))) {
1284 return FindControlForward(start, null);
1287 while (start != container) {
1288 found = FindFlatForward(start.parent, start);
1289 if (found != null) {
1292 start = start.parent;
1298 private static Control FindFlatBackward(Control container, Control start) {
1304 end = container.child_controls.Count;
1306 if (start != null) {
1307 index = start.tab_index;
1309 // FIXME: Possible speed-up: Keep the highest taborder index in the container
1311 for (int i = 0; i < end; i++) {
1312 if (container.child_controls[i].tab_index > index) {
1313 index = container.child_controls[i].tab_index;
1321 for (int i = end - 1; i >= 0; i--) {
1322 if (start == container.child_controls[i]) {
1327 if (found == null || found.tab_index < container.child_controls[i].tab_index) {
1328 if (container.child_controls[i].tab_index < index || (hit && container.child_controls[i].tab_index == index))
1329 found = container.child_controls[i];
1336 private static Control FindControlBackward(Control container, Control start) {
1338 Control found = null;
1340 if (start == null) {
1341 found = FindFlatBackward(container, start);
1343 else if (start != container) {
1344 if (start.parent != null) {
1345 found = FindFlatBackward(start.parent, start);
1347 if (found == null) {
1348 if (start.parent != container)
1349 return start.parent;
1355 if (found == null || start.parent == null)
1358 while (found != null && (found == container || (!((found is IContainerControl) && found.GetStyle(ControlStyles.ContainerControl))) &&
1359 found.child_controls != null && found.child_controls.Count > 0)) {
1360 // while (ctl.child_controls != null && ctl.child_controls.Count > 0 &&
1361 // (ctl == this || (!((ctl is IContainerControl) && ctl.GetStyle(ControlStyles.ContainerControl))))) {
1362 found = FindFlatBackward(found, null);
1372 if (start != null) {
1373 found = FindFlatBackward(start.parent, start);
1374 if (found == null) {
1375 if (start.parent != container) {
1376 return start.parent;
1380 if (found == null) {
1381 found = FindFlatBackward(container, start);
1384 if (container != start) {
1385 while ((found != null) && (!found.Contains(start)) && found.child_controls != null && found.child_controls.Count > 0 && !(found is IContainerControl)) {// || found.GetStyle(ControlStyles.ContainerControl))) {
1386 found = FindControlBackward(found, null);
1387 if (found != null) {
1396 internal virtual void HandleClick(int clicks, MouseEventArgs me) {
1397 if (GetStyle(ControlStyles.StandardClick)) {
1398 if ((clicks > 1) && GetStyle(ControlStyles.StandardDoubleClick)) {
1400 OnDoubleClick(EventArgs.Empty);
1402 OnClick(EventArgs.Empty);
1412 internal void CaptureWithConfine (Control ConfineWindow)
1414 if (this.IsHandleCreated && !is_captured) {
1416 XplatUI.GrabWindow (this.window.Handle, ConfineWindow.Handle);
1420 private void CheckDataBindings ()
1422 if (data_bindings == null)
1425 BindingContext binding_context = BindingContext;
1426 foreach (Binding binding in data_bindings) {
1427 binding.Check (binding_context);
1431 private void ChangeParent(Control new_parent) {
1435 Color pre_fore_color;
1436 Color pre_back_color;
1437 RightToLeft pre_rtl;
1439 // These properties are inherited from our parent
1440 // Get them pre parent-change and then send events
1441 // if they are changed after we have our new parent
1442 pre_enabled = Enabled;
1443 pre_visible = Visible;
1445 pre_fore_color = ForeColor;
1446 pre_back_color = BackColor;
1447 pre_rtl = RightToLeft;
1448 // MS doesn't seem to send a CursorChangedEvent
1450 parent = new_parent;
1452 if (IsHandleCreated)
1453 XplatUI.SetParent(Handle,
1454 (new_parent == null || !new_parent.IsHandleCreated) ? IntPtr.Zero : new_parent.Handle);
1456 OnParentChanged(EventArgs.Empty);
1458 if (pre_enabled != Enabled) {
1459 OnEnabledChanged(EventArgs.Empty);
1462 if (pre_visible != Visible) {
1463 OnVisibleChanged(EventArgs.Empty);
1466 if (pre_font != Font) {
1467 OnFontChanged(EventArgs.Empty);
1470 if (pre_fore_color != ForeColor) {
1471 OnForeColorChanged(EventArgs.Empty);
1474 if (pre_back_color != BackColor) {
1475 OnBackColorChanged(EventArgs.Empty);
1478 if (pre_rtl != RightToLeft) {
1479 // MS sneaks a OnCreateControl and OnHandleCreated in here, I guess
1480 // because when RTL changes they have to recreate the win32 control
1481 // We don't really need that (until someone runs into compatibility issues)
1482 OnRightToLeftChanged(EventArgs.Empty);
1485 if ((new_parent != null) && new_parent.Created && !Created) {
1489 if ((binding_context == null) && Created) {
1490 OnBindingContextChanged(EventArgs.Empty);
1494 private void UpdateDistances() {
1495 if (parent != null) {
1496 dist_left = bounds.X;
1497 dist_top = bounds.Y;
1498 dist_right = parent.ClientSize.Width - bounds.X - bounds.Width;
1499 dist_bottom = parent.ClientSize.Height - bounds.Y - bounds.Height;
1502 #endregion // Private & Internal Methods
1504 #region Public Static Properties
1505 public static Color DefaultBackColor {
1507 return ThemeEngine.Current.DefaultControlBackColor;
1511 public static Font DefaultFont {
1513 return ThemeEngine.Current.DefaultFont;
1517 public static Color DefaultForeColor {
1519 return ThemeEngine.Current.DefaultControlForeColor;
1523 public static Keys ModifierKeys {
1525 return XplatUI.State.ModifierKeys;
1529 public static MouseButtons MouseButtons {
1531 return XplatUI.State.MouseButtons;
1535 public static Point MousePosition {
1537 return Cursor.Position;
1542 [EditorBrowsable (EditorBrowsableState.Advanced)]
1543 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
1546 public static bool CheckForIllegalCrossThreadCalls
1549 return verify_thread_handle;
1553 verify_thread_handle = value;
1557 #endregion // Public Static Properties
1559 #region Public Instance Properties
1560 [EditorBrowsable(EditorBrowsableState.Advanced)]
1562 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1563 public AccessibleObject AccessibilityObject {
1565 if (accessibility_object==null) {
1566 accessibility_object=CreateAccessibilityInstance();
1568 return accessibility_object;
1572 [EditorBrowsable(EditorBrowsableState.Advanced)]
1574 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1575 public string AccessibleDefaultActionDescription {
1577 return AccessibilityObject.default_action;
1581 AccessibilityObject.default_action=value;
1586 [DefaultValue(null)]
1587 [MWFCategory("Accessibility")]
1588 public string AccessibleDescription {
1590 return AccessibilityObject.description;
1594 AccessibilityObject.description=value;
1599 [DefaultValue(null)]
1600 [MWFCategory("Accessibility")]
1601 public string AccessibleName {
1603 return AccessibilityObject.Name;
1607 AccessibilityObject.Name=value;
1611 [DefaultValue(AccessibleRole.Default)]
1612 [MWFDescription("Role of the control"), MWFCategory("Accessibility")]
1613 public AccessibleRole AccessibleRole {
1615 return AccessibilityObject.role;
1619 AccessibilityObject.role=value;
1623 [DefaultValue(false)]
1624 [MWFCategory("Behavior")]
1625 public virtual bool AllowDrop {
1631 if (allow_drop == value)
1634 if (IsHandleCreated) {
1636 XplatUI.SetAllowDrop (Handle, value);
1642 [RefreshProperties(RefreshProperties.Repaint)]
1643 [DefaultValue(AnchorStyles.Top | AnchorStyles.Left)]
1644 [MWFCategory("Layout")]
1645 public virtual AnchorStyles Anchor {
1647 return anchor_style;
1653 if (parent != null) {
1654 parent.PerformLayout(this, "Parent");
1660 // XXX: Implement me!
1663 [RefreshProperties (RefreshProperties.All)]
1664 [Localizable (true)]
1665 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
1667 [EditorBrowsable (EditorBrowsableState.Never)]
1668 [DefaultValue (false)]
1669 public virtual bool AutoSize {
1671 //Console.Error.WriteLine("Unimplemented: Control::get_AutoSize()");
1675 Console.Error.WriteLine("Unimplemented: Control::set_AutoSize(bool)");
1680 [AmbientValue (typeof(Size), "0, 0")]
1681 public virtual Size MaximumSize {
1683 return maximum_size;
1686 maximum_size = value;
1690 public virtual Size MinimumSize {
1692 return minimum_size;
1695 minimum_size = value;
1701 [MWFCategory("Appearance")]
1702 public virtual Color BackColor {
1704 if (background_color.IsEmpty) {
1706 Color pcolor = parent.BackColor;
1707 if (pcolor.A == 0xff || GetStyle(ControlStyles.SupportsTransparentBackColor))
1710 return DefaultBackColor;
1712 return background_color;
1716 if (!value.IsEmpty && (value.A != 0xff) && !GetStyle(ControlStyles.SupportsTransparentBackColor)) {
1717 throw new ArgumentException("Transparent background colors are not supported on this control");
1720 if (background_color != value) {
1721 background_color=value;
1722 SetChildColor(this);
1723 OnBackColorChanged(EventArgs.Empty);
1730 [DefaultValue(null)]
1731 [MWFCategory("Appearance")]
1732 public virtual Image BackgroundImage {
1734 return background_image;
1738 if (background_image!=value) {
1739 background_image=value;
1740 OnBackgroundImageChanged(EventArgs.Empty);
1748 [Localizable (true)]
1749 public virtual ImageLayout BackgroundImageLayout {
1751 return backgroundimage_layout;
1754 if (Array.IndexOf (Enum.GetValues (typeof (ImageLayout)), value) == -1)
1755 throw new InvalidEnumArgumentException ("value", (int) value, typeof(ImageLayout));
1757 if (value != backgroundimage_layout) {
1758 backgroundimage_layout = value;
1765 [EditorBrowsable(EditorBrowsableState.Advanced)]
1767 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1768 public virtual BindingContext BindingContext {
1770 if (binding_context != null)
1771 return binding_context;
1774 binding_context = Parent.BindingContext;
1775 return binding_context;
1778 if (binding_context != value) {
1779 binding_context = value;
1780 OnBindingContextChanged(EventArgs.Empty);
1785 [EditorBrowsable(EditorBrowsableState.Advanced)]
1787 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1790 return bounds.Y+bounds.Height;
1794 [EditorBrowsable(EditorBrowsableState.Advanced)]
1796 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1797 public Rectangle Bounds {
1803 SetBounds(value.Left, value.Top, value.Width, value.Height, BoundsSpecified.All);
1807 [EditorBrowsable(EditorBrowsableState.Advanced)]
1809 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1810 public bool CanFocus {
1812 if (IsHandleCreated && Visible && Enabled) {
1819 [EditorBrowsable(EditorBrowsableState.Advanced)]
1821 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1822 public bool CanSelect {
1826 if (!GetStyle(ControlStyles.Selectable)) {
1831 while (parent != null) {
1832 if (!parent.is_visible || !parent.is_enabled) {
1836 parent = parent.parent;
1842 internal virtual bool InternalCapture {
1852 [EditorBrowsable(EditorBrowsableState.Advanced)]
1854 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1855 public bool Capture {
1857 return this.is_captured;
1861 if (this.IsHandleCreated && value != is_captured) {
1864 XplatUI.GrabWindow(this.window.Handle, IntPtr.Zero);
1866 XplatUI.UngrabWindow(this.window.Handle);
1867 is_captured = false;
1873 [DefaultValue(true)]
1874 [MWFCategory("Focus")]
1875 public bool CausesValidation {
1877 return this.causes_validation;
1881 if (this.causes_validation != value) {
1882 causes_validation = value;
1883 OnCausesValidationChanged(EventArgs.Empty);
1888 [EditorBrowsable(EditorBrowsableState.Advanced)]
1890 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1891 public Rectangle ClientRectangle {
1893 client_rect.Width = client_size.Width;
1894 client_rect.Height = client_size.Height;
1899 [EditorBrowsable(EditorBrowsableState.Advanced)]
1901 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1902 public Size ClientSize {
1905 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1906 return ((Form)this).form_parent_window.ClientSize;
1914 this.SetClientSizeCore(value.Width, value.Height);
1918 [EditorBrowsable(EditorBrowsableState.Advanced)]
1920 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1921 [DescriptionAttribute("ControlCompanyNameDescr")]
1922 public String CompanyName {
1924 return "Mono Project, Novell, Inc.";
1928 [EditorBrowsable(EditorBrowsableState.Advanced)]
1930 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1931 public bool ContainsFocus {
1933 IntPtr focused_window;
1935 focused_window = XplatUI.GetFocus();
1936 if (IsHandleCreated) {
1937 if (focused_window == Handle) {
1941 for (int i=0; i < child_controls.Count; i++) {
1942 if (child_controls[i].ContainsFocus) {
1953 [DefaultValue(null)]
1954 [MWFCategory("Behavior")]
1955 public virtual ContextMenu ContextMenu {
1957 return GetContextMenuInternal ();
1961 if (context_menu != value) {
1962 context_menu = value;
1963 OnContextMenuChanged(EventArgs.Empty);
1968 internal virtual ContextMenu GetContextMenuInternal ()
1970 return context_menu;
1974 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
1975 public ControlCollection Controls {
1977 return this.child_controls;
1981 [EditorBrowsable(EditorBrowsableState.Advanced)]
1983 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1984 public bool Created {
1986 return (!is_disposed && is_created);
1990 [AmbientValue(null)]
1991 [MWFCategory("Appearance")]
1992 public virtual Cursor Cursor {
1994 if (cursor != null) {
1998 if (parent != null) {
1999 return parent.Cursor;
2002 return Cursors.Default;
2006 if (cursor != value) {
2011 if (IsHandleCreated) {
2012 pt = Cursor.Position;
2014 if (bounds.Contains(pt) || Capture) {
2015 if (GetChildAtPoint(pt) == null) {
2016 if (cursor != null) {
2017 XplatUI.SetCursor(window.Handle, cursor.handle);
2019 if (parent != null) {
2020 XplatUI.SetCursor(window.Handle, parent.Cursor.handle);
2022 XplatUI.SetCursor(window.Handle, Cursors.Default.handle);
2029 OnCursorChanged(EventArgs.Empty);
2035 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
2036 [ParenthesizePropertyName(true)]
2037 [RefreshProperties(RefreshProperties.All)]
2038 [MWFCategory("Data")]
2039 public ControlBindingsCollection DataBindings {
2041 if (data_bindings == null)
2042 data_bindings = new ControlBindingsCollection (this);
2043 return data_bindings;
2047 [EditorBrowsable(EditorBrowsableState.Advanced)]
2049 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2050 public virtual Rectangle DisplayRectangle {
2052 return ClientRectangle;
2056 [EditorBrowsable(EditorBrowsableState.Advanced)]
2058 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2059 public bool Disposing {
2066 [RefreshProperties(RefreshProperties.Repaint)]
2067 [DefaultValue(DockStyle.None)]
2068 [MWFCategory("Layout")]
2069 public virtual DockStyle Dock {
2075 if (dock_style == value) {
2079 if (!Enum.IsDefined (typeof (DockStyle), value)) {
2080 throw new InvalidEnumArgumentException ("value", (int) value,
2081 typeof (DockStyle));
2086 if (dock_style == DockStyle.None) {
2087 if (explicit_bounds == Rectangle.Empty)
2088 Bounds = new Rectangle (new Point (0, 0), DefaultSize);
2090 Bounds = explicit_bounds;
2093 if (parent != null) {
2094 parent.PerformLayout(this, "Parent");
2097 OnDockChanged(EventArgs.Empty);
2102 protected virtual bool DoubleBuffered {
2104 return (control_style & ControlStyles.DoubleBuffer) != 0;
2108 SetStyle (ControlStyles.DoubleBuffer, value);
2115 [MWFCategory("Behavior")]
2116 public bool Enabled {
2122 if (parent != null) {
2123 return parent.Enabled;
2131 bool old_value = is_enabled;
2134 if (old_value != value && !value && this.has_focus)
2135 SelectNextControl(this, true, true, true, true);
2137 OnEnabledChanged (EventArgs.Empty);
2141 [EditorBrowsable(EditorBrowsableState.Advanced)]
2143 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2144 public virtual bool Focused {
2146 return this.has_focus;
2151 [AmbientValue(null)]
2153 [MWFCategory("Appearance")]
2154 public virtual Font Font {
2160 if (Parent != null && Parent.Font != null) {
2167 [param:MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Font))]
2169 if (font != null && font.Equals (value)) {
2175 OnFontChanged (EventArgs.Empty);
2180 [MWFCategory("Appearance")]
2181 public virtual Color ForeColor {
2183 if (foreground_color.IsEmpty) {
2185 return parent.ForeColor;
2187 return DefaultForeColor;
2189 return foreground_color;
2193 if (foreground_color != value) {
2194 foreground_color=value;
2196 OnForeColorChanged(EventArgs.Empty);
2203 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2204 public IntPtr Handle { // IWin32Window
2207 if (verify_thread_handle) {
2208 if (this.InvokeRequired) {
2209 throw new InvalidOperationException("Cross-thread access of handle detected. Handle access only valid on thread that created the control");
2213 if (!IsHandleCreated) {
2216 return window.Handle;
2220 [EditorBrowsable(EditorBrowsableState.Advanced)]
2222 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2223 public bool HasChildren {
2225 if (this.child_controls.Count>0) {
2232 [EditorBrowsable(EditorBrowsableState.Always)]
2234 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2237 return this.bounds.Height;
2241 SetBounds(bounds.X, bounds.Y, bounds.Width, value, BoundsSpecified.Height);
2245 [AmbientValue(ImeMode.Inherit)]
2247 [MWFCategory("Behavior")]
2248 public ImeMode ImeMode {
2250 if (ime_mode == ImeMode.Inherit) {
2252 return parent.ImeMode;
2254 return ImeMode.NoControl; // default value
2260 if (ime_mode != value) {
2263 OnImeModeChanged(EventArgs.Empty);
2268 [EditorBrowsable(EditorBrowsableState.Advanced)]
2270 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2271 public bool InvokeRequired { // ISynchronizeInvoke
2273 if (creator_thread != null && creator_thread!=Thread.CurrentThread) {
2280 [EditorBrowsable(EditorBrowsableState.Advanced)]
2282 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2283 public bool IsAccessible {
2285 return is_accessible;
2289 is_accessible = value;
2293 [EditorBrowsable(EditorBrowsableState.Advanced)]
2295 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2296 public bool IsDisposed {
2298 return this.is_disposed;
2302 [EditorBrowsable(EditorBrowsableState.Advanced)]
2304 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2305 public bool IsHandleCreated {
2307 if ((window != null) && (window.Handle != IntPtr.Zero)) {
2308 Hwnd hwnd = Hwnd.ObjectFromHandle (window.Handle);
2309 if (hwnd != null && !hwnd.zombie)
2319 [EditorBrowsable (EditorBrowsableState.Advanced)]
2320 public virtual Layout.LayoutEngine LayoutEngine {
2321 get { return new Layout.DefaultLayout (); }
2325 [EditorBrowsable(EditorBrowsableState.Always)]
2327 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2330 return this.bounds.X;
2334 SetBounds(value, bounds.Y, bounds.Width, bounds.Height, BoundsSpecified.X);
2339 [MWFCategory("Layout")]
2340 public Point Location {
2342 return new Point(bounds.X, bounds.Y);
2346 SetBounds(value.X, value.Y, bounds.Width, bounds.Height, BoundsSpecified.Location);
2351 [Localizable (true)]
2352 public Padding Margin {
2353 get { return this.margin; }
2354 set { this.margin = value; }
2359 public string Name {
2371 public Padding Padding {
2378 OnPaddingChanged (EventArgs.Empty);
2384 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2385 public Control Parent {
2391 if (value == this) {
2392 throw new ArgumentException("A circular control reference has been made. A control cannot be owned or parented to itself.");
2395 if (parent!=value) {
2397 parent.Controls.Remove(this);
2402 value.Controls.Add(this);
2407 [EditorBrowsable(EditorBrowsableState.Advanced)]
2409 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2410 public string ProductName {
2412 Type t = typeof (AssemblyProductAttribute);
2413 Assembly assembly = GetType().Module.Assembly;
2414 object [] attrs = assembly.GetCustomAttributes (t, false);
2415 AssemblyProductAttribute a = null;
2416 // On MS we get a NullRefException if product attribute is not
2418 if (attrs != null && attrs.Length > 0)
2419 a = (AssemblyProductAttribute) attrs [0];
2424 [EditorBrowsable(EditorBrowsableState.Advanced)]
2426 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2427 public string ProductVersion {
2429 Type t = typeof (AssemblyVersionAttribute);
2430 Assembly assembly = GetType().Module.Assembly;
2431 object [] attrs = assembly.GetCustomAttributes (t, false);
2432 if (attrs == null || attrs.Length < 1)
2434 return ((AssemblyVersionAttribute)attrs [0]).Version;
2438 [EditorBrowsable(EditorBrowsableState.Advanced)]
2440 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2441 public bool RecreatingHandle {
2443 return is_recreating;
2447 [EditorBrowsable(EditorBrowsableState.Advanced)]
2449 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2450 public Region Region {
2456 if (value != null && IsHandleCreated) {
2457 XplatUI.SetClipRegion(Handle, value);
2459 clip_region = value;
2463 [EditorBrowsable(EditorBrowsableState.Advanced)]
2465 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2468 return this.bounds.X+this.bounds.Width;
2472 [AmbientValue(RightToLeft.Inherit)]
2474 [MWFCategory("Appearance")]
2475 public virtual RightToLeft RightToLeft {
2477 if (right_to_left == RightToLeft.Inherit) {
2479 return parent.RightToLeft;
2481 return RightToLeft.No; // default value
2483 return right_to_left;
2487 if (value != right_to_left) {
2488 right_to_left = value;
2489 OnRightToLeftChanged(EventArgs.Empty);
2494 [EditorBrowsable(EditorBrowsableState.Advanced)]
2495 public override ISite Site {
2503 if (value != null) {
2504 AmbientProperties ap = (AmbientProperties) value.GetService (typeof (AmbientProperties));
2506 BackColor = ap.BackColor;
2507 ForeColor = ap.ForeColor;
2516 [MWFCategory("Layout")]
2519 return new Size(Width, Height);
2523 SetBounds(bounds.X, bounds.Y, value.Width, value.Height, BoundsSpecified.Size);
2528 [MergableProperty(false)]
2529 [MWFCategory("Behavior")]
2530 public int TabIndex {
2532 if (tab_index != -1) {
2539 if (tab_index != value) {
2541 OnTabIndexChanged(EventArgs.Empty);
2547 [DefaultValue(true)]
2548 [MWFCategory("Behavior")]
2549 public bool TabStop {
2555 if (tab_stop != value) {
2557 OnTabStopChanged(EventArgs.Empty);
2562 [Localizable(false)]
2564 [TypeConverter(typeof(StringConverter))]
2565 [DefaultValue(null)]
2566 [MWFCategory("Data")]
2573 control_tag = value;
2579 [BindableAttribute(true)]
2580 [MWFCategory("Appearance")]
2581 public virtual string Text {
2583 // Our implementation ignores ControlStyles.CacheText - we always cache
2588 if (value == null) {
2589 value = String.Empty;
2594 if (IsHandleCreated) {
2595 /* we need to call .SetWindowStyle here instead of just .Text
2596 because the presence/absence of Text (== "" or not) can cause
2597 other window style things to appear/disappear */
2598 XplatUI.SetWindowStyle(window.Handle, CreateParams);
2599 XplatUI.Text(Handle, text);
2601 OnTextChanged (EventArgs.Empty);
2606 [EditorBrowsable(EditorBrowsableState.Always)]
2608 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2611 return this.bounds.Y;
2615 SetBounds(bounds.X, value, bounds.Width, bounds.Height, BoundsSpecified.Y);
2619 [EditorBrowsable(EditorBrowsableState.Advanced)]
2621 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2622 public Control TopLevelControl {
2626 while (p.parent != null) {
2630 return p is Form ? p : null;
2635 [MWFCategory("Behavior")]
2636 public bool Visible {
2640 } else if (parent != null) {
2641 return parent.Visible;
2648 SetVisibleCore(value);
2652 [EditorBrowsable(EditorBrowsableState.Always)]
2654 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2657 return this.bounds.Width;
2661 SetBounds(bounds.X, bounds.Y, value, bounds.Height, BoundsSpecified.Width);
2665 [EditorBrowsable(EditorBrowsableState.Never)]
2667 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2668 public IWindowTarget WindowTarget {
2677 #endregion // Public Instance Properties
2679 #region Protected Instance Properties
2680 protected virtual CreateParams CreateParams {
2682 CreateParams create_params = new CreateParams();
2685 create_params.Caption = Text;
2688 create_params.Caption = text;
2692 create_params.X = Left;
2695 create_params.X = this.bounds.X;
2699 create_params.Y = Top;
2702 create_params.Y = this.bounds.Y;
2706 create_params.Width = Width;
2709 create_params.Width = this.bounds.Width;
2713 create_params.Height = Height;
2716 create_params.Height = this.bounds.Height;
2720 create_params.ClassName = XplatUI.DefaultClassName;
2721 create_params.ClassStyle = 0;
2722 create_params.ExStyle = 0;
2723 create_params.Param = 0;
2726 create_params.ExStyle |= (int)WindowExStyles.WS_EX_ACCEPTFILES;
2729 if ((parent!=null) && (parent.IsHandleCreated)) {
2730 create_params.Parent = parent.Handle;
2733 create_params.Style = (int)WindowStyles.WS_CHILD | (int)WindowStyles.WS_CLIPCHILDREN | (int)WindowStyles.WS_CLIPSIBLINGS;
2736 create_params.Style |= (int)WindowStyles.WS_VISIBLE;
2740 create_params.Style |= (int)WindowStyles.WS_DISABLED;
2743 switch (border_style) {
2744 case BorderStyle.FixedSingle:
2745 create_params.Style |= (int) WindowStyles.WS_BORDER;
2747 case BorderStyle.Fixed3D:
2748 create_params.ExStyle |= (int) WindowExStyles.WS_EX_CLIENTEDGE;
2752 return create_params;
2756 protected virtual ImeMode DefaultImeMode {
2758 return ImeMode.Inherit;
2763 protected virtual Padding DefaultMargin {
2764 get { return new Padding (3); }
2768 protected virtual Size DefaultSize {
2770 return new Size(0, 0);
2774 protected int FontHeight {
2786 protected bool RenderRightToLeft {
2788 return (this.right_to_left == RightToLeft.Yes);
2792 protected bool ResizeRedraw {
2794 return GetStyle(ControlStyles.ResizeRedraw);
2798 SetStyle(ControlStyles.ResizeRedraw, value);
2802 [EditorBrowsable(EditorBrowsableState.Advanced)]
2804 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2805 protected virtual bool ShowFocusCues {
2811 [EditorBrowsable(EditorBrowsableState.Advanced)]
2813 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2814 protected bool ShowKeyboardCues {
2819 #endregion // Protected Instance Properties
2821 #region Public Static Methods
2822 [EditorBrowsable(EditorBrowsableState.Advanced)]
2823 public static Control FromChildHandle(IntPtr handle) {
2824 return Control.ControlNativeWindow.ControlFromChildHandle (handle);
2827 [EditorBrowsable(EditorBrowsableState.Advanced)]
2828 public static Control FromHandle(IntPtr handle) {
2829 return Control.ControlNativeWindow.ControlFromHandle(handle);
2832 public static bool IsMnemonic(char charCode, string text) {
2835 amp = text.IndexOf('&');
2838 if (amp + 1 < text.Length) {
2839 if (text[amp + 1] != '&') {
2840 if (Char.ToUpper(charCode) == Char.ToUpper(text.ToCharArray(amp + 1, 1)[0])) {
2850 #region Protected Static Methods
2851 [EditorBrowsable(EditorBrowsableState.Advanced)]
2852 protected static bool ReflectMessage(IntPtr hWnd, ref Message m) {
2855 c = Control.FromHandle(hWnd);
2865 #region Public Instance Methods
2866 [EditorBrowsable(EditorBrowsableState.Advanced)]
2867 public IAsyncResult BeginInvoke(Delegate method) {
2868 object [] prms = null;
2869 if (method is EventHandler)
2870 prms = new object [] { this, EventArgs.Empty };
2871 return BeginInvokeInternal(method, prms, false);
2874 [EditorBrowsable(EditorBrowsableState.Advanced)]
2875 public IAsyncResult BeginInvoke (Delegate method, object[] args) {
2876 return BeginInvokeInternal (method, args, false);
2879 public void BringToFront() {
2880 if (parent != null) {
2881 parent.child_controls.SetChildIndex(this, 0);
2884 XplatUI.SetZOrder(Handle, IntPtr.Zero, false, false);
2888 public bool Contains(Control ctl) {
2889 while (ctl != null) {
2898 public void CreateControl() {
2900 throw new ObjectDisposedException(GetType().FullName.ToString());
2906 if (!IsHandleCreated) {
2914 Control [] controls = child_controls.GetAllControls ();
2915 for (int i=0; i<controls.Length; i++) {
2916 controls [i].CreateControl ();
2919 UpdateChildrenZOrder();
2921 if (binding_context == null) { // seem to be sent whenever it's null?
2922 OnBindingContextChanged(EventArgs.Empty);
2928 public Graphics CreateGraphics() {
2929 if (!IsHandleCreated) {
2930 this.CreateHandle();
2932 return Graphics.FromHwnd(this.window.Handle);
2935 public DragDropEffects DoDragDrop(object data, DragDropEffects allowedEffects) {
2936 return XplatUI.StartDrag(this.window.Handle, data, allowedEffects);
2939 [EditorBrowsable(EditorBrowsableState.Advanced)]
2940 public object EndInvoke (IAsyncResult async_result) {
2941 AsyncMethodResult result = (AsyncMethodResult) async_result;
2942 return result.EndInvoke ();
2945 public Form FindForm() {
2958 [EditorBrowsable (EditorBrowsableState.Advanced)]
2960 public bool Focus() {
2961 if (CanFocus && IsHandleCreated && !has_focus && !is_focusing) {
2964 is_focusing = false;
2969 public Control GetChildAtPoint(Point pt) {
2970 // Microsoft's version of this function doesn't seem to work, so I can't check
2971 // if we only consider children or also grandchildren, etc.
2972 // I'm gonna say 'children only'
2973 for (int i=0; i<child_controls.Count; i++) {
2974 if (child_controls[i].Bounds.Contains(pt)) {
2975 return child_controls[i];
2981 public IContainerControl GetContainerControl() {
2982 Control current = this;
2984 while (current!=null) {
2985 if ((current is IContainerControl) && ((current.control_style & ControlStyles.ContainerControl)!=0)) {
2986 return (IContainerControl)current;
2988 current = current.parent;
2993 public Control GetNextControl(Control ctl, bool forward) {
2995 if (!this.Contains(ctl)) {
3000 ctl = FindControlForward(this, ctl);
3003 ctl = FindControlBackward(this, ctl);
3013 [EditorBrowsable (EditorBrowsableState.Advanced)]
3014 public virtual Size GetPreferredSize (Size proposedSize) {
3015 return preferred_size;
3019 public void Hide() {
3020 this.Visible = false;
3023 public void Invalidate() {
3024 Invalidate(ClientRectangle, false);
3027 public void Invalidate(bool invalidateChildren) {
3028 Invalidate(ClientRectangle, invalidateChildren);
3031 public void Invalidate(System.Drawing.Rectangle rc) {
3032 Invalidate(rc, false);
3035 public void Invalidate(System.Drawing.Rectangle rc, bool invalidateChildren) {
3036 if (!IsHandleCreated || !Visible || rc.Width == 0 || rc.Height == 0) {
3040 NotifyInvalidate(rc);
3042 XplatUI.Invalidate(Handle, rc, false);
3044 if (invalidateChildren) {
3045 Control [] controls = child_controls.GetAllControls ();
3046 for (int i=0; i<controls.Length; i++)
3047 controls [i].Invalidate ();
3049 OnInvalidated(new InvalidateEventArgs(rc));
3052 public void Invalidate(System.Drawing.Region region) {
3053 Invalidate(region, false);
3056 public void Invalidate(System.Drawing.Region region, bool invalidateChildren) {
3057 RectangleF bounds = region.GetBounds (CreateGraphics ());
3058 Invalidate (new Rectangle ((int) bounds.X, (int) bounds.Y, (int) bounds.Width, (int) bounds.Height),
3059 invalidateChildren);
3062 public object Invoke (Delegate method) {
3063 object [] prms = null;
3064 if (method is EventHandler)
3065 prms = new object [] { this, EventArgs.Empty };
3067 return Invoke(method, prms);
3070 public object Invoke (Delegate method, object[] args) {
3071 if (!this.InvokeRequired) {
3072 return method.DynamicInvoke(args);
3075 IAsyncResult result = BeginInvoke (method, args);
3076 return EndInvoke(result);
3079 internal object InvokeInternal (Delegate method, bool disposing) {
3080 return InvokeInternal(method, null, disposing);
3083 internal object InvokeInternal (Delegate method, object[] args, bool disposing) {
3084 if (!this.InvokeRequired) {
3085 return method.DynamicInvoke(args);
3088 IAsyncResult result = BeginInvokeInternal (method, args, disposing);
3089 return EndInvoke(result);
3092 [EditorBrowsable(EditorBrowsableState.Advanced)]
3093 public void PerformLayout() {
3094 PerformLayout(null, null);
3098 private void SetImplicitBounds (int x, int y, int width, int height)
3100 Rectangle saved_bounds = explicit_bounds;
3101 SetBounds (x, y, width, height);
3102 explicit_bounds = saved_bounds;
3106 [EditorBrowsable(EditorBrowsableState.Advanced)]
3107 public void PerformLayout(Control affectedControl, string affectedProperty) {
3108 LayoutEventArgs levent = new LayoutEventArgs(affectedControl, affectedProperty);
3110 if (layout_suspended > 0) {
3111 layout_pending = true;
3115 layout_pending = false;
3117 // Prevent us from getting messed up
3120 // Perform all Dock and Anchor calculations
3124 this.layout_engine.Layout(this, levent);
3126 // This has been moved to Layout/DefaultLayout.cs for 2.0, please duplicate any changes/fixes there.
3128 AnchorStyles anchor;
3131 space = DisplayRectangle;
3133 // Deal with docking; go through in reverse, MS docs say that lowest Z-order is closest to edge
3134 Control [] controls = child_controls.GetAllControls ();
3135 for (int i = controls.Length - 1; i >= 0; i--) {
3136 child = controls [i];
3138 if (!child.Visible) {
3142 switch (child.Dock) {
3143 case DockStyle.None: {
3148 case DockStyle.Left: {
3149 child.SetImplicitBounds(space.Left, space.Y, child.Width, space.Height);
3150 space.X+=child.Width;
3151 space.Width-=child.Width;
3155 case DockStyle.Top: {
3156 child.SetImplicitBounds(space.Left, space.Y, space.Width, child.Height);
3157 space.Y+=child.Height;
3158 space.Height-=child.Height;
3162 case DockStyle.Right: {
3163 child.SetImplicitBounds(space.Right-child.Width, space.Y, child.Width, space.Height);
3164 space.Width-=child.Width;
3168 case DockStyle.Bottom: {
3169 child.SetImplicitBounds(space.Left, space.Bottom-child.Height, space.Width, child.Height);
3170 space.Height-=child.Height;
3176 for (int i = controls.Length - 1; i >= 0; i--) {
3179 //if (child.Visible && (child.Dock == DockStyle.Fill)) {
3180 if (child.Dock == DockStyle.Fill) {
3181 child.SetImplicitBounds(space.Left, space.Top, space.Width, space.Height);
3185 space = DisplayRectangle;
3187 for (int i=0; i < controls.Length; i++) {
3193 child = controls[i];
3195 // If the control is docked we don't need to do anything
3196 if (child.Dock != DockStyle.None) {
3200 anchor = child.Anchor;
3204 width = child.Width;
3205 height = child.Height;
3207 if ((anchor & AnchorStyles.Left) !=0 ) {
3208 if ((anchor & AnchorStyles.Right) != 0) {
3209 width = space.Width - child.dist_right - left;
3211 ; // Left anchored only, nothing to be done
3213 } else if ((anchor & AnchorStyles.Right) != 0) {
3214 left = space.Width - child.dist_right - width;
3216 // left+=diff_width/2 will introduce rounding errors (diff_width removed from svn after r51780)
3217 // This calculates from scratch every time:
3218 left = child.dist_left + (space.Width - (child.dist_left + width + child.dist_right)) / 2;
3221 if ((anchor & AnchorStyles.Top) !=0 ) {
3222 if ((anchor & AnchorStyles.Bottom) != 0) {
3223 height = space.Height - child.dist_bottom - top;
3225 ; // Top anchored only, nothing to be done
3227 } else if ((anchor & AnchorStyles.Bottom) != 0) {
3228 top = space.Height - child.dist_bottom - height;
3230 // top += diff_height/2 will introduce rounding errors (diff_height removed from after r51780)
3231 // This calculates from scratch every time:
3232 top = child.dist_top + (space.Height - (child.dist_top + height + child.dist_bottom)) / 2;
3244 child.SetImplicitBounds(left, top, width, height);
3248 // Let everyone know
3252 // Need to make sure we decremend layout_suspended
3258 public Point PointToClient (Point p) {
3262 XplatUI.ScreenToClient (Handle, ref x, ref y);
3264 return new Point (x, y);
3267 public Point PointToScreen(Point p) {
3271 XplatUI.ClientToScreen(Handle, ref x, ref y);
3273 return new Point(x, y);
3276 public virtual bool PreProcessMessage(ref Message msg) {
3277 return InternalPreProcessMessage (ref msg);
3280 internal virtual bool InternalPreProcessMessage (ref Message msg) {
3283 if ((msg.Msg == (int)Msg.WM_KEYDOWN) || (msg.Msg == (int)Msg.WM_SYSKEYDOWN)) {
3284 key_data = (Keys)msg.WParam.ToInt32() | XplatUI.State.ModifierKeys;
3286 if (!ProcessCmdKey(ref msg, key_data)) {
3287 if (IsInputKey(key_data)) {
3291 return ProcessDialogKey(key_data);
3295 } else if (msg.Msg == (int)Msg.WM_CHAR) {
3296 if (IsInputChar((char)msg.WParam)) {
3299 return ProcessDialogChar((char)msg.WParam);
3300 } else if (msg.Msg == (int)Msg.WM_SYSCHAR) {
3301 return ProcessDialogChar((char)msg.WParam);
3306 public Rectangle RectangleToClient(Rectangle r) {
3307 return new Rectangle(PointToClient(r.Location), r.Size);
3310 public Rectangle RectangleToScreen(Rectangle r) {
3311 return new Rectangle(PointToScreen(r.Location), r.Size);
3314 public virtual void Refresh() {
3315 if (IsHandleCreated == true) {
3317 XplatUI.UpdateWindow(window.Handle);
3319 Control [] controls = child_controls.GetAllControls ();
3320 for (int i=0; i < controls.Length; i++) {
3321 controls[i].Refresh();
3327 [EditorBrowsable(EditorBrowsableState.Never)]
3328 public virtual void ResetBackColor() {
3329 BackColor = Color.Empty;
3332 [EditorBrowsable(EditorBrowsableState.Never)]
3333 public void ResetBindings() {
3334 data_bindings.Clear();
3337 [EditorBrowsable(EditorBrowsableState.Never)]
3338 public virtual void ResetCursor() {
3342 [EditorBrowsable(EditorBrowsableState.Never)]
3343 public virtual void ResetFont() {
3347 [EditorBrowsable(EditorBrowsableState.Never)]
3348 public virtual void ResetForeColor() {
3349 foreground_color = Color.Empty;
3352 [EditorBrowsable(EditorBrowsableState.Never)]
3353 public void ResetImeMode() {
3354 ime_mode = DefaultImeMode;
3357 [EditorBrowsable(EditorBrowsableState.Never)]
3358 public virtual void ResetRightToLeft() {
3359 right_to_left = RightToLeft.Inherit;
3362 public virtual void ResetText() {
3363 text = String.Empty;
3366 public void ResumeLayout() {
3367 ResumeLayout (true);
3370 public void ResumeLayout(bool performLayout) {
3371 if (layout_suspended > 0) {
3375 if (layout_suspended == 0) {
3376 Control [] controls = child_controls.GetAllControls ();
3377 if (performLayout && layout_pending) {
3383 [EditorBrowsable (EditorBrowsableState.Never)]
3386 public void Scale(float ratio) {
3387 ScaleCore(ratio, ratio);
3391 [EditorBrowsable (EditorBrowsableState.Never)]
3394 public void Scale(float dx, float dy) {
3399 [EditorBrowsable (EditorBrowsableState.Advanced)]
3400 public void Scale(SizeF factor) {
3401 ScaleCore(factor.Width, factor.Height);
3405 public void Select() {
3406 Select(false, false);
3410 private void printTree(Control c, string t) {
3411 foreach(Control i in c.child_controls) {
3412 Console.WriteLine("{2}{0}.TabIndex={1}", i, i.tab_index, t);
3413 printTree(i, t+"\t");
3417 public bool SelectNextControl(Control ctl, bool forward, bool tabStopOnly, bool nested, bool wrap) {
3421 Console.WriteLine("{0}", this.FindForm());
3422 printTree(this, "\t");
3425 if (!this.Contains(ctl) || (!nested && (ctl.parent != this))) {
3430 c = GetNextControl(c, forward);
3439 if (c.CanSelect && ((c.parent == this) || nested) && (c.tab_stop || !tabStopOnly)) {
3440 c.Select (true, true);
3443 } while (c != ctl); // If we wrap back to ourselves we stop
3448 public void SendToBack() {
3449 if (parent != null) {
3450 parent.child_controls.SetChildIndex(this, parent.child_controls.Count);
3454 public void SetBounds(int x, int y, int width, int height) {
3455 SetBounds(x, y, width, height, BoundsSpecified.All);
3458 public void SetBounds(int x, int y, int width, int height, BoundsSpecified specified) {
3459 if ((specified & BoundsSpecified.X) != BoundsSpecified.X) {
3463 if ((specified & BoundsSpecified.Y) != BoundsSpecified.Y) {
3467 if ((specified & BoundsSpecified.Width) != BoundsSpecified.Width) {
3471 if ((specified & BoundsSpecified.Height) != BoundsSpecified.Height) {
3475 SetBoundsCore(x, y, width, height, specified);
3476 if (parent != null) {
3477 parent.PerformLayout(this, "Bounds");
3481 public void Show() {
3483 this.CreateControl();
3489 public void SuspendLayout() {
3493 public void Update() {
3494 if (IsHandleCreated) {
3495 XplatUI.UpdateWindow(window.Handle);
3498 #endregion // Public Instance Methods
3500 #region Protected Instance Methods
3501 [EditorBrowsable(EditorBrowsableState.Advanced)]
3502 [MonoTODO("Implement this and tie it into Control.ControlAccessibleObject.NotifyClients")]
3503 protected void AccessibilityNotifyClients(AccessibleEvents accEvent, int childID) {
3504 throw new NotImplementedException();
3507 [EditorBrowsable(EditorBrowsableState.Advanced)]
3508 protected virtual AccessibleObject CreateAccessibilityInstance() {
3509 return new Control.ControlAccessibleObject(this);
3512 [EditorBrowsable(EditorBrowsableState.Advanced)]
3513 protected virtual ControlCollection CreateControlsInstance() {
3514 return new ControlCollection(this);
3517 [EditorBrowsable(EditorBrowsableState.Advanced)]
3518 protected virtual void CreateHandle() {
3520 throw new ObjectDisposedException(GetType().FullName.ToString());
3523 if (IsHandleCreated && !is_recreating) {
3527 window.CreateHandle(CreateParams);
3529 if (window.Handle != IntPtr.Zero) {
3530 creator_thread = Thread.CurrentThread;
3532 XplatUI.EnableWindow(window.Handle, is_enabled);
3533 XplatUI.SetVisible(window.Handle, is_visible, true);
3535 if (clip_region != null) {
3536 XplatUI.SetClipRegion(Handle, clip_region);
3539 // Set our handle with our parent
3540 if ((parent != null) && (parent.IsHandleCreated)) {
3541 XplatUI.SetParent(window.Handle, parent.Handle);
3544 // Set our handle as parent for our children
3545 Control [] children;
3547 children = child_controls.GetAllControls ();
3548 for (int i = 0; i < children.Length; i++ ) {
3549 if (!children[i].RecreatingHandle)
3550 XplatUI.SetParent(children[i].Handle, window.Handle);
3554 XplatUI.SetAllowDrop (Handle, allow_drop);
3556 // Find out where the window manager placed us
3557 if ((CreateParams.Style & (int)WindowStyles.WS_CHILD) != 0) {
3558 XplatUI.SetBorderStyle(window.Handle, (FormBorderStyle)border_style);
3562 OnHandleCreated(EventArgs.Empty);
3566 [EditorBrowsable(EditorBrowsableState.Advanced)]
3567 protected virtual void DefWndProc(ref Message m) {
3568 window.DefWndProc(ref m);
3571 [EditorBrowsable(EditorBrowsableState.Advanced)]
3572 protected virtual void DestroyHandle() {
3573 if (IsHandleCreated) {
3574 if (window != null) {
3575 window.DestroyHandle();
3580 protected internal bool GetStyle(ControlStyles flag) {
3581 return (control_style & flag) != 0;
3584 protected bool GetTopLevel() {
3588 [EditorBrowsable(EditorBrowsableState.Advanced)]
3589 protected virtual void InitLayout() {
3593 [EditorBrowsable(EditorBrowsableState.Advanced)]
3594 protected void InvokeGotFocus(Control toInvoke, EventArgs e) {
3595 toInvoke.OnGotFocus(e);
3598 [EditorBrowsable(EditorBrowsableState.Advanced)]
3599 protected void InvokeLostFocus(Control toInvoke, EventArgs e) {
3600 toInvoke.OnLostFocus(e);
3603 [EditorBrowsable(EditorBrowsableState.Advanced)]
3604 protected void InvokeOnClick(Control toInvoke, EventArgs e) {
3605 toInvoke.OnClick(e);
3608 protected void InvokePaint(Control toInvoke, PaintEventArgs e) {
3609 toInvoke.OnPaint(e);
3612 protected void InvokePaintBackground(Control toInvoke, PaintEventArgs e) {
3613 toInvoke.OnPaintBackground(e);
3616 protected virtual bool IsInputChar (char charCode) {
3620 protected virtual bool IsInputKey (Keys keyData) {
3621 // Doc says this one calls IsInputChar; not sure what to do with that
3625 [EditorBrowsable(EditorBrowsableState.Advanced)]
3626 protected virtual void NotifyInvalidate(Rectangle invalidatedArea) {
3630 protected virtual bool ProcessCmdKey(ref Message msg, Keys keyData) {
3631 if ((context_menu != null) && context_menu.ProcessCmdKey(ref msg, keyData)) {
3635 if (parent != null) {
3636 return parent.ProcessCmdKey(ref msg, keyData);
3642 protected virtual bool ProcessDialogChar(char charCode) {
3643 if (parent != null) {
3644 return parent.ProcessDialogChar (charCode);
3650 protected virtual bool ProcessDialogKey (Keys keyData) {
3651 if (parent != null) {
3652 return parent.ProcessDialogKey (keyData);
3658 protected virtual bool ProcessKeyEventArgs (ref Message msg)
3660 KeyEventArgs key_event;
3663 case (int)Msg.WM_SYSKEYDOWN:
3664 case (int)Msg.WM_KEYDOWN: {
3665 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
3666 OnKeyDown (key_event);
3667 return key_event.Handled;
3670 case (int)Msg.WM_SYSKEYUP:
3671 case (int)Msg.WM_KEYUP: {
3672 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
3673 OnKeyUp (key_event);
3674 return key_event.Handled;
3677 case (int)Msg.WM_SYSCHAR:
3678 case (int)Msg.WM_CHAR: {
3679 KeyPressEventArgs key_press_event;
3681 key_press_event = new KeyPressEventArgs((char)msg.WParam);
3682 OnKeyPress(key_press_event);
3684 msg.WParam = (IntPtr)key_press_event.KeyChar;
3686 return key_press_event.Handled;
3697 protected internal virtual bool ProcessKeyMessage(ref Message msg) {
3698 if (parent != null) {
3699 if (parent.ProcessKeyPreview(ref msg)) {
3704 return ProcessKeyEventArgs(ref msg);
3707 protected virtual bool ProcessKeyPreview(ref Message msg) {
3708 if (parent != null) {
3709 return parent.ProcessKeyPreview(ref msg);
3715 protected virtual bool ProcessMnemonic(char charCode) {
3720 [EditorBrowsable(EditorBrowsableState.Advanced)]
3721 protected void RaiseDragEvent(object key, DragEventArgs e) {
3725 [EditorBrowsable(EditorBrowsableState.Advanced)]
3726 protected void RaiseKeyEvent(object key, KeyEventArgs e) {
3730 [EditorBrowsable(EditorBrowsableState.Advanced)]
3731 protected void RaiseMouseEvent(object key, MouseEventArgs e) {
3735 [EditorBrowsable(EditorBrowsableState.Advanced)]
3736 protected void RaisePaintEvent(object key, PaintEventArgs e) {
3740 private void SetIsRecreating ()
3744 foreach (Control c in Controls.GetAllControls()) {
3745 c.SetIsRecreating ();
3749 [EditorBrowsable(EditorBrowsableState.Advanced)]
3750 protected void RecreateHandle() {
3752 Console.WriteLine("Recreating control {0}", XplatUI.Window(window.Handle));
3757 if (IsHandleCreated) {
3759 Console.WriteLine(" + handle is created, destroying it.");
3762 // WM_DESTROY will CreateHandle for us
3765 Console.WriteLine(" + handle is not created, creating it.");
3773 is_recreating = false;
3775 Console.WriteLine (" + new handle = {0:X}", Handle.ToInt32());
3781 [EditorBrowsable(EditorBrowsableState.Advanced)]
3782 protected void ResetMouseEventArgs() {
3786 [EditorBrowsable(EditorBrowsableState.Advanced)]
3787 protected ContentAlignment RtlTranslateAlignment(ContentAlignment align) {
3788 if (right_to_left == RightToLeft.No) {
3793 case ContentAlignment.TopLeft: {
3794 return ContentAlignment.TopRight;
3797 case ContentAlignment.TopRight: {
3798 return ContentAlignment.TopLeft;
3801 case ContentAlignment.MiddleLeft: {
3802 return ContentAlignment.MiddleRight;
3805 case ContentAlignment.MiddleRight: {
3806 return ContentAlignment.MiddleLeft;
3809 case ContentAlignment.BottomLeft: {
3810 return ContentAlignment.BottomRight;
3813 case ContentAlignment.BottomRight: {
3814 return ContentAlignment.BottomLeft;
3818 // if it's center it doesn't change
3824 [EditorBrowsable(EditorBrowsableState.Advanced)]
3825 protected HorizontalAlignment RtlTranslateAlignment(HorizontalAlignment align) {
3826 if ((right_to_left == RightToLeft.No) || (align == HorizontalAlignment.Center)) {
3830 if (align == HorizontalAlignment.Left) {
3831 return HorizontalAlignment.Right;
3834 // align must be HorizontalAlignment.Right
3835 return HorizontalAlignment.Left;
3838 [EditorBrowsable(EditorBrowsableState.Advanced)]
3839 protected LeftRightAlignment RtlTranslateAlignment(LeftRightAlignment align) {
3840 if (right_to_left == RightToLeft.No) {
3844 if (align == LeftRightAlignment.Left) {
3845 return LeftRightAlignment.Right;
3848 // align must be LeftRightAlignment.Right;
3849 return LeftRightAlignment.Left;
3852 [EditorBrowsable(EditorBrowsableState.Advanced)]
3853 protected ContentAlignment RtlTranslateContent(ContentAlignment align) {
3854 return RtlTranslateAlignment(align);
3857 [EditorBrowsable(EditorBrowsableState.Advanced)]
3858 protected HorizontalAlignment RtlTranslateHorizontal(HorizontalAlignment align) {
3859 return RtlTranslateAlignment(align);
3862 [EditorBrowsable(EditorBrowsableState.Advanced)]
3863 protected LeftRightAlignment RtlTranslateLeftRight(LeftRightAlignment align) {
3864 return RtlTranslateAlignment(align);
3867 [EditorBrowsable(EditorBrowsableState.Advanced)]
3868 protected virtual void ScaleCore(float dx, float dy) {
3874 location = new Point((int)(Left * dx), (int)(Top * dy));
3875 size = this.ClientSize;
3877 if (!GetStyle(ControlStyles.FixedWidth)) {
3878 size.Width = (int)(size.Width * dx);
3881 if (!GetStyle(ControlStyles.FixedHeight)) {
3882 size.Height = (int)(size.Height * dy);
3885 SetBounds(location.X, location.Y, size.Width, size.Height, BoundsSpecified.All);
3887 /* Now scale our children */
3888 Control [] controls = child_controls.GetAllControls ();
3889 for (int i=0; i < controls.Length; i++) {
3890 controls[i].Scale(dx, dy);
3896 protected virtual void Select(bool directed, bool forward) {
3897 IContainerControl container;
3899 container = GetContainerControl();
3900 if (container != null)
3901 container.ActiveControl = this;
3904 [EditorBrowsable(EditorBrowsableState.Advanced)]
3905 protected virtual void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
3906 // SetBoundsCore updates the Win32 control itself. UpdateBounds updates the controls variables and fires events, I'm guessing - pdb
3907 if (IsHandleCreated) {
3908 XplatUI.SetWindowPos(Handle, x, y, width, height);
3910 // Win32 automatically changes negative width/height to 0.
3911 // The control has already been sent a WM_WINDOWPOSCHANGED message and it has the correct
3912 // data, but it'll be overwritten when we call UpdateBounds unless we get the updated
3914 if (width < 0 || height < 0) {
3916 XplatUI.GetWindowPos(Handle, this is Form, out ix, out iy, out width, out height, out cw, out ch);
3920 UpdateBounds(x, y, width, height);
3925 [EditorBrowsable(EditorBrowsableState.Advanced)]
3926 protected virtual void SetClientSizeCore(int x, int y) {
3927 // Calculate the actual window size from the client size (it usually stays the same or grows)
3928 Rectangle ClientRect;
3929 Rectangle WindowRect;
3932 ClientRect = new Rectangle(0, 0, x, y);
3933 cp = this.CreateParams;
3935 if (XplatUI.CalculateWindowRect(ref ClientRect, cp.Style, cp.ExStyle, null, out WindowRect)==false) {
3939 SetBounds(bounds.X, bounds.Y, WindowRect.Width, WindowRect.Height, BoundsSpecified.Size);
3942 [EditorBrowsable(EditorBrowsableState.Advanced)]
3943 protected internal void SetStyle(ControlStyles flag, bool value) {
3945 control_style |= flag;
3947 control_style &= ~flag;
3951 protected void SetTopLevel(bool value) {
3952 if ((GetTopLevel() != value) && (parent != null)) {
3953 throw new Exception();
3957 if (value == true) {
3967 is_toplevel = value;
3970 protected virtual void SetVisibleCore(bool value) {
3971 if (value!=is_visible) {
3972 if (value && (window.Handle == IntPtr.Zero) || !is_created) {
3978 if (IsHandleCreated) {
3979 XplatUI.SetVisible(Handle, value, true);
3980 // Explicitly move Toplevel windows to where we want them;
3981 // apparently moving unmapped toplevel windows doesn't work
3982 if (is_visible && (this is Form)) {
3983 XplatUI.SetWindowPos(window.Handle, bounds.X, bounds.Y, bounds.Width, bounds.Height);
3987 OnVisibleChanged(EventArgs.Empty);
3989 if (value == false && parent != null && Focused) {
3992 // Need to start at parent, GetContainerControl might return ourselves if we're a container
3993 container = (Control)parent.GetContainerControl();
3994 if (container != null) {
3995 container.SelectNextControl(this, true, true, true, true);
3999 if (parent != null) {
4000 parent.PerformLayout(this, "visible");
4002 PerformLayout(this, "visible");
4007 [EditorBrowsable(EditorBrowsableState.Advanced)]
4008 protected void UpdateBounds() {
4016 if (!IsHandleCreated) {
4020 XplatUI.GetWindowPos(this.Handle, this is Form, out x, out y, out width, out height, out client_width, out client_height);
4022 UpdateBounds(x, y, width, height, client_width, client_height);
4025 [EditorBrowsable(EditorBrowsableState.Advanced)]
4026 protected void UpdateBounds(int x, int y, int width, int height) {
4030 // Calculate client rectangle
4031 rect = new Rectangle(0, 0, 0, 0);
4034 XplatUI.CalculateWindowRect(ref rect, cp.Style, cp.ExStyle, cp.menu, out rect);
4035 UpdateBounds(x, y, width, height, width - (rect.Right - rect.Left), height - (rect.Bottom - rect.Top));
4038 [EditorBrowsable(EditorBrowsableState.Advanced)]
4039 protected void UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) {
4040 // UpdateBounds only seems to set our sizes and fire events but not update the GUI window to match
4042 bool resized = false;
4044 // Needed to generate required notifications
4045 if ((this.bounds.X!=x) || (this.bounds.Y!=y)) {
4049 if ((this.Bounds.Width!=width) || (this.Bounds.Height!=height)) {
4056 bounds.Height=height;
4058 // Assume explicit bounds set. SetImplicitBounds will restore old bounds
4059 explicit_bounds = bounds;
4061 client_size.Width=clientWidth;
4062 client_size.Height=clientHeight;
4065 OnLocationChanged(EventArgs.Empty);
4069 OnSizeChanged(EventArgs.Empty);
4073 [EditorBrowsable(EditorBrowsableState.Advanced)]
4074 protected void UpdateStyles() {
4075 if (!IsHandleCreated) {
4079 XplatUI.SetWindowStyle(window.Handle, CreateParams);
4080 OnStyleChanged(EventArgs.Empty);
4083 private void UpdateZOrderOfChild(Control child) {
4084 if (IsHandleCreated && child.IsHandleCreated && (child.parent == this)) {
4087 index = child_controls.IndexOf(child);
4090 XplatUI.SetZOrder(child.Handle, child_controls[index - 1].Handle, false, false);
4092 IntPtr after = AfterTopMostControl ();
4093 if (after != IntPtr.Zero)
4094 XplatUI.SetZOrder (child.Handle, after, false, false);
4096 XplatUI.SetZOrder (child.Handle, IntPtr.Zero, true, false);
4101 // Override this if there is a control that shall always remain on
4102 // top of other controls (such as scrollbars). If there are several
4103 // of these controls, the bottom-most should be returned.
4104 internal virtual IntPtr AfterTopMostControl ()
4109 private void UpdateChildrenZOrder() {
4110 Control [] controls;
4112 if (!IsHandleCreated) {
4116 controls = child_controls.GetAllControls ();
4117 for (int i = 1; i < controls.Length; i++ ) {
4118 XplatUI.SetZOrder(controls[i].Handle, controls[i-1].Handle, false, false);
4122 [EditorBrowsable(EditorBrowsableState.Advanced)]
4123 protected void UpdateZOrder() {
4124 if (parent != null) {
4125 parent.UpdateZOrderOfChild(this);
4129 protected virtual void WndProc(ref Message m) {
4131 Console.WriteLine("Control {0} received message {1}", window.Handle == IntPtr.Zero ? this.Text : XplatUI.Window(window.Handle), m.ToString ());
4133 if ((this.control_style & ControlStyles.EnableNotifyMessage) != 0) {
4137 switch((Msg)m.Msg) {
4138 case Msg.WM_DESTROY: {
4139 OnHandleDestroyed(EventArgs.Empty);
4141 IntPtr handle = window.Handle;
4143 window.InvalidateHandle();
4145 if (is_recreating) {
4147 Console.WriteLine ("Creating handle for {0:X}", handle.ToInt32());
4151 Console.WriteLine (" + new handle = {0:X}", Handle.ToInt32());
4153 is_recreating = false;
4158 case Msg.WM_WINDOWPOSCHANGED: {
4160 Rectangle save_bounds = explicit_bounds;
4162 explicit_bounds = save_bounds;
4163 if (GetStyle(ControlStyles.ResizeRedraw)) {
4170 // Nice description of what should happen when handling WM_PAINT
4171 // can be found here: http://pluralsight.com/wiki/default.aspx/Craig/FlickerFreeControlDrawing.html
4172 // and here http://msdn.microsoft.com/msdnmag/issues/06/03/WindowsFormsPerformance/
4173 case Msg.WM_PAINT: {
4174 PaintEventArgs paint_event;
4176 paint_event = XplatUI.PaintEventStart(Handle, true);
4178 if (paint_event == null) {
4182 if (invalid_region != null && !invalid_region.IsVisible (paint_event.ClipRectangle)) {
4184 // Just blit the previous image
4185 XplatUI.BlitFromOffscreen (Handle, paint_event.Graphics, backbuffer, backbuffer_dc, paint_event.ClipRectangle);
4186 XplatUI.PaintEventEnd (Handle, true);
4191 Graphics back_dc = null;
4193 if (ThemeEngine.Current.DoubleBufferingSupported) {
4194 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
4195 CreateBackBuffer ();
4197 back_dc = backbuffer_dc;
4198 dc = paint_event.SetGraphics (back_dc);
4202 if (!GetStyle(ControlStyles.Opaque)) {
4203 OnPaintBackground(paint_event);
4206 // Button-derived controls choose to ignore their Opaque style, give them a chance to draw their background anyways
4207 OnPaintBackgroundInternal(paint_event);
4209 OnPaintInternal(paint_event);
4210 if (!paint_event.Handled) {
4211 OnPaint(paint_event);
4214 if (ThemeEngine.Current.DoubleBufferingSupported)
4215 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
4216 XplatUI.BlitFromOffscreen (Handle, dc, back, back_dc, paint_event.ClipRectangle);
4217 paint_event.SetGraphics (dc);
4218 invalid_region.Exclude (paint_event.ClipRectangle);
4220 if (back != backbuffer)
4221 XplatUI.DestroyOffscreenDrawable (back, back_dc);
4224 XplatUI.PaintEventEnd(Handle, true);
4229 case Msg.WM_ERASEBKGND: {
4230 // The DefWndProc will never have to handle this, we always paint the background in managed code
4231 // In theory this code would look at ControlStyles.AllPaintingInWmPaint and and call OnPaintBackground
4232 // here but it just makes things more complicated...
4233 m.Result = (IntPtr)1;
4237 case Msg.WM_LBUTTONUP: {
4240 me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Left,
4242 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4245 HandleClick(mouse_clicks, me);
4248 if (InternalCapture) {
4249 InternalCapture = false;
4252 if (mouse_clicks > 1) {
4258 case Msg.WM_LBUTTONDOWN: {
4260 Select (true, true);
4262 InternalCapture = true;
4263 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4264 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4270 case Msg.WM_LBUTTONDBLCLK: {
4271 InternalCapture = true;
4273 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4274 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4279 case Msg.WM_MBUTTONUP: {
4282 me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Middle,
4284 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4287 HandleClick(mouse_clicks, me);
4289 if (InternalCapture) {
4290 InternalCapture = false;
4292 if (mouse_clicks > 1) {
4298 case Msg.WM_MBUTTONDOWN: {
4299 InternalCapture = true;
4300 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4301 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4306 case Msg.WM_MBUTTONDBLCLK: {
4307 InternalCapture = true;
4309 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4310 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4315 case Msg.WM_RBUTTONUP: {
4319 pt = new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()));
4320 pt = PointToScreen(pt);
4322 XplatUI.SendMessage(m.HWnd, Msg.WM_CONTEXTMENU, m.HWnd, (IntPtr)(pt.X + (pt.Y << 16)));
4324 me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Right,
4326 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4329 HandleClick(mouse_clicks, me);
4332 if (InternalCapture) {
4333 InternalCapture = false;
4336 if (mouse_clicks > 1) {
4342 case Msg.WM_RBUTTONDOWN: {
4343 InternalCapture = true;
4344 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4345 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4350 case Msg.WM_RBUTTONDBLCLK: {
4351 InternalCapture = true;
4353 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4354 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4359 case Msg.WM_CONTEXTMENU: {
4360 if (context_menu != null) {
4363 pt = new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()));
4364 context_menu.Show(this, PointToClient(pt));
4372 case Msg.WM_MOUSEWHEEL: {
4374 OnMouseWheel (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4375 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4376 HighOrder(m.WParam.ToInt32())));
4381 case Msg.WM_MOUSEMOVE: {
4382 OnMouseMove (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4384 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4389 case Msg.WM_MOUSE_ENTER: {
4394 OnMouseEnter(EventArgs.Empty);
4398 case Msg.WM_MOUSE_LEAVE: {
4400 OnMouseLeave(EventArgs.Empty);
4404 case Msg.WM_MOUSEHOVER: {
4405 OnMouseHover(EventArgs.Empty);
4409 case Msg.WM_SYSKEYUP: {
4410 if (ProcessKeyMessage(ref m)) {
4411 m.Result = IntPtr.Zero;
4415 if ((m.WParam.ToInt32() & (int)Keys.KeyCode) == (int)Keys.Menu) {
4419 if (form != null && form.ActiveMenu != null) {
4420 form.ActiveMenu.ProcessCmdKey(ref m, (Keys)m.WParam.ToInt32());
4428 case Msg.WM_SYSKEYDOWN:
4429 case Msg.WM_KEYDOWN:
4431 case Msg.WM_SYSCHAR:
4433 if (ProcessKeyMessage(ref m)) {
4434 m.Result = IntPtr.Zero;
4443 if (m.LParam != IntPtr.Zero) {
4446 hi = new HELPINFO();
4448 hi = (HELPINFO) Marshal.PtrToStructure (m.LParam, typeof (HELPINFO));
4449 mouse_pos = new Point(hi.MousePos.x, hi.MousePos.y);
4451 mouse_pos = Control.MousePosition;
4453 OnHelpRequested(new HelpEventArgs(mouse_pos));
4454 m.Result = (IntPtr)1;
4458 case Msg.WM_KILLFOCUS: {
4459 this.has_focus = false;
4460 OnLostFocusInternal (EventArgs.Empty);
4464 case Msg.WM_SETFOCUS: {
4466 this.has_focus = true;
4467 OnGotFocusInternal (EventArgs.Empty);
4472 case Msg.WM_SYSCOLORCHANGE: {
4473 ThemeEngine.Current.ResetDefaults();
4474 OnSystemColorsChanged(EventArgs.Empty);
4478 case Msg.WM_SETCURSOR: {
4479 if ((cursor == null) || ((HitTest)(m.LParam.ToInt32() & 0xffff) != HitTest.HTCLIENT)) {
4484 XplatUI.SetCursor(window.Handle, cursor.handle);
4485 m.Result = (IntPtr)1;
4495 #endregion // Public Instance Methods
4497 #region OnXXX methods
4498 [EditorBrowsable(EditorBrowsableState.Advanced)]
4499 protected virtual void OnBackColorChanged(EventArgs e) {
4500 EventHandler eh = (EventHandler)(Events [BackColorChangedEvent]);
4503 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackColorChanged(e);
4506 [EditorBrowsable(EditorBrowsableState.Advanced)]
4507 protected virtual void OnBackgroundImageChanged(EventArgs e) {
4508 EventHandler eh = (EventHandler)(Events [BackgroundImageChangedEvent]);
4511 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackgroundImageChanged(e);
4514 [EditorBrowsable(EditorBrowsableState.Advanced)]
4515 protected virtual void OnBindingContextChanged(EventArgs e) {
4516 CheckDataBindings ();
4517 EventHandler eh = (EventHandler)(Events [BindingContextChangedEvent]);
4520 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBindingContextChanged(e);
4523 [EditorBrowsable(EditorBrowsableState.Advanced)]
4524 protected virtual void OnCausesValidationChanged(EventArgs e) {
4525 EventHandler eh = (EventHandler)(Events [CausesValidationChangedEvent]);
4530 [EditorBrowsable(EditorBrowsableState.Advanced)]
4531 protected virtual void OnChangeUICues(UICuesEventArgs e) {
4532 UICuesEventHandler eh = (UICuesEventHandler)(Events [ChangeUICuesEvent]);
4537 [EditorBrowsable(EditorBrowsableState.Advanced)]
4538 protected virtual void OnClick(EventArgs e) {
4539 EventHandler eh = (EventHandler)(Events [ClickEvent]);
4544 [EditorBrowsable(EditorBrowsableState.Advanced)]
4545 protected virtual void OnContextMenuChanged(EventArgs e) {
4546 EventHandler eh = (EventHandler)(Events [ContextMenuChangedEvent]);
4551 [EditorBrowsable(EditorBrowsableState.Advanced)]
4552 protected virtual void OnControlAdded(ControlEventArgs e) {
4553 ControlEventHandler eh = (ControlEventHandler)(Events [ControlAddedEvent]);
4558 [EditorBrowsable(EditorBrowsableState.Advanced)]
4559 protected virtual void OnControlRemoved(ControlEventArgs e) {
4560 ControlEventHandler eh = (ControlEventHandler)(Events [ControlRemovedEvent]);
4565 [EditorBrowsable(EditorBrowsableState.Advanced)]
4566 protected virtual void OnCreateControl() {
4570 [EditorBrowsable(EditorBrowsableState.Advanced)]
4571 protected virtual void OnCursorChanged(EventArgs e) {
4572 EventHandler eh = (EventHandler)(Events [CursorChangedEvent]);
4577 [EditorBrowsable(EditorBrowsableState.Advanced)]
4578 protected virtual void OnDockChanged(EventArgs e) {
4579 EventHandler eh = (EventHandler)(Events [DockChangedEvent]);
4584 [EditorBrowsable(EditorBrowsableState.Advanced)]
4585 protected virtual void OnDoubleClick(EventArgs e) {
4586 EventHandler eh = (EventHandler)(Events [DoubleClickEvent]);
4591 [EditorBrowsable(EditorBrowsableState.Advanced)]
4592 protected virtual void OnDragDrop(DragEventArgs drgevent) {
4593 DragEventHandler eh = (DragEventHandler)(Events [DragDropEvent]);
4595 eh (this, drgevent);
4598 [EditorBrowsable(EditorBrowsableState.Advanced)]
4599 protected virtual void OnDragEnter(DragEventArgs drgevent) {
4600 DragEventHandler eh = (DragEventHandler)(Events [DragEnterEvent]);
4602 eh (this, drgevent);
4605 [EditorBrowsable(EditorBrowsableState.Advanced)]
4606 protected virtual void OnDragLeave(EventArgs e) {
4607 EventHandler eh = (EventHandler)(Events [DragLeaveEvent]);
4612 [EditorBrowsable(EditorBrowsableState.Advanced)]
4613 protected virtual void OnDragOver(DragEventArgs drgevent) {
4614 DragEventHandler eh = (DragEventHandler)(Events [DragOverEvent]);
4616 eh (this, drgevent);
4619 [EditorBrowsable(EditorBrowsableState.Advanced)]
4620 protected virtual void OnEnabledChanged(EventArgs e) {
4621 if (IsHandleCreated) {
4623 if (((Form)this).context == null) {
4624 XplatUI.EnableWindow(window.Handle, Enabled);
4627 XplatUI.EnableWindow(window.Handle, Enabled);
4632 EventHandler eh = (EventHandler)(Events [EnabledChangedEvent]);
4636 for (int i=0; i<child_controls.Count; i++) {
4637 child_controls[i].OnParentEnabledChanged(e);
4641 [EditorBrowsable(EditorBrowsableState.Advanced)]
4642 protected virtual void OnEnter(EventArgs e) {
4643 EventHandler eh = (EventHandler)(Events [EnterEvent]);
4648 [EditorBrowsable(EditorBrowsableState.Advanced)]
4649 protected virtual void OnFontChanged(EventArgs e) {
4650 EventHandler eh = (EventHandler)(Events [FontChangedEvent]);
4653 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentFontChanged(e);
4656 [EditorBrowsable(EditorBrowsableState.Advanced)]
4657 protected virtual void OnForeColorChanged(EventArgs e) {
4658 EventHandler eh = (EventHandler)(Events [ForeColorChangedEvent]);
4661 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentForeColorChanged(e);
4664 [EditorBrowsable(EditorBrowsableState.Advanced)]
4665 protected virtual void OnGiveFeedback(GiveFeedbackEventArgs gfbevent) {
4666 GiveFeedbackEventHandler eh = (GiveFeedbackEventHandler)(Events [GiveFeedbackEvent]);
4668 eh (this, gfbevent);
4671 [EditorBrowsable(EditorBrowsableState.Advanced)]
4672 protected virtual void OnGotFocus(EventArgs e) {
4673 EventHandler eh = (EventHandler)(Events [GotFocusEvent]);
4678 [EditorBrowsable(EditorBrowsableState.Advanced)]
4679 protected virtual void OnHandleCreated(EventArgs e) {
4680 EventHandler eh = (EventHandler)(Events [HandleCreatedEvent]);
4685 [EditorBrowsable(EditorBrowsableState.Advanced)]
4686 protected virtual void OnHandleDestroyed(EventArgs e) {
4687 EventHandler eh = (EventHandler)(Events [HandleDestroyedEvent]);
4692 [EditorBrowsable(EditorBrowsableState.Advanced)]
4693 protected virtual void OnHelpRequested(HelpEventArgs hevent) {
4694 HelpEventHandler eh = (HelpEventHandler)(Events [HelpRequestedEvent]);
4699 protected virtual void OnImeModeChanged(EventArgs e) {
4700 EventHandler eh = (EventHandler)(Events [ImeModeChangedEvent]);
4705 [EditorBrowsable(EditorBrowsableState.Advanced)]
4706 protected virtual void OnInvalidated(InvalidateEventArgs e) {
4707 if (ThemeEngine.Current.DoubleBufferingSupported)
4708 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
4709 // should this block be here? seems like it
4710 // would be more at home in
4711 // NotifyInvalidated..
4712 if (e.InvalidRect == ClientRectangle) {
4713 InvalidateBackBuffer ();
4716 // we need this Inflate call here so
4717 // that the border of the rectangle is
4718 // considered Visible (the
4719 // invalid_region.IsVisible call) in
4720 // the WM_PAINT handling below.
4721 Rectangle r = Rectangle.Inflate(e.InvalidRect, 1,1);
4722 if (invalid_region == null)
4723 invalid_region = new Region (r);
4725 invalid_region.Union (r);
4729 InvalidateEventHandler eh = (InvalidateEventHandler)(Events [InvalidatedEvent]);
4734 [EditorBrowsable(EditorBrowsableState.Advanced)]
4735 protected virtual void OnKeyDown(KeyEventArgs e) {
4736 KeyEventHandler eh = (KeyEventHandler)(Events [KeyDownEvent]);
4741 [EditorBrowsable(EditorBrowsableState.Advanced)]
4742 protected virtual void OnKeyPress(KeyPressEventArgs e) {
4743 KeyPressEventHandler eh = (KeyPressEventHandler)(Events [KeyPressEvent]);
4748 [EditorBrowsable(EditorBrowsableState.Advanced)]
4749 protected virtual void OnKeyUp(KeyEventArgs e) {
4750 KeyEventHandler eh = (KeyEventHandler)(Events [KeyUpEvent]);
4755 [EditorBrowsable(EditorBrowsableState.Advanced)]
4756 protected virtual void OnLayout(LayoutEventArgs levent) {
4757 LayoutEventHandler eh = (LayoutEventHandler)(Events [LayoutEvent]);
4762 [EditorBrowsable(EditorBrowsableState.Advanced)]
4763 protected virtual void OnLeave(EventArgs e) {
4764 EventHandler eh = (EventHandler)(Events [LeaveEvent]);
4769 [EditorBrowsable(EditorBrowsableState.Advanced)]
4770 protected virtual void OnLocationChanged(EventArgs e) {
4772 EventHandler eh = (EventHandler)(Events [LocationChangedEvent]);
4777 [EditorBrowsable(EditorBrowsableState.Advanced)]
4778 protected virtual void OnLostFocus(EventArgs e) {
4779 EventHandler eh = (EventHandler)(Events [LostFocusEvent]);
4784 [EditorBrowsable(EditorBrowsableState.Advanced)]
4785 protected virtual void OnMouseDown(MouseEventArgs e) {
4786 MouseEventHandler eh = (MouseEventHandler)(Events [MouseDownEvent]);
4791 [EditorBrowsable(EditorBrowsableState.Advanced)]
4792 protected virtual void OnMouseEnter(EventArgs e) {
4793 EventHandler eh = (EventHandler)(Events [MouseEnterEvent]);
4798 [EditorBrowsable(EditorBrowsableState.Advanced)]
4799 protected virtual void OnMouseHover(EventArgs e) {
4800 EventHandler eh = (EventHandler)(Events [MouseHoverEvent]);
4805 [EditorBrowsable(EditorBrowsableState.Advanced)]
4806 protected virtual void OnMouseLeave(EventArgs e) {
4807 EventHandler eh = (EventHandler)(Events [MouseLeaveEvent]);
4812 [EditorBrowsable(EditorBrowsableState.Advanced)]
4813 protected virtual void OnMouseMove(MouseEventArgs e) {
4814 MouseEventHandler eh = (MouseEventHandler)(Events [MouseMoveEvent]);
4819 [EditorBrowsable(EditorBrowsableState.Advanced)]
4820 protected virtual void OnMouseUp(MouseEventArgs e) {
4821 MouseEventHandler eh = (MouseEventHandler)(Events [MouseUpEvent]);
4826 [EditorBrowsable(EditorBrowsableState.Advanced)]
4827 protected virtual void OnMouseWheel(MouseEventArgs e) {
4828 MouseEventHandler eh = (MouseEventHandler)(Events [MouseWheelEvent]);
4833 [EditorBrowsable(EditorBrowsableState.Advanced)]
4834 protected virtual void OnMove(EventArgs e) {
4835 EventHandler eh = (EventHandler)(Events [MoveEvent]);
4840 [EditorBrowsable(EditorBrowsableState.Advanced)]
4841 protected virtual void OnNotifyMessage(Message m) {
4846 protected virtual void OnPaddingChanged (EventArgs e) {
4847 EventHandler eh = (EventHandler) (Events [PaddingChangedEvent]);
4853 [EditorBrowsable(EditorBrowsableState.Advanced)]
4854 protected virtual void OnPaint(PaintEventArgs e) {
4855 PaintEventHandler eh = (PaintEventHandler)(Events [PaintEvent]);
4860 internal virtual void OnPaintBackgroundInternal(PaintEventArgs e) {
4864 internal virtual void OnPaintInternal(PaintEventArgs e) {
4868 internal virtual void OnGotFocusInternal (EventArgs e)
4873 internal virtual void OnLostFocusInternal (EventArgs e)
4878 [EditorBrowsable(EditorBrowsableState.Advanced)]
4879 protected virtual void OnPaintBackground(PaintEventArgs pevent) {
4880 PaintControlBackground (pevent);
4883 [EditorBrowsable(EditorBrowsableState.Advanced)]
4884 protected virtual void OnParentBackColorChanged(EventArgs e) {
4885 if (background_color.IsEmpty && background_image==null) {
4887 OnBackColorChanged(e);
4891 [EditorBrowsable(EditorBrowsableState.Advanced)]
4892 protected virtual void OnParentBackgroundImageChanged(EventArgs e) {
4893 if (background_color.IsEmpty && background_image==null) {
4895 OnBackgroundImageChanged(e);
4899 [EditorBrowsable(EditorBrowsableState.Advanced)]
4900 protected virtual void OnParentBindingContextChanged(EventArgs e) {
4901 if (binding_context==null) {
4902 binding_context=Parent.binding_context;
4903 OnBindingContextChanged(e);
4907 [EditorBrowsable(EditorBrowsableState.Advanced)]
4908 protected virtual void OnParentChanged(EventArgs e) {
4909 EventHandler eh = (EventHandler)(Events [ParentChangedEvent]);
4914 [EditorBrowsable(EditorBrowsableState.Advanced)]
4915 protected virtual void OnParentEnabledChanged(EventArgs e) {
4917 OnEnabledChanged(e);
4921 [EditorBrowsable(EditorBrowsableState.Advanced)]
4922 protected virtual void OnParentFontChanged(EventArgs e) {
4929 [EditorBrowsable(EditorBrowsableState.Advanced)]
4930 protected virtual void OnParentForeColorChanged(EventArgs e) {
4931 if (foreground_color.IsEmpty) {
4933 OnForeColorChanged(e);
4937 [EditorBrowsable(EditorBrowsableState.Advanced)]
4938 protected virtual void OnParentRightToLeftChanged(EventArgs e) {
4939 if (right_to_left==RightToLeft.Inherit) {
4941 OnRightToLeftChanged(e);
4945 [EditorBrowsable(EditorBrowsableState.Advanced)]
4946 protected virtual void OnParentVisibleChanged(EventArgs e) {
4948 OnVisibleChanged(e);
4952 [EditorBrowsable(EditorBrowsableState.Advanced)]
4953 protected virtual void OnQueryContinueDrag(QueryContinueDragEventArgs e) {
4954 QueryContinueDragEventHandler eh = (QueryContinueDragEventHandler)(Events [QueryContinueDragEvent]);
4959 [EditorBrowsable(EditorBrowsableState.Advanced)]
4960 protected virtual void OnResize(EventArgs e) {
4961 EventHandler eh = (EventHandler)(Events [ResizeEvent]);
4965 PerformLayout(this, "bounds");
4967 if (parent != null) {
4968 parent.PerformLayout();
4972 [EditorBrowsable(EditorBrowsableState.Advanced)]
4973 protected virtual void OnRightToLeftChanged(EventArgs e) {
4974 EventHandler eh = (EventHandler)(Events [RightToLeftChangedEvent]);
4977 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentRightToLeftChanged(e);
4980 [EditorBrowsable(EditorBrowsableState.Advanced)]
4981 protected virtual void OnSizeChanged(EventArgs e) {
4982 DisposeBackBuffer ();
4984 EventHandler eh = (EventHandler)(Events [SizeChangedEvent]);
4989 [EditorBrowsable(EditorBrowsableState.Advanced)]
4990 protected virtual void OnStyleChanged(EventArgs e) {
4991 EventHandler eh = (EventHandler)(Events [StyleChangedEvent]);
4996 [EditorBrowsable(EditorBrowsableState.Advanced)]
4997 protected virtual void OnSystemColorsChanged(EventArgs e) {
4998 EventHandler eh = (EventHandler)(Events [SystemColorsChangedEvent]);
5003 [EditorBrowsable(EditorBrowsableState.Advanced)]
5004 protected virtual void OnTabIndexChanged(EventArgs e) {
5005 EventHandler eh = (EventHandler)(Events [TabIndexChangedEvent]);
5010 [EditorBrowsable(EditorBrowsableState.Advanced)]
5011 protected virtual void OnTabStopChanged(EventArgs e) {
5012 EventHandler eh = (EventHandler)(Events [TabStopChangedEvent]);
5017 [EditorBrowsable(EditorBrowsableState.Advanced)]
5018 protected virtual void OnTextChanged(EventArgs e) {
5019 EventHandler eh = (EventHandler)(Events [TextChangedEvent]);
5024 [EditorBrowsable(EditorBrowsableState.Advanced)]
5025 protected virtual void OnValidated(EventArgs e) {
5026 EventHandler eh = (EventHandler)(Events [ValidatedEvent]);
5031 [EditorBrowsable(EditorBrowsableState.Advanced)]
5032 protected virtual void OnValidating(System.ComponentModel.CancelEventArgs e) {
5033 CancelEventHandler eh = (CancelEventHandler)(Events [ValidatingEvent]);
5038 [EditorBrowsable(EditorBrowsableState.Advanced)]
5039 protected virtual void OnVisibleChanged(EventArgs e) {
5040 if ((parent != null) && !Created && Visible) {
5047 EventHandler eh = (EventHandler)(Events [VisibleChangedEvent]);
5051 // We need to tell our kids
5052 for (int i=0; i<child_controls.Count; i++) {
5053 if (child_controls[i].Visible) {
5054 child_controls[i].OnParentVisibleChanged(e);
5058 #endregion // OnXXX methods
5061 static object BackColorChangedEvent = new object ();
5062 static object BackgroundImageChangedEvent = new object ();
5064 static object BackgroundImageLayoutChangedEvent = new object ();
5066 static object BindingContextChangedEvent = new object ();
5067 static object CausesValidationChangedEvent = new object ();
5068 static object ChangeUICuesEvent = new object ();
5069 static object ClickEvent = new object ();
5070 static object ContextMenuChangedEvent = new object ();
5071 static object ControlAddedEvent = new object ();
5072 static object ControlRemovedEvent = new object ();
5073 static object CursorChangedEvent = new object ();
5074 static object DockChangedEvent = new object ();
5075 static object DoubleClickEvent = new object ();
5076 static object DragDropEvent = new object ();
5077 static object DragEnterEvent = new object ();
5078 static object DragLeaveEvent = new object ();
5079 static object DragOverEvent = new object ();
5080 static object EnabledChangedEvent = new object ();
5081 static object EnterEvent = new object ();
5082 static object FontChangedEvent = new object ();
5083 static object ForeColorChangedEvent = new object ();
5084 static object GiveFeedbackEvent = new object ();
5085 static object GotFocusEvent = new object ();
5086 static object HandleCreatedEvent = new object ();
5087 static object HandleDestroyedEvent = new object ();
5088 static object HelpRequestedEvent = new object ();
5089 static object ImeModeChangedEvent = new object ();
5090 static object InvalidatedEvent = new object ();
5091 static object KeyDownEvent = new object ();
5092 static object KeyPressEvent = new object ();
5093 static object KeyUpEvent = new object ();
5094 static object LayoutEvent = new object ();
5095 static object LeaveEvent = new object ();
5096 static object LocationChangedEvent = new object ();
5097 static object LostFocusEvent = new object ();
5099 static object MouseClickEvent = new object ();
5100 static object MouseDoubleClickEvent = new object ();
5102 static object MouseDownEvent = new object ();
5103 static object MouseEnterEvent = new object ();
5104 static object MouseHoverEvent = new object ();
5105 static object MouseLeaveEvent = new object ();
5106 static object MouseMoveEvent = new object ();
5107 static object MouseUpEvent = new object ();
5108 static object MouseWheelEvent = new object ();
5109 static object MoveEvent = new object ();
5111 static object PaddingChangedEvent = new object ();
5113 static object PaintEvent = new object ();
5114 static object ParentChangedEvent = new object ();
5115 static object QueryAccessibilityHelpEvent = new object ();
5116 static object QueryContinueDragEvent = new object ();
5117 static object ResizeEvent = new object ();
5118 static object RightToLeftChangedEvent = new object ();
5119 static object SizeChangedEvent = new object ();
5120 static object StyleChangedEvent = new object ();
5121 static object SystemColorsChangedEvent = new object ();
5122 static object TabIndexChangedEvent = new object ();
5123 static object TabStopChangedEvent = new object ();
5124 static object TextChangedEvent = new object ();
5125 static object ValidatedEvent = new object ();
5126 static object ValidatingEvent = new object ();
5127 static object VisibleChangedEvent = new object ();
5129 public event EventHandler BackColorChanged {
5130 add { Events.AddHandler (BackColorChangedEvent, value); }
5131 remove { Events.RemoveHandler (BackColorChangedEvent, value); }
5134 public event EventHandler BackgroundImageChanged {
5135 add { Events.AddHandler (BackgroundImageChangedEvent, value); }
5136 remove { Events.RemoveHandler (BackgroundImageChangedEvent, value); }
5140 public event EventHandler BackgroundImageLayoutChanged {
5141 add {Events.AddHandler (BackgroundImageLayoutChangedEvent, value);}
5142 remove {Events.RemoveHandler (BackgroundImageLayoutChangedEvent, value);}
5146 public event EventHandler BindingContextChanged {
5147 add { Events.AddHandler (BindingContextChangedEvent, value); }
5148 remove { Events.RemoveHandler (BindingContextChangedEvent, value); }
5151 public event EventHandler CausesValidationChanged {
5152 add { Events.AddHandler (CausesValidationChangedEvent, value); }
5153 remove { Events.RemoveHandler (CausesValidationChangedEvent, value); }
5156 public event UICuesEventHandler ChangeUICues {
5157 add { Events.AddHandler (ChangeUICuesEvent, value); }
5158 remove { Events.RemoveHandler (ChangeUICuesEvent, value); }
5161 public event EventHandler Click {
5162 add { Events.AddHandler (ClickEvent, value); }
5163 remove { Events.RemoveHandler (ClickEvent, value); }
5168 public event EventHandler ContextMenuChanged {
5169 add { Events.AddHandler (ContextMenuChangedEvent, value); }
5170 remove { Events.RemoveHandler (ContextMenuChangedEvent, value); }
5173 [EditorBrowsable(EditorBrowsableState.Advanced)]
5179 public event ControlEventHandler ControlAdded {
5180 add { Events.AddHandler (ControlAddedEvent, value); }
5181 remove { Events.RemoveHandler (ControlAddedEvent, value); }
5184 [EditorBrowsable(EditorBrowsableState.Advanced)]
5190 public event ControlEventHandler ControlRemoved {
5191 add { Events.AddHandler (ControlRemovedEvent, value); }
5192 remove { Events.RemoveHandler (ControlRemovedEvent, value); }
5195 [MWFDescription("Fired when the cursor for the control has been changed"), MWFCategory("PropertyChanged")]
5196 public event EventHandler CursorChanged {
5197 add { Events.AddHandler (CursorChangedEvent, value); }
5198 remove { Events.RemoveHandler (CursorChangedEvent, value); }
5200 public event EventHandler DockChanged {
5201 add { Events.AddHandler (DockChangedEvent, value); }
5202 remove { Events.RemoveHandler (DockChangedEvent, value); }
5205 public event EventHandler DoubleClick {
5206 add { Events.AddHandler (DoubleClickEvent, value); }
5207 remove { Events.RemoveHandler (DoubleClickEvent, value); }
5210 public event DragEventHandler DragDrop {
5211 add { Events.AddHandler (DragDropEvent, value); }
5212 remove { Events.RemoveHandler (DragDropEvent, value); }
5215 public event DragEventHandler DragEnter {
5216 add { Events.AddHandler (DragEnterEvent, value); }
5217 remove { Events.RemoveHandler (DragEnterEvent, value); }
5220 public event EventHandler DragLeave {
5221 add { Events.AddHandler (DragLeaveEvent, value); }
5222 remove { Events.RemoveHandler (DragLeaveEvent, value); }
5225 public event DragEventHandler DragOver {
5226 add { Events.AddHandler (DragOverEvent, value); }
5227 remove { Events.RemoveHandler (DragOverEvent, value); }
5230 public event EventHandler EnabledChanged {
5231 add { Events.AddHandler (EnabledChangedEvent, value); }
5232 remove { Events.RemoveHandler (EnabledChangedEvent, value); }
5235 public event EventHandler Enter {
5236 add { Events.AddHandler (EnterEvent, value); }
5237 remove { Events.RemoveHandler (EnterEvent, value); }
5240 public event EventHandler FontChanged {
5241 add { Events.AddHandler (FontChangedEvent, value); }
5242 remove { Events.RemoveHandler (FontChangedEvent, value); }
5245 public event EventHandler ForeColorChanged {
5246 add { Events.AddHandler (ForeColorChangedEvent, value); }
5247 remove { Events.RemoveHandler (ForeColorChangedEvent, value); }
5250 public event GiveFeedbackEventHandler GiveFeedback {
5251 add { Events.AddHandler (GiveFeedbackEvent, value); }
5252 remove { Events.RemoveHandler (GiveFeedbackEvent, value); }
5255 [EditorBrowsable(EditorBrowsableState.Advanced)]
5257 public event EventHandler GotFocus {
5258 add { Events.AddHandler (GotFocusEvent, value); }
5259 remove { Events.RemoveHandler (GotFocusEvent, value); }
5263 [EditorBrowsable(EditorBrowsableState.Advanced)]
5265 public event EventHandler HandleCreated {
5266 add { Events.AddHandler (HandleCreatedEvent, value); }
5267 remove { Events.RemoveHandler (HandleCreatedEvent, value); }
5270 [EditorBrowsable(EditorBrowsableState.Advanced)]
5272 public event EventHandler HandleDestroyed {
5273 add { Events.AddHandler (HandleDestroyedEvent, value); }
5274 remove { Events.RemoveHandler (HandleDestroyedEvent, value); }
5277 public event HelpEventHandler HelpRequested {
5278 add { Events.AddHandler (HelpRequestedEvent, value); }
5279 remove { Events.RemoveHandler (HelpRequestedEvent, value); }
5282 public event EventHandler ImeModeChanged {
5283 add { Events.AddHandler (ImeModeChangedEvent, value); }
5284 remove { Events.RemoveHandler (ImeModeChangedEvent, value); }
5287 [EditorBrowsable(EditorBrowsableState.Advanced)]
5289 public event InvalidateEventHandler Invalidated {
5290 add { Events.AddHandler (InvalidatedEvent, value); }
5291 remove { Events.RemoveHandler (InvalidatedEvent, value); }
5294 public event KeyEventHandler KeyDown {
5295 add { Events.AddHandler (KeyDownEvent, value); }
5296 remove { Events.RemoveHandler (KeyDownEvent, value); }
5299 public event KeyPressEventHandler KeyPress {
5300 add { Events.AddHandler (KeyPressEvent, value); }
5301 remove { Events.RemoveHandler (KeyPressEvent, value); }
5304 public event KeyEventHandler KeyUp {
5305 add { Events.AddHandler (KeyUpEvent, value); }
5306 remove { Events.RemoveHandler (KeyUpEvent, value); }
5309 public event LayoutEventHandler Layout {
5310 add { Events.AddHandler (LayoutEvent, value); }
5311 remove { Events.RemoveHandler (LayoutEvent, value); }
5314 public event EventHandler Leave {
5315 add { Events.AddHandler (LeaveEvent, value); }
5316 remove { Events.RemoveHandler (LeaveEvent, value); }
5319 public event EventHandler LocationChanged {
5320 add { Events.AddHandler (LocationChangedEvent, value); }
5321 remove { Events.RemoveHandler (LocationChangedEvent, value); }
5324 [EditorBrowsable(EditorBrowsableState.Advanced)]
5326 public event EventHandler LostFocus {
5327 add { Events.AddHandler (LostFocusEvent, value); }
5328 remove { Events.RemoveHandler (LostFocusEvent, value); }
5332 public event MouseEventHandler MouseClick
5334 add { Events.AddHandler (MouseClickEvent, value); }
5335 remove { Events.RemoveHandler (MouseClickEvent, value); }
5337 public event MouseEventHandler MouseDoubleClick
5339 add { Events.AddHandler (MouseDoubleClickEvent, value); }
5340 remove { Events.RemoveHandler (MouseDoubleClickEvent, value); }
5343 public event MouseEventHandler MouseDown {
5344 add { Events.AddHandler (MouseDownEvent, value); }
5345 remove { Events.RemoveHandler (MouseDownEvent, value); }
5348 public event EventHandler MouseEnter {
5349 add { Events.AddHandler (MouseEnterEvent, value); }
5350 remove { Events.RemoveHandler (MouseEnterEvent, value); }
5353 public event EventHandler MouseHover {
5354 add { Events.AddHandler (MouseHoverEvent, value); }
5355 remove { Events.RemoveHandler (MouseHoverEvent, value); }
5358 public event EventHandler MouseLeave {
5359 add { Events.AddHandler (MouseLeaveEvent, value); }
5360 remove { Events.RemoveHandler (MouseLeaveEvent, value); }
5363 public event MouseEventHandler MouseMove {
5364 add { Events.AddHandler (MouseMoveEvent, value); }
5365 remove { Events.RemoveHandler (MouseMoveEvent, value); }
5368 public event MouseEventHandler MouseUp {
5369 add { Events.AddHandler (MouseUpEvent, value); }
5370 remove { Events.RemoveHandler (MouseUpEvent, value); }
5373 [EditorBrowsable(EditorBrowsableState.Advanced)]
5375 public event MouseEventHandler MouseWheel {
5376 add { Events.AddHandler (MouseWheelEvent, value); }
5377 remove { Events.RemoveHandler (MouseWheelEvent, value); }
5380 public event EventHandler Move {
5381 add { Events.AddHandler (MoveEvent, value); }
5382 remove { Events.RemoveHandler (MoveEvent, value); }
5385 public event EventHandler PaddingChanged
5387 add { Events.AddHandler (PaddingChangedEvent, value); }
5388 remove { Events.RemoveHandler (PaddingChangedEvent, value); }
5391 public event PaintEventHandler Paint {
5392 add { Events.AddHandler (PaintEvent, value); }
5393 remove { Events.RemoveHandler (PaintEvent, value); }
5396 public event EventHandler ParentChanged {
5397 add { Events.AddHandler (ParentChangedEvent, value); }
5398 remove { Events.RemoveHandler (ParentChangedEvent, value); }
5401 public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp {
5402 add { Events.AddHandler (QueryAccessibilityHelpEvent, value); }
5403 remove { Events.RemoveHandler (QueryAccessibilityHelpEvent, value); }
5406 public event QueryContinueDragEventHandler QueryContinueDrag {
5407 add { Events.AddHandler (QueryContinueDragEvent, value); }
5408 remove { Events.RemoveHandler (QueryContinueDragEvent, value); }
5412 [EditorBrowsable (EditorBrowsableState.Advanced)]
5414 public event EventHandler Resize {
5415 add { Events.AddHandler (ResizeEvent, value); }
5416 remove { Events.RemoveHandler (ResizeEvent, value); }
5419 public event EventHandler RightToLeftChanged {
5420 add { Events.AddHandler (RightToLeftChangedEvent, value); }
5421 remove { Events.RemoveHandler (RightToLeftChangedEvent, value); }
5424 public event EventHandler SizeChanged {
5425 add { Events.AddHandler (SizeChangedEvent, value); }
5426 remove { Events.RemoveHandler (SizeChangedEvent, value); }
5429 public event EventHandler StyleChanged {
5430 add { Events.AddHandler (StyleChangedEvent, value); }
5431 remove { Events.RemoveHandler (StyleChangedEvent, value); }
5434 public event EventHandler SystemColorsChanged {
5435 add { Events.AddHandler (SystemColorsChangedEvent, value); }
5436 remove { Events.RemoveHandler (SystemColorsChangedEvent, value); }
5439 public event EventHandler TabIndexChanged {
5440 add { Events.AddHandler (TabIndexChangedEvent, value); }
5441 remove { Events.RemoveHandler (TabIndexChangedEvent, value); }
5444 public event EventHandler TabStopChanged {
5445 add { Events.AddHandler (TabStopChangedEvent, value); }
5446 remove { Events.RemoveHandler (TabStopChangedEvent, value); }
5449 public event EventHandler TextChanged {
5450 add { Events.AddHandler (TextChangedEvent, value); }
5451 remove { Events.RemoveHandler (TextChangedEvent, value); }
5454 public event EventHandler Validated {
5455 add { Events.AddHandler (ValidatedEvent, value); }
5456 remove { Events.RemoveHandler (ValidatedEvent, value); }
5459 public event CancelEventHandler Validating {
5460 add { Events.AddHandler (ValidatingEvent, value); }
5461 remove { Events.RemoveHandler (ValidatingEvent, value); }
5464 public event EventHandler VisibleChanged {
5465 add { Events.AddHandler (VisibleChangedEvent, value); }
5466 remove { Events.RemoveHandler (VisibleChangedEvent, value); }
5469 #endregion // Events