1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 // Copyright (c) 2004-2006 Novell, Inc.
23 // Peter Bartok pbartok@novell.com
25 // Partially based on work by:
26 // Aleksey Ryabchuk ryabchuk@yahoo.com
27 // Alexandre Pigolkine pigolkine@gmx.de
28 // Dennis Hayes dennish@raytek.com
29 // Jaak Simm jaaksimm@firm.ee
30 // John Sohn jsohn@columbus.rr.com
38 using System.ComponentModel;
39 using System.ComponentModel.Design;
40 using System.ComponentModel.Design.Serialization;
41 using System.Collections;
42 using System.Diagnostics;
44 using System.Drawing.Drawing2D;
45 using System.Reflection;
46 using System.Runtime.InteropServices;
47 using System.Security;
48 using System.Threading;
50 namespace System.Windows.Forms
52 [Designer("System.Windows.Forms.Design.ControlDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
53 [DefaultProperty("Text")]
54 [DefaultEvent("Click")]
55 [DesignerSerializer("System.Windows.Forms.Design.ControlCodeDomSerializer, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
56 [ToolboxItemFilter("System.Windows.Forms")]
57 public class Control : Component, ISynchronizeInvoke, IWin32Window
59 #region Local Variables
62 internal Rectangle bounds; // bounding rectangle for control (client area + decorations)
63 internal object creator_thread; // thread that created the control
64 internal ControlNativeWindow window; // object for native window handle
65 internal string name; // for object naming
68 internal bool is_created; // true if OnCreateControl has been sent
69 internal bool has_focus; // true if control has focus
70 internal bool is_visible; // true if control is visible
71 internal bool is_entered; // is the mouse inside the control?
72 internal bool is_enabled; // true if control is enabled (usable/not grayed out)
73 internal bool is_accessible; // true if the control is visible to accessibility applications
74 internal bool is_captured; // tracks if the control has captured the mouse
75 internal bool is_toplevel; // tracks if the control is a toplevel window
76 internal bool is_recreating; // tracks if the handle for the control is being recreated
77 internal bool causes_validation; // tracks if validation is executed on changes
78 internal int tab_index; // position in tab order of siblings
79 internal bool tab_stop = true; // is the control a tab stop?
80 internal bool is_disposed; // has the window already been disposed?
81 internal Size client_size; // size of the client area (window excluding decorations)
82 internal Rectangle client_rect; // rectangle with the client area (window excluding decorations)
83 internal ControlStyles control_style; // rather win32-specific, style bits for control
84 internal ImeMode ime_mode = ImeMode.Inherit;
85 internal bool layout_pending; // true if our parent needs to re-layout us
86 internal object control_tag; // object that contains data about our control
87 internal int mouse_clicks; // Counter for mouse clicks
88 internal Cursor cursor; // Cursor for the window
89 internal bool allow_drop; // true if the control accepts droping objects on it
90 internal Region clip_region; // User-specified clip region for the window
93 internal Color foreground_color; // foreground color for control
94 internal Color background_color; // background color for control
95 internal Image background_image; // background image for control
96 internal Font font; // font for control
97 internal string text; // window/title text for control
98 internal BorderStyle border_style; // Border style of control
101 internal AnchorStyles anchor_style; // anchoring requirements for our control
102 internal DockStyle dock_style; // docking requirements for our control (supercedes anchoring)
103 internal int dist_left; // distance to the left border of the parent
104 internal int dist_top; // distance to the top border of the parent
105 internal int dist_right; // distance to the right border of the parent
106 internal int dist_bottom; // distance to the bottom border of the parent
108 // to be categorized...
109 static internal ArrayList controls = new ArrayList(); // All of the application's controls, in a flat list
110 internal ControlCollection child_controls; // our children
111 internal Control parent; // our parent control
112 internal AccessibleObject accessibility_object; // object that contains accessibility information about our control
113 internal BindingContext binding_context; // TODO
114 internal RightToLeft right_to_left; // drawing direction for control
115 internal int layout_suspended;
116 internal ContextMenu context_menu; // Context menu associated with the control
118 private Graphics dc_mem; // Graphics context for double buffering
119 private Bitmap bmp_mem; // Bitmap for double buffering control
120 private Region invalid_region;
122 private ControlBindingsCollection data_bindings;
125 internal bool use_compatible_text_rendering;
126 static internal bool verify_thread_handle;
127 private Padding padding;
128 private Size maximum_size;
129 private Size minimum_size;
130 private Size preferred_size;
131 private Padding margin;
132 internal Layout.LayoutEngine layout_engine;
135 #endregion // Local Variables
137 #region Private Classes
138 // This helper class allows us to dispatch messages to Control.WndProc
139 internal class ControlNativeWindow : NativeWindow {
140 private Control owner;
142 public ControlNativeWindow(Control control) : base() {
147 public Control Owner {
153 static internal Control ControlFromHandle(IntPtr hWnd) {
154 ControlNativeWindow window;
156 window = (ControlNativeWindow)window_collection[hWnd];
157 if (window != null) {
164 protected override void WndProc(ref Message m) {
165 owner.WndProc(ref m);
170 #region Public Classes
172 public class ControlAccessibleObject : AccessibleObject {
173 #region ControlAccessibleObject Constructors
174 public ControlAccessibleObject(Control ownerControl) {
175 this.owner = ownerControl;
177 #endregion // ControlAccessibleObject Constructors
179 #region ControlAccessibleObject Public Instance Properties
180 public override string DefaultAction {
182 return base.DefaultAction;
186 public override string Description {
188 return base.Description;
192 public IntPtr Handle {
198 // We don't want to let them set it
202 public override string Help {
208 public override string KeyboardShortcut {
210 return base.KeyboardShortcut;
214 public override string Name {
224 public Control Owner {
230 public override AccessibleObject Parent {
237 public override AccessibleRole Role {
242 #endregion // ControlAccessibleObject Public Instance Properties
244 #region ControlAccessibleObject Public Instance Methods
245 public override int GetHelpTopic(out string FileName) {
246 return base.GetHelpTopic (out FileName);
249 [MonoTODO("Implement this and tie it into Control.AccessibilityNotifyClients")]
250 public void NotifyClients(AccessibleEvents accEvent) {
251 throw new NotImplementedException();
254 [MonoTODO("Implement this and tie it into Control.AccessibilityNotifyClients")]
255 public void NotifyClients(AccessibleEvents accEvent, int childID) {
256 throw new NotImplementedException();
259 public override string ToString() {
260 return "ControlAccessibleObject: Owner = " + owner.ToString() + ", Text: " + owner.text;
263 #endregion // ControlAccessibleObject Public Instance Methods
266 [DesignerSerializer("System.Windows.Forms.Design.ControlCollectionCodeDomSerializer, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
267 [ListBindable(false)]
268 public class ControlCollection : IList, ICollection, ICloneable, IEnumerable {
269 #region ControlCollection Local Variables
270 private ArrayList list;
271 internal ArrayList impl_list;
272 private Control [] all_controls;
273 internal Control owner;
274 #endregion // ControlCollection Local Variables
276 #region ControlCollection Public Constructor
277 public ControlCollection(Control owner) {
279 this.list=new ArrayList();
283 #region ControlCollection Public Instance Properties
290 public bool IsReadOnly {
292 return list.IsReadOnly;
296 public virtual Control this[int index] {
298 if (index < 0 || index >= list.Count) {
299 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
301 return (Control)list[index];
304 #endregion // ControlCollection Public Instance Properties
306 #region ControlCollection Private Instance Methods
307 public virtual void Add (Control value)
312 if (Contains (value)) {
313 owner.PerformLayout();
317 if (value.tab_index == -1) {
323 end = owner.child_controls.Count;
324 for (int i = 0; i < end; i++) {
325 index = owner.child_controls[i].tab_index;
330 value.tab_index = use;
333 if (value.parent != null) {
334 value.parent.Controls.Remove(value);
340 value.ChangeParent(owner);
344 owner.UpdateChildrenZOrder();
345 owner.PerformLayout(value, "Parent");
346 owner.OnControlAdded(new ControlEventArgs(value));
349 internal void AddToList (Control c)
355 internal virtual void AddImplicit (Control control)
357 if (impl_list == null)
358 impl_list = new ArrayList ();
360 if (AllContains (control))
364 impl_list.Add (control);
366 control.ChangeParent (owner);
367 control.InitLayout ();
368 owner.UpdateChildrenZOrder ();
369 owner.PerformLayout (control, "Parent");
370 owner.OnControlAdded (new ControlEventArgs (control));
373 public virtual void AddRange (Control[] controls)
375 if (controls == null)
376 throw new ArgumentNullException ("controls");
378 owner.SuspendLayout ();
381 for (int i = 0; i < controls.Length; i++)
384 owner.ResumeLayout ();
388 internal virtual void AddRangeImplicit (Control [] controls)
390 if (controls == null)
391 throw new ArgumentNullException ("controls");
393 owner.SuspendLayout ();
396 for (int i = 0; i < controls.Length; i++)
397 AddImplicit (controls [i]);
399 owner.ResumeLayout ();
403 public virtual void Clear ()
407 // MS sends remove events in reverse order
408 while (list.Count > 0) {
409 Remove((Control)list[list.Count - 1]);
413 internal virtual void ClearImplicit ()
415 if (impl_list == null)
421 public bool Contains (Control value)
423 for (int i = list.Count; i > 0; ) {
426 if (list [i] == value) {
427 // Do we need to do anything here?
434 internal bool ImplicitContains (Control value)
436 if (impl_list == null)
439 for (int i = impl_list.Count; i > 0; ) {
442 if (impl_list [i] == value) {
443 // Do we need to do anything here?
450 internal bool AllContains (Control value)
452 return Contains (value) || ImplicitContains (value);
455 public void CopyTo (Array array, int index)
457 list.CopyTo(array, index);
460 public override bool Equals(object other) {
461 if (other is ControlCollection && (((ControlCollection)other).owner==this.owner)) {
468 public int GetChildIndex(Control child) {
469 return GetChildIndex(child, false);
472 public int GetChildIndex(Control child, bool throwException) {
475 index=list.IndexOf(child);
477 if (index==-1 && throwException) {
478 throw new ArgumentException("Not a child control", "child");
483 public IEnumerator GetEnumerator() {
484 return list.GetEnumerator();
487 internal IEnumerator GetAllEnumerator ()
489 Control [] res = GetAllControls ();
490 return res.GetEnumerator ();
493 internal Control [] GetAllControls ()
495 if (all_controls != null)
498 if (impl_list == null) {
499 all_controls = (Control []) list.ToArray (typeof (Control));
503 all_controls = new Control [list.Count + impl_list.Count];
504 impl_list.CopyTo (all_controls);
505 list.CopyTo (all_controls, impl_list.Count);
510 public override int GetHashCode() {
511 return base.GetHashCode();
514 public int IndexOf(Control control) {
515 return list.IndexOf(control);
518 public virtual void Remove(Control value) {
519 owner.PerformLayout(value, "Parent");
520 owner.OnControlRemoved(new ControlEventArgs(value));
525 value.ChangeParent(null);
527 owner.UpdateChildrenZOrder();
530 internal virtual void RemoveImplicit (Control control)
532 if (impl_list != null) {
534 owner.PerformLayout (control, "Parent");
535 owner.OnControlRemoved (new ControlEventArgs (control));
536 impl_list.Remove (control);
538 control.ChangeParent (null);
539 owner.UpdateChildrenZOrder ();
542 public void RemoveAt(int index) {
543 if (index < 0 || index >= list.Count) {
544 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
546 Remove ((Control)list[index]);
549 public void SetChildIndex(Control child, int newIndex) {
552 old_index=list.IndexOf(child);
554 throw new ArgumentException("Not a child control", "child");
557 if (old_index==newIndex) {
562 list.RemoveAt(old_index);
564 if (newIndex>list.Count) {
567 list.Insert(newIndex, child);
569 child.UpdateZOrder();
570 owner.PerformLayout();
572 #endregion // ControlCollection Private Instance Methods
574 #region ControlCollection Interface Properties
575 object IList.this[int index] {
577 if (index<0 || index>=list.Count) {
578 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
584 if (!(value is Control)) {
585 throw new ArgumentException("Object of type Control required", "value");
589 Control ctrl = (Control) value;
592 ctrl.ChangeParent(owner);
596 owner.UpdateChildrenZOrder();
597 owner.PerformLayout(ctrl, "Parent");
601 bool IList.IsFixedSize {
607 bool ICollection.IsSynchronized {
609 return list.IsSynchronized;
613 object ICollection.SyncRoot {
615 return list.SyncRoot;
618 #endregion // ControlCollection Interface Properties
620 #region ControlCollection Interface Methods
621 int IList.Add(object value) {
623 throw new ArgumentNullException("value", "Cannot add null controls");
626 if (!(value is Control)) {
627 throw new ArgumentException("Object of type Control required", "value");
630 return list.Add(value);
633 bool IList.Contains(object value) {
634 if (!(value is Control)) {
635 throw new ArgumentException("Object of type Control required", "value");
638 return this.Contains((Control) value);
641 int IList.IndexOf(object value) {
642 if (!(value is Control)) {
643 throw new ArgumentException("Object of type Control required", "value");
646 return this.IndexOf((Control) value);
649 void IList.Insert(int index, object value) {
650 if (!(value is Control)) {
651 throw new ArgumentException("Object of type Control required", "value");
654 list.Insert(index, value);
657 void IList.Remove(object value) {
658 if (!(value is Control)) {
659 throw new ArgumentException("Object of type Control required", "value");
665 Object ICloneable.Clone() {
666 ControlCollection clone = new ControlCollection(this.owner);
667 clone.list=(ArrayList)list.Clone(); // FIXME: Do we need this?
670 #endregion // ControlCollection Interface Methods
672 #endregion // ControlCollection Class
674 #region Public Constructors
677 anchor_style = AnchorStyles.Top | AnchorStyles.Left;
685 layout_pending = false;
687 causes_validation = true;
689 layout_suspended = 0;
693 right_to_left = RightToLeft.Inherit;
694 border_style = BorderStyle.None;
695 background_color = Color.Empty;
702 use_compatible_text_rendering = Application.use_compatible_text_rendering;
703 padding = new Padding(0);
704 maximum_size = new Size();
705 minimum_size = new Size();
706 preferred_size = new Size();
707 margin = this.DefaultMargin;
708 layout_engine = new Layout.DefaultLayout();
711 control_style = ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint |
712 ControlStyles.Selectable | ControlStyles.StandardClick |
713 ControlStyles.StandardDoubleClick;
716 background_image = null;
720 window = new ControlNativeWindow(this);
721 child_controls = CreateControlsInstance();
722 client_size = new Size(DefaultSize.Width, DefaultSize.Height);
723 client_rect = new Rectangle(0, 0, DefaultSize.Width, DefaultSize.Height);
724 XplatUI.CalculateWindowRect(ref client_rect, CreateParams.Style, CreateParams.ExStyle, null, out bounds);
725 if ((CreateParams.Style & (int)WindowStyles.WS_CHILD) == 0) {
731 public Control(Control parent, string text) : this() {
736 public Control(Control parent, string text, int left, int top, int width, int height) : this() {
741 bounds.Height=height;
742 SetBounds(left, top, width, height, BoundsSpecified.All);
746 public Control(string text) : this() {
750 public Control(string text, int left, int top, int width, int height) : this() {
754 bounds.Height=height;
755 SetBounds(left, top, width, height, BoundsSpecified.All);
759 private delegate void RemoveDelegate(object c);
761 protected override void Dispose(bool disposing) {
775 if (invalid_region!=null) {
776 invalid_region.Dispose();
779 if (this.InvokeRequired) {
780 if (Application.MessageLoop) {
781 this.BeginInvokeInternal(new MethodInvoker(DestroyHandle), null, true);
782 this.BeginInvokeInternal(new RemoveDelegate(controls.Remove), new object[] {this}, true);
786 lock (Control.controls) {
787 Control.controls.Remove(this);
792 if (parent != null) {
793 parent.Controls.Remove(this);
796 Control [] children = child_controls.GetAllControls ();
797 for (int i=0; i<children.Length; i++) {
798 children[i].parent = null; // Need to set to null or our child will try and remove from ourselves and crash
799 children[i].Dispose();
804 base.Dispose(disposing);
806 #endregion // Public Constructors
808 #region Internal Properties
809 internal BorderStyle InternalBorderStyle {
815 if (!Enum.IsDefined (typeof (BorderStyle), value))
816 throw new InvalidEnumArgumentException (string.Format("Enum argument value '{0}' is not valid for BorderStyle", value));
818 if (border_style != value) {
819 border_style = value;
821 if (IsHandleCreated) {
822 XplatUI.SetBorderStyle(window.Handle, (FormBorderStyle)border_style);
828 #endregion // Internal Properties
830 #region Private & Internal Methods
831 internal IAsyncResult BeginInvokeInternal (Delegate method, object [] args, bool disposing) {
832 AsyncMethodResult result;
833 AsyncMethodData data;
840 if (!p.IsHandleCreated) {
841 throw new InvalidOperationException("Cannot call Invoke or InvokeAsync on a control until the window handle is created");
847 result = new AsyncMethodResult ();
848 data = new AsyncMethodData ();
850 data.Handle = window.Handle;
851 data.Method = method;
853 data.Result = result;
856 if (!ExecutionContext.IsFlowSuppressed ()) {
857 data.Context = ExecutionContext.Capture ();
860 #if !MWF_ON_MSRUNTIME
861 if (SecurityManager.SecurityEnabled) {
862 data.Stack = CompressedStack.GetCompressedStack ();
867 XplatUI.SendAsyncMethod (data);
872 internal void PointToClient (ref int x, ref int y)
874 XplatUI.ScreenToClient (Handle, ref x, ref y);
877 internal void PointToScreen (ref int x, ref int y)
879 XplatUI.ClientToScreen (Handle, ref x, ref y);
882 internal bool IsRecreating {
884 return is_recreating;
888 internal Graphics DeviceContext {
890 if (dc_mem == null) {
891 CreateBuffers(this.Width, this.Height);
897 private void ImageBufferNeedsRedraw () {
898 if (invalid_region != null)
899 invalid_region.Dispose();
900 invalid_region = new Region (ClientRectangle);
903 private Bitmap ImageBuffer {
906 CreateBuffers(this.Width, this.Height);
912 internal void CreateBuffers (int width, int height) {
921 bmp_mem = new Bitmap (width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
922 dc_mem = Graphics.FromImage (bmp_mem);
923 ImageBufferNeedsRedraw ();
926 internal void InvalidateBuffers ()
928 if (dc_mem != null) {
934 ImageBufferNeedsRedraw ();
937 internal static void SetChildColor(Control parent) {
940 for (int i=0; i < parent.child_controls.Count; i++) {
941 child=parent.child_controls[i];
942 if (child.child_controls.Count>0) {
943 SetChildColor(child);
949 internal bool Select(Control control) {
950 IContainerControl container;
952 if (control == null) {
956 container = GetContainerControl();
957 if (container != null) {
958 container.ActiveControl = control;
960 if (control.IsHandleCreated) {
961 XplatUI.SetFocus(control.window.Handle);
966 internal void SelectChild (Control control)
968 if (control.IsHandleCreated)
969 XplatUI.SetFocus (control.window.Handle);
972 internal virtual void DoDefaultAction() {
973 // Only here to be overriden by our actual controls; this is needed by the accessibility class
976 internal static int LowOrder (int param) {
977 return ((int)(short)(param & 0xffff));
980 internal static int HighOrder (int param) {
981 return ((int)(short)(param >> 16));
984 // This method exists so controls overriding OnPaintBackground can have default background painting done
985 internal virtual void PaintControlBackground (PaintEventArgs pevent)
987 if (GetStyle(ControlStyles.SupportsTransparentBackColor) && (BackColor.A != 0xff)) {
988 if (parent != null) {
989 PaintEventArgs parent_pe;
992 parent_pe = new PaintEventArgs(pevent.Graphics, new Rectangle(pevent.ClipRectangle.X + Left, pevent.ClipRectangle.Y + Top, pevent.ClipRectangle.Width, pevent.ClipRectangle.Height));
994 state = parent_pe.Graphics.Save();
995 parent_pe.Graphics.TranslateTransform(-Left, -Top);
996 parent.OnPaintBackground(parent_pe);
997 parent_pe.Graphics.Restore(state);
999 state = parent_pe.Graphics.Save();
1000 parent_pe.Graphics.TranslateTransform(-Left, -Top);
1001 parent.OnPaint(parent_pe);
1002 parent_pe.Graphics.Restore(state);
1003 parent_pe.SetGraphics(null);
1007 if ((clip_region != null) && (XplatUI.UserClipWontExposeParent)) {
1008 if (parent != null) {
1009 PaintEventArgs parent_pe;
1011 GraphicsState state;
1014 hwnd = Hwnd.ObjectFromHandle(Handle);
1017 parent_pe = new PaintEventArgs(pevent.Graphics, new Rectangle(pevent.ClipRectangle.X + Left, pevent.ClipRectangle.Y + Top, pevent.ClipRectangle.Width, pevent.ClipRectangle.Height));
1019 region = new Region ();
1021 region.Union(ClientRectangle);
1023 foreach (Rectangle r in hwnd.ClipRectangles) {
1027 state = parent_pe.Graphics.Save();
1028 parent_pe.Graphics.Clip = region;
1030 parent_pe.Graphics.TranslateTransform(-Left, -Top);
1031 parent.OnPaintBackground(parent_pe);
1032 parent_pe.Graphics.Restore(state);
1034 state = parent_pe.Graphics.Save();
1035 parent_pe.Graphics.Clip = region;
1037 parent_pe.Graphics.TranslateTransform(-Left, -Top);
1038 parent.OnPaint(parent_pe);
1039 parent_pe.Graphics.Restore(state);
1040 parent_pe.SetGraphics(null);
1042 region.Intersect(clip_region);
1043 pevent.Graphics.Clip = region;
1048 if (background_image == null) {
1049 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));
1053 DrawBackgroundImage (pevent.Graphics);
1056 void DrawBackgroundImage (Graphics g)
1058 using (TextureBrush b = new TextureBrush (background_image, WrapMode.Tile)) {
1059 g.FillRectangle (b, ClientRectangle);
1063 internal virtual void DndEnter (DragEventArgs e)
1070 internal virtual void DndOver (DragEventArgs e)
1077 internal virtual void DndDrop (DragEventArgs e)
1081 } catch (Exception exc) {
1082 Console.Error.WriteLine ("MWF: Exception while dropping:");
1083 Console.Error.WriteLine (exc);
1087 internal virtual void DndLeave (EventArgs e)
1094 internal virtual void DndFeedback(GiveFeedbackEventArgs e)
1101 internal virtual void DndContinueDrag(QueryContinueDragEventArgs e)
1104 OnQueryContinueDrag(e);
1108 internal static MouseButtons FromParamToMouseButtons (int param) {
1109 MouseButtons buttons = MouseButtons.None;
1111 if ((param & (int) MsgButtons.MK_LBUTTON) != 0)
1112 buttons |= MouseButtons.Left;
1114 if ((param & (int) MsgButtons.MK_MBUTTON) != 0)
1115 buttons |= MouseButtons.Middle;
1117 if ((param & (int) MsgButtons.MK_RBUTTON) != 0)
1118 buttons |= MouseButtons.Right;
1124 internal void FireEnter ()
1126 OnEnter (EventArgs.Empty);
1129 internal void FireLeave ()
1131 OnLeave (EventArgs.Empty);
1134 internal void FireValidating (CancelEventArgs ce)
1139 internal void FireValidated ()
1141 OnValidated (EventArgs.Empty);
1144 internal virtual bool ProcessControlMnemonic(char charCode) {
1145 return ProcessMnemonic(charCode);
1148 private static Control FindFlatForward(Control container, Control start) {
1154 end = container.child_controls.Count;
1156 if (start != null) {
1157 index = start.tab_index;
1163 for (int i = 0, pos = -1; i < end; i++) {
1164 if (start == container.child_controls[i]) {
1169 if (found == null) {
1170 if (container.child_controls[i].tab_index > index || (pos > -1 && pos < i && container.child_controls[i].tab_index == index)) {
1171 found = container.child_controls[i];
1173 } else if (found.tab_index > container.child_controls[i].tab_index) {
1174 if (container.child_controls[i].tab_index > index) {
1175 found = container.child_controls[i];
1182 private static Control FindControlForward(Control container, Control start) {
1188 if (start != null) {
1189 if (start.child_controls != null && start.child_controls.Count > 0 &&
1190 !((start is IContainerControl) && start.GetStyle(ControlStyles.ContainerControl))) {
1191 found = FindControlForward(start, null);
1192 if (found != null) {
1198 while (p != container) {
1199 found = FindFlatForward(p, start);
1200 if (found != null) {
1207 return FindFlatForward(container, start);
1210 private static Control FindFlatBackward(Control container, Control start) {
1216 end = container.child_controls.Count;
1218 if (start != null) {
1219 index = start.tab_index;
1221 // FIXME: Possible speed-up: Keep the highest taborder index in the container
1223 for (int i = 0; i < end; i++) {
1224 if (container.child_controls[i].tab_index > index) {
1225 index = container.child_controls[i].tab_index;
1231 for (int i = end-1, pos = -1; i >= 0; i--) {
1232 if (start == container.child_controls[i]) {
1237 if (found == null) {
1238 if (container.child_controls[i].tab_index < index ||
1239 (pos > -1 && pos > i && container.child_controls[i].tab_index == index)) {
1240 found = container.child_controls[i];
1242 } else if (found.tab_index < container.child_controls[i].tab_index) {
1243 if (container.child_controls[i].tab_index < index) {
1244 found = container.child_controls[i];
1251 private static Control FindControlBackward(Control container, Control start) {
1256 if (start != null) {
1257 found = FindFlatBackward(start.parent, start);
1258 if (found == null) {
1259 if (start.parent != container) {
1260 return start.parent;
1264 if (found == null) {
1265 found = FindFlatBackward(container, start);
1268 if (container != start) {
1269 while ((found != null) && (!found.Contains(start)) && found.child_controls != null && found.child_controls.Count > 0 && !(found is IContainerControl)) {// || found.GetStyle(ControlStyles.ContainerControl))) {
1270 found = FindControlBackward(found, null);
1271 if (found != null) {
1280 internal virtual void HandleClick(int clicks, MouseEventArgs me) {
1281 if (GetStyle(ControlStyles.StandardClick)) {
1282 if ((clicks > 1) && GetStyle(ControlStyles.StandardDoubleClick)) {
1284 OnDoubleClick(EventArgs.Empty);
1286 OnClick(EventArgs.Empty);
1296 private void CheckDataBindings ()
1298 if (data_bindings == null)
1301 BindingContext binding_context = BindingContext;
1302 foreach (Binding binding in data_bindings) {
1303 binding.Check (binding_context);
1308 private void ChangeParent(Control new_parent) {
1312 Color pre_fore_color;
1313 Color pre_back_color;
1314 RightToLeft pre_rtl;
1316 // These properties are inherited from our parent
1317 // Get them pre parent-change and then send events
1318 // if they are changed after we have our new parent
1319 pre_enabled = Enabled;
1320 pre_visible = Visible;
1322 pre_fore_color = ForeColor;
1323 pre_back_color = BackColor;
1324 pre_rtl = RightToLeft;
1325 // MS doesn't seem to send a CursorChangedEvent
1327 parent = new_parent;
1329 if (IsHandleCreated)
1330 XplatUI.SetParent(Handle,
1331 (new_parent == null || !new_parent.IsHandleCreated) ? IntPtr.Zero : new_parent.Handle);
1333 OnParentChanged(EventArgs.Empty);
1335 if (pre_enabled != Enabled) {
1336 OnEnabledChanged(EventArgs.Empty);
1339 if (pre_visible != Visible) {
1340 OnVisibleChanged(EventArgs.Empty);
1343 if (pre_font != Font) {
1344 OnFontChanged(EventArgs.Empty);
1347 if (pre_fore_color != ForeColor) {
1348 OnForeColorChanged(EventArgs.Empty);
1351 if (pre_back_color != BackColor) {
1352 OnBackColorChanged(EventArgs.Empty);
1355 if (pre_rtl != RightToLeft) {
1356 // MS sneaks a OnCreateControl and OnHandleCreated in here, I guess
1357 // because when RTL changes they have to recreate the win32 control
1358 // We don't really need that (until someone runs into compatibility issues)
1359 OnRightToLeftChanged(EventArgs.Empty);
1362 if ((new_parent != null) && new_parent.Created && !Created) {
1366 if ((binding_context == null) && Created) {
1367 OnBindingContextChanged(EventArgs.Empty);
1371 private void UpdateDistances() {
1372 if ((parent != null) && (parent.layout_suspended == 0)) {
1373 dist_left = bounds.X;
1374 dist_top = bounds.Y;
1375 dist_right = parent.ClientSize.Width - bounds.X - bounds.Width;
1376 dist_bottom = parent.ClientSize.Height - bounds.Y - bounds.Height;
1379 #endregion // Private & Internal Methods
1381 #region Public Static Properties
1382 public static Color DefaultBackColor {
1384 return ThemeEngine.Current.DefaultControlBackColor;
1388 public static Font DefaultFont {
1390 return ThemeEngine.Current.DefaultFont;
1394 public static Color DefaultForeColor {
1396 return ThemeEngine.Current.DefaultControlForeColor;
1400 public static Keys ModifierKeys {
1402 return XplatUI.State.ModifierKeys;
1406 public static MouseButtons MouseButtons {
1408 return XplatUI.State.MouseButtons;
1412 public static Point MousePosition {
1414 return Cursor.Position;
1420 public static bool CheckForIllegalCrossThreadCalls
1423 return verify_thread_handle;
1427 verify_thread_handle = value;
1431 #endregion // Public Static Properties
1433 #region Public Instance Properties
1434 [EditorBrowsable(EditorBrowsableState.Advanced)]
1436 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1437 public AccessibleObject AccessibilityObject {
1439 if (accessibility_object==null) {
1440 accessibility_object=CreateAccessibilityInstance();
1442 return accessibility_object;
1446 [EditorBrowsable(EditorBrowsableState.Advanced)]
1448 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1449 public string AccessibleDefaultActionDescription {
1451 return AccessibilityObject.default_action;
1455 AccessibilityObject.default_action=value;
1460 [DefaultValue(null)]
1461 [MWFCategory("Accessibility")]
1462 public string AccessibleDescription {
1464 return AccessibilityObject.description;
1468 AccessibilityObject.description=value;
1473 [DefaultValue(null)]
1474 [MWFCategory("Accessibility")]
1475 public string AccessibleName {
1477 return AccessibilityObject.Name;
1481 AccessibilityObject.Name=value;
1485 [DefaultValue(AccessibleRole.Default)]
1486 [MWFDescription("Role of the control"), MWFCategory("Accessibility")]
1487 public AccessibleRole AccessibleRole {
1489 return AccessibilityObject.role;
1493 AccessibilityObject.role=value;
1497 [DefaultValue(false)]
1498 [MWFCategory("Behavior")]
1499 public virtual bool AllowDrop {
1505 if (allow_drop == value)
1508 if (IsHandleCreated) {
1510 XplatUI.SetAllowDrop (Handle, value);
1516 [RefreshProperties(RefreshProperties.Repaint)]
1517 [DefaultValue(AnchorStyles.Top | AnchorStyles.Left)]
1518 [MWFCategory("Layout")]
1519 public virtual AnchorStyles Anchor {
1521 return anchor_style;
1527 if (parent != null) {
1528 parent.PerformLayout(this, "Parent");
1534 // XXX: Implement me!
1537 public virtual bool AutoSize {
1539 //Console.Error.WriteLine("Unimplemented: Control::get_AutoSize()");
1543 Console.Error.WriteLine("Unimplemented: Control::set_AutoSize(bool)");
1548 public virtual Size MaximumSize {
1550 return maximum_size;
1553 maximum_size = value;
1557 public virtual Size MinimumSize {
1559 return minimum_size;
1562 minimum_size = value;
1568 [MWFCategory("Appearance")]
1569 public virtual Color BackColor {
1571 if (background_color.IsEmpty) {
1573 Color pcolor = parent.BackColor;
1574 if (pcolor.A == 0xff || GetStyle(ControlStyles.SupportsTransparentBackColor))
1577 return DefaultBackColor;
1579 return background_color;
1583 if (!value.IsEmpty && (value.A != 0xff) && !GetStyle(ControlStyles.SupportsTransparentBackColor)) {
1584 throw new ArgumentException("Transparent background colors are not supported on this control");
1587 if (background_color != value) {
1588 background_color=value;
1589 SetChildColor(this);
1590 OnBackColorChanged(EventArgs.Empty);
1597 [DefaultValue(null)]
1598 [MWFCategory("Appearance")]
1599 public virtual Image BackgroundImage {
1601 return background_image;
1605 if (background_image!=value) {
1606 background_image=value;
1607 OnBackgroundImageChanged(EventArgs.Empty);
1612 [EditorBrowsable(EditorBrowsableState.Advanced)]
1614 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1615 public virtual BindingContext BindingContext {
1617 if (binding_context != null)
1618 return binding_context;
1621 binding_context = Parent.BindingContext;
1622 return binding_context;
1625 if (binding_context != value) {
1626 binding_context = value;
1627 OnBindingContextChanged(EventArgs.Empty);
1632 [EditorBrowsable(EditorBrowsableState.Advanced)]
1634 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1637 return bounds.Y+bounds.Height;
1641 [EditorBrowsable(EditorBrowsableState.Advanced)]
1643 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1644 public Rectangle Bounds {
1650 SetBounds(value.Left, value.Top, value.Width, value.Height, BoundsSpecified.All);
1654 [EditorBrowsable(EditorBrowsableState.Advanced)]
1656 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1657 public bool CanFocus {
1659 if (IsHandleCreated && Visible && Enabled) {
1666 [EditorBrowsable(EditorBrowsableState.Advanced)]
1668 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1669 public bool CanSelect {
1673 if (!GetStyle(ControlStyles.Selectable)) {
1678 while (parent != null) {
1679 if (!parent.is_visible || !parent.is_enabled) {
1683 parent = parent.parent;
1689 internal virtual bool InternalCapture {
1699 [EditorBrowsable(EditorBrowsableState.Advanced)]
1701 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1702 public bool Capture {
1704 return this.is_captured;
1708 if (this.IsHandleCreated) {
1709 if (value && !is_captured) {
1711 XplatUI.GrabWindow(this.window.Handle, IntPtr.Zero);
1712 } else if (!value && is_captured) {
1713 XplatUI.UngrabWindow(this.window.Handle);
1714 is_captured = false;
1720 [DefaultValue(true)]
1721 [MWFCategory("Focus")]
1722 public bool CausesValidation {
1724 return this.causes_validation;
1728 if (this.causes_validation != value) {
1729 causes_validation = value;
1730 OnCausesValidationChanged(EventArgs.Empty);
1735 [EditorBrowsable(EditorBrowsableState.Advanced)]
1737 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1738 public Rectangle ClientRectangle {
1740 client_rect.Width = client_size.Width;
1741 client_rect.Height = client_size.Height;
1746 [EditorBrowsable(EditorBrowsableState.Advanced)]
1748 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1749 public Size ClientSize {
1752 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1753 return ((Form)this).form_parent_window.ClientSize;
1761 this.SetClientSizeCore(value.Width, value.Height);
1765 [EditorBrowsable(EditorBrowsableState.Advanced)]
1767 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1768 [DescriptionAttribute("ControlCompanyNameDescr")]
1769 public String CompanyName {
1771 return "Mono Project, Novell, Inc.";
1775 [EditorBrowsable(EditorBrowsableState.Advanced)]
1777 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1778 public bool ContainsFocus {
1780 IntPtr focused_window;
1782 focused_window = XplatUI.GetFocus();
1783 if (IsHandleCreated) {
1784 if (focused_window == Handle) {
1788 for (int i=0; i < child_controls.Count; i++) {
1789 if (child_controls[i].ContainsFocus) {
1798 [DefaultValue(null)]
1799 [MWFCategory("Behavior")]
1800 public virtual ContextMenu ContextMenu {
1802 return context_menu;
1806 if (context_menu != value) {
1807 context_menu = value;
1808 OnContextMenuChanged(EventArgs.Empty);
1814 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
1815 public ControlCollection Controls {
1817 return this.child_controls;
1821 [EditorBrowsable(EditorBrowsableState.Advanced)]
1823 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1824 public bool Created {
1826 return (!is_disposed && is_created);
1830 [AmbientValue(null)]
1831 [MWFCategory("Appearance")]
1832 public virtual Cursor Cursor {
1834 if (cursor != null) {
1838 if (parent != null) {
1839 return parent.Cursor;
1842 return Cursors.Default;
1846 if (cursor != value) {
1851 if (IsHandleCreated) {
1852 pt = Cursor.Position;
1854 if (bounds.Contains(pt) || Capture) {
1855 if (GetChildAtPoint(pt) == null) {
1856 if (cursor != null) {
1857 XplatUI.SetCursor(window.Handle, cursor.handle);
1859 if (parent != null) {
1860 XplatUI.SetCursor(window.Handle, parent.Cursor.handle);
1862 XplatUI.SetCursor(window.Handle, Cursors.Default.handle);
1869 OnCursorChanged(EventArgs.Empty);
1875 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
1876 [ParenthesizePropertyName(true)]
1877 [RefreshProperties(RefreshProperties.All)]
1878 [MWFCategory("Data")]
1879 public ControlBindingsCollection DataBindings {
1881 if (data_bindings == null)
1882 data_bindings = new ControlBindingsCollection (this);
1883 return data_bindings;
1887 [EditorBrowsable(EditorBrowsableState.Advanced)]
1889 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1890 public virtual Rectangle DisplayRectangle {
1892 return ClientRectangle;
1896 [EditorBrowsable(EditorBrowsableState.Advanced)]
1898 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1899 public bool Disposing {
1906 [RefreshProperties(RefreshProperties.Repaint)]
1907 [DefaultValue(DockStyle.None)]
1908 [MWFCategory("Layout")]
1909 public virtual DockStyle Dock {
1915 if (dock_style == value) {
1921 if (parent != null) {
1922 parent.PerformLayout(this, "Parent");
1925 OnDockChanged(EventArgs.Empty);
1931 [MWFCategory("Behavior")]
1932 public bool Enabled {
1938 if (parent != null) {
1939 return parent.Enabled;
1946 if (Enabled == value) {
1953 // FIXME - we need to switch focus to next control if we're disabling the focused control
1955 OnEnabledChanged (EventArgs.Empty);
1959 [EditorBrowsable(EditorBrowsableState.Advanced)]
1961 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1962 public virtual bool Focused {
1964 return this.has_focus;
1969 [AmbientValue(null)]
1971 [MWFCategory("Appearance")]
1972 public virtual Font Font {
1978 if (Parent != null && Parent.Font != null) {
1985 [param:MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Font))]
1987 if (font != null && font.Equals (value)) {
1993 OnFontChanged (EventArgs.Empty);
1998 [MWFCategory("Appearance")]
1999 public virtual Color ForeColor {
2001 if (foreground_color.IsEmpty) {
2003 return parent.ForeColor;
2005 return DefaultForeColor;
2007 return foreground_color;
2011 if (foreground_color != value) {
2012 foreground_color=value;
2014 OnForeColorChanged(EventArgs.Empty);
2021 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2022 public IntPtr Handle { // IWin32Window
2025 if (verify_thread_handle) {
2026 if (this.InvokeRequired) {
2027 throw new InvalidOperationException("Cross-thread access of handle detected. Handle access only valid on thread that created the control");
2031 if (!IsHandleCreated) {
2034 return window.Handle;
2038 [EditorBrowsable(EditorBrowsableState.Advanced)]
2040 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2041 public bool HasChildren {
2043 if (this.child_controls.Count>0) {
2050 [EditorBrowsable(EditorBrowsableState.Always)]
2052 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2055 return this.bounds.Height;
2059 SetBounds(bounds.X, bounds.Y, bounds.Width, value, BoundsSpecified.Height);
2063 [AmbientValue(ImeMode.Inherit)]
2065 [MWFCategory("Behavior")]
2066 public ImeMode ImeMode {
2068 if (ime_mode == DefaultImeMode) {
2070 return parent.ImeMode;
2072 return ImeMode.NoControl; // default value
2078 if (ime_mode != value) {
2081 OnImeModeChanged(EventArgs.Empty);
2086 [EditorBrowsable(EditorBrowsableState.Advanced)]
2088 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2089 public bool InvokeRequired { // ISynchronizeInvoke
2091 if (creator_thread != null && creator_thread!=Thread.CurrentThread) {
2098 [EditorBrowsable(EditorBrowsableState.Advanced)]
2100 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2101 public bool IsAccessible {
2103 return is_accessible;
2107 is_accessible = value;
2111 [EditorBrowsable(EditorBrowsableState.Advanced)]
2113 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2114 public bool IsDisposed {
2116 return this.is_disposed;
2120 [EditorBrowsable(EditorBrowsableState.Advanced)]
2122 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2123 public bool IsHandleCreated {
2125 if ((window != null) && (window.Handle != IntPtr.Zero)) {
2126 Hwnd hwnd = Hwnd.ObjectFromHandle (window.Handle);
2127 if (hwnd != null && !hwnd.zombie)
2136 public virtual Layout.LayoutEngine LayoutEngine {
2137 get { return this.layout_engine; }
2141 [EditorBrowsable(EditorBrowsableState.Always)]
2143 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2146 return this.bounds.X;
2150 SetBounds(value, bounds.Y, bounds.Width, bounds.Height, BoundsSpecified.X);
2155 [MWFCategory("Layout")]
2156 public Point Location {
2158 return new Point(bounds.X, bounds.Y);
2162 SetBounds(value.X, value.Y, bounds.Width, bounds.Height, BoundsSpecified.Location);
2167 [Localizable (true)]
2168 public Padding Margin {
2169 get { return this.margin; }
2170 set { this.margin = value; }
2175 public string Name {
2187 public Padding Padding {
2199 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2200 public Control Parent {
2206 if (value == this) {
2207 throw new ArgumentException("A circular control reference has been made. A control cannot be owned or parented to itself.");
2210 if (parent!=value) {
2212 parent.Controls.Remove(this);
2217 value.Controls.Add(this);
2222 [EditorBrowsable(EditorBrowsableState.Advanced)]
2224 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2225 public string ProductName {
2227 Type t = typeof (AssemblyProductAttribute);
2228 Assembly assembly = GetType().Module.Assembly;
2229 object [] attrs = assembly.GetCustomAttributes (t, false);
2230 AssemblyProductAttribute a = null;
2231 // On MS we get a NullRefException if product attribute is not
2233 if (attrs != null && attrs.Length > 0)
2234 a = (AssemblyProductAttribute) attrs [0];
2239 [EditorBrowsable(EditorBrowsableState.Advanced)]
2241 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2242 public string ProductVersion {
2244 Type t = typeof (AssemblyVersionAttribute);
2245 Assembly assembly = GetType().Module.Assembly;
2246 object [] attrs = assembly.GetCustomAttributes (t, false);
2247 if (attrs == null || attrs.Length < 1)
2249 return ((AssemblyVersionAttribute)attrs [0]).Version;
2253 [EditorBrowsable(EditorBrowsableState.Advanced)]
2255 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2256 public bool RecreatingHandle {
2258 return is_recreating;
2262 [EditorBrowsable(EditorBrowsableState.Advanced)]
2264 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2265 public Region Region {
2271 if (IsHandleCreated) {
2272 XplatUI.SetClipRegion(Handle, value);
2274 clip_region = value;
2278 [EditorBrowsable(EditorBrowsableState.Advanced)]
2280 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2283 return this.bounds.X+this.bounds.Width;
2287 [AmbientValue(RightToLeft.Inherit)]
2289 [MWFCategory("Appearance")]
2290 public virtual RightToLeft RightToLeft {
2292 if (right_to_left == RightToLeft.Inherit) {
2294 return parent.RightToLeft;
2296 return RightToLeft.No; // default value
2298 return right_to_left;
2302 if (value != right_to_left) {
2303 right_to_left = value;
2304 OnRightToLeftChanged(EventArgs.Empty);
2309 [EditorBrowsable(EditorBrowsableState.Advanced)]
2310 public override ISite Site {
2318 AmbientProperties ap = (AmbientProperties) value.GetService (typeof (AmbientProperties));
2320 BackColor = ap.BackColor;
2321 ForeColor = ap.ForeColor;
2329 [MWFCategory("Layout")]
2332 return new Size(Width, Height);
2336 SetBounds(bounds.X, bounds.Y, value.Width, value.Height, BoundsSpecified.Size);
2341 [MergableProperty(false)]
2342 [MWFCategory("Behavior")]
2343 public int TabIndex {
2345 if (tab_index != -1) {
2352 if (tab_index != value) {
2354 OnTabIndexChanged(EventArgs.Empty);
2360 [DefaultValue(true)]
2361 [MWFCategory("Behavior")]
2362 public bool TabStop {
2368 if (tab_stop != value) {
2370 OnTabStopChanged(EventArgs.Empty);
2375 [Localizable(false)]
2377 [TypeConverter(typeof(StringConverter))]
2378 [DefaultValue(null)]
2379 [MWFCategory("Data")]
2386 control_tag = value;
2392 [BindableAttribute(true)]
2393 [MWFCategory("Appearance")]
2394 public virtual string Text {
2396 // Our implementation ignores ControlStyles.CacheText - we always cache
2401 if (value == null) {
2402 value = String.Empty;
2407 if (IsHandleCreated) {
2408 /* we need to call .SetWindowStyle here instead of just .Text
2409 because the presence/absence of Text (== "" or not) can cause
2410 other window style things to appear/disappear */
2411 XplatUI.SetWindowStyle(window.Handle, CreateParams);
2412 XplatUI.Text(Handle, text);
2414 OnTextChanged (EventArgs.Empty);
2419 [EditorBrowsable(EditorBrowsableState.Always)]
2421 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2424 return this.bounds.Y;
2428 SetBounds(bounds.X, value, bounds.Width, bounds.Height, BoundsSpecified.Y);
2432 [EditorBrowsable(EditorBrowsableState.Advanced)]
2434 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2435 public Control TopLevelControl {
2439 while (p.parent != null) {
2448 [MWFCategory("Behavior")]
2449 public bool Visible {
2453 } else if (parent != null) {
2454 return parent.Visible;
2461 SetVisibleCore(value);
2465 [EditorBrowsable(EditorBrowsableState.Always)]
2467 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2470 return this.bounds.Width;
2474 SetBounds(bounds.X, bounds.Y, value, bounds.Height, BoundsSpecified.Width);
2478 [EditorBrowsable(EditorBrowsableState.Never)]
2480 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2481 public IWindowTarget WindowTarget {
2490 #endregion // Public Instance Properties
2492 #region Protected Instance Properties
2493 protected virtual CreateParams CreateParams {
2495 CreateParams create_params = new CreateParams();
2498 create_params.Caption = Text;
2501 create_params.Caption = text;
2505 create_params.X = Left;
2508 create_params.X = this.bounds.X;
2512 create_params.Y = Top;
2515 create_params.Y = this.bounds.Y;
2519 create_params.Width = Width;
2522 create_params.Width = this.bounds.Width;
2526 create_params.Height = Height;
2529 create_params.Height = this.bounds.Height;
2533 create_params.ClassName = XplatUI.DefaultClassName;
2534 create_params.ClassStyle = 0;
2535 create_params.ExStyle = 0;
2536 create_params.Param = 0;
2539 create_params.ExStyle |= (int)WindowExStyles.WS_EX_ACCEPTFILES;
2542 if ((parent!=null) && (parent.IsHandleCreated)) {
2543 create_params.Parent = parent.Handle;
2546 create_params.Style = (int)WindowStyles.WS_CHILD | (int)WindowStyles.WS_CLIPCHILDREN | (int)WindowStyles.WS_CLIPSIBLINGS;
2549 create_params.Style |= (int)WindowStyles.WS_VISIBLE;
2553 create_params.Style |= (int)WindowStyles.WS_DISABLED;
2556 switch (border_style) {
2557 case BorderStyle.FixedSingle:
2558 create_params.Style |= (int) WindowStyles.WS_BORDER;
2560 case BorderStyle.Fixed3D:
2561 create_params.ExStyle |= (int) WindowExStyles.WS_EX_CLIENTEDGE;
2565 return create_params;
2569 protected virtual ImeMode DefaultImeMode {
2571 return ImeMode.Inherit;
2576 protected virtual Padding DefaultMargin {
2577 get { return new Padding (3); }
2581 protected virtual Size DefaultSize {
2583 return new Size(0, 0);
2587 protected int FontHeight {
2597 protected bool RenderRightToLeft {
2599 return (this.right_to_left == RightToLeft.Yes);
2603 protected bool ResizeRedraw {
2605 return GetStyle(ControlStyles.ResizeRedraw);
2609 SetStyle(ControlStyles.ResizeRedraw, value);
2613 [EditorBrowsable(EditorBrowsableState.Advanced)]
2615 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2616 protected virtual bool ShowFocusCues {
2622 [EditorBrowsable(EditorBrowsableState.Advanced)]
2624 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2625 protected bool ShowKeyboardCues {
2630 #endregion // Protected Instance Properties
2632 #region Public Static Methods
2633 [EditorBrowsable(EditorBrowsableState.Advanced)]
2634 public static Control FromChildHandle(IntPtr handle) {
2635 lock (Control.controls) {
2636 IEnumerator control = Control.controls.GetEnumerator();
2638 while (control.MoveNext()) {
2639 if (((Control)control.Current).window.Handle == handle) {
2641 if (((Control)control.Current).Parent != null) {
2642 return ((Control)control.Current).Parent;
2650 [EditorBrowsable(EditorBrowsableState.Advanced)]
2651 public static Control FromHandle(IntPtr handle) {
2653 IEnumerator control = Control.controls.GetEnumerator();
2655 while (control.MoveNext()) {
2656 if (((Control)control.Current).window.Handle == handle) {
2658 return ((Control)control.Current);
2664 return Control.ControlNativeWindow.ControlFromHandle(handle);
2668 public static bool IsMnemonic(char charCode, string text) {
2671 amp = text.IndexOf('&');
2674 if (amp + 1 < text.Length) {
2675 if (text[amp + 1] != '&') {
2676 if (Char.ToUpper(charCode) == Char.ToUpper(text.ToCharArray(amp + 1, 1)[0])) {
2686 #region Protected Static Methods
2687 [EditorBrowsable(EditorBrowsableState.Advanced)]
2688 protected static bool ReflectMessage(IntPtr hWnd, ref Message m) {
2691 c = Control.FromHandle(hWnd);
2701 #region Public Instance Methods
2702 [EditorBrowsable(EditorBrowsableState.Advanced)]
2703 public IAsyncResult BeginInvoke(Delegate method) {
2704 object [] prms = null;
2705 if (method is EventHandler)
2706 prms = new object [] { this, EventArgs.Empty };
2707 return BeginInvokeInternal(method, prms, false);
2710 [EditorBrowsable(EditorBrowsableState.Advanced)]
2711 public IAsyncResult BeginInvoke (Delegate method, object[] args) {
2712 return BeginInvokeInternal (method, args, false);
2715 public void BringToFront() {
2716 if (parent != null) {
2717 parent.child_controls.SetChildIndex(this, 0);
2720 XplatUI.SetZOrder(Handle, IntPtr.Zero, false, false);
2724 public bool Contains(Control ctl) {
2725 while (ctl != null) {
2734 public void CreateControl() {
2736 throw new ObjectDisposedException(GetType().FullName.ToString());
2742 if (!IsHandleCreated) {
2750 Control [] controls = child_controls.GetAllControls ();
2751 for (int i=0; i<controls.Length; i++) {
2752 controls [i].CreateControl ();
2755 UpdateChildrenZOrder();
2757 if (binding_context == null) { // seem to be sent whenever it's null?
2758 OnBindingContextChanged(EventArgs.Empty);
2764 public Graphics CreateGraphics() {
2765 if (!IsHandleCreated) {
2766 this.CreateHandle();
2768 return Graphics.FromHwnd(this.window.Handle);
2771 public DragDropEffects DoDragDrop(object data, DragDropEffects allowedEffects) {
2772 return XplatUI.StartDrag(this.window.Handle, data, allowedEffects);
2775 [EditorBrowsable(EditorBrowsableState.Advanced)]
2776 public object EndInvoke (IAsyncResult async_result) {
2777 AsyncMethodResult result = (AsyncMethodResult) async_result;
2778 return result.EndInvoke ();
2781 public Form FindForm() {
2794 public bool Focus() {
2795 if (CanFocus && IsHandleCreated && !has_focus) {
2801 public Control GetChildAtPoint(Point pt) {
2802 // Microsoft's version of this function doesn't seem to work, so I can't check
2803 // if we only consider children or also grandchildren, etc.
2804 // I'm gonna say 'children only'
2805 for (int i=0; i<child_controls.Count; i++) {
2806 if (child_controls[i].Bounds.Contains(pt)) {
2807 return child_controls[i];
2813 public IContainerControl GetContainerControl() {
2814 Control current = this;
2816 while (current!=null) {
2817 if ((current is IContainerControl) && ((current.control_style & ControlStyles.ContainerControl)!=0)) {
2818 return (IContainerControl)current;
2820 current = current.parent;
2825 public Control GetNextControl(Control ctl, bool forward) {
2828 if ((parent == null) && (ctl is IContainerControl) && ctl.GetStyle(ControlStyles.ContainerControl)) {
2830 return FindFlatForward(this, ctl);
2832 return FindFlatBackward(this, ctl);
2837 // If ctl is not contained by this, we start at the first child of this
2838 if (!this.Contains(ctl)) {
2842 // Search through our controls, starting at ctl, stepping into children as we encounter them
2843 // try to find the control with the tabindex closest to our own, or, if we're looking into
2844 // child controls, the one with the smallest tabindex
2846 return FindControlForward(this, ctl);
2848 return FindControlBackward(this, ctl);
2852 public virtual Size GetPreferredSize (Size proposedSize) {
2853 return preferred_size;
2857 public void Hide() {
2858 this.Visible = false;
2861 public void Invalidate() {
2862 Invalidate(ClientRectangle, false);
2865 public void Invalidate(bool invalidateChildren) {
2866 Invalidate(ClientRectangle, invalidateChildren);
2869 public void Invalidate(System.Drawing.Rectangle rc) {
2870 Invalidate(rc, false);
2873 public void Invalidate(System.Drawing.Rectangle rc, bool invalidateChildren) {
2874 if (!IsHandleCreated || !Visible || rc.Width == 0 || rc.Height == 0) {
2878 NotifyInvalidate(rc);
2880 XplatUI.Invalidate(Handle, rc, false);
2882 if (invalidateChildren) {
2883 Control [] controls = child_controls.GetAllControls ();
2884 for (int i=0; i<controls.Length; i++)
2885 controls [i].Invalidate ();
2887 OnInvalidated(new InvalidateEventArgs(rc));
2890 public void Invalidate(System.Drawing.Region region) {
2891 Invalidate(region, false);
2894 public void Invalidate(System.Drawing.Region region, bool invalidateChildren) {
2895 RectangleF bounds = region.GetBounds (CreateGraphics ());
2896 Invalidate (new Rectangle ((int) bounds.X, (int) bounds.Y, (int) bounds.Width, (int) bounds.Height),
2897 invalidateChildren);
2900 public object Invoke (Delegate method) {
2901 object [] prms = null;
2902 if (method is EventHandler)
2903 prms = new object [] { this, EventArgs.Empty };
2905 return Invoke(method, prms);
2908 public object Invoke (Delegate method, object[] args) {
2909 if (!this.InvokeRequired) {
2910 return method.DynamicInvoke(args);
2913 IAsyncResult result = BeginInvoke (method, args);
2914 return EndInvoke(result);
2917 internal object InvokeInternal (Delegate method, bool disposing) {
2918 return InvokeInternal(method, null, disposing);
2921 internal object InvokeInternal (Delegate method, object[] args, bool disposing) {
2922 if (!this.InvokeRequired) {
2923 return method.DynamicInvoke(args);
2926 IAsyncResult result = BeginInvokeInternal (method, args, disposing);
2927 return EndInvoke(result);
2930 [EditorBrowsable(EditorBrowsableState.Advanced)]
2931 public void PerformLayout() {
2932 PerformLayout(null, null);
2935 [EditorBrowsable(EditorBrowsableState.Advanced)]
2936 public void PerformLayout(Control affectedControl, string affectedProperty) {
2937 LayoutEventArgs levent = new LayoutEventArgs(affectedControl, affectedProperty);
2939 if (layout_suspended > 0) {
2940 layout_pending = true;
2944 layout_pending = false;
2946 // Prevent us from getting messed up
2949 // Perform all Dock and Anchor calculations
2953 this.layout_engine.Layout(this, levent);
2955 // This has been moved to Layout/DefaultLayout.cs for 2.0, please duplicate any changes/fixes there.
2957 AnchorStyles anchor;
2960 space = DisplayRectangle;
2962 // Deal with docking; go through in reverse, MS docs say that lowest Z-order is closest to edge
2963 Control [] controls = child_controls.GetAllControls ();
2964 for (int i = controls.Length - 1; i >= 0; i--) {
2965 child = controls [i];
2967 if (!child.Visible) {
2971 switch (child.Dock) {
2972 case DockStyle.None: {
2977 case DockStyle.Left: {
2978 child.SetBounds(space.Left, space.Y, child.Width, space.Height);
2979 space.X+=child.Width;
2980 space.Width-=child.Width;
2984 case DockStyle.Top: {
2985 child.SetBounds(space.Left, space.Y, space.Width, child.Height);
2986 space.Y+=child.Height;
2987 space.Height-=child.Height;
2991 case DockStyle.Right: {
2992 child.SetBounds(space.Right-child.Width, space.Y, child.Width, space.Height);
2993 space.Width-=child.Width;
2997 case DockStyle.Bottom: {
2998 child.SetBounds(space.Left, space.Bottom-child.Height, space.Width, child.Height);
2999 space.Height-=child.Height;
3005 for (int i = controls.Length - 1; i >= 0; i--) {
3008 //if (child.Visible && (child.Dock == DockStyle.Fill)) {
3009 if (child.Dock == DockStyle.Fill) {
3010 child.SetBounds(space.Left, space.Top, space.Width, space.Height);
3014 space = DisplayRectangle;
3016 for (int i=0; i < controls.Length; i++) {
3022 child = controls[i];
3024 // If the control is docked we don't need to do anything
3025 if (child.Dock != DockStyle.None) {
3029 anchor = child.Anchor;
3033 width = child.Width;
3034 height = child.Height;
3036 if ((anchor & AnchorStyles.Left) !=0 ) {
3037 if ((anchor & AnchorStyles.Right) != 0) {
3038 width = space.Width - child.dist_right - left;
3040 ; // Left anchored only, nothing to be done
3042 } else if ((anchor & AnchorStyles.Right) != 0) {
3043 left = space.Width - child.dist_right - width;
3045 // left+=diff_width/2 will introduce rounding errors (diff_width removed from svn after r51780)
3046 // This calculates from scratch every time:
3047 left = child.dist_left + (space.Width - (child.dist_left + width + child.dist_right)) / 2;
3050 if ((anchor & AnchorStyles.Top) !=0 ) {
3051 if ((anchor & AnchorStyles.Bottom) != 0) {
3052 height = space.Height - child.dist_bottom - top;
3054 ; // Top anchored only, nothing to be done
3056 } else if ((anchor & AnchorStyles.Bottom) != 0) {
3057 top = space.Height - child.dist_bottom - height;
3059 // top += diff_height/2 will introduce rounding errors (diff_height removed from after r51780)
3060 // This calculates from scratch every time:
3061 top = child.dist_top + (space.Height - (child.dist_top + height + child.dist_bottom)) / 2;
3073 child.SetBounds(left, top, width, height);
3077 // Let everyone know
3081 // Need to make sure we decremend layout_suspended
3087 public Point PointToClient (Point p) {
3091 XplatUI.ScreenToClient (Handle, ref x, ref y);
3093 return new Point (x, y);
3096 public Point PointToScreen(Point p) {
3100 XplatUI.ClientToScreen(Handle, ref x, ref y);
3102 return new Point(x, y);
3105 public virtual bool PreProcessMessage(ref Message msg) {
3106 return InternalPreProcessMessage (ref msg);
3109 internal virtual bool InternalPreProcessMessage (ref Message msg) {
3112 if ((msg.Msg == (int)Msg.WM_KEYDOWN) || (msg.Msg == (int)Msg.WM_SYSKEYDOWN)) {
3113 key_data = (Keys)msg.WParam.ToInt32() | XplatUI.State.ModifierKeys;
3115 if (!ProcessCmdKey(ref msg, key_data)) {
3116 if (IsInputKey(key_data)) {
3120 return ProcessDialogKey(key_data);
3124 } else if (msg.Msg == (int)Msg.WM_CHAR) {
3125 if (IsInputChar((char)msg.WParam)) {
3128 return ProcessDialogChar((char)msg.WParam);
3129 } else if (msg.Msg == (int)Msg.WM_SYSCHAR) {
3130 return ProcessDialogChar((char)msg.WParam);
3135 public Rectangle RectangleToClient(Rectangle r) {
3136 return new Rectangle(PointToClient(r.Location), r.Size);
3139 public Rectangle RectangleToScreen(Rectangle r) {
3140 return new Rectangle(PointToScreen(r.Location), r.Size);
3143 public virtual void Refresh() {
3144 if (IsHandleCreated == true) {
3146 XplatUI.UpdateWindow(window.Handle);
3148 Control [] controls = child_controls.GetAllControls ();
3149 for (int i=0; i < controls.Length; i++) {
3150 controls[i].Refresh();
3156 [EditorBrowsable(EditorBrowsableState.Never)]
3157 public virtual void ResetBackColor() {
3158 BackColor = Color.Empty;
3161 [EditorBrowsable(EditorBrowsableState.Never)]
3162 public void ResetBindings() {
3163 data_bindings.Clear();
3166 [EditorBrowsable(EditorBrowsableState.Never)]
3167 public virtual void ResetCursor() {
3171 [EditorBrowsable(EditorBrowsableState.Never)]
3172 public virtual void ResetFont() {
3176 [EditorBrowsable(EditorBrowsableState.Never)]
3177 public virtual void ResetForeColor() {
3178 foreground_color = Color.Empty;
3181 [EditorBrowsable(EditorBrowsableState.Never)]
3182 public void ResetImeMode() {
3183 ime_mode = DefaultImeMode;
3186 [EditorBrowsable(EditorBrowsableState.Never)]
3187 public virtual void ResetRightToLeft() {
3188 right_to_left = RightToLeft.Inherit;
3191 public virtual void ResetText() {
3192 text = String.Empty;
3195 public void ResumeLayout() {
3196 ResumeLayout (true);
3199 public void ResumeLayout(bool performLayout) {
3200 if (layout_suspended > 0) {
3204 if (layout_suspended == 0) {
3205 Control [] controls = child_controls.GetAllControls ();
3206 for (int i=0; i<controls.Length; i++) {
3207 controls [i].UpdateDistances ();
3210 if (performLayout && layout_pending) {
3216 public void Scale(float ratio) {
3217 ScaleCore(ratio, ratio);
3220 public void Scale(float dx, float dy) {
3225 public void Scale(SizeF factor) {
3226 ScaleCore(factor.Width, factor.Height);
3230 public void Select() {
3231 Select(false, false);
3234 public bool SelectNextControl(Control ctl, bool forward, bool tabStopOnly, bool nested, bool wrap) {
3239 c = GetNextControl(c, forward);
3248 if (c.CanSelect && ((c.parent == this) || nested) && (c.tab_stop || !tabStopOnly)) {
3249 c.Select (true, true);
3252 } while (c != ctl); // If we wrap back to ourselves we stop
3257 public void SendToBack() {
3258 if (parent != null) {
3259 parent.child_controls.SetChildIndex(this, parent.child_controls.Count);
3263 public void SetBounds(int x, int y, int width, int height) {
3264 SetBounds(x, y, width, height, BoundsSpecified.All);
3267 public void SetBounds(int x, int y, int width, int height, BoundsSpecified specified) {
3268 if ((specified & BoundsSpecified.X) != BoundsSpecified.X) {
3272 if ((specified & BoundsSpecified.Y) != BoundsSpecified.Y) {
3276 if ((specified & BoundsSpecified.Width) != BoundsSpecified.Width) {
3280 if ((specified & BoundsSpecified.Height) != BoundsSpecified.Height) {
3284 SetBoundsCore(x, y, width, height, specified);
3285 if (parent != null) {
3286 parent.PerformLayout(this, "Bounds");
3290 public void Show() {
3292 this.CreateControl();
3298 public void SuspendLayout() {
3302 public void Update() {
3303 if (IsHandleCreated) {
3304 XplatUI.UpdateWindow(window.Handle);
3307 #endregion // Public Instance Methods
3309 #region Protected Instance Methods
3310 [EditorBrowsable(EditorBrowsableState.Advanced)]
3311 [MonoTODO("Implement this and tie it into Control.ControlAccessibleObject.NotifyClients")]
3312 protected void AccessibilityNotifyClients(AccessibleEvents accEvent, int childID) {
3313 throw new NotImplementedException();
3316 [EditorBrowsable(EditorBrowsableState.Advanced)]
3317 protected virtual AccessibleObject CreateAccessibilityInstance() {
3318 return new Control.ControlAccessibleObject(this);
3321 [EditorBrowsable(EditorBrowsableState.Advanced)]
3322 protected virtual ControlCollection CreateControlsInstance() {
3323 return new ControlCollection(this);
3326 [EditorBrowsable(EditorBrowsableState.Advanced)]
3327 protected virtual void CreateHandle() {
3329 throw new ObjectDisposedException(GetType().FullName.ToString());
3332 if (IsHandleCreated && !is_recreating) {
3336 window.CreateHandle(CreateParams);
3338 if (window.Handle != IntPtr.Zero) {
3339 lock (Control.controls) {
3340 if (!Control.controls.Contains(window.Handle)) {
3341 Control.controls.Add(this);
3345 creator_thread = Thread.CurrentThread;
3347 XplatUI.EnableWindow(window.Handle, is_enabled);
3348 XplatUI.SetVisible(window.Handle, is_visible);
3350 if (clip_region != null) {
3351 XplatUI.SetClipRegion(Handle, clip_region);
3354 // Set our handle with our parent
3355 if ((parent != null) && (parent.IsHandleCreated)) {
3356 XplatUI.SetParent(window.Handle, parent.Handle);
3359 // Set our handle as parent for our children
3360 Control [] children;
3362 children = child_controls.GetAllControls ();
3363 for (int i = 0; i < children.Length; i++ ) {
3364 if (children[i].IsHandleCreated) {
3365 XplatUI.SetParent(children[i].Handle, window.Handle);
3370 XplatUI.SetAllowDrop (Handle, allow_drop);
3372 // Find out where the window manager placed us
3373 if ((CreateParams.Style & (int)WindowStyles.WS_CHILD) != 0) {
3374 XplatUI.SetBorderStyle(window.Handle, (FormBorderStyle)border_style);
3378 OnHandleCreated(EventArgs.Empty);
3382 [EditorBrowsable(EditorBrowsableState.Advanced)]
3383 protected virtual void DefWndProc(ref Message m) {
3384 window.DefWndProc(ref m);
3387 [EditorBrowsable(EditorBrowsableState.Advanced)]
3388 protected virtual void DestroyHandle() {
3389 if (IsHandleCreated) {
3390 if (window != null) {
3391 window.DestroyHandle();
3396 protected bool GetStyle(ControlStyles flag) {
3397 return (control_style & flag) != 0;
3400 protected bool GetTopLevel() {
3404 [EditorBrowsable(EditorBrowsableState.Advanced)]
3405 protected virtual void InitLayout() {
3409 [EditorBrowsable(EditorBrowsableState.Advanced)]
3410 protected void InvokeGotFocus(Control toInvoke, EventArgs e) {
3411 toInvoke.OnGotFocus(e);
3414 [EditorBrowsable(EditorBrowsableState.Advanced)]
3415 protected void InvokeLostFocus(Control toInvoke, EventArgs e) {
3416 toInvoke.OnLostFocus(e);
3419 [EditorBrowsable(EditorBrowsableState.Advanced)]
3420 protected void InvokeOnClick(Control toInvoke, EventArgs e) {
3421 toInvoke.OnClick(e);
3424 protected void InvokePaint(Control toInvoke, PaintEventArgs e) {
3425 toInvoke.OnPaint(e);
3428 protected void InvokePaintBackground(Control toInvoke, PaintEventArgs e) {
3429 toInvoke.OnPaintBackground(e);
3432 protected virtual bool IsInputChar (char charCode) {
3436 protected virtual bool IsInputKey (Keys keyData) {
3437 // Doc says this one calls IsInputChar; not sure what to do with that
3441 [EditorBrowsable(EditorBrowsableState.Advanced)]
3442 protected virtual void NotifyInvalidate(Rectangle invalidatedArea) {
3446 protected virtual bool ProcessCmdKey(ref Message msg, Keys keyData) {
3447 if ((context_menu != null) && context_menu.ProcessCmdKey(ref msg, keyData)) {
3451 if (parent != null) {
3452 return parent.ProcessCmdKey(ref msg, keyData);
3458 protected virtual bool ProcessDialogChar(char charCode) {
3459 if (parent != null) {
3460 return parent.ProcessDialogChar (charCode);
3466 protected virtual bool ProcessDialogKey (Keys keyData) {
3467 if (parent != null) {
3468 return parent.ProcessDialogKey (keyData);
3474 protected virtual bool ProcessKeyEventArgs (ref Message msg)
3476 KeyEventArgs key_event;
3479 case (int)Msg.WM_SYSKEYDOWN:
3480 case (int)Msg.WM_KEYDOWN: {
3481 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
3482 OnKeyDown (key_event);
3483 return key_event.Handled;
3486 case (int)Msg.WM_SYSKEYUP:
3487 case (int)Msg.WM_KEYUP: {
3488 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
3489 OnKeyUp (key_event);
3490 return key_event.Handled;
3493 case (int)Msg.WM_SYSCHAR:
3494 case (int)Msg.WM_CHAR: {
3495 KeyPressEventArgs key_press_event;
3497 key_press_event = new KeyPressEventArgs((char)msg.WParam);
3498 OnKeyPress(key_press_event);
3500 msg.WParam = (IntPtr)key_press_event.KeyChar;
3502 return key_press_event.Handled;
3513 protected internal virtual bool ProcessKeyMessage(ref Message msg) {
3514 if (parent != null) {
3515 if (parent.ProcessKeyPreview(ref msg)) {
3520 return ProcessKeyEventArgs(ref msg);
3523 protected virtual bool ProcessKeyPreview(ref Message msg) {
3524 if (parent != null) {
3525 return parent.ProcessKeyPreview(ref msg);
3531 protected virtual bool ProcessMnemonic(char charCode) {
3536 [EditorBrowsable(EditorBrowsableState.Advanced)]
3537 protected void RaiseDragEvent(object key, DragEventArgs e) {
3541 [EditorBrowsable(EditorBrowsableState.Advanced)]
3542 protected void RaiseKeyEvent(object key, KeyEventArgs e) {
3546 [EditorBrowsable(EditorBrowsableState.Advanced)]
3547 protected void RaiseMouseEvent(object key, MouseEventArgs e) {
3551 [EditorBrowsable(EditorBrowsableState.Advanced)]
3552 protected void RaisePaintEvent(object key, PaintEventArgs e) {
3556 private void SetIsRecreating ()
3560 foreach (Control c in Controls.GetAllControls()) {
3561 c.SetIsRecreating ();
3565 [EditorBrowsable(EditorBrowsableState.Advanced)]
3566 protected void RecreateHandle() {
3568 Console.WriteLine("Recreating control {0}", XplatUI.Window(window.Handle));
3573 if (IsHandleCreated) {
3575 Console.WriteLine(" + handle is created, destroying it.");
3578 // WM_DESTROY will CreateHandle for us
3581 Console.WriteLine(" + handle is not created, creating it.");
3589 is_recreating = false;
3591 Console.WriteLine (" + new handle = {0:X}", Handle.ToInt32());
3597 [EditorBrowsable(EditorBrowsableState.Advanced)]
3598 protected void ResetMouseEventArgs() {
3602 [EditorBrowsable(EditorBrowsableState.Advanced)]
3603 protected ContentAlignment RtlTranslateAlignment(ContentAlignment align) {
3604 if (right_to_left == RightToLeft.No) {
3609 case ContentAlignment.TopLeft: {
3610 return ContentAlignment.TopRight;
3613 case ContentAlignment.TopRight: {
3614 return ContentAlignment.TopLeft;
3617 case ContentAlignment.MiddleLeft: {
3618 return ContentAlignment.MiddleRight;
3621 case ContentAlignment.MiddleRight: {
3622 return ContentAlignment.MiddleLeft;
3625 case ContentAlignment.BottomLeft: {
3626 return ContentAlignment.BottomRight;
3629 case ContentAlignment.BottomRight: {
3630 return ContentAlignment.BottomLeft;
3634 // if it's center it doesn't change
3640 [EditorBrowsable(EditorBrowsableState.Advanced)]
3641 protected HorizontalAlignment RtlTranslateAlignment(HorizontalAlignment align) {
3642 if ((right_to_left == RightToLeft.No) || (align == HorizontalAlignment.Center)) {
3646 if (align == HorizontalAlignment.Left) {
3647 return HorizontalAlignment.Right;
3650 // align must be HorizontalAlignment.Right
3651 return HorizontalAlignment.Left;
3654 [EditorBrowsable(EditorBrowsableState.Advanced)]
3655 protected LeftRightAlignment RtlTranslateAlignment(LeftRightAlignment align) {
3656 if (right_to_left == RightToLeft.No) {
3660 if (align == LeftRightAlignment.Left) {
3661 return LeftRightAlignment.Right;
3664 // align must be LeftRightAlignment.Right;
3665 return LeftRightAlignment.Left;
3668 [EditorBrowsable(EditorBrowsableState.Advanced)]
3669 protected ContentAlignment RtlTranslateContent(ContentAlignment align) {
3670 return RtlTranslateAlignment(align);
3673 [EditorBrowsable(EditorBrowsableState.Advanced)]
3674 protected HorizontalAlignment RtlTranslateHorizontal(HorizontalAlignment align) {
3675 return RtlTranslateAlignment(align);
3678 [EditorBrowsable(EditorBrowsableState.Advanced)]
3679 protected LeftRightAlignment RtlTranslateLeftRight(LeftRightAlignment align) {
3680 return RtlTranslateAlignment(align);
3683 [EditorBrowsable(EditorBrowsableState.Advanced)]
3684 protected virtual void ScaleCore(float dx, float dy) {
3690 location = new Point((int)(Left * dx), (int)(Top * dy));
3691 size = this.ClientSize;
3693 if (!GetStyle(ControlStyles.FixedWidth)) {
3694 size.Width = (int)(size.Width * dx);
3697 if (!GetStyle(ControlStyles.FixedHeight)) {
3698 size.Height = (int)(size.Height * dy);
3701 SetBounds(location.X, location.Y, size.Width, size.Height, BoundsSpecified.All);
3703 /* Now scale our children */
3704 Control [] controls = child_controls.GetAllControls ();
3705 for (int i=0; i < controls.Length; i++) {
3706 controls[i].Scale(dx, dy);
3712 protected virtual void Select(bool directed, bool forward) {
3713 IContainerControl container;
3715 container = GetContainerControl();
3716 if (container != null)
3717 container.ActiveControl = this;
3720 [EditorBrowsable(EditorBrowsableState.Advanced)]
3721 protected virtual void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
3722 // SetBoundsCore updates the Win32 control itself. UpdateBounds updates the controls variables and fires events, I'm guessing - pdb
3723 if (IsHandleCreated) {
3724 XplatUI.SetWindowPos(Handle, x, y, width, height);
3727 UpdateBounds(x, y, width, height);
3732 [EditorBrowsable(EditorBrowsableState.Advanced)]
3733 protected virtual void SetClientSizeCore(int x, int y) {
3734 // Calculate the actual window size from the client size (it usually stays the same or grows)
3735 Rectangle ClientRect;
3736 Rectangle WindowRect;
3739 ClientRect = new Rectangle(0, 0, x, y);
3740 cp = this.CreateParams;
3742 if (XplatUI.CalculateWindowRect(ref ClientRect, cp.Style, cp.ExStyle, null, out WindowRect)==false) {
3746 SetBounds(bounds.X, bounds.Y, WindowRect.Width, WindowRect.Height, BoundsSpecified.Size);
3749 [EditorBrowsable(EditorBrowsableState.Advanced)]
3750 protected void SetStyle(ControlStyles flag, bool value) {
3752 control_style |= flag;
3754 control_style &= ~flag;
3758 protected void SetTopLevel(bool value) {
3759 if ((GetTopLevel() != value) && (parent != null)) {
3760 throw new Exception();
3764 if (value == true) {
3774 is_toplevel = value;
3777 protected virtual void SetVisibleCore(bool value) {
3778 if (value!=is_visible) {
3779 if (value && (window.Handle == IntPtr.Zero) || !is_created) {
3785 if (IsHandleCreated) {
3786 XplatUI.SetVisible(Handle, value);
3787 // Explicitly move Toplevel windows to where we want them;
3788 // apparently moving unmapped toplevel windows doesn't work
3789 if (is_visible && (this is Form)) {
3790 XplatUI.SetWindowPos(window.Handle, bounds.X, bounds.Y, bounds.Width, bounds.Height);
3794 OnVisibleChanged(EventArgs.Empty);
3796 if (value == false && parent != null && Focused) {
3799 // Need to start at parent, GetContainerControl might return ourselves if we're a container
3800 container = (Control)parent.GetContainerControl();
3801 if (container != null) {
3802 container.SelectNextControl(this, true, true, true, true);
3806 if (parent != null) {
3807 parent.PerformLayout(this, "visible");
3809 PerformLayout(this, "visible");
3814 [EditorBrowsable(EditorBrowsableState.Advanced)]
3815 protected void UpdateBounds() {
3823 if (!IsHandleCreated) {
3827 XplatUI.GetWindowPos(this.Handle, this is Form, out x, out y, out width, out height, out client_width, out client_height);
3829 UpdateBounds(x, y, width, height, client_width, client_height);
3832 [EditorBrowsable(EditorBrowsableState.Advanced)]
3833 protected void UpdateBounds(int x, int y, int width, int height) {
3837 // Calculate client rectangle
3838 rect = new Rectangle(0, 0, 0, 0);
3841 XplatUI.CalculateWindowRect(ref rect, cp.Style, cp.ExStyle, cp.menu, out rect);
3842 UpdateBounds(x, y, width, height, width - (rect.Right - rect.Left), height - (rect.Bottom - rect.Top));
3845 [EditorBrowsable(EditorBrowsableState.Advanced)]
3846 protected void UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) {
3847 // UpdateBounds only seems to set our sizes and fire events but not update the GUI window to match
3849 bool resized = false;
3851 // Needed to generate required notifications
3852 if ((this.bounds.X!=x) || (this.bounds.Y!=y)) {
3856 if ((this.Bounds.Width!=width) || (this.Bounds.Height!=height)) {
3863 bounds.Height=height;
3865 client_size.Width=clientWidth;
3866 client_size.Height=clientHeight;
3869 OnLocationChanged(EventArgs.Empty);
3873 OnSizeChanged(EventArgs.Empty);
3877 [EditorBrowsable(EditorBrowsableState.Advanced)]
3878 protected void UpdateStyles() {
3879 if (!IsHandleCreated) {
3883 XplatUI.SetWindowStyle(window.Handle, CreateParams);
3884 OnStyleChanged(EventArgs.Empty);
3887 private void UpdateZOrderOfChild(Control child) {
3888 if (IsHandleCreated && child.IsHandleCreated && (child.parent == this)) {
3891 index = child_controls.IndexOf(child);
3894 XplatUI.SetZOrder(child.Handle, child_controls[index - 1].Handle, false, false);
3896 XplatUI.SetZOrder(child.Handle, IntPtr.Zero, true, false);
3901 private void UpdateChildrenZOrder() {
3902 Control [] controls;
3904 if (!IsHandleCreated) {
3908 controls = child_controls.GetAllControls ();
3909 for (int i = 1; i < controls.Length; i++ ) {
3910 XplatUI.SetZOrder(controls[i].Handle, controls[i-1].Handle, false, false);
3914 [EditorBrowsable(EditorBrowsableState.Advanced)]
3915 protected void UpdateZOrder() {
3916 if (parent != null) {
3917 parent.UpdateZOrderOfChild(this);
3921 protected virtual void WndProc(ref Message m) {
3923 Console.WriteLine("Control {0} received message {1}", window.Handle == IntPtr.Zero ? this.Text : XplatUI.Window(window.Handle), (Msg)m.Msg);
3925 if ((this.control_style & ControlStyles.EnableNotifyMessage) != 0) {
3929 switch((Msg)m.Msg) {
3930 case Msg.WM_DESTROY: {
3931 OnHandleDestroyed(EventArgs.Empty);
3933 IntPtr handle = window.Handle;
3935 window.InvalidateHandle();
3937 if (is_recreating) {
3939 Console.WriteLine ("Creating handle for {0:X}", handle.ToInt32());
3943 Console.WriteLine (" + new handle = {0:X}", Handle.ToInt32());
3945 is_recreating = false;
3950 case Msg.WM_WINDOWPOSCHANGED: {
3953 if (GetStyle(ControlStyles.ResizeRedraw)) {
3960 // Nice description of what should happen when handling WM_PAINT
3961 // can be found here: http://pluralsight.com/wiki/default.aspx/Craig/FlickerFreeControlDrawing.html
3962 // and here http://msdn.microsoft.com/msdnmag/issues/06/03/WindowsFormsPerformance/
3963 case Msg.WM_PAINT: {
3964 PaintEventArgs paint_event;
3966 paint_event = XplatUI.PaintEventStart(Handle, true);
3968 if (paint_event == null) {
3972 if (invalid_region != null && !invalid_region.IsVisible (paint_event.ClipRectangle)) {
3973 // Just blit the previous image
3974 paint_event.Graphics.DrawImage (ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle, GraphicsUnit.Pixel);
3975 XplatUI.PaintEventEnd(Handle, true);
3980 Graphics back_dc = null;
3981 Bitmap backbuffer = null;
3982 if (ThemeEngine.Current.DoubleBufferingSupported) {
3983 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
3984 backbuffer = ImageBuffer;
3985 back_dc = Graphics.FromImage (backbuffer);
3986 dc = paint_event.SetGraphics (back_dc);
3990 if (!GetStyle(ControlStyles.Opaque)) {
3991 OnPaintBackground(paint_event);
3994 // Button-derived controls choose to ignore their Opaque style, give them a chance to draw their background anyways
3995 OnPaintBackgroundInternal(paint_event);
3997 OnPaintInternal(paint_event);
3998 if (!paint_event.Handled) {
3999 OnPaint(paint_event);
4002 if (ThemeEngine.Current.DoubleBufferingSupported)
4003 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
4004 dc.DrawImage (ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle, GraphicsUnit.Pixel);
4005 paint_event.SetGraphics (dc);
4006 invalid_region.Exclude (paint_event.ClipRectangle);
4008 if (backbuffer != bmp_mem)
4009 backbuffer.Dispose();
4012 XplatUI.PaintEventEnd(Handle, true);
4017 case Msg.WM_ERASEBKGND: {
4018 // The DefWndProc will never have to handle this, we always paint the background in managed code
4019 // In theory this code would look at ControlStyles.AllPaintingInWmPaint and and call OnPaintBackground
4020 // here but it just makes things more complicated...
4021 m.Result = (IntPtr)1;
4025 case Msg.WM_LBUTTONUP: {
4028 me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Left,
4030 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4033 HandleClick(mouse_clicks, me);
4036 if (InternalCapture) {
4037 InternalCapture = false;
4040 if (mouse_clicks > 1) {
4046 case Msg.WM_LBUTTONDOWN: {
4048 Select (true, true);
4050 InternalCapture = true;
4051 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4052 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4058 case Msg.WM_LBUTTONDBLCLK: {
4059 InternalCapture = true;
4061 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4062 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4068 case Msg.WM_MBUTTONUP: {
4071 me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Middle,
4073 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4076 HandleClick(mouse_clicks, me);
4078 if (InternalCapture) {
4079 InternalCapture = false;
4081 if (mouse_clicks > 1) {
4087 case Msg.WM_MBUTTONDOWN: {
4088 InternalCapture = true;
4089 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4090 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4096 case Msg.WM_MBUTTONDBLCLK: {
4097 InternalCapture = true;
4099 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4100 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4105 case Msg.WM_RBUTTONUP: {
4109 pt = new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()));
4110 pt = PointToScreen(pt);
4112 XplatUI.SendMessage(m.HWnd, Msg.WM_CONTEXTMENU, m.HWnd, (IntPtr)(pt.X + (pt.Y << 16)));
4114 me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Right,
4116 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4119 HandleClick(mouse_clicks, me);
4122 if (InternalCapture) {
4123 InternalCapture = false;
4126 if (mouse_clicks > 1) {
4132 case Msg.WM_RBUTTONDOWN: {
4133 InternalCapture = true;
4134 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4135 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4140 case Msg.WM_RBUTTONDBLCLK: {
4141 InternalCapture = true;
4143 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4144 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4149 case Msg.WM_CONTEXTMENU: {
4150 if (context_menu != null) {
4153 pt = new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()));
4154 context_menu.Show(this, PointToClient(pt));
4162 case Msg.WM_MOUSEWHEEL: {
4164 OnMouseWheel (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4165 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4166 HighOrder(m.WParam.ToInt32())));
4171 case Msg.WM_MOUSEMOVE: {
4172 OnMouseMove (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4174 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4179 case Msg.WM_MOUSE_ENTER: {
4184 OnMouseEnter(EventArgs.Empty);
4188 case Msg.WM_MOUSE_LEAVE: {
4190 OnMouseLeave(EventArgs.Empty);
4194 case Msg.WM_MOUSEHOVER: {
4195 OnMouseHover(EventArgs.Empty);
4199 case Msg.WM_SYSKEYUP: {
4200 if (ProcessKeyMessage(ref m)) {
4201 m.Result = IntPtr.Zero;
4205 if ((m.WParam.ToInt32() & (int)Keys.KeyCode) == (int)Keys.Menu) {
4209 if (form != null && form.ActiveMenu != null) {
4210 form.ActiveMenu.ProcessCmdKey(ref m, (Keys)m.WParam.ToInt32());
4218 case Msg.WM_SYSKEYDOWN:
4219 case Msg.WM_KEYDOWN:
4221 case Msg.WM_SYSCHAR:
4223 if (ProcessKeyMessage(ref m)) {
4224 m.Result = IntPtr.Zero;
4233 if (m.LParam != IntPtr.Zero) {
4236 hi = new HELPINFO();
4238 hi = (HELPINFO) Marshal.PtrToStructure (m.LParam, typeof (HELPINFO));
4239 mouse_pos = new Point(hi.MousePos.x, hi.MousePos.y);
4241 mouse_pos = Control.MousePosition;
4243 OnHelpRequested(new HelpEventArgs(mouse_pos));
4244 m.Result = (IntPtr)1;
4248 case Msg.WM_KILLFOCUS: {
4249 this.has_focus = false;
4250 OnLostFocusInternal (EventArgs.Empty);
4254 case Msg.WM_SETFOCUS: {
4256 this.has_focus = true;
4257 OnGotFocusInternal (EventArgs.Empty);
4263 case Msg.WM_SYSCOLORCHANGE: {
4264 ThemeEngine.Current.ResetDefaults();
4265 OnSystemColorsChanged(EventArgs.Empty);
4270 case Msg.WM_SETCURSOR: {
4271 if ((cursor == null) || ((HitTest)(m.LParam.ToInt32() & 0xffff) != HitTest.HTCLIENT)) {
4276 XplatUI.SetCursor(window.Handle, cursor.handle);
4277 m.Result = (IntPtr)1;
4288 #endregion // Public Instance Methods
4290 #region OnXXX methods
4291 [EditorBrowsable(EditorBrowsableState.Advanced)]
4292 protected virtual void OnBackColorChanged(EventArgs e) {
4293 if (BackColorChanged!=null) BackColorChanged(this, e);
4294 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackColorChanged(e);
4297 [EditorBrowsable(EditorBrowsableState.Advanced)]
4298 protected virtual void OnBackgroundImageChanged(EventArgs e) {
4299 if (BackgroundImageChanged!=null) BackgroundImageChanged(this, e);
4300 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackgroundImageChanged(e);
4303 [EditorBrowsable(EditorBrowsableState.Advanced)]
4304 protected virtual void OnBindingContextChanged(EventArgs e) {
4305 CheckDataBindings ();
4306 if (BindingContextChanged!=null) {
4307 BindingContextChanged(this, e);
4309 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBindingContextChanged(e);
4312 [EditorBrowsable(EditorBrowsableState.Advanced)]
4313 protected virtual void OnCausesValidationChanged(EventArgs e) {
4314 if (CausesValidationChanged!=null) CausesValidationChanged(this, e);
4317 [EditorBrowsable(EditorBrowsableState.Advanced)]
4318 protected virtual void OnChangeUICues(UICuesEventArgs e) {
4319 if (ChangeUICues!=null) ChangeUICues(this, e);
4322 [EditorBrowsable(EditorBrowsableState.Advanced)]
4323 protected virtual void OnClick(EventArgs e) {
4324 if (Click!=null) Click(this, e);
4327 [EditorBrowsable(EditorBrowsableState.Advanced)]
4328 protected virtual void OnContextMenuChanged(EventArgs e) {
4329 if (ContextMenuChanged!=null) ContextMenuChanged(this, e);
4332 [EditorBrowsable(EditorBrowsableState.Advanced)]
4333 protected virtual void OnControlAdded(ControlEventArgs e) {
4334 if (ControlAdded!=null) ControlAdded(this, e);
4337 [EditorBrowsable(EditorBrowsableState.Advanced)]
4338 protected virtual void OnControlRemoved(ControlEventArgs e) {
4339 if (ControlRemoved!=null) ControlRemoved(this, e);
4342 [EditorBrowsable(EditorBrowsableState.Advanced)]
4343 protected virtual void OnCreateControl() {
4347 [EditorBrowsable(EditorBrowsableState.Advanced)]
4348 protected virtual void OnCursorChanged(EventArgs e) {
4349 if (CursorChanged!=null) CursorChanged(this, e);
4352 [EditorBrowsable(EditorBrowsableState.Advanced)]
4353 protected virtual void OnDockChanged(EventArgs e) {
4354 if (DockChanged!=null) DockChanged(this, e);
4357 [EditorBrowsable(EditorBrowsableState.Advanced)]
4358 protected virtual void OnDoubleClick(EventArgs e) {
4359 if (DoubleClick!=null) DoubleClick(this, e);
4362 [EditorBrowsable(EditorBrowsableState.Advanced)]
4363 protected virtual void OnDragDrop(DragEventArgs drgevent) {
4364 if (DragDrop!=null) DragDrop(this, drgevent);
4367 [EditorBrowsable(EditorBrowsableState.Advanced)]
4368 protected virtual void OnDragEnter(DragEventArgs drgevent) {
4369 if (DragEnter!=null) DragEnter(this, drgevent);
4372 [EditorBrowsable(EditorBrowsableState.Advanced)]
4373 protected virtual void OnDragLeave(EventArgs e) {
4374 if (DragLeave!=null) DragLeave(this, e);
4377 [EditorBrowsable(EditorBrowsableState.Advanced)]
4378 protected virtual void OnDragOver(DragEventArgs drgevent) {
4379 if (DragOver!=null) DragOver(this, drgevent);
4382 [EditorBrowsable(EditorBrowsableState.Advanced)]
4383 protected virtual void OnEnabledChanged(EventArgs e) {
4384 if (IsHandleCreated) {
4386 if (((Form)this).context == null) {
4387 XplatUI.EnableWindow(window.Handle, Enabled);
4390 XplatUI.EnableWindow(window.Handle, Enabled);
4395 if (EnabledChanged != null) {
4396 EnabledChanged(this, e);
4399 for (int i=0; i<child_controls.Count; i++) {
4400 child_controls[i].OnParentEnabledChanged(e);
4404 [EditorBrowsable(EditorBrowsableState.Advanced)]
4405 protected virtual void OnEnter(EventArgs e) {
4406 if (Enter!=null) Enter(this, e);
4409 [EditorBrowsable(EditorBrowsableState.Advanced)]
4410 protected virtual void OnFontChanged(EventArgs e) {
4411 if (FontChanged!=null) FontChanged(this, e);
4412 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentFontChanged(e);
4415 [EditorBrowsable(EditorBrowsableState.Advanced)]
4416 protected virtual void OnForeColorChanged(EventArgs e) {
4417 if (ForeColorChanged!=null) ForeColorChanged(this, e);
4418 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentForeColorChanged(e);
4421 [EditorBrowsable(EditorBrowsableState.Advanced)]
4422 protected virtual void OnGiveFeedback(GiveFeedbackEventArgs gfbevent) {
4423 if (GiveFeedback!=null) GiveFeedback(this, gfbevent);
4426 [EditorBrowsable(EditorBrowsableState.Advanced)]
4427 protected virtual void OnGotFocus(EventArgs e) {
4428 if (GotFocus!=null) GotFocus(this, e);
4431 [EditorBrowsable(EditorBrowsableState.Advanced)]
4432 protected virtual void OnHandleCreated(EventArgs e) {
4433 if (HandleCreated!=null) HandleCreated(this, e);
4436 [EditorBrowsable(EditorBrowsableState.Advanced)]
4437 protected virtual void OnHandleDestroyed(EventArgs e) {
4438 if (HandleDestroyed!=null) HandleDestroyed(this, e);
4441 [EditorBrowsable(EditorBrowsableState.Advanced)]
4442 protected virtual void OnHelpRequested(HelpEventArgs hevent) {
4443 if (HelpRequested!=null) HelpRequested(this, hevent);
4446 protected virtual void OnImeModeChanged(EventArgs e) {
4447 if (ImeModeChanged!=null) ImeModeChanged(this, e);
4450 [EditorBrowsable(EditorBrowsableState.Advanced)]
4451 protected virtual void OnInvalidated(InvalidateEventArgs e) {
4452 if (ThemeEngine.Current.DoubleBufferingSupported)
4453 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
4454 // should this block be here? seems like it
4455 // would be more at home in
4456 // NotifyInvalidated..
4457 if (e.InvalidRect == ClientRectangle) {
4458 ImageBufferNeedsRedraw ();
4461 // we need this Inflate call here so
4462 // that the border of the rectangle is
4463 // considered Visible (the
4464 // invalid_region.IsVisible call) in
4465 // the WM_PAINT handling below.
4466 Rectangle r = Rectangle.Inflate(e.InvalidRect, 1,1);
4467 if (invalid_region == null)
4468 invalid_region = new Region (r);
4470 invalid_region.Union (r);
4473 if (Invalidated!=null) Invalidated(this, e);
4476 [EditorBrowsable(EditorBrowsableState.Advanced)]
4477 protected virtual void OnKeyDown(KeyEventArgs e) {
4478 if (KeyDown!=null) KeyDown(this, e);
4481 [EditorBrowsable(EditorBrowsableState.Advanced)]
4482 protected virtual void OnKeyPress(KeyPressEventArgs e) {
4483 if (KeyPress!=null) KeyPress(this, e);
4486 [EditorBrowsable(EditorBrowsableState.Advanced)]
4487 protected virtual void OnKeyUp(KeyEventArgs e) {
4488 if (KeyUp!=null) KeyUp(this, e);
4491 [EditorBrowsable(EditorBrowsableState.Advanced)]
4492 protected virtual void OnLayout(LayoutEventArgs levent) {
4493 if (Layout!=null) Layout(this, levent);
4496 [EditorBrowsable(EditorBrowsableState.Advanced)]
4497 protected virtual void OnLeave(EventArgs e) {
4498 if (Leave!=null) Leave(this, e);
4501 [EditorBrowsable(EditorBrowsableState.Advanced)]
4502 protected virtual void OnLocationChanged(EventArgs e) {
4504 if (LocationChanged!=null) LocationChanged(this, e);
4507 [EditorBrowsable(EditorBrowsableState.Advanced)]
4508 protected virtual void OnLostFocus(EventArgs e) {
4509 if (LostFocus!=null) LostFocus(this, e);
4512 [EditorBrowsable(EditorBrowsableState.Advanced)]
4513 protected virtual void OnMouseDown(MouseEventArgs e) {
4514 if (MouseDown!=null) MouseDown(this, e);
4517 [EditorBrowsable(EditorBrowsableState.Advanced)]
4518 protected virtual void OnMouseEnter(EventArgs e) {
4519 if (MouseEnter!=null) MouseEnter(this, e);
4522 [EditorBrowsable(EditorBrowsableState.Advanced)]
4523 protected virtual void OnMouseHover(EventArgs e) {
4524 if (MouseHover!=null) MouseHover(this, e);
4527 [EditorBrowsable(EditorBrowsableState.Advanced)]
4528 protected virtual void OnMouseLeave(EventArgs e) {
4529 if (MouseLeave!=null) MouseLeave(this, e);
4532 [EditorBrowsable(EditorBrowsableState.Advanced)]
4533 protected virtual void OnMouseMove(MouseEventArgs e) {
4534 if (MouseMove!=null) MouseMove(this, e);
4537 [EditorBrowsable(EditorBrowsableState.Advanced)]
4538 protected virtual void OnMouseUp(MouseEventArgs e) {
4539 if (MouseUp!=null) MouseUp(this, e);
4542 [EditorBrowsable(EditorBrowsableState.Advanced)]
4543 protected virtual void OnMouseWheel(MouseEventArgs e) {
4544 if (MouseWheel!=null) MouseWheel(this, e);
4547 [EditorBrowsable(EditorBrowsableState.Advanced)]
4548 protected virtual void OnMove(EventArgs e) {
4549 if (Move!=null) Move(this, e);
4552 [EditorBrowsable(EditorBrowsableState.Advanced)]
4553 protected virtual void OnNotifyMessage(Message m) {
4557 [EditorBrowsable(EditorBrowsableState.Advanced)]
4558 protected virtual void OnPaint(PaintEventArgs e) {
4559 if (Paint!=null) Paint(this, e);
4562 internal virtual void OnPaintBackgroundInternal(PaintEventArgs e) {
4566 internal virtual void OnPaintInternal(PaintEventArgs e) {
4570 internal virtual void OnGotFocusInternal (EventArgs e)
4575 internal virtual void OnLostFocusInternal (EventArgs e)
4580 [EditorBrowsable(EditorBrowsableState.Advanced)]
4581 protected virtual void OnPaintBackground(PaintEventArgs pevent) {
4582 PaintControlBackground (pevent);
4585 [EditorBrowsable(EditorBrowsableState.Advanced)]
4586 protected virtual void OnParentBackColorChanged(EventArgs e) {
4587 if (background_color.IsEmpty && background_image==null) {
4589 OnBackColorChanged(e);
4593 [EditorBrowsable(EditorBrowsableState.Advanced)]
4594 protected virtual void OnParentBackgroundImageChanged(EventArgs e) {
4595 if (background_color.IsEmpty && background_image==null) {
4597 OnBackgroundImageChanged(e);
4601 [EditorBrowsable(EditorBrowsableState.Advanced)]
4602 protected virtual void OnParentBindingContextChanged(EventArgs e) {
4603 if (binding_context==null) {
4604 binding_context=Parent.binding_context;
4605 OnBindingContextChanged(e);
4609 [EditorBrowsable(EditorBrowsableState.Advanced)]
4610 protected virtual void OnParentChanged(EventArgs e) {
4611 if (ParentChanged!=null) ParentChanged(this, e);
4614 [EditorBrowsable(EditorBrowsableState.Advanced)]
4615 protected virtual void OnParentEnabledChanged(EventArgs e) {
4617 OnEnabledChanged(e);
4621 [EditorBrowsable(EditorBrowsableState.Advanced)]
4622 protected virtual void OnParentFontChanged(EventArgs e) {
4629 [EditorBrowsable(EditorBrowsableState.Advanced)]
4630 protected virtual void OnParentForeColorChanged(EventArgs e) {
4631 if (foreground_color.IsEmpty) {
4633 OnForeColorChanged(e);
4637 [EditorBrowsable(EditorBrowsableState.Advanced)]
4638 protected virtual void OnParentRightToLeftChanged(EventArgs e) {
4639 if (right_to_left==RightToLeft.Inherit) {
4641 OnRightToLeftChanged(e);
4645 [EditorBrowsable(EditorBrowsableState.Advanced)]
4646 protected virtual void OnParentVisibleChanged(EventArgs e) {
4648 OnVisibleChanged(e);
4652 [EditorBrowsable(EditorBrowsableState.Advanced)]
4653 protected virtual void OnQueryContinueDrag(QueryContinueDragEventArgs e) {
4654 if (QueryContinueDrag!=null) QueryContinueDrag(this, e);
4657 [EditorBrowsable(EditorBrowsableState.Advanced)]
4658 protected virtual void OnResize(EventArgs e) {
4659 if (Resize!=null) Resize(this, e);
4661 PerformLayout(this, "bounds");
4663 if (parent != null) {
4664 parent.PerformLayout();
4668 [EditorBrowsable(EditorBrowsableState.Advanced)]
4669 protected virtual void OnRightToLeftChanged(EventArgs e) {
4670 if (RightToLeftChanged!=null) RightToLeftChanged(this, e);
4671 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentRightToLeftChanged(e);
4674 [EditorBrowsable(EditorBrowsableState.Advanced)]
4675 protected virtual void OnSizeChanged(EventArgs e) {
4676 InvalidateBuffers ();
4678 if (SizeChanged!=null) SizeChanged(this, e);
4681 [EditorBrowsable(EditorBrowsableState.Advanced)]
4682 protected virtual void OnStyleChanged(EventArgs e) {
4683 if (StyleChanged!=null) StyleChanged(this, e);
4686 [EditorBrowsable(EditorBrowsableState.Advanced)]
4687 protected virtual void OnSystemColorsChanged(EventArgs e) {
4688 if (SystemColorsChanged!=null) SystemColorsChanged(this, e);
4691 [EditorBrowsable(EditorBrowsableState.Advanced)]
4692 protected virtual void OnTabIndexChanged(EventArgs e) {
4693 if (TabIndexChanged!=null) TabIndexChanged(this, e);
4696 [EditorBrowsable(EditorBrowsableState.Advanced)]
4697 protected virtual void OnTabStopChanged(EventArgs e) {
4698 if (TabStopChanged!=null) TabStopChanged(this, e);
4701 [EditorBrowsable(EditorBrowsableState.Advanced)]
4702 protected virtual void OnTextChanged(EventArgs e) {
4703 if (TextChanged!=null) TextChanged(this, e);
4706 [EditorBrowsable(EditorBrowsableState.Advanced)]
4707 protected virtual void OnValidated(EventArgs e) {
4708 if (Validated!=null) Validated(this, e);
4711 [EditorBrowsable(EditorBrowsableState.Advanced)]
4712 protected virtual void OnValidating(System.ComponentModel.CancelEventArgs e) {
4713 if (Validating!=null) Validating(this, e);
4716 [EditorBrowsable(EditorBrowsableState.Advanced)]
4717 protected virtual void OnVisibleChanged(EventArgs e) {
4718 if ((parent != null) && !Created && Visible) {
4725 if (VisibleChanged!=null) VisibleChanged(this, e);
4727 // We need to tell our kids
4728 for (int i=0; i<child_controls.Count; i++) {
4729 if (child_controls[i].Visible) {
4730 child_controls[i].OnParentVisibleChanged(e);
4734 #endregion // OnXXX methods
4737 public event EventHandler BackColorChanged;
4738 public event EventHandler BackgroundImageChanged;
4739 public event EventHandler BindingContextChanged;
4740 public event EventHandler CausesValidationChanged;
4741 public event UICuesEventHandler ChangeUICues;
4742 public event EventHandler Click;
4743 public event EventHandler ContextMenuChanged;
4745 [EditorBrowsable(EditorBrowsableState.Advanced)]
4747 public event ControlEventHandler ControlAdded;
4749 [EditorBrowsable(EditorBrowsableState.Advanced)]
4751 public event ControlEventHandler ControlRemoved;
4753 [MWFDescription("Fired when the cursor for the control has been changed"), MWFCategory("PropertyChanged")]
4754 public event EventHandler CursorChanged;
4755 public event EventHandler DockChanged;
4756 public event EventHandler DoubleClick;
4757 public event DragEventHandler DragDrop;
4758 public event DragEventHandler DragEnter;
4759 public event EventHandler DragLeave;
4760 public event DragEventHandler DragOver;
4761 public event EventHandler EnabledChanged;
4762 public event EventHandler Enter;
4763 public event EventHandler FontChanged;
4764 public event EventHandler ForeColorChanged;
4765 public event GiveFeedbackEventHandler GiveFeedback;
4767 [EditorBrowsable(EditorBrowsableState.Advanced)]
4769 public event EventHandler GotFocus;
4771 [EditorBrowsable(EditorBrowsableState.Advanced)]
4773 public event EventHandler HandleCreated;
4775 [EditorBrowsable(EditorBrowsableState.Advanced)]
4777 public event EventHandler HandleDestroyed;
4779 public event HelpEventHandler HelpRequested;
4780 public event EventHandler ImeModeChanged;
4782 [EditorBrowsable(EditorBrowsableState.Advanced)]
4784 public event InvalidateEventHandler Invalidated;
4786 public event KeyEventHandler KeyDown;
4787 public event KeyPressEventHandler KeyPress;
4788 public event KeyEventHandler KeyUp;
4789 public event LayoutEventHandler Layout;
4790 public event EventHandler Leave;
4791 public event EventHandler LocationChanged;
4793 [EditorBrowsable(EditorBrowsableState.Advanced)]
4795 public event EventHandler LostFocus;
4797 public event MouseEventHandler MouseDown;
4798 public event EventHandler MouseEnter;
4799 public event EventHandler MouseHover;
4800 public event EventHandler MouseLeave;
4801 public event MouseEventHandler MouseMove;
4802 public event MouseEventHandler MouseUp;
4804 [EditorBrowsable(EditorBrowsableState.Advanced)]
4806 public event MouseEventHandler MouseWheel;
4808 public event EventHandler Move;
4809 public event PaintEventHandler Paint;
4810 public event EventHandler ParentChanged;
4811 public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp;
4812 public event QueryContinueDragEventHandler QueryContinueDrag;
4813 public event EventHandler Resize;
4814 public event EventHandler RightToLeftChanged;
4815 public event EventHandler SizeChanged;
4816 public event EventHandler StyleChanged;
4817 public event EventHandler SystemColorsChanged;
4818 public event EventHandler TabIndexChanged;
4819 public event EventHandler TabStopChanged;
4820 public event EventHandler TextChanged;
4821 public event EventHandler Validated;
4822 public event CancelEventHandler Validating;
4823 public event EventHandler VisibleChanged;
4824 #endregion // Events