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 private 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);
357 control.ChangeParent (owner);
358 owner.UpdateZOrder ();
359 owner.PerformLayout (control, "Parent");
360 owner.OnControlAdded (new ControlEventArgs (control));
363 public virtual void AddRange (Control[] controls)
365 if (controls == null)
366 throw new ArgumentNullException ("controls");
368 owner.SuspendLayout ();
371 for (int i = 0; i < controls.Length; i++)
374 owner.ResumeLayout ();
378 internal virtual void AddRangeImplicit (Control [] controls)
380 if (controls == null)
381 throw new ArgumentNullException ("controls");
383 owner.SuspendLayout ();
386 for (int i = 0; i < controls.Length; i++)
387 AddImplicit (controls [i]);
389 owner.ResumeLayout ();
393 public virtual void Clear ()
397 // MS sends remove events in reverse order
398 while (list.Count > 0) {
399 RemoveAt(list.Count - 1);
403 internal virtual void ClearImplicit ()
405 if (impl_list == null)
411 public bool Contains (Control value)
413 for (int i = list.Count; i > 0; ) {
416 if (list [i] == value) {
417 // Do we need to do anything here?
424 internal bool ImplicitContains (Control value)
426 if (impl_list == null)
429 for (int i = impl_list.Count; i > 0; ) {
432 if (impl_list [i] == value) {
433 // Do we need to do anything here?
440 internal bool AllContains (Control value)
442 return Contains (value) || ImplicitContains (value);
445 public virtual void CopyTo (Array array, int index)
447 list.CopyTo(array, index);
450 public override bool Equals(object other) {
451 if (other is ControlCollection && (((ControlCollection)other).owner==this.owner)) {
458 public int GetChildIndex(Control child) {
459 return GetChildIndex(child, false);
462 public int GetChildIndex(Control child, bool throwException) {
465 index=list.IndexOf(child);
467 if (index==-1 && throwException) {
468 throw new ArgumentException("Not a child control", "child");
473 public IEnumerator GetEnumerator() {
474 return list.GetEnumerator();
477 internal IEnumerator GetAllEnumerator ()
479 Control [] res = GetAllControls ();
480 return res.GetEnumerator ();
483 internal Control [] GetAllControls ()
485 if (all_controls != null)
488 if (impl_list == null)
489 return (Control []) list.ToArray (typeof (Control));
490 Control [] res = new Control [list.Count + impl_list.Count];
492 impl_list.CopyTo (res, list.Count);
496 public override int GetHashCode() {
497 return base.GetHashCode();
500 public int IndexOf(Control control) {
501 return list.IndexOf(control);
504 public virtual void Remove(Control value) {
507 owner.PerformLayout(value, "Parent");
508 owner.OnControlRemoved(new ControlEventArgs(value));
511 value.ChangeParent(null);
513 owner.UpdateZOrder();
516 internal virtual void RemoveImplicit (Control control)
518 if (impl_list != null) {
520 owner.PerformLayout (control, "Parent");
521 owner.OnControlRemoved (new ControlEventArgs (control));
522 impl_list.Remove (control);
524 control.ChangeParent (null);
525 owner.UpdateZOrder ();
528 public void RemoveAt(int index) {
529 if (index < 0 || index >= list.Count) {
530 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
532 Remove ((Control)list[index]);
535 public void SetChildIndex(Control child, int newIndex) {
538 old_index=list.IndexOf(child);
540 throw new ArgumentException("Not a child control", "child");
543 if (old_index==newIndex) {
549 if (newIndex>list.Count) {
552 list.Insert(newIndex, child);
554 child.parent = owner;
555 owner.UpdateZOrder();
557 #endregion // ControlCollection Private Instance Methods
559 #region ControlCollection Interface Properties
560 object IList.this[int index] {
562 if (index<0 || index>=list.Count) {
563 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
569 if (!(value is Control)) {
570 throw new ArgumentException("Object of type Control required", "value");
573 list[index]=(Control)value;
577 bool IList.IsFixedSize {
583 bool IList.IsReadOnly {
585 return list.IsReadOnly;
589 bool ICollection.IsSynchronized {
591 return list.IsSynchronized;
595 object ICollection.SyncRoot {
597 return list.SyncRoot;
600 #endregion // ControlCollection Interface Properties
602 #region ControlCollection Interface Methods
603 int IList.Add(object value) {
605 throw new ArgumentNullException("value", "Cannot add null controls");
608 if (!(value is Control)) {
609 throw new ArgumentException("Object of type Control required", "value");
612 return list.Add(value);
615 bool IList.Contains(object value) {
616 if (!(value is Control)) {
617 throw new ArgumentException("Object of type Control required", "value");
620 return this.Contains((Control) value);
623 int IList.IndexOf(object value) {
624 if (!(value is Control)) {
625 throw new ArgumentException("Object of type Control required", "value");
628 return this.IndexOf((Control) value);
631 void IList.Insert(int index, object value) {
632 if (!(value is Control)) {
633 throw new ArgumentException("Object of type Control required", "value");
636 list.Insert(index, value);
639 void IList.Remove(object value) {
640 if (!(value is Control)) {
641 throw new ArgumentException("Object of type Control required", "value");
647 void ICollection.CopyTo(Array array, int index) {
649 list.CopyTo(array, index);
653 Object ICloneable.Clone() {
654 ControlCollection clone = new ControlCollection(this.owner);
655 clone.list=(ArrayList)list.Clone(); // FIXME: Do we need this?
658 #endregion // ControlCollection Interface Methods
660 #endregion // ControlCollection Class
662 #region Public Constructors
665 anchor_style = AnchorStyles.Top | AnchorStyles.Left;
673 layout_pending = false;
675 causes_validation = true;
677 layout_suspended = 0;
681 right_to_left = RightToLeft.Inherit;
682 border_style = BorderStyle.None;
683 background_color = Color.Empty;
690 use_compatible_text_rendering = Application.use_compatible_text_rendering;
693 control_style = ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint |
694 ControlStyles.Selectable | ControlStyles.StandardClick |
695 ControlStyles.StandardDoubleClick;
698 background_image = null;
702 window = new ControlNativeWindow(this);
703 child_controls = CreateControlsInstance();
704 client_size = new Size(DefaultSize.Width, DefaultSize.Height);
705 client_rect = new Rectangle(0, 0, DefaultSize.Width, DefaultSize.Height);
706 XplatUI.CalculateWindowRect(IntPtr.Zero, ref client_rect, CreateParams.Style, CreateParams.ExStyle, null, out bounds);
707 if ((CreateParams.Style & (int)WindowStyles.WS_CHILD) == 0) {
713 public Control(Control parent, string text) : this() {
718 public Control(Control parent, string text, int left, int top, int width, int height) : this() {
723 bounds.Height=height;
724 SetBoundsCore(left, top, width, height, BoundsSpecified.All);
728 public Control(string text) : this() {
732 public Control(string text, int left, int top, int width, int height) : this() {
736 bounds.Height=height;
737 SetBoundsCore(left, top, width, height, BoundsSpecified.All);
741 private delegate void RemoveDelegate(object c);
743 protected override void Dispose(bool disposing) {
755 if (this.InvokeRequired) {
756 if (Application.MessageLoop) {
757 this.BeginInvokeInternal(new MethodInvoker(DestroyHandle), null, true);
758 this.BeginInvokeInternal(new RemoveDelegate(controls.Remove), new object[] {this}, true);
762 controls.Remove(this);
765 #endregion // Public Constructors
767 #region Internal Properties
768 internal BorderStyle InternalBorderStyle {
774 if (!Enum.IsDefined (typeof (BorderStyle), value))
775 throw new InvalidEnumArgumentException (string.Format("Enum argument value '{0}' is not valid for BorderStyle", value));
777 if (border_style != value) {
778 border_style = value;
780 if (IsHandleCreated) {
781 XplatUI.SetBorderStyle(window.Handle, (FormBorderStyle)border_style);
787 #endregion // Internal Properties
789 #region Private & Internal Methods
790 internal IAsyncResult BeginInvokeInternal (Delegate method, object [] args, bool disposing) {
791 AsyncMethodResult result;
792 AsyncMethodData data;
799 if (!p.IsHandleCreated) {
800 throw new InvalidOperationException("Cannot call Invoke or InvokeAsync on a control until the window handle is created");
806 result = new AsyncMethodResult ();
807 data = new AsyncMethodData ();
809 data.Method = method;
811 data.Result = result;
814 if (!ExecutionContext.IsFlowSuppressed ()) {
815 data.Context = ExecutionContext.Capture ();
818 #if !MWF_ON_MSRUNTIME
819 if (SecurityManager.SecurityEnabled) {
820 data.Stack = CompressedStack.GetCompressedStack ();
825 XplatUI.SendAsyncMethod (data);
830 internal void PointToClient (ref int x, ref int y)
832 XplatUI.ScreenToClient (Handle, ref x, ref y);
835 internal void PointToScreen (ref int x, ref int y)
837 XplatUI.ClientToScreen (Handle, ref x, ref y);
840 internal Graphics DeviceContext {
843 CreateBuffers(this.Width, this.Height);
849 private Bitmap ImageBuffer {
852 CreateBuffers(this.Width, this.Height);
858 internal void CreateBuffers (int width, int height) {
859 if (dc_mem != null) {
873 bmp_mem = new Bitmap (width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
874 dc_mem = Graphics.FromImage (bmp_mem);
878 internal void InvalidateBuffers ()
880 if (dc_mem != null) {
891 internal static void SetChildColor(Control parent) {
894 for (int i=0; i < parent.child_controls.Count; i++) {
895 child=parent.child_controls[i];
896 if (child.child_controls.Count>0) {
897 SetChildColor(child);
903 internal bool Select(Control control) {
905 IContainerControl container;
907 if (control == null) {
911 parent = control.parent;
913 if (((control.control_style & ControlStyles.Selectable) !=0) && (parent != null)) {
914 while (parent != null) {
915 if (!parent.Visible || !parent.is_enabled) {
918 parent = parent.parent;
922 control.is_selected = true;
924 container = GetContainerControl();
925 if (container != null) {
926 container.ActiveControl = control;
928 if (control.IsHandleCreated) {
929 XplatUI.SetFocus(control.window.Handle);
934 internal virtual void DoDefaultAction() {
935 // Only here to be overriden by our actual controls; this is needed by the accessibility class
938 internal static int LowOrder (int param) {
939 return ((int)(short)(param & 0xffff));
942 internal static int HighOrder (int param) {
943 return ((int)(short)(param >> 16));
946 // This method exists so controls overriding OnPaintBackground can have default background painting done
947 internal virtual void PaintControlBackground (PaintEventArgs pevent)
949 if (background_image == null) {
950 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));
954 DrawBackgroundImage (pevent.Graphics);
957 void DrawBackgroundImage (Graphics g)
959 using (TextureBrush b = new TextureBrush (background_image, WrapMode.Tile)) {
960 g.FillRectangle (b, ClientRectangle);
964 internal virtual void DndEnter (DragEventArgs e)
971 internal virtual void DndOver (DragEventArgs e)
978 internal virtual void DndDrop (DragEventArgs e)
982 } catch (Exception exc) {
983 Console.Error.WriteLine ("MWF: Exception while dropping:");
984 Console.Error.WriteLine (exc);
988 internal virtual void DndLeave (EventArgs e)
995 internal virtual void DndFeedback(GiveFeedbackEventArgs e)
1002 internal virtual void DndContinueDrag(QueryContinueDragEventArgs e)
1005 OnQueryContinueDrag(e);
1009 internal static MouseButtons FromParamToMouseButtons (int param) {
1010 MouseButtons buttons = MouseButtons.None;
1012 if ((param & (int) MsgButtons.MK_LBUTTON) != 0)
1013 buttons |= MouseButtons.Left;
1015 if ((param & (int) MsgButtons.MK_MBUTTON) != 0)
1016 buttons |= MouseButtons.Middle;
1018 if ((param & (int) MsgButtons.MK_RBUTTON) != 0)
1019 buttons |= MouseButtons.Right;
1025 internal virtual bool ProcessControlMnemonic(char charCode) {
1026 return ProcessMnemonic(charCode);
1029 private static Control FindFlatForward(Control container, Control start) {
1035 end = container.child_controls.Count;
1037 if (start != null) {
1038 index = start.tab_index;
1043 for (int i = 0; i < end; i++) {
1044 if (found == null) {
1045 if (container.child_controls[i].tab_index > index) {
1046 found = container.child_controls[i];
1048 } else if (found.tab_index > container.child_controls[i].tab_index) {
1049 if (container.child_controls[i].tab_index > index) {
1050 found = container.child_controls[i];
1057 private static Control FindControlForward(Control container, Control start) {
1063 if (start != null) {
1064 if ((start is IContainerControl) || start.GetStyle(ControlStyles.ContainerControl)) {
1065 found = FindControlForward(start, null);
1066 if (found != null) {
1072 while (p != container) {
1073 found = FindFlatForward(p, start);
1074 if (found != null) {
1081 return FindFlatForward(container, start);
1084 private static Control FindFlatBackward(Control container, Control start) {
1090 end = container.child_controls.Count;
1092 if (start != null) {
1093 index = start.tab_index;
1095 // FIXME: Possible speed-up: Keep the highest taborder index in the container
1097 for (int i = 0; i < end; i++) {
1098 if (container.child_controls[i].tab_index > index) {
1099 index = container.child_controls[i].tab_index;
1105 for (int i = 0; i < end; i++) {
1106 if (found == null) {
1107 if (container.child_controls[i].tab_index < index) {
1108 found = container.child_controls[i];
1110 } else if (found.tab_index < container.child_controls[i].tab_index) {
1111 if (container.child_controls[i].tab_index < index) {
1112 found = container.child_controls[i];
1119 private static Control FindControlBackward(Control container, Control start) {
1124 if (start != null) {
1125 found = FindFlatBackward(start.parent, start);
1126 if (found == null && start.parent != container) {
1127 return start.parent;
1130 if (found == null) {
1131 found = FindFlatBackward(container, start);
1134 while ((found != null) && ((found is IContainerControl) || found.GetStyle(ControlStyles.ContainerControl))) {
1135 found = FindControlBackward(found, null);
1136 if (found != null) {
1144 private void HandleClick(int clicks) {
1145 if (GetStyle(ControlStyles.StandardClick)) {
1147 if (GetStyle(ControlStyles.StandardDoubleClick)) {
1148 OnDoubleClick(EventArgs.Empty);
1150 OnClick(EventArgs.Empty);
1153 OnClick(EventArgs.Empty);
1158 private void CheckDataBindings ()
1160 if (data_bindings == null)
1163 BindingContext binding_context = BindingContext;
1164 foreach (Binding binding in data_bindings) {
1165 binding.Check (binding_context);
1170 private void ChangeParent(Control new_parent) {
1174 Color pre_fore_color;
1175 Color pre_back_color;
1176 RightToLeft pre_rtl;
1178 // These properties are inherited from our parent
1179 // Get them pre parent-change and then send events
1180 // if they are changed after we have our new parent
1181 pre_enabled = Enabled;
1182 pre_visible = Visible;
1184 pre_fore_color = ForeColor;
1185 pre_back_color = BackColor;
1186 pre_rtl = RightToLeft;
1187 // MS doesn't seem to send a CursorChangedEvent
1189 parent = new_parent;
1191 if (IsHandleCreated && (new_parent != null) && new_parent.IsHandleCreated) {
1192 XplatUI.SetParent(Handle, new_parent.Handle);
1195 OnParentChanged(EventArgs.Empty);
1197 if (pre_enabled != Enabled) {
1198 OnEnabledChanged(EventArgs.Empty);
1201 if (pre_visible != Visible) {
1202 OnVisibleChanged(EventArgs.Empty);
1205 if (pre_font != Font) {
1206 OnFontChanged(EventArgs.Empty);
1209 if (pre_fore_color != ForeColor) {
1210 OnForeColorChanged(EventArgs.Empty);
1213 if (pre_back_color != BackColor) {
1214 OnBackColorChanged(EventArgs.Empty);
1217 if (pre_rtl != RightToLeft) {
1218 // MS sneaks a OnCreateControl and OnHandleCreated in here, I guess
1219 // because when RTL changes they have to recreate the win32 control
1220 // We don't really need that (until someone runs into compatibility issues)
1221 OnRightToLeftChanged(EventArgs.Empty);
1224 if ((new_parent != null) && new_parent.Created && !Created) {
1228 if ((binding_context == null) && Created) {
1229 OnBindingContextChanged(EventArgs.Empty);
1233 private void UpdateDistances() {
1234 if ((parent != null) && (parent.layout_suspended == 0)) {
1235 dist_left = bounds.X;
1236 dist_top = bounds.Y;
1237 dist_right = parent.ClientSize.Width - bounds.X - bounds.Width;
1238 dist_bottom = parent.ClientSize.Height - bounds.Y - bounds.Height;
1241 #endregion // Private & Internal Methods
1243 #region Public Static Properties
1244 public static Color DefaultBackColor {
1246 return ThemeEngine.Current.DefaultControlBackColor;
1250 public static Font DefaultFont {
1252 return ThemeEngine.Current.DefaultFont;
1256 public static Color DefaultForeColor {
1258 return ThemeEngine.Current.DefaultControlForeColor;
1262 public static Keys ModifierKeys {
1264 return XplatUI.State.ModifierKeys;
1268 public static MouseButtons MouseButtons {
1270 return XplatUI.State.MouseButtons;
1274 public static Point MousePosition {
1276 return Cursor.Position;
1282 public static bool CheckForIllegalCrossThreadCalls
1291 #endregion // Public Static Properties
1293 #region Public Instance Properties
1294 [EditorBrowsable(EditorBrowsableState.Advanced)]
1296 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1297 public AccessibleObject AccessibilityObject {
1299 if (accessibility_object==null) {
1300 accessibility_object=CreateAccessibilityInstance();
1302 return accessibility_object;
1306 [EditorBrowsable(EditorBrowsableState.Advanced)]
1308 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1309 public string AccessibleDefaultActionDescription {
1311 return AccessibilityObject.default_action;
1315 AccessibilityObject.default_action=value;
1320 [DefaultValue(null)]
1321 public string AccessibleDescription {
1323 return AccessibilityObject.description;
1327 AccessibilityObject.description=value;
1332 [DefaultValue(null)]
1333 public string AccessibleName {
1335 return AccessibilityObject.Name;
1339 AccessibilityObject.Name=value;
1343 [DefaultValue(AccessibleRole.Default)]
1344 [MWFDescription("Role of the control"), MWFCategory("Accessibility")]
1345 public AccessibleRole AccessibleRole {
1347 return AccessibilityObject.role;
1351 AccessibilityObject.role=value;
1355 [DefaultValue(false)]
1356 public virtual bool AllowDrop {
1362 if (allow_drop == value)
1366 XplatUI.SetAllowDrop (Handle, value);
1371 [RefreshProperties(RefreshProperties.Repaint)]
1372 [DefaultValue(AnchorStyles.Top | AnchorStyles.Left)]
1373 public virtual AnchorStyles Anchor {
1375 return anchor_style;
1381 if (parent != null) {
1382 parent.PerformLayout(this, "Parent");
1388 public virtual Color BackColor {
1390 if (background_color.IsEmpty) {
1392 return parent.BackColor;
1394 return DefaultBackColor;
1396 return background_color;
1400 background_color=value;
1401 SetChildColor(this);
1402 OnBackColorChanged(EventArgs.Empty);
1408 [DefaultValue(null)]
1409 public virtual Image BackgroundImage {
1411 return background_image;
1415 if (background_image!=value) {
1416 background_image=value;
1417 OnBackgroundImageChanged(EventArgs.Empty);
1422 [EditorBrowsable(EditorBrowsableState.Advanced)]
1424 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1425 public virtual BindingContext BindingContext {
1427 if (binding_context != null)
1428 return binding_context;
1431 binding_context = Parent.BindingContext;
1432 return binding_context;
1435 if (binding_context != value) {
1436 binding_context = value;
1437 OnBindingContextChanged(EventArgs.Empty);
1442 [EditorBrowsable(EditorBrowsableState.Advanced)]
1444 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1447 return bounds.Y+bounds.Height;
1451 [EditorBrowsable(EditorBrowsableState.Advanced)]
1453 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1454 public Rectangle Bounds {
1460 SetBoundsCore(value.Left, value.Top, value.Width, value.Height, BoundsSpecified.All);
1464 [EditorBrowsable(EditorBrowsableState.Advanced)]
1466 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1467 public bool CanFocus {
1469 if (Visible && is_enabled && GetStyle(ControlStyles.Selectable)) {
1476 [EditorBrowsable(EditorBrowsableState.Advanced)]
1478 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1479 public bool CanSelect {
1483 if (!GetStyle(ControlStyles.Selectable)) {
1488 while (parent != null) {
1489 if (!parent.is_visible || !parent.is_enabled) {
1493 parent = parent.parent;
1499 [EditorBrowsable(EditorBrowsableState.Advanced)]
1501 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1502 public bool Capture {
1504 return this.is_captured;
1508 if (this.IsHandleCreated) {
1509 if (value && !is_captured) {
1511 XplatUI.GrabWindow(this.window.Handle, IntPtr.Zero);
1512 } else if (!value && is_captured) {
1513 XplatUI.UngrabWindow(this.window.Handle);
1514 is_captured = false;
1520 [DefaultValue(true)]
1521 public bool CausesValidation {
1523 return this.causes_validation;
1527 if (this.causes_validation != value) {
1528 causes_validation = value;
1529 OnCausesValidationChanged(EventArgs.Empty);
1534 [EditorBrowsable(EditorBrowsableState.Advanced)]
1536 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1537 public Rectangle ClientRectangle {
1539 client_rect.Width = client_size.Width;
1540 client_rect.Height = client_size.Height;
1545 [EditorBrowsable(EditorBrowsableState.Advanced)]
1547 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1548 public Size ClientSize {
1551 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1552 return ((Form)this).form_parent_window.ClientSize;
1560 this.SetClientSizeCore(value.Width, value.Height);
1564 [EditorBrowsable(EditorBrowsableState.Advanced)]
1566 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1567 [DescriptionAttribute("ControlCompanyNameDescr")]
1568 public String CompanyName {
1570 return "Mono Project, Novell, Inc.";
1574 [EditorBrowsable(EditorBrowsableState.Advanced)]
1576 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1577 public bool ContainsFocus {
1583 for (int i=0; i < child_controls.Count; i++) {
1584 if (child_controls[i].ContainsFocus) {
1592 [DefaultValue(null)]
1593 public virtual ContextMenu ContextMenu {
1595 return context_menu;
1599 if (context_menu != value) {
1600 context_menu = value;
1601 OnContextMenuChanged(EventArgs.Empty);
1607 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
1608 public ControlCollection Controls {
1610 return this.child_controls;
1614 [EditorBrowsable(EditorBrowsableState.Advanced)]
1616 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1617 public bool Created {
1619 return (!is_disposed && is_created);
1623 [AmbientValue(null)]
1624 public virtual Cursor Cursor {
1626 if (cursor != null) {
1630 if (parent != null) {
1631 return parent.Cursor;
1634 return Cursors.Default;
1638 if (cursor != value) {
1643 if (IsHandleCreated) {
1644 pt = Cursor.Position;
1646 if (bounds.Contains(pt)) {
1647 if (GetChildAtPoint(pt) == null) {
1648 if (cursor != null) {
1649 XplatUI.SetCursor(window.Handle, cursor.handle);
1651 if (parent != null) {
1652 XplatUI.SetCursor(window.Handle, parent.Cursor.handle);
1654 XplatUI.SetCursor(window.Handle, Cursors.def.handle);
1661 OnCursorChanged(EventArgs.Empty);
1667 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
1668 [ParenthesizePropertyName(true)]
1669 [RefreshProperties(RefreshProperties.All)]
1670 public ControlBindingsCollection DataBindings {
1672 if (data_bindings == null)
1673 data_bindings = new ControlBindingsCollection (this);
1674 return data_bindings;
1678 [EditorBrowsable(EditorBrowsableState.Advanced)]
1680 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1681 public virtual Rectangle DisplayRectangle {
1683 return ClientRectangle;
1687 [EditorBrowsable(EditorBrowsableState.Advanced)]
1689 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1690 public bool Disposing {
1697 [RefreshProperties(RefreshProperties.Repaint)]
1698 [DefaultValue(DockStyle.None)]
1699 public virtual DockStyle Dock {
1705 if (dock_style == value) {
1711 if (parent != null) {
1712 parent.PerformLayout(this, "Parent");
1715 OnDockChanged(EventArgs.Empty);
1721 public bool Enabled {
1727 if (parent != null) {
1728 return parent.Enabled;
1735 if (is_enabled == value) {
1739 if (IsHandleCreated) {
1741 if (((Form)this).context == null) {
1742 XplatUI.EnableWindow(window.Handle, value);
1745 XplatUI.EnableWindow(window.Handle, value);
1750 OnEnabledChanged (EventArgs.Empty);
1754 [EditorBrowsable(EditorBrowsableState.Advanced)]
1756 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1757 public virtual bool Focused {
1759 return this.has_focus;
1764 [AmbientValue(null)]
1766 public virtual Font Font {
1772 if (Parent != null && Parent.Font != null) {
1780 if (font != null && font.Equals (value)) {
1786 OnFontChanged (EventArgs.Empty);
1791 public virtual Color ForeColor {
1793 if (foreground_color.IsEmpty) {
1795 return parent.ForeColor;
1797 return DefaultForeColor;
1799 return foreground_color;
1803 if (foreground_color != value) {
1804 foreground_color=value;
1806 OnForeColorChanged(EventArgs.Empty);
1813 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1814 public IntPtr Handle { // IWin32Window
1816 if (!IsHandleCreated) {
1819 return window.Handle;
1823 [EditorBrowsable(EditorBrowsableState.Advanced)]
1825 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1826 public bool HasChildren {
1828 if (this.child_controls.Count>0) {
1835 [EditorBrowsable(EditorBrowsableState.Always)]
1837 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1840 return this.bounds.Height;
1844 SetBoundsCore(bounds.X, bounds.Y, bounds.Width, value, BoundsSpecified.Height);
1848 [AmbientValue(ImeMode.Inherit)]
1850 public ImeMode ImeMode {
1852 if (ime_mode == DefaultImeMode) {
1854 return parent.ImeMode;
1856 return ImeMode.NoControl; // default value
1862 if (ime_mode != value) {
1865 OnImeModeChanged(EventArgs.Empty);
1870 [EditorBrowsable(EditorBrowsableState.Advanced)]
1872 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1873 public bool InvokeRequired { // ISynchronizeInvoke
1875 if (creator_thread != null && creator_thread!=Thread.CurrentThread) {
1882 [EditorBrowsable(EditorBrowsableState.Advanced)]
1884 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1885 public bool IsAccessible {
1887 return is_accessible;
1891 is_accessible = value;
1895 [EditorBrowsable(EditorBrowsableState.Advanced)]
1897 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1898 public bool IsDisposed {
1900 return this.is_disposed;
1904 [EditorBrowsable(EditorBrowsableState.Advanced)]
1906 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1907 public bool IsHandleCreated {
1909 if ((window != null) && (window.Handle != IntPtr.Zero)) {
1917 [EditorBrowsable(EditorBrowsableState.Always)]
1919 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1922 return this.bounds.X;
1926 SetBoundsCore(value, bounds.Y, bounds.Width, bounds.Height, BoundsSpecified.X);
1931 public Point Location {
1933 return new Point(bounds.X, bounds.Y);
1937 SetBoundsCore(value.X, value.Y, bounds.Width, bounds.Height, BoundsSpecified.Location);
1942 public string Name {
1953 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1954 public Control Parent {
1960 if (value == this) {
1961 throw new ArgumentException("A circular control reference has been made. A control cannot be owned or parented to itself.");
1964 if (parent!=value) {
1966 parent.Controls.Remove(this);
1970 value.Controls.Add(this);
1975 [EditorBrowsable(EditorBrowsableState.Advanced)]
1977 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1978 public string ProductName {
1980 Type t = typeof (AssemblyProductAttribute);
1981 Assembly assembly = GetType().Module.Assembly;
1982 object [] attrs = assembly.GetCustomAttributes (t, false);
1983 AssemblyProductAttribute a = null;
1984 // On MS we get a NullRefException if product attribute is not
1986 if (attrs != null && attrs.Length > 0)
1987 a = (AssemblyProductAttribute) attrs [0];
1992 [EditorBrowsable(EditorBrowsableState.Advanced)]
1994 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1995 public string ProductVersion {
1997 Type t = typeof (AssemblyVersionAttribute);
1998 Assembly assembly = GetType().Module.Assembly;
1999 object [] attrs = assembly.GetCustomAttributes (t, false);
2000 if (attrs == null || attrs.Length < 1)
2002 return ((AssemblyVersionAttribute)attrs [0]).Version;
2006 [EditorBrowsable(EditorBrowsableState.Advanced)]
2008 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2009 public bool RecreatingHandle {
2011 return is_recreating;
2015 [EditorBrowsable(EditorBrowsableState.Advanced)]
2017 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2018 public Region Region {
2020 return new Region(this.bounds);
2027 g = this.CreateGraphics();
2028 r = value.GetBounds(g);
2030 SetBounds((int)r.X, (int)r.Y, (int)r.Width, (int)r.Height);
2036 [EditorBrowsable(EditorBrowsableState.Advanced)]
2038 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2041 return this.bounds.X+this.bounds.Width;
2045 [AmbientValue(RightToLeft.Inherit)]
2047 public virtual RightToLeft RightToLeft {
2049 if (right_to_left == RightToLeft.Inherit) {
2051 return parent.RightToLeft;
2053 return RightToLeft.No; // default value
2055 return right_to_left;
2059 if (value != right_to_left) {
2060 right_to_left = value;
2061 OnRightToLeftChanged(EventArgs.Empty);
2066 [EditorBrowsable(EditorBrowsableState.Advanced)]
2067 public override ISite Site {
2075 AmbientProperties ap = (AmbientProperties) value.GetService (typeof (AmbientProperties));
2077 BackColor = ap.BackColor;
2078 ForeColor = ap.ForeColor;
2088 return new Size(Width, Height);
2092 SetBoundsCore(bounds.X, bounds.Y, value.Width, value.Height, BoundsSpecified.Size);
2097 [MergableProperty(false)]
2098 public int TabIndex {
2100 if (tab_index != -1) {
2107 if (tab_index != value) {
2109 OnTabIndexChanged(EventArgs.Empty);
2115 [DefaultValue(true)]
2116 public bool TabStop {
2122 if (tab_stop != value) {
2124 OnTabStopChanged(EventArgs.Empty);
2129 [Localizable(false)]
2131 [TypeConverter(typeof(StringConverter))]
2132 [DefaultValue(null)]
2139 control_tag = value;
2145 [BindableAttribute(true)]
2146 public virtual string Text {
2148 // Our implementation ignores ControlStyles.CacheText - we always cache
2153 if (value == null) {
2154 value = String.Empty;
2159 if (IsHandleCreated) {
2160 XplatUI.Text(Handle, text);
2162 OnTextChanged (EventArgs.Empty);
2167 [EditorBrowsable(EditorBrowsableState.Always)]
2169 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2172 return this.bounds.Y;
2176 SetBoundsCore(bounds.X, value, bounds.Width, bounds.Height, BoundsSpecified.Y);
2180 [EditorBrowsable(EditorBrowsableState.Advanced)]
2182 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2183 public Control TopLevelControl {
2187 while (p.parent != null) {
2196 public bool Visible {
2200 } else if (parent != null) {
2201 return parent.Visible;
2208 SetVisibleCore(value);
2212 [EditorBrowsable(EditorBrowsableState.Always)]
2214 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2217 return this.bounds.Width;
2221 SetBoundsCore(bounds.X, bounds.Y, value, bounds.Height, BoundsSpecified.Width);
2225 [EditorBrowsable(EditorBrowsableState.Never)]
2227 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2228 public IWindowTarget WindowTarget {
2237 #endregion // Public Instance Properties
2239 #region Protected Instance Properties
2240 protected virtual CreateParams CreateParams {
2242 CreateParams create_params = new CreateParams();
2245 create_params.Caption = Text;
2248 create_params.Caption = text;
2252 create_params.X = Left;
2255 create_params.X = this.bounds.X;
2259 create_params.Y = Top;
2262 create_params.Y = this.bounds.Y;
2266 create_params.Width = Width;
2269 create_params.Width = this.bounds.Width;
2273 create_params.Height = Height;
2276 create_params.Height = this.bounds.Height;
2280 create_params.ClassName = XplatUI.DefaultClassName;
2281 create_params.ClassStyle = 0;
2282 create_params.ExStyle = 0;
2283 create_params.Param = 0;
2286 create_params.ExStyle |= (int)WindowStyles.WS_EX_ACCEPTFILES;
2290 create_params.Parent = parent.Handle;
2293 create_params.Style = (int)WindowStyles.WS_CHILD | (int)WindowStyles.WS_CLIPCHILDREN | (int)WindowStyles.WS_CLIPSIBLINGS;
2296 create_params.Style |= (int)WindowStyles.WS_VISIBLE;
2300 create_params.Style |= (int)WindowStyles.WS_DISABLED;
2303 switch (border_style) {
2304 case BorderStyle.FixedSingle:
2305 create_params.Style |= (int) WindowStyles.WS_BORDER;
2307 case BorderStyle.Fixed3D:
2308 create_params.ExStyle |= (int) WindowStyles.WS_EX_CLIENTEDGE;
2312 return create_params;
2316 protected virtual ImeMode DefaultImeMode {
2318 return ImeMode.Inherit;
2322 protected virtual Size DefaultSize {
2324 return new Size(100, 23);
2328 protected int FontHeight {
2338 protected bool RenderRightToLeft {
2340 return (this.right_to_left == RightToLeft.Yes);
2344 protected bool ResizeRedraw {
2346 return GetStyle(ControlStyles.ResizeRedraw);
2350 SetStyle(ControlStyles.ResizeRedraw, value);
2354 [EditorBrowsable(EditorBrowsableState.Advanced)]
2356 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2357 protected virtual bool ShowFocusCues {
2363 [EditorBrowsable(EditorBrowsableState.Advanced)]
2365 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2366 protected bool ShowKeyboardCues {
2371 #endregion // Protected Instance Properties
2373 #region Public Static Methods
2374 [EditorBrowsable(EditorBrowsableState.Advanced)]
2375 public static Control FromChildHandle(IntPtr handle) {
2376 IEnumerator control = Control.controls.GetEnumerator();
2378 while (control.MoveNext()) {
2379 if (((Control)control.Current).window.Handle == handle) {
2381 if (((Control)control.Current).Parent != null) {
2382 return ((Control)control.Current).Parent;
2389 [EditorBrowsable(EditorBrowsableState.Advanced)]
2390 public static Control FromHandle(IntPtr handle) {
2392 IEnumerator control = Control.controls.GetEnumerator();
2394 while (control.MoveNext()) {
2395 if (((Control)control.Current).window.Handle == handle) {
2397 return ((Control)control.Current);
2403 return Control.ControlNativeWindow.ControlFromHandle(handle);
2407 public static bool IsMnemonic(char charCode, string text) {
2410 amp = text.IndexOf('&');
2413 if (amp + 1 < text.Length) {
2414 if (text[amp + 1] != '&') {
2415 if (Char.ToUpper(charCode) == Char.ToUpper(text.ToCharArray(amp + 1, 1)[0])) {
2425 #region Protected Static Methods
2426 [EditorBrowsable(EditorBrowsableState.Advanced)]
2427 protected static bool ReflectMessage(IntPtr hWnd, ref Message m) {
2430 c = Control.FromHandle(hWnd);
2440 #region Public Instance Methods
2441 [EditorBrowsable(EditorBrowsableState.Advanced)]
2442 public IAsyncResult BeginInvoke(Delegate method) {
2443 object [] prms = null;
2444 if (method is EventHandler)
2445 prms = new object [] { this, EventArgs.Empty };
2446 return BeginInvokeInternal(method, prms, false);
2449 [EditorBrowsable(EditorBrowsableState.Advanced)]
2450 public IAsyncResult BeginInvoke (Delegate method, object[] args) {
2451 return BeginInvokeInternal (method, args, false);
2454 public void BringToFront() {
2455 if ((parent != null) && (parent.child_controls[0]!=this)) {
2456 if (parent.child_controls.Contains(this)) {
2457 parent.child_controls.SetChildIndex(this, 0);
2461 XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, true, false);
2463 if (parent != null) {
2468 public bool Contains(Control ctl) {
2469 while (ctl != null) {
2478 public void CreateControl() {
2483 if (!IsHandleCreated) {
2491 Control [] controls = child_controls.GetAllControls ();
2492 for (int i=0; i<controls.Length; i++) {
2493 controls [i].CreateControl ();
2498 if (binding_context == null) { // seem to be sent whenever it's null?
2499 OnBindingContextChanged(EventArgs.Empty);
2505 public Graphics CreateGraphics() {
2506 if (!IsHandleCreated) {
2507 this.CreateHandle();
2509 return Graphics.FromHwnd(this.window.Handle);
2512 public DragDropEffects DoDragDrop(object data, DragDropEffects allowedEffects) {
2513 return XplatUI.StartDrag(this.window.Handle, data, allowedEffects);
2516 [EditorBrowsable(EditorBrowsableState.Advanced)]
2517 public object EndInvoke (IAsyncResult async_result) {
2518 AsyncMethodResult result = (AsyncMethodResult) async_result;
2519 return result.EndInvoke ();
2522 public Form FindForm() {
2535 public bool Focus() {
2536 if (IsHandleCreated && !has_focus) {
2538 XplatUI.SetFocus(window.Handle);
2543 public Control GetChildAtPoint(Point pt) {
2544 // Microsoft's version of this function doesn't seem to work, so I can't check
2545 // if we only consider children or also grandchildren, etc.
2546 // I'm gonna say 'children only'
2547 for (int i=0; i<child_controls.Count; i++) {
2548 if (child_controls[i].Bounds.Contains(pt)) {
2549 return child_controls[i];
2555 public IContainerControl GetContainerControl() {
2556 Control current = this;
2558 while (current!=null) {
2559 if ((current is IContainerControl) && ((current.control_style & ControlStyles.ContainerControl)!=0)) {
2560 return (IContainerControl)current;
2562 current = current.parent;
2567 public Control GetNextControl(Control ctl, bool forward) {
2568 // If we're not a container we don't play
2569 if (!(this is IContainerControl) && !this.GetStyle(ControlStyles.ContainerControl)) {
2573 // If ctl is not contained by this, we start at the first child of this
2574 if (!this.Contains(ctl)) {
2578 // Search through our controls, starting at ctl, stepping into children as we encounter them
2579 // try to find the control with the tabindex closest to our own, or, if we're looking into
2580 // child controls, the one with the smallest tabindex
2582 return FindControlForward(this, ctl);
2584 return FindControlBackward(this, ctl);
2587 public void Hide() {
2588 this.Visible = false;
2591 public void Invalidate() {
2592 Invalidate(ClientRectangle, false);
2595 public void Invalidate(bool invalidateChildren) {
2596 Invalidate(ClientRectangle, invalidateChildren);
2599 public void Invalidate(System.Drawing.Rectangle rc) {
2600 Invalidate(rc, false);
2603 public void Invalidate(System.Drawing.Rectangle rc, bool invalidateChildren) {
2604 if (!IsHandleCreated || !Visible || rc.Width == 0 || rc.Height == 0) {
2608 NotifyInvalidate(rc);
2610 XplatUI.Invalidate(Handle, rc, false);
2612 if (invalidateChildren) {
2613 Control [] controls = child_controls.GetAllControls ();
2614 for (int i=0; i<controls.Length; i++)
2615 controls [i].Invalidate ();
2617 OnInvalidated(new InvalidateEventArgs(rc));
2620 public void Invalidate(System.Drawing.Region region) {
2621 Invalidate(region, false);
2624 public void Invalidate(System.Drawing.Region region, bool invalidateChildren) {
2625 RectangleF bounds = region.GetBounds (CreateGraphics ());
2626 Invalidate (new Rectangle ((int) bounds.X, (int) bounds.Y, (int) bounds.Width, (int) bounds.Height),
2627 invalidateChildren);
2630 public object Invoke (Delegate method) {
2631 object [] prms = null;
2632 if (method is EventHandler)
2633 prms = new object [] { this, EventArgs.Empty };
2635 return Invoke(method, prms);
2638 public object Invoke (Delegate method, object[] args) {
2639 if (!this.InvokeRequired) {
2640 return method.DynamicInvoke(args);
2643 IAsyncResult result = BeginInvoke (method, args);
2644 return EndInvoke(result);
2647 internal object InvokeInternal (Delegate method, bool disposing) {
2648 return InvokeInternal(method, null, disposing);
2651 internal object InvokeInternal (Delegate method, object[] args, bool disposing) {
2652 if (!this.InvokeRequired) {
2653 return method.DynamicInvoke(args);
2656 IAsyncResult result = BeginInvokeInternal (method, args, disposing);
2657 return EndInvoke(result);
2660 [EditorBrowsable(EditorBrowsableState.Advanced)]
2661 public void PerformLayout() {
2662 PerformLayout(null, null);
2665 [EditorBrowsable(EditorBrowsableState.Advanced)]
2666 public void PerformLayout(Control affectedControl, string affectedProperty) {
2667 LayoutEventArgs levent = new LayoutEventArgs(affectedControl, affectedProperty);
2669 if (layout_suspended > 0) {
2670 layout_pending = true;
2674 layout_pending = false;
2676 // Prevent us from getting messed up
2679 // Perform all Dock and Anchor calculations
2682 AnchorStyles anchor;
2685 space=this.DisplayRectangle;
2687 // Deal with docking; go through in reverse, MS docs say that lowest Z-order is closest to edge
2688 Control [] controls = child_controls.GetAllControls ();
2689 for (int i = controls.Length - 1; i >= 0; i--) {
2690 child = controls [i];
2691 switch (child.Dock) {
2692 case DockStyle.None: {
2697 case DockStyle.Left: {
2698 child.SetBounds(space.Left, space.Y, child.Width, space.Height);
2699 space.X+=child.Width;
2700 space.Width-=child.Width;
2704 case DockStyle.Top: {
2705 child.SetBounds(space.Left, space.Y, space.Width, child.Height);
2706 space.Y+=child.Height;
2707 space.Height-=child.Height;
2711 case DockStyle.Right: {
2712 child.SetBounds(space.Right-child.Width, space.Y, child.Width, space.Height);
2713 space.Width-=child.Width;
2717 case DockStyle.Bottom: {
2718 child.SetBounds(space.Left, space.Bottom-child.Height, space.Width, child.Height);
2719 space.Height-=child.Height;
2725 for (int i = controls.Length - 1; i >= 0; i--) {
2728 if (child.Dock == DockStyle.Fill) {
2729 child.SetBounds(space.Left, space.Top, space.Width, space.Height);
2735 space=this.DisplayRectangle;
2737 for (int i=0; i < controls.Length; i++) {
2743 child = controls[i];
2744 anchor = child.Anchor;
2748 width = child.Width;
2749 height = child.Height;
2751 // If the control is docked we don't need to do anything
2752 if (child.Dock != DockStyle.None) {
2756 if ((anchor & AnchorStyles.Left) !=0 ) {
2757 if ((anchor & AnchorStyles.Right) != 0) {
2758 width = client_size.Width - child.dist_right - left;
2760 ; // Left anchored only, nothing to be done
2762 } else if ((anchor & AnchorStyles.Right) != 0) {
2763 left = client_size.Width - child.dist_right - width;
2765 // left+=diff_width/2 will introduce rounding errors (diff_width removed from svn after r51780)
2766 // This calculates from scratch every time:
2767 left = child.dist_left + (client_size.Width - (child.dist_left + width + child.dist_right)) / 2;
2770 if ((anchor & AnchorStyles.Top) !=0 ) {
2771 if ((anchor & AnchorStyles.Bottom) != 0) {
2772 height = client_size.Height - child.dist_bottom - top;
2774 ; // Top anchored only, nothing to be done
2776 } else if ((anchor & AnchorStyles.Bottom) != 0) {
2777 top = client_size.Height - child.dist_bottom - height;
2779 // top += diff_height/2 will introduce rounding errors (diff_height removed from after r51780)
2780 // This calculates from scratch every time:
2781 top = child.dist_top + (client_size.Height - (child.dist_top + height + child.dist_bottom)) / 2;
2793 child.SetBounds(left, top, width, height);
2796 // Let everyone know
2800 // Need to make sure we decremend layout_suspended
2806 public Point PointToClient (Point p) {
2810 XplatUI.ScreenToClient (Handle, ref x, ref y);
2812 return new Point (x, y);
2815 public Point PointToScreen(Point p) {
2819 XplatUI.ClientToScreen(Handle, ref x, ref y);
2821 return new Point(x, y);
2824 public virtual bool PreProcessMessage(ref Message msg) {
2827 if ((msg.Msg == (int)Msg.WM_KEYDOWN) || (msg.Msg == (int)Msg.WM_SYSKEYDOWN)) {
2828 key_data = (Keys)msg.WParam.ToInt32() | XplatUI.State.ModifierKeys;
2830 if (!ProcessCmdKey(ref msg, key_data)) {
2831 if (IsInputKey(key_data)) {
2835 return ProcessDialogKey(key_data);
2839 } else if (msg.Msg == (int)Msg.WM_CHAR) {
2840 if (IsInputChar((char)msg.WParam)) {
2843 } else if (msg.Msg == (int)Msg.WM_SYSCHAR) {
2844 if (IsInputChar((char)msg.WParam)) {
2847 return ProcessDialogChar((char)msg.WParam);
2852 public Rectangle RectangleToClient(Rectangle r) {
2853 return new Rectangle(PointToClient(r.Location), r.Size);
2856 public Rectangle RectangleToScreen(Rectangle r) {
2857 return new Rectangle(PointToScreen(r.Location), r.Size);
2860 public virtual void Refresh() {
2861 if (IsHandleCreated == true) {
2864 XplatUI.UpdateWindow(window.Handle);
2866 Control [] controls = child_controls.GetAllControls ();
2867 for (int i=0; i < controls.Length; i++) {
2868 controls[i].Refresh();
2874 [EditorBrowsable(EditorBrowsableState.Never)]
2875 public virtual void ResetBackColor() {
2876 background_color = Color.Empty;
2879 [EditorBrowsable(EditorBrowsableState.Never)]
2881 public void ResetBindings() {
2885 [EditorBrowsable(EditorBrowsableState.Never)]
2886 public virtual void ResetCursor() {
2890 [EditorBrowsable(EditorBrowsableState.Never)]
2891 public virtual void ResetFont() {
2895 [EditorBrowsable(EditorBrowsableState.Never)]
2896 public virtual void ResetForeColor() {
2897 foreground_color = Color.Empty;
2900 [EditorBrowsable(EditorBrowsableState.Never)]
2901 public void ResetImeMode() {
2902 ime_mode = DefaultImeMode;
2905 [EditorBrowsable(EditorBrowsableState.Never)]
2906 public virtual void ResetRightToLeft() {
2907 right_to_left = RightToLeft.Inherit;
2910 public virtual void ResetText() {
2911 text = String.Empty;
2914 public void ResumeLayout() {
2915 ResumeLayout (true);
2918 public void ResumeLayout(bool performLayout) {
2919 if (layout_suspended > 0) {
2923 if (layout_suspended == 0) {
2924 Control [] controls = child_controls.GetAllControls ();
2925 for (int i=0; i<controls.Length; i++) {
2926 controls [i].UpdateDistances ();
2929 if (performLayout && layout_pending) {
2935 public void Scale(float ratio) {
2936 ScaleCore(ratio, ratio);
2939 public void Scale(float dx, float dy) {
2943 public void Select() {
2944 Select(false, false);
2947 public bool SelectNextControl(Control ctl, bool forward, bool tabStopOnly, bool nested, bool wrap) {
2952 c = GetNextControl(c, forward);
2961 if (c.CanSelect && ((c.parent == ctl.parent) || nested) && (c.tab_stop || !tabStopOnly)) {
2965 } while (c != ctl); // If we wrap back to ourselves we stop
2970 public void SendToBack() {
2971 if ((parent != null) && (parent.child_controls[parent.child_controls.Count-1]!=this)) {
2972 if (parent.child_controls.Contains(this)) {
2973 parent.child_controls.SetChildIndex(this, parent.child_controls.Count);
2977 XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, false, true);
2978 if (parent != null) {
2983 public void SetBounds(int x, int y, int width, int height) {
2984 SetBoundsCore(x, y, width, height, BoundsSpecified.All);
2987 public void SetBounds(int x, int y, int width, int height, BoundsSpecified specified) {
2988 SetBoundsCore(x, y, width, height, specified);
2991 public void Show() {
2993 this.CreateControl();
2999 public void SuspendLayout() {
3003 public void Update() {
3004 needs_redraw = true;
3005 if (IsHandleCreated) {
3006 XplatUI.UpdateWindow(window.Handle);
3009 #endregion // Public Instance Methods
3011 #region Protected Instance Methods
3012 [EditorBrowsable(EditorBrowsableState.Advanced)]
3013 [MonoTODO("Implement this and tie it into Control.ControlAccessibleObject.NotifyClients")]
3014 protected void AccessibilityNotifyClients(AccessibleEvents accEvent, int childID) {
3015 throw new NotImplementedException();
3018 [EditorBrowsable(EditorBrowsableState.Advanced)]
3019 protected virtual AccessibleObject CreateAccessibilityInstance() {
3020 return new Control.ControlAccessibleObject(this);
3023 [EditorBrowsable(EditorBrowsableState.Advanced)]
3024 protected virtual ControlCollection CreateControlsInstance() {
3025 return new ControlCollection(this);
3028 [EditorBrowsable(EditorBrowsableState.Advanced)]
3029 protected virtual void CreateHandle() {
3031 throw new ObjectDisposedException(Name);
3034 if (IsHandleCreated && !is_recreating) {
3038 window.CreateHandle(CreateParams);
3040 if (window.Handle != IntPtr.Zero) {
3041 if (!controls.Contains(window.Handle)) {
3045 creator_thread = Thread.CurrentThread;
3047 XplatUI.EnableWindow(window.Handle, is_enabled);
3049 // Set our handle with our parent
3050 if ((parent != null) && (parent.IsHandleCreated)) {
3051 XplatUI.SetParent(window.Handle, parent.Handle);
3054 // Set our handle as parent for our children
3055 Control [] children;
3057 children = child_controls.GetAllControls ();
3058 for (int i = 0; i < children.Length; i++ ) {
3059 if (children[i].IsHandleCreated) {
3060 XplatUI.SetParent(children[i].Handle, window.Handle);
3064 // Find out where the window manager placed us
3066 if ((CreateParams.Style & (int)WindowStyles.WS_CHILD) != 0) {
3067 XplatUI.SetBorderStyle(window.Handle, (FormBorderStyle)border_style);
3071 OnHandleCreated(EventArgs.Empty);
3076 [EditorBrowsable(EditorBrowsableState.Advanced)]
3077 protected virtual void DefWndProc(ref Message m) {
3078 window.DefWndProc(ref m);
3081 [EditorBrowsable(EditorBrowsableState.Advanced)]
3082 protected virtual void DestroyHandle() {
3083 if (IsHandleCreated) {
3084 if (window != null) {
3085 window.DestroyHandle();
3090 protected bool GetStyle(ControlStyles flag) {
3091 return (control_style & flag) != 0;
3094 protected bool GetTopLevel() {
3098 [EditorBrowsable(EditorBrowsableState.Advanced)]
3099 protected virtual void InitLayout() {
3103 [EditorBrowsable(EditorBrowsableState.Advanced)]
3104 protected void InvokeGotFocus(Control toInvoke, EventArgs e) {
3105 toInvoke.OnGotFocus(e);
3108 [EditorBrowsable(EditorBrowsableState.Advanced)]
3109 protected void InvokeLostFocus(Control toInvoke, EventArgs e) {
3110 toInvoke.OnLostFocus(e);
3113 [EditorBrowsable(EditorBrowsableState.Advanced)]
3114 protected void InvokeOnClick(Control toInvoke, EventArgs e) {
3115 toInvoke.OnClick(e);
3118 protected void InvokePaint(Control toInvoke, PaintEventArgs e) {
3119 toInvoke.OnPaint(e);
3122 protected void InvokePaintBackground(Control toInvoke, PaintEventArgs e) {
3123 toInvoke.OnPaintBackground(e);
3126 protected virtual bool IsInputChar (char charCode) {
3130 protected virtual bool IsInputKey (Keys keyData) {
3131 // Doc says this one calls IsInputChar; not sure what to do with that
3135 [EditorBrowsable(EditorBrowsableState.Advanced)]
3136 protected virtual void NotifyInvalidate(Rectangle invalidatedArea) {
3140 protected virtual bool ProcessCmdKey(ref Message msg, Keys keyData) {
3141 if ((context_menu != null) && context_menu.ProcessCmdKey(ref msg, keyData)) {
3145 if (parent != null) {
3146 return parent.ProcessCmdKey(ref msg, keyData);
3152 protected virtual bool ProcessDialogChar(char charCode) {
3153 if (parent != null) {
3154 return parent.ProcessDialogChar (charCode);
3160 protected virtual bool ProcessDialogKey (Keys keyData) {
3161 if (parent != null) {
3162 return parent.ProcessDialogKey (keyData);
3168 protected virtual bool ProcessKeyEventArgs (ref Message msg)
3170 KeyEventArgs key_event;
3173 case (int)Msg.WM_SYSKEYDOWN:
3174 case (int)Msg.WM_KEYDOWN: {
3175 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
3176 OnKeyDown (key_event);
3177 return key_event.Handled;
3180 case (int)Msg.WM_SYSKEYUP:
3181 case (int)Msg.WM_KEYUP: {
3182 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
3183 OnKeyUp (key_event);
3184 return key_event.Handled;
3187 case (int)Msg.WM_SYSCHAR:
3188 case (int)Msg.WM_CHAR: {
3189 KeyPressEventArgs key_press_event;
3191 key_press_event = new KeyPressEventArgs((char)msg.WParam);
3192 OnKeyPress(key_press_event);
3193 return key_press_event.Handled;
3204 protected internal virtual bool ProcessKeyMessage(ref Message msg) {
3205 if (parent != null) {
3206 if (parent.ProcessKeyPreview(ref msg)) {
3211 return ProcessKeyEventArgs(ref msg);
3214 protected virtual bool ProcessKeyPreview(ref Message msg) {
3215 if (parent != null) {
3216 return parent.ProcessKeyPreview(ref msg);
3222 protected virtual bool ProcessMnemonic(char charCode) {
3227 [EditorBrowsable(EditorBrowsableState.Advanced)]
3228 protected void RaiseDragEvent(object key, DragEventArgs e) {
3232 [EditorBrowsable(EditorBrowsableState.Advanced)]
3233 protected void RaiseKeyEvent(object key, KeyEventArgs e) {
3237 [EditorBrowsable(EditorBrowsableState.Advanced)]
3238 protected void RaiseMouseEvent(object key, MouseEventArgs e) {
3242 [EditorBrowsable(EditorBrowsableState.Advanced)]
3243 protected void RaisePaintEvent(object key, PaintEventArgs e) {
3247 [EditorBrowsable(EditorBrowsableState.Advanced)]
3248 protected void RecreateHandle() {
3249 IEnumerator child = child_controls.GetAllEnumerator();
3253 if (IsHandleCreated) {
3259 while (child.MoveNext()) {
3260 ((Control)child.Current).RecreateHandle();
3270 is_recreating = false;
3273 [EditorBrowsable(EditorBrowsableState.Advanced)]
3274 protected void ResetMouseEventArgs() {
3278 [EditorBrowsable(EditorBrowsableState.Advanced)]
3279 protected ContentAlignment RtlTranslateAlignment(ContentAlignment align) {
3280 if (right_to_left == RightToLeft.No) {
3285 case ContentAlignment.TopLeft: {
3286 return ContentAlignment.TopRight;
3289 case ContentAlignment.TopRight: {
3290 return ContentAlignment.TopLeft;
3293 case ContentAlignment.MiddleLeft: {
3294 return ContentAlignment.MiddleRight;
3297 case ContentAlignment.MiddleRight: {
3298 return ContentAlignment.MiddleLeft;
3301 case ContentAlignment.BottomLeft: {
3302 return ContentAlignment.BottomRight;
3305 case ContentAlignment.BottomRight: {
3306 return ContentAlignment.BottomLeft;
3310 // if it's center it doesn't change
3316 [EditorBrowsable(EditorBrowsableState.Advanced)]
3317 protected HorizontalAlignment RtlTranslateAlignment(HorizontalAlignment align) {
3318 if ((right_to_left == RightToLeft.No) || (align == HorizontalAlignment.Center)) {
3322 if (align == HorizontalAlignment.Left) {
3323 return HorizontalAlignment.Right;
3326 // align must be HorizontalAlignment.Right
3327 return HorizontalAlignment.Left;
3330 [EditorBrowsable(EditorBrowsableState.Advanced)]
3331 protected LeftRightAlignment RtlTranslateAlignment(LeftRightAlignment align) {
3332 if (right_to_left == RightToLeft.No) {
3336 if (align == LeftRightAlignment.Left) {
3337 return LeftRightAlignment.Right;
3340 // align must be LeftRightAlignment.Right;
3341 return LeftRightAlignment.Left;
3344 [EditorBrowsable(EditorBrowsableState.Advanced)]
3345 protected ContentAlignment RtlTranslateContent(ContentAlignment align) {
3346 return RtlTranslateAlignment(align);
3349 [EditorBrowsable(EditorBrowsableState.Advanced)]
3350 protected HorizontalAlignment RtlTranslateHorizontal(HorizontalAlignment align) {
3351 return RtlTranslateAlignment(align);
3354 [EditorBrowsable(EditorBrowsableState.Advanced)]
3355 protected LeftRightAlignment RtlTranslateLeftRight(LeftRightAlignment align) {
3356 return RtlTranslateAlignment(align);
3359 [EditorBrowsable(EditorBrowsableState.Advanced)]
3360 protected virtual void ScaleCore(float dx, float dy) {
3366 location = new Point((int)(Left * dx), (int)(Top * dy));
3367 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 Location = location;
3381 /* Now scale our children */
3382 Control [] controls = child_controls.GetAllControls ();
3383 for (int i=0; i < controls.Length; i++) {
3384 controls[i].Scale(dx, dy);
3390 protected virtual void Select(bool directed, bool forward) {
3395 // Select this control
3400 if (parent == null) {
3404 // FIXME - this thing is doing the wrong stuff, needs to be similar to SelectNextControl
3406 index = parent.child_controls.IndexOf(this);
3411 if ((index+1) < parent.child_controls.Count) {
3420 index = parent.child_controls.Count-1;
3423 result = Select(parent.child_controls[index]);
3424 } while (!result && parent.child_controls[index] != this);
3427 [EditorBrowsable(EditorBrowsableState.Advanced)]
3428 protected virtual void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
3429 // SetBoundsCore updates the Win32 control itself. UpdateBounds updates the controls variables and fires events, I'm guessing - pdb
3430 if ((specified & BoundsSpecified.X) != BoundsSpecified.X) {
3434 if ((specified & BoundsSpecified.Y) != BoundsSpecified.Y) {
3438 if ((specified & BoundsSpecified.Width) != BoundsSpecified.Width) {
3442 if ((specified & BoundsSpecified.Height) != BoundsSpecified.Height) {
3446 if (IsHandleCreated) {
3447 XplatUI.SetWindowPos(Handle, x, y, width, height);
3450 UpdateBounds(x, y, width, height);
3455 [EditorBrowsable(EditorBrowsableState.Advanced)]
3456 protected virtual void SetClientSizeCore(int x, int y) {
3457 // Calculate the actual window size from the client size (it usually stays the same or grows)
3458 Rectangle ClientRect;
3459 Rectangle WindowRect;
3462 ClientRect = new Rectangle(0, 0, x, y);
3463 cp = this.CreateParams;
3465 if (XplatUI.CalculateWindowRect(Handle, ref ClientRect, cp.Style, cp.ExStyle, null, out WindowRect)==false) {
3469 SetBoundsCore(bounds.X, bounds.Y, WindowRect.Width, WindowRect.Height, BoundsSpecified.Size);
3472 [EditorBrowsable(EditorBrowsableState.Advanced)]
3473 protected void SetStyle(ControlStyles flag, bool value) {
3475 control_style |= flag;
3477 control_style &= ~flag;
3479 OnStyleChanged(EventArgs.Empty);
3482 protected void SetTopLevel(bool value) {
3483 if ((GetTopLevel() != value) && (parent != null)) {
3484 throw new Exception();
3488 if (value == true) {
3498 is_toplevel = value;
3501 protected virtual void SetVisibleCore(bool value) {
3502 if (value!=is_visible) {
3505 if (IsHandleCreated) {
3506 XplatUI.SetVisible(Handle, value);
3507 // Explicitly move Toplevel windows to where we want them;
3508 // apparently moving unmapped toplevel windows doesn't work
3509 if (is_visible && (this is Form)) {
3510 XplatUI.SetWindowPos(window.Handle, bounds.X, bounds.Y, bounds.Width, bounds.Height);
3515 if (dc_mem != null) {
3520 if (bmp_mem != null) {
3525 this.CreateBuffers(bounds.Width, bounds.Height);
3529 OnVisibleChanged(EventArgs.Empty);
3531 if (value == false && parent != null) {
3534 // Need to start at parent, GetContainerControl might return ourselves if we're a container
3535 container = (Control)parent.GetContainerControl();
3536 if (container != null) {
3537 container.SelectNextControl(this, true, true, true, true);
3541 if (parent != null) {
3542 parent.PerformLayout(this, "visible");
3544 PerformLayout(this, "visible");
3549 [EditorBrowsable(EditorBrowsableState.Advanced)]
3550 protected void UpdateBounds() {
3558 if (!IsHandleCreated) {
3562 XplatUI.GetWindowPos(this.Handle, this is Form, out x, out y, out width, out height, out client_width, out client_height);
3564 UpdateBounds(x, y, width, height, client_width, client_height);
3567 [EditorBrowsable(EditorBrowsableState.Advanced)]
3568 protected void UpdateBounds(int x, int y, int width, int height) {
3569 // UpdateBounds only seems to set our sizes and fire events but not update the GUI window to match
3571 bool resized = false;
3573 int client_x_diff = this.bounds.Width-this.client_size.Width;
3574 int client_y_diff = this.bounds.Height-this.client_size.Height;
3576 // Needed to generate required notifications
3577 if ((this.bounds.X!=x) || (this.bounds.Y!=y)) {
3581 if ((this.Bounds.Width!=width) || (this.Bounds.Height!=height)) {
3588 bounds.Height=height;
3590 // Update client rectangle as well
3591 client_size.Width=width-client_x_diff;
3592 client_size.Height=height-client_y_diff;
3595 OnLocationChanged(EventArgs.Empty);
3599 OnSizeChanged(EventArgs.Empty);
3603 [EditorBrowsable(EditorBrowsableState.Advanced)]
3604 protected void UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) {
3605 UpdateBounds(x, y, width, height);
3607 this.client_size.Width=clientWidth;
3608 this.client_size.Height=clientHeight;
3611 [EditorBrowsable(EditorBrowsableState.Advanced)]
3612 protected void UpdateStyles() {
3613 if (!IsHandleCreated) {
3617 XplatUI.SetWindowStyle(window.Handle, CreateParams);
3620 [EditorBrowsable(EditorBrowsableState.Advanced)]
3621 protected void UpdateZOrder() {
3622 Control [] controls;
3623 if (!IsHandleCreated) {
3627 controls = child_controls.GetAllControls ();
3628 for (int i = 1; i < controls.Length; i++ ) {
3629 XplatUI.SetZOrder(controls[i].Handle, controls[i-1].Handle, false, false);
3633 protected virtual void WndProc(ref Message m) {
3635 Console.WriteLine("Control {0} received message {1}", window.Handle == IntPtr.Zero ? this.Text : XplatUI.Window(window.Handle), (Msg)m.Msg);
3637 if ((this.control_style & ControlStyles.EnableNotifyMessage) != 0) {
3641 switch((Msg)m.Msg) {
3642 case Msg.WM_DESTROY: {
3643 OnHandleDestroyed(EventArgs.Empty);
3644 window.InvalidateHandle();
3648 case Msg.WM_WINDOWPOSCHANGED: {
3651 if (GetStyle(ControlStyles.ResizeRedraw)) {
3658 case Msg.WM_PAINT: {
3659 PaintEventArgs paint_event;
3661 paint_event = XplatUI.PaintEventStart(Handle, true);
3663 if (!needs_redraw) {
3664 // Just blit the previous image
3665 paint_event.Graphics.DrawImage (ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle, GraphicsUnit.Pixel);
3666 XplatUI.PaintEventEnd(Handle, true);
3671 if (ThemeEngine.Current.DoubleBufferingSupported)
3672 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
3673 dc = paint_event.SetGraphics (DeviceContext);
3676 OnPaintBackground(paint_event);
3677 // Leave out for now, our controls can do Paint += ... as well
3678 //OnPaintInternal(paint_event);
3679 OnPaint(paint_event);
3681 if (ThemeEngine.Current.DoubleBufferingSupported)
3682 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
3683 dc.DrawImage (ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle, GraphicsUnit.Pixel);
3684 paint_event.SetGraphics (dc);
3685 needs_redraw = false;
3688 XplatUI.PaintEventEnd(Handle, true);
3693 case Msg.WM_ERASEBKGND: {
3694 // The DefWndProc will never have to handle this, we always paint the background in managed code
3695 m.Result = (IntPtr)1;
3699 case Msg.WM_LBUTTONUP: {
3700 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Left,
3702 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3704 HandleClick(mouse_clicks);
3705 if (mouse_clicks > 1) {
3711 case Msg.WM_LBUTTONDOWN: {
3712 if (CanSelect && !is_selected) {
3715 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3716 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3722 case Msg.WM_LBUTTONDBLCLK: {
3724 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3725 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3731 case Msg.WM_MBUTTONUP: {
3732 HandleClick(mouse_clicks);
3733 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Middle,
3735 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3737 if (mouse_clicks > 1) {
3743 case Msg.WM_MBUTTONDOWN: {
3744 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3745 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3751 case Msg.WM_MBUTTONDBLCLK: {
3753 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3754 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3759 case Msg.WM_RBUTTONUP: {
3760 if (context_menu != null) {
3761 context_menu.Show(this, new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ())));
3764 HandleClick(mouse_clicks);
3765 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Right,
3767 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3769 if (mouse_clicks > 1) {
3775 case Msg.WM_RBUTTONDOWN: {
3776 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3777 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3782 case Msg.WM_RBUTTONDBLCLK: {
3784 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3785 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3790 case Msg.WM_MOUSEWHEEL: {
3792 OnMouseWheel (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3793 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3794 HighOrder(m.WParam.ToInt32())));
3799 case Msg.WM_MOUSEMOVE: {
3800 OnMouseMove (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3802 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3807 case Msg.WM_MOUSE_ENTER: {
3812 OnMouseEnter(EventArgs.Empty);
3816 case Msg.WM_MOUSE_LEAVE: {
3818 OnMouseLeave(EventArgs.Empty);
3822 case Msg.WM_MOUSEHOVER: {
3823 OnMouseHover(EventArgs.Empty);
3827 case Msg.WM_SYSKEYDOWN:
3828 case Msg.WM_KEYDOWN:
3829 case Msg.WM_SYSKEYUP:
3831 case Msg.WM_SYSCHAR:
3833 if (ProcessKeyMessage(ref m)) {
3837 if ((m.Msg == (int)Msg.WM_SYSKEYUP) && ((m.WParam.ToInt32() & (int)Keys.KeyCode) == (int)Keys.Menu)) {
3841 if (form != null && form.ActiveMenu != null) {
3842 form.ActiveMenu.ProcessCmdKey(ref m, (Keys)m.WParam.ToInt32());
3852 if (m.LParam != IntPtr.Zero) {
3855 hi = new HELPINFO();
3857 hi = (HELPINFO) Marshal.PtrToStructure (m.LParam, typeof (HELPINFO));
3858 mouse_pos = new Point(hi.MousePos.x, hi.MousePos.y);
3860 mouse_pos = Control.MousePosition;
3862 OnHelpRequested(new HelpEventArgs(mouse_pos));
3863 m.Result = (IntPtr)1;
3867 case Msg.WM_KILLFOCUS: {
3868 OnLeave(EventArgs.Empty);
3869 if (CausesValidation) {
3871 e = new CancelEventArgs(false);
3880 OnValidated(EventArgs.Empty);
3883 this.has_focus = false;
3884 this.is_selected = false;
3885 OnLostFocus(EventArgs.Empty);
3889 case Msg.WM_SETFOCUS: {
3890 OnEnter(EventArgs.Empty);
3891 this.has_focus = true;
3892 OnGotFocus(EventArgs.Empty);
3897 case Msg.WM_SYSCOLORCHANGE: {
3898 ThemeEngine.Current.ResetDefaults();
3899 OnSystemColorsChanged(EventArgs.Empty);
3904 case Msg.WM_SETCURSOR: {
3905 if (cursor == null) {
3910 XplatUI.SetCursor(window.Handle, cursor.handle);
3911 m.Result = (IntPtr)1;
3922 #endregion // Public Instance Methods
3924 #region OnXXX methods
3925 [EditorBrowsable(EditorBrowsableState.Advanced)]
3926 protected virtual void OnBackColorChanged(EventArgs e) {
3927 if (BackColorChanged!=null) BackColorChanged(this, e);
3928 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackColorChanged(e);
3931 [EditorBrowsable(EditorBrowsableState.Advanced)]
3932 protected virtual void OnBackgroundImageChanged(EventArgs e) {
3933 if (BackgroundImageChanged!=null) BackgroundImageChanged(this, e);
3934 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackgroundImageChanged(e);
3937 [EditorBrowsable(EditorBrowsableState.Advanced)]
3938 protected virtual void OnBindingContextChanged(EventArgs e) {
3939 CheckDataBindings ();
3940 if (BindingContextChanged!=null) {
3941 BindingContextChanged(this, e);
3943 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBindingContextChanged(e);
3946 [EditorBrowsable(EditorBrowsableState.Advanced)]
3947 protected virtual void OnCausesValidationChanged(EventArgs e) {
3948 if (CausesValidationChanged!=null) CausesValidationChanged(this, e);
3951 [EditorBrowsable(EditorBrowsableState.Advanced)]
3952 protected virtual void OnChangeUICues(UICuesEventArgs e) {
3953 if (ChangeUICues!=null) ChangeUICues(this, e);
3956 [EditorBrowsable(EditorBrowsableState.Advanced)]
3957 protected virtual void OnClick(EventArgs e) {
3958 if (Click!=null) Click(this, e);
3961 [EditorBrowsable(EditorBrowsableState.Advanced)]
3962 protected virtual void OnContextMenuChanged(EventArgs e) {
3963 if (ContextMenuChanged!=null) ContextMenuChanged(this, e);
3966 [EditorBrowsable(EditorBrowsableState.Advanced)]
3967 protected virtual void OnControlAdded(ControlEventArgs e) {
3968 if (ControlAdded!=null) ControlAdded(this, e);
3971 [EditorBrowsable(EditorBrowsableState.Advanced)]
3972 protected virtual void OnControlRemoved(ControlEventArgs e) {
3973 if (ControlRemoved!=null) ControlRemoved(this, e);
3976 [EditorBrowsable(EditorBrowsableState.Advanced)]
3977 protected virtual void OnCreateControl() {
3981 [EditorBrowsable(EditorBrowsableState.Advanced)]
3982 protected virtual void OnCursorChanged(EventArgs e) {
3983 if (CursorChanged!=null) CursorChanged(this, e);
3986 [EditorBrowsable(EditorBrowsableState.Advanced)]
3987 protected virtual void OnDockChanged(EventArgs e) {
3988 if (DockChanged!=null) DockChanged(this, e);
3991 [EditorBrowsable(EditorBrowsableState.Advanced)]
3992 protected virtual void OnDoubleClick(EventArgs e) {
3993 if (DoubleClick!=null) DoubleClick(this, e);
3996 [EditorBrowsable(EditorBrowsableState.Advanced)]
3997 protected virtual void OnDragDrop(DragEventArgs drgevent) {
3998 if (DragDrop!=null) DragDrop(this, drgevent);
4001 [EditorBrowsable(EditorBrowsableState.Advanced)]
4002 protected virtual void OnDragEnter(DragEventArgs drgevent) {
4003 if (DragEnter!=null) DragEnter(this, drgevent);
4006 [EditorBrowsable(EditorBrowsableState.Advanced)]
4007 protected virtual void OnDragLeave(EventArgs e) {
4008 if (DragLeave!=null) DragLeave(this, e);
4011 [EditorBrowsable(EditorBrowsableState.Advanced)]
4012 protected virtual void OnDragOver(DragEventArgs drgevent) {
4013 if (DragOver!=null) DragOver(this, drgevent);
4016 [EditorBrowsable(EditorBrowsableState.Advanced)]
4017 protected virtual void OnEnabledChanged(EventArgs e) {
4018 if (EnabledChanged!=null) EnabledChanged(this, e);
4019 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentEnabledChanged(e);
4022 [EditorBrowsable(EditorBrowsableState.Advanced)]
4023 protected virtual void OnEnter(EventArgs e) {
4024 if (Enter!=null) Enter(this, e);
4027 [EditorBrowsable(EditorBrowsableState.Advanced)]
4028 protected virtual void OnFontChanged(EventArgs e) {
4029 if (FontChanged!=null) FontChanged(this, e);
4030 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentFontChanged(e);
4033 [EditorBrowsable(EditorBrowsableState.Advanced)]
4034 protected virtual void OnForeColorChanged(EventArgs e) {
4035 if (ForeColorChanged!=null) ForeColorChanged(this, e);
4036 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentForeColorChanged(e);
4039 [EditorBrowsable(EditorBrowsableState.Advanced)]
4040 protected virtual void OnGiveFeedback(GiveFeedbackEventArgs gfbevent) {
4041 if (GiveFeedback!=null) GiveFeedback(this, gfbevent);
4044 [EditorBrowsable(EditorBrowsableState.Advanced)]
4045 protected virtual void OnGotFocus(EventArgs e) {
4046 if (GotFocus!=null) GotFocus(this, e);
4049 [EditorBrowsable(EditorBrowsableState.Advanced)]
4050 protected virtual void OnHandleCreated(EventArgs e) {
4051 if (HandleCreated!=null) HandleCreated(this, e);
4054 [EditorBrowsable(EditorBrowsableState.Advanced)]
4055 protected virtual void OnHandleDestroyed(EventArgs e) {
4056 if (HandleDestroyed!=null) HandleDestroyed(this, e);
4059 [EditorBrowsable(EditorBrowsableState.Advanced)]
4060 protected virtual void OnHelpRequested(HelpEventArgs hevent) {
4061 if (HelpRequested!=null) HelpRequested(this, hevent);
4064 protected virtual void OnImeModeChanged(EventArgs e) {
4065 if (ImeModeChanged!=null) ImeModeChanged(this, e);
4068 [EditorBrowsable(EditorBrowsableState.Advanced)]
4069 protected virtual void OnInvalidated(InvalidateEventArgs e) {
4070 needs_redraw = true;
4071 if (Invalidated!=null) Invalidated(this, e);
4074 [EditorBrowsable(EditorBrowsableState.Advanced)]
4075 protected virtual void OnKeyDown(KeyEventArgs e) {
4076 if (KeyDown!=null) KeyDown(this, e);
4079 [EditorBrowsable(EditorBrowsableState.Advanced)]
4080 protected virtual void OnKeyPress(KeyPressEventArgs e) {
4081 if (KeyPress!=null) KeyPress(this, e);
4084 [EditorBrowsable(EditorBrowsableState.Advanced)]
4085 protected virtual void OnKeyUp(KeyEventArgs e) {
4086 if (KeyUp!=null) KeyUp(this, e);
4089 [EditorBrowsable(EditorBrowsableState.Advanced)]
4090 protected virtual void OnLayout(LayoutEventArgs levent) {
4091 if (Layout!=null) Layout(this, levent);
4094 [EditorBrowsable(EditorBrowsableState.Advanced)]
4095 protected virtual void OnLeave(EventArgs e) {
4096 if (Leave!=null) Leave(this, e);
4099 [EditorBrowsable(EditorBrowsableState.Advanced)]
4100 protected virtual void OnLocationChanged(EventArgs e) {
4102 if (LocationChanged!=null) LocationChanged(this, e);
4105 [EditorBrowsable(EditorBrowsableState.Advanced)]
4106 protected virtual void OnLostFocus(EventArgs e) {
4107 if (LostFocus!=null) LostFocus(this, e);
4110 [EditorBrowsable(EditorBrowsableState.Advanced)]
4111 protected virtual void OnMouseDown(MouseEventArgs e) {
4112 if (MouseDown!=null) MouseDown(this, e);
4115 [EditorBrowsable(EditorBrowsableState.Advanced)]
4116 protected virtual void OnMouseEnter(EventArgs e) {
4117 if (MouseEnter!=null) MouseEnter(this, e);
4120 [EditorBrowsable(EditorBrowsableState.Advanced)]
4121 protected virtual void OnMouseHover(EventArgs e) {
4122 if (MouseHover!=null) MouseHover(this, e);
4125 [EditorBrowsable(EditorBrowsableState.Advanced)]
4126 protected virtual void OnMouseLeave(EventArgs e) {
4127 if (MouseLeave!=null) MouseLeave(this, e);
4130 [EditorBrowsable(EditorBrowsableState.Advanced)]
4131 protected virtual void OnMouseMove(MouseEventArgs e) {
4132 if (MouseMove!=null) MouseMove(this, e);
4135 [EditorBrowsable(EditorBrowsableState.Advanced)]
4136 protected virtual void OnMouseUp(MouseEventArgs e) {
4137 if (MouseUp!=null) MouseUp(this, e);
4140 [EditorBrowsable(EditorBrowsableState.Advanced)]
4141 protected virtual void OnMouseWheel(MouseEventArgs e) {
4142 if (MouseWheel!=null) MouseWheel(this, e);
4145 [EditorBrowsable(EditorBrowsableState.Advanced)]
4146 protected virtual void OnMove(EventArgs e) {
4147 if (Move!=null) Move(this, e);
4150 [EditorBrowsable(EditorBrowsableState.Advanced)]
4151 protected virtual void OnNotifyMessage(Message m) {
4155 [EditorBrowsable(EditorBrowsableState.Advanced)]
4156 protected virtual void OnPaint(PaintEventArgs e) {
4157 if (Paint!=null) Paint(this, e);
4160 internal virtual void OnPaintInternal(PaintEventArgs e) {
4164 [EditorBrowsable(EditorBrowsableState.Advanced)]
4165 protected virtual void OnPaintBackground(PaintEventArgs pevent) {
4166 PaintControlBackground (pevent);
4169 [EditorBrowsable(EditorBrowsableState.Advanced)]
4170 protected virtual void OnParentBackColorChanged(EventArgs e) {
4171 if (background_color.IsEmpty && background_image==null) {
4173 OnBackColorChanged(e);
4177 [EditorBrowsable(EditorBrowsableState.Advanced)]
4178 protected virtual void OnParentBackgroundImageChanged(EventArgs e) {
4179 if (background_color.IsEmpty && background_image==null) {
4181 OnBackgroundImageChanged(e);
4185 [EditorBrowsable(EditorBrowsableState.Advanced)]
4186 protected virtual void OnParentBindingContextChanged(EventArgs e) {
4187 if (binding_context==null) {
4188 binding_context=Parent.binding_context;
4189 OnBindingContextChanged(e);
4193 [EditorBrowsable(EditorBrowsableState.Advanced)]
4194 protected virtual void OnParentChanged(EventArgs e) {
4195 if (ParentChanged!=null) ParentChanged(this, e);
4198 [EditorBrowsable(EditorBrowsableState.Advanced)]
4199 protected virtual void OnParentEnabledChanged(EventArgs e) {
4200 if (is_enabled != Parent.is_enabled) {
4201 is_enabled=Parent.is_enabled;
4203 if (EnabledChanged != null) {
4204 EnabledChanged(this, e);
4209 [EditorBrowsable(EditorBrowsableState.Advanced)]
4210 protected virtual void OnParentFontChanged(EventArgs e) {
4217 [EditorBrowsable(EditorBrowsableState.Advanced)]
4218 protected virtual void OnParentForeColorChanged(EventArgs e) {
4219 if (foreground_color.IsEmpty) {
4221 OnForeColorChanged(e);
4225 [EditorBrowsable(EditorBrowsableState.Advanced)]
4226 protected virtual void OnParentRightToLeftChanged(EventArgs e) {
4227 if (right_to_left==RightToLeft.Inherit) {
4229 OnRightToLeftChanged(e);
4233 [EditorBrowsable(EditorBrowsableState.Advanced)]
4234 protected virtual void OnParentVisibleChanged(EventArgs e) {
4236 OnVisibleChanged(e);
4240 [EditorBrowsable(EditorBrowsableState.Advanced)]
4241 protected virtual void OnQueryContinueDrag(QueryContinueDragEventArgs e) {
4242 if (QueryContinueDrag!=null) QueryContinueDrag(this, e);
4245 [EditorBrowsable(EditorBrowsableState.Advanced)]
4246 protected virtual void OnResize(EventArgs e) {
4247 if (Resize!=null) Resize(this, e);
4249 PerformLayout(this, "bounds");
4251 if (parent != null) {
4252 parent.PerformLayout();
4256 [EditorBrowsable(EditorBrowsableState.Advanced)]
4257 protected virtual void OnRightToLeftChanged(EventArgs e) {
4258 if (RightToLeftChanged!=null) RightToLeftChanged(this, e);
4259 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentRightToLeftChanged(e);
4262 [EditorBrowsable(EditorBrowsableState.Advanced)]
4263 protected virtual void OnSizeChanged(EventArgs e) {
4264 InvalidateBuffers ();
4266 if (SizeChanged!=null) SizeChanged(this, e);
4269 [EditorBrowsable(EditorBrowsableState.Advanced)]
4270 protected virtual void OnStyleChanged(EventArgs e) {
4271 if (StyleChanged!=null) StyleChanged(this, e);
4274 [EditorBrowsable(EditorBrowsableState.Advanced)]
4275 protected virtual void OnSystemColorsChanged(EventArgs e) {
4276 if (SystemColorsChanged!=null) SystemColorsChanged(this, e);
4279 [EditorBrowsable(EditorBrowsableState.Advanced)]
4280 protected virtual void OnTabIndexChanged(EventArgs e) {
4281 if (TabIndexChanged!=null) TabIndexChanged(this, e);
4284 [EditorBrowsable(EditorBrowsableState.Advanced)]
4285 protected virtual void OnTabStopChanged(EventArgs e) {
4286 if (TabStopChanged!=null) TabStopChanged(this, e);
4289 [EditorBrowsable(EditorBrowsableState.Advanced)]
4290 protected virtual void OnTextChanged(EventArgs e) {
4291 if (TextChanged!=null) TextChanged(this, e);
4294 [EditorBrowsable(EditorBrowsableState.Advanced)]
4295 protected virtual void OnValidated(EventArgs e) {
4296 if (Validated!=null) Validated(this, e);
4299 [EditorBrowsable(EditorBrowsableState.Advanced)]
4300 protected virtual void OnValidating(System.ComponentModel.CancelEventArgs e) {
4301 if (Validating!=null) Validating(this, e);
4304 [EditorBrowsable(EditorBrowsableState.Advanced)]
4305 protected virtual void OnVisibleChanged(EventArgs e) {
4306 if ((parent != null) && !Created && Visible) {
4317 if (bmp_mem!=null) {
4323 if (VisibleChanged!=null) VisibleChanged(this, e);
4325 // We need to tell our kids
4326 for (int i=0; i<child_controls.Count; i++) {
4327 child_controls[i].OnParentVisibleChanged(e);
4330 #endregion // OnXXX methods
4333 public event EventHandler BackColorChanged;
4334 public event EventHandler BackgroundImageChanged;
4335 public event EventHandler BindingContextChanged;
4336 public event EventHandler CausesValidationChanged;
4337 public event UICuesEventHandler ChangeUICues;
4338 public event EventHandler Click;
4339 public event EventHandler ContextMenuChanged;
4341 [EditorBrowsable(EditorBrowsableState.Advanced)]
4343 public event ControlEventHandler ControlAdded;
4345 [EditorBrowsable(EditorBrowsableState.Advanced)]
4347 public event ControlEventHandler ControlRemoved;
4349 [MWFDescription("Fired when the cursor for the control has been changed"), MWFCategory("PropertyChanged")]
4350 public event EventHandler CursorChanged;
4351 public event EventHandler DockChanged;
4352 public event EventHandler DoubleClick;
4353 public event DragEventHandler DragDrop;
4354 public event DragEventHandler DragEnter;
4355 public event EventHandler DragLeave;
4356 public event DragEventHandler DragOver;
4357 public event EventHandler EnabledChanged;
4358 public event EventHandler Enter;
4359 public event EventHandler FontChanged;
4360 public event EventHandler ForeColorChanged;
4361 public event GiveFeedbackEventHandler GiveFeedback;
4363 [EditorBrowsable(EditorBrowsableState.Advanced)]
4365 public event EventHandler GotFocus;
4367 [EditorBrowsable(EditorBrowsableState.Advanced)]
4369 public event EventHandler HandleCreated;
4371 [EditorBrowsable(EditorBrowsableState.Advanced)]
4373 public event EventHandler HandleDestroyed;
4375 public event HelpEventHandler HelpRequested;
4376 public event EventHandler ImeModeChanged;
4378 [EditorBrowsable(EditorBrowsableState.Advanced)]
4380 public event InvalidateEventHandler Invalidated;
4382 public event KeyEventHandler KeyDown;
4383 public event KeyPressEventHandler KeyPress;
4384 public event KeyEventHandler KeyUp;
4385 public event LayoutEventHandler Layout;
4386 public event EventHandler Leave;
4387 public event EventHandler LocationChanged;
4389 [EditorBrowsable(EditorBrowsableState.Advanced)]
4391 public event EventHandler LostFocus;
4393 public event MouseEventHandler MouseDown;
4394 public event EventHandler MouseEnter;
4395 public event EventHandler MouseHover;
4396 public event EventHandler MouseLeave;
4397 public event MouseEventHandler MouseMove;
4398 public event MouseEventHandler MouseUp;
4400 [EditorBrowsable(EditorBrowsableState.Advanced)]
4402 public event MouseEventHandler MouseWheel;
4404 public event EventHandler Move;
4405 public event PaintEventHandler Paint;
4406 public event EventHandler ParentChanged;
4407 public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp;
4408 public event QueryContinueDragEventHandler QueryContinueDrag;
4409 public event EventHandler Resize;
4410 public event EventHandler RightToLeftChanged;
4411 public event EventHandler SizeChanged;
4412 public event EventHandler StyleChanged;
4413 public event EventHandler SystemColorsChanged;
4414 public event EventHandler TabIndexChanged;
4415 public event EventHandler TabStopChanged;
4416 public event EventHandler TextChanged;
4417 public event EventHandler Validated;
4418 public event CancelEventHandler Validating;
4419 public event EventHandler VisibleChanged;
4420 #endregion // Events