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
39 using System.ComponentModel;
40 using System.ComponentModel.Design;
41 using System.ComponentModel.Design.Serialization;
42 using System.Collections;
43 using System.Diagnostics;
45 using System.Drawing.Drawing2D;
46 using System.Reflection;
47 using System.Runtime.InteropServices;
48 using System.Security;
49 using System.Threading;
51 namespace System.Windows.Forms
53 [Designer("System.Windows.Forms.Design.ControlDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
54 [DefaultProperty("Text")]
55 [DefaultEvent("Click")]
56 [DesignerSerializer("System.Windows.Forms.Design.ControlCodeDomSerializer, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
57 [ToolboxItemFilter("System.Windows.Forms")]
58 public class Control : Component, ISynchronizeInvoke, IWin32Window
60 #region Local Variables
63 internal Rectangle bounds; // bounding rectangle for control (client area + decorations)
64 private Rectangle explicit_bounds; // explicitly set bounds
65 internal object creator_thread; // thread that created the control
66 internal ControlNativeWindow window; // object for native window handle
67 internal string name; // for object naming
70 internal bool is_created; // true if OnCreateControl has been sent
71 internal bool has_focus; // true if control has focus
72 internal bool is_visible; // true if control is visible
73 internal bool is_entered; // is the mouse inside the control?
74 internal bool is_enabled; // true if control is enabled (usable/not grayed out)
75 internal bool is_accessible; // true if the control is visible to accessibility applications
76 internal bool is_captured; // tracks if the control has captured the mouse
77 internal bool is_toplevel; // tracks if the control is a toplevel window
78 internal bool is_recreating; // tracks if the handle for the control is being recreated
79 internal bool causes_validation; // tracks if validation is executed on changes
80 internal bool is_focusing; // tracks if Focus has been called on the control and has not yet finished
81 internal int tab_index; // position in tab order of siblings
82 internal bool tab_stop = true; // is the control a tab stop?
83 internal bool is_disposed; // has the window already been disposed?
84 internal Size client_size; // size of the client area (window excluding decorations)
85 internal Rectangle client_rect; // rectangle with the client area (window excluding decorations)
86 internal ControlStyles control_style; // rather win32-specific, style bits for control
87 internal ImeMode ime_mode = ImeMode.Inherit;
88 internal bool layout_pending; // true if our parent needs to re-layout us
89 internal object control_tag; // object that contains data about our control
90 internal int mouse_clicks; // Counter for mouse clicks
91 internal Cursor cursor; // Cursor for the window
92 internal bool allow_drop; // true if the control accepts droping objects on it
93 internal Region clip_region; // User-specified clip region for the window
96 internal Color foreground_color; // foreground color for control
97 internal Color background_color; // background color for control
98 internal Image background_image; // background image for control
99 internal Font font; // font for control
100 internal string text; // window/title text for control
101 internal BorderStyle border_style; // Border style of control
104 internal AnchorStyles anchor_style; // anchoring requirements for our control
105 internal DockStyle dock_style; // docking requirements for our control (supercedes anchoring)
106 internal int dist_left; // distance to the left border of the parent
107 internal int dist_top; // distance to the top border of the parent
108 internal int dist_right; // distance to the right border of the parent
109 internal int dist_bottom; // distance to the bottom border of the parent
111 // to be categorized...
112 static internal ArrayList controls = new ArrayList(); // All of the application's controls, in a flat list
113 internal ControlCollection child_controls; // our children
114 internal Control parent; // our parent control
115 internal AccessibleObject accessibility_object; // object that contains accessibility information about our control
116 internal BindingContext binding_context; // TODO
117 internal RightToLeft right_to_left; // drawing direction for control
118 internal int layout_suspended;
119 internal ContextMenu context_menu; // Context menu associated with the control
121 private Graphics dc_mem; // Graphics context for double buffering
122 private Bitmap bmp_mem; // Bitmap for double buffering control
123 private Region invalid_region;
125 private ControlBindingsCollection data_bindings;
128 internal bool use_compatible_text_rendering;
129 static internal bool verify_thread_handle;
130 private Padding padding;
131 private Size maximum_size;
132 private Size minimum_size;
133 private Size preferred_size;
134 private Padding margin;
135 internal Layout.LayoutEngine layout_engine;
138 #endregion // Local Variables
140 #region Private Classes
141 // This helper class allows us to dispatch messages to Control.WndProc
142 internal class ControlNativeWindow : NativeWindow {
143 private Control owner;
145 public ControlNativeWindow(Control control) : base() {
150 public Control Owner {
156 static internal Control ControlFromHandle(IntPtr hWnd) {
157 ControlNativeWindow window;
159 window = (ControlNativeWindow)window_collection[hWnd];
160 if (window != null) {
167 static internal Control ControlFromChildHandle (IntPtr handle) {
168 ControlNativeWindow window;
170 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
171 while (hwnd != null) {
172 window = (ControlNativeWindow)window_collection[hwnd.Handle];
173 if (window != null) {
182 protected override void WndProc(ref Message m) {
183 owner.WndProc(ref m);
188 #region Public Classes
190 public class ControlAccessibleObject : AccessibleObject {
191 #region ControlAccessibleObject Constructors
192 public ControlAccessibleObject(Control ownerControl) {
193 this.owner = ownerControl;
195 #endregion // ControlAccessibleObject Constructors
197 #region ControlAccessibleObject Public Instance Properties
198 public override string DefaultAction {
200 return base.DefaultAction;
204 public override string Description {
206 return base.Description;
210 public IntPtr Handle {
216 // We don't want to let them set it
220 public override string Help {
226 public override string KeyboardShortcut {
228 return base.KeyboardShortcut;
232 public override string Name {
242 public Control Owner {
248 public override AccessibleObject Parent {
255 public override AccessibleRole Role {
260 #endregion // ControlAccessibleObject Public Instance Properties
262 #region ControlAccessibleObject Public Instance Methods
263 public override int GetHelpTopic(out string FileName) {
264 return base.GetHelpTopic (out FileName);
267 [MonoTODO("Implement this and tie it into Control.AccessibilityNotifyClients")]
268 public void NotifyClients(AccessibleEvents accEvent) {
269 throw new NotImplementedException();
272 [MonoTODO("Implement this and tie it into Control.AccessibilityNotifyClients")]
273 public void NotifyClients(AccessibleEvents accEvent, int childID) {
274 throw new NotImplementedException();
277 public override string ToString() {
278 return "ControlAccessibleObject: Owner = " + owner.ToString() + ", Text: " + owner.text;
281 #endregion // ControlAccessibleObject Public Instance Methods
284 [DesignerSerializer("System.Windows.Forms.Design.ControlCollectionCodeDomSerializer, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
285 [ListBindable(false)]
286 public class ControlCollection : IList, ICollection, ICloneable, IEnumerable {
287 #region ControlCollection Local Variables
288 private ArrayList list;
289 internal ArrayList impl_list;
290 private Control [] all_controls;
291 internal Control owner;
292 #endregion // ControlCollection Local Variables
294 #region ControlCollection Public Constructor
295 public ControlCollection(Control owner) {
297 this.list=new ArrayList();
301 #region ControlCollection Public Instance Properties
308 public bool IsReadOnly {
310 return list.IsReadOnly;
314 public virtual Control this[int index] {
316 if (index < 0 || index >= list.Count) {
317 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
319 return (Control)list[index];
322 #endregion // ControlCollection Public Instance Properties
324 #region ControlCollection Private Instance Methods
325 public virtual void Add (Control value)
330 if (Contains (value)) {
331 owner.PerformLayout();
335 if (value.tab_index == -1) {
341 end = owner.child_controls.Count;
342 for (int i = 0; i < end; i++) {
343 index = owner.child_controls[i].tab_index;
348 value.tab_index = use;
351 if (value.parent != null) {
352 value.parent.Controls.Remove(value);
358 value.ChangeParent(owner);
362 owner.UpdateChildrenZOrder();
363 owner.PerformLayout(value, "Parent");
364 owner.OnControlAdded(new ControlEventArgs(value));
367 internal void AddToList (Control c)
373 internal virtual void AddImplicit (Control control)
375 if (impl_list == null)
376 impl_list = new ArrayList ();
378 if (AllContains (control))
382 impl_list.Add (control);
384 control.ChangeParent (owner);
385 control.InitLayout ();
386 owner.UpdateChildrenZOrder ();
387 owner.PerformLayout (control, "Parent");
388 owner.OnControlAdded (new ControlEventArgs (control));
391 public virtual void AddRange (Control[] controls)
393 if (controls == null)
394 throw new ArgumentNullException ("controls");
396 owner.SuspendLayout ();
399 for (int i = 0; i < controls.Length; i++)
402 owner.ResumeLayout ();
406 internal virtual void AddRangeImplicit (Control [] controls)
408 if (controls == null)
409 throw new ArgumentNullException ("controls");
411 owner.SuspendLayout ();
414 for (int i = 0; i < controls.Length; i++)
415 AddImplicit (controls [i]);
417 owner.ResumeLayout ();
421 public virtual void Clear ()
425 // MS sends remove events in reverse order
426 while (list.Count > 0) {
427 Remove((Control)list[list.Count - 1]);
431 internal virtual void ClearImplicit ()
433 if (impl_list == null)
439 public bool Contains (Control value)
441 for (int i = list.Count; i > 0; ) {
444 if (list [i] == value) {
445 // Do we need to do anything here?
452 internal bool ImplicitContains (Control value)
454 if (impl_list == null)
457 for (int i = impl_list.Count; i > 0; ) {
460 if (impl_list [i] == value) {
461 // Do we need to do anything here?
468 internal bool AllContains (Control value)
470 return Contains (value) || ImplicitContains (value);
473 public void CopyTo (Array array, int index)
475 list.CopyTo(array, index);
478 public override bool Equals(object other) {
479 if (other is ControlCollection && (((ControlCollection)other).owner==this.owner)) {
486 public int GetChildIndex(Control child) {
487 return GetChildIndex(child, false);
490 public int GetChildIndex(Control child, bool throwException) {
493 index=list.IndexOf(child);
495 if (index==-1 && throwException) {
496 throw new ArgumentException("Not a child control", "child");
501 public IEnumerator GetEnumerator() {
502 return list.GetEnumerator();
505 internal IEnumerator GetAllEnumerator ()
507 Control [] res = GetAllControls ();
508 return res.GetEnumerator ();
511 internal Control [] GetAllControls ()
513 if (all_controls != null)
516 if (impl_list == null) {
517 all_controls = (Control []) list.ToArray (typeof (Control));
521 all_controls = new Control [list.Count + impl_list.Count];
522 impl_list.CopyTo (all_controls);
523 list.CopyTo (all_controls, impl_list.Count);
528 public override int GetHashCode() {
529 return base.GetHashCode();
532 public int IndexOf(Control control) {
533 return list.IndexOf(control);
536 public virtual void Remove(Control value) {
537 owner.PerformLayout(value, "Parent");
538 owner.OnControlRemoved(new ControlEventArgs(value));
543 value.ChangeParent(null);
545 owner.UpdateChildrenZOrder();
548 internal virtual void RemoveImplicit (Control control)
550 if (impl_list != null) {
552 owner.PerformLayout (control, "Parent");
553 owner.OnControlRemoved (new ControlEventArgs (control));
554 impl_list.Remove (control);
556 control.ChangeParent (null);
557 owner.UpdateChildrenZOrder ();
560 public void RemoveAt(int index) {
561 if (index < 0 || index >= list.Count) {
562 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
564 Remove ((Control)list[index]);
567 public void SetChildIndex(Control child, int newIndex) {
570 old_index=list.IndexOf(child);
572 throw new ArgumentException("Not a child control", "child");
575 if (old_index==newIndex) {
580 list.RemoveAt(old_index);
582 if (newIndex>list.Count) {
585 list.Insert(newIndex, child);
587 child.UpdateZOrder();
588 owner.PerformLayout();
590 #endregion // ControlCollection Private Instance Methods
592 #region ControlCollection Interface Properties
593 object IList.this[int index] {
595 if (index<0 || index>=list.Count) {
596 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
602 if (!(value is Control)) {
603 throw new ArgumentException("Object of type Control required", "value");
607 Control ctrl = (Control) value;
610 ctrl.ChangeParent(owner);
614 owner.UpdateChildrenZOrder();
615 owner.PerformLayout(ctrl, "Parent");
619 bool IList.IsFixedSize {
625 bool ICollection.IsSynchronized {
627 return list.IsSynchronized;
631 object ICollection.SyncRoot {
633 return list.SyncRoot;
636 #endregion // ControlCollection Interface Properties
638 #region ControlCollection Interface Methods
639 int IList.Add(object value) {
641 throw new ArgumentNullException("value", "Cannot add null controls");
644 if (!(value is Control)) {
645 throw new ArgumentException("Object of type Control required", "value");
648 return list.Add(value);
651 bool IList.Contains(object value) {
652 if (!(value is Control)) {
653 throw new ArgumentException("Object of type Control required", "value");
656 return this.Contains((Control) value);
659 int IList.IndexOf(object value) {
660 if (!(value is Control)) {
661 throw new ArgumentException("Object of type Control required", "value");
664 return this.IndexOf((Control) value);
667 void IList.Insert(int index, object value) {
668 if (!(value is Control)) {
669 throw new ArgumentException("Object of type Control required", "value");
672 list.Insert(index, value);
675 void IList.Remove(object value) {
676 if (!(value is Control)) {
677 throw new ArgumentException("Object of type Control required", "value");
683 Object ICloneable.Clone() {
684 ControlCollection clone = new ControlCollection(this.owner);
685 clone.list=(ArrayList)list.Clone(); // FIXME: Do we need this?
688 #endregion // ControlCollection Interface Methods
690 #endregion // ControlCollection Class
692 #region Public Constructors
695 anchor_style = AnchorStyles.Top | AnchorStyles.Left;
703 layout_pending = false;
705 causes_validation = true;
707 layout_suspended = 0;
711 right_to_left = RightToLeft.Inherit;
712 border_style = BorderStyle.None;
713 background_color = Color.Empty;
720 use_compatible_text_rendering = Application.use_compatible_text_rendering;
721 padding = new Padding(0);
722 maximum_size = new Size();
723 minimum_size = new Size();
724 preferred_size = new Size();
725 margin = this.DefaultMargin;
726 layout_engine = this.LayoutEngine;
729 control_style = ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint |
730 ControlStyles.Selectable | ControlStyles.StandardClick |
731 ControlStyles.StandardDoubleClick;
733 control_style |= ControlStyles.UseTextForAccessibility;
737 background_image = null;
741 window = new ControlNativeWindow(this);
742 child_controls = CreateControlsInstance();
743 client_size = new Size(DefaultSize.Width, DefaultSize.Height);
744 client_rect = new Rectangle(0, 0, DefaultSize.Width, DefaultSize.Height);
745 XplatUI.CalculateWindowRect(ref client_rect, CreateParams.Style, CreateParams.ExStyle, null, out bounds);
746 if ((CreateParams.Style & (int)WindowStyles.WS_CHILD) == 0) {
752 public Control(Control parent, string text) : this() {
757 public Control(Control parent, string text, int left, int top, int width, int height) : this() {
762 bounds.Height=height;
763 SetBounds(left, top, width, height, BoundsSpecified.All);
767 public Control(string text) : this() {
771 public Control(string text, int left, int top, int width, int height) : this() {
775 bounds.Height=height;
776 SetBounds(left, top, width, height, BoundsSpecified.All);
780 private delegate void RemoveDelegate(object c);
782 protected override void Dispose(bool disposing) {
783 if (!is_disposed && disposing) {
796 if (invalid_region!=null) {
797 invalid_region.Dispose();
800 if (this.InvokeRequired) {
801 if (Application.MessageLoop) {
802 this.BeginInvokeInternal(new MethodInvoker(DestroyHandle), null, true);
803 this.BeginInvokeInternal(new RemoveDelegate(controls.Remove), new object[] {this}, true);
807 lock (Control.controls) {
808 Control.controls.Remove(this);
813 if (parent != null) {
814 parent.Controls.Remove(this);
817 Control [] children = child_controls.GetAllControls ();
818 for (int i=0; i<children.Length; i++) {
819 children[i].parent = null; // Need to set to null or our child will try and remove from ourselves and crash
820 children[i].Dispose();
825 base.Dispose(disposing);
827 #endregion // Public Constructors
829 #region Internal Properties
830 internal BorderStyle InternalBorderStyle {
836 if (!Enum.IsDefined (typeof (BorderStyle), value))
837 throw new InvalidEnumArgumentException (string.Format("Enum argument value '{0}' is not valid for BorderStyle", value));
839 if (border_style != value) {
840 border_style = value;
842 if (IsHandleCreated) {
843 XplatUI.SetBorderStyle(window.Handle, (FormBorderStyle)border_style);
849 #endregion // Internal Properties
851 #region Private & Internal Methods
852 internal IAsyncResult BeginInvokeInternal (Delegate method, object [] args, bool disposing) {
853 AsyncMethodResult result;
854 AsyncMethodData data;
861 if (!p.IsHandleCreated) {
862 throw new InvalidOperationException("Cannot call Invoke or InvokeAsync on a control until the window handle is created");
868 result = new AsyncMethodResult ();
869 data = new AsyncMethodData ();
871 data.Handle = window.Handle;
872 data.Method = method;
874 data.Result = result;
877 if (!ExecutionContext.IsFlowSuppressed ()) {
878 data.Context = ExecutionContext.Capture ();
881 #if !MWF_ON_MSRUNTIME
882 if (SecurityManager.SecurityEnabled) {
883 data.Stack = CompressedStack.GetCompressedStack ();
888 XplatUI.SendAsyncMethod (data);
893 internal void PointToClient (ref int x, ref int y)
895 XplatUI.ScreenToClient (Handle, ref x, ref y);
898 internal void PointToScreen (ref int x, ref int y)
900 XplatUI.ClientToScreen (Handle, ref x, ref y);
903 internal bool IsRecreating {
905 return is_recreating;
909 internal Graphics DeviceContext {
911 if (dc_mem == null) {
912 CreateBuffers(this.Width, this.Height);
918 private void ImageBufferNeedsRedraw () {
919 if (invalid_region != null)
920 invalid_region.Dispose();
921 invalid_region = new Region (ClientRectangle);
924 private Bitmap ImageBuffer {
927 CreateBuffers(this.Width, this.Height);
933 internal void CreateBuffers (int width, int height) {
942 bmp_mem = new Bitmap (width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
943 dc_mem = Graphics.FromImage (bmp_mem);
944 ImageBufferNeedsRedraw ();
947 internal void InvalidateBuffers ()
949 if (dc_mem != null) {
955 ImageBufferNeedsRedraw ();
958 internal static void SetChildColor(Control parent) {
961 for (int i=0; i < parent.child_controls.Count; i++) {
962 child=parent.child_controls[i];
963 if (child.child_controls.Count>0) {
964 SetChildColor(child);
970 internal bool Select(Control control) {
971 IContainerControl container;
973 if (control == null) {
977 container = GetContainerControl();
978 if (container != null) {
979 container.ActiveControl = control;
981 if (control.IsHandleCreated) {
982 XplatUI.SetFocus(control.window.Handle);
987 internal void SelectChild (Control control)
989 if (control.IsHandleCreated)
990 XplatUI.SetFocus (control.window.Handle);
993 internal virtual void DoDefaultAction() {
994 // Only here to be overriden by our actual controls; this is needed by the accessibility class
997 internal static int LowOrder (int param) {
998 return ((int)(short)(param & 0xffff));
1001 internal static int HighOrder (int param) {
1002 return ((int)(short)(param >> 16));
1005 // This method exists so controls overriding OnPaintBackground can have default background painting done
1006 internal virtual void PaintControlBackground (PaintEventArgs pevent)
1008 if (GetStyle(ControlStyles.SupportsTransparentBackColor) && (BackColor.A != 0xff)) {
1009 if (parent != null) {
1010 PaintEventArgs parent_pe;
1011 GraphicsState state;
1013 parent_pe = new PaintEventArgs(pevent.Graphics, new Rectangle(pevent.ClipRectangle.X + Left, pevent.ClipRectangle.Y + Top, pevent.ClipRectangle.Width, pevent.ClipRectangle.Height));
1015 state = parent_pe.Graphics.Save();
1016 parent_pe.Graphics.TranslateTransform(-Left, -Top);
1017 parent.OnPaintBackground(parent_pe);
1018 parent_pe.Graphics.Restore(state);
1020 state = parent_pe.Graphics.Save();
1021 parent_pe.Graphics.TranslateTransform(-Left, -Top);
1022 parent.OnPaint(parent_pe);
1023 parent_pe.Graphics.Restore(state);
1024 parent_pe.SetGraphics(null);
1028 if ((clip_region != null) && (XplatUI.UserClipWontExposeParent)) {
1029 if (parent != null) {
1030 PaintEventArgs parent_pe;
1032 GraphicsState state;
1035 hwnd = Hwnd.ObjectFromHandle(Handle);
1038 parent_pe = new PaintEventArgs(pevent.Graphics, new Rectangle(pevent.ClipRectangle.X + Left, pevent.ClipRectangle.Y + Top, pevent.ClipRectangle.Width, pevent.ClipRectangle.Height));
1040 region = new Region ();
1042 region.Union(ClientRectangle);
1044 foreach (Rectangle r in hwnd.ClipRectangles) {
1048 state = parent_pe.Graphics.Save();
1049 parent_pe.Graphics.Clip = region;
1051 parent_pe.Graphics.TranslateTransform(-Left, -Top);
1052 parent.OnPaintBackground(parent_pe);
1053 parent_pe.Graphics.Restore(state);
1055 state = parent_pe.Graphics.Save();
1056 parent_pe.Graphics.Clip = region;
1058 parent_pe.Graphics.TranslateTransform(-Left, -Top);
1059 parent.OnPaint(parent_pe);
1060 parent_pe.Graphics.Restore(state);
1061 parent_pe.SetGraphics(null);
1063 region.Intersect(clip_region);
1064 pevent.Graphics.Clip = region;
1069 if (background_image == null) {
1070 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));
1074 DrawBackgroundImage (pevent.Graphics);
1077 void DrawBackgroundImage (Graphics g)
1079 using (TextureBrush b = new TextureBrush (background_image, WrapMode.Tile)) {
1080 g.FillRectangle (b, ClientRectangle);
1084 internal virtual void DndEnter (DragEventArgs e)
1091 internal virtual void DndOver (DragEventArgs e)
1098 internal virtual void DndDrop (DragEventArgs e)
1102 } catch (Exception exc) {
1103 Console.Error.WriteLine ("MWF: Exception while dropping:");
1104 Console.Error.WriteLine (exc);
1108 internal virtual void DndLeave (EventArgs e)
1115 internal virtual void DndFeedback(GiveFeedbackEventArgs e)
1122 internal virtual void DndContinueDrag(QueryContinueDragEventArgs e)
1125 OnQueryContinueDrag(e);
1129 internal static MouseButtons FromParamToMouseButtons (int param) {
1130 MouseButtons buttons = MouseButtons.None;
1132 if ((param & (int) MsgButtons.MK_LBUTTON) != 0)
1133 buttons |= MouseButtons.Left;
1135 if ((param & (int) MsgButtons.MK_MBUTTON) != 0)
1136 buttons |= MouseButtons.Middle;
1138 if ((param & (int) MsgButtons.MK_RBUTTON) != 0)
1139 buttons |= MouseButtons.Right;
1145 internal void FireEnter ()
1147 OnEnter (EventArgs.Empty);
1150 internal void FireLeave ()
1152 OnLeave (EventArgs.Empty);
1155 internal void FireValidating (CancelEventArgs ce)
1160 internal void FireValidated ()
1162 OnValidated (EventArgs.Empty);
1165 internal virtual bool ProcessControlMnemonic(char charCode) {
1166 return ProcessMnemonic(charCode);
1169 private static Control FindFlatForward(Control container, Control start) {
1175 end = container.child_controls.Count;
1177 if (start != null) {
1178 index = start.tab_index;
1184 for (int i = 0, pos = -1; i < end; i++) {
1185 if (start == container.child_controls[i]) {
1190 if (found == null) {
1191 if (container.child_controls[i].tab_index > index || (pos > -1 && pos < i && container.child_controls[i].tab_index == index)) {
1192 found = container.child_controls[i];
1194 } else if (found.tab_index > container.child_controls[i].tab_index) {
1195 if (container.child_controls[i].tab_index > index) {
1196 found = container.child_controls[i];
1203 private static Control FindControlForward(Control container, Control start) {
1208 if (start == null) {
1209 return FindFlatForward(container, start);
1212 if (start.child_controls != null && start.child_controls.Count > 0 &&
1213 (start == container || !((start is IContainerControl) && start.GetStyle(ControlStyles.ContainerControl)))) {
1214 return FindControlForward(start, null);
1217 while (start != container) {
1218 found = FindFlatForward(start.parent, start);
1219 if (found != null) {
1222 start = start.parent;
1228 private static Control FindFlatBackward(Control container, Control start) {
1234 end = container.child_controls.Count;
1236 if (start != null) {
1237 index = start.tab_index;
1239 // FIXME: Possible speed-up: Keep the highest taborder index in the container
1241 for (int i = 0; i < end; i++) {
1242 if (container.child_controls[i].tab_index > index) {
1243 index = container.child_controls[i].tab_index;
1251 for (int i = end - 1; i >= 0; i--) {
1252 if (start == container.child_controls[i]) {
1257 if (found == null || found.tab_index < container.child_controls[i].tab_index) {
1258 if (container.child_controls[i].tab_index < index || (hit && container.child_controls[i].tab_index == index))
1259 found = container.child_controls[i];
1266 private static Control FindControlBackward(Control container, Control start) {
1268 Control found = null;
1270 if (start == null) {
1271 found = FindFlatBackward(container, start);
1273 else if (start != container) {
1274 if (start.parent != null) {
1275 found = FindFlatBackward(start.parent, start);
1277 if (found == null) {
1278 if (start.parent != container)
1279 return start.parent;
1285 if (found == null || start.parent == null)
1288 while (found != null && (found == container || (!((found is IContainerControl) && found.GetStyle(ControlStyles.ContainerControl))) &&
1289 found.child_controls != null && found.child_controls.Count > 0)) {
1290 // while (ctl.child_controls != null && ctl.child_controls.Count > 0 &&
1291 // (ctl == this || (!((ctl is IContainerControl) && ctl.GetStyle(ControlStyles.ContainerControl))))) {
1292 found = FindFlatBackward(found, null);
1302 if (start != null) {
1303 found = FindFlatBackward(start.parent, start);
1304 if (found == null) {
1305 if (start.parent != container) {
1306 return start.parent;
1310 if (found == null) {
1311 found = FindFlatBackward(container, start);
1314 if (container != start) {
1315 while ((found != null) && (!found.Contains(start)) && found.child_controls != null && found.child_controls.Count > 0 && !(found is IContainerControl)) {// || found.GetStyle(ControlStyles.ContainerControl))) {
1316 found = FindControlBackward(found, null);
1317 if (found != null) {
1326 internal virtual void HandleClick(int clicks, MouseEventArgs me) {
1327 if (GetStyle(ControlStyles.StandardClick)) {
1328 if ((clicks > 1) && GetStyle(ControlStyles.StandardDoubleClick)) {
1330 OnDoubleClick(EventArgs.Empty);
1332 OnClick(EventArgs.Empty);
1342 private void CheckDataBindings ()
1344 if (data_bindings == null)
1347 BindingContext binding_context = BindingContext;
1348 foreach (Binding binding in data_bindings) {
1349 binding.Check (binding_context);
1354 private void ChangeParent(Control new_parent) {
1358 Color pre_fore_color;
1359 Color pre_back_color;
1360 RightToLeft pre_rtl;
1362 // These properties are inherited from our parent
1363 // Get them pre parent-change and then send events
1364 // if they are changed after we have our new parent
1365 pre_enabled = Enabled;
1366 pre_visible = Visible;
1368 pre_fore_color = ForeColor;
1369 pre_back_color = BackColor;
1370 pre_rtl = RightToLeft;
1371 // MS doesn't seem to send a CursorChangedEvent
1373 parent = new_parent;
1375 if (IsHandleCreated)
1376 XplatUI.SetParent(Handle,
1377 (new_parent == null || !new_parent.IsHandleCreated) ? IntPtr.Zero : new_parent.Handle);
1379 OnParentChanged(EventArgs.Empty);
1381 if (pre_enabled != Enabled) {
1382 OnEnabledChanged(EventArgs.Empty);
1385 if (pre_visible != Visible) {
1386 OnVisibleChanged(EventArgs.Empty);
1389 if (pre_font != Font) {
1390 OnFontChanged(EventArgs.Empty);
1393 if (pre_fore_color != ForeColor) {
1394 OnForeColorChanged(EventArgs.Empty);
1397 if (pre_back_color != BackColor) {
1398 OnBackColorChanged(EventArgs.Empty);
1401 if (pre_rtl != RightToLeft) {
1402 // MS sneaks a OnCreateControl and OnHandleCreated in here, I guess
1403 // because when RTL changes they have to recreate the win32 control
1404 // We don't really need that (until someone runs into compatibility issues)
1405 OnRightToLeftChanged(EventArgs.Empty);
1408 if ((new_parent != null) && new_parent.Created && !Created) {
1412 if ((binding_context == null) && Created) {
1413 OnBindingContextChanged(EventArgs.Empty);
1417 private void UpdateDistances() {
1418 if ((parent != null) && (parent.layout_suspended == 0)) {
1419 dist_left = bounds.X;
1420 dist_top = bounds.Y;
1421 dist_right = parent.ClientSize.Width - bounds.X - bounds.Width;
1422 dist_bottom = parent.ClientSize.Height - bounds.Y - bounds.Height;
1425 #endregion // Private & Internal Methods
1427 #region Public Static Properties
1428 public static Color DefaultBackColor {
1430 return ThemeEngine.Current.DefaultControlBackColor;
1434 public static Font DefaultFont {
1436 return ThemeEngine.Current.DefaultFont;
1440 public static Color DefaultForeColor {
1442 return ThemeEngine.Current.DefaultControlForeColor;
1446 public static Keys ModifierKeys {
1448 return XplatUI.State.ModifierKeys;
1452 public static MouseButtons MouseButtons {
1454 return XplatUI.State.MouseButtons;
1458 public static Point MousePosition {
1460 return Cursor.Position;
1466 public static bool CheckForIllegalCrossThreadCalls
1469 return verify_thread_handle;
1473 verify_thread_handle = value;
1477 #endregion // Public Static Properties
1479 #region Public Instance Properties
1480 [EditorBrowsable(EditorBrowsableState.Advanced)]
1482 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1483 public AccessibleObject AccessibilityObject {
1485 if (accessibility_object==null) {
1486 accessibility_object=CreateAccessibilityInstance();
1488 return accessibility_object;
1492 [EditorBrowsable(EditorBrowsableState.Advanced)]
1494 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1495 public string AccessibleDefaultActionDescription {
1497 return AccessibilityObject.default_action;
1501 AccessibilityObject.default_action=value;
1506 [DefaultValue(null)]
1507 [MWFCategory("Accessibility")]
1508 public string AccessibleDescription {
1510 return AccessibilityObject.description;
1514 AccessibilityObject.description=value;
1519 [DefaultValue(null)]
1520 [MWFCategory("Accessibility")]
1521 public string AccessibleName {
1523 return AccessibilityObject.Name;
1527 AccessibilityObject.Name=value;
1531 [DefaultValue(AccessibleRole.Default)]
1532 [MWFDescription("Role of the control"), MWFCategory("Accessibility")]
1533 public AccessibleRole AccessibleRole {
1535 return AccessibilityObject.role;
1539 AccessibilityObject.role=value;
1543 [DefaultValue(false)]
1544 [MWFCategory("Behavior")]
1545 public virtual bool AllowDrop {
1551 if (allow_drop == value)
1554 if (IsHandleCreated) {
1556 XplatUI.SetAllowDrop (Handle, value);
1562 [RefreshProperties(RefreshProperties.Repaint)]
1563 [DefaultValue(AnchorStyles.Top | AnchorStyles.Left)]
1564 [MWFCategory("Layout")]
1565 public virtual AnchorStyles Anchor {
1567 return anchor_style;
1573 if (parent != null) {
1574 parent.PerformLayout(this, "Parent");
1580 // XXX: Implement me!
1583 public virtual bool AutoSize {
1585 //Console.Error.WriteLine("Unimplemented: Control::get_AutoSize()");
1589 Console.Error.WriteLine("Unimplemented: Control::set_AutoSize(bool)");
1594 public virtual Size MaximumSize {
1596 return maximum_size;
1599 maximum_size = value;
1603 public virtual Size MinimumSize {
1605 return minimum_size;
1608 minimum_size = value;
1614 [MWFCategory("Appearance")]
1615 public virtual Color BackColor {
1617 if (background_color.IsEmpty) {
1619 Color pcolor = parent.BackColor;
1620 if (pcolor.A == 0xff || GetStyle(ControlStyles.SupportsTransparentBackColor))
1623 return DefaultBackColor;
1625 return background_color;
1629 if (!value.IsEmpty && (value.A != 0xff) && !GetStyle(ControlStyles.SupportsTransparentBackColor)) {
1630 throw new ArgumentException("Transparent background colors are not supported on this control");
1633 if (background_color != value) {
1634 background_color=value;
1635 SetChildColor(this);
1636 OnBackColorChanged(EventArgs.Empty);
1643 [DefaultValue(null)]
1644 [MWFCategory("Appearance")]
1645 public virtual Image BackgroundImage {
1647 return background_image;
1651 if (background_image!=value) {
1652 background_image=value;
1653 OnBackgroundImageChanged(EventArgs.Empty);
1658 [EditorBrowsable(EditorBrowsableState.Advanced)]
1660 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1661 public virtual BindingContext BindingContext {
1663 if (binding_context != null)
1664 return binding_context;
1667 binding_context = Parent.BindingContext;
1668 return binding_context;
1671 if (binding_context != value) {
1672 binding_context = value;
1673 OnBindingContextChanged(EventArgs.Empty);
1678 [EditorBrowsable(EditorBrowsableState.Advanced)]
1680 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1683 return bounds.Y+bounds.Height;
1687 [EditorBrowsable(EditorBrowsableState.Advanced)]
1689 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1690 public Rectangle Bounds {
1696 SetBounds(value.Left, value.Top, value.Width, value.Height, BoundsSpecified.All);
1700 [EditorBrowsable(EditorBrowsableState.Advanced)]
1702 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1703 public bool CanFocus {
1705 if (IsHandleCreated && Visible && Enabled) {
1712 [EditorBrowsable(EditorBrowsableState.Advanced)]
1714 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1715 public bool CanSelect {
1719 if (!GetStyle(ControlStyles.Selectable)) {
1724 while (parent != null) {
1725 if (!parent.is_visible || !parent.is_enabled) {
1729 parent = parent.parent;
1735 internal virtual bool InternalCapture {
1745 [EditorBrowsable(EditorBrowsableState.Advanced)]
1747 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1748 public bool Capture {
1750 return this.is_captured;
1754 if (this.IsHandleCreated && value != is_captured) {
1757 XplatUI.GrabWindow(this.window.Handle, IntPtr.Zero);
1759 XplatUI.UngrabWindow(this.window.Handle);
1760 is_captured = false;
1766 [DefaultValue(true)]
1767 [MWFCategory("Focus")]
1768 public bool CausesValidation {
1770 return this.causes_validation;
1774 if (this.causes_validation != value) {
1775 causes_validation = value;
1776 OnCausesValidationChanged(EventArgs.Empty);
1781 [EditorBrowsable(EditorBrowsableState.Advanced)]
1783 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1784 public Rectangle ClientRectangle {
1786 client_rect.Width = client_size.Width;
1787 client_rect.Height = client_size.Height;
1792 [EditorBrowsable(EditorBrowsableState.Advanced)]
1794 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1795 public Size ClientSize {
1798 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1799 return ((Form)this).form_parent_window.ClientSize;
1807 this.SetClientSizeCore(value.Width, value.Height);
1811 [EditorBrowsable(EditorBrowsableState.Advanced)]
1813 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1814 [DescriptionAttribute("ControlCompanyNameDescr")]
1815 public String CompanyName {
1817 return "Mono Project, Novell, Inc.";
1821 [EditorBrowsable(EditorBrowsableState.Advanced)]
1823 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1824 public bool ContainsFocus {
1826 IntPtr focused_window;
1828 focused_window = XplatUI.GetFocus();
1829 if (IsHandleCreated) {
1830 if (focused_window == Handle) {
1834 for (int i=0; i < child_controls.Count; i++) {
1835 if (child_controls[i].ContainsFocus) {
1844 [DefaultValue(null)]
1845 [MWFCategory("Behavior")]
1846 public virtual ContextMenu ContextMenu {
1848 return context_menu;
1852 if (context_menu != value) {
1853 context_menu = value;
1854 OnContextMenuChanged(EventArgs.Empty);
1860 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
1861 public ControlCollection Controls {
1863 return this.child_controls;
1867 [EditorBrowsable(EditorBrowsableState.Advanced)]
1869 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1870 public bool Created {
1872 return (!is_disposed && is_created);
1876 [AmbientValue(null)]
1877 [MWFCategory("Appearance")]
1878 public virtual Cursor Cursor {
1880 if (cursor != null) {
1884 if (parent != null) {
1885 return parent.Cursor;
1888 return Cursors.Default;
1892 if (cursor != value) {
1897 if (IsHandleCreated) {
1898 pt = Cursor.Position;
1900 if (bounds.Contains(pt) || Capture) {
1901 if (GetChildAtPoint(pt) == null) {
1902 if (cursor != null) {
1903 XplatUI.SetCursor(window.Handle, cursor.handle);
1905 if (parent != null) {
1906 XplatUI.SetCursor(window.Handle, parent.Cursor.handle);
1908 XplatUI.SetCursor(window.Handle, Cursors.Default.handle);
1915 OnCursorChanged(EventArgs.Empty);
1921 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
1922 [ParenthesizePropertyName(true)]
1923 [RefreshProperties(RefreshProperties.All)]
1924 [MWFCategory("Data")]
1925 public ControlBindingsCollection DataBindings {
1927 if (data_bindings == null)
1928 data_bindings = new ControlBindingsCollection (this);
1929 return data_bindings;
1933 [EditorBrowsable(EditorBrowsableState.Advanced)]
1935 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1936 public virtual Rectangle DisplayRectangle {
1938 return ClientRectangle;
1942 [EditorBrowsable(EditorBrowsableState.Advanced)]
1944 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1945 public bool Disposing {
1952 [RefreshProperties(RefreshProperties.Repaint)]
1953 [DefaultValue(DockStyle.None)]
1954 [MWFCategory("Layout")]
1955 public virtual DockStyle Dock {
1961 if (dock_style == value) {
1967 if (dock_style == DockStyle.None) {
1968 if (explicit_bounds == Rectangle.Empty)
1969 Bounds = new Rectangle (new Point (0, 0), DefaultSize);
1971 Bounds = explicit_bounds;
1974 if (parent != null) {
1975 parent.PerformLayout(this, "Parent");
1978 OnDockChanged(EventArgs.Empty);
1984 [MWFCategory("Behavior")]
1985 public bool Enabled {
1991 if (parent != null) {
1992 return parent.Enabled;
2000 bool old_value = is_enabled;
2003 if (old_value != value && !value && this.has_focus)
2004 SelectNextControl(this, true, true, true, true);
2006 OnEnabledChanged (EventArgs.Empty);
2010 [EditorBrowsable(EditorBrowsableState.Advanced)]
2012 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2013 public virtual bool Focused {
2015 return this.has_focus;
2020 [AmbientValue(null)]
2022 [MWFCategory("Appearance")]
2023 public virtual Font Font {
2029 if (Parent != null && Parent.Font != null) {
2036 [param:MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Font))]
2038 if (font != null && font.Equals (value)) {
2044 OnFontChanged (EventArgs.Empty);
2049 [MWFCategory("Appearance")]
2050 public virtual Color ForeColor {
2052 if (foreground_color.IsEmpty) {
2054 return parent.ForeColor;
2056 return DefaultForeColor;
2058 return foreground_color;
2062 if (foreground_color != value) {
2063 foreground_color=value;
2065 OnForeColorChanged(EventArgs.Empty);
2072 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2073 public IntPtr Handle { // IWin32Window
2076 if (verify_thread_handle) {
2077 if (this.InvokeRequired) {
2078 throw new InvalidOperationException("Cross-thread access of handle detected. Handle access only valid on thread that created the control");
2082 if (!IsHandleCreated) {
2085 return window.Handle;
2089 [EditorBrowsable(EditorBrowsableState.Advanced)]
2091 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2092 public bool HasChildren {
2094 if (this.child_controls.Count>0) {
2101 [EditorBrowsable(EditorBrowsableState.Always)]
2103 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2106 return this.bounds.Height;
2110 SetBounds(bounds.X, bounds.Y, bounds.Width, value, BoundsSpecified.Height);
2114 [AmbientValue(ImeMode.Inherit)]
2116 [MWFCategory("Behavior")]
2117 public ImeMode ImeMode {
2119 if (ime_mode == DefaultImeMode) {
2121 return parent.ImeMode;
2123 return ImeMode.NoControl; // default value
2129 if (ime_mode != value) {
2132 OnImeModeChanged(EventArgs.Empty);
2137 [EditorBrowsable(EditorBrowsableState.Advanced)]
2139 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2140 public bool InvokeRequired { // ISynchronizeInvoke
2142 if (creator_thread != null && creator_thread!=Thread.CurrentThread) {
2149 [EditorBrowsable(EditorBrowsableState.Advanced)]
2151 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2152 public bool IsAccessible {
2154 return is_accessible;
2158 is_accessible = value;
2162 [EditorBrowsable(EditorBrowsableState.Advanced)]
2164 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2165 public bool IsDisposed {
2167 return this.is_disposed;
2171 [EditorBrowsable(EditorBrowsableState.Advanced)]
2173 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2174 public bool IsHandleCreated {
2176 if ((window != null) && (window.Handle != IntPtr.Zero)) {
2177 Hwnd hwnd = Hwnd.ObjectFromHandle (window.Handle);
2178 if (hwnd != null && !hwnd.zombie)
2187 public virtual Layout.LayoutEngine LayoutEngine {
2188 get { return new Layout.DefaultLayout (); }
2192 [EditorBrowsable(EditorBrowsableState.Always)]
2194 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2197 return this.bounds.X;
2201 SetBounds(value, bounds.Y, bounds.Width, bounds.Height, BoundsSpecified.X);
2206 [MWFCategory("Layout")]
2207 public Point Location {
2209 return new Point(bounds.X, bounds.Y);
2213 SetBounds(value.X, value.Y, bounds.Width, bounds.Height, BoundsSpecified.Location);
2218 [Localizable (true)]
2219 public Padding Margin {
2220 get { return this.margin; }
2221 set { this.margin = value; }
2226 public string Name {
2238 public Padding Padding {
2250 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2251 public Control Parent {
2257 if (value == this) {
2258 throw new ArgumentException("A circular control reference has been made. A control cannot be owned or parented to itself.");
2261 if (parent!=value) {
2263 parent.Controls.Remove(this);
2268 value.Controls.Add(this);
2273 [EditorBrowsable(EditorBrowsableState.Advanced)]
2275 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2276 public string ProductName {
2278 Type t = typeof (AssemblyProductAttribute);
2279 Assembly assembly = GetType().Module.Assembly;
2280 object [] attrs = assembly.GetCustomAttributes (t, false);
2281 AssemblyProductAttribute a = null;
2282 // On MS we get a NullRefException if product attribute is not
2284 if (attrs != null && attrs.Length > 0)
2285 a = (AssemblyProductAttribute) attrs [0];
2290 [EditorBrowsable(EditorBrowsableState.Advanced)]
2292 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2293 public string ProductVersion {
2295 Type t = typeof (AssemblyVersionAttribute);
2296 Assembly assembly = GetType().Module.Assembly;
2297 object [] attrs = assembly.GetCustomAttributes (t, false);
2298 if (attrs == null || attrs.Length < 1)
2300 return ((AssemblyVersionAttribute)attrs [0]).Version;
2304 [EditorBrowsable(EditorBrowsableState.Advanced)]
2306 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2307 public bool RecreatingHandle {
2309 return is_recreating;
2313 [EditorBrowsable(EditorBrowsableState.Advanced)]
2315 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2316 public Region Region {
2322 if (IsHandleCreated) {
2323 XplatUI.SetClipRegion(Handle, value);
2325 clip_region = value;
2329 [EditorBrowsable(EditorBrowsableState.Advanced)]
2331 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2334 return this.bounds.X+this.bounds.Width;
2338 [AmbientValue(RightToLeft.Inherit)]
2340 [MWFCategory("Appearance")]
2341 public virtual RightToLeft RightToLeft {
2343 if (right_to_left == RightToLeft.Inherit) {
2345 return parent.RightToLeft;
2347 return RightToLeft.No; // default value
2349 return right_to_left;
2353 if (value != right_to_left) {
2354 right_to_left = value;
2355 OnRightToLeftChanged(EventArgs.Empty);
2360 [EditorBrowsable(EditorBrowsableState.Advanced)]
2361 public override ISite Site {
2369 AmbientProperties ap = (AmbientProperties) value.GetService (typeof (AmbientProperties));
2371 BackColor = ap.BackColor;
2372 ForeColor = ap.ForeColor;
2380 [MWFCategory("Layout")]
2383 return new Size(Width, Height);
2387 SetBounds(bounds.X, bounds.Y, value.Width, value.Height, BoundsSpecified.Size);
2392 [MergableProperty(false)]
2393 [MWFCategory("Behavior")]
2394 public int TabIndex {
2396 if (tab_index != -1) {
2403 if (tab_index != value) {
2405 OnTabIndexChanged(EventArgs.Empty);
2411 [DefaultValue(true)]
2412 [MWFCategory("Behavior")]
2413 public bool TabStop {
2419 if (tab_stop != value) {
2421 OnTabStopChanged(EventArgs.Empty);
2426 [Localizable(false)]
2428 [TypeConverter(typeof(StringConverter))]
2429 [DefaultValue(null)]
2430 [MWFCategory("Data")]
2437 control_tag = value;
2443 [BindableAttribute(true)]
2444 [MWFCategory("Appearance")]
2445 public virtual string Text {
2447 // Our implementation ignores ControlStyles.CacheText - we always cache
2452 if (value == null) {
2453 value = String.Empty;
2458 if (IsHandleCreated) {
2459 /* we need to call .SetWindowStyle here instead of just .Text
2460 because the presence/absence of Text (== "" or not) can cause
2461 other window style things to appear/disappear */
2462 XplatUI.SetWindowStyle(window.Handle, CreateParams);
2463 XplatUI.Text(Handle, text);
2465 OnTextChanged (EventArgs.Empty);
2470 [EditorBrowsable(EditorBrowsableState.Always)]
2472 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2475 return this.bounds.Y;
2479 SetBounds(bounds.X, value, bounds.Width, bounds.Height, BoundsSpecified.Y);
2483 [EditorBrowsable(EditorBrowsableState.Advanced)]
2485 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2486 public Control TopLevelControl {
2490 while (p.parent != null) {
2494 return p is Form ? p : null;
2499 [MWFCategory("Behavior")]
2500 public bool Visible {
2504 } else if (parent != null) {
2505 return parent.Visible;
2512 SetVisibleCore(value);
2516 [EditorBrowsable(EditorBrowsableState.Always)]
2518 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2521 return this.bounds.Width;
2525 SetBounds(bounds.X, bounds.Y, value, bounds.Height, BoundsSpecified.Width);
2529 [EditorBrowsable(EditorBrowsableState.Never)]
2531 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2532 public IWindowTarget WindowTarget {
2541 #endregion // Public Instance Properties
2543 #region Protected Instance Properties
2544 protected virtual CreateParams CreateParams {
2546 CreateParams create_params = new CreateParams();
2549 create_params.Caption = Text;
2552 create_params.Caption = text;
2556 create_params.X = Left;
2559 create_params.X = this.bounds.X;
2563 create_params.Y = Top;
2566 create_params.Y = this.bounds.Y;
2570 create_params.Width = Width;
2573 create_params.Width = this.bounds.Width;
2577 create_params.Height = Height;
2580 create_params.Height = this.bounds.Height;
2584 create_params.ClassName = XplatUI.DefaultClassName;
2585 create_params.ClassStyle = 0;
2586 create_params.ExStyle = 0;
2587 create_params.Param = 0;
2590 create_params.ExStyle |= (int)WindowExStyles.WS_EX_ACCEPTFILES;
2593 if ((parent!=null) && (parent.IsHandleCreated)) {
2594 create_params.Parent = parent.Handle;
2597 create_params.Style = (int)WindowStyles.WS_CHILD | (int)WindowStyles.WS_CLIPCHILDREN | (int)WindowStyles.WS_CLIPSIBLINGS;
2600 create_params.Style |= (int)WindowStyles.WS_VISIBLE;
2604 create_params.Style |= (int)WindowStyles.WS_DISABLED;
2607 switch (border_style) {
2608 case BorderStyle.FixedSingle:
2609 create_params.Style |= (int) WindowStyles.WS_BORDER;
2611 case BorderStyle.Fixed3D:
2612 create_params.ExStyle |= (int) WindowExStyles.WS_EX_CLIENTEDGE;
2616 return create_params;
2620 protected virtual ImeMode DefaultImeMode {
2622 return ImeMode.Inherit;
2627 protected virtual Padding DefaultMargin {
2628 get { return new Padding (3); }
2632 protected virtual Size DefaultSize {
2634 return new Size(0, 0);
2638 protected int FontHeight {
2648 protected bool RenderRightToLeft {
2650 return (this.right_to_left == RightToLeft.Yes);
2654 protected bool ResizeRedraw {
2656 return GetStyle(ControlStyles.ResizeRedraw);
2660 SetStyle(ControlStyles.ResizeRedraw, value);
2664 [EditorBrowsable(EditorBrowsableState.Advanced)]
2666 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2667 protected virtual bool ShowFocusCues {
2673 [EditorBrowsable(EditorBrowsableState.Advanced)]
2675 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2676 protected bool ShowKeyboardCues {
2681 #endregion // Protected Instance Properties
2683 #region Public Static Methods
2684 [EditorBrowsable(EditorBrowsableState.Advanced)]
2685 public static Control FromChildHandle(IntPtr handle) {
2686 return Control.ControlNativeWindow.ControlFromChildHandle (handle);
2689 [EditorBrowsable(EditorBrowsableState.Advanced)]
2690 public static Control FromHandle(IntPtr handle) {
2691 return Control.ControlNativeWindow.ControlFromHandle(handle);
2694 public static bool IsMnemonic(char charCode, string text) {
2697 amp = text.IndexOf('&');
2700 if (amp + 1 < text.Length) {
2701 if (text[amp + 1] != '&') {
2702 if (Char.ToUpper(charCode) == Char.ToUpper(text.ToCharArray(amp + 1, 1)[0])) {
2712 #region Protected Static Methods
2713 [EditorBrowsable(EditorBrowsableState.Advanced)]
2714 protected static bool ReflectMessage(IntPtr hWnd, ref Message m) {
2717 c = Control.FromHandle(hWnd);
2727 #region Public Instance Methods
2728 [EditorBrowsable(EditorBrowsableState.Advanced)]
2729 public IAsyncResult BeginInvoke(Delegate method) {
2730 object [] prms = null;
2731 if (method is EventHandler)
2732 prms = new object [] { this, EventArgs.Empty };
2733 return BeginInvokeInternal(method, prms, false);
2736 [EditorBrowsable(EditorBrowsableState.Advanced)]
2737 public IAsyncResult BeginInvoke (Delegate method, object[] args) {
2738 return BeginInvokeInternal (method, args, false);
2741 public void BringToFront() {
2742 if (parent != null) {
2743 parent.child_controls.SetChildIndex(this, 0);
2746 XplatUI.SetZOrder(Handle, IntPtr.Zero, false, false);
2750 public bool Contains(Control ctl) {
2751 while (ctl != null) {
2760 public void CreateControl() {
2762 throw new ObjectDisposedException(GetType().FullName.ToString());
2768 if (!IsHandleCreated) {
2776 Control [] controls = child_controls.GetAllControls ();
2777 for (int i=0; i<controls.Length; i++) {
2778 controls [i].CreateControl ();
2781 UpdateChildrenZOrder();
2783 if (binding_context == null) { // seem to be sent whenever it's null?
2784 OnBindingContextChanged(EventArgs.Empty);
2790 public Graphics CreateGraphics() {
2791 if (!IsHandleCreated) {
2792 this.CreateHandle();
2794 return Graphics.FromHwnd(this.window.Handle);
2797 public DragDropEffects DoDragDrop(object data, DragDropEffects allowedEffects) {
2798 return XplatUI.StartDrag(this.window.Handle, data, allowedEffects);
2801 [EditorBrowsable(EditorBrowsableState.Advanced)]
2802 public object EndInvoke (IAsyncResult async_result) {
2803 AsyncMethodResult result = (AsyncMethodResult) async_result;
2804 return result.EndInvoke ();
2807 public Form FindForm() {
2820 public bool Focus() {
2821 if (CanFocus && IsHandleCreated && !has_focus && !is_focusing) {
2824 is_focusing = false;
2829 public Control GetChildAtPoint(Point pt) {
2830 // Microsoft's version of this function doesn't seem to work, so I can't check
2831 // if we only consider children or also grandchildren, etc.
2832 // I'm gonna say 'children only'
2833 for (int i=0; i<child_controls.Count; i++) {
2834 if (child_controls[i].Bounds.Contains(pt)) {
2835 return child_controls[i];
2841 public IContainerControl GetContainerControl() {
2842 Control current = this;
2844 while (current!=null) {
2845 if ((current is IContainerControl) && ((current.control_style & ControlStyles.ContainerControl)!=0)) {
2846 return (IContainerControl)current;
2848 current = current.parent;
2853 public Control GetNextControl(Control ctl, bool forward) {
2855 if (!this.Contains(ctl)) {
2860 ctl = FindControlForward(this, ctl);
2863 ctl = FindControlBackward(this, ctl);
2873 public virtual Size GetPreferredSize (Size proposedSize) {
2874 return preferred_size;
2878 public void Hide() {
2879 this.Visible = false;
2882 public void Invalidate() {
2883 Invalidate(ClientRectangle, false);
2886 public void Invalidate(bool invalidateChildren) {
2887 Invalidate(ClientRectangle, invalidateChildren);
2890 public void Invalidate(System.Drawing.Rectangle rc) {
2891 Invalidate(rc, false);
2894 public void Invalidate(System.Drawing.Rectangle rc, bool invalidateChildren) {
2895 if (!IsHandleCreated || !Visible || rc.Width == 0 || rc.Height == 0) {
2899 NotifyInvalidate(rc);
2901 XplatUI.Invalidate(Handle, rc, false);
2903 if (invalidateChildren) {
2904 Control [] controls = child_controls.GetAllControls ();
2905 for (int i=0; i<controls.Length; i++)
2906 controls [i].Invalidate ();
2908 OnInvalidated(new InvalidateEventArgs(rc));
2911 public void Invalidate(System.Drawing.Region region) {
2912 Invalidate(region, false);
2915 public void Invalidate(System.Drawing.Region region, bool invalidateChildren) {
2916 RectangleF bounds = region.GetBounds (CreateGraphics ());
2917 Invalidate (new Rectangle ((int) bounds.X, (int) bounds.Y, (int) bounds.Width, (int) bounds.Height),
2918 invalidateChildren);
2921 public object Invoke (Delegate method) {
2922 object [] prms = null;
2923 if (method is EventHandler)
2924 prms = new object [] { this, EventArgs.Empty };
2926 return Invoke(method, prms);
2929 public object Invoke (Delegate method, object[] args) {
2930 if (!this.InvokeRequired) {
2931 return method.DynamicInvoke(args);
2934 IAsyncResult result = BeginInvoke (method, args);
2935 return EndInvoke(result);
2938 internal object InvokeInternal (Delegate method, bool disposing) {
2939 return InvokeInternal(method, null, disposing);
2942 internal object InvokeInternal (Delegate method, object[] args, bool disposing) {
2943 if (!this.InvokeRequired) {
2944 return method.DynamicInvoke(args);
2947 IAsyncResult result = BeginInvokeInternal (method, args, disposing);
2948 return EndInvoke(result);
2951 [EditorBrowsable(EditorBrowsableState.Advanced)]
2952 public void PerformLayout() {
2953 PerformLayout(null, null);
2956 private void SetImplicitBounds (int x, int y, int width, int height)
2958 Rectangle saved_bounds = explicit_bounds;
2959 SetBounds (x, y, width, height);
2960 explicit_bounds = saved_bounds;
2963 [EditorBrowsable(EditorBrowsableState.Advanced)]
2964 public void PerformLayout(Control affectedControl, string affectedProperty) {
2965 LayoutEventArgs levent = new LayoutEventArgs(affectedControl, affectedProperty);
2967 if (layout_suspended > 0) {
2968 layout_pending = true;
2972 layout_pending = false;
2974 // Prevent us from getting messed up
2977 // Perform all Dock and Anchor calculations
2981 this.layout_engine.Layout(this, levent);
2983 // This has been moved to Layout/DefaultLayout.cs for 2.0, please duplicate any changes/fixes there.
2985 AnchorStyles anchor;
2988 space = DisplayRectangle;
2990 // Deal with docking; go through in reverse, MS docs say that lowest Z-order is closest to edge
2991 Control [] controls = child_controls.GetAllControls ();
2992 for (int i = controls.Length - 1; i >= 0; i--) {
2993 child = controls [i];
2995 if (!child.Visible) {
2999 switch (child.Dock) {
3000 case DockStyle.None: {
3005 case DockStyle.Left: {
3006 child.SetImplicitBounds(space.Left, space.Y, child.Width, space.Height);
3007 space.X+=child.Width;
3008 space.Width-=child.Width;
3012 case DockStyle.Top: {
3013 child.SetImplicitBounds(space.Left, space.Y, space.Width, child.Height);
3014 space.Y+=child.Height;
3015 space.Height-=child.Height;
3019 case DockStyle.Right: {
3020 child.SetImplicitBounds(space.Right-child.Width, space.Y, child.Width, space.Height);
3021 space.Width-=child.Width;
3025 case DockStyle.Bottom: {
3026 child.SetImplicitBounds(space.Left, space.Bottom-child.Height, space.Width, child.Height);
3027 space.Height-=child.Height;
3033 for (int i = controls.Length - 1; i >= 0; i--) {
3036 //if (child.Visible && (child.Dock == DockStyle.Fill)) {
3037 if (child.Dock == DockStyle.Fill) {
3038 child.SetImplicitBounds(space.Left, space.Top, space.Width, space.Height);
3042 space = DisplayRectangle;
3044 for (int i=0; i < controls.Length; i++) {
3050 child = controls[i];
3052 // If the control is docked we don't need to do anything
3053 if (child.Dock != DockStyle.None) {
3057 anchor = child.Anchor;
3061 width = child.Width;
3062 height = child.Height;
3064 if ((anchor & AnchorStyles.Left) !=0 ) {
3065 if ((anchor & AnchorStyles.Right) != 0) {
3066 width = space.Width - child.dist_right - left;
3068 ; // Left anchored only, nothing to be done
3070 } else if ((anchor & AnchorStyles.Right) != 0) {
3071 left = space.Width - child.dist_right - width;
3073 // left+=diff_width/2 will introduce rounding errors (diff_width removed from svn after r51780)
3074 // This calculates from scratch every time:
3075 left = child.dist_left + (space.Width - (child.dist_left + width + child.dist_right)) / 2;
3078 if ((anchor & AnchorStyles.Top) !=0 ) {
3079 if ((anchor & AnchorStyles.Bottom) != 0) {
3080 height = space.Height - child.dist_bottom - top;
3082 ; // Top anchored only, nothing to be done
3084 } else if ((anchor & AnchorStyles.Bottom) != 0) {
3085 top = space.Height - child.dist_bottom - height;
3087 // top += diff_height/2 will introduce rounding errors (diff_height removed from after r51780)
3088 // This calculates from scratch every time:
3089 top = child.dist_top + (space.Height - (child.dist_top + height + child.dist_bottom)) / 2;
3101 child.SetImplicitBounds(left, top, width, height);
3105 // Let everyone know
3109 // Need to make sure we decremend layout_suspended
3115 public Point PointToClient (Point p) {
3119 XplatUI.ScreenToClient (Handle, ref x, ref y);
3121 return new Point (x, y);
3124 public Point PointToScreen(Point p) {
3128 XplatUI.ClientToScreen(Handle, ref x, ref y);
3130 return new Point(x, y);
3133 public virtual bool PreProcessMessage(ref Message msg) {
3134 return InternalPreProcessMessage (ref msg);
3137 internal virtual bool InternalPreProcessMessage (ref Message msg) {
3140 if ((msg.Msg == (int)Msg.WM_KEYDOWN) || (msg.Msg == (int)Msg.WM_SYSKEYDOWN)) {
3141 key_data = (Keys)msg.WParam.ToInt32() | XplatUI.State.ModifierKeys;
3143 if (!ProcessCmdKey(ref msg, key_data)) {
3144 if (IsInputKey(key_data)) {
3148 return ProcessDialogKey(key_data);
3152 } else if (msg.Msg == (int)Msg.WM_CHAR) {
3153 if (IsInputChar((char)msg.WParam)) {
3156 return ProcessDialogChar((char)msg.WParam);
3157 } else if (msg.Msg == (int)Msg.WM_SYSCHAR) {
3158 return ProcessDialogChar((char)msg.WParam);
3163 public Rectangle RectangleToClient(Rectangle r) {
3164 return new Rectangle(PointToClient(r.Location), r.Size);
3167 public Rectangle RectangleToScreen(Rectangle r) {
3168 return new Rectangle(PointToScreen(r.Location), r.Size);
3171 public virtual void Refresh() {
3172 if (IsHandleCreated == true) {
3174 XplatUI.UpdateWindow(window.Handle);
3176 Control [] controls = child_controls.GetAllControls ();
3177 for (int i=0; i < controls.Length; i++) {
3178 controls[i].Refresh();
3184 [EditorBrowsable(EditorBrowsableState.Never)]
3185 public virtual void ResetBackColor() {
3186 BackColor = Color.Empty;
3189 [EditorBrowsable(EditorBrowsableState.Never)]
3190 public void ResetBindings() {
3191 data_bindings.Clear();
3194 [EditorBrowsable(EditorBrowsableState.Never)]
3195 public virtual void ResetCursor() {
3199 [EditorBrowsable(EditorBrowsableState.Never)]
3200 public virtual void ResetFont() {
3204 [EditorBrowsable(EditorBrowsableState.Never)]
3205 public virtual void ResetForeColor() {
3206 foreground_color = Color.Empty;
3209 [EditorBrowsable(EditorBrowsableState.Never)]
3210 public void ResetImeMode() {
3211 ime_mode = DefaultImeMode;
3214 [EditorBrowsable(EditorBrowsableState.Never)]
3215 public virtual void ResetRightToLeft() {
3216 right_to_left = RightToLeft.Inherit;
3219 public virtual void ResetText() {
3220 text = String.Empty;
3223 public void ResumeLayout() {
3224 ResumeLayout (true);
3227 public void ResumeLayout(bool performLayout) {
3228 if (layout_suspended > 0) {
3232 if (layout_suspended == 0) {
3233 Control [] controls = child_controls.GetAllControls ();
3234 for (int i=0; i<controls.Length; i++) {
3235 controls [i].UpdateDistances ();
3238 if (performLayout && layout_pending) {
3244 public void Scale(float ratio) {
3245 ScaleCore(ratio, ratio);
3248 public void Scale(float dx, float dy) {
3253 public void Scale(SizeF factor) {
3254 ScaleCore(factor.Width, factor.Height);
3258 public void Select() {
3259 Select(false, false);
3263 private void printTree(Control c, string t) {
3264 foreach(Control i in c.child_controls) {
3265 Console.WriteLine("{2}{0}.TabIndex={1}", i, i.tab_index, t);
3266 printTree(i, t+"\t");
3270 public bool SelectNextControl(Control ctl, bool forward, bool tabStopOnly, bool nested, bool wrap) {
3274 Console.WriteLine("{0}", this.FindForm());
3275 printTree(this, "\t");
3278 if (!this.Contains(ctl) || (!nested && (ctl.parent != this))) {
3283 c = GetNextControl(c, forward);
3292 if (c.CanSelect && ((c.parent == this) || nested) && (c.tab_stop || !tabStopOnly)) {
3293 c.Select (true, true);
3296 } while (c != ctl); // If we wrap back to ourselves we stop
3301 public void SendToBack() {
3302 if (parent != null) {
3303 parent.child_controls.SetChildIndex(this, parent.child_controls.Count);
3307 public void SetBounds(int x, int y, int width, int height) {
3308 SetBounds(x, y, width, height, BoundsSpecified.All);
3311 public void SetBounds(int x, int y, int width, int height, BoundsSpecified specified) {
3312 if ((specified & BoundsSpecified.X) != BoundsSpecified.X) {
3316 if ((specified & BoundsSpecified.Y) != BoundsSpecified.Y) {
3320 if ((specified & BoundsSpecified.Width) != BoundsSpecified.Width) {
3324 if ((specified & BoundsSpecified.Height) != BoundsSpecified.Height) {
3328 SetBoundsCore(x, y, width, height, specified);
3329 if (parent != null) {
3330 parent.PerformLayout(this, "Bounds");
3334 public void Show() {
3336 this.CreateControl();
3342 public void SuspendLayout() {
3346 public void Update() {
3347 if (IsHandleCreated) {
3348 XplatUI.UpdateWindow(window.Handle);
3351 #endregion // Public Instance Methods
3353 #region Protected Instance Methods
3354 [EditorBrowsable(EditorBrowsableState.Advanced)]
3355 [MonoTODO("Implement this and tie it into Control.ControlAccessibleObject.NotifyClients")]
3356 protected void AccessibilityNotifyClients(AccessibleEvents accEvent, int childID) {
3357 throw new NotImplementedException();
3360 [EditorBrowsable(EditorBrowsableState.Advanced)]
3361 protected virtual AccessibleObject CreateAccessibilityInstance() {
3362 return new Control.ControlAccessibleObject(this);
3365 [EditorBrowsable(EditorBrowsableState.Advanced)]
3366 protected virtual ControlCollection CreateControlsInstance() {
3367 return new ControlCollection(this);
3370 [EditorBrowsable(EditorBrowsableState.Advanced)]
3371 protected virtual void CreateHandle() {
3373 throw new ObjectDisposedException(GetType().FullName.ToString());
3376 if (IsHandleCreated && !is_recreating) {
3380 window.CreateHandle(CreateParams);
3382 if (window.Handle != IntPtr.Zero) {
3383 lock (Control.controls) {
3384 if (!Control.controls.Contains(window.Handle)) {
3385 Control.controls.Add(this);
3389 creator_thread = Thread.CurrentThread;
3391 XplatUI.EnableWindow(window.Handle, is_enabled);
3392 XplatUI.SetVisible(window.Handle, is_visible, true);
3394 if (clip_region != null) {
3395 XplatUI.SetClipRegion(Handle, clip_region);
3398 // Set our handle with our parent
3399 if ((parent != null) && (parent.IsHandleCreated)) {
3400 XplatUI.SetParent(window.Handle, parent.Handle);
3403 // Set our handle as parent for our children
3404 Control [] children;
3406 children = child_controls.GetAllControls ();
3407 for (int i = 0; i < children.Length; i++ ) {
3408 if (!children[i].RecreatingHandle)
3409 XplatUI.SetParent(children[i].Handle, window.Handle);
3413 XplatUI.SetAllowDrop (Handle, allow_drop);
3415 // Find out where the window manager placed us
3416 if ((CreateParams.Style & (int)WindowStyles.WS_CHILD) != 0) {
3417 XplatUI.SetBorderStyle(window.Handle, (FormBorderStyle)border_style);
3421 OnHandleCreated(EventArgs.Empty);
3425 [EditorBrowsable(EditorBrowsableState.Advanced)]
3426 protected virtual void DefWndProc(ref Message m) {
3427 window.DefWndProc(ref m);
3430 [EditorBrowsable(EditorBrowsableState.Advanced)]
3431 protected virtual void DestroyHandle() {
3432 if (IsHandleCreated) {
3433 if (window != null) {
3434 window.DestroyHandle();
3439 protected bool GetStyle(ControlStyles flag) {
3440 return (control_style & flag) != 0;
3443 protected bool GetTopLevel() {
3447 [EditorBrowsable(EditorBrowsableState.Advanced)]
3448 protected virtual void InitLayout() {
3452 [EditorBrowsable(EditorBrowsableState.Advanced)]
3453 protected void InvokeGotFocus(Control toInvoke, EventArgs e) {
3454 toInvoke.OnGotFocus(e);
3457 [EditorBrowsable(EditorBrowsableState.Advanced)]
3458 protected void InvokeLostFocus(Control toInvoke, EventArgs e) {
3459 toInvoke.OnLostFocus(e);
3462 [EditorBrowsable(EditorBrowsableState.Advanced)]
3463 protected void InvokeOnClick(Control toInvoke, EventArgs e) {
3464 toInvoke.OnClick(e);
3467 protected void InvokePaint(Control toInvoke, PaintEventArgs e) {
3468 toInvoke.OnPaint(e);
3471 protected void InvokePaintBackground(Control toInvoke, PaintEventArgs e) {
3472 toInvoke.OnPaintBackground(e);
3475 protected virtual bool IsInputChar (char charCode) {
3479 protected virtual bool IsInputKey (Keys keyData) {
3480 // Doc says this one calls IsInputChar; not sure what to do with that
3484 [EditorBrowsable(EditorBrowsableState.Advanced)]
3485 protected virtual void NotifyInvalidate(Rectangle invalidatedArea) {
3489 protected virtual bool ProcessCmdKey(ref Message msg, Keys keyData) {
3490 if ((context_menu != null) && context_menu.ProcessCmdKey(ref msg, keyData)) {
3494 if (parent != null) {
3495 return parent.ProcessCmdKey(ref msg, keyData);
3501 protected virtual bool ProcessDialogChar(char charCode) {
3502 if (parent != null) {
3503 return parent.ProcessDialogChar (charCode);
3509 protected virtual bool ProcessDialogKey (Keys keyData) {
3510 if (parent != null) {
3511 return parent.ProcessDialogKey (keyData);
3517 protected virtual bool ProcessKeyEventArgs (ref Message msg)
3519 KeyEventArgs key_event;
3522 case (int)Msg.WM_SYSKEYDOWN:
3523 case (int)Msg.WM_KEYDOWN: {
3524 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
3525 OnKeyDown (key_event);
3526 return key_event.Handled;
3529 case (int)Msg.WM_SYSKEYUP:
3530 case (int)Msg.WM_KEYUP: {
3531 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
3532 OnKeyUp (key_event);
3533 return key_event.Handled;
3536 case (int)Msg.WM_SYSCHAR:
3537 case (int)Msg.WM_CHAR: {
3538 KeyPressEventArgs key_press_event;
3540 key_press_event = new KeyPressEventArgs((char)msg.WParam);
3541 OnKeyPress(key_press_event);
3543 msg.WParam = (IntPtr)key_press_event.KeyChar;
3545 return key_press_event.Handled;
3556 protected internal virtual bool ProcessKeyMessage(ref Message msg) {
3557 if (parent != null) {
3558 if (parent.ProcessKeyPreview(ref msg)) {
3563 return ProcessKeyEventArgs(ref msg);
3566 protected virtual bool ProcessKeyPreview(ref Message msg) {
3567 if (parent != null) {
3568 return parent.ProcessKeyPreview(ref msg);
3574 protected virtual bool ProcessMnemonic(char charCode) {
3579 [EditorBrowsable(EditorBrowsableState.Advanced)]
3580 protected void RaiseDragEvent(object key, DragEventArgs e) {
3584 [EditorBrowsable(EditorBrowsableState.Advanced)]
3585 protected void RaiseKeyEvent(object key, KeyEventArgs e) {
3589 [EditorBrowsable(EditorBrowsableState.Advanced)]
3590 protected void RaiseMouseEvent(object key, MouseEventArgs e) {
3594 [EditorBrowsable(EditorBrowsableState.Advanced)]
3595 protected void RaisePaintEvent(object key, PaintEventArgs e) {
3599 private void SetIsRecreating ()
3603 foreach (Control c in Controls.GetAllControls()) {
3604 c.SetIsRecreating ();
3608 [EditorBrowsable(EditorBrowsableState.Advanced)]
3609 protected void RecreateHandle() {
3611 Console.WriteLine("Recreating control {0}", XplatUI.Window(window.Handle));
3616 if (IsHandleCreated) {
3618 Console.WriteLine(" + handle is created, destroying it.");
3621 // WM_DESTROY will CreateHandle for us
3624 Console.WriteLine(" + handle is not created, creating it.");
3632 is_recreating = false;
3634 Console.WriteLine (" + new handle = {0:X}", Handle.ToInt32());
3640 [EditorBrowsable(EditorBrowsableState.Advanced)]
3641 protected void ResetMouseEventArgs() {
3645 [EditorBrowsable(EditorBrowsableState.Advanced)]
3646 protected ContentAlignment RtlTranslateAlignment(ContentAlignment align) {
3647 if (right_to_left == RightToLeft.No) {
3652 case ContentAlignment.TopLeft: {
3653 return ContentAlignment.TopRight;
3656 case ContentAlignment.TopRight: {
3657 return ContentAlignment.TopLeft;
3660 case ContentAlignment.MiddleLeft: {
3661 return ContentAlignment.MiddleRight;
3664 case ContentAlignment.MiddleRight: {
3665 return ContentAlignment.MiddleLeft;
3668 case ContentAlignment.BottomLeft: {
3669 return ContentAlignment.BottomRight;
3672 case ContentAlignment.BottomRight: {
3673 return ContentAlignment.BottomLeft;
3677 // if it's center it doesn't change
3683 [EditorBrowsable(EditorBrowsableState.Advanced)]
3684 protected HorizontalAlignment RtlTranslateAlignment(HorizontalAlignment align) {
3685 if ((right_to_left == RightToLeft.No) || (align == HorizontalAlignment.Center)) {
3689 if (align == HorizontalAlignment.Left) {
3690 return HorizontalAlignment.Right;
3693 // align must be HorizontalAlignment.Right
3694 return HorizontalAlignment.Left;
3697 [EditorBrowsable(EditorBrowsableState.Advanced)]
3698 protected LeftRightAlignment RtlTranslateAlignment(LeftRightAlignment align) {
3699 if (right_to_left == RightToLeft.No) {
3703 if (align == LeftRightAlignment.Left) {
3704 return LeftRightAlignment.Right;
3707 // align must be LeftRightAlignment.Right;
3708 return LeftRightAlignment.Left;
3711 [EditorBrowsable(EditorBrowsableState.Advanced)]
3712 protected ContentAlignment RtlTranslateContent(ContentAlignment align) {
3713 return RtlTranslateAlignment(align);
3716 [EditorBrowsable(EditorBrowsableState.Advanced)]
3717 protected HorizontalAlignment RtlTranslateHorizontal(HorizontalAlignment align) {
3718 return RtlTranslateAlignment(align);
3721 [EditorBrowsable(EditorBrowsableState.Advanced)]
3722 protected LeftRightAlignment RtlTranslateLeftRight(LeftRightAlignment align) {
3723 return RtlTranslateAlignment(align);
3726 [EditorBrowsable(EditorBrowsableState.Advanced)]
3727 protected virtual void ScaleCore(float dx, float dy) {
3733 location = new Point((int)(Left * dx), (int)(Top * dy));
3734 size = this.ClientSize;
3736 if (!GetStyle(ControlStyles.FixedWidth)) {
3737 size.Width = (int)(size.Width * dx);
3740 if (!GetStyle(ControlStyles.FixedHeight)) {
3741 size.Height = (int)(size.Height * dy);
3744 SetBounds(location.X, location.Y, size.Width, size.Height, BoundsSpecified.All);
3746 /* Now scale our children */
3747 Control [] controls = child_controls.GetAllControls ();
3748 for (int i=0; i < controls.Length; i++) {
3749 controls[i].Scale(dx, dy);
3755 protected virtual void Select(bool directed, bool forward) {
3756 IContainerControl container;
3758 container = GetContainerControl();
3759 if (container != null)
3760 container.ActiveControl = this;
3763 [EditorBrowsable(EditorBrowsableState.Advanced)]
3764 protected virtual void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
3765 // SetBoundsCore updates the Win32 control itself. UpdateBounds updates the controls variables and fires events, I'm guessing - pdb
3766 if (IsHandleCreated) {
3767 XplatUI.SetWindowPos(Handle, x, y, width, height);
3769 // Win32 automatically changes negative width/height to 0.
3770 // The control has already been sent a WM_WINDOWPOSCHANGED message and it has the correct
3771 // data, but it'll be overwritten when we call UpdateBounds unless we get the updated
3773 if (width < 0 || height < 0) {
3775 XplatUI.GetWindowPos(Handle, this is Form, out ix, out iy, out width, out height, out cw, out ch);
3779 UpdateBounds(x, y, width, height);
3784 [EditorBrowsable(EditorBrowsableState.Advanced)]
3785 protected virtual void SetClientSizeCore(int x, int y) {
3786 // Calculate the actual window size from the client size (it usually stays the same or grows)
3787 Rectangle ClientRect;
3788 Rectangle WindowRect;
3791 ClientRect = new Rectangle(0, 0, x, y);
3792 cp = this.CreateParams;
3794 if (XplatUI.CalculateWindowRect(ref ClientRect, cp.Style, cp.ExStyle, null, out WindowRect)==false) {
3798 SetBounds(bounds.X, bounds.Y, WindowRect.Width, WindowRect.Height, BoundsSpecified.Size);
3801 [EditorBrowsable(EditorBrowsableState.Advanced)]
3802 protected void SetStyle(ControlStyles flag, bool value) {
3804 control_style |= flag;
3806 control_style &= ~flag;
3810 protected void SetTopLevel(bool value) {
3811 if ((GetTopLevel() != value) && (parent != null)) {
3812 throw new Exception();
3816 if (value == true) {
3826 is_toplevel = value;
3829 protected virtual void SetVisibleCore(bool value) {
3830 if (value!=is_visible) {
3831 if (value && (window.Handle == IntPtr.Zero) || !is_created) {
3837 if (IsHandleCreated) {
3838 XplatUI.SetVisible(Handle, value, true);
3839 // Explicitly move Toplevel windows to where we want them;
3840 // apparently moving unmapped toplevel windows doesn't work
3841 if (is_visible && (this is Form)) {
3842 XplatUI.SetWindowPos(window.Handle, bounds.X, bounds.Y, bounds.Width, bounds.Height);
3846 OnVisibleChanged(EventArgs.Empty);
3848 if (value == false && parent != null && Focused) {
3851 // Need to start at parent, GetContainerControl might return ourselves if we're a container
3852 container = (Control)parent.GetContainerControl();
3853 if (container != null) {
3854 container.SelectNextControl(this, true, true, true, true);
3858 if (parent != null) {
3859 parent.PerformLayout(this, "visible");
3861 PerformLayout(this, "visible");
3866 [EditorBrowsable(EditorBrowsableState.Advanced)]
3867 protected void UpdateBounds() {
3875 if (!IsHandleCreated) {
3879 XplatUI.GetWindowPos(this.Handle, this is Form, out x, out y, out width, out height, out client_width, out client_height);
3881 UpdateBounds(x, y, width, height, client_width, client_height);
3884 [EditorBrowsable(EditorBrowsableState.Advanced)]
3885 protected void UpdateBounds(int x, int y, int width, int height) {
3889 // Calculate client rectangle
3890 rect = new Rectangle(0, 0, 0, 0);
3893 XplatUI.CalculateWindowRect(ref rect, cp.Style, cp.ExStyle, cp.menu, out rect);
3894 UpdateBounds(x, y, width, height, width - (rect.Right - rect.Left), height - (rect.Bottom - rect.Top));
3897 [EditorBrowsable(EditorBrowsableState.Advanced)]
3898 protected void UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) {
3899 // UpdateBounds only seems to set our sizes and fire events but not update the GUI window to match
3901 bool resized = false;
3903 // Needed to generate required notifications
3904 if ((this.bounds.X!=x) || (this.bounds.Y!=y)) {
3908 if ((this.Bounds.Width!=width) || (this.Bounds.Height!=height)) {
3915 bounds.Height=height;
3917 // Assume explicit bounds set. SetImplicitBounds will restore old bounds
3918 explicit_bounds = bounds;
3920 client_size.Width=clientWidth;
3921 client_size.Height=clientHeight;
3924 OnLocationChanged(EventArgs.Empty);
3928 OnSizeChanged(EventArgs.Empty);
3932 [EditorBrowsable(EditorBrowsableState.Advanced)]
3933 protected void UpdateStyles() {
3934 if (!IsHandleCreated) {
3938 XplatUI.SetWindowStyle(window.Handle, CreateParams);
3939 OnStyleChanged(EventArgs.Empty);
3942 private void UpdateZOrderOfChild(Control child) {
3943 if (IsHandleCreated && child.IsHandleCreated && (child.parent == this)) {
3946 index = child_controls.IndexOf(child);
3949 XplatUI.SetZOrder(child.Handle, child_controls[index - 1].Handle, false, false);
3951 XplatUI.SetZOrder(child.Handle, IntPtr.Zero, true, false);
3956 private void UpdateChildrenZOrder() {
3957 Control [] controls;
3959 if (!IsHandleCreated) {
3963 controls = child_controls.GetAllControls ();
3964 for (int i = 1; i < controls.Length; i++ ) {
3965 XplatUI.SetZOrder(controls[i].Handle, controls[i-1].Handle, false, false);
3969 [EditorBrowsable(EditorBrowsableState.Advanced)]
3970 protected void UpdateZOrder() {
3971 if (parent != null) {
3972 parent.UpdateZOrderOfChild(this);
3976 protected virtual void WndProc(ref Message m) {
3978 Console.WriteLine("Control {0} received message {1}", window.Handle == IntPtr.Zero ? this.Text : XplatUI.Window(window.Handle), (Msg)m.Msg);
3980 if ((this.control_style & ControlStyles.EnableNotifyMessage) != 0) {
3984 switch((Msg)m.Msg) {
3985 case Msg.WM_DESTROY: {
3986 OnHandleDestroyed(EventArgs.Empty);
3988 IntPtr handle = window.Handle;
3990 window.InvalidateHandle();
3992 if (is_recreating) {
3994 Console.WriteLine ("Creating handle for {0:X}", handle.ToInt32());
3998 Console.WriteLine (" + new handle = {0:X}", Handle.ToInt32());
4000 is_recreating = false;
4005 case Msg.WM_WINDOWPOSCHANGED: {
4007 Rectangle save_bounds = explicit_bounds;
4009 explicit_bounds = save_bounds;
4010 if (GetStyle(ControlStyles.ResizeRedraw)) {
4017 // Nice description of what should happen when handling WM_PAINT
4018 // can be found here: http://pluralsight.com/wiki/default.aspx/Craig/FlickerFreeControlDrawing.html
4019 // and here http://msdn.microsoft.com/msdnmag/issues/06/03/WindowsFormsPerformance/
4020 case Msg.WM_PAINT: {
4021 PaintEventArgs paint_event;
4023 paint_event = XplatUI.PaintEventStart(Handle, true);
4025 if (paint_event == null) {
4029 if (invalid_region != null && !invalid_region.IsVisible (paint_event.ClipRectangle)) {
4030 // Just blit the previous image
4031 paint_event.Graphics.DrawImage (ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle, GraphicsUnit.Pixel);
4032 XplatUI.PaintEventEnd(Handle, true);
4037 Graphics back_dc = null;
4038 Bitmap backbuffer = null;
4039 if (ThemeEngine.Current.DoubleBufferingSupported) {
4040 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
4041 backbuffer = ImageBuffer;
4042 back_dc = Graphics.FromImage (backbuffer);
4043 dc = paint_event.SetGraphics (back_dc);
4047 if (!GetStyle(ControlStyles.Opaque)) {
4048 OnPaintBackground(paint_event);
4051 // Button-derived controls choose to ignore their Opaque style, give them a chance to draw their background anyways
4052 OnPaintBackgroundInternal(paint_event);
4054 OnPaintInternal(paint_event);
4055 if (!paint_event.Handled) {
4056 OnPaint(paint_event);
4059 if (ThemeEngine.Current.DoubleBufferingSupported)
4060 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
4061 dc.DrawImage (ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle, GraphicsUnit.Pixel);
4062 paint_event.SetGraphics (dc);
4063 invalid_region.Exclude (paint_event.ClipRectangle);
4065 if (backbuffer != bmp_mem)
4066 backbuffer.Dispose();
4069 XplatUI.PaintEventEnd(Handle, true);
4074 case Msg.WM_ERASEBKGND: {
4075 // The DefWndProc will never have to handle this, we always paint the background in managed code
4076 // In theory this code would look at ControlStyles.AllPaintingInWmPaint and and call OnPaintBackground
4077 // here but it just makes things more complicated...
4078 m.Result = (IntPtr)1;
4082 case Msg.WM_LBUTTONUP: {
4085 me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Left,
4087 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4090 HandleClick(mouse_clicks, me);
4093 if (InternalCapture) {
4094 InternalCapture = false;
4097 if (mouse_clicks > 1) {
4103 case Msg.WM_LBUTTONDOWN: {
4105 Select (true, true);
4107 InternalCapture = true;
4108 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4109 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4115 case Msg.WM_LBUTTONDBLCLK: {
4116 InternalCapture = true;
4118 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4119 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4125 case Msg.WM_MBUTTONUP: {
4128 me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Middle,
4130 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4133 HandleClick(mouse_clicks, me);
4135 if (InternalCapture) {
4136 InternalCapture = false;
4138 if (mouse_clicks > 1) {
4144 case Msg.WM_MBUTTONDOWN: {
4145 InternalCapture = true;
4146 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4147 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4153 case Msg.WM_MBUTTONDBLCLK: {
4154 InternalCapture = true;
4156 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4157 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4162 case Msg.WM_RBUTTONUP: {
4166 pt = new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()));
4167 pt = PointToScreen(pt);
4169 XplatUI.SendMessage(m.HWnd, Msg.WM_CONTEXTMENU, m.HWnd, (IntPtr)(pt.X + (pt.Y << 16)));
4171 me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Right,
4173 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4176 HandleClick(mouse_clicks, me);
4179 if (InternalCapture) {
4180 InternalCapture = false;
4183 if (mouse_clicks > 1) {
4189 case Msg.WM_RBUTTONDOWN: {
4190 InternalCapture = true;
4191 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4192 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4197 case Msg.WM_RBUTTONDBLCLK: {
4198 InternalCapture = true;
4200 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4201 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4206 case Msg.WM_CONTEXTMENU: {
4207 if (context_menu != null) {
4210 pt = new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()));
4211 context_menu.Show(this, PointToClient(pt));
4219 case Msg.WM_MOUSEWHEEL: {
4221 OnMouseWheel (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4222 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4223 HighOrder(m.WParam.ToInt32())));
4228 case Msg.WM_MOUSEMOVE: {
4229 OnMouseMove (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4231 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4236 case Msg.WM_MOUSE_ENTER: {
4241 OnMouseEnter(EventArgs.Empty);
4245 case Msg.WM_MOUSE_LEAVE: {
4247 OnMouseLeave(EventArgs.Empty);
4251 case Msg.WM_MOUSEHOVER: {
4252 OnMouseHover(EventArgs.Empty);
4256 case Msg.WM_SYSKEYUP: {
4257 if (ProcessKeyMessage(ref m)) {
4258 m.Result = IntPtr.Zero;
4262 if ((m.WParam.ToInt32() & (int)Keys.KeyCode) == (int)Keys.Menu) {
4266 if (form != null && form.ActiveMenu != null) {
4267 form.ActiveMenu.ProcessCmdKey(ref m, (Keys)m.WParam.ToInt32());
4275 case Msg.WM_SYSKEYDOWN:
4276 case Msg.WM_KEYDOWN:
4278 case Msg.WM_SYSCHAR:
4280 if (ProcessKeyMessage(ref m)) {
4281 m.Result = IntPtr.Zero;
4290 if (m.LParam != IntPtr.Zero) {
4293 hi = new HELPINFO();
4295 hi = (HELPINFO) Marshal.PtrToStructure (m.LParam, typeof (HELPINFO));
4296 mouse_pos = new Point(hi.MousePos.x, hi.MousePos.y);
4298 mouse_pos = Control.MousePosition;
4300 OnHelpRequested(new HelpEventArgs(mouse_pos));
4301 m.Result = (IntPtr)1;
4305 case Msg.WM_KILLFOCUS: {
4306 this.has_focus = false;
4307 OnLostFocusInternal (EventArgs.Empty);
4311 case Msg.WM_SETFOCUS: {
4313 this.has_focus = true;
4314 OnGotFocusInternal (EventArgs.Empty);
4320 case Msg.WM_SYSCOLORCHANGE: {
4321 ThemeEngine.Current.ResetDefaults();
4322 OnSystemColorsChanged(EventArgs.Empty);
4327 case Msg.WM_SETCURSOR: {
4328 if ((cursor == null) || ((HitTest)(m.LParam.ToInt32() & 0xffff) != HitTest.HTCLIENT)) {
4333 XplatUI.SetCursor(window.Handle, cursor.handle);
4334 m.Result = (IntPtr)1;
4345 #endregion // Public Instance Methods
4347 #region OnXXX methods
4348 [EditorBrowsable(EditorBrowsableState.Advanced)]
4349 protected virtual void OnBackColorChanged(EventArgs e) {
4350 if (BackColorChanged!=null) BackColorChanged(this, e);
4351 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackColorChanged(e);
4354 [EditorBrowsable(EditorBrowsableState.Advanced)]
4355 protected virtual void OnBackgroundImageChanged(EventArgs e) {
4356 if (BackgroundImageChanged!=null) BackgroundImageChanged(this, e);
4357 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackgroundImageChanged(e);
4360 [EditorBrowsable(EditorBrowsableState.Advanced)]
4361 protected virtual void OnBindingContextChanged(EventArgs e) {
4362 CheckDataBindings ();
4363 if (BindingContextChanged!=null) {
4364 BindingContextChanged(this, e);
4366 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBindingContextChanged(e);
4369 [EditorBrowsable(EditorBrowsableState.Advanced)]
4370 protected virtual void OnCausesValidationChanged(EventArgs e) {
4371 if (CausesValidationChanged!=null) CausesValidationChanged(this, e);
4374 [EditorBrowsable(EditorBrowsableState.Advanced)]
4375 protected virtual void OnChangeUICues(UICuesEventArgs e) {
4376 if (ChangeUICues!=null) ChangeUICues(this, e);
4379 [EditorBrowsable(EditorBrowsableState.Advanced)]
4380 protected virtual void OnClick(EventArgs e) {
4381 if (Click!=null) Click(this, e);
4384 [EditorBrowsable(EditorBrowsableState.Advanced)]
4385 protected virtual void OnContextMenuChanged(EventArgs e) {
4386 if (ContextMenuChanged!=null) ContextMenuChanged(this, e);
4389 [EditorBrowsable(EditorBrowsableState.Advanced)]
4390 protected virtual void OnControlAdded(ControlEventArgs e) {
4391 if (ControlAdded!=null) ControlAdded(this, e);
4394 [EditorBrowsable(EditorBrowsableState.Advanced)]
4395 protected virtual void OnControlRemoved(ControlEventArgs e) {
4396 if (ControlRemoved!=null) ControlRemoved(this, e);
4399 [EditorBrowsable(EditorBrowsableState.Advanced)]
4400 protected virtual void OnCreateControl() {
4404 [EditorBrowsable(EditorBrowsableState.Advanced)]
4405 protected virtual void OnCursorChanged(EventArgs e) {
4406 if (CursorChanged!=null) CursorChanged(this, e);
4409 [EditorBrowsable(EditorBrowsableState.Advanced)]
4410 protected virtual void OnDockChanged(EventArgs e) {
4411 if (DockChanged!=null) DockChanged(this, e);
4414 [EditorBrowsable(EditorBrowsableState.Advanced)]
4415 protected virtual void OnDoubleClick(EventArgs e) {
4416 if (DoubleClick!=null) DoubleClick(this, e);
4419 [EditorBrowsable(EditorBrowsableState.Advanced)]
4420 protected virtual void OnDragDrop(DragEventArgs drgevent) {
4421 if (DragDrop!=null) DragDrop(this, drgevent);
4424 [EditorBrowsable(EditorBrowsableState.Advanced)]
4425 protected virtual void OnDragEnter(DragEventArgs drgevent) {
4426 if (DragEnter!=null) DragEnter(this, drgevent);
4429 [EditorBrowsable(EditorBrowsableState.Advanced)]
4430 protected virtual void OnDragLeave(EventArgs e) {
4431 if (DragLeave!=null) DragLeave(this, e);
4434 [EditorBrowsable(EditorBrowsableState.Advanced)]
4435 protected virtual void OnDragOver(DragEventArgs drgevent) {
4436 if (DragOver!=null) DragOver(this, drgevent);
4439 [EditorBrowsable(EditorBrowsableState.Advanced)]
4440 protected virtual void OnEnabledChanged(EventArgs e) {
4441 if (IsHandleCreated) {
4443 if (((Form)this).context == null) {
4444 XplatUI.EnableWindow(window.Handle, Enabled);
4447 XplatUI.EnableWindow(window.Handle, Enabled);
4452 if (EnabledChanged != null) {
4453 EnabledChanged(this, e);
4456 for (int i=0; i<child_controls.Count; i++) {
4457 child_controls[i].OnParentEnabledChanged(e);
4461 [EditorBrowsable(EditorBrowsableState.Advanced)]
4462 protected virtual void OnEnter(EventArgs e) {
4463 if (Enter!=null) Enter(this, e);
4466 [EditorBrowsable(EditorBrowsableState.Advanced)]
4467 protected virtual void OnFontChanged(EventArgs e) {
4468 if (FontChanged!=null) FontChanged(this, e);
4469 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentFontChanged(e);
4472 [EditorBrowsable(EditorBrowsableState.Advanced)]
4473 protected virtual void OnForeColorChanged(EventArgs e) {
4474 if (ForeColorChanged!=null) ForeColorChanged(this, e);
4475 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentForeColorChanged(e);
4478 [EditorBrowsable(EditorBrowsableState.Advanced)]
4479 protected virtual void OnGiveFeedback(GiveFeedbackEventArgs gfbevent) {
4480 if (GiveFeedback!=null) GiveFeedback(this, gfbevent);
4483 [EditorBrowsable(EditorBrowsableState.Advanced)]
4484 protected virtual void OnGotFocus(EventArgs e) {
4485 if (GotFocus!=null) GotFocus(this, e);
4488 [EditorBrowsable(EditorBrowsableState.Advanced)]
4489 protected virtual void OnHandleCreated(EventArgs e) {
4490 if (HandleCreated!=null) HandleCreated(this, e);
4493 [EditorBrowsable(EditorBrowsableState.Advanced)]
4494 protected virtual void OnHandleDestroyed(EventArgs e) {
4495 if (HandleDestroyed!=null) HandleDestroyed(this, e);
4498 [EditorBrowsable(EditorBrowsableState.Advanced)]
4499 protected virtual void OnHelpRequested(HelpEventArgs hevent) {
4500 if (HelpRequested!=null) HelpRequested(this, hevent);
4503 protected virtual void OnImeModeChanged(EventArgs e) {
4504 if (ImeModeChanged!=null) ImeModeChanged(this, e);
4507 [EditorBrowsable(EditorBrowsableState.Advanced)]
4508 protected virtual void OnInvalidated(InvalidateEventArgs e) {
4509 if (ThemeEngine.Current.DoubleBufferingSupported)
4510 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
4511 // should this block be here? seems like it
4512 // would be more at home in
4513 // NotifyInvalidated..
4514 if (e.InvalidRect == ClientRectangle) {
4515 ImageBufferNeedsRedraw ();
4518 // we need this Inflate call here so
4519 // that the border of the rectangle is
4520 // considered Visible (the
4521 // invalid_region.IsVisible call) in
4522 // the WM_PAINT handling below.
4523 Rectangle r = Rectangle.Inflate(e.InvalidRect, 1,1);
4524 if (invalid_region == null)
4525 invalid_region = new Region (r);
4527 invalid_region.Union (r);
4530 if (Invalidated!=null) Invalidated(this, e);
4533 [EditorBrowsable(EditorBrowsableState.Advanced)]
4534 protected virtual void OnKeyDown(KeyEventArgs e) {
4535 if (KeyDown!=null) KeyDown(this, e);
4538 [EditorBrowsable(EditorBrowsableState.Advanced)]
4539 protected virtual void OnKeyPress(KeyPressEventArgs e) {
4540 if (KeyPress!=null) KeyPress(this, e);
4543 [EditorBrowsable(EditorBrowsableState.Advanced)]
4544 protected virtual void OnKeyUp(KeyEventArgs e) {
4545 if (KeyUp!=null) KeyUp(this, e);
4548 [EditorBrowsable(EditorBrowsableState.Advanced)]
4549 protected virtual void OnLayout(LayoutEventArgs levent) {
4550 if (Layout!=null) Layout(this, levent);
4553 [EditorBrowsable(EditorBrowsableState.Advanced)]
4554 protected virtual void OnLeave(EventArgs e) {
4555 if (Leave!=null) Leave(this, e);
4558 [EditorBrowsable(EditorBrowsableState.Advanced)]
4559 protected virtual void OnLocationChanged(EventArgs e) {
4561 if (LocationChanged!=null) LocationChanged(this, e);
4564 [EditorBrowsable(EditorBrowsableState.Advanced)]
4565 protected virtual void OnLostFocus(EventArgs e) {
4566 if (LostFocus!=null) LostFocus(this, e);
4569 [EditorBrowsable(EditorBrowsableState.Advanced)]
4570 protected virtual void OnMouseDown(MouseEventArgs e) {
4571 if (MouseDown!=null) MouseDown(this, e);
4574 [EditorBrowsable(EditorBrowsableState.Advanced)]
4575 protected virtual void OnMouseEnter(EventArgs e) {
4576 if (MouseEnter!=null) MouseEnter(this, e);
4579 [EditorBrowsable(EditorBrowsableState.Advanced)]
4580 protected virtual void OnMouseHover(EventArgs e) {
4581 if (MouseHover!=null) MouseHover(this, e);
4584 [EditorBrowsable(EditorBrowsableState.Advanced)]
4585 protected virtual void OnMouseLeave(EventArgs e) {
4586 if (MouseLeave!=null) MouseLeave(this, e);
4589 [EditorBrowsable(EditorBrowsableState.Advanced)]
4590 protected virtual void OnMouseMove(MouseEventArgs e) {
4591 if (MouseMove!=null) MouseMove(this, e);
4594 [EditorBrowsable(EditorBrowsableState.Advanced)]
4595 protected virtual void OnMouseUp(MouseEventArgs e) {
4596 if (MouseUp!=null) MouseUp(this, e);
4599 [EditorBrowsable(EditorBrowsableState.Advanced)]
4600 protected virtual void OnMouseWheel(MouseEventArgs e) {
4601 if (MouseWheel!=null) MouseWheel(this, e);
4604 [EditorBrowsable(EditorBrowsableState.Advanced)]
4605 protected virtual void OnMove(EventArgs e) {
4606 if (Move!=null) Move(this, e);
4609 [EditorBrowsable(EditorBrowsableState.Advanced)]
4610 protected virtual void OnNotifyMessage(Message m) {
4614 [EditorBrowsable(EditorBrowsableState.Advanced)]
4615 protected virtual void OnPaint(PaintEventArgs e) {
4616 if (Paint!=null) Paint(this, e);
4619 internal virtual void OnPaintBackgroundInternal(PaintEventArgs e) {
4623 internal virtual void OnPaintInternal(PaintEventArgs e) {
4627 internal virtual void OnGotFocusInternal (EventArgs e)
4632 internal virtual void OnLostFocusInternal (EventArgs e)
4637 [EditorBrowsable(EditorBrowsableState.Advanced)]
4638 protected virtual void OnPaintBackground(PaintEventArgs pevent) {
4639 PaintControlBackground (pevent);
4642 [EditorBrowsable(EditorBrowsableState.Advanced)]
4643 protected virtual void OnParentBackColorChanged(EventArgs e) {
4644 if (background_color.IsEmpty && background_image==null) {
4646 OnBackColorChanged(e);
4650 [EditorBrowsable(EditorBrowsableState.Advanced)]
4651 protected virtual void OnParentBackgroundImageChanged(EventArgs e) {
4652 if (background_color.IsEmpty && background_image==null) {
4654 OnBackgroundImageChanged(e);
4658 [EditorBrowsable(EditorBrowsableState.Advanced)]
4659 protected virtual void OnParentBindingContextChanged(EventArgs e) {
4660 if (binding_context==null) {
4661 binding_context=Parent.binding_context;
4662 OnBindingContextChanged(e);
4666 [EditorBrowsable(EditorBrowsableState.Advanced)]
4667 protected virtual void OnParentChanged(EventArgs e) {
4668 if (ParentChanged!=null) ParentChanged(this, e);
4671 [EditorBrowsable(EditorBrowsableState.Advanced)]
4672 protected virtual void OnParentEnabledChanged(EventArgs e) {
4674 OnEnabledChanged(e);
4678 [EditorBrowsable(EditorBrowsableState.Advanced)]
4679 protected virtual void OnParentFontChanged(EventArgs e) {
4686 [EditorBrowsable(EditorBrowsableState.Advanced)]
4687 protected virtual void OnParentForeColorChanged(EventArgs e) {
4688 if (foreground_color.IsEmpty) {
4690 OnForeColorChanged(e);
4694 [EditorBrowsable(EditorBrowsableState.Advanced)]
4695 protected virtual void OnParentRightToLeftChanged(EventArgs e) {
4696 if (right_to_left==RightToLeft.Inherit) {
4698 OnRightToLeftChanged(e);
4702 [EditorBrowsable(EditorBrowsableState.Advanced)]
4703 protected virtual void OnParentVisibleChanged(EventArgs e) {
4705 OnVisibleChanged(e);
4709 [EditorBrowsable(EditorBrowsableState.Advanced)]
4710 protected virtual void OnQueryContinueDrag(QueryContinueDragEventArgs e) {
4711 if (QueryContinueDrag!=null) QueryContinueDrag(this, e);
4714 [EditorBrowsable(EditorBrowsableState.Advanced)]
4715 protected virtual void OnResize(EventArgs e) {
4716 if (Resize!=null) Resize(this, e);
4718 PerformLayout(this, "bounds");
4720 if (parent != null) {
4721 parent.PerformLayout();
4725 [EditorBrowsable(EditorBrowsableState.Advanced)]
4726 protected virtual void OnRightToLeftChanged(EventArgs e) {
4727 if (RightToLeftChanged!=null) RightToLeftChanged(this, e);
4728 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentRightToLeftChanged(e);
4731 [EditorBrowsable(EditorBrowsableState.Advanced)]
4732 protected virtual void OnSizeChanged(EventArgs e) {
4733 InvalidateBuffers ();
4735 if (SizeChanged!=null) SizeChanged(this, e);
4738 [EditorBrowsable(EditorBrowsableState.Advanced)]
4739 protected virtual void OnStyleChanged(EventArgs e) {
4740 if (StyleChanged!=null) StyleChanged(this, e);
4743 [EditorBrowsable(EditorBrowsableState.Advanced)]
4744 protected virtual void OnSystemColorsChanged(EventArgs e) {
4745 if (SystemColorsChanged!=null) SystemColorsChanged(this, e);
4748 [EditorBrowsable(EditorBrowsableState.Advanced)]
4749 protected virtual void OnTabIndexChanged(EventArgs e) {
4750 if (TabIndexChanged!=null) TabIndexChanged(this, e);
4753 [EditorBrowsable(EditorBrowsableState.Advanced)]
4754 protected virtual void OnTabStopChanged(EventArgs e) {
4755 if (TabStopChanged!=null) TabStopChanged(this, e);
4758 [EditorBrowsable(EditorBrowsableState.Advanced)]
4759 protected virtual void OnTextChanged(EventArgs e) {
4760 if (TextChanged!=null) TextChanged(this, e);
4763 [EditorBrowsable(EditorBrowsableState.Advanced)]
4764 protected virtual void OnValidated(EventArgs e) {
4765 if (Validated!=null) Validated(this, e);
4768 [EditorBrowsable(EditorBrowsableState.Advanced)]
4769 protected virtual void OnValidating(System.ComponentModel.CancelEventArgs e) {
4770 if (Validating!=null) Validating(this, e);
4773 [EditorBrowsable(EditorBrowsableState.Advanced)]
4774 protected virtual void OnVisibleChanged(EventArgs e) {
4775 if ((parent != null) && !Created && Visible) {
4782 if (VisibleChanged!=null) VisibleChanged(this, e);
4784 // We need to tell our kids
4785 for (int i=0; i<child_controls.Count; i++) {
4786 if (child_controls[i].Visible) {
4787 child_controls[i].OnParentVisibleChanged(e);
4791 #endregion // OnXXX methods
4794 public event EventHandler BackColorChanged;
4795 public event EventHandler BackgroundImageChanged;
4796 public event EventHandler BindingContextChanged;
4797 public event EventHandler CausesValidationChanged;
4798 public event UICuesEventHandler ChangeUICues;
4799 public event EventHandler Click;
4800 public event EventHandler ContextMenuChanged;
4802 [EditorBrowsable(EditorBrowsableState.Advanced)]
4804 public event ControlEventHandler ControlAdded;
4806 [EditorBrowsable(EditorBrowsableState.Advanced)]
4808 public event ControlEventHandler ControlRemoved;
4810 [MWFDescription("Fired when the cursor for the control has been changed"), MWFCategory("PropertyChanged")]
4811 public event EventHandler CursorChanged;
4812 public event EventHandler DockChanged;
4813 public event EventHandler DoubleClick;
4814 public event DragEventHandler DragDrop;
4815 public event DragEventHandler DragEnter;
4816 public event EventHandler DragLeave;
4817 public event DragEventHandler DragOver;
4818 public event EventHandler EnabledChanged;
4819 public event EventHandler Enter;
4820 public event EventHandler FontChanged;
4821 public event EventHandler ForeColorChanged;
4822 public event GiveFeedbackEventHandler GiveFeedback;
4824 [EditorBrowsable(EditorBrowsableState.Advanced)]
4826 public event EventHandler GotFocus;
4828 [EditorBrowsable(EditorBrowsableState.Advanced)]
4830 public event EventHandler HandleCreated;
4832 [EditorBrowsable(EditorBrowsableState.Advanced)]
4834 public event EventHandler HandleDestroyed;
4836 public event HelpEventHandler HelpRequested;
4837 public event EventHandler ImeModeChanged;
4839 [EditorBrowsable(EditorBrowsableState.Advanced)]
4841 public event InvalidateEventHandler Invalidated;
4843 public event KeyEventHandler KeyDown;
4844 public event KeyPressEventHandler KeyPress;
4845 public event KeyEventHandler KeyUp;
4846 public event LayoutEventHandler Layout;
4847 public event EventHandler Leave;
4848 public event EventHandler LocationChanged;
4850 [EditorBrowsable(EditorBrowsableState.Advanced)]
4852 public event EventHandler LostFocus;
4854 public event MouseEventHandler MouseDown;
4855 public event EventHandler MouseEnter;
4856 public event EventHandler MouseHover;
4857 public event EventHandler MouseLeave;
4858 public event MouseEventHandler MouseMove;
4859 public event MouseEventHandler MouseUp;
4861 [EditorBrowsable(EditorBrowsableState.Advanced)]
4863 public event MouseEventHandler MouseWheel;
4865 public event EventHandler Move;
4866 public event PaintEventHandler Paint;
4867 public event EventHandler ParentChanged;
4868 public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp;
4869 public event QueryContinueDragEventHandler QueryContinueDrag;
4870 public event EventHandler Resize;
4871 public event EventHandler RightToLeftChanged;
4872 public event EventHandler SizeChanged;
4873 public event EventHandler StyleChanged;
4874 public event EventHandler SystemColorsChanged;
4875 public event EventHandler TabIndexChanged;
4876 public event EventHandler TabStopChanged;
4877 public event EventHandler TextChanged;
4878 public event EventHandler Validated;
4879 public event CancelEventHandler Validating;
4880 public event EventHandler VisibleChanged;
4881 #endregion // Events