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 static internal bool verify_thread_handle;
126 private Padding padding;
129 #endregion // Local Variables
131 #region Private Classes
132 // This helper class allows us to dispatch messages to Control.WndProc
133 internal class ControlNativeWindow : NativeWindow {
134 private Control owner;
136 public ControlNativeWindow(Control control) : base() {
141 public Control Owner {
147 static internal Control ControlFromHandle(IntPtr hWnd) {
148 ControlNativeWindow window;
150 window = (ControlNativeWindow)window_collection[hWnd];
151 if (window != null) {
158 protected override void WndProc(ref Message m) {
159 owner.WndProc(ref m);
164 #region Public Classes
166 public class ControlAccessibleObject : AccessibleObject {
167 #region ControlAccessibleObject Constructors
168 public ControlAccessibleObject(Control ownerControl) {
169 this.owner = ownerControl;
171 #endregion // ControlAccessibleObject Constructors
173 #region ControlAccessibleObject Public Instance Properties
174 public override string DefaultAction {
176 return base.DefaultAction;
180 public override string Description {
182 return base.Description;
186 public IntPtr Handle {
192 // We don't want to let them set it
196 public override string Help {
202 public override string KeyboardShortcut {
204 return base.KeyboardShortcut;
208 public override string Name {
218 public Control Owner {
224 public override AccessibleObject Parent {
231 public override AccessibleRole Role {
236 #endregion // ControlAccessibleObject Public Instance Properties
238 #region ControlAccessibleObject Public Instance Methods
239 public override int GetHelpTopic(out string FileName) {
240 return base.GetHelpTopic (out FileName);
243 [MonoTODO("Implement this and tie it into Control.AccessibilityNotifyClients")]
244 public void NotifyClients(AccessibleEvents accEvent) {
245 throw new NotImplementedException();
248 [MonoTODO("Implement this and tie it into Control.AccessibilityNotifyClients")]
249 public void NotifyClients(AccessibleEvents accEvent, int childID) {
250 throw new NotImplementedException();
253 public override string ToString() {
254 return "ControlAccessibleObject: Owner = " + owner.ToString() + ", Text: " + owner.text;
257 #endregion // ControlAccessibleObject Public Instance Methods
260 [DesignerSerializer("System.Windows.Forms.Design.ControlCollectionCodeDomSerializer, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
261 [ListBindable(false)]
262 public class ControlCollection : IList, ICollection, ICloneable, IEnumerable {
263 #region ControlCollection Local Variables
264 private ArrayList list;
265 internal ArrayList impl_list;
266 private Control [] all_controls;
267 internal Control owner;
268 #endregion // ControlCollection Local Variables
270 #region ControlCollection Public Constructor
271 public ControlCollection(Control owner) {
273 this.list=new ArrayList();
277 #region ControlCollection Public Instance Properties
284 public bool IsReadOnly {
286 return list.IsReadOnly;
290 public virtual Control this[int index] {
292 if (index < 0 || index >= list.Count) {
293 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
295 return (Control)list[index];
298 #endregion // ControlCollection Public Instance Properties
300 #region ControlCollection Private Instance Methods
301 public virtual void Add (Control value)
306 if (Contains (value)) {
307 owner.PerformLayout();
311 if (value.tab_index == -1) {
317 end = owner.child_controls.Count;
318 for (int i = 0; i < end; i++) {
319 index = owner.child_controls[i].tab_index;
324 value.tab_index = use;
327 if (value.parent != null) {
328 value.parent.Controls.Remove(value);
334 value.ChangeParent(owner);
338 owner.UpdateZOrder();
339 owner.PerformLayout(value, "Parent");
340 owner.OnControlAdded(new ControlEventArgs(value));
343 internal void AddToList (Control c)
349 internal virtual void AddImplicit (Control control)
351 if (impl_list == null)
352 impl_list = new ArrayList ();
354 impl_list.Add (control);
356 control.ChangeParent (owner);
357 control.InitLayout ();
358 owner.UpdateZOrder ();
359 owner.PerformLayout (control, "Parent");
360 owner.OnControlAdded (new ControlEventArgs (control));
363 public virtual void AddRange (Control[] controls)
365 if (controls == null)
366 throw new ArgumentNullException ("controls");
368 owner.SuspendLayout ();
371 for (int i = 0; i < controls.Length; i++)
374 owner.ResumeLayout ();
378 internal virtual void AddRangeImplicit (Control [] controls)
380 if (controls == null)
381 throw new ArgumentNullException ("controls");
383 owner.SuspendLayout ();
386 for (int i = 0; i < controls.Length; i++)
387 AddImplicit (controls [i]);
389 owner.ResumeLayout ();
393 public virtual void Clear ()
397 // MS sends remove events in reverse order
398 while (list.Count > 0) {
399 RemoveAt(list.Count - 1);
403 internal virtual void ClearImplicit ()
405 if (impl_list == null)
411 public bool Contains (Control value)
413 for (int i = list.Count; i > 0; ) {
416 if (list [i] == value) {
417 // Do we need to do anything here?
424 internal bool ImplicitContains (Control value)
426 if (impl_list == null)
429 for (int i = impl_list.Count; i > 0; ) {
432 if (impl_list [i] == value) {
433 // Do we need to do anything here?
440 internal bool AllContains (Control value)
442 return Contains (value) || ImplicitContains (value);
445 public void CopyTo (Array array, int index)
447 list.CopyTo(array, index);
450 public override bool Equals(object other) {
451 if (other is ControlCollection && (((ControlCollection)other).owner==this.owner)) {
458 public int GetChildIndex(Control child) {
459 return GetChildIndex(child, false);
462 public int GetChildIndex(Control child, bool throwException) {
465 index=list.IndexOf(child);
467 if (index==-1 && throwException) {
468 throw new ArgumentException("Not a child control", "child");
473 public IEnumerator GetEnumerator() {
474 return list.GetEnumerator();
477 internal IEnumerator GetAllEnumerator ()
479 Control [] res = GetAllControls ();
480 return res.GetEnumerator ();
483 internal Control [] GetAllControls ()
485 if (all_controls != null)
488 if (impl_list == null)
489 return (Control []) list.ToArray (typeof (Control));
491 Control [] res = new Control [list.Count + impl_list.Count];
492 impl_list.CopyTo (res);
493 list.CopyTo (res, impl_list.Count);
498 public override int GetHashCode() {
499 return base.GetHashCode();
502 public int IndexOf(Control control) {
503 return list.IndexOf(control);
506 public virtual void Remove(Control value) {
509 owner.PerformLayout(value, "Parent");
510 owner.OnControlRemoved(new ControlEventArgs(value));
513 value.ChangeParent(null);
515 owner.UpdateZOrder();
518 internal virtual void RemoveImplicit (Control control)
520 if (impl_list != null) {
522 owner.PerformLayout (control, "Parent");
523 owner.OnControlRemoved (new ControlEventArgs (control));
524 impl_list.Remove (control);
526 control.ChangeParent (null);
527 owner.UpdateZOrder ();
530 public void RemoveAt(int index) {
531 if (index < 0 || index >= list.Count) {
532 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
534 Remove ((Control)list[index]);
537 public void SetChildIndex(Control child, int newIndex) {
540 old_index=list.IndexOf(child);
542 throw new ArgumentException("Not a child control", "child");
545 if (old_index==newIndex) {
549 list.RemoveAt(old_index);
551 if (newIndex>list.Count) {
554 list.Insert(newIndex, child);
556 owner.UpdateZOrder();
558 #endregion // ControlCollection Private Instance Methods
560 #region ControlCollection Interface Properties
561 object IList.this[int index] {
563 if (index<0 || index>=list.Count) {
564 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
570 if (!(value is Control)) {
571 throw new ArgumentException("Object of type Control required", "value");
574 list[index]=(Control)value;
578 bool IList.IsFixedSize {
584 bool ICollection.IsSynchronized {
586 return list.IsSynchronized;
590 object ICollection.SyncRoot {
592 return list.SyncRoot;
595 #endregion // ControlCollection Interface Properties
597 #region ControlCollection Interface Methods
598 int IList.Add(object value) {
600 throw new ArgumentNullException("value", "Cannot add null controls");
603 if (!(value is Control)) {
604 throw new ArgumentException("Object of type Control required", "value");
607 return list.Add(value);
610 bool IList.Contains(object value) {
611 if (!(value is Control)) {
612 throw new ArgumentException("Object of type Control required", "value");
615 return this.Contains((Control) value);
618 int IList.IndexOf(object value) {
619 if (!(value is Control)) {
620 throw new ArgumentException("Object of type Control required", "value");
623 return this.IndexOf((Control) value);
626 void IList.Insert(int index, object value) {
627 if (!(value is Control)) {
628 throw new ArgumentException("Object of type Control required", "value");
631 list.Insert(index, value);
634 void IList.Remove(object value) {
635 if (!(value is Control)) {
636 throw new ArgumentException("Object of type Control required", "value");
642 Object ICloneable.Clone() {
643 ControlCollection clone = new ControlCollection(this.owner);
644 clone.list=(ArrayList)list.Clone(); // FIXME: Do we need this?
647 #endregion // ControlCollection Interface Methods
649 #endregion // ControlCollection Class
651 #region Public Constructors
654 anchor_style = AnchorStyles.Top | AnchorStyles.Left;
662 layout_pending = false;
664 causes_validation = true;
666 layout_suspended = 0;
670 right_to_left = RightToLeft.Inherit;
671 border_style = BorderStyle.None;
672 background_color = Color.Empty;
679 use_compatible_text_rendering = Application.use_compatible_text_rendering;
680 padding = new Padding(0);
683 control_style = ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint |
684 ControlStyles.Selectable | ControlStyles.StandardClick |
685 ControlStyles.StandardDoubleClick;
688 background_image = null;
692 window = new ControlNativeWindow(this);
693 child_controls = CreateControlsInstance();
694 client_size = new Size(DefaultSize.Width, DefaultSize.Height);
695 client_rect = new Rectangle(0, 0, DefaultSize.Width, DefaultSize.Height);
696 XplatUI.CalculateWindowRect(ref client_rect, CreateParams.Style, CreateParams.ExStyle, null, out bounds);
697 if ((CreateParams.Style & (int)WindowStyles.WS_CHILD) == 0) {
703 public Control(Control parent, string text) : this() {
708 public Control(Control parent, string text, int left, int top, int width, int height) : this() {
713 bounds.Height=height;
714 SetBoundsCore(left, top, width, height, BoundsSpecified.All);
718 public Control(string text) : this() {
722 public Control(string text, int left, int top, int width, int height) : this() {
726 bounds.Height=height;
727 SetBoundsCore(left, top, width, height, BoundsSpecified.All);
731 private delegate void RemoveDelegate(object c);
733 protected override void Dispose(bool disposing) {
744 if (this.InvokeRequired) {
745 if (Application.MessageLoop) {
746 this.BeginInvokeInternal(new MethodInvoker(DestroyHandle), null, true);
747 this.BeginInvokeInternal(new RemoveDelegate(controls.Remove), new object[] {this}, true);
751 controls.Remove(this);
754 base.Dispose(disposing);
756 #endregion // Public Constructors
758 #region Internal Properties
759 internal BorderStyle InternalBorderStyle {
765 if (!Enum.IsDefined (typeof (BorderStyle), value))
766 throw new InvalidEnumArgumentException (string.Format("Enum argument value '{0}' is not valid for BorderStyle", value));
768 if (border_style != value) {
769 border_style = value;
771 if (IsHandleCreated) {
772 XplatUI.SetBorderStyle(window.Handle, (FormBorderStyle)border_style);
778 #endregion // Internal Properties
780 #region Private & Internal Methods
781 internal IAsyncResult BeginInvokeInternal (Delegate method, object [] args, bool disposing) {
782 AsyncMethodResult result;
783 AsyncMethodData data;
790 if (!p.IsHandleCreated) {
791 throw new InvalidOperationException("Cannot call Invoke or InvokeAsync on a control until the window handle is created");
797 result = new AsyncMethodResult ();
798 data = new AsyncMethodData ();
800 data.Method = method;
802 data.Result = result;
805 if (!ExecutionContext.IsFlowSuppressed ()) {
806 data.Context = ExecutionContext.Capture ();
809 #if !MWF_ON_MSRUNTIME
810 if (SecurityManager.SecurityEnabled) {
811 data.Stack = CompressedStack.GetCompressedStack ();
816 XplatUI.SendAsyncMethod (data);
821 internal void PointToClient (ref int x, ref int y)
823 XplatUI.ScreenToClient (Handle, ref x, ref y);
826 internal void PointToScreen (ref int x, ref int y)
828 XplatUI.ClientToScreen (Handle, ref x, ref y);
831 private bool IsRecreating {
837 if (parent != null) {
838 return parent.IsRecreating;
845 private bool ParentIsRecreating {
847 if (parent != null) {
848 return parent.IsRecreating;
854 internal Graphics DeviceContext {
857 CreateBuffers(this.Width, this.Height);
863 private Bitmap ImageBuffer {
866 CreateBuffers(this.Width, this.Height);
872 internal void CreateBuffers (int width, int height) {
873 if (dc_mem != null) {
887 bmp_mem = new Bitmap (width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
888 dc_mem = Graphics.FromImage (bmp_mem);
892 internal void InvalidateBuffers ()
894 if (dc_mem != null) {
905 internal static void SetChildColor(Control parent) {
908 for (int i=0; i < parent.child_controls.Count; i++) {
909 child=parent.child_controls[i];
910 if (child.child_controls.Count>0) {
911 SetChildColor(child);
917 internal bool Select(Control control) {
919 IContainerControl container;
921 if (control == null) {
925 parent = control.parent;
927 if (((control.control_style & ControlStyles.Selectable) !=0) && (parent != null)) {
928 while (parent != null) {
929 if (!parent.Visible || !parent.is_enabled) {
932 parent = parent.parent;
936 control.is_selected = true;
938 container = GetContainerControl();
939 if (container != null) {
940 container.ActiveControl = control;
942 if (control.IsHandleCreated) {
943 XplatUI.SetFocus(control.window.Handle);
948 internal virtual void DoDefaultAction() {
949 // Only here to be overriden by our actual controls; this is needed by the accessibility class
952 internal static int LowOrder (int param) {
953 return ((int)(short)(param & 0xffff));
956 internal static int HighOrder (int param) {
957 return ((int)(short)(param >> 16));
960 // This method exists so controls overriding OnPaintBackground can have default background painting done
961 internal virtual void PaintControlBackground (PaintEventArgs pevent)
963 if (GetStyle(ControlStyles.SupportsTransparentBackColor) && (BackColor.A != 0xff)) {
964 if (parent != null) {
965 PaintEventArgs parent_pe;
968 parent_pe = new PaintEventArgs(pevent.Graphics, new Rectangle(pevent.ClipRectangle.X + Left, pevent.ClipRectangle.Y + Top, pevent.ClipRectangle.Width, pevent.ClipRectangle.Height));
970 state = parent_pe.Graphics.Save();
971 parent_pe.Graphics.TranslateTransform(-Left, -Top);
972 parent.OnPaintBackground(parent_pe);
973 parent_pe.Graphics.Restore(state);
975 state = parent_pe.Graphics.Save();
976 parent_pe.Graphics.TranslateTransform(-Left, -Top);
977 parent.OnPaint(parent_pe);
978 parent_pe.Graphics.Restore(state);
979 parent_pe.SetGraphics(null);
983 if (background_image == null) {
984 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));
988 DrawBackgroundImage (pevent.Graphics);
991 void DrawBackgroundImage (Graphics g)
993 using (TextureBrush b = new TextureBrush (background_image, WrapMode.Tile)) {
994 g.FillRectangle (b, ClientRectangle);
998 internal virtual void DndEnter (DragEventArgs e)
1005 internal virtual void DndOver (DragEventArgs e)
1012 internal virtual void DndDrop (DragEventArgs e)
1016 } catch (Exception exc) {
1017 Console.Error.WriteLine ("MWF: Exception while dropping:");
1018 Console.Error.WriteLine (exc);
1022 internal virtual void DndLeave (EventArgs e)
1029 internal virtual void DndFeedback(GiveFeedbackEventArgs e)
1036 internal virtual void DndContinueDrag(QueryContinueDragEventArgs e)
1039 OnQueryContinueDrag(e);
1043 internal static MouseButtons FromParamToMouseButtons (int param) {
1044 MouseButtons buttons = MouseButtons.None;
1046 if ((param & (int) MsgButtons.MK_LBUTTON) != 0)
1047 buttons |= MouseButtons.Left;
1049 if ((param & (int) MsgButtons.MK_MBUTTON) != 0)
1050 buttons |= MouseButtons.Middle;
1052 if ((param & (int) MsgButtons.MK_RBUTTON) != 0)
1053 buttons |= MouseButtons.Right;
1059 internal virtual bool ProcessControlMnemonic(char charCode) {
1060 return ProcessMnemonic(charCode);
1063 private static Control FindFlatForward(Control container, Control start) {
1069 end = container.child_controls.Count;
1071 if (start != null) {
1072 index = start.tab_index;
1077 for (int i = 0; i < end; i++) {
1078 if (found == null) {
1079 if (container.child_controls[i].tab_index > index) {
1080 found = container.child_controls[i];
1082 } else if (found.tab_index > container.child_controls[i].tab_index) {
1083 if (container.child_controls[i].tab_index > index) {
1084 found = container.child_controls[i];
1091 private static Control FindControlForward(Control container, Control start) {
1097 if (start != null) {
1098 if ((start is IContainerControl) || start.GetStyle(ControlStyles.ContainerControl)) {
1099 found = FindControlForward(start, null);
1100 if (found != null) {
1106 while (p != container) {
1107 found = FindFlatForward(p, start);
1108 if (found != null) {
1115 return FindFlatForward(container, start);
1118 private static Control FindFlatBackward(Control container, Control start) {
1124 end = container.child_controls.Count;
1126 if (start != null) {
1127 index = start.tab_index;
1129 // FIXME: Possible speed-up: Keep the highest taborder index in the container
1131 for (int i = 0; i < end; i++) {
1132 if (container.child_controls[i].tab_index > index) {
1133 index = container.child_controls[i].tab_index;
1139 for (int i = 0; i < end; i++) {
1140 if (found == null) {
1141 if (container.child_controls[i].tab_index < index) {
1142 found = container.child_controls[i];
1144 } else if (found.tab_index < container.child_controls[i].tab_index) {
1145 if (container.child_controls[i].tab_index < index) {
1146 found = container.child_controls[i];
1153 private static Control FindControlBackward(Control container, Control start) {
1158 if (start != null) {
1159 found = FindFlatBackward(start.parent, start);
1160 if (found == null && start.parent != container) {
1161 return start.parent;
1164 if (found == null) {
1165 found = FindFlatBackward(container, start);
1168 while ((found != null) && ((found is IContainerControl) || found.GetStyle(ControlStyles.ContainerControl))) {
1169 found = FindControlBackward(found, null);
1170 if (found != null) {
1178 private void HandleClick(int clicks, MouseEventArgs me) {
1179 if (GetStyle(ControlStyles.StandardClick)) {
1180 if ((clicks > 1) && GetStyle(ControlStyles.StandardDoubleClick)) {
1182 OnDoubleClick(EventArgs.Empty);
1184 OnClick(EventArgs.Empty);
1194 private void CheckDataBindings ()
1196 if (data_bindings == null)
1199 BindingContext binding_context = BindingContext;
1200 foreach (Binding binding in data_bindings) {
1201 binding.Check (binding_context);
1206 private void ChangeParent(Control new_parent) {
1210 Color pre_fore_color;
1211 Color pre_back_color;
1212 RightToLeft pre_rtl;
1214 // These properties are inherited from our parent
1215 // Get them pre parent-change and then send events
1216 // if they are changed after we have our new parent
1217 pre_enabled = Enabled;
1218 pre_visible = Visible;
1220 pre_fore_color = ForeColor;
1221 pre_back_color = BackColor;
1222 pre_rtl = RightToLeft;
1223 // MS doesn't seem to send a CursorChangedEvent
1225 parent = new_parent;
1227 if (IsHandleCreated && (new_parent != null) && new_parent.IsHandleCreated) {
1228 XplatUI.SetParent(Handle, new_parent.Handle);
1231 OnParentChanged(EventArgs.Empty);
1233 if (pre_enabled != Enabled) {
1234 OnEnabledChanged(EventArgs.Empty);
1237 if (pre_visible != Visible) {
1238 OnVisibleChanged(EventArgs.Empty);
1241 if (pre_font != Font) {
1242 OnFontChanged(EventArgs.Empty);
1245 if (pre_fore_color != ForeColor) {
1246 OnForeColorChanged(EventArgs.Empty);
1249 if (pre_back_color != BackColor) {
1250 OnBackColorChanged(EventArgs.Empty);
1253 if (pre_rtl != RightToLeft) {
1254 // MS sneaks a OnCreateControl and OnHandleCreated in here, I guess
1255 // because when RTL changes they have to recreate the win32 control
1256 // We don't really need that (until someone runs into compatibility issues)
1257 OnRightToLeftChanged(EventArgs.Empty);
1260 if ((new_parent != null) && new_parent.Created && !Created) {
1264 if ((binding_context == null) && Created) {
1265 OnBindingContextChanged(EventArgs.Empty);
1269 private void UpdateDistances() {
1270 if ((parent != null) && (parent.layout_suspended == 0)) {
1271 dist_left = bounds.X;
1272 dist_top = bounds.Y;
1273 dist_right = parent.ClientSize.Width - bounds.X - bounds.Width;
1274 dist_bottom = parent.ClientSize.Height - bounds.Y - bounds.Height;
1277 #endregion // Private & Internal Methods
1279 #region Public Static Properties
1280 public static Color DefaultBackColor {
1282 return ThemeEngine.Current.DefaultControlBackColor;
1286 public static Font DefaultFont {
1288 return ThemeEngine.Current.DefaultFont;
1292 public static Color DefaultForeColor {
1294 return ThemeEngine.Current.DefaultControlForeColor;
1298 public static Keys ModifierKeys {
1300 return XplatUI.State.ModifierKeys;
1304 public static MouseButtons MouseButtons {
1306 return XplatUI.State.MouseButtons;
1310 public static Point MousePosition {
1312 return Cursor.Position;
1318 public static bool CheckForIllegalCrossThreadCalls
1321 return verify_thread_handle;
1325 verify_thread_handle = value;
1329 #endregion // Public Static Properties
1331 #region Public Instance Properties
1332 [EditorBrowsable(EditorBrowsableState.Advanced)]
1334 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1335 public AccessibleObject AccessibilityObject {
1337 if (accessibility_object==null) {
1338 accessibility_object=CreateAccessibilityInstance();
1340 return accessibility_object;
1344 [EditorBrowsable(EditorBrowsableState.Advanced)]
1346 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1347 public string AccessibleDefaultActionDescription {
1349 return AccessibilityObject.default_action;
1353 AccessibilityObject.default_action=value;
1358 [DefaultValue(null)]
1359 [MWFCategory("Accessibility")]
1360 public string AccessibleDescription {
1362 return AccessibilityObject.description;
1366 AccessibilityObject.description=value;
1371 [DefaultValue(null)]
1372 [MWFCategory("Accessibility")]
1373 public string AccessibleName {
1375 return AccessibilityObject.Name;
1379 AccessibilityObject.Name=value;
1383 [DefaultValue(AccessibleRole.Default)]
1384 [MWFDescription("Role of the control"), MWFCategory("Accessibility")]
1385 public AccessibleRole AccessibleRole {
1387 return AccessibilityObject.role;
1391 AccessibilityObject.role=value;
1395 [DefaultValue(false)]
1396 [MWFCategory("Behavior")]
1397 public virtual bool AllowDrop {
1403 if (allow_drop == value)
1406 if (IsHandleCreated) {
1408 XplatUI.SetAllowDrop (Handle, value);
1414 [RefreshProperties(RefreshProperties.Repaint)]
1415 [DefaultValue(AnchorStyles.Top | AnchorStyles.Left)]
1416 [MWFCategory("Layout")]
1417 public virtual AnchorStyles Anchor {
1419 return anchor_style;
1425 if (parent != null) {
1426 parent.PerformLayout(this, "Parent");
1432 // XXX: Implement me!
1435 public virtual bool AutoSize {
1437 Console.Error.WriteLine("Unimplemented: Control::get_AutoSize()");
1441 Console.Error.WriteLine("Unimplemented: Control::set_AutoSize(bool)");
1448 [MWFCategory("Appearance")]
1449 public virtual Color BackColor {
1451 if (background_color.IsEmpty) {
1453 Color pcolor = parent.BackColor;
1454 if (pcolor.A == 0xff || GetStyle(ControlStyles.SupportsTransparentBackColor))
1457 return DefaultBackColor;
1459 return background_color;
1463 if (!value.IsEmpty && (value.A != 0xff) && !GetStyle(ControlStyles.SupportsTransparentBackColor)) {
1464 throw new ArgumentException("Transparent background colors are not supported on this control");
1467 background_color=value;
1468 SetChildColor(this);
1469 OnBackColorChanged(EventArgs.Empty);
1475 [DefaultValue(null)]
1476 [MWFCategory("Appearance")]
1477 public virtual Image BackgroundImage {
1479 return background_image;
1483 if (background_image!=value) {
1484 background_image=value;
1485 OnBackgroundImageChanged(EventArgs.Empty);
1490 [EditorBrowsable(EditorBrowsableState.Advanced)]
1492 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1493 public virtual BindingContext BindingContext {
1495 if (binding_context != null)
1496 return binding_context;
1499 binding_context = Parent.BindingContext;
1500 return binding_context;
1503 if (binding_context != value) {
1504 binding_context = value;
1505 OnBindingContextChanged(EventArgs.Empty);
1510 [EditorBrowsable(EditorBrowsableState.Advanced)]
1512 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1515 return bounds.Y+bounds.Height;
1519 [EditorBrowsable(EditorBrowsableState.Advanced)]
1521 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1522 public Rectangle Bounds {
1528 SetBoundsCore(value.Left, value.Top, value.Width, value.Height, BoundsSpecified.All);
1532 [EditorBrowsable(EditorBrowsableState.Advanced)]
1534 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1535 public bool CanFocus {
1537 if (IsHandleCreated && Visible && Enabled) {
1544 [EditorBrowsable(EditorBrowsableState.Advanced)]
1546 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1547 public bool CanSelect {
1551 if (!GetStyle(ControlStyles.Selectable)) {
1556 while (parent != null) {
1557 if (!parent.is_visible || !parent.is_enabled) {
1561 parent = parent.parent;
1567 internal virtual bool InternalCapture {
1577 [EditorBrowsable(EditorBrowsableState.Advanced)]
1579 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1580 public bool Capture {
1582 return this.is_captured;
1586 if (this.IsHandleCreated) {
1587 if (value && !is_captured) {
1589 XplatUI.GrabWindow(this.window.Handle, IntPtr.Zero);
1590 } else if (!value && is_captured) {
1591 XplatUI.UngrabWindow(this.window.Handle);
1592 is_captured = false;
1598 [DefaultValue(true)]
1599 [MWFCategory("Focus")]
1600 public bool CausesValidation {
1602 return this.causes_validation;
1606 if (this.causes_validation != value) {
1607 causes_validation = value;
1608 OnCausesValidationChanged(EventArgs.Empty);
1613 [EditorBrowsable(EditorBrowsableState.Advanced)]
1615 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1616 public Rectangle ClientRectangle {
1618 client_rect.Width = client_size.Width;
1619 client_rect.Height = client_size.Height;
1624 [EditorBrowsable(EditorBrowsableState.Advanced)]
1626 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1627 public Size ClientSize {
1630 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1631 return ((Form)this).form_parent_window.ClientSize;
1639 this.SetClientSizeCore(value.Width, value.Height);
1643 [EditorBrowsable(EditorBrowsableState.Advanced)]
1645 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1646 [DescriptionAttribute("ControlCompanyNameDescr")]
1647 public String CompanyName {
1649 return "Mono Project, Novell, Inc.";
1653 [EditorBrowsable(EditorBrowsableState.Advanced)]
1655 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1656 public bool ContainsFocus {
1662 for (int i=0; i < child_controls.Count; i++) {
1663 if (child_controls[i].ContainsFocus) {
1671 [DefaultValue(null)]
1672 [MWFCategory("Behavior")]
1673 public virtual ContextMenu ContextMenu {
1675 return context_menu;
1679 if (context_menu != value) {
1680 context_menu = value;
1681 OnContextMenuChanged(EventArgs.Empty);
1687 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
1688 public ControlCollection Controls {
1690 return this.child_controls;
1694 [EditorBrowsable(EditorBrowsableState.Advanced)]
1696 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1697 public bool Created {
1699 return (!is_disposed && is_created);
1703 [AmbientValue(null)]
1704 [MWFCategory("Appearance")]
1705 public virtual Cursor Cursor {
1707 if (cursor != null) {
1711 if (parent != null) {
1712 return parent.Cursor;
1715 return Cursors.Default;
1719 if (cursor != value) {
1724 if (IsHandleCreated) {
1725 pt = Cursor.Position;
1727 if (bounds.Contains(pt)) {
1728 if (GetChildAtPoint(pt) == null) {
1729 if (cursor != null) {
1730 XplatUI.SetCursor(window.Handle, cursor.handle);
1732 if (parent != null) {
1733 XplatUI.SetCursor(window.Handle, parent.Cursor.handle);
1735 XplatUI.SetCursor(window.Handle, Cursors.def.handle);
1742 OnCursorChanged(EventArgs.Empty);
1748 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
1749 [ParenthesizePropertyName(true)]
1750 [RefreshProperties(RefreshProperties.All)]
1751 [MWFCategory("Data")]
1752 public ControlBindingsCollection DataBindings {
1754 if (data_bindings == null)
1755 data_bindings = new ControlBindingsCollection (this);
1756 return data_bindings;
1760 [EditorBrowsable(EditorBrowsableState.Advanced)]
1762 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1763 public virtual Rectangle DisplayRectangle {
1765 return ClientRectangle;
1769 [EditorBrowsable(EditorBrowsableState.Advanced)]
1771 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1772 public bool Disposing {
1779 [RefreshProperties(RefreshProperties.Repaint)]
1780 [DefaultValue(DockStyle.None)]
1781 [MWFCategory("Layout")]
1782 public virtual DockStyle Dock {
1788 if (dock_style == value) {
1794 if (parent != null) {
1795 parent.PerformLayout(this, "Parent");
1798 OnDockChanged(EventArgs.Empty);
1804 [MWFCategory("Behavior")]
1805 public bool Enabled {
1811 if (parent != null) {
1812 return parent.Enabled;
1819 if (is_enabled == value) {
1823 if (IsHandleCreated) {
1825 if (((Form)this).context == null) {
1826 XplatUI.EnableWindow(window.Handle, value);
1829 XplatUI.EnableWindow(window.Handle, value);
1834 OnEnabledChanged (EventArgs.Empty);
1838 [EditorBrowsable(EditorBrowsableState.Advanced)]
1840 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1841 public virtual bool Focused {
1843 return this.has_focus;
1848 [AmbientValue(null)]
1850 [MWFCategory("Appearance")]
1851 public virtual Font Font {
1857 if (Parent != null && Parent.Font != null) {
1864 [param:MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Font))]
1866 if (font != null && font.Equals (value)) {
1872 OnFontChanged (EventArgs.Empty);
1877 [MWFCategory("Appearance")]
1878 public virtual Color ForeColor {
1880 if (foreground_color.IsEmpty) {
1882 return parent.ForeColor;
1884 return DefaultForeColor;
1886 return foreground_color;
1890 if (foreground_color != value) {
1891 foreground_color=value;
1893 OnForeColorChanged(EventArgs.Empty);
1900 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1901 public IntPtr Handle { // IWin32Window
1904 if (verify_thread_handle) {
1905 if (this.InvokeRequired) {
1906 throw new InvalidOperationException("Cross-thread access of handle detected. Handle access only valid on thread that created the control");
1910 if (!IsHandleCreated) {
1913 return window.Handle;
1917 [EditorBrowsable(EditorBrowsableState.Advanced)]
1919 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1920 public bool HasChildren {
1922 if (this.child_controls.Count>0) {
1929 [EditorBrowsable(EditorBrowsableState.Always)]
1931 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1934 return this.bounds.Height;
1938 SetBoundsCore(bounds.X, bounds.Y, bounds.Width, value, BoundsSpecified.Height);
1942 [AmbientValue(ImeMode.Inherit)]
1944 [MWFCategory("Behavior")]
1945 public ImeMode ImeMode {
1947 if (ime_mode == DefaultImeMode) {
1949 return parent.ImeMode;
1951 return ImeMode.NoControl; // default value
1957 if (ime_mode != value) {
1960 OnImeModeChanged(EventArgs.Empty);
1965 [EditorBrowsable(EditorBrowsableState.Advanced)]
1967 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1968 public bool InvokeRequired { // ISynchronizeInvoke
1970 if (creator_thread != null && creator_thread!=Thread.CurrentThread) {
1977 [EditorBrowsable(EditorBrowsableState.Advanced)]
1979 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1980 public bool IsAccessible {
1982 return is_accessible;
1986 is_accessible = value;
1990 [EditorBrowsable(EditorBrowsableState.Advanced)]
1992 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1993 public bool IsDisposed {
1995 return this.is_disposed;
1999 [EditorBrowsable(EditorBrowsableState.Advanced)]
2001 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2002 public bool IsHandleCreated {
2004 if ((window != null) && (window.Handle != IntPtr.Zero)) {
2012 [EditorBrowsable(EditorBrowsableState.Always)]
2014 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2017 return this.bounds.X;
2021 SetBoundsCore(value, bounds.Y, bounds.Width, bounds.Height, BoundsSpecified.X);
2026 [MWFCategory("Layout")]
2027 public Point Location {
2029 return new Point(bounds.X, bounds.Y);
2033 SetBoundsCore(value.X, value.Y, bounds.Width, bounds.Height, BoundsSpecified.Location);
2038 public string Name {
2050 public Padding Padding {
2062 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2063 public Control Parent {
2069 if (value == this) {
2070 throw new ArgumentException("A circular control reference has been made. A control cannot be owned or parented to itself.");
2073 if (parent!=value) {
2075 parent.Controls.Remove(this);
2079 value.Controls.Add(this);
2084 [EditorBrowsable(EditorBrowsableState.Advanced)]
2086 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2087 public string ProductName {
2089 Type t = typeof (AssemblyProductAttribute);
2090 Assembly assembly = GetType().Module.Assembly;
2091 object [] attrs = assembly.GetCustomAttributes (t, false);
2092 AssemblyProductAttribute a = null;
2093 // On MS we get a NullRefException if product attribute is not
2095 if (attrs != null && attrs.Length > 0)
2096 a = (AssemblyProductAttribute) attrs [0];
2101 [EditorBrowsable(EditorBrowsableState.Advanced)]
2103 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2104 public string ProductVersion {
2106 Type t = typeof (AssemblyVersionAttribute);
2107 Assembly assembly = GetType().Module.Assembly;
2108 object [] attrs = assembly.GetCustomAttributes (t, false);
2109 if (attrs == null || attrs.Length < 1)
2111 return ((AssemblyVersionAttribute)attrs [0]).Version;
2115 [EditorBrowsable(EditorBrowsableState.Advanced)]
2117 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2118 public bool RecreatingHandle {
2120 return is_recreating;
2124 [EditorBrowsable(EditorBrowsableState.Advanced)]
2126 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2127 public Region Region {
2129 return new Region(this.bounds);
2136 g = this.CreateGraphics();
2137 r = value.GetBounds(g);
2139 SetBounds((int)r.X, (int)r.Y, (int)r.Width, (int)r.Height);
2145 [EditorBrowsable(EditorBrowsableState.Advanced)]
2147 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2150 return this.bounds.X+this.bounds.Width;
2154 [AmbientValue(RightToLeft.Inherit)]
2156 [MWFCategory("Appearance")]
2157 public virtual RightToLeft RightToLeft {
2159 if (right_to_left == RightToLeft.Inherit) {
2161 return parent.RightToLeft;
2163 return RightToLeft.No; // default value
2165 return right_to_left;
2169 if (value != right_to_left) {
2170 right_to_left = value;
2171 OnRightToLeftChanged(EventArgs.Empty);
2176 [EditorBrowsable(EditorBrowsableState.Advanced)]
2177 public override ISite Site {
2185 AmbientProperties ap = (AmbientProperties) value.GetService (typeof (AmbientProperties));
2187 BackColor = ap.BackColor;
2188 ForeColor = ap.ForeColor;
2196 [MWFCategory("Layout")]
2199 return new Size(Width, Height);
2203 SetBoundsCore(bounds.X, bounds.Y, value.Width, value.Height, BoundsSpecified.Size);
2208 [MergableProperty(false)]
2209 [MWFCategory("Behavior")]
2210 public int TabIndex {
2212 if (tab_index != -1) {
2219 if (tab_index != value) {
2221 OnTabIndexChanged(EventArgs.Empty);
2227 [DefaultValue(true)]
2228 [MWFCategory("Behavior")]
2229 public bool TabStop {
2235 if (tab_stop != value) {
2237 OnTabStopChanged(EventArgs.Empty);
2242 [Localizable(false)]
2244 [TypeConverter(typeof(StringConverter))]
2245 [DefaultValue(null)]
2246 [MWFCategory("Data")]
2253 control_tag = value;
2259 [BindableAttribute(true)]
2260 [MWFCategory("Appearance")]
2261 public virtual string Text {
2263 // Our implementation ignores ControlStyles.CacheText - we always cache
2268 if (value == null) {
2269 value = String.Empty;
2274 if (IsHandleCreated) {
2275 XplatUI.Text(Handle, text);
2277 OnTextChanged (EventArgs.Empty);
2282 [EditorBrowsable(EditorBrowsableState.Always)]
2284 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2287 return this.bounds.Y;
2291 SetBoundsCore(bounds.X, value, bounds.Width, bounds.Height, BoundsSpecified.Y);
2295 [EditorBrowsable(EditorBrowsableState.Advanced)]
2297 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2298 public Control TopLevelControl {
2302 while (p.parent != null) {
2311 [MWFCategory("Behavior")]
2312 public bool Visible {
2316 } else if (parent != null) {
2317 return parent.Visible;
2324 SetVisibleCore(value);
2328 [EditorBrowsable(EditorBrowsableState.Always)]
2330 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2333 return this.bounds.Width;
2337 SetBoundsCore(bounds.X, bounds.Y, value, bounds.Height, BoundsSpecified.Width);
2341 [EditorBrowsable(EditorBrowsableState.Never)]
2343 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2344 public IWindowTarget WindowTarget {
2353 #endregion // Public Instance Properties
2355 #region Protected Instance Properties
2356 protected virtual CreateParams CreateParams {
2358 CreateParams create_params = new CreateParams();
2361 create_params.Caption = Text;
2364 create_params.Caption = text;
2368 create_params.X = Left;
2371 create_params.X = this.bounds.X;
2375 create_params.Y = Top;
2378 create_params.Y = this.bounds.Y;
2382 create_params.Width = Width;
2385 create_params.Width = this.bounds.Width;
2389 create_params.Height = Height;
2392 create_params.Height = this.bounds.Height;
2396 create_params.ClassName = XplatUI.DefaultClassName;
2397 create_params.ClassStyle = 0;
2398 create_params.ExStyle = 0;
2399 create_params.Param = 0;
2402 create_params.ExStyle |= (int)WindowExStyles.WS_EX_ACCEPTFILES;
2405 if ((parent!=null) && (parent.IsHandleCreated)) {
2406 create_params.Parent = parent.Handle;
2409 create_params.Style = (int)WindowStyles.WS_CHILD | (int)WindowStyles.WS_CLIPCHILDREN | (int)WindowStyles.WS_CLIPSIBLINGS;
2412 create_params.Style |= (int)WindowStyles.WS_VISIBLE;
2416 create_params.Style |= (int)WindowStyles.WS_DISABLED;
2419 switch (border_style) {
2420 case BorderStyle.FixedSingle:
2421 create_params.Style |= (int) WindowStyles.WS_BORDER;
2423 case BorderStyle.Fixed3D:
2424 create_params.ExStyle |= (int) WindowExStyles.WS_EX_CLIENTEDGE;
2428 return create_params;
2432 protected virtual ImeMode DefaultImeMode {
2434 return ImeMode.Inherit;
2438 protected virtual Size DefaultSize {
2440 return new Size(0, 0);
2444 protected int FontHeight {
2454 protected bool RenderRightToLeft {
2456 return (this.right_to_left == RightToLeft.Yes);
2460 protected bool ResizeRedraw {
2462 return GetStyle(ControlStyles.ResizeRedraw);
2466 SetStyle(ControlStyles.ResizeRedraw, value);
2470 [EditorBrowsable(EditorBrowsableState.Advanced)]
2472 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2473 protected virtual bool ShowFocusCues {
2479 [EditorBrowsable(EditorBrowsableState.Advanced)]
2481 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2482 protected bool ShowKeyboardCues {
2487 #endregion // Protected Instance Properties
2489 #region Public Static Methods
2490 [EditorBrowsable(EditorBrowsableState.Advanced)]
2491 public static Control FromChildHandle(IntPtr handle) {
2492 IEnumerator control = Control.controls.GetEnumerator();
2494 while (control.MoveNext()) {
2495 if (((Control)control.Current).window.Handle == handle) {
2497 if (((Control)control.Current).Parent != null) {
2498 return ((Control)control.Current).Parent;
2505 [EditorBrowsable(EditorBrowsableState.Advanced)]
2506 public static Control FromHandle(IntPtr handle) {
2508 IEnumerator control = Control.controls.GetEnumerator();
2510 while (control.MoveNext()) {
2511 if (((Control)control.Current).window.Handle == handle) {
2513 return ((Control)control.Current);
2519 return Control.ControlNativeWindow.ControlFromHandle(handle);
2523 public static bool IsMnemonic(char charCode, string text) {
2526 amp = text.IndexOf('&');
2529 if (amp + 1 < text.Length) {
2530 if (text[amp + 1] != '&') {
2531 if (Char.ToUpper(charCode) == Char.ToUpper(text.ToCharArray(amp + 1, 1)[0])) {
2541 #region Protected Static Methods
2542 [EditorBrowsable(EditorBrowsableState.Advanced)]
2543 protected static bool ReflectMessage(IntPtr hWnd, ref Message m) {
2546 c = Control.FromHandle(hWnd);
2556 #region Public Instance Methods
2557 [EditorBrowsable(EditorBrowsableState.Advanced)]
2558 public IAsyncResult BeginInvoke(Delegate method) {
2559 object [] prms = null;
2560 if (method is EventHandler)
2561 prms = new object [] { this, EventArgs.Empty };
2562 return BeginInvokeInternal(method, prms, false);
2565 [EditorBrowsable(EditorBrowsableState.Advanced)]
2566 public IAsyncResult BeginInvoke (Delegate method, object[] args) {
2567 return BeginInvokeInternal (method, args, false);
2570 public void BringToFront() {
2571 if ((parent != null) && (parent.child_controls[0]!=this)) {
2572 if (parent.child_controls.Contains(this)) {
2573 parent.child_controls.SetChildIndex(this, 0);
2575 } else if (parent != null) {
2576 if (parent.child_controls.impl_list != null) {
2577 Control last_impl = (Control) parent.child_controls.impl_list [parent.child_controls.impl_list.Count - 1];
2578 if (IsHandleCreated) {
2579 XplatUI.SetZOrder (this.window.Handle, last_impl.Handle, false, false);
2582 if (IsHandleCreated) {
2583 XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, true, false);
2588 if (parent != null) {
2593 public bool Contains(Control ctl) {
2594 while (ctl != null) {
2603 public void CreateControl() {
2608 if (!IsHandleCreated) {
2616 Control [] controls = child_controls.GetAllControls ();
2617 for (int i=0; i<controls.Length; i++) {
2618 controls [i].CreateControl ();
2623 if (binding_context == null) { // seem to be sent whenever it's null?
2624 OnBindingContextChanged(EventArgs.Empty);
2630 public Graphics CreateGraphics() {
2631 if (!IsHandleCreated) {
2632 this.CreateHandle();
2634 return Graphics.FromHwnd(this.window.Handle);
2637 public DragDropEffects DoDragDrop(object data, DragDropEffects allowedEffects) {
2638 return XplatUI.StartDrag(this.window.Handle, data, allowedEffects);
2641 [EditorBrowsable(EditorBrowsableState.Advanced)]
2642 public object EndInvoke (IAsyncResult async_result) {
2643 AsyncMethodResult result = (AsyncMethodResult) async_result;
2644 return result.EndInvoke ();
2647 public Form FindForm() {
2660 public bool Focus() {
2661 if (CanFocus && IsHandleCreated && !has_focus) {
2662 XplatUI.SetFocus(window.Handle);
2667 public Control GetChildAtPoint(Point pt) {
2668 // Microsoft's version of this function doesn't seem to work, so I can't check
2669 // if we only consider children or also grandchildren, etc.
2670 // I'm gonna say 'children only'
2671 for (int i=0; i<child_controls.Count; i++) {
2672 if (child_controls[i].Bounds.Contains(pt)) {
2673 return child_controls[i];
2679 public IContainerControl GetContainerControl() {
2680 Control current = this;
2682 while (current!=null) {
2683 if ((current is IContainerControl) && ((current.control_style & ControlStyles.ContainerControl)!=0)) {
2684 return (IContainerControl)current;
2686 current = current.parent;
2691 public Control GetNextControl(Control ctl, bool forward) {
2692 // If we're not a container we don't play
2693 if (!(this is IContainerControl) && !this.GetStyle(ControlStyles.ContainerControl)) {
2697 // If ctl is not contained by this, we start at the first child of this
2698 if (!this.Contains(ctl)) {
2702 // Search through our controls, starting at ctl, stepping into children as we encounter them
2703 // try to find the control with the tabindex closest to our own, or, if we're looking into
2704 // child controls, the one with the smallest tabindex
2706 return FindControlForward(this, ctl);
2708 return FindControlBackward(this, ctl);
2711 public void Hide() {
2712 this.Visible = false;
2715 public void Invalidate() {
2716 Invalidate(ClientRectangle, false);
2719 public void Invalidate(bool invalidateChildren) {
2720 Invalidate(ClientRectangle, invalidateChildren);
2723 public void Invalidate(System.Drawing.Rectangle rc) {
2724 Invalidate(rc, false);
2727 public void Invalidate(System.Drawing.Rectangle rc, bool invalidateChildren) {
2728 if (!IsHandleCreated || !Visible || rc.Width == 0 || rc.Height == 0) {
2732 NotifyInvalidate(rc);
2734 XplatUI.Invalidate(Handle, rc, false);
2736 if (invalidateChildren) {
2737 Control [] controls = child_controls.GetAllControls ();
2738 for (int i=0; i<controls.Length; i++)
2739 controls [i].Invalidate ();
2741 OnInvalidated(new InvalidateEventArgs(rc));
2744 public void Invalidate(System.Drawing.Region region) {
2745 Invalidate(region, false);
2748 public void Invalidate(System.Drawing.Region region, bool invalidateChildren) {
2749 RectangleF bounds = region.GetBounds (CreateGraphics ());
2750 Invalidate (new Rectangle ((int) bounds.X, (int) bounds.Y, (int) bounds.Width, (int) bounds.Height),
2751 invalidateChildren);
2754 public object Invoke (Delegate method) {
2755 object [] prms = null;
2756 if (method is EventHandler)
2757 prms = new object [] { this, EventArgs.Empty };
2759 return Invoke(method, prms);
2762 public object Invoke (Delegate method, object[] args) {
2763 if (!this.InvokeRequired) {
2764 return method.DynamicInvoke(args);
2767 IAsyncResult result = BeginInvoke (method, args);
2768 return EndInvoke(result);
2771 internal object InvokeInternal (Delegate method, bool disposing) {
2772 return InvokeInternal(method, null, disposing);
2775 internal object InvokeInternal (Delegate method, object[] args, bool disposing) {
2776 if (!this.InvokeRequired) {
2777 return method.DynamicInvoke(args);
2780 IAsyncResult result = BeginInvokeInternal (method, args, disposing);
2781 return EndInvoke(result);
2784 [EditorBrowsable(EditorBrowsableState.Advanced)]
2785 public void PerformLayout() {
2786 PerformLayout(null, null);
2789 [EditorBrowsable(EditorBrowsableState.Advanced)]
2790 public void PerformLayout(Control affectedControl, string affectedProperty) {
2791 LayoutEventArgs levent = new LayoutEventArgs(affectedControl, affectedProperty);
2793 if (layout_suspended > 0) {
2794 layout_pending = true;
2798 layout_pending = false;
2800 // Prevent us from getting messed up
2803 // Perform all Dock and Anchor calculations
2806 AnchorStyles anchor;
2809 space= DisplayRectangle;
2811 // Deal with docking; go through in reverse, MS docs say that lowest Z-order is closest to edge
2812 Control [] controls = child_controls.GetAllControls ();
2813 for (int i = controls.Length - 1; i >= 0; i--) {
2814 child = controls [i];
2816 if (!child.Visible) {
2820 switch (child.Dock) {
2821 case DockStyle.None: {
2826 case DockStyle.Left: {
2827 child.SetBounds(space.Left, space.Y, child.Width, space.Height);
2828 space.X+=child.Width;
2829 space.Width-=child.Width;
2833 case DockStyle.Top: {
2834 child.SetBounds(space.Left, space.Y, space.Width, child.Height);
2835 space.Y+=child.Height;
2836 space.Height-=child.Height;
2840 case DockStyle.Right: {
2841 child.SetBounds(space.Right-child.Width, space.Y, child.Width, space.Height);
2842 space.Width-=child.Width;
2846 case DockStyle.Bottom: {
2847 child.SetBounds(space.Left, space.Bottom-child.Height, space.Width, child.Height);
2848 space.Height-=child.Height;
2854 for (int i = controls.Length - 1; i >= 0; i--) {
2857 if (child.Visible && (child.Dock == DockStyle.Fill)) {
2858 child.SetBounds(space.Left, space.Top, space.Width, space.Height);
2864 space=DisplayRectangle;
2866 for (int i=0; i < controls.Length; i++) {
2872 child = controls[i];
2874 // If the control is docked we don't need to do anything
2875 if (child.Dock != DockStyle.None) {
2879 anchor = child.Anchor;
2883 width = child.Width;
2884 height = child.Height;
2886 if ((anchor & AnchorStyles.Left) !=0 ) {
2887 if ((anchor & AnchorStyles.Right) != 0) {
2888 width = space.Width - child.dist_right - left;
2890 ; // Left anchored only, nothing to be done
2892 } else if ((anchor & AnchorStyles.Right) != 0) {
2893 left = space.Width - child.dist_right - width;
2895 // left+=diff_width/2 will introduce rounding errors (diff_width removed from svn after r51780)
2896 // This calculates from scratch every time:
2897 left = child.dist_left + (space.Width - (child.dist_left + width + child.dist_right)) / 2;
2900 if ((anchor & AnchorStyles.Top) !=0 ) {
2901 if ((anchor & AnchorStyles.Bottom) != 0) {
2902 height = space.Height - child.dist_bottom - top;
2904 ; // Top anchored only, nothing to be done
2906 } else if ((anchor & AnchorStyles.Bottom) != 0) {
2907 top = space.Height - child.dist_bottom - height;
2909 // top += diff_height/2 will introduce rounding errors (diff_height removed from after r51780)
2910 // This calculates from scratch every time:
2911 top = child.dist_top + (space.Height - (child.dist_top + height + child.dist_bottom)) / 2;
2923 child.SetBounds(left, top, width, height);
2926 // Let everyone know
2930 // Need to make sure we decremend layout_suspended
2936 public Point PointToClient (Point p) {
2940 XplatUI.ScreenToClient (Handle, ref x, ref y);
2942 return new Point (x, y);
2945 public Point PointToScreen(Point p) {
2949 XplatUI.ClientToScreen(Handle, ref x, ref y);
2951 return new Point(x, y);
2954 public virtual bool PreProcessMessage(ref Message msg) {
2957 if ((msg.Msg == (int)Msg.WM_KEYDOWN) || (msg.Msg == (int)Msg.WM_SYSKEYDOWN)) {
2958 key_data = (Keys)msg.WParam.ToInt32() | XplatUI.State.ModifierKeys;
2960 if (!ProcessCmdKey(ref msg, key_data)) {
2961 if (IsInputKey(key_data)) {
2965 return ProcessDialogKey(key_data);
2969 } else if (msg.Msg == (int)Msg.WM_CHAR) {
2970 if (IsInputChar((char)msg.WParam)) {
2973 } else if (msg.Msg == (int)Msg.WM_SYSCHAR) {
2974 if (IsInputChar((char)msg.WParam)) {
2977 return ProcessDialogChar((char)msg.WParam);
2982 public Rectangle RectangleToClient(Rectangle r) {
2983 return new Rectangle(PointToClient(r.Location), r.Size);
2986 public Rectangle RectangleToScreen(Rectangle r) {
2987 return new Rectangle(PointToScreen(r.Location), r.Size);
2990 public virtual void Refresh() {
2991 if (IsHandleCreated == true) {
2993 XplatUI.UpdateWindow(window.Handle);
2995 Control [] controls = child_controls.GetAllControls ();
2996 for (int i=0; i < controls.Length; i++) {
2997 controls[i].Refresh();
3003 [EditorBrowsable(EditorBrowsableState.Never)]
3004 public virtual void ResetBackColor() {
3005 background_color = Color.Empty;
3008 [EditorBrowsable(EditorBrowsableState.Never)]
3009 public void ResetBindings() {
3010 data_bindings.Clear();
3013 [EditorBrowsable(EditorBrowsableState.Never)]
3014 public virtual void ResetCursor() {
3018 [EditorBrowsable(EditorBrowsableState.Never)]
3019 public virtual void ResetFont() {
3023 [EditorBrowsable(EditorBrowsableState.Never)]
3024 public virtual void ResetForeColor() {
3025 foreground_color = Color.Empty;
3028 [EditorBrowsable(EditorBrowsableState.Never)]
3029 public void ResetImeMode() {
3030 ime_mode = DefaultImeMode;
3033 [EditorBrowsable(EditorBrowsableState.Never)]
3034 public virtual void ResetRightToLeft() {
3035 right_to_left = RightToLeft.Inherit;
3038 public virtual void ResetText() {
3039 text = String.Empty;
3042 public void ResumeLayout() {
3043 ResumeLayout (true);
3046 public void ResumeLayout(bool performLayout) {
3047 if (layout_suspended > 0) {
3051 if (layout_suspended == 0) {
3052 Control [] controls = child_controls.GetAllControls ();
3053 for (int i=0; i<controls.Length; i++) {
3054 controls [i].UpdateDistances ();
3057 if (performLayout && layout_pending) {
3063 public void Scale(float ratio) {
3064 ScaleCore(ratio, ratio);
3067 public void Scale(float dx, float dy) {
3071 public void Select() {
3072 Select(false, false);
3075 public bool SelectNextControl(Control ctl, bool forward, bool tabStopOnly, bool nested, bool wrap) {
3080 c = GetNextControl(c, forward);
3089 if (c.CanSelect && ((c.parent == ctl.parent) || nested) && (c.tab_stop || !tabStopOnly)) {
3093 } while (c != ctl); // If we wrap back to ourselves we stop
3098 public void SendToBack() {
3099 if ((parent != null) && (parent.child_controls[parent.child_controls.Count-1]!=this)) {
3100 if (parent.child_controls.Contains(this)) {
3101 parent.child_controls.SetChildIndex(this, parent.child_controls.Count);
3105 if (IsHandleCreated) {
3106 XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, false, true);
3109 if (parent != null) {
3114 public void SetBounds(int x, int y, int width, int height) {
3115 SetBoundsCore(x, y, width, height, BoundsSpecified.All);
3118 public void SetBounds(int x, int y, int width, int height, BoundsSpecified specified) {
3119 SetBoundsCore(x, y, width, height, specified);
3122 public void Show() {
3124 this.CreateControl();
3130 public void SuspendLayout() {
3134 public void Update() {
3135 needs_redraw = true;
3136 if (IsHandleCreated) {
3137 XplatUI.UpdateWindow(window.Handle);
3140 #endregion // Public Instance Methods
3142 #region Protected Instance Methods
3143 [EditorBrowsable(EditorBrowsableState.Advanced)]
3144 [MonoTODO("Implement this and tie it into Control.ControlAccessibleObject.NotifyClients")]
3145 protected void AccessibilityNotifyClients(AccessibleEvents accEvent, int childID) {
3146 throw new NotImplementedException();
3149 [EditorBrowsable(EditorBrowsableState.Advanced)]
3150 protected virtual AccessibleObject CreateAccessibilityInstance() {
3151 return new Control.ControlAccessibleObject(this);
3154 [EditorBrowsable(EditorBrowsableState.Advanced)]
3155 protected virtual ControlCollection CreateControlsInstance() {
3156 return new ControlCollection(this);
3159 [EditorBrowsable(EditorBrowsableState.Advanced)]
3160 protected virtual void CreateHandle() {
3162 throw new ObjectDisposedException(Name);
3165 if (IsHandleCreated && !is_recreating) {
3169 window.CreateHandle(CreateParams);
3171 if (window.Handle != IntPtr.Zero) {
3172 if (!controls.Contains(window.Handle)) {
3176 creator_thread = Thread.CurrentThread;
3178 XplatUI.EnableWindow(window.Handle, is_enabled);
3180 // Set our handle with our parent
3181 if ((parent != null) && (parent.IsHandleCreated)) {
3182 XplatUI.SetParent(window.Handle, parent.Handle);
3185 // Set our handle as parent for our children
3186 Control [] children;
3188 children = child_controls.GetAllControls ();
3189 for (int i = 0; i < children.Length; i++ ) {
3190 if (children[i].IsHandleCreated) {
3191 XplatUI.SetParent(children[i].Handle, window.Handle);
3196 XplatUI.SetAllowDrop (Handle, allow_drop);
3198 // Find out where the window manager placed us
3199 if ((CreateParams.Style & (int)WindowStyles.WS_CHILD) != 0) {
3200 XplatUI.SetBorderStyle(window.Handle, (FormBorderStyle)border_style);
3204 OnHandleCreated(EventArgs.Empty);
3209 [EditorBrowsable(EditorBrowsableState.Advanced)]
3210 protected virtual void DefWndProc(ref Message m) {
3211 window.DefWndProc(ref m);
3214 [EditorBrowsable(EditorBrowsableState.Advanced)]
3215 protected virtual void DestroyHandle() {
3216 if (IsHandleCreated) {
3217 if (window != null) {
3218 window.DestroyHandle();
3223 protected bool GetStyle(ControlStyles flag) {
3224 return (control_style & flag) != 0;
3227 protected bool GetTopLevel() {
3231 [EditorBrowsable(EditorBrowsableState.Advanced)]
3232 protected virtual void InitLayout() {
3236 [EditorBrowsable(EditorBrowsableState.Advanced)]
3237 protected void InvokeGotFocus(Control toInvoke, EventArgs e) {
3238 toInvoke.OnGotFocus(e);
3241 [EditorBrowsable(EditorBrowsableState.Advanced)]
3242 protected void InvokeLostFocus(Control toInvoke, EventArgs e) {
3243 toInvoke.OnLostFocus(e);
3246 [EditorBrowsable(EditorBrowsableState.Advanced)]
3247 protected void InvokeOnClick(Control toInvoke, EventArgs e) {
3248 toInvoke.OnClick(e);
3251 protected void InvokePaint(Control toInvoke, PaintEventArgs e) {
3252 toInvoke.OnPaint(e);
3255 protected void InvokePaintBackground(Control toInvoke, PaintEventArgs e) {
3256 toInvoke.OnPaintBackground(e);
3259 protected virtual bool IsInputChar (char charCode) {
3263 protected virtual bool IsInputKey (Keys keyData) {
3264 // Doc says this one calls IsInputChar; not sure what to do with that
3268 [EditorBrowsable(EditorBrowsableState.Advanced)]
3269 protected virtual void NotifyInvalidate(Rectangle invalidatedArea) {
3273 protected virtual bool ProcessCmdKey(ref Message msg, Keys keyData) {
3274 if ((context_menu != null) && context_menu.ProcessCmdKey(ref msg, keyData)) {
3278 if (parent != null) {
3279 return parent.ProcessCmdKey(ref msg, keyData);
3285 protected virtual bool ProcessDialogChar(char charCode) {
3286 if (parent != null) {
3287 return parent.ProcessDialogChar (charCode);
3293 protected virtual bool ProcessDialogKey (Keys keyData) {
3294 if (parent != null) {
3295 return parent.ProcessDialogKey (keyData);
3301 protected virtual bool ProcessKeyEventArgs (ref Message msg)
3303 KeyEventArgs key_event;
3306 case (int)Msg.WM_SYSKEYDOWN:
3307 case (int)Msg.WM_KEYDOWN: {
3308 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
3309 OnKeyDown (key_event);
3310 return key_event.Handled;
3313 case (int)Msg.WM_SYSKEYUP:
3314 case (int)Msg.WM_KEYUP: {
3315 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
3316 OnKeyUp (key_event);
3317 return key_event.Handled;
3320 case (int)Msg.WM_SYSCHAR:
3321 case (int)Msg.WM_CHAR: {
3322 KeyPressEventArgs key_press_event;
3324 key_press_event = new KeyPressEventArgs((char)msg.WParam);
3325 OnKeyPress(key_press_event);
3326 return key_press_event.Handled;
3337 protected internal virtual bool ProcessKeyMessage(ref Message msg) {
3338 if (parent != null) {
3339 if (parent.ProcessKeyPreview(ref msg)) {
3344 return ProcessKeyEventArgs(ref msg);
3347 protected virtual bool ProcessKeyPreview(ref Message msg) {
3348 if (parent != null) {
3349 return parent.ProcessKeyPreview(ref msg);
3355 protected virtual bool ProcessMnemonic(char charCode) {
3360 [EditorBrowsable(EditorBrowsableState.Advanced)]
3361 protected void RaiseDragEvent(object key, DragEventArgs e) {
3365 [EditorBrowsable(EditorBrowsableState.Advanced)]
3366 protected void RaiseKeyEvent(object key, KeyEventArgs e) {
3370 [EditorBrowsable(EditorBrowsableState.Advanced)]
3371 protected void RaiseMouseEvent(object key, MouseEventArgs e) {
3375 [EditorBrowsable(EditorBrowsableState.Advanced)]
3376 protected void RaisePaintEvent(object key, PaintEventArgs e) {
3380 [EditorBrowsable(EditorBrowsableState.Advanced)]
3381 protected void RecreateHandle() {
3384 if (IsHandleCreated) {
3386 // WM_DESTROY will CreateHandle for us
3395 is_recreating = false;
3398 [EditorBrowsable(EditorBrowsableState.Advanced)]
3399 protected void ResetMouseEventArgs() {
3403 [EditorBrowsable(EditorBrowsableState.Advanced)]
3404 protected ContentAlignment RtlTranslateAlignment(ContentAlignment align) {
3405 if (right_to_left == RightToLeft.No) {
3410 case ContentAlignment.TopLeft: {
3411 return ContentAlignment.TopRight;
3414 case ContentAlignment.TopRight: {
3415 return ContentAlignment.TopLeft;
3418 case ContentAlignment.MiddleLeft: {
3419 return ContentAlignment.MiddleRight;
3422 case ContentAlignment.MiddleRight: {
3423 return ContentAlignment.MiddleLeft;
3426 case ContentAlignment.BottomLeft: {
3427 return ContentAlignment.BottomRight;
3430 case ContentAlignment.BottomRight: {
3431 return ContentAlignment.BottomLeft;
3435 // if it's center it doesn't change
3441 [EditorBrowsable(EditorBrowsableState.Advanced)]
3442 protected HorizontalAlignment RtlTranslateAlignment(HorizontalAlignment align) {
3443 if ((right_to_left == RightToLeft.No) || (align == HorizontalAlignment.Center)) {
3447 if (align == HorizontalAlignment.Left) {
3448 return HorizontalAlignment.Right;
3451 // align must be HorizontalAlignment.Right
3452 return HorizontalAlignment.Left;
3455 [EditorBrowsable(EditorBrowsableState.Advanced)]
3456 protected LeftRightAlignment RtlTranslateAlignment(LeftRightAlignment align) {
3457 if (right_to_left == RightToLeft.No) {
3461 if (align == LeftRightAlignment.Left) {
3462 return LeftRightAlignment.Right;
3465 // align must be LeftRightAlignment.Right;
3466 return LeftRightAlignment.Left;
3469 [EditorBrowsable(EditorBrowsableState.Advanced)]
3470 protected ContentAlignment RtlTranslateContent(ContentAlignment align) {
3471 return RtlTranslateAlignment(align);
3474 [EditorBrowsable(EditorBrowsableState.Advanced)]
3475 protected HorizontalAlignment RtlTranslateHorizontal(HorizontalAlignment align) {
3476 return RtlTranslateAlignment(align);
3479 [EditorBrowsable(EditorBrowsableState.Advanced)]
3480 protected LeftRightAlignment RtlTranslateLeftRight(LeftRightAlignment align) {
3481 return RtlTranslateAlignment(align);
3484 [EditorBrowsable(EditorBrowsableState.Advanced)]
3485 protected virtual void ScaleCore(float dx, float dy) {
3491 location = new Point((int)(Left * dx), (int)(Top * dy));
3492 size = this.ClientSize;
3494 if (!GetStyle(ControlStyles.FixedWidth)) {
3495 size.Width = (int)(size.Width * dx);
3498 if (!GetStyle(ControlStyles.FixedHeight)) {
3499 size.Height = (int)(size.Height * dy);
3502 SetBoundsCore(location.X, location.Y, size.Width, size.Height, BoundsSpecified.All);
3504 /* Now scale our children */
3505 Control [] controls = child_controls.GetAllControls ();
3506 for (int i=0; i < controls.Length; i++) {
3507 controls[i].Scale(dx, dy);
3513 protected virtual void Select(bool directed, bool forward) {
3518 // Select this control
3523 if (parent == null) {
3527 // FIXME - this thing is doing the wrong stuff, needs to be similar to SelectNextControl
3529 index = parent.child_controls.IndexOf(this);
3534 if ((index+1) < parent.child_controls.Count) {
3543 index = parent.child_controls.Count-1;
3546 result = Select(parent.child_controls[index]);
3547 } while (!result && parent.child_controls[index] != this);
3550 [EditorBrowsable(EditorBrowsableState.Advanced)]
3551 protected virtual void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
3552 // SetBoundsCore updates the Win32 control itself. UpdateBounds updates the controls variables and fires events, I'm guessing - pdb
3553 if ((specified & BoundsSpecified.X) != BoundsSpecified.X) {
3557 if ((specified & BoundsSpecified.Y) != BoundsSpecified.Y) {
3561 if ((specified & BoundsSpecified.Width) != BoundsSpecified.Width) {
3565 if ((specified & BoundsSpecified.Height) != BoundsSpecified.Height) {
3569 if (IsHandleCreated) {
3570 XplatUI.SetWindowPos(Handle, x, y, width, height);
3573 UpdateBounds(x, y, width, height);
3578 [EditorBrowsable(EditorBrowsableState.Advanced)]
3579 protected virtual void SetClientSizeCore(int x, int y) {
3580 // Calculate the actual window size from the client size (it usually stays the same or grows)
3581 Rectangle ClientRect;
3582 Rectangle WindowRect;
3585 ClientRect = new Rectangle(0, 0, x, y);
3586 cp = this.CreateParams;
3588 if (XplatUI.CalculateWindowRect(ref ClientRect, cp.Style, cp.ExStyle, null, out WindowRect)==false) {
3592 SetBoundsCore(bounds.X, bounds.Y, WindowRect.Width, WindowRect.Height, BoundsSpecified.Size);
3595 [EditorBrowsable(EditorBrowsableState.Advanced)]
3596 protected void SetStyle(ControlStyles flag, bool value) {
3598 control_style |= flag;
3600 control_style &= ~flag;
3604 protected void SetTopLevel(bool value) {
3605 if ((GetTopLevel() != value) && (parent != null)) {
3606 throw new Exception();
3610 if (value == true) {
3620 is_toplevel = value;
3623 protected virtual void SetVisibleCore(bool value) {
3624 if (value!=is_visible) {
3625 if (value && !is_created) {
3631 if (IsHandleCreated) {
3632 XplatUI.SetVisible(Handle, value);
3633 // Explicitly move Toplevel windows to where we want them;
3634 // apparently moving unmapped toplevel windows doesn't work
3635 if (is_visible && (this is Form)) {
3636 XplatUI.SetWindowPos(window.Handle, bounds.X, bounds.Y, bounds.Width, bounds.Height);
3640 OnVisibleChanged(EventArgs.Empty);
3642 if (value == false && parent != null) {
3645 // Need to start at parent, GetContainerControl might return ourselves if we're a container
3646 container = (Control)parent.GetContainerControl();
3647 if (container != null) {
3648 container.SelectNextControl(this, true, true, true, true);
3652 if (parent != null) {
3653 parent.PerformLayout(this, "visible");
3655 PerformLayout(this, "visible");
3660 [EditorBrowsable(EditorBrowsableState.Advanced)]
3661 protected void UpdateBounds() {
3669 if (!IsHandleCreated) {
3673 XplatUI.GetWindowPos(this.Handle, this is Form, out x, out y, out width, out height, out client_width, out client_height);
3675 UpdateBounds(x, y, width, height, client_width, client_height);
3678 [EditorBrowsable(EditorBrowsableState.Advanced)]
3679 protected void UpdateBounds(int x, int y, int width, int height) {
3683 // Calculate client rectangle
3684 rect = new Rectangle(0, 0, 0, 0);
3687 XplatUI.CalculateWindowRect(ref rect, cp.Style, cp.ExStyle, cp.menu, out rect);
3688 UpdateBounds(x, y, width, height, width - (rect.Right - rect.Left), height - (rect.Bottom - rect.Top));
3691 [EditorBrowsable(EditorBrowsableState.Advanced)]
3692 protected void UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) {
3693 // UpdateBounds only seems to set our sizes and fire events but not update the GUI window to match
3695 bool resized = false;
3697 // Needed to generate required notifications
3698 if ((this.bounds.X!=x) || (this.bounds.Y!=y)) {
3702 if ((this.Bounds.Width!=width) || (this.Bounds.Height!=height)) {
3709 bounds.Height=height;
3711 client_size.Width=clientWidth;
3712 client_size.Height=clientHeight;
3715 OnLocationChanged(EventArgs.Empty);
3719 OnSizeChanged(EventArgs.Empty);
3723 [EditorBrowsable(EditorBrowsableState.Advanced)]
3724 protected void UpdateStyles() {
3725 if (!IsHandleCreated) {
3729 XplatUI.SetWindowStyle(window.Handle, CreateParams);
3730 OnStyleChanged(EventArgs.Empty);
3733 [EditorBrowsable(EditorBrowsableState.Advanced)]
3734 protected void UpdateZOrder() {
3735 Control [] controls;
3736 if (!IsHandleCreated) {
3740 controls = child_controls.GetAllControls ();
3741 for (int i = 1; i < controls.Length; i++ ) {
3742 XplatUI.SetZOrder(controls[i].Handle, controls[i-1].Handle, false, false);
3746 protected virtual void WndProc(ref Message m) {
3748 Console.WriteLine("Control {0} received message {1}", window.Handle == IntPtr.Zero ? this.Text : XplatUI.Window(window.Handle), (Msg)m.Msg);
3750 if ((this.control_style & ControlStyles.EnableNotifyMessage) != 0) {
3754 switch((Msg)m.Msg) {
3755 case Msg.WM_DESTROY: {
3756 OnHandleDestroyed(EventArgs.Empty);
3757 window.InvalidateHandle();
3759 if (ParentIsRecreating) {
3761 } else if (is_recreating) {
3767 case Msg.WM_WINDOWPOSCHANGED: {
3770 if (GetStyle(ControlStyles.ResizeRedraw)) {
3777 // Nice description of what should happen when handling WM_PAINT
3778 // can be found here: http://pluralsight.com/wiki/default.aspx/Craig/FlickerFreeControlDrawing.html
3779 // and here http://msdn.microsoft.com/msdnmag/issues/06/03/WindowsFormsPerformance/
3780 case Msg.WM_PAINT: {
3781 PaintEventArgs paint_event;
3783 paint_event = XplatUI.PaintEventStart(Handle, true);
3785 if (!needs_redraw) {
3786 // Just blit the previous image
3787 paint_event.Graphics.DrawImage (ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle, GraphicsUnit.Pixel);
3788 XplatUI.PaintEventEnd(Handle, true);
3793 if (ThemeEngine.Current.DoubleBufferingSupported)
3794 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
3795 dc = paint_event.SetGraphics (DeviceContext);
3798 if (!GetStyle(ControlStyles.Opaque)) {
3799 OnPaintBackground(paint_event);
3802 // Button-derived controls choose to ignore their Opaque style, give them a chance to draw their background anyways
3803 OnPaintBackgroundInternal(paint_event);
3805 OnPaintInternal(paint_event);
3806 if (!paint_event.Handled) {
3807 OnPaint(paint_event);
3810 if (ThemeEngine.Current.DoubleBufferingSupported)
3811 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
3812 dc.DrawImage (ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle, GraphicsUnit.Pixel);
3813 paint_event.SetGraphics (dc);
3814 needs_redraw = false;
3817 XplatUI.PaintEventEnd(Handle, true);
3822 case Msg.WM_ERASEBKGND: {
3823 // The DefWndProc will never have to handle this, we always paint the background in managed code
3824 // In theory this code would look at ControlStyles.AllPaintingInWmPaint and and call OnPaintBackground
3825 // here but it just makes things more complicated...
3826 m.Result = (IntPtr)1;
3830 case Msg.WM_LBUTTONUP: {
3833 me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Left,
3835 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3838 HandleClick(mouse_clicks, me);
3841 if (InternalCapture) {
3842 InternalCapture = false;
3845 if (mouse_clicks > 1) {
3851 case Msg.WM_LBUTTONDOWN: {
3852 if (CanSelect && !is_selected) {
3855 InternalCapture = true;
3856 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3857 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3863 case Msg.WM_LBUTTONDBLCLK: {
3864 InternalCapture = true;
3866 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3867 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3873 case Msg.WM_MBUTTONUP: {
3876 me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Middle,
3878 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3881 HandleClick(mouse_clicks, me);
3883 if (InternalCapture) {
3884 InternalCapture = false;
3886 if (mouse_clicks > 1) {
3892 case Msg.WM_MBUTTONDOWN: {
3893 InternalCapture = true;
3894 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3895 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3901 case Msg.WM_MBUTTONDBLCLK: {
3902 InternalCapture = true;
3904 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3905 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3910 case Msg.WM_RBUTTONUP: {
3914 pt = new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()));
3915 pt = PointToScreen(pt);
3917 XplatUI.SendMessage(m.HWnd, Msg.WM_CONTEXTMENU, m.HWnd, (IntPtr)(pt.X + (pt.Y << 16)));
3919 me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Right,
3921 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3924 HandleClick(mouse_clicks, me);
3927 if (InternalCapture) {
3928 InternalCapture = false;
3931 if (mouse_clicks > 1) {
3937 case Msg.WM_RBUTTONDOWN: {
3938 InternalCapture = true;
3939 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3940 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3945 case Msg.WM_RBUTTONDBLCLK: {
3946 InternalCapture = true;
3948 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3949 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3954 case Msg.WM_CONTEXTMENU: {
3955 if (context_menu != null) {
3958 pt = new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()));
3959 context_menu.Show(this, PointToClient(pt));
3967 case Msg.WM_MOUSEWHEEL: {
3969 OnMouseWheel (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3970 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3971 HighOrder(m.WParam.ToInt32())));
3976 case Msg.WM_MOUSEMOVE: {
3977 OnMouseMove (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3979 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3984 case Msg.WM_MOUSE_ENTER: {
3989 OnMouseEnter(EventArgs.Empty);
3993 case Msg.WM_MOUSE_LEAVE: {
3995 OnMouseLeave(EventArgs.Empty);
3999 case Msg.WM_MOUSEHOVER: {
4000 OnMouseHover(EventArgs.Empty);
4004 case Msg.WM_SYSKEYUP: {
4005 if (ProcessKeyMessage(ref m)) {
4006 m.Result = IntPtr.Zero;
4010 if ((m.WParam.ToInt32() & (int)Keys.KeyCode) == (int)Keys.Menu) {
4014 if (form != null && form.ActiveMenu != null) {
4015 form.ActiveMenu.ProcessCmdKey(ref m, (Keys)m.WParam.ToInt32());
4023 case Msg.WM_SYSKEYDOWN:
4024 case Msg.WM_KEYDOWN:
4026 case Msg.WM_SYSCHAR:
4028 if (ProcessKeyMessage(ref m)) {
4029 m.Result = IntPtr.Zero;
4038 if (m.LParam != IntPtr.Zero) {
4041 hi = new HELPINFO();
4043 hi = (HELPINFO) Marshal.PtrToStructure (m.LParam, typeof (HELPINFO));
4044 mouse_pos = new Point(hi.MousePos.x, hi.MousePos.y);
4046 mouse_pos = Control.MousePosition;
4048 OnHelpRequested(new HelpEventArgs(mouse_pos));
4049 m.Result = (IntPtr)1;
4053 case Msg.WM_KILLFOCUS: {
4054 OnLeave(EventArgs.Empty);
4055 if (CausesValidation) {
4057 e = new CancelEventArgs(false);
4066 OnValidated(EventArgs.Empty);
4069 this.has_focus = false;
4070 this.is_selected = false;
4071 OnLostFocus(EventArgs.Empty);
4075 case Msg.WM_SETFOCUS: {
4076 OnEnter(EventArgs.Empty);
4077 this.has_focus = true;
4078 OnGotFocus(EventArgs.Empty);
4083 case Msg.WM_SYSCOLORCHANGE: {
4084 ThemeEngine.Current.ResetDefaults();
4085 OnSystemColorsChanged(EventArgs.Empty);
4090 case Msg.WM_SETCURSOR: {
4091 if ((cursor == null) || ((HitTest)(m.LParam.ToInt32() & 0xffff) != HitTest.HTCLIENT)) {
4096 XplatUI.SetCursor(window.Handle, cursor.handle);
4097 m.Result = (IntPtr)1;
4108 #endregion // Public Instance Methods
4110 #region OnXXX methods
4111 [EditorBrowsable(EditorBrowsableState.Advanced)]
4112 protected virtual void OnBackColorChanged(EventArgs e) {
4113 if (BackColorChanged!=null) BackColorChanged(this, e);
4114 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackColorChanged(e);
4117 [EditorBrowsable(EditorBrowsableState.Advanced)]
4118 protected virtual void OnBackgroundImageChanged(EventArgs e) {
4119 if (BackgroundImageChanged!=null) BackgroundImageChanged(this, e);
4120 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackgroundImageChanged(e);
4123 [EditorBrowsable(EditorBrowsableState.Advanced)]
4124 protected virtual void OnBindingContextChanged(EventArgs e) {
4125 CheckDataBindings ();
4126 if (BindingContextChanged!=null) {
4127 BindingContextChanged(this, e);
4129 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBindingContextChanged(e);
4132 [EditorBrowsable(EditorBrowsableState.Advanced)]
4133 protected virtual void OnCausesValidationChanged(EventArgs e) {
4134 if (CausesValidationChanged!=null) CausesValidationChanged(this, e);
4137 [EditorBrowsable(EditorBrowsableState.Advanced)]
4138 protected virtual void OnChangeUICues(UICuesEventArgs e) {
4139 if (ChangeUICues!=null) ChangeUICues(this, e);
4142 [EditorBrowsable(EditorBrowsableState.Advanced)]
4143 protected virtual void OnClick(EventArgs e) {
4144 if (Click!=null) Click(this, e);
4147 [EditorBrowsable(EditorBrowsableState.Advanced)]
4148 protected virtual void OnContextMenuChanged(EventArgs e) {
4149 if (ContextMenuChanged!=null) ContextMenuChanged(this, e);
4152 [EditorBrowsable(EditorBrowsableState.Advanced)]
4153 protected virtual void OnControlAdded(ControlEventArgs e) {
4154 if (ControlAdded!=null) ControlAdded(this, e);
4157 [EditorBrowsable(EditorBrowsableState.Advanced)]
4158 protected virtual void OnControlRemoved(ControlEventArgs e) {
4159 if (ControlRemoved!=null) ControlRemoved(this, e);
4162 [EditorBrowsable(EditorBrowsableState.Advanced)]
4163 protected virtual void OnCreateControl() {
4167 [EditorBrowsable(EditorBrowsableState.Advanced)]
4168 protected virtual void OnCursorChanged(EventArgs e) {
4169 if (CursorChanged!=null) CursorChanged(this, e);
4172 [EditorBrowsable(EditorBrowsableState.Advanced)]
4173 protected virtual void OnDockChanged(EventArgs e) {
4174 if (DockChanged!=null) DockChanged(this, e);
4177 [EditorBrowsable(EditorBrowsableState.Advanced)]
4178 protected virtual void OnDoubleClick(EventArgs e) {
4179 if (DoubleClick!=null) DoubleClick(this, e);
4182 [EditorBrowsable(EditorBrowsableState.Advanced)]
4183 protected virtual void OnDragDrop(DragEventArgs drgevent) {
4184 if (DragDrop!=null) DragDrop(this, drgevent);
4187 [EditorBrowsable(EditorBrowsableState.Advanced)]
4188 protected virtual void OnDragEnter(DragEventArgs drgevent) {
4189 if (DragEnter!=null) DragEnter(this, drgevent);
4192 [EditorBrowsable(EditorBrowsableState.Advanced)]
4193 protected virtual void OnDragLeave(EventArgs e) {
4194 if (DragLeave!=null) DragLeave(this, e);
4197 [EditorBrowsable(EditorBrowsableState.Advanced)]
4198 protected virtual void OnDragOver(DragEventArgs drgevent) {
4199 if (DragOver!=null) DragOver(this, drgevent);
4202 [EditorBrowsable(EditorBrowsableState.Advanced)]
4203 protected virtual void OnEnabledChanged(EventArgs e) {
4204 if (EnabledChanged!=null) EnabledChanged(this, e);
4205 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentEnabledChanged(e);
4208 [EditorBrowsable(EditorBrowsableState.Advanced)]
4209 protected virtual void OnEnter(EventArgs e) {
4210 if (Enter!=null) Enter(this, e);
4213 [EditorBrowsable(EditorBrowsableState.Advanced)]
4214 protected virtual void OnFontChanged(EventArgs e) {
4215 if (FontChanged!=null) FontChanged(this, e);
4216 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentFontChanged(e);
4219 [EditorBrowsable(EditorBrowsableState.Advanced)]
4220 protected virtual void OnForeColorChanged(EventArgs e) {
4221 if (ForeColorChanged!=null) ForeColorChanged(this, e);
4222 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentForeColorChanged(e);
4225 [EditorBrowsable(EditorBrowsableState.Advanced)]
4226 protected virtual void OnGiveFeedback(GiveFeedbackEventArgs gfbevent) {
4227 if (GiveFeedback!=null) GiveFeedback(this, gfbevent);
4230 [EditorBrowsable(EditorBrowsableState.Advanced)]
4231 protected virtual void OnGotFocus(EventArgs e) {
4232 if (GotFocus!=null) GotFocus(this, e);
4235 [EditorBrowsable(EditorBrowsableState.Advanced)]
4236 protected virtual void OnHandleCreated(EventArgs e) {
4237 if (HandleCreated!=null) HandleCreated(this, e);
4240 [EditorBrowsable(EditorBrowsableState.Advanced)]
4241 protected virtual void OnHandleDestroyed(EventArgs e) {
4242 if (HandleDestroyed!=null) HandleDestroyed(this, e);
4245 [EditorBrowsable(EditorBrowsableState.Advanced)]
4246 protected virtual void OnHelpRequested(HelpEventArgs hevent) {
4247 if (HelpRequested!=null) HelpRequested(this, hevent);
4250 protected virtual void OnImeModeChanged(EventArgs e) {
4251 if (ImeModeChanged!=null) ImeModeChanged(this, e);
4254 [EditorBrowsable(EditorBrowsableState.Advanced)]
4255 protected virtual void OnInvalidated(InvalidateEventArgs e) {
4256 needs_redraw = true;
4257 if (Invalidated!=null) Invalidated(this, e);
4260 [EditorBrowsable(EditorBrowsableState.Advanced)]
4261 protected virtual void OnKeyDown(KeyEventArgs e) {
4262 if (KeyDown!=null) KeyDown(this, e);
4265 [EditorBrowsable(EditorBrowsableState.Advanced)]
4266 protected virtual void OnKeyPress(KeyPressEventArgs e) {
4267 if (KeyPress!=null) KeyPress(this, e);
4270 [EditorBrowsable(EditorBrowsableState.Advanced)]
4271 protected virtual void OnKeyUp(KeyEventArgs e) {
4272 if (KeyUp!=null) KeyUp(this, e);
4275 [EditorBrowsable(EditorBrowsableState.Advanced)]
4276 protected virtual void OnLayout(LayoutEventArgs levent) {
4277 if (Layout!=null) Layout(this, levent);
4280 [EditorBrowsable(EditorBrowsableState.Advanced)]
4281 protected virtual void OnLeave(EventArgs e) {
4282 if (Leave!=null) Leave(this, e);
4285 [EditorBrowsable(EditorBrowsableState.Advanced)]
4286 protected virtual void OnLocationChanged(EventArgs e) {
4288 if (LocationChanged!=null) LocationChanged(this, e);
4291 [EditorBrowsable(EditorBrowsableState.Advanced)]
4292 protected virtual void OnLostFocus(EventArgs e) {
4293 if (LostFocus!=null) LostFocus(this, e);
4296 [EditorBrowsable(EditorBrowsableState.Advanced)]
4297 protected virtual void OnMouseDown(MouseEventArgs e) {
4298 if (MouseDown!=null) MouseDown(this, e);
4301 [EditorBrowsable(EditorBrowsableState.Advanced)]
4302 protected virtual void OnMouseEnter(EventArgs e) {
4303 if (MouseEnter!=null) MouseEnter(this, e);
4306 [EditorBrowsable(EditorBrowsableState.Advanced)]
4307 protected virtual void OnMouseHover(EventArgs e) {
4308 if (MouseHover!=null) MouseHover(this, e);
4311 [EditorBrowsable(EditorBrowsableState.Advanced)]
4312 protected virtual void OnMouseLeave(EventArgs e) {
4313 if (MouseLeave!=null) MouseLeave(this, e);
4316 [EditorBrowsable(EditorBrowsableState.Advanced)]
4317 protected virtual void OnMouseMove(MouseEventArgs e) {
4318 if (MouseMove!=null) MouseMove(this, e);
4321 [EditorBrowsable(EditorBrowsableState.Advanced)]
4322 protected virtual void OnMouseUp(MouseEventArgs e) {
4323 if (MouseUp!=null) MouseUp(this, e);
4326 [EditorBrowsable(EditorBrowsableState.Advanced)]
4327 protected virtual void OnMouseWheel(MouseEventArgs e) {
4328 if (MouseWheel!=null) MouseWheel(this, e);
4331 [EditorBrowsable(EditorBrowsableState.Advanced)]
4332 protected virtual void OnMove(EventArgs e) {
4333 if (Move!=null) Move(this, e);
4336 [EditorBrowsable(EditorBrowsableState.Advanced)]
4337 protected virtual void OnNotifyMessage(Message m) {
4341 [EditorBrowsable(EditorBrowsableState.Advanced)]
4342 protected virtual void OnPaint(PaintEventArgs e) {
4343 if (Paint!=null) Paint(this, e);
4346 internal virtual void OnPaintBackgroundInternal(PaintEventArgs e) {
4350 internal virtual void OnPaintInternal(PaintEventArgs e) {
4354 [EditorBrowsable(EditorBrowsableState.Advanced)]
4355 protected virtual void OnPaintBackground(PaintEventArgs pevent) {
4356 PaintControlBackground (pevent);
4359 [EditorBrowsable(EditorBrowsableState.Advanced)]
4360 protected virtual void OnParentBackColorChanged(EventArgs e) {
4361 if (background_color.IsEmpty && background_image==null) {
4363 OnBackColorChanged(e);
4367 [EditorBrowsable(EditorBrowsableState.Advanced)]
4368 protected virtual void OnParentBackgroundImageChanged(EventArgs e) {
4369 if (background_color.IsEmpty && background_image==null) {
4371 OnBackgroundImageChanged(e);
4375 [EditorBrowsable(EditorBrowsableState.Advanced)]
4376 protected virtual void OnParentBindingContextChanged(EventArgs e) {
4377 if (binding_context==null) {
4378 binding_context=Parent.binding_context;
4379 OnBindingContextChanged(e);
4383 [EditorBrowsable(EditorBrowsableState.Advanced)]
4384 protected virtual void OnParentChanged(EventArgs e) {
4385 if (ParentChanged!=null) ParentChanged(this, e);
4388 [EditorBrowsable(EditorBrowsableState.Advanced)]
4389 protected virtual void OnParentEnabledChanged(EventArgs e) {
4390 if (is_enabled != Parent.is_enabled) {
4391 is_enabled=Parent.is_enabled;
4393 if (EnabledChanged != null) {
4394 EnabledChanged(this, e);
4399 [EditorBrowsable(EditorBrowsableState.Advanced)]
4400 protected virtual void OnParentFontChanged(EventArgs e) {
4407 [EditorBrowsable(EditorBrowsableState.Advanced)]
4408 protected virtual void OnParentForeColorChanged(EventArgs e) {
4409 if (foreground_color.IsEmpty) {
4411 OnForeColorChanged(e);
4415 [EditorBrowsable(EditorBrowsableState.Advanced)]
4416 protected virtual void OnParentRightToLeftChanged(EventArgs e) {
4417 if (right_to_left==RightToLeft.Inherit) {
4419 OnRightToLeftChanged(e);
4423 [EditorBrowsable(EditorBrowsableState.Advanced)]
4424 protected virtual void OnParentVisibleChanged(EventArgs e) {
4426 OnVisibleChanged(e);
4430 [EditorBrowsable(EditorBrowsableState.Advanced)]
4431 protected virtual void OnQueryContinueDrag(QueryContinueDragEventArgs e) {
4432 if (QueryContinueDrag!=null) QueryContinueDrag(this, e);
4435 [EditorBrowsable(EditorBrowsableState.Advanced)]
4436 protected virtual void OnResize(EventArgs e) {
4437 if (Resize!=null) Resize(this, e);
4439 PerformLayout(this, "bounds");
4441 if (parent != null) {
4442 parent.PerformLayout();
4446 [EditorBrowsable(EditorBrowsableState.Advanced)]
4447 protected virtual void OnRightToLeftChanged(EventArgs e) {
4448 if (RightToLeftChanged!=null) RightToLeftChanged(this, e);
4449 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentRightToLeftChanged(e);
4452 [EditorBrowsable(EditorBrowsableState.Advanced)]
4453 protected virtual void OnSizeChanged(EventArgs e) {
4454 InvalidateBuffers ();
4456 if (SizeChanged!=null) SizeChanged(this, e);
4459 [EditorBrowsable(EditorBrowsableState.Advanced)]
4460 protected virtual void OnStyleChanged(EventArgs e) {
4461 if (StyleChanged!=null) StyleChanged(this, e);
4464 [EditorBrowsable(EditorBrowsableState.Advanced)]
4465 protected virtual void OnSystemColorsChanged(EventArgs e) {
4466 if (SystemColorsChanged!=null) SystemColorsChanged(this, e);
4469 [EditorBrowsable(EditorBrowsableState.Advanced)]
4470 protected virtual void OnTabIndexChanged(EventArgs e) {
4471 if (TabIndexChanged!=null) TabIndexChanged(this, e);
4474 [EditorBrowsable(EditorBrowsableState.Advanced)]
4475 protected virtual void OnTabStopChanged(EventArgs e) {
4476 if (TabStopChanged!=null) TabStopChanged(this, e);
4479 [EditorBrowsable(EditorBrowsableState.Advanced)]
4480 protected virtual void OnTextChanged(EventArgs e) {
4481 if (TextChanged!=null) TextChanged(this, e);
4484 [EditorBrowsable(EditorBrowsableState.Advanced)]
4485 protected virtual void OnValidated(EventArgs e) {
4486 if (Validated!=null) Validated(this, e);
4489 [EditorBrowsable(EditorBrowsableState.Advanced)]
4490 protected virtual void OnValidating(System.ComponentModel.CancelEventArgs e) {
4491 if (Validating!=null) Validating(this, e);
4494 [EditorBrowsable(EditorBrowsableState.Advanced)]
4495 protected virtual void OnVisibleChanged(EventArgs e) {
4496 if ((parent != null) && !Created && Visible) {
4503 needs_redraw = true;
4505 if (VisibleChanged!=null) VisibleChanged(this, e);
4507 // We need to tell our kids
4508 for (int i=0; i<child_controls.Count; i++) {
4509 if (child_controls[i].Visible) {
4510 child_controls[i].OnParentVisibleChanged(e);
4514 #endregion // OnXXX methods
4517 public event EventHandler BackColorChanged;
4518 public event EventHandler BackgroundImageChanged;
4519 public event EventHandler BindingContextChanged;
4520 public event EventHandler CausesValidationChanged;
4521 public event UICuesEventHandler ChangeUICues;
4522 public event EventHandler Click;
4523 public event EventHandler ContextMenuChanged;
4525 [EditorBrowsable(EditorBrowsableState.Advanced)]
4527 public event ControlEventHandler ControlAdded;
4529 [EditorBrowsable(EditorBrowsableState.Advanced)]
4531 public event ControlEventHandler ControlRemoved;
4533 [MWFDescription("Fired when the cursor for the control has been changed"), MWFCategory("PropertyChanged")]
4534 public event EventHandler CursorChanged;
4535 public event EventHandler DockChanged;
4536 public event EventHandler DoubleClick;
4537 public event DragEventHandler DragDrop;
4538 public event DragEventHandler DragEnter;
4539 public event EventHandler DragLeave;
4540 public event DragEventHandler DragOver;
4541 public event EventHandler EnabledChanged;
4542 public event EventHandler Enter;
4543 public event EventHandler FontChanged;
4544 public event EventHandler ForeColorChanged;
4545 public event GiveFeedbackEventHandler GiveFeedback;
4547 [EditorBrowsable(EditorBrowsableState.Advanced)]
4549 public event EventHandler GotFocus;
4551 [EditorBrowsable(EditorBrowsableState.Advanced)]
4553 public event EventHandler HandleCreated;
4555 [EditorBrowsable(EditorBrowsableState.Advanced)]
4557 public event EventHandler HandleDestroyed;
4559 public event HelpEventHandler HelpRequested;
4560 public event EventHandler ImeModeChanged;
4562 [EditorBrowsable(EditorBrowsableState.Advanced)]
4564 public event InvalidateEventHandler Invalidated;
4566 public event KeyEventHandler KeyDown;
4567 public event KeyPressEventHandler KeyPress;
4568 public event KeyEventHandler KeyUp;
4569 public event LayoutEventHandler Layout;
4570 public event EventHandler Leave;
4571 public event EventHandler LocationChanged;
4573 [EditorBrowsable(EditorBrowsableState.Advanced)]
4575 public event EventHandler LostFocus;
4577 public event MouseEventHandler MouseDown;
4578 public event EventHandler MouseEnter;
4579 public event EventHandler MouseHover;
4580 public event EventHandler MouseLeave;
4581 public event MouseEventHandler MouseMove;
4582 public event MouseEventHandler MouseUp;
4584 [EditorBrowsable(EditorBrowsableState.Advanced)]
4586 public event MouseEventHandler MouseWheel;
4588 public event EventHandler Move;
4589 public event PaintEventHandler Paint;
4590 public event EventHandler ParentChanged;
4591 public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp;
4592 public event QueryContinueDragEventHandler QueryContinueDrag;
4593 public event EventHandler Resize;
4594 public event EventHandler RightToLeftChanged;
4595 public event EventHandler SizeChanged;
4596 public event EventHandler StyleChanged;
4597 public event EventHandler SystemColorsChanged;
4598 public event EventHandler TabIndexChanged;
4599 public event EventHandler TabStopChanged;
4600 public event EventHandler TextChanged;
4601 public event EventHandler Validated;
4602 public event CancelEventHandler Validating;
4603 public event EventHandler VisibleChanged;
4604 #endregion // Events