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;
127 #endregion // Local Variables
129 #region Private Classes
130 // This helper class allows us to dispatch messages to Control.WndProc
131 internal class ControlNativeWindow : NativeWindow {
132 private Control owner;
134 public ControlNativeWindow(Control control) : base() {
139 public Control Owner {
145 static internal Control ControlFromHandle(IntPtr hWnd) {
146 ControlNativeWindow window;
148 window = (ControlNativeWindow)window_collection[hWnd];
149 if (window != null) {
156 protected override void WndProc(ref Message m) {
157 owner.WndProc(ref m);
162 #region Public Classes
164 public class ControlAccessibleObject : AccessibleObject {
165 #region ControlAccessibleObject Local Variables
166 private Control owner;
167 #endregion // ControlAccessibleObject Local Variables
169 #region ControlAccessibleObject Constructors
170 public ControlAccessibleObject(Control ownerControl) {
171 this.owner = ownerControl;
173 #endregion // ControlAccessibleObject Constructors
175 #region ControlAccessibleObject Public Instance Properties
176 public override string DefaultAction {
178 return base.DefaultAction;
182 public override string Description {
184 return base.Description;
188 public IntPtr Handle {
194 // We don't want to let them set it
198 public override string Help {
204 public override string KeyboardShortcut {
206 return base.KeyboardShortcut;
210 public override string Name {
220 public Control Owner {
226 public override AccessibleObject Parent {
233 public override AccessibleRole Role {
238 #endregion // ControlAccessibleObject Public Instance Properties
240 #region ControlAccessibleObject Public Instance Methods
241 public override int GetHelpTopic(out string FileName) {
242 return base.GetHelpTopic (out FileName);
245 [MonoTODO("Implement this and tie it into Control.AccessibilityNotifyClients")]
246 public void NotifyClients(AccessibleEvents accEvent) {
247 throw new NotImplementedException();
250 [MonoTODO("Implement this and tie it into Control.AccessibilityNotifyClients")]
251 public void NotifyClients(AccessibleEvents accEvent, int childID) {
252 throw new NotImplementedException();
255 public override string ToString() {
256 return "ControlAccessibleObject: Owner = " + owner.ToString() + ", Text: " + owner.text;
259 #endregion // ControlAccessibleObject Public Instance Methods
262 [DesignerSerializer("System.Windows.Forms.Design.ControlCollectionCodeDomSerializer, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
263 [ListBindable(false)]
264 public class ControlCollection : IList, ICollection, ICloneable, IEnumerable {
265 #region ControlCollection Local Variables
266 private ArrayList list;
267 internal ArrayList impl_list;
268 private Control [] all_controls;
269 internal Control owner;
270 #endregion // ControlCollection Local Variables
272 #region ControlCollection Public Constructor
273 public ControlCollection(Control owner) {
275 this.list=new ArrayList();
279 #region ControlCollection Public Instance Properties
286 public virtual bool IsReadOnly {
288 return list.IsReadOnly;
292 public virtual Control this[int index] {
294 if (index < 0 || index >= list.Count) {
295 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
297 return (Control)list[index];
300 #endregion // ControlCollection Public Instance Properties
302 #region ControlCollection Private Instance Methods
303 public virtual void Add (Control value)
308 if (Contains (value)) {
309 owner.PerformLayout();
313 if (value.tab_index == -1) {
319 end = owner.child_controls.Count;
320 for (int i = 0; i < end; i++) {
321 index = owner.child_controls[i].tab_index;
326 value.tab_index = use;
329 if (value.parent != null) {
330 value.parent.Controls.Remove(value);
336 value.ChangeParent(owner);
340 owner.UpdateZOrder();
341 owner.PerformLayout(value, "Parent");
342 owner.OnControlAdded(new ControlEventArgs(value));
345 internal void AddToList (Control c)
351 internal virtual void AddImplicit (Control control)
353 if (impl_list == null)
354 impl_list = new ArrayList ();
356 impl_list.Add (control);
358 control.ChangeParent (owner);
359 control.InitLayout ();
360 owner.UpdateZOrder ();
361 owner.PerformLayout (control, "Parent");
362 owner.OnControlAdded (new ControlEventArgs (control));
365 public virtual void AddRange (Control[] controls)
367 if (controls == null)
368 throw new ArgumentNullException ("controls");
370 owner.SuspendLayout ();
373 for (int i = 0; i < controls.Length; i++)
376 owner.ResumeLayout ();
380 internal virtual void AddRangeImplicit (Control [] controls)
382 if (controls == null)
383 throw new ArgumentNullException ("controls");
385 owner.SuspendLayout ();
388 for (int i = 0; i < controls.Length; i++)
389 AddImplicit (controls [i]);
391 owner.ResumeLayout ();
395 public virtual void Clear ()
399 // MS sends remove events in reverse order
400 while (list.Count > 0) {
401 RemoveAt(list.Count - 1);
405 internal virtual void ClearImplicit ()
407 if (impl_list == null)
413 public bool Contains (Control value)
415 for (int i = list.Count; i > 0; ) {
418 if (list [i] == value) {
419 // Do we need to do anything here?
426 internal bool ImplicitContains (Control value)
428 if (impl_list == null)
431 for (int i = impl_list.Count; i > 0; ) {
434 if (impl_list [i] == value) {
435 // Do we need to do anything here?
442 internal bool AllContains (Control value)
444 return Contains (value) || ImplicitContains (value);
447 public virtual void CopyTo (Array array, int index)
449 list.CopyTo(array, index);
452 public override bool Equals(object other) {
453 if (other is ControlCollection && (((ControlCollection)other).owner==this.owner)) {
460 public int GetChildIndex(Control child) {
461 return GetChildIndex(child, false);
464 public int GetChildIndex(Control child, bool throwException) {
467 index=list.IndexOf(child);
469 if (index==-1 && throwException) {
470 throw new ArgumentException("Not a child control", "child");
475 public IEnumerator GetEnumerator() {
476 return list.GetEnumerator();
479 internal IEnumerator GetAllEnumerator ()
481 Control [] res = GetAllControls ();
482 return res.GetEnumerator ();
485 internal Control [] GetAllControls ()
487 if (all_controls != null)
490 if (impl_list == null)
491 return (Control []) list.ToArray (typeof (Control));
493 Control [] res = new Control [list.Count + impl_list.Count];
494 impl_list.CopyTo (res);
495 list.CopyTo (res, impl_list.Count);
500 public override int GetHashCode() {
501 return base.GetHashCode();
504 public int IndexOf(Control control) {
505 return list.IndexOf(control);
508 public virtual void Remove(Control value) {
511 owner.PerformLayout(value, "Parent");
512 owner.OnControlRemoved(new ControlEventArgs(value));
515 value.ChangeParent(null);
517 owner.UpdateZOrder();
520 internal virtual void RemoveImplicit (Control control)
522 if (impl_list != null) {
524 owner.PerformLayout (control, "Parent");
525 owner.OnControlRemoved (new ControlEventArgs (control));
526 impl_list.Remove (control);
528 control.ChangeParent (null);
529 owner.UpdateZOrder ();
532 public void RemoveAt(int index) {
533 if (index < 0 || index >= list.Count) {
534 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
536 Remove ((Control)list[index]);
539 public void SetChildIndex(Control child, int newIndex) {
542 old_index=list.IndexOf(child);
544 throw new ArgumentException("Not a child control", "child");
547 if (old_index==newIndex) {
553 if (newIndex>list.Count) {
556 list.Insert(newIndex, child);
558 child.parent = owner;
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 IList.IsReadOnly {
589 return list.IsReadOnly;
593 bool ICollection.IsSynchronized {
595 return list.IsSynchronized;
599 object ICollection.SyncRoot {
601 return list.SyncRoot;
604 #endregion // ControlCollection Interface Properties
606 #region ControlCollection Interface Methods
607 int IList.Add(object value) {
609 throw new ArgumentNullException("value", "Cannot add null controls");
612 if (!(value is Control)) {
613 throw new ArgumentException("Object of type Control required", "value");
616 return list.Add(value);
619 bool IList.Contains(object value) {
620 if (!(value is Control)) {
621 throw new ArgumentException("Object of type Control required", "value");
624 return this.Contains((Control) value);
627 int IList.IndexOf(object value) {
628 if (!(value is Control)) {
629 throw new ArgumentException("Object of type Control required", "value");
632 return this.IndexOf((Control) value);
635 void IList.Insert(int index, object value) {
636 if (!(value is Control)) {
637 throw new ArgumentException("Object of type Control required", "value");
640 list.Insert(index, value);
643 void IList.Remove(object value) {
644 if (!(value is Control)) {
645 throw new ArgumentException("Object of type Control required", "value");
651 void ICollection.CopyTo(Array array, int index) {
653 list.CopyTo(array, index);
657 Object ICloneable.Clone() {
658 ControlCollection clone = new ControlCollection(this.owner);
659 clone.list=(ArrayList)list.Clone(); // FIXME: Do we need this?
662 #endregion // ControlCollection Interface Methods
664 #endregion // ControlCollection Class
666 #region Public Constructors
669 anchor_style = AnchorStyles.Top | AnchorStyles.Left;
677 layout_pending = false;
679 causes_validation = true;
681 layout_suspended = 0;
685 right_to_left = RightToLeft.Inherit;
686 border_style = BorderStyle.None;
687 background_color = Color.Empty;
694 use_compatible_text_rendering = Application.use_compatible_text_rendering;
697 control_style = ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint |
698 ControlStyles.Selectable | ControlStyles.StandardClick |
699 ControlStyles.StandardDoubleClick;
702 background_image = null;
706 window = new ControlNativeWindow(this);
707 child_controls = CreateControlsInstance();
708 client_size = new Size(DefaultSize.Width, DefaultSize.Height);
709 client_rect = new Rectangle(0, 0, DefaultSize.Width, DefaultSize.Height);
710 XplatUI.CalculateWindowRect(IntPtr.Zero, ref client_rect, CreateParams.Style, CreateParams.ExStyle, null, out bounds);
711 if ((CreateParams.Style & (int)WindowStyles.WS_CHILD) == 0) {
717 public Control(Control parent, string text) : this() {
722 public Control(Control parent, string text, int left, int top, int width, int height) : this() {
727 bounds.Height=height;
728 SetBoundsCore(left, top, width, height, BoundsSpecified.All);
732 public Control(string text) : this() {
736 public Control(string text, int left, int top, int width, int height) : this() {
740 bounds.Height=height;
741 SetBoundsCore(left, top, width, height, BoundsSpecified.All);
745 private delegate void RemoveDelegate(object c);
747 protected override void Dispose(bool disposing) {
759 if (this.InvokeRequired) {
760 if (Application.MessageLoop) {
761 this.BeginInvokeInternal(new MethodInvoker(DestroyHandle), null, true);
762 this.BeginInvokeInternal(new RemoveDelegate(controls.Remove), new object[] {this}, true);
766 controls.Remove(this);
769 #endregion // Public Constructors
771 #region Internal Properties
772 internal BorderStyle InternalBorderStyle {
778 if (!Enum.IsDefined (typeof (BorderStyle), value))
779 throw new InvalidEnumArgumentException (string.Format("Enum argument value '{0}' is not valid for BorderStyle", value));
781 if (border_style != value) {
782 border_style = value;
784 if (IsHandleCreated) {
785 XplatUI.SetBorderStyle(window.Handle, (FormBorderStyle)border_style);
791 #endregion // Internal Properties
793 #region Private & Internal Methods
794 internal IAsyncResult BeginInvokeInternal (Delegate method, object [] args, bool disposing) {
795 AsyncMethodResult result;
796 AsyncMethodData data;
803 if (!p.IsHandleCreated) {
804 throw new InvalidOperationException("Cannot call Invoke or InvokeAsync on a control until the window handle is created");
810 result = new AsyncMethodResult ();
811 data = new AsyncMethodData ();
813 data.Method = method;
815 data.Result = result;
818 if (!ExecutionContext.IsFlowSuppressed ()) {
819 data.Context = ExecutionContext.Capture ();
822 #if !MWF_ON_MSRUNTIME
823 if (SecurityManager.SecurityEnabled) {
824 data.Stack = CompressedStack.GetCompressedStack ();
829 XplatUI.SendAsyncMethod (data);
834 internal void PointToClient (ref int x, ref int y)
836 XplatUI.ScreenToClient (Handle, ref x, ref y);
839 internal void PointToScreen (ref int x, ref int y)
841 XplatUI.ClientToScreen (Handle, ref x, ref y);
844 internal Graphics DeviceContext {
847 CreateBuffers(this.Width, this.Height);
853 private Bitmap ImageBuffer {
856 CreateBuffers(this.Width, this.Height);
862 internal void CreateBuffers (int width, int height) {
863 if (dc_mem != null) {
877 bmp_mem = new Bitmap (width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
878 dc_mem = Graphics.FromImage (bmp_mem);
882 internal void InvalidateBuffers ()
884 if (dc_mem != null) {
895 internal static void SetChildColor(Control parent) {
898 for (int i=0; i < parent.child_controls.Count; i++) {
899 child=parent.child_controls[i];
900 if (child.child_controls.Count>0) {
901 SetChildColor(child);
907 internal bool Select(Control control) {
909 IContainerControl container;
911 if (control == null) {
915 parent = control.parent;
917 if (((control.control_style & ControlStyles.Selectable) !=0) && (parent != null)) {
918 while (parent != null) {
919 if (!parent.Visible || !parent.is_enabled) {
922 parent = parent.parent;
926 control.is_selected = true;
928 container = GetContainerControl();
929 if (container != null) {
930 container.ActiveControl = control;
932 if (control.IsHandleCreated) {
933 XplatUI.SetFocus(control.window.Handle);
938 internal virtual void DoDefaultAction() {
939 // Only here to be overriden by our actual controls; this is needed by the accessibility class
942 internal static int LowOrder (int param) {
943 return ((int)(short)(param & 0xffff));
946 internal static int HighOrder (int param) {
947 return ((int)(short)(param >> 16));
950 // This method exists so controls overriding OnPaintBackground can have default background painting done
951 internal virtual void PaintControlBackground (PaintEventArgs pevent)
953 if (background_image == null) {
954 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));
958 DrawBackgroundImage (pevent.Graphics);
961 void DrawBackgroundImage (Graphics g)
963 using (TextureBrush b = new TextureBrush (background_image, WrapMode.Tile)) {
964 g.FillRectangle (b, ClientRectangle);
968 internal virtual void DndEnter (DragEventArgs e)
975 internal virtual void DndOver (DragEventArgs e)
982 internal virtual void DndDrop (DragEventArgs e)
986 } catch (Exception exc) {
987 Console.Error.WriteLine ("MWF: Exception while dropping:");
988 Console.Error.WriteLine (exc);
992 internal virtual void DndLeave (EventArgs e)
999 internal virtual void DndFeedback(GiveFeedbackEventArgs e)
1006 internal virtual void DndContinueDrag(QueryContinueDragEventArgs e)
1009 OnQueryContinueDrag(e);
1013 internal static MouseButtons FromParamToMouseButtons (int param) {
1014 MouseButtons buttons = MouseButtons.None;
1016 if ((param & (int) MsgButtons.MK_LBUTTON) != 0)
1017 buttons |= MouseButtons.Left;
1019 if ((param & (int) MsgButtons.MK_MBUTTON) != 0)
1020 buttons |= MouseButtons.Middle;
1022 if ((param & (int) MsgButtons.MK_RBUTTON) != 0)
1023 buttons |= MouseButtons.Right;
1029 internal virtual bool ProcessControlMnemonic(char charCode) {
1030 return ProcessMnemonic(charCode);
1033 private static Control FindFlatForward(Control container, Control start) {
1039 end = container.child_controls.Count;
1041 if (start != null) {
1042 index = start.tab_index;
1047 for (int i = 0; i < end; i++) {
1048 if (found == null) {
1049 if (container.child_controls[i].tab_index > index) {
1050 found = container.child_controls[i];
1052 } else if (found.tab_index > container.child_controls[i].tab_index) {
1053 if (container.child_controls[i].tab_index > index) {
1054 found = container.child_controls[i];
1061 private static Control FindControlForward(Control container, Control start) {
1067 if (start != null) {
1068 if ((start is IContainerControl) || start.GetStyle(ControlStyles.ContainerControl)) {
1069 found = FindControlForward(start, null);
1070 if (found != null) {
1076 while (p != container) {
1077 found = FindFlatForward(p, start);
1078 if (found != null) {
1085 return FindFlatForward(container, start);
1088 private static Control FindFlatBackward(Control container, Control start) {
1094 end = container.child_controls.Count;
1096 if (start != null) {
1097 index = start.tab_index;
1099 // FIXME: Possible speed-up: Keep the highest taborder index in the container
1101 for (int i = 0; i < end; i++) {
1102 if (container.child_controls[i].tab_index > index) {
1103 index = container.child_controls[i].tab_index;
1109 for (int i = 0; i < end; i++) {
1110 if (found == null) {
1111 if (container.child_controls[i].tab_index < index) {
1112 found = container.child_controls[i];
1114 } else if (found.tab_index < container.child_controls[i].tab_index) {
1115 if (container.child_controls[i].tab_index < index) {
1116 found = container.child_controls[i];
1123 private static Control FindControlBackward(Control container, Control start) {
1128 if (start != null) {
1129 found = FindFlatBackward(start.parent, start);
1130 if (found == null && start.parent != container) {
1131 return start.parent;
1134 if (found == null) {
1135 found = FindFlatBackward(container, start);
1138 while ((found != null) && ((found is IContainerControl) || found.GetStyle(ControlStyles.ContainerControl))) {
1139 found = FindControlBackward(found, null);
1140 if (found != null) {
1148 private void HandleClick(int clicks) {
1149 if (GetStyle(ControlStyles.StandardClick)) {
1151 if (GetStyle(ControlStyles.StandardDoubleClick)) {
1152 OnDoubleClick(EventArgs.Empty);
1154 OnClick(EventArgs.Empty);
1157 OnClick(EventArgs.Empty);
1162 private void CheckDataBindings ()
1164 if (data_bindings == null)
1167 BindingContext binding_context = BindingContext;
1168 foreach (Binding binding in data_bindings) {
1169 binding.Check (binding_context);
1174 private void ChangeParent(Control new_parent) {
1178 Color pre_fore_color;
1179 Color pre_back_color;
1180 RightToLeft pre_rtl;
1182 // These properties are inherited from our parent
1183 // Get them pre parent-change and then send events
1184 // if they are changed after we have our new parent
1185 pre_enabled = Enabled;
1186 pre_visible = Visible;
1188 pre_fore_color = ForeColor;
1189 pre_back_color = BackColor;
1190 pre_rtl = RightToLeft;
1191 // MS doesn't seem to send a CursorChangedEvent
1193 parent = new_parent;
1195 if (IsHandleCreated && (new_parent != null) && new_parent.IsHandleCreated) {
1196 XplatUI.SetParent(Handle, new_parent.Handle);
1199 OnParentChanged(EventArgs.Empty);
1201 if (pre_enabled != Enabled) {
1202 OnEnabledChanged(EventArgs.Empty);
1205 if (pre_visible != Visible) {
1206 OnVisibleChanged(EventArgs.Empty);
1209 if (pre_font != Font) {
1210 OnFontChanged(EventArgs.Empty);
1213 if (pre_fore_color != ForeColor) {
1214 OnForeColorChanged(EventArgs.Empty);
1217 if (pre_back_color != BackColor) {
1218 OnBackColorChanged(EventArgs.Empty);
1221 if (pre_rtl != RightToLeft) {
1222 // MS sneaks a OnCreateControl and OnHandleCreated in here, I guess
1223 // because when RTL changes they have to recreate the win32 control
1224 // We don't really need that (until someone runs into compatibility issues)
1225 OnRightToLeftChanged(EventArgs.Empty);
1228 if ((new_parent != null) && new_parent.Created && !Created) {
1232 if ((binding_context == null) && Created) {
1233 OnBindingContextChanged(EventArgs.Empty);
1237 private void UpdateDistances() {
1238 if ((parent != null) && (parent.layout_suspended == 0)) {
1239 dist_left = bounds.X;
1240 dist_top = bounds.Y;
1241 dist_right = parent.ClientSize.Width - bounds.X - bounds.Width;
1242 dist_bottom = parent.ClientSize.Height - bounds.Y - bounds.Height;
1245 #endregion // Private & Internal Methods
1247 #region Public Static Properties
1248 public static Color DefaultBackColor {
1250 return ThemeEngine.Current.DefaultControlBackColor;
1254 public static Font DefaultFont {
1256 return ThemeEngine.Current.DefaultFont;
1260 public static Color DefaultForeColor {
1262 return ThemeEngine.Current.DefaultControlForeColor;
1266 public static Keys ModifierKeys {
1268 return XplatUI.State.ModifierKeys;
1272 public static MouseButtons MouseButtons {
1274 return XplatUI.State.MouseButtons;
1278 public static Point MousePosition {
1280 return Cursor.Position;
1286 public static bool CheckForIllegalCrossThreadCalls
1295 #endregion // Public Static Properties
1297 #region Public Instance Properties
1298 [EditorBrowsable(EditorBrowsableState.Advanced)]
1300 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1301 public AccessibleObject AccessibilityObject {
1303 if (accessibility_object==null) {
1304 accessibility_object=CreateAccessibilityInstance();
1306 return accessibility_object;
1310 [EditorBrowsable(EditorBrowsableState.Advanced)]
1312 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1313 public string AccessibleDefaultActionDescription {
1315 return AccessibilityObject.default_action;
1319 AccessibilityObject.default_action=value;
1324 [DefaultValue(null)]
1325 public string AccessibleDescription {
1327 return AccessibilityObject.description;
1331 AccessibilityObject.description=value;
1336 [DefaultValue(null)]
1337 public string AccessibleName {
1339 return AccessibilityObject.Name;
1343 AccessibilityObject.Name=value;
1347 [DefaultValue(AccessibleRole.Default)]
1348 [MWFDescription("Role of the control"), MWFCategory("Accessibility")]
1349 public AccessibleRole AccessibleRole {
1351 return AccessibilityObject.role;
1355 AccessibilityObject.role=value;
1359 [DefaultValue(false)]
1360 public virtual bool AllowDrop {
1366 if (allow_drop == value)
1370 XplatUI.SetAllowDrop (Handle, value);
1375 [RefreshProperties(RefreshProperties.Repaint)]
1376 [DefaultValue(AnchorStyles.Top | AnchorStyles.Left)]
1377 public virtual AnchorStyles Anchor {
1379 return anchor_style;
1385 if (parent != null) {
1386 parent.PerformLayout(this, "Parent");
1392 public virtual Color BackColor {
1394 if (background_color.IsEmpty) {
1396 return parent.BackColor;
1398 return DefaultBackColor;
1400 return background_color;
1404 background_color=value;
1405 SetChildColor(this);
1406 OnBackColorChanged(EventArgs.Empty);
1412 [DefaultValue(null)]
1413 public virtual Image BackgroundImage {
1415 return background_image;
1419 if (background_image!=value) {
1420 background_image=value;
1421 OnBackgroundImageChanged(EventArgs.Empty);
1426 [EditorBrowsable(EditorBrowsableState.Advanced)]
1428 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1429 public virtual BindingContext BindingContext {
1431 if (binding_context != null)
1432 return binding_context;
1435 binding_context = Parent.BindingContext;
1436 return binding_context;
1439 if (binding_context != value) {
1440 binding_context = value;
1441 OnBindingContextChanged(EventArgs.Empty);
1446 [EditorBrowsable(EditorBrowsableState.Advanced)]
1448 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1451 return bounds.Y+bounds.Height;
1455 [EditorBrowsable(EditorBrowsableState.Advanced)]
1457 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1458 public Rectangle Bounds {
1464 SetBoundsCore(value.Left, value.Top, value.Width, value.Height, BoundsSpecified.All);
1468 [EditorBrowsable(EditorBrowsableState.Advanced)]
1470 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1471 public bool CanFocus {
1473 if (Visible && is_enabled && GetStyle(ControlStyles.Selectable)) {
1480 [EditorBrowsable(EditorBrowsableState.Advanced)]
1482 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1483 public bool CanSelect {
1487 if (!GetStyle(ControlStyles.Selectable)) {
1492 while (parent != null) {
1493 if (!parent.is_visible || !parent.is_enabled) {
1497 parent = parent.parent;
1503 [EditorBrowsable(EditorBrowsableState.Advanced)]
1505 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1506 public bool Capture {
1508 return this.is_captured;
1512 if (this.IsHandleCreated) {
1513 if (value && !is_captured) {
1515 XplatUI.GrabWindow(this.window.Handle, IntPtr.Zero);
1516 } else if (!value && is_captured) {
1517 XplatUI.UngrabWindow(this.window.Handle);
1518 is_captured = false;
1524 [DefaultValue(true)]
1525 public bool CausesValidation {
1527 return this.causes_validation;
1531 if (this.causes_validation != value) {
1532 causes_validation = value;
1533 OnCausesValidationChanged(EventArgs.Empty);
1538 [EditorBrowsable(EditorBrowsableState.Advanced)]
1540 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1541 public Rectangle ClientRectangle {
1543 client_rect.Width = client_size.Width;
1544 client_rect.Height = client_size.Height;
1549 [EditorBrowsable(EditorBrowsableState.Advanced)]
1551 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1552 public Size ClientSize {
1555 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1556 return ((Form)this).form_parent_window.ClientSize;
1564 this.SetClientSizeCore(value.Width, value.Height);
1568 [EditorBrowsable(EditorBrowsableState.Advanced)]
1570 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1571 [DescriptionAttribute("ControlCompanyNameDescr")]
1572 public String CompanyName {
1574 return "Mono Project, Novell, Inc.";
1578 [EditorBrowsable(EditorBrowsableState.Advanced)]
1580 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1581 public bool ContainsFocus {
1587 for (int i=0; i < child_controls.Count; i++) {
1588 if (child_controls[i].ContainsFocus) {
1596 [DefaultValue(null)]
1597 public virtual ContextMenu ContextMenu {
1599 return context_menu;
1603 if (context_menu != value) {
1604 context_menu = value;
1605 OnContextMenuChanged(EventArgs.Empty);
1611 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
1612 public ControlCollection Controls {
1614 return this.child_controls;
1618 [EditorBrowsable(EditorBrowsableState.Advanced)]
1620 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1621 public bool Created {
1623 return (!is_disposed && is_created);
1627 [AmbientValue(null)]
1628 public virtual Cursor Cursor {
1630 if (cursor != null) {
1634 if (parent != null) {
1635 return parent.Cursor;
1638 return Cursors.Default;
1642 if (cursor != value) {
1647 if (IsHandleCreated) {
1648 pt = Cursor.Position;
1650 if (bounds.Contains(pt)) {
1651 if (GetChildAtPoint(pt) == null) {
1652 if (cursor != null) {
1653 XplatUI.SetCursor(window.Handle, cursor.handle);
1655 if (parent != null) {
1656 XplatUI.SetCursor(window.Handle, parent.Cursor.handle);
1658 XplatUI.SetCursor(window.Handle, Cursors.def.handle);
1665 OnCursorChanged(EventArgs.Empty);
1671 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
1672 [ParenthesizePropertyName(true)]
1673 [RefreshProperties(RefreshProperties.All)]
1674 public ControlBindingsCollection DataBindings {
1676 if (data_bindings == null)
1677 data_bindings = new ControlBindingsCollection (this);
1678 return data_bindings;
1682 [EditorBrowsable(EditorBrowsableState.Advanced)]
1684 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1685 public virtual Rectangle DisplayRectangle {
1687 return ClientRectangle;
1691 [EditorBrowsable(EditorBrowsableState.Advanced)]
1693 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1694 public bool Disposing {
1701 [RefreshProperties(RefreshProperties.Repaint)]
1702 [DefaultValue(DockStyle.None)]
1703 public virtual DockStyle Dock {
1709 if (dock_style == value) {
1715 if (parent != null) {
1716 parent.PerformLayout(this, "Parent");
1719 OnDockChanged(EventArgs.Empty);
1725 public bool Enabled {
1731 if (parent != null) {
1732 return parent.Enabled;
1739 if (is_enabled == value) {
1743 if (IsHandleCreated) {
1745 if (((Form)this).context == null) {
1746 XplatUI.EnableWindow(window.Handle, value);
1749 XplatUI.EnableWindow(window.Handle, value);
1754 OnEnabledChanged (EventArgs.Empty);
1758 [EditorBrowsable(EditorBrowsableState.Advanced)]
1760 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1761 public virtual bool Focused {
1763 return this.has_focus;
1768 [AmbientValue(null)]
1770 public virtual Font Font {
1776 if (Parent != null && Parent.Font != null) {
1784 if (font != null && font.Equals (value)) {
1790 OnFontChanged (EventArgs.Empty);
1795 public virtual Color ForeColor {
1797 if (foreground_color.IsEmpty) {
1799 return parent.ForeColor;
1801 return DefaultForeColor;
1803 return foreground_color;
1807 if (foreground_color != value) {
1808 foreground_color=value;
1810 OnForeColorChanged(EventArgs.Empty);
1817 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1818 public IntPtr Handle { // IWin32Window
1820 if (!IsHandleCreated) {
1823 return window.Handle;
1827 [EditorBrowsable(EditorBrowsableState.Advanced)]
1829 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1830 public bool HasChildren {
1832 if (this.child_controls.Count>0) {
1839 [EditorBrowsable(EditorBrowsableState.Always)]
1841 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1844 return this.bounds.Height;
1848 SetBoundsCore(bounds.X, bounds.Y, bounds.Width, value, BoundsSpecified.Height);
1852 [AmbientValue(ImeMode.Inherit)]
1854 public ImeMode ImeMode {
1856 if (ime_mode == DefaultImeMode) {
1858 return parent.ImeMode;
1860 return ImeMode.NoControl; // default value
1866 if (ime_mode != value) {
1869 OnImeModeChanged(EventArgs.Empty);
1874 [EditorBrowsable(EditorBrowsableState.Advanced)]
1876 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1877 public bool InvokeRequired { // ISynchronizeInvoke
1879 if (creator_thread != null && creator_thread!=Thread.CurrentThread) {
1886 [EditorBrowsable(EditorBrowsableState.Advanced)]
1888 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1889 public bool IsAccessible {
1891 return is_accessible;
1895 is_accessible = value;
1899 [EditorBrowsable(EditorBrowsableState.Advanced)]
1901 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1902 public bool IsDisposed {
1904 return this.is_disposed;
1908 [EditorBrowsable(EditorBrowsableState.Advanced)]
1910 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1911 public bool IsHandleCreated {
1913 if ((window != null) && (window.Handle != IntPtr.Zero)) {
1921 [EditorBrowsable(EditorBrowsableState.Always)]
1923 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1926 return this.bounds.X;
1930 SetBoundsCore(value, bounds.Y, bounds.Width, bounds.Height, BoundsSpecified.X);
1935 public Point Location {
1937 return new Point(bounds.X, bounds.Y);
1941 SetBoundsCore(value.X, value.Y, bounds.Width, bounds.Height, BoundsSpecified.Location);
1946 public string Name {
1957 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1958 public Control Parent {
1964 if (value == this) {
1965 throw new ArgumentException("A circular control reference has been made. A control cannot be owned or parented to itself.");
1968 if (parent!=value) {
1970 parent.Controls.Remove(this);
1974 value.Controls.Add(this);
1979 [EditorBrowsable(EditorBrowsableState.Advanced)]
1981 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1982 public string ProductName {
1984 Type t = typeof (AssemblyProductAttribute);
1985 Assembly assembly = GetType().Module.Assembly;
1986 object [] attrs = assembly.GetCustomAttributes (t, false);
1987 AssemblyProductAttribute a = null;
1988 // On MS we get a NullRefException if product attribute is not
1990 if (attrs != null && attrs.Length > 0)
1991 a = (AssemblyProductAttribute) attrs [0];
1996 [EditorBrowsable(EditorBrowsableState.Advanced)]
1998 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1999 public string ProductVersion {
2001 Type t = typeof (AssemblyVersionAttribute);
2002 Assembly assembly = GetType().Module.Assembly;
2003 object [] attrs = assembly.GetCustomAttributes (t, false);
2004 if (attrs == null || attrs.Length < 1)
2006 return ((AssemblyVersionAttribute)attrs [0]).Version;
2010 [EditorBrowsable(EditorBrowsableState.Advanced)]
2012 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2013 public bool RecreatingHandle {
2015 return is_recreating;
2019 [EditorBrowsable(EditorBrowsableState.Advanced)]
2021 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2022 public Region Region {
2024 return new Region(this.bounds);
2031 g = this.CreateGraphics();
2032 r = value.GetBounds(g);
2034 SetBounds((int)r.X, (int)r.Y, (int)r.Width, (int)r.Height);
2040 [EditorBrowsable(EditorBrowsableState.Advanced)]
2042 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2045 return this.bounds.X+this.bounds.Width;
2049 [AmbientValue(RightToLeft.Inherit)]
2051 public virtual RightToLeft RightToLeft {
2053 if (right_to_left == RightToLeft.Inherit) {
2055 return parent.RightToLeft;
2057 return RightToLeft.No; // default value
2059 return right_to_left;
2063 if (value != right_to_left) {
2064 right_to_left = value;
2065 OnRightToLeftChanged(EventArgs.Empty);
2070 [EditorBrowsable(EditorBrowsableState.Advanced)]
2071 public override ISite Site {
2079 AmbientProperties ap = (AmbientProperties) value.GetService (typeof (AmbientProperties));
2081 BackColor = ap.BackColor;
2082 ForeColor = ap.ForeColor;
2092 return new Size(Width, Height);
2096 SetBoundsCore(bounds.X, bounds.Y, value.Width, value.Height, BoundsSpecified.Size);
2101 [MergableProperty(false)]
2102 public int TabIndex {
2104 if (tab_index != -1) {
2111 if (tab_index != value) {
2113 OnTabIndexChanged(EventArgs.Empty);
2119 [DefaultValue(true)]
2120 public bool TabStop {
2126 if (tab_stop != value) {
2128 OnTabStopChanged(EventArgs.Empty);
2133 [Localizable(false)]
2135 [TypeConverter(typeof(StringConverter))]
2136 [DefaultValue(null)]
2143 control_tag = value;
2149 [BindableAttribute(true)]
2150 public virtual string Text {
2152 // Our implementation ignores ControlStyles.CacheText - we always cache
2157 if (value == null) {
2158 value = String.Empty;
2163 if (IsHandleCreated) {
2164 XplatUI.Text(Handle, text);
2166 OnTextChanged (EventArgs.Empty);
2171 [EditorBrowsable(EditorBrowsableState.Always)]
2173 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2176 return this.bounds.Y;
2180 SetBoundsCore(bounds.X, value, bounds.Width, bounds.Height, BoundsSpecified.Y);
2184 [EditorBrowsable(EditorBrowsableState.Advanced)]
2186 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2187 public Control TopLevelControl {
2191 while (p.parent != null) {
2200 public bool Visible {
2204 } else if (parent != null) {
2205 return parent.Visible;
2212 SetVisibleCore(value);
2216 [EditorBrowsable(EditorBrowsableState.Always)]
2218 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2221 return this.bounds.Width;
2225 SetBoundsCore(bounds.X, bounds.Y, value, bounds.Height, BoundsSpecified.Width);
2229 [EditorBrowsable(EditorBrowsableState.Never)]
2231 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2232 public IWindowTarget WindowTarget {
2241 #endregion // Public Instance Properties
2243 #region Protected Instance Properties
2244 protected virtual CreateParams CreateParams {
2246 CreateParams create_params = new CreateParams();
2249 create_params.Caption = Text;
2252 create_params.Caption = text;
2256 create_params.X = Left;
2259 create_params.X = this.bounds.X;
2263 create_params.Y = Top;
2266 create_params.Y = this.bounds.Y;
2270 create_params.Width = Width;
2273 create_params.Width = this.bounds.Width;
2277 create_params.Height = Height;
2280 create_params.Height = this.bounds.Height;
2284 create_params.ClassName = XplatUI.DefaultClassName;
2285 create_params.ClassStyle = 0;
2286 create_params.ExStyle = 0;
2287 create_params.Param = 0;
2290 create_params.ExStyle |= (int)WindowStyles.WS_EX_ACCEPTFILES;
2294 create_params.Parent = parent.Handle;
2297 create_params.Style = (int)WindowStyles.WS_CHILD | (int)WindowStyles.WS_CLIPCHILDREN | (int)WindowStyles.WS_CLIPSIBLINGS;
2300 create_params.Style |= (int)WindowStyles.WS_VISIBLE;
2304 create_params.Style |= (int)WindowStyles.WS_DISABLED;
2307 switch (border_style) {
2308 case BorderStyle.FixedSingle:
2309 create_params.Style |= (int) WindowStyles.WS_BORDER;
2311 case BorderStyle.Fixed3D:
2312 create_params.ExStyle |= (int) WindowStyles.WS_EX_CLIENTEDGE;
2316 return create_params;
2320 protected virtual ImeMode DefaultImeMode {
2322 return ImeMode.Inherit;
2326 protected virtual Size DefaultSize {
2328 return new Size(0, 0);
2332 protected int FontHeight {
2342 protected bool RenderRightToLeft {
2344 return (this.right_to_left == RightToLeft.Yes);
2348 protected bool ResizeRedraw {
2350 return GetStyle(ControlStyles.ResizeRedraw);
2354 SetStyle(ControlStyles.ResizeRedraw, value);
2358 [EditorBrowsable(EditorBrowsableState.Advanced)]
2360 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2361 protected virtual bool ShowFocusCues {
2367 [EditorBrowsable(EditorBrowsableState.Advanced)]
2369 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2370 protected bool ShowKeyboardCues {
2375 #endregion // Protected Instance Properties
2377 #region Public Static Methods
2378 [EditorBrowsable(EditorBrowsableState.Advanced)]
2379 public static Control FromChildHandle(IntPtr handle) {
2380 IEnumerator control = Control.controls.GetEnumerator();
2382 while (control.MoveNext()) {
2383 if (((Control)control.Current).window.Handle == handle) {
2385 if (((Control)control.Current).Parent != null) {
2386 return ((Control)control.Current).Parent;
2393 [EditorBrowsable(EditorBrowsableState.Advanced)]
2394 public static Control FromHandle(IntPtr handle) {
2396 IEnumerator control = Control.controls.GetEnumerator();
2398 while (control.MoveNext()) {
2399 if (((Control)control.Current).window.Handle == handle) {
2401 return ((Control)control.Current);
2407 return Control.ControlNativeWindow.ControlFromHandle(handle);
2411 public static bool IsMnemonic(char charCode, string text) {
2414 amp = text.IndexOf('&');
2417 if (amp + 1 < text.Length) {
2418 if (text[amp + 1] != '&') {
2419 if (Char.ToUpper(charCode) == Char.ToUpper(text.ToCharArray(amp + 1, 1)[0])) {
2429 #region Protected Static Methods
2430 [EditorBrowsable(EditorBrowsableState.Advanced)]
2431 protected static bool ReflectMessage(IntPtr hWnd, ref Message m) {
2434 c = Control.FromHandle(hWnd);
2444 #region Public Instance Methods
2445 [EditorBrowsable(EditorBrowsableState.Advanced)]
2446 public IAsyncResult BeginInvoke(Delegate method) {
2447 object [] prms = null;
2448 if (method is EventHandler)
2449 prms = new object [] { this, EventArgs.Empty };
2450 return BeginInvokeInternal(method, prms, false);
2453 [EditorBrowsable(EditorBrowsableState.Advanced)]
2454 public IAsyncResult BeginInvoke (Delegate method, object[] args) {
2455 return BeginInvokeInternal (method, args, false);
2458 public void BringToFront() {
2459 if ((parent != null) && (parent.child_controls[0]!=this)) {
2460 if (parent.child_controls.Contains(this)) {
2461 parent.child_controls.SetChildIndex(this, 0);
2464 if (parent.child_controls.impl_list != null) {
2465 Control last_impl = (Control) parent.child_controls.impl_list [parent.child_controls.impl_list.Count - 1];
2466 XplatUI.SetZOrder (this.window.Handle, last_impl.Handle, false, false);
2468 XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, true, false);
2472 if (parent != null) {
2477 public bool Contains(Control ctl) {
2478 while (ctl != null) {
2487 public void CreateControl() {
2492 if (!IsHandleCreated) {
2500 Control [] controls = child_controls.GetAllControls ();
2501 for (int i=0; i<controls.Length; i++) {
2502 controls [i].CreateControl ();
2507 if (binding_context == null) { // seem to be sent whenever it's null?
2508 OnBindingContextChanged(EventArgs.Empty);
2514 public Graphics CreateGraphics() {
2515 if (!IsHandleCreated) {
2516 this.CreateHandle();
2518 return Graphics.FromHwnd(this.window.Handle);
2521 public DragDropEffects DoDragDrop(object data, DragDropEffects allowedEffects) {
2522 return XplatUI.StartDrag(this.window.Handle, data, allowedEffects);
2525 [EditorBrowsable(EditorBrowsableState.Advanced)]
2526 public object EndInvoke (IAsyncResult async_result) {
2527 AsyncMethodResult result = (AsyncMethodResult) async_result;
2528 return result.EndInvoke ();
2531 public Form FindForm() {
2544 public bool Focus() {
2545 if (IsHandleCreated && !has_focus) {
2547 XplatUI.SetFocus(window.Handle);
2552 public Control GetChildAtPoint(Point pt) {
2553 // Microsoft's version of this function doesn't seem to work, so I can't check
2554 // if we only consider children or also grandchildren, etc.
2555 // I'm gonna say 'children only'
2556 for (int i=0; i<child_controls.Count; i++) {
2557 if (child_controls[i].Bounds.Contains(pt)) {
2558 return child_controls[i];
2564 public IContainerControl GetContainerControl() {
2565 Control current = this;
2567 while (current!=null) {
2568 if ((current is IContainerControl) && ((current.control_style & ControlStyles.ContainerControl)!=0)) {
2569 return (IContainerControl)current;
2571 current = current.parent;
2576 public Control GetNextControl(Control ctl, bool forward) {
2577 // If we're not a container we don't play
2578 if (!(this is IContainerControl) && !this.GetStyle(ControlStyles.ContainerControl)) {
2582 // If ctl is not contained by this, we start at the first child of this
2583 if (!this.Contains(ctl)) {
2587 // Search through our controls, starting at ctl, stepping into children as we encounter them
2588 // try to find the control with the tabindex closest to our own, or, if we're looking into
2589 // child controls, the one with the smallest tabindex
2591 return FindControlForward(this, ctl);
2593 return FindControlBackward(this, ctl);
2596 public void Hide() {
2597 this.Visible = false;
2600 public void Invalidate() {
2601 Invalidate(ClientRectangle, false);
2604 public void Invalidate(bool invalidateChildren) {
2605 Invalidate(ClientRectangle, invalidateChildren);
2608 public void Invalidate(System.Drawing.Rectangle rc) {
2609 Invalidate(rc, false);
2612 public void Invalidate(System.Drawing.Rectangle rc, bool invalidateChildren) {
2613 if (!IsHandleCreated || !Visible || rc.Width == 0 || rc.Height == 0) {
2617 NotifyInvalidate(rc);
2619 XplatUI.Invalidate(Handle, rc, false);
2621 if (invalidateChildren) {
2622 Control [] controls = child_controls.GetAllControls ();
2623 for (int i=0; i<controls.Length; i++)
2624 controls [i].Invalidate ();
2626 OnInvalidated(new InvalidateEventArgs(rc));
2629 public void Invalidate(System.Drawing.Region region) {
2630 Invalidate(region, false);
2633 public void Invalidate(System.Drawing.Region region, bool invalidateChildren) {
2634 RectangleF bounds = region.GetBounds (CreateGraphics ());
2635 Invalidate (new Rectangle ((int) bounds.X, (int) bounds.Y, (int) bounds.Width, (int) bounds.Height),
2636 invalidateChildren);
2639 public object Invoke (Delegate method) {
2640 object [] prms = null;
2641 if (method is EventHandler)
2642 prms = new object [] { this, EventArgs.Empty };
2644 return Invoke(method, prms);
2647 public object Invoke (Delegate method, object[] args) {
2648 if (!this.InvokeRequired) {
2649 return method.DynamicInvoke(args);
2652 IAsyncResult result = BeginInvoke (method, args);
2653 return EndInvoke(result);
2656 internal object InvokeInternal (Delegate method, bool disposing) {
2657 return InvokeInternal(method, null, disposing);
2660 internal object InvokeInternal (Delegate method, object[] args, bool disposing) {
2661 if (!this.InvokeRequired) {
2662 return method.DynamicInvoke(args);
2665 IAsyncResult result = BeginInvokeInternal (method, args, disposing);
2666 return EndInvoke(result);
2669 [EditorBrowsable(EditorBrowsableState.Advanced)]
2670 public void PerformLayout() {
2671 PerformLayout(null, null);
2674 [EditorBrowsable(EditorBrowsableState.Advanced)]
2675 public void PerformLayout(Control affectedControl, string affectedProperty) {
2676 LayoutEventArgs levent = new LayoutEventArgs(affectedControl, affectedProperty);
2678 if (layout_suspended > 0) {
2679 layout_pending = true;
2683 layout_pending = false;
2685 // Prevent us from getting messed up
2688 // Perform all Dock and Anchor calculations
2691 AnchorStyles anchor;
2694 space=this.DisplayRectangle;
2696 // Deal with docking; go through in reverse, MS docs say that lowest Z-order is closest to edge
2697 Control [] controls = child_controls.GetAllControls ();
2698 for (int i = controls.Length - 1; i >= 0; i--) {
2699 child = controls [i];
2700 switch (child.Dock) {
2701 case DockStyle.None: {
2706 case DockStyle.Left: {
2707 child.SetBounds(space.Left, space.Y, child.Width, space.Height);
2708 space.X+=child.Width;
2709 space.Width-=child.Width;
2713 case DockStyle.Top: {
2714 child.SetBounds(space.Left, space.Y, space.Width, child.Height);
2715 space.Y+=child.Height;
2716 space.Height-=child.Height;
2720 case DockStyle.Right: {
2721 child.SetBounds(space.Right-child.Width, space.Y, child.Width, space.Height);
2722 space.Width-=child.Width;
2726 case DockStyle.Bottom: {
2727 child.SetBounds(space.Left, space.Bottom-child.Height, space.Width, child.Height);
2728 space.Height-=child.Height;
2734 for (int i = controls.Length - 1; i >= 0; i--) {
2737 if (child.Dock == DockStyle.Fill) {
2738 child.SetBounds(space.Left, space.Top, space.Width, space.Height);
2744 space=this.DisplayRectangle;
2746 for (int i=0; i < controls.Length; i++) {
2752 child = controls[i];
2753 anchor = child.Anchor;
2757 width = child.Width;
2758 height = child.Height;
2760 // If the control is docked we don't need to do anything
2761 if (child.Dock != DockStyle.None) {
2765 if ((anchor & AnchorStyles.Left) !=0 ) {
2766 if ((anchor & AnchorStyles.Right) != 0) {
2767 width = client_size.Width - child.dist_right - left;
2769 ; // Left anchored only, nothing to be done
2771 } else if ((anchor & AnchorStyles.Right) != 0) {
2772 left = client_size.Width - child.dist_right - width;
2774 // left+=diff_width/2 will introduce rounding errors (diff_width removed from svn after r51780)
2775 // This calculates from scratch every time:
2776 left = child.dist_left + (client_size.Width - (child.dist_left + width + child.dist_right)) / 2;
2779 if ((anchor & AnchorStyles.Top) !=0 ) {
2780 if ((anchor & AnchorStyles.Bottom) != 0) {
2781 height = client_size.Height - child.dist_bottom - top;
2783 ; // Top anchored only, nothing to be done
2785 } else if ((anchor & AnchorStyles.Bottom) != 0) {
2786 top = client_size.Height - child.dist_bottom - height;
2788 // top += diff_height/2 will introduce rounding errors (diff_height removed from after r51780)
2789 // This calculates from scratch every time:
2790 top = child.dist_top + (client_size.Height - (child.dist_top + height + child.dist_bottom)) / 2;
2802 child.SetBounds(left, top, width, height);
2805 // Let everyone know
2809 // Need to make sure we decremend layout_suspended
2815 public Point PointToClient (Point p) {
2819 XplatUI.ScreenToClient (Handle, ref x, ref y);
2821 return new Point (x, y);
2824 public Point PointToScreen(Point p) {
2828 XplatUI.ClientToScreen(Handle, ref x, ref y);
2830 return new Point(x, y);
2833 public virtual bool PreProcessMessage(ref Message msg) {
2836 if ((msg.Msg == (int)Msg.WM_KEYDOWN) || (msg.Msg == (int)Msg.WM_SYSKEYDOWN)) {
2837 key_data = (Keys)msg.WParam.ToInt32() | XplatUI.State.ModifierKeys;
2839 if (!ProcessCmdKey(ref msg, key_data)) {
2840 if (IsInputKey(key_data)) {
2844 return ProcessDialogKey(key_data);
2848 } else if (msg.Msg == (int)Msg.WM_CHAR) {
2849 if (IsInputChar((char)msg.WParam)) {
2852 } else if (msg.Msg == (int)Msg.WM_SYSCHAR) {
2853 if (IsInputChar((char)msg.WParam)) {
2856 return ProcessDialogChar((char)msg.WParam);
2861 public Rectangle RectangleToClient(Rectangle r) {
2862 return new Rectangle(PointToClient(r.Location), r.Size);
2865 public Rectangle RectangleToScreen(Rectangle r) {
2866 return new Rectangle(PointToScreen(r.Location), r.Size);
2869 public virtual void Refresh() {
2870 if (IsHandleCreated == true) {
2873 XplatUI.UpdateWindow(window.Handle);
2875 Control [] controls = child_controls.GetAllControls ();
2876 for (int i=0; i < controls.Length; i++) {
2877 controls[i].Refresh();
2883 [EditorBrowsable(EditorBrowsableState.Never)]
2884 public virtual void ResetBackColor() {
2885 background_color = Color.Empty;
2888 [EditorBrowsable(EditorBrowsableState.Never)]
2890 public void ResetBindings() {
2894 [EditorBrowsable(EditorBrowsableState.Never)]
2895 public virtual void ResetCursor() {
2899 [EditorBrowsable(EditorBrowsableState.Never)]
2900 public virtual void ResetFont() {
2904 [EditorBrowsable(EditorBrowsableState.Never)]
2905 public virtual void ResetForeColor() {
2906 foreground_color = Color.Empty;
2909 [EditorBrowsable(EditorBrowsableState.Never)]
2910 public void ResetImeMode() {
2911 ime_mode = DefaultImeMode;
2914 [EditorBrowsable(EditorBrowsableState.Never)]
2915 public virtual void ResetRightToLeft() {
2916 right_to_left = RightToLeft.Inherit;
2919 public virtual void ResetText() {
2920 text = String.Empty;
2923 public void ResumeLayout() {
2924 ResumeLayout (true);
2927 public void ResumeLayout(bool performLayout) {
2928 if (layout_suspended > 0) {
2932 if (layout_suspended == 0) {
2933 Control [] controls = child_controls.GetAllControls ();
2934 for (int i=0; i<controls.Length; i++) {
2935 controls [i].UpdateDistances ();
2938 if (performLayout && layout_pending) {
2944 public void Scale(float ratio) {
2945 ScaleCore(ratio, ratio);
2948 public void Scale(float dx, float dy) {
2952 public void Select() {
2953 Select(false, false);
2956 public bool SelectNextControl(Control ctl, bool forward, bool tabStopOnly, bool nested, bool wrap) {
2961 c = GetNextControl(c, forward);
2970 if (c.CanSelect && ((c.parent == ctl.parent) || nested) && (c.tab_stop || !tabStopOnly)) {
2974 } while (c != ctl); // If we wrap back to ourselves we stop
2979 public void SendToBack() {
2980 if ((parent != null) && (parent.child_controls[parent.child_controls.Count-1]!=this)) {
2981 if (parent.child_controls.Contains(this)) {
2982 parent.child_controls.SetChildIndex(this, parent.child_controls.Count);
2986 XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, false, true);
2987 if (parent != null) {
2992 public void SetBounds(int x, int y, int width, int height) {
2993 SetBoundsCore(x, y, width, height, BoundsSpecified.All);
2996 public void SetBounds(int x, int y, int width, int height, BoundsSpecified specified) {
2997 SetBoundsCore(x, y, width, height, specified);
3000 public void Show() {
3002 this.CreateControl();
3008 public void SuspendLayout() {
3012 public void Update() {
3013 needs_redraw = true;
3014 if (IsHandleCreated) {
3015 XplatUI.UpdateWindow(window.Handle);
3018 #endregion // Public Instance Methods
3020 #region Protected Instance Methods
3021 [EditorBrowsable(EditorBrowsableState.Advanced)]
3022 [MonoTODO("Implement this and tie it into Control.ControlAccessibleObject.NotifyClients")]
3023 protected void AccessibilityNotifyClients(AccessibleEvents accEvent, int childID) {
3024 throw new NotImplementedException();
3027 [EditorBrowsable(EditorBrowsableState.Advanced)]
3028 protected virtual AccessibleObject CreateAccessibilityInstance() {
3029 return new Control.ControlAccessibleObject(this);
3032 [EditorBrowsable(EditorBrowsableState.Advanced)]
3033 protected virtual ControlCollection CreateControlsInstance() {
3034 return new ControlCollection(this);
3037 [EditorBrowsable(EditorBrowsableState.Advanced)]
3038 protected virtual void CreateHandle() {
3040 throw new ObjectDisposedException(Name);
3043 if (IsHandleCreated && !is_recreating) {
3047 window.CreateHandle(CreateParams);
3049 if (window.Handle != IntPtr.Zero) {
3050 if (!controls.Contains(window.Handle)) {
3054 creator_thread = Thread.CurrentThread;
3056 XplatUI.EnableWindow(window.Handle, is_enabled);
3058 // Set our handle with our parent
3059 if ((parent != null) && (parent.IsHandleCreated)) {
3060 XplatUI.SetParent(window.Handle, parent.Handle);
3063 // Set our handle as parent for our children
3064 Control [] children;
3066 children = child_controls.GetAllControls ();
3067 for (int i = 0; i < children.Length; i++ ) {
3068 if (children[i].IsHandleCreated) {
3069 XplatUI.SetParent(children[i].Handle, window.Handle);
3073 // Find out where the window manager placed us
3075 if ((CreateParams.Style & (int)WindowStyles.WS_CHILD) != 0) {
3076 XplatUI.SetBorderStyle(window.Handle, (FormBorderStyle)border_style);
3080 OnHandleCreated(EventArgs.Empty);
3085 [EditorBrowsable(EditorBrowsableState.Advanced)]
3086 protected virtual void DefWndProc(ref Message m) {
3087 window.DefWndProc(ref m);
3090 [EditorBrowsable(EditorBrowsableState.Advanced)]
3091 protected virtual void DestroyHandle() {
3092 if (IsHandleCreated) {
3093 if (window != null) {
3094 window.DestroyHandle();
3099 protected bool GetStyle(ControlStyles flag) {
3100 return (control_style & flag) != 0;
3103 protected bool GetTopLevel() {
3107 [EditorBrowsable(EditorBrowsableState.Advanced)]
3108 protected virtual void InitLayout() {
3112 [EditorBrowsable(EditorBrowsableState.Advanced)]
3113 protected void InvokeGotFocus(Control toInvoke, EventArgs e) {
3114 toInvoke.OnGotFocus(e);
3117 [EditorBrowsable(EditorBrowsableState.Advanced)]
3118 protected void InvokeLostFocus(Control toInvoke, EventArgs e) {
3119 toInvoke.OnLostFocus(e);
3122 [EditorBrowsable(EditorBrowsableState.Advanced)]
3123 protected void InvokeOnClick(Control toInvoke, EventArgs e) {
3124 toInvoke.OnClick(e);
3127 protected void InvokePaint(Control toInvoke, PaintEventArgs e) {
3128 toInvoke.OnPaint(e);
3131 protected void InvokePaintBackground(Control toInvoke, PaintEventArgs e) {
3132 toInvoke.OnPaintBackground(e);
3135 protected virtual bool IsInputChar (char charCode) {
3139 protected virtual bool IsInputKey (Keys keyData) {
3140 // Doc says this one calls IsInputChar; not sure what to do with that
3144 [EditorBrowsable(EditorBrowsableState.Advanced)]
3145 protected virtual void NotifyInvalidate(Rectangle invalidatedArea) {
3149 protected virtual bool ProcessCmdKey(ref Message msg, Keys keyData) {
3150 if ((context_menu != null) && context_menu.ProcessCmdKey(ref msg, keyData)) {
3154 if (parent != null) {
3155 return parent.ProcessCmdKey(ref msg, keyData);
3161 protected virtual bool ProcessDialogChar(char charCode) {
3162 if (parent != null) {
3163 return parent.ProcessDialogChar (charCode);
3169 protected virtual bool ProcessDialogKey (Keys keyData) {
3170 if (parent != null) {
3171 return parent.ProcessDialogKey (keyData);
3177 protected virtual bool ProcessKeyEventArgs (ref Message msg)
3179 KeyEventArgs key_event;
3182 case (int)Msg.WM_SYSKEYDOWN:
3183 case (int)Msg.WM_KEYDOWN: {
3184 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
3185 OnKeyDown (key_event);
3186 return key_event.Handled;
3189 case (int)Msg.WM_SYSKEYUP:
3190 case (int)Msg.WM_KEYUP: {
3191 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
3192 OnKeyUp (key_event);
3193 return key_event.Handled;
3196 case (int)Msg.WM_SYSCHAR:
3197 case (int)Msg.WM_CHAR: {
3198 KeyPressEventArgs key_press_event;
3200 key_press_event = new KeyPressEventArgs((char)msg.WParam);
3201 OnKeyPress(key_press_event);
3202 return key_press_event.Handled;
3213 protected internal virtual bool ProcessKeyMessage(ref Message msg) {
3214 if (parent != null) {
3215 if (parent.ProcessKeyPreview(ref msg)) {
3220 return ProcessKeyEventArgs(ref msg);
3223 protected virtual bool ProcessKeyPreview(ref Message msg) {
3224 if (parent != null) {
3225 return parent.ProcessKeyPreview(ref msg);
3231 protected virtual bool ProcessMnemonic(char charCode) {
3236 [EditorBrowsable(EditorBrowsableState.Advanced)]
3237 protected void RaiseDragEvent(object key, DragEventArgs e) {
3241 [EditorBrowsable(EditorBrowsableState.Advanced)]
3242 protected void RaiseKeyEvent(object key, KeyEventArgs e) {
3246 [EditorBrowsable(EditorBrowsableState.Advanced)]
3247 protected void RaiseMouseEvent(object key, MouseEventArgs e) {
3251 [EditorBrowsable(EditorBrowsableState.Advanced)]
3252 protected void RaisePaintEvent(object key, PaintEventArgs e) {
3256 [EditorBrowsable(EditorBrowsableState.Advanced)]
3257 protected void RecreateHandle() {
3260 if (IsHandleCreated) {
3271 is_recreating = false;
3274 [EditorBrowsable(EditorBrowsableState.Advanced)]
3275 protected void ResetMouseEventArgs() {
3279 [EditorBrowsable(EditorBrowsableState.Advanced)]
3280 protected ContentAlignment RtlTranslateAlignment(ContentAlignment align) {
3281 if (right_to_left == RightToLeft.No) {
3286 case ContentAlignment.TopLeft: {
3287 return ContentAlignment.TopRight;
3290 case ContentAlignment.TopRight: {
3291 return ContentAlignment.TopLeft;
3294 case ContentAlignment.MiddleLeft: {
3295 return ContentAlignment.MiddleRight;
3298 case ContentAlignment.MiddleRight: {
3299 return ContentAlignment.MiddleLeft;
3302 case ContentAlignment.BottomLeft: {
3303 return ContentAlignment.BottomRight;
3306 case ContentAlignment.BottomRight: {
3307 return ContentAlignment.BottomLeft;
3311 // if it's center it doesn't change
3317 [EditorBrowsable(EditorBrowsableState.Advanced)]
3318 protected HorizontalAlignment RtlTranslateAlignment(HorizontalAlignment align) {
3319 if ((right_to_left == RightToLeft.No) || (align == HorizontalAlignment.Center)) {
3323 if (align == HorizontalAlignment.Left) {
3324 return HorizontalAlignment.Right;
3327 // align must be HorizontalAlignment.Right
3328 return HorizontalAlignment.Left;
3331 [EditorBrowsable(EditorBrowsableState.Advanced)]
3332 protected LeftRightAlignment RtlTranslateAlignment(LeftRightAlignment align) {
3333 if (right_to_left == RightToLeft.No) {
3337 if (align == LeftRightAlignment.Left) {
3338 return LeftRightAlignment.Right;
3341 // align must be LeftRightAlignment.Right;
3342 return LeftRightAlignment.Left;
3345 [EditorBrowsable(EditorBrowsableState.Advanced)]
3346 protected ContentAlignment RtlTranslateContent(ContentAlignment align) {
3347 return RtlTranslateAlignment(align);
3350 [EditorBrowsable(EditorBrowsableState.Advanced)]
3351 protected HorizontalAlignment RtlTranslateHorizontal(HorizontalAlignment align) {
3352 return RtlTranslateAlignment(align);
3355 [EditorBrowsable(EditorBrowsableState.Advanced)]
3356 protected LeftRightAlignment RtlTranslateLeftRight(LeftRightAlignment align) {
3357 return RtlTranslateAlignment(align);
3360 [EditorBrowsable(EditorBrowsableState.Advanced)]
3361 protected virtual void ScaleCore(float dx, float dy) {
3367 location = new Point((int)(Left * dx), (int)(Top * dy));
3368 size = this.ClientSize;
3370 if (!GetStyle(ControlStyles.FixedWidth)) {
3371 size.Width = (int)(size.Width * dx);
3374 if (!GetStyle(ControlStyles.FixedHeight)) {
3375 size.Height = (int)(size.Height * dy);
3378 SetBoundsCore(location.X, location.Y, size.Width, size.Height, BoundsSpecified.All);
3380 /* Now scale our children */
3381 Control [] controls = child_controls.GetAllControls ();
3382 for (int i=0; i < controls.Length; i++) {
3383 controls[i].Scale(dx, dy);
3389 protected virtual void Select(bool directed, bool forward) {
3394 // Select this control
3399 if (parent == null) {
3403 // FIXME - this thing is doing the wrong stuff, needs to be similar to SelectNextControl
3405 index = parent.child_controls.IndexOf(this);
3410 if ((index+1) < parent.child_controls.Count) {
3419 index = parent.child_controls.Count-1;
3422 result = Select(parent.child_controls[index]);
3423 } while (!result && parent.child_controls[index] != this);
3426 [EditorBrowsable(EditorBrowsableState.Advanced)]
3427 protected virtual void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
3428 // SetBoundsCore updates the Win32 control itself. UpdateBounds updates the controls variables and fires events, I'm guessing - pdb
3429 if ((specified & BoundsSpecified.X) != BoundsSpecified.X) {
3433 if ((specified & BoundsSpecified.Y) != BoundsSpecified.Y) {
3437 if ((specified & BoundsSpecified.Width) != BoundsSpecified.Width) {
3441 if ((specified & BoundsSpecified.Height) != BoundsSpecified.Height) {
3445 if (IsHandleCreated) {
3446 XplatUI.SetWindowPos(Handle, x, y, width, height);
3449 UpdateBounds(x, y, width, height);
3454 [EditorBrowsable(EditorBrowsableState.Advanced)]
3455 protected virtual void SetClientSizeCore(int x, int y) {
3456 // Calculate the actual window size from the client size (it usually stays the same or grows)
3457 Rectangle ClientRect;
3458 Rectangle WindowRect;
3461 ClientRect = new Rectangle(0, 0, x, y);
3462 cp = this.CreateParams;
3464 if (XplatUI.CalculateWindowRect(Handle, ref ClientRect, cp.Style, cp.ExStyle, null, out WindowRect)==false) {
3468 SetBoundsCore(bounds.X, bounds.Y, WindowRect.Width, WindowRect.Height, BoundsSpecified.Size);
3471 [EditorBrowsable(EditorBrowsableState.Advanced)]
3472 protected void SetStyle(ControlStyles flag, bool value) {
3474 control_style |= flag;
3476 control_style &= ~flag;
3478 OnStyleChanged(EventArgs.Empty);
3481 protected void SetTopLevel(bool value) {
3482 if ((GetTopLevel() != value) && (parent != null)) {
3483 throw new Exception();
3487 if (value == true) {
3497 is_toplevel = value;
3500 protected virtual void SetVisibleCore(bool value) {
3501 if (value!=is_visible) {
3504 if (IsHandleCreated) {
3505 XplatUI.SetVisible(Handle, value);
3506 // Explicitly move Toplevel windows to where we want them;
3507 // apparently moving unmapped toplevel windows doesn't work
3508 if (is_visible && (this is Form)) {
3509 XplatUI.SetWindowPos(window.Handle, bounds.X, bounds.Y, bounds.Width, bounds.Height);
3514 if (dc_mem != null) {
3519 if (bmp_mem != null) {
3524 this.CreateBuffers(bounds.Width, bounds.Height);
3528 OnVisibleChanged(EventArgs.Empty);
3530 if (value == false && parent != null) {
3533 // Need to start at parent, GetContainerControl might return ourselves if we're a container
3534 container = (Control)parent.GetContainerControl();
3535 if (container != null) {
3536 container.SelectNextControl(this, true, true, true, true);
3540 if (parent != null) {
3541 parent.PerformLayout(this, "visible");
3543 PerformLayout(this, "visible");
3548 [EditorBrowsable(EditorBrowsableState.Advanced)]
3549 protected void UpdateBounds() {
3557 if (!IsHandleCreated) {
3561 XplatUI.GetWindowPos(this.Handle, this is Form, out x, out y, out width, out height, out client_width, out client_height);
3563 UpdateBounds(x, y, width, height, client_width, client_height);
3566 [EditorBrowsable(EditorBrowsableState.Advanced)]
3567 protected void UpdateBounds(int x, int y, int width, int height) {
3568 // UpdateBounds only seems to set our sizes and fire events but not update the GUI window to match
3570 bool resized = false;
3572 int client_x_diff = this.bounds.Width-this.client_size.Width;
3573 int client_y_diff = this.bounds.Height-this.client_size.Height;
3575 // Needed to generate required notifications
3576 if ((this.bounds.X!=x) || (this.bounds.Y!=y)) {
3580 if ((this.Bounds.Width!=width) || (this.Bounds.Height!=height)) {
3587 bounds.Height=height;
3589 // Update client rectangle as well
3590 client_size.Width=width-client_x_diff;
3591 client_size.Height=height-client_y_diff;
3594 OnLocationChanged(EventArgs.Empty);
3598 OnSizeChanged(EventArgs.Empty);
3602 [EditorBrowsable(EditorBrowsableState.Advanced)]
3603 protected void UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) {
3604 UpdateBounds(x, y, width, height);
3606 this.client_size.Width=clientWidth;
3607 this.client_size.Height=clientHeight;
3610 [EditorBrowsable(EditorBrowsableState.Advanced)]
3611 protected void UpdateStyles() {
3612 if (!IsHandleCreated) {
3616 XplatUI.SetWindowStyle(window.Handle, CreateParams);
3619 [EditorBrowsable(EditorBrowsableState.Advanced)]
3620 protected void UpdateZOrder() {
3621 Control [] controls;
3622 if (!IsHandleCreated) {
3626 controls = child_controls.GetAllControls ();
3627 for (int i = 1; i < controls.Length; i++ ) {
3628 XplatUI.SetZOrder(controls[i].Handle, controls[i-1].Handle, false, false);
3632 protected virtual void WndProc(ref Message m) {
3634 Console.WriteLine("Control {0} received message {1}", window.Handle == IntPtr.Zero ? this.Text : XplatUI.Window(window.Handle), (Msg)m.Msg);
3636 if ((this.control_style & ControlStyles.EnableNotifyMessage) != 0) {
3640 switch((Msg)m.Msg) {
3641 case Msg.WM_DESTROY: {
3642 OnHandleDestroyed(EventArgs.Empty);
3643 window.InvalidateHandle();
3647 case Msg.WM_WINDOWPOSCHANGED: {
3650 if (GetStyle(ControlStyles.ResizeRedraw)) {
3657 case Msg.WM_PAINT: {
3658 PaintEventArgs paint_event;
3660 paint_event = XplatUI.PaintEventStart(Handle, true);
3662 if (!needs_redraw) {
3663 // Just blit the previous image
3664 paint_event.Graphics.DrawImage (ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle, GraphicsUnit.Pixel);
3665 XplatUI.PaintEventEnd(Handle, true);
3670 if (ThemeEngine.Current.DoubleBufferingSupported)
3671 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
3672 dc = paint_event.SetGraphics (DeviceContext);
3675 OnPaintBackground(paint_event);
3676 // Leave out for now, our controls can do Paint += ... as well
3677 //OnPaintInternal(paint_event);
3678 OnPaint(paint_event);
3680 if (ThemeEngine.Current.DoubleBufferingSupported)
3681 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
3682 dc.DrawImage (ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle, GraphicsUnit.Pixel);
3683 paint_event.SetGraphics (dc);
3684 needs_redraw = false;
3687 XplatUI.PaintEventEnd(Handle, true);
3692 case Msg.WM_ERASEBKGND: {
3693 // The DefWndProc will never have to handle this, we always paint the background in managed code
3694 m.Result = (IntPtr)1;
3698 case Msg.WM_LBUTTONUP: {
3699 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Left,
3701 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3703 HandleClick(mouse_clicks);
3704 if (mouse_clicks > 1) {
3710 case Msg.WM_LBUTTONDOWN: {
3711 if (CanSelect && !is_selected) {
3714 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3715 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3721 case Msg.WM_LBUTTONDBLCLK: {
3723 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3724 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3730 case Msg.WM_MBUTTONUP: {
3731 HandleClick(mouse_clicks);
3732 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Middle,
3734 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3736 if (mouse_clicks > 1) {
3742 case Msg.WM_MBUTTONDOWN: {
3743 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3744 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3750 case Msg.WM_MBUTTONDBLCLK: {
3752 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3753 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3758 case Msg.WM_RBUTTONUP: {
3759 if (context_menu != null) {
3760 context_menu.Show(this, new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ())));
3763 HandleClick(mouse_clicks);
3764 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Right,
3766 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3768 if (mouse_clicks > 1) {
3774 case Msg.WM_RBUTTONDOWN: {
3775 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3776 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3781 case Msg.WM_RBUTTONDBLCLK: {
3783 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3784 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3789 case Msg.WM_MOUSEWHEEL: {
3791 OnMouseWheel (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3792 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3793 HighOrder(m.WParam.ToInt32())));
3798 case Msg.WM_MOUSEMOVE: {
3799 OnMouseMove (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3801 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3806 case Msg.WM_MOUSE_ENTER: {
3811 OnMouseEnter(EventArgs.Empty);
3815 case Msg.WM_MOUSE_LEAVE: {
3817 OnMouseLeave(EventArgs.Empty);
3821 case Msg.WM_MOUSEHOVER: {
3822 OnMouseHover(EventArgs.Empty);
3826 case Msg.WM_SYSKEYDOWN:
3827 case Msg.WM_KEYDOWN:
3828 case Msg.WM_SYSKEYUP:
3830 case Msg.WM_SYSCHAR:
3832 if (ProcessKeyMessage(ref m)) {
3836 if ((m.Msg == (int)Msg.WM_SYSKEYUP) && ((m.WParam.ToInt32() & (int)Keys.KeyCode) == (int)Keys.Menu)) {
3840 if (form != null && form.ActiveMenu != null) {
3841 form.ActiveMenu.ProcessCmdKey(ref m, (Keys)m.WParam.ToInt32());
3851 if (m.LParam != IntPtr.Zero) {
3854 hi = new HELPINFO();
3856 hi = (HELPINFO) Marshal.PtrToStructure (m.LParam, typeof (HELPINFO));
3857 mouse_pos = new Point(hi.MousePos.x, hi.MousePos.y);
3859 mouse_pos = Control.MousePosition;
3861 OnHelpRequested(new HelpEventArgs(mouse_pos));
3862 m.Result = (IntPtr)1;
3866 case Msg.WM_KILLFOCUS: {
3867 OnLeave(EventArgs.Empty);
3868 if (CausesValidation) {
3870 e = new CancelEventArgs(false);
3879 OnValidated(EventArgs.Empty);
3882 this.has_focus = false;
3883 this.is_selected = false;
3884 OnLostFocus(EventArgs.Empty);
3888 case Msg.WM_SETFOCUS: {
3889 OnEnter(EventArgs.Empty);
3890 this.has_focus = true;
3891 OnGotFocus(EventArgs.Empty);
3896 case Msg.WM_SYSCOLORCHANGE: {
3897 ThemeEngine.Current.ResetDefaults();
3898 OnSystemColorsChanged(EventArgs.Empty);
3903 case Msg.WM_SETCURSOR: {
3904 if ((cursor == null) || ((HitTest)(m.LParam.ToInt32() & 0xffff) != HitTest.HTCLIENT)) {
3909 XplatUI.SetCursor(window.Handle, cursor.handle);
3910 m.Result = (IntPtr)1;
3921 #endregion // Public Instance Methods
3923 #region OnXXX methods
3924 [EditorBrowsable(EditorBrowsableState.Advanced)]
3925 protected virtual void OnBackColorChanged(EventArgs e) {
3926 if (BackColorChanged!=null) BackColorChanged(this, e);
3927 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackColorChanged(e);
3930 [EditorBrowsable(EditorBrowsableState.Advanced)]
3931 protected virtual void OnBackgroundImageChanged(EventArgs e) {
3932 if (BackgroundImageChanged!=null) BackgroundImageChanged(this, e);
3933 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackgroundImageChanged(e);
3936 [EditorBrowsable(EditorBrowsableState.Advanced)]
3937 protected virtual void OnBindingContextChanged(EventArgs e) {
3938 CheckDataBindings ();
3939 if (BindingContextChanged!=null) {
3940 BindingContextChanged(this, e);
3942 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBindingContextChanged(e);
3945 [EditorBrowsable(EditorBrowsableState.Advanced)]
3946 protected virtual void OnCausesValidationChanged(EventArgs e) {
3947 if (CausesValidationChanged!=null) CausesValidationChanged(this, e);
3950 [EditorBrowsable(EditorBrowsableState.Advanced)]
3951 protected virtual void OnChangeUICues(UICuesEventArgs e) {
3952 if (ChangeUICues!=null) ChangeUICues(this, e);
3955 [EditorBrowsable(EditorBrowsableState.Advanced)]
3956 protected virtual void OnClick(EventArgs e) {
3957 if (Click!=null) Click(this, e);
3960 [EditorBrowsable(EditorBrowsableState.Advanced)]
3961 protected virtual void OnContextMenuChanged(EventArgs e) {
3962 if (ContextMenuChanged!=null) ContextMenuChanged(this, e);
3965 [EditorBrowsable(EditorBrowsableState.Advanced)]
3966 protected virtual void OnControlAdded(ControlEventArgs e) {
3967 if (ControlAdded!=null) ControlAdded(this, e);
3970 [EditorBrowsable(EditorBrowsableState.Advanced)]
3971 protected virtual void OnControlRemoved(ControlEventArgs e) {
3972 if (ControlRemoved!=null) ControlRemoved(this, e);
3975 [EditorBrowsable(EditorBrowsableState.Advanced)]
3976 protected virtual void OnCreateControl() {
3980 [EditorBrowsable(EditorBrowsableState.Advanced)]
3981 protected virtual void OnCursorChanged(EventArgs e) {
3982 if (CursorChanged!=null) CursorChanged(this, e);
3985 [EditorBrowsable(EditorBrowsableState.Advanced)]
3986 protected virtual void OnDockChanged(EventArgs e) {
3987 if (DockChanged!=null) DockChanged(this, e);
3990 [EditorBrowsable(EditorBrowsableState.Advanced)]
3991 protected virtual void OnDoubleClick(EventArgs e) {
3992 if (DoubleClick!=null) DoubleClick(this, e);
3995 [EditorBrowsable(EditorBrowsableState.Advanced)]
3996 protected virtual void OnDragDrop(DragEventArgs drgevent) {
3997 if (DragDrop!=null) DragDrop(this, drgevent);
4000 [EditorBrowsable(EditorBrowsableState.Advanced)]
4001 protected virtual void OnDragEnter(DragEventArgs drgevent) {
4002 if (DragEnter!=null) DragEnter(this, drgevent);
4005 [EditorBrowsable(EditorBrowsableState.Advanced)]
4006 protected virtual void OnDragLeave(EventArgs e) {
4007 if (DragLeave!=null) DragLeave(this, e);
4010 [EditorBrowsable(EditorBrowsableState.Advanced)]
4011 protected virtual void OnDragOver(DragEventArgs drgevent) {
4012 if (DragOver!=null) DragOver(this, drgevent);
4015 [EditorBrowsable(EditorBrowsableState.Advanced)]
4016 protected virtual void OnEnabledChanged(EventArgs e) {
4017 if (EnabledChanged!=null) EnabledChanged(this, e);
4018 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentEnabledChanged(e);
4021 [EditorBrowsable(EditorBrowsableState.Advanced)]
4022 protected virtual void OnEnter(EventArgs e) {
4023 if (Enter!=null) Enter(this, e);
4026 [EditorBrowsable(EditorBrowsableState.Advanced)]
4027 protected virtual void OnFontChanged(EventArgs e) {
4028 if (FontChanged!=null) FontChanged(this, e);
4029 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentFontChanged(e);
4032 [EditorBrowsable(EditorBrowsableState.Advanced)]
4033 protected virtual void OnForeColorChanged(EventArgs e) {
4034 if (ForeColorChanged!=null) ForeColorChanged(this, e);
4035 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentForeColorChanged(e);
4038 [EditorBrowsable(EditorBrowsableState.Advanced)]
4039 protected virtual void OnGiveFeedback(GiveFeedbackEventArgs gfbevent) {
4040 if (GiveFeedback!=null) GiveFeedback(this, gfbevent);
4043 [EditorBrowsable(EditorBrowsableState.Advanced)]
4044 protected virtual void OnGotFocus(EventArgs e) {
4045 if (GotFocus!=null) GotFocus(this, e);
4048 [EditorBrowsable(EditorBrowsableState.Advanced)]
4049 protected virtual void OnHandleCreated(EventArgs e) {
4050 if (HandleCreated!=null) HandleCreated(this, e);
4053 [EditorBrowsable(EditorBrowsableState.Advanced)]
4054 protected virtual void OnHandleDestroyed(EventArgs e) {
4055 if (HandleDestroyed!=null) HandleDestroyed(this, e);
4058 [EditorBrowsable(EditorBrowsableState.Advanced)]
4059 protected virtual void OnHelpRequested(HelpEventArgs hevent) {
4060 if (HelpRequested!=null) HelpRequested(this, hevent);
4063 protected virtual void OnImeModeChanged(EventArgs e) {
4064 if (ImeModeChanged!=null) ImeModeChanged(this, e);
4067 [EditorBrowsable(EditorBrowsableState.Advanced)]
4068 protected virtual void OnInvalidated(InvalidateEventArgs e) {
4069 needs_redraw = true;
4070 if (Invalidated!=null) Invalidated(this, e);
4073 [EditorBrowsable(EditorBrowsableState.Advanced)]
4074 protected virtual void OnKeyDown(KeyEventArgs e) {
4075 if (KeyDown!=null) KeyDown(this, e);
4078 [EditorBrowsable(EditorBrowsableState.Advanced)]
4079 protected virtual void OnKeyPress(KeyPressEventArgs e) {
4080 if (KeyPress!=null) KeyPress(this, e);
4083 [EditorBrowsable(EditorBrowsableState.Advanced)]
4084 protected virtual void OnKeyUp(KeyEventArgs e) {
4085 if (KeyUp!=null) KeyUp(this, e);
4088 [EditorBrowsable(EditorBrowsableState.Advanced)]
4089 protected virtual void OnLayout(LayoutEventArgs levent) {
4090 if (Layout!=null) Layout(this, levent);
4093 [EditorBrowsable(EditorBrowsableState.Advanced)]
4094 protected virtual void OnLeave(EventArgs e) {
4095 if (Leave!=null) Leave(this, e);
4098 [EditorBrowsable(EditorBrowsableState.Advanced)]
4099 protected virtual void OnLocationChanged(EventArgs e) {
4101 if (LocationChanged!=null) LocationChanged(this, e);
4104 [EditorBrowsable(EditorBrowsableState.Advanced)]
4105 protected virtual void OnLostFocus(EventArgs e) {
4106 if (LostFocus!=null) LostFocus(this, e);
4109 [EditorBrowsable(EditorBrowsableState.Advanced)]
4110 protected virtual void OnMouseDown(MouseEventArgs e) {
4111 if (MouseDown!=null) MouseDown(this, e);
4114 [EditorBrowsable(EditorBrowsableState.Advanced)]
4115 protected virtual void OnMouseEnter(EventArgs e) {
4116 if (MouseEnter!=null) MouseEnter(this, e);
4119 [EditorBrowsable(EditorBrowsableState.Advanced)]
4120 protected virtual void OnMouseHover(EventArgs e) {
4121 if (MouseHover!=null) MouseHover(this, e);
4124 [EditorBrowsable(EditorBrowsableState.Advanced)]
4125 protected virtual void OnMouseLeave(EventArgs e) {
4126 if (MouseLeave!=null) MouseLeave(this, e);
4129 [EditorBrowsable(EditorBrowsableState.Advanced)]
4130 protected virtual void OnMouseMove(MouseEventArgs e) {
4131 if (MouseMove!=null) MouseMove(this, e);
4134 [EditorBrowsable(EditorBrowsableState.Advanced)]
4135 protected virtual void OnMouseUp(MouseEventArgs e) {
4136 if (MouseUp!=null) MouseUp(this, e);
4139 [EditorBrowsable(EditorBrowsableState.Advanced)]
4140 protected virtual void OnMouseWheel(MouseEventArgs e) {
4141 if (MouseWheel!=null) MouseWheel(this, e);
4144 [EditorBrowsable(EditorBrowsableState.Advanced)]
4145 protected virtual void OnMove(EventArgs e) {
4146 if (Move!=null) Move(this, e);
4149 [EditorBrowsable(EditorBrowsableState.Advanced)]
4150 protected virtual void OnNotifyMessage(Message m) {
4154 [EditorBrowsable(EditorBrowsableState.Advanced)]
4155 protected virtual void OnPaint(PaintEventArgs e) {
4156 if (Paint!=null) Paint(this, e);
4159 internal virtual void OnPaintInternal(PaintEventArgs e) {
4163 [EditorBrowsable(EditorBrowsableState.Advanced)]
4164 protected virtual void OnPaintBackground(PaintEventArgs pevent) {
4165 PaintControlBackground (pevent);
4168 [EditorBrowsable(EditorBrowsableState.Advanced)]
4169 protected virtual void OnParentBackColorChanged(EventArgs e) {
4170 if (background_color.IsEmpty && background_image==null) {
4172 OnBackColorChanged(e);
4176 [EditorBrowsable(EditorBrowsableState.Advanced)]
4177 protected virtual void OnParentBackgroundImageChanged(EventArgs e) {
4178 if (background_color.IsEmpty && background_image==null) {
4180 OnBackgroundImageChanged(e);
4184 [EditorBrowsable(EditorBrowsableState.Advanced)]
4185 protected virtual void OnParentBindingContextChanged(EventArgs e) {
4186 if (binding_context==null) {
4187 binding_context=Parent.binding_context;
4188 OnBindingContextChanged(e);
4192 [EditorBrowsable(EditorBrowsableState.Advanced)]
4193 protected virtual void OnParentChanged(EventArgs e) {
4194 if (ParentChanged!=null) ParentChanged(this, e);
4197 [EditorBrowsable(EditorBrowsableState.Advanced)]
4198 protected virtual void OnParentEnabledChanged(EventArgs e) {
4199 if (is_enabled != Parent.is_enabled) {
4200 is_enabled=Parent.is_enabled;
4202 if (EnabledChanged != null) {
4203 EnabledChanged(this, e);
4208 [EditorBrowsable(EditorBrowsableState.Advanced)]
4209 protected virtual void OnParentFontChanged(EventArgs e) {
4216 [EditorBrowsable(EditorBrowsableState.Advanced)]
4217 protected virtual void OnParentForeColorChanged(EventArgs e) {
4218 if (foreground_color.IsEmpty) {
4220 OnForeColorChanged(e);
4224 [EditorBrowsable(EditorBrowsableState.Advanced)]
4225 protected virtual void OnParentRightToLeftChanged(EventArgs e) {
4226 if (right_to_left==RightToLeft.Inherit) {
4228 OnRightToLeftChanged(e);
4232 [EditorBrowsable(EditorBrowsableState.Advanced)]
4233 protected virtual void OnParentVisibleChanged(EventArgs e) {
4235 OnVisibleChanged(e);
4239 [EditorBrowsable(EditorBrowsableState.Advanced)]
4240 protected virtual void OnQueryContinueDrag(QueryContinueDragEventArgs e) {
4241 if (QueryContinueDrag!=null) QueryContinueDrag(this, e);
4244 [EditorBrowsable(EditorBrowsableState.Advanced)]
4245 protected virtual void OnResize(EventArgs e) {
4246 if (Resize!=null) Resize(this, e);
4248 PerformLayout(this, "bounds");
4250 if (parent != null) {
4251 parent.PerformLayout();
4255 [EditorBrowsable(EditorBrowsableState.Advanced)]
4256 protected virtual void OnRightToLeftChanged(EventArgs e) {
4257 if (RightToLeftChanged!=null) RightToLeftChanged(this, e);
4258 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentRightToLeftChanged(e);
4261 [EditorBrowsable(EditorBrowsableState.Advanced)]
4262 protected virtual void OnSizeChanged(EventArgs e) {
4263 InvalidateBuffers ();
4265 if (SizeChanged!=null) SizeChanged(this, e);
4268 [EditorBrowsable(EditorBrowsableState.Advanced)]
4269 protected virtual void OnStyleChanged(EventArgs e) {
4270 if (StyleChanged!=null) StyleChanged(this, e);
4273 [EditorBrowsable(EditorBrowsableState.Advanced)]
4274 protected virtual void OnSystemColorsChanged(EventArgs e) {
4275 if (SystemColorsChanged!=null) SystemColorsChanged(this, e);
4278 [EditorBrowsable(EditorBrowsableState.Advanced)]
4279 protected virtual void OnTabIndexChanged(EventArgs e) {
4280 if (TabIndexChanged!=null) TabIndexChanged(this, e);
4283 [EditorBrowsable(EditorBrowsableState.Advanced)]
4284 protected virtual void OnTabStopChanged(EventArgs e) {
4285 if (TabStopChanged!=null) TabStopChanged(this, e);
4288 [EditorBrowsable(EditorBrowsableState.Advanced)]
4289 protected virtual void OnTextChanged(EventArgs e) {
4290 if (TextChanged!=null) TextChanged(this, e);
4293 [EditorBrowsable(EditorBrowsableState.Advanced)]
4294 protected virtual void OnValidated(EventArgs e) {
4295 if (Validated!=null) Validated(this, e);
4298 [EditorBrowsable(EditorBrowsableState.Advanced)]
4299 protected virtual void OnValidating(System.ComponentModel.CancelEventArgs e) {
4300 if (Validating!=null) Validating(this, e);
4303 [EditorBrowsable(EditorBrowsableState.Advanced)]
4304 protected virtual void OnVisibleChanged(EventArgs e) {
4305 if ((parent != null) && !Created && Visible) {
4316 if (bmp_mem!=null) {
4322 if (VisibleChanged!=null) VisibleChanged(this, e);
4324 // We need to tell our kids
4325 for (int i=0; i<child_controls.Count; i++) {
4326 child_controls[i].OnParentVisibleChanged(e);
4329 #endregion // OnXXX methods
4332 public event EventHandler BackColorChanged;
4333 public event EventHandler BackgroundImageChanged;
4334 public event EventHandler BindingContextChanged;
4335 public event EventHandler CausesValidationChanged;
4336 public event UICuesEventHandler ChangeUICues;
4337 public event EventHandler Click;
4338 public event EventHandler ContextMenuChanged;
4340 [EditorBrowsable(EditorBrowsableState.Advanced)]
4342 public event ControlEventHandler ControlAdded;
4344 [EditorBrowsable(EditorBrowsableState.Advanced)]
4346 public event ControlEventHandler ControlRemoved;
4348 [MWFDescription("Fired when the cursor for the control has been changed"), MWFCategory("PropertyChanged")]
4349 public event EventHandler CursorChanged;
4350 public event EventHandler DockChanged;
4351 public event EventHandler DoubleClick;
4352 public event DragEventHandler DragDrop;
4353 public event DragEventHandler DragEnter;
4354 public event EventHandler DragLeave;
4355 public event DragEventHandler DragOver;
4356 public event EventHandler EnabledChanged;
4357 public event EventHandler Enter;
4358 public event EventHandler FontChanged;
4359 public event EventHandler ForeColorChanged;
4360 public event GiveFeedbackEventHandler GiveFeedback;
4362 [EditorBrowsable(EditorBrowsableState.Advanced)]
4364 public event EventHandler GotFocus;
4366 [EditorBrowsable(EditorBrowsableState.Advanced)]
4368 public event EventHandler HandleCreated;
4370 [EditorBrowsable(EditorBrowsableState.Advanced)]
4372 public event EventHandler HandleDestroyed;
4374 public event HelpEventHandler HelpRequested;
4375 public event EventHandler ImeModeChanged;
4377 [EditorBrowsable(EditorBrowsableState.Advanced)]
4379 public event InvalidateEventHandler Invalidated;
4381 public event KeyEventHandler KeyDown;
4382 public event KeyPressEventHandler KeyPress;
4383 public event KeyEventHandler KeyUp;
4384 public event LayoutEventHandler Layout;
4385 public event EventHandler Leave;
4386 public event EventHandler LocationChanged;
4388 [EditorBrowsable(EditorBrowsableState.Advanced)]
4390 public event EventHandler LostFocus;
4392 public event MouseEventHandler MouseDown;
4393 public event EventHandler MouseEnter;
4394 public event EventHandler MouseHover;
4395 public event EventHandler MouseLeave;
4396 public event MouseEventHandler MouseMove;
4397 public event MouseEventHandler MouseUp;
4399 [EditorBrowsable(EditorBrowsableState.Advanced)]
4401 public event MouseEventHandler MouseWheel;
4403 public event EventHandler Move;
4404 public event PaintEventHandler Paint;
4405 public event EventHandler ParentChanged;
4406 public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp;
4407 public event QueryContinueDragEventHandler QueryContinueDrag;
4408 public event EventHandler Resize;
4409 public event EventHandler RightToLeftChanged;
4410 public event EventHandler SizeChanged;
4411 public event EventHandler StyleChanged;
4412 public event EventHandler SystemColorsChanged;
4413 public event EventHandler TabIndexChanged;
4414 public event EventHandler TabStopChanged;
4415 public event EventHandler TextChanged;
4416 public event EventHandler Validated;
4417 public event CancelEventHandler Validating;
4418 public event EventHandler VisibleChanged;
4419 #endregion // Events