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
36 using System.ComponentModel;
37 using System.ComponentModel.Design;
38 using System.ComponentModel.Design.Serialization;
39 using System.Collections;
40 using System.Diagnostics;
42 using System.Drawing.Drawing2D;
43 using System.Reflection;
44 using System.Runtime.InteropServices;
45 using System.Security;
46 using System.Threading;
49 namespace System.Windows.Forms
51 [Designer("System.Windows.Forms.Design.ControlDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
52 [DefaultProperty("Text")]
53 [DefaultEvent("Click")]
54 [DesignerSerializer("System.Windows.Forms.Design.ControlCodeDomSerializer, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
55 [ToolboxItemFilter("System.Windows.Forms")]
56 public class Control : Component, ISynchronizeInvoke, IWin32Window
58 #region Local Variables
61 internal Rectangle bounds; // bounding rectangle for control (client area + decorations)
62 internal object creator_thread; // thread that created the control
63 internal ControlNativeWindow window; // object for native window handle
64 internal string name; // for object naming
67 internal bool is_created; // true if OnCreateControl has been sent
68 internal bool has_focus; // true if control has focus
69 internal bool is_visible; // true if control is visible
70 internal bool is_entered; // is the mouse inside the control?
71 internal bool is_enabled; // true if control is enabled (usable/not grayed out)
72 internal bool is_selected; // true if control is selected
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
92 internal Color foreground_color; // foreground color for control
93 internal Color background_color; // background color for control
94 internal Image background_image; // background image for control
95 internal Font font; // font for control
96 internal string text; // window/title text for control
97 internal BorderStyle border_style; // Border style of control
100 internal AnchorStyles anchor_style; // anchoring requirements for our control
101 internal DockStyle dock_style; // docking requirements for our control (supercedes anchoring)
102 internal int dist_left; // distance to the left border of the parent
103 internal int dist_top; // distance to the top border of the parent
104 internal int dist_right; // distance to the right border of the parent
105 internal int dist_bottom; // distance to the bottom border of the parent
107 // to be categorized...
108 static internal ArrayList controls = new ArrayList(); // All of the application's controls, in a flat list
109 internal ControlCollection child_controls; // our children
110 internal Control parent; // our parent control
111 internal AccessibleObject accessibility_object; // object that contains accessibility information about our control
112 internal BindingContext binding_context; // TODO
113 internal RightToLeft right_to_left; // drawing direction for control
114 internal int layout_suspended;
115 internal ContextMenu context_menu; // Context menu associated with the control
117 private Graphics dc_mem; // Graphics context for double buffering
118 private Bitmap bmp_mem; // Bitmap for double buffering control
119 private bool needs_redraw = true;
121 private ControlBindingsCollection data_bindings;
124 internal bool use_compatible_text_rendering;
125 private Padding padding;
128 #endregion // Local Variables
130 #region Private Classes
131 // This helper class allows us to dispatch messages to Control.WndProc
132 internal class ControlNativeWindow : NativeWindow {
133 private Control owner;
135 public ControlNativeWindow(Control control) : base() {
140 public Control Owner {
146 static internal Control ControlFromHandle(IntPtr hWnd) {
147 ControlNativeWindow window;
149 window = (ControlNativeWindow)window_collection[hWnd];
150 if (window != null) {
157 protected override void WndProc(ref Message m) {
158 owner.WndProc(ref m);
163 #region Public Classes
165 public class ControlAccessibleObject : AccessibleObject {
166 #region ControlAccessibleObject Local Variables
167 private Control owner;
168 #endregion // ControlAccessibleObject Local Variables
170 #region ControlAccessibleObject Constructors
171 public ControlAccessibleObject(Control ownerControl) {
172 this.owner = ownerControl;
174 #endregion // ControlAccessibleObject Constructors
176 #region ControlAccessibleObject Public Instance Properties
177 public override string DefaultAction {
179 return base.DefaultAction;
183 public override string Description {
185 return base.Description;
189 public IntPtr Handle {
195 // We don't want to let them set it
199 public override string Help {
205 public override string KeyboardShortcut {
207 return base.KeyboardShortcut;
211 public override string Name {
221 public Control Owner {
227 public override AccessibleObject Parent {
234 public override AccessibleRole Role {
239 #endregion // ControlAccessibleObject Public Instance Properties
241 #region ControlAccessibleObject Public Instance Methods
242 public override int GetHelpTopic(out string FileName) {
243 return base.GetHelpTopic (out FileName);
246 [MonoTODO("Implement this and tie it into Control.AccessibilityNotifyClients")]
247 public void NotifyClients(AccessibleEvents accEvent) {
248 throw new NotImplementedException();
251 [MonoTODO("Implement this and tie it into Control.AccessibilityNotifyClients")]
252 public void NotifyClients(AccessibleEvents accEvent, int childID) {
253 throw new NotImplementedException();
256 public override string ToString() {
257 return "ControlAccessibleObject: Owner = " + owner.ToString() + ", Text: " + owner.text;
260 #endregion // ControlAccessibleObject Public Instance Methods
263 [DesignerSerializer("System.Windows.Forms.Design.ControlCollectionCodeDomSerializer, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
264 [ListBindable(false)]
265 public class ControlCollection : IList, ICollection, ICloneable, IEnumerable {
266 #region ControlCollection Local Variables
267 private ArrayList list;
268 internal ArrayList impl_list;
269 private Control [] all_controls;
270 internal Control owner;
271 #endregion // ControlCollection Local Variables
273 #region ControlCollection Public Constructor
274 public ControlCollection(Control owner) {
276 this.list=new ArrayList();
280 #region ControlCollection Public Instance Properties
287 public bool IsReadOnly {
289 return list.IsReadOnly;
293 public virtual Control this[int index] {
295 if (index < 0 || index >= list.Count) {
296 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
298 return (Control)list[index];
301 #endregion // ControlCollection Public Instance Properties
303 #region ControlCollection Private Instance Methods
304 public virtual void Add (Control value)
309 if (Contains (value)) {
310 owner.PerformLayout();
314 if (value.tab_index == -1) {
320 end = owner.child_controls.Count;
321 for (int i = 0; i < end; i++) {
322 index = owner.child_controls[i].tab_index;
327 value.tab_index = use;
330 if (value.parent != null) {
331 value.parent.Controls.Remove(value);
337 value.ChangeParent(owner);
341 owner.UpdateZOrder();
342 owner.PerformLayout(value, "Parent");
343 owner.OnControlAdded(new ControlEventArgs(value));
346 internal void AddToList (Control c)
352 internal virtual void AddImplicit (Control control)
354 if (impl_list == null)
355 impl_list = new ArrayList ();
357 impl_list.Add (control);
359 control.ChangeParent (owner);
360 control.InitLayout ();
361 owner.UpdateZOrder ();
362 owner.PerformLayout (control, "Parent");
363 owner.OnControlAdded (new ControlEventArgs (control));
366 public virtual void AddRange (Control[] controls)
368 if (controls == null)
369 throw new ArgumentNullException ("controls");
371 owner.SuspendLayout ();
374 for (int i = 0; i < controls.Length; i++)
377 owner.ResumeLayout ();
381 internal virtual void AddRangeImplicit (Control [] controls)
383 if (controls == null)
384 throw new ArgumentNullException ("controls");
386 owner.SuspendLayout ();
389 for (int i = 0; i < controls.Length; i++)
390 AddImplicit (controls [i]);
392 owner.ResumeLayout ();
396 public virtual void Clear ()
400 // MS sends remove events in reverse order
401 while (list.Count > 0) {
402 RemoveAt(list.Count - 1);
406 internal virtual void ClearImplicit ()
408 if (impl_list == null)
414 public bool Contains (Control value)
416 for (int i = list.Count; i > 0; ) {
419 if (list [i] == value) {
420 // Do we need to do anything here?
427 internal bool ImplicitContains (Control value)
429 if (impl_list == null)
432 for (int i = impl_list.Count; i > 0; ) {
435 if (impl_list [i] == value) {
436 // Do we need to do anything here?
443 internal bool AllContains (Control value)
445 return Contains (value) || ImplicitContains (value);
448 public void CopyTo (Array array, int index)
450 list.CopyTo(array, index);
453 public override bool Equals(object other) {
454 if (other is ControlCollection && (((ControlCollection)other).owner==this.owner)) {
461 public int GetChildIndex(Control child) {
462 return GetChildIndex(child, false);
465 public int GetChildIndex(Control child, bool throwException) {
468 index=list.IndexOf(child);
470 if (index==-1 && throwException) {
471 throw new ArgumentException("Not a child control", "child");
476 public IEnumerator GetEnumerator() {
477 return list.GetEnumerator();
480 internal IEnumerator GetAllEnumerator ()
482 Control [] res = GetAllControls ();
483 return res.GetEnumerator ();
486 internal Control [] GetAllControls ()
488 if (all_controls != null)
491 if (impl_list == null)
492 return (Control []) list.ToArray (typeof (Control));
494 Control [] res = new Control [list.Count + impl_list.Count];
495 impl_list.CopyTo (res);
496 list.CopyTo (res, impl_list.Count);
501 public override int GetHashCode() {
502 return base.GetHashCode();
505 public int IndexOf(Control control) {
506 return list.IndexOf(control);
509 public virtual void Remove(Control value) {
512 owner.PerformLayout(value, "Parent");
513 owner.OnControlRemoved(new ControlEventArgs(value));
516 value.ChangeParent(null);
518 owner.UpdateZOrder();
521 internal virtual void RemoveImplicit (Control control)
523 if (impl_list != null) {
525 owner.PerformLayout (control, "Parent");
526 owner.OnControlRemoved (new ControlEventArgs (control));
527 impl_list.Remove (control);
529 control.ChangeParent (null);
530 owner.UpdateZOrder ();
533 public void RemoveAt(int index) {
534 if (index < 0 || index >= list.Count) {
535 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
537 Remove ((Control)list[index]);
540 public void SetChildIndex(Control child, int newIndex) {
543 old_index=list.IndexOf(child);
545 throw new ArgumentException("Not a child control", "child");
548 if (old_index==newIndex) {
552 list.RemoveAt(old_index);
554 if (newIndex>list.Count) {
557 list.Insert(newIndex, child);
559 owner.UpdateZOrder();
561 #endregion // ControlCollection Private Instance Methods
563 #region ControlCollection Interface Properties
564 object IList.this[int index] {
566 if (index<0 || index>=list.Count) {
567 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
573 if (!(value is Control)) {
574 throw new ArgumentException("Object of type Control required", "value");
577 list[index]=(Control)value;
581 bool IList.IsFixedSize {
587 bool ICollection.IsSynchronized {
589 return list.IsSynchronized;
593 object ICollection.SyncRoot {
595 return list.SyncRoot;
598 #endregion // ControlCollection Interface Properties
600 #region ControlCollection Interface Methods
601 int IList.Add(object value) {
603 throw new ArgumentNullException("value", "Cannot add null controls");
606 if (!(value is Control)) {
607 throw new ArgumentException("Object of type Control required", "value");
610 return list.Add(value);
613 bool IList.Contains(object value) {
614 if (!(value is Control)) {
615 throw new ArgumentException("Object of type Control required", "value");
618 return this.Contains((Control) value);
621 int IList.IndexOf(object value) {
622 if (!(value is Control)) {
623 throw new ArgumentException("Object of type Control required", "value");
626 return this.IndexOf((Control) value);
629 void IList.Insert(int index, object value) {
630 if (!(value is Control)) {
631 throw new ArgumentException("Object of type Control required", "value");
634 list.Insert(index, value);
637 void IList.Remove(object value) {
638 if (!(value is Control)) {
639 throw new ArgumentException("Object of type Control required", "value");
645 Object ICloneable.Clone() {
646 ControlCollection clone = new ControlCollection(this.owner);
647 clone.list=(ArrayList)list.Clone(); // FIXME: Do we need this?
650 #endregion // ControlCollection Interface Methods
652 #endregion // ControlCollection Class
654 #region Public Constructors
657 anchor_style = AnchorStyles.Top | AnchorStyles.Left;
665 layout_pending = false;
667 causes_validation = true;
669 layout_suspended = 0;
673 right_to_left = RightToLeft.Inherit;
674 border_style = BorderStyle.None;
675 background_color = Color.Empty;
682 use_compatible_text_rendering = Application.use_compatible_text_rendering;
683 padding = new Padding(0);
686 control_style = ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint |
687 ControlStyles.Selectable | ControlStyles.StandardClick |
688 ControlStyles.StandardDoubleClick;
691 background_image = null;
695 window = new ControlNativeWindow(this);
696 child_controls = CreateControlsInstance();
697 client_size = new Size(DefaultSize.Width, DefaultSize.Height);
698 client_rect = new Rectangle(0, 0, DefaultSize.Width, DefaultSize.Height);
699 XplatUI.CalculateWindowRect(ref client_rect, CreateParams.Style, CreateParams.ExStyle, null, out bounds);
700 if ((CreateParams.Style & (int)WindowStyles.WS_CHILD) == 0) {
706 public Control(Control parent, string text) : this() {
711 public Control(Control parent, string text, int left, int top, int width, int height) : this() {
716 bounds.Height=height;
717 SetBoundsCore(left, top, width, height, BoundsSpecified.All);
721 public Control(string text) : this() {
725 public Control(string text, int left, int top, int width, int height) : this() {
729 bounds.Height=height;
730 SetBoundsCore(left, top, width, height, BoundsSpecified.All);
734 private delegate void RemoveDelegate(object c);
736 protected override void Dispose(bool disposing) {
748 if (this.InvokeRequired) {
749 if (Application.MessageLoop) {
750 this.BeginInvokeInternal(new MethodInvoker(DestroyHandle), null, true);
751 this.BeginInvokeInternal(new RemoveDelegate(controls.Remove), new object[] {this}, true);
755 controls.Remove(this);
758 #endregion // Public Constructors
760 #region Internal Properties
761 internal BorderStyle InternalBorderStyle {
767 if (!Enum.IsDefined (typeof (BorderStyle), value))
768 throw new InvalidEnumArgumentException (string.Format("Enum argument value '{0}' is not valid for BorderStyle", value));
770 if (border_style != value) {
771 border_style = value;
773 if (IsHandleCreated) {
774 XplatUI.SetBorderStyle(window.Handle, (FormBorderStyle)border_style);
780 #endregion // Internal Properties
782 #region Private & Internal Methods
783 internal IAsyncResult BeginInvokeInternal (Delegate method, object [] args, bool disposing) {
784 AsyncMethodResult result;
785 AsyncMethodData data;
792 if (!p.IsHandleCreated) {
793 throw new InvalidOperationException("Cannot call Invoke or InvokeAsync on a control until the window handle is created");
799 result = new AsyncMethodResult ();
800 data = new AsyncMethodData ();
802 data.Method = method;
804 data.Result = result;
807 if (!ExecutionContext.IsFlowSuppressed ()) {
808 data.Context = ExecutionContext.Capture ();
811 #if !MWF_ON_MSRUNTIME
812 if (SecurityManager.SecurityEnabled) {
813 data.Stack = CompressedStack.GetCompressedStack ();
818 XplatUI.SendAsyncMethod (data);
823 internal void PointToClient (ref int x, ref int y)
825 XplatUI.ScreenToClient (Handle, ref x, ref y);
828 internal void PointToScreen (ref int x, ref int y)
830 XplatUI.ClientToScreen (Handle, ref x, ref y);
833 private bool IsRecreating {
839 if (parent != null) {
840 return parent.IsRecreating;
847 private bool ParentIsRecreating {
849 if (parent != null) {
850 return parent.IsRecreating;
856 internal Graphics DeviceContext {
859 CreateBuffers(this.Width, this.Height);
865 private Bitmap ImageBuffer {
868 CreateBuffers(this.Width, this.Height);
874 internal void CreateBuffers (int width, int height) {
875 if (dc_mem != null) {
889 bmp_mem = new Bitmap (width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
890 dc_mem = Graphics.FromImage (bmp_mem);
894 internal void InvalidateBuffers ()
896 if (dc_mem != null) {
907 internal static void SetChildColor(Control parent) {
910 for (int i=0; i < parent.child_controls.Count; i++) {
911 child=parent.child_controls[i];
912 if (child.child_controls.Count>0) {
913 SetChildColor(child);
919 internal bool Select(Control control) {
921 IContainerControl container;
923 if (control == null) {
927 parent = control.parent;
929 if (((control.control_style & ControlStyles.Selectable) !=0) && (parent != null)) {
930 while (parent != null) {
931 if (!parent.Visible || !parent.is_enabled) {
934 parent = parent.parent;
938 control.is_selected = true;
940 container = GetContainerControl();
941 if (container != null) {
942 container.ActiveControl = control;
944 if (control.IsHandleCreated) {
945 XplatUI.SetFocus(control.window.Handle);
950 internal virtual void DoDefaultAction() {
951 // Only here to be overriden by our actual controls; this is needed by the accessibility class
954 internal static int LowOrder (int param) {
955 return ((int)(short)(param & 0xffff));
958 internal static int HighOrder (int param) {
959 return ((int)(short)(param >> 16));
962 // This method exists so controls overriding OnPaintBackground can have default background painting done
963 internal virtual void PaintControlBackground (PaintEventArgs pevent)
965 if (background_image == null) {
966 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));
970 DrawBackgroundImage (pevent.Graphics);
973 void DrawBackgroundImage (Graphics g)
975 using (TextureBrush b = new TextureBrush (background_image, WrapMode.Tile)) {
976 g.FillRectangle (b, ClientRectangle);
980 internal virtual void DndEnter (DragEventArgs e)
987 internal virtual void DndOver (DragEventArgs e)
994 internal virtual void DndDrop (DragEventArgs e)
998 } catch (Exception exc) {
999 Console.Error.WriteLine ("MWF: Exception while dropping:");
1000 Console.Error.WriteLine (exc);
1004 internal virtual void DndLeave (EventArgs e)
1011 internal virtual void DndFeedback(GiveFeedbackEventArgs e)
1018 internal virtual void DndContinueDrag(QueryContinueDragEventArgs e)
1021 OnQueryContinueDrag(e);
1025 internal static MouseButtons FromParamToMouseButtons (int param) {
1026 MouseButtons buttons = MouseButtons.None;
1028 if ((param & (int) MsgButtons.MK_LBUTTON) != 0)
1029 buttons |= MouseButtons.Left;
1031 if ((param & (int) MsgButtons.MK_MBUTTON) != 0)
1032 buttons |= MouseButtons.Middle;
1034 if ((param & (int) MsgButtons.MK_RBUTTON) != 0)
1035 buttons |= MouseButtons.Right;
1041 internal virtual bool ProcessControlMnemonic(char charCode) {
1042 return ProcessMnemonic(charCode);
1045 private static Control FindFlatForward(Control container, Control start) {
1051 end = container.child_controls.Count;
1053 if (start != null) {
1054 index = start.tab_index;
1059 for (int i = 0; i < end; i++) {
1060 if (found == null) {
1061 if (container.child_controls[i].tab_index > index) {
1062 found = container.child_controls[i];
1064 } else if (found.tab_index > container.child_controls[i].tab_index) {
1065 if (container.child_controls[i].tab_index > index) {
1066 found = container.child_controls[i];
1073 private static Control FindControlForward(Control container, Control start) {
1079 if (start != null) {
1080 if ((start is IContainerControl) || start.GetStyle(ControlStyles.ContainerControl)) {
1081 found = FindControlForward(start, null);
1082 if (found != null) {
1088 while (p != container) {
1089 found = FindFlatForward(p, start);
1090 if (found != null) {
1097 return FindFlatForward(container, start);
1100 private static Control FindFlatBackward(Control container, Control start) {
1106 end = container.child_controls.Count;
1108 if (start != null) {
1109 index = start.tab_index;
1111 // FIXME: Possible speed-up: Keep the highest taborder index in the container
1113 for (int i = 0; i < end; i++) {
1114 if (container.child_controls[i].tab_index > index) {
1115 index = container.child_controls[i].tab_index;
1121 for (int i = 0; i < end; i++) {
1122 if (found == null) {
1123 if (container.child_controls[i].tab_index < index) {
1124 found = container.child_controls[i];
1126 } else if (found.tab_index < container.child_controls[i].tab_index) {
1127 if (container.child_controls[i].tab_index < index) {
1128 found = container.child_controls[i];
1135 private static Control FindControlBackward(Control container, Control start) {
1140 if (start != null) {
1141 found = FindFlatBackward(start.parent, start);
1142 if (found == null && start.parent != container) {
1143 return start.parent;
1146 if (found == null) {
1147 found = FindFlatBackward(container, start);
1150 while ((found != null) && ((found is IContainerControl) || found.GetStyle(ControlStyles.ContainerControl))) {
1151 found = FindControlBackward(found, null);
1152 if (found != null) {
1160 private void HandleClick(int clicks, MouseEventArgs me) {
1161 if (GetStyle(ControlStyles.StandardClick)) {
1162 if ((clicks > 1) && GetStyle(ControlStyles.StandardDoubleClick)) {
1164 OnDoubleClick(EventArgs.Empty);
1166 OnClick(EventArgs.Empty);
1176 private void CheckDataBindings ()
1178 if (data_bindings == null)
1181 BindingContext binding_context = BindingContext;
1182 foreach (Binding binding in data_bindings) {
1183 binding.Check (binding_context);
1188 private void ChangeParent(Control new_parent) {
1192 Color pre_fore_color;
1193 Color pre_back_color;
1194 RightToLeft pre_rtl;
1196 // These properties are inherited from our parent
1197 // Get them pre parent-change and then send events
1198 // if they are changed after we have our new parent
1199 pre_enabled = Enabled;
1200 pre_visible = Visible;
1202 pre_fore_color = ForeColor;
1203 pre_back_color = BackColor;
1204 pre_rtl = RightToLeft;
1205 // MS doesn't seem to send a CursorChangedEvent
1207 parent = new_parent;
1209 if (IsHandleCreated && (new_parent != null) && new_parent.IsHandleCreated) {
1210 XplatUI.SetParent(Handle, new_parent.Handle);
1213 OnParentChanged(EventArgs.Empty);
1215 if (pre_enabled != Enabled) {
1216 OnEnabledChanged(EventArgs.Empty);
1219 if (pre_visible != Visible) {
1220 OnVisibleChanged(EventArgs.Empty);
1223 if (pre_font != Font) {
1224 OnFontChanged(EventArgs.Empty);
1227 if (pre_fore_color != ForeColor) {
1228 OnForeColorChanged(EventArgs.Empty);
1231 if (pre_back_color != BackColor) {
1232 OnBackColorChanged(EventArgs.Empty);
1235 if (pre_rtl != RightToLeft) {
1236 // MS sneaks a OnCreateControl and OnHandleCreated in here, I guess
1237 // because when RTL changes they have to recreate the win32 control
1238 // We don't really need that (until someone runs into compatibility issues)
1239 OnRightToLeftChanged(EventArgs.Empty);
1242 if ((new_parent != null) && new_parent.Created && !Created) {
1246 if ((binding_context == null) && Created) {
1247 OnBindingContextChanged(EventArgs.Empty);
1251 private void UpdateDistances() {
1252 if ((parent != null) && (parent.layout_suspended == 0)) {
1253 dist_left = bounds.X;
1254 dist_top = bounds.Y;
1255 dist_right = parent.ClientSize.Width - bounds.X - bounds.Width;
1256 dist_bottom = parent.ClientSize.Height - bounds.Y - bounds.Height;
1259 #endregion // Private & Internal Methods
1261 #region Public Static Properties
1262 public static Color DefaultBackColor {
1264 return ThemeEngine.Current.DefaultControlBackColor;
1268 public static Font DefaultFont {
1270 return ThemeEngine.Current.DefaultFont;
1274 public static Color DefaultForeColor {
1276 return ThemeEngine.Current.DefaultControlForeColor;
1280 public static Keys ModifierKeys {
1282 return XplatUI.State.ModifierKeys;
1286 public static MouseButtons MouseButtons {
1288 return XplatUI.State.MouseButtons;
1292 public static Point MousePosition {
1294 return Cursor.Position;
1300 public static bool CheckForIllegalCrossThreadCalls
1309 #endregion // Public Static Properties
1311 #region Public Instance Properties
1312 [EditorBrowsable(EditorBrowsableState.Advanced)]
1314 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1315 public AccessibleObject AccessibilityObject {
1317 if (accessibility_object==null) {
1318 accessibility_object=CreateAccessibilityInstance();
1320 return accessibility_object;
1324 [EditorBrowsable(EditorBrowsableState.Advanced)]
1326 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1327 public string AccessibleDefaultActionDescription {
1329 return AccessibilityObject.default_action;
1333 AccessibilityObject.default_action=value;
1338 [DefaultValue(null)]
1339 public string AccessibleDescription {
1341 return AccessibilityObject.description;
1345 AccessibilityObject.description=value;
1350 [DefaultValue(null)]
1351 public string AccessibleName {
1353 return AccessibilityObject.Name;
1357 AccessibilityObject.Name=value;
1361 [DefaultValue(AccessibleRole.Default)]
1362 [MWFDescription("Role of the control"), MWFCategory("Accessibility")]
1363 public AccessibleRole AccessibleRole {
1365 return AccessibilityObject.role;
1369 AccessibilityObject.role=value;
1373 [DefaultValue(false)]
1374 public virtual bool AllowDrop {
1380 if (allow_drop == value)
1384 XplatUI.SetAllowDrop (Handle, value);
1389 [RefreshProperties(RefreshProperties.Repaint)]
1390 [DefaultValue(AnchorStyles.Top | AnchorStyles.Left)]
1391 public virtual AnchorStyles Anchor {
1393 return anchor_style;
1399 if (parent != null) {
1400 parent.PerformLayout(this, "Parent");
1406 // XXX: Implement me!
1409 public virtual bool AutoSize {
1411 Console.Error.WriteLine("Unimplemented: Control::get_AutoSize()");
1415 Console.Error.WriteLine("Unimplemented: Control::set_AutoSize(bool)");
1422 public virtual Color BackColor {
1424 if (background_color.IsEmpty) {
1426 return parent.BackColor;
1428 return DefaultBackColor;
1430 return background_color;
1434 background_color=value;
1435 SetChildColor(this);
1436 OnBackColorChanged(EventArgs.Empty);
1442 [DefaultValue(null)]
1443 public virtual Image BackgroundImage {
1445 return background_image;
1449 if (background_image!=value) {
1450 background_image=value;
1451 OnBackgroundImageChanged(EventArgs.Empty);
1456 [EditorBrowsable(EditorBrowsableState.Advanced)]
1458 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1459 public virtual BindingContext BindingContext {
1461 if (binding_context != null)
1462 return binding_context;
1465 binding_context = Parent.BindingContext;
1466 return binding_context;
1469 if (binding_context != value) {
1470 binding_context = value;
1471 OnBindingContextChanged(EventArgs.Empty);
1476 [EditorBrowsable(EditorBrowsableState.Advanced)]
1478 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1481 return bounds.Y+bounds.Height;
1485 [EditorBrowsable(EditorBrowsableState.Advanced)]
1487 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1488 public Rectangle Bounds {
1494 SetBoundsCore(value.Left, value.Top, value.Width, value.Height, BoundsSpecified.All);
1498 [EditorBrowsable(EditorBrowsableState.Advanced)]
1500 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1501 public bool CanFocus {
1503 if (IsHandleCreated && Visible && Enabled) {
1510 [EditorBrowsable(EditorBrowsableState.Advanced)]
1512 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1513 public bool CanSelect {
1517 if (!GetStyle(ControlStyles.Selectable)) {
1522 while (parent != null) {
1523 if (!parent.is_visible || !parent.is_enabled) {
1527 parent = parent.parent;
1533 [EditorBrowsable(EditorBrowsableState.Advanced)]
1535 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1536 public bool Capture {
1538 return this.is_captured;
1542 if (this.IsHandleCreated) {
1543 if (value && !is_captured) {
1545 XplatUI.GrabWindow(this.window.Handle, IntPtr.Zero);
1546 } else if (!value && is_captured) {
1547 XplatUI.UngrabWindow(this.window.Handle);
1548 is_captured = false;
1554 [DefaultValue(true)]
1555 public bool CausesValidation {
1557 return this.causes_validation;
1561 if (this.causes_validation != value) {
1562 causes_validation = value;
1563 OnCausesValidationChanged(EventArgs.Empty);
1568 [EditorBrowsable(EditorBrowsableState.Advanced)]
1570 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1571 public Rectangle ClientRectangle {
1573 client_rect.Width = client_size.Width;
1574 client_rect.Height = client_size.Height;
1579 [EditorBrowsable(EditorBrowsableState.Advanced)]
1581 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1582 public Size ClientSize {
1585 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1586 return ((Form)this).form_parent_window.ClientSize;
1594 this.SetClientSizeCore(value.Width, value.Height);
1598 [EditorBrowsable(EditorBrowsableState.Advanced)]
1600 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1601 [DescriptionAttribute("ControlCompanyNameDescr")]
1602 public String CompanyName {
1604 return "Mono Project, Novell, Inc.";
1608 [EditorBrowsable(EditorBrowsableState.Advanced)]
1610 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1611 public bool ContainsFocus {
1617 for (int i=0; i < child_controls.Count; i++) {
1618 if (child_controls[i].ContainsFocus) {
1626 [DefaultValue(null)]
1627 public virtual ContextMenu ContextMenu {
1629 return context_menu;
1633 if (context_menu != value) {
1634 context_menu = value;
1635 OnContextMenuChanged(EventArgs.Empty);
1641 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
1642 public ControlCollection Controls {
1644 return this.child_controls;
1648 [EditorBrowsable(EditorBrowsableState.Advanced)]
1650 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1651 public bool Created {
1653 return (!is_disposed && is_created);
1657 [AmbientValue(null)]
1658 public virtual Cursor Cursor {
1660 if (cursor != null) {
1664 if (parent != null) {
1665 return parent.Cursor;
1668 return Cursors.Default;
1672 if (cursor != value) {
1677 if (IsHandleCreated) {
1678 pt = Cursor.Position;
1680 if (bounds.Contains(pt)) {
1681 if (GetChildAtPoint(pt) == null) {
1682 if (cursor != null) {
1683 XplatUI.SetCursor(window.Handle, cursor.handle);
1685 if (parent != null) {
1686 XplatUI.SetCursor(window.Handle, parent.Cursor.handle);
1688 XplatUI.SetCursor(window.Handle, Cursors.def.handle);
1695 OnCursorChanged(EventArgs.Empty);
1701 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
1702 [ParenthesizePropertyName(true)]
1703 [RefreshProperties(RefreshProperties.All)]
1704 public ControlBindingsCollection DataBindings {
1706 if (data_bindings == null)
1707 data_bindings = new ControlBindingsCollection (this);
1708 return data_bindings;
1712 [EditorBrowsable(EditorBrowsableState.Advanced)]
1714 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1715 public virtual Rectangle DisplayRectangle {
1717 return ClientRectangle;
1721 [EditorBrowsable(EditorBrowsableState.Advanced)]
1723 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1724 public bool Disposing {
1731 [RefreshProperties(RefreshProperties.Repaint)]
1732 [DefaultValue(DockStyle.None)]
1733 public virtual DockStyle Dock {
1739 if (dock_style == value) {
1745 if (parent != null) {
1746 parent.PerformLayout(this, "Parent");
1749 OnDockChanged(EventArgs.Empty);
1755 public bool Enabled {
1761 if (parent != null) {
1762 return parent.Enabled;
1769 if (is_enabled == value) {
1773 if (IsHandleCreated) {
1775 if (((Form)this).context == null) {
1776 XplatUI.EnableWindow(window.Handle, value);
1779 XplatUI.EnableWindow(window.Handle, value);
1784 OnEnabledChanged (EventArgs.Empty);
1788 [EditorBrowsable(EditorBrowsableState.Advanced)]
1790 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1791 public virtual bool Focused {
1793 return this.has_focus;
1798 [AmbientValue(null)]
1800 public virtual Font Font {
1806 if (Parent != null && Parent.Font != null) {
1814 if (font != null && font.Equals (value)) {
1820 OnFontChanged (EventArgs.Empty);
1825 public virtual Color ForeColor {
1827 if (foreground_color.IsEmpty) {
1829 return parent.ForeColor;
1831 return DefaultForeColor;
1833 return foreground_color;
1837 if (foreground_color != value) {
1838 foreground_color=value;
1840 OnForeColorChanged(EventArgs.Empty);
1847 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1848 public IntPtr Handle { // IWin32Window
1850 if (!IsHandleCreated) {
1853 return window.Handle;
1857 [EditorBrowsable(EditorBrowsableState.Advanced)]
1859 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1860 public bool HasChildren {
1862 if (this.child_controls.Count>0) {
1869 [EditorBrowsable(EditorBrowsableState.Always)]
1871 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1874 return this.bounds.Height;
1878 SetBoundsCore(bounds.X, bounds.Y, bounds.Width, value, BoundsSpecified.Height);
1882 [AmbientValue(ImeMode.Inherit)]
1884 public ImeMode ImeMode {
1886 if (ime_mode == DefaultImeMode) {
1888 return parent.ImeMode;
1890 return ImeMode.NoControl; // default value
1896 if (ime_mode != value) {
1899 OnImeModeChanged(EventArgs.Empty);
1904 [EditorBrowsable(EditorBrowsableState.Advanced)]
1906 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1907 public bool InvokeRequired { // ISynchronizeInvoke
1909 if (creator_thread != null && creator_thread!=Thread.CurrentThread) {
1916 [EditorBrowsable(EditorBrowsableState.Advanced)]
1918 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1919 public bool IsAccessible {
1921 return is_accessible;
1925 is_accessible = value;
1929 [EditorBrowsable(EditorBrowsableState.Advanced)]
1931 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1932 public bool IsDisposed {
1934 return this.is_disposed;
1938 [EditorBrowsable(EditorBrowsableState.Advanced)]
1940 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1941 public bool IsHandleCreated {
1943 if ((window != null) && (window.Handle != IntPtr.Zero)) {
1951 [EditorBrowsable(EditorBrowsableState.Always)]
1953 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1956 return this.bounds.X;
1960 SetBoundsCore(value, bounds.Y, bounds.Width, bounds.Height, BoundsSpecified.X);
1965 public Point Location {
1967 return new Point(bounds.X, bounds.Y);
1971 SetBoundsCore(value.X, value.Y, bounds.Width, bounds.Height, BoundsSpecified.Location);
1976 public string Name {
1988 public Padding Padding {
2000 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2001 public Control Parent {
2007 if (value == this) {
2008 throw new ArgumentException("A circular control reference has been made. A control cannot be owned or parented to itself.");
2011 if (parent!=value) {
2013 parent.Controls.Remove(this);
2017 value.Controls.Add(this);
2022 [EditorBrowsable(EditorBrowsableState.Advanced)]
2024 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2025 public string ProductName {
2027 Type t = typeof (AssemblyProductAttribute);
2028 Assembly assembly = GetType().Module.Assembly;
2029 object [] attrs = assembly.GetCustomAttributes (t, false);
2030 AssemblyProductAttribute a = null;
2031 // On MS we get a NullRefException if product attribute is not
2033 if (attrs != null && attrs.Length > 0)
2034 a = (AssemblyProductAttribute) attrs [0];
2039 [EditorBrowsable(EditorBrowsableState.Advanced)]
2041 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2042 public string ProductVersion {
2044 Type t = typeof (AssemblyVersionAttribute);
2045 Assembly assembly = GetType().Module.Assembly;
2046 object [] attrs = assembly.GetCustomAttributes (t, false);
2047 if (attrs == null || attrs.Length < 1)
2049 return ((AssemblyVersionAttribute)attrs [0]).Version;
2053 [EditorBrowsable(EditorBrowsableState.Advanced)]
2055 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2056 public bool RecreatingHandle {
2058 return is_recreating;
2062 [EditorBrowsable(EditorBrowsableState.Advanced)]
2064 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2065 public Region Region {
2067 return new Region(this.bounds);
2074 g = this.CreateGraphics();
2075 r = value.GetBounds(g);
2077 SetBounds((int)r.X, (int)r.Y, (int)r.Width, (int)r.Height);
2083 [EditorBrowsable(EditorBrowsableState.Advanced)]
2085 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2088 return this.bounds.X+this.bounds.Width;
2092 [AmbientValue(RightToLeft.Inherit)]
2094 public virtual RightToLeft RightToLeft {
2096 if (right_to_left == RightToLeft.Inherit) {
2098 return parent.RightToLeft;
2100 return RightToLeft.No; // default value
2102 return right_to_left;
2106 if (value != right_to_left) {
2107 right_to_left = value;
2108 OnRightToLeftChanged(EventArgs.Empty);
2113 [EditorBrowsable(EditorBrowsableState.Advanced)]
2114 public override ISite Site {
2122 AmbientProperties ap = (AmbientProperties) value.GetService (typeof (AmbientProperties));
2124 BackColor = ap.BackColor;
2125 ForeColor = ap.ForeColor;
2135 return new Size(Width, Height);
2139 SetBoundsCore(bounds.X, bounds.Y, value.Width, value.Height, BoundsSpecified.Size);
2144 [MergableProperty(false)]
2145 public int TabIndex {
2147 if (tab_index != -1) {
2154 if (tab_index != value) {
2156 OnTabIndexChanged(EventArgs.Empty);
2162 [DefaultValue(true)]
2163 public bool TabStop {
2169 if (tab_stop != value) {
2171 OnTabStopChanged(EventArgs.Empty);
2176 [Localizable(false)]
2178 [TypeConverter(typeof(StringConverter))]
2179 [DefaultValue(null)]
2186 control_tag = value;
2192 [BindableAttribute(true)]
2193 public virtual string Text {
2195 // Our implementation ignores ControlStyles.CacheText - we always cache
2200 if (value == null) {
2201 value = String.Empty;
2206 if (IsHandleCreated) {
2207 XplatUI.Text(Handle, text);
2209 OnTextChanged (EventArgs.Empty);
2214 [EditorBrowsable(EditorBrowsableState.Always)]
2216 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2219 return this.bounds.Y;
2223 SetBoundsCore(bounds.X, value, bounds.Width, bounds.Height, BoundsSpecified.Y);
2227 [EditorBrowsable(EditorBrowsableState.Advanced)]
2229 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2230 public Control TopLevelControl {
2234 while (p.parent != null) {
2243 public bool Visible {
2247 } else if (parent != null) {
2248 return parent.Visible;
2255 SetVisibleCore(value);
2259 [EditorBrowsable(EditorBrowsableState.Always)]
2261 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2264 return this.bounds.Width;
2268 SetBoundsCore(bounds.X, bounds.Y, value, bounds.Height, BoundsSpecified.Width);
2272 [EditorBrowsable(EditorBrowsableState.Never)]
2274 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2275 public IWindowTarget WindowTarget {
2284 #endregion // Public Instance Properties
2286 #region Protected Instance Properties
2287 protected virtual CreateParams CreateParams {
2289 CreateParams create_params = new CreateParams();
2292 create_params.Caption = Text;
2295 create_params.Caption = text;
2299 create_params.X = Left;
2302 create_params.X = this.bounds.X;
2306 create_params.Y = Top;
2309 create_params.Y = this.bounds.Y;
2313 create_params.Width = Width;
2316 create_params.Width = this.bounds.Width;
2320 create_params.Height = Height;
2323 create_params.Height = this.bounds.Height;
2327 create_params.ClassName = XplatUI.DefaultClassName;
2328 create_params.ClassStyle = 0;
2329 create_params.ExStyle = 0;
2330 create_params.Param = 0;
2333 create_params.ExStyle |= (int)WindowExStyles.WS_EX_ACCEPTFILES;
2336 if ((parent!=null) && (parent.IsHandleCreated)) {
2337 create_params.Parent = parent.Handle;
2340 create_params.Style = (int)WindowStyles.WS_CHILD | (int)WindowStyles.WS_CLIPCHILDREN | (int)WindowStyles.WS_CLIPSIBLINGS;
2343 create_params.Style |= (int)WindowStyles.WS_VISIBLE;
2347 create_params.Style |= (int)WindowStyles.WS_DISABLED;
2350 switch (border_style) {
2351 case BorderStyle.FixedSingle:
2352 create_params.Style |= (int) WindowStyles.WS_BORDER;
2354 case BorderStyle.Fixed3D:
2355 create_params.ExStyle |= (int) WindowExStyles.WS_EX_CLIENTEDGE;
2359 return create_params;
2363 protected virtual ImeMode DefaultImeMode {
2365 return ImeMode.Inherit;
2369 protected virtual Size DefaultSize {
2371 return new Size(0, 0);
2375 protected int FontHeight {
2385 protected bool RenderRightToLeft {
2387 return (this.right_to_left == RightToLeft.Yes);
2391 protected bool ResizeRedraw {
2393 return GetStyle(ControlStyles.ResizeRedraw);
2397 SetStyle(ControlStyles.ResizeRedraw, value);
2401 [EditorBrowsable(EditorBrowsableState.Advanced)]
2403 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2404 protected virtual bool ShowFocusCues {
2410 [EditorBrowsable(EditorBrowsableState.Advanced)]
2412 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2413 protected bool ShowKeyboardCues {
2418 #endregion // Protected Instance Properties
2420 #region Public Static Methods
2421 [EditorBrowsable(EditorBrowsableState.Advanced)]
2422 public static Control FromChildHandle(IntPtr handle) {
2423 IEnumerator control = Control.controls.GetEnumerator();
2425 while (control.MoveNext()) {
2426 if (((Control)control.Current).window.Handle == handle) {
2428 if (((Control)control.Current).Parent != null) {
2429 return ((Control)control.Current).Parent;
2436 [EditorBrowsable(EditorBrowsableState.Advanced)]
2437 public static Control FromHandle(IntPtr handle) {
2439 IEnumerator control = Control.controls.GetEnumerator();
2441 while (control.MoveNext()) {
2442 if (((Control)control.Current).window.Handle == handle) {
2444 return ((Control)control.Current);
2450 return Control.ControlNativeWindow.ControlFromHandle(handle);
2454 public static bool IsMnemonic(char charCode, string text) {
2457 amp = text.IndexOf('&');
2460 if (amp + 1 < text.Length) {
2461 if (text[amp + 1] != '&') {
2462 if (Char.ToUpper(charCode) == Char.ToUpper(text.ToCharArray(amp + 1, 1)[0])) {
2472 #region Protected Static Methods
2473 [EditorBrowsable(EditorBrowsableState.Advanced)]
2474 protected static bool ReflectMessage(IntPtr hWnd, ref Message m) {
2477 c = Control.FromHandle(hWnd);
2487 #region Public Instance Methods
2488 [EditorBrowsable(EditorBrowsableState.Advanced)]
2489 public IAsyncResult BeginInvoke(Delegate method) {
2490 object [] prms = null;
2491 if (method is EventHandler)
2492 prms = new object [] { this, EventArgs.Empty };
2493 return BeginInvokeInternal(method, prms, false);
2496 [EditorBrowsable(EditorBrowsableState.Advanced)]
2497 public IAsyncResult BeginInvoke (Delegate method, object[] args) {
2498 return BeginInvokeInternal (method, args, false);
2501 public void BringToFront() {
2502 if ((parent != null) && (parent.child_controls[0]!=this)) {
2503 if (parent.child_controls.Contains(this)) {
2504 parent.child_controls.SetChildIndex(this, 0);
2506 } else if (parent != null) {
2507 if (parent.child_controls.impl_list != null) {
2508 Control last_impl = (Control) parent.child_controls.impl_list [parent.child_controls.impl_list.Count - 1];
2509 if (IsHandleCreated) {
2510 XplatUI.SetZOrder (this.window.Handle, last_impl.Handle, false, false);
2513 if (IsHandleCreated) {
2514 XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, true, false);
2519 if (parent != null) {
2524 public bool Contains(Control ctl) {
2525 while (ctl != null) {
2534 public void CreateControl() {
2539 if (!IsHandleCreated) {
2547 Control [] controls = child_controls.GetAllControls ();
2548 for (int i=0; i<controls.Length; i++) {
2549 controls [i].CreateControl ();
2554 if (binding_context == null) { // seem to be sent whenever it's null?
2555 OnBindingContextChanged(EventArgs.Empty);
2561 public Graphics CreateGraphics() {
2562 if (!IsHandleCreated) {
2563 this.CreateHandle();
2565 return Graphics.FromHwnd(this.window.Handle);
2568 public DragDropEffects DoDragDrop(object data, DragDropEffects allowedEffects) {
2569 return XplatUI.StartDrag(this.window.Handle, data, allowedEffects);
2572 [EditorBrowsable(EditorBrowsableState.Advanced)]
2573 public object EndInvoke (IAsyncResult async_result) {
2574 AsyncMethodResult result = (AsyncMethodResult) async_result;
2575 return result.EndInvoke ();
2578 public Form FindForm() {
2591 public bool Focus() {
2592 if (CanFocus && IsHandleCreated && !has_focus) {
2593 XplatUI.SetFocus(window.Handle);
2598 public Control GetChildAtPoint(Point pt) {
2599 // Microsoft's version of this function doesn't seem to work, so I can't check
2600 // if we only consider children or also grandchildren, etc.
2601 // I'm gonna say 'children only'
2602 for (int i=0; i<child_controls.Count; i++) {
2603 if (child_controls[i].Bounds.Contains(pt)) {
2604 return child_controls[i];
2610 public IContainerControl GetContainerControl() {
2611 Control current = this;
2613 while (current!=null) {
2614 if ((current is IContainerControl) && ((current.control_style & ControlStyles.ContainerControl)!=0)) {
2615 return (IContainerControl)current;
2617 current = current.parent;
2622 public Control GetNextControl(Control ctl, bool forward) {
2623 // If we're not a container we don't play
2624 if (!(this is IContainerControl) && !this.GetStyle(ControlStyles.ContainerControl)) {
2628 // If ctl is not contained by this, we start at the first child of this
2629 if (!this.Contains(ctl)) {
2633 // Search through our controls, starting at ctl, stepping into children as we encounter them
2634 // try to find the control with the tabindex closest to our own, or, if we're looking into
2635 // child controls, the one with the smallest tabindex
2637 return FindControlForward(this, ctl);
2639 return FindControlBackward(this, ctl);
2642 public void Hide() {
2643 this.Visible = false;
2646 public void Invalidate() {
2647 Invalidate(ClientRectangle, false);
2650 public void Invalidate(bool invalidateChildren) {
2651 Invalidate(ClientRectangle, invalidateChildren);
2654 public void Invalidate(System.Drawing.Rectangle rc) {
2655 Invalidate(rc, false);
2658 public void Invalidate(System.Drawing.Rectangle rc, bool invalidateChildren) {
2659 if (!IsHandleCreated || !Visible || rc.Width == 0 || rc.Height == 0) {
2663 NotifyInvalidate(rc);
2665 XplatUI.Invalidate(Handle, rc, false);
2667 if (invalidateChildren) {
2668 Control [] controls = child_controls.GetAllControls ();
2669 for (int i=0; i<controls.Length; i++)
2670 controls [i].Invalidate ();
2672 OnInvalidated(new InvalidateEventArgs(rc));
2675 public void Invalidate(System.Drawing.Region region) {
2676 Invalidate(region, false);
2679 public void Invalidate(System.Drawing.Region region, bool invalidateChildren) {
2680 RectangleF bounds = region.GetBounds (CreateGraphics ());
2681 Invalidate (new Rectangle ((int) bounds.X, (int) bounds.Y, (int) bounds.Width, (int) bounds.Height),
2682 invalidateChildren);
2685 public object Invoke (Delegate method) {
2686 object [] prms = null;
2687 if (method is EventHandler)
2688 prms = new object [] { this, EventArgs.Empty };
2690 return Invoke(method, prms);
2693 public object Invoke (Delegate method, object[] args) {
2694 if (!this.InvokeRequired) {
2695 return method.DynamicInvoke(args);
2698 IAsyncResult result = BeginInvoke (method, args);
2699 return EndInvoke(result);
2702 internal object InvokeInternal (Delegate method, bool disposing) {
2703 return InvokeInternal(method, null, disposing);
2706 internal object InvokeInternal (Delegate method, object[] args, bool disposing) {
2707 if (!this.InvokeRequired) {
2708 return method.DynamicInvoke(args);
2711 IAsyncResult result = BeginInvokeInternal (method, args, disposing);
2712 return EndInvoke(result);
2715 [EditorBrowsable(EditorBrowsableState.Advanced)]
2716 public void PerformLayout() {
2717 PerformLayout(null, null);
2720 [EditorBrowsable(EditorBrowsableState.Advanced)]
2721 public void PerformLayout(Control affectedControl, string affectedProperty) {
2722 LayoutEventArgs levent = new LayoutEventArgs(affectedControl, affectedProperty);
2724 if (layout_suspended > 0) {
2725 layout_pending = true;
2729 layout_pending = false;
2731 // Prevent us from getting messed up
2734 // Perform all Dock and Anchor calculations
2737 AnchorStyles anchor;
2740 space= DisplayRectangle;
2742 // Deal with docking; go through in reverse, MS docs say that lowest Z-order is closest to edge
2743 Control [] controls = child_controls.GetAllControls ();
2744 for (int i = controls.Length - 1; i >= 0; i--) {
2745 child = controls [i];
2747 if (!child.Visible) {
2751 switch (child.Dock) {
2752 case DockStyle.None: {
2757 case DockStyle.Left: {
2758 child.SetBounds(space.Left, space.Y, child.Width, space.Height);
2759 space.X+=child.Width;
2760 space.Width-=child.Width;
2764 case DockStyle.Top: {
2765 child.SetBounds(space.Left, space.Y, space.Width, child.Height);
2766 space.Y+=child.Height;
2767 space.Height-=child.Height;
2771 case DockStyle.Right: {
2772 child.SetBounds(space.Right-child.Width, space.Y, child.Width, space.Height);
2773 space.Width-=child.Width;
2777 case DockStyle.Bottom: {
2778 child.SetBounds(space.Left, space.Bottom-child.Height, space.Width, child.Height);
2779 space.Height-=child.Height;
2785 for (int i = controls.Length - 1; i >= 0; i--) {
2788 if (child.Visible && (child.Dock == DockStyle.Fill)) {
2789 child.SetBounds(space.Left, space.Top, space.Width, space.Height);
2795 space=DisplayRectangle;
2797 for (int i=0; i < controls.Length; i++) {
2803 child = controls[i];
2805 // If the control is docked we don't need to do anything
2806 if (child.Dock != DockStyle.None) {
2810 anchor = child.Anchor;
2814 width = child.Width;
2815 height = child.Height;
2817 if ((anchor & AnchorStyles.Left) !=0 ) {
2818 if ((anchor & AnchorStyles.Right) != 0) {
2819 width = space.Width - child.dist_right - left;
2821 ; // Left anchored only, nothing to be done
2823 } else if ((anchor & AnchorStyles.Right) != 0) {
2824 left = space.Width - child.dist_right - width;
2826 // left+=diff_width/2 will introduce rounding errors (diff_width removed from svn after r51780)
2827 // This calculates from scratch every time:
2828 left = child.dist_left + (space.Width - (child.dist_left + width + child.dist_right)) / 2;
2831 if ((anchor & AnchorStyles.Top) !=0 ) {
2832 if ((anchor & AnchorStyles.Bottom) != 0) {
2833 height = space.Height - child.dist_bottom - top;
2835 ; // Top anchored only, nothing to be done
2837 } else if ((anchor & AnchorStyles.Bottom) != 0) {
2838 top = space.Height - child.dist_bottom - height;
2840 // top += diff_height/2 will introduce rounding errors (diff_height removed from after r51780)
2841 // This calculates from scratch every time:
2842 top = child.dist_top + (space.Height - (child.dist_top + height + child.dist_bottom)) / 2;
2854 child.SetBounds(left, top, width, height);
2857 // Let everyone know
2861 // Need to make sure we decremend layout_suspended
2867 public Point PointToClient (Point p) {
2871 XplatUI.ScreenToClient (Handle, ref x, ref y);
2873 return new Point (x, y);
2876 public Point PointToScreen(Point p) {
2880 XplatUI.ClientToScreen(Handle, ref x, ref y);
2882 return new Point(x, y);
2885 public virtual bool PreProcessMessage(ref Message msg) {
2888 if ((msg.Msg == (int)Msg.WM_KEYDOWN) || (msg.Msg == (int)Msg.WM_SYSKEYDOWN)) {
2889 key_data = (Keys)msg.WParam.ToInt32() | XplatUI.State.ModifierKeys;
2891 if (!ProcessCmdKey(ref msg, key_data)) {
2892 if (IsInputKey(key_data)) {
2896 return ProcessDialogKey(key_data);
2900 } else if (msg.Msg == (int)Msg.WM_CHAR) {
2901 if (IsInputChar((char)msg.WParam)) {
2904 } else if (msg.Msg == (int)Msg.WM_SYSCHAR) {
2905 if (IsInputChar((char)msg.WParam)) {
2908 return ProcessDialogChar((char)msg.WParam);
2913 public Rectangle RectangleToClient(Rectangle r) {
2914 return new Rectangle(PointToClient(r.Location), r.Size);
2917 public Rectangle RectangleToScreen(Rectangle r) {
2918 return new Rectangle(PointToScreen(r.Location), r.Size);
2921 public virtual void Refresh() {
2922 if (IsHandleCreated == true) {
2925 XplatUI.UpdateWindow(window.Handle);
2927 Control [] controls = child_controls.GetAllControls ();
2928 for (int i=0; i < controls.Length; i++) {
2929 controls[i].Refresh();
2935 [EditorBrowsable(EditorBrowsableState.Never)]
2936 public virtual void ResetBackColor() {
2937 background_color = Color.Empty;
2940 [EditorBrowsable(EditorBrowsableState.Never)]
2942 public void ResetBindings() {
2946 [EditorBrowsable(EditorBrowsableState.Never)]
2947 public virtual void ResetCursor() {
2951 [EditorBrowsable(EditorBrowsableState.Never)]
2952 public virtual void ResetFont() {
2956 [EditorBrowsable(EditorBrowsableState.Never)]
2957 public virtual void ResetForeColor() {
2958 foreground_color = Color.Empty;
2961 [EditorBrowsable(EditorBrowsableState.Never)]
2962 public void ResetImeMode() {
2963 ime_mode = DefaultImeMode;
2966 [EditorBrowsable(EditorBrowsableState.Never)]
2967 public virtual void ResetRightToLeft() {
2968 right_to_left = RightToLeft.Inherit;
2971 public virtual void ResetText() {
2972 text = String.Empty;
2975 public void ResumeLayout() {
2976 ResumeLayout (true);
2979 public void ResumeLayout(bool performLayout) {
2980 if (layout_suspended > 0) {
2984 if (layout_suspended == 0) {
2985 Control [] controls = child_controls.GetAllControls ();
2986 for (int i=0; i<controls.Length; i++) {
2987 controls [i].UpdateDistances ();
2990 if (performLayout && layout_pending) {
2996 public void Scale(float ratio) {
2997 ScaleCore(ratio, ratio);
3000 public void Scale(float dx, float dy) {
3004 public void Select() {
3005 Select(false, false);
3008 public bool SelectNextControl(Control ctl, bool forward, bool tabStopOnly, bool nested, bool wrap) {
3013 c = GetNextControl(c, forward);
3022 if (c.CanSelect && ((c.parent == ctl.parent) || nested) && (c.tab_stop || !tabStopOnly)) {
3026 } while (c != ctl); // If we wrap back to ourselves we stop
3031 public void SendToBack() {
3032 if ((parent != null) && (parent.child_controls[parent.child_controls.Count-1]!=this)) {
3033 if (parent.child_controls.Contains(this)) {
3034 parent.child_controls.SetChildIndex(this, parent.child_controls.Count);
3038 if (IsHandleCreated) {
3039 XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, false, true);
3042 if (parent != null) {
3047 public void SetBounds(int x, int y, int width, int height) {
3048 SetBoundsCore(x, y, width, height, BoundsSpecified.All);
3051 public void SetBounds(int x, int y, int width, int height, BoundsSpecified specified) {
3052 SetBoundsCore(x, y, width, height, specified);
3055 public void Show() {
3057 this.CreateControl();
3063 public void SuspendLayout() {
3067 public void Update() {
3068 needs_redraw = true;
3069 if (IsHandleCreated) {
3070 XplatUI.UpdateWindow(window.Handle);
3073 #endregion // Public Instance Methods
3075 #region Protected Instance Methods
3076 [EditorBrowsable(EditorBrowsableState.Advanced)]
3077 [MonoTODO("Implement this and tie it into Control.ControlAccessibleObject.NotifyClients")]
3078 protected void AccessibilityNotifyClients(AccessibleEvents accEvent, int childID) {
3079 throw new NotImplementedException();
3082 [EditorBrowsable(EditorBrowsableState.Advanced)]
3083 protected virtual AccessibleObject CreateAccessibilityInstance() {
3084 return new Control.ControlAccessibleObject(this);
3087 [EditorBrowsable(EditorBrowsableState.Advanced)]
3088 protected virtual ControlCollection CreateControlsInstance() {
3089 return new ControlCollection(this);
3092 [EditorBrowsable(EditorBrowsableState.Advanced)]
3093 protected virtual void CreateHandle() {
3095 throw new ObjectDisposedException(Name);
3098 if (IsHandleCreated && !is_recreating) {
3102 window.CreateHandle(CreateParams);
3104 if (window.Handle != IntPtr.Zero) {
3105 if (!controls.Contains(window.Handle)) {
3109 creator_thread = Thread.CurrentThread;
3111 XplatUI.EnableWindow(window.Handle, is_enabled);
3113 // Set our handle with our parent
3114 if ((parent != null) && (parent.IsHandleCreated)) {
3115 XplatUI.SetParent(window.Handle, parent.Handle);
3118 // Set our handle as parent for our children
3119 Control [] children;
3121 children = child_controls.GetAllControls ();
3122 for (int i = 0; i < children.Length; i++ ) {
3123 if (children[i].IsHandleCreated) {
3124 XplatUI.SetParent(children[i].Handle, window.Handle);
3128 // Find out where the window manager placed us
3130 if ((CreateParams.Style & (int)WindowStyles.WS_CHILD) != 0) {
3131 XplatUI.SetBorderStyle(window.Handle, (FormBorderStyle)border_style);
3135 OnHandleCreated(EventArgs.Empty);
3140 [EditorBrowsable(EditorBrowsableState.Advanced)]
3141 protected virtual void DefWndProc(ref Message m) {
3142 window.DefWndProc(ref m);
3145 [EditorBrowsable(EditorBrowsableState.Advanced)]
3146 protected virtual void DestroyHandle() {
3147 if (IsHandleCreated) {
3148 if (window != null) {
3149 window.DestroyHandle();
3154 protected bool GetStyle(ControlStyles flag) {
3155 return (control_style & flag) != 0;
3158 protected bool GetTopLevel() {
3162 [EditorBrowsable(EditorBrowsableState.Advanced)]
3163 protected virtual void InitLayout() {
3167 [EditorBrowsable(EditorBrowsableState.Advanced)]
3168 protected void InvokeGotFocus(Control toInvoke, EventArgs e) {
3169 toInvoke.OnGotFocus(e);
3172 [EditorBrowsable(EditorBrowsableState.Advanced)]
3173 protected void InvokeLostFocus(Control toInvoke, EventArgs e) {
3174 toInvoke.OnLostFocus(e);
3177 [EditorBrowsable(EditorBrowsableState.Advanced)]
3178 protected void InvokeOnClick(Control toInvoke, EventArgs e) {
3179 toInvoke.OnClick(e);
3182 protected void InvokePaint(Control toInvoke, PaintEventArgs e) {
3183 toInvoke.OnPaint(e);
3186 protected void InvokePaintBackground(Control toInvoke, PaintEventArgs e) {
3187 toInvoke.OnPaintBackground(e);
3190 protected virtual bool IsInputChar (char charCode) {
3194 protected virtual bool IsInputKey (Keys keyData) {
3195 // Doc says this one calls IsInputChar; not sure what to do with that
3199 [EditorBrowsable(EditorBrowsableState.Advanced)]
3200 protected virtual void NotifyInvalidate(Rectangle invalidatedArea) {
3204 protected virtual bool ProcessCmdKey(ref Message msg, Keys keyData) {
3205 if ((context_menu != null) && context_menu.ProcessCmdKey(ref msg, keyData)) {
3209 if (parent != null) {
3210 return parent.ProcessCmdKey(ref msg, keyData);
3216 protected virtual bool ProcessDialogChar(char charCode) {
3217 if (parent != null) {
3218 return parent.ProcessDialogChar (charCode);
3224 protected virtual bool ProcessDialogKey (Keys keyData) {
3225 if (parent != null) {
3226 return parent.ProcessDialogKey (keyData);
3232 protected virtual bool ProcessKeyEventArgs (ref Message msg)
3234 KeyEventArgs key_event;
3237 case (int)Msg.WM_SYSKEYDOWN:
3238 case (int)Msg.WM_KEYDOWN: {
3239 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
3240 OnKeyDown (key_event);
3241 return key_event.Handled;
3244 case (int)Msg.WM_SYSKEYUP:
3245 case (int)Msg.WM_KEYUP: {
3246 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
3247 OnKeyUp (key_event);
3248 return key_event.Handled;
3251 case (int)Msg.WM_SYSCHAR:
3252 case (int)Msg.WM_CHAR: {
3253 KeyPressEventArgs key_press_event;
3255 key_press_event = new KeyPressEventArgs((char)msg.WParam);
3256 OnKeyPress(key_press_event);
3257 return key_press_event.Handled;
3268 protected internal virtual bool ProcessKeyMessage(ref Message msg) {
3269 if (parent != null) {
3270 if (parent.ProcessKeyPreview(ref msg)) {
3275 return ProcessKeyEventArgs(ref msg);
3278 protected virtual bool ProcessKeyPreview(ref Message msg) {
3279 if (parent != null) {
3280 return parent.ProcessKeyPreview(ref msg);
3286 protected virtual bool ProcessMnemonic(char charCode) {
3291 [EditorBrowsable(EditorBrowsableState.Advanced)]
3292 protected void RaiseDragEvent(object key, DragEventArgs e) {
3296 [EditorBrowsable(EditorBrowsableState.Advanced)]
3297 protected void RaiseKeyEvent(object key, KeyEventArgs e) {
3301 [EditorBrowsable(EditorBrowsableState.Advanced)]
3302 protected void RaiseMouseEvent(object key, MouseEventArgs e) {
3306 [EditorBrowsable(EditorBrowsableState.Advanced)]
3307 protected void RaisePaintEvent(object key, PaintEventArgs e) {
3311 [EditorBrowsable(EditorBrowsableState.Advanced)]
3312 protected void RecreateHandle() {
3315 if (IsHandleCreated) {
3317 // WM_DESTROY will CreateHandle for us
3326 is_recreating = false;
3329 [EditorBrowsable(EditorBrowsableState.Advanced)]
3330 protected void ResetMouseEventArgs() {
3334 [EditorBrowsable(EditorBrowsableState.Advanced)]
3335 protected ContentAlignment RtlTranslateAlignment(ContentAlignment align) {
3336 if (right_to_left == RightToLeft.No) {
3341 case ContentAlignment.TopLeft: {
3342 return ContentAlignment.TopRight;
3345 case ContentAlignment.TopRight: {
3346 return ContentAlignment.TopLeft;
3349 case ContentAlignment.MiddleLeft: {
3350 return ContentAlignment.MiddleRight;
3353 case ContentAlignment.MiddleRight: {
3354 return ContentAlignment.MiddleLeft;
3357 case ContentAlignment.BottomLeft: {
3358 return ContentAlignment.BottomRight;
3361 case ContentAlignment.BottomRight: {
3362 return ContentAlignment.BottomLeft;
3366 // if it's center it doesn't change
3372 [EditorBrowsable(EditorBrowsableState.Advanced)]
3373 protected HorizontalAlignment RtlTranslateAlignment(HorizontalAlignment align) {
3374 if ((right_to_left == RightToLeft.No) || (align == HorizontalAlignment.Center)) {
3378 if (align == HorizontalAlignment.Left) {
3379 return HorizontalAlignment.Right;
3382 // align must be HorizontalAlignment.Right
3383 return HorizontalAlignment.Left;
3386 [EditorBrowsable(EditorBrowsableState.Advanced)]
3387 protected LeftRightAlignment RtlTranslateAlignment(LeftRightAlignment align) {
3388 if (right_to_left == RightToLeft.No) {
3392 if (align == LeftRightAlignment.Left) {
3393 return LeftRightAlignment.Right;
3396 // align must be LeftRightAlignment.Right;
3397 return LeftRightAlignment.Left;
3400 [EditorBrowsable(EditorBrowsableState.Advanced)]
3401 protected ContentAlignment RtlTranslateContent(ContentAlignment align) {
3402 return RtlTranslateAlignment(align);
3405 [EditorBrowsable(EditorBrowsableState.Advanced)]
3406 protected HorizontalAlignment RtlTranslateHorizontal(HorizontalAlignment align) {
3407 return RtlTranslateAlignment(align);
3410 [EditorBrowsable(EditorBrowsableState.Advanced)]
3411 protected LeftRightAlignment RtlTranslateLeftRight(LeftRightAlignment align) {
3412 return RtlTranslateAlignment(align);
3415 [EditorBrowsable(EditorBrowsableState.Advanced)]
3416 protected virtual void ScaleCore(float dx, float dy) {
3422 location = new Point((int)(Left * dx), (int)(Top * dy));
3423 size = this.ClientSize;
3425 if (!GetStyle(ControlStyles.FixedWidth)) {
3426 size.Width = (int)(size.Width * dx);
3429 if (!GetStyle(ControlStyles.FixedHeight)) {
3430 size.Height = (int)(size.Height * dy);
3433 SetBoundsCore(location.X, location.Y, size.Width, size.Height, BoundsSpecified.All);
3435 /* Now scale our children */
3436 Control [] controls = child_controls.GetAllControls ();
3437 for (int i=0; i < controls.Length; i++) {
3438 controls[i].Scale(dx, dy);
3444 protected virtual void Select(bool directed, bool forward) {
3449 // Select this control
3454 if (parent == null) {
3458 // FIXME - this thing is doing the wrong stuff, needs to be similar to SelectNextControl
3460 index = parent.child_controls.IndexOf(this);
3465 if ((index+1) < parent.child_controls.Count) {
3474 index = parent.child_controls.Count-1;
3477 result = Select(parent.child_controls[index]);
3478 } while (!result && parent.child_controls[index] != this);
3481 [EditorBrowsable(EditorBrowsableState.Advanced)]
3482 protected virtual void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
3483 // SetBoundsCore updates the Win32 control itself. UpdateBounds updates the controls variables and fires events, I'm guessing - pdb
3484 if ((specified & BoundsSpecified.X) != BoundsSpecified.X) {
3488 if ((specified & BoundsSpecified.Y) != BoundsSpecified.Y) {
3492 if ((specified & BoundsSpecified.Width) != BoundsSpecified.Width) {
3496 if ((specified & BoundsSpecified.Height) != BoundsSpecified.Height) {
3500 if (IsHandleCreated) {
3501 XplatUI.SetWindowPos(Handle, x, y, width, height);
3504 UpdateBounds(x, y, width, height);
3509 [EditorBrowsable(EditorBrowsableState.Advanced)]
3510 protected virtual void SetClientSizeCore(int x, int y) {
3511 // Calculate the actual window size from the client size (it usually stays the same or grows)
3512 Rectangle ClientRect;
3513 Rectangle WindowRect;
3516 ClientRect = new Rectangle(0, 0, x, y);
3517 cp = this.CreateParams;
3519 if (XplatUI.CalculateWindowRect(ref ClientRect, cp.Style, cp.ExStyle, null, out WindowRect)==false) {
3523 SetBoundsCore(bounds.X, bounds.Y, WindowRect.Width, WindowRect.Height, BoundsSpecified.Size);
3526 [EditorBrowsable(EditorBrowsableState.Advanced)]
3527 protected void SetStyle(ControlStyles flag, bool value) {
3529 control_style |= flag;
3531 control_style &= ~flag;
3533 OnStyleChanged(EventArgs.Empty);
3536 protected void SetTopLevel(bool value) {
3537 if ((GetTopLevel() != value) && (parent != null)) {
3538 throw new Exception();
3542 if (value == true) {
3552 is_toplevel = value;
3555 protected virtual void SetVisibleCore(bool value) {
3556 if (value!=is_visible) {
3559 if (IsHandleCreated) {
3560 XplatUI.SetVisible(Handle, value);
3561 // Explicitly move Toplevel windows to where we want them;
3562 // apparently moving unmapped toplevel windows doesn't work
3563 if (is_visible && (this is Form)) {
3564 XplatUI.SetWindowPos(window.Handle, bounds.X, bounds.Y, bounds.Width, bounds.Height);
3568 if (is_visible && !is_created) {
3572 OnVisibleChanged(EventArgs.Empty);
3574 if (value == false && parent != null) {
3577 // Need to start at parent, GetContainerControl might return ourselves if we're a container
3578 container = (Control)parent.GetContainerControl();
3579 if (container != null) {
3580 container.SelectNextControl(this, true, true, true, true);
3584 if (parent != null) {
3585 parent.PerformLayout(this, "visible");
3587 PerformLayout(this, "visible");
3592 [EditorBrowsable(EditorBrowsableState.Advanced)]
3593 protected void UpdateBounds() {
3601 if (!IsHandleCreated) {
3605 XplatUI.GetWindowPos(this.Handle, this is Form, out x, out y, out width, out height, out client_width, out client_height);
3607 UpdateBounds(x, y, width, height, client_width, client_height);
3610 [EditorBrowsable(EditorBrowsableState.Advanced)]
3611 protected void UpdateBounds(int x, int y, int width, int height) {
3615 // Calculate client rectangle
3616 rect = new Rectangle(0, 0, 0, 0);
3619 XplatUI.CalculateWindowRect(ref rect, cp.Style, cp.ExStyle, cp.menu, out rect);
3620 UpdateBounds(x, y, width, height, width - (rect.Right - rect.Left), height - (rect.Bottom - rect.Top));
3623 [EditorBrowsable(EditorBrowsableState.Advanced)]
3624 protected void UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) {
3625 // UpdateBounds only seems to set our sizes and fire events but not update the GUI window to match
3627 bool resized = false;
3629 // Needed to generate required notifications
3630 if ((this.bounds.X!=x) || (this.bounds.Y!=y)) {
3634 if ((this.Bounds.Width!=width) || (this.Bounds.Height!=height)) {
3641 bounds.Height=height;
3643 client_size.Width=clientWidth;
3644 client_size.Height=clientHeight;
3647 OnLocationChanged(EventArgs.Empty);
3651 OnSizeChanged(EventArgs.Empty);
3655 [EditorBrowsable(EditorBrowsableState.Advanced)]
3656 protected void UpdateStyles() {
3657 if (!IsHandleCreated) {
3661 XplatUI.SetWindowStyle(window.Handle, CreateParams);
3664 [EditorBrowsable(EditorBrowsableState.Advanced)]
3665 protected void UpdateZOrder() {
3666 Control [] controls;
3667 if (!IsHandleCreated) {
3671 controls = child_controls.GetAllControls ();
3672 for (int i = 1; i < controls.Length; i++ ) {
3673 XplatUI.SetZOrder(controls[i].Handle, controls[i-1].Handle, false, false);
3677 protected virtual void WndProc(ref Message m) {
3679 Console.WriteLine("Control {0} received message {1}", window.Handle == IntPtr.Zero ? this.Text : XplatUI.Window(window.Handle), (Msg)m.Msg);
3681 if ((this.control_style & ControlStyles.EnableNotifyMessage) != 0) {
3685 switch((Msg)m.Msg) {
3686 case Msg.WM_DESTROY: {
3687 OnHandleDestroyed(EventArgs.Empty);
3688 window.InvalidateHandle();
3690 if (ParentIsRecreating) {
3692 } else if (is_recreating) {
3698 case Msg.WM_WINDOWPOSCHANGED: {
3701 if (GetStyle(ControlStyles.ResizeRedraw)) {
3708 case Msg.WM_PAINT: {
3709 PaintEventArgs paint_event;
3711 paint_event = XplatUI.PaintEventStart(Handle, true);
3713 if (!needs_redraw) {
3714 // Just blit the previous image
3715 paint_event.Graphics.DrawImage (ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle, GraphicsUnit.Pixel);
3716 XplatUI.PaintEventEnd(Handle, true);
3721 if (ThemeEngine.Current.DoubleBufferingSupported)
3722 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
3723 dc = paint_event.SetGraphics (DeviceContext);
3726 OnPaintBackground(paint_event);
3727 // Leave out for now, our controls can do Paint += ... as well
3728 //OnPaintInternal(paint_event);
3729 OnPaint(paint_event);
3731 if (ThemeEngine.Current.DoubleBufferingSupported)
3732 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
3733 dc.DrawImage (ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle, GraphicsUnit.Pixel);
3734 paint_event.SetGraphics (dc);
3735 needs_redraw = false;
3738 XplatUI.PaintEventEnd(Handle, true);
3743 case Msg.WM_ERASEBKGND: {
3744 // The DefWndProc will never have to handle this, we always paint the background in managed code
3745 m.Result = (IntPtr)1;
3749 case Msg.WM_LBUTTONUP: {
3752 me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Left,
3754 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3757 HandleClick(mouse_clicks, me);
3764 if (mouse_clicks > 1) {
3770 case Msg.WM_LBUTTONDOWN: {
3771 if (CanSelect && !is_selected) {
3775 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3776 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3782 case Msg.WM_LBUTTONDBLCLK: {
3785 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3786 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3792 case Msg.WM_MBUTTONUP: {
3795 me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Middle,
3797 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3800 HandleClick(mouse_clicks, me);
3805 if (mouse_clicks > 1) {
3811 case Msg.WM_MBUTTONDOWN: {
3813 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3814 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3820 case Msg.WM_MBUTTONDBLCLK: {
3823 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3824 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3829 case Msg.WM_RBUTTONUP: {
3832 if (context_menu != null) {
3833 context_menu.Show(this, new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ())));
3835 me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Right,
3837 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3840 HandleClick(mouse_clicks, me);
3847 if (mouse_clicks > 1) {
3853 case Msg.WM_RBUTTONDOWN: {
3855 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3856 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3861 case Msg.WM_RBUTTONDBLCLK: {
3864 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3865 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3870 case Msg.WM_MOUSEWHEEL: {
3872 OnMouseWheel (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3873 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3874 HighOrder(m.WParam.ToInt32())));
3879 case Msg.WM_MOUSEMOVE: {
3880 OnMouseMove (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3882 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3887 case Msg.WM_MOUSE_ENTER: {
3892 OnMouseEnter(EventArgs.Empty);
3896 case Msg.WM_MOUSE_LEAVE: {
3898 OnMouseLeave(EventArgs.Empty);
3902 case Msg.WM_MOUSEHOVER: {
3903 OnMouseHover(EventArgs.Empty);
3907 case Msg.WM_SYSKEYUP: {
3908 if (ProcessKeyMessage(ref m)) {
3909 m.Result = IntPtr.Zero;
3913 if ((m.WParam.ToInt32() & (int)Keys.KeyCode) == (int)Keys.Menu) {
3917 if (form != null && form.ActiveMenu != null) {
3918 form.ActiveMenu.ProcessCmdKey(ref m, (Keys)m.WParam.ToInt32());
3926 case Msg.WM_SYSKEYDOWN:
3927 case Msg.WM_KEYDOWN:
3929 case Msg.WM_SYSCHAR:
3931 if (ProcessKeyMessage(ref m)) {
3932 m.Result = IntPtr.Zero;
3941 if (m.LParam != IntPtr.Zero) {
3944 hi = new HELPINFO();
3946 hi = (HELPINFO) Marshal.PtrToStructure (m.LParam, typeof (HELPINFO));
3947 mouse_pos = new Point(hi.MousePos.x, hi.MousePos.y);
3949 mouse_pos = Control.MousePosition;
3951 OnHelpRequested(new HelpEventArgs(mouse_pos));
3952 m.Result = (IntPtr)1;
3956 case Msg.WM_KILLFOCUS: {
3957 OnLeave(EventArgs.Empty);
3958 if (CausesValidation) {
3960 e = new CancelEventArgs(false);
3969 OnValidated(EventArgs.Empty);
3972 this.has_focus = false;
3973 this.is_selected = false;
3974 OnLostFocus(EventArgs.Empty);
3978 case Msg.WM_SETFOCUS: {
3979 OnEnter(EventArgs.Empty);
3980 this.has_focus = true;
3981 OnGotFocus(EventArgs.Empty);
3986 case Msg.WM_SYSCOLORCHANGE: {
3987 ThemeEngine.Current.ResetDefaults();
3988 OnSystemColorsChanged(EventArgs.Empty);
3993 case Msg.WM_SETCURSOR: {
3994 if ((cursor == null) || ((HitTest)(m.LParam.ToInt32() & 0xffff) != HitTest.HTCLIENT)) {
3999 XplatUI.SetCursor(window.Handle, cursor.handle);
4000 m.Result = (IntPtr)1;
4011 #endregion // Public Instance Methods
4013 #region OnXXX methods
4014 [EditorBrowsable(EditorBrowsableState.Advanced)]
4015 protected virtual void OnBackColorChanged(EventArgs e) {
4016 if (BackColorChanged!=null) BackColorChanged(this, e);
4017 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackColorChanged(e);
4020 [EditorBrowsable(EditorBrowsableState.Advanced)]
4021 protected virtual void OnBackgroundImageChanged(EventArgs e) {
4022 if (BackgroundImageChanged!=null) BackgroundImageChanged(this, e);
4023 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackgroundImageChanged(e);
4026 [EditorBrowsable(EditorBrowsableState.Advanced)]
4027 protected virtual void OnBindingContextChanged(EventArgs e) {
4028 CheckDataBindings ();
4029 if (BindingContextChanged!=null) {
4030 BindingContextChanged(this, e);
4032 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBindingContextChanged(e);
4035 [EditorBrowsable(EditorBrowsableState.Advanced)]
4036 protected virtual void OnCausesValidationChanged(EventArgs e) {
4037 if (CausesValidationChanged!=null) CausesValidationChanged(this, e);
4040 [EditorBrowsable(EditorBrowsableState.Advanced)]
4041 protected virtual void OnChangeUICues(UICuesEventArgs e) {
4042 if (ChangeUICues!=null) ChangeUICues(this, e);
4045 [EditorBrowsable(EditorBrowsableState.Advanced)]
4046 protected virtual void OnClick(EventArgs e) {
4047 if (Click!=null) Click(this, e);
4050 [EditorBrowsable(EditorBrowsableState.Advanced)]
4051 protected virtual void OnContextMenuChanged(EventArgs e) {
4052 if (ContextMenuChanged!=null) ContextMenuChanged(this, e);
4055 [EditorBrowsable(EditorBrowsableState.Advanced)]
4056 protected virtual void OnControlAdded(ControlEventArgs e) {
4057 if (ControlAdded!=null) ControlAdded(this, e);
4060 [EditorBrowsable(EditorBrowsableState.Advanced)]
4061 protected virtual void OnControlRemoved(ControlEventArgs e) {
4062 if (ControlRemoved!=null) ControlRemoved(this, e);
4065 [EditorBrowsable(EditorBrowsableState.Advanced)]
4066 protected virtual void OnCreateControl() {
4070 [EditorBrowsable(EditorBrowsableState.Advanced)]
4071 protected virtual void OnCursorChanged(EventArgs e) {
4072 if (CursorChanged!=null) CursorChanged(this, e);
4075 [EditorBrowsable(EditorBrowsableState.Advanced)]
4076 protected virtual void OnDockChanged(EventArgs e) {
4077 if (DockChanged!=null) DockChanged(this, e);
4080 [EditorBrowsable(EditorBrowsableState.Advanced)]
4081 protected virtual void OnDoubleClick(EventArgs e) {
4082 if (DoubleClick!=null) DoubleClick(this, e);
4085 [EditorBrowsable(EditorBrowsableState.Advanced)]
4086 protected virtual void OnDragDrop(DragEventArgs drgevent) {
4087 if (DragDrop!=null) DragDrop(this, drgevent);
4090 [EditorBrowsable(EditorBrowsableState.Advanced)]
4091 protected virtual void OnDragEnter(DragEventArgs drgevent) {
4092 if (DragEnter!=null) DragEnter(this, drgevent);
4095 [EditorBrowsable(EditorBrowsableState.Advanced)]
4096 protected virtual void OnDragLeave(EventArgs e) {
4097 if (DragLeave!=null) DragLeave(this, e);
4100 [EditorBrowsable(EditorBrowsableState.Advanced)]
4101 protected virtual void OnDragOver(DragEventArgs drgevent) {
4102 if (DragOver!=null) DragOver(this, drgevent);
4105 [EditorBrowsable(EditorBrowsableState.Advanced)]
4106 protected virtual void OnEnabledChanged(EventArgs e) {
4107 if (EnabledChanged!=null) EnabledChanged(this, e);
4108 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentEnabledChanged(e);
4111 [EditorBrowsable(EditorBrowsableState.Advanced)]
4112 protected virtual void OnEnter(EventArgs e) {
4113 if (Enter!=null) Enter(this, e);
4116 [EditorBrowsable(EditorBrowsableState.Advanced)]
4117 protected virtual void OnFontChanged(EventArgs e) {
4118 if (FontChanged!=null) FontChanged(this, e);
4119 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentFontChanged(e);
4122 [EditorBrowsable(EditorBrowsableState.Advanced)]
4123 protected virtual void OnForeColorChanged(EventArgs e) {
4124 if (ForeColorChanged!=null) ForeColorChanged(this, e);
4125 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentForeColorChanged(e);
4128 [EditorBrowsable(EditorBrowsableState.Advanced)]
4129 protected virtual void OnGiveFeedback(GiveFeedbackEventArgs gfbevent) {
4130 if (GiveFeedback!=null) GiveFeedback(this, gfbevent);
4133 [EditorBrowsable(EditorBrowsableState.Advanced)]
4134 protected virtual void OnGotFocus(EventArgs e) {
4135 if (GotFocus!=null) GotFocus(this, e);
4138 [EditorBrowsable(EditorBrowsableState.Advanced)]
4139 protected virtual void OnHandleCreated(EventArgs e) {
4140 if (HandleCreated!=null) HandleCreated(this, e);
4143 [EditorBrowsable(EditorBrowsableState.Advanced)]
4144 protected virtual void OnHandleDestroyed(EventArgs e) {
4145 if (HandleDestroyed!=null) HandleDestroyed(this, e);
4148 [EditorBrowsable(EditorBrowsableState.Advanced)]
4149 protected virtual void OnHelpRequested(HelpEventArgs hevent) {
4150 if (HelpRequested!=null) HelpRequested(this, hevent);
4153 protected virtual void OnImeModeChanged(EventArgs e) {
4154 if (ImeModeChanged!=null) ImeModeChanged(this, e);
4157 [EditorBrowsable(EditorBrowsableState.Advanced)]
4158 protected virtual void OnInvalidated(InvalidateEventArgs e) {
4159 needs_redraw = true;
4160 if (Invalidated!=null) Invalidated(this, e);
4163 [EditorBrowsable(EditorBrowsableState.Advanced)]
4164 protected virtual void OnKeyDown(KeyEventArgs e) {
4165 if (KeyDown!=null) KeyDown(this, e);
4168 [EditorBrowsable(EditorBrowsableState.Advanced)]
4169 protected virtual void OnKeyPress(KeyPressEventArgs e) {
4170 if (KeyPress!=null) KeyPress(this, e);
4173 [EditorBrowsable(EditorBrowsableState.Advanced)]
4174 protected virtual void OnKeyUp(KeyEventArgs e) {
4175 if (KeyUp!=null) KeyUp(this, e);
4178 [EditorBrowsable(EditorBrowsableState.Advanced)]
4179 protected virtual void OnLayout(LayoutEventArgs levent) {
4180 if (Layout!=null) Layout(this, levent);
4183 [EditorBrowsable(EditorBrowsableState.Advanced)]
4184 protected virtual void OnLeave(EventArgs e) {
4185 if (Leave!=null) Leave(this, e);
4188 [EditorBrowsable(EditorBrowsableState.Advanced)]
4189 protected virtual void OnLocationChanged(EventArgs e) {
4191 if (LocationChanged!=null) LocationChanged(this, e);
4194 [EditorBrowsable(EditorBrowsableState.Advanced)]
4195 protected virtual void OnLostFocus(EventArgs e) {
4196 if (LostFocus!=null) LostFocus(this, e);
4199 [EditorBrowsable(EditorBrowsableState.Advanced)]
4200 protected virtual void OnMouseDown(MouseEventArgs e) {
4201 if (MouseDown!=null) MouseDown(this, e);
4204 [EditorBrowsable(EditorBrowsableState.Advanced)]
4205 protected virtual void OnMouseEnter(EventArgs e) {
4206 if (MouseEnter!=null) MouseEnter(this, e);
4209 [EditorBrowsable(EditorBrowsableState.Advanced)]
4210 protected virtual void OnMouseHover(EventArgs e) {
4211 if (MouseHover!=null) MouseHover(this, e);
4214 [EditorBrowsable(EditorBrowsableState.Advanced)]
4215 protected virtual void OnMouseLeave(EventArgs e) {
4216 if (MouseLeave!=null) MouseLeave(this, e);
4219 [EditorBrowsable(EditorBrowsableState.Advanced)]
4220 protected virtual void OnMouseMove(MouseEventArgs e) {
4221 if (MouseMove!=null) MouseMove(this, e);
4224 [EditorBrowsable(EditorBrowsableState.Advanced)]
4225 protected virtual void OnMouseUp(MouseEventArgs e) {
4226 if (MouseUp!=null) MouseUp(this, e);
4229 [EditorBrowsable(EditorBrowsableState.Advanced)]
4230 protected virtual void OnMouseWheel(MouseEventArgs e) {
4231 if (MouseWheel!=null) MouseWheel(this, e);
4234 [EditorBrowsable(EditorBrowsableState.Advanced)]
4235 protected virtual void OnMove(EventArgs e) {
4236 if (Move!=null) Move(this, e);
4239 [EditorBrowsable(EditorBrowsableState.Advanced)]
4240 protected virtual void OnNotifyMessage(Message m) {
4244 [EditorBrowsable(EditorBrowsableState.Advanced)]
4245 protected virtual void OnPaint(PaintEventArgs e) {
4246 if (Paint!=null) Paint(this, e);
4249 internal virtual void OnPaintInternal(PaintEventArgs e) {
4253 [EditorBrowsable(EditorBrowsableState.Advanced)]
4254 protected virtual void OnPaintBackground(PaintEventArgs pevent) {
4255 PaintControlBackground (pevent);
4258 [EditorBrowsable(EditorBrowsableState.Advanced)]
4259 protected virtual void OnParentBackColorChanged(EventArgs e) {
4260 if (background_color.IsEmpty && background_image==null) {
4262 OnBackColorChanged(e);
4266 [EditorBrowsable(EditorBrowsableState.Advanced)]
4267 protected virtual void OnParentBackgroundImageChanged(EventArgs e) {
4268 if (background_color.IsEmpty && background_image==null) {
4270 OnBackgroundImageChanged(e);
4274 [EditorBrowsable(EditorBrowsableState.Advanced)]
4275 protected virtual void OnParentBindingContextChanged(EventArgs e) {
4276 if (binding_context==null) {
4277 binding_context=Parent.binding_context;
4278 OnBindingContextChanged(e);
4282 [EditorBrowsable(EditorBrowsableState.Advanced)]
4283 protected virtual void OnParentChanged(EventArgs e) {
4284 if (ParentChanged!=null) ParentChanged(this, e);
4287 [EditorBrowsable(EditorBrowsableState.Advanced)]
4288 protected virtual void OnParentEnabledChanged(EventArgs e) {
4289 if (is_enabled != Parent.is_enabled) {
4290 is_enabled=Parent.is_enabled;
4292 if (EnabledChanged != null) {
4293 EnabledChanged(this, e);
4298 [EditorBrowsable(EditorBrowsableState.Advanced)]
4299 protected virtual void OnParentFontChanged(EventArgs e) {
4306 [EditorBrowsable(EditorBrowsableState.Advanced)]
4307 protected virtual void OnParentForeColorChanged(EventArgs e) {
4308 if (foreground_color.IsEmpty) {
4310 OnForeColorChanged(e);
4314 [EditorBrowsable(EditorBrowsableState.Advanced)]
4315 protected virtual void OnParentRightToLeftChanged(EventArgs e) {
4316 if (right_to_left==RightToLeft.Inherit) {
4318 OnRightToLeftChanged(e);
4322 [EditorBrowsable(EditorBrowsableState.Advanced)]
4323 protected virtual void OnParentVisibleChanged(EventArgs e) {
4325 OnVisibleChanged(e);
4329 [EditorBrowsable(EditorBrowsableState.Advanced)]
4330 protected virtual void OnQueryContinueDrag(QueryContinueDragEventArgs e) {
4331 if (QueryContinueDrag!=null) QueryContinueDrag(this, e);
4334 [EditorBrowsable(EditorBrowsableState.Advanced)]
4335 protected virtual void OnResize(EventArgs e) {
4336 if (Resize!=null) Resize(this, e);
4338 PerformLayout(this, "bounds");
4340 if (parent != null) {
4341 parent.PerformLayout();
4345 [EditorBrowsable(EditorBrowsableState.Advanced)]
4346 protected virtual void OnRightToLeftChanged(EventArgs e) {
4347 if (RightToLeftChanged!=null) RightToLeftChanged(this, e);
4348 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentRightToLeftChanged(e);
4351 [EditorBrowsable(EditorBrowsableState.Advanced)]
4352 protected virtual void OnSizeChanged(EventArgs e) {
4353 InvalidateBuffers ();
4355 if (SizeChanged!=null) SizeChanged(this, e);
4358 [EditorBrowsable(EditorBrowsableState.Advanced)]
4359 protected virtual void OnStyleChanged(EventArgs e) {
4360 if (StyleChanged!=null) StyleChanged(this, e);
4363 [EditorBrowsable(EditorBrowsableState.Advanced)]
4364 protected virtual void OnSystemColorsChanged(EventArgs e) {
4365 if (SystemColorsChanged!=null) SystemColorsChanged(this, e);
4368 [EditorBrowsable(EditorBrowsableState.Advanced)]
4369 protected virtual void OnTabIndexChanged(EventArgs e) {
4370 if (TabIndexChanged!=null) TabIndexChanged(this, e);
4373 [EditorBrowsable(EditorBrowsableState.Advanced)]
4374 protected virtual void OnTabStopChanged(EventArgs e) {
4375 if (TabStopChanged!=null) TabStopChanged(this, e);
4378 [EditorBrowsable(EditorBrowsableState.Advanced)]
4379 protected virtual void OnTextChanged(EventArgs e) {
4380 if (TextChanged!=null) TextChanged(this, e);
4383 [EditorBrowsable(EditorBrowsableState.Advanced)]
4384 protected virtual void OnValidated(EventArgs e) {
4385 if (Validated!=null) Validated(this, e);
4388 [EditorBrowsable(EditorBrowsableState.Advanced)]
4389 protected virtual void OnValidating(System.ComponentModel.CancelEventArgs e) {
4390 if (Validating!=null) Validating(this, e);
4393 [EditorBrowsable(EditorBrowsableState.Advanced)]
4394 protected virtual void OnVisibleChanged(EventArgs e) {
4395 if ((parent != null) && !Created && Visible) {
4402 needs_redraw = true;
4404 if (VisibleChanged!=null) VisibleChanged(this, e);
4406 // We need to tell our kids
4407 for (int i=0; i<child_controls.Count; i++) {
4408 if (child_controls[i].Visible) {
4409 child_controls[i].OnParentVisibleChanged(e);
4413 #endregion // OnXXX methods
4416 public event EventHandler BackColorChanged;
4417 public event EventHandler BackgroundImageChanged;
4418 public event EventHandler BindingContextChanged;
4419 public event EventHandler CausesValidationChanged;
4420 public event UICuesEventHandler ChangeUICues;
4421 public event EventHandler Click;
4422 public event EventHandler ContextMenuChanged;
4424 [EditorBrowsable(EditorBrowsableState.Advanced)]
4426 public event ControlEventHandler ControlAdded;
4428 [EditorBrowsable(EditorBrowsableState.Advanced)]
4430 public event ControlEventHandler ControlRemoved;
4432 [MWFDescription("Fired when the cursor for the control has been changed"), MWFCategory("PropertyChanged")]
4433 public event EventHandler CursorChanged;
4434 public event EventHandler DockChanged;
4435 public event EventHandler DoubleClick;
4436 public event DragEventHandler DragDrop;
4437 public event DragEventHandler DragEnter;
4438 public event EventHandler DragLeave;
4439 public event DragEventHandler DragOver;
4440 public event EventHandler EnabledChanged;
4441 public event EventHandler Enter;
4442 public event EventHandler FontChanged;
4443 public event EventHandler ForeColorChanged;
4444 public event GiveFeedbackEventHandler GiveFeedback;
4446 [EditorBrowsable(EditorBrowsableState.Advanced)]
4448 public event EventHandler GotFocus;
4450 [EditorBrowsable(EditorBrowsableState.Advanced)]
4452 public event EventHandler HandleCreated;
4454 [EditorBrowsable(EditorBrowsableState.Advanced)]
4456 public event EventHandler HandleDestroyed;
4458 public event HelpEventHandler HelpRequested;
4459 public event EventHandler ImeModeChanged;
4461 [EditorBrowsable(EditorBrowsableState.Advanced)]
4463 public event InvalidateEventHandler Invalidated;
4465 public event KeyEventHandler KeyDown;
4466 public event KeyPressEventHandler KeyPress;
4467 public event KeyEventHandler KeyUp;
4468 public event LayoutEventHandler Layout;
4469 public event EventHandler Leave;
4470 public event EventHandler LocationChanged;
4472 [EditorBrowsable(EditorBrowsableState.Advanced)]
4474 public event EventHandler LostFocus;
4476 public event MouseEventHandler MouseDown;
4477 public event EventHandler MouseEnter;
4478 public event EventHandler MouseHover;
4479 public event EventHandler MouseLeave;
4480 public event MouseEventHandler MouseMove;
4481 public event MouseEventHandler MouseUp;
4483 [EditorBrowsable(EditorBrowsableState.Advanced)]
4485 public event MouseEventHandler MouseWheel;
4487 public event EventHandler Move;
4488 public event PaintEventHandler Paint;
4489 public event EventHandler ParentChanged;
4490 public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp;
4491 public event QueryContinueDragEventHandler QueryContinueDrag;
4492 public event EventHandler Resize;
4493 public event EventHandler RightToLeftChanged;
4494 public event EventHandler SizeChanged;
4495 public event EventHandler StyleChanged;
4496 public event EventHandler SystemColorsChanged;
4497 public event EventHandler TabIndexChanged;
4498 public event EventHandler TabStopChanged;
4499 public event EventHandler TextChanged;
4500 public event EventHandler Validated;
4501 public event CancelEventHandler Validating;
4502 public event EventHandler VisibleChanged;
4503 #endregion // Events