1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 // Copyright (c) 2004-2006 Novell, Inc.
23 // Peter Bartok pbartok@novell.com
25 // Partially based on work by:
26 // Aleksey Ryabchuk ryabchuk@yahoo.com
27 // Alexandre Pigolkine pigolkine@gmx.de
28 // Dennis Hayes dennish@raytek.com
29 // Jaak Simm jaaksimm@firm.ee
30 // John Sohn jsohn@columbus.rr.com
36 using System.ComponentModel;
37 using System.ComponentModel.Design;
38 using System.ComponentModel.Design.Serialization;
39 using System.Collections;
40 using System.Diagnostics;
42 using System.Drawing.Drawing2D;
43 using System.Reflection;
44 using System.Runtime.InteropServices;
45 using System.Security;
46 using System.Threading;
49 namespace System.Windows.Forms
51 [Designer("System.Windows.Forms.Design.ControlDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
52 [DefaultProperty("Text")]
53 [DefaultEvent("Click")]
54 [DesignerSerializer("System.Windows.Forms.Design.ControlCodeDomSerializer, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
55 [ToolboxItemFilter("System.Windows.Forms")]
56 public class Control : Component, ISynchronizeInvoke, IWin32Window
58 #region Local Variables
61 internal Rectangle bounds; // bounding rectangle for control (client area + decorations)
62 internal object creator_thread; // thread that created the control
63 internal ControlNativeWindow window; // object for native window handle
64 internal string name; // for object naming
67 internal bool is_created; // true if OnCreateControl has been sent
68 internal bool has_focus; // true if control has focus
69 internal bool is_visible; // true if control is visible
70 internal bool is_entered; // is the mouse inside the control?
71 internal bool is_enabled; // true if control is enabled (usable/not grayed out)
72 internal bool is_selected; // true if control is selected
73 internal bool is_accessible; // true if the control is visible to accessibility applications
74 internal bool is_captured; // tracks if the control has captured the mouse
75 internal bool is_toplevel; // tracks if the control is a toplevel window
76 internal bool is_recreating; // tracks if the handle for the control is being recreated
77 internal bool causes_validation; // tracks if validation is executed on changes
78 internal int tab_index; // position in tab order of siblings
79 internal bool tab_stop = true; // is the control a tab stop?
80 internal bool is_disposed; // has the window already been disposed?
81 internal Size client_size; // size of the client area (window excluding decorations)
82 internal Rectangle client_rect; // rectangle with the client area (window excluding decorations)
83 internal ControlStyles control_style; // rather win32-specific, style bits for control
84 internal ImeMode ime_mode = ImeMode.Inherit;
85 internal bool layout_pending; // true if our parent needs to re-layout us
86 internal object control_tag; // object that contains data about our control
87 internal int mouse_clicks; // Counter for mouse clicks
88 internal Cursor cursor; // Cursor for the window
89 internal bool allow_drop; // true if the control accepts droping objects on it
92 internal Color foreground_color; // foreground color for control
93 internal Color background_color; // background color for control
94 internal Image background_image; // background image for control
95 internal Font font; // font for control
96 internal string text; // window/title text for control
97 internal BorderStyle border_style; // Border style of control
100 internal AnchorStyles anchor_style; // anchoring requirements for our control
101 internal DockStyle dock_style; // docking requirements for our control (supercedes anchoring)
102 internal int dist_left; // distance to the left border of the parent
103 internal int dist_top; // distance to the top border of the parent
104 internal int dist_right; // distance to the right border of the parent
105 internal int dist_bottom; // distance to the bottom border of the parent
107 // to be categorized...
108 static internal ArrayList controls = new ArrayList(); // All of the application's controls, in a flat list
109 internal ControlCollection child_controls; // our children
110 internal Control parent; // our parent control
111 internal AccessibleObject accessibility_object; // object that contains accessibility information about our control
112 internal BindingContext binding_context; // TODO
113 internal RightToLeft right_to_left; // drawing direction for control
114 internal int layout_suspended;
115 internal ContextMenu context_menu; // Context menu associated with the control
117 private Graphics dc_mem; // Graphics context for double buffering
118 private Bitmap bmp_mem; // Bitmap for double buffering control
119 private bool needs_redraw = true;
121 private ControlBindingsCollection data_bindings;
124 internal bool use_compatible_text_rendering;
125 private Padding padding;
128 #endregion // Local Variables
130 #region Private Classes
131 // This helper class allows us to dispatch messages to Control.WndProc
132 internal class ControlNativeWindow : NativeWindow {
133 private Control owner;
135 public ControlNativeWindow(Control control) : base() {
140 public Control Owner {
146 static internal Control ControlFromHandle(IntPtr hWnd) {
147 ControlNativeWindow window;
149 window = (ControlNativeWindow)window_collection[hWnd];
150 if (window != null) {
157 protected override void WndProc(ref Message m) {
158 owner.WndProc(ref m);
163 #region Public Classes
165 public class ControlAccessibleObject : AccessibleObject {
166 #region ControlAccessibleObject Local Variables
167 private Control owner;
168 #endregion // ControlAccessibleObject Local Variables
170 #region ControlAccessibleObject Constructors
171 public ControlAccessibleObject(Control ownerControl) {
172 this.owner = ownerControl;
174 #endregion // ControlAccessibleObject Constructors
176 #region ControlAccessibleObject Public Instance Properties
177 public override string DefaultAction {
179 return base.DefaultAction;
183 public override string Description {
185 return base.Description;
189 public IntPtr Handle {
195 // We don't want to let them set it
199 public override string Help {
205 public override string KeyboardShortcut {
207 return base.KeyboardShortcut;
211 public override string Name {
221 public Control Owner {
227 public override AccessibleObject Parent {
234 public override AccessibleRole Role {
239 #endregion // ControlAccessibleObject Public Instance Properties
241 #region ControlAccessibleObject Public Instance Methods
242 public override int GetHelpTopic(out string FileName) {
243 return base.GetHelpTopic (out FileName);
246 [MonoTODO("Implement this and tie it into Control.AccessibilityNotifyClients")]
247 public void NotifyClients(AccessibleEvents accEvent) {
248 throw new NotImplementedException();
251 [MonoTODO("Implement this and tie it into Control.AccessibilityNotifyClients")]
252 public void NotifyClients(AccessibleEvents accEvent, int childID) {
253 throw new NotImplementedException();
256 public override string ToString() {
257 return "ControlAccessibleObject: Owner = " + owner.ToString() + ", Text: " + owner.text;
260 #endregion // ControlAccessibleObject Public Instance Methods
263 [DesignerSerializer("System.Windows.Forms.Design.ControlCollectionCodeDomSerializer, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
264 [ListBindable(false)]
265 public class ControlCollection : IList, ICollection, ICloneable, IEnumerable {
266 #region ControlCollection Local Variables
267 private ArrayList list;
268 internal ArrayList impl_list;
269 private Control [] all_controls;
270 internal Control owner;
271 #endregion // ControlCollection Local Variables
273 #region ControlCollection Public Constructor
274 public ControlCollection(Control owner) {
276 this.list=new ArrayList();
280 #region ControlCollection Public Instance Properties
287 public virtual bool IsReadOnly {
289 return list.IsReadOnly;
293 public virtual Control this[int index] {
295 if (index < 0 || index >= list.Count) {
296 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
298 return (Control)list[index];
301 #endregion // ControlCollection Public Instance Properties
303 #region ControlCollection Private Instance Methods
304 public virtual void Add (Control value)
309 if (Contains (value)) {
310 owner.PerformLayout();
314 if (value.tab_index == -1) {
320 end = owner.child_controls.Count;
321 for (int i = 0; i < end; i++) {
322 index = owner.child_controls[i].tab_index;
327 value.tab_index = use;
330 if (value.parent != null) {
331 value.parent.Controls.Remove(value);
337 value.ChangeParent(owner);
341 owner.UpdateZOrder();
342 owner.PerformLayout(value, "Parent");
343 owner.OnControlAdded(new ControlEventArgs(value));
346 internal void AddToList (Control c)
352 internal virtual void AddImplicit (Control control)
354 if (impl_list == null)
355 impl_list = new ArrayList ();
357 impl_list.Add (control);
359 control.ChangeParent (owner);
360 control.InitLayout ();
361 owner.UpdateZOrder ();
362 owner.PerformLayout (control, "Parent");
363 owner.OnControlAdded (new ControlEventArgs (control));
366 public virtual void AddRange (Control[] controls)
368 if (controls == null)
369 throw new ArgumentNullException ("controls");
371 owner.SuspendLayout ();
374 for (int i = 0; i < controls.Length; i++)
377 owner.ResumeLayout ();
381 internal virtual void AddRangeImplicit (Control [] controls)
383 if (controls == null)
384 throw new ArgumentNullException ("controls");
386 owner.SuspendLayout ();
389 for (int i = 0; i < controls.Length; i++)
390 AddImplicit (controls [i]);
392 owner.ResumeLayout ();
396 public virtual void Clear ()
400 // MS sends remove events in reverse order
401 while (list.Count > 0) {
402 RemoveAt(list.Count - 1);
406 internal virtual void ClearImplicit ()
408 if (impl_list == null)
414 public bool Contains (Control value)
416 for (int i = list.Count; i > 0; ) {
419 if (list [i] == value) {
420 // Do we need to do anything here?
427 internal bool ImplicitContains (Control value)
429 if (impl_list == null)
432 for (int i = impl_list.Count; i > 0; ) {
435 if (impl_list [i] == value) {
436 // Do we need to do anything here?
443 internal bool AllContains (Control value)
445 return Contains (value) || ImplicitContains (value);
448 public virtual void CopyTo (Array array, int index)
450 list.CopyTo(array, index);
453 public override bool Equals(object other) {
454 if (other is ControlCollection && (((ControlCollection)other).owner==this.owner)) {
461 public int GetChildIndex(Control child) {
462 return GetChildIndex(child, false);
465 public int GetChildIndex(Control child, bool throwException) {
468 index=list.IndexOf(child);
470 if (index==-1 && throwException) {
471 throw new ArgumentException("Not a child control", "child");
476 public IEnumerator GetEnumerator() {
477 return list.GetEnumerator();
480 internal IEnumerator GetAllEnumerator ()
482 Control [] res = GetAllControls ();
483 return res.GetEnumerator ();
486 internal Control [] GetAllControls ()
488 if (all_controls != null)
491 if (impl_list == null)
492 return (Control []) list.ToArray (typeof (Control));
494 Control [] res = new Control [list.Count + impl_list.Count];
495 impl_list.CopyTo (res);
496 list.CopyTo (res, impl_list.Count);
501 public override int GetHashCode() {
502 return base.GetHashCode();
505 public int IndexOf(Control control) {
506 return list.IndexOf(control);
509 public virtual void Remove(Control value) {
512 owner.PerformLayout(value, "Parent");
513 owner.OnControlRemoved(new ControlEventArgs(value));
516 value.ChangeParent(null);
518 owner.UpdateZOrder();
521 internal virtual void RemoveImplicit (Control control)
523 if (impl_list != null) {
525 owner.PerformLayout (control, "Parent");
526 owner.OnControlRemoved (new ControlEventArgs (control));
527 impl_list.Remove (control);
529 control.ChangeParent (null);
530 owner.UpdateZOrder ();
533 public void RemoveAt(int index) {
534 if (index < 0 || index >= list.Count) {
535 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
537 Remove ((Control)list[index]);
540 public void SetChildIndex(Control child, int newIndex) {
543 old_index=list.IndexOf(child);
545 throw new ArgumentException("Not a child control", "child");
548 if (old_index==newIndex) {
552 list.RemoveAt(old_index);
554 if (newIndex>list.Count) {
557 list.Insert(newIndex, child);
559 owner.UpdateZOrder();
561 #endregion // ControlCollection Private Instance Methods
563 #region ControlCollection Interface Properties
564 object IList.this[int index] {
566 if (index<0 || index>=list.Count) {
567 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
573 if (!(value is Control)) {
574 throw new ArgumentException("Object of type Control required", "value");
577 list[index]=(Control)value;
581 bool IList.IsFixedSize {
587 bool IList.IsReadOnly {
589 return list.IsReadOnly;
593 bool ICollection.IsSynchronized {
595 return list.IsSynchronized;
599 object ICollection.SyncRoot {
601 return list.SyncRoot;
604 #endregion // ControlCollection Interface Properties
606 #region ControlCollection Interface Methods
607 int IList.Add(object value) {
609 throw new ArgumentNullException("value", "Cannot add null controls");
612 if (!(value is Control)) {
613 throw new ArgumentException("Object of type Control required", "value");
616 return list.Add(value);
619 bool IList.Contains(object value) {
620 if (!(value is Control)) {
621 throw new ArgumentException("Object of type Control required", "value");
624 return this.Contains((Control) value);
627 int IList.IndexOf(object value) {
628 if (!(value is Control)) {
629 throw new ArgumentException("Object of type Control required", "value");
632 return this.IndexOf((Control) value);
635 void IList.Insert(int index, object value) {
636 if (!(value is Control)) {
637 throw new ArgumentException("Object of type Control required", "value");
640 list.Insert(index, value);
643 void IList.Remove(object value) {
644 if (!(value is Control)) {
645 throw new ArgumentException("Object of type Control required", "value");
651 void ICollection.CopyTo(Array array, int index) {
653 list.CopyTo(array, index);
657 Object ICloneable.Clone() {
658 ControlCollection clone = new ControlCollection(this.owner);
659 clone.list=(ArrayList)list.Clone(); // FIXME: Do we need this?
662 #endregion // ControlCollection Interface Methods
664 #endregion // ControlCollection Class
666 #region Public Constructors
669 anchor_style = AnchorStyles.Top | AnchorStyles.Left;
677 layout_pending = false;
679 causes_validation = true;
681 layout_suspended = 0;
685 right_to_left = RightToLeft.Inherit;
686 border_style = BorderStyle.None;
687 background_color = Color.Empty;
694 use_compatible_text_rendering = Application.use_compatible_text_rendering;
695 padding = new Padding(0);
698 control_style = ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint |
699 ControlStyles.Selectable | ControlStyles.StandardClick |
700 ControlStyles.StandardDoubleClick;
703 background_image = null;
707 window = new ControlNativeWindow(this);
708 child_controls = CreateControlsInstance();
709 client_size = new Size(DefaultSize.Width, DefaultSize.Height);
710 client_rect = new Rectangle(0, 0, DefaultSize.Width, DefaultSize.Height);
711 XplatUI.CalculateWindowRect(ref client_rect, CreateParams.Style, CreateParams.ExStyle, null, out bounds);
712 if ((CreateParams.Style & (int)WindowStyles.WS_CHILD) == 0) {
718 public Control(Control parent, string text) : this() {
723 public Control(Control parent, string text, int left, int top, int width, int height) : this() {
728 bounds.Height=height;
729 SetBoundsCore(left, top, width, height, BoundsSpecified.All);
733 public Control(string text) : this() {
737 public Control(string text, int left, int top, int width, int height) : this() {
741 bounds.Height=height;
742 SetBoundsCore(left, top, width, height, BoundsSpecified.All);
746 private delegate void RemoveDelegate(object c);
748 protected override void Dispose(bool disposing) {
760 if (this.InvokeRequired) {
761 if (Application.MessageLoop) {
762 this.BeginInvokeInternal(new MethodInvoker(DestroyHandle), null, true);
763 this.BeginInvokeInternal(new RemoveDelegate(controls.Remove), new object[] {this}, true);
767 controls.Remove(this);
770 #endregion // Public Constructors
772 #region Internal Properties
773 internal BorderStyle InternalBorderStyle {
779 if (!Enum.IsDefined (typeof (BorderStyle), value))
780 throw new InvalidEnumArgumentException (string.Format("Enum argument value '{0}' is not valid for BorderStyle", value));
782 if (border_style != value) {
783 border_style = value;
785 if (IsHandleCreated) {
786 XplatUI.SetBorderStyle(window.Handle, (FormBorderStyle)border_style);
792 #endregion // Internal Properties
794 #region Private & Internal Methods
795 internal IAsyncResult BeginInvokeInternal (Delegate method, object [] args, bool disposing) {
796 AsyncMethodResult result;
797 AsyncMethodData data;
804 if (!p.IsHandleCreated) {
805 throw new InvalidOperationException("Cannot call Invoke or InvokeAsync on a control until the window handle is created");
811 result = new AsyncMethodResult ();
812 data = new AsyncMethodData ();
814 data.Method = method;
816 data.Result = result;
819 if (!ExecutionContext.IsFlowSuppressed ()) {
820 data.Context = ExecutionContext.Capture ();
823 #if !MWF_ON_MSRUNTIME
824 if (SecurityManager.SecurityEnabled) {
825 data.Stack = CompressedStack.GetCompressedStack ();
830 XplatUI.SendAsyncMethod (data);
835 internal void PointToClient (ref int x, ref int y)
837 XplatUI.ScreenToClient (Handle, ref x, ref y);
840 internal void PointToScreen (ref int x, ref int y)
842 XplatUI.ClientToScreen (Handle, ref x, ref y);
845 private bool IsRecreating {
851 if (parent != null) {
852 return parent.IsRecreating;
859 private bool ParentIsRecreating {
861 if (parent != null) {
862 return parent.IsRecreating;
868 internal Graphics DeviceContext {
871 CreateBuffers(this.Width, this.Height);
877 private Bitmap ImageBuffer {
880 CreateBuffers(this.Width, this.Height);
886 internal void CreateBuffers (int width, int height) {
887 if (dc_mem != null) {
901 bmp_mem = new Bitmap (width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
902 dc_mem = Graphics.FromImage (bmp_mem);
906 internal void InvalidateBuffers ()
908 if (dc_mem != null) {
919 internal static void SetChildColor(Control parent) {
922 for (int i=0; i < parent.child_controls.Count; i++) {
923 child=parent.child_controls[i];
924 if (child.child_controls.Count>0) {
925 SetChildColor(child);
931 internal bool Select(Control control) {
933 IContainerControl container;
935 if (control == null) {
939 parent = control.parent;
941 if (((control.control_style & ControlStyles.Selectable) !=0) && (parent != null)) {
942 while (parent != null) {
943 if (!parent.Visible || !parent.is_enabled) {
946 parent = parent.parent;
950 control.is_selected = true;
952 container = GetContainerControl();
953 if (container != null) {
954 container.ActiveControl = control;
956 if (control.IsHandleCreated) {
957 XplatUI.SetFocus(control.window.Handle);
962 internal virtual void DoDefaultAction() {
963 // Only here to be overriden by our actual controls; this is needed by the accessibility class
966 internal static int LowOrder (int param) {
967 return ((int)(short)(param & 0xffff));
970 internal static int HighOrder (int param) {
971 return ((int)(short)(param >> 16));
974 // This method exists so controls overriding OnPaintBackground can have default background painting done
975 internal virtual void PaintControlBackground (PaintEventArgs pevent)
977 if (background_image == null) {
978 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));
982 DrawBackgroundImage (pevent.Graphics);
985 void DrawBackgroundImage (Graphics g)
987 using (TextureBrush b = new TextureBrush (background_image, WrapMode.Tile)) {
988 g.FillRectangle (b, ClientRectangle);
992 internal virtual void DndEnter (DragEventArgs e)
999 internal virtual void DndOver (DragEventArgs e)
1006 internal virtual void DndDrop (DragEventArgs e)
1010 } catch (Exception exc) {
1011 Console.Error.WriteLine ("MWF: Exception while dropping:");
1012 Console.Error.WriteLine (exc);
1016 internal virtual void DndLeave (EventArgs e)
1023 internal virtual void DndFeedback(GiveFeedbackEventArgs e)
1030 internal virtual void DndContinueDrag(QueryContinueDragEventArgs e)
1033 OnQueryContinueDrag(e);
1037 internal static MouseButtons FromParamToMouseButtons (int param) {
1038 MouseButtons buttons = MouseButtons.None;
1040 if ((param & (int) MsgButtons.MK_LBUTTON) != 0)
1041 buttons |= MouseButtons.Left;
1043 if ((param & (int) MsgButtons.MK_MBUTTON) != 0)
1044 buttons |= MouseButtons.Middle;
1046 if ((param & (int) MsgButtons.MK_RBUTTON) != 0)
1047 buttons |= MouseButtons.Right;
1053 internal virtual bool ProcessControlMnemonic(char charCode) {
1054 return ProcessMnemonic(charCode);
1057 private static Control FindFlatForward(Control container, Control start) {
1063 end = container.child_controls.Count;
1065 if (start != null) {
1066 index = start.tab_index;
1071 for (int i = 0; i < end; i++) {
1072 if (found == null) {
1073 if (container.child_controls[i].tab_index > index) {
1074 found = container.child_controls[i];
1076 } else if (found.tab_index > container.child_controls[i].tab_index) {
1077 if (container.child_controls[i].tab_index > index) {
1078 found = container.child_controls[i];
1085 private static Control FindControlForward(Control container, Control start) {
1091 if (start != null) {
1092 if ((start is IContainerControl) || start.GetStyle(ControlStyles.ContainerControl)) {
1093 found = FindControlForward(start, null);
1094 if (found != null) {
1100 while (p != container) {
1101 found = FindFlatForward(p, start);
1102 if (found != null) {
1109 return FindFlatForward(container, start);
1112 private static Control FindFlatBackward(Control container, Control start) {
1118 end = container.child_controls.Count;
1120 if (start != null) {
1121 index = start.tab_index;
1123 // FIXME: Possible speed-up: Keep the highest taborder index in the container
1125 for (int i = 0; i < end; i++) {
1126 if (container.child_controls[i].tab_index > index) {
1127 index = container.child_controls[i].tab_index;
1133 for (int i = 0; i < end; i++) {
1134 if (found == null) {
1135 if (container.child_controls[i].tab_index < index) {
1136 found = container.child_controls[i];
1138 } else if (found.tab_index < container.child_controls[i].tab_index) {
1139 if (container.child_controls[i].tab_index < index) {
1140 found = container.child_controls[i];
1147 private static Control FindControlBackward(Control container, Control start) {
1152 if (start != null) {
1153 found = FindFlatBackward(start.parent, start);
1154 if (found == null && start.parent != container) {
1155 return start.parent;
1158 if (found == null) {
1159 found = FindFlatBackward(container, start);
1162 while ((found != null) && ((found is IContainerControl) || found.GetStyle(ControlStyles.ContainerControl))) {
1163 found = FindControlBackward(found, null);
1164 if (found != null) {
1172 private void HandleClick(int clicks, MouseEventArgs me) {
1173 if (GetStyle(ControlStyles.StandardClick)) {
1174 if ((clicks > 1) && GetStyle(ControlStyles.StandardDoubleClick)) {
1176 OnDoubleClick(EventArgs.Empty);
1178 OnClick(EventArgs.Empty);
1188 private void CheckDataBindings ()
1190 if (data_bindings == null)
1193 BindingContext binding_context = BindingContext;
1194 foreach (Binding binding in data_bindings) {
1195 binding.Check (binding_context);
1200 private void ChangeParent(Control new_parent) {
1204 Color pre_fore_color;
1205 Color pre_back_color;
1206 RightToLeft pre_rtl;
1208 // These properties are inherited from our parent
1209 // Get them pre parent-change and then send events
1210 // if they are changed after we have our new parent
1211 pre_enabled = Enabled;
1212 pre_visible = Visible;
1214 pre_fore_color = ForeColor;
1215 pre_back_color = BackColor;
1216 pre_rtl = RightToLeft;
1217 // MS doesn't seem to send a CursorChangedEvent
1219 parent = new_parent;
1221 if (IsHandleCreated && (new_parent != null) && new_parent.IsHandleCreated) {
1222 XplatUI.SetParent(Handle, new_parent.Handle);
1225 OnParentChanged(EventArgs.Empty);
1227 if (pre_enabled != Enabled) {
1228 OnEnabledChanged(EventArgs.Empty);
1231 if (pre_visible != Visible) {
1232 OnVisibleChanged(EventArgs.Empty);
1235 if (pre_font != Font) {
1236 OnFontChanged(EventArgs.Empty);
1239 if (pre_fore_color != ForeColor) {
1240 OnForeColorChanged(EventArgs.Empty);
1243 if (pre_back_color != BackColor) {
1244 OnBackColorChanged(EventArgs.Empty);
1247 if (pre_rtl != RightToLeft) {
1248 // MS sneaks a OnCreateControl and OnHandleCreated in here, I guess
1249 // because when RTL changes they have to recreate the win32 control
1250 // We don't really need that (until someone runs into compatibility issues)
1251 OnRightToLeftChanged(EventArgs.Empty);
1254 if ((new_parent != null) && new_parent.Created && !Created) {
1258 if ((binding_context == null) && Created) {
1259 OnBindingContextChanged(EventArgs.Empty);
1263 private void UpdateDistances() {
1264 if ((parent != null) && (parent.layout_suspended == 0)) {
1265 dist_left = bounds.X;
1266 dist_top = bounds.Y;
1267 dist_right = parent.ClientSize.Width - bounds.X - bounds.Width;
1268 dist_bottom = parent.ClientSize.Height - bounds.Y - bounds.Height;
1271 #endregion // Private & Internal Methods
1273 #region Public Static Properties
1274 public static Color DefaultBackColor {
1276 return ThemeEngine.Current.DefaultControlBackColor;
1280 public static Font DefaultFont {
1282 return ThemeEngine.Current.DefaultFont;
1286 public static Color DefaultForeColor {
1288 return ThemeEngine.Current.DefaultControlForeColor;
1292 public static Keys ModifierKeys {
1294 return XplatUI.State.ModifierKeys;
1298 public static MouseButtons MouseButtons {
1300 return XplatUI.State.MouseButtons;
1304 public static Point MousePosition {
1306 return Cursor.Position;
1312 public static bool CheckForIllegalCrossThreadCalls
1321 #endregion // Public Static Properties
1323 #region Public Instance Properties
1324 [EditorBrowsable(EditorBrowsableState.Advanced)]
1326 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1327 public AccessibleObject AccessibilityObject {
1329 if (accessibility_object==null) {
1330 accessibility_object=CreateAccessibilityInstance();
1332 return accessibility_object;
1336 [EditorBrowsable(EditorBrowsableState.Advanced)]
1338 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1339 public string AccessibleDefaultActionDescription {
1341 return AccessibilityObject.default_action;
1345 AccessibilityObject.default_action=value;
1350 [DefaultValue(null)]
1351 public string AccessibleDescription {
1353 return AccessibilityObject.description;
1357 AccessibilityObject.description=value;
1362 [DefaultValue(null)]
1363 public string AccessibleName {
1365 return AccessibilityObject.Name;
1369 AccessibilityObject.Name=value;
1373 [DefaultValue(AccessibleRole.Default)]
1374 [MWFDescription("Role of the control"), MWFCategory("Accessibility")]
1375 public AccessibleRole AccessibleRole {
1377 return AccessibilityObject.role;
1381 AccessibilityObject.role=value;
1385 [DefaultValue(false)]
1386 public virtual bool AllowDrop {
1392 if (allow_drop == value)
1396 XplatUI.SetAllowDrop (Handle, value);
1401 [RefreshProperties(RefreshProperties.Repaint)]
1402 [DefaultValue(AnchorStyles.Top | AnchorStyles.Left)]
1403 public virtual AnchorStyles Anchor {
1405 return anchor_style;
1411 if (parent != null) {
1412 parent.PerformLayout(this, "Parent");
1418 // XXX: Implement me!
1421 public virtual bool AutoSize {
1423 Console.Error.WriteLine("Unimplemented: Control::get_AutoSize()");
1427 Console.Error.WriteLine("Unimplemented: Control::set_AutoSize(bool)");
1434 public virtual Color BackColor {
1436 if (background_color.IsEmpty) {
1438 return parent.BackColor;
1440 return DefaultBackColor;
1442 return background_color;
1446 background_color=value;
1447 SetChildColor(this);
1448 OnBackColorChanged(EventArgs.Empty);
1454 [DefaultValue(null)]
1455 public virtual Image BackgroundImage {
1457 return background_image;
1461 if (background_image!=value) {
1462 background_image=value;
1463 OnBackgroundImageChanged(EventArgs.Empty);
1468 [EditorBrowsable(EditorBrowsableState.Advanced)]
1470 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1471 public virtual BindingContext BindingContext {
1473 if (binding_context != null)
1474 return binding_context;
1477 binding_context = Parent.BindingContext;
1478 return binding_context;
1481 if (binding_context != value) {
1482 binding_context = value;
1483 OnBindingContextChanged(EventArgs.Empty);
1488 [EditorBrowsable(EditorBrowsableState.Advanced)]
1490 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1493 return bounds.Y+bounds.Height;
1497 [EditorBrowsable(EditorBrowsableState.Advanced)]
1499 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1500 public Rectangle Bounds {
1506 SetBoundsCore(value.Left, value.Top, value.Width, value.Height, BoundsSpecified.All);
1510 [EditorBrowsable(EditorBrowsableState.Advanced)]
1512 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1513 public bool CanFocus {
1515 if (IsHandleCreated && Visible && Enabled) {
1522 [EditorBrowsable(EditorBrowsableState.Advanced)]
1524 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1525 public bool CanSelect {
1529 if (!GetStyle(ControlStyles.Selectable)) {
1534 while (parent != null) {
1535 if (!parent.is_visible || !parent.is_enabled) {
1539 parent = parent.parent;
1545 [EditorBrowsable(EditorBrowsableState.Advanced)]
1547 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1548 public bool Capture {
1550 return this.is_captured;
1554 if (this.IsHandleCreated) {
1555 if (value && !is_captured) {
1557 XplatUI.GrabWindow(this.window.Handle, IntPtr.Zero);
1558 } else if (!value && is_captured) {
1559 XplatUI.UngrabWindow(this.window.Handle);
1560 is_captured = false;
1566 [DefaultValue(true)]
1567 public bool CausesValidation {
1569 return this.causes_validation;
1573 if (this.causes_validation != value) {
1574 causes_validation = value;
1575 OnCausesValidationChanged(EventArgs.Empty);
1580 [EditorBrowsable(EditorBrowsableState.Advanced)]
1582 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1583 public Rectangle ClientRectangle {
1585 client_rect.Width = client_size.Width;
1586 client_rect.Height = client_size.Height;
1591 [EditorBrowsable(EditorBrowsableState.Advanced)]
1593 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1594 public Size ClientSize {
1597 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1598 return ((Form)this).form_parent_window.ClientSize;
1606 this.SetClientSizeCore(value.Width, value.Height);
1610 [EditorBrowsable(EditorBrowsableState.Advanced)]
1612 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1613 [DescriptionAttribute("ControlCompanyNameDescr")]
1614 public String CompanyName {
1616 return "Mono Project, Novell, Inc.";
1620 [EditorBrowsable(EditorBrowsableState.Advanced)]
1622 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1623 public bool ContainsFocus {
1629 for (int i=0; i < child_controls.Count; i++) {
1630 if (child_controls[i].ContainsFocus) {
1638 [DefaultValue(null)]
1639 public virtual ContextMenu ContextMenu {
1641 return context_menu;
1645 if (context_menu != value) {
1646 context_menu = value;
1647 OnContextMenuChanged(EventArgs.Empty);
1653 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
1654 public ControlCollection Controls {
1656 return this.child_controls;
1660 [EditorBrowsable(EditorBrowsableState.Advanced)]
1662 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1663 public bool Created {
1665 return (!is_disposed && is_created);
1669 [AmbientValue(null)]
1670 public virtual Cursor Cursor {
1672 if (cursor != null) {
1676 if (parent != null) {
1677 return parent.Cursor;
1680 return Cursors.Default;
1684 if (cursor != value) {
1689 if (IsHandleCreated) {
1690 pt = Cursor.Position;
1692 if (bounds.Contains(pt)) {
1693 if (GetChildAtPoint(pt) == null) {
1694 if (cursor != null) {
1695 XplatUI.SetCursor(window.Handle, cursor.handle);
1697 if (parent != null) {
1698 XplatUI.SetCursor(window.Handle, parent.Cursor.handle);
1700 XplatUI.SetCursor(window.Handle, Cursors.def.handle);
1707 OnCursorChanged(EventArgs.Empty);
1713 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
1714 [ParenthesizePropertyName(true)]
1715 [RefreshProperties(RefreshProperties.All)]
1716 public ControlBindingsCollection DataBindings {
1718 if (data_bindings == null)
1719 data_bindings = new ControlBindingsCollection (this);
1720 return data_bindings;
1724 [EditorBrowsable(EditorBrowsableState.Advanced)]
1726 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1727 public virtual Rectangle DisplayRectangle {
1729 return ClientRectangle;
1733 [EditorBrowsable(EditorBrowsableState.Advanced)]
1735 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1736 public bool Disposing {
1743 [RefreshProperties(RefreshProperties.Repaint)]
1744 [DefaultValue(DockStyle.None)]
1745 public virtual DockStyle Dock {
1751 if (dock_style == value) {
1757 if (parent != null) {
1758 parent.PerformLayout(this, "Parent");
1761 OnDockChanged(EventArgs.Empty);
1767 public bool Enabled {
1773 if (parent != null) {
1774 return parent.Enabled;
1781 if (is_enabled == value) {
1785 if (IsHandleCreated) {
1787 if (((Form)this).context == null) {
1788 XplatUI.EnableWindow(window.Handle, value);
1791 XplatUI.EnableWindow(window.Handle, value);
1796 OnEnabledChanged (EventArgs.Empty);
1800 [EditorBrowsable(EditorBrowsableState.Advanced)]
1802 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1803 public virtual bool Focused {
1805 return this.has_focus;
1810 [AmbientValue(null)]
1812 public virtual Font Font {
1818 if (Parent != null && Parent.Font != null) {
1826 if (font != null && font.Equals (value)) {
1832 OnFontChanged (EventArgs.Empty);
1837 public virtual Color ForeColor {
1839 if (foreground_color.IsEmpty) {
1841 return parent.ForeColor;
1843 return DefaultForeColor;
1845 return foreground_color;
1849 if (foreground_color != value) {
1850 foreground_color=value;
1852 OnForeColorChanged(EventArgs.Empty);
1859 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1860 public IntPtr Handle { // IWin32Window
1862 if (!IsHandleCreated) {
1865 return window.Handle;
1869 [EditorBrowsable(EditorBrowsableState.Advanced)]
1871 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1872 public bool HasChildren {
1874 if (this.child_controls.Count>0) {
1881 [EditorBrowsable(EditorBrowsableState.Always)]
1883 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1886 return this.bounds.Height;
1890 SetBoundsCore(bounds.X, bounds.Y, bounds.Width, value, BoundsSpecified.Height);
1894 [AmbientValue(ImeMode.Inherit)]
1896 public ImeMode ImeMode {
1898 if (ime_mode == DefaultImeMode) {
1900 return parent.ImeMode;
1902 return ImeMode.NoControl; // default value
1908 if (ime_mode != value) {
1911 OnImeModeChanged(EventArgs.Empty);
1916 [EditorBrowsable(EditorBrowsableState.Advanced)]
1918 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1919 public bool InvokeRequired { // ISynchronizeInvoke
1921 if (creator_thread != null && creator_thread!=Thread.CurrentThread) {
1928 [EditorBrowsable(EditorBrowsableState.Advanced)]
1930 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1931 public bool IsAccessible {
1933 return is_accessible;
1937 is_accessible = value;
1941 [EditorBrowsable(EditorBrowsableState.Advanced)]
1943 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1944 public bool IsDisposed {
1946 return this.is_disposed;
1950 [EditorBrowsable(EditorBrowsableState.Advanced)]
1952 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1953 public bool IsHandleCreated {
1955 if ((window != null) && (window.Handle != IntPtr.Zero)) {
1963 [EditorBrowsable(EditorBrowsableState.Always)]
1965 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1968 return this.bounds.X;
1972 SetBoundsCore(value, bounds.Y, bounds.Width, bounds.Height, BoundsSpecified.X);
1977 public Point Location {
1979 return new Point(bounds.X, bounds.Y);
1983 SetBoundsCore(value.X, value.Y, bounds.Width, bounds.Height, BoundsSpecified.Location);
1988 public string Name {
2000 public Padding Padding {
2012 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2013 public Control Parent {
2019 if (value == this) {
2020 throw new ArgumentException("A circular control reference has been made. A control cannot be owned or parented to itself.");
2023 if (parent!=value) {
2025 parent.Controls.Remove(this);
2029 value.Controls.Add(this);
2034 [EditorBrowsable(EditorBrowsableState.Advanced)]
2036 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2037 public string ProductName {
2039 Type t = typeof (AssemblyProductAttribute);
2040 Assembly assembly = GetType().Module.Assembly;
2041 object [] attrs = assembly.GetCustomAttributes (t, false);
2042 AssemblyProductAttribute a = null;
2043 // On MS we get a NullRefException if product attribute is not
2045 if (attrs != null && attrs.Length > 0)
2046 a = (AssemblyProductAttribute) attrs [0];
2051 [EditorBrowsable(EditorBrowsableState.Advanced)]
2053 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2054 public string ProductVersion {
2056 Type t = typeof (AssemblyVersionAttribute);
2057 Assembly assembly = GetType().Module.Assembly;
2058 object [] attrs = assembly.GetCustomAttributes (t, false);
2059 if (attrs == null || attrs.Length < 1)
2061 return ((AssemblyVersionAttribute)attrs [0]).Version;
2065 [EditorBrowsable(EditorBrowsableState.Advanced)]
2067 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2068 public bool RecreatingHandle {
2070 return is_recreating;
2074 [EditorBrowsable(EditorBrowsableState.Advanced)]
2076 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2077 public Region Region {
2079 return new Region(this.bounds);
2086 g = this.CreateGraphics();
2087 r = value.GetBounds(g);
2089 SetBounds((int)r.X, (int)r.Y, (int)r.Width, (int)r.Height);
2095 [EditorBrowsable(EditorBrowsableState.Advanced)]
2097 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2100 return this.bounds.X+this.bounds.Width;
2104 [AmbientValue(RightToLeft.Inherit)]
2106 public virtual RightToLeft RightToLeft {
2108 if (right_to_left == RightToLeft.Inherit) {
2110 return parent.RightToLeft;
2112 return RightToLeft.No; // default value
2114 return right_to_left;
2118 if (value != right_to_left) {
2119 right_to_left = value;
2120 OnRightToLeftChanged(EventArgs.Empty);
2125 [EditorBrowsable(EditorBrowsableState.Advanced)]
2126 public override ISite Site {
2134 AmbientProperties ap = (AmbientProperties) value.GetService (typeof (AmbientProperties));
2136 BackColor = ap.BackColor;
2137 ForeColor = ap.ForeColor;
2147 return new Size(Width, Height);
2151 SetBoundsCore(bounds.X, bounds.Y, value.Width, value.Height, BoundsSpecified.Size);
2156 [MergableProperty(false)]
2157 public int TabIndex {
2159 if (tab_index != -1) {
2166 if (tab_index != value) {
2168 OnTabIndexChanged(EventArgs.Empty);
2174 [DefaultValue(true)]
2175 public bool TabStop {
2181 if (tab_stop != value) {
2183 OnTabStopChanged(EventArgs.Empty);
2188 [Localizable(false)]
2190 [TypeConverter(typeof(StringConverter))]
2191 [DefaultValue(null)]
2198 control_tag = value;
2204 [BindableAttribute(true)]
2205 public virtual string Text {
2207 // Our implementation ignores ControlStyles.CacheText - we always cache
2212 if (value == null) {
2213 value = String.Empty;
2218 if (IsHandleCreated) {
2219 XplatUI.Text(Handle, text);
2221 OnTextChanged (EventArgs.Empty);
2226 [EditorBrowsable(EditorBrowsableState.Always)]
2228 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2231 return this.bounds.Y;
2235 SetBoundsCore(bounds.X, value, bounds.Width, bounds.Height, BoundsSpecified.Y);
2239 [EditorBrowsable(EditorBrowsableState.Advanced)]
2241 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2242 public Control TopLevelControl {
2246 while (p.parent != null) {
2255 public bool Visible {
2259 } else if (parent != null) {
2260 return parent.Visible;
2267 SetVisibleCore(value);
2271 [EditorBrowsable(EditorBrowsableState.Always)]
2273 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2276 return this.bounds.Width;
2280 SetBoundsCore(bounds.X, bounds.Y, value, bounds.Height, BoundsSpecified.Width);
2284 [EditorBrowsable(EditorBrowsableState.Never)]
2286 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2287 public IWindowTarget WindowTarget {
2296 #endregion // Public Instance Properties
2298 #region Protected Instance Properties
2299 protected virtual CreateParams CreateParams {
2301 CreateParams create_params = new CreateParams();
2304 create_params.Caption = Text;
2307 create_params.Caption = text;
2311 create_params.X = Left;
2314 create_params.X = this.bounds.X;
2318 create_params.Y = Top;
2321 create_params.Y = this.bounds.Y;
2325 create_params.Width = Width;
2328 create_params.Width = this.bounds.Width;
2332 create_params.Height = Height;
2335 create_params.Height = this.bounds.Height;
2339 create_params.ClassName = XplatUI.DefaultClassName;
2340 create_params.ClassStyle = 0;
2341 create_params.ExStyle = 0;
2342 create_params.Param = 0;
2345 create_params.ExStyle |= (int)WindowExStyles.WS_EX_ACCEPTFILES;
2349 create_params.Parent = parent.Handle;
2352 create_params.Style = (int)WindowStyles.WS_CHILD | (int)WindowStyles.WS_CLIPCHILDREN | (int)WindowStyles.WS_CLIPSIBLINGS;
2355 create_params.Style |= (int)WindowStyles.WS_VISIBLE;
2359 create_params.Style |= (int)WindowStyles.WS_DISABLED;
2362 switch (border_style) {
2363 case BorderStyle.FixedSingle:
2364 create_params.Style |= (int) WindowStyles.WS_BORDER;
2366 case BorderStyle.Fixed3D:
2367 create_params.ExStyle |= (int) WindowExStyles.WS_EX_CLIENTEDGE;
2371 return create_params;
2375 protected virtual ImeMode DefaultImeMode {
2377 return ImeMode.Inherit;
2381 protected virtual Size DefaultSize {
2383 return new Size(0, 0);
2387 protected int FontHeight {
2397 protected bool RenderRightToLeft {
2399 return (this.right_to_left == RightToLeft.Yes);
2403 protected bool ResizeRedraw {
2405 return GetStyle(ControlStyles.ResizeRedraw);
2409 SetStyle(ControlStyles.ResizeRedraw, value);
2413 [EditorBrowsable(EditorBrowsableState.Advanced)]
2415 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2416 protected virtual bool ShowFocusCues {
2422 [EditorBrowsable(EditorBrowsableState.Advanced)]
2424 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2425 protected bool ShowKeyboardCues {
2430 #endregion // Protected Instance Properties
2432 #region Public Static Methods
2433 [EditorBrowsable(EditorBrowsableState.Advanced)]
2434 public static Control FromChildHandle(IntPtr handle) {
2435 IEnumerator control = Control.controls.GetEnumerator();
2437 while (control.MoveNext()) {
2438 if (((Control)control.Current).window.Handle == handle) {
2440 if (((Control)control.Current).Parent != null) {
2441 return ((Control)control.Current).Parent;
2448 [EditorBrowsable(EditorBrowsableState.Advanced)]
2449 public static Control FromHandle(IntPtr handle) {
2451 IEnumerator control = Control.controls.GetEnumerator();
2453 while (control.MoveNext()) {
2454 if (((Control)control.Current).window.Handle == handle) {
2456 return ((Control)control.Current);
2462 return Control.ControlNativeWindow.ControlFromHandle(handle);
2466 public static bool IsMnemonic(char charCode, string text) {
2469 amp = text.IndexOf('&');
2472 if (amp + 1 < text.Length) {
2473 if (text[amp + 1] != '&') {
2474 if (Char.ToUpper(charCode) == Char.ToUpper(text.ToCharArray(amp + 1, 1)[0])) {
2484 #region Protected Static Methods
2485 [EditorBrowsable(EditorBrowsableState.Advanced)]
2486 protected static bool ReflectMessage(IntPtr hWnd, ref Message m) {
2489 c = Control.FromHandle(hWnd);
2499 #region Public Instance Methods
2500 [EditorBrowsable(EditorBrowsableState.Advanced)]
2501 public IAsyncResult BeginInvoke(Delegate method) {
2502 object [] prms = null;
2503 if (method is EventHandler)
2504 prms = new object [] { this, EventArgs.Empty };
2505 return BeginInvokeInternal(method, prms, false);
2508 [EditorBrowsable(EditorBrowsableState.Advanced)]
2509 public IAsyncResult BeginInvoke (Delegate method, object[] args) {
2510 return BeginInvokeInternal (method, args, false);
2513 public void BringToFront() {
2514 if ((parent != null) && (parent.child_controls[0]!=this)) {
2515 if (parent.child_controls.Contains(this)) {
2516 parent.child_controls.SetChildIndex(this, 0);
2518 } else if (parent != null) {
2519 if (parent.child_controls.impl_list != null) {
2520 Control last_impl = (Control) parent.child_controls.impl_list [parent.child_controls.impl_list.Count - 1];
2521 if (IsHandleCreated) {
2522 XplatUI.SetZOrder (this.window.Handle, last_impl.Handle, false, false);
2525 if (IsHandleCreated) {
2526 XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, true, false);
2531 if (parent != null) {
2536 public bool Contains(Control ctl) {
2537 while (ctl != null) {
2546 public void CreateControl() {
2551 if (!IsHandleCreated) {
2559 Control [] controls = child_controls.GetAllControls ();
2560 for (int i=0; i<controls.Length; i++) {
2561 controls [i].CreateControl ();
2566 if (binding_context == null) { // seem to be sent whenever it's null?
2567 OnBindingContextChanged(EventArgs.Empty);
2573 public Graphics CreateGraphics() {
2574 if (!IsHandleCreated) {
2575 this.CreateHandle();
2577 return Graphics.FromHwnd(this.window.Handle);
2580 public DragDropEffects DoDragDrop(object data, DragDropEffects allowedEffects) {
2581 return XplatUI.StartDrag(this.window.Handle, data, allowedEffects);
2584 [EditorBrowsable(EditorBrowsableState.Advanced)]
2585 public object EndInvoke (IAsyncResult async_result) {
2586 AsyncMethodResult result = (AsyncMethodResult) async_result;
2587 return result.EndInvoke ();
2590 public Form FindForm() {
2603 public bool Focus() {
2604 if (CanFocus && IsHandleCreated && !has_focus) {
2605 XplatUI.SetFocus(window.Handle);
2610 public Control GetChildAtPoint(Point pt) {
2611 // Microsoft's version of this function doesn't seem to work, so I can't check
2612 // if we only consider children or also grandchildren, etc.
2613 // I'm gonna say 'children only'
2614 for (int i=0; i<child_controls.Count; i++) {
2615 if (child_controls[i].Bounds.Contains(pt)) {
2616 return child_controls[i];
2622 public IContainerControl GetContainerControl() {
2623 Control current = this;
2625 while (current!=null) {
2626 if ((current is IContainerControl) && ((current.control_style & ControlStyles.ContainerControl)!=0)) {
2627 return (IContainerControl)current;
2629 current = current.parent;
2634 public Control GetNextControl(Control ctl, bool forward) {
2635 // If we're not a container we don't play
2636 if (!(this is IContainerControl) && !this.GetStyle(ControlStyles.ContainerControl)) {
2640 // If ctl is not contained by this, we start at the first child of this
2641 if (!this.Contains(ctl)) {
2645 // Search through our controls, starting at ctl, stepping into children as we encounter them
2646 // try to find the control with the tabindex closest to our own, or, if we're looking into
2647 // child controls, the one with the smallest tabindex
2649 return FindControlForward(this, ctl);
2651 return FindControlBackward(this, ctl);
2654 public void Hide() {
2655 this.Visible = false;
2658 public void Invalidate() {
2659 Invalidate(ClientRectangle, false);
2662 public void Invalidate(bool invalidateChildren) {
2663 Invalidate(ClientRectangle, invalidateChildren);
2666 public void Invalidate(System.Drawing.Rectangle rc) {
2667 Invalidate(rc, false);
2670 public void Invalidate(System.Drawing.Rectangle rc, bool invalidateChildren) {
2671 if (!IsHandleCreated || !Visible || rc.Width == 0 || rc.Height == 0) {
2675 NotifyInvalidate(rc);
2677 XplatUI.Invalidate(Handle, rc, false);
2679 if (invalidateChildren) {
2680 Control [] controls = child_controls.GetAllControls ();
2681 for (int i=0; i<controls.Length; i++)
2682 controls [i].Invalidate ();
2684 OnInvalidated(new InvalidateEventArgs(rc));
2687 public void Invalidate(System.Drawing.Region region) {
2688 Invalidate(region, false);
2691 public void Invalidate(System.Drawing.Region region, bool invalidateChildren) {
2692 RectangleF bounds = region.GetBounds (CreateGraphics ());
2693 Invalidate (new Rectangle ((int) bounds.X, (int) bounds.Y, (int) bounds.Width, (int) bounds.Height),
2694 invalidateChildren);
2697 public object Invoke (Delegate method) {
2698 object [] prms = null;
2699 if (method is EventHandler)
2700 prms = new object [] { this, EventArgs.Empty };
2702 return Invoke(method, prms);
2705 public object Invoke (Delegate method, object[] args) {
2706 if (!this.InvokeRequired) {
2707 return method.DynamicInvoke(args);
2710 IAsyncResult result = BeginInvoke (method, args);
2711 return EndInvoke(result);
2714 internal object InvokeInternal (Delegate method, bool disposing) {
2715 return InvokeInternal(method, null, disposing);
2718 internal object InvokeInternal (Delegate method, object[] args, bool disposing) {
2719 if (!this.InvokeRequired) {
2720 return method.DynamicInvoke(args);
2723 IAsyncResult result = BeginInvokeInternal (method, args, disposing);
2724 return EndInvoke(result);
2727 [EditorBrowsable(EditorBrowsableState.Advanced)]
2728 public void PerformLayout() {
2729 PerformLayout(null, null);
2732 [EditorBrowsable(EditorBrowsableState.Advanced)]
2733 public void PerformLayout(Control affectedControl, string affectedProperty) {
2734 LayoutEventArgs levent = new LayoutEventArgs(affectedControl, affectedProperty);
2736 if (layout_suspended > 0) {
2737 layout_pending = true;
2741 layout_pending = false;
2743 // Prevent us from getting messed up
2746 // Perform all Dock and Anchor calculations
2749 AnchorStyles anchor;
2752 space= DisplayRectangle;
2754 // Deal with docking; go through in reverse, MS docs say that lowest Z-order is closest to edge
2755 Control [] controls = child_controls.GetAllControls ();
2756 for (int i = controls.Length - 1; i >= 0; i--) {
2757 child = controls [i];
2759 if (!child.Visible) {
2763 switch (child.Dock) {
2764 case DockStyle.None: {
2769 case DockStyle.Left: {
2770 child.SetBounds(space.Left, space.Y, child.Width, space.Height);
2771 space.X+=child.Width;
2772 space.Width-=child.Width;
2776 case DockStyle.Top: {
2777 child.SetBounds(space.Left, space.Y, space.Width, child.Height);
2778 space.Y+=child.Height;
2779 space.Height-=child.Height;
2783 case DockStyle.Right: {
2784 child.SetBounds(space.Right-child.Width, space.Y, child.Width, space.Height);
2785 space.Width-=child.Width;
2789 case DockStyle.Bottom: {
2790 child.SetBounds(space.Left, space.Bottom-child.Height, space.Width, child.Height);
2791 space.Height-=child.Height;
2797 for (int i = controls.Length - 1; i >= 0; i--) {
2800 if (child.Visible && (child.Dock == DockStyle.Fill)) {
2801 child.SetBounds(space.Left, space.Top, space.Width, space.Height);
2807 space=DisplayRectangle;
2809 for (int i=0; i < controls.Length; i++) {
2815 child = controls[i];
2817 // If the control is docked we don't need to do anything
2818 if (child.Dock != DockStyle.None) {
2822 anchor = child.Anchor;
2826 width = child.Width;
2827 height = child.Height;
2829 if ((anchor & AnchorStyles.Left) !=0 ) {
2830 if ((anchor & AnchorStyles.Right) != 0) {
2831 width = space.Width - child.dist_right - left;
2833 ; // Left anchored only, nothing to be done
2835 } else if ((anchor & AnchorStyles.Right) != 0) {
2836 left = space.Width - child.dist_right - width;
2838 // left+=diff_width/2 will introduce rounding errors (diff_width removed from svn after r51780)
2839 // This calculates from scratch every time:
2840 left = child.dist_left + (space.Width - (child.dist_left + width + child.dist_right)) / 2;
2843 if ((anchor & AnchorStyles.Top) !=0 ) {
2844 if ((anchor & AnchorStyles.Bottom) != 0) {
2845 height = space.Height - child.dist_bottom - top;
2847 ; // Top anchored only, nothing to be done
2849 } else if ((anchor & AnchorStyles.Bottom) != 0) {
2850 top = space.Height - child.dist_bottom - height;
2852 // top += diff_height/2 will introduce rounding errors (diff_height removed from after r51780)
2853 // This calculates from scratch every time:
2854 top = child.dist_top + (space.Height - (child.dist_top + height + child.dist_bottom)) / 2;
2866 child.SetBounds(left, top, width, height);
2869 // Let everyone know
2873 // Need to make sure we decremend layout_suspended
2879 public Point PointToClient (Point p) {
2883 XplatUI.ScreenToClient (Handle, ref x, ref y);
2885 return new Point (x, y);
2888 public Point PointToScreen(Point p) {
2892 XplatUI.ClientToScreen(Handle, ref x, ref y);
2894 return new Point(x, y);
2897 public virtual bool PreProcessMessage(ref Message msg) {
2900 if ((msg.Msg == (int)Msg.WM_KEYDOWN) || (msg.Msg == (int)Msg.WM_SYSKEYDOWN)) {
2901 key_data = (Keys)msg.WParam.ToInt32() | XplatUI.State.ModifierKeys;
2903 if (!ProcessCmdKey(ref msg, key_data)) {
2904 if (IsInputKey(key_data)) {
2908 return ProcessDialogKey(key_data);
2912 } else if (msg.Msg == (int)Msg.WM_CHAR) {
2913 if (IsInputChar((char)msg.WParam)) {
2916 } else if (msg.Msg == (int)Msg.WM_SYSCHAR) {
2917 if (IsInputChar((char)msg.WParam)) {
2920 return ProcessDialogChar((char)msg.WParam);
2925 public Rectangle RectangleToClient(Rectangle r) {
2926 return new Rectangle(PointToClient(r.Location), r.Size);
2929 public Rectangle RectangleToScreen(Rectangle r) {
2930 return new Rectangle(PointToScreen(r.Location), r.Size);
2933 public virtual void Refresh() {
2934 if (IsHandleCreated == true) {
2937 XplatUI.UpdateWindow(window.Handle);
2939 Control [] controls = child_controls.GetAllControls ();
2940 for (int i=0; i < controls.Length; i++) {
2941 controls[i].Refresh();
2947 [EditorBrowsable(EditorBrowsableState.Never)]
2948 public virtual void ResetBackColor() {
2949 background_color = Color.Empty;
2952 [EditorBrowsable(EditorBrowsableState.Never)]
2954 public void ResetBindings() {
2958 [EditorBrowsable(EditorBrowsableState.Never)]
2959 public virtual void ResetCursor() {
2963 [EditorBrowsable(EditorBrowsableState.Never)]
2964 public virtual void ResetFont() {
2968 [EditorBrowsable(EditorBrowsableState.Never)]
2969 public virtual void ResetForeColor() {
2970 foreground_color = Color.Empty;
2973 [EditorBrowsable(EditorBrowsableState.Never)]
2974 public void ResetImeMode() {
2975 ime_mode = DefaultImeMode;
2978 [EditorBrowsable(EditorBrowsableState.Never)]
2979 public virtual void ResetRightToLeft() {
2980 right_to_left = RightToLeft.Inherit;
2983 public virtual void ResetText() {
2984 text = String.Empty;
2987 public void ResumeLayout() {
2988 ResumeLayout (true);
2991 public void ResumeLayout(bool performLayout) {
2992 if (layout_suspended > 0) {
2996 if (layout_suspended == 0) {
2997 Control [] controls = child_controls.GetAllControls ();
2998 for (int i=0; i<controls.Length; i++) {
2999 controls [i].UpdateDistances ();
3002 if (performLayout && layout_pending) {
3008 public void Scale(float ratio) {
3009 ScaleCore(ratio, ratio);
3012 public void Scale(float dx, float dy) {
3016 public void Select() {
3017 Select(false, false);
3020 public bool SelectNextControl(Control ctl, bool forward, bool tabStopOnly, bool nested, bool wrap) {
3025 c = GetNextControl(c, forward);
3034 if (c.CanSelect && ((c.parent == ctl.parent) || nested) && (c.tab_stop || !tabStopOnly)) {
3038 } while (c != ctl); // If we wrap back to ourselves we stop
3043 public void SendToBack() {
3044 if ((parent != null) && (parent.child_controls[parent.child_controls.Count-1]!=this)) {
3045 if (parent.child_controls.Contains(this)) {
3046 parent.child_controls.SetChildIndex(this, parent.child_controls.Count);
3050 if (IsHandleCreated) {
3051 XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, false, true);
3054 if (parent != null) {
3059 public void SetBounds(int x, int y, int width, int height) {
3060 SetBoundsCore(x, y, width, height, BoundsSpecified.All);
3063 public void SetBounds(int x, int y, int width, int height, BoundsSpecified specified) {
3064 SetBoundsCore(x, y, width, height, specified);
3067 public void Show() {
3069 this.CreateControl();
3075 public void SuspendLayout() {
3079 public void Update() {
3080 needs_redraw = true;
3081 if (IsHandleCreated) {
3082 XplatUI.UpdateWindow(window.Handle);
3085 #endregion // Public Instance Methods
3087 #region Protected Instance Methods
3088 [EditorBrowsable(EditorBrowsableState.Advanced)]
3089 [MonoTODO("Implement this and tie it into Control.ControlAccessibleObject.NotifyClients")]
3090 protected void AccessibilityNotifyClients(AccessibleEvents accEvent, int childID) {
3091 throw new NotImplementedException();
3094 [EditorBrowsable(EditorBrowsableState.Advanced)]
3095 protected virtual AccessibleObject CreateAccessibilityInstance() {
3096 return new Control.ControlAccessibleObject(this);
3099 [EditorBrowsable(EditorBrowsableState.Advanced)]
3100 protected virtual ControlCollection CreateControlsInstance() {
3101 return new ControlCollection(this);
3104 [EditorBrowsable(EditorBrowsableState.Advanced)]
3105 protected virtual void CreateHandle() {
3107 throw new ObjectDisposedException(Name);
3110 if (IsHandleCreated && !is_recreating) {
3114 window.CreateHandle(CreateParams);
3116 if (window.Handle != IntPtr.Zero) {
3117 if (!controls.Contains(window.Handle)) {
3121 creator_thread = Thread.CurrentThread;
3123 XplatUI.EnableWindow(window.Handle, is_enabled);
3125 // Set our handle with our parent
3126 if ((parent != null) && (parent.IsHandleCreated)) {
3127 XplatUI.SetParent(window.Handle, parent.Handle);
3130 // Set our handle as parent for our children
3131 Control [] children;
3133 children = child_controls.GetAllControls ();
3134 for (int i = 0; i < children.Length; i++ ) {
3135 if (children[i].IsHandleCreated) {
3136 XplatUI.SetParent(children[i].Handle, window.Handle);
3140 // Find out where the window manager placed us
3142 if ((CreateParams.Style & (int)WindowStyles.WS_CHILD) != 0) {
3143 XplatUI.SetBorderStyle(window.Handle, (FormBorderStyle)border_style);
3147 OnHandleCreated(EventArgs.Empty);
3152 [EditorBrowsable(EditorBrowsableState.Advanced)]
3153 protected virtual void DefWndProc(ref Message m) {
3154 window.DefWndProc(ref m);
3157 [EditorBrowsable(EditorBrowsableState.Advanced)]
3158 protected virtual void DestroyHandle() {
3159 if (IsHandleCreated) {
3160 if (window != null) {
3161 window.DestroyHandle();
3166 protected bool GetStyle(ControlStyles flag) {
3167 return (control_style & flag) != 0;
3170 protected bool GetTopLevel() {
3174 [EditorBrowsable(EditorBrowsableState.Advanced)]
3175 protected virtual void InitLayout() {
3179 [EditorBrowsable(EditorBrowsableState.Advanced)]
3180 protected void InvokeGotFocus(Control toInvoke, EventArgs e) {
3181 toInvoke.OnGotFocus(e);
3184 [EditorBrowsable(EditorBrowsableState.Advanced)]
3185 protected void InvokeLostFocus(Control toInvoke, EventArgs e) {
3186 toInvoke.OnLostFocus(e);
3189 [EditorBrowsable(EditorBrowsableState.Advanced)]
3190 protected void InvokeOnClick(Control toInvoke, EventArgs e) {
3191 toInvoke.OnClick(e);
3194 protected void InvokePaint(Control toInvoke, PaintEventArgs e) {
3195 toInvoke.OnPaint(e);
3198 protected void InvokePaintBackground(Control toInvoke, PaintEventArgs e) {
3199 toInvoke.OnPaintBackground(e);
3202 protected virtual bool IsInputChar (char charCode) {
3206 protected virtual bool IsInputKey (Keys keyData) {
3207 // Doc says this one calls IsInputChar; not sure what to do with that
3211 [EditorBrowsable(EditorBrowsableState.Advanced)]
3212 protected virtual void NotifyInvalidate(Rectangle invalidatedArea) {
3216 protected virtual bool ProcessCmdKey(ref Message msg, Keys keyData) {
3217 if ((context_menu != null) && context_menu.ProcessCmdKey(ref msg, keyData)) {
3221 if (parent != null) {
3222 return parent.ProcessCmdKey(ref msg, keyData);
3228 protected virtual bool ProcessDialogChar(char charCode) {
3229 if (parent != null) {
3230 return parent.ProcessDialogChar (charCode);
3236 protected virtual bool ProcessDialogKey (Keys keyData) {
3237 if (parent != null) {
3238 return parent.ProcessDialogKey (keyData);
3244 protected virtual bool ProcessKeyEventArgs (ref Message msg)
3246 KeyEventArgs key_event;
3249 case (int)Msg.WM_SYSKEYDOWN:
3250 case (int)Msg.WM_KEYDOWN: {
3251 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
3252 OnKeyDown (key_event);
3253 return key_event.Handled;
3256 case (int)Msg.WM_SYSKEYUP:
3257 case (int)Msg.WM_KEYUP: {
3258 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
3259 OnKeyUp (key_event);
3260 return key_event.Handled;
3263 case (int)Msg.WM_SYSCHAR:
3264 case (int)Msg.WM_CHAR: {
3265 KeyPressEventArgs key_press_event;
3267 key_press_event = new KeyPressEventArgs((char)msg.WParam);
3268 OnKeyPress(key_press_event);
3269 return key_press_event.Handled;
3280 protected internal virtual bool ProcessKeyMessage(ref Message msg) {
3281 if (parent != null) {
3282 if (parent.ProcessKeyPreview(ref msg)) {
3287 return ProcessKeyEventArgs(ref msg);
3290 protected virtual bool ProcessKeyPreview(ref Message msg) {
3291 if (parent != null) {
3292 return parent.ProcessKeyPreview(ref msg);
3298 protected virtual bool ProcessMnemonic(char charCode) {
3303 [EditorBrowsable(EditorBrowsableState.Advanced)]
3304 protected void RaiseDragEvent(object key, DragEventArgs e) {
3308 [EditorBrowsable(EditorBrowsableState.Advanced)]
3309 protected void RaiseKeyEvent(object key, KeyEventArgs e) {
3313 [EditorBrowsable(EditorBrowsableState.Advanced)]
3314 protected void RaiseMouseEvent(object key, MouseEventArgs e) {
3318 [EditorBrowsable(EditorBrowsableState.Advanced)]
3319 protected void RaisePaintEvent(object key, PaintEventArgs e) {
3323 [EditorBrowsable(EditorBrowsableState.Advanced)]
3324 protected void RecreateHandle() {
3327 if (IsHandleCreated) {
3329 // WM_DESTROY will CreateHandle for us
3338 is_recreating = false;
3341 [EditorBrowsable(EditorBrowsableState.Advanced)]
3342 protected void ResetMouseEventArgs() {
3346 [EditorBrowsable(EditorBrowsableState.Advanced)]
3347 protected ContentAlignment RtlTranslateAlignment(ContentAlignment align) {
3348 if (right_to_left == RightToLeft.No) {
3353 case ContentAlignment.TopLeft: {
3354 return ContentAlignment.TopRight;
3357 case ContentAlignment.TopRight: {
3358 return ContentAlignment.TopLeft;
3361 case ContentAlignment.MiddleLeft: {
3362 return ContentAlignment.MiddleRight;
3365 case ContentAlignment.MiddleRight: {
3366 return ContentAlignment.MiddleLeft;
3369 case ContentAlignment.BottomLeft: {
3370 return ContentAlignment.BottomRight;
3373 case ContentAlignment.BottomRight: {
3374 return ContentAlignment.BottomLeft;
3378 // if it's center it doesn't change
3384 [EditorBrowsable(EditorBrowsableState.Advanced)]
3385 protected HorizontalAlignment RtlTranslateAlignment(HorizontalAlignment align) {
3386 if ((right_to_left == RightToLeft.No) || (align == HorizontalAlignment.Center)) {
3390 if (align == HorizontalAlignment.Left) {
3391 return HorizontalAlignment.Right;
3394 // align must be HorizontalAlignment.Right
3395 return HorizontalAlignment.Left;
3398 [EditorBrowsable(EditorBrowsableState.Advanced)]
3399 protected LeftRightAlignment RtlTranslateAlignment(LeftRightAlignment align) {
3400 if (right_to_left == RightToLeft.No) {
3404 if (align == LeftRightAlignment.Left) {
3405 return LeftRightAlignment.Right;
3408 // align must be LeftRightAlignment.Right;
3409 return LeftRightAlignment.Left;
3412 [EditorBrowsable(EditorBrowsableState.Advanced)]
3413 protected ContentAlignment RtlTranslateContent(ContentAlignment align) {
3414 return RtlTranslateAlignment(align);
3417 [EditorBrowsable(EditorBrowsableState.Advanced)]
3418 protected HorizontalAlignment RtlTranslateHorizontal(HorizontalAlignment align) {
3419 return RtlTranslateAlignment(align);
3422 [EditorBrowsable(EditorBrowsableState.Advanced)]
3423 protected LeftRightAlignment RtlTranslateLeftRight(LeftRightAlignment align) {
3424 return RtlTranslateAlignment(align);
3427 [EditorBrowsable(EditorBrowsableState.Advanced)]
3428 protected virtual void ScaleCore(float dx, float dy) {
3434 location = new Point((int)(Left * dx), (int)(Top * dy));
3435 size = this.ClientSize;
3437 if (!GetStyle(ControlStyles.FixedWidth)) {
3438 size.Width = (int)(size.Width * dx);
3441 if (!GetStyle(ControlStyles.FixedHeight)) {
3442 size.Height = (int)(size.Height * dy);
3445 SetBoundsCore(location.X, location.Y, size.Width, size.Height, BoundsSpecified.All);
3447 /* Now scale our children */
3448 Control [] controls = child_controls.GetAllControls ();
3449 for (int i=0; i < controls.Length; i++) {
3450 controls[i].Scale(dx, dy);
3456 protected virtual void Select(bool directed, bool forward) {
3461 // Select this control
3466 if (parent == null) {
3470 // FIXME - this thing is doing the wrong stuff, needs to be similar to SelectNextControl
3472 index = parent.child_controls.IndexOf(this);
3477 if ((index+1) < parent.child_controls.Count) {
3486 index = parent.child_controls.Count-1;
3489 result = Select(parent.child_controls[index]);
3490 } while (!result && parent.child_controls[index] != this);
3493 [EditorBrowsable(EditorBrowsableState.Advanced)]
3494 protected virtual void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
3495 // SetBoundsCore updates the Win32 control itself. UpdateBounds updates the controls variables and fires events, I'm guessing - pdb
3496 if ((specified & BoundsSpecified.X) != BoundsSpecified.X) {
3500 if ((specified & BoundsSpecified.Y) != BoundsSpecified.Y) {
3504 if ((specified & BoundsSpecified.Width) != BoundsSpecified.Width) {
3508 if ((specified & BoundsSpecified.Height) != BoundsSpecified.Height) {
3512 if (IsHandleCreated) {
3513 XplatUI.SetWindowPos(Handle, x, y, width, height);
3516 UpdateBounds(x, y, width, height);
3521 [EditorBrowsable(EditorBrowsableState.Advanced)]
3522 protected virtual void SetClientSizeCore(int x, int y) {
3523 // Calculate the actual window size from the client size (it usually stays the same or grows)
3524 Rectangle ClientRect;
3525 Rectangle WindowRect;
3528 ClientRect = new Rectangle(0, 0, x, y);
3529 cp = this.CreateParams;
3531 if (XplatUI.CalculateWindowRect(ref ClientRect, cp.Style, cp.ExStyle, null, out WindowRect)==false) {
3535 SetBoundsCore(bounds.X, bounds.Y, WindowRect.Width, WindowRect.Height, BoundsSpecified.Size);
3538 [EditorBrowsable(EditorBrowsableState.Advanced)]
3539 protected void SetStyle(ControlStyles flag, bool value) {
3541 control_style |= flag;
3543 control_style &= ~flag;
3545 OnStyleChanged(EventArgs.Empty);
3548 protected void SetTopLevel(bool value) {
3549 if ((GetTopLevel() != value) && (parent != null)) {
3550 throw new Exception();
3554 if (value == true) {
3564 is_toplevel = value;
3567 protected virtual void SetVisibleCore(bool value) {
3568 if (value!=is_visible) {
3571 if (IsHandleCreated) {
3572 XplatUI.SetVisible(Handle, value);
3573 // Explicitly move Toplevel windows to where we want them;
3574 // apparently moving unmapped toplevel windows doesn't work
3575 if (is_visible && (this is Form)) {
3576 XplatUI.SetWindowPos(window.Handle, bounds.X, bounds.Y, bounds.Width, bounds.Height);
3580 if (is_visible && !is_created) {
3584 OnVisibleChanged(EventArgs.Empty);
3586 if (value == false && parent != null) {
3589 // Need to start at parent, GetContainerControl might return ourselves if we're a container
3590 container = (Control)parent.GetContainerControl();
3591 if (container != null) {
3592 container.SelectNextControl(this, true, true, true, true);
3596 if (parent != null) {
3597 parent.PerformLayout(this, "visible");
3599 PerformLayout(this, "visible");
3604 [EditorBrowsable(EditorBrowsableState.Advanced)]
3605 protected void UpdateBounds() {
3613 if (!IsHandleCreated) {
3617 XplatUI.GetWindowPos(this.Handle, this is Form, out x, out y, out width, out height, out client_width, out client_height);
3619 UpdateBounds(x, y, width, height, client_width, client_height);
3622 [EditorBrowsable(EditorBrowsableState.Advanced)]
3623 protected void UpdateBounds(int x, int y, int width, int height) {
3624 // UpdateBounds only seems to set our sizes and fire events but not update the GUI window to match
3626 bool resized = false;
3628 int client_x_diff = this.bounds.Width-this.client_size.Width;
3629 int client_y_diff = this.bounds.Height-this.client_size.Height;
3631 // Needed to generate required notifications
3632 if ((this.bounds.X!=x) || (this.bounds.Y!=y)) {
3636 if ((this.Bounds.Width!=width) || (this.Bounds.Height!=height)) {
3643 bounds.Height=height;
3645 // Update client rectangle as well
3646 client_size.Width=width-client_x_diff;
3647 client_size.Height=height-client_y_diff;
3650 OnLocationChanged(EventArgs.Empty);
3654 OnSizeChanged(EventArgs.Empty);
3658 [EditorBrowsable(EditorBrowsableState.Advanced)]
3659 protected void UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) {
3660 UpdateBounds(x, y, width, height);
3662 this.client_size.Width=clientWidth;
3663 this.client_size.Height=clientHeight;
3666 [EditorBrowsable(EditorBrowsableState.Advanced)]
3667 protected void UpdateStyles() {
3668 if (!IsHandleCreated) {
3672 XplatUI.SetWindowStyle(window.Handle, CreateParams);
3675 [EditorBrowsable(EditorBrowsableState.Advanced)]
3676 protected void UpdateZOrder() {
3677 Control [] controls;
3678 if (!IsHandleCreated) {
3682 controls = child_controls.GetAllControls ();
3683 for (int i = 1; i < controls.Length; i++ ) {
3684 XplatUI.SetZOrder(controls[i].Handle, controls[i-1].Handle, false, false);
3688 protected virtual void WndProc(ref Message m) {
3690 Console.WriteLine("Control {0} received message {1}", window.Handle == IntPtr.Zero ? this.Text : XplatUI.Window(window.Handle), (Msg)m.Msg);
3692 if ((this.control_style & ControlStyles.EnableNotifyMessage) != 0) {
3696 switch((Msg)m.Msg) {
3697 case Msg.WM_DESTROY: {
3698 OnHandleDestroyed(EventArgs.Empty);
3699 window.InvalidateHandle();
3701 if (ParentIsRecreating) {
3703 } else if (is_recreating) {
3709 case Msg.WM_WINDOWPOSCHANGED: {
3712 if (GetStyle(ControlStyles.ResizeRedraw)) {
3719 case Msg.WM_PAINT: {
3720 PaintEventArgs paint_event;
3722 paint_event = XplatUI.PaintEventStart(Handle, true);
3724 if (!needs_redraw) {
3725 // Just blit the previous image
3726 paint_event.Graphics.DrawImage (ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle, GraphicsUnit.Pixel);
3727 XplatUI.PaintEventEnd(Handle, true);
3732 if (ThemeEngine.Current.DoubleBufferingSupported)
3733 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
3734 dc = paint_event.SetGraphics (DeviceContext);
3737 OnPaintBackground(paint_event);
3738 // Leave out for now, our controls can do Paint += ... as well
3739 //OnPaintInternal(paint_event);
3740 OnPaint(paint_event);
3742 if (ThemeEngine.Current.DoubleBufferingSupported)
3743 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
3744 dc.DrawImage (ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle, GraphicsUnit.Pixel);
3745 paint_event.SetGraphics (dc);
3746 needs_redraw = false;
3749 XplatUI.PaintEventEnd(Handle, true);
3754 case Msg.WM_ERASEBKGND: {
3755 // The DefWndProc will never have to handle this, we always paint the background in managed code
3756 m.Result = (IntPtr)1;
3760 case Msg.WM_LBUTTONUP: {
3763 me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Left,
3765 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3768 HandleClick(mouse_clicks, me);
3775 if (mouse_clicks > 1) {
3781 case Msg.WM_LBUTTONDOWN: {
3782 if (CanSelect && !is_selected) {
3786 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3787 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3793 case Msg.WM_LBUTTONDBLCLK: {
3796 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3797 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3803 case Msg.WM_MBUTTONUP: {
3806 me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Middle,
3808 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3811 HandleClick(mouse_clicks, me);
3816 if (mouse_clicks > 1) {
3822 case Msg.WM_MBUTTONDOWN: {
3824 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3825 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3831 case Msg.WM_MBUTTONDBLCLK: {
3834 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3835 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3840 case Msg.WM_RBUTTONUP: {
3843 if (context_menu != null) {
3844 context_menu.Show(this, new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ())));
3846 me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Right,
3848 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3851 HandleClick(mouse_clicks, me);
3858 if (mouse_clicks > 1) {
3864 case Msg.WM_RBUTTONDOWN: {
3866 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3867 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3872 case Msg.WM_RBUTTONDBLCLK: {
3875 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3876 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3881 case Msg.WM_MOUSEWHEEL: {
3883 OnMouseWheel (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3884 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3885 HighOrder(m.WParam.ToInt32())));
3890 case Msg.WM_MOUSEMOVE: {
3891 OnMouseMove (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3893 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3898 case Msg.WM_MOUSE_ENTER: {
3903 OnMouseEnter(EventArgs.Empty);
3907 case Msg.WM_MOUSE_LEAVE: {
3909 OnMouseLeave(EventArgs.Empty);
3913 case Msg.WM_MOUSEHOVER: {
3914 OnMouseHover(EventArgs.Empty);
3918 case Msg.WM_SYSKEYUP: {
3919 if (ProcessKeyMessage(ref m)) {
3920 m.Result = IntPtr.Zero;
3924 if ((m.WParam.ToInt32() & (int)Keys.KeyCode) == (int)Keys.Menu) {
3928 if (form != null && form.ActiveMenu != null) {
3929 form.ActiveMenu.ProcessCmdKey(ref m, (Keys)m.WParam.ToInt32());
3937 case Msg.WM_SYSKEYDOWN:
3938 case Msg.WM_KEYDOWN:
3940 case Msg.WM_SYSCHAR:
3942 if (ProcessKeyMessage(ref m)) {
3943 m.Result = IntPtr.Zero;
3952 if (m.LParam != IntPtr.Zero) {
3955 hi = new HELPINFO();
3957 hi = (HELPINFO) Marshal.PtrToStructure (m.LParam, typeof (HELPINFO));
3958 mouse_pos = new Point(hi.MousePos.x, hi.MousePos.y);
3960 mouse_pos = Control.MousePosition;
3962 OnHelpRequested(new HelpEventArgs(mouse_pos));
3963 m.Result = (IntPtr)1;
3967 case Msg.WM_KILLFOCUS: {
3968 OnLeave(EventArgs.Empty);
3969 if (CausesValidation) {
3971 e = new CancelEventArgs(false);
3980 OnValidated(EventArgs.Empty);
3983 this.has_focus = false;
3984 this.is_selected = false;
3985 OnLostFocus(EventArgs.Empty);
3989 case Msg.WM_SETFOCUS: {
3990 OnEnter(EventArgs.Empty);
3991 this.has_focus = true;
3992 OnGotFocus(EventArgs.Empty);
3997 case Msg.WM_SYSCOLORCHANGE: {
3998 ThemeEngine.Current.ResetDefaults();
3999 OnSystemColorsChanged(EventArgs.Empty);
4004 case Msg.WM_SETCURSOR: {
4005 if ((cursor == null) || ((HitTest)(m.LParam.ToInt32() & 0xffff) != HitTest.HTCLIENT)) {
4010 XplatUI.SetCursor(window.Handle, cursor.handle);
4011 m.Result = (IntPtr)1;
4022 #endregion // Public Instance Methods
4024 #region OnXXX methods
4025 [EditorBrowsable(EditorBrowsableState.Advanced)]
4026 protected virtual void OnBackColorChanged(EventArgs e) {
4027 if (BackColorChanged!=null) BackColorChanged(this, e);
4028 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackColorChanged(e);
4031 [EditorBrowsable(EditorBrowsableState.Advanced)]
4032 protected virtual void OnBackgroundImageChanged(EventArgs e) {
4033 if (BackgroundImageChanged!=null) BackgroundImageChanged(this, e);
4034 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackgroundImageChanged(e);
4037 [EditorBrowsable(EditorBrowsableState.Advanced)]
4038 protected virtual void OnBindingContextChanged(EventArgs e) {
4039 CheckDataBindings ();
4040 if (BindingContextChanged!=null) {
4041 BindingContextChanged(this, e);
4043 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBindingContextChanged(e);
4046 [EditorBrowsable(EditorBrowsableState.Advanced)]
4047 protected virtual void OnCausesValidationChanged(EventArgs e) {
4048 if (CausesValidationChanged!=null) CausesValidationChanged(this, e);
4051 [EditorBrowsable(EditorBrowsableState.Advanced)]
4052 protected virtual void OnChangeUICues(UICuesEventArgs e) {
4053 if (ChangeUICues!=null) ChangeUICues(this, e);
4056 [EditorBrowsable(EditorBrowsableState.Advanced)]
4057 protected virtual void OnClick(EventArgs e) {
4058 if (Click!=null) Click(this, e);
4061 [EditorBrowsable(EditorBrowsableState.Advanced)]
4062 protected virtual void OnContextMenuChanged(EventArgs e) {
4063 if (ContextMenuChanged!=null) ContextMenuChanged(this, e);
4066 [EditorBrowsable(EditorBrowsableState.Advanced)]
4067 protected virtual void OnControlAdded(ControlEventArgs e) {
4068 if (ControlAdded!=null) ControlAdded(this, e);
4071 [EditorBrowsable(EditorBrowsableState.Advanced)]
4072 protected virtual void OnControlRemoved(ControlEventArgs e) {
4073 if (ControlRemoved!=null) ControlRemoved(this, e);
4076 [EditorBrowsable(EditorBrowsableState.Advanced)]
4077 protected virtual void OnCreateControl() {
4081 [EditorBrowsable(EditorBrowsableState.Advanced)]
4082 protected virtual void OnCursorChanged(EventArgs e) {
4083 if (CursorChanged!=null) CursorChanged(this, e);
4086 [EditorBrowsable(EditorBrowsableState.Advanced)]
4087 protected virtual void OnDockChanged(EventArgs e) {
4088 if (DockChanged!=null) DockChanged(this, e);
4091 [EditorBrowsable(EditorBrowsableState.Advanced)]
4092 protected virtual void OnDoubleClick(EventArgs e) {
4093 if (DoubleClick!=null) DoubleClick(this, e);
4096 [EditorBrowsable(EditorBrowsableState.Advanced)]
4097 protected virtual void OnDragDrop(DragEventArgs drgevent) {
4098 if (DragDrop!=null) DragDrop(this, drgevent);
4101 [EditorBrowsable(EditorBrowsableState.Advanced)]
4102 protected virtual void OnDragEnter(DragEventArgs drgevent) {
4103 if (DragEnter!=null) DragEnter(this, drgevent);
4106 [EditorBrowsable(EditorBrowsableState.Advanced)]
4107 protected virtual void OnDragLeave(EventArgs e) {
4108 if (DragLeave!=null) DragLeave(this, e);
4111 [EditorBrowsable(EditorBrowsableState.Advanced)]
4112 protected virtual void OnDragOver(DragEventArgs drgevent) {
4113 if (DragOver!=null) DragOver(this, drgevent);
4116 [EditorBrowsable(EditorBrowsableState.Advanced)]
4117 protected virtual void OnEnabledChanged(EventArgs e) {
4118 if (EnabledChanged!=null) EnabledChanged(this, e);
4119 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentEnabledChanged(e);
4122 [EditorBrowsable(EditorBrowsableState.Advanced)]
4123 protected virtual void OnEnter(EventArgs e) {
4124 if (Enter!=null) Enter(this, e);
4127 [EditorBrowsable(EditorBrowsableState.Advanced)]
4128 protected virtual void OnFontChanged(EventArgs e) {
4129 if (FontChanged!=null) FontChanged(this, e);
4130 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentFontChanged(e);
4133 [EditorBrowsable(EditorBrowsableState.Advanced)]
4134 protected virtual void OnForeColorChanged(EventArgs e) {
4135 if (ForeColorChanged!=null) ForeColorChanged(this, e);
4136 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentForeColorChanged(e);
4139 [EditorBrowsable(EditorBrowsableState.Advanced)]
4140 protected virtual void OnGiveFeedback(GiveFeedbackEventArgs gfbevent) {
4141 if (GiveFeedback!=null) GiveFeedback(this, gfbevent);
4144 [EditorBrowsable(EditorBrowsableState.Advanced)]
4145 protected virtual void OnGotFocus(EventArgs e) {
4146 if (GotFocus!=null) GotFocus(this, e);
4149 [EditorBrowsable(EditorBrowsableState.Advanced)]
4150 protected virtual void OnHandleCreated(EventArgs e) {
4151 if (HandleCreated!=null) HandleCreated(this, e);
4154 [EditorBrowsable(EditorBrowsableState.Advanced)]
4155 protected virtual void OnHandleDestroyed(EventArgs e) {
4156 if (HandleDestroyed!=null) HandleDestroyed(this, e);
4159 [EditorBrowsable(EditorBrowsableState.Advanced)]
4160 protected virtual void OnHelpRequested(HelpEventArgs hevent) {
4161 if (HelpRequested!=null) HelpRequested(this, hevent);
4164 protected virtual void OnImeModeChanged(EventArgs e) {
4165 if (ImeModeChanged!=null) ImeModeChanged(this, e);
4168 [EditorBrowsable(EditorBrowsableState.Advanced)]
4169 protected virtual void OnInvalidated(InvalidateEventArgs e) {
4170 needs_redraw = true;
4171 if (Invalidated!=null) Invalidated(this, e);
4174 [EditorBrowsable(EditorBrowsableState.Advanced)]
4175 protected virtual void OnKeyDown(KeyEventArgs e) {
4176 if (KeyDown!=null) KeyDown(this, e);
4179 [EditorBrowsable(EditorBrowsableState.Advanced)]
4180 protected virtual void OnKeyPress(KeyPressEventArgs e) {
4181 if (KeyPress!=null) KeyPress(this, e);
4184 [EditorBrowsable(EditorBrowsableState.Advanced)]
4185 protected virtual void OnKeyUp(KeyEventArgs e) {
4186 if (KeyUp!=null) KeyUp(this, e);
4189 [EditorBrowsable(EditorBrowsableState.Advanced)]
4190 protected virtual void OnLayout(LayoutEventArgs levent) {
4191 if (Layout!=null) Layout(this, levent);
4194 [EditorBrowsable(EditorBrowsableState.Advanced)]
4195 protected virtual void OnLeave(EventArgs e) {
4196 if (Leave!=null) Leave(this, e);
4199 [EditorBrowsable(EditorBrowsableState.Advanced)]
4200 protected virtual void OnLocationChanged(EventArgs e) {
4202 if (LocationChanged!=null) LocationChanged(this, e);
4205 [EditorBrowsable(EditorBrowsableState.Advanced)]
4206 protected virtual void OnLostFocus(EventArgs e) {
4207 if (LostFocus!=null) LostFocus(this, e);
4210 [EditorBrowsable(EditorBrowsableState.Advanced)]
4211 protected virtual void OnMouseDown(MouseEventArgs e) {
4212 if (MouseDown!=null) MouseDown(this, e);
4215 [EditorBrowsable(EditorBrowsableState.Advanced)]
4216 protected virtual void OnMouseEnter(EventArgs e) {
4217 if (MouseEnter!=null) MouseEnter(this, e);
4220 [EditorBrowsable(EditorBrowsableState.Advanced)]
4221 protected virtual void OnMouseHover(EventArgs e) {
4222 if (MouseHover!=null) MouseHover(this, e);
4225 [EditorBrowsable(EditorBrowsableState.Advanced)]
4226 protected virtual void OnMouseLeave(EventArgs e) {
4227 if (MouseLeave!=null) MouseLeave(this, e);
4230 [EditorBrowsable(EditorBrowsableState.Advanced)]
4231 protected virtual void OnMouseMove(MouseEventArgs e) {
4232 if (MouseMove!=null) MouseMove(this, e);
4235 [EditorBrowsable(EditorBrowsableState.Advanced)]
4236 protected virtual void OnMouseUp(MouseEventArgs e) {
4237 if (MouseUp!=null) MouseUp(this, e);
4240 [EditorBrowsable(EditorBrowsableState.Advanced)]
4241 protected virtual void OnMouseWheel(MouseEventArgs e) {
4242 if (MouseWheel!=null) MouseWheel(this, e);
4245 [EditorBrowsable(EditorBrowsableState.Advanced)]
4246 protected virtual void OnMove(EventArgs e) {
4247 if (Move!=null) Move(this, e);
4250 [EditorBrowsable(EditorBrowsableState.Advanced)]
4251 protected virtual void OnNotifyMessage(Message m) {
4255 [EditorBrowsable(EditorBrowsableState.Advanced)]
4256 protected virtual void OnPaint(PaintEventArgs e) {
4257 if (Paint!=null) Paint(this, e);
4260 internal virtual void OnPaintInternal(PaintEventArgs e) {
4264 [EditorBrowsable(EditorBrowsableState.Advanced)]
4265 protected virtual void OnPaintBackground(PaintEventArgs pevent) {
4266 PaintControlBackground (pevent);
4269 [EditorBrowsable(EditorBrowsableState.Advanced)]
4270 protected virtual void OnParentBackColorChanged(EventArgs e) {
4271 if (background_color.IsEmpty && background_image==null) {
4273 OnBackColorChanged(e);
4277 [EditorBrowsable(EditorBrowsableState.Advanced)]
4278 protected virtual void OnParentBackgroundImageChanged(EventArgs e) {
4279 if (background_color.IsEmpty && background_image==null) {
4281 OnBackgroundImageChanged(e);
4285 [EditorBrowsable(EditorBrowsableState.Advanced)]
4286 protected virtual void OnParentBindingContextChanged(EventArgs e) {
4287 if (binding_context==null) {
4288 binding_context=Parent.binding_context;
4289 OnBindingContextChanged(e);
4293 [EditorBrowsable(EditorBrowsableState.Advanced)]
4294 protected virtual void OnParentChanged(EventArgs e) {
4295 if (ParentChanged!=null) ParentChanged(this, e);
4298 [EditorBrowsable(EditorBrowsableState.Advanced)]
4299 protected virtual void OnParentEnabledChanged(EventArgs e) {
4300 if (is_enabled != Parent.is_enabled) {
4301 is_enabled=Parent.is_enabled;
4303 if (EnabledChanged != null) {
4304 EnabledChanged(this, e);
4309 [EditorBrowsable(EditorBrowsableState.Advanced)]
4310 protected virtual void OnParentFontChanged(EventArgs e) {
4317 [EditorBrowsable(EditorBrowsableState.Advanced)]
4318 protected virtual void OnParentForeColorChanged(EventArgs e) {
4319 if (foreground_color.IsEmpty) {
4321 OnForeColorChanged(e);
4325 [EditorBrowsable(EditorBrowsableState.Advanced)]
4326 protected virtual void OnParentRightToLeftChanged(EventArgs e) {
4327 if (right_to_left==RightToLeft.Inherit) {
4329 OnRightToLeftChanged(e);
4333 [EditorBrowsable(EditorBrowsableState.Advanced)]
4334 protected virtual void OnParentVisibleChanged(EventArgs e) {
4336 OnVisibleChanged(e);
4340 [EditorBrowsable(EditorBrowsableState.Advanced)]
4341 protected virtual void OnQueryContinueDrag(QueryContinueDragEventArgs e) {
4342 if (QueryContinueDrag!=null) QueryContinueDrag(this, e);
4345 [EditorBrowsable(EditorBrowsableState.Advanced)]
4346 protected virtual void OnResize(EventArgs e) {
4347 if (Resize!=null) Resize(this, e);
4349 PerformLayout(this, "bounds");
4351 if (parent != null) {
4352 parent.PerformLayout();
4356 [EditorBrowsable(EditorBrowsableState.Advanced)]
4357 protected virtual void OnRightToLeftChanged(EventArgs e) {
4358 if (RightToLeftChanged!=null) RightToLeftChanged(this, e);
4359 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentRightToLeftChanged(e);
4362 [EditorBrowsable(EditorBrowsableState.Advanced)]
4363 protected virtual void OnSizeChanged(EventArgs e) {
4364 InvalidateBuffers ();
4366 if (SizeChanged!=null) SizeChanged(this, e);
4369 [EditorBrowsable(EditorBrowsableState.Advanced)]
4370 protected virtual void OnStyleChanged(EventArgs e) {
4371 if (StyleChanged!=null) StyleChanged(this, e);
4374 [EditorBrowsable(EditorBrowsableState.Advanced)]
4375 protected virtual void OnSystemColorsChanged(EventArgs e) {
4376 if (SystemColorsChanged!=null) SystemColorsChanged(this, e);
4379 [EditorBrowsable(EditorBrowsableState.Advanced)]
4380 protected virtual void OnTabIndexChanged(EventArgs e) {
4381 if (TabIndexChanged!=null) TabIndexChanged(this, e);
4384 [EditorBrowsable(EditorBrowsableState.Advanced)]
4385 protected virtual void OnTabStopChanged(EventArgs e) {
4386 if (TabStopChanged!=null) TabStopChanged(this, e);
4389 [EditorBrowsable(EditorBrowsableState.Advanced)]
4390 protected virtual void OnTextChanged(EventArgs e) {
4391 if (TextChanged!=null) TextChanged(this, e);
4394 [EditorBrowsable(EditorBrowsableState.Advanced)]
4395 protected virtual void OnValidated(EventArgs e) {
4396 if (Validated!=null) Validated(this, e);
4399 [EditorBrowsable(EditorBrowsableState.Advanced)]
4400 protected virtual void OnValidating(System.ComponentModel.CancelEventArgs e) {
4401 if (Validating!=null) Validating(this, e);
4404 [EditorBrowsable(EditorBrowsableState.Advanced)]
4405 protected virtual void OnVisibleChanged(EventArgs e) {
4406 if ((parent != null) && !Created && Visible) {
4413 needs_redraw = true;
4415 if (VisibleChanged!=null) VisibleChanged(this, e);
4417 // We need to tell our kids
4418 for (int i=0; i<child_controls.Count; i++) {
4419 if (child_controls[i].Visible) {
4420 child_controls[i].OnParentVisibleChanged(e);
4424 #endregion // OnXXX methods
4427 public event EventHandler BackColorChanged;
4428 public event EventHandler BackgroundImageChanged;
4429 public event EventHandler BindingContextChanged;
4430 public event EventHandler CausesValidationChanged;
4431 public event UICuesEventHandler ChangeUICues;
4432 public event EventHandler Click;
4433 public event EventHandler ContextMenuChanged;
4435 [EditorBrowsable(EditorBrowsableState.Advanced)]
4437 public event ControlEventHandler ControlAdded;
4439 [EditorBrowsable(EditorBrowsableState.Advanced)]
4441 public event ControlEventHandler ControlRemoved;
4443 [MWFDescription("Fired when the cursor for the control has been changed"), MWFCategory("PropertyChanged")]
4444 public event EventHandler CursorChanged;
4445 public event EventHandler DockChanged;
4446 public event EventHandler DoubleClick;
4447 public event DragEventHandler DragDrop;
4448 public event DragEventHandler DragEnter;
4449 public event EventHandler DragLeave;
4450 public event DragEventHandler DragOver;
4451 public event EventHandler EnabledChanged;
4452 public event EventHandler Enter;
4453 public event EventHandler FontChanged;
4454 public event EventHandler ForeColorChanged;
4455 public event GiveFeedbackEventHandler GiveFeedback;
4457 [EditorBrowsable(EditorBrowsableState.Advanced)]
4459 public event EventHandler GotFocus;
4461 [EditorBrowsable(EditorBrowsableState.Advanced)]
4463 public event EventHandler HandleCreated;
4465 [EditorBrowsable(EditorBrowsableState.Advanced)]
4467 public event EventHandler HandleDestroyed;
4469 public event HelpEventHandler HelpRequested;
4470 public event EventHandler ImeModeChanged;
4472 [EditorBrowsable(EditorBrowsableState.Advanced)]
4474 public event InvalidateEventHandler Invalidated;
4476 public event KeyEventHandler KeyDown;
4477 public event KeyPressEventHandler KeyPress;
4478 public event KeyEventHandler KeyUp;
4479 public event LayoutEventHandler Layout;
4480 public event EventHandler Leave;
4481 public event EventHandler LocationChanged;
4483 [EditorBrowsable(EditorBrowsableState.Advanced)]
4485 public event EventHandler LostFocus;
4487 public event MouseEventHandler MouseDown;
4488 public event EventHandler MouseEnter;
4489 public event EventHandler MouseHover;
4490 public event EventHandler MouseLeave;
4491 public event MouseEventHandler MouseMove;
4492 public event MouseEventHandler MouseUp;
4494 [EditorBrowsable(EditorBrowsableState.Advanced)]
4496 public event MouseEventHandler MouseWheel;
4498 public event EventHandler Move;
4499 public event PaintEventHandler Paint;
4500 public event EventHandler ParentChanged;
4501 public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp;
4502 public event QueryContinueDragEventHandler QueryContinueDrag;
4503 public event EventHandler Resize;
4504 public event EventHandler RightToLeftChanged;
4505 public event EventHandler SizeChanged;
4506 public event EventHandler StyleChanged;
4507 public event EventHandler SystemColorsChanged;
4508 public event EventHandler TabIndexChanged;
4509 public event EventHandler TabStopChanged;
4510 public event EventHandler TextChanged;
4511 public event EventHandler Validated;
4512 public event CancelEventHandler Validating;
4513 public event EventHandler VisibleChanged;
4514 #endregion // Events