1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 // Copyright (c) 2004-2006 Novell, Inc.
23 // Peter Bartok pbartok@novell.com
25 // Partially based on work by:
26 // Aleksey Ryabchuk ryabchuk@yahoo.com
27 // Alexandre Pigolkine pigolkine@gmx.de
28 // Dennis Hayes dennish@raytek.com
29 // Jaak Simm jaaksimm@firm.ee
30 // John Sohn jsohn@columbus.rr.com
36 using System.ComponentModel;
37 using System.ComponentModel.Design;
38 using System.ComponentModel.Design.Serialization;
39 using System.Collections;
40 using System.Diagnostics;
42 using System.Drawing.Drawing2D;
43 using System.Reflection;
44 using System.Runtime.InteropServices;
45 using System.Security;
46 using System.Threading;
49 namespace System.Windows.Forms
51 [Designer("System.Windows.Forms.Design.ControlDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
52 [DefaultProperty("Text")]
53 [DefaultEvent("Click")]
54 [DesignerSerializer("System.Windows.Forms.Design.ControlCodeDomSerializer, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
55 [ToolboxItemFilter("System.Windows.Forms")]
56 public class Control : Component, ISynchronizeInvoke, IWin32Window
58 #region Local Variables
61 internal Rectangle bounds; // bounding rectangle for control (client area + decorations)
62 internal object creator_thread; // thread that created the control
63 internal ControlNativeWindow window; // object for native window handle
64 internal string name; // for object naming
67 internal bool is_created; // true if OnCreateControl has been sent
68 internal bool has_focus; // true if control has focus
69 internal bool is_visible; // true if control is visible
70 internal bool is_entered; // is the mouse inside the control?
71 internal bool is_enabled; // true if control is enabled (usable/not grayed out)
72 internal bool is_accessible; // true if the control is visible to accessibility applications
73 internal bool is_captured; // tracks if the control has captured the mouse
74 internal bool is_toplevel; // tracks if the control is a toplevel window
75 internal bool is_recreating; // tracks if the handle for the control is being recreated
76 internal ArrayList children_to_recreate; // keep track of the children which need to be recreated
77 internal bool causes_validation; // tracks if validation is executed on changes
78 internal int tab_index; // position in tab order of siblings
79 internal bool tab_stop = true; // is the control a tab stop?
80 internal bool is_disposed; // has the window already been disposed?
81 internal Size client_size; // size of the client area (window excluding decorations)
82 internal Rectangle client_rect; // rectangle with the client area (window excluding decorations)
83 internal ControlStyles control_style; // rather win32-specific, style bits for control
84 internal ImeMode ime_mode = ImeMode.Inherit;
85 internal bool layout_pending; // true if our parent needs to re-layout us
86 internal object control_tag; // object that contains data about our control
87 internal int mouse_clicks; // Counter for mouse clicks
88 internal Cursor cursor; // Cursor for the window
89 internal bool allow_drop; // true if the control accepts droping objects on it
90 internal Region clip_region; // User-specified clip region for the window
93 internal Color foreground_color; // foreground color for control
94 internal Color background_color; // background color for control
95 internal Image background_image; // background image for control
96 internal Font font; // font for control
97 internal string text; // window/title text for control
98 internal BorderStyle border_style; // Border style of control
101 internal AnchorStyles anchor_style; // anchoring requirements for our control
102 internal DockStyle dock_style; // docking requirements for our control (supercedes anchoring)
103 internal int dist_left; // distance to the left border of the parent
104 internal int dist_top; // distance to the top border of the parent
105 internal int dist_right; // distance to the right border of the parent
106 internal int dist_bottom; // distance to the bottom border of the parent
108 // to be categorized...
109 static internal ArrayList controls = new ArrayList(); // All of the application's controls, in a flat list
110 internal ControlCollection child_controls; // our children
111 internal Control parent; // our parent control
112 internal AccessibleObject accessibility_object; // object that contains accessibility information about our control
113 internal BindingContext binding_context; // TODO
114 internal RightToLeft right_to_left; // drawing direction for control
115 internal int layout_suspended;
116 internal ContextMenu context_menu; // Context menu associated with the control
118 private Graphics dc_mem; // Graphics context for double buffering
119 private GraphicsState dc_state; // Pristine graphics context to reset after paint code alters dc_mem
120 private Bitmap bmp_mem; // Bitmap for double buffering control
121 private bool needs_redraw = true;
123 private ControlBindingsCollection data_bindings;
126 internal bool use_compatible_text_rendering;
127 static internal bool verify_thread_handle;
128 private Padding padding;
129 private Size maximum_size;
130 private Size minimum_size;
131 private Size preferred_size;
132 private Padding margin;
133 internal Layout.LayoutEngine layout_engine;
136 #endregion // Local Variables
138 #region Private Classes
139 // This helper class allows us to dispatch messages to Control.WndProc
140 internal class ControlNativeWindow : NativeWindow {
141 private Control owner;
143 public ControlNativeWindow(Control control) : base() {
148 public Control Owner {
154 static internal Control ControlFromHandle(IntPtr hWnd) {
155 ControlNativeWindow window;
157 window = (ControlNativeWindow)window_collection[hWnd];
158 if (window != null) {
165 protected override void WndProc(ref Message m) {
166 owner.WndProc(ref m);
171 #region Public Classes
173 public class ControlAccessibleObject : AccessibleObject {
174 #region ControlAccessibleObject Constructors
175 public ControlAccessibleObject(Control ownerControl) {
176 this.owner = ownerControl;
178 #endregion // ControlAccessibleObject Constructors
180 #region ControlAccessibleObject Public Instance Properties
181 public override string DefaultAction {
183 return base.DefaultAction;
187 public override string Description {
189 return base.Description;
193 public IntPtr Handle {
199 // We don't want to let them set it
203 public override string Help {
209 public override string KeyboardShortcut {
211 return base.KeyboardShortcut;
215 public override string Name {
225 public Control Owner {
231 public override AccessibleObject Parent {
238 public override AccessibleRole Role {
243 #endregion // ControlAccessibleObject Public Instance Properties
245 #region ControlAccessibleObject Public Instance Methods
246 public override int GetHelpTopic(out string FileName) {
247 return base.GetHelpTopic (out FileName);
250 [MonoTODO("Implement this and tie it into Control.AccessibilityNotifyClients")]
251 public void NotifyClients(AccessibleEvents accEvent) {
252 throw new NotImplementedException();
255 [MonoTODO("Implement this and tie it into Control.AccessibilityNotifyClients")]
256 public void NotifyClients(AccessibleEvents accEvent, int childID) {
257 throw new NotImplementedException();
260 public override string ToString() {
261 return "ControlAccessibleObject: Owner = " + owner.ToString() + ", Text: " + owner.text;
264 #endregion // ControlAccessibleObject Public Instance Methods
267 [DesignerSerializer("System.Windows.Forms.Design.ControlCollectionCodeDomSerializer, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
268 [ListBindable(false)]
269 public class ControlCollection : IList, ICollection, ICloneable, IEnumerable {
270 #region ControlCollection Local Variables
271 private ArrayList list;
272 internal ArrayList impl_list;
273 private Control [] all_controls;
274 internal Control owner;
275 #endregion // ControlCollection Local Variables
277 #region ControlCollection Public Constructor
278 public ControlCollection(Control owner) {
280 this.list=new ArrayList();
284 #region ControlCollection Public Instance Properties
291 public bool IsReadOnly {
293 return list.IsReadOnly;
297 public virtual Control this[int index] {
299 if (index < 0 || index >= list.Count) {
300 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
302 return (Control)list[index];
305 #endregion // ControlCollection Public Instance Properties
307 #region ControlCollection Private Instance Methods
308 public virtual void Add (Control value)
313 if (Contains (value)) {
314 owner.PerformLayout();
318 if (value.tab_index == -1) {
324 end = owner.child_controls.Count;
325 for (int i = 0; i < end; i++) {
326 index = owner.child_controls[i].tab_index;
331 value.tab_index = use;
334 if (value.parent != null) {
335 value.parent.Controls.Remove(value);
341 value.ChangeParent(owner);
345 owner.UpdateChildrenZOrder();
346 owner.PerformLayout(value, "Parent");
347 owner.OnControlAdded(new ControlEventArgs(value));
350 internal void AddToList (Control c)
356 internal virtual void AddImplicit (Control control)
358 if (impl_list == null)
359 impl_list = new ArrayList ();
361 if (AllContains (control))
365 impl_list.Add (control);
367 control.ChangeParent (owner);
368 control.InitLayout ();
369 owner.UpdateChildrenZOrder ();
370 owner.PerformLayout (control, "Parent");
371 owner.OnControlAdded (new ControlEventArgs (control));
374 public virtual void AddRange (Control[] controls)
376 if (controls == null)
377 throw new ArgumentNullException ("controls");
379 owner.SuspendLayout ();
382 for (int i = 0; i < controls.Length; i++)
385 owner.ResumeLayout ();
389 internal virtual void AddRangeImplicit (Control [] controls)
391 if (controls == null)
392 throw new ArgumentNullException ("controls");
394 owner.SuspendLayout ();
397 for (int i = 0; i < controls.Length; i++)
398 AddImplicit (controls [i]);
400 owner.ResumeLayout ();
404 public virtual void Clear ()
408 // MS sends remove events in reverse order
409 while (list.Count > 0) {
410 Remove((Control)list[list.Count - 1]);
414 internal virtual void ClearImplicit ()
416 if (impl_list == null)
422 public bool Contains (Control value)
424 for (int i = list.Count; i > 0; ) {
427 if (list [i] == value) {
428 // Do we need to do anything here?
435 internal bool ImplicitContains (Control value)
437 if (impl_list == null)
440 for (int i = impl_list.Count; i > 0; ) {
443 if (impl_list [i] == value) {
444 // Do we need to do anything here?
451 internal bool AllContains (Control value)
453 return Contains (value) || ImplicitContains (value);
456 public void CopyTo (Array array, int index)
458 list.CopyTo(array, index);
461 public override bool Equals(object other) {
462 if (other is ControlCollection && (((ControlCollection)other).owner==this.owner)) {
469 public int GetChildIndex(Control child) {
470 return GetChildIndex(child, false);
473 public int GetChildIndex(Control child, bool throwException) {
476 index=list.IndexOf(child);
478 if (index==-1 && throwException) {
479 throw new ArgumentException("Not a child control", "child");
484 public IEnumerator GetEnumerator() {
485 return list.GetEnumerator();
488 internal IEnumerator GetAllEnumerator ()
490 Control [] res = GetAllControls ();
491 return res.GetEnumerator ();
494 internal Control [] GetAllControls ()
496 if (all_controls != null)
499 if (impl_list == null) {
500 all_controls = (Control []) list.ToArray (typeof (Control));
504 all_controls = new Control [list.Count + impl_list.Count];
505 impl_list.CopyTo (all_controls);
506 list.CopyTo (all_controls, impl_list.Count);
511 public override int GetHashCode() {
512 return base.GetHashCode();
515 public int IndexOf(Control control) {
516 return list.IndexOf(control);
519 public virtual void Remove(Control value) {
520 owner.PerformLayout(value, "Parent");
521 owner.OnControlRemoved(new ControlEventArgs(value));
526 value.ChangeParent(null);
528 owner.UpdateChildrenZOrder();
531 internal virtual void RemoveImplicit (Control control)
533 if (impl_list != null) {
535 owner.PerformLayout (control, "Parent");
536 owner.OnControlRemoved (new ControlEventArgs (control));
537 impl_list.Remove (control);
539 control.ChangeParent (null);
540 owner.UpdateChildrenZOrder ();
543 public void RemoveAt(int index) {
544 if (index < 0 || index >= list.Count) {
545 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
547 Remove ((Control)list[index]);
550 public void SetChildIndex(Control child, int newIndex) {
553 old_index=list.IndexOf(child);
555 throw new ArgumentException("Not a child control", "child");
558 if (old_index==newIndex) {
563 list.RemoveAt(old_index);
565 if (newIndex>list.Count) {
568 list.Insert(newIndex, child);
570 child.UpdateZOrder();
571 owner.PerformLayout();
573 #endregion // ControlCollection Private Instance Methods
575 #region ControlCollection Interface Properties
576 object IList.this[int index] {
578 if (index<0 || index>=list.Count) {
579 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
585 if (!(value is Control)) {
586 throw new ArgumentException("Object of type Control required", "value");
590 Control ctrl = (Control) value;
593 ctrl.ChangeParent(owner);
597 owner.UpdateChildrenZOrder();
598 owner.PerformLayout(ctrl, "Parent");
602 bool IList.IsFixedSize {
608 bool ICollection.IsSynchronized {
610 return list.IsSynchronized;
614 object ICollection.SyncRoot {
616 return list.SyncRoot;
619 #endregion // ControlCollection Interface Properties
621 #region ControlCollection Interface Methods
622 int IList.Add(object value) {
624 throw new ArgumentNullException("value", "Cannot add null controls");
627 if (!(value is Control)) {
628 throw new ArgumentException("Object of type Control required", "value");
631 return list.Add(value);
634 bool IList.Contains(object value) {
635 if (!(value is Control)) {
636 throw new ArgumentException("Object of type Control required", "value");
639 return this.Contains((Control) value);
642 int IList.IndexOf(object value) {
643 if (!(value is Control)) {
644 throw new ArgumentException("Object of type Control required", "value");
647 return this.IndexOf((Control) value);
650 void IList.Insert(int index, object value) {
651 if (!(value is Control)) {
652 throw new ArgumentException("Object of type Control required", "value");
655 list.Insert(index, value);
658 void IList.Remove(object value) {
659 if (!(value is Control)) {
660 throw new ArgumentException("Object of type Control required", "value");
666 Object ICloneable.Clone() {
667 ControlCollection clone = new ControlCollection(this.owner);
668 clone.list=(ArrayList)list.Clone(); // FIXME: Do we need this?
671 #endregion // ControlCollection Interface Methods
673 #endregion // ControlCollection Class
675 #region Public Constructors
678 anchor_style = AnchorStyles.Top | AnchorStyles.Left;
686 layout_pending = false;
688 causes_validation = true;
690 layout_suspended = 0;
694 right_to_left = RightToLeft.Inherit;
695 border_style = BorderStyle.None;
696 background_color = Color.Empty;
703 use_compatible_text_rendering = Application.use_compatible_text_rendering;
704 padding = new Padding(0);
705 maximum_size = new Size();
706 minimum_size = new Size();
707 preferred_size = new Size();
708 margin = this.DefaultMargin;
709 layout_engine = new Layout.DefaultLayout();
712 control_style = ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint |
713 ControlStyles.Selectable | ControlStyles.StandardClick |
714 ControlStyles.StandardDoubleClick;
717 background_image = null;
721 window = new ControlNativeWindow(this);
722 child_controls = CreateControlsInstance();
723 client_size = new Size(DefaultSize.Width, DefaultSize.Height);
724 client_rect = new Rectangle(0, 0, DefaultSize.Width, DefaultSize.Height);
725 XplatUI.CalculateWindowRect(ref client_rect, CreateParams.Style, CreateParams.ExStyle, null, out bounds);
726 if ((CreateParams.Style & (int)WindowStyles.WS_CHILD) == 0) {
732 public Control(Control parent, string text) : this() {
737 public Control(Control parent, string text, int left, int top, int width, int height) : this() {
742 bounds.Height=height;
743 SetBounds(left, top, width, height, BoundsSpecified.All);
747 public Control(string text) : this() {
751 public Control(string text, int left, int top, int width, int height) : this() {
755 bounds.Height=height;
756 SetBounds(left, top, width, height, BoundsSpecified.All);
760 private delegate void RemoveDelegate(object c);
762 protected override void Dispose(bool disposing) {
776 if (this.InvokeRequired) {
777 if (Application.MessageLoop) {
778 this.BeginInvokeInternal(new MethodInvoker(DestroyHandle), null, true);
779 this.BeginInvokeInternal(new RemoveDelegate(controls.Remove), new object[] {this}, true);
783 lock (Control.controls) {
784 Control.controls.Remove(this);
789 if (parent != null) {
790 parent.Controls.Remove(this);
793 Control [] children = child_controls.GetAllControls ();
794 for (int i=0; i<children.Length; i++) {
795 children[i].parent = null; // Need to set to null or our child will try and remove from ourselves and crash
796 children[i].Dispose();
801 base.Dispose(disposing);
803 #endregion // Public Constructors
805 #region Internal Properties
806 internal BorderStyle InternalBorderStyle {
812 if (!Enum.IsDefined (typeof (BorderStyle), value))
813 throw new InvalidEnumArgumentException (string.Format("Enum argument value '{0}' is not valid for BorderStyle", value));
815 if (border_style != value) {
816 border_style = value;
818 if (IsHandleCreated) {
819 XplatUI.SetBorderStyle(window.Handle, (FormBorderStyle)border_style);
825 #endregion // Internal Properties
827 #region Private & Internal Methods
828 internal IAsyncResult BeginInvokeInternal (Delegate method, object [] args, bool disposing) {
829 AsyncMethodResult result;
830 AsyncMethodData data;
837 if (!p.IsHandleCreated) {
838 throw new InvalidOperationException("Cannot call Invoke or InvokeAsync on a control until the window handle is created");
844 result = new AsyncMethodResult ();
845 data = new AsyncMethodData ();
847 data.Handle = window.Handle;
848 data.Method = method;
850 data.Result = result;
853 if (!ExecutionContext.IsFlowSuppressed ()) {
854 data.Context = ExecutionContext.Capture ();
857 #if !MWF_ON_MSRUNTIME
858 if (SecurityManager.SecurityEnabled) {
859 data.Stack = CompressedStack.GetCompressedStack ();
864 XplatUI.SendAsyncMethod (data);
869 internal void PointToClient (ref int x, ref int y)
871 XplatUI.ScreenToClient (Handle, ref x, ref y);
874 internal void PointToScreen (ref int x, ref int y)
876 XplatUI.ClientToScreen (Handle, ref x, ref y);
879 internal bool IsRecreating {
885 return ParentWaitingOnRecreation(this);
889 internal bool ChildNeedsRecreating (Control child)
891 if (children_to_recreate != null && children_to_recreate.Contains (child))
893 return ParentWaitingOnRecreation (this);
896 internal void RemoveChildFromRecreateList (Control child)
898 if (children_to_recreate != null)
899 children_to_recreate.Remove (child);
902 private bool ParentWaitingOnRecreation (Control c) {
903 if (parent != null) {
904 return parent.ChildNeedsRecreating (c);
909 internal Graphics DeviceContext {
911 if (dc_mem == null) {
912 CreateBuffers(this.Width, this.Height);
913 dc_state = dc_mem.Save();
919 internal void ResetDeviceContext() {
920 dc_mem.Restore(dc_state);
921 dc_state = dc_mem.Save();
924 private Bitmap ImageBuffer {
927 CreateBuffers(this.Width, this.Height);
933 internal void CreateBuffers (int width, int height) {
934 if (dc_mem != null) {
948 bmp_mem = new Bitmap (width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
949 dc_mem = Graphics.FromImage (bmp_mem);
953 internal void InvalidateBuffers ()
955 if (dc_mem != null) {
966 internal static void SetChildColor(Control parent) {
969 for (int i=0; i < parent.child_controls.Count; i++) {
970 child=parent.child_controls[i];
971 if (child.child_controls.Count>0) {
972 SetChildColor(child);
978 internal bool Select(Control control) {
979 IContainerControl container;
981 if (control == null) {
985 container = GetContainerControl();
986 if (container != null) {
987 container.ActiveControl = control;
989 if (control.IsHandleCreated) {
990 XplatUI.SetFocus(control.window.Handle);
995 internal void SelectChild (Control control)
997 if (control.IsHandleCreated)
998 XplatUI.SetFocus (control.window.Handle);
1001 internal virtual void DoDefaultAction() {
1002 // Only here to be overriden by our actual controls; this is needed by the accessibility class
1005 internal static int LowOrder (int param) {
1006 return ((int)(short)(param & 0xffff));
1009 internal static int HighOrder (int param) {
1010 return ((int)(short)(param >> 16));
1013 // This method exists so controls overriding OnPaintBackground can have default background painting done
1014 internal virtual void PaintControlBackground (PaintEventArgs pevent)
1016 if (GetStyle(ControlStyles.SupportsTransparentBackColor) && (BackColor.A != 0xff)) {
1017 if (parent != null) {
1018 PaintEventArgs parent_pe;
1019 GraphicsState state;
1021 parent_pe = new PaintEventArgs(pevent.Graphics, new Rectangle(pevent.ClipRectangle.X + Left, pevent.ClipRectangle.Y + Top, pevent.ClipRectangle.Width, pevent.ClipRectangle.Height));
1023 state = parent_pe.Graphics.Save();
1024 parent_pe.Graphics.TranslateTransform(-Left, -Top);
1025 parent.OnPaintBackground(parent_pe);
1026 parent_pe.Graphics.Restore(state);
1028 state = parent_pe.Graphics.Save();
1029 parent_pe.Graphics.TranslateTransform(-Left, -Top);
1030 parent.OnPaint(parent_pe);
1031 parent_pe.Graphics.Restore(state);
1032 parent_pe.SetGraphics(null);
1036 if ((clip_region != null) && (XplatUI.UserClipWontExposeParent)) {
1037 if (parent != null) {
1038 PaintEventArgs parent_pe;
1040 GraphicsState state;
1043 hwnd = Hwnd.ObjectFromHandle(Handle);
1046 parent_pe = new PaintEventArgs(pevent.Graphics, new Rectangle(pevent.ClipRectangle.X + Left, pevent.ClipRectangle.Y + Top, pevent.ClipRectangle.Width, pevent.ClipRectangle.Height));
1048 region = new Region ();
1050 region.Union(ClientRectangle);
1052 foreach (Rectangle r in hwnd.ClipRectangles) {
1056 state = parent_pe.Graphics.Save();
1057 parent_pe.Graphics.Clip = region;
1059 parent_pe.Graphics.TranslateTransform(-Left, -Top);
1060 parent.OnPaintBackground(parent_pe);
1061 parent_pe.Graphics.Restore(state);
1063 state = parent_pe.Graphics.Save();
1064 parent_pe.Graphics.Clip = region;
1066 parent_pe.Graphics.TranslateTransform(-Left, -Top);
1067 parent.OnPaint(parent_pe);
1068 parent_pe.Graphics.Restore(state);
1069 parent_pe.SetGraphics(null);
1071 region.Intersect(clip_region);
1072 pevent.Graphics.Clip = region;
1077 if (background_image == null) {
1078 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));
1082 DrawBackgroundImage (pevent.Graphics);
1085 void DrawBackgroundImage (Graphics g)
1087 using (TextureBrush b = new TextureBrush (background_image, WrapMode.Tile)) {
1088 g.FillRectangle (b, ClientRectangle);
1092 internal virtual void DndEnter (DragEventArgs e)
1099 internal virtual void DndOver (DragEventArgs e)
1106 internal virtual void DndDrop (DragEventArgs e)
1110 } catch (Exception exc) {
1111 Console.Error.WriteLine ("MWF: Exception while dropping:");
1112 Console.Error.WriteLine (exc);
1116 internal virtual void DndLeave (EventArgs e)
1123 internal virtual void DndFeedback(GiveFeedbackEventArgs e)
1130 internal virtual void DndContinueDrag(QueryContinueDragEventArgs e)
1133 OnQueryContinueDrag(e);
1137 internal static MouseButtons FromParamToMouseButtons (int param) {
1138 MouseButtons buttons = MouseButtons.None;
1140 if ((param & (int) MsgButtons.MK_LBUTTON) != 0)
1141 buttons |= MouseButtons.Left;
1143 if ((param & (int) MsgButtons.MK_MBUTTON) != 0)
1144 buttons |= MouseButtons.Middle;
1146 if ((param & (int) MsgButtons.MK_RBUTTON) != 0)
1147 buttons |= MouseButtons.Right;
1153 internal void FireEnter ()
1155 OnEnter (EventArgs.Empty);
1158 internal void FireLeave ()
1160 OnLeave (EventArgs.Empty);
1163 internal void FireValidating (CancelEventArgs ce)
1168 internal void FireValidated ()
1170 OnValidated (EventArgs.Empty);
1173 internal virtual bool ProcessControlMnemonic(char charCode) {
1174 return ProcessMnemonic(charCode);
1177 private static Control FindFlatForward(Control container, Control start) {
1183 end = container.child_controls.Count;
1185 if (start != null) {
1186 index = start.tab_index;
1191 for (int i = 0; i < end; i++) {
1192 if (found == null) {
1193 if (container.child_controls[i].tab_index > index) {
1194 found = container.child_controls[i];
1196 } else if (found.tab_index > container.child_controls[i].tab_index) {
1197 if (container.child_controls[i].tab_index > index) {
1198 found = container.child_controls[i];
1205 private static Control FindControlForward(Control container, Control start) {
1211 if (start != null) {
1212 if ((start is IContainerControl) || start.GetStyle(ControlStyles.ContainerControl)) {
1213 found = FindControlForward(start, null);
1214 if (found != null) {
1220 while (p != container) {
1221 found = FindFlatForward(p, start);
1222 if (found != null) {
1229 return FindFlatForward(container, start);
1232 private static Control FindFlatBackward(Control container, Control start) {
1238 end = container.child_controls.Count;
1240 if (start != null) {
1241 index = start.tab_index;
1243 // FIXME: Possible speed-up: Keep the highest taborder index in the container
1245 for (int i = 0; i < end; i++) {
1246 if (container.child_controls[i].tab_index > index) {
1247 index = container.child_controls[i].tab_index;
1253 for (int i = 0; i < end; i++) {
1254 if (found == null) {
1255 if (container.child_controls[i].tab_index < index) {
1256 found = container.child_controls[i];
1258 } else if (found.tab_index < container.child_controls[i].tab_index) {
1259 if (container.child_controls[i].tab_index < index) {
1260 found = container.child_controls[i];
1267 private static Control FindControlBackward(Control container, Control start) {
1272 if (start != null) {
1273 found = FindFlatBackward(start.parent, start);
1274 if (found == null) {
1275 if (start.parent != container) {
1276 return start.parent;
1282 if (found == null) {
1283 found = FindFlatBackward(container, start);
1286 if (container != start) {
1287 while ((found != null) && (!found.Contains(start)) && ((found is IContainerControl) || found.GetStyle(ControlStyles.ContainerControl))) {
1288 found = FindControlBackward(found, null);
1289 if (found != null) {
1298 internal virtual void HandleClick(int clicks, MouseEventArgs me) {
1299 if (GetStyle(ControlStyles.StandardClick)) {
1300 if ((clicks > 1) && GetStyle(ControlStyles.StandardDoubleClick)) {
1302 OnDoubleClick(EventArgs.Empty);
1304 OnClick(EventArgs.Empty);
1314 private void CheckDataBindings ()
1316 if (data_bindings == null)
1319 BindingContext binding_context = BindingContext;
1320 foreach (Binding binding in data_bindings) {
1321 binding.Check (binding_context);
1326 private void ChangeParent(Control new_parent) {
1330 Color pre_fore_color;
1331 Color pre_back_color;
1332 RightToLeft pre_rtl;
1334 // These properties are inherited from our parent
1335 // Get them pre parent-change and then send events
1336 // if they are changed after we have our new parent
1337 pre_enabled = Enabled;
1338 pre_visible = Visible;
1340 pre_fore_color = ForeColor;
1341 pre_back_color = BackColor;
1342 pre_rtl = RightToLeft;
1343 // MS doesn't seem to send a CursorChangedEvent
1345 parent = new_parent;
1347 if (IsHandleCreated)
1348 XplatUI.SetParent(Handle,
1349 (new_parent == null || !new_parent.IsHandleCreated) ? IntPtr.Zero : new_parent.Handle);
1351 OnParentChanged(EventArgs.Empty);
1353 if (pre_enabled != Enabled) {
1354 OnEnabledChanged(EventArgs.Empty);
1357 if (pre_visible != Visible) {
1358 OnVisibleChanged(EventArgs.Empty);
1361 if (pre_font != Font) {
1362 OnFontChanged(EventArgs.Empty);
1365 if (pre_fore_color != ForeColor) {
1366 OnForeColorChanged(EventArgs.Empty);
1369 if (pre_back_color != BackColor) {
1370 OnBackColorChanged(EventArgs.Empty);
1373 if (pre_rtl != RightToLeft) {
1374 // MS sneaks a OnCreateControl and OnHandleCreated in here, I guess
1375 // because when RTL changes they have to recreate the win32 control
1376 // We don't really need that (until someone runs into compatibility issues)
1377 OnRightToLeftChanged(EventArgs.Empty);
1380 if ((new_parent != null) && new_parent.Created && !Created) {
1384 if ((binding_context == null) && Created) {
1385 OnBindingContextChanged(EventArgs.Empty);
1389 private void UpdateDistances() {
1390 if ((parent != null) && (parent.layout_suspended == 0)) {
1391 dist_left = bounds.X;
1392 dist_top = bounds.Y;
1393 dist_right = parent.ClientSize.Width - bounds.X - bounds.Width;
1394 dist_bottom = parent.ClientSize.Height - bounds.Y - bounds.Height;
1397 #endregion // Private & Internal Methods
1399 #region Public Static Properties
1400 public static Color DefaultBackColor {
1402 return ThemeEngine.Current.DefaultControlBackColor;
1406 public static Font DefaultFont {
1408 return ThemeEngine.Current.DefaultFont;
1412 public static Color DefaultForeColor {
1414 return ThemeEngine.Current.DefaultControlForeColor;
1418 public static Keys ModifierKeys {
1420 return XplatUI.State.ModifierKeys;
1424 public static MouseButtons MouseButtons {
1426 return XplatUI.State.MouseButtons;
1430 public static Point MousePosition {
1432 return Cursor.Position;
1438 public static bool CheckForIllegalCrossThreadCalls
1441 return verify_thread_handle;
1445 verify_thread_handle = value;
1449 #endregion // Public Static Properties
1451 #region Public Instance Properties
1452 [EditorBrowsable(EditorBrowsableState.Advanced)]
1454 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1455 public AccessibleObject AccessibilityObject {
1457 if (accessibility_object==null) {
1458 accessibility_object=CreateAccessibilityInstance();
1460 return accessibility_object;
1464 [EditorBrowsable(EditorBrowsableState.Advanced)]
1466 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1467 public string AccessibleDefaultActionDescription {
1469 return AccessibilityObject.default_action;
1473 AccessibilityObject.default_action=value;
1478 [DefaultValue(null)]
1479 [MWFCategory("Accessibility")]
1480 public string AccessibleDescription {
1482 return AccessibilityObject.description;
1486 AccessibilityObject.description=value;
1491 [DefaultValue(null)]
1492 [MWFCategory("Accessibility")]
1493 public string AccessibleName {
1495 return AccessibilityObject.Name;
1499 AccessibilityObject.Name=value;
1503 [DefaultValue(AccessibleRole.Default)]
1504 [MWFDescription("Role of the control"), MWFCategory("Accessibility")]
1505 public AccessibleRole AccessibleRole {
1507 return AccessibilityObject.role;
1511 AccessibilityObject.role=value;
1515 [DefaultValue(false)]
1516 [MWFCategory("Behavior")]
1517 public virtual bool AllowDrop {
1523 if (allow_drop == value)
1526 if (IsHandleCreated) {
1528 XplatUI.SetAllowDrop (Handle, value);
1534 [RefreshProperties(RefreshProperties.Repaint)]
1535 [DefaultValue(AnchorStyles.Top | AnchorStyles.Left)]
1536 [MWFCategory("Layout")]
1537 public virtual AnchorStyles Anchor {
1539 return anchor_style;
1545 if (parent != null) {
1546 parent.PerformLayout(this, "Parent");
1552 // XXX: Implement me!
1555 public virtual bool AutoSize {
1557 //Console.Error.WriteLine("Unimplemented: Control::get_AutoSize()");
1561 Console.Error.WriteLine("Unimplemented: Control::set_AutoSize(bool)");
1566 public virtual Size MaximumSize {
1568 return maximum_size;
1571 maximum_size = value;
1575 public virtual Size MinimumSize {
1577 return minimum_size;
1580 minimum_size = value;
1586 [MWFCategory("Appearance")]
1587 public virtual Color BackColor {
1589 if (background_color.IsEmpty) {
1591 Color pcolor = parent.BackColor;
1592 if (pcolor.A == 0xff || GetStyle(ControlStyles.SupportsTransparentBackColor))
1595 return DefaultBackColor;
1597 return background_color;
1601 if (!value.IsEmpty && (value.A != 0xff) && !GetStyle(ControlStyles.SupportsTransparentBackColor)) {
1602 throw new ArgumentException("Transparent background colors are not supported on this control");
1605 if (background_color != value) {
1606 background_color=value;
1607 SetChildColor(this);
1608 OnBackColorChanged(EventArgs.Empty);
1615 [DefaultValue(null)]
1616 [MWFCategory("Appearance")]
1617 public virtual Image BackgroundImage {
1619 return background_image;
1623 if (background_image!=value) {
1624 background_image=value;
1625 OnBackgroundImageChanged(EventArgs.Empty);
1630 [EditorBrowsable(EditorBrowsableState.Advanced)]
1632 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1633 public virtual BindingContext BindingContext {
1635 if (binding_context != null)
1636 return binding_context;
1639 binding_context = Parent.BindingContext;
1640 return binding_context;
1643 if (binding_context != value) {
1644 binding_context = value;
1645 OnBindingContextChanged(EventArgs.Empty);
1650 [EditorBrowsable(EditorBrowsableState.Advanced)]
1652 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1655 return bounds.Y+bounds.Height;
1659 [EditorBrowsable(EditorBrowsableState.Advanced)]
1661 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1662 public Rectangle Bounds {
1668 SetBounds(value.Left, value.Top, value.Width, value.Height, BoundsSpecified.All);
1672 [EditorBrowsable(EditorBrowsableState.Advanced)]
1674 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1675 public bool CanFocus {
1677 if (IsHandleCreated && Visible && Enabled) {
1684 [EditorBrowsable(EditorBrowsableState.Advanced)]
1686 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1687 public bool CanSelect {
1691 if (!GetStyle(ControlStyles.Selectable)) {
1696 while (parent != null) {
1697 if (!parent.is_visible || !parent.is_enabled) {
1701 parent = parent.parent;
1707 internal virtual bool InternalCapture {
1717 [EditorBrowsable(EditorBrowsableState.Advanced)]
1719 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1720 public bool Capture {
1722 return this.is_captured;
1726 if (this.IsHandleCreated) {
1727 if (value && !is_captured) {
1729 XplatUI.GrabWindow(this.window.Handle, IntPtr.Zero);
1730 } else if (!value && is_captured) {
1731 XplatUI.UngrabWindow(this.window.Handle);
1732 is_captured = false;
1738 [DefaultValue(true)]
1739 [MWFCategory("Focus")]
1740 public bool CausesValidation {
1742 return this.causes_validation;
1746 if (this.causes_validation != value) {
1747 causes_validation = value;
1748 OnCausesValidationChanged(EventArgs.Empty);
1753 [EditorBrowsable(EditorBrowsableState.Advanced)]
1755 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1756 public Rectangle ClientRectangle {
1758 client_rect.Width = client_size.Width;
1759 client_rect.Height = client_size.Height;
1764 [EditorBrowsable(EditorBrowsableState.Advanced)]
1766 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1767 public Size ClientSize {
1770 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1771 return ((Form)this).form_parent_window.ClientSize;
1779 this.SetClientSizeCore(value.Width, value.Height);
1783 [EditorBrowsable(EditorBrowsableState.Advanced)]
1785 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1786 [DescriptionAttribute("ControlCompanyNameDescr")]
1787 public String CompanyName {
1789 return "Mono Project, Novell, Inc.";
1793 [EditorBrowsable(EditorBrowsableState.Advanced)]
1795 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1796 public bool ContainsFocus {
1798 IntPtr focused_window;
1800 focused_window = XplatUI.GetFocus();
1801 if (IsHandleCreated) {
1802 if (focused_window == Handle) {
1806 for (int i=0; i < child_controls.Count; i++) {
1807 if (child_controls[i].ContainsFocus) {
1816 [DefaultValue(null)]
1817 [MWFCategory("Behavior")]
1818 public virtual ContextMenu ContextMenu {
1820 return context_menu;
1824 if (context_menu != value) {
1825 context_menu = value;
1826 OnContextMenuChanged(EventArgs.Empty);
1832 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
1833 public ControlCollection Controls {
1835 return this.child_controls;
1839 [EditorBrowsable(EditorBrowsableState.Advanced)]
1841 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1842 public bool Created {
1844 return (!is_disposed && is_created);
1848 [AmbientValue(null)]
1849 [MWFCategory("Appearance")]
1850 public virtual Cursor Cursor {
1852 if (cursor != null) {
1856 if (parent != null) {
1857 return parent.Cursor;
1860 return Cursors.Default;
1864 if (cursor != value) {
1869 if (IsHandleCreated) {
1870 pt = Cursor.Position;
1872 if (bounds.Contains(pt) || Capture) {
1873 if (GetChildAtPoint(pt) == null) {
1874 if (cursor != null) {
1875 XplatUI.SetCursor(window.Handle, cursor.handle);
1877 if (parent != null) {
1878 XplatUI.SetCursor(window.Handle, parent.Cursor.handle);
1880 XplatUI.SetCursor(window.Handle, Cursors.Default.handle);
1887 OnCursorChanged(EventArgs.Empty);
1893 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
1894 [ParenthesizePropertyName(true)]
1895 [RefreshProperties(RefreshProperties.All)]
1896 [MWFCategory("Data")]
1897 public ControlBindingsCollection DataBindings {
1899 if (data_bindings == null)
1900 data_bindings = new ControlBindingsCollection (this);
1901 return data_bindings;
1905 [EditorBrowsable(EditorBrowsableState.Advanced)]
1907 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1908 public virtual Rectangle DisplayRectangle {
1910 return ClientRectangle;
1914 [EditorBrowsable(EditorBrowsableState.Advanced)]
1916 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1917 public bool Disposing {
1924 [RefreshProperties(RefreshProperties.Repaint)]
1925 [DefaultValue(DockStyle.None)]
1926 [MWFCategory("Layout")]
1927 public virtual DockStyle Dock {
1933 if (dock_style == value) {
1939 if (parent != null) {
1940 parent.PerformLayout(this, "Parent");
1943 OnDockChanged(EventArgs.Empty);
1949 [MWFCategory("Behavior")]
1950 public bool Enabled {
1956 if (parent != null) {
1957 return parent.Enabled;
1964 if (Enabled == value) {
1971 // FIXME - we need to switch focus to next control if we're disabling the focused control
1973 OnEnabledChanged (EventArgs.Empty);
1977 [EditorBrowsable(EditorBrowsableState.Advanced)]
1979 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1980 public virtual bool Focused {
1982 return this.has_focus;
1987 [AmbientValue(null)]
1989 [MWFCategory("Appearance")]
1990 public virtual Font Font {
1996 if (Parent != null && Parent.Font != null) {
2003 [param:MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Font))]
2005 if (font != null && font.Equals (value)) {
2011 OnFontChanged (EventArgs.Empty);
2016 [MWFCategory("Appearance")]
2017 public virtual Color ForeColor {
2019 if (foreground_color.IsEmpty) {
2021 return parent.ForeColor;
2023 return DefaultForeColor;
2025 return foreground_color;
2029 if (foreground_color != value) {
2030 foreground_color=value;
2032 OnForeColorChanged(EventArgs.Empty);
2039 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2040 public IntPtr Handle { // IWin32Window
2043 if (verify_thread_handle) {
2044 if (this.InvokeRequired) {
2045 throw new InvalidOperationException("Cross-thread access of handle detected. Handle access only valid on thread that created the control");
2049 if (!IsHandleCreated) {
2052 return window.Handle;
2056 [EditorBrowsable(EditorBrowsableState.Advanced)]
2058 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2059 public bool HasChildren {
2061 if (this.child_controls.Count>0) {
2068 [EditorBrowsable(EditorBrowsableState.Always)]
2070 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2073 return this.bounds.Height;
2077 SetBounds(bounds.X, bounds.Y, bounds.Width, value, BoundsSpecified.Height);
2081 [AmbientValue(ImeMode.Inherit)]
2083 [MWFCategory("Behavior")]
2084 public ImeMode ImeMode {
2086 if (ime_mode == DefaultImeMode) {
2088 return parent.ImeMode;
2090 return ImeMode.NoControl; // default value
2096 if (ime_mode != value) {
2099 OnImeModeChanged(EventArgs.Empty);
2104 [EditorBrowsable(EditorBrowsableState.Advanced)]
2106 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2107 public bool InvokeRequired { // ISynchronizeInvoke
2109 if (creator_thread != null && creator_thread!=Thread.CurrentThread) {
2116 [EditorBrowsable(EditorBrowsableState.Advanced)]
2118 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2119 public bool IsAccessible {
2121 return is_accessible;
2125 is_accessible = value;
2129 [EditorBrowsable(EditorBrowsableState.Advanced)]
2131 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2132 public bool IsDisposed {
2134 return this.is_disposed;
2138 [EditorBrowsable(EditorBrowsableState.Advanced)]
2140 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2141 public bool IsHandleCreated {
2143 if ((window != null) && (window.Handle != IntPtr.Zero)) {
2144 Hwnd hwnd = Hwnd.ObjectFromHandle (window.Handle);
2145 if (hwnd != null && !hwnd.zombie)
2154 public virtual Layout.LayoutEngine LayoutEngine {
2155 get { return this.layout_engine; }
2159 [EditorBrowsable(EditorBrowsableState.Always)]
2161 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2164 return this.bounds.X;
2168 SetBounds(value, bounds.Y, bounds.Width, bounds.Height, BoundsSpecified.X);
2173 [MWFCategory("Layout")]
2174 public Point Location {
2176 return new Point(bounds.X, bounds.Y);
2180 SetBounds(value.X, value.Y, bounds.Width, bounds.Height, BoundsSpecified.Location);
2185 [Localizable (true)]
2186 public Padding Margin {
2187 get { return this.margin; }
2188 set { this.margin = value; }
2193 public string Name {
2205 public Padding Padding {
2217 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2218 public Control Parent {
2224 if (value == this) {
2225 throw new ArgumentException("A circular control reference has been made. A control cannot be owned or parented to itself.");
2228 if (parent!=value) {
2230 parent.Controls.Remove(this);
2235 value.Controls.Add(this);
2240 [EditorBrowsable(EditorBrowsableState.Advanced)]
2242 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2243 public string ProductName {
2245 Type t = typeof (AssemblyProductAttribute);
2246 Assembly assembly = GetType().Module.Assembly;
2247 object [] attrs = assembly.GetCustomAttributes (t, false);
2248 AssemblyProductAttribute a = null;
2249 // On MS we get a NullRefException if product attribute is not
2251 if (attrs != null && attrs.Length > 0)
2252 a = (AssemblyProductAttribute) attrs [0];
2257 [EditorBrowsable(EditorBrowsableState.Advanced)]
2259 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2260 public string ProductVersion {
2262 Type t = typeof (AssemblyVersionAttribute);
2263 Assembly assembly = GetType().Module.Assembly;
2264 object [] attrs = assembly.GetCustomAttributes (t, false);
2265 if (attrs == null || attrs.Length < 1)
2267 return ((AssemblyVersionAttribute)attrs [0]).Version;
2271 [EditorBrowsable(EditorBrowsableState.Advanced)]
2273 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2274 public bool RecreatingHandle {
2276 return is_recreating;
2280 [EditorBrowsable(EditorBrowsableState.Advanced)]
2282 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2283 public Region Region {
2289 if (IsHandleCreated) {
2290 XplatUI.SetClipRegion(Handle, value);
2292 clip_region = value;
2296 [EditorBrowsable(EditorBrowsableState.Advanced)]
2298 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2301 return this.bounds.X+this.bounds.Width;
2305 [AmbientValue(RightToLeft.Inherit)]
2307 [MWFCategory("Appearance")]
2308 public virtual RightToLeft RightToLeft {
2310 if (right_to_left == RightToLeft.Inherit) {
2312 return parent.RightToLeft;
2314 return RightToLeft.No; // default value
2316 return right_to_left;
2320 if (value != right_to_left) {
2321 right_to_left = value;
2322 OnRightToLeftChanged(EventArgs.Empty);
2327 [EditorBrowsable(EditorBrowsableState.Advanced)]
2328 public override ISite Site {
2336 AmbientProperties ap = (AmbientProperties) value.GetService (typeof (AmbientProperties));
2338 BackColor = ap.BackColor;
2339 ForeColor = ap.ForeColor;
2347 [MWFCategory("Layout")]
2350 return new Size(Width, Height);
2354 SetBounds(bounds.X, bounds.Y, value.Width, value.Height, BoundsSpecified.Size);
2359 [MergableProperty(false)]
2360 [MWFCategory("Behavior")]
2361 public int TabIndex {
2363 if (tab_index != -1) {
2370 if (tab_index != value) {
2372 OnTabIndexChanged(EventArgs.Empty);
2378 [DefaultValue(true)]
2379 [MWFCategory("Behavior")]
2380 public bool TabStop {
2386 if (tab_stop != value) {
2388 OnTabStopChanged(EventArgs.Empty);
2393 [Localizable(false)]
2395 [TypeConverter(typeof(StringConverter))]
2396 [DefaultValue(null)]
2397 [MWFCategory("Data")]
2404 control_tag = value;
2410 [BindableAttribute(true)]
2411 [MWFCategory("Appearance")]
2412 public virtual string Text {
2414 // Our implementation ignores ControlStyles.CacheText - we always cache
2419 if (value == null) {
2420 value = String.Empty;
2425 if (IsHandleCreated) {
2426 /* we need to call .SetWindowStyle here instead of just .Text
2427 because the presence/absence of Text (== "" or not) can cause
2428 other window style things to appear/disappear */
2429 XplatUI.SetWindowStyle(window.Handle, CreateParams);
2430 XplatUI.Text(Handle, text);
2432 OnTextChanged (EventArgs.Empty);
2437 [EditorBrowsable(EditorBrowsableState.Always)]
2439 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2442 return this.bounds.Y;
2446 SetBounds(bounds.X, value, bounds.Width, bounds.Height, BoundsSpecified.Y);
2450 [EditorBrowsable(EditorBrowsableState.Advanced)]
2452 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2453 public Control TopLevelControl {
2457 while (p.parent != null) {
2466 [MWFCategory("Behavior")]
2467 public bool Visible {
2471 } else if (parent != null) {
2472 return parent.Visible;
2479 SetVisibleCore(value);
2483 [EditorBrowsable(EditorBrowsableState.Always)]
2485 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2488 return this.bounds.Width;
2492 SetBounds(bounds.X, bounds.Y, value, bounds.Height, BoundsSpecified.Width);
2496 [EditorBrowsable(EditorBrowsableState.Never)]
2498 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2499 public IWindowTarget WindowTarget {
2508 #endregion // Public Instance Properties
2510 #region Protected Instance Properties
2511 protected virtual CreateParams CreateParams {
2513 CreateParams create_params = new CreateParams();
2516 create_params.Caption = Text;
2519 create_params.Caption = text;
2523 create_params.X = Left;
2526 create_params.X = this.bounds.X;
2530 create_params.Y = Top;
2533 create_params.Y = this.bounds.Y;
2537 create_params.Width = Width;
2540 create_params.Width = this.bounds.Width;
2544 create_params.Height = Height;
2547 create_params.Height = this.bounds.Height;
2551 create_params.ClassName = XplatUI.DefaultClassName;
2552 create_params.ClassStyle = 0;
2553 create_params.ExStyle = 0;
2554 create_params.Param = 0;
2557 create_params.ExStyle |= (int)WindowExStyles.WS_EX_ACCEPTFILES;
2560 if ((parent!=null) && (parent.IsHandleCreated)) {
2561 create_params.Parent = parent.Handle;
2564 create_params.Style = (int)WindowStyles.WS_CHILD | (int)WindowStyles.WS_CLIPCHILDREN | (int)WindowStyles.WS_CLIPSIBLINGS;
2567 create_params.Style |= (int)WindowStyles.WS_VISIBLE;
2571 create_params.Style |= (int)WindowStyles.WS_DISABLED;
2574 switch (border_style) {
2575 case BorderStyle.FixedSingle:
2576 create_params.Style |= (int) WindowStyles.WS_BORDER;
2578 case BorderStyle.Fixed3D:
2579 create_params.ExStyle |= (int) WindowExStyles.WS_EX_CLIENTEDGE;
2583 return create_params;
2587 protected virtual ImeMode DefaultImeMode {
2589 return ImeMode.Inherit;
2594 protected virtual Padding DefaultMargin {
2595 get { return new Padding (3); }
2599 protected virtual Size DefaultSize {
2601 return new Size(0, 0);
2605 protected int FontHeight {
2615 protected bool RenderRightToLeft {
2617 return (this.right_to_left == RightToLeft.Yes);
2621 protected bool ResizeRedraw {
2623 return GetStyle(ControlStyles.ResizeRedraw);
2627 SetStyle(ControlStyles.ResizeRedraw, value);
2631 [EditorBrowsable(EditorBrowsableState.Advanced)]
2633 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2634 protected virtual bool ShowFocusCues {
2640 [EditorBrowsable(EditorBrowsableState.Advanced)]
2642 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2643 protected bool ShowKeyboardCues {
2648 #endregion // Protected Instance Properties
2650 #region Public Static Methods
2651 [EditorBrowsable(EditorBrowsableState.Advanced)]
2652 public static Control FromChildHandle(IntPtr handle) {
2653 lock (Control.controls) {
2654 IEnumerator control = Control.controls.GetEnumerator();
2656 while (control.MoveNext()) {
2657 if (((Control)control.Current).window.Handle == handle) {
2659 if (((Control)control.Current).Parent != null) {
2660 return ((Control)control.Current).Parent;
2668 [EditorBrowsable(EditorBrowsableState.Advanced)]
2669 public static Control FromHandle(IntPtr handle) {
2671 IEnumerator control = Control.controls.GetEnumerator();
2673 while (control.MoveNext()) {
2674 if (((Control)control.Current).window.Handle == handle) {
2676 return ((Control)control.Current);
2682 return Control.ControlNativeWindow.ControlFromHandle(handle);
2686 public static bool IsMnemonic(char charCode, string text) {
2689 amp = text.IndexOf('&');
2692 if (amp + 1 < text.Length) {
2693 if (text[amp + 1] != '&') {
2694 if (Char.ToUpper(charCode) == Char.ToUpper(text.ToCharArray(amp + 1, 1)[0])) {
2704 #region Protected Static Methods
2705 [EditorBrowsable(EditorBrowsableState.Advanced)]
2706 protected static bool ReflectMessage(IntPtr hWnd, ref Message m) {
2709 c = Control.FromHandle(hWnd);
2719 #region Public Instance Methods
2720 [EditorBrowsable(EditorBrowsableState.Advanced)]
2721 public IAsyncResult BeginInvoke(Delegate method) {
2722 object [] prms = null;
2723 if (method is EventHandler)
2724 prms = new object [] { this, EventArgs.Empty };
2725 return BeginInvokeInternal(method, prms, false);
2728 [EditorBrowsable(EditorBrowsableState.Advanced)]
2729 public IAsyncResult BeginInvoke (Delegate method, object[] args) {
2730 return BeginInvokeInternal (method, args, false);
2733 public void BringToFront() {
2734 if (parent != null) {
2735 parent.child_controls.SetChildIndex(this, 0);
2738 XplatUI.SetZOrder(Handle, IntPtr.Zero, false, false);
2742 public bool Contains(Control ctl) {
2743 while (ctl != null) {
2752 public void CreateControl() {
2754 throw new ObjectDisposedException(GetType().FullName.ToString());
2760 if (!IsHandleCreated) {
2768 Control [] controls = child_controls.GetAllControls ();
2769 for (int i=0; i<controls.Length; i++) {
2770 controls [i].CreateControl ();
2773 UpdateChildrenZOrder();
2775 if (binding_context == null) { // seem to be sent whenever it's null?
2776 OnBindingContextChanged(EventArgs.Empty);
2782 public Graphics CreateGraphics() {
2783 if (!IsHandleCreated) {
2784 this.CreateHandle();
2786 return Graphics.FromHwnd(this.window.Handle);
2789 public DragDropEffects DoDragDrop(object data, DragDropEffects allowedEffects) {
2790 return XplatUI.StartDrag(this.window.Handle, data, allowedEffects);
2793 [EditorBrowsable(EditorBrowsableState.Advanced)]
2794 public object EndInvoke (IAsyncResult async_result) {
2795 AsyncMethodResult result = (AsyncMethodResult) async_result;
2796 return result.EndInvoke ();
2799 public Form FindForm() {
2812 public bool Focus() {
2813 if (CanFocus && IsHandleCreated && !has_focus) {
2814 XplatUI.SetFocus(window.Handle);
2819 public Control GetChildAtPoint(Point pt) {
2820 // Microsoft's version of this function doesn't seem to work, so I can't check
2821 // if we only consider children or also grandchildren, etc.
2822 // I'm gonna say 'children only'
2823 for (int i=0; i<child_controls.Count; i++) {
2824 if (child_controls[i].Bounds.Contains(pt)) {
2825 return child_controls[i];
2831 public IContainerControl GetContainerControl() {
2832 Control current = this;
2834 while (current!=null) {
2835 if ((current is IContainerControl) && ((current.control_style & ControlStyles.ContainerControl)!=0)) {
2836 return (IContainerControl)current;
2838 current = current.parent;
2843 public Control GetNextControl(Control ctl, bool forward) {
2844 // If we're not a container we don't play
2845 if (!(this is IContainerControl) && !this.GetStyle(ControlStyles.ContainerControl)) {
2852 return FindFlatBackward(ctl, null);
2855 if ((parent == null) && (ctl is IContainerControl) && ctl.GetStyle(ControlStyles.ContainerControl)) {
2857 return FindFlatForward(this, ctl);
2859 return FindFlatBackward(this, ctl);
2864 // If ctl is not contained by this, we start at the first child of this
2865 if (!this.Contains(ctl)) {
2869 // Search through our controls, starting at ctl, stepping into children as we encounter them
2870 // try to find the control with the tabindex closest to our own, or, if we're looking into
2871 // child controls, the one with the smallest tabindex
2873 return FindControlForward(this, ctl);
2875 return FindControlBackward(this, ctl);
2879 public virtual Size GetPreferredSize (Size proposedSize) {
2880 return preferred_size;
2884 public void Hide() {
2885 this.Visible = false;
2888 public void Invalidate() {
2889 Invalidate(ClientRectangle, false);
2892 public void Invalidate(bool invalidateChildren) {
2893 Invalidate(ClientRectangle, invalidateChildren);
2896 public void Invalidate(System.Drawing.Rectangle rc) {
2897 Invalidate(rc, false);
2900 public void Invalidate(System.Drawing.Rectangle rc, bool invalidateChildren) {
2901 if (!IsHandleCreated || !Visible || rc.Width == 0 || rc.Height == 0) {
2905 NotifyInvalidate(rc);
2907 XplatUI.Invalidate(Handle, rc, false);
2909 if (invalidateChildren) {
2910 Control [] controls = child_controls.GetAllControls ();
2911 for (int i=0; i<controls.Length; i++)
2912 controls [i].Invalidate ();
2914 OnInvalidated(new InvalidateEventArgs(rc));
2917 public void Invalidate(System.Drawing.Region region) {
2918 Invalidate(region, false);
2921 public void Invalidate(System.Drawing.Region region, bool invalidateChildren) {
2922 RectangleF bounds = region.GetBounds (CreateGraphics ());
2923 Invalidate (new Rectangle ((int) bounds.X, (int) bounds.Y, (int) bounds.Width, (int) bounds.Height),
2924 invalidateChildren);
2927 public object Invoke (Delegate method) {
2928 object [] prms = null;
2929 if (method is EventHandler)
2930 prms = new object [] { this, EventArgs.Empty };
2932 return Invoke(method, prms);
2935 public object Invoke (Delegate method, object[] args) {
2936 if (!this.InvokeRequired) {
2937 return method.DynamicInvoke(args);
2940 IAsyncResult result = BeginInvoke (method, args);
2941 return EndInvoke(result);
2944 internal object InvokeInternal (Delegate method, bool disposing) {
2945 return InvokeInternal(method, null, disposing);
2948 internal object InvokeInternal (Delegate method, object[] args, bool disposing) {
2949 if (!this.InvokeRequired) {
2950 return method.DynamicInvoke(args);
2953 IAsyncResult result = BeginInvokeInternal (method, args, disposing);
2954 return EndInvoke(result);
2957 [EditorBrowsable(EditorBrowsableState.Advanced)]
2958 public void PerformLayout() {
2959 PerformLayout(null, null);
2962 [EditorBrowsable(EditorBrowsableState.Advanced)]
2963 public void PerformLayout(Control affectedControl, string affectedProperty) {
2964 LayoutEventArgs levent = new LayoutEventArgs(affectedControl, affectedProperty);
2966 if (layout_suspended > 0) {
2967 layout_pending = true;
2971 layout_pending = false;
2973 // Prevent us from getting messed up
2976 // Perform all Dock and Anchor calculations
2980 this.layout_engine.Layout(this, levent);
2982 // This has been moved to Layout/DefaultLayout.cs for 2.0, please duplicate any changes/fixes there.
2984 AnchorStyles anchor;
2987 space = DisplayRectangle;
2989 // Deal with docking; go through in reverse, MS docs say that lowest Z-order is closest to edge
2990 Control [] controls = child_controls.GetAllControls ();
2991 for (int i = controls.Length - 1; i >= 0; i--) {
2992 child = controls [i];
2994 if (!child.Visible) {
2998 switch (child.Dock) {
2999 case DockStyle.None: {
3004 case DockStyle.Left: {
3005 child.SetBounds(space.Left, space.Y, child.Width, space.Height);
3006 space.X+=child.Width;
3007 space.Width-=child.Width;
3011 case DockStyle.Top: {
3012 child.SetBounds(space.Left, space.Y, space.Width, child.Height);
3013 space.Y+=child.Height;
3014 space.Height-=child.Height;
3018 case DockStyle.Right: {
3019 child.SetBounds(space.Right-child.Width, space.Y, child.Width, space.Height);
3020 space.Width-=child.Width;
3024 case DockStyle.Bottom: {
3025 child.SetBounds(space.Left, space.Bottom-child.Height, space.Width, child.Height);
3026 space.Height-=child.Height;
3032 for (int i = controls.Length - 1; i >= 0; i--) {
3035 //if (child.Visible && (child.Dock == DockStyle.Fill)) {
3036 if (child.Dock == DockStyle.Fill) {
3037 child.SetBounds(space.Left, space.Top, space.Width, space.Height);
3041 space = DisplayRectangle;
3043 for (int i=0; i < controls.Length; i++) {
3049 child = controls[i];
3051 // If the control is docked we don't need to do anything
3052 if (child.Dock != DockStyle.None) {
3056 anchor = child.Anchor;
3060 width = child.Width;
3061 height = child.Height;
3063 if ((anchor & AnchorStyles.Left) !=0 ) {
3064 if ((anchor & AnchorStyles.Right) != 0) {
3065 width = space.Width - child.dist_right - left;
3067 ; // Left anchored only, nothing to be done
3069 } else if ((anchor & AnchorStyles.Right) != 0) {
3070 left = space.Width - child.dist_right - width;
3072 // left+=diff_width/2 will introduce rounding errors (diff_width removed from svn after r51780)
3073 // This calculates from scratch every time:
3074 left = child.dist_left + (space.Width - (child.dist_left + width + child.dist_right)) / 2;
3077 if ((anchor & AnchorStyles.Top) !=0 ) {
3078 if ((anchor & AnchorStyles.Bottom) != 0) {
3079 height = space.Height - child.dist_bottom - top;
3081 ; // Top anchored only, nothing to be done
3083 } else if ((anchor & AnchorStyles.Bottom) != 0) {
3084 top = space.Height - child.dist_bottom - height;
3086 // top += diff_height/2 will introduce rounding errors (diff_height removed from after r51780)
3087 // This calculates from scratch every time:
3088 top = child.dist_top + (space.Height - (child.dist_top + height + child.dist_bottom)) / 2;
3100 child.SetBounds(left, top, width, height);
3104 // Let everyone know
3108 // Need to make sure we decremend layout_suspended
3114 public Point PointToClient (Point p) {
3118 XplatUI.ScreenToClient (Handle, ref x, ref y);
3120 return new Point (x, y);
3123 public Point PointToScreen(Point p) {
3127 XplatUI.ClientToScreen(Handle, ref x, ref y);
3129 return new Point(x, y);
3132 public virtual bool PreProcessMessage(ref Message msg) {
3133 return InternalPreProcessMessage (ref msg);
3136 internal virtual bool InternalPreProcessMessage (ref Message msg) {
3139 if ((msg.Msg == (int)Msg.WM_KEYDOWN) || (msg.Msg == (int)Msg.WM_SYSKEYDOWN)) {
3140 key_data = (Keys)msg.WParam.ToInt32() | XplatUI.State.ModifierKeys;
3142 if (!ProcessCmdKey(ref msg, key_data)) {
3143 if (IsInputKey(key_data)) {
3147 return ProcessDialogKey(key_data);
3151 } else if (msg.Msg == (int)Msg.WM_CHAR) {
3152 if (IsInputChar((char)msg.WParam)) {
3155 return ProcessDialogChar((char)msg.WParam);
3156 } else if (msg.Msg == (int)Msg.WM_SYSCHAR) {
3157 return ProcessDialogChar((char)msg.WParam);
3162 public Rectangle RectangleToClient(Rectangle r) {
3163 return new Rectangle(PointToClient(r.Location), r.Size);
3166 public Rectangle RectangleToScreen(Rectangle r) {
3167 return new Rectangle(PointToScreen(r.Location), r.Size);
3170 public virtual void Refresh() {
3171 if (IsHandleCreated == true) {
3173 XplatUI.UpdateWindow(window.Handle);
3175 Control [] controls = child_controls.GetAllControls ();
3176 for (int i=0; i < controls.Length; i++) {
3177 controls[i].Refresh();
3183 [EditorBrowsable(EditorBrowsableState.Never)]
3184 public virtual void ResetBackColor() {
3185 BackColor = Color.Empty;
3188 [EditorBrowsable(EditorBrowsableState.Never)]
3189 public void ResetBindings() {
3190 data_bindings.Clear();
3193 [EditorBrowsable(EditorBrowsableState.Never)]
3194 public virtual void ResetCursor() {
3198 [EditorBrowsable(EditorBrowsableState.Never)]
3199 public virtual void ResetFont() {
3203 [EditorBrowsable(EditorBrowsableState.Never)]
3204 public virtual void ResetForeColor() {
3205 foreground_color = Color.Empty;
3208 [EditorBrowsable(EditorBrowsableState.Never)]
3209 public void ResetImeMode() {
3210 ime_mode = DefaultImeMode;
3213 [EditorBrowsable(EditorBrowsableState.Never)]
3214 public virtual void ResetRightToLeft() {
3215 right_to_left = RightToLeft.Inherit;
3218 public virtual void ResetText() {
3219 text = String.Empty;
3222 public void ResumeLayout() {
3223 ResumeLayout (true);
3226 public void ResumeLayout(bool performLayout) {
3227 if (layout_suspended > 0) {
3231 if (layout_suspended == 0) {
3232 Control [] controls = child_controls.GetAllControls ();
3233 for (int i=0; i<controls.Length; i++) {
3234 controls [i].UpdateDistances ();
3237 if (performLayout && layout_pending) {
3243 public void Scale(float ratio) {
3244 ScaleCore(ratio, ratio);
3247 public void Scale(float dx, float dy) {
3252 public void Scale(SizeF factor) {
3253 ScaleCore(factor.Width, factor.Height);
3257 public void Select() {
3258 Select(false, false);
3261 public bool SelectNextControl(Control ctl, bool forward, bool tabStopOnly, bool nested, bool wrap) {
3266 c = GetNextControl(c, forward);
3275 if (c.CanSelect && ((c.parent == this) || nested) && (c.tab_stop || !tabStopOnly)) {
3276 c.Select (true, true);
3279 } while (c != ctl); // If we wrap back to ourselves we stop
3284 public void SendToBack() {
3285 if (parent != null) {
3286 parent.child_controls.SetChildIndex(this, parent.child_controls.Count);
3290 public void SetBounds(int x, int y, int width, int height) {
3291 SetBounds(x, y, width, height, BoundsSpecified.All);
3294 public void SetBounds(int x, int y, int width, int height, BoundsSpecified specified) {
3295 if ((specified & BoundsSpecified.X) != BoundsSpecified.X) {
3299 if ((specified & BoundsSpecified.Y) != BoundsSpecified.Y) {
3303 if ((specified & BoundsSpecified.Width) != BoundsSpecified.Width) {
3307 if ((specified & BoundsSpecified.Height) != BoundsSpecified.Height) {
3311 SetBoundsCore(x, y, width, height, specified);
3312 if (parent != null) {
3313 parent.PerformLayout(this, "Bounds");
3317 public void Show() {
3319 this.CreateControl();
3325 public void SuspendLayout() {
3329 public void Update() {
3330 needs_redraw = true;
3331 if (IsHandleCreated) {
3332 XplatUI.UpdateWindow(window.Handle);
3335 #endregion // Public Instance Methods
3337 #region Protected Instance Methods
3338 [EditorBrowsable(EditorBrowsableState.Advanced)]
3339 [MonoTODO("Implement this and tie it into Control.ControlAccessibleObject.NotifyClients")]
3340 protected void AccessibilityNotifyClients(AccessibleEvents accEvent, int childID) {
3341 throw new NotImplementedException();
3344 [EditorBrowsable(EditorBrowsableState.Advanced)]
3345 protected virtual AccessibleObject CreateAccessibilityInstance() {
3346 return new Control.ControlAccessibleObject(this);
3349 [EditorBrowsable(EditorBrowsableState.Advanced)]
3350 protected virtual ControlCollection CreateControlsInstance() {
3351 return new ControlCollection(this);
3354 [EditorBrowsable(EditorBrowsableState.Advanced)]
3355 protected virtual void CreateHandle() {
3357 throw new ObjectDisposedException(GetType().FullName.ToString());
3360 if (IsHandleCreated && !is_recreating) {
3364 window.CreateHandle(CreateParams);
3366 if (window.Handle != IntPtr.Zero) {
3367 lock (Control.controls) {
3368 if (!Control.controls.Contains(window.Handle)) {
3369 Control.controls.Add(this);
3373 creator_thread = Thread.CurrentThread;
3375 XplatUI.EnableWindow(window.Handle, is_enabled);
3377 if (clip_region != null) {
3378 XplatUI.SetClipRegion(Handle, clip_region);
3381 // Set our handle with our parent
3382 if ((parent != null) && (parent.IsHandleCreated)) {
3383 XplatUI.SetParent(window.Handle, parent.Handle);
3386 // Set our handle as parent for our children
3387 Control [] children;
3389 children = child_controls.GetAllControls ();
3390 for (int i = 0; i < children.Length; i++ ) {
3391 if (children[i].IsHandleCreated) {
3392 XplatUI.SetParent(children[i].Handle, window.Handle);
3397 XplatUI.SetAllowDrop (Handle, allow_drop);
3399 // Find out where the window manager placed us
3400 if ((CreateParams.Style & (int)WindowStyles.WS_CHILD) != 0) {
3401 XplatUI.SetBorderStyle(window.Handle, (FormBorderStyle)border_style);
3405 OnHandleCreated(EventArgs.Empty);
3409 [EditorBrowsable(EditorBrowsableState.Advanced)]
3410 protected virtual void DefWndProc(ref Message m) {
3411 window.DefWndProc(ref m);
3414 [EditorBrowsable(EditorBrowsableState.Advanced)]
3415 protected virtual void DestroyHandle() {
3416 if (IsHandleCreated) {
3417 if (window != null) {
3418 window.DestroyHandle();
3423 protected bool GetStyle(ControlStyles flag) {
3424 return (control_style & flag) != 0;
3427 protected bool GetTopLevel() {
3431 [EditorBrowsable(EditorBrowsableState.Advanced)]
3432 protected virtual void InitLayout() {
3436 [EditorBrowsable(EditorBrowsableState.Advanced)]
3437 protected void InvokeGotFocus(Control toInvoke, EventArgs e) {
3438 toInvoke.OnGotFocus(e);
3441 [EditorBrowsable(EditorBrowsableState.Advanced)]
3442 protected void InvokeLostFocus(Control toInvoke, EventArgs e) {
3443 toInvoke.OnLostFocus(e);
3446 [EditorBrowsable(EditorBrowsableState.Advanced)]
3447 protected void InvokeOnClick(Control toInvoke, EventArgs e) {
3448 toInvoke.OnClick(e);
3451 protected void InvokePaint(Control toInvoke, PaintEventArgs e) {
3452 toInvoke.OnPaint(e);
3455 protected void InvokePaintBackground(Control toInvoke, PaintEventArgs e) {
3456 toInvoke.OnPaintBackground(e);
3459 protected virtual bool IsInputChar (char charCode) {
3463 protected virtual bool IsInputKey (Keys keyData) {
3464 // Doc says this one calls IsInputChar; not sure what to do with that
3468 [EditorBrowsable(EditorBrowsableState.Advanced)]
3469 protected virtual void NotifyInvalidate(Rectangle invalidatedArea) {
3473 protected virtual bool ProcessCmdKey(ref Message msg, Keys keyData) {
3474 if ((context_menu != null) && context_menu.ProcessCmdKey(ref msg, keyData)) {
3478 if (parent != null) {
3479 return parent.ProcessCmdKey(ref msg, keyData);
3485 protected virtual bool ProcessDialogChar(char charCode) {
3486 if (parent != null) {
3487 return parent.ProcessDialogChar (charCode);
3493 protected virtual bool ProcessDialogKey (Keys keyData) {
3494 if (parent != null) {
3495 return parent.ProcessDialogKey (keyData);
3501 protected virtual bool ProcessKeyEventArgs (ref Message msg)
3503 KeyEventArgs key_event;
3506 case (int)Msg.WM_SYSKEYDOWN:
3507 case (int)Msg.WM_KEYDOWN: {
3508 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
3509 OnKeyDown (key_event);
3510 return key_event.Handled;
3513 case (int)Msg.WM_SYSKEYUP:
3514 case (int)Msg.WM_KEYUP: {
3515 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
3516 OnKeyUp (key_event);
3517 return key_event.Handled;
3520 case (int)Msg.WM_SYSCHAR:
3521 case (int)Msg.WM_CHAR: {
3522 KeyPressEventArgs key_press_event;
3524 key_press_event = new KeyPressEventArgs((char)msg.WParam);
3525 OnKeyPress(key_press_event);
3527 msg.WParam = (IntPtr)key_press_event.KeyChar;
3529 return key_press_event.Handled;
3540 protected internal virtual bool ProcessKeyMessage(ref Message msg) {
3541 if (parent != null) {
3542 if (parent.ProcessKeyPreview(ref msg)) {
3547 return ProcessKeyEventArgs(ref msg);
3550 protected virtual bool ProcessKeyPreview(ref Message msg) {
3551 if (parent != null) {
3552 return parent.ProcessKeyPreview(ref msg);
3558 protected virtual bool ProcessMnemonic(char charCode) {
3563 [EditorBrowsable(EditorBrowsableState.Advanced)]
3564 protected void RaiseDragEvent(object key, DragEventArgs e) {
3568 [EditorBrowsable(EditorBrowsableState.Advanced)]
3569 protected void RaiseKeyEvent(object key, KeyEventArgs e) {
3573 [EditorBrowsable(EditorBrowsableState.Advanced)]
3574 protected void RaiseMouseEvent(object key, MouseEventArgs e) {
3578 [EditorBrowsable(EditorBrowsableState.Advanced)]
3579 protected void RaisePaintEvent(object key, PaintEventArgs e) {
3583 [EditorBrowsable(EditorBrowsableState.Advanced)]
3584 protected void RecreateHandle() {
3587 if (IsHandleCreated) {
3588 children_to_recreate = new ArrayList();
3589 children_to_recreate.AddRange (child_controls.GetAllControls ());
3591 // WM_DESTROY will CreateHandle for us
3599 parent.RemoveChildFromRecreateList (this);
3602 is_recreating = false;
3605 [EditorBrowsable(EditorBrowsableState.Advanced)]
3606 protected void ResetMouseEventArgs() {
3610 [EditorBrowsable(EditorBrowsableState.Advanced)]
3611 protected ContentAlignment RtlTranslateAlignment(ContentAlignment align) {
3612 if (right_to_left == RightToLeft.No) {
3617 case ContentAlignment.TopLeft: {
3618 return ContentAlignment.TopRight;
3621 case ContentAlignment.TopRight: {
3622 return ContentAlignment.TopLeft;
3625 case ContentAlignment.MiddleLeft: {
3626 return ContentAlignment.MiddleRight;
3629 case ContentAlignment.MiddleRight: {
3630 return ContentAlignment.MiddleLeft;
3633 case ContentAlignment.BottomLeft: {
3634 return ContentAlignment.BottomRight;
3637 case ContentAlignment.BottomRight: {
3638 return ContentAlignment.BottomLeft;
3642 // if it's center it doesn't change
3648 [EditorBrowsable(EditorBrowsableState.Advanced)]
3649 protected HorizontalAlignment RtlTranslateAlignment(HorizontalAlignment align) {
3650 if ((right_to_left == RightToLeft.No) || (align == HorizontalAlignment.Center)) {
3654 if (align == HorizontalAlignment.Left) {
3655 return HorizontalAlignment.Right;
3658 // align must be HorizontalAlignment.Right
3659 return HorizontalAlignment.Left;
3662 [EditorBrowsable(EditorBrowsableState.Advanced)]
3663 protected LeftRightAlignment RtlTranslateAlignment(LeftRightAlignment align) {
3664 if (right_to_left == RightToLeft.No) {
3668 if (align == LeftRightAlignment.Left) {
3669 return LeftRightAlignment.Right;
3672 // align must be LeftRightAlignment.Right;
3673 return LeftRightAlignment.Left;
3676 [EditorBrowsable(EditorBrowsableState.Advanced)]
3677 protected ContentAlignment RtlTranslateContent(ContentAlignment align) {
3678 return RtlTranslateAlignment(align);
3681 [EditorBrowsable(EditorBrowsableState.Advanced)]
3682 protected HorizontalAlignment RtlTranslateHorizontal(HorizontalAlignment align) {
3683 return RtlTranslateAlignment(align);
3686 [EditorBrowsable(EditorBrowsableState.Advanced)]
3687 protected LeftRightAlignment RtlTranslateLeftRight(LeftRightAlignment align) {
3688 return RtlTranslateAlignment(align);
3691 [EditorBrowsable(EditorBrowsableState.Advanced)]
3692 protected virtual void ScaleCore(float dx, float dy) {
3698 location = new Point((int)(Left * dx), (int)(Top * dy));
3699 size = this.ClientSize;
3701 if (!GetStyle(ControlStyles.FixedWidth)) {
3702 size.Width = (int)(size.Width * dx);
3705 if (!GetStyle(ControlStyles.FixedHeight)) {
3706 size.Height = (int)(size.Height * dy);
3709 SetBounds(location.X, location.Y, size.Width, size.Height, BoundsSpecified.All);
3711 /* Now scale our children */
3712 Control [] controls = child_controls.GetAllControls ();
3713 for (int i=0; i < controls.Length; i++) {
3714 controls[i].Scale(dx, dy);
3720 protected virtual void Select(bool directed, bool forward) {
3721 IContainerControl container;
3723 container = GetContainerControl();
3724 if (container != null)
3725 container.ActiveControl = this;
3728 [EditorBrowsable(EditorBrowsableState.Advanced)]
3729 protected virtual void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
3730 // SetBoundsCore updates the Win32 control itself. UpdateBounds updates the controls variables and fires events, I'm guessing - pdb
3731 if (IsHandleCreated) {
3732 XplatUI.SetWindowPos(Handle, x, y, width, height);
3735 UpdateBounds(x, y, width, height);
3740 [EditorBrowsable(EditorBrowsableState.Advanced)]
3741 protected virtual void SetClientSizeCore(int x, int y) {
3742 // Calculate the actual window size from the client size (it usually stays the same or grows)
3743 Rectangle ClientRect;
3744 Rectangle WindowRect;
3747 ClientRect = new Rectangle(0, 0, x, y);
3748 cp = this.CreateParams;
3750 if (XplatUI.CalculateWindowRect(ref ClientRect, cp.Style, cp.ExStyle, null, out WindowRect)==false) {
3754 SetBounds(bounds.X, bounds.Y, WindowRect.Width, WindowRect.Height, BoundsSpecified.Size);
3757 [EditorBrowsable(EditorBrowsableState.Advanced)]
3758 protected void SetStyle(ControlStyles flag, bool value) {
3760 control_style |= flag;
3762 control_style &= ~flag;
3766 protected void SetTopLevel(bool value) {
3767 if ((GetTopLevel() != value) && (parent != null)) {
3768 throw new Exception();
3772 if (value == true) {
3782 is_toplevel = value;
3785 protected virtual void SetVisibleCore(bool value) {
3786 if (value!=is_visible) {
3787 if (value && (window.Handle == IntPtr.Zero) || !is_created) {
3793 if (IsHandleCreated) {
3794 XplatUI.SetVisible(Handle, value);
3795 // Explicitly move Toplevel windows to where we want them;
3796 // apparently moving unmapped toplevel windows doesn't work
3797 if (is_visible && (this is Form)) {
3798 XplatUI.SetWindowPos(window.Handle, bounds.X, bounds.Y, bounds.Width, bounds.Height);
3802 OnVisibleChanged(EventArgs.Empty);
3804 if (value == false && parent != null && Focused) {
3807 // Need to start at parent, GetContainerControl might return ourselves if we're a container
3808 container = (Control)parent.GetContainerControl();
3809 if (container != null) {
3810 container.SelectNextControl(this, true, true, true, true);
3814 if (parent != null) {
3815 parent.PerformLayout(this, "visible");
3817 PerformLayout(this, "visible");
3822 [EditorBrowsable(EditorBrowsableState.Advanced)]
3823 protected void UpdateBounds() {
3831 if (!IsHandleCreated) {
3835 XplatUI.GetWindowPos(this.Handle, this is Form, out x, out y, out width, out height, out client_width, out client_height);
3837 UpdateBounds(x, y, width, height, client_width, client_height);
3840 [EditorBrowsable(EditorBrowsableState.Advanced)]
3841 protected void UpdateBounds(int x, int y, int width, int height) {
3845 // Calculate client rectangle
3846 rect = new Rectangle(0, 0, 0, 0);
3849 XplatUI.CalculateWindowRect(ref rect, cp.Style, cp.ExStyle, cp.menu, out rect);
3850 UpdateBounds(x, y, width, height, width - (rect.Right - rect.Left), height - (rect.Bottom - rect.Top));
3853 [EditorBrowsable(EditorBrowsableState.Advanced)]
3854 protected void UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) {
3855 // UpdateBounds only seems to set our sizes and fire events but not update the GUI window to match
3857 bool resized = false;
3859 // Needed to generate required notifications
3860 if ((this.bounds.X!=x) || (this.bounds.Y!=y)) {
3864 if ((this.Bounds.Width!=width) || (this.Bounds.Height!=height)) {
3871 bounds.Height=height;
3873 client_size.Width=clientWidth;
3874 client_size.Height=clientHeight;
3877 OnLocationChanged(EventArgs.Empty);
3881 OnSizeChanged(EventArgs.Empty);
3885 [EditorBrowsable(EditorBrowsableState.Advanced)]
3886 protected void UpdateStyles() {
3887 if (!IsHandleCreated) {
3891 XplatUI.SetWindowStyle(window.Handle, CreateParams);
3892 OnStyleChanged(EventArgs.Empty);
3895 private void UpdateZOrderOfChild(Control child) {
3896 if (IsHandleCreated && child.IsHandleCreated && (child.parent == this)) {
3899 index = child_controls.IndexOf(child);
3902 XplatUI.SetZOrder(child.Handle, child_controls[index - 1].Handle, false, false);
3904 XplatUI.SetZOrder(child.Handle, IntPtr.Zero, true, false);
3909 private void UpdateChildrenZOrder() {
3910 Control [] controls;
3912 if (!IsHandleCreated) {
3916 controls = child_controls.GetAllControls ();
3917 for (int i = 1; i < controls.Length; i++ ) {
3918 XplatUI.SetZOrder(controls[i].Handle, controls[i-1].Handle, false, false);
3922 [EditorBrowsable(EditorBrowsableState.Advanced)]
3923 protected void UpdateZOrder() {
3924 if (parent != null) {
3925 parent.UpdateZOrderOfChild(this);
3929 protected virtual void WndProc(ref Message m) {
3931 Console.WriteLine("Control {0} received message {1}", window.Handle == IntPtr.Zero ? this.Text : XplatUI.Window(window.Handle), (Msg)m.Msg);
3933 if ((this.control_style & ControlStyles.EnableNotifyMessage) != 0) {
3937 switch((Msg)m.Msg) {
3938 case Msg.WM_DESTROY: {
3939 OnHandleDestroyed(EventArgs.Empty);
3940 window.InvalidateHandle();
3942 if (ParentWaitingOnRecreation (this)) {
3944 } else if (is_recreating) {
3950 case Msg.WM_WINDOWPOSCHANGED: {
3953 if (GetStyle(ControlStyles.ResizeRedraw)) {
3960 // Nice description of what should happen when handling WM_PAINT
3961 // can be found here: http://pluralsight.com/wiki/default.aspx/Craig/FlickerFreeControlDrawing.html
3962 // and here http://msdn.microsoft.com/msdnmag/issues/06/03/WindowsFormsPerformance/
3963 case Msg.WM_PAINT: {
3964 PaintEventArgs paint_event;
3967 paint_event = XplatUI.PaintEventStart(Handle, true);
3968 reset_context = false;
3970 if (paint_event == null) {
3974 if (!needs_redraw) {
3975 // Just blit the previous image
3976 paint_event.Graphics.DrawImage (ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle, GraphicsUnit.Pixel);
3977 XplatUI.PaintEventEnd(Handle, true);
3982 Rectangle old_clip_rect = Rectangle.Empty;
3983 if (ThemeEngine.Current.DoubleBufferingSupported) {
3984 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
3985 old_clip_rect = paint_event.ClipRectangle;
3986 paint_event.ClipRectangle = ClientRectangle;
3987 dc = paint_event.SetGraphics (DeviceContext);
3988 reset_context = true;
3992 if (!GetStyle(ControlStyles.Opaque)) {
3993 OnPaintBackground(paint_event);
3996 // Button-derived controls choose to ignore their Opaque style, give them a chance to draw their background anyways
3997 OnPaintBackgroundInternal(paint_event);
3999 OnPaintInternal(paint_event);
4000 if (!paint_event.Handled) {
4001 OnPaint(paint_event);
4004 if (ThemeEngine.Current.DoubleBufferingSupported)
4005 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
4006 paint_event.ClipRectangle = old_clip_rect;
4007 dc.DrawImage (ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle, GraphicsUnit.Pixel);
4008 paint_event.SetGraphics (dc);
4009 needs_redraw = false;
4012 XplatUI.PaintEventEnd(Handle, true);
4014 if (reset_context) {
4015 ResetDeviceContext();
4021 case Msg.WM_ERASEBKGND: {
4022 // The DefWndProc will never have to handle this, we always paint the background in managed code
4023 // In theory this code would look at ControlStyles.AllPaintingInWmPaint and and call OnPaintBackground
4024 // here but it just makes things more complicated...
4025 m.Result = (IntPtr)1;
4029 case Msg.WM_LBUTTONUP: {
4032 me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Left,
4034 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4037 HandleClick(mouse_clicks, me);
4040 if (InternalCapture) {
4041 InternalCapture = false;
4044 if (mouse_clicks > 1) {
4050 case Msg.WM_LBUTTONDOWN: {
4052 Select (true, true);
4054 InternalCapture = true;
4055 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4056 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4062 case Msg.WM_LBUTTONDBLCLK: {
4063 InternalCapture = true;
4065 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4066 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4072 case Msg.WM_MBUTTONUP: {
4075 me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Middle,
4077 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4080 HandleClick(mouse_clicks, me);
4082 if (InternalCapture) {
4083 InternalCapture = false;
4085 if (mouse_clicks > 1) {
4091 case Msg.WM_MBUTTONDOWN: {
4092 InternalCapture = true;
4093 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4094 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4100 case Msg.WM_MBUTTONDBLCLK: {
4101 InternalCapture = true;
4103 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4104 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4109 case Msg.WM_RBUTTONUP: {
4113 pt = new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()));
4114 pt = PointToScreen(pt);
4116 XplatUI.SendMessage(m.HWnd, Msg.WM_CONTEXTMENU, m.HWnd, (IntPtr)(pt.X + (pt.Y << 16)));
4118 me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Right,
4120 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4123 HandleClick(mouse_clicks, me);
4126 if (InternalCapture) {
4127 InternalCapture = false;
4130 if (mouse_clicks > 1) {
4136 case Msg.WM_RBUTTONDOWN: {
4137 InternalCapture = true;
4138 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4139 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4144 case Msg.WM_RBUTTONDBLCLK: {
4145 InternalCapture = true;
4147 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4148 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4153 case Msg.WM_CONTEXTMENU: {
4154 if (context_menu != null) {
4157 pt = new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()));
4158 context_menu.Show(this, PointToClient(pt));
4166 case Msg.WM_MOUSEWHEEL: {
4168 OnMouseWheel (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4169 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4170 HighOrder(m.WParam.ToInt32())));
4175 case Msg.WM_MOUSEMOVE: {
4176 OnMouseMove (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4178 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4183 case Msg.WM_MOUSE_ENTER: {
4188 OnMouseEnter(EventArgs.Empty);
4192 case Msg.WM_MOUSE_LEAVE: {
4194 OnMouseLeave(EventArgs.Empty);
4198 case Msg.WM_MOUSEHOVER: {
4199 OnMouseHover(EventArgs.Empty);
4203 case Msg.WM_SYSKEYUP: {
4204 if (ProcessKeyMessage(ref m)) {
4205 m.Result = IntPtr.Zero;
4209 if ((m.WParam.ToInt32() & (int)Keys.KeyCode) == (int)Keys.Menu) {
4213 if (form != null && form.ActiveMenu != null) {
4214 form.ActiveMenu.ProcessCmdKey(ref m, (Keys)m.WParam.ToInt32());
4222 case Msg.WM_SYSKEYDOWN:
4223 case Msg.WM_KEYDOWN:
4225 case Msg.WM_SYSCHAR:
4227 if (ProcessKeyMessage(ref m)) {
4228 m.Result = IntPtr.Zero;
4237 if (m.LParam != IntPtr.Zero) {
4240 hi = new HELPINFO();
4242 hi = (HELPINFO) Marshal.PtrToStructure (m.LParam, typeof (HELPINFO));
4243 mouse_pos = new Point(hi.MousePos.x, hi.MousePos.y);
4245 mouse_pos = Control.MousePosition;
4247 OnHelpRequested(new HelpEventArgs(mouse_pos));
4248 m.Result = (IntPtr)1;
4252 case Msg.WM_KILLFOCUS: {
4253 this.has_focus = false;
4254 OnLostFocusInternal (EventArgs.Empty);
4258 case Msg.WM_SETFOCUS: {
4260 this.has_focus = true;
4261 OnGotFocusInternal (EventArgs.Empty);
4267 case Msg.WM_SYSCOLORCHANGE: {
4268 ThemeEngine.Current.ResetDefaults();
4269 OnSystemColorsChanged(EventArgs.Empty);
4274 case Msg.WM_SETCURSOR: {
4275 if ((cursor == null) || ((HitTest)(m.LParam.ToInt32() & 0xffff) != HitTest.HTCLIENT)) {
4280 XplatUI.SetCursor(window.Handle, cursor.handle);
4281 m.Result = (IntPtr)1;
4292 #endregion // Public Instance Methods
4294 #region OnXXX methods
4295 [EditorBrowsable(EditorBrowsableState.Advanced)]
4296 protected virtual void OnBackColorChanged(EventArgs e) {
4297 if (BackColorChanged!=null) BackColorChanged(this, e);
4298 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackColorChanged(e);
4301 [EditorBrowsable(EditorBrowsableState.Advanced)]
4302 protected virtual void OnBackgroundImageChanged(EventArgs e) {
4303 if (BackgroundImageChanged!=null) BackgroundImageChanged(this, e);
4304 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackgroundImageChanged(e);
4307 [EditorBrowsable(EditorBrowsableState.Advanced)]
4308 protected virtual void OnBindingContextChanged(EventArgs e) {
4309 CheckDataBindings ();
4310 if (BindingContextChanged!=null) {
4311 BindingContextChanged(this, e);
4313 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBindingContextChanged(e);
4316 [EditorBrowsable(EditorBrowsableState.Advanced)]
4317 protected virtual void OnCausesValidationChanged(EventArgs e) {
4318 if (CausesValidationChanged!=null) CausesValidationChanged(this, e);
4321 [EditorBrowsable(EditorBrowsableState.Advanced)]
4322 protected virtual void OnChangeUICues(UICuesEventArgs e) {
4323 if (ChangeUICues!=null) ChangeUICues(this, e);
4326 [EditorBrowsable(EditorBrowsableState.Advanced)]
4327 protected virtual void OnClick(EventArgs e) {
4328 if (Click!=null) Click(this, e);
4331 [EditorBrowsable(EditorBrowsableState.Advanced)]
4332 protected virtual void OnContextMenuChanged(EventArgs e) {
4333 if (ContextMenuChanged!=null) ContextMenuChanged(this, e);
4336 [EditorBrowsable(EditorBrowsableState.Advanced)]
4337 protected virtual void OnControlAdded(ControlEventArgs e) {
4338 if (ControlAdded!=null) ControlAdded(this, e);
4341 [EditorBrowsable(EditorBrowsableState.Advanced)]
4342 protected virtual void OnControlRemoved(ControlEventArgs e) {
4343 if (ControlRemoved!=null) ControlRemoved(this, e);
4346 [EditorBrowsable(EditorBrowsableState.Advanced)]
4347 protected virtual void OnCreateControl() {
4351 [EditorBrowsable(EditorBrowsableState.Advanced)]
4352 protected virtual void OnCursorChanged(EventArgs e) {
4353 if (CursorChanged!=null) CursorChanged(this, e);
4356 [EditorBrowsable(EditorBrowsableState.Advanced)]
4357 protected virtual void OnDockChanged(EventArgs e) {
4358 if (DockChanged!=null) DockChanged(this, e);
4361 [EditorBrowsable(EditorBrowsableState.Advanced)]
4362 protected virtual void OnDoubleClick(EventArgs e) {
4363 if (DoubleClick!=null) DoubleClick(this, e);
4366 [EditorBrowsable(EditorBrowsableState.Advanced)]
4367 protected virtual void OnDragDrop(DragEventArgs drgevent) {
4368 if (DragDrop!=null) DragDrop(this, drgevent);
4371 [EditorBrowsable(EditorBrowsableState.Advanced)]
4372 protected virtual void OnDragEnter(DragEventArgs drgevent) {
4373 if (DragEnter!=null) DragEnter(this, drgevent);
4376 [EditorBrowsable(EditorBrowsableState.Advanced)]
4377 protected virtual void OnDragLeave(EventArgs e) {
4378 if (DragLeave!=null) DragLeave(this, e);
4381 [EditorBrowsable(EditorBrowsableState.Advanced)]
4382 protected virtual void OnDragOver(DragEventArgs drgevent) {
4383 if (DragOver!=null) DragOver(this, drgevent);
4386 [EditorBrowsable(EditorBrowsableState.Advanced)]
4387 protected virtual void OnEnabledChanged(EventArgs e) {
4388 if (IsHandleCreated) {
4390 if (((Form)this).context == null) {
4391 XplatUI.EnableWindow(window.Handle, Enabled);
4394 XplatUI.EnableWindow(window.Handle, Enabled);
4399 if (EnabledChanged != null) {
4400 EnabledChanged(this, e);
4403 for (int i=0; i<child_controls.Count; i++) {
4404 child_controls[i].OnParentEnabledChanged(e);
4408 [EditorBrowsable(EditorBrowsableState.Advanced)]
4409 protected virtual void OnEnter(EventArgs e) {
4410 if (Enter!=null) Enter(this, e);
4413 [EditorBrowsable(EditorBrowsableState.Advanced)]
4414 protected virtual void OnFontChanged(EventArgs e) {
4415 if (FontChanged!=null) FontChanged(this, e);
4416 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentFontChanged(e);
4419 [EditorBrowsable(EditorBrowsableState.Advanced)]
4420 protected virtual void OnForeColorChanged(EventArgs e) {
4421 if (ForeColorChanged!=null) ForeColorChanged(this, e);
4422 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentForeColorChanged(e);
4425 [EditorBrowsable(EditorBrowsableState.Advanced)]
4426 protected virtual void OnGiveFeedback(GiveFeedbackEventArgs gfbevent) {
4427 if (GiveFeedback!=null) GiveFeedback(this, gfbevent);
4430 [EditorBrowsable(EditorBrowsableState.Advanced)]
4431 protected virtual void OnGotFocus(EventArgs e) {
4432 if (GotFocus!=null) GotFocus(this, e);
4435 [EditorBrowsable(EditorBrowsableState.Advanced)]
4436 protected virtual void OnHandleCreated(EventArgs e) {
4437 if (HandleCreated!=null) HandleCreated(this, e);
4440 [EditorBrowsable(EditorBrowsableState.Advanced)]
4441 protected virtual void OnHandleDestroyed(EventArgs e) {
4442 if (HandleDestroyed!=null) HandleDestroyed(this, e);
4445 [EditorBrowsable(EditorBrowsableState.Advanced)]
4446 protected virtual void OnHelpRequested(HelpEventArgs hevent) {
4447 if (HelpRequested!=null) HelpRequested(this, hevent);
4450 protected virtual void OnImeModeChanged(EventArgs e) {
4451 if (ImeModeChanged!=null) ImeModeChanged(this, e);
4454 [EditorBrowsable(EditorBrowsableState.Advanced)]
4455 protected virtual void OnInvalidated(InvalidateEventArgs e) {
4456 needs_redraw = true;
4457 if (Invalidated!=null) Invalidated(this, e);
4460 [EditorBrowsable(EditorBrowsableState.Advanced)]
4461 protected virtual void OnKeyDown(KeyEventArgs e) {
4462 if (KeyDown!=null) KeyDown(this, e);
4465 [EditorBrowsable(EditorBrowsableState.Advanced)]
4466 protected virtual void OnKeyPress(KeyPressEventArgs e) {
4467 if (KeyPress!=null) KeyPress(this, e);
4470 [EditorBrowsable(EditorBrowsableState.Advanced)]
4471 protected virtual void OnKeyUp(KeyEventArgs e) {
4472 if (KeyUp!=null) KeyUp(this, e);
4475 [EditorBrowsable(EditorBrowsableState.Advanced)]
4476 protected virtual void OnLayout(LayoutEventArgs levent) {
4477 if (Layout!=null) Layout(this, levent);
4480 [EditorBrowsable(EditorBrowsableState.Advanced)]
4481 protected virtual void OnLeave(EventArgs e) {
4482 if (Leave!=null) Leave(this, e);
4485 [EditorBrowsable(EditorBrowsableState.Advanced)]
4486 protected virtual void OnLocationChanged(EventArgs e) {
4488 if (LocationChanged!=null) LocationChanged(this, e);
4491 [EditorBrowsable(EditorBrowsableState.Advanced)]
4492 protected virtual void OnLostFocus(EventArgs e) {
4493 if (LostFocus!=null) LostFocus(this, e);
4496 [EditorBrowsable(EditorBrowsableState.Advanced)]
4497 protected virtual void OnMouseDown(MouseEventArgs e) {
4498 if (MouseDown!=null) MouseDown(this, e);
4501 [EditorBrowsable(EditorBrowsableState.Advanced)]
4502 protected virtual void OnMouseEnter(EventArgs e) {
4503 if (MouseEnter!=null) MouseEnter(this, e);
4506 [EditorBrowsable(EditorBrowsableState.Advanced)]
4507 protected virtual void OnMouseHover(EventArgs e) {
4508 if (MouseHover!=null) MouseHover(this, e);
4511 [EditorBrowsable(EditorBrowsableState.Advanced)]
4512 protected virtual void OnMouseLeave(EventArgs e) {
4513 if (MouseLeave!=null) MouseLeave(this, e);
4516 [EditorBrowsable(EditorBrowsableState.Advanced)]
4517 protected virtual void OnMouseMove(MouseEventArgs e) {
4518 if (MouseMove!=null) MouseMove(this, e);
4521 [EditorBrowsable(EditorBrowsableState.Advanced)]
4522 protected virtual void OnMouseUp(MouseEventArgs e) {
4523 if (MouseUp!=null) MouseUp(this, e);
4526 [EditorBrowsable(EditorBrowsableState.Advanced)]
4527 protected virtual void OnMouseWheel(MouseEventArgs e) {
4528 if (MouseWheel!=null) MouseWheel(this, e);
4531 [EditorBrowsable(EditorBrowsableState.Advanced)]
4532 protected virtual void OnMove(EventArgs e) {
4533 if (Move!=null) Move(this, e);
4536 [EditorBrowsable(EditorBrowsableState.Advanced)]
4537 protected virtual void OnNotifyMessage(Message m) {
4541 [EditorBrowsable(EditorBrowsableState.Advanced)]
4542 protected virtual void OnPaint(PaintEventArgs e) {
4543 if (Paint!=null) Paint(this, e);
4546 internal virtual void OnPaintBackgroundInternal(PaintEventArgs e) {
4550 internal virtual void OnPaintInternal(PaintEventArgs e) {
4554 internal virtual void OnGotFocusInternal (EventArgs e)
4559 internal virtual void OnLostFocusInternal (EventArgs e)
4564 [EditorBrowsable(EditorBrowsableState.Advanced)]
4565 protected virtual void OnPaintBackground(PaintEventArgs pevent) {
4566 PaintControlBackground (pevent);
4569 [EditorBrowsable(EditorBrowsableState.Advanced)]
4570 protected virtual void OnParentBackColorChanged(EventArgs e) {
4571 if (background_color.IsEmpty && background_image==null) {
4573 OnBackColorChanged(e);
4577 [EditorBrowsable(EditorBrowsableState.Advanced)]
4578 protected virtual void OnParentBackgroundImageChanged(EventArgs e) {
4579 if (background_color.IsEmpty && background_image==null) {
4581 OnBackgroundImageChanged(e);
4585 [EditorBrowsable(EditorBrowsableState.Advanced)]
4586 protected virtual void OnParentBindingContextChanged(EventArgs e) {
4587 if (binding_context==null) {
4588 binding_context=Parent.binding_context;
4589 OnBindingContextChanged(e);
4593 [EditorBrowsable(EditorBrowsableState.Advanced)]
4594 protected virtual void OnParentChanged(EventArgs e) {
4595 if (ParentChanged!=null) ParentChanged(this, e);
4598 [EditorBrowsable(EditorBrowsableState.Advanced)]
4599 protected virtual void OnParentEnabledChanged(EventArgs e) {
4601 OnEnabledChanged(e);
4605 [EditorBrowsable(EditorBrowsableState.Advanced)]
4606 protected virtual void OnParentFontChanged(EventArgs e) {
4613 [EditorBrowsable(EditorBrowsableState.Advanced)]
4614 protected virtual void OnParentForeColorChanged(EventArgs e) {
4615 if (foreground_color.IsEmpty) {
4617 OnForeColorChanged(e);
4621 [EditorBrowsable(EditorBrowsableState.Advanced)]
4622 protected virtual void OnParentRightToLeftChanged(EventArgs e) {
4623 if (right_to_left==RightToLeft.Inherit) {
4625 OnRightToLeftChanged(e);
4629 [EditorBrowsable(EditorBrowsableState.Advanced)]
4630 protected virtual void OnParentVisibleChanged(EventArgs e) {
4632 OnVisibleChanged(e);
4636 [EditorBrowsable(EditorBrowsableState.Advanced)]
4637 protected virtual void OnQueryContinueDrag(QueryContinueDragEventArgs e) {
4638 if (QueryContinueDrag!=null) QueryContinueDrag(this, e);
4641 [EditorBrowsable(EditorBrowsableState.Advanced)]
4642 protected virtual void OnResize(EventArgs e) {
4643 if (Resize!=null) Resize(this, e);
4645 PerformLayout(this, "bounds");
4647 if (parent != null) {
4648 parent.PerformLayout();
4652 [EditorBrowsable(EditorBrowsableState.Advanced)]
4653 protected virtual void OnRightToLeftChanged(EventArgs e) {
4654 if (RightToLeftChanged!=null) RightToLeftChanged(this, e);
4655 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentRightToLeftChanged(e);
4658 [EditorBrowsable(EditorBrowsableState.Advanced)]
4659 protected virtual void OnSizeChanged(EventArgs e) {
4660 InvalidateBuffers ();
4662 if (SizeChanged!=null) SizeChanged(this, e);
4665 [EditorBrowsable(EditorBrowsableState.Advanced)]
4666 protected virtual void OnStyleChanged(EventArgs e) {
4667 if (StyleChanged!=null) StyleChanged(this, e);
4670 [EditorBrowsable(EditorBrowsableState.Advanced)]
4671 protected virtual void OnSystemColorsChanged(EventArgs e) {
4672 if (SystemColorsChanged!=null) SystemColorsChanged(this, e);
4675 [EditorBrowsable(EditorBrowsableState.Advanced)]
4676 protected virtual void OnTabIndexChanged(EventArgs e) {
4677 if (TabIndexChanged!=null) TabIndexChanged(this, e);
4680 [EditorBrowsable(EditorBrowsableState.Advanced)]
4681 protected virtual void OnTabStopChanged(EventArgs e) {
4682 if (TabStopChanged!=null) TabStopChanged(this, e);
4685 [EditorBrowsable(EditorBrowsableState.Advanced)]
4686 protected virtual void OnTextChanged(EventArgs e) {
4687 if (TextChanged!=null) TextChanged(this, e);
4690 [EditorBrowsable(EditorBrowsableState.Advanced)]
4691 protected virtual void OnValidated(EventArgs e) {
4692 if (Validated!=null) Validated(this, e);
4695 [EditorBrowsable(EditorBrowsableState.Advanced)]
4696 protected virtual void OnValidating(System.ComponentModel.CancelEventArgs e) {
4697 if (Validating!=null) Validating(this, e);
4700 [EditorBrowsable(EditorBrowsableState.Advanced)]
4701 protected virtual void OnVisibleChanged(EventArgs e) {
4702 if ((parent != null) && !Created && Visible) {
4709 needs_redraw = true;
4711 if (VisibleChanged!=null) VisibleChanged(this, e);
4713 // We need to tell our kids
4714 for (int i=0; i<child_controls.Count; i++) {
4715 if (child_controls[i].Visible) {
4716 child_controls[i].OnParentVisibleChanged(e);
4720 #endregion // OnXXX methods
4723 public event EventHandler BackColorChanged;
4724 public event EventHandler BackgroundImageChanged;
4725 public event EventHandler BindingContextChanged;
4726 public event EventHandler CausesValidationChanged;
4727 public event UICuesEventHandler ChangeUICues;
4728 public event EventHandler Click;
4729 public event EventHandler ContextMenuChanged;
4731 [EditorBrowsable(EditorBrowsableState.Advanced)]
4733 public event ControlEventHandler ControlAdded;
4735 [EditorBrowsable(EditorBrowsableState.Advanced)]
4737 public event ControlEventHandler ControlRemoved;
4739 [MWFDescription("Fired when the cursor for the control has been changed"), MWFCategory("PropertyChanged")]
4740 public event EventHandler CursorChanged;
4741 public event EventHandler DockChanged;
4742 public event EventHandler DoubleClick;
4743 public event DragEventHandler DragDrop;
4744 public event DragEventHandler DragEnter;
4745 public event EventHandler DragLeave;
4746 public event DragEventHandler DragOver;
4747 public event EventHandler EnabledChanged;
4748 public event EventHandler Enter;
4749 public event EventHandler FontChanged;
4750 public event EventHandler ForeColorChanged;
4751 public event GiveFeedbackEventHandler GiveFeedback;
4753 [EditorBrowsable(EditorBrowsableState.Advanced)]
4755 public event EventHandler GotFocus;
4757 [EditorBrowsable(EditorBrowsableState.Advanced)]
4759 public event EventHandler HandleCreated;
4761 [EditorBrowsable(EditorBrowsableState.Advanced)]
4763 public event EventHandler HandleDestroyed;
4765 public event HelpEventHandler HelpRequested;
4766 public event EventHandler ImeModeChanged;
4768 [EditorBrowsable(EditorBrowsableState.Advanced)]
4770 public event InvalidateEventHandler Invalidated;
4772 public event KeyEventHandler KeyDown;
4773 public event KeyPressEventHandler KeyPress;
4774 public event KeyEventHandler KeyUp;
4775 public event LayoutEventHandler Layout;
4776 public event EventHandler Leave;
4777 public event EventHandler LocationChanged;
4779 [EditorBrowsable(EditorBrowsableState.Advanced)]
4781 public event EventHandler LostFocus;
4783 public event MouseEventHandler MouseDown;
4784 public event EventHandler MouseEnter;
4785 public event EventHandler MouseHover;
4786 public event EventHandler MouseLeave;
4787 public event MouseEventHandler MouseMove;
4788 public event MouseEventHandler MouseUp;
4790 [EditorBrowsable(EditorBrowsableState.Advanced)]
4792 public event MouseEventHandler MouseWheel;
4794 public event EventHandler Move;
4795 public event PaintEventHandler Paint;
4796 public event EventHandler ParentChanged;
4797 public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp;
4798 public event QueryContinueDragEventHandler QueryContinueDrag;
4799 public event EventHandler Resize;
4800 public event EventHandler RightToLeftChanged;
4801 public event EventHandler SizeChanged;
4802 public event EventHandler StyleChanged;
4803 public event EventHandler SystemColorsChanged;
4804 public event EventHandler TabIndexChanged;
4805 public event EventHandler TabStopChanged;
4806 public event EventHandler TextChanged;
4807 public event EventHandler Validated;
4808 public event CancelEventHandler Validating;
4809 public event EventHandler VisibleChanged;
4810 #endregion // Events