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
38 using System.ComponentModel;
39 using System.ComponentModel.Design;
40 using System.ComponentModel.Design.Serialization;
41 using System.Collections;
42 using System.Diagnostics;
44 using System.Drawing.Drawing2D;
45 using System.Reflection;
46 using System.Runtime.InteropServices;
47 using System.Security;
48 using System.Threading;
50 namespace System.Windows.Forms
52 [Designer("System.Windows.Forms.Design.ControlDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
53 [DefaultProperty("Text")]
54 [DefaultEvent("Click")]
55 [DesignerSerializer("System.Windows.Forms.Design.ControlCodeDomSerializer, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
56 [ToolboxItemFilter("System.Windows.Forms")]
57 public class Control : Component, ISynchronizeInvoke, IWin32Window
59 #region Local Variables
62 internal Rectangle bounds; // bounding rectangle for control (client area + decorations)
63 internal object creator_thread; // thread that created the control
64 internal ControlNativeWindow window; // object for native window handle
65 internal string name; // for object naming
68 internal bool is_created; // true if OnCreateControl has been sent
69 internal bool has_focus; // true if control has focus
70 internal bool is_visible; // true if control is visible
71 internal bool is_entered; // is the mouse inside the control?
72 internal bool is_enabled; // true if control is enabled (usable/not grayed out)
73 internal bool is_accessible; // true if the control is visible to accessibility applications
74 internal bool is_captured; // tracks if the control has captured the mouse
75 internal bool is_toplevel; // tracks if the control is a toplevel window
76 internal bool is_recreating; // tracks if the handle for the control is being recreated
77 internal bool causes_validation; // tracks if validation is executed on changes
78 internal int tab_index; // position in tab order of siblings
79 internal bool tab_stop = true; // is the control a tab stop?
80 internal bool is_disposed; // has the window already been disposed?
81 internal Size client_size; // size of the client area (window excluding decorations)
82 internal Rectangle client_rect; // rectangle with the client area (window excluding decorations)
83 internal ControlStyles control_style; // rather win32-specific, style bits for control
84 internal ImeMode ime_mode = ImeMode.Inherit;
85 internal bool layout_pending; // true if our parent needs to re-layout us
86 internal object control_tag; // object that contains data about our control
87 internal int mouse_clicks; // Counter for mouse clicks
88 internal Cursor cursor; // Cursor for the window
89 internal bool allow_drop; // true if the control accepts droping objects on it
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 Bitmap bmp_mem; // Bitmap for double buffering control
120 private Region invalid_region;
122 private ControlBindingsCollection data_bindings;
125 internal bool use_compatible_text_rendering;
126 static internal bool verify_thread_handle;
127 private Padding padding;
128 private Size maximum_size;
129 private Size minimum_size;
130 private Size preferred_size;
131 private Padding margin;
132 internal Layout.LayoutEngine layout_engine;
135 #endregion // Local Variables
137 #region Private Classes
138 // This helper class allows us to dispatch messages to Control.WndProc
139 internal class ControlNativeWindow : NativeWindow {
140 private Control owner;
142 public ControlNativeWindow(Control control) : base() {
147 public Control Owner {
153 static internal Control ControlFromHandle(IntPtr hWnd) {
154 ControlNativeWindow window;
156 window = (ControlNativeWindow)window_collection[hWnd];
157 if (window != null) {
164 static internal Control ControlFromChildHandle (IntPtr handle) {
165 ControlNativeWindow window;
167 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
168 while (hwnd != null) {
169 window = (ControlNativeWindow)window_collection[hwnd.Handle];
170 if (window != null) {
179 protected override void WndProc(ref Message m) {
180 owner.WndProc(ref m);
185 #region Public Classes
187 public class ControlAccessibleObject : AccessibleObject {
188 #region ControlAccessibleObject Constructors
189 public ControlAccessibleObject(Control ownerControl) {
190 this.owner = ownerControl;
192 #endregion // ControlAccessibleObject Constructors
194 #region ControlAccessibleObject Public Instance Properties
195 public override string DefaultAction {
197 return base.DefaultAction;
201 public override string Description {
203 return base.Description;
207 public IntPtr Handle {
213 // We don't want to let them set it
217 public override string Help {
223 public override string KeyboardShortcut {
225 return base.KeyboardShortcut;
229 public override string Name {
239 public Control Owner {
245 public override AccessibleObject Parent {
252 public override AccessibleRole Role {
257 #endregion // ControlAccessibleObject Public Instance Properties
259 #region ControlAccessibleObject Public Instance Methods
260 public override int GetHelpTopic(out string FileName) {
261 return base.GetHelpTopic (out FileName);
264 [MonoTODO("Implement this and tie it into Control.AccessibilityNotifyClients")]
265 public void NotifyClients(AccessibleEvents accEvent) {
266 throw new NotImplementedException();
269 [MonoTODO("Implement this and tie it into Control.AccessibilityNotifyClients")]
270 public void NotifyClients(AccessibleEvents accEvent, int childID) {
271 throw new NotImplementedException();
274 public override string ToString() {
275 return "ControlAccessibleObject: Owner = " + owner.ToString() + ", Text: " + owner.text;
278 #endregion // ControlAccessibleObject Public Instance Methods
281 [DesignerSerializer("System.Windows.Forms.Design.ControlCollectionCodeDomSerializer, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
282 [ListBindable(false)]
283 public class ControlCollection : IList, ICollection, ICloneable, IEnumerable {
284 #region ControlCollection Local Variables
285 private ArrayList list;
286 internal ArrayList impl_list;
287 private Control [] all_controls;
288 internal Control owner;
289 #endregion // ControlCollection Local Variables
291 #region ControlCollection Public Constructor
292 public ControlCollection(Control owner) {
294 this.list=new ArrayList();
298 #region ControlCollection Public Instance Properties
305 public bool IsReadOnly {
307 return list.IsReadOnly;
311 public virtual Control this[int index] {
313 if (index < 0 || index >= list.Count) {
314 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
316 return (Control)list[index];
319 #endregion // ControlCollection Public Instance Properties
321 #region ControlCollection Private Instance Methods
322 public virtual void Add (Control value)
327 if (Contains (value)) {
328 owner.PerformLayout();
332 if (value.tab_index == -1) {
338 end = owner.child_controls.Count;
339 for (int i = 0; i < end; i++) {
340 index = owner.child_controls[i].tab_index;
345 value.tab_index = use;
348 if (value.parent != null) {
349 value.parent.Controls.Remove(value);
355 value.ChangeParent(owner);
359 owner.UpdateChildrenZOrder();
360 owner.PerformLayout(value, "Parent");
361 owner.OnControlAdded(new ControlEventArgs(value));
364 internal void AddToList (Control c)
370 internal virtual void AddImplicit (Control control)
372 if (impl_list == null)
373 impl_list = new ArrayList ();
375 if (AllContains (control))
379 impl_list.Add (control);
381 control.ChangeParent (owner);
382 control.InitLayout ();
383 owner.UpdateChildrenZOrder ();
384 owner.PerformLayout (control, "Parent");
385 owner.OnControlAdded (new ControlEventArgs (control));
388 public virtual void AddRange (Control[] controls)
390 if (controls == null)
391 throw new ArgumentNullException ("controls");
393 owner.SuspendLayout ();
396 for (int i = 0; i < controls.Length; i++)
399 owner.ResumeLayout ();
403 internal virtual void AddRangeImplicit (Control [] controls)
405 if (controls == null)
406 throw new ArgumentNullException ("controls");
408 owner.SuspendLayout ();
411 for (int i = 0; i < controls.Length; i++)
412 AddImplicit (controls [i]);
414 owner.ResumeLayout ();
418 public virtual void Clear ()
422 // MS sends remove events in reverse order
423 while (list.Count > 0) {
424 Remove((Control)list[list.Count - 1]);
428 internal virtual void ClearImplicit ()
430 if (impl_list == null)
436 public bool Contains (Control value)
438 for (int i = list.Count; i > 0; ) {
441 if (list [i] == value) {
442 // Do we need to do anything here?
449 internal bool ImplicitContains (Control value)
451 if (impl_list == null)
454 for (int i = impl_list.Count; i > 0; ) {
457 if (impl_list [i] == value) {
458 // Do we need to do anything here?
465 internal bool AllContains (Control value)
467 return Contains (value) || ImplicitContains (value);
470 public void CopyTo (Array array, int index)
472 list.CopyTo(array, index);
475 public override bool Equals(object other) {
476 if (other is ControlCollection && (((ControlCollection)other).owner==this.owner)) {
483 public int GetChildIndex(Control child) {
484 return GetChildIndex(child, false);
487 public int GetChildIndex(Control child, bool throwException) {
490 index=list.IndexOf(child);
492 if (index==-1 && throwException) {
493 throw new ArgumentException("Not a child control", "child");
498 public IEnumerator GetEnumerator() {
499 return list.GetEnumerator();
502 internal IEnumerator GetAllEnumerator ()
504 Control [] res = GetAllControls ();
505 return res.GetEnumerator ();
508 internal Control [] GetAllControls ()
510 if (all_controls != null)
513 if (impl_list == null) {
514 all_controls = (Control []) list.ToArray (typeof (Control));
518 all_controls = new Control [list.Count + impl_list.Count];
519 impl_list.CopyTo (all_controls);
520 list.CopyTo (all_controls, impl_list.Count);
525 public override int GetHashCode() {
526 return base.GetHashCode();
529 public int IndexOf(Control control) {
530 return list.IndexOf(control);
533 public virtual void Remove(Control value) {
534 owner.PerformLayout(value, "Parent");
535 owner.OnControlRemoved(new ControlEventArgs(value));
540 value.ChangeParent(null);
542 owner.UpdateChildrenZOrder();
545 internal virtual void RemoveImplicit (Control control)
547 if (impl_list != null) {
549 owner.PerformLayout (control, "Parent");
550 owner.OnControlRemoved (new ControlEventArgs (control));
551 impl_list.Remove (control);
553 control.ChangeParent (null);
554 owner.UpdateChildrenZOrder ();
557 public void RemoveAt(int index) {
558 if (index < 0 || index >= list.Count) {
559 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
561 Remove ((Control)list[index]);
564 public void SetChildIndex(Control child, int newIndex) {
567 old_index=list.IndexOf(child);
569 throw new ArgumentException("Not a child control", "child");
572 if (old_index==newIndex) {
577 list.RemoveAt(old_index);
579 if (newIndex>list.Count) {
582 list.Insert(newIndex, child);
584 child.UpdateZOrder();
585 owner.PerformLayout();
587 #endregion // ControlCollection Private Instance Methods
589 #region ControlCollection Interface Properties
590 object IList.this[int index] {
592 if (index<0 || index>=list.Count) {
593 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
599 if (!(value is Control)) {
600 throw new ArgumentException("Object of type Control required", "value");
604 Control ctrl = (Control) value;
607 ctrl.ChangeParent(owner);
611 owner.UpdateChildrenZOrder();
612 owner.PerformLayout(ctrl, "Parent");
616 bool IList.IsFixedSize {
622 bool ICollection.IsSynchronized {
624 return list.IsSynchronized;
628 object ICollection.SyncRoot {
630 return list.SyncRoot;
633 #endregion // ControlCollection Interface Properties
635 #region ControlCollection Interface Methods
636 int IList.Add(object value) {
638 throw new ArgumentNullException("value", "Cannot add null controls");
641 if (!(value is Control)) {
642 throw new ArgumentException("Object of type Control required", "value");
645 return list.Add(value);
648 bool IList.Contains(object value) {
649 if (!(value is Control)) {
650 throw new ArgumentException("Object of type Control required", "value");
653 return this.Contains((Control) value);
656 int IList.IndexOf(object value) {
657 if (!(value is Control)) {
658 throw new ArgumentException("Object of type Control required", "value");
661 return this.IndexOf((Control) value);
664 void IList.Insert(int index, object value) {
665 if (!(value is Control)) {
666 throw new ArgumentException("Object of type Control required", "value");
669 list.Insert(index, value);
672 void IList.Remove(object value) {
673 if (!(value is Control)) {
674 throw new ArgumentException("Object of type Control required", "value");
680 Object ICloneable.Clone() {
681 ControlCollection clone = new ControlCollection(this.owner);
682 clone.list=(ArrayList)list.Clone(); // FIXME: Do we need this?
685 #endregion // ControlCollection Interface Methods
687 #endregion // ControlCollection Class
689 #region Public Constructors
692 anchor_style = AnchorStyles.Top | AnchorStyles.Left;
700 layout_pending = false;
702 causes_validation = true;
704 layout_suspended = 0;
708 right_to_left = RightToLeft.Inherit;
709 border_style = BorderStyle.None;
710 background_color = Color.Empty;
717 use_compatible_text_rendering = Application.use_compatible_text_rendering;
718 padding = new Padding(0);
719 maximum_size = new Size();
720 minimum_size = new Size();
721 preferred_size = new Size();
722 margin = this.DefaultMargin;
723 layout_engine = new Layout.DefaultLayout();
726 control_style = ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint |
727 ControlStyles.Selectable | ControlStyles.StandardClick |
728 ControlStyles.StandardDoubleClick;
731 background_image = null;
735 window = new ControlNativeWindow(this);
736 child_controls = CreateControlsInstance();
737 client_size = new Size(DefaultSize.Width, DefaultSize.Height);
738 client_rect = new Rectangle(0, 0, DefaultSize.Width, DefaultSize.Height);
739 XplatUI.CalculateWindowRect(ref client_rect, CreateParams.Style, CreateParams.ExStyle, null, out bounds);
740 if ((CreateParams.Style & (int)WindowStyles.WS_CHILD) == 0) {
746 public Control(Control parent, string text) : this() {
751 public Control(Control parent, string text, int left, int top, int width, int height) : this() {
756 bounds.Height=height;
757 SetBounds(left, top, width, height, BoundsSpecified.All);
761 public Control(string text) : this() {
765 public Control(string text, int left, int top, int width, int height) : this() {
769 bounds.Height=height;
770 SetBounds(left, top, width, height, BoundsSpecified.All);
774 private delegate void RemoveDelegate(object c);
776 protected override void Dispose(bool disposing) {
790 if (invalid_region!=null) {
791 invalid_region.Dispose();
794 if (this.InvokeRequired) {
795 if (Application.MessageLoop) {
796 this.BeginInvokeInternal(new MethodInvoker(DestroyHandle), null, true);
797 this.BeginInvokeInternal(new RemoveDelegate(controls.Remove), new object[] {this}, true);
801 lock (Control.controls) {
802 Control.controls.Remove(this);
807 if (parent != null) {
808 parent.Controls.Remove(this);
811 Control [] children = child_controls.GetAllControls ();
812 for (int i=0; i<children.Length; i++) {
813 children[i].parent = null; // Need to set to null or our child will try and remove from ourselves and crash
814 children[i].Dispose();
819 base.Dispose(disposing);
821 #endregion // Public Constructors
823 #region Internal Properties
824 internal BorderStyle InternalBorderStyle {
830 if (!Enum.IsDefined (typeof (BorderStyle), value))
831 throw new InvalidEnumArgumentException (string.Format("Enum argument value '{0}' is not valid for BorderStyle", value));
833 if (border_style != value) {
834 border_style = value;
836 if (IsHandleCreated) {
837 XplatUI.SetBorderStyle(window.Handle, (FormBorderStyle)border_style);
843 #endregion // Internal Properties
845 #region Private & Internal Methods
846 internal IAsyncResult BeginInvokeInternal (Delegate method, object [] args, bool disposing) {
847 AsyncMethodResult result;
848 AsyncMethodData data;
855 if (!p.IsHandleCreated) {
856 throw new InvalidOperationException("Cannot call Invoke or InvokeAsync on a control until the window handle is created");
862 result = new AsyncMethodResult ();
863 data = new AsyncMethodData ();
865 data.Handle = window.Handle;
866 data.Method = method;
868 data.Result = result;
871 if (!ExecutionContext.IsFlowSuppressed ()) {
872 data.Context = ExecutionContext.Capture ();
875 #if !MWF_ON_MSRUNTIME
876 if (SecurityManager.SecurityEnabled) {
877 data.Stack = CompressedStack.GetCompressedStack ();
882 XplatUI.SendAsyncMethod (data);
887 internal void PointToClient (ref int x, ref int y)
889 XplatUI.ScreenToClient (Handle, ref x, ref y);
892 internal void PointToScreen (ref int x, ref int y)
894 XplatUI.ClientToScreen (Handle, ref x, ref y);
897 internal bool IsRecreating {
899 return is_recreating;
903 internal Graphics DeviceContext {
905 if (dc_mem == null) {
906 CreateBuffers(this.Width, this.Height);
912 private void ImageBufferNeedsRedraw () {
913 if (invalid_region != null)
914 invalid_region.Dispose();
915 invalid_region = new Region (ClientRectangle);
918 private Bitmap ImageBuffer {
921 CreateBuffers(this.Width, this.Height);
927 internal void CreateBuffers (int width, int height) {
936 bmp_mem = new Bitmap (width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
937 dc_mem = Graphics.FromImage (bmp_mem);
938 ImageBufferNeedsRedraw ();
941 internal void InvalidateBuffers ()
943 if (dc_mem != null) {
949 ImageBufferNeedsRedraw ();
952 internal static void SetChildColor(Control parent) {
955 for (int i=0; i < parent.child_controls.Count; i++) {
956 child=parent.child_controls[i];
957 if (child.child_controls.Count>0) {
958 SetChildColor(child);
964 internal bool Select(Control control) {
965 IContainerControl container;
967 if (control == null) {
971 container = GetContainerControl();
972 if (container != null) {
973 container.ActiveControl = control;
975 if (control.IsHandleCreated) {
976 XplatUI.SetFocus(control.window.Handle);
981 internal void SelectChild (Control control)
983 if (control.IsHandleCreated)
984 XplatUI.SetFocus (control.window.Handle);
987 internal virtual void DoDefaultAction() {
988 // Only here to be overriden by our actual controls; this is needed by the accessibility class
991 internal static int LowOrder (int param) {
992 return ((int)(short)(param & 0xffff));
995 internal static int HighOrder (int param) {
996 return ((int)(short)(param >> 16));
999 // This method exists so controls overriding OnPaintBackground can have default background painting done
1000 internal virtual void PaintControlBackground (PaintEventArgs pevent)
1002 if (GetStyle(ControlStyles.SupportsTransparentBackColor) && (BackColor.A != 0xff)) {
1003 if (parent != null) {
1004 PaintEventArgs parent_pe;
1005 GraphicsState state;
1007 parent_pe = new PaintEventArgs(pevent.Graphics, new Rectangle(pevent.ClipRectangle.X + Left, pevent.ClipRectangle.Y + Top, pevent.ClipRectangle.Width, pevent.ClipRectangle.Height));
1009 state = parent_pe.Graphics.Save();
1010 parent_pe.Graphics.TranslateTransform(-Left, -Top);
1011 parent.OnPaintBackground(parent_pe);
1012 parent_pe.Graphics.Restore(state);
1014 state = parent_pe.Graphics.Save();
1015 parent_pe.Graphics.TranslateTransform(-Left, -Top);
1016 parent.OnPaint(parent_pe);
1017 parent_pe.Graphics.Restore(state);
1018 parent_pe.SetGraphics(null);
1022 if ((clip_region != null) && (XplatUI.UserClipWontExposeParent)) {
1023 if (parent != null) {
1024 PaintEventArgs parent_pe;
1026 GraphicsState state;
1029 hwnd = Hwnd.ObjectFromHandle(Handle);
1032 parent_pe = new PaintEventArgs(pevent.Graphics, new Rectangle(pevent.ClipRectangle.X + Left, pevent.ClipRectangle.Y + Top, pevent.ClipRectangle.Width, pevent.ClipRectangle.Height));
1034 region = new Region ();
1036 region.Union(ClientRectangle);
1038 foreach (Rectangle r in hwnd.ClipRectangles) {
1042 state = parent_pe.Graphics.Save();
1043 parent_pe.Graphics.Clip = region;
1045 parent_pe.Graphics.TranslateTransform(-Left, -Top);
1046 parent.OnPaintBackground(parent_pe);
1047 parent_pe.Graphics.Restore(state);
1049 state = parent_pe.Graphics.Save();
1050 parent_pe.Graphics.Clip = region;
1052 parent_pe.Graphics.TranslateTransform(-Left, -Top);
1053 parent.OnPaint(parent_pe);
1054 parent_pe.Graphics.Restore(state);
1055 parent_pe.SetGraphics(null);
1057 region.Intersect(clip_region);
1058 pevent.Graphics.Clip = region;
1063 if (background_image == null) {
1064 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));
1068 DrawBackgroundImage (pevent.Graphics);
1071 void DrawBackgroundImage (Graphics g)
1073 using (TextureBrush b = new TextureBrush (background_image, WrapMode.Tile)) {
1074 g.FillRectangle (b, ClientRectangle);
1078 internal virtual void DndEnter (DragEventArgs e)
1085 internal virtual void DndOver (DragEventArgs e)
1092 internal virtual void DndDrop (DragEventArgs e)
1096 } catch (Exception exc) {
1097 Console.Error.WriteLine ("MWF: Exception while dropping:");
1098 Console.Error.WriteLine (exc);
1102 internal virtual void DndLeave (EventArgs e)
1109 internal virtual void DndFeedback(GiveFeedbackEventArgs e)
1116 internal virtual void DndContinueDrag(QueryContinueDragEventArgs e)
1119 OnQueryContinueDrag(e);
1123 internal static MouseButtons FromParamToMouseButtons (int param) {
1124 MouseButtons buttons = MouseButtons.None;
1126 if ((param & (int) MsgButtons.MK_LBUTTON) != 0)
1127 buttons |= MouseButtons.Left;
1129 if ((param & (int) MsgButtons.MK_MBUTTON) != 0)
1130 buttons |= MouseButtons.Middle;
1132 if ((param & (int) MsgButtons.MK_RBUTTON) != 0)
1133 buttons |= MouseButtons.Right;
1139 internal void FireEnter ()
1141 OnEnter (EventArgs.Empty);
1144 internal void FireLeave ()
1146 OnLeave (EventArgs.Empty);
1149 internal void FireValidating (CancelEventArgs ce)
1154 internal void FireValidated ()
1156 OnValidated (EventArgs.Empty);
1159 internal virtual bool ProcessControlMnemonic(char charCode) {
1160 return ProcessMnemonic(charCode);
1163 private static Control FindFlatForward(Control container, Control start) {
1169 end = container.child_controls.Count;
1171 if (start != null) {
1172 index = start.tab_index;
1178 for (int i = 0, pos = -1; i < end; i++) {
1179 if (start == container.child_controls[i]) {
1184 if (found == null) {
1185 if (container.child_controls[i].tab_index > index || (pos > -1 && pos < i && container.child_controls[i].tab_index == index)) {
1186 found = container.child_controls[i];
1188 } else if (found.tab_index > container.child_controls[i].tab_index) {
1189 if (container.child_controls[i].tab_index > index) {
1190 found = container.child_controls[i];
1197 private static Control FindControlForward(Control container, Control start) {
1203 if (start != null) {
1204 if (start.child_controls != null && start.child_controls.Count > 0 &&
1205 !((start is IContainerControl) && start.GetStyle(ControlStyles.ContainerControl))) {
1206 found = FindControlForward(start, null);
1207 if (found != null) {
1213 while (p != container) {
1214 found = FindFlatForward(p, start);
1215 if (found != null) {
1222 return FindFlatForward(container, start);
1225 private static Control FindFlatBackward(Control container, Control start) {
1231 end = container.child_controls.Count;
1233 if (start != null) {
1234 index = start.tab_index;
1236 // FIXME: Possible speed-up: Keep the highest taborder index in the container
1238 for (int i = 0; i < end; i++) {
1239 if (container.child_controls[i].tab_index > index) {
1240 index = container.child_controls[i].tab_index;
1246 for (int i = end-1, pos = -1; i >= 0; i--) {
1247 if (start == container.child_controls[i]) {
1252 if (found == null) {
1253 if (container.child_controls[i].tab_index < index ||
1254 (pos > -1 && pos > i && container.child_controls[i].tab_index == index)) {
1255 found = container.child_controls[i];
1257 } else if (found.tab_index < container.child_controls[i].tab_index) {
1258 if (container.child_controls[i].tab_index < index) {
1259 found = container.child_controls[i];
1266 private static Control FindControlBackward(Control container, Control start) {
1271 if (start != null) {
1272 found = FindFlatBackward(start.parent, start);
1273 if (found == null) {
1274 if (start.parent != container) {
1275 return start.parent;
1279 if (found == null) {
1280 found = FindFlatBackward(container, start);
1283 if (container != start) {
1284 while ((found != null) && (!found.Contains(start)) && found.child_controls != null && found.child_controls.Count > 0 && !(found is IContainerControl)) {// || found.GetStyle(ControlStyles.ContainerControl))) {
1285 found = FindControlBackward(found, null);
1286 if (found != null) {
1295 internal virtual void HandleClick(int clicks, MouseEventArgs me) {
1296 if (GetStyle(ControlStyles.StandardClick)) {
1297 if ((clicks > 1) && GetStyle(ControlStyles.StandardDoubleClick)) {
1299 OnDoubleClick(EventArgs.Empty);
1301 OnClick(EventArgs.Empty);
1311 private void CheckDataBindings ()
1313 if (data_bindings == null)
1316 BindingContext binding_context = BindingContext;
1317 foreach (Binding binding in data_bindings) {
1318 binding.Check (binding_context);
1323 private void ChangeParent(Control new_parent) {
1327 Color pre_fore_color;
1328 Color pre_back_color;
1329 RightToLeft pre_rtl;
1331 // These properties are inherited from our parent
1332 // Get them pre parent-change and then send events
1333 // if they are changed after we have our new parent
1334 pre_enabled = Enabled;
1335 pre_visible = Visible;
1337 pre_fore_color = ForeColor;
1338 pre_back_color = BackColor;
1339 pre_rtl = RightToLeft;
1340 // MS doesn't seem to send a CursorChangedEvent
1342 parent = new_parent;
1344 if (IsHandleCreated)
1345 XplatUI.SetParent(Handle,
1346 (new_parent == null || !new_parent.IsHandleCreated) ? IntPtr.Zero : new_parent.Handle);
1348 OnParentChanged(EventArgs.Empty);
1350 if (pre_enabled != Enabled) {
1351 OnEnabledChanged(EventArgs.Empty);
1354 if (pre_visible != Visible) {
1355 OnVisibleChanged(EventArgs.Empty);
1358 if (pre_font != Font) {
1359 OnFontChanged(EventArgs.Empty);
1362 if (pre_fore_color != ForeColor) {
1363 OnForeColorChanged(EventArgs.Empty);
1366 if (pre_back_color != BackColor) {
1367 OnBackColorChanged(EventArgs.Empty);
1370 if (pre_rtl != RightToLeft) {
1371 // MS sneaks a OnCreateControl and OnHandleCreated in here, I guess
1372 // because when RTL changes they have to recreate the win32 control
1373 // We don't really need that (until someone runs into compatibility issues)
1374 OnRightToLeftChanged(EventArgs.Empty);
1377 if ((new_parent != null) && new_parent.Created && !Created) {
1381 if ((binding_context == null) && Created) {
1382 OnBindingContextChanged(EventArgs.Empty);
1386 private void UpdateDistances() {
1387 if ((parent != null) && (parent.layout_suspended == 0)) {
1388 dist_left = bounds.X;
1389 dist_top = bounds.Y;
1390 dist_right = parent.ClientSize.Width - bounds.X - bounds.Width;
1391 dist_bottom = parent.ClientSize.Height - bounds.Y - bounds.Height;
1394 #endregion // Private & Internal Methods
1396 #region Public Static Properties
1397 public static Color DefaultBackColor {
1399 return ThemeEngine.Current.DefaultControlBackColor;
1403 public static Font DefaultFont {
1405 return ThemeEngine.Current.DefaultFont;
1409 public static Color DefaultForeColor {
1411 return ThemeEngine.Current.DefaultControlForeColor;
1415 public static Keys ModifierKeys {
1417 return XplatUI.State.ModifierKeys;
1421 public static MouseButtons MouseButtons {
1423 return XplatUI.State.MouseButtons;
1427 public static Point MousePosition {
1429 return Cursor.Position;
1435 public static bool CheckForIllegalCrossThreadCalls
1438 return verify_thread_handle;
1442 verify_thread_handle = value;
1446 #endregion // Public Static Properties
1448 #region Public Instance Properties
1449 [EditorBrowsable(EditorBrowsableState.Advanced)]
1451 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1452 public AccessibleObject AccessibilityObject {
1454 if (accessibility_object==null) {
1455 accessibility_object=CreateAccessibilityInstance();
1457 return accessibility_object;
1461 [EditorBrowsable(EditorBrowsableState.Advanced)]
1463 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1464 public string AccessibleDefaultActionDescription {
1466 return AccessibilityObject.default_action;
1470 AccessibilityObject.default_action=value;
1475 [DefaultValue(null)]
1476 [MWFCategory("Accessibility")]
1477 public string AccessibleDescription {
1479 return AccessibilityObject.description;
1483 AccessibilityObject.description=value;
1488 [DefaultValue(null)]
1489 [MWFCategory("Accessibility")]
1490 public string AccessibleName {
1492 return AccessibilityObject.Name;
1496 AccessibilityObject.Name=value;
1500 [DefaultValue(AccessibleRole.Default)]
1501 [MWFDescription("Role of the control"), MWFCategory("Accessibility")]
1502 public AccessibleRole AccessibleRole {
1504 return AccessibilityObject.role;
1508 AccessibilityObject.role=value;
1512 [DefaultValue(false)]
1513 [MWFCategory("Behavior")]
1514 public virtual bool AllowDrop {
1520 if (allow_drop == value)
1523 if (IsHandleCreated) {
1525 XplatUI.SetAllowDrop (Handle, value);
1531 [RefreshProperties(RefreshProperties.Repaint)]
1532 [DefaultValue(AnchorStyles.Top | AnchorStyles.Left)]
1533 [MWFCategory("Layout")]
1534 public virtual AnchorStyles Anchor {
1536 return anchor_style;
1542 if (parent != null) {
1543 parent.PerformLayout(this, "Parent");
1549 // XXX: Implement me!
1552 public virtual bool AutoSize {
1554 //Console.Error.WriteLine("Unimplemented: Control::get_AutoSize()");
1558 Console.Error.WriteLine("Unimplemented: Control::set_AutoSize(bool)");
1563 public virtual Size MaximumSize {
1565 return maximum_size;
1568 maximum_size = value;
1572 public virtual Size MinimumSize {
1574 return minimum_size;
1577 minimum_size = value;
1583 [MWFCategory("Appearance")]
1584 public virtual Color BackColor {
1586 if (background_color.IsEmpty) {
1588 Color pcolor = parent.BackColor;
1589 if (pcolor.A == 0xff || GetStyle(ControlStyles.SupportsTransparentBackColor))
1592 return DefaultBackColor;
1594 return background_color;
1598 if (!value.IsEmpty && (value.A != 0xff) && !GetStyle(ControlStyles.SupportsTransparentBackColor)) {
1599 throw new ArgumentException("Transparent background colors are not supported on this control");
1602 if (background_color != value) {
1603 background_color=value;
1604 SetChildColor(this);
1605 OnBackColorChanged(EventArgs.Empty);
1612 [DefaultValue(null)]
1613 [MWFCategory("Appearance")]
1614 public virtual Image BackgroundImage {
1616 return background_image;
1620 if (background_image!=value) {
1621 background_image=value;
1622 OnBackgroundImageChanged(EventArgs.Empty);
1627 [EditorBrowsable(EditorBrowsableState.Advanced)]
1629 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1630 public virtual BindingContext BindingContext {
1632 if (binding_context != null)
1633 return binding_context;
1636 binding_context = Parent.BindingContext;
1637 return binding_context;
1640 if (binding_context != value) {
1641 binding_context = value;
1642 OnBindingContextChanged(EventArgs.Empty);
1647 [EditorBrowsable(EditorBrowsableState.Advanced)]
1649 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1652 return bounds.Y+bounds.Height;
1656 [EditorBrowsable(EditorBrowsableState.Advanced)]
1658 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1659 public Rectangle Bounds {
1665 SetBounds(value.Left, value.Top, value.Width, value.Height, BoundsSpecified.All);
1669 [EditorBrowsable(EditorBrowsableState.Advanced)]
1671 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1672 public bool CanFocus {
1674 if (IsHandleCreated && Visible && Enabled) {
1681 [EditorBrowsable(EditorBrowsableState.Advanced)]
1683 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1684 public bool CanSelect {
1688 if (!GetStyle(ControlStyles.Selectable)) {
1693 while (parent != null) {
1694 if (!parent.is_visible || !parent.is_enabled) {
1698 parent = parent.parent;
1704 internal virtual bool InternalCapture {
1714 [EditorBrowsable(EditorBrowsableState.Advanced)]
1716 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1717 public bool Capture {
1719 return this.is_captured;
1723 if (this.IsHandleCreated) {
1724 if (value && !is_captured) {
1726 XplatUI.GrabWindow(this.window.Handle, IntPtr.Zero);
1727 } else if (!value && is_captured) {
1728 XplatUI.UngrabWindow(this.window.Handle);
1729 is_captured = false;
1735 [DefaultValue(true)]
1736 [MWFCategory("Focus")]
1737 public bool CausesValidation {
1739 return this.causes_validation;
1743 if (this.causes_validation != value) {
1744 causes_validation = value;
1745 OnCausesValidationChanged(EventArgs.Empty);
1750 [EditorBrowsable(EditorBrowsableState.Advanced)]
1752 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1753 public Rectangle ClientRectangle {
1755 client_rect.Width = client_size.Width;
1756 client_rect.Height = client_size.Height;
1761 [EditorBrowsable(EditorBrowsableState.Advanced)]
1763 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1764 public Size ClientSize {
1767 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1768 return ((Form)this).form_parent_window.ClientSize;
1776 this.SetClientSizeCore(value.Width, value.Height);
1780 [EditorBrowsable(EditorBrowsableState.Advanced)]
1782 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1783 [DescriptionAttribute("ControlCompanyNameDescr")]
1784 public String CompanyName {
1786 return "Mono Project, Novell, Inc.";
1790 [EditorBrowsable(EditorBrowsableState.Advanced)]
1792 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1793 public bool ContainsFocus {
1795 IntPtr focused_window;
1797 focused_window = XplatUI.GetFocus();
1798 if (IsHandleCreated) {
1799 if (focused_window == Handle) {
1803 for (int i=0; i < child_controls.Count; i++) {
1804 if (child_controls[i].ContainsFocus) {
1813 [DefaultValue(null)]
1814 [MWFCategory("Behavior")]
1815 public virtual ContextMenu ContextMenu {
1817 return context_menu;
1821 if (context_menu != value) {
1822 context_menu = value;
1823 OnContextMenuChanged(EventArgs.Empty);
1829 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
1830 public ControlCollection Controls {
1832 return this.child_controls;
1836 [EditorBrowsable(EditorBrowsableState.Advanced)]
1838 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1839 public bool Created {
1841 return (!is_disposed && is_created);
1845 [AmbientValue(null)]
1846 [MWFCategory("Appearance")]
1847 public virtual Cursor Cursor {
1849 if (cursor != null) {
1853 if (parent != null) {
1854 return parent.Cursor;
1857 return Cursors.Default;
1861 if (cursor != value) {
1866 if (IsHandleCreated) {
1867 pt = Cursor.Position;
1869 if (bounds.Contains(pt) || Capture) {
1870 if (GetChildAtPoint(pt) == null) {
1871 if (cursor != null) {
1872 XplatUI.SetCursor(window.Handle, cursor.handle);
1874 if (parent != null) {
1875 XplatUI.SetCursor(window.Handle, parent.Cursor.handle);
1877 XplatUI.SetCursor(window.Handle, Cursors.Default.handle);
1884 OnCursorChanged(EventArgs.Empty);
1890 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
1891 [ParenthesizePropertyName(true)]
1892 [RefreshProperties(RefreshProperties.All)]
1893 [MWFCategory("Data")]
1894 public ControlBindingsCollection DataBindings {
1896 if (data_bindings == null)
1897 data_bindings = new ControlBindingsCollection (this);
1898 return data_bindings;
1902 [EditorBrowsable(EditorBrowsableState.Advanced)]
1904 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1905 public virtual Rectangle DisplayRectangle {
1907 return ClientRectangle;
1911 [EditorBrowsable(EditorBrowsableState.Advanced)]
1913 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1914 public bool Disposing {
1921 [RefreshProperties(RefreshProperties.Repaint)]
1922 [DefaultValue(DockStyle.None)]
1923 [MWFCategory("Layout")]
1924 public virtual DockStyle Dock {
1930 if (dock_style == value) {
1936 if (parent != null) {
1937 parent.PerformLayout(this, "Parent");
1940 OnDockChanged(EventArgs.Empty);
1946 [MWFCategory("Behavior")]
1947 public bool Enabled {
1953 if (parent != null) {
1954 return parent.Enabled;
1961 if (Enabled == value) {
1968 // FIXME - we need to switch focus to next control if we're disabling the focused control
1970 OnEnabledChanged (EventArgs.Empty);
1974 [EditorBrowsable(EditorBrowsableState.Advanced)]
1976 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1977 public virtual bool Focused {
1979 return this.has_focus;
1984 [AmbientValue(null)]
1986 [MWFCategory("Appearance")]
1987 public virtual Font Font {
1993 if (Parent != null && Parent.Font != null) {
2000 [param:MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Font))]
2002 if (font != null && font.Equals (value)) {
2008 OnFontChanged (EventArgs.Empty);
2013 [MWFCategory("Appearance")]
2014 public virtual Color ForeColor {
2016 if (foreground_color.IsEmpty) {
2018 return parent.ForeColor;
2020 return DefaultForeColor;
2022 return foreground_color;
2026 if (foreground_color != value) {
2027 foreground_color=value;
2029 OnForeColorChanged(EventArgs.Empty);
2036 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2037 public IntPtr Handle { // IWin32Window
2040 if (verify_thread_handle) {
2041 if (this.InvokeRequired) {
2042 throw new InvalidOperationException("Cross-thread access of handle detected. Handle access only valid on thread that created the control");
2046 if (!IsHandleCreated) {
2049 return window.Handle;
2053 [EditorBrowsable(EditorBrowsableState.Advanced)]
2055 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2056 public bool HasChildren {
2058 if (this.child_controls.Count>0) {
2065 [EditorBrowsable(EditorBrowsableState.Always)]
2067 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2070 return this.bounds.Height;
2074 SetBounds(bounds.X, bounds.Y, bounds.Width, value, BoundsSpecified.Height);
2078 [AmbientValue(ImeMode.Inherit)]
2080 [MWFCategory("Behavior")]
2081 public ImeMode ImeMode {
2083 if (ime_mode == DefaultImeMode) {
2085 return parent.ImeMode;
2087 return ImeMode.NoControl; // default value
2093 if (ime_mode != value) {
2096 OnImeModeChanged(EventArgs.Empty);
2101 [EditorBrowsable(EditorBrowsableState.Advanced)]
2103 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2104 public bool InvokeRequired { // ISynchronizeInvoke
2106 if (creator_thread != null && creator_thread!=Thread.CurrentThread) {
2113 [EditorBrowsable(EditorBrowsableState.Advanced)]
2115 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2116 public bool IsAccessible {
2118 return is_accessible;
2122 is_accessible = value;
2126 [EditorBrowsable(EditorBrowsableState.Advanced)]
2128 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2129 public bool IsDisposed {
2131 return this.is_disposed;
2135 [EditorBrowsable(EditorBrowsableState.Advanced)]
2137 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2138 public bool IsHandleCreated {
2140 if ((window != null) && (window.Handle != IntPtr.Zero)) {
2141 Hwnd hwnd = Hwnd.ObjectFromHandle (window.Handle);
2142 if (hwnd != null && !hwnd.zombie)
2151 public virtual Layout.LayoutEngine LayoutEngine {
2152 get { return this.layout_engine; }
2156 [EditorBrowsable(EditorBrowsableState.Always)]
2158 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2161 return this.bounds.X;
2165 SetBounds(value, bounds.Y, bounds.Width, bounds.Height, BoundsSpecified.X);
2170 [MWFCategory("Layout")]
2171 public Point Location {
2173 return new Point(bounds.X, bounds.Y);
2177 SetBounds(value.X, value.Y, bounds.Width, bounds.Height, BoundsSpecified.Location);
2182 [Localizable (true)]
2183 public Padding Margin {
2184 get { return this.margin; }
2185 set { this.margin = value; }
2190 public string Name {
2202 public Padding Padding {
2214 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2215 public Control Parent {
2221 if (value == this) {
2222 throw new ArgumentException("A circular control reference has been made. A control cannot be owned or parented to itself.");
2225 if (parent!=value) {
2227 parent.Controls.Remove(this);
2232 value.Controls.Add(this);
2237 [EditorBrowsable(EditorBrowsableState.Advanced)]
2239 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2240 public string ProductName {
2242 Type t = typeof (AssemblyProductAttribute);
2243 Assembly assembly = GetType().Module.Assembly;
2244 object [] attrs = assembly.GetCustomAttributes (t, false);
2245 AssemblyProductAttribute a = null;
2246 // On MS we get a NullRefException if product attribute is not
2248 if (attrs != null && attrs.Length > 0)
2249 a = (AssemblyProductAttribute) attrs [0];
2254 [EditorBrowsable(EditorBrowsableState.Advanced)]
2256 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2257 public string ProductVersion {
2259 Type t = typeof (AssemblyVersionAttribute);
2260 Assembly assembly = GetType().Module.Assembly;
2261 object [] attrs = assembly.GetCustomAttributes (t, false);
2262 if (attrs == null || attrs.Length < 1)
2264 return ((AssemblyVersionAttribute)attrs [0]).Version;
2268 [EditorBrowsable(EditorBrowsableState.Advanced)]
2270 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2271 public bool RecreatingHandle {
2273 return is_recreating;
2277 [EditorBrowsable(EditorBrowsableState.Advanced)]
2279 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2280 public Region Region {
2286 if (IsHandleCreated) {
2287 XplatUI.SetClipRegion(Handle, value);
2289 clip_region = value;
2293 [EditorBrowsable(EditorBrowsableState.Advanced)]
2295 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2298 return this.bounds.X+this.bounds.Width;
2302 [AmbientValue(RightToLeft.Inherit)]
2304 [MWFCategory("Appearance")]
2305 public virtual RightToLeft RightToLeft {
2307 if (right_to_left == RightToLeft.Inherit) {
2309 return parent.RightToLeft;
2311 return RightToLeft.No; // default value
2313 return right_to_left;
2317 if (value != right_to_left) {
2318 right_to_left = value;
2319 OnRightToLeftChanged(EventArgs.Empty);
2324 [EditorBrowsable(EditorBrowsableState.Advanced)]
2325 public override ISite Site {
2333 AmbientProperties ap = (AmbientProperties) value.GetService (typeof (AmbientProperties));
2335 BackColor = ap.BackColor;
2336 ForeColor = ap.ForeColor;
2344 [MWFCategory("Layout")]
2347 return new Size(Width, Height);
2351 SetBounds(bounds.X, bounds.Y, value.Width, value.Height, BoundsSpecified.Size);
2356 [MergableProperty(false)]
2357 [MWFCategory("Behavior")]
2358 public int TabIndex {
2360 if (tab_index != -1) {
2367 if (tab_index != value) {
2369 OnTabIndexChanged(EventArgs.Empty);
2375 [DefaultValue(true)]
2376 [MWFCategory("Behavior")]
2377 public bool TabStop {
2383 if (tab_stop != value) {
2385 OnTabStopChanged(EventArgs.Empty);
2390 [Localizable(false)]
2392 [TypeConverter(typeof(StringConverter))]
2393 [DefaultValue(null)]
2394 [MWFCategory("Data")]
2401 control_tag = value;
2407 [BindableAttribute(true)]
2408 [MWFCategory("Appearance")]
2409 public virtual string Text {
2411 // Our implementation ignores ControlStyles.CacheText - we always cache
2416 if (value == null) {
2417 value = String.Empty;
2422 if (IsHandleCreated) {
2423 /* we need to call .SetWindowStyle here instead of just .Text
2424 because the presence/absence of Text (== "" or not) can cause
2425 other window style things to appear/disappear */
2426 XplatUI.SetWindowStyle(window.Handle, CreateParams);
2427 XplatUI.Text(Handle, text);
2429 OnTextChanged (EventArgs.Empty);
2434 [EditorBrowsable(EditorBrowsableState.Always)]
2436 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2439 return this.bounds.Y;
2443 SetBounds(bounds.X, value, bounds.Width, bounds.Height, BoundsSpecified.Y);
2447 [EditorBrowsable(EditorBrowsableState.Advanced)]
2449 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2450 public Control TopLevelControl {
2454 while (p.parent != null) {
2463 [MWFCategory("Behavior")]
2464 public bool Visible {
2468 } else if (parent != null) {
2469 return parent.Visible;
2476 SetVisibleCore(value);
2480 [EditorBrowsable(EditorBrowsableState.Always)]
2482 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2485 return this.bounds.Width;
2489 SetBounds(bounds.X, bounds.Y, value, bounds.Height, BoundsSpecified.Width);
2493 [EditorBrowsable(EditorBrowsableState.Never)]
2495 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2496 public IWindowTarget WindowTarget {
2505 #endregion // Public Instance Properties
2507 #region Protected Instance Properties
2508 protected virtual CreateParams CreateParams {
2510 CreateParams create_params = new CreateParams();
2513 create_params.Caption = Text;
2516 create_params.Caption = text;
2520 create_params.X = Left;
2523 create_params.X = this.bounds.X;
2527 create_params.Y = Top;
2530 create_params.Y = this.bounds.Y;
2534 create_params.Width = Width;
2537 create_params.Width = this.bounds.Width;
2541 create_params.Height = Height;
2544 create_params.Height = this.bounds.Height;
2548 create_params.ClassName = XplatUI.DefaultClassName;
2549 create_params.ClassStyle = 0;
2550 create_params.ExStyle = 0;
2551 create_params.Param = 0;
2554 create_params.ExStyle |= (int)WindowExStyles.WS_EX_ACCEPTFILES;
2557 if ((parent!=null) && (parent.IsHandleCreated)) {
2558 create_params.Parent = parent.Handle;
2561 create_params.Style = (int)WindowStyles.WS_CHILD | (int)WindowStyles.WS_CLIPCHILDREN | (int)WindowStyles.WS_CLIPSIBLINGS;
2564 create_params.Style |= (int)WindowStyles.WS_VISIBLE;
2568 create_params.Style |= (int)WindowStyles.WS_DISABLED;
2571 switch (border_style) {
2572 case BorderStyle.FixedSingle:
2573 create_params.Style |= (int) WindowStyles.WS_BORDER;
2575 case BorderStyle.Fixed3D:
2576 create_params.ExStyle |= (int) WindowExStyles.WS_EX_CLIENTEDGE;
2580 return create_params;
2584 protected virtual ImeMode DefaultImeMode {
2586 return ImeMode.Inherit;
2591 protected virtual Padding DefaultMargin {
2592 get { return new Padding (3); }
2596 protected virtual Size DefaultSize {
2598 return new Size(0, 0);
2602 protected int FontHeight {
2612 protected bool RenderRightToLeft {
2614 return (this.right_to_left == RightToLeft.Yes);
2618 protected bool ResizeRedraw {
2620 return GetStyle(ControlStyles.ResizeRedraw);
2624 SetStyle(ControlStyles.ResizeRedraw, value);
2628 [EditorBrowsable(EditorBrowsableState.Advanced)]
2630 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2631 protected virtual bool ShowFocusCues {
2637 [EditorBrowsable(EditorBrowsableState.Advanced)]
2639 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2640 protected bool ShowKeyboardCues {
2645 #endregion // Protected Instance Properties
2647 #region Public Static Methods
2648 [EditorBrowsable(EditorBrowsableState.Advanced)]
2649 public static Control FromChildHandle(IntPtr handle) {
2650 return Control.ControlNativeWindow.ControlFromChildHandle (handle);
2653 [EditorBrowsable(EditorBrowsableState.Advanced)]
2654 public static Control FromHandle(IntPtr handle) {
2655 return Control.ControlNativeWindow.ControlFromHandle(handle);
2658 public static bool IsMnemonic(char charCode, string text) {
2661 amp = text.IndexOf('&');
2664 if (amp + 1 < text.Length) {
2665 if (text[amp + 1] != '&') {
2666 if (Char.ToUpper(charCode) == Char.ToUpper(text.ToCharArray(amp + 1, 1)[0])) {
2676 #region Protected Static Methods
2677 [EditorBrowsable(EditorBrowsableState.Advanced)]
2678 protected static bool ReflectMessage(IntPtr hWnd, ref Message m) {
2681 c = Control.FromHandle(hWnd);
2691 #region Public Instance Methods
2692 [EditorBrowsable(EditorBrowsableState.Advanced)]
2693 public IAsyncResult BeginInvoke(Delegate method) {
2694 object [] prms = null;
2695 if (method is EventHandler)
2696 prms = new object [] { this, EventArgs.Empty };
2697 return BeginInvokeInternal(method, prms, false);
2700 [EditorBrowsable(EditorBrowsableState.Advanced)]
2701 public IAsyncResult BeginInvoke (Delegate method, object[] args) {
2702 return BeginInvokeInternal (method, args, false);
2705 public void BringToFront() {
2706 if (parent != null) {
2707 parent.child_controls.SetChildIndex(this, 0);
2710 XplatUI.SetZOrder(Handle, IntPtr.Zero, false, false);
2714 public bool Contains(Control ctl) {
2715 while (ctl != null) {
2724 public void CreateControl() {
2726 throw new ObjectDisposedException(GetType().FullName.ToString());
2732 if (!IsHandleCreated) {
2740 Control [] controls = child_controls.GetAllControls ();
2741 for (int i=0; i<controls.Length; i++) {
2742 controls [i].CreateControl ();
2745 UpdateChildrenZOrder();
2747 if (binding_context == null) { // seem to be sent whenever it's null?
2748 OnBindingContextChanged(EventArgs.Empty);
2754 public Graphics CreateGraphics() {
2755 if (!IsHandleCreated) {
2756 this.CreateHandle();
2758 return Graphics.FromHwnd(this.window.Handle);
2761 public DragDropEffects DoDragDrop(object data, DragDropEffects allowedEffects) {
2762 return XplatUI.StartDrag(this.window.Handle, data, allowedEffects);
2765 [EditorBrowsable(EditorBrowsableState.Advanced)]
2766 public object EndInvoke (IAsyncResult async_result) {
2767 AsyncMethodResult result = (AsyncMethodResult) async_result;
2768 return result.EndInvoke ();
2771 public Form FindForm() {
2784 public bool Focus() {
2785 if (CanFocus && IsHandleCreated && !has_focus) {
2791 public Control GetChildAtPoint(Point pt) {
2792 // Microsoft's version of this function doesn't seem to work, so I can't check
2793 // if we only consider children or also grandchildren, etc.
2794 // I'm gonna say 'children only'
2795 for (int i=0; i<child_controls.Count; i++) {
2796 if (child_controls[i].Bounds.Contains(pt)) {
2797 return child_controls[i];
2803 public IContainerControl GetContainerControl() {
2804 Control current = this;
2806 while (current!=null) {
2807 if ((current is IContainerControl) && ((current.control_style & ControlStyles.ContainerControl)!=0)) {
2808 return (IContainerControl)current;
2810 current = current.parent;
2815 public Control GetNextControl(Control ctl, bool forward) {
2818 if ((parent == null) && (ctl is IContainerControl) && ctl.GetStyle(ControlStyles.ContainerControl)) {
2820 return FindFlatForward(this, ctl);
2822 return FindFlatBackward(this, ctl);
2827 // If ctl is not contained by this, we start at the first child of this
2828 if (!this.Contains(ctl)) {
2832 // Search through our controls, starting at ctl, stepping into children as we encounter them
2833 // try to find the control with the tabindex closest to our own, or, if we're looking into
2834 // child controls, the one with the smallest tabindex
2836 return FindControlForward(this, ctl);
2838 return FindControlBackward(this, ctl);
2842 public virtual Size GetPreferredSize (Size proposedSize) {
2843 return preferred_size;
2847 public void Hide() {
2848 this.Visible = false;
2851 public void Invalidate() {
2852 Invalidate(ClientRectangle, false);
2855 public void Invalidate(bool invalidateChildren) {
2856 Invalidate(ClientRectangle, invalidateChildren);
2859 public void Invalidate(System.Drawing.Rectangle rc) {
2860 Invalidate(rc, false);
2863 public void Invalidate(System.Drawing.Rectangle rc, bool invalidateChildren) {
2864 if (!IsHandleCreated || !Visible || rc.Width == 0 || rc.Height == 0) {
2868 NotifyInvalidate(rc);
2870 XplatUI.Invalidate(Handle, rc, false);
2872 if (invalidateChildren) {
2873 Control [] controls = child_controls.GetAllControls ();
2874 for (int i=0; i<controls.Length; i++)
2875 controls [i].Invalidate ();
2877 OnInvalidated(new InvalidateEventArgs(rc));
2880 public void Invalidate(System.Drawing.Region region) {
2881 Invalidate(region, false);
2884 public void Invalidate(System.Drawing.Region region, bool invalidateChildren) {
2885 RectangleF bounds = region.GetBounds (CreateGraphics ());
2886 Invalidate (new Rectangle ((int) bounds.X, (int) bounds.Y, (int) bounds.Width, (int) bounds.Height),
2887 invalidateChildren);
2890 public object Invoke (Delegate method) {
2891 object [] prms = null;
2892 if (method is EventHandler)
2893 prms = new object [] { this, EventArgs.Empty };
2895 return Invoke(method, prms);
2898 public object Invoke (Delegate method, object[] args) {
2899 if (!this.InvokeRequired) {
2900 return method.DynamicInvoke(args);
2903 IAsyncResult result = BeginInvoke (method, args);
2904 return EndInvoke(result);
2907 internal object InvokeInternal (Delegate method, bool disposing) {
2908 return InvokeInternal(method, null, disposing);
2911 internal object InvokeInternal (Delegate method, object[] args, bool disposing) {
2912 if (!this.InvokeRequired) {
2913 return method.DynamicInvoke(args);
2916 IAsyncResult result = BeginInvokeInternal (method, args, disposing);
2917 return EndInvoke(result);
2920 [EditorBrowsable(EditorBrowsableState.Advanced)]
2921 public void PerformLayout() {
2922 PerformLayout(null, null);
2925 [EditorBrowsable(EditorBrowsableState.Advanced)]
2926 public void PerformLayout(Control affectedControl, string affectedProperty) {
2927 LayoutEventArgs levent = new LayoutEventArgs(affectedControl, affectedProperty);
2929 if (layout_suspended > 0) {
2930 layout_pending = true;
2934 layout_pending = false;
2936 // Prevent us from getting messed up
2939 // Perform all Dock and Anchor calculations
2943 this.layout_engine.Layout(this, levent);
2945 // This has been moved to Layout/DefaultLayout.cs for 2.0, please duplicate any changes/fixes there.
2947 AnchorStyles anchor;
2950 space = DisplayRectangle;
2952 // Deal with docking; go through in reverse, MS docs say that lowest Z-order is closest to edge
2953 Control [] controls = child_controls.GetAllControls ();
2954 for (int i = controls.Length - 1; i >= 0; i--) {
2955 child = controls [i];
2957 if (!child.Visible) {
2961 switch (child.Dock) {
2962 case DockStyle.None: {
2967 case DockStyle.Left: {
2968 child.SetBounds(space.Left, space.Y, child.Width, space.Height);
2969 space.X+=child.Width;
2970 space.Width-=child.Width;
2974 case DockStyle.Top: {
2975 child.SetBounds(space.Left, space.Y, space.Width, child.Height);
2976 space.Y+=child.Height;
2977 space.Height-=child.Height;
2981 case DockStyle.Right: {
2982 child.SetBounds(space.Right-child.Width, space.Y, child.Width, space.Height);
2983 space.Width-=child.Width;
2987 case DockStyle.Bottom: {
2988 child.SetBounds(space.Left, space.Bottom-child.Height, space.Width, child.Height);
2989 space.Height-=child.Height;
2995 for (int i = controls.Length - 1; i >= 0; i--) {
2998 //if (child.Visible && (child.Dock == DockStyle.Fill)) {
2999 if (child.Dock == DockStyle.Fill) {
3000 child.SetBounds(space.Left, space.Top, space.Width, space.Height);
3004 space = DisplayRectangle;
3006 for (int i=0; i < controls.Length; i++) {
3012 child = controls[i];
3014 // If the control is docked we don't need to do anything
3015 if (child.Dock != DockStyle.None) {
3019 anchor = child.Anchor;
3023 width = child.Width;
3024 height = child.Height;
3026 if ((anchor & AnchorStyles.Left) !=0 ) {
3027 if ((anchor & AnchorStyles.Right) != 0) {
3028 width = space.Width - child.dist_right - left;
3030 ; // Left anchored only, nothing to be done
3032 } else if ((anchor & AnchorStyles.Right) != 0) {
3033 left = space.Width - child.dist_right - width;
3035 // left+=diff_width/2 will introduce rounding errors (diff_width removed from svn after r51780)
3036 // This calculates from scratch every time:
3037 left = child.dist_left + (space.Width - (child.dist_left + width + child.dist_right)) / 2;
3040 if ((anchor & AnchorStyles.Top) !=0 ) {
3041 if ((anchor & AnchorStyles.Bottom) != 0) {
3042 height = space.Height - child.dist_bottom - top;
3044 ; // Top anchored only, nothing to be done
3046 } else if ((anchor & AnchorStyles.Bottom) != 0) {
3047 top = space.Height - child.dist_bottom - height;
3049 // top += diff_height/2 will introduce rounding errors (diff_height removed from after r51780)
3050 // This calculates from scratch every time:
3051 top = child.dist_top + (space.Height - (child.dist_top + height + child.dist_bottom)) / 2;
3063 child.SetBounds(left, top, width, height);
3067 // Let everyone know
3071 // Need to make sure we decremend layout_suspended
3077 public Point PointToClient (Point p) {
3081 XplatUI.ScreenToClient (Handle, ref x, ref y);
3083 return new Point (x, y);
3086 public Point PointToScreen(Point p) {
3090 XplatUI.ClientToScreen(Handle, ref x, ref y);
3092 return new Point(x, y);
3095 public virtual bool PreProcessMessage(ref Message msg) {
3096 return InternalPreProcessMessage (ref msg);
3099 internal virtual bool InternalPreProcessMessage (ref Message msg) {
3102 if ((msg.Msg == (int)Msg.WM_KEYDOWN) || (msg.Msg == (int)Msg.WM_SYSKEYDOWN)) {
3103 key_data = (Keys)msg.WParam.ToInt32() | XplatUI.State.ModifierKeys;
3105 if (!ProcessCmdKey(ref msg, key_data)) {
3106 if (IsInputKey(key_data)) {
3110 return ProcessDialogKey(key_data);
3114 } else if (msg.Msg == (int)Msg.WM_CHAR) {
3115 if (IsInputChar((char)msg.WParam)) {
3118 return ProcessDialogChar((char)msg.WParam);
3119 } else if (msg.Msg == (int)Msg.WM_SYSCHAR) {
3120 return ProcessDialogChar((char)msg.WParam);
3125 public Rectangle RectangleToClient(Rectangle r) {
3126 return new Rectangle(PointToClient(r.Location), r.Size);
3129 public Rectangle RectangleToScreen(Rectangle r) {
3130 return new Rectangle(PointToScreen(r.Location), r.Size);
3133 public virtual void Refresh() {
3134 if (IsHandleCreated == true) {
3136 XplatUI.UpdateWindow(window.Handle);
3138 Control [] controls = child_controls.GetAllControls ();
3139 for (int i=0; i < controls.Length; i++) {
3140 controls[i].Refresh();
3146 [EditorBrowsable(EditorBrowsableState.Never)]
3147 public virtual void ResetBackColor() {
3148 BackColor = Color.Empty;
3151 [EditorBrowsable(EditorBrowsableState.Never)]
3152 public void ResetBindings() {
3153 data_bindings.Clear();
3156 [EditorBrowsable(EditorBrowsableState.Never)]
3157 public virtual void ResetCursor() {
3161 [EditorBrowsable(EditorBrowsableState.Never)]
3162 public virtual void ResetFont() {
3166 [EditorBrowsable(EditorBrowsableState.Never)]
3167 public virtual void ResetForeColor() {
3168 foreground_color = Color.Empty;
3171 [EditorBrowsable(EditorBrowsableState.Never)]
3172 public void ResetImeMode() {
3173 ime_mode = DefaultImeMode;
3176 [EditorBrowsable(EditorBrowsableState.Never)]
3177 public virtual void ResetRightToLeft() {
3178 right_to_left = RightToLeft.Inherit;
3181 public virtual void ResetText() {
3182 text = String.Empty;
3185 public void ResumeLayout() {
3186 ResumeLayout (true);
3189 public void ResumeLayout(bool performLayout) {
3190 if (layout_suspended > 0) {
3194 if (layout_suspended == 0) {
3195 Control [] controls = child_controls.GetAllControls ();
3196 for (int i=0; i<controls.Length; i++) {
3197 controls [i].UpdateDistances ();
3200 if (performLayout && layout_pending) {
3206 public void Scale(float ratio) {
3207 ScaleCore(ratio, ratio);
3210 public void Scale(float dx, float dy) {
3215 public void Scale(SizeF factor) {
3216 ScaleCore(factor.Width, factor.Height);
3220 public void Select() {
3221 Select(false, false);
3224 public bool SelectNextControl(Control ctl, bool forward, bool tabStopOnly, bool nested, bool wrap) {
3229 c = GetNextControl(c, forward);
3238 if (c.CanSelect && ((c.parent == this) || nested) && (c.tab_stop || !tabStopOnly)) {
3239 c.Select (true, true);
3242 } while (c != ctl); // If we wrap back to ourselves we stop
3247 public void SendToBack() {
3248 if (parent != null) {
3249 parent.child_controls.SetChildIndex(this, parent.child_controls.Count);
3253 public void SetBounds(int x, int y, int width, int height) {
3254 SetBounds(x, y, width, height, BoundsSpecified.All);
3257 public void SetBounds(int x, int y, int width, int height, BoundsSpecified specified) {
3258 if ((specified & BoundsSpecified.X) != BoundsSpecified.X) {
3262 if ((specified & BoundsSpecified.Y) != BoundsSpecified.Y) {
3266 if ((specified & BoundsSpecified.Width) != BoundsSpecified.Width) {
3270 if ((specified & BoundsSpecified.Height) != BoundsSpecified.Height) {
3274 SetBoundsCore(x, y, width, height, specified);
3275 if (parent != null) {
3276 parent.PerformLayout(this, "Bounds");
3280 public void Show() {
3282 this.CreateControl();
3288 public void SuspendLayout() {
3292 public void Update() {
3293 if (IsHandleCreated) {
3294 XplatUI.UpdateWindow(window.Handle);
3297 #endregion // Public Instance Methods
3299 #region Protected Instance Methods
3300 [EditorBrowsable(EditorBrowsableState.Advanced)]
3301 [MonoTODO("Implement this and tie it into Control.ControlAccessibleObject.NotifyClients")]
3302 protected void AccessibilityNotifyClients(AccessibleEvents accEvent, int childID) {
3303 throw new NotImplementedException();
3306 [EditorBrowsable(EditorBrowsableState.Advanced)]
3307 protected virtual AccessibleObject CreateAccessibilityInstance() {
3308 return new Control.ControlAccessibleObject(this);
3311 [EditorBrowsable(EditorBrowsableState.Advanced)]
3312 protected virtual ControlCollection CreateControlsInstance() {
3313 return new ControlCollection(this);
3316 [EditorBrowsable(EditorBrowsableState.Advanced)]
3317 protected virtual void CreateHandle() {
3319 throw new ObjectDisposedException(GetType().FullName.ToString());
3322 if (IsHandleCreated && !is_recreating) {
3326 window.CreateHandle(CreateParams);
3328 if (window.Handle != IntPtr.Zero) {
3329 lock (Control.controls) {
3330 if (!Control.controls.Contains(window.Handle)) {
3331 Control.controls.Add(this);
3335 creator_thread = Thread.CurrentThread;
3337 XplatUI.EnableWindow(window.Handle, is_enabled);
3338 XplatUI.SetVisible(window.Handle, is_visible);
3340 if (clip_region != null) {
3341 XplatUI.SetClipRegion(Handle, clip_region);
3344 // Set our handle with our parent
3345 if ((parent != null) && (parent.IsHandleCreated)) {
3346 XplatUI.SetParent(window.Handle, parent.Handle);
3349 // Set our handle as parent for our children
3350 Control [] children;
3352 children = child_controls.GetAllControls ();
3353 for (int i = 0; i < children.Length; i++ ) {
3354 XplatUI.SetParent(children[i].Handle, window.Handle);
3358 XplatUI.SetAllowDrop (Handle, allow_drop);
3360 // Find out where the window manager placed us
3361 if ((CreateParams.Style & (int)WindowStyles.WS_CHILD) != 0) {
3362 XplatUI.SetBorderStyle(window.Handle, (FormBorderStyle)border_style);
3366 OnHandleCreated(EventArgs.Empty);
3370 [EditorBrowsable(EditorBrowsableState.Advanced)]
3371 protected virtual void DefWndProc(ref Message m) {
3372 window.DefWndProc(ref m);
3375 [EditorBrowsable(EditorBrowsableState.Advanced)]
3376 protected virtual void DestroyHandle() {
3377 if (IsHandleCreated) {
3378 if (window != null) {
3379 window.DestroyHandle();
3384 protected bool GetStyle(ControlStyles flag) {
3385 return (control_style & flag) != 0;
3388 protected bool GetTopLevel() {
3392 [EditorBrowsable(EditorBrowsableState.Advanced)]
3393 protected virtual void InitLayout() {
3397 [EditorBrowsable(EditorBrowsableState.Advanced)]
3398 protected void InvokeGotFocus(Control toInvoke, EventArgs e) {
3399 toInvoke.OnGotFocus(e);
3402 [EditorBrowsable(EditorBrowsableState.Advanced)]
3403 protected void InvokeLostFocus(Control toInvoke, EventArgs e) {
3404 toInvoke.OnLostFocus(e);
3407 [EditorBrowsable(EditorBrowsableState.Advanced)]
3408 protected void InvokeOnClick(Control toInvoke, EventArgs e) {
3409 toInvoke.OnClick(e);
3412 protected void InvokePaint(Control toInvoke, PaintEventArgs e) {
3413 toInvoke.OnPaint(e);
3416 protected void InvokePaintBackground(Control toInvoke, PaintEventArgs e) {
3417 toInvoke.OnPaintBackground(e);
3420 protected virtual bool IsInputChar (char charCode) {
3424 protected virtual bool IsInputKey (Keys keyData) {
3425 // Doc says this one calls IsInputChar; not sure what to do with that
3429 [EditorBrowsable(EditorBrowsableState.Advanced)]
3430 protected virtual void NotifyInvalidate(Rectangle invalidatedArea) {
3434 protected virtual bool ProcessCmdKey(ref Message msg, Keys keyData) {
3435 if ((context_menu != null) && context_menu.ProcessCmdKey(ref msg, keyData)) {
3439 if (parent != null) {
3440 return parent.ProcessCmdKey(ref msg, keyData);
3446 protected virtual bool ProcessDialogChar(char charCode) {
3447 if (parent != null) {
3448 return parent.ProcessDialogChar (charCode);
3454 protected virtual bool ProcessDialogKey (Keys keyData) {
3455 if (parent != null) {
3456 return parent.ProcessDialogKey (keyData);
3462 protected virtual bool ProcessKeyEventArgs (ref Message msg)
3464 KeyEventArgs key_event;
3467 case (int)Msg.WM_SYSKEYDOWN:
3468 case (int)Msg.WM_KEYDOWN: {
3469 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
3470 OnKeyDown (key_event);
3471 return key_event.Handled;
3474 case (int)Msg.WM_SYSKEYUP:
3475 case (int)Msg.WM_KEYUP: {
3476 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
3477 OnKeyUp (key_event);
3478 return key_event.Handled;
3481 case (int)Msg.WM_SYSCHAR:
3482 case (int)Msg.WM_CHAR: {
3483 KeyPressEventArgs key_press_event;
3485 key_press_event = new KeyPressEventArgs((char)msg.WParam);
3486 OnKeyPress(key_press_event);
3488 msg.WParam = (IntPtr)key_press_event.KeyChar;
3490 return key_press_event.Handled;
3501 protected internal virtual bool ProcessKeyMessage(ref Message msg) {
3502 if (parent != null) {
3503 if (parent.ProcessKeyPreview(ref msg)) {
3508 return ProcessKeyEventArgs(ref msg);
3511 protected virtual bool ProcessKeyPreview(ref Message msg) {
3512 if (parent != null) {
3513 return parent.ProcessKeyPreview(ref msg);
3519 protected virtual bool ProcessMnemonic(char charCode) {
3524 [EditorBrowsable(EditorBrowsableState.Advanced)]
3525 protected void RaiseDragEvent(object key, DragEventArgs e) {
3529 [EditorBrowsable(EditorBrowsableState.Advanced)]
3530 protected void RaiseKeyEvent(object key, KeyEventArgs e) {
3534 [EditorBrowsable(EditorBrowsableState.Advanced)]
3535 protected void RaiseMouseEvent(object key, MouseEventArgs e) {
3539 [EditorBrowsable(EditorBrowsableState.Advanced)]
3540 protected void RaisePaintEvent(object key, PaintEventArgs e) {
3544 private void SetIsRecreating ()
3548 foreach (Control c in Controls.GetAllControls()) {
3549 c.SetIsRecreating ();
3553 [EditorBrowsable(EditorBrowsableState.Advanced)]
3554 protected void RecreateHandle() {
3556 Console.WriteLine("Recreating control {0}", XplatUI.Window(window.Handle));
3561 if (IsHandleCreated) {
3563 Console.WriteLine(" + handle is created, destroying it.");
3566 // WM_DESTROY will CreateHandle for us
3569 Console.WriteLine(" + handle is not created, creating it.");
3577 is_recreating = false;
3579 Console.WriteLine (" + new handle = {0:X}", Handle.ToInt32());
3585 [EditorBrowsable(EditorBrowsableState.Advanced)]
3586 protected void ResetMouseEventArgs() {
3590 [EditorBrowsable(EditorBrowsableState.Advanced)]
3591 protected ContentAlignment RtlTranslateAlignment(ContentAlignment align) {
3592 if (right_to_left == RightToLeft.No) {
3597 case ContentAlignment.TopLeft: {
3598 return ContentAlignment.TopRight;
3601 case ContentAlignment.TopRight: {
3602 return ContentAlignment.TopLeft;
3605 case ContentAlignment.MiddleLeft: {
3606 return ContentAlignment.MiddleRight;
3609 case ContentAlignment.MiddleRight: {
3610 return ContentAlignment.MiddleLeft;
3613 case ContentAlignment.BottomLeft: {
3614 return ContentAlignment.BottomRight;
3617 case ContentAlignment.BottomRight: {
3618 return ContentAlignment.BottomLeft;
3622 // if it's center it doesn't change
3628 [EditorBrowsable(EditorBrowsableState.Advanced)]
3629 protected HorizontalAlignment RtlTranslateAlignment(HorizontalAlignment align) {
3630 if ((right_to_left == RightToLeft.No) || (align == HorizontalAlignment.Center)) {
3634 if (align == HorizontalAlignment.Left) {
3635 return HorizontalAlignment.Right;
3638 // align must be HorizontalAlignment.Right
3639 return HorizontalAlignment.Left;
3642 [EditorBrowsable(EditorBrowsableState.Advanced)]
3643 protected LeftRightAlignment RtlTranslateAlignment(LeftRightAlignment align) {
3644 if (right_to_left == RightToLeft.No) {
3648 if (align == LeftRightAlignment.Left) {
3649 return LeftRightAlignment.Right;
3652 // align must be LeftRightAlignment.Right;
3653 return LeftRightAlignment.Left;
3656 [EditorBrowsable(EditorBrowsableState.Advanced)]
3657 protected ContentAlignment RtlTranslateContent(ContentAlignment align) {
3658 return RtlTranslateAlignment(align);
3661 [EditorBrowsable(EditorBrowsableState.Advanced)]
3662 protected HorizontalAlignment RtlTranslateHorizontal(HorizontalAlignment align) {
3663 return RtlTranslateAlignment(align);
3666 [EditorBrowsable(EditorBrowsableState.Advanced)]
3667 protected LeftRightAlignment RtlTranslateLeftRight(LeftRightAlignment align) {
3668 return RtlTranslateAlignment(align);
3671 [EditorBrowsable(EditorBrowsableState.Advanced)]
3672 protected virtual void ScaleCore(float dx, float dy) {
3678 location = new Point((int)(Left * dx), (int)(Top * dy));
3679 size = this.ClientSize;
3681 if (!GetStyle(ControlStyles.FixedWidth)) {
3682 size.Width = (int)(size.Width * dx);
3685 if (!GetStyle(ControlStyles.FixedHeight)) {
3686 size.Height = (int)(size.Height * dy);
3689 SetBounds(location.X, location.Y, size.Width, size.Height, BoundsSpecified.All);
3691 /* Now scale our children */
3692 Control [] controls = child_controls.GetAllControls ();
3693 for (int i=0; i < controls.Length; i++) {
3694 controls[i].Scale(dx, dy);
3700 protected virtual void Select(bool directed, bool forward) {
3701 IContainerControl container;
3703 container = GetContainerControl();
3704 if (container != null)
3705 container.ActiveControl = this;
3708 [EditorBrowsable(EditorBrowsableState.Advanced)]
3709 protected virtual void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
3710 // SetBoundsCore updates the Win32 control itself. UpdateBounds updates the controls variables and fires events, I'm guessing - pdb
3711 if (IsHandleCreated) {
3712 XplatUI.SetWindowPos(Handle, x, y, width, height);
3715 UpdateBounds(x, y, width, height);
3720 [EditorBrowsable(EditorBrowsableState.Advanced)]
3721 protected virtual void SetClientSizeCore(int x, int y) {
3722 // Calculate the actual window size from the client size (it usually stays the same or grows)
3723 Rectangle ClientRect;
3724 Rectangle WindowRect;
3727 ClientRect = new Rectangle(0, 0, x, y);
3728 cp = this.CreateParams;
3730 if (XplatUI.CalculateWindowRect(ref ClientRect, cp.Style, cp.ExStyle, null, out WindowRect)==false) {
3734 SetBounds(bounds.X, bounds.Y, WindowRect.Width, WindowRect.Height, BoundsSpecified.Size);
3737 [EditorBrowsable(EditorBrowsableState.Advanced)]
3738 protected void SetStyle(ControlStyles flag, bool value) {
3740 control_style |= flag;
3742 control_style &= ~flag;
3746 protected void SetTopLevel(bool value) {
3747 if ((GetTopLevel() != value) && (parent != null)) {
3748 throw new Exception();
3752 if (value == true) {
3762 is_toplevel = value;
3765 protected virtual void SetVisibleCore(bool value) {
3766 if (value!=is_visible) {
3767 if (value && (window.Handle == IntPtr.Zero) || !is_created) {
3773 if (IsHandleCreated) {
3774 XplatUI.SetVisible(Handle, value);
3775 // Explicitly move Toplevel windows to where we want them;
3776 // apparently moving unmapped toplevel windows doesn't work
3777 if (is_visible && (this is Form)) {
3778 XplatUI.SetWindowPos(window.Handle, bounds.X, bounds.Y, bounds.Width, bounds.Height);
3782 OnVisibleChanged(EventArgs.Empty);
3784 if (value == false && parent != null && Focused) {
3787 // Need to start at parent, GetContainerControl might return ourselves if we're a container
3788 container = (Control)parent.GetContainerControl();
3789 if (container != null) {
3790 container.SelectNextControl(this, true, true, true, true);
3794 if (parent != null) {
3795 parent.PerformLayout(this, "visible");
3797 PerformLayout(this, "visible");
3802 [EditorBrowsable(EditorBrowsableState.Advanced)]
3803 protected void UpdateBounds() {
3811 if (!IsHandleCreated) {
3815 XplatUI.GetWindowPos(this.Handle, this is Form, out x, out y, out width, out height, out client_width, out client_height);
3817 UpdateBounds(x, y, width, height, client_width, client_height);
3820 [EditorBrowsable(EditorBrowsableState.Advanced)]
3821 protected void UpdateBounds(int x, int y, int width, int height) {
3825 // Calculate client rectangle
3826 rect = new Rectangle(0, 0, 0, 0);
3829 XplatUI.CalculateWindowRect(ref rect, cp.Style, cp.ExStyle, cp.menu, out rect);
3830 UpdateBounds(x, y, width, height, width - (rect.Right - rect.Left), height - (rect.Bottom - rect.Top));
3833 [EditorBrowsable(EditorBrowsableState.Advanced)]
3834 protected void UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) {
3835 // UpdateBounds only seems to set our sizes and fire events but not update the GUI window to match
3837 bool resized = false;
3839 // Needed to generate required notifications
3840 if ((this.bounds.X!=x) || (this.bounds.Y!=y)) {
3844 if ((this.Bounds.Width!=width) || (this.Bounds.Height!=height)) {
3851 bounds.Height=height;
3853 client_size.Width=clientWidth;
3854 client_size.Height=clientHeight;
3857 OnLocationChanged(EventArgs.Empty);
3861 OnSizeChanged(EventArgs.Empty);
3865 [EditorBrowsable(EditorBrowsableState.Advanced)]
3866 protected void UpdateStyles() {
3867 if (!IsHandleCreated) {
3871 XplatUI.SetWindowStyle(window.Handle, CreateParams);
3872 OnStyleChanged(EventArgs.Empty);
3875 private void UpdateZOrderOfChild(Control child) {
3876 if (IsHandleCreated && child.IsHandleCreated && (child.parent == this)) {
3879 index = child_controls.IndexOf(child);
3882 XplatUI.SetZOrder(child.Handle, child_controls[index - 1].Handle, false, false);
3884 XplatUI.SetZOrder(child.Handle, IntPtr.Zero, true, false);
3889 private void UpdateChildrenZOrder() {
3890 Control [] controls;
3892 if (!IsHandleCreated) {
3896 controls = child_controls.GetAllControls ();
3897 for (int i = 1; i < controls.Length; i++ ) {
3898 XplatUI.SetZOrder(controls[i].Handle, controls[i-1].Handle, false, false);
3902 [EditorBrowsable(EditorBrowsableState.Advanced)]
3903 protected void UpdateZOrder() {
3904 if (parent != null) {
3905 parent.UpdateZOrderOfChild(this);
3909 protected virtual void WndProc(ref Message m) {
3911 Console.WriteLine("Control {0} received message {1}", window.Handle == IntPtr.Zero ? this.Text : XplatUI.Window(window.Handle), (Msg)m.Msg);
3913 if ((this.control_style & ControlStyles.EnableNotifyMessage) != 0) {
3917 switch((Msg)m.Msg) {
3918 case Msg.WM_DESTROY: {
3919 OnHandleDestroyed(EventArgs.Empty);
3921 IntPtr handle = window.Handle;
3923 window.InvalidateHandle();
3925 if (is_recreating) {
3927 Console.WriteLine ("Creating handle for {0:X}", handle.ToInt32());
3931 Console.WriteLine (" + new handle = {0:X}", Handle.ToInt32());
3933 is_recreating = false;
3938 case Msg.WM_WINDOWPOSCHANGED: {
3941 if (GetStyle(ControlStyles.ResizeRedraw)) {
3948 // Nice description of what should happen when handling WM_PAINT
3949 // can be found here: http://pluralsight.com/wiki/default.aspx/Craig/FlickerFreeControlDrawing.html
3950 // and here http://msdn.microsoft.com/msdnmag/issues/06/03/WindowsFormsPerformance/
3951 case Msg.WM_PAINT: {
3952 PaintEventArgs paint_event;
3954 paint_event = XplatUI.PaintEventStart(Handle, true);
3956 if (paint_event == null) {
3960 if (invalid_region != null && !invalid_region.IsVisible (paint_event.ClipRectangle)) {
3961 // Just blit the previous image
3962 paint_event.Graphics.DrawImage (ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle, GraphicsUnit.Pixel);
3963 XplatUI.PaintEventEnd(Handle, true);
3968 Graphics back_dc = null;
3969 Bitmap backbuffer = null;
3970 if (ThemeEngine.Current.DoubleBufferingSupported) {
3971 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
3972 backbuffer = ImageBuffer;
3973 back_dc = Graphics.FromImage (backbuffer);
3974 dc = paint_event.SetGraphics (back_dc);
3978 if (!GetStyle(ControlStyles.Opaque)) {
3979 OnPaintBackground(paint_event);
3982 // Button-derived controls choose to ignore their Opaque style, give them a chance to draw their background anyways
3983 OnPaintBackgroundInternal(paint_event);
3985 OnPaintInternal(paint_event);
3986 if (!paint_event.Handled) {
3987 OnPaint(paint_event);
3990 if (ThemeEngine.Current.DoubleBufferingSupported)
3991 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
3992 dc.DrawImage (ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle, GraphicsUnit.Pixel);
3993 paint_event.SetGraphics (dc);
3994 invalid_region.Exclude (paint_event.ClipRectangle);
3996 if (backbuffer != bmp_mem)
3997 backbuffer.Dispose();
4000 XplatUI.PaintEventEnd(Handle, true);
4005 case Msg.WM_ERASEBKGND: {
4006 // The DefWndProc will never have to handle this, we always paint the background in managed code
4007 // In theory this code would look at ControlStyles.AllPaintingInWmPaint and and call OnPaintBackground
4008 // here but it just makes things more complicated...
4009 m.Result = (IntPtr)1;
4013 case Msg.WM_LBUTTONUP: {
4016 me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Left,
4018 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4021 HandleClick(mouse_clicks, me);
4024 if (InternalCapture) {
4025 InternalCapture = false;
4028 if (mouse_clicks > 1) {
4034 case Msg.WM_LBUTTONDOWN: {
4036 Select (true, true);
4038 InternalCapture = true;
4039 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4040 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4046 case Msg.WM_LBUTTONDBLCLK: {
4047 InternalCapture = true;
4049 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4050 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4056 case Msg.WM_MBUTTONUP: {
4059 me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Middle,
4061 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4064 HandleClick(mouse_clicks, me);
4066 if (InternalCapture) {
4067 InternalCapture = false;
4069 if (mouse_clicks > 1) {
4075 case Msg.WM_MBUTTONDOWN: {
4076 InternalCapture = true;
4077 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4078 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4084 case Msg.WM_MBUTTONDBLCLK: {
4085 InternalCapture = true;
4087 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4088 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4093 case Msg.WM_RBUTTONUP: {
4097 pt = new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()));
4098 pt = PointToScreen(pt);
4100 XplatUI.SendMessage(m.HWnd, Msg.WM_CONTEXTMENU, m.HWnd, (IntPtr)(pt.X + (pt.Y << 16)));
4102 me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Right,
4104 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4107 HandleClick(mouse_clicks, me);
4110 if (InternalCapture) {
4111 InternalCapture = false;
4114 if (mouse_clicks > 1) {
4120 case Msg.WM_RBUTTONDOWN: {
4121 InternalCapture = true;
4122 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4123 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4128 case Msg.WM_RBUTTONDBLCLK: {
4129 InternalCapture = true;
4131 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4132 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4137 case Msg.WM_CONTEXTMENU: {
4138 if (context_menu != null) {
4141 pt = new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()));
4142 context_menu.Show(this, PointToClient(pt));
4150 case Msg.WM_MOUSEWHEEL: {
4152 OnMouseWheel (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4153 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4154 HighOrder(m.WParam.ToInt32())));
4159 case Msg.WM_MOUSEMOVE: {
4160 OnMouseMove (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4162 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4167 case Msg.WM_MOUSE_ENTER: {
4172 OnMouseEnter(EventArgs.Empty);
4176 case Msg.WM_MOUSE_LEAVE: {
4178 OnMouseLeave(EventArgs.Empty);
4182 case Msg.WM_MOUSEHOVER: {
4183 OnMouseHover(EventArgs.Empty);
4187 case Msg.WM_SYSKEYUP: {
4188 if (ProcessKeyMessage(ref m)) {
4189 m.Result = IntPtr.Zero;
4193 if ((m.WParam.ToInt32() & (int)Keys.KeyCode) == (int)Keys.Menu) {
4197 if (form != null && form.ActiveMenu != null) {
4198 form.ActiveMenu.ProcessCmdKey(ref m, (Keys)m.WParam.ToInt32());
4206 case Msg.WM_SYSKEYDOWN:
4207 case Msg.WM_KEYDOWN:
4209 case Msg.WM_SYSCHAR:
4211 if (ProcessKeyMessage(ref m)) {
4212 m.Result = IntPtr.Zero;
4221 if (m.LParam != IntPtr.Zero) {
4224 hi = new HELPINFO();
4226 hi = (HELPINFO) Marshal.PtrToStructure (m.LParam, typeof (HELPINFO));
4227 mouse_pos = new Point(hi.MousePos.x, hi.MousePos.y);
4229 mouse_pos = Control.MousePosition;
4231 OnHelpRequested(new HelpEventArgs(mouse_pos));
4232 m.Result = (IntPtr)1;
4236 case Msg.WM_KILLFOCUS: {
4237 this.has_focus = false;
4238 OnLostFocusInternal (EventArgs.Empty);
4242 case Msg.WM_SETFOCUS: {
4244 this.has_focus = true;
4245 OnGotFocusInternal (EventArgs.Empty);
4251 case Msg.WM_SYSCOLORCHANGE: {
4252 ThemeEngine.Current.ResetDefaults();
4253 OnSystemColorsChanged(EventArgs.Empty);
4258 case Msg.WM_SETCURSOR: {
4259 if ((cursor == null) || ((HitTest)(m.LParam.ToInt32() & 0xffff) != HitTest.HTCLIENT)) {
4264 XplatUI.SetCursor(window.Handle, cursor.handle);
4265 m.Result = (IntPtr)1;
4276 #endregion // Public Instance Methods
4278 #region OnXXX methods
4279 [EditorBrowsable(EditorBrowsableState.Advanced)]
4280 protected virtual void OnBackColorChanged(EventArgs e) {
4281 if (BackColorChanged!=null) BackColorChanged(this, e);
4282 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackColorChanged(e);
4285 [EditorBrowsable(EditorBrowsableState.Advanced)]
4286 protected virtual void OnBackgroundImageChanged(EventArgs e) {
4287 if (BackgroundImageChanged!=null) BackgroundImageChanged(this, e);
4288 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackgroundImageChanged(e);
4291 [EditorBrowsable(EditorBrowsableState.Advanced)]
4292 protected virtual void OnBindingContextChanged(EventArgs e) {
4293 CheckDataBindings ();
4294 if (BindingContextChanged!=null) {
4295 BindingContextChanged(this, e);
4297 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBindingContextChanged(e);
4300 [EditorBrowsable(EditorBrowsableState.Advanced)]
4301 protected virtual void OnCausesValidationChanged(EventArgs e) {
4302 if (CausesValidationChanged!=null) CausesValidationChanged(this, e);
4305 [EditorBrowsable(EditorBrowsableState.Advanced)]
4306 protected virtual void OnChangeUICues(UICuesEventArgs e) {
4307 if (ChangeUICues!=null) ChangeUICues(this, e);
4310 [EditorBrowsable(EditorBrowsableState.Advanced)]
4311 protected virtual void OnClick(EventArgs e) {
4312 if (Click!=null) Click(this, e);
4315 [EditorBrowsable(EditorBrowsableState.Advanced)]
4316 protected virtual void OnContextMenuChanged(EventArgs e) {
4317 if (ContextMenuChanged!=null) ContextMenuChanged(this, e);
4320 [EditorBrowsable(EditorBrowsableState.Advanced)]
4321 protected virtual void OnControlAdded(ControlEventArgs e) {
4322 if (ControlAdded!=null) ControlAdded(this, e);
4325 [EditorBrowsable(EditorBrowsableState.Advanced)]
4326 protected virtual void OnControlRemoved(ControlEventArgs e) {
4327 if (ControlRemoved!=null) ControlRemoved(this, e);
4330 [EditorBrowsable(EditorBrowsableState.Advanced)]
4331 protected virtual void OnCreateControl() {
4335 [EditorBrowsable(EditorBrowsableState.Advanced)]
4336 protected virtual void OnCursorChanged(EventArgs e) {
4337 if (CursorChanged!=null) CursorChanged(this, e);
4340 [EditorBrowsable(EditorBrowsableState.Advanced)]
4341 protected virtual void OnDockChanged(EventArgs e) {
4342 if (DockChanged!=null) DockChanged(this, e);
4345 [EditorBrowsable(EditorBrowsableState.Advanced)]
4346 protected virtual void OnDoubleClick(EventArgs e) {
4347 if (DoubleClick!=null) DoubleClick(this, e);
4350 [EditorBrowsable(EditorBrowsableState.Advanced)]
4351 protected virtual void OnDragDrop(DragEventArgs drgevent) {
4352 if (DragDrop!=null) DragDrop(this, drgevent);
4355 [EditorBrowsable(EditorBrowsableState.Advanced)]
4356 protected virtual void OnDragEnter(DragEventArgs drgevent) {
4357 if (DragEnter!=null) DragEnter(this, drgevent);
4360 [EditorBrowsable(EditorBrowsableState.Advanced)]
4361 protected virtual void OnDragLeave(EventArgs e) {
4362 if (DragLeave!=null) DragLeave(this, e);
4365 [EditorBrowsable(EditorBrowsableState.Advanced)]
4366 protected virtual void OnDragOver(DragEventArgs drgevent) {
4367 if (DragOver!=null) DragOver(this, drgevent);
4370 [EditorBrowsable(EditorBrowsableState.Advanced)]
4371 protected virtual void OnEnabledChanged(EventArgs e) {
4372 if (IsHandleCreated) {
4374 if (((Form)this).context == null) {
4375 XplatUI.EnableWindow(window.Handle, Enabled);
4378 XplatUI.EnableWindow(window.Handle, Enabled);
4383 if (EnabledChanged != null) {
4384 EnabledChanged(this, e);
4387 for (int i=0; i<child_controls.Count; i++) {
4388 child_controls[i].OnParentEnabledChanged(e);
4392 [EditorBrowsable(EditorBrowsableState.Advanced)]
4393 protected virtual void OnEnter(EventArgs e) {
4394 if (Enter!=null) Enter(this, e);
4397 [EditorBrowsable(EditorBrowsableState.Advanced)]
4398 protected virtual void OnFontChanged(EventArgs e) {
4399 if (FontChanged!=null) FontChanged(this, e);
4400 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentFontChanged(e);
4403 [EditorBrowsable(EditorBrowsableState.Advanced)]
4404 protected virtual void OnForeColorChanged(EventArgs e) {
4405 if (ForeColorChanged!=null) ForeColorChanged(this, e);
4406 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentForeColorChanged(e);
4409 [EditorBrowsable(EditorBrowsableState.Advanced)]
4410 protected virtual void OnGiveFeedback(GiveFeedbackEventArgs gfbevent) {
4411 if (GiveFeedback!=null) GiveFeedback(this, gfbevent);
4414 [EditorBrowsable(EditorBrowsableState.Advanced)]
4415 protected virtual void OnGotFocus(EventArgs e) {
4416 if (GotFocus!=null) GotFocus(this, e);
4419 [EditorBrowsable(EditorBrowsableState.Advanced)]
4420 protected virtual void OnHandleCreated(EventArgs e) {
4421 if (HandleCreated!=null) HandleCreated(this, e);
4424 [EditorBrowsable(EditorBrowsableState.Advanced)]
4425 protected virtual void OnHandleDestroyed(EventArgs e) {
4426 if (HandleDestroyed!=null) HandleDestroyed(this, e);
4429 [EditorBrowsable(EditorBrowsableState.Advanced)]
4430 protected virtual void OnHelpRequested(HelpEventArgs hevent) {
4431 if (HelpRequested!=null) HelpRequested(this, hevent);
4434 protected virtual void OnImeModeChanged(EventArgs e) {
4435 if (ImeModeChanged!=null) ImeModeChanged(this, e);
4438 [EditorBrowsable(EditorBrowsableState.Advanced)]
4439 protected virtual void OnInvalidated(InvalidateEventArgs e) {
4440 if (ThemeEngine.Current.DoubleBufferingSupported)
4441 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
4442 // should this block be here? seems like it
4443 // would be more at home in
4444 // NotifyInvalidated..
4445 if (e.InvalidRect == ClientRectangle) {
4446 ImageBufferNeedsRedraw ();
4449 // we need this Inflate call here so
4450 // that the border of the rectangle is
4451 // considered Visible (the
4452 // invalid_region.IsVisible call) in
4453 // the WM_PAINT handling below.
4454 Rectangle r = Rectangle.Inflate(e.InvalidRect, 1,1);
4455 if (invalid_region == null)
4456 invalid_region = new Region (r);
4458 invalid_region.Union (r);
4461 if (Invalidated!=null) Invalidated(this, e);
4464 [EditorBrowsable(EditorBrowsableState.Advanced)]
4465 protected virtual void OnKeyDown(KeyEventArgs e) {
4466 if (KeyDown!=null) KeyDown(this, e);
4469 [EditorBrowsable(EditorBrowsableState.Advanced)]
4470 protected virtual void OnKeyPress(KeyPressEventArgs e) {
4471 if (KeyPress!=null) KeyPress(this, e);
4474 [EditorBrowsable(EditorBrowsableState.Advanced)]
4475 protected virtual void OnKeyUp(KeyEventArgs e) {
4476 if (KeyUp!=null) KeyUp(this, e);
4479 [EditorBrowsable(EditorBrowsableState.Advanced)]
4480 protected virtual void OnLayout(LayoutEventArgs levent) {
4481 if (Layout!=null) Layout(this, levent);
4484 [EditorBrowsable(EditorBrowsableState.Advanced)]
4485 protected virtual void OnLeave(EventArgs e) {
4486 if (Leave!=null) Leave(this, e);
4489 [EditorBrowsable(EditorBrowsableState.Advanced)]
4490 protected virtual void OnLocationChanged(EventArgs e) {
4492 if (LocationChanged!=null) LocationChanged(this, e);
4495 [EditorBrowsable(EditorBrowsableState.Advanced)]
4496 protected virtual void OnLostFocus(EventArgs e) {
4497 if (LostFocus!=null) LostFocus(this, e);
4500 [EditorBrowsable(EditorBrowsableState.Advanced)]
4501 protected virtual void OnMouseDown(MouseEventArgs e) {
4502 if (MouseDown!=null) MouseDown(this, e);
4505 [EditorBrowsable(EditorBrowsableState.Advanced)]
4506 protected virtual void OnMouseEnter(EventArgs e) {
4507 if (MouseEnter!=null) MouseEnter(this, e);
4510 [EditorBrowsable(EditorBrowsableState.Advanced)]
4511 protected virtual void OnMouseHover(EventArgs e) {
4512 if (MouseHover!=null) MouseHover(this, e);
4515 [EditorBrowsable(EditorBrowsableState.Advanced)]
4516 protected virtual void OnMouseLeave(EventArgs e) {
4517 if (MouseLeave!=null) MouseLeave(this, e);
4520 [EditorBrowsable(EditorBrowsableState.Advanced)]
4521 protected virtual void OnMouseMove(MouseEventArgs e) {
4522 if (MouseMove!=null) MouseMove(this, e);
4525 [EditorBrowsable(EditorBrowsableState.Advanced)]
4526 protected virtual void OnMouseUp(MouseEventArgs e) {
4527 if (MouseUp!=null) MouseUp(this, e);
4530 [EditorBrowsable(EditorBrowsableState.Advanced)]
4531 protected virtual void OnMouseWheel(MouseEventArgs e) {
4532 if (MouseWheel!=null) MouseWheel(this, e);
4535 [EditorBrowsable(EditorBrowsableState.Advanced)]
4536 protected virtual void OnMove(EventArgs e) {
4537 if (Move!=null) Move(this, e);
4540 [EditorBrowsable(EditorBrowsableState.Advanced)]
4541 protected virtual void OnNotifyMessage(Message m) {
4545 [EditorBrowsable(EditorBrowsableState.Advanced)]
4546 protected virtual void OnPaint(PaintEventArgs e) {
4547 if (Paint!=null) Paint(this, e);
4550 internal virtual void OnPaintBackgroundInternal(PaintEventArgs e) {
4554 internal virtual void OnPaintInternal(PaintEventArgs e) {
4558 internal virtual void OnGotFocusInternal (EventArgs e)
4563 internal virtual void OnLostFocusInternal (EventArgs e)
4568 [EditorBrowsable(EditorBrowsableState.Advanced)]
4569 protected virtual void OnPaintBackground(PaintEventArgs pevent) {
4570 PaintControlBackground (pevent);
4573 [EditorBrowsable(EditorBrowsableState.Advanced)]
4574 protected virtual void OnParentBackColorChanged(EventArgs e) {
4575 if (background_color.IsEmpty && background_image==null) {
4577 OnBackColorChanged(e);
4581 [EditorBrowsable(EditorBrowsableState.Advanced)]
4582 protected virtual void OnParentBackgroundImageChanged(EventArgs e) {
4583 if (background_color.IsEmpty && background_image==null) {
4585 OnBackgroundImageChanged(e);
4589 [EditorBrowsable(EditorBrowsableState.Advanced)]
4590 protected virtual void OnParentBindingContextChanged(EventArgs e) {
4591 if (binding_context==null) {
4592 binding_context=Parent.binding_context;
4593 OnBindingContextChanged(e);
4597 [EditorBrowsable(EditorBrowsableState.Advanced)]
4598 protected virtual void OnParentChanged(EventArgs e) {
4599 if (ParentChanged!=null) ParentChanged(this, e);
4602 [EditorBrowsable(EditorBrowsableState.Advanced)]
4603 protected virtual void OnParentEnabledChanged(EventArgs e) {
4605 OnEnabledChanged(e);
4609 [EditorBrowsable(EditorBrowsableState.Advanced)]
4610 protected virtual void OnParentFontChanged(EventArgs e) {
4617 [EditorBrowsable(EditorBrowsableState.Advanced)]
4618 protected virtual void OnParentForeColorChanged(EventArgs e) {
4619 if (foreground_color.IsEmpty) {
4621 OnForeColorChanged(e);
4625 [EditorBrowsable(EditorBrowsableState.Advanced)]
4626 protected virtual void OnParentRightToLeftChanged(EventArgs e) {
4627 if (right_to_left==RightToLeft.Inherit) {
4629 OnRightToLeftChanged(e);
4633 [EditorBrowsable(EditorBrowsableState.Advanced)]
4634 protected virtual void OnParentVisibleChanged(EventArgs e) {
4636 OnVisibleChanged(e);
4640 [EditorBrowsable(EditorBrowsableState.Advanced)]
4641 protected virtual void OnQueryContinueDrag(QueryContinueDragEventArgs e) {
4642 if (QueryContinueDrag!=null) QueryContinueDrag(this, e);
4645 [EditorBrowsable(EditorBrowsableState.Advanced)]
4646 protected virtual void OnResize(EventArgs e) {
4647 if (Resize!=null) Resize(this, e);
4649 PerformLayout(this, "bounds");
4651 if (parent != null) {
4652 parent.PerformLayout();
4656 [EditorBrowsable(EditorBrowsableState.Advanced)]
4657 protected virtual void OnRightToLeftChanged(EventArgs e) {
4658 if (RightToLeftChanged!=null) RightToLeftChanged(this, e);
4659 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentRightToLeftChanged(e);
4662 [EditorBrowsable(EditorBrowsableState.Advanced)]
4663 protected virtual void OnSizeChanged(EventArgs e) {
4664 InvalidateBuffers ();
4666 if (SizeChanged!=null) SizeChanged(this, e);
4669 [EditorBrowsable(EditorBrowsableState.Advanced)]
4670 protected virtual void OnStyleChanged(EventArgs e) {
4671 if (StyleChanged!=null) StyleChanged(this, e);
4674 [EditorBrowsable(EditorBrowsableState.Advanced)]
4675 protected virtual void OnSystemColorsChanged(EventArgs e) {
4676 if (SystemColorsChanged!=null) SystemColorsChanged(this, e);
4679 [EditorBrowsable(EditorBrowsableState.Advanced)]
4680 protected virtual void OnTabIndexChanged(EventArgs e) {
4681 if (TabIndexChanged!=null) TabIndexChanged(this, e);
4684 [EditorBrowsable(EditorBrowsableState.Advanced)]
4685 protected virtual void OnTabStopChanged(EventArgs e) {
4686 if (TabStopChanged!=null) TabStopChanged(this, e);
4689 [EditorBrowsable(EditorBrowsableState.Advanced)]
4690 protected virtual void OnTextChanged(EventArgs e) {
4691 if (TextChanged!=null) TextChanged(this, e);
4694 [EditorBrowsable(EditorBrowsableState.Advanced)]
4695 protected virtual void OnValidated(EventArgs e) {
4696 if (Validated!=null) Validated(this, e);
4699 [EditorBrowsable(EditorBrowsableState.Advanced)]
4700 protected virtual void OnValidating(System.ComponentModel.CancelEventArgs e) {
4701 if (Validating!=null) Validating(this, e);
4704 [EditorBrowsable(EditorBrowsableState.Advanced)]
4705 protected virtual void OnVisibleChanged(EventArgs e) {
4706 if ((parent != null) && !Created && Visible) {
4713 if (VisibleChanged!=null) VisibleChanged(this, e);
4715 // We need to tell our kids
4716 for (int i=0; i<child_controls.Count; i++) {
4717 if (child_controls[i].Visible) {
4718 child_controls[i].OnParentVisibleChanged(e);
4722 #endregion // OnXXX methods
4725 public event EventHandler BackColorChanged;
4726 public event EventHandler BackgroundImageChanged;
4727 public event EventHandler BindingContextChanged;
4728 public event EventHandler CausesValidationChanged;
4729 public event UICuesEventHandler ChangeUICues;
4730 public event EventHandler Click;
4731 public event EventHandler ContextMenuChanged;
4733 [EditorBrowsable(EditorBrowsableState.Advanced)]
4735 public event ControlEventHandler ControlAdded;
4737 [EditorBrowsable(EditorBrowsableState.Advanced)]
4739 public event ControlEventHandler ControlRemoved;
4741 [MWFDescription("Fired when the cursor for the control has been changed"), MWFCategory("PropertyChanged")]
4742 public event EventHandler CursorChanged;
4743 public event EventHandler DockChanged;
4744 public event EventHandler DoubleClick;
4745 public event DragEventHandler DragDrop;
4746 public event DragEventHandler DragEnter;
4747 public event EventHandler DragLeave;
4748 public event DragEventHandler DragOver;
4749 public event EventHandler EnabledChanged;
4750 public event EventHandler Enter;
4751 public event EventHandler FontChanged;
4752 public event EventHandler ForeColorChanged;
4753 public event GiveFeedbackEventHandler GiveFeedback;
4755 [EditorBrowsable(EditorBrowsableState.Advanced)]
4757 public event EventHandler GotFocus;
4759 [EditorBrowsable(EditorBrowsableState.Advanced)]
4761 public event EventHandler HandleCreated;
4763 [EditorBrowsable(EditorBrowsableState.Advanced)]
4765 public event EventHandler HandleDestroyed;
4767 public event HelpEventHandler HelpRequested;
4768 public event EventHandler ImeModeChanged;
4770 [EditorBrowsable(EditorBrowsableState.Advanced)]
4772 public event InvalidateEventHandler Invalidated;
4774 public event KeyEventHandler KeyDown;
4775 public event KeyPressEventHandler KeyPress;
4776 public event KeyEventHandler KeyUp;
4777 public event LayoutEventHandler Layout;
4778 public event EventHandler Leave;
4779 public event EventHandler LocationChanged;
4781 [EditorBrowsable(EditorBrowsableState.Advanced)]
4783 public event EventHandler LostFocus;
4785 public event MouseEventHandler MouseDown;
4786 public event EventHandler MouseEnter;
4787 public event EventHandler MouseHover;
4788 public event EventHandler MouseLeave;
4789 public event MouseEventHandler MouseMove;
4790 public event MouseEventHandler MouseUp;
4792 [EditorBrowsable(EditorBrowsableState.Advanced)]
4794 public event MouseEventHandler MouseWheel;
4796 public event EventHandler Move;
4797 public event PaintEventHandler Paint;
4798 public event EventHandler ParentChanged;
4799 public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp;
4800 public event QueryContinueDragEventHandler QueryContinueDrag;
4801 public event EventHandler Resize;
4802 public event EventHandler RightToLeftChanged;
4803 public event EventHandler SizeChanged;
4804 public event EventHandler StyleChanged;
4805 public event EventHandler SystemColorsChanged;
4806 public event EventHandler TabIndexChanged;
4807 public event EventHandler TabStopChanged;
4808 public event EventHandler TextChanged;
4809 public event EventHandler Validated;
4810 public event CancelEventHandler Validating;
4811 public event EventHandler VisibleChanged;
4812 #endregion // Events