1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 // Copyright (c) 2004-2006 Novell, Inc.
23 // Peter Bartok pbartok@novell.com
25 // Partially based on work by:
26 // Aleksey Ryabchuk ryabchuk@yahoo.com
27 // Alexandre Pigolkine pigolkine@gmx.de
28 // Dennis Hayes dennish@raytek.com
29 // Jaak Simm jaaksimm@firm.ee
30 // John Sohn jsohn@columbus.rr.com
36 using System.ComponentModel;
37 using System.ComponentModel.Design;
38 using System.ComponentModel.Design.Serialization;
39 using System.Collections;
40 using System.Diagnostics;
42 using System.Drawing.Drawing2D;
43 using System.Reflection;
44 using System.Runtime.InteropServices;
45 using System.Security;
46 using System.Threading;
49 namespace System.Windows.Forms
51 [Designer("System.Windows.Forms.Design.ControlDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
52 [DefaultProperty("Text")]
53 [DefaultEvent("Click")]
54 [DesignerSerializer("System.Windows.Forms.Design.ControlCodeDomSerializer, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
55 [ToolboxItemFilter("System.Windows.Forms")]
56 public class Control : Component, ISynchronizeInvoke, IWin32Window
58 #region Local Variables
61 internal Rectangle bounds; // bounding rectangle for control (client area + decorations)
62 internal object creator_thread; // thread that created the control
63 internal ControlNativeWindow window; // object for native window handle
64 internal string name; // for object naming
67 internal bool is_created; // true if OnCreateControl has been sent
68 internal bool has_focus; // true if control has focus
69 internal bool is_visible; // true if control is visible
70 internal bool is_entered; // is the mouse inside the control?
71 internal bool is_enabled; // true if control is enabled (usable/not grayed out)
72 internal bool is_accessible; // true if the control is visible to accessibility applications
73 internal bool is_captured; // tracks if the control has captured the mouse
74 internal bool is_toplevel; // tracks if the control is a toplevel window
75 internal bool is_recreating; // tracks if the handle for the control is being recreated
76 internal bool causes_validation; // tracks if validation is executed on changes
77 internal int tab_index; // position in tab order of siblings
78 internal bool tab_stop = true; // is the control a tab stop?
79 internal bool is_disposed; // has the window already been disposed?
80 internal Size client_size; // size of the client area (window excluding decorations)
81 internal Rectangle client_rect; // rectangle with the client area (window excluding decorations)
82 internal ControlStyles control_style; // rather win32-specific, style bits for control
83 internal ImeMode ime_mode = ImeMode.Inherit;
84 internal bool layout_pending; // true if our parent needs to re-layout us
85 internal object control_tag; // object that contains data about our control
86 internal int mouse_clicks; // Counter for mouse clicks
87 internal Cursor cursor; // Cursor for the window
88 internal bool allow_drop; // true if the control accepts droping objects on it
89 internal Region clip_region; // User-specified clip region for the window
92 internal Color foreground_color; // foreground color for control
93 internal Color background_color; // background color for control
94 internal Image background_image; // background image for control
95 internal Font font; // font for control
96 internal string text; // window/title text for control
97 internal BorderStyle border_style; // Border style of control
100 internal AnchorStyles anchor_style; // anchoring requirements for our control
101 internal DockStyle dock_style; // docking requirements for our control (supercedes anchoring)
102 internal int dist_left; // distance to the left border of the parent
103 internal int dist_top; // distance to the top border of the parent
104 internal int dist_right; // distance to the right border of the parent
105 internal int dist_bottom; // distance to the bottom border of the parent
107 // to be categorized...
108 static internal ArrayList controls = new ArrayList(); // All of the application's controls, in a flat list
109 internal ControlCollection child_controls; // our children
110 internal Control parent; // our parent control
111 internal AccessibleObject accessibility_object; // object that contains accessibility information about our control
112 internal BindingContext binding_context; // TODO
113 internal RightToLeft right_to_left; // drawing direction for control
114 internal int layout_suspended;
115 internal ContextMenu context_menu; // Context menu associated with the control
117 private Graphics dc_mem; // Graphics context for double buffering
118 private GraphicsState dc_state; // Pristine graphics context to reset after paint code alters dc_mem
119 private Bitmap bmp_mem; // Bitmap for double buffering control
120 private bool needs_redraw = true;
122 private ControlBindingsCollection data_bindings;
125 internal bool use_compatible_text_rendering;
126 static internal bool verify_thread_handle;
127 private Padding padding;
130 #endregion // Local Variables
132 #region Private Classes
133 // This helper class allows us to dispatch messages to Control.WndProc
134 internal class ControlNativeWindow : NativeWindow {
135 private Control owner;
137 public ControlNativeWindow(Control control) : base() {
142 public Control Owner {
148 static internal Control ControlFromHandle(IntPtr hWnd) {
149 ControlNativeWindow window;
151 window = (ControlNativeWindow)window_collection[hWnd];
152 if (window != null) {
159 protected override void WndProc(ref Message m) {
160 owner.WndProc(ref m);
165 #region Public Classes
167 public class ControlAccessibleObject : AccessibleObject {
168 #region ControlAccessibleObject Constructors
169 public ControlAccessibleObject(Control ownerControl) {
170 this.owner = ownerControl;
172 #endregion // ControlAccessibleObject Constructors
174 #region ControlAccessibleObject Public Instance Properties
175 public override string DefaultAction {
177 return base.DefaultAction;
181 public override string Description {
183 return base.Description;
187 public IntPtr Handle {
193 // We don't want to let them set it
197 public override string Help {
203 public override string KeyboardShortcut {
205 return base.KeyboardShortcut;
209 public override string Name {
219 public Control Owner {
225 public override AccessibleObject Parent {
232 public override AccessibleRole Role {
237 #endregion // ControlAccessibleObject Public Instance Properties
239 #region ControlAccessibleObject Public Instance Methods
240 public override int GetHelpTopic(out string FileName) {
241 return base.GetHelpTopic (out FileName);
244 [MonoTODO("Implement this and tie it into Control.AccessibilityNotifyClients")]
245 public void NotifyClients(AccessibleEvents accEvent) {
246 throw new NotImplementedException();
249 [MonoTODO("Implement this and tie it into Control.AccessibilityNotifyClients")]
250 public void NotifyClients(AccessibleEvents accEvent, int childID) {
251 throw new NotImplementedException();
254 public override string ToString() {
255 return "ControlAccessibleObject: Owner = " + owner.ToString() + ", Text: " + owner.text;
258 #endregion // ControlAccessibleObject Public Instance Methods
261 [DesignerSerializer("System.Windows.Forms.Design.ControlCollectionCodeDomSerializer, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
262 [ListBindable(false)]
263 public class ControlCollection : IList, ICollection, ICloneable, IEnumerable {
264 #region ControlCollection Local Variables
265 private ArrayList list;
266 internal ArrayList impl_list;
267 private Control [] all_controls;
268 internal Control owner;
269 #endregion // ControlCollection Local Variables
271 #region ControlCollection Public Constructor
272 public ControlCollection(Control owner) {
274 this.list=new ArrayList();
278 #region ControlCollection Public Instance Properties
285 public bool IsReadOnly {
287 return list.IsReadOnly;
291 public virtual Control this[int index] {
293 if (index < 0 || index >= list.Count) {
294 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
296 return (Control)list[index];
299 #endregion // ControlCollection Public Instance Properties
301 #region ControlCollection Private Instance Methods
302 public virtual void Add (Control value)
307 if (Contains (value)) {
308 owner.PerformLayout();
312 if (value.tab_index == -1) {
318 end = owner.child_controls.Count;
319 for (int i = 0; i < end; i++) {
320 index = owner.child_controls[i].tab_index;
325 value.tab_index = use;
328 if (value.parent != null) {
329 value.parent.Controls.Remove(value);
335 value.ChangeParent(owner);
339 owner.UpdateChildrenZOrder();
340 owner.PerformLayout(value, "Parent");
341 owner.OnControlAdded(new ControlEventArgs(value));
344 internal void AddToList (Control c)
350 internal virtual void AddImplicit (Control control)
352 if (impl_list == null)
353 impl_list = new ArrayList ();
355 impl_list.Add (control);
357 control.ChangeParent (owner);
358 control.InitLayout ();
359 owner.UpdateChildrenZOrder ();
360 owner.PerformLayout (control, "Parent");
361 owner.OnControlAdded (new ControlEventArgs (control));
364 public virtual void AddRange (Control[] controls)
366 if (controls == null)
367 throw new ArgumentNullException ("controls");
369 owner.SuspendLayout ();
372 for (int i = 0; i < controls.Length; i++)
375 owner.ResumeLayout ();
379 internal virtual void AddRangeImplicit (Control [] controls)
381 if (controls == null)
382 throw new ArgumentNullException ("controls");
384 owner.SuspendLayout ();
387 for (int i = 0; i < controls.Length; i++)
388 AddImplicit (controls [i]);
390 owner.ResumeLayout ();
394 public virtual void Clear ()
398 // MS sends remove events in reverse order
399 while (list.Count > 0) {
400 RemoveAt(list.Count - 1);
404 internal virtual void ClearImplicit ()
406 if (impl_list == null)
412 public bool Contains (Control value)
414 for (int i = list.Count; i > 0; ) {
417 if (list [i] == value) {
418 // Do we need to do anything here?
425 internal bool ImplicitContains (Control value)
427 if (impl_list == null)
430 for (int i = impl_list.Count; i > 0; ) {
433 if (impl_list [i] == value) {
434 // Do we need to do anything here?
441 internal bool AllContains (Control value)
443 return Contains (value) || ImplicitContains (value);
446 public void CopyTo (Array array, int index)
448 list.CopyTo(array, index);
451 public override bool Equals(object other) {
452 if (other is ControlCollection && (((ControlCollection)other).owner==this.owner)) {
459 public int GetChildIndex(Control child) {
460 return GetChildIndex(child, false);
463 public int GetChildIndex(Control child, bool throwException) {
466 index=list.IndexOf(child);
468 if (index==-1 && throwException) {
469 throw new ArgumentException("Not a child control", "child");
474 public IEnumerator GetEnumerator() {
475 return list.GetEnumerator();
478 internal IEnumerator GetAllEnumerator ()
480 Control [] res = GetAllControls ();
481 return res.GetEnumerator ();
484 internal Control [] GetAllControls ()
486 if (all_controls != null)
489 if (impl_list == null) {
490 all_controls = (Control []) list.ToArray (typeof (Control));
494 all_controls = new Control [list.Count + impl_list.Count];
495 impl_list.CopyTo (all_controls);
496 list.CopyTo (all_controls, impl_list.Count);
501 public override int GetHashCode() {
502 return base.GetHashCode();
505 public int IndexOf(Control control) {
506 return list.IndexOf(control);
509 public virtual void Remove(Control value) {
512 owner.PerformLayout(value, "Parent");
513 owner.OnControlRemoved(new ControlEventArgs(value));
516 value.ChangeParent(null);
518 owner.UpdateChildrenZOrder();
521 internal virtual void RemoveImplicit (Control control)
523 if (impl_list != null) {
525 owner.PerformLayout (control, "Parent");
526 owner.OnControlRemoved (new ControlEventArgs (control));
527 impl_list.Remove (control);
529 control.ChangeParent (null);
530 owner.UpdateChildrenZOrder ();
533 public void RemoveAt(int index) {
534 if (index < 0 || index >= list.Count) {
535 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
537 Remove ((Control)list[index]);
540 public void SetChildIndex(Control child, int newIndex) {
543 old_index=list.IndexOf(child);
545 throw new ArgumentException("Not a child control", "child");
548 if (old_index==newIndex) {
552 list.RemoveAt(old_index);
554 if (newIndex>list.Count) {
557 list.Insert(newIndex, child);
559 child.UpdateZOrder();
560 owner.PerformLayout();
562 #endregion // ControlCollection Private Instance Methods
564 #region ControlCollection Interface Properties
565 object IList.this[int index] {
567 if (index<0 || index>=list.Count) {
568 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
574 if (!(value is Control)) {
575 throw new ArgumentException("Object of type Control required", "value");
578 list[index]=(Control)value;
582 bool IList.IsFixedSize {
588 bool ICollection.IsSynchronized {
590 return list.IsSynchronized;
594 object ICollection.SyncRoot {
596 return list.SyncRoot;
599 #endregion // ControlCollection Interface Properties
601 #region ControlCollection Interface Methods
602 int IList.Add(object value) {
604 throw new ArgumentNullException("value", "Cannot add null controls");
607 if (!(value is Control)) {
608 throw new ArgumentException("Object of type Control required", "value");
611 return list.Add(value);
614 bool IList.Contains(object value) {
615 if (!(value is Control)) {
616 throw new ArgumentException("Object of type Control required", "value");
619 return this.Contains((Control) value);
622 int IList.IndexOf(object value) {
623 if (!(value is Control)) {
624 throw new ArgumentException("Object of type Control required", "value");
627 return this.IndexOf((Control) value);
630 void IList.Insert(int index, object value) {
631 if (!(value is Control)) {
632 throw new ArgumentException("Object of type Control required", "value");
635 list.Insert(index, value);
638 void IList.Remove(object value) {
639 if (!(value is Control)) {
640 throw new ArgumentException("Object of type Control required", "value");
646 Object ICloneable.Clone() {
647 ControlCollection clone = new ControlCollection(this.owner);
648 clone.list=(ArrayList)list.Clone(); // FIXME: Do we need this?
651 #endregion // ControlCollection Interface Methods
653 #endregion // ControlCollection Class
655 #region Public Constructors
658 anchor_style = AnchorStyles.Top | AnchorStyles.Left;
666 layout_pending = false;
668 causes_validation = true;
670 layout_suspended = 0;
674 right_to_left = RightToLeft.Inherit;
675 border_style = BorderStyle.None;
676 background_color = Color.Empty;
683 use_compatible_text_rendering = Application.use_compatible_text_rendering;
684 padding = new Padding(0);
687 control_style = ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint |
688 ControlStyles.Selectable | ControlStyles.StandardClick |
689 ControlStyles.StandardDoubleClick;
692 background_image = null;
696 window = new ControlNativeWindow(this);
697 child_controls = CreateControlsInstance();
698 client_size = new Size(DefaultSize.Width, DefaultSize.Height);
699 client_rect = new Rectangle(0, 0, DefaultSize.Width, DefaultSize.Height);
700 XplatUI.CalculateWindowRect(ref client_rect, CreateParams.Style, CreateParams.ExStyle, null, out bounds);
701 if ((CreateParams.Style & (int)WindowStyles.WS_CHILD) == 0) {
707 public Control(Control parent, string text) : this() {
712 public Control(Control parent, string text, int left, int top, int width, int height) : this() {
717 bounds.Height=height;
718 SetBoundsCore(left, top, width, height, BoundsSpecified.All);
722 public Control(string text) : this() {
726 public Control(string text, int left, int top, int width, int height) : this() {
730 bounds.Height=height;
731 SetBoundsCore(left, top, width, height, BoundsSpecified.All);
735 private delegate void RemoveDelegate(object c);
737 protected override void Dispose(bool disposing) {
751 if (this.InvokeRequired) {
752 if (Application.MessageLoop) {
753 this.BeginInvokeInternal(new MethodInvoker(DestroyHandle), null, true);
754 this.BeginInvokeInternal(new RemoveDelegate(controls.Remove), new object[] {this}, true);
758 controls.Remove(this);
762 if (parent != null) {
763 parent.Controls.Remove(this);
766 Control [] children = child_controls.GetAllControls ();
767 for (int i=0; i<children.Length; i++) {
768 children[i].parent = null; // Need to set to null or our child will try and remove from ourselves and crash
769 children[i].Dispose();
773 base.Dispose(disposing);
775 #endregion // Public Constructors
777 #region Internal Properties
778 internal BorderStyle InternalBorderStyle {
784 if (!Enum.IsDefined (typeof (BorderStyle), value))
785 throw new InvalidEnumArgumentException (string.Format("Enum argument value '{0}' is not valid for BorderStyle", value));
787 if (border_style != value) {
788 border_style = value;
790 if (IsHandleCreated) {
791 XplatUI.SetBorderStyle(window.Handle, (FormBorderStyle)border_style);
797 #endregion // Internal Properties
799 #region Private & Internal Methods
800 internal IAsyncResult BeginInvokeInternal (Delegate method, object [] args, bool disposing) {
801 AsyncMethodResult result;
802 AsyncMethodData data;
809 if (!p.IsHandleCreated) {
810 throw new InvalidOperationException("Cannot call Invoke or InvokeAsync on a control until the window handle is created");
816 result = new AsyncMethodResult ();
817 data = new AsyncMethodData ();
819 data.Method = method;
821 data.Result = result;
824 if (!ExecutionContext.IsFlowSuppressed ()) {
825 data.Context = ExecutionContext.Capture ();
828 #if !MWF_ON_MSRUNTIME
829 if (SecurityManager.SecurityEnabled) {
830 data.Stack = CompressedStack.GetCompressedStack ();
835 XplatUI.SendAsyncMethod (data);
840 internal void PointToClient (ref int x, ref int y)
842 XplatUI.ScreenToClient (Handle, ref x, ref y);
845 internal void PointToScreen (ref int x, ref int y)
847 XplatUI.ClientToScreen (Handle, ref x, ref y);
850 private bool IsRecreating {
856 if (parent != null) {
857 return parent.IsRecreating;
864 private bool ParentIsRecreating {
866 if (parent != null) {
867 return parent.IsRecreating;
873 internal Graphics DeviceContext {
875 if (dc_mem == null) {
876 CreateBuffers(this.Width, this.Height);
877 dc_state = dc_mem.Save();
883 internal void ResetDeviceContext() {
884 dc_mem.Restore(dc_state);
885 dc_state = dc_mem.Save();
888 private Bitmap ImageBuffer {
891 CreateBuffers(this.Width, this.Height);
897 internal void CreateBuffers (int width, int height) {
898 if (dc_mem != null) {
912 bmp_mem = new Bitmap (width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
913 dc_mem = Graphics.FromImage (bmp_mem);
917 internal void InvalidateBuffers ()
919 if (dc_mem != null) {
930 internal static void SetChildColor(Control parent) {
933 for (int i=0; i < parent.child_controls.Count; i++) {
934 child=parent.child_controls[i];
935 if (child.child_controls.Count>0) {
936 SetChildColor(child);
942 internal bool Select(Control control) {
943 IContainerControl container;
945 if (control == null) {
949 container = GetContainerControl();
950 if (container != null) {
951 container.ActiveControl = control;
953 if (control.IsHandleCreated) {
954 XplatUI.SetFocus(control.window.Handle);
959 internal void SelectChild (Control control)
961 if (control.IsHandleCreated)
962 XplatUI.SetFocus (control.window.Handle);
965 internal virtual void DoDefaultAction() {
966 // Only here to be overriden by our actual controls; this is needed by the accessibility class
969 internal static int LowOrder (int param) {
970 return ((int)(short)(param & 0xffff));
973 internal static int HighOrder (int param) {
974 return ((int)(short)(param >> 16));
977 // This method exists so controls overriding OnPaintBackground can have default background painting done
978 internal virtual void PaintControlBackground (PaintEventArgs pevent)
980 if (GetStyle(ControlStyles.SupportsTransparentBackColor) && (BackColor.A != 0xff)) {
981 if (parent != null) {
982 PaintEventArgs parent_pe;
985 parent_pe = new PaintEventArgs(pevent.Graphics, new Rectangle(pevent.ClipRectangle.X + Left, pevent.ClipRectangle.Y + Top, pevent.ClipRectangle.Width, pevent.ClipRectangle.Height));
987 state = parent_pe.Graphics.Save();
988 parent_pe.Graphics.TranslateTransform(-Left, -Top);
989 parent.OnPaintBackground(parent_pe);
990 parent_pe.Graphics.Restore(state);
992 state = parent_pe.Graphics.Save();
993 parent_pe.Graphics.TranslateTransform(-Left, -Top);
994 parent.OnPaint(parent_pe);
995 parent_pe.Graphics.Restore(state);
996 parent_pe.SetGraphics(null);
1000 if ((clip_region != null) && (XplatUI.UserClipWontExposeParent)) {
1001 if (parent != null) {
1002 PaintEventArgs parent_pe;
1004 GraphicsState state;
1007 hwnd = Hwnd.ObjectFromHandle(Handle);
1010 parent_pe = new PaintEventArgs(pevent.Graphics, new Rectangle(pevent.ClipRectangle.X + Left, pevent.ClipRectangle.Y + Top, pevent.ClipRectangle.Width, pevent.ClipRectangle.Height));
1012 region = new Region ();
1014 region.Union(ClientRectangle);
1016 foreach (Rectangle r in hwnd.ClipRectangles) {
1020 state = parent_pe.Graphics.Save();
1021 parent_pe.Graphics.Clip = region;
1023 parent_pe.Graphics.TranslateTransform(-Left, -Top);
1024 parent.OnPaintBackground(parent_pe);
1025 parent_pe.Graphics.Restore(state);
1027 state = parent_pe.Graphics.Save();
1028 parent_pe.Graphics.Clip = region;
1030 parent_pe.Graphics.TranslateTransform(-Left, -Top);
1031 parent.OnPaint(parent_pe);
1032 parent_pe.Graphics.Restore(state);
1033 parent_pe.SetGraphics(null);
1035 region.Intersect(clip_region);
1036 pevent.Graphics.Clip = region;
1041 if (background_image == null) {
1042 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));
1046 DrawBackgroundImage (pevent.Graphics);
1049 void DrawBackgroundImage (Graphics g)
1051 using (TextureBrush b = new TextureBrush (background_image, WrapMode.Tile)) {
1052 g.FillRectangle (b, ClientRectangle);
1056 internal virtual void DndEnter (DragEventArgs e)
1063 internal virtual void DndOver (DragEventArgs e)
1070 internal virtual void DndDrop (DragEventArgs e)
1074 } catch (Exception exc) {
1075 Console.Error.WriteLine ("MWF: Exception while dropping:");
1076 Console.Error.WriteLine (exc);
1080 internal virtual void DndLeave (EventArgs e)
1087 internal virtual void DndFeedback(GiveFeedbackEventArgs e)
1094 internal virtual void DndContinueDrag(QueryContinueDragEventArgs e)
1097 OnQueryContinueDrag(e);
1101 internal static MouseButtons FromParamToMouseButtons (int param) {
1102 MouseButtons buttons = MouseButtons.None;
1104 if ((param & (int) MsgButtons.MK_LBUTTON) != 0)
1105 buttons |= MouseButtons.Left;
1107 if ((param & (int) MsgButtons.MK_MBUTTON) != 0)
1108 buttons |= MouseButtons.Middle;
1110 if ((param & (int) MsgButtons.MK_RBUTTON) != 0)
1111 buttons |= MouseButtons.Right;
1117 internal void FireEnter ()
1119 OnEnter (EventArgs.Empty);
1122 internal void FireLeave ()
1124 OnLeave (EventArgs.Empty);
1127 internal virtual bool ProcessControlMnemonic(char charCode) {
1128 return ProcessMnemonic(charCode);
1131 private static Control FindFlatForward(Control container, Control start) {
1137 end = container.child_controls.Count;
1139 if (start != null) {
1140 index = start.tab_index;
1145 for (int i = 0; i < end; i++) {
1146 if (found == null) {
1147 if (container.child_controls[i].tab_index > index) {
1148 found = container.child_controls[i];
1150 } else if (found.tab_index > container.child_controls[i].tab_index) {
1151 if (container.child_controls[i].tab_index > index) {
1152 found = container.child_controls[i];
1159 private static Control FindControlForward(Control container, Control start) {
1165 if (start != null) {
1166 if ((start is IContainerControl) || start.GetStyle(ControlStyles.ContainerControl)) {
1167 found = FindControlForward(start, null);
1168 if (found != null) {
1174 while (p != container) {
1175 found = FindFlatForward(p, start);
1176 if (found != null) {
1183 return FindFlatForward(container, start);
1186 private static Control FindFlatBackward(Control container, Control start) {
1192 end = container.child_controls.Count;
1194 if (start != null) {
1195 index = start.tab_index;
1197 // FIXME: Possible speed-up: Keep the highest taborder index in the container
1199 for (int i = 0; i < end; i++) {
1200 if (container.child_controls[i].tab_index > index) {
1201 index = container.child_controls[i].tab_index;
1207 for (int i = 0; i < end; i++) {
1208 if (found == null) {
1209 if (container.child_controls[i].tab_index < index) {
1210 found = container.child_controls[i];
1212 } else if (found.tab_index < container.child_controls[i].tab_index) {
1213 if (container.child_controls[i].tab_index < index) {
1214 found = container.child_controls[i];
1221 private static Control FindControlBackward(Control container, Control start) {
1226 if (start != null) {
1227 found = FindFlatBackward(start.parent, start);
1228 if (found == null && start.parent != container) {
1229 return start.parent;
1232 if (found == null) {
1233 found = FindFlatBackward(container, start);
1236 while ((found != null) && ((found is IContainerControl) || found.GetStyle(ControlStyles.ContainerControl))) {
1237 found = FindControlBackward(found, null);
1238 if (found != null) {
1246 private void HandleClick(int clicks, MouseEventArgs me) {
1247 if (GetStyle(ControlStyles.StandardClick)) {
1248 if ((clicks > 1) && GetStyle(ControlStyles.StandardDoubleClick)) {
1250 OnDoubleClick(EventArgs.Empty);
1252 OnClick(EventArgs.Empty);
1262 private void CheckDataBindings ()
1264 if (data_bindings == null)
1267 BindingContext binding_context = BindingContext;
1268 foreach (Binding binding in data_bindings) {
1269 binding.Check (binding_context);
1274 private void ChangeParent(Control new_parent) {
1278 Color pre_fore_color;
1279 Color pre_back_color;
1280 RightToLeft pre_rtl;
1282 // These properties are inherited from our parent
1283 // Get them pre parent-change and then send events
1284 // if they are changed after we have our new parent
1285 pre_enabled = Enabled;
1286 pre_visible = Visible;
1288 pre_fore_color = ForeColor;
1289 pre_back_color = BackColor;
1290 pre_rtl = RightToLeft;
1291 // MS doesn't seem to send a CursorChangedEvent
1293 parent = new_parent;
1295 if (IsHandleCreated && (new_parent != null) && new_parent.IsHandleCreated) {
1296 XplatUI.SetParent(Handle, new_parent.Handle);
1299 OnParentChanged(EventArgs.Empty);
1301 if (pre_enabled != Enabled) {
1302 OnEnabledChanged(EventArgs.Empty);
1305 if (pre_visible != Visible) {
1306 OnVisibleChanged(EventArgs.Empty);
1309 if (pre_font != Font) {
1310 OnFontChanged(EventArgs.Empty);
1313 if (pre_fore_color != ForeColor) {
1314 OnForeColorChanged(EventArgs.Empty);
1317 if (pre_back_color != BackColor) {
1318 OnBackColorChanged(EventArgs.Empty);
1321 if (pre_rtl != RightToLeft) {
1322 // MS sneaks a OnCreateControl and OnHandleCreated in here, I guess
1323 // because when RTL changes they have to recreate the win32 control
1324 // We don't really need that (until someone runs into compatibility issues)
1325 OnRightToLeftChanged(EventArgs.Empty);
1328 if ((new_parent != null) && new_parent.Created && !Created) {
1332 if ((binding_context == null) && Created) {
1333 OnBindingContextChanged(EventArgs.Empty);
1337 private void UpdateDistances() {
1338 if ((parent != null) && (parent.layout_suspended == 0)) {
1339 dist_left = bounds.X;
1340 dist_top = bounds.Y;
1341 dist_right = parent.ClientSize.Width - bounds.X - bounds.Width;
1342 dist_bottom = parent.ClientSize.Height - bounds.Y - bounds.Height;
1345 #endregion // Private & Internal Methods
1347 #region Public Static Properties
1348 public static Color DefaultBackColor {
1350 return ThemeEngine.Current.DefaultControlBackColor;
1354 public static Font DefaultFont {
1356 return ThemeEngine.Current.DefaultFont;
1360 public static Color DefaultForeColor {
1362 return ThemeEngine.Current.DefaultControlForeColor;
1366 public static Keys ModifierKeys {
1368 return XplatUI.State.ModifierKeys;
1372 public static MouseButtons MouseButtons {
1374 return XplatUI.State.MouseButtons;
1378 public static Point MousePosition {
1380 return Cursor.Position;
1386 public static bool CheckForIllegalCrossThreadCalls
1389 return verify_thread_handle;
1393 verify_thread_handle = value;
1397 #endregion // Public Static Properties
1399 #region Public Instance Properties
1400 [EditorBrowsable(EditorBrowsableState.Advanced)]
1402 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1403 public AccessibleObject AccessibilityObject {
1405 if (accessibility_object==null) {
1406 accessibility_object=CreateAccessibilityInstance();
1408 return accessibility_object;
1412 [EditorBrowsable(EditorBrowsableState.Advanced)]
1414 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1415 public string AccessibleDefaultActionDescription {
1417 return AccessibilityObject.default_action;
1421 AccessibilityObject.default_action=value;
1426 [DefaultValue(null)]
1427 [MWFCategory("Accessibility")]
1428 public string AccessibleDescription {
1430 return AccessibilityObject.description;
1434 AccessibilityObject.description=value;
1439 [DefaultValue(null)]
1440 [MWFCategory("Accessibility")]
1441 public string AccessibleName {
1443 return AccessibilityObject.Name;
1447 AccessibilityObject.Name=value;
1451 [DefaultValue(AccessibleRole.Default)]
1452 [MWFDescription("Role of the control"), MWFCategory("Accessibility")]
1453 public AccessibleRole AccessibleRole {
1455 return AccessibilityObject.role;
1459 AccessibilityObject.role=value;
1463 [DefaultValue(false)]
1464 [MWFCategory("Behavior")]
1465 public virtual bool AllowDrop {
1471 if (allow_drop == value)
1474 if (IsHandleCreated) {
1476 XplatUI.SetAllowDrop (Handle, value);
1482 [RefreshProperties(RefreshProperties.Repaint)]
1483 [DefaultValue(AnchorStyles.Top | AnchorStyles.Left)]
1484 [MWFCategory("Layout")]
1485 public virtual AnchorStyles Anchor {
1487 return anchor_style;
1493 if (parent != null) {
1494 parent.PerformLayout(this, "Parent");
1500 // XXX: Implement me!
1503 public virtual bool AutoSize {
1505 Console.Error.WriteLine("Unimplemented: Control::get_AutoSize()");
1509 Console.Error.WriteLine("Unimplemented: Control::set_AutoSize(bool)");
1516 [MWFCategory("Appearance")]
1517 public virtual Color BackColor {
1519 if (background_color.IsEmpty) {
1521 Color pcolor = parent.BackColor;
1522 if (pcolor.A == 0xff || GetStyle(ControlStyles.SupportsTransparentBackColor))
1525 return DefaultBackColor;
1527 return background_color;
1531 if (!value.IsEmpty && (value.A != 0xff) && !GetStyle(ControlStyles.SupportsTransparentBackColor)) {
1532 throw new ArgumentException("Transparent background colors are not supported on this control");
1535 background_color=value;
1536 SetChildColor(this);
1537 OnBackColorChanged(EventArgs.Empty);
1543 [DefaultValue(null)]
1544 [MWFCategory("Appearance")]
1545 public virtual Image BackgroundImage {
1547 return background_image;
1551 if (background_image!=value) {
1552 background_image=value;
1553 OnBackgroundImageChanged(EventArgs.Empty);
1558 [EditorBrowsable(EditorBrowsableState.Advanced)]
1560 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1561 public virtual BindingContext BindingContext {
1563 if (binding_context != null)
1564 return binding_context;
1567 binding_context = Parent.BindingContext;
1568 return binding_context;
1571 if (binding_context != value) {
1572 binding_context = value;
1573 OnBindingContextChanged(EventArgs.Empty);
1578 [EditorBrowsable(EditorBrowsableState.Advanced)]
1580 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1583 return bounds.Y+bounds.Height;
1587 [EditorBrowsable(EditorBrowsableState.Advanced)]
1589 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1590 public Rectangle Bounds {
1596 SetBoundsCore(value.Left, value.Top, value.Width, value.Height, BoundsSpecified.All);
1600 [EditorBrowsable(EditorBrowsableState.Advanced)]
1602 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1603 public bool CanFocus {
1605 if (IsHandleCreated && Visible && Enabled) {
1612 [EditorBrowsable(EditorBrowsableState.Advanced)]
1614 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1615 public bool CanSelect {
1619 if (!GetStyle(ControlStyles.Selectable)) {
1624 while (parent != null) {
1625 if (!parent.is_visible || !parent.is_enabled) {
1629 parent = parent.parent;
1635 internal virtual bool InternalCapture {
1645 [EditorBrowsable(EditorBrowsableState.Advanced)]
1647 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1648 public bool Capture {
1650 return this.is_captured;
1654 if (this.IsHandleCreated) {
1655 if (value && !is_captured) {
1657 XplatUI.GrabWindow(this.window.Handle, IntPtr.Zero);
1658 } else if (!value && is_captured) {
1659 XplatUI.UngrabWindow(this.window.Handle);
1660 is_captured = false;
1666 [DefaultValue(true)]
1667 [MWFCategory("Focus")]
1668 public bool CausesValidation {
1670 return this.causes_validation;
1674 if (this.causes_validation != value) {
1675 causes_validation = value;
1676 OnCausesValidationChanged(EventArgs.Empty);
1681 [EditorBrowsable(EditorBrowsableState.Advanced)]
1683 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1684 public Rectangle ClientRectangle {
1686 client_rect.Width = client_size.Width;
1687 client_rect.Height = client_size.Height;
1692 [EditorBrowsable(EditorBrowsableState.Advanced)]
1694 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1695 public Size ClientSize {
1698 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1699 return ((Form)this).form_parent_window.ClientSize;
1707 this.SetClientSizeCore(value.Width, value.Height);
1711 [EditorBrowsable(EditorBrowsableState.Advanced)]
1713 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1714 [DescriptionAttribute("ControlCompanyNameDescr")]
1715 public String CompanyName {
1717 return "Mono Project, Novell, Inc.";
1721 [EditorBrowsable(EditorBrowsableState.Advanced)]
1723 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1724 public bool ContainsFocus {
1726 IntPtr focused_window;
1728 focused_window = XplatUI.GetFocus();
1729 if (IsHandleCreated) {
1730 if (focused_window == Handle) {
1734 for (int i=0; i < child_controls.Count; i++) {
1735 if (child_controls[i].ContainsFocus) {
1744 [DefaultValue(null)]
1745 [MWFCategory("Behavior")]
1746 public virtual ContextMenu ContextMenu {
1748 return context_menu;
1752 if (context_menu != value) {
1753 context_menu = value;
1754 OnContextMenuChanged(EventArgs.Empty);
1760 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
1761 public ControlCollection Controls {
1763 return this.child_controls;
1767 [EditorBrowsable(EditorBrowsableState.Advanced)]
1769 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1770 public bool Created {
1772 return (!is_disposed && is_created);
1776 [AmbientValue(null)]
1777 [MWFCategory("Appearance")]
1778 public virtual Cursor Cursor {
1780 if (cursor != null) {
1784 if (parent != null) {
1785 return parent.Cursor;
1788 return Cursors.Default;
1792 if (cursor != value) {
1797 if (IsHandleCreated) {
1798 pt = Cursor.Position;
1800 if (bounds.Contains(pt) || Capture) {
1801 if (GetChildAtPoint(pt) == null) {
1802 if (cursor != null) {
1803 XplatUI.SetCursor(window.Handle, cursor.handle);
1805 if (parent != null) {
1806 XplatUI.SetCursor(window.Handle, parent.Cursor.handle);
1808 XplatUI.SetCursor(window.Handle, Cursors.Default.handle);
1815 OnCursorChanged(EventArgs.Empty);
1821 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
1822 [ParenthesizePropertyName(true)]
1823 [RefreshProperties(RefreshProperties.All)]
1824 [MWFCategory("Data")]
1825 public ControlBindingsCollection DataBindings {
1827 if (data_bindings == null)
1828 data_bindings = new ControlBindingsCollection (this);
1829 return data_bindings;
1833 [EditorBrowsable(EditorBrowsableState.Advanced)]
1835 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1836 public virtual Rectangle DisplayRectangle {
1838 return ClientRectangle;
1842 [EditorBrowsable(EditorBrowsableState.Advanced)]
1844 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1845 public bool Disposing {
1852 [RefreshProperties(RefreshProperties.Repaint)]
1853 [DefaultValue(DockStyle.None)]
1854 [MWFCategory("Layout")]
1855 public virtual DockStyle Dock {
1861 if (dock_style == value) {
1867 if (parent != null) {
1868 parent.PerformLayout(this, "Parent");
1871 OnDockChanged(EventArgs.Empty);
1877 [MWFCategory("Behavior")]
1878 public bool Enabled {
1884 if (parent != null) {
1885 return parent.Enabled;
1892 if (Enabled == value) {
1899 // FIXME - we need to switch focus to next control if we're disabling the focused control
1901 OnEnabledChanged (EventArgs.Empty);
1905 [EditorBrowsable(EditorBrowsableState.Advanced)]
1907 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1908 public virtual bool Focused {
1910 return this.has_focus;
1915 [AmbientValue(null)]
1917 [MWFCategory("Appearance")]
1918 public virtual Font Font {
1924 if (Parent != null && Parent.Font != null) {
1931 [param:MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Font))]
1933 if (font != null && font.Equals (value)) {
1939 OnFontChanged (EventArgs.Empty);
1944 [MWFCategory("Appearance")]
1945 public virtual Color ForeColor {
1947 if (foreground_color.IsEmpty) {
1949 return parent.ForeColor;
1951 return DefaultForeColor;
1953 return foreground_color;
1957 if (foreground_color != value) {
1958 foreground_color=value;
1960 OnForeColorChanged(EventArgs.Empty);
1967 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1968 public IntPtr Handle { // IWin32Window
1971 if (verify_thread_handle) {
1972 if (this.InvokeRequired) {
1973 throw new InvalidOperationException("Cross-thread access of handle detected. Handle access only valid on thread that created the control");
1977 if (!IsHandleCreated) {
1980 return window.Handle;
1984 [EditorBrowsable(EditorBrowsableState.Advanced)]
1986 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1987 public bool HasChildren {
1989 if (this.child_controls.Count>0) {
1996 [EditorBrowsable(EditorBrowsableState.Always)]
1998 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2001 return this.bounds.Height;
2005 SetBoundsCore(bounds.X, bounds.Y, bounds.Width, value, BoundsSpecified.Height);
2009 [AmbientValue(ImeMode.Inherit)]
2011 [MWFCategory("Behavior")]
2012 public ImeMode ImeMode {
2014 if (ime_mode == DefaultImeMode) {
2016 return parent.ImeMode;
2018 return ImeMode.NoControl; // default value
2024 if (ime_mode != value) {
2027 OnImeModeChanged(EventArgs.Empty);
2032 [EditorBrowsable(EditorBrowsableState.Advanced)]
2034 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2035 public bool InvokeRequired { // ISynchronizeInvoke
2037 if (creator_thread != null && creator_thread!=Thread.CurrentThread) {
2044 [EditorBrowsable(EditorBrowsableState.Advanced)]
2046 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2047 public bool IsAccessible {
2049 return is_accessible;
2053 is_accessible = value;
2057 [EditorBrowsable(EditorBrowsableState.Advanced)]
2059 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2060 public bool IsDisposed {
2062 return this.is_disposed;
2066 [EditorBrowsable(EditorBrowsableState.Advanced)]
2068 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2069 public bool IsHandleCreated {
2071 if ((window != null) && (window.Handle != IntPtr.Zero)) {
2079 [EditorBrowsable(EditorBrowsableState.Always)]
2081 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2084 return this.bounds.X;
2088 SetBoundsCore(value, bounds.Y, bounds.Width, bounds.Height, BoundsSpecified.X);
2093 [MWFCategory("Layout")]
2094 public Point Location {
2096 return new Point(bounds.X, bounds.Y);
2100 SetBoundsCore(value.X, value.Y, bounds.Width, bounds.Height, BoundsSpecified.Location);
2105 public string Name {
2117 public Padding Padding {
2129 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2130 public Control Parent {
2136 if (value == this) {
2137 throw new ArgumentException("A circular control reference has been made. A control cannot be owned or parented to itself.");
2140 if (parent!=value) {
2142 parent.Controls.Remove(this);
2146 value.Controls.Add(this);
2151 [EditorBrowsable(EditorBrowsableState.Advanced)]
2153 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2154 public string ProductName {
2156 Type t = typeof (AssemblyProductAttribute);
2157 Assembly assembly = GetType().Module.Assembly;
2158 object [] attrs = assembly.GetCustomAttributes (t, false);
2159 AssemblyProductAttribute a = null;
2160 // On MS we get a NullRefException if product attribute is not
2162 if (attrs != null && attrs.Length > 0)
2163 a = (AssemblyProductAttribute) attrs [0];
2168 [EditorBrowsable(EditorBrowsableState.Advanced)]
2170 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2171 public string ProductVersion {
2173 Type t = typeof (AssemblyVersionAttribute);
2174 Assembly assembly = GetType().Module.Assembly;
2175 object [] attrs = assembly.GetCustomAttributes (t, false);
2176 if (attrs == null || attrs.Length < 1)
2178 return ((AssemblyVersionAttribute)attrs [0]).Version;
2182 [EditorBrowsable(EditorBrowsableState.Advanced)]
2184 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2185 public bool RecreatingHandle {
2187 return is_recreating;
2191 [EditorBrowsable(EditorBrowsableState.Advanced)]
2193 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2194 public Region Region {
2200 if (IsHandleCreated) {
2201 XplatUI.SetClipRegion(Handle, value);
2203 clip_region = value;
2207 [EditorBrowsable(EditorBrowsableState.Advanced)]
2209 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2212 return this.bounds.X+this.bounds.Width;
2216 [AmbientValue(RightToLeft.Inherit)]
2218 [MWFCategory("Appearance")]
2219 public virtual RightToLeft RightToLeft {
2221 if (right_to_left == RightToLeft.Inherit) {
2223 return parent.RightToLeft;
2225 return RightToLeft.No; // default value
2227 return right_to_left;
2231 if (value != right_to_left) {
2232 right_to_left = value;
2233 OnRightToLeftChanged(EventArgs.Empty);
2238 [EditorBrowsable(EditorBrowsableState.Advanced)]
2239 public override ISite Site {
2247 AmbientProperties ap = (AmbientProperties) value.GetService (typeof (AmbientProperties));
2249 BackColor = ap.BackColor;
2250 ForeColor = ap.ForeColor;
2258 [MWFCategory("Layout")]
2261 return new Size(Width, Height);
2265 SetBoundsCore(bounds.X, bounds.Y, value.Width, value.Height, BoundsSpecified.Size);
2270 [MergableProperty(false)]
2271 [MWFCategory("Behavior")]
2272 public int TabIndex {
2274 if (tab_index != -1) {
2281 if (tab_index != value) {
2283 OnTabIndexChanged(EventArgs.Empty);
2289 [DefaultValue(true)]
2290 [MWFCategory("Behavior")]
2291 public bool TabStop {
2297 if (tab_stop != value) {
2299 OnTabStopChanged(EventArgs.Empty);
2304 [Localizable(false)]
2306 [TypeConverter(typeof(StringConverter))]
2307 [DefaultValue(null)]
2308 [MWFCategory("Data")]
2315 control_tag = value;
2321 [BindableAttribute(true)]
2322 [MWFCategory("Appearance")]
2323 public virtual string Text {
2325 // Our implementation ignores ControlStyles.CacheText - we always cache
2330 if (value == null) {
2331 value = String.Empty;
2336 if (IsHandleCreated) {
2337 XplatUI.Text(Handle, text);
2339 OnTextChanged (EventArgs.Empty);
2344 [EditorBrowsable(EditorBrowsableState.Always)]
2346 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2349 return this.bounds.Y;
2353 SetBoundsCore(bounds.X, value, bounds.Width, bounds.Height, BoundsSpecified.Y);
2357 [EditorBrowsable(EditorBrowsableState.Advanced)]
2359 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2360 public Control TopLevelControl {
2364 while (p.parent != null) {
2373 [MWFCategory("Behavior")]
2374 public bool Visible {
2378 } else if (parent != null) {
2379 return parent.Visible;
2386 SetVisibleCore(value);
2390 [EditorBrowsable(EditorBrowsableState.Always)]
2392 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2395 return this.bounds.Width;
2399 SetBoundsCore(bounds.X, bounds.Y, value, bounds.Height, BoundsSpecified.Width);
2403 [EditorBrowsable(EditorBrowsableState.Never)]
2405 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2406 public IWindowTarget WindowTarget {
2415 #endregion // Public Instance Properties
2417 #region Protected Instance Properties
2418 protected virtual CreateParams CreateParams {
2420 CreateParams create_params = new CreateParams();
2423 create_params.Caption = Text;
2426 create_params.Caption = text;
2430 create_params.X = Left;
2433 create_params.X = this.bounds.X;
2437 create_params.Y = Top;
2440 create_params.Y = this.bounds.Y;
2444 create_params.Width = Width;
2447 create_params.Width = this.bounds.Width;
2451 create_params.Height = Height;
2454 create_params.Height = this.bounds.Height;
2458 create_params.ClassName = XplatUI.DefaultClassName;
2459 create_params.ClassStyle = 0;
2460 create_params.ExStyle = 0;
2461 create_params.Param = 0;
2464 create_params.ExStyle |= (int)WindowExStyles.WS_EX_ACCEPTFILES;
2467 if ((parent!=null) && (parent.IsHandleCreated)) {
2468 create_params.Parent = parent.Handle;
2471 create_params.Style = (int)WindowStyles.WS_CHILD | (int)WindowStyles.WS_CLIPCHILDREN | (int)WindowStyles.WS_CLIPSIBLINGS;
2474 create_params.Style |= (int)WindowStyles.WS_VISIBLE;
2478 create_params.Style |= (int)WindowStyles.WS_DISABLED;
2481 switch (border_style) {
2482 case BorderStyle.FixedSingle:
2483 create_params.Style |= (int) WindowStyles.WS_BORDER;
2485 case BorderStyle.Fixed3D:
2486 create_params.ExStyle |= (int) WindowExStyles.WS_EX_CLIENTEDGE;
2490 return create_params;
2494 protected virtual ImeMode DefaultImeMode {
2496 return ImeMode.Inherit;
2500 protected virtual Size DefaultSize {
2502 return new Size(0, 0);
2506 protected int FontHeight {
2516 protected bool RenderRightToLeft {
2518 return (this.right_to_left == RightToLeft.Yes);
2522 protected bool ResizeRedraw {
2524 return GetStyle(ControlStyles.ResizeRedraw);
2528 SetStyle(ControlStyles.ResizeRedraw, value);
2532 [EditorBrowsable(EditorBrowsableState.Advanced)]
2534 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2535 protected virtual bool ShowFocusCues {
2541 [EditorBrowsable(EditorBrowsableState.Advanced)]
2543 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2544 protected bool ShowKeyboardCues {
2549 #endregion // Protected Instance Properties
2551 #region Public Static Methods
2552 [EditorBrowsable(EditorBrowsableState.Advanced)]
2553 public static Control FromChildHandle(IntPtr handle) {
2554 IEnumerator control = Control.controls.GetEnumerator();
2556 while (control.MoveNext()) {
2557 if (((Control)control.Current).window.Handle == handle) {
2559 if (((Control)control.Current).Parent != null) {
2560 return ((Control)control.Current).Parent;
2567 [EditorBrowsable(EditorBrowsableState.Advanced)]
2568 public static Control FromHandle(IntPtr handle) {
2570 IEnumerator control = Control.controls.GetEnumerator();
2572 while (control.MoveNext()) {
2573 if (((Control)control.Current).window.Handle == handle) {
2575 return ((Control)control.Current);
2581 return Control.ControlNativeWindow.ControlFromHandle(handle);
2585 public static bool IsMnemonic(char charCode, string text) {
2588 amp = text.IndexOf('&');
2591 if (amp + 1 < text.Length) {
2592 if (text[amp + 1] != '&') {
2593 if (Char.ToUpper(charCode) == Char.ToUpper(text.ToCharArray(amp + 1, 1)[0])) {
2603 #region Protected Static Methods
2604 [EditorBrowsable(EditorBrowsableState.Advanced)]
2605 protected static bool ReflectMessage(IntPtr hWnd, ref Message m) {
2608 c = Control.FromHandle(hWnd);
2618 #region Public Instance Methods
2619 [EditorBrowsable(EditorBrowsableState.Advanced)]
2620 public IAsyncResult BeginInvoke(Delegate method) {
2621 object [] prms = null;
2622 if (method is EventHandler)
2623 prms = new object [] { this, EventArgs.Empty };
2624 return BeginInvokeInternal(method, prms, false);
2627 [EditorBrowsable(EditorBrowsableState.Advanced)]
2628 public IAsyncResult BeginInvoke (Delegate method, object[] args) {
2629 return BeginInvokeInternal (method, args, false);
2632 public void BringToFront() {
2633 if (parent != null) {
2634 parent.child_controls.SetChildIndex(this, 0);
2639 public bool Contains(Control ctl) {
2640 while (ctl != null) {
2649 public void CreateControl() {
2654 if (!IsHandleCreated) {
2662 Control [] controls = child_controls.GetAllControls ();
2663 for (int i=0; i<controls.Length; i++) {
2664 controls [i].CreateControl ();
2667 UpdateChildrenZOrder();
2669 if (binding_context == null) { // seem to be sent whenever it's null?
2670 OnBindingContextChanged(EventArgs.Empty);
2676 public Graphics CreateGraphics() {
2677 if (!IsHandleCreated) {
2678 this.CreateHandle();
2680 return Graphics.FromHwnd(this.window.Handle);
2683 public DragDropEffects DoDragDrop(object data, DragDropEffects allowedEffects) {
2684 return XplatUI.StartDrag(this.window.Handle, data, allowedEffects);
2687 [EditorBrowsable(EditorBrowsableState.Advanced)]
2688 public object EndInvoke (IAsyncResult async_result) {
2689 AsyncMethodResult result = (AsyncMethodResult) async_result;
2690 return result.EndInvoke ();
2693 public Form FindForm() {
2706 public bool Focus() {
2707 if (CanFocus && IsHandleCreated && !has_focus) {
2708 XplatUI.SetFocus(window.Handle);
2713 public Control GetChildAtPoint(Point pt) {
2714 // Microsoft's version of this function doesn't seem to work, so I can't check
2715 // if we only consider children or also grandchildren, etc.
2716 // I'm gonna say 'children only'
2717 for (int i=0; i<child_controls.Count; i++) {
2718 if (child_controls[i].Bounds.Contains(pt)) {
2719 return child_controls[i];
2725 public IContainerControl GetContainerControl() {
2726 Control current = this;
2728 while (current!=null) {
2729 if ((current is IContainerControl) && ((current.control_style & ControlStyles.ContainerControl)!=0)) {
2730 return (IContainerControl)current;
2732 current = current.parent;
2737 public Control GetNextControl(Control ctl, bool forward) {
2738 // If we're not a container we don't play
2739 if (!(this is IContainerControl) && !this.GetStyle(ControlStyles.ContainerControl)) {
2743 // If ctl is not contained by this, we start at the first child of this
2744 if (!this.Contains(ctl)) {
2748 // Search through our controls, starting at ctl, stepping into children as we encounter them
2749 // try to find the control with the tabindex closest to our own, or, if we're looking into
2750 // child controls, the one with the smallest tabindex
2752 return FindControlForward(this, ctl);
2754 return FindControlBackward(this, ctl);
2757 public void Hide() {
2758 this.Visible = false;
2761 public void Invalidate() {
2762 Invalidate(ClientRectangle, false);
2765 public void Invalidate(bool invalidateChildren) {
2766 Invalidate(ClientRectangle, invalidateChildren);
2769 public void Invalidate(System.Drawing.Rectangle rc) {
2770 Invalidate(rc, false);
2773 public void Invalidate(System.Drawing.Rectangle rc, bool invalidateChildren) {
2774 if (!IsHandleCreated || !Visible || rc.Width == 0 || rc.Height == 0) {
2778 NotifyInvalidate(rc);
2780 XplatUI.Invalidate(Handle, rc, false);
2782 if (invalidateChildren) {
2783 Control [] controls = child_controls.GetAllControls ();
2784 for (int i=0; i<controls.Length; i++)
2785 controls [i].Invalidate ();
2787 OnInvalidated(new InvalidateEventArgs(rc));
2790 public void Invalidate(System.Drawing.Region region) {
2791 Invalidate(region, false);
2794 public void Invalidate(System.Drawing.Region region, bool invalidateChildren) {
2795 RectangleF bounds = region.GetBounds (CreateGraphics ());
2796 Invalidate (new Rectangle ((int) bounds.X, (int) bounds.Y, (int) bounds.Width, (int) bounds.Height),
2797 invalidateChildren);
2800 public object Invoke (Delegate method) {
2801 object [] prms = null;
2802 if (method is EventHandler)
2803 prms = new object [] { this, EventArgs.Empty };
2805 return Invoke(method, prms);
2808 public object Invoke (Delegate method, object[] args) {
2809 if (!this.InvokeRequired) {
2810 return method.DynamicInvoke(args);
2813 IAsyncResult result = BeginInvoke (method, args);
2814 return EndInvoke(result);
2817 internal object InvokeInternal (Delegate method, bool disposing) {
2818 return InvokeInternal(method, null, disposing);
2821 internal object InvokeInternal (Delegate method, object[] args, bool disposing) {
2822 if (!this.InvokeRequired) {
2823 return method.DynamicInvoke(args);
2826 IAsyncResult result = BeginInvokeInternal (method, args, disposing);
2827 return EndInvoke(result);
2830 [EditorBrowsable(EditorBrowsableState.Advanced)]
2831 public void PerformLayout() {
2832 PerformLayout(null, null);
2835 [EditorBrowsable(EditorBrowsableState.Advanced)]
2836 public void PerformLayout(Control affectedControl, string affectedProperty) {
2837 LayoutEventArgs levent = new LayoutEventArgs(affectedControl, affectedProperty);
2839 if (layout_suspended > 0) {
2840 layout_pending = true;
2844 layout_pending = false;
2846 // Prevent us from getting messed up
2849 // Perform all Dock and Anchor calculations
2852 AnchorStyles anchor;
2855 space= DisplayRectangle;
2857 // Deal with docking; go through in reverse, MS docs say that lowest Z-order is closest to edge
2858 Control [] controls = child_controls.GetAllControls ();
2859 for (int i = controls.Length - 1; i >= 0; i--) {
2860 child = controls [i];
2862 if (!child.Visible) {
2866 switch (child.Dock) {
2867 case DockStyle.None: {
2872 case DockStyle.Left: {
2873 child.SetBounds(space.Left, space.Y, child.Width, space.Height);
2874 space.X+=child.Width;
2875 space.Width-=child.Width;
2879 case DockStyle.Top: {
2880 child.SetBounds(space.Left, space.Y, space.Width, child.Height);
2881 space.Y+=child.Height;
2882 space.Height-=child.Height;
2886 case DockStyle.Right: {
2887 child.SetBounds(space.Right-child.Width, space.Y, child.Width, space.Height);
2888 space.Width-=child.Width;
2892 case DockStyle.Bottom: {
2893 child.SetBounds(space.Left, space.Bottom-child.Height, space.Width, child.Height);
2894 space.Height-=child.Height;
2900 for (int i = controls.Length - 1; i >= 0; i--) {
2903 if (child.Visible && (child.Dock == DockStyle.Fill)) {
2904 child.SetBounds(space.Left, space.Top, space.Width, space.Height);
2908 space=DisplayRectangle;
2910 for (int i=0; i < controls.Length; i++) {
2916 child = controls[i];
2918 // If the control is docked we don't need to do anything
2919 if (child.Dock != DockStyle.None) {
2923 anchor = child.Anchor;
2927 width = child.Width;
2928 height = child.Height;
2930 if ((anchor & AnchorStyles.Left) !=0 ) {
2931 if ((anchor & AnchorStyles.Right) != 0) {
2932 width = space.Width - child.dist_right - left;
2934 ; // Left anchored only, nothing to be done
2936 } else if ((anchor & AnchorStyles.Right) != 0) {
2937 left = space.Width - child.dist_right - width;
2939 // left+=diff_width/2 will introduce rounding errors (diff_width removed from svn after r51780)
2940 // This calculates from scratch every time:
2941 left = child.dist_left + (space.Width - (child.dist_left + width + child.dist_right)) / 2;
2944 if ((anchor & AnchorStyles.Top) !=0 ) {
2945 if ((anchor & AnchorStyles.Bottom) != 0) {
2946 height = space.Height - child.dist_bottom - top;
2948 ; // Top anchored only, nothing to be done
2950 } else if ((anchor & AnchorStyles.Bottom) != 0) {
2951 top = space.Height - child.dist_bottom - height;
2953 // top += diff_height/2 will introduce rounding errors (diff_height removed from after r51780)
2954 // This calculates from scratch every time:
2955 top = child.dist_top + (space.Height - (child.dist_top + height + child.dist_bottom)) / 2;
2967 child.SetBounds(left, top, width, height);
2970 // Let everyone know
2974 // Need to make sure we decremend layout_suspended
2980 public Point PointToClient (Point p) {
2984 XplatUI.ScreenToClient (Handle, ref x, ref y);
2986 return new Point (x, y);
2989 public Point PointToScreen(Point p) {
2993 XplatUI.ClientToScreen(Handle, ref x, ref y);
2995 return new Point(x, y);
2998 public virtual bool PreProcessMessage(ref Message msg) {
3001 if ((msg.Msg == (int)Msg.WM_KEYDOWN) || (msg.Msg == (int)Msg.WM_SYSKEYDOWN)) {
3002 key_data = (Keys)msg.WParam.ToInt32() | XplatUI.State.ModifierKeys;
3004 if (!ProcessCmdKey(ref msg, key_data)) {
3005 if (IsInputKey(key_data)) {
3009 return ProcessDialogKey(key_data);
3013 } else if (msg.Msg == (int)Msg.WM_CHAR) {
3014 if (IsInputChar((char)msg.WParam)) {
3017 } else if (msg.Msg == (int)Msg.WM_SYSCHAR) {
3018 if (IsInputChar((char)msg.WParam)) {
3021 return ProcessDialogChar((char)msg.WParam);
3026 public Rectangle RectangleToClient(Rectangle r) {
3027 return new Rectangle(PointToClient(r.Location), r.Size);
3030 public Rectangle RectangleToScreen(Rectangle r) {
3031 return new Rectangle(PointToScreen(r.Location), r.Size);
3034 public virtual void Refresh() {
3035 if (IsHandleCreated == true) {
3037 XplatUI.UpdateWindow(window.Handle);
3039 Control [] controls = child_controls.GetAllControls ();
3040 for (int i=0; i < controls.Length; i++) {
3041 controls[i].Refresh();
3047 [EditorBrowsable(EditorBrowsableState.Never)]
3048 public virtual void ResetBackColor() {
3049 background_color = Color.Empty;
3052 [EditorBrowsable(EditorBrowsableState.Never)]
3053 public void ResetBindings() {
3054 data_bindings.Clear();
3057 [EditorBrowsable(EditorBrowsableState.Never)]
3058 public virtual void ResetCursor() {
3062 [EditorBrowsable(EditorBrowsableState.Never)]
3063 public virtual void ResetFont() {
3067 [EditorBrowsable(EditorBrowsableState.Never)]
3068 public virtual void ResetForeColor() {
3069 foreground_color = Color.Empty;
3072 [EditorBrowsable(EditorBrowsableState.Never)]
3073 public void ResetImeMode() {
3074 ime_mode = DefaultImeMode;
3077 [EditorBrowsable(EditorBrowsableState.Never)]
3078 public virtual void ResetRightToLeft() {
3079 right_to_left = RightToLeft.Inherit;
3082 public virtual void ResetText() {
3083 text = String.Empty;
3086 public void ResumeLayout() {
3087 ResumeLayout (true);
3090 public void ResumeLayout(bool performLayout) {
3091 if (layout_suspended > 0) {
3095 if (layout_suspended == 0) {
3096 Control [] controls = child_controls.GetAllControls ();
3097 for (int i=0; i<controls.Length; i++) {
3098 controls [i].UpdateDistances ();
3101 if (performLayout && layout_pending) {
3107 public void Scale(float ratio) {
3108 ScaleCore(ratio, ratio);
3111 public void Scale(float dx, float dy) {
3116 public void Scale(SizeF factor) {
3117 ScaleCore(factor.Width, factor.Height);
3121 public void Select() {
3122 Select(false, false);
3125 public bool SelectNextControl(Control ctl, bool forward, bool tabStopOnly, bool nested, bool wrap) {
3130 c = GetNextControl(c, forward);
3139 if (c.CanSelect && ((c.parent == this) || nested) && (c.tab_stop || !tabStopOnly)) {
3143 } while (c != ctl); // If we wrap back to ourselves we stop
3148 public void SendToBack() {
3149 if (parent != null) {
3150 parent.child_controls.SetChildIndex(this, parent.child_controls.Count);
3154 public void SetBounds(int x, int y, int width, int height) {
3155 SetBoundsCore(x, y, width, height, BoundsSpecified.All);
3158 public void SetBounds(int x, int y, int width, int height, BoundsSpecified specified) {
3159 SetBoundsCore(x, y, width, height, specified);
3162 public void Show() {
3164 this.CreateControl();
3170 public void SuspendLayout() {
3174 public void Update() {
3175 needs_redraw = true;
3176 if (IsHandleCreated) {
3177 XplatUI.UpdateWindow(window.Handle);
3180 #endregion // Public Instance Methods
3182 #region Protected Instance Methods
3183 [EditorBrowsable(EditorBrowsableState.Advanced)]
3184 [MonoTODO("Implement this and tie it into Control.ControlAccessibleObject.NotifyClients")]
3185 protected void AccessibilityNotifyClients(AccessibleEvents accEvent, int childID) {
3186 throw new NotImplementedException();
3189 [EditorBrowsable(EditorBrowsableState.Advanced)]
3190 protected virtual AccessibleObject CreateAccessibilityInstance() {
3191 return new Control.ControlAccessibleObject(this);
3194 [EditorBrowsable(EditorBrowsableState.Advanced)]
3195 protected virtual ControlCollection CreateControlsInstance() {
3196 return new ControlCollection(this);
3199 [EditorBrowsable(EditorBrowsableState.Advanced)]
3200 protected virtual void CreateHandle() {
3202 throw new ObjectDisposedException(Name);
3205 if (IsHandleCreated && !is_recreating) {
3209 window.CreateHandle(CreateParams);
3211 if (window.Handle != IntPtr.Zero) {
3212 if (!controls.Contains(window.Handle)) {
3216 creator_thread = Thread.CurrentThread;
3218 XplatUI.EnableWindow(window.Handle, is_enabled);
3220 if (clip_region != null) {
3221 XplatUI.SetClipRegion(Handle, clip_region);
3224 // Set our handle with our parent
3225 if ((parent != null) && (parent.IsHandleCreated)) {
3226 XplatUI.SetParent(window.Handle, parent.Handle);
3229 // Set our handle as parent for our children
3230 Control [] children;
3232 children = child_controls.GetAllControls ();
3233 for (int i = 0; i < children.Length; i++ ) {
3234 if (children[i].IsHandleCreated) {
3235 XplatUI.SetParent(children[i].Handle, window.Handle);
3240 XplatUI.SetAllowDrop (Handle, allow_drop);
3242 // Find out where the window manager placed us
3243 if ((CreateParams.Style & (int)WindowStyles.WS_CHILD) != 0) {
3244 XplatUI.SetBorderStyle(window.Handle, (FormBorderStyle)border_style);
3248 OnHandleCreated(EventArgs.Empty);
3253 [EditorBrowsable(EditorBrowsableState.Advanced)]
3254 protected virtual void DefWndProc(ref Message m) {
3255 window.DefWndProc(ref m);
3258 [EditorBrowsable(EditorBrowsableState.Advanced)]
3259 protected virtual void DestroyHandle() {
3260 if (IsHandleCreated) {
3261 if (window != null) {
3262 window.DestroyHandle();
3267 protected bool GetStyle(ControlStyles flag) {
3268 return (control_style & flag) != 0;
3271 protected bool GetTopLevel() {
3275 [EditorBrowsable(EditorBrowsableState.Advanced)]
3276 protected virtual void InitLayout() {
3280 [EditorBrowsable(EditorBrowsableState.Advanced)]
3281 protected void InvokeGotFocus(Control toInvoke, EventArgs e) {
3282 toInvoke.OnGotFocus(e);
3285 [EditorBrowsable(EditorBrowsableState.Advanced)]
3286 protected void InvokeLostFocus(Control toInvoke, EventArgs e) {
3287 toInvoke.OnLostFocus(e);
3290 [EditorBrowsable(EditorBrowsableState.Advanced)]
3291 protected void InvokeOnClick(Control toInvoke, EventArgs e) {
3292 toInvoke.OnClick(e);
3295 protected void InvokePaint(Control toInvoke, PaintEventArgs e) {
3296 toInvoke.OnPaint(e);
3299 protected void InvokePaintBackground(Control toInvoke, PaintEventArgs e) {
3300 toInvoke.OnPaintBackground(e);
3303 protected virtual bool IsInputChar (char charCode) {
3307 protected virtual bool IsInputKey (Keys keyData) {
3308 // Doc says this one calls IsInputChar; not sure what to do with that
3312 [EditorBrowsable(EditorBrowsableState.Advanced)]
3313 protected virtual void NotifyInvalidate(Rectangle invalidatedArea) {
3317 protected virtual bool ProcessCmdKey(ref Message msg, Keys keyData) {
3318 if ((context_menu != null) && context_menu.ProcessCmdKey(ref msg, keyData)) {
3322 if (parent != null) {
3323 return parent.ProcessCmdKey(ref msg, keyData);
3329 protected virtual bool ProcessDialogChar(char charCode) {
3330 if (parent != null) {
3331 return parent.ProcessDialogChar (charCode);
3337 protected virtual bool ProcessDialogKey (Keys keyData) {
3338 if (parent != null) {
3339 return parent.ProcessDialogKey (keyData);
3345 protected virtual bool ProcessKeyEventArgs (ref Message msg)
3347 KeyEventArgs key_event;
3350 case (int)Msg.WM_SYSKEYDOWN:
3351 case (int)Msg.WM_KEYDOWN: {
3352 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
3353 OnKeyDown (key_event);
3354 return key_event.Handled;
3357 case (int)Msg.WM_SYSKEYUP:
3358 case (int)Msg.WM_KEYUP: {
3359 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
3360 OnKeyUp (key_event);
3361 return key_event.Handled;
3364 case (int)Msg.WM_SYSCHAR:
3365 case (int)Msg.WM_CHAR: {
3366 KeyPressEventArgs key_press_event;
3368 key_press_event = new KeyPressEventArgs((char)msg.WParam);
3369 OnKeyPress(key_press_event);
3370 return key_press_event.Handled;
3381 protected internal virtual bool ProcessKeyMessage(ref Message msg) {
3382 if (parent != null) {
3383 if (parent.ProcessKeyPreview(ref msg)) {
3388 return ProcessKeyEventArgs(ref msg);
3391 protected virtual bool ProcessKeyPreview(ref Message msg) {
3392 if (parent != null) {
3393 return parent.ProcessKeyPreview(ref msg);
3399 protected virtual bool ProcessMnemonic(char charCode) {
3404 [EditorBrowsable(EditorBrowsableState.Advanced)]
3405 protected void RaiseDragEvent(object key, DragEventArgs e) {
3409 [EditorBrowsable(EditorBrowsableState.Advanced)]
3410 protected void RaiseKeyEvent(object key, KeyEventArgs e) {
3414 [EditorBrowsable(EditorBrowsableState.Advanced)]
3415 protected void RaiseMouseEvent(object key, MouseEventArgs e) {
3419 [EditorBrowsable(EditorBrowsableState.Advanced)]
3420 protected void RaisePaintEvent(object key, PaintEventArgs e) {
3424 [EditorBrowsable(EditorBrowsableState.Advanced)]
3425 protected void RecreateHandle() {
3428 if (IsHandleCreated) {
3430 // WM_DESTROY will CreateHandle for us
3439 is_recreating = false;
3442 [EditorBrowsable(EditorBrowsableState.Advanced)]
3443 protected void ResetMouseEventArgs() {
3447 [EditorBrowsable(EditorBrowsableState.Advanced)]
3448 protected ContentAlignment RtlTranslateAlignment(ContentAlignment align) {
3449 if (right_to_left == RightToLeft.No) {
3454 case ContentAlignment.TopLeft: {
3455 return ContentAlignment.TopRight;
3458 case ContentAlignment.TopRight: {
3459 return ContentAlignment.TopLeft;
3462 case ContentAlignment.MiddleLeft: {
3463 return ContentAlignment.MiddleRight;
3466 case ContentAlignment.MiddleRight: {
3467 return ContentAlignment.MiddleLeft;
3470 case ContentAlignment.BottomLeft: {
3471 return ContentAlignment.BottomRight;
3474 case ContentAlignment.BottomRight: {
3475 return ContentAlignment.BottomLeft;
3479 // if it's center it doesn't change
3485 [EditorBrowsable(EditorBrowsableState.Advanced)]
3486 protected HorizontalAlignment RtlTranslateAlignment(HorizontalAlignment align) {
3487 if ((right_to_left == RightToLeft.No) || (align == HorizontalAlignment.Center)) {
3491 if (align == HorizontalAlignment.Left) {
3492 return HorizontalAlignment.Right;
3495 // align must be HorizontalAlignment.Right
3496 return HorizontalAlignment.Left;
3499 [EditorBrowsable(EditorBrowsableState.Advanced)]
3500 protected LeftRightAlignment RtlTranslateAlignment(LeftRightAlignment align) {
3501 if (right_to_left == RightToLeft.No) {
3505 if (align == LeftRightAlignment.Left) {
3506 return LeftRightAlignment.Right;
3509 // align must be LeftRightAlignment.Right;
3510 return LeftRightAlignment.Left;
3513 [EditorBrowsable(EditorBrowsableState.Advanced)]
3514 protected ContentAlignment RtlTranslateContent(ContentAlignment align) {
3515 return RtlTranslateAlignment(align);
3518 [EditorBrowsable(EditorBrowsableState.Advanced)]
3519 protected HorizontalAlignment RtlTranslateHorizontal(HorizontalAlignment align) {
3520 return RtlTranslateAlignment(align);
3523 [EditorBrowsable(EditorBrowsableState.Advanced)]
3524 protected LeftRightAlignment RtlTranslateLeftRight(LeftRightAlignment align) {
3525 return RtlTranslateAlignment(align);
3528 [EditorBrowsable(EditorBrowsableState.Advanced)]
3529 protected virtual void ScaleCore(float dx, float dy) {
3535 location = new Point((int)(Left * dx), (int)(Top * dy));
3536 size = this.ClientSize;
3538 if (!GetStyle(ControlStyles.FixedWidth)) {
3539 size.Width = (int)(size.Width * dx);
3542 if (!GetStyle(ControlStyles.FixedHeight)) {
3543 size.Height = (int)(size.Height * dy);
3546 SetBoundsCore(location.X, location.Y, size.Width, size.Height, BoundsSpecified.All);
3548 /* Now scale our children */
3549 Control [] controls = child_controls.GetAllControls ();
3550 for (int i=0; i < controls.Length; i++) {
3551 controls[i].Scale(dx, dy);
3557 protected virtual void Select(bool directed, bool forward) {
3558 IContainerControl container;
3560 container = GetContainerControl();
3561 if (container != null) {
3562 container.ActiveControl = this;
3566 [EditorBrowsable(EditorBrowsableState.Advanced)]
3567 protected virtual void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
3568 // SetBoundsCore updates the Win32 control itself. UpdateBounds updates the controls variables and fires events, I'm guessing - pdb
3569 if ((specified & BoundsSpecified.X) != BoundsSpecified.X) {
3573 if ((specified & BoundsSpecified.Y) != BoundsSpecified.Y) {
3577 if ((specified & BoundsSpecified.Width) != BoundsSpecified.Width) {
3581 if ((specified & BoundsSpecified.Height) != BoundsSpecified.Height) {
3585 if (IsHandleCreated) {
3586 XplatUI.SetWindowPos(Handle, x, y, width, height);
3589 UpdateBounds(x, y, width, height);
3594 [EditorBrowsable(EditorBrowsableState.Advanced)]
3595 protected virtual void SetClientSizeCore(int x, int y) {
3596 // Calculate the actual window size from the client size (it usually stays the same or grows)
3597 Rectangle ClientRect;
3598 Rectangle WindowRect;
3601 ClientRect = new Rectangle(0, 0, x, y);
3602 cp = this.CreateParams;
3604 if (XplatUI.CalculateWindowRect(ref ClientRect, cp.Style, cp.ExStyle, null, out WindowRect)==false) {
3608 SetBoundsCore(bounds.X, bounds.Y, WindowRect.Width, WindowRect.Height, BoundsSpecified.Size);
3611 [EditorBrowsable(EditorBrowsableState.Advanced)]
3612 protected void SetStyle(ControlStyles flag, bool value) {
3614 control_style |= flag;
3616 control_style &= ~flag;
3620 protected void SetTopLevel(bool value) {
3621 if ((GetTopLevel() != value) && (parent != null)) {
3622 throw new Exception();
3626 if (value == true) {
3636 is_toplevel = value;
3639 protected virtual void SetVisibleCore(bool value) {
3640 if (value!=is_visible) {
3641 if (value && !is_created) {
3647 if (IsHandleCreated) {
3648 XplatUI.SetVisible(Handle, value);
3649 // Explicitly move Toplevel windows to where we want them;
3650 // apparently moving unmapped toplevel windows doesn't work
3651 if (is_visible && (this is Form)) {
3652 XplatUI.SetWindowPos(window.Handle, bounds.X, bounds.Y, bounds.Width, bounds.Height);
3656 OnVisibleChanged(EventArgs.Empty);
3658 if (value == false && parent != null && Focused) {
3661 // Need to start at parent, GetContainerControl might return ourselves if we're a container
3662 container = (Control)parent.GetContainerControl();
3663 if (container != null) {
3664 container.SelectNextControl(this, true, true, true, true);
3668 if (parent != null) {
3669 parent.PerformLayout(this, "visible");
3671 PerformLayout(this, "visible");
3676 [EditorBrowsable(EditorBrowsableState.Advanced)]
3677 protected void UpdateBounds() {
3685 if (!IsHandleCreated) {
3689 XplatUI.GetWindowPos(this.Handle, this is Form, out x, out y, out width, out height, out client_width, out client_height);
3691 UpdateBounds(x, y, width, height, client_width, client_height);
3694 [EditorBrowsable(EditorBrowsableState.Advanced)]
3695 protected void UpdateBounds(int x, int y, int width, int height) {
3699 // Calculate client rectangle
3700 rect = new Rectangle(0, 0, 0, 0);
3703 XplatUI.CalculateWindowRect(ref rect, cp.Style, cp.ExStyle, cp.menu, out rect);
3704 UpdateBounds(x, y, width, height, width - (rect.Right - rect.Left), height - (rect.Bottom - rect.Top));
3707 [EditorBrowsable(EditorBrowsableState.Advanced)]
3708 protected void UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) {
3709 // UpdateBounds only seems to set our sizes and fire events but not update the GUI window to match
3711 bool resized = false;
3713 // Needed to generate required notifications
3714 if ((this.bounds.X!=x) || (this.bounds.Y!=y)) {
3718 if ((this.Bounds.Width!=width) || (this.Bounds.Height!=height)) {
3725 bounds.Height=height;
3727 client_size.Width=clientWidth;
3728 client_size.Height=clientHeight;
3731 OnLocationChanged(EventArgs.Empty);
3735 OnSizeChanged(EventArgs.Empty);
3739 [EditorBrowsable(EditorBrowsableState.Advanced)]
3740 protected void UpdateStyles() {
3741 if (!IsHandleCreated) {
3745 XplatUI.SetWindowStyle(window.Handle, CreateParams);
3746 OnStyleChanged(EventArgs.Empty);
3749 private void UpdateZOrderOfChild(Control child) {
3750 if (IsHandleCreated && child.IsHandleCreated && (child.parent == this)) {
3753 index = child_controls.IndexOf(child);
3756 XplatUI.SetZOrder(child.Handle, child_controls[index - 1].Handle, false, false);
3758 XplatUI.SetZOrder(child.Handle, IntPtr.Zero, true, false);
3763 private void UpdateChildrenZOrder() {
3764 Control [] controls;
3766 if (!IsHandleCreated) {
3770 controls = child_controls.GetAllControls ();
3771 for (int i = 1; i < controls.Length; i++ ) {
3772 XplatUI.SetZOrder(controls[i].Handle, controls[i-1].Handle, false, false);
3776 [EditorBrowsable(EditorBrowsableState.Advanced)]
3777 protected void UpdateZOrder() {
3778 if (parent != null) {
3779 parent.UpdateZOrderOfChild(this);
3783 protected virtual void WndProc(ref Message m) {
3785 Console.WriteLine("Control {0} received message {1}", window.Handle == IntPtr.Zero ? this.Text : XplatUI.Window(window.Handle), (Msg)m.Msg);
3787 if ((this.control_style & ControlStyles.EnableNotifyMessage) != 0) {
3791 switch((Msg)m.Msg) {
3792 case Msg.WM_DESTROY: {
3793 OnHandleDestroyed(EventArgs.Empty);
3794 window.InvalidateHandle();
3796 if (ParentIsRecreating) {
3798 } else if (is_recreating) {
3804 case Msg.WM_WINDOWPOSCHANGED: {
3807 if (GetStyle(ControlStyles.ResizeRedraw)) {
3814 // Nice description of what should happen when handling WM_PAINT
3815 // can be found here: http://pluralsight.com/wiki/default.aspx/Craig/FlickerFreeControlDrawing.html
3816 // and here http://msdn.microsoft.com/msdnmag/issues/06/03/WindowsFormsPerformance/
3817 case Msg.WM_PAINT: {
3818 PaintEventArgs paint_event;
3821 paint_event = XplatUI.PaintEventStart(Handle, true);
3822 reset_context = false;
3824 if (paint_event == null) {
3828 if (!needs_redraw) {
3829 // Just blit the previous image
3830 paint_event.Graphics.DrawImage (ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle, GraphicsUnit.Pixel);
3831 XplatUI.PaintEventEnd(Handle, true);
3836 if (ThemeEngine.Current.DoubleBufferingSupported) {
3837 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
3838 dc = paint_event.SetGraphics (DeviceContext);
3839 reset_context = true;
3843 if (!GetStyle(ControlStyles.Opaque)) {
3844 OnPaintBackground(paint_event);
3847 // Button-derived controls choose to ignore their Opaque style, give them a chance to draw their background anyways
3848 OnPaintBackgroundInternal(paint_event);
3850 OnPaintInternal(paint_event);
3851 if (!paint_event.Handled) {
3852 OnPaint(paint_event);
3855 if (ThemeEngine.Current.DoubleBufferingSupported)
3856 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
3857 dc.DrawImage (ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle, GraphicsUnit.Pixel);
3858 paint_event.SetGraphics (dc);
3859 needs_redraw = false;
3862 XplatUI.PaintEventEnd(Handle, true);
3864 if (reset_context) {
3865 ResetDeviceContext();
3871 case Msg.WM_ERASEBKGND: {
3872 // The DefWndProc will never have to handle this, we always paint the background in managed code
3873 // In theory this code would look at ControlStyles.AllPaintingInWmPaint and and call OnPaintBackground
3874 // here but it just makes things more complicated...
3875 m.Result = (IntPtr)1;
3879 case Msg.WM_LBUTTONUP: {
3882 me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Left,
3884 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3887 HandleClick(mouse_clicks, me);
3890 if (InternalCapture) {
3891 InternalCapture = false;
3894 if (mouse_clicks > 1) {
3900 case Msg.WM_LBUTTONDOWN: {
3904 InternalCapture = true;
3905 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3906 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3912 case Msg.WM_LBUTTONDBLCLK: {
3913 InternalCapture = true;
3915 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3916 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3922 case Msg.WM_MBUTTONUP: {
3925 me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Middle,
3927 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3930 HandleClick(mouse_clicks, me);
3932 if (InternalCapture) {
3933 InternalCapture = false;
3935 if (mouse_clicks > 1) {
3941 case Msg.WM_MBUTTONDOWN: {
3942 InternalCapture = true;
3943 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3944 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3950 case Msg.WM_MBUTTONDBLCLK: {
3951 InternalCapture = true;
3953 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3954 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3959 case Msg.WM_RBUTTONUP: {
3963 pt = new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()));
3964 pt = PointToScreen(pt);
3966 XplatUI.SendMessage(m.HWnd, Msg.WM_CONTEXTMENU, m.HWnd, (IntPtr)(pt.X + (pt.Y << 16)));
3968 me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Right,
3970 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3973 HandleClick(mouse_clicks, me);
3976 if (InternalCapture) {
3977 InternalCapture = false;
3980 if (mouse_clicks > 1) {
3986 case Msg.WM_RBUTTONDOWN: {
3987 InternalCapture = true;
3988 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3989 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3994 case Msg.WM_RBUTTONDBLCLK: {
3995 InternalCapture = true;
3997 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3998 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4003 case Msg.WM_CONTEXTMENU: {
4004 if (context_menu != null) {
4007 pt = new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()));
4008 context_menu.Show(this, PointToClient(pt));
4016 case Msg.WM_MOUSEWHEEL: {
4018 OnMouseWheel (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4019 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4020 HighOrder(m.WParam.ToInt32())));
4025 case Msg.WM_MOUSEMOVE: {
4026 OnMouseMove (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4028 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4033 case Msg.WM_MOUSE_ENTER: {
4038 OnMouseEnter(EventArgs.Empty);
4042 case Msg.WM_MOUSE_LEAVE: {
4044 OnMouseLeave(EventArgs.Empty);
4048 case Msg.WM_MOUSEHOVER: {
4049 OnMouseHover(EventArgs.Empty);
4053 case Msg.WM_SYSKEYUP: {
4054 if (ProcessKeyMessage(ref m)) {
4055 m.Result = IntPtr.Zero;
4059 if ((m.WParam.ToInt32() & (int)Keys.KeyCode) == (int)Keys.Menu) {
4063 if (form != null && form.ActiveMenu != null) {
4064 form.ActiveMenu.ProcessCmdKey(ref m, (Keys)m.WParam.ToInt32());
4072 case Msg.WM_SYSKEYDOWN:
4073 case Msg.WM_KEYDOWN:
4075 case Msg.WM_SYSCHAR:
4077 if (ProcessKeyMessage(ref m)) {
4078 m.Result = IntPtr.Zero;
4087 if (m.LParam != IntPtr.Zero) {
4090 hi = new HELPINFO();
4092 hi = (HELPINFO) Marshal.PtrToStructure (m.LParam, typeof (HELPINFO));
4093 mouse_pos = new Point(hi.MousePos.x, hi.MousePos.y);
4095 mouse_pos = Control.MousePosition;
4097 OnHelpRequested(new HelpEventArgs(mouse_pos));
4098 m.Result = (IntPtr)1;
4102 case Msg.WM_KILLFOCUS: {
4103 if (CausesValidation) {
4105 e = new CancelEventArgs(false);
4114 OnValidated(EventArgs.Empty);
4117 this.has_focus = false;
4118 OnLostFocusInternal (EventArgs.Empty);
4122 case Msg.WM_SETFOCUS: {
4124 this.has_focus = true;
4125 OnGotFocusInternal (EventArgs.Empty);
4131 case Msg.WM_SYSCOLORCHANGE: {
4132 ThemeEngine.Current.ResetDefaults();
4133 OnSystemColorsChanged(EventArgs.Empty);
4138 case Msg.WM_SETCURSOR: {
4139 if ((cursor == null) || ((HitTest)(m.LParam.ToInt32() & 0xffff) != HitTest.HTCLIENT)) {
4144 XplatUI.SetCursor(window.Handle, cursor.handle);
4145 m.Result = (IntPtr)1;
4156 #endregion // Public Instance Methods
4158 #region OnXXX methods
4159 [EditorBrowsable(EditorBrowsableState.Advanced)]
4160 protected virtual void OnBackColorChanged(EventArgs e) {
4161 if (BackColorChanged!=null) BackColorChanged(this, e);
4162 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackColorChanged(e);
4165 [EditorBrowsable(EditorBrowsableState.Advanced)]
4166 protected virtual void OnBackgroundImageChanged(EventArgs e) {
4167 if (BackgroundImageChanged!=null) BackgroundImageChanged(this, e);
4168 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackgroundImageChanged(e);
4171 [EditorBrowsable(EditorBrowsableState.Advanced)]
4172 protected virtual void OnBindingContextChanged(EventArgs e) {
4173 CheckDataBindings ();
4174 if (BindingContextChanged!=null) {
4175 BindingContextChanged(this, e);
4177 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBindingContextChanged(e);
4180 [EditorBrowsable(EditorBrowsableState.Advanced)]
4181 protected virtual void OnCausesValidationChanged(EventArgs e) {
4182 if (CausesValidationChanged!=null) CausesValidationChanged(this, e);
4185 [EditorBrowsable(EditorBrowsableState.Advanced)]
4186 protected virtual void OnChangeUICues(UICuesEventArgs e) {
4187 if (ChangeUICues!=null) ChangeUICues(this, e);
4190 [EditorBrowsable(EditorBrowsableState.Advanced)]
4191 protected virtual void OnClick(EventArgs e) {
4192 if (Click!=null) Click(this, e);
4195 [EditorBrowsable(EditorBrowsableState.Advanced)]
4196 protected virtual void OnContextMenuChanged(EventArgs e) {
4197 if (ContextMenuChanged!=null) ContextMenuChanged(this, e);
4200 [EditorBrowsable(EditorBrowsableState.Advanced)]
4201 protected virtual void OnControlAdded(ControlEventArgs e) {
4202 if (ControlAdded!=null) ControlAdded(this, e);
4205 [EditorBrowsable(EditorBrowsableState.Advanced)]
4206 protected virtual void OnControlRemoved(ControlEventArgs e) {
4207 if (ControlRemoved!=null) ControlRemoved(this, e);
4210 [EditorBrowsable(EditorBrowsableState.Advanced)]
4211 protected virtual void OnCreateControl() {
4215 [EditorBrowsable(EditorBrowsableState.Advanced)]
4216 protected virtual void OnCursorChanged(EventArgs e) {
4217 if (CursorChanged!=null) CursorChanged(this, e);
4220 [EditorBrowsable(EditorBrowsableState.Advanced)]
4221 protected virtual void OnDockChanged(EventArgs e) {
4222 if (DockChanged!=null) DockChanged(this, e);
4225 [EditorBrowsable(EditorBrowsableState.Advanced)]
4226 protected virtual void OnDoubleClick(EventArgs e) {
4227 if (DoubleClick!=null) DoubleClick(this, e);
4230 [EditorBrowsable(EditorBrowsableState.Advanced)]
4231 protected virtual void OnDragDrop(DragEventArgs drgevent) {
4232 if (DragDrop!=null) DragDrop(this, drgevent);
4235 [EditorBrowsable(EditorBrowsableState.Advanced)]
4236 protected virtual void OnDragEnter(DragEventArgs drgevent) {
4237 if (DragEnter!=null) DragEnter(this, drgevent);
4240 [EditorBrowsable(EditorBrowsableState.Advanced)]
4241 protected virtual void OnDragLeave(EventArgs e) {
4242 if (DragLeave!=null) DragLeave(this, e);
4245 [EditorBrowsable(EditorBrowsableState.Advanced)]
4246 protected virtual void OnDragOver(DragEventArgs drgevent) {
4247 if (DragOver!=null) DragOver(this, drgevent);
4250 [EditorBrowsable(EditorBrowsableState.Advanced)]
4251 protected virtual void OnEnabledChanged(EventArgs e) {
4252 if (IsHandleCreated) {
4254 if (((Form)this).context == null) {
4255 XplatUI.EnableWindow(window.Handle, Enabled);
4258 XplatUI.EnableWindow(window.Handle, Enabled);
4263 if (EnabledChanged != null) {
4264 EnabledChanged(this, e);
4267 for (int i=0; i<child_controls.Count; i++) {
4268 child_controls[i].OnParentEnabledChanged(e);
4272 [EditorBrowsable(EditorBrowsableState.Advanced)]
4273 protected virtual void OnEnter(EventArgs e) {
4274 if (Enter!=null) Enter(this, e);
4277 [EditorBrowsable(EditorBrowsableState.Advanced)]
4278 protected virtual void OnFontChanged(EventArgs e) {
4279 if (FontChanged!=null) FontChanged(this, e);
4280 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentFontChanged(e);
4283 [EditorBrowsable(EditorBrowsableState.Advanced)]
4284 protected virtual void OnForeColorChanged(EventArgs e) {
4285 if (ForeColorChanged!=null) ForeColorChanged(this, e);
4286 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentForeColorChanged(e);
4289 [EditorBrowsable(EditorBrowsableState.Advanced)]
4290 protected virtual void OnGiveFeedback(GiveFeedbackEventArgs gfbevent) {
4291 if (GiveFeedback!=null) GiveFeedback(this, gfbevent);
4294 [EditorBrowsable(EditorBrowsableState.Advanced)]
4295 protected virtual void OnGotFocus(EventArgs e) {
4296 if (GotFocus!=null) GotFocus(this, e);
4299 [EditorBrowsable(EditorBrowsableState.Advanced)]
4300 protected virtual void OnHandleCreated(EventArgs e) {
4301 if (HandleCreated!=null) HandleCreated(this, e);
4304 [EditorBrowsable(EditorBrowsableState.Advanced)]
4305 protected virtual void OnHandleDestroyed(EventArgs e) {
4306 if (HandleDestroyed!=null) HandleDestroyed(this, e);
4309 [EditorBrowsable(EditorBrowsableState.Advanced)]
4310 protected virtual void OnHelpRequested(HelpEventArgs hevent) {
4311 if (HelpRequested!=null) HelpRequested(this, hevent);
4314 protected virtual void OnImeModeChanged(EventArgs e) {
4315 if (ImeModeChanged!=null) ImeModeChanged(this, e);
4318 [EditorBrowsable(EditorBrowsableState.Advanced)]
4319 protected virtual void OnInvalidated(InvalidateEventArgs e) {
4320 needs_redraw = true;
4321 if (Invalidated!=null) Invalidated(this, e);
4324 [EditorBrowsable(EditorBrowsableState.Advanced)]
4325 protected virtual void OnKeyDown(KeyEventArgs e) {
4326 if (KeyDown!=null) KeyDown(this, e);
4329 [EditorBrowsable(EditorBrowsableState.Advanced)]
4330 protected virtual void OnKeyPress(KeyPressEventArgs e) {
4331 if (KeyPress!=null) KeyPress(this, e);
4334 [EditorBrowsable(EditorBrowsableState.Advanced)]
4335 protected virtual void OnKeyUp(KeyEventArgs e) {
4336 if (KeyUp!=null) KeyUp(this, e);
4339 [EditorBrowsable(EditorBrowsableState.Advanced)]
4340 protected virtual void OnLayout(LayoutEventArgs levent) {
4341 if (Layout!=null) Layout(this, levent);
4344 [EditorBrowsable(EditorBrowsableState.Advanced)]
4345 protected virtual void OnLeave(EventArgs e) {
4346 if (Leave!=null) Leave(this, e);
4349 [EditorBrowsable(EditorBrowsableState.Advanced)]
4350 protected virtual void OnLocationChanged(EventArgs e) {
4352 if (LocationChanged!=null) LocationChanged(this, e);
4355 [EditorBrowsable(EditorBrowsableState.Advanced)]
4356 protected virtual void OnLostFocus(EventArgs e) {
4357 if (LostFocus!=null) LostFocus(this, e);
4360 [EditorBrowsable(EditorBrowsableState.Advanced)]
4361 protected virtual void OnMouseDown(MouseEventArgs e) {
4362 if (MouseDown!=null) MouseDown(this, e);
4365 [EditorBrowsable(EditorBrowsableState.Advanced)]
4366 protected virtual void OnMouseEnter(EventArgs e) {
4367 if (MouseEnter!=null) MouseEnter(this, e);
4370 [EditorBrowsable(EditorBrowsableState.Advanced)]
4371 protected virtual void OnMouseHover(EventArgs e) {
4372 if (MouseHover!=null) MouseHover(this, e);
4375 [EditorBrowsable(EditorBrowsableState.Advanced)]
4376 protected virtual void OnMouseLeave(EventArgs e) {
4377 if (MouseLeave!=null) MouseLeave(this, e);
4380 [EditorBrowsable(EditorBrowsableState.Advanced)]
4381 protected virtual void OnMouseMove(MouseEventArgs e) {
4382 if (MouseMove!=null) MouseMove(this, e);
4385 [EditorBrowsable(EditorBrowsableState.Advanced)]
4386 protected virtual void OnMouseUp(MouseEventArgs e) {
4387 if (MouseUp!=null) MouseUp(this, e);
4390 [EditorBrowsable(EditorBrowsableState.Advanced)]
4391 protected virtual void OnMouseWheel(MouseEventArgs e) {
4392 if (MouseWheel!=null) MouseWheel(this, e);
4395 [EditorBrowsable(EditorBrowsableState.Advanced)]
4396 protected virtual void OnMove(EventArgs e) {
4397 if (Move!=null) Move(this, e);
4400 [EditorBrowsable(EditorBrowsableState.Advanced)]
4401 protected virtual void OnNotifyMessage(Message m) {
4405 [EditorBrowsable(EditorBrowsableState.Advanced)]
4406 protected virtual void OnPaint(PaintEventArgs e) {
4407 if (Paint!=null) Paint(this, e);
4410 internal virtual void OnPaintBackgroundInternal(PaintEventArgs e) {
4414 internal virtual void OnPaintInternal(PaintEventArgs e) {
4418 internal virtual void OnGotFocusInternal (EventArgs e)
4423 internal virtual void OnLostFocusInternal (EventArgs e)
4428 [EditorBrowsable(EditorBrowsableState.Advanced)]
4429 protected virtual void OnPaintBackground(PaintEventArgs pevent) {
4430 PaintControlBackground (pevent);
4433 [EditorBrowsable(EditorBrowsableState.Advanced)]
4434 protected virtual void OnParentBackColorChanged(EventArgs e) {
4435 if (background_color.IsEmpty && background_image==null) {
4437 OnBackColorChanged(e);
4441 [EditorBrowsable(EditorBrowsableState.Advanced)]
4442 protected virtual void OnParentBackgroundImageChanged(EventArgs e) {
4443 if (background_color.IsEmpty && background_image==null) {
4445 OnBackgroundImageChanged(e);
4449 [EditorBrowsable(EditorBrowsableState.Advanced)]
4450 protected virtual void OnParentBindingContextChanged(EventArgs e) {
4451 if (binding_context==null) {
4452 binding_context=Parent.binding_context;
4453 OnBindingContextChanged(e);
4457 [EditorBrowsable(EditorBrowsableState.Advanced)]
4458 protected virtual void OnParentChanged(EventArgs e) {
4459 if (ParentChanged!=null) ParentChanged(this, e);
4462 [EditorBrowsable(EditorBrowsableState.Advanced)]
4463 protected virtual void OnParentEnabledChanged(EventArgs e) {
4465 OnEnabledChanged(e);
4469 [EditorBrowsable(EditorBrowsableState.Advanced)]
4470 protected virtual void OnParentFontChanged(EventArgs e) {
4477 [EditorBrowsable(EditorBrowsableState.Advanced)]
4478 protected virtual void OnParentForeColorChanged(EventArgs e) {
4479 if (foreground_color.IsEmpty) {
4481 OnForeColorChanged(e);
4485 [EditorBrowsable(EditorBrowsableState.Advanced)]
4486 protected virtual void OnParentRightToLeftChanged(EventArgs e) {
4487 if (right_to_left==RightToLeft.Inherit) {
4489 OnRightToLeftChanged(e);
4493 [EditorBrowsable(EditorBrowsableState.Advanced)]
4494 protected virtual void OnParentVisibleChanged(EventArgs e) {
4496 OnVisibleChanged(e);
4500 [EditorBrowsable(EditorBrowsableState.Advanced)]
4501 protected virtual void OnQueryContinueDrag(QueryContinueDragEventArgs e) {
4502 if (QueryContinueDrag!=null) QueryContinueDrag(this, e);
4505 [EditorBrowsable(EditorBrowsableState.Advanced)]
4506 protected virtual void OnResize(EventArgs e) {
4507 if (Resize!=null) Resize(this, e);
4509 PerformLayout(this, "bounds");
4511 if (parent != null) {
4512 parent.PerformLayout();
4516 [EditorBrowsable(EditorBrowsableState.Advanced)]
4517 protected virtual void OnRightToLeftChanged(EventArgs e) {
4518 if (RightToLeftChanged!=null) RightToLeftChanged(this, e);
4519 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentRightToLeftChanged(e);
4522 [EditorBrowsable(EditorBrowsableState.Advanced)]
4523 protected virtual void OnSizeChanged(EventArgs e) {
4524 InvalidateBuffers ();
4526 if (SizeChanged!=null) SizeChanged(this, e);
4529 [EditorBrowsable(EditorBrowsableState.Advanced)]
4530 protected virtual void OnStyleChanged(EventArgs e) {
4531 if (StyleChanged!=null) StyleChanged(this, e);
4534 [EditorBrowsable(EditorBrowsableState.Advanced)]
4535 protected virtual void OnSystemColorsChanged(EventArgs e) {
4536 if (SystemColorsChanged!=null) SystemColorsChanged(this, e);
4539 [EditorBrowsable(EditorBrowsableState.Advanced)]
4540 protected virtual void OnTabIndexChanged(EventArgs e) {
4541 if (TabIndexChanged!=null) TabIndexChanged(this, e);
4544 [EditorBrowsable(EditorBrowsableState.Advanced)]
4545 protected virtual void OnTabStopChanged(EventArgs e) {
4546 if (TabStopChanged!=null) TabStopChanged(this, e);
4549 [EditorBrowsable(EditorBrowsableState.Advanced)]
4550 protected virtual void OnTextChanged(EventArgs e) {
4551 if (TextChanged!=null) TextChanged(this, e);
4554 [EditorBrowsable(EditorBrowsableState.Advanced)]
4555 protected virtual void OnValidated(EventArgs e) {
4556 if (Validated!=null) Validated(this, e);
4559 [EditorBrowsable(EditorBrowsableState.Advanced)]
4560 protected virtual void OnValidating(System.ComponentModel.CancelEventArgs e) {
4561 if (Validating!=null) Validating(this, e);
4564 [EditorBrowsable(EditorBrowsableState.Advanced)]
4565 protected virtual void OnVisibleChanged(EventArgs e) {
4566 if ((parent != null) && !Created && Visible) {
4573 needs_redraw = true;
4575 if (VisibleChanged!=null) VisibleChanged(this, e);
4577 // We need to tell our kids
4578 for (int i=0; i<child_controls.Count; i++) {
4579 if (child_controls[i].Visible) {
4580 child_controls[i].OnParentVisibleChanged(e);
4584 #endregion // OnXXX methods
4587 public event EventHandler BackColorChanged;
4588 public event EventHandler BackgroundImageChanged;
4589 public event EventHandler BindingContextChanged;
4590 public event EventHandler CausesValidationChanged;
4591 public event UICuesEventHandler ChangeUICues;
4592 public event EventHandler Click;
4593 public event EventHandler ContextMenuChanged;
4595 [EditorBrowsable(EditorBrowsableState.Advanced)]
4597 public event ControlEventHandler ControlAdded;
4599 [EditorBrowsable(EditorBrowsableState.Advanced)]
4601 public event ControlEventHandler ControlRemoved;
4603 [MWFDescription("Fired when the cursor for the control has been changed"), MWFCategory("PropertyChanged")]
4604 public event EventHandler CursorChanged;
4605 public event EventHandler DockChanged;
4606 public event EventHandler DoubleClick;
4607 public event DragEventHandler DragDrop;
4608 public event DragEventHandler DragEnter;
4609 public event EventHandler DragLeave;
4610 public event DragEventHandler DragOver;
4611 public event EventHandler EnabledChanged;
4612 public event EventHandler Enter;
4613 public event EventHandler FontChanged;
4614 public event EventHandler ForeColorChanged;
4615 public event GiveFeedbackEventHandler GiveFeedback;
4617 [EditorBrowsable(EditorBrowsableState.Advanced)]
4619 public event EventHandler GotFocus;
4621 [EditorBrowsable(EditorBrowsableState.Advanced)]
4623 public event EventHandler HandleCreated;
4625 [EditorBrowsable(EditorBrowsableState.Advanced)]
4627 public event EventHandler HandleDestroyed;
4629 public event HelpEventHandler HelpRequested;
4630 public event EventHandler ImeModeChanged;
4632 [EditorBrowsable(EditorBrowsableState.Advanced)]
4634 public event InvalidateEventHandler Invalidated;
4636 public event KeyEventHandler KeyDown;
4637 public event KeyPressEventHandler KeyPress;
4638 public event KeyEventHandler KeyUp;
4639 public event LayoutEventHandler Layout;
4640 public event EventHandler Leave;
4641 public event EventHandler LocationChanged;
4643 [EditorBrowsable(EditorBrowsableState.Advanced)]
4645 public event EventHandler LostFocus;
4647 public event MouseEventHandler MouseDown;
4648 public event EventHandler MouseEnter;
4649 public event EventHandler MouseHover;
4650 public event EventHandler MouseLeave;
4651 public event MouseEventHandler MouseMove;
4652 public event MouseEventHandler MouseUp;
4654 [EditorBrowsable(EditorBrowsableState.Advanced)]
4656 public event MouseEventHandler MouseWheel;
4658 public event EventHandler Move;
4659 public event PaintEventHandler Paint;
4660 public event EventHandler ParentChanged;
4661 public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp;
4662 public event QueryContinueDragEventHandler QueryContinueDrag;
4663 public event EventHandler Resize;
4664 public event EventHandler RightToLeftChanged;
4665 public event EventHandler SizeChanged;
4666 public event EventHandler StyleChanged;
4667 public event EventHandler SystemColorsChanged;
4668 public event EventHandler TabIndexChanged;
4669 public event EventHandler TabStopChanged;
4670 public event EventHandler TextChanged;
4671 public event EventHandler Validated;
4672 public event CancelEventHandler Validating;
4673 public event EventHandler VisibleChanged;
4674 #endregion // Events