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 dist_left = bounds.X;
1235 dist_top = bounds.Y;
1236 if ((parent != null) && (parent.layout_suspended == 0)) {
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) || this.parent == null) {
1487 parent = this.parent;
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 if (!this.is_disposed && (this.window.Handle != IntPtr.Zero)) {
1626 [AmbientValue(null)]
1627 public virtual Cursor Cursor {
1629 if (cursor != null) {
1633 if (parent != null) {
1634 return parent.Cursor;
1637 return Cursors.Default;
1641 if (cursor != value) {
1646 if (IsHandleCreated) {
1647 pt = Cursor.Position;
1649 if (bounds.Contains(pt)) {
1650 if (GetChildAtPoint(pt) == null) {
1651 if (cursor != null) {
1652 XplatUI.SetCursor(window.Handle, cursor.handle);
1654 if (parent != null) {
1655 XplatUI.SetCursor(window.Handle, parent.Cursor.handle);
1657 XplatUI.SetCursor(window.Handle, Cursors.def.handle);
1664 OnCursorChanged(EventArgs.Empty);
1670 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
1671 [ParenthesizePropertyName(true)]
1672 [RefreshProperties(RefreshProperties.All)]
1673 public ControlBindingsCollection DataBindings {
1675 if (data_bindings == null)
1676 data_bindings = new ControlBindingsCollection (this);
1677 return data_bindings;
1681 [EditorBrowsable(EditorBrowsableState.Advanced)]
1683 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1684 public virtual Rectangle DisplayRectangle {
1686 return ClientRectangle;
1690 [EditorBrowsable(EditorBrowsableState.Advanced)]
1692 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1693 public bool Disposing {
1700 [RefreshProperties(RefreshProperties.Repaint)]
1701 [DefaultValue(DockStyle.None)]
1702 public virtual DockStyle Dock {
1708 if (dock_style == value) {
1714 if (parent != null) {
1715 parent.PerformLayout(this, "Parent");
1718 OnDockChanged(EventArgs.Empty);
1724 public bool Enabled {
1730 if (parent != null) {
1731 return parent.Enabled;
1738 if (is_enabled == value) {
1742 if (IsHandleCreated) {
1744 if (((Form)this).context == null) {
1745 XplatUI.EnableWindow(window.Handle, value);
1748 XplatUI.EnableWindow(window.Handle, value);
1753 OnEnabledChanged (EventArgs.Empty);
1757 [EditorBrowsable(EditorBrowsableState.Advanced)]
1759 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1760 public virtual bool Focused {
1762 return this.has_focus;
1767 [AmbientValue(null)]
1769 public virtual Font Font {
1775 if (Parent != null && Parent.Font != null) {
1783 if (font != null && font.Equals (value)) {
1789 OnFontChanged (EventArgs.Empty);
1794 public virtual Color ForeColor {
1796 if (foreground_color.IsEmpty) {
1798 return parent.ForeColor;
1800 return DefaultForeColor;
1802 return foreground_color;
1806 if (foreground_color != value) {
1807 foreground_color=value;
1809 OnForeColorChanged(EventArgs.Empty);
1816 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1817 public IntPtr Handle { // IWin32Window
1819 if (!IsHandleCreated) {
1822 return window.Handle;
1826 [EditorBrowsable(EditorBrowsableState.Advanced)]
1828 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1829 public bool HasChildren {
1831 if (this.child_controls.Count>0) {
1838 [EditorBrowsable(EditorBrowsableState.Always)]
1840 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1843 return this.bounds.Height;
1847 SetBoundsCore(bounds.X, bounds.Y, bounds.Width, value, BoundsSpecified.Height);
1851 [AmbientValue(ImeMode.Inherit)]
1853 public ImeMode ImeMode {
1855 if (ime_mode == DefaultImeMode) {
1857 return parent.ImeMode;
1859 return ImeMode.NoControl; // default value
1865 if (ime_mode != value) {
1868 OnImeModeChanged(EventArgs.Empty);
1873 [EditorBrowsable(EditorBrowsableState.Advanced)]
1875 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1876 public bool InvokeRequired { // ISynchronizeInvoke
1878 if (creator_thread != null && creator_thread!=Thread.CurrentThread) {
1885 [EditorBrowsable(EditorBrowsableState.Advanced)]
1887 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1888 public bool IsAccessible {
1890 return is_accessible;
1894 is_accessible = value;
1898 [EditorBrowsable(EditorBrowsableState.Advanced)]
1900 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1901 public bool IsDisposed {
1903 return this.is_disposed;
1907 [EditorBrowsable(EditorBrowsableState.Advanced)]
1909 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1910 public bool IsHandleCreated {
1912 if ((window!=null) && (window.Handle!=IntPtr.Zero)) {
1920 [EditorBrowsable(EditorBrowsableState.Always)]
1922 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1925 return this.bounds.X;
1929 SetBoundsCore(value, bounds.Y, bounds.Width, bounds.Height, BoundsSpecified.X);
1934 public Point Location {
1936 return new Point(bounds.X, bounds.Y);
1940 SetBoundsCore(value.X, value.Y, bounds.Width, bounds.Height, BoundsSpecified.Location);
1945 public string Name {
1956 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1957 public Control Parent {
1963 if (value == this) {
1964 throw new ArgumentException("A circular control reference has been made. A control cannot be owned or parented to itself.");
1967 if (parent!=value) {
1969 parent.Controls.Remove(this);
1973 value.Controls.Add(this);
1978 [EditorBrowsable(EditorBrowsableState.Advanced)]
1980 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1981 public string ProductName {
1983 Type t = typeof (AssemblyProductAttribute);
1984 Assembly assembly = GetType().Module.Assembly;
1985 object [] attrs = assembly.GetCustomAttributes (t, false);
1986 AssemblyProductAttribute a = null;
1987 // On MS we get a NullRefException if product attribute is not
1989 if (attrs != null && attrs.Length > 0)
1990 a = (AssemblyProductAttribute) attrs [0];
1995 [EditorBrowsable(EditorBrowsableState.Advanced)]
1997 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1998 public string ProductVersion {
2000 Type t = typeof (AssemblyVersionAttribute);
2001 Assembly assembly = GetType().Module.Assembly;
2002 object [] attrs = assembly.GetCustomAttributes (t, false);
2003 if (attrs == null || attrs.Length < 1)
2005 return ((AssemblyVersionAttribute)attrs [0]).Version;
2009 [EditorBrowsable(EditorBrowsableState.Advanced)]
2011 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2012 public bool RecreatingHandle {
2014 return is_recreating;
2018 [EditorBrowsable(EditorBrowsableState.Advanced)]
2020 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2021 public Region Region {
2023 return new Region(this.bounds);
2030 g = this.CreateGraphics();
2031 r = value.GetBounds(g);
2033 SetBounds((int)r.X, (int)r.Y, (int)r.Width, (int)r.Height);
2039 [EditorBrowsable(EditorBrowsableState.Advanced)]
2041 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2044 return this.bounds.X+this.bounds.Width;
2048 [AmbientValue(RightToLeft.Inherit)]
2050 public virtual RightToLeft RightToLeft {
2052 if (right_to_left == RightToLeft.Inherit) {
2054 return parent.RightToLeft;
2056 return RightToLeft.No; // default value
2058 return right_to_left;
2062 if (value != right_to_left) {
2063 right_to_left = value;
2064 OnRightToLeftChanged(EventArgs.Empty);
2069 [EditorBrowsable(EditorBrowsableState.Advanced)]
2070 public override ISite Site {
2083 return new Size(Width, Height);
2087 SetBoundsCore(bounds.X, bounds.Y, value.Width, value.Height, BoundsSpecified.Size);
2092 [MergableProperty(false)]
2093 public int TabIndex {
2095 if (tab_index != -1) {
2102 if (tab_index != value) {
2104 OnTabIndexChanged(EventArgs.Empty);
2110 [DefaultValue(true)]
2111 public bool TabStop {
2117 if (tab_stop != value) {
2119 OnTabStopChanged(EventArgs.Empty);
2124 [Localizable(false)]
2126 [TypeConverter(typeof(StringConverter))]
2127 [DefaultValue(null)]
2134 control_tag = value;
2140 [BindableAttribute(true)]
2141 public virtual string Text {
2143 // Our implementation ignores ControlStyles.CacheText - we always cache
2148 if (value == null) {
2149 value = String.Empty;
2154 if (IsHandleCreated) {
2155 XplatUI.Text(Handle, text);
2157 OnTextChanged (EventArgs.Empty);
2162 [EditorBrowsable(EditorBrowsableState.Always)]
2164 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2167 return this.bounds.Y;
2171 SetBoundsCore(bounds.X, value, bounds.Width, bounds.Height, BoundsSpecified.Y);
2175 [EditorBrowsable(EditorBrowsableState.Advanced)]
2177 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2178 public Control TopLevelControl {
2182 while (p.parent != null) {
2191 public bool Visible {
2195 } else if (parent != null) {
2196 return parent.Visible;
2203 SetVisibleCore(value);
2207 [EditorBrowsable(EditorBrowsableState.Always)]
2209 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2212 return this.bounds.Width;
2216 SetBoundsCore(bounds.X, bounds.Y, value, bounds.Height, BoundsSpecified.Width);
2220 [EditorBrowsable(EditorBrowsableState.Never)]
2222 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2223 public IWindowTarget WindowTarget {
2232 #endregion // Public Instance Properties
2234 #region Protected Instance Properties
2235 protected virtual CreateParams CreateParams {
2237 CreateParams create_params = new CreateParams();
2240 create_params.Caption = Text;
2243 create_params.Caption = text;
2247 create_params.X = Left;
2250 create_params.X = this.bounds.X;
2254 create_params.Y = Top;
2257 create_params.Y = this.bounds.Y;
2261 create_params.Width = Width;
2264 create_params.Width = this.bounds.Width;
2268 create_params.Height = Height;
2271 create_params.Height = this.bounds.Height;
2275 create_params.ClassName = XplatUI.DefaultClassName;
2276 create_params.ClassStyle = 0;
2277 create_params.ExStyle = 0;
2278 create_params.Param = 0;
2281 create_params.ExStyle |= (int)WindowStyles.WS_EX_ACCEPTFILES;
2285 create_params.Parent = parent.Handle;
2288 create_params.Style = (int)WindowStyles.WS_CHILD | (int)WindowStyles.WS_CLIPCHILDREN | (int)WindowStyles.WS_CLIPSIBLINGS;
2291 create_params.Style |= (int)WindowStyles.WS_VISIBLE;
2295 create_params.Style |= (int)WindowStyles.WS_DISABLED;
2298 switch (border_style) {
2299 case BorderStyle.FixedSingle:
2300 create_params.Style |= (int) WindowStyles.WS_BORDER;
2302 case BorderStyle.Fixed3D:
2303 create_params.ExStyle |= (int) WindowStyles.WS_EX_CLIENTEDGE;
2307 return create_params;
2311 protected virtual ImeMode DefaultImeMode {
2313 return ImeMode.Inherit;
2317 protected virtual Size DefaultSize {
2319 return new Size(100, 23);
2323 protected int FontHeight {
2333 protected bool RenderRightToLeft {
2335 return (this.right_to_left == RightToLeft.Yes);
2339 protected bool ResizeRedraw {
2341 return GetStyle(ControlStyles.ResizeRedraw);
2345 SetStyle(ControlStyles.ResizeRedraw, value);
2349 [EditorBrowsable(EditorBrowsableState.Advanced)]
2351 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2352 protected virtual bool ShowFocusCues {
2358 [EditorBrowsable(EditorBrowsableState.Advanced)]
2360 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2361 protected bool ShowKeyboardCues {
2366 #endregion // Protected Instance Properties
2368 #region Public Static Methods
2369 [EditorBrowsable(EditorBrowsableState.Advanced)]
2370 public static Control FromChildHandle(IntPtr handle) {
2371 IEnumerator control = Control.controls.GetEnumerator();
2373 while (control.MoveNext()) {
2374 if (((Control)control.Current).window.Handle == handle) {
2376 if (((Control)control.Current).Parent != null) {
2377 return ((Control)control.Current).Parent;
2384 [EditorBrowsable(EditorBrowsableState.Advanced)]
2385 public static Control FromHandle(IntPtr handle) {
2387 IEnumerator control = Control.controls.GetEnumerator();
2389 while (control.MoveNext()) {
2390 if (((Control)control.Current).window.Handle == handle) {
2392 return ((Control)control.Current);
2398 return Control.ControlNativeWindow.ControlFromHandle(handle);
2402 public static bool IsMnemonic(char charCode, string text) {
2405 amp = text.IndexOf('&');
2408 if (amp + 1 < text.Length) {
2409 if (text[amp + 1] != '&') {
2410 if (Char.ToUpper(charCode) == Char.ToUpper(text.ToCharArray(amp + 1, 1)[0])) {
2420 #region Protected Static Methods
2421 [EditorBrowsable(EditorBrowsableState.Advanced)]
2422 protected static bool ReflectMessage(IntPtr hWnd, ref Message m) {
2425 c = Control.FromHandle(hWnd);
2435 #region Public Instance Methods
2436 [EditorBrowsable(EditorBrowsableState.Advanced)]
2437 public IAsyncResult BeginInvoke(Delegate method) {
2438 return BeginInvokeInternal(method, null, false);
2441 [EditorBrowsable(EditorBrowsableState.Advanced)]
2442 public IAsyncResult BeginInvoke (Delegate method, object[] args) {
2443 return BeginInvokeInternal (method, args, false);
2446 public void BringToFront() {
2447 if ((parent != null) && (parent.child_controls[0]!=this)) {
2448 if (parent.child_controls.Contains(this)) {
2449 parent.child_controls.SetChildIndex(this, 0);
2453 XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, true, false);
2455 if (parent != null) {
2460 public bool Contains(Control ctl) {
2461 while (ctl != null) {
2470 public void CreateControl() {
2475 if (!IsHandleCreated) {
2483 Control [] controls = child_controls.GetAllControls ();
2484 for (int i=0; i<controls.Length; i++) {
2485 controls [i].CreateControl ();
2490 if (binding_context == null) { // seem to be sent whenever it's null?
2491 OnBindingContextChanged(EventArgs.Empty);
2497 public Graphics CreateGraphics() {
2498 if (!IsHandleCreated) {
2499 this.CreateHandle();
2501 return Graphics.FromHwnd(this.window.Handle);
2504 public DragDropEffects DoDragDrop(object data, DragDropEffects allowedEffects) {
2505 return XplatUI.StartDrag(this.window.Handle, data, allowedEffects);
2508 [EditorBrowsable(EditorBrowsableState.Advanced)]
2509 public object EndInvoke (IAsyncResult async_result) {
2510 AsyncMethodResult result = (AsyncMethodResult) async_result;
2511 return result.EndInvoke ();
2514 public Form FindForm() {
2527 public bool Focus() {
2528 if (IsHandleCreated && !has_focus) {
2530 XplatUI.SetFocus(window.Handle);
2535 public Control GetChildAtPoint(Point pt) {
2536 // Microsoft's version of this function doesn't seem to work, so I can't check
2537 // if we only consider children or also grandchildren, etc.
2538 // I'm gonna say 'children only'
2539 for (int i=0; i<child_controls.Count; i++) {
2540 if (child_controls[i].Bounds.Contains(pt)) {
2541 return child_controls[i];
2547 public IContainerControl GetContainerControl() {
2548 Control current = this;
2550 while (current!=null) {
2551 if ((current is IContainerControl) && ((current.control_style & ControlStyles.ContainerControl)!=0)) {
2552 return (IContainerControl)current;
2554 current = current.parent;
2559 public Control GetNextControl(Control ctl, bool forward) {
2560 // If we're not a container we don't play
2561 if (!(this is IContainerControl) && !this.GetStyle(ControlStyles.ContainerControl)) {
2565 // If ctl is not contained by this, we start at the first child of this
2566 if (!this.Contains(ctl)) {
2570 // Search through our controls, starting at ctl, stepping into children as we encounter them
2571 // try to find the control with the tabindex closest to our own, or, if we're looking into
2572 // child controls, the one with the smallest tabindex
2574 return FindControlForward(this, ctl);
2576 return FindControlBackward(this, ctl);
2579 public void Hide() {
2580 this.Visible = false;
2583 public void Invalidate() {
2584 Invalidate(ClientRectangle, false);
2587 public void Invalidate(bool invalidateChildren) {
2588 Invalidate(ClientRectangle, invalidateChildren);
2591 public void Invalidate(System.Drawing.Rectangle rc) {
2592 Invalidate(rc, false);
2595 public void Invalidate(System.Drawing.Rectangle rc, bool invalidateChildren) {
2596 if (!IsHandleCreated || !Visible || rc.Width == 0 || rc.Height == 0) {
2600 NotifyInvalidate(rc);
2602 XplatUI.Invalidate(Handle, rc, false);
2604 if (invalidateChildren) {
2605 Control [] controls = child_controls.GetAllControls ();
2606 for (int i=0; i<controls.Length; i++)
2607 controls [i].Invalidate ();
2609 OnInvalidated(new InvalidateEventArgs(rc));
2612 public void Invalidate(System.Drawing.Region region) {
2613 Invalidate(region, false);
2616 public void Invalidate(System.Drawing.Region region, bool invalidateChildren) {
2617 RectangleF bounds = region.GetBounds (CreateGraphics ());
2618 Invalidate (new Rectangle ((int) bounds.X, (int) bounds.Y, (int) bounds.Width, (int) bounds.Height),
2619 invalidateChildren);
2622 public object Invoke (Delegate method) {
2623 object [] prms = null;
2624 if (method is EventHandler)
2625 prms = new object [] { this, EventArgs.Empty };
2627 return Invoke(method, prms);
2630 public object Invoke (Delegate method, object[] args) {
2631 if (!this.InvokeRequired) {
2632 return method.DynamicInvoke(args);
2635 IAsyncResult result = BeginInvoke (method, args);
2636 return EndInvoke(result);
2639 internal object InvokeInternal (Delegate method, bool disposing) {
2640 return InvokeInternal(method, null, disposing);
2643 internal object InvokeInternal (Delegate method, object[] args, bool disposing) {
2644 if (!this.InvokeRequired) {
2645 return method.DynamicInvoke(args);
2648 IAsyncResult result = BeginInvokeInternal (method, args, disposing);
2649 return EndInvoke(result);
2652 [EditorBrowsable(EditorBrowsableState.Advanced)]
2653 public void PerformLayout() {
2654 PerformLayout(null, null);
2657 [EditorBrowsable(EditorBrowsableState.Advanced)]
2658 public void PerformLayout(Control affectedControl, string affectedProperty) {
2659 LayoutEventArgs levent = new LayoutEventArgs(affectedControl, affectedProperty);
2661 if (layout_suspended > 0) {
2662 layout_pending = true;
2666 layout_pending = false;
2668 // Prevent us from getting messed up
2671 // Perform all Dock and Anchor calculations
2674 AnchorStyles anchor;
2677 space=this.DisplayRectangle;
2679 // Deal with docking; go through in reverse, MS docs say that lowest Z-order is closest to edge
2680 Control [] controls = child_controls.GetAllControls ();
2681 for (int i = controls.Length - 1; i >= 0; i--) {
2682 child = controls [i];
2683 switch (child.Dock) {
2684 case DockStyle.None: {
2689 case DockStyle.Left: {
2690 child.SetBounds(space.Left, space.Y, child.Width, space.Height);
2691 space.X+=child.Width;
2692 space.Width-=child.Width;
2696 case DockStyle.Top: {
2697 child.SetBounds(space.Left, space.Y, space.Width, child.Height);
2698 space.Y+=child.Height;
2699 space.Height-=child.Height;
2703 case DockStyle.Right: {
2704 child.SetBounds(space.Right-child.Width, space.Y, child.Width, space.Height);
2705 space.Width-=child.Width;
2709 case DockStyle.Bottom: {
2710 child.SetBounds(space.Left, space.Bottom-child.Height, space.Width, child.Height);
2711 space.Height-=child.Height;
2717 for (int i = controls.Length - 1; i >= 0; i--) {
2720 if (child.Dock == DockStyle.Fill) {
2721 child.SetBounds(space.Left, space.Top, space.Width, space.Height);
2727 space=this.DisplayRectangle;
2729 for (int i=0; i < controls.Length; i++) {
2735 child = controls[i];
2736 anchor = child.Anchor;
2740 width = child.Width;
2741 height = child.Height;
2743 // If the control is docked we don't need to do anything
2744 if (child.Dock != DockStyle.None) {
2748 if ((anchor & AnchorStyles.Left) !=0 ) {
2749 if ((anchor & AnchorStyles.Right) != 0) {
2750 width = client_size.Width - child.dist_right - left;
2752 ; // Left anchored only, nothing to be done
2754 } else if ((anchor & AnchorStyles.Right) != 0) {
2755 left = client_size.Width - child.dist_right - width;
2757 // left+=diff_width/2 will introduce rounding errors (diff_width removed from svn after r51780)
2758 // This calculates from scratch every time:
2759 left = child.dist_left + (client_size.Width - (child.dist_left + width + child.dist_right)) / 2;
2762 if ((anchor & AnchorStyles.Top) !=0 ) {
2763 if ((anchor & AnchorStyles.Bottom) != 0) {
2764 height = client_size.Height - child.dist_bottom - top;
2766 ; // Top anchored only, nothing to be done
2768 } else if ((anchor & AnchorStyles.Bottom) != 0) {
2769 top = client_size.Height - child.dist_bottom - height;
2771 // top += diff_height/2 will introduce rounding errors (diff_height removed from after r51780)
2772 // This calculates from scratch every time:
2773 top = child.dist_top + (client_size.Height - (child.dist_top + height + child.dist_bottom)) / 2;
2785 child.SetBounds(left, top, width, height);
2788 // Let everyone know
2792 // Need to make sure we decremend layout_suspended
2798 public Point PointToClient (Point p) {
2802 XplatUI.ScreenToClient (Handle, ref x, ref y);
2804 return new Point (x, y);
2807 public Point PointToScreen(Point p) {
2811 XplatUI.ClientToScreen(Handle, ref x, ref y);
2813 return new Point(x, y);
2816 public virtual bool PreProcessMessage(ref Message msg) {
2819 if ((msg.Msg == (int)Msg.WM_KEYDOWN) || (msg.Msg == (int)Msg.WM_SYSKEYDOWN)) {
2820 key_data = (Keys)msg.WParam.ToInt32() | XplatUI.State.ModifierKeys;
2822 if (!ProcessCmdKey(ref msg, key_data)) {
2823 if (IsInputKey(key_data)) {
2827 return ProcessDialogKey(key_data);
2831 } else if (msg.Msg == (int)Msg.WM_CHAR) {
2832 if (IsInputChar((char)msg.WParam)) {
2835 } else if (msg.Msg == (int)Msg.WM_SYSCHAR) {
2836 if (IsInputChar((char)msg.WParam)) {
2839 return ProcessDialogChar((char)msg.WParam);
2844 public Rectangle RectangleToClient(Rectangle r) {
2845 return new Rectangle(PointToClient(r.Location), r.Size);
2848 public Rectangle RectangleToScreen(Rectangle r) {
2849 return new Rectangle(PointToScreen(r.Location), r.Size);
2852 public virtual void Refresh() {
2853 if (IsHandleCreated == true) {
2856 XplatUI.UpdateWindow(window.Handle);
2858 Control [] controls = child_controls.GetAllControls ();
2859 for (int i=0; i < controls.Length; i++) {
2860 controls[i].Refresh();
2866 [EditorBrowsable(EditorBrowsableState.Never)]
2867 public virtual void ResetBackColor() {
2868 background_color = Color.Empty;
2871 [EditorBrowsable(EditorBrowsableState.Never)]
2873 public void ResetBindings() {
2877 [EditorBrowsable(EditorBrowsableState.Never)]
2878 public virtual void ResetCursor() {
2882 [EditorBrowsable(EditorBrowsableState.Never)]
2883 public virtual void ResetFont() {
2887 [EditorBrowsable(EditorBrowsableState.Never)]
2888 public virtual void ResetForeColor() {
2889 foreground_color = Color.Empty;
2892 [EditorBrowsable(EditorBrowsableState.Never)]
2893 public void ResetImeMode() {
2894 ime_mode = DefaultImeMode;
2897 [EditorBrowsable(EditorBrowsableState.Never)]
2898 public virtual void ResetRightToLeft() {
2899 right_to_left = RightToLeft.Inherit;
2902 public virtual void ResetText() {
2903 text = String.Empty;
2906 public void ResumeLayout() {
2907 ResumeLayout (true);
2910 public void ResumeLayout(bool performLayout) {
2913 if (layout_suspended > 0) {
2917 Control [] controls = child_controls.GetAllControls ();
2918 for (int i=0; i<controls.Length; i++) {
2919 controls [i].UpdateDistances ();
2922 if (performLayout || layout_pending) {
2927 public void Scale(float ratio) {
2928 ScaleCore(ratio, ratio);
2931 public void Scale(float dx, float dy) {
2935 public void Select() {
2936 Select(false, false);
2939 public bool SelectNextControl(Control ctl, bool forward, bool tabStopOnly, bool nested, bool wrap) {
2944 c = GetNextControl(c, forward);
2953 if (c.CanSelect && ((c.parent == ctl.parent) || nested) && (c.tab_stop || !tabStopOnly)) {
2957 } while (c != ctl); // If we wrap back to ourselves we stop
2962 public void SendToBack() {
2963 if ((parent != null) && (parent.child_controls[parent.child_controls.Count-1]!=this)) {
2964 if (parent.child_controls.Contains(this)) {
2965 parent.child_controls.SetChildIndex(this, parent.child_controls.Count);
2969 XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, false, true);
2970 if (parent != null) {
2975 public void SetBounds(int x, int y, int width, int height) {
2976 SetBoundsCore(x, y, width, height, BoundsSpecified.All);
2979 public void SetBounds(int x, int y, int width, int height, BoundsSpecified specified) {
2980 SetBoundsCore(x, y, width, height, specified);
2983 public void Show() {
2984 if (!IsHandleCreated) {
2985 this.CreateControl();
2991 public void SuspendLayout() {
2995 public void Update() {
2996 needs_redraw = true;
2997 if (IsHandleCreated) {
2998 XplatUI.UpdateWindow(window.Handle);
3001 #endregion // Public Instance Methods
3003 #region Protected Instance Methods
3004 [EditorBrowsable(EditorBrowsableState.Advanced)]
3005 [MonoTODO("Implement this and tie it into Control.ControlAccessibleObject.NotifyClients")]
3006 protected void AccessibilityNotifyClients(AccessibleEvents accEvent, int childID) {
3007 throw new NotImplementedException();
3010 [EditorBrowsable(EditorBrowsableState.Advanced)]
3011 protected virtual AccessibleObject CreateAccessibilityInstance() {
3012 return new Control.ControlAccessibleObject(this);
3015 [EditorBrowsable(EditorBrowsableState.Advanced)]
3016 protected virtual ControlCollection CreateControlsInstance() {
3017 return new ControlCollection(this);
3020 [EditorBrowsable(EditorBrowsableState.Advanced)]
3021 protected virtual void CreateHandle() {
3023 throw new ObjectDisposedException(Name);
3026 if (IsHandleCreated) {
3030 window.CreateHandle(CreateParams);
3032 if (window.Handle != IntPtr.Zero) {
3033 if (!controls.Contains(window.Handle)) {
3037 creator_thread = Thread.CurrentThread;
3039 XplatUI.EnableWindow(window.Handle, is_enabled);
3041 // Set our handle with our parent
3042 if ((parent != null) && (parent.IsHandleCreated)) {
3043 XplatUI.SetParent(window.Handle, parent.Handle);
3046 // Set our handle as parent for our children
3047 Control [] children;
3049 children = child_controls.GetAllControls ();
3050 for (int i = 0; i < children.Length; i++ ) {
3051 if (children[i].IsHandleCreated) {
3052 XplatUI.SetParent(children[i].Handle, window.Handle);
3056 // Find out where the window manager placed us
3058 if ((CreateParams.Style & (int)WindowStyles.WS_CHILD) != 0) {
3059 XplatUI.SetBorderStyle(window.Handle, (FormBorderStyle)border_style);
3063 OnHandleCreated(EventArgs.Empty);
3068 [EditorBrowsable(EditorBrowsableState.Advanced)]
3069 protected virtual void DefWndProc(ref Message m) {
3070 window.DefWndProc(ref m);
3073 [EditorBrowsable(EditorBrowsableState.Advanced)]
3074 protected virtual void DestroyHandle() {
3075 if (IsHandleCreated) {
3076 if (window != null) {
3077 window.DestroyHandle();
3082 protected bool GetStyle(ControlStyles flag) {
3083 return (control_style & flag) != 0;
3086 protected bool GetTopLevel() {
3090 [EditorBrowsable(EditorBrowsableState.Advanced)]
3091 protected virtual void InitLayout() {
3095 [EditorBrowsable(EditorBrowsableState.Advanced)]
3096 protected void InvokeGotFocus(Control toInvoke, EventArgs e) {
3097 toInvoke.OnGotFocus(e);
3100 [EditorBrowsable(EditorBrowsableState.Advanced)]
3101 protected void InvokeLostFocus(Control toInvoke, EventArgs e) {
3102 toInvoke.OnLostFocus(e);
3105 [EditorBrowsable(EditorBrowsableState.Advanced)]
3106 protected void InvokeOnClick(Control toInvoke, EventArgs e) {
3107 toInvoke.OnClick(e);
3110 protected void InvokePaint(Control toInvoke, PaintEventArgs e) {
3111 toInvoke.OnPaint(e);
3114 protected void InvokePaintBackground(Control toInvoke, PaintEventArgs e) {
3115 toInvoke.OnPaintBackground(e);
3118 protected virtual bool IsInputChar (char charCode) {
3122 protected virtual bool IsInputKey (Keys keyData) {
3123 // Doc says this one calls IsInputChar; not sure what to do with that
3127 [EditorBrowsable(EditorBrowsableState.Advanced)]
3128 protected virtual void NotifyInvalidate(Rectangle invalidatedArea) {
3132 protected virtual bool ProcessCmdKey(ref Message msg, Keys keyData) {
3133 if ((context_menu != null) && context_menu.ProcessCmdKey(ref msg, keyData)) {
3137 if (parent != null) {
3138 return parent.ProcessCmdKey(ref msg, keyData);
3144 protected virtual bool ProcessDialogChar(char charCode) {
3145 if (parent != null) {
3146 return parent.ProcessDialogChar (charCode);
3152 protected virtual bool ProcessDialogKey (Keys keyData) {
3153 if (parent != null) {
3154 return parent.ProcessDialogKey (keyData);
3160 protected virtual bool ProcessKeyEventArgs (ref Message msg)
3162 KeyEventArgs key_event;
3165 case (int)Msg.WM_SYSKEYDOWN:
3166 case (int)Msg.WM_KEYDOWN: {
3167 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
3168 OnKeyDown (key_event);
3169 return key_event.Handled;
3172 case (int)Msg.WM_SYSKEYUP:
3173 case (int)Msg.WM_KEYUP: {
3174 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
3175 OnKeyUp (key_event);
3176 return key_event.Handled;
3179 case (int)Msg.WM_SYSCHAR:
3180 case (int)Msg.WM_CHAR: {
3181 KeyPressEventArgs key_press_event;
3183 key_press_event = new KeyPressEventArgs((char)msg.WParam);
3184 OnKeyPress(key_press_event);
3185 return key_press_event.Handled;
3196 protected internal virtual bool ProcessKeyMessage(ref Message msg) {
3197 if (parent != null) {
3198 if (parent.ProcessKeyPreview(ref msg)) {
3203 return ProcessKeyEventArgs(ref msg);
3206 protected virtual bool ProcessKeyPreview(ref Message msg) {
3207 if (parent != null) {
3208 return parent.ProcessKeyPreview(ref msg);
3214 protected virtual bool ProcessMnemonic(char charCode) {
3219 [EditorBrowsable(EditorBrowsableState.Advanced)]
3220 protected void RaiseDragEvent(object key, DragEventArgs e) {
3224 [EditorBrowsable(EditorBrowsableState.Advanced)]
3225 protected void RaiseKeyEvent(object key, KeyEventArgs e) {
3229 [EditorBrowsable(EditorBrowsableState.Advanced)]
3230 protected void RaiseMouseEvent(object key, MouseEventArgs e) {
3234 [EditorBrowsable(EditorBrowsableState.Advanced)]
3235 protected void RaisePaintEvent(object key, PaintEventArgs e) {
3239 [EditorBrowsable(EditorBrowsableState.Advanced)]
3240 protected void RecreateHandle() {
3241 IEnumerator child = child_controls.GetAllEnumerator();
3245 if (IsHandleCreated) {
3251 while (child.MoveNext()) {
3252 ((Control)child.Current).RecreateHandle();
3258 is_recreating = false;
3261 [EditorBrowsable(EditorBrowsableState.Advanced)]
3262 protected void ResetMouseEventArgs() {
3266 [EditorBrowsable(EditorBrowsableState.Advanced)]
3267 protected ContentAlignment RtlTranslateAlignment(ContentAlignment align) {
3268 if (right_to_left == RightToLeft.No) {
3273 case ContentAlignment.TopLeft: {
3274 return ContentAlignment.TopRight;
3277 case ContentAlignment.TopRight: {
3278 return ContentAlignment.TopLeft;
3281 case ContentAlignment.MiddleLeft: {
3282 return ContentAlignment.MiddleRight;
3285 case ContentAlignment.MiddleRight: {
3286 return ContentAlignment.MiddleLeft;
3289 case ContentAlignment.BottomLeft: {
3290 return ContentAlignment.BottomRight;
3293 case ContentAlignment.BottomRight: {
3294 return ContentAlignment.BottomLeft;
3298 // if it's center it doesn't change
3304 [EditorBrowsable(EditorBrowsableState.Advanced)]
3305 protected HorizontalAlignment RtlTranslateAlignment(HorizontalAlignment align) {
3306 if ((right_to_left == RightToLeft.No) || (align == HorizontalAlignment.Center)) {
3310 if (align == HorizontalAlignment.Left) {
3311 return HorizontalAlignment.Right;
3314 // align must be HorizontalAlignment.Right
3315 return HorizontalAlignment.Left;
3318 [EditorBrowsable(EditorBrowsableState.Advanced)]
3319 protected LeftRightAlignment RtlTranslateAlignment(LeftRightAlignment align) {
3320 if (right_to_left == RightToLeft.No) {
3324 if (align == LeftRightAlignment.Left) {
3325 return LeftRightAlignment.Right;
3328 // align must be LeftRightAlignment.Right;
3329 return LeftRightAlignment.Left;
3332 [EditorBrowsable(EditorBrowsableState.Advanced)]
3333 protected ContentAlignment RtlTranslateContent(ContentAlignment align) {
3334 return RtlTranslateAlignment(align);
3337 [EditorBrowsable(EditorBrowsableState.Advanced)]
3338 protected HorizontalAlignment RtlTranslateHorizontal(HorizontalAlignment align) {
3339 return RtlTranslateAlignment(align);
3342 [EditorBrowsable(EditorBrowsableState.Advanced)]
3343 protected LeftRightAlignment RtlTranslateLeftRight(LeftRightAlignment align) {
3344 return RtlTranslateAlignment(align);
3347 [EditorBrowsable(EditorBrowsableState.Advanced)]
3348 protected virtual void ScaleCore(float dx, float dy) {
3354 location = new Point((int)(Left * dx), (int)(Top * dy));
3355 size = this.ClientSize;
3358 if (!GetStyle(ControlStyles.FixedWidth)) {
3359 size.Width = (int)(size.Width * dx);
3362 if (!GetStyle(ControlStyles.FixedHeight)) {
3363 size.Height = (int)(size.Height * dy);
3366 Location = location;
3369 /* Now scale our children */
3370 Control [] controls = child_controls.GetAllControls ();
3371 for (int i=0; i < controls.Length; i++) {
3372 controls[i].Scale(dx, dy);
3378 protected virtual void Select(bool directed, bool forward) {
3383 // Select this control
3388 if (parent == null) {
3392 // FIXME - this thing is doing the wrong stuff, needs to be similar to SelectNextControl
3394 index = parent.child_controls.IndexOf(this);
3399 if ((index+1) < parent.child_controls.Count) {
3408 index = parent.child_controls.Count-1;
3411 result = Select(parent.child_controls[index]);
3412 } while (!result && parent.child_controls[index] != this);
3415 [EditorBrowsable(EditorBrowsableState.Advanced)]
3416 protected virtual void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
3417 // SetBoundsCore updates the Win32 control itself. UpdateBounds updates the controls variables and fires events, I'm guessing - pdb
3418 if ((specified & BoundsSpecified.X) != BoundsSpecified.X) {
3422 if ((specified & BoundsSpecified.Y) != BoundsSpecified.Y) {
3426 if ((specified & BoundsSpecified.Width) != BoundsSpecified.Width) {
3430 if ((specified & BoundsSpecified.Height) != BoundsSpecified.Height) {
3434 if (IsHandleCreated) {
3435 XplatUI.SetWindowPos(Handle, x, y, width, height);
3438 UpdateBounds(x, y, width, height);
3441 [EditorBrowsable(EditorBrowsableState.Advanced)]
3442 protected virtual void SetClientSizeCore(int x, int y) {
3443 // Calculate the actual window size from the client size (it usually stays the same or grows)
3444 Rectangle ClientRect;
3445 Rectangle WindowRect;
3448 ClientRect = new Rectangle(0, 0, x, y);
3449 cp = this.CreateParams;
3451 if (XplatUI.CalculateWindowRect(Handle, ref ClientRect, cp.Style, cp.ExStyle, null, out WindowRect)==false) {
3455 SetBoundsCore(bounds.X, bounds.Y, WindowRect.Width, WindowRect.Height, BoundsSpecified.Size);
3458 [EditorBrowsable(EditorBrowsableState.Advanced)]
3459 protected void SetStyle(ControlStyles flag, bool value) {
3461 control_style |= flag;
3463 control_style &= ~flag;
3465 OnStyleChanged(EventArgs.Empty);
3468 protected void SetTopLevel(bool value) {
3469 if ((GetTopLevel() != value) && (parent != null)) {
3470 throw new Exception();
3474 if (value == true) {
3484 is_toplevel = value;
3487 protected virtual void SetVisibleCore(bool value) {
3488 if (value!=is_visible) {
3491 if (IsHandleCreated) {
3492 XplatUI.SetVisible(Handle, value);
3493 // Explicitly move Toplevel windows to where we want them;
3494 // apparently moving unmapped toplevel windows doesn't work
3495 if (is_visible && (this is Form)) {
3496 XplatUI.SetWindowPos(window.Handle, bounds.X, bounds.Y, bounds.Width, bounds.Height);
3501 if (dc_mem != null) {
3506 if (bmp_mem != null) {
3511 this.CreateBuffers(bounds.Width, bounds.Height);
3515 OnVisibleChanged(EventArgs.Empty);
3517 if (value == false && parent != null) {
3520 // Need to start at parent, GetContainerControl might return ourselves if we're a container
3521 container = (Control)parent.GetContainerControl();
3522 if (container != null) {
3523 container.SelectNextControl(this, true, true, true, true);
3527 if (parent != null) {
3528 parent.PerformLayout(this, "visible");
3530 PerformLayout(this, "visible");
3535 [EditorBrowsable(EditorBrowsableState.Advanced)]
3536 protected void UpdateBounds() {
3544 if (!IsHandleCreated) {
3548 XplatUI.GetWindowPos(this.Handle, this is Form, out x, out y, out width, out height, out client_width, out client_height);
3550 UpdateBounds(x, y, width, height, client_width, client_height);
3553 [EditorBrowsable(EditorBrowsableState.Advanced)]
3554 protected void UpdateBounds(int x, int y, int width, int height) {
3555 // UpdateBounds only seems to set our sizes and fire events but not update the GUI window to match
3557 bool resized = false;
3559 int client_x_diff = this.bounds.Width-this.client_size.Width;
3560 int client_y_diff = this.bounds.Height-this.client_size.Height;
3562 // Needed to generate required notifications
3563 if ((this.bounds.X!=x) || (this.bounds.Y!=y)) {
3567 if ((this.Bounds.Width!=width) || (this.Bounds.Height!=height)) {
3574 bounds.Height=height;
3576 // Update client rectangle as well
3577 client_size.Width=width-client_x_diff;
3578 client_size.Height=height-client_y_diff;
3583 OnLocationChanged(EventArgs.Empty);
3587 OnSizeChanged(EventArgs.Empty);
3591 [EditorBrowsable(EditorBrowsableState.Advanced)]
3592 protected void UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) {
3593 UpdateBounds(x, y, width, height);
3595 this.client_size.Width=clientWidth;
3596 this.client_size.Height=clientHeight;
3599 [EditorBrowsable(EditorBrowsableState.Advanced)]
3600 protected void UpdateStyles() {
3601 if (!IsHandleCreated) {
3605 XplatUI.SetWindowStyle(window.Handle, CreateParams);
3608 [EditorBrowsable(EditorBrowsableState.Advanced)]
3609 protected void UpdateZOrder() {
3610 Control [] controls;
3611 if (!IsHandleCreated) {
3615 controls = child_controls.GetAllControls ();
3616 for (int i = 1; i < controls.Length; i++ ) {
3617 XplatUI.SetZOrder(controls[i].Handle, controls[i-1].Handle, false, false);
3621 protected virtual void WndProc(ref Message m) {
3623 Console.WriteLine("Control {0} received message {1}", window.Handle == IntPtr.Zero ? this.Text : XplatUI.Window(window.Handle), (Msg)m.Msg);
3625 if ((this.control_style & ControlStyles.EnableNotifyMessage) != 0) {
3629 switch((Msg)m.Msg) {
3630 case Msg.WM_DESTROY: {
3631 OnHandleDestroyed(EventArgs.Empty);
3632 window.InvalidateHandle();
3636 case Msg.WM_WINDOWPOSCHANGED: {
3639 if (GetStyle(ControlStyles.ResizeRedraw)) {
3646 case Msg.WM_PAINT: {
3647 PaintEventArgs paint_event;
3649 paint_event = XplatUI.PaintEventStart(Handle, true);
3651 if (!needs_redraw) {
3652 // Just blit the previous image
3653 paint_event.Graphics.DrawImage (ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle, GraphicsUnit.Pixel);
3654 XplatUI.PaintEventEnd(Handle, true);
3659 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
3660 dc = paint_event.SetGraphics (DeviceContext);
3663 OnPaintBackground(paint_event);
3664 // Leave out for now, our controls can do Paint += ... as well
3665 //OnPaintInternal(paint_event);
3666 OnPaint(paint_event);
3668 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
3669 dc.DrawImage (ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle, GraphicsUnit.Pixel);
3670 paint_event.SetGraphics (dc);
3671 needs_redraw = false;
3674 XplatUI.PaintEventEnd(Handle, true);
3679 case Msg.WM_ERASEBKGND: {
3680 // The DefWndProc will never have to handle this, we always paint the background in managed code
3681 m.Result = (IntPtr)1;
3685 case Msg.WM_LBUTTONUP: {
3686 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Left,
3688 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3690 HandleClick(mouse_clicks);
3691 if (mouse_clicks > 1) {
3697 case Msg.WM_LBUTTONDOWN: {
3698 if (CanSelect && !is_selected) {
3701 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3702 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3708 case Msg.WM_LBUTTONDBLCLK: {
3710 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3711 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3717 case Msg.WM_MBUTTONUP: {
3718 HandleClick(mouse_clicks);
3719 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Middle,
3721 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3723 if (mouse_clicks > 1) {
3729 case Msg.WM_MBUTTONDOWN: {
3730 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3731 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3737 case Msg.WM_MBUTTONDBLCLK: {
3739 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3740 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3745 case Msg.WM_RBUTTONUP: {
3746 if (context_menu != null) {
3747 context_menu.Show(this, new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ())));
3750 HandleClick(mouse_clicks);
3751 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Right,
3753 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3755 if (mouse_clicks > 1) {
3761 case Msg.WM_RBUTTONDOWN: {
3762 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3763 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3768 case Msg.WM_RBUTTONDBLCLK: {
3770 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3771 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3776 case Msg.WM_MOUSEWHEEL: {
3778 OnMouseWheel (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3779 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3780 HighOrder(m.WParam.ToInt32())));
3785 case Msg.WM_MOUSEMOVE: {
3786 OnMouseMove (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3788 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3793 case Msg.WM_MOUSE_ENTER: {
3798 OnMouseEnter(EventArgs.Empty);
3802 case Msg.WM_MOUSE_LEAVE: {
3804 OnMouseLeave(EventArgs.Empty);
3808 case Msg.WM_MOUSEHOVER: {
3809 OnMouseHover(EventArgs.Empty);
3813 case Msg.WM_SYSKEYDOWN:
3814 case Msg.WM_KEYDOWN:
3815 case Msg.WM_SYSKEYUP:
3817 case Msg.WM_SYSCHAR:
3819 if (ProcessKeyMessage(ref m)) {
3823 if ((m.Msg == (int)Msg.WM_SYSKEYUP) && ((m.WParam.ToInt32() & (int)Keys.KeyCode) == (int)Keys.Menu)) {
3827 if (form != null && form.ActiveMenu != null) {
3828 form.ActiveMenu.ProcessCmdKey(ref m, (Keys)m.WParam.ToInt32());
3838 if (m.LParam != IntPtr.Zero) {
3841 hi = new HELPINFO();
3843 hi = (HELPINFO) Marshal.PtrToStructure (m.LParam, typeof (HELPINFO));
3844 mouse_pos = new Point(hi.MousePos.x, hi.MousePos.y);
3846 mouse_pos = Control.MousePosition;
3848 OnHelpRequested(new HelpEventArgs(mouse_pos));
3849 m.Result = (IntPtr)1;
3853 case Msg.WM_KILLFOCUS: {
3854 OnLeave(EventArgs.Empty);
3855 if (CausesValidation) {
3857 e = new CancelEventArgs(false);
3866 OnValidated(EventArgs.Empty);
3869 this.has_focus = false;
3870 this.is_selected = false;
3871 OnLostFocus(EventArgs.Empty);
3875 case Msg.WM_SETFOCUS: {
3876 OnEnter(EventArgs.Empty);
3877 this.has_focus = true;
3878 OnGotFocus(EventArgs.Empty);
3883 case Msg.WM_SYSCOLORCHANGE: {
3884 ThemeEngine.Current.ResetDefaults();
3885 OnSystemColorsChanged(EventArgs.Empty);
3890 case Msg.WM_SETCURSOR: {
3891 if (cursor == null) {
3896 XplatUI.SetCursor(window.Handle, cursor.handle);
3897 m.Result = (IntPtr)1;
3908 #endregion // Public Instance Methods
3910 #region OnXXX methods
3911 [EditorBrowsable(EditorBrowsableState.Advanced)]
3912 protected virtual void OnBackColorChanged(EventArgs e) {
3913 if (BackColorChanged!=null) BackColorChanged(this, e);
3914 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackColorChanged(e);
3917 [EditorBrowsable(EditorBrowsableState.Advanced)]
3918 protected virtual void OnBackgroundImageChanged(EventArgs e) {
3919 if (BackgroundImageChanged!=null) BackgroundImageChanged(this, e);
3920 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackgroundImageChanged(e);
3923 [EditorBrowsable(EditorBrowsableState.Advanced)]
3924 protected virtual void OnBindingContextChanged(EventArgs e) {
3925 CheckDataBindings ();
3926 if (BindingContextChanged!=null) {
3927 BindingContextChanged(this, e);
3929 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBindingContextChanged(e);
3932 [EditorBrowsable(EditorBrowsableState.Advanced)]
3933 protected virtual void OnCausesValidationChanged(EventArgs e) {
3934 if (CausesValidationChanged!=null) CausesValidationChanged(this, e);
3937 [EditorBrowsable(EditorBrowsableState.Advanced)]
3938 protected virtual void OnChangeUICues(UICuesEventArgs e) {
3939 if (ChangeUICues!=null) ChangeUICues(this, e);
3942 [EditorBrowsable(EditorBrowsableState.Advanced)]
3943 protected virtual void OnClick(EventArgs e) {
3944 if (Click!=null) Click(this, e);
3947 [EditorBrowsable(EditorBrowsableState.Advanced)]
3948 protected virtual void OnContextMenuChanged(EventArgs e) {
3949 if (ContextMenuChanged!=null) ContextMenuChanged(this, e);
3952 [EditorBrowsable(EditorBrowsableState.Advanced)]
3953 protected virtual void OnControlAdded(ControlEventArgs e) {
3954 if (ControlAdded!=null) ControlAdded(this, e);
3957 [EditorBrowsable(EditorBrowsableState.Advanced)]
3958 protected virtual void OnControlRemoved(ControlEventArgs e) {
3959 if (ControlRemoved!=null) ControlRemoved(this, e);
3962 [EditorBrowsable(EditorBrowsableState.Advanced)]
3963 protected virtual void OnCreateControl() {
3967 [EditorBrowsable(EditorBrowsableState.Advanced)]
3968 protected virtual void OnCursorChanged(EventArgs e) {
3969 if (CursorChanged!=null) CursorChanged(this, e);
3972 [EditorBrowsable(EditorBrowsableState.Advanced)]
3973 protected virtual void OnDockChanged(EventArgs e) {
3974 if (DockChanged!=null) DockChanged(this, e);
3977 [EditorBrowsable(EditorBrowsableState.Advanced)]
3978 protected virtual void OnDoubleClick(EventArgs e) {
3979 if (DoubleClick!=null) DoubleClick(this, e);
3982 [EditorBrowsable(EditorBrowsableState.Advanced)]
3983 protected virtual void OnDragDrop(DragEventArgs drgevent) {
3984 if (DragDrop!=null) DragDrop(this, drgevent);
3987 [EditorBrowsable(EditorBrowsableState.Advanced)]
3988 protected virtual void OnDragEnter(DragEventArgs drgevent) {
3989 if (DragEnter!=null) DragEnter(this, drgevent);
3992 [EditorBrowsable(EditorBrowsableState.Advanced)]
3993 protected virtual void OnDragLeave(EventArgs e) {
3994 if (DragLeave!=null) DragLeave(this, e);
3997 [EditorBrowsable(EditorBrowsableState.Advanced)]
3998 protected virtual void OnDragOver(DragEventArgs drgevent) {
3999 if (DragOver!=null) DragOver(this, drgevent);
4002 [EditorBrowsable(EditorBrowsableState.Advanced)]
4003 protected virtual void OnEnabledChanged(EventArgs e) {
4004 if (EnabledChanged!=null) EnabledChanged(this, e);
4005 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentEnabledChanged(e);
4008 [EditorBrowsable(EditorBrowsableState.Advanced)]
4009 protected virtual void OnEnter(EventArgs e) {
4010 if (Enter!=null) Enter(this, e);
4013 [EditorBrowsable(EditorBrowsableState.Advanced)]
4014 protected virtual void OnFontChanged(EventArgs e) {
4015 if (FontChanged!=null) FontChanged(this, e);
4016 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentFontChanged(e);
4019 [EditorBrowsable(EditorBrowsableState.Advanced)]
4020 protected virtual void OnForeColorChanged(EventArgs e) {
4021 if (ForeColorChanged!=null) ForeColorChanged(this, e);
4022 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentForeColorChanged(e);
4025 [EditorBrowsable(EditorBrowsableState.Advanced)]
4026 protected virtual void OnGiveFeedback(GiveFeedbackEventArgs gfbevent) {
4027 if (GiveFeedback!=null) GiveFeedback(this, gfbevent);
4030 [EditorBrowsable(EditorBrowsableState.Advanced)]
4031 protected virtual void OnGotFocus(EventArgs e) {
4032 if (GotFocus!=null) GotFocus(this, e);
4035 [EditorBrowsable(EditorBrowsableState.Advanced)]
4036 protected virtual void OnHandleCreated(EventArgs e) {
4037 if (HandleCreated!=null) HandleCreated(this, e);
4040 [EditorBrowsable(EditorBrowsableState.Advanced)]
4041 protected virtual void OnHandleDestroyed(EventArgs e) {
4042 if (HandleDestroyed!=null) HandleDestroyed(this, e);
4045 [EditorBrowsable(EditorBrowsableState.Advanced)]
4046 protected virtual void OnHelpRequested(HelpEventArgs hevent) {
4047 if (HelpRequested!=null) HelpRequested(this, hevent);
4050 protected virtual void OnImeModeChanged(EventArgs e) {
4051 if (ImeModeChanged!=null) ImeModeChanged(this, e);
4054 [EditorBrowsable(EditorBrowsableState.Advanced)]
4055 protected virtual void OnInvalidated(InvalidateEventArgs e) {
4056 needs_redraw = true;
4057 if (Invalidated!=null) Invalidated(this, e);
4060 [EditorBrowsable(EditorBrowsableState.Advanced)]
4061 protected virtual void OnKeyDown(KeyEventArgs e) {
4062 if (KeyDown!=null) KeyDown(this, e);
4065 [EditorBrowsable(EditorBrowsableState.Advanced)]
4066 protected virtual void OnKeyPress(KeyPressEventArgs e) {
4067 if (KeyPress!=null) KeyPress(this, e);
4070 [EditorBrowsable(EditorBrowsableState.Advanced)]
4071 protected virtual void OnKeyUp(KeyEventArgs e) {
4072 if (KeyUp!=null) KeyUp(this, e);
4075 [EditorBrowsable(EditorBrowsableState.Advanced)]
4076 protected virtual void OnLayout(LayoutEventArgs levent) {
4077 if (Layout!=null) Layout(this, levent);
4080 [EditorBrowsable(EditorBrowsableState.Advanced)]
4081 protected virtual void OnLeave(EventArgs e) {
4082 if (Leave!=null) Leave(this, e);
4085 [EditorBrowsable(EditorBrowsableState.Advanced)]
4086 protected virtual void OnLocationChanged(EventArgs e) {
4088 if (LocationChanged!=null) LocationChanged(this, e);
4091 [EditorBrowsable(EditorBrowsableState.Advanced)]
4092 protected virtual void OnLostFocus(EventArgs e) {
4093 if (LostFocus!=null) LostFocus(this, e);
4096 [EditorBrowsable(EditorBrowsableState.Advanced)]
4097 protected virtual void OnMouseDown(MouseEventArgs e) {
4098 if (MouseDown!=null) MouseDown(this, e);
4101 [EditorBrowsable(EditorBrowsableState.Advanced)]
4102 protected virtual void OnMouseEnter(EventArgs e) {
4103 if (MouseEnter!=null) MouseEnter(this, e);
4106 [EditorBrowsable(EditorBrowsableState.Advanced)]
4107 protected virtual void OnMouseHover(EventArgs e) {
4108 if (MouseHover!=null) MouseHover(this, e);
4111 [EditorBrowsable(EditorBrowsableState.Advanced)]
4112 protected virtual void OnMouseLeave(EventArgs e) {
4113 if (MouseLeave!=null) MouseLeave(this, e);
4116 [EditorBrowsable(EditorBrowsableState.Advanced)]
4117 protected virtual void OnMouseMove(MouseEventArgs e) {
4118 if (MouseMove!=null) MouseMove(this, e);
4121 [EditorBrowsable(EditorBrowsableState.Advanced)]
4122 protected virtual void OnMouseUp(MouseEventArgs e) {
4123 if (MouseUp!=null) MouseUp(this, e);
4126 [EditorBrowsable(EditorBrowsableState.Advanced)]
4127 protected virtual void OnMouseWheel(MouseEventArgs e) {
4128 if (MouseWheel!=null) MouseWheel(this, e);
4131 [EditorBrowsable(EditorBrowsableState.Advanced)]
4132 protected virtual void OnMove(EventArgs e) {
4133 if (Move!=null) Move(this, e);
4136 [EditorBrowsable(EditorBrowsableState.Advanced)]
4137 protected virtual void OnNotifyMessage(Message m) {
4141 [EditorBrowsable(EditorBrowsableState.Advanced)]
4142 protected virtual void OnPaint(PaintEventArgs e) {
4143 if (Paint!=null) Paint(this, e);
4146 internal virtual void OnPaintInternal(PaintEventArgs e) {
4150 [EditorBrowsable(EditorBrowsableState.Advanced)]
4151 protected virtual void OnPaintBackground(PaintEventArgs pevent) {
4152 PaintControlBackground (pevent);
4155 [EditorBrowsable(EditorBrowsableState.Advanced)]
4156 protected virtual void OnParentBackColorChanged(EventArgs e) {
4157 if (background_color.IsEmpty && background_image==null) {
4159 OnBackColorChanged(e);
4163 [EditorBrowsable(EditorBrowsableState.Advanced)]
4164 protected virtual void OnParentBackgroundImageChanged(EventArgs e) {
4165 if (background_color.IsEmpty && background_image==null) {
4167 OnBackgroundImageChanged(e);
4171 [EditorBrowsable(EditorBrowsableState.Advanced)]
4172 protected virtual void OnParentBindingContextChanged(EventArgs e) {
4173 if (binding_context==null) {
4174 binding_context=Parent.binding_context;
4175 OnBindingContextChanged(e);
4179 [EditorBrowsable(EditorBrowsableState.Advanced)]
4180 protected virtual void OnParentChanged(EventArgs e) {
4181 if (ParentChanged!=null) ParentChanged(this, e);
4184 [EditorBrowsable(EditorBrowsableState.Advanced)]
4185 protected virtual void OnParentEnabledChanged(EventArgs e) {
4186 if (is_enabled != Parent.is_enabled) {
4187 is_enabled=Parent.is_enabled;
4189 if (EnabledChanged != null) {
4190 EnabledChanged(this, e);
4195 [EditorBrowsable(EditorBrowsableState.Advanced)]
4196 protected virtual void OnParentFontChanged(EventArgs e) {
4203 [EditorBrowsable(EditorBrowsableState.Advanced)]
4204 protected virtual void OnParentForeColorChanged(EventArgs e) {
4205 if (foreground_color.IsEmpty) {
4207 OnForeColorChanged(e);
4211 [EditorBrowsable(EditorBrowsableState.Advanced)]
4212 protected virtual void OnParentRightToLeftChanged(EventArgs e) {
4213 if (right_to_left==RightToLeft.Inherit) {
4215 OnRightToLeftChanged(e);
4219 [EditorBrowsable(EditorBrowsableState.Advanced)]
4220 protected virtual void OnParentVisibleChanged(EventArgs e) {
4222 OnVisibleChanged(e);
4226 [EditorBrowsable(EditorBrowsableState.Advanced)]
4227 protected virtual void OnQueryContinueDrag(QueryContinueDragEventArgs e) {
4228 if (QueryContinueDrag!=null) QueryContinueDrag(this, e);
4231 [EditorBrowsable(EditorBrowsableState.Advanced)]
4232 protected virtual void OnResize(EventArgs e) {
4233 if (Resize!=null) Resize(this, e);
4235 PerformLayout(this, "bounds");
4237 if (parent != null) {
4238 parent.PerformLayout();
4242 [EditorBrowsable(EditorBrowsableState.Advanced)]
4243 protected virtual void OnRightToLeftChanged(EventArgs e) {
4244 if (RightToLeftChanged!=null) RightToLeftChanged(this, e);
4245 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentRightToLeftChanged(e);
4248 [EditorBrowsable(EditorBrowsableState.Advanced)]
4249 protected virtual void OnSizeChanged(EventArgs e) {
4250 InvalidateBuffers ();
4252 if (SizeChanged!=null) SizeChanged(this, e);
4255 [EditorBrowsable(EditorBrowsableState.Advanced)]
4256 protected virtual void OnStyleChanged(EventArgs e) {
4257 if (StyleChanged!=null) StyleChanged(this, e);
4260 [EditorBrowsable(EditorBrowsableState.Advanced)]
4261 protected virtual void OnSystemColorsChanged(EventArgs e) {
4262 if (SystemColorsChanged!=null) SystemColorsChanged(this, e);
4265 [EditorBrowsable(EditorBrowsableState.Advanced)]
4266 protected virtual void OnTabIndexChanged(EventArgs e) {
4267 if (TabIndexChanged!=null) TabIndexChanged(this, e);
4270 [EditorBrowsable(EditorBrowsableState.Advanced)]
4271 protected virtual void OnTabStopChanged(EventArgs e) {
4272 if (TabStopChanged!=null) TabStopChanged(this, e);
4275 [EditorBrowsable(EditorBrowsableState.Advanced)]
4276 protected virtual void OnTextChanged(EventArgs e) {
4277 if (TextChanged!=null) TextChanged(this, e);
4280 [EditorBrowsable(EditorBrowsableState.Advanced)]
4281 protected virtual void OnValidated(EventArgs e) {
4282 if (Validated!=null) Validated(this, e);
4285 [EditorBrowsable(EditorBrowsableState.Advanced)]
4286 protected virtual void OnValidating(System.ComponentModel.CancelEventArgs e) {
4287 if (Validating!=null) Validating(this, e);
4290 [EditorBrowsable(EditorBrowsableState.Advanced)]
4291 protected virtual void OnVisibleChanged(EventArgs e) {
4298 if (bmp_mem!=null) {
4304 if (!this.IsHandleCreated) {
4305 this.CreateControl();
4311 if (VisibleChanged!=null) VisibleChanged(this, e);
4313 // We need to tell our kids
4314 for (int i=0; i<child_controls.Count; i++) {
4315 child_controls[i].OnParentVisibleChanged(e);
4318 #endregion // OnXXX methods
4321 public event EventHandler BackColorChanged;
4322 public event EventHandler BackgroundImageChanged;
4323 public event EventHandler BindingContextChanged;
4324 public event EventHandler CausesValidationChanged;
4325 public event UICuesEventHandler ChangeUICues;
4326 public event EventHandler Click;
4327 public event EventHandler ContextMenuChanged;
4329 [EditorBrowsable(EditorBrowsableState.Advanced)]
4331 public event ControlEventHandler ControlAdded;
4333 [EditorBrowsable(EditorBrowsableState.Advanced)]
4335 public event ControlEventHandler ControlRemoved;
4337 [MWFDescription("Fired when the cursor for the control has been changed"), MWFCategory("PropertyChanged")]
4338 public event EventHandler CursorChanged;
4339 public event EventHandler DockChanged;
4340 public event EventHandler DoubleClick;
4341 public event DragEventHandler DragDrop;
4342 public event DragEventHandler DragEnter;
4343 public event EventHandler DragLeave;
4344 public event DragEventHandler DragOver;
4345 public event EventHandler EnabledChanged;
4346 public event EventHandler Enter;
4347 public event EventHandler FontChanged;
4348 public event EventHandler ForeColorChanged;
4349 public event GiveFeedbackEventHandler GiveFeedback;
4351 [EditorBrowsable(EditorBrowsableState.Advanced)]
4353 public event EventHandler GotFocus;
4355 [EditorBrowsable(EditorBrowsableState.Advanced)]
4357 public event EventHandler HandleCreated;
4359 [EditorBrowsable(EditorBrowsableState.Advanced)]
4361 public event EventHandler HandleDestroyed;
4363 public event HelpEventHandler HelpRequested;
4364 public event EventHandler ImeModeChanged;
4366 [EditorBrowsable(EditorBrowsableState.Advanced)]
4368 public event InvalidateEventHandler Invalidated;
4370 public event KeyEventHandler KeyDown;
4371 public event KeyPressEventHandler KeyPress;
4372 public event KeyEventHandler KeyUp;
4373 public event LayoutEventHandler Layout;
4374 public event EventHandler Leave;
4375 public event EventHandler LocationChanged;
4377 [EditorBrowsable(EditorBrowsableState.Advanced)]
4379 public event EventHandler LostFocus;
4381 public event MouseEventHandler MouseDown;
4382 public event EventHandler MouseEnter;
4383 public event EventHandler MouseHover;
4384 public event EventHandler MouseLeave;
4385 public event MouseEventHandler MouseMove;
4386 public event MouseEventHandler MouseUp;
4388 [EditorBrowsable(EditorBrowsableState.Advanced)]
4390 public event MouseEventHandler MouseWheel;
4392 public event EventHandler Move;
4393 public event PaintEventHandler Paint;
4394 public event EventHandler ParentChanged;
4395 public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp;
4396 public event QueryContinueDragEventHandler QueryContinueDrag;
4397 public event EventHandler Resize;
4398 public event EventHandler RightToLeftChanged;
4399 public event EventHandler SizeChanged;
4400 public event EventHandler StyleChanged;
4401 public event EventHandler SystemColorsChanged;
4402 public event EventHandler TabIndexChanged;
4403 public event EventHandler TabStopChanged;
4404 public event EventHandler TextChanged;
4405 public event EventHandler Validated;
4406 public event CancelEventHandler Validating;
4407 public event EventHandler VisibleChanged;
4408 #endregion // Events