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 = new Layout.DefaultLayout();
729 control_style = ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint |
730 ControlStyles.Selectable | ControlStyles.StandardClick |
731 ControlStyles.StandardDoubleClick;
734 background_image = null;
738 window = new ControlNativeWindow(this);
739 child_controls = CreateControlsInstance();
740 client_size = new Size(DefaultSize.Width, DefaultSize.Height);
741 client_rect = new Rectangle(0, 0, DefaultSize.Width, DefaultSize.Height);
742 XplatUI.CalculateWindowRect(ref client_rect, CreateParams.Style, CreateParams.ExStyle, null, out bounds);
743 if ((CreateParams.Style & (int)WindowStyles.WS_CHILD) == 0) {
749 public Control(Control parent, string text) : this() {
754 public Control(Control parent, string text, int left, int top, int width, int height) : this() {
759 bounds.Height=height;
760 SetBounds(left, top, width, height, BoundsSpecified.All);
764 public Control(string text) : this() {
768 public Control(string text, int left, int top, int width, int height) : this() {
772 bounds.Height=height;
773 SetBounds(left, top, width, height, BoundsSpecified.All);
777 private delegate void RemoveDelegate(object c);
779 protected override void Dispose(bool disposing) {
780 if (!is_disposed && disposing) {
793 if (invalid_region!=null) {
794 invalid_region.Dispose();
797 if (this.InvokeRequired) {
798 if (Application.MessageLoop) {
799 this.BeginInvokeInternal(new MethodInvoker(DestroyHandle), null, true);
800 this.BeginInvokeInternal(new RemoveDelegate(controls.Remove), new object[] {this}, true);
804 lock (Control.controls) {
805 Control.controls.Remove(this);
810 if (parent != null) {
811 parent.Controls.Remove(this);
814 Control [] children = child_controls.GetAllControls ();
815 for (int i=0; i<children.Length; i++) {
816 children[i].parent = null; // Need to set to null or our child will try and remove from ourselves and crash
817 children[i].Dispose();
822 base.Dispose(disposing);
824 #endregion // Public Constructors
826 #region Internal Properties
827 internal BorderStyle InternalBorderStyle {
833 if (!Enum.IsDefined (typeof (BorderStyle), value))
834 throw new InvalidEnumArgumentException (string.Format("Enum argument value '{0}' is not valid for BorderStyle", value));
836 if (border_style != value) {
837 border_style = value;
839 if (IsHandleCreated) {
840 XplatUI.SetBorderStyle(window.Handle, (FormBorderStyle)border_style);
846 #endregion // Internal Properties
848 #region Private & Internal Methods
849 internal IAsyncResult BeginInvokeInternal (Delegate method, object [] args, bool disposing) {
850 AsyncMethodResult result;
851 AsyncMethodData data;
858 if (!p.IsHandleCreated) {
859 throw new InvalidOperationException("Cannot call Invoke or InvokeAsync on a control until the window handle is created");
865 result = new AsyncMethodResult ();
866 data = new AsyncMethodData ();
868 data.Handle = window.Handle;
869 data.Method = method;
871 data.Result = result;
874 if (!ExecutionContext.IsFlowSuppressed ()) {
875 data.Context = ExecutionContext.Capture ();
878 #if !MWF_ON_MSRUNTIME
879 if (SecurityManager.SecurityEnabled) {
880 data.Stack = CompressedStack.GetCompressedStack ();
885 XplatUI.SendAsyncMethod (data);
890 internal void PointToClient (ref int x, ref int y)
892 XplatUI.ScreenToClient (Handle, ref x, ref y);
895 internal void PointToScreen (ref int x, ref int y)
897 XplatUI.ClientToScreen (Handle, ref x, ref y);
900 internal bool IsRecreating {
902 return is_recreating;
906 internal Graphics DeviceContext {
908 if (dc_mem == null) {
909 CreateBuffers(this.Width, this.Height);
915 private void ImageBufferNeedsRedraw () {
916 if (invalid_region != null)
917 invalid_region.Dispose();
918 invalid_region = new Region (ClientRectangle);
921 private Bitmap ImageBuffer {
924 CreateBuffers(this.Width, this.Height);
930 internal void CreateBuffers (int width, int height) {
939 bmp_mem = new Bitmap (width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
940 dc_mem = Graphics.FromImage (bmp_mem);
941 ImageBufferNeedsRedraw ();
944 internal void InvalidateBuffers ()
946 if (dc_mem != null) {
952 ImageBufferNeedsRedraw ();
955 internal static void SetChildColor(Control parent) {
958 for (int i=0; i < parent.child_controls.Count; i++) {
959 child=parent.child_controls[i];
960 if (child.child_controls.Count>0) {
961 SetChildColor(child);
967 internal bool Select(Control control) {
968 IContainerControl container;
970 if (control == null) {
974 container = GetContainerControl();
975 if (container != null) {
976 container.ActiveControl = control;
978 if (control.IsHandleCreated) {
979 XplatUI.SetFocus(control.window.Handle);
984 internal void SelectChild (Control control)
986 if (control.IsHandleCreated)
987 XplatUI.SetFocus (control.window.Handle);
990 internal virtual void DoDefaultAction() {
991 // Only here to be overriden by our actual controls; this is needed by the accessibility class
994 internal static int LowOrder (int param) {
995 return ((int)(short)(param & 0xffff));
998 internal static int HighOrder (int param) {
999 return ((int)(short)(param >> 16));
1002 // This method exists so controls overriding OnPaintBackground can have default background painting done
1003 internal virtual void PaintControlBackground (PaintEventArgs pevent)
1005 if (GetStyle(ControlStyles.SupportsTransparentBackColor) && (BackColor.A != 0xff)) {
1006 if (parent != null) {
1007 PaintEventArgs parent_pe;
1008 GraphicsState state;
1010 parent_pe = new PaintEventArgs(pevent.Graphics, new Rectangle(pevent.ClipRectangle.X + Left, pevent.ClipRectangle.Y + Top, pevent.ClipRectangle.Width, pevent.ClipRectangle.Height));
1012 state = parent_pe.Graphics.Save();
1013 parent_pe.Graphics.TranslateTransform(-Left, -Top);
1014 parent.OnPaintBackground(parent_pe);
1015 parent_pe.Graphics.Restore(state);
1017 state = parent_pe.Graphics.Save();
1018 parent_pe.Graphics.TranslateTransform(-Left, -Top);
1019 parent.OnPaint(parent_pe);
1020 parent_pe.Graphics.Restore(state);
1021 parent_pe.SetGraphics(null);
1025 if ((clip_region != null) && (XplatUI.UserClipWontExposeParent)) {
1026 if (parent != null) {
1027 PaintEventArgs parent_pe;
1029 GraphicsState state;
1032 hwnd = Hwnd.ObjectFromHandle(Handle);
1035 parent_pe = new PaintEventArgs(pevent.Graphics, new Rectangle(pevent.ClipRectangle.X + Left, pevent.ClipRectangle.Y + Top, pevent.ClipRectangle.Width, pevent.ClipRectangle.Height));
1037 region = new Region ();
1039 region.Union(ClientRectangle);
1041 foreach (Rectangle r in hwnd.ClipRectangles) {
1045 state = parent_pe.Graphics.Save();
1046 parent_pe.Graphics.Clip = region;
1048 parent_pe.Graphics.TranslateTransform(-Left, -Top);
1049 parent.OnPaintBackground(parent_pe);
1050 parent_pe.Graphics.Restore(state);
1052 state = parent_pe.Graphics.Save();
1053 parent_pe.Graphics.Clip = region;
1055 parent_pe.Graphics.TranslateTransform(-Left, -Top);
1056 parent.OnPaint(parent_pe);
1057 parent_pe.Graphics.Restore(state);
1058 parent_pe.SetGraphics(null);
1060 region.Intersect(clip_region);
1061 pevent.Graphics.Clip = region;
1066 if (background_image == null) {
1067 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));
1071 DrawBackgroundImage (pevent.Graphics);
1074 void DrawBackgroundImage (Graphics g)
1076 using (TextureBrush b = new TextureBrush (background_image, WrapMode.Tile)) {
1077 g.FillRectangle (b, ClientRectangle);
1081 internal virtual void DndEnter (DragEventArgs e)
1088 internal virtual void DndOver (DragEventArgs e)
1095 internal virtual void DndDrop (DragEventArgs e)
1099 } catch (Exception exc) {
1100 Console.Error.WriteLine ("MWF: Exception while dropping:");
1101 Console.Error.WriteLine (exc);
1105 internal virtual void DndLeave (EventArgs e)
1112 internal virtual void DndFeedback(GiveFeedbackEventArgs e)
1119 internal virtual void DndContinueDrag(QueryContinueDragEventArgs e)
1122 OnQueryContinueDrag(e);
1126 internal static MouseButtons FromParamToMouseButtons (int param) {
1127 MouseButtons buttons = MouseButtons.None;
1129 if ((param & (int) MsgButtons.MK_LBUTTON) != 0)
1130 buttons |= MouseButtons.Left;
1132 if ((param & (int) MsgButtons.MK_MBUTTON) != 0)
1133 buttons |= MouseButtons.Middle;
1135 if ((param & (int) MsgButtons.MK_RBUTTON) != 0)
1136 buttons |= MouseButtons.Right;
1142 internal void FireEnter ()
1144 OnEnter (EventArgs.Empty);
1147 internal void FireLeave ()
1149 OnLeave (EventArgs.Empty);
1152 internal void FireValidating (CancelEventArgs ce)
1157 internal void FireValidated ()
1159 OnValidated (EventArgs.Empty);
1162 internal virtual bool ProcessControlMnemonic(char charCode) {
1163 return ProcessMnemonic(charCode);
1166 private static Control FindFlatForward(Control container, Control start) {
1172 end = container.child_controls.Count;
1174 if (start != null) {
1175 index = start.tab_index;
1181 for (int i = 0, pos = -1; i < end; i++) {
1182 if (start == container.child_controls[i]) {
1187 if (found == null) {
1188 if (container.child_controls[i].tab_index > index || (pos > -1 && pos < i && container.child_controls[i].tab_index == index)) {
1189 found = container.child_controls[i];
1191 } else if (found.tab_index > container.child_controls[i].tab_index) {
1192 if (container.child_controls[i].tab_index > index) {
1193 found = container.child_controls[i];
1200 private static Control FindControlForward(Control container, Control start) {
1205 if (start == null) {
1206 return FindFlatForward(container, start);
1209 if (start.child_controls != null && start.child_controls.Count > 0 &&
1210 (start == container || !((start is IContainerControl) && start.GetStyle(ControlStyles.ContainerControl)))) {
1211 return FindControlForward(start, null);
1214 while (start != container) {
1215 found = FindFlatForward(start.parent, start);
1216 if (found != null) {
1219 start = start.parent;
1225 private static Control FindFlatBackward(Control container, Control start) {
1231 end = container.child_controls.Count;
1233 if (start != null) {
1234 index = start.tab_index;
1236 // FIXME: Possible speed-up: Keep the highest taborder index in the container
1238 for (int i = 0; i < end; i++) {
1239 if (container.child_controls[i].tab_index > index) {
1240 index = container.child_controls[i].tab_index;
1248 for (int i = end - 1; i >= 0; i--) {
1249 if (start == container.child_controls[i]) {
1254 if (found == null || found.tab_index < container.child_controls[i].tab_index) {
1255 if (container.child_controls[i].tab_index < index || (hit && container.child_controls[i].tab_index == index))
1256 found = container.child_controls[i];
1263 private static Control FindControlBackward(Control container, Control start) {
1265 Control found = null;
1267 if (start == null) {
1268 found = FindFlatBackward(container, start);
1270 else if (start != container) {
1271 if (start.parent != null) {
1272 found = FindFlatBackward(start.parent, start);
1274 if (found == null) {
1275 if (start.parent != container)
1276 return start.parent;
1282 if (found == null || start.parent == null)
1285 while (found != null && (found == container || (!((found is IContainerControl) && found.GetStyle(ControlStyles.ContainerControl))) &&
1286 found.child_controls != null && found.child_controls.Count > 0)) {
1287 // while (ctl.child_controls != null && ctl.child_controls.Count > 0 &&
1288 // (ctl == this || (!((ctl is IContainerControl) && ctl.GetStyle(ControlStyles.ContainerControl))))) {
1289 found = FindFlatBackward(found, null);
1299 if (start != null) {
1300 found = FindFlatBackward(start.parent, start);
1301 if (found == null) {
1302 if (start.parent != container) {
1303 return start.parent;
1307 if (found == null) {
1308 found = FindFlatBackward(container, start);
1311 if (container != start) {
1312 while ((found != null) && (!found.Contains(start)) && found.child_controls != null && found.child_controls.Count > 0 && !(found is IContainerControl)) {// || found.GetStyle(ControlStyles.ContainerControl))) {
1313 found = FindControlBackward(found, null);
1314 if (found != null) {
1323 internal virtual void HandleClick(int clicks, MouseEventArgs me) {
1324 if (GetStyle(ControlStyles.StandardClick)) {
1325 if ((clicks > 1) && GetStyle(ControlStyles.StandardDoubleClick)) {
1327 OnDoubleClick(EventArgs.Empty);
1329 OnClick(EventArgs.Empty);
1339 private void CheckDataBindings ()
1341 if (data_bindings == null)
1344 BindingContext binding_context = BindingContext;
1345 foreach (Binding binding in data_bindings) {
1346 binding.Check (binding_context);
1351 private void ChangeParent(Control new_parent) {
1355 Color pre_fore_color;
1356 Color pre_back_color;
1357 RightToLeft pre_rtl;
1359 // These properties are inherited from our parent
1360 // Get them pre parent-change and then send events
1361 // if they are changed after we have our new parent
1362 pre_enabled = Enabled;
1363 pre_visible = Visible;
1365 pre_fore_color = ForeColor;
1366 pre_back_color = BackColor;
1367 pre_rtl = RightToLeft;
1368 // MS doesn't seem to send a CursorChangedEvent
1370 parent = new_parent;
1372 if (IsHandleCreated)
1373 XplatUI.SetParent(Handle,
1374 (new_parent == null || !new_parent.IsHandleCreated) ? IntPtr.Zero : new_parent.Handle);
1376 OnParentChanged(EventArgs.Empty);
1378 if (pre_enabled != Enabled) {
1379 OnEnabledChanged(EventArgs.Empty);
1382 if (pre_visible != Visible) {
1383 OnVisibleChanged(EventArgs.Empty);
1386 if (pre_font != Font) {
1387 OnFontChanged(EventArgs.Empty);
1390 if (pre_fore_color != ForeColor) {
1391 OnForeColorChanged(EventArgs.Empty);
1394 if (pre_back_color != BackColor) {
1395 OnBackColorChanged(EventArgs.Empty);
1398 if (pre_rtl != RightToLeft) {
1399 // MS sneaks a OnCreateControl and OnHandleCreated in here, I guess
1400 // because when RTL changes they have to recreate the win32 control
1401 // We don't really need that (until someone runs into compatibility issues)
1402 OnRightToLeftChanged(EventArgs.Empty);
1405 if ((new_parent != null) && new_parent.Created && !Created) {
1409 if ((binding_context == null) && Created) {
1410 OnBindingContextChanged(EventArgs.Empty);
1414 private void UpdateDistances() {
1415 if ((parent != null) && (parent.layout_suspended == 0)) {
1416 dist_left = bounds.X;
1417 dist_top = bounds.Y;
1418 dist_right = parent.ClientSize.Width - bounds.X - bounds.Width;
1419 dist_bottom = parent.ClientSize.Height - bounds.Y - bounds.Height;
1422 #endregion // Private & Internal Methods
1424 #region Public Static Properties
1425 public static Color DefaultBackColor {
1427 return ThemeEngine.Current.DefaultControlBackColor;
1431 public static Font DefaultFont {
1433 return ThemeEngine.Current.DefaultFont;
1437 public static Color DefaultForeColor {
1439 return ThemeEngine.Current.DefaultControlForeColor;
1443 public static Keys ModifierKeys {
1445 return XplatUI.State.ModifierKeys;
1449 public static MouseButtons MouseButtons {
1451 return XplatUI.State.MouseButtons;
1455 public static Point MousePosition {
1457 return Cursor.Position;
1463 public static bool CheckForIllegalCrossThreadCalls
1466 return verify_thread_handle;
1470 verify_thread_handle = value;
1474 #endregion // Public Static Properties
1476 #region Public Instance Properties
1477 [EditorBrowsable(EditorBrowsableState.Advanced)]
1479 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1480 public AccessibleObject AccessibilityObject {
1482 if (accessibility_object==null) {
1483 accessibility_object=CreateAccessibilityInstance();
1485 return accessibility_object;
1489 [EditorBrowsable(EditorBrowsableState.Advanced)]
1491 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1492 public string AccessibleDefaultActionDescription {
1494 return AccessibilityObject.default_action;
1498 AccessibilityObject.default_action=value;
1503 [DefaultValue(null)]
1504 [MWFCategory("Accessibility")]
1505 public string AccessibleDescription {
1507 return AccessibilityObject.description;
1511 AccessibilityObject.description=value;
1516 [DefaultValue(null)]
1517 [MWFCategory("Accessibility")]
1518 public string AccessibleName {
1520 return AccessibilityObject.Name;
1524 AccessibilityObject.Name=value;
1528 [DefaultValue(AccessibleRole.Default)]
1529 [MWFDescription("Role of the control"), MWFCategory("Accessibility")]
1530 public AccessibleRole AccessibleRole {
1532 return AccessibilityObject.role;
1536 AccessibilityObject.role=value;
1540 [DefaultValue(false)]
1541 [MWFCategory("Behavior")]
1542 public virtual bool AllowDrop {
1548 if (allow_drop == value)
1551 if (IsHandleCreated) {
1553 XplatUI.SetAllowDrop (Handle, value);
1559 [RefreshProperties(RefreshProperties.Repaint)]
1560 [DefaultValue(AnchorStyles.Top | AnchorStyles.Left)]
1561 [MWFCategory("Layout")]
1562 public virtual AnchorStyles Anchor {
1564 return anchor_style;
1570 if (parent != null) {
1571 parent.PerformLayout(this, "Parent");
1577 // XXX: Implement me!
1580 public virtual bool AutoSize {
1582 //Console.Error.WriteLine("Unimplemented: Control::get_AutoSize()");
1586 Console.Error.WriteLine("Unimplemented: Control::set_AutoSize(bool)");
1591 public virtual Size MaximumSize {
1593 return maximum_size;
1596 maximum_size = value;
1600 public virtual Size MinimumSize {
1602 return minimum_size;
1605 minimum_size = value;
1611 [MWFCategory("Appearance")]
1612 public virtual Color BackColor {
1614 if (background_color.IsEmpty) {
1616 Color pcolor = parent.BackColor;
1617 if (pcolor.A == 0xff || GetStyle(ControlStyles.SupportsTransparentBackColor))
1620 return DefaultBackColor;
1622 return background_color;
1626 if (!value.IsEmpty && (value.A != 0xff) && !GetStyle(ControlStyles.SupportsTransparentBackColor)) {
1627 throw new ArgumentException("Transparent background colors are not supported on this control");
1630 if (background_color != value) {
1631 background_color=value;
1632 SetChildColor(this);
1633 OnBackColorChanged(EventArgs.Empty);
1640 [DefaultValue(null)]
1641 [MWFCategory("Appearance")]
1642 public virtual Image BackgroundImage {
1644 return background_image;
1648 if (background_image!=value) {
1649 background_image=value;
1650 OnBackgroundImageChanged(EventArgs.Empty);
1655 [EditorBrowsable(EditorBrowsableState.Advanced)]
1657 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1658 public virtual BindingContext BindingContext {
1660 if (binding_context != null)
1661 return binding_context;
1664 binding_context = Parent.BindingContext;
1665 return binding_context;
1668 if (binding_context != value) {
1669 binding_context = value;
1670 OnBindingContextChanged(EventArgs.Empty);
1675 [EditorBrowsable(EditorBrowsableState.Advanced)]
1677 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1680 return bounds.Y+bounds.Height;
1684 [EditorBrowsable(EditorBrowsableState.Advanced)]
1686 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1687 public Rectangle Bounds {
1693 SetBounds(value.Left, value.Top, value.Width, value.Height, BoundsSpecified.All);
1697 [EditorBrowsable(EditorBrowsableState.Advanced)]
1699 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1700 public bool CanFocus {
1702 if (IsHandleCreated && Visible && Enabled) {
1709 [EditorBrowsable(EditorBrowsableState.Advanced)]
1711 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1712 public bool CanSelect {
1716 if (!GetStyle(ControlStyles.Selectable)) {
1721 while (parent != null) {
1722 if (!parent.is_visible || !parent.is_enabled) {
1726 parent = parent.parent;
1732 internal virtual bool InternalCapture {
1742 [EditorBrowsable(EditorBrowsableState.Advanced)]
1744 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1745 public bool Capture {
1747 return this.is_captured;
1751 if (this.IsHandleCreated && value != is_captured) {
1754 XplatUI.GrabWindow(this.window.Handle, IntPtr.Zero);
1756 XplatUI.UngrabWindow(this.window.Handle);
1757 is_captured = false;
1763 [DefaultValue(true)]
1764 [MWFCategory("Focus")]
1765 public bool CausesValidation {
1767 return this.causes_validation;
1771 if (this.causes_validation != value) {
1772 causes_validation = value;
1773 OnCausesValidationChanged(EventArgs.Empty);
1778 [EditorBrowsable(EditorBrowsableState.Advanced)]
1780 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1781 public Rectangle ClientRectangle {
1783 client_rect.Width = client_size.Width;
1784 client_rect.Height = client_size.Height;
1789 [EditorBrowsable(EditorBrowsableState.Advanced)]
1791 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1792 public Size ClientSize {
1795 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1796 return ((Form)this).form_parent_window.ClientSize;
1804 this.SetClientSizeCore(value.Width, value.Height);
1808 [EditorBrowsable(EditorBrowsableState.Advanced)]
1810 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1811 [DescriptionAttribute("ControlCompanyNameDescr")]
1812 public String CompanyName {
1814 return "Mono Project, Novell, Inc.";
1818 [EditorBrowsable(EditorBrowsableState.Advanced)]
1820 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1821 public bool ContainsFocus {
1823 IntPtr focused_window;
1825 focused_window = XplatUI.GetFocus();
1826 if (IsHandleCreated) {
1827 if (focused_window == Handle) {
1831 for (int i=0; i < child_controls.Count; i++) {
1832 if (child_controls[i].ContainsFocus) {
1841 [DefaultValue(null)]
1842 [MWFCategory("Behavior")]
1843 public virtual ContextMenu ContextMenu {
1845 return context_menu;
1849 if (context_menu != value) {
1850 context_menu = value;
1851 OnContextMenuChanged(EventArgs.Empty);
1857 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
1858 public ControlCollection Controls {
1860 return this.child_controls;
1864 [EditorBrowsable(EditorBrowsableState.Advanced)]
1866 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1867 public bool Created {
1869 return (!is_disposed && is_created);
1873 [AmbientValue(null)]
1874 [MWFCategory("Appearance")]
1875 public virtual Cursor Cursor {
1877 if (cursor != null) {
1881 if (parent != null) {
1882 return parent.Cursor;
1885 return Cursors.Default;
1889 if (cursor != value) {
1894 if (IsHandleCreated) {
1895 pt = Cursor.Position;
1897 if (bounds.Contains(pt) || Capture) {
1898 if (GetChildAtPoint(pt) == null) {
1899 if (cursor != null) {
1900 XplatUI.SetCursor(window.Handle, cursor.handle);
1902 if (parent != null) {
1903 XplatUI.SetCursor(window.Handle, parent.Cursor.handle);
1905 XplatUI.SetCursor(window.Handle, Cursors.Default.handle);
1912 OnCursorChanged(EventArgs.Empty);
1918 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
1919 [ParenthesizePropertyName(true)]
1920 [RefreshProperties(RefreshProperties.All)]
1921 [MWFCategory("Data")]
1922 public ControlBindingsCollection DataBindings {
1924 if (data_bindings == null)
1925 data_bindings = new ControlBindingsCollection (this);
1926 return data_bindings;
1930 [EditorBrowsable(EditorBrowsableState.Advanced)]
1932 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1933 public virtual Rectangle DisplayRectangle {
1935 return ClientRectangle;
1939 [EditorBrowsable(EditorBrowsableState.Advanced)]
1941 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1942 public bool Disposing {
1949 [RefreshProperties(RefreshProperties.Repaint)]
1950 [DefaultValue(DockStyle.None)]
1951 [MWFCategory("Layout")]
1952 public virtual DockStyle Dock {
1958 if (dock_style == value) {
1964 if (dock_style == DockStyle.None) {
1965 if (explicit_bounds == Rectangle.Empty)
1966 Bounds = new Rectangle (new Point (0, 0), DefaultSize);
1968 Bounds = explicit_bounds;
1971 if (parent != null) {
1972 parent.PerformLayout(this, "Parent");
1975 OnDockChanged(EventArgs.Empty);
1981 [MWFCategory("Behavior")]
1982 public bool Enabled {
1988 if (parent != null) {
1989 return parent.Enabled;
1997 bool old_value = is_enabled;
2000 if (old_value != value && !value && this.has_focus)
2001 SelectNextControl(this, true, true, true, true);
2003 OnEnabledChanged (EventArgs.Empty);
2007 [EditorBrowsable(EditorBrowsableState.Advanced)]
2009 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2010 public virtual bool Focused {
2012 return this.has_focus;
2017 [AmbientValue(null)]
2019 [MWFCategory("Appearance")]
2020 public virtual Font Font {
2026 if (Parent != null && Parent.Font != null) {
2033 [param:MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Font))]
2035 if (font != null && font.Equals (value)) {
2041 OnFontChanged (EventArgs.Empty);
2046 [MWFCategory("Appearance")]
2047 public virtual Color ForeColor {
2049 if (foreground_color.IsEmpty) {
2051 return parent.ForeColor;
2053 return DefaultForeColor;
2055 return foreground_color;
2059 if (foreground_color != value) {
2060 foreground_color=value;
2062 OnForeColorChanged(EventArgs.Empty);
2069 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2070 public IntPtr Handle { // IWin32Window
2073 if (verify_thread_handle) {
2074 if (this.InvokeRequired) {
2075 throw new InvalidOperationException("Cross-thread access of handle detected. Handle access only valid on thread that created the control");
2079 if (!IsHandleCreated) {
2082 return window.Handle;
2086 [EditorBrowsable(EditorBrowsableState.Advanced)]
2088 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2089 public bool HasChildren {
2091 if (this.child_controls.Count>0) {
2098 [EditorBrowsable(EditorBrowsableState.Always)]
2100 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2103 return this.bounds.Height;
2107 SetBounds(bounds.X, bounds.Y, bounds.Width, value, BoundsSpecified.Height);
2111 [AmbientValue(ImeMode.Inherit)]
2113 [MWFCategory("Behavior")]
2114 public ImeMode ImeMode {
2116 if (ime_mode == DefaultImeMode) {
2118 return parent.ImeMode;
2120 return ImeMode.NoControl; // default value
2126 if (ime_mode != value) {
2129 OnImeModeChanged(EventArgs.Empty);
2134 [EditorBrowsable(EditorBrowsableState.Advanced)]
2136 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2137 public bool InvokeRequired { // ISynchronizeInvoke
2139 if (creator_thread != null && creator_thread!=Thread.CurrentThread) {
2146 [EditorBrowsable(EditorBrowsableState.Advanced)]
2148 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2149 public bool IsAccessible {
2151 return is_accessible;
2155 is_accessible = value;
2159 [EditorBrowsable(EditorBrowsableState.Advanced)]
2161 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2162 public bool IsDisposed {
2164 return this.is_disposed;
2168 [EditorBrowsable(EditorBrowsableState.Advanced)]
2170 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2171 public bool IsHandleCreated {
2173 if ((window != null) && (window.Handle != IntPtr.Zero)) {
2174 Hwnd hwnd = Hwnd.ObjectFromHandle (window.Handle);
2175 if (hwnd != null && !hwnd.zombie)
2184 public virtual Layout.LayoutEngine LayoutEngine {
2185 get { return this.layout_engine; }
2189 [EditorBrowsable(EditorBrowsableState.Always)]
2191 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2194 return this.bounds.X;
2198 SetBounds(value, bounds.Y, bounds.Width, bounds.Height, BoundsSpecified.X);
2203 [MWFCategory("Layout")]
2204 public Point Location {
2206 return new Point(bounds.X, bounds.Y);
2210 SetBounds(value.X, value.Y, bounds.Width, bounds.Height, BoundsSpecified.Location);
2215 [Localizable (true)]
2216 public Padding Margin {
2217 get { return this.margin; }
2218 set { this.margin = value; }
2223 public string Name {
2235 public Padding Padding {
2247 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2248 public Control Parent {
2254 if (value == this) {
2255 throw new ArgumentException("A circular control reference has been made. A control cannot be owned or parented to itself.");
2258 if (parent!=value) {
2260 parent.Controls.Remove(this);
2265 value.Controls.Add(this);
2270 [EditorBrowsable(EditorBrowsableState.Advanced)]
2272 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2273 public string ProductName {
2275 Type t = typeof (AssemblyProductAttribute);
2276 Assembly assembly = GetType().Module.Assembly;
2277 object [] attrs = assembly.GetCustomAttributes (t, false);
2278 AssemblyProductAttribute a = null;
2279 // On MS we get a NullRefException if product attribute is not
2281 if (attrs != null && attrs.Length > 0)
2282 a = (AssemblyProductAttribute) attrs [0];
2287 [EditorBrowsable(EditorBrowsableState.Advanced)]
2289 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2290 public string ProductVersion {
2292 Type t = typeof (AssemblyVersionAttribute);
2293 Assembly assembly = GetType().Module.Assembly;
2294 object [] attrs = assembly.GetCustomAttributes (t, false);
2295 if (attrs == null || attrs.Length < 1)
2297 return ((AssemblyVersionAttribute)attrs [0]).Version;
2301 [EditorBrowsable(EditorBrowsableState.Advanced)]
2303 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2304 public bool RecreatingHandle {
2306 return is_recreating;
2310 [EditorBrowsable(EditorBrowsableState.Advanced)]
2312 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2313 public Region Region {
2319 if (IsHandleCreated) {
2320 XplatUI.SetClipRegion(Handle, value);
2322 clip_region = value;
2326 [EditorBrowsable(EditorBrowsableState.Advanced)]
2328 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2331 return this.bounds.X+this.bounds.Width;
2335 [AmbientValue(RightToLeft.Inherit)]
2337 [MWFCategory("Appearance")]
2338 public virtual RightToLeft RightToLeft {
2340 if (right_to_left == RightToLeft.Inherit) {
2342 return parent.RightToLeft;
2344 return RightToLeft.No; // default value
2346 return right_to_left;
2350 if (value != right_to_left) {
2351 right_to_left = value;
2352 OnRightToLeftChanged(EventArgs.Empty);
2357 [EditorBrowsable(EditorBrowsableState.Advanced)]
2358 public override ISite Site {
2366 AmbientProperties ap = (AmbientProperties) value.GetService (typeof (AmbientProperties));
2368 BackColor = ap.BackColor;
2369 ForeColor = ap.ForeColor;
2377 [MWFCategory("Layout")]
2380 return new Size(Width, Height);
2384 SetBounds(bounds.X, bounds.Y, value.Width, value.Height, BoundsSpecified.Size);
2389 [MergableProperty(false)]
2390 [MWFCategory("Behavior")]
2391 public int TabIndex {
2393 if (tab_index != -1) {
2400 if (tab_index != value) {
2402 OnTabIndexChanged(EventArgs.Empty);
2408 [DefaultValue(true)]
2409 [MWFCategory("Behavior")]
2410 public bool TabStop {
2416 if (tab_stop != value) {
2418 OnTabStopChanged(EventArgs.Empty);
2423 [Localizable(false)]
2425 [TypeConverter(typeof(StringConverter))]
2426 [DefaultValue(null)]
2427 [MWFCategory("Data")]
2434 control_tag = value;
2440 [BindableAttribute(true)]
2441 [MWFCategory("Appearance")]
2442 public virtual string Text {
2444 // Our implementation ignores ControlStyles.CacheText - we always cache
2449 if (value == null) {
2450 value = String.Empty;
2455 if (IsHandleCreated) {
2456 /* we need to call .SetWindowStyle here instead of just .Text
2457 because the presence/absence of Text (== "" or not) can cause
2458 other window style things to appear/disappear */
2459 XplatUI.SetWindowStyle(window.Handle, CreateParams);
2460 XplatUI.Text(Handle, text);
2462 OnTextChanged (EventArgs.Empty);
2467 [EditorBrowsable(EditorBrowsableState.Always)]
2469 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2472 return this.bounds.Y;
2476 SetBounds(bounds.X, value, bounds.Width, bounds.Height, BoundsSpecified.Y);
2480 [EditorBrowsable(EditorBrowsableState.Advanced)]
2482 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2483 public Control TopLevelControl {
2487 while (p.parent != null) {
2491 return p is Form ? p : null;
2496 [MWFCategory("Behavior")]
2497 public bool Visible {
2501 } else if (parent != null) {
2502 return parent.Visible;
2509 SetVisibleCore(value);
2513 [EditorBrowsable(EditorBrowsableState.Always)]
2515 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2518 return this.bounds.Width;
2522 SetBounds(bounds.X, bounds.Y, value, bounds.Height, BoundsSpecified.Width);
2526 [EditorBrowsable(EditorBrowsableState.Never)]
2528 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2529 public IWindowTarget WindowTarget {
2538 #endregion // Public Instance Properties
2540 #region Protected Instance Properties
2541 protected virtual CreateParams CreateParams {
2543 CreateParams create_params = new CreateParams();
2546 create_params.Caption = Text;
2549 create_params.Caption = text;
2553 create_params.X = Left;
2556 create_params.X = this.bounds.X;
2560 create_params.Y = Top;
2563 create_params.Y = this.bounds.Y;
2567 create_params.Width = Width;
2570 create_params.Width = this.bounds.Width;
2574 create_params.Height = Height;
2577 create_params.Height = this.bounds.Height;
2581 create_params.ClassName = XplatUI.DefaultClassName;
2582 create_params.ClassStyle = 0;
2583 create_params.ExStyle = 0;
2584 create_params.Param = 0;
2587 create_params.ExStyle |= (int)WindowExStyles.WS_EX_ACCEPTFILES;
2590 if ((parent!=null) && (parent.IsHandleCreated)) {
2591 create_params.Parent = parent.Handle;
2594 create_params.Style = (int)WindowStyles.WS_CHILD | (int)WindowStyles.WS_CLIPCHILDREN | (int)WindowStyles.WS_CLIPSIBLINGS;
2597 create_params.Style |= (int)WindowStyles.WS_VISIBLE;
2601 create_params.Style |= (int)WindowStyles.WS_DISABLED;
2604 switch (border_style) {
2605 case BorderStyle.FixedSingle:
2606 create_params.Style |= (int) WindowStyles.WS_BORDER;
2608 case BorderStyle.Fixed3D:
2609 create_params.ExStyle |= (int) WindowExStyles.WS_EX_CLIENTEDGE;
2613 return create_params;
2617 protected virtual ImeMode DefaultImeMode {
2619 return ImeMode.Inherit;
2624 protected virtual Padding DefaultMargin {
2625 get { return new Padding (3); }
2629 protected virtual Size DefaultSize {
2631 return new Size(0, 0);
2635 protected int FontHeight {
2645 protected bool RenderRightToLeft {
2647 return (this.right_to_left == RightToLeft.Yes);
2651 protected bool ResizeRedraw {
2653 return GetStyle(ControlStyles.ResizeRedraw);
2657 SetStyle(ControlStyles.ResizeRedraw, value);
2661 [EditorBrowsable(EditorBrowsableState.Advanced)]
2663 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2664 protected virtual bool ShowFocusCues {
2670 [EditorBrowsable(EditorBrowsableState.Advanced)]
2672 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2673 protected bool ShowKeyboardCues {
2678 #endregion // Protected Instance Properties
2680 #region Public Static Methods
2681 [EditorBrowsable(EditorBrowsableState.Advanced)]
2682 public static Control FromChildHandle(IntPtr handle) {
2683 return Control.ControlNativeWindow.ControlFromChildHandle (handle);
2686 [EditorBrowsable(EditorBrowsableState.Advanced)]
2687 public static Control FromHandle(IntPtr handle) {
2688 return Control.ControlNativeWindow.ControlFromHandle(handle);
2691 public static bool IsMnemonic(char charCode, string text) {
2694 amp = text.IndexOf('&');
2697 if (amp + 1 < text.Length) {
2698 if (text[amp + 1] != '&') {
2699 if (Char.ToUpper(charCode) == Char.ToUpper(text.ToCharArray(amp + 1, 1)[0])) {
2709 #region Protected Static Methods
2710 [EditorBrowsable(EditorBrowsableState.Advanced)]
2711 protected static bool ReflectMessage(IntPtr hWnd, ref Message m) {
2714 c = Control.FromHandle(hWnd);
2724 #region Public Instance Methods
2725 [EditorBrowsable(EditorBrowsableState.Advanced)]
2726 public IAsyncResult BeginInvoke(Delegate method) {
2727 object [] prms = null;
2728 if (method is EventHandler)
2729 prms = new object [] { this, EventArgs.Empty };
2730 return BeginInvokeInternal(method, prms, false);
2733 [EditorBrowsable(EditorBrowsableState.Advanced)]
2734 public IAsyncResult BeginInvoke (Delegate method, object[] args) {
2735 return BeginInvokeInternal (method, args, false);
2738 public void BringToFront() {
2739 if (parent != null) {
2740 parent.child_controls.SetChildIndex(this, 0);
2743 XplatUI.SetZOrder(Handle, IntPtr.Zero, false, false);
2747 public bool Contains(Control ctl) {
2748 while (ctl != null) {
2757 public void CreateControl() {
2759 throw new ObjectDisposedException(GetType().FullName.ToString());
2765 if (!IsHandleCreated) {
2773 Control [] controls = child_controls.GetAllControls ();
2774 for (int i=0; i<controls.Length; i++) {
2775 controls [i].CreateControl ();
2778 UpdateChildrenZOrder();
2780 if (binding_context == null) { // seem to be sent whenever it's null?
2781 OnBindingContextChanged(EventArgs.Empty);
2787 public Graphics CreateGraphics() {
2788 if (!IsHandleCreated) {
2789 this.CreateHandle();
2791 return Graphics.FromHwnd(this.window.Handle);
2794 public DragDropEffects DoDragDrop(object data, DragDropEffects allowedEffects) {
2795 return XplatUI.StartDrag(this.window.Handle, data, allowedEffects);
2798 [EditorBrowsable(EditorBrowsableState.Advanced)]
2799 public object EndInvoke (IAsyncResult async_result) {
2800 AsyncMethodResult result = (AsyncMethodResult) async_result;
2801 return result.EndInvoke ();
2804 public Form FindForm() {
2817 public bool Focus() {
2818 if (CanFocus && IsHandleCreated && !has_focus && !is_focusing) {
2821 is_focusing = false;
2826 public Control GetChildAtPoint(Point pt) {
2827 // Microsoft's version of this function doesn't seem to work, so I can't check
2828 // if we only consider children or also grandchildren, etc.
2829 // I'm gonna say 'children only'
2830 for (int i=0; i<child_controls.Count; i++) {
2831 if (child_controls[i].Bounds.Contains(pt)) {
2832 return child_controls[i];
2838 public IContainerControl GetContainerControl() {
2839 Control current = this;
2841 while (current!=null) {
2842 if ((current is IContainerControl) && ((current.control_style & ControlStyles.ContainerControl)!=0)) {
2843 return (IContainerControl)current;
2845 current = current.parent;
2850 public Control GetNextControl(Control ctl, bool forward) {
2852 if (!this.Contains(ctl)) {
2857 ctl = FindControlForward(this, ctl);
2860 ctl = FindControlBackward(this, ctl);
2870 public virtual Size GetPreferredSize (Size proposedSize) {
2871 return preferred_size;
2875 public void Hide() {
2876 this.Visible = false;
2879 public void Invalidate() {
2880 Invalidate(ClientRectangle, false);
2883 public void Invalidate(bool invalidateChildren) {
2884 Invalidate(ClientRectangle, invalidateChildren);
2887 public void Invalidate(System.Drawing.Rectangle rc) {
2888 Invalidate(rc, false);
2891 public void Invalidate(System.Drawing.Rectangle rc, bool invalidateChildren) {
2892 if (!IsHandleCreated || !Visible || rc.Width == 0 || rc.Height == 0) {
2896 NotifyInvalidate(rc);
2898 XplatUI.Invalidate(Handle, rc, false);
2900 if (invalidateChildren) {
2901 Control [] controls = child_controls.GetAllControls ();
2902 for (int i=0; i<controls.Length; i++)
2903 controls [i].Invalidate ();
2905 OnInvalidated(new InvalidateEventArgs(rc));
2908 public void Invalidate(System.Drawing.Region region) {
2909 Invalidate(region, false);
2912 public void Invalidate(System.Drawing.Region region, bool invalidateChildren) {
2913 RectangleF bounds = region.GetBounds (CreateGraphics ());
2914 Invalidate (new Rectangle ((int) bounds.X, (int) bounds.Y, (int) bounds.Width, (int) bounds.Height),
2915 invalidateChildren);
2918 public object Invoke (Delegate method) {
2919 object [] prms = null;
2920 if (method is EventHandler)
2921 prms = new object [] { this, EventArgs.Empty };
2923 return Invoke(method, prms);
2926 public object Invoke (Delegate method, object[] args) {
2927 if (!this.InvokeRequired) {
2928 return method.DynamicInvoke(args);
2931 IAsyncResult result = BeginInvoke (method, args);
2932 return EndInvoke(result);
2935 internal object InvokeInternal (Delegate method, bool disposing) {
2936 return InvokeInternal(method, null, disposing);
2939 internal object InvokeInternal (Delegate method, object[] args, bool disposing) {
2940 if (!this.InvokeRequired) {
2941 return method.DynamicInvoke(args);
2944 IAsyncResult result = BeginInvokeInternal (method, args, disposing);
2945 return EndInvoke(result);
2948 [EditorBrowsable(EditorBrowsableState.Advanced)]
2949 public void PerformLayout() {
2950 PerformLayout(null, null);
2953 private void SetImplicitBounds (int x, int y, int width, int height)
2955 Rectangle saved_bounds = explicit_bounds;
2956 SetBounds (x, y, width, height);
2957 explicit_bounds = saved_bounds;
2960 [EditorBrowsable(EditorBrowsableState.Advanced)]
2961 public void PerformLayout(Control affectedControl, string affectedProperty) {
2962 LayoutEventArgs levent = new LayoutEventArgs(affectedControl, affectedProperty);
2964 if (layout_suspended > 0) {
2965 layout_pending = true;
2969 layout_pending = false;
2971 // Prevent us from getting messed up
2974 // Perform all Dock and Anchor calculations
2978 this.layout_engine.Layout(this, levent);
2980 // This has been moved to Layout/DefaultLayout.cs for 2.0, please duplicate any changes/fixes there.
2982 AnchorStyles anchor;
2985 space = DisplayRectangle;
2987 // Deal with docking; go through in reverse, MS docs say that lowest Z-order is closest to edge
2988 Control [] controls = child_controls.GetAllControls ();
2989 for (int i = controls.Length - 1; i >= 0; i--) {
2990 child = controls [i];
2992 if (!child.Visible) {
2996 switch (child.Dock) {
2997 case DockStyle.None: {
3002 case DockStyle.Left: {
3003 child.SetImplicitBounds(space.Left, space.Y, child.Width, space.Height);
3004 space.X+=child.Width;
3005 space.Width-=child.Width;
3009 case DockStyle.Top: {
3010 child.SetImplicitBounds(space.Left, space.Y, space.Width, child.Height);
3011 space.Y+=child.Height;
3012 space.Height-=child.Height;
3016 case DockStyle.Right: {
3017 child.SetImplicitBounds(space.Right-child.Width, space.Y, child.Width, space.Height);
3018 space.Width-=child.Width;
3022 case DockStyle.Bottom: {
3023 child.SetImplicitBounds(space.Left, space.Bottom-child.Height, space.Width, child.Height);
3024 space.Height-=child.Height;
3030 for (int i = controls.Length - 1; i >= 0; i--) {
3033 //if (child.Visible && (child.Dock == DockStyle.Fill)) {
3034 if (child.Dock == DockStyle.Fill) {
3035 child.SetImplicitBounds(space.Left, space.Top, space.Width, space.Height);
3039 space = DisplayRectangle;
3041 for (int i=0; i < controls.Length; i++) {
3047 child = controls[i];
3049 // If the control is docked we don't need to do anything
3050 if (child.Dock != DockStyle.None) {
3054 anchor = child.Anchor;
3058 width = child.Width;
3059 height = child.Height;
3061 if ((anchor & AnchorStyles.Left) !=0 ) {
3062 if ((anchor & AnchorStyles.Right) != 0) {
3063 width = space.Width - child.dist_right - left;
3065 ; // Left anchored only, nothing to be done
3067 } else if ((anchor & AnchorStyles.Right) != 0) {
3068 left = space.Width - child.dist_right - width;
3070 // left+=diff_width/2 will introduce rounding errors (diff_width removed from svn after r51780)
3071 // This calculates from scratch every time:
3072 left = child.dist_left + (space.Width - (child.dist_left + width + child.dist_right)) / 2;
3075 if ((anchor & AnchorStyles.Top) !=0 ) {
3076 if ((anchor & AnchorStyles.Bottom) != 0) {
3077 height = space.Height - child.dist_bottom - top;
3079 ; // Top anchored only, nothing to be done
3081 } else if ((anchor & AnchorStyles.Bottom) != 0) {
3082 top = space.Height - child.dist_bottom - height;
3084 // top += diff_height/2 will introduce rounding errors (diff_height removed from after r51780)
3085 // This calculates from scratch every time:
3086 top = child.dist_top + (space.Height - (child.dist_top + height + child.dist_bottom)) / 2;
3098 child.SetImplicitBounds(left, top, width, height);
3102 // Let everyone know
3106 // Need to make sure we decremend layout_suspended
3112 public Point PointToClient (Point p) {
3116 XplatUI.ScreenToClient (Handle, ref x, ref y);
3118 return new Point (x, y);
3121 public Point PointToScreen(Point p) {
3125 XplatUI.ClientToScreen(Handle, ref x, ref y);
3127 return new Point(x, y);
3130 public virtual bool PreProcessMessage(ref Message msg) {
3131 return InternalPreProcessMessage (ref msg);
3134 internal virtual bool InternalPreProcessMessage (ref Message msg) {
3137 if ((msg.Msg == (int)Msg.WM_KEYDOWN) || (msg.Msg == (int)Msg.WM_SYSKEYDOWN)) {
3138 key_data = (Keys)msg.WParam.ToInt32() | XplatUI.State.ModifierKeys;
3140 if (!ProcessCmdKey(ref msg, key_data)) {
3141 if (IsInputKey(key_data)) {
3145 return ProcessDialogKey(key_data);
3149 } else if (msg.Msg == (int)Msg.WM_CHAR) {
3150 if (IsInputChar((char)msg.WParam)) {
3153 return ProcessDialogChar((char)msg.WParam);
3154 } else if (msg.Msg == (int)Msg.WM_SYSCHAR) {
3155 return ProcessDialogChar((char)msg.WParam);
3160 public Rectangle RectangleToClient(Rectangle r) {
3161 return new Rectangle(PointToClient(r.Location), r.Size);
3164 public Rectangle RectangleToScreen(Rectangle r) {
3165 return new Rectangle(PointToScreen(r.Location), r.Size);
3168 public virtual void Refresh() {
3169 if (IsHandleCreated == true) {
3171 XplatUI.UpdateWindow(window.Handle);
3173 Control [] controls = child_controls.GetAllControls ();
3174 for (int i=0; i < controls.Length; i++) {
3175 controls[i].Refresh();
3181 [EditorBrowsable(EditorBrowsableState.Never)]
3182 public virtual void ResetBackColor() {
3183 BackColor = Color.Empty;
3186 [EditorBrowsable(EditorBrowsableState.Never)]
3187 public void ResetBindings() {
3188 data_bindings.Clear();
3191 [EditorBrowsable(EditorBrowsableState.Never)]
3192 public virtual void ResetCursor() {
3196 [EditorBrowsable(EditorBrowsableState.Never)]
3197 public virtual void ResetFont() {
3201 [EditorBrowsable(EditorBrowsableState.Never)]
3202 public virtual void ResetForeColor() {
3203 foreground_color = Color.Empty;
3206 [EditorBrowsable(EditorBrowsableState.Never)]
3207 public void ResetImeMode() {
3208 ime_mode = DefaultImeMode;
3211 [EditorBrowsable(EditorBrowsableState.Never)]
3212 public virtual void ResetRightToLeft() {
3213 right_to_left = RightToLeft.Inherit;
3216 public virtual void ResetText() {
3217 text = String.Empty;
3220 public void ResumeLayout() {
3221 ResumeLayout (true);
3224 public void ResumeLayout(bool performLayout) {
3225 if (layout_suspended > 0) {
3229 if (layout_suspended == 0) {
3230 Control [] controls = child_controls.GetAllControls ();
3231 for (int i=0; i<controls.Length; i++) {
3232 controls [i].UpdateDistances ();
3235 if (performLayout && layout_pending) {
3241 public void Scale(float ratio) {
3242 ScaleCore(ratio, ratio);
3245 public void Scale(float dx, float dy) {
3250 public void Scale(SizeF factor) {
3251 ScaleCore(factor.Width, factor.Height);
3255 public void Select() {
3256 Select(false, false);
3260 private void printTree(Control c, string t) {
3261 foreach(Control i in c.child_controls) {
3262 Console.WriteLine("{2}{0}.TabIndex={1}", i, i.tab_index, t);
3263 printTree(i, t+"\t");
3267 public bool SelectNextControl(Control ctl, bool forward, bool tabStopOnly, bool nested, bool wrap) {
3271 Console.WriteLine("{0}", this.FindForm());
3272 printTree(this, "\t");
3275 if (!this.Contains(ctl) || (!nested && (ctl.parent != this))) {
3280 c = GetNextControl(c, forward);
3289 if (c.CanSelect && ((c.parent == this) || nested) && (c.tab_stop || !tabStopOnly)) {
3290 c.Select (true, true);
3293 } while (c != ctl); // If we wrap back to ourselves we stop
3298 public void SendToBack() {
3299 if (parent != null) {
3300 parent.child_controls.SetChildIndex(this, parent.child_controls.Count);
3304 public void SetBounds(int x, int y, int width, int height) {
3305 SetBounds(x, y, width, height, BoundsSpecified.All);
3308 public void SetBounds(int x, int y, int width, int height, BoundsSpecified specified) {
3309 if ((specified & BoundsSpecified.X) != BoundsSpecified.X) {
3313 if ((specified & BoundsSpecified.Y) != BoundsSpecified.Y) {
3317 if ((specified & BoundsSpecified.Width) != BoundsSpecified.Width) {
3321 if ((specified & BoundsSpecified.Height) != BoundsSpecified.Height) {
3325 SetBoundsCore(x, y, width, height, specified);
3326 if (parent != null) {
3327 parent.PerformLayout(this, "Bounds");
3331 public void Show() {
3333 this.CreateControl();
3339 public void SuspendLayout() {
3343 public void Update() {
3344 if (IsHandleCreated) {
3345 XplatUI.UpdateWindow(window.Handle);
3348 #endregion // Public Instance Methods
3350 #region Protected Instance Methods
3351 [EditorBrowsable(EditorBrowsableState.Advanced)]
3352 [MonoTODO("Implement this and tie it into Control.ControlAccessibleObject.NotifyClients")]
3353 protected void AccessibilityNotifyClients(AccessibleEvents accEvent, int childID) {
3354 throw new NotImplementedException();
3357 [EditorBrowsable(EditorBrowsableState.Advanced)]
3358 protected virtual AccessibleObject CreateAccessibilityInstance() {
3359 return new Control.ControlAccessibleObject(this);
3362 [EditorBrowsable(EditorBrowsableState.Advanced)]
3363 protected virtual ControlCollection CreateControlsInstance() {
3364 return new ControlCollection(this);
3367 [EditorBrowsable(EditorBrowsableState.Advanced)]
3368 protected virtual void CreateHandle() {
3370 throw new ObjectDisposedException(GetType().FullName.ToString());
3373 if (IsHandleCreated && !is_recreating) {
3377 window.CreateHandle(CreateParams);
3379 if (window.Handle != IntPtr.Zero) {
3380 lock (Control.controls) {
3381 if (!Control.controls.Contains(window.Handle)) {
3382 Control.controls.Add(this);
3386 creator_thread = Thread.CurrentThread;
3388 XplatUI.EnableWindow(window.Handle, is_enabled);
3389 XplatUI.SetVisible(window.Handle, is_visible, true);
3391 if (clip_region != null) {
3392 XplatUI.SetClipRegion(Handle, clip_region);
3395 // Set our handle with our parent
3396 if ((parent != null) && (parent.IsHandleCreated)) {
3397 XplatUI.SetParent(window.Handle, parent.Handle);
3400 // Set our handle as parent for our children
3401 Control [] children;
3403 children = child_controls.GetAllControls ();
3404 for (int i = 0; i < children.Length; i++ ) {
3405 if (!children[i].RecreatingHandle)
3406 XplatUI.SetParent(children[i].Handle, window.Handle);
3410 XplatUI.SetAllowDrop (Handle, allow_drop);
3412 // Find out where the window manager placed us
3413 if ((CreateParams.Style & (int)WindowStyles.WS_CHILD) != 0) {
3414 XplatUI.SetBorderStyle(window.Handle, (FormBorderStyle)border_style);
3418 OnHandleCreated(EventArgs.Empty);
3422 [EditorBrowsable(EditorBrowsableState.Advanced)]
3423 protected virtual void DefWndProc(ref Message m) {
3424 window.DefWndProc(ref m);
3427 [EditorBrowsable(EditorBrowsableState.Advanced)]
3428 protected virtual void DestroyHandle() {
3429 if (IsHandleCreated) {
3430 if (window != null) {
3431 window.DestroyHandle();
3436 protected bool GetStyle(ControlStyles flag) {
3437 return (control_style & flag) != 0;
3440 protected bool GetTopLevel() {
3444 [EditorBrowsable(EditorBrowsableState.Advanced)]
3445 protected virtual void InitLayout() {
3449 [EditorBrowsable(EditorBrowsableState.Advanced)]
3450 protected void InvokeGotFocus(Control toInvoke, EventArgs e) {
3451 toInvoke.OnGotFocus(e);
3454 [EditorBrowsable(EditorBrowsableState.Advanced)]
3455 protected void InvokeLostFocus(Control toInvoke, EventArgs e) {
3456 toInvoke.OnLostFocus(e);
3459 [EditorBrowsable(EditorBrowsableState.Advanced)]
3460 protected void InvokeOnClick(Control toInvoke, EventArgs e) {
3461 toInvoke.OnClick(e);
3464 protected void InvokePaint(Control toInvoke, PaintEventArgs e) {
3465 toInvoke.OnPaint(e);
3468 protected void InvokePaintBackground(Control toInvoke, PaintEventArgs e) {
3469 toInvoke.OnPaintBackground(e);
3472 protected virtual bool IsInputChar (char charCode) {
3476 protected virtual bool IsInputKey (Keys keyData) {
3477 // Doc says this one calls IsInputChar; not sure what to do with that
3481 [EditorBrowsable(EditorBrowsableState.Advanced)]
3482 protected virtual void NotifyInvalidate(Rectangle invalidatedArea) {
3486 protected virtual bool ProcessCmdKey(ref Message msg, Keys keyData) {
3487 if ((context_menu != null) && context_menu.ProcessCmdKey(ref msg, keyData)) {
3491 if (parent != null) {
3492 return parent.ProcessCmdKey(ref msg, keyData);
3498 protected virtual bool ProcessDialogChar(char charCode) {
3499 if (parent != null) {
3500 return parent.ProcessDialogChar (charCode);
3506 protected virtual bool ProcessDialogKey (Keys keyData) {
3507 if (parent != null) {
3508 return parent.ProcessDialogKey (keyData);
3514 protected virtual bool ProcessKeyEventArgs (ref Message msg)
3516 KeyEventArgs key_event;
3519 case (int)Msg.WM_SYSKEYDOWN:
3520 case (int)Msg.WM_KEYDOWN: {
3521 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
3522 OnKeyDown (key_event);
3523 return key_event.Handled;
3526 case (int)Msg.WM_SYSKEYUP:
3527 case (int)Msg.WM_KEYUP: {
3528 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
3529 OnKeyUp (key_event);
3530 return key_event.Handled;
3533 case (int)Msg.WM_SYSCHAR:
3534 case (int)Msg.WM_CHAR: {
3535 KeyPressEventArgs key_press_event;
3537 key_press_event = new KeyPressEventArgs((char)msg.WParam);
3538 OnKeyPress(key_press_event);
3540 msg.WParam = (IntPtr)key_press_event.KeyChar;
3542 return key_press_event.Handled;
3553 protected internal virtual bool ProcessKeyMessage(ref Message msg) {
3554 if (parent != null) {
3555 if (parent.ProcessKeyPreview(ref msg)) {
3560 return ProcessKeyEventArgs(ref msg);
3563 protected virtual bool ProcessKeyPreview(ref Message msg) {
3564 if (parent != null) {
3565 return parent.ProcessKeyPreview(ref msg);
3571 protected virtual bool ProcessMnemonic(char charCode) {
3576 [EditorBrowsable(EditorBrowsableState.Advanced)]
3577 protected void RaiseDragEvent(object key, DragEventArgs e) {
3581 [EditorBrowsable(EditorBrowsableState.Advanced)]
3582 protected void RaiseKeyEvent(object key, KeyEventArgs e) {
3586 [EditorBrowsable(EditorBrowsableState.Advanced)]
3587 protected void RaiseMouseEvent(object key, MouseEventArgs e) {
3591 [EditorBrowsable(EditorBrowsableState.Advanced)]
3592 protected void RaisePaintEvent(object key, PaintEventArgs e) {
3596 private void SetIsRecreating ()
3600 foreach (Control c in Controls.GetAllControls()) {
3601 c.SetIsRecreating ();
3605 [EditorBrowsable(EditorBrowsableState.Advanced)]
3606 protected void RecreateHandle() {
3608 Console.WriteLine("Recreating control {0}", XplatUI.Window(window.Handle));
3613 if (IsHandleCreated) {
3615 Console.WriteLine(" + handle is created, destroying it.");
3618 // WM_DESTROY will CreateHandle for us
3621 Console.WriteLine(" + handle is not created, creating it.");
3629 is_recreating = false;
3631 Console.WriteLine (" + new handle = {0:X}", Handle.ToInt32());
3637 [EditorBrowsable(EditorBrowsableState.Advanced)]
3638 protected void ResetMouseEventArgs() {
3642 [EditorBrowsable(EditorBrowsableState.Advanced)]
3643 protected ContentAlignment RtlTranslateAlignment(ContentAlignment align) {
3644 if (right_to_left == RightToLeft.No) {
3649 case ContentAlignment.TopLeft: {
3650 return ContentAlignment.TopRight;
3653 case ContentAlignment.TopRight: {
3654 return ContentAlignment.TopLeft;
3657 case ContentAlignment.MiddleLeft: {
3658 return ContentAlignment.MiddleRight;
3661 case ContentAlignment.MiddleRight: {
3662 return ContentAlignment.MiddleLeft;
3665 case ContentAlignment.BottomLeft: {
3666 return ContentAlignment.BottomRight;
3669 case ContentAlignment.BottomRight: {
3670 return ContentAlignment.BottomLeft;
3674 // if it's center it doesn't change
3680 [EditorBrowsable(EditorBrowsableState.Advanced)]
3681 protected HorizontalAlignment RtlTranslateAlignment(HorizontalAlignment align) {
3682 if ((right_to_left == RightToLeft.No) || (align == HorizontalAlignment.Center)) {
3686 if (align == HorizontalAlignment.Left) {
3687 return HorizontalAlignment.Right;
3690 // align must be HorizontalAlignment.Right
3691 return HorizontalAlignment.Left;
3694 [EditorBrowsable(EditorBrowsableState.Advanced)]
3695 protected LeftRightAlignment RtlTranslateAlignment(LeftRightAlignment align) {
3696 if (right_to_left == RightToLeft.No) {
3700 if (align == LeftRightAlignment.Left) {
3701 return LeftRightAlignment.Right;
3704 // align must be LeftRightAlignment.Right;
3705 return LeftRightAlignment.Left;
3708 [EditorBrowsable(EditorBrowsableState.Advanced)]
3709 protected ContentAlignment RtlTranslateContent(ContentAlignment align) {
3710 return RtlTranslateAlignment(align);
3713 [EditorBrowsable(EditorBrowsableState.Advanced)]
3714 protected HorizontalAlignment RtlTranslateHorizontal(HorizontalAlignment align) {
3715 return RtlTranslateAlignment(align);
3718 [EditorBrowsable(EditorBrowsableState.Advanced)]
3719 protected LeftRightAlignment RtlTranslateLeftRight(LeftRightAlignment align) {
3720 return RtlTranslateAlignment(align);
3723 [EditorBrowsable(EditorBrowsableState.Advanced)]
3724 protected virtual void ScaleCore(float dx, float dy) {
3730 location = new Point((int)(Left * dx), (int)(Top * dy));
3731 size = this.ClientSize;
3733 if (!GetStyle(ControlStyles.FixedWidth)) {
3734 size.Width = (int)(size.Width * dx);
3737 if (!GetStyle(ControlStyles.FixedHeight)) {
3738 size.Height = (int)(size.Height * dy);
3741 SetBounds(location.X, location.Y, size.Width, size.Height, BoundsSpecified.All);
3743 /* Now scale our children */
3744 Control [] controls = child_controls.GetAllControls ();
3745 for (int i=0; i < controls.Length; i++) {
3746 controls[i].Scale(dx, dy);
3752 protected virtual void Select(bool directed, bool forward) {
3753 IContainerControl container;
3755 container = GetContainerControl();
3756 if (container != null)
3757 container.ActiveControl = this;
3760 [EditorBrowsable(EditorBrowsableState.Advanced)]
3761 protected virtual void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
3762 // SetBoundsCore updates the Win32 control itself. UpdateBounds updates the controls variables and fires events, I'm guessing - pdb
3763 if (IsHandleCreated) {
3764 XplatUI.SetWindowPos(Handle, x, y, width, height);
3766 // Win32 automatically changes negative width/height to 0.
3767 // The control has already been sent a WM_WINDOWPOSCHANGED message and it has the correct
3768 // data, but it'll be overwritten when we call UpdateBounds unless we get the updated
3770 if (width < 0 || height < 0) {
3772 XplatUI.GetWindowPos(Handle, this is Form, out ix, out iy, out width, out height, out cw, out ch);
3776 UpdateBounds(x, y, width, height);
3781 [EditorBrowsable(EditorBrowsableState.Advanced)]
3782 protected virtual void SetClientSizeCore(int x, int y) {
3783 // Calculate the actual window size from the client size (it usually stays the same or grows)
3784 Rectangle ClientRect;
3785 Rectangle WindowRect;
3788 ClientRect = new Rectangle(0, 0, x, y);
3789 cp = this.CreateParams;
3791 if (XplatUI.CalculateWindowRect(ref ClientRect, cp.Style, cp.ExStyle, null, out WindowRect)==false) {
3795 SetBounds(bounds.X, bounds.Y, WindowRect.Width, WindowRect.Height, BoundsSpecified.Size);
3798 [EditorBrowsable(EditorBrowsableState.Advanced)]
3799 protected void SetStyle(ControlStyles flag, bool value) {
3801 control_style |= flag;
3803 control_style &= ~flag;
3807 protected void SetTopLevel(bool value) {
3808 if ((GetTopLevel() != value) && (parent != null)) {
3809 throw new Exception();
3813 if (value == true) {
3823 is_toplevel = value;
3826 protected virtual void SetVisibleCore(bool value) {
3827 if (value!=is_visible) {
3828 if (value && (window.Handle == IntPtr.Zero) || !is_created) {
3834 if (IsHandleCreated) {
3835 XplatUI.SetVisible(Handle, value, true);
3836 // Explicitly move Toplevel windows to where we want them;
3837 // apparently moving unmapped toplevel windows doesn't work
3838 if (is_visible && (this is Form)) {
3839 XplatUI.SetWindowPos(window.Handle, bounds.X, bounds.Y, bounds.Width, bounds.Height);
3843 OnVisibleChanged(EventArgs.Empty);
3845 if (value == false && parent != null && Focused) {
3848 // Need to start at parent, GetContainerControl might return ourselves if we're a container
3849 container = (Control)parent.GetContainerControl();
3850 if (container != null) {
3851 container.SelectNextControl(this, true, true, true, true);
3855 if (parent != null) {
3856 parent.PerformLayout(this, "visible");
3858 PerformLayout(this, "visible");
3863 [EditorBrowsable(EditorBrowsableState.Advanced)]
3864 protected void UpdateBounds() {
3872 if (!IsHandleCreated) {
3876 XplatUI.GetWindowPos(this.Handle, this is Form, out x, out y, out width, out height, out client_width, out client_height);
3878 UpdateBounds(x, y, width, height, client_width, client_height);
3881 [EditorBrowsable(EditorBrowsableState.Advanced)]
3882 protected void UpdateBounds(int x, int y, int width, int height) {
3886 // Calculate client rectangle
3887 rect = new Rectangle(0, 0, 0, 0);
3890 XplatUI.CalculateWindowRect(ref rect, cp.Style, cp.ExStyle, cp.menu, out rect);
3891 UpdateBounds(x, y, width, height, width - (rect.Right - rect.Left), height - (rect.Bottom - rect.Top));
3894 [EditorBrowsable(EditorBrowsableState.Advanced)]
3895 protected void UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) {
3896 // UpdateBounds only seems to set our sizes and fire events but not update the GUI window to match
3898 bool resized = false;
3900 // Needed to generate required notifications
3901 if ((this.bounds.X!=x) || (this.bounds.Y!=y)) {
3905 if ((this.Bounds.Width!=width) || (this.Bounds.Height!=height)) {
3912 bounds.Height=height;
3914 // Assume explicit bounds set. SetImplicitBounds will restore old bounds
3915 explicit_bounds = bounds;
3917 client_size.Width=clientWidth;
3918 client_size.Height=clientHeight;
3921 OnLocationChanged(EventArgs.Empty);
3925 OnSizeChanged(EventArgs.Empty);
3929 [EditorBrowsable(EditorBrowsableState.Advanced)]
3930 protected void UpdateStyles() {
3931 if (!IsHandleCreated) {
3935 XplatUI.SetWindowStyle(window.Handle, CreateParams);
3936 OnStyleChanged(EventArgs.Empty);
3939 private void UpdateZOrderOfChild(Control child) {
3940 if (IsHandleCreated && child.IsHandleCreated && (child.parent == this)) {
3943 index = child_controls.IndexOf(child);
3946 XplatUI.SetZOrder(child.Handle, child_controls[index - 1].Handle, false, false);
3948 XplatUI.SetZOrder(child.Handle, IntPtr.Zero, true, false);
3953 private void UpdateChildrenZOrder() {
3954 Control [] controls;
3956 if (!IsHandleCreated) {
3960 controls = child_controls.GetAllControls ();
3961 for (int i = 1; i < controls.Length; i++ ) {
3962 XplatUI.SetZOrder(controls[i].Handle, controls[i-1].Handle, false, false);
3966 [EditorBrowsable(EditorBrowsableState.Advanced)]
3967 protected void UpdateZOrder() {
3968 if (parent != null) {
3969 parent.UpdateZOrderOfChild(this);
3973 protected virtual void WndProc(ref Message m) {
3975 Console.WriteLine("Control {0} received message {1}", window.Handle == IntPtr.Zero ? this.Text : XplatUI.Window(window.Handle), (Msg)m.Msg);
3977 if ((this.control_style & ControlStyles.EnableNotifyMessage) != 0) {
3981 switch((Msg)m.Msg) {
3982 case Msg.WM_DESTROY: {
3983 OnHandleDestroyed(EventArgs.Empty);
3985 IntPtr handle = window.Handle;
3987 window.InvalidateHandle();
3989 if (is_recreating) {
3991 Console.WriteLine ("Creating handle for {0:X}", handle.ToInt32());
3995 Console.WriteLine (" + new handle = {0:X}", Handle.ToInt32());
3997 is_recreating = false;
4002 case Msg.WM_WINDOWPOSCHANGED: {
4004 Rectangle save_bounds = explicit_bounds;
4006 explicit_bounds = save_bounds;
4007 if (GetStyle(ControlStyles.ResizeRedraw)) {
4014 // Nice description of what should happen when handling WM_PAINT
4015 // can be found here: http://pluralsight.com/wiki/default.aspx/Craig/FlickerFreeControlDrawing.html
4016 // and here http://msdn.microsoft.com/msdnmag/issues/06/03/WindowsFormsPerformance/
4017 case Msg.WM_PAINT: {
4018 PaintEventArgs paint_event;
4020 paint_event = XplatUI.PaintEventStart(Handle, true);
4022 if (paint_event == null) {
4026 if (invalid_region != null && !invalid_region.IsVisible (paint_event.ClipRectangle)) {
4027 // Just blit the previous image
4028 paint_event.Graphics.DrawImage (ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle, GraphicsUnit.Pixel);
4029 XplatUI.PaintEventEnd(Handle, true);
4034 Graphics back_dc = null;
4035 Bitmap backbuffer = null;
4036 if (ThemeEngine.Current.DoubleBufferingSupported) {
4037 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
4038 backbuffer = ImageBuffer;
4039 back_dc = Graphics.FromImage (backbuffer);
4040 dc = paint_event.SetGraphics (back_dc);
4044 if (!GetStyle(ControlStyles.Opaque)) {
4045 OnPaintBackground(paint_event);
4048 // Button-derived controls choose to ignore their Opaque style, give them a chance to draw their background anyways
4049 OnPaintBackgroundInternal(paint_event);
4051 OnPaintInternal(paint_event);
4052 if (!paint_event.Handled) {
4053 OnPaint(paint_event);
4056 if (ThemeEngine.Current.DoubleBufferingSupported)
4057 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
4058 dc.DrawImage (ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle, GraphicsUnit.Pixel);
4059 paint_event.SetGraphics (dc);
4060 invalid_region.Exclude (paint_event.ClipRectangle);
4062 if (backbuffer != bmp_mem)
4063 backbuffer.Dispose();
4066 XplatUI.PaintEventEnd(Handle, true);
4071 case Msg.WM_ERASEBKGND: {
4072 // The DefWndProc will never have to handle this, we always paint the background in managed code
4073 // In theory this code would look at ControlStyles.AllPaintingInWmPaint and and call OnPaintBackground
4074 // here but it just makes things more complicated...
4075 m.Result = (IntPtr)1;
4079 case Msg.WM_LBUTTONUP: {
4082 me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Left,
4084 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4087 HandleClick(mouse_clicks, me);
4090 if (InternalCapture) {
4091 InternalCapture = false;
4094 if (mouse_clicks > 1) {
4100 case Msg.WM_LBUTTONDOWN: {
4102 Select (true, true);
4104 InternalCapture = true;
4105 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4106 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4112 case Msg.WM_LBUTTONDBLCLK: {
4113 InternalCapture = true;
4115 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4116 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4122 case Msg.WM_MBUTTONUP: {
4125 me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Middle,
4127 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4130 HandleClick(mouse_clicks, me);
4132 if (InternalCapture) {
4133 InternalCapture = false;
4135 if (mouse_clicks > 1) {
4141 case Msg.WM_MBUTTONDOWN: {
4142 InternalCapture = true;
4143 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4144 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4150 case Msg.WM_MBUTTONDBLCLK: {
4151 InternalCapture = true;
4153 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4154 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4159 case Msg.WM_RBUTTONUP: {
4163 pt = new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()));
4164 pt = PointToScreen(pt);
4166 XplatUI.SendMessage(m.HWnd, Msg.WM_CONTEXTMENU, m.HWnd, (IntPtr)(pt.X + (pt.Y << 16)));
4168 me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Right,
4170 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4173 HandleClick(mouse_clicks, me);
4176 if (InternalCapture) {
4177 InternalCapture = false;
4180 if (mouse_clicks > 1) {
4186 case Msg.WM_RBUTTONDOWN: {
4187 InternalCapture = true;
4188 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4189 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4194 case Msg.WM_RBUTTONDBLCLK: {
4195 InternalCapture = true;
4197 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4198 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4203 case Msg.WM_CONTEXTMENU: {
4204 if (context_menu != null) {
4207 pt = new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()));
4208 context_menu.Show(this, PointToClient(pt));
4216 case Msg.WM_MOUSEWHEEL: {
4218 OnMouseWheel (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4219 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4220 HighOrder(m.WParam.ToInt32())));
4225 case Msg.WM_MOUSEMOVE: {
4226 OnMouseMove (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4228 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4233 case Msg.WM_MOUSE_ENTER: {
4238 OnMouseEnter(EventArgs.Empty);
4242 case Msg.WM_MOUSE_LEAVE: {
4244 OnMouseLeave(EventArgs.Empty);
4248 case Msg.WM_MOUSEHOVER: {
4249 OnMouseHover(EventArgs.Empty);
4253 case Msg.WM_SYSKEYUP: {
4254 if (ProcessKeyMessage(ref m)) {
4255 m.Result = IntPtr.Zero;
4259 if ((m.WParam.ToInt32() & (int)Keys.KeyCode) == (int)Keys.Menu) {
4263 if (form != null && form.ActiveMenu != null) {
4264 form.ActiveMenu.ProcessCmdKey(ref m, (Keys)m.WParam.ToInt32());
4272 case Msg.WM_SYSKEYDOWN:
4273 case Msg.WM_KEYDOWN:
4275 case Msg.WM_SYSCHAR:
4277 if (ProcessKeyMessage(ref m)) {
4278 m.Result = IntPtr.Zero;
4287 if (m.LParam != IntPtr.Zero) {
4290 hi = new HELPINFO();
4292 hi = (HELPINFO) Marshal.PtrToStructure (m.LParam, typeof (HELPINFO));
4293 mouse_pos = new Point(hi.MousePos.x, hi.MousePos.y);
4295 mouse_pos = Control.MousePosition;
4297 OnHelpRequested(new HelpEventArgs(mouse_pos));
4298 m.Result = (IntPtr)1;
4302 case Msg.WM_KILLFOCUS: {
4303 this.has_focus = false;
4304 OnLostFocusInternal (EventArgs.Empty);
4308 case Msg.WM_SETFOCUS: {
4310 this.has_focus = true;
4311 OnGotFocusInternal (EventArgs.Empty);
4317 case Msg.WM_SYSCOLORCHANGE: {
4318 ThemeEngine.Current.ResetDefaults();
4319 OnSystemColorsChanged(EventArgs.Empty);
4324 case Msg.WM_SETCURSOR: {
4325 if ((cursor == null) || ((HitTest)(m.LParam.ToInt32() & 0xffff) != HitTest.HTCLIENT)) {
4330 XplatUI.SetCursor(window.Handle, cursor.handle);
4331 m.Result = (IntPtr)1;
4342 #endregion // Public Instance Methods
4344 #region OnXXX methods
4345 [EditorBrowsable(EditorBrowsableState.Advanced)]
4346 protected virtual void OnBackColorChanged(EventArgs e) {
4347 if (BackColorChanged!=null) BackColorChanged(this, e);
4348 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackColorChanged(e);
4351 [EditorBrowsable(EditorBrowsableState.Advanced)]
4352 protected virtual void OnBackgroundImageChanged(EventArgs e) {
4353 if (BackgroundImageChanged!=null) BackgroundImageChanged(this, e);
4354 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackgroundImageChanged(e);
4357 [EditorBrowsable(EditorBrowsableState.Advanced)]
4358 protected virtual void OnBindingContextChanged(EventArgs e) {
4359 CheckDataBindings ();
4360 if (BindingContextChanged!=null) {
4361 BindingContextChanged(this, e);
4363 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBindingContextChanged(e);
4366 [EditorBrowsable(EditorBrowsableState.Advanced)]
4367 protected virtual void OnCausesValidationChanged(EventArgs e) {
4368 if (CausesValidationChanged!=null) CausesValidationChanged(this, e);
4371 [EditorBrowsable(EditorBrowsableState.Advanced)]
4372 protected virtual void OnChangeUICues(UICuesEventArgs e) {
4373 if (ChangeUICues!=null) ChangeUICues(this, e);
4376 [EditorBrowsable(EditorBrowsableState.Advanced)]
4377 protected virtual void OnClick(EventArgs e) {
4378 if (Click!=null) Click(this, e);
4381 [EditorBrowsable(EditorBrowsableState.Advanced)]
4382 protected virtual void OnContextMenuChanged(EventArgs e) {
4383 if (ContextMenuChanged!=null) ContextMenuChanged(this, e);
4386 [EditorBrowsable(EditorBrowsableState.Advanced)]
4387 protected virtual void OnControlAdded(ControlEventArgs e) {
4388 if (ControlAdded!=null) ControlAdded(this, e);
4391 [EditorBrowsable(EditorBrowsableState.Advanced)]
4392 protected virtual void OnControlRemoved(ControlEventArgs e) {
4393 if (ControlRemoved!=null) ControlRemoved(this, e);
4396 [EditorBrowsable(EditorBrowsableState.Advanced)]
4397 protected virtual void OnCreateControl() {
4401 [EditorBrowsable(EditorBrowsableState.Advanced)]
4402 protected virtual void OnCursorChanged(EventArgs e) {
4403 if (CursorChanged!=null) CursorChanged(this, e);
4406 [EditorBrowsable(EditorBrowsableState.Advanced)]
4407 protected virtual void OnDockChanged(EventArgs e) {
4408 if (DockChanged!=null) DockChanged(this, e);
4411 [EditorBrowsable(EditorBrowsableState.Advanced)]
4412 protected virtual void OnDoubleClick(EventArgs e) {
4413 if (DoubleClick!=null) DoubleClick(this, e);
4416 [EditorBrowsable(EditorBrowsableState.Advanced)]
4417 protected virtual void OnDragDrop(DragEventArgs drgevent) {
4418 if (DragDrop!=null) DragDrop(this, drgevent);
4421 [EditorBrowsable(EditorBrowsableState.Advanced)]
4422 protected virtual void OnDragEnter(DragEventArgs drgevent) {
4423 if (DragEnter!=null) DragEnter(this, drgevent);
4426 [EditorBrowsable(EditorBrowsableState.Advanced)]
4427 protected virtual void OnDragLeave(EventArgs e) {
4428 if (DragLeave!=null) DragLeave(this, e);
4431 [EditorBrowsable(EditorBrowsableState.Advanced)]
4432 protected virtual void OnDragOver(DragEventArgs drgevent) {
4433 if (DragOver!=null) DragOver(this, drgevent);
4436 [EditorBrowsable(EditorBrowsableState.Advanced)]
4437 protected virtual void OnEnabledChanged(EventArgs e) {
4438 if (IsHandleCreated) {
4440 if (((Form)this).context == null) {
4441 XplatUI.EnableWindow(window.Handle, Enabled);
4444 XplatUI.EnableWindow(window.Handle, Enabled);
4449 if (EnabledChanged != null) {
4450 EnabledChanged(this, e);
4453 for (int i=0; i<child_controls.Count; i++) {
4454 child_controls[i].OnParentEnabledChanged(e);
4458 [EditorBrowsable(EditorBrowsableState.Advanced)]
4459 protected virtual void OnEnter(EventArgs e) {
4460 if (Enter!=null) Enter(this, e);
4463 [EditorBrowsable(EditorBrowsableState.Advanced)]
4464 protected virtual void OnFontChanged(EventArgs e) {
4465 if (FontChanged!=null) FontChanged(this, e);
4466 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentFontChanged(e);
4469 [EditorBrowsable(EditorBrowsableState.Advanced)]
4470 protected virtual void OnForeColorChanged(EventArgs e) {
4471 if (ForeColorChanged!=null) ForeColorChanged(this, e);
4472 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentForeColorChanged(e);
4475 [EditorBrowsable(EditorBrowsableState.Advanced)]
4476 protected virtual void OnGiveFeedback(GiveFeedbackEventArgs gfbevent) {
4477 if (GiveFeedback!=null) GiveFeedback(this, gfbevent);
4480 [EditorBrowsable(EditorBrowsableState.Advanced)]
4481 protected virtual void OnGotFocus(EventArgs e) {
4482 if (GotFocus!=null) GotFocus(this, e);
4485 [EditorBrowsable(EditorBrowsableState.Advanced)]
4486 protected virtual void OnHandleCreated(EventArgs e) {
4487 if (HandleCreated!=null) HandleCreated(this, e);
4490 [EditorBrowsable(EditorBrowsableState.Advanced)]
4491 protected virtual void OnHandleDestroyed(EventArgs e) {
4492 if (HandleDestroyed!=null) HandleDestroyed(this, e);
4495 [EditorBrowsable(EditorBrowsableState.Advanced)]
4496 protected virtual void OnHelpRequested(HelpEventArgs hevent) {
4497 if (HelpRequested!=null) HelpRequested(this, hevent);
4500 protected virtual void OnImeModeChanged(EventArgs e) {
4501 if (ImeModeChanged!=null) ImeModeChanged(this, e);
4504 [EditorBrowsable(EditorBrowsableState.Advanced)]
4505 protected virtual void OnInvalidated(InvalidateEventArgs e) {
4506 if (ThemeEngine.Current.DoubleBufferingSupported)
4507 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
4508 // should this block be here? seems like it
4509 // would be more at home in
4510 // NotifyInvalidated..
4511 if (e.InvalidRect == ClientRectangle) {
4512 ImageBufferNeedsRedraw ();
4515 // we need this Inflate call here so
4516 // that the border of the rectangle is
4517 // considered Visible (the
4518 // invalid_region.IsVisible call) in
4519 // the WM_PAINT handling below.
4520 Rectangle r = Rectangle.Inflate(e.InvalidRect, 1,1);
4521 if (invalid_region == null)
4522 invalid_region = new Region (r);
4524 invalid_region.Union (r);
4527 if (Invalidated!=null) Invalidated(this, e);
4530 [EditorBrowsable(EditorBrowsableState.Advanced)]
4531 protected virtual void OnKeyDown(KeyEventArgs e) {
4532 if (KeyDown!=null) KeyDown(this, e);
4535 [EditorBrowsable(EditorBrowsableState.Advanced)]
4536 protected virtual void OnKeyPress(KeyPressEventArgs e) {
4537 if (KeyPress!=null) KeyPress(this, e);
4540 [EditorBrowsable(EditorBrowsableState.Advanced)]
4541 protected virtual void OnKeyUp(KeyEventArgs e) {
4542 if (KeyUp!=null) KeyUp(this, e);
4545 [EditorBrowsable(EditorBrowsableState.Advanced)]
4546 protected virtual void OnLayout(LayoutEventArgs levent) {
4547 if (Layout!=null) Layout(this, levent);
4550 [EditorBrowsable(EditorBrowsableState.Advanced)]
4551 protected virtual void OnLeave(EventArgs e) {
4552 if (Leave!=null) Leave(this, e);
4555 [EditorBrowsable(EditorBrowsableState.Advanced)]
4556 protected virtual void OnLocationChanged(EventArgs e) {
4558 if (LocationChanged!=null) LocationChanged(this, e);
4561 [EditorBrowsable(EditorBrowsableState.Advanced)]
4562 protected virtual void OnLostFocus(EventArgs e) {
4563 if (LostFocus!=null) LostFocus(this, e);
4566 [EditorBrowsable(EditorBrowsableState.Advanced)]
4567 protected virtual void OnMouseDown(MouseEventArgs e) {
4568 if (MouseDown!=null) MouseDown(this, e);
4571 [EditorBrowsable(EditorBrowsableState.Advanced)]
4572 protected virtual void OnMouseEnter(EventArgs e) {
4573 if (MouseEnter!=null) MouseEnter(this, e);
4576 [EditorBrowsable(EditorBrowsableState.Advanced)]
4577 protected virtual void OnMouseHover(EventArgs e) {
4578 if (MouseHover!=null) MouseHover(this, e);
4581 [EditorBrowsable(EditorBrowsableState.Advanced)]
4582 protected virtual void OnMouseLeave(EventArgs e) {
4583 if (MouseLeave!=null) MouseLeave(this, e);
4586 [EditorBrowsable(EditorBrowsableState.Advanced)]
4587 protected virtual void OnMouseMove(MouseEventArgs e) {
4588 if (MouseMove!=null) MouseMove(this, e);
4591 [EditorBrowsable(EditorBrowsableState.Advanced)]
4592 protected virtual void OnMouseUp(MouseEventArgs e) {
4593 if (MouseUp!=null) MouseUp(this, e);
4596 [EditorBrowsable(EditorBrowsableState.Advanced)]
4597 protected virtual void OnMouseWheel(MouseEventArgs e) {
4598 if (MouseWheel!=null) MouseWheel(this, e);
4601 [EditorBrowsable(EditorBrowsableState.Advanced)]
4602 protected virtual void OnMove(EventArgs e) {
4603 if (Move!=null) Move(this, e);
4606 [EditorBrowsable(EditorBrowsableState.Advanced)]
4607 protected virtual void OnNotifyMessage(Message m) {
4611 [EditorBrowsable(EditorBrowsableState.Advanced)]
4612 protected virtual void OnPaint(PaintEventArgs e) {
4613 if (Paint!=null) Paint(this, e);
4616 internal virtual void OnPaintBackgroundInternal(PaintEventArgs e) {
4620 internal virtual void OnPaintInternal(PaintEventArgs e) {
4624 internal virtual void OnGotFocusInternal (EventArgs e)
4629 internal virtual void OnLostFocusInternal (EventArgs e)
4634 [EditorBrowsable(EditorBrowsableState.Advanced)]
4635 protected virtual void OnPaintBackground(PaintEventArgs pevent) {
4636 PaintControlBackground (pevent);
4639 [EditorBrowsable(EditorBrowsableState.Advanced)]
4640 protected virtual void OnParentBackColorChanged(EventArgs e) {
4641 if (background_color.IsEmpty && background_image==null) {
4643 OnBackColorChanged(e);
4647 [EditorBrowsable(EditorBrowsableState.Advanced)]
4648 protected virtual void OnParentBackgroundImageChanged(EventArgs e) {
4649 if (background_color.IsEmpty && background_image==null) {
4651 OnBackgroundImageChanged(e);
4655 [EditorBrowsable(EditorBrowsableState.Advanced)]
4656 protected virtual void OnParentBindingContextChanged(EventArgs e) {
4657 if (binding_context==null) {
4658 binding_context=Parent.binding_context;
4659 OnBindingContextChanged(e);
4663 [EditorBrowsable(EditorBrowsableState.Advanced)]
4664 protected virtual void OnParentChanged(EventArgs e) {
4665 if (ParentChanged!=null) ParentChanged(this, e);
4668 [EditorBrowsable(EditorBrowsableState.Advanced)]
4669 protected virtual void OnParentEnabledChanged(EventArgs e) {
4671 OnEnabledChanged(e);
4675 [EditorBrowsable(EditorBrowsableState.Advanced)]
4676 protected virtual void OnParentFontChanged(EventArgs e) {
4683 [EditorBrowsable(EditorBrowsableState.Advanced)]
4684 protected virtual void OnParentForeColorChanged(EventArgs e) {
4685 if (foreground_color.IsEmpty) {
4687 OnForeColorChanged(e);
4691 [EditorBrowsable(EditorBrowsableState.Advanced)]
4692 protected virtual void OnParentRightToLeftChanged(EventArgs e) {
4693 if (right_to_left==RightToLeft.Inherit) {
4695 OnRightToLeftChanged(e);
4699 [EditorBrowsable(EditorBrowsableState.Advanced)]
4700 protected virtual void OnParentVisibleChanged(EventArgs e) {
4702 OnVisibleChanged(e);
4706 [EditorBrowsable(EditorBrowsableState.Advanced)]
4707 protected virtual void OnQueryContinueDrag(QueryContinueDragEventArgs e) {
4708 if (QueryContinueDrag!=null) QueryContinueDrag(this, e);
4711 [EditorBrowsable(EditorBrowsableState.Advanced)]
4712 protected virtual void OnResize(EventArgs e) {
4713 if (Resize!=null) Resize(this, e);
4715 PerformLayout(this, "bounds");
4717 if (parent != null) {
4718 parent.PerformLayout();
4722 [EditorBrowsable(EditorBrowsableState.Advanced)]
4723 protected virtual void OnRightToLeftChanged(EventArgs e) {
4724 if (RightToLeftChanged!=null) RightToLeftChanged(this, e);
4725 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentRightToLeftChanged(e);
4728 [EditorBrowsable(EditorBrowsableState.Advanced)]
4729 protected virtual void OnSizeChanged(EventArgs e) {
4730 InvalidateBuffers ();
4732 if (SizeChanged!=null) SizeChanged(this, e);
4735 [EditorBrowsable(EditorBrowsableState.Advanced)]
4736 protected virtual void OnStyleChanged(EventArgs e) {
4737 if (StyleChanged!=null) StyleChanged(this, e);
4740 [EditorBrowsable(EditorBrowsableState.Advanced)]
4741 protected virtual void OnSystemColorsChanged(EventArgs e) {
4742 if (SystemColorsChanged!=null) SystemColorsChanged(this, e);
4745 [EditorBrowsable(EditorBrowsableState.Advanced)]
4746 protected virtual void OnTabIndexChanged(EventArgs e) {
4747 if (TabIndexChanged!=null) TabIndexChanged(this, e);
4750 [EditorBrowsable(EditorBrowsableState.Advanced)]
4751 protected virtual void OnTabStopChanged(EventArgs e) {
4752 if (TabStopChanged!=null) TabStopChanged(this, e);
4755 [EditorBrowsable(EditorBrowsableState.Advanced)]
4756 protected virtual void OnTextChanged(EventArgs e) {
4757 if (TextChanged!=null) TextChanged(this, e);
4760 [EditorBrowsable(EditorBrowsableState.Advanced)]
4761 protected virtual void OnValidated(EventArgs e) {
4762 if (Validated!=null) Validated(this, e);
4765 [EditorBrowsable(EditorBrowsableState.Advanced)]
4766 protected virtual void OnValidating(System.ComponentModel.CancelEventArgs e) {
4767 if (Validating!=null) Validating(this, e);
4770 [EditorBrowsable(EditorBrowsableState.Advanced)]
4771 protected virtual void OnVisibleChanged(EventArgs e) {
4772 if ((parent != null) && !Created && Visible) {
4779 if (VisibleChanged!=null) VisibleChanged(this, e);
4781 // We need to tell our kids
4782 for (int i=0; i<child_controls.Count; i++) {
4783 if (child_controls[i].Visible) {
4784 child_controls[i].OnParentVisibleChanged(e);
4788 #endregion // OnXXX methods
4791 public event EventHandler BackColorChanged;
4792 public event EventHandler BackgroundImageChanged;
4793 public event EventHandler BindingContextChanged;
4794 public event EventHandler CausesValidationChanged;
4795 public event UICuesEventHandler ChangeUICues;
4796 public event EventHandler Click;
4797 public event EventHandler ContextMenuChanged;
4799 [EditorBrowsable(EditorBrowsableState.Advanced)]
4801 public event ControlEventHandler ControlAdded;
4803 [EditorBrowsable(EditorBrowsableState.Advanced)]
4805 public event ControlEventHandler ControlRemoved;
4807 [MWFDescription("Fired when the cursor for the control has been changed"), MWFCategory("PropertyChanged")]
4808 public event EventHandler CursorChanged;
4809 public event EventHandler DockChanged;
4810 public event EventHandler DoubleClick;
4811 public event DragEventHandler DragDrop;
4812 public event DragEventHandler DragEnter;
4813 public event EventHandler DragLeave;
4814 public event DragEventHandler DragOver;
4815 public event EventHandler EnabledChanged;
4816 public event EventHandler Enter;
4817 public event EventHandler FontChanged;
4818 public event EventHandler ForeColorChanged;
4819 public event GiveFeedbackEventHandler GiveFeedback;
4821 [EditorBrowsable(EditorBrowsableState.Advanced)]
4823 public event EventHandler GotFocus;
4825 [EditorBrowsable(EditorBrowsableState.Advanced)]
4827 public event EventHandler HandleCreated;
4829 [EditorBrowsable(EditorBrowsableState.Advanced)]
4831 public event EventHandler HandleDestroyed;
4833 public event HelpEventHandler HelpRequested;
4834 public event EventHandler ImeModeChanged;
4836 [EditorBrowsable(EditorBrowsableState.Advanced)]
4838 public event InvalidateEventHandler Invalidated;
4840 public event KeyEventHandler KeyDown;
4841 public event KeyPressEventHandler KeyPress;
4842 public event KeyEventHandler KeyUp;
4843 public event LayoutEventHandler Layout;
4844 public event EventHandler Leave;
4845 public event EventHandler LocationChanged;
4847 [EditorBrowsable(EditorBrowsableState.Advanced)]
4849 public event EventHandler LostFocus;
4851 public event MouseEventHandler MouseDown;
4852 public event EventHandler MouseEnter;
4853 public event EventHandler MouseHover;
4854 public event EventHandler MouseLeave;
4855 public event MouseEventHandler MouseMove;
4856 public event MouseEventHandler MouseUp;
4858 [EditorBrowsable(EditorBrowsableState.Advanced)]
4860 public event MouseEventHandler MouseWheel;
4862 public event EventHandler Move;
4863 public event PaintEventHandler Paint;
4864 public event EventHandler ParentChanged;
4865 public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp;
4866 public event QueryContinueDragEventHandler QueryContinueDrag;
4867 public event EventHandler Resize;
4868 public event EventHandler RightToLeftChanged;
4869 public event EventHandler SizeChanged;
4870 public event EventHandler StyleChanged;
4871 public event EventHandler SystemColorsChanged;
4872 public event EventHandler TabIndexChanged;
4873 public event EventHandler TabStopChanged;
4874 public event EventHandler TextChanged;
4875 public event EventHandler Validated;
4876 public event CancelEventHandler Validating;
4877 public event EventHandler VisibleChanged;
4878 #endregion // Events