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-2005 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.Reflection;
43 using System.Runtime.InteropServices;
44 using System.Security;
45 using System.Threading;
48 namespace System.Windows.Forms
50 [Designer("System.Windows.Forms.Design.ControlDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
51 [DefaultProperty("Text")]
52 [DefaultEvent("Click")]
53 [DesignerSerializer("System.Windows.Forms.Design.ControlCodeDomSerializer, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
54 [ToolboxItemFilter("System.Windows.Forms")]
55 public class Control : Component, ISynchronizeInvoke, IWin32Window
57 #region Local Variables
60 internal Rectangle bounds; // bounding rectangle for control (client area + decorations)
61 internal object creator_thread; // thread that created the control
62 internal ControlNativeWindow window; // object for native window handle
63 internal string name; // for object naming
66 private bool create_handled; // true if OnCreateControl has been sent
67 internal bool has_focus; // true if control has focus
68 internal bool is_visible; // true if control is visible
69 internal bool is_entered; // is the mouse inside the control?
70 internal bool is_enabled; // true if control is enabled (usable/not grayed out)
71 internal bool is_selected; // true if control is selected
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 private bool allow_drop; // true if the control accepts droping objects on it
91 internal Color foreground_color; // foreground color for control
92 internal Color background_color; // background color for control
93 internal Image background_image; // background image for control
94 internal Font font; // font for control
95 internal string text; // window/title text for control
96 internal BorderStyle border_style; // Border style of control
99 internal AnchorStyles anchor_style; // anchoring requirements for our control
100 internal DockStyle dock_style; // docking requirements for our control (supercedes anchoring)
101 internal SizeF size_ratio; // size ratio of our control to it's parent; required for anchoring
102 internal Size prev_size; // previous size of the control; required for anchoring
104 // to be categorized...
105 static internal ArrayList controls = new ArrayList(); // All of the application's controls, in a flat list
106 internal ControlCollection child_controls; // our children
107 internal Control parent; // our parent control
108 internal AccessibleObject accessibility_object; // object that contains accessibility information about our control
109 internal BindingContext binding_context; // TODO
110 internal RightToLeft right_to_left; // drawing direction for control
111 internal int layout_suspended;
112 internal ContextMenu context_menu; // Context menu associated with the control
114 private Graphics dc_mem; // Graphics context for double buffering
115 private Bitmap bmp_mem; // Bitmap for double buffering control
116 private bool needs_redraw = true;
118 private ControlBindingsCollection data_bindings;
120 #endregion // Local Variables
122 #region Private Classes
123 // This helper class allows us to dispatch messages to Control.WndProc
124 internal class ControlNativeWindow : NativeWindow {
125 private Control owner;
127 public ControlNativeWindow(Control control) : base() {
132 public Control Owner {
138 static internal Control ControlFromHandle(IntPtr hWnd) {
139 ControlNativeWindow window;
141 window = (ControlNativeWindow)window_collection[hWnd];
146 protected override void WndProc(ref Message m) {
147 owner.WndProc(ref m);
152 #region Public Classes
154 public class ControlAccessibleObject : AccessibleObject {
155 #region ControlAccessibleObject Local Variables
156 private Control owner;
157 #endregion // ControlAccessibleObject Local Variables
159 #region ControlAccessibleObject Constructors
160 public ControlAccessibleObject(Control ownerControl) {
161 this.owner = ownerControl;
163 #endregion // ControlAccessibleObject Constructors
165 #region ControlAccessibleObject Public Instance Properties
166 public override string DefaultAction {
168 return base.DefaultAction;
172 public override string Description {
174 return base.Description;
178 public IntPtr Handle {
184 // We don't want to let them set it
188 public override string Help {
194 public override string KeyboardShortcut {
196 return base.KeyboardShortcut;
200 public override string Name {
210 public Control Owner {
216 public override AccessibleRole Role {
221 #endregion // ControlAccessibleObject Public Instance Properties
223 #region ControlAccessibleObject Public Instance Methods
224 public override int GetHelpTopic(out string FileName) {
225 return base.GetHelpTopic (out FileName);
228 [MonoTODO("Implement this and tie it into Control.AccessibilityNotifyClients")]
229 public void NotifyClients(AccessibleEvents accEvent) {
230 throw new NotImplementedException();
233 [MonoTODO("Implement this and tie it into Control.AccessibilityNotifyClients")]
234 public void NotifyClients(AccessibleEvents accEvent, int childID) {
235 throw new NotImplementedException();
238 public override string ToString() {
239 return "ControlAccessibleObject: Owner = " + owner.ToString() + ", Text: " + owner.text;
242 #endregion // ControlAccessibleObject Public Instance Methods
245 [DesignerSerializer("System.Windows.Forms.Design.ControlCollectionCodeDomSerializer, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
246 [ListBindable(false)]
247 public class ControlCollection : IList, ICollection, ICloneable, IEnumerable {
248 #region ControlCollection Local Variables
249 internal ArrayList list;
250 internal Control owner;
251 #endregion // ControlCollection Local Variables
253 #region ControlCollection Public Constructor
254 public ControlCollection(Control owner) {
256 this.list=new ArrayList();
260 #region ControlCollection Public Instance Properties
267 public bool IsReadOnly {
269 return list.IsReadOnly;
273 public virtual Control this[int index] {
275 if (index < 0 || index >= list.Count) {
276 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
278 return (Control)list[index];
281 #endregion // ControlCollection Public Instance Properties
283 #region ControlCollection Private Instance Methods
284 public virtual void Add (Control value)
287 for (int i = 0; i < list.Count; i++) {
288 if (list [i] == value) {
289 // Do we need to do anything here?
294 if (value.tab_index == -1) {
300 end = owner.child_controls.Count;
301 for (int i = 0; i < end; i++) {
302 index = owner.child_controls[i].tab_index;
307 value.tab_index = use;
311 value.Parent = owner;
312 owner.UpdateZOrder();
313 owner.OnControlAdded(new ControlEventArgs(value));
316 public virtual void AddRange (Control[] controls)
318 if (controls == null)
319 throw new ArgumentNullException ("controls");
321 owner.SuspendLayout ();
324 for (int i = 0; i < controls.Length; i++)
327 owner.ResumeLayout ();
331 public virtual void Clear ()
333 owner.SuspendLayout();
334 for (int i = 0; i < list.Count; i++) {
335 owner.OnControlRemoved(new ControlEventArgs((Control)list[i]));
338 owner.ResumeLayout();
341 public virtual bool Contains (Control value)
343 return list.Contains (value);
346 public void CopyTo (Array array, int index)
348 list.CopyTo(array, index);
351 public override bool Equals(object other) {
352 if (other is ControlCollection && (((ControlCollection)other).owner==this.owner)) {
359 public int GetChildIndex(Control child) {
360 return GetChildIndex(child, false);
363 public int GetChildIndex(Control child, bool throwException) {
366 index=list.IndexOf(child);
368 if (index==-1 && throwException) {
369 throw new ArgumentException("Not a child control", "child");
374 public IEnumerator GetEnumerator() {
375 return list.GetEnumerator();
378 public override int GetHashCode() {
379 return base.GetHashCode();
382 public int IndexOf(Control control) {
383 return list.IndexOf(control);
386 public virtual void Remove(Control value) {
387 owner.OnControlRemoved(new ControlEventArgs(value));
389 owner.UpdateZOrder();
392 public void RemoveAt(int index) {
393 if (index<0 || index>=list.Count) {
394 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
397 owner.OnControlRemoved(new ControlEventArgs((Control)list[index]));
398 list.RemoveAt(index);
399 owner.UpdateZOrder();
402 public void SetChildIndex(Control child, int newIndex) {
405 old_index=list.IndexOf(child);
407 throw new ArgumentException("Not a child control", "child");
410 if (old_index==newIndex) {
416 if (newIndex>list.Count) {
419 list.Insert(newIndex, child);
421 owner.UpdateZOrder();
423 #endregion // ControlCollection Private Instance Methods
425 #region ControlCollection Interface Properties
426 object IList.this[int index] {
428 if (index<0 || index>=list.Count) {
429 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
435 if (!(value is Control)) {
436 throw new ArgumentException("Object of type Control required", "value");
439 list[index]=(Control)value;
443 bool IList.IsFixedSize {
449 bool IList.IsReadOnly {
451 return list.IsReadOnly;
455 bool ICollection.IsSynchronized {
457 return list.IsSynchronized;
461 object ICollection.SyncRoot {
463 return list.SyncRoot;
466 #endregion // ControlCollection Interface Properties
468 #region ControlCollection Interface Methods
469 int IList.Add(object value) {
471 throw new ArgumentNullException("value", "Cannot add null controls");
474 if (!(value is Control)) {
475 throw new ArgumentException("Object of type Control required", "value");
478 return list.Add(value);
481 bool IList.Contains(object value) {
482 if (!(value is Control)) {
483 throw new ArgumentException("Object of type Control required", "value");
486 return this.Contains((Control) value);
489 int IList.IndexOf(object value) {
490 if (!(value is Control)) {
491 throw new ArgumentException("Object of type Control required", "value");
494 return this.IndexOf((Control) value);
497 void IList.Insert(int index, object value) {
498 if (!(value is Control)) {
499 throw new ArgumentException("Object of type Control required", "value");
501 list.Insert(index, value);
504 void IList.Remove(object value) {
505 if (!(value is Control)) {
506 throw new ArgumentException("Object of type Control required", "value");
511 void ICollection.CopyTo(Array array, int index) {
513 list.CopyTo(array, index);
517 Object ICloneable.Clone() {
518 ControlCollection clone = new ControlCollection(this.owner);
519 clone.list=(ArrayList)list.Clone(); // FIXME: Do we need this?
522 #endregion // ControlCollection Interface Methods
524 #endregion // ControlCollection Class
526 #region Public Constructors
528 creator_thread = Thread.CurrentThread;
530 prev_size = Size.Empty;
531 anchor_style = AnchorStyles.Top | AnchorStyles.Left;
533 create_handled = false;
539 layout_pending = false;
541 causes_validation = true;
543 layout_suspended = 0;
547 right_to_left = RightToLeft.Inherit;
549 control_style = ControlStyles.Selectable | ControlStyles.StandardClick | ControlStyles.StandardDoubleClick;
552 background_image = null;
556 window = new ControlNativeWindow(this);
557 child_controls = CreateControlsInstance();
558 client_size = new Size(DefaultSize.Width, DefaultSize.Height);
559 client_rect = new Rectangle(0, 0, DefaultSize.Width, DefaultSize.Height);
560 XplatUI.CalculateWindowRect(IntPtr.Zero, ref client_rect, CreateParams.Style, CreateParams.ExStyle, IntPtr.Zero, out bounds);
561 if ((CreateParams.Style & (int)WindowStyles.WS_CHILD) == 0) {
567 public Control(Control parent, string text) : this() {
572 public Control(Control parent, string text, int left, int top, int width, int height) : this() {
577 bounds.Height=height;
578 SetBoundsCore(left, top, width, height, BoundsSpecified.All);
582 public Control(string text) : this() {
586 public Control(string text, int left, int top, int width, int height) : this() {
590 bounds.Height=height;
591 SetBoundsCore(left, top, width, height, BoundsSpecified.All);
595 protected override void Dispose(bool disposing) {
608 controls.Remove(this);
610 #endregion // Public Constructors
612 #region Internal Properties
613 internal BorderStyle InternalBorderStyle {
619 if (border_style != value) {
620 border_style = value;
622 XplatUI.SetBorderStyle(window.Handle, border_style);
626 #endregion // Internal Properties
628 #region Private & Internal Methods
629 internal static IAsyncResult BeginInvokeInternal (Delegate method, object [] args) {
630 AsyncMethodResult result = new AsyncMethodResult ();
631 AsyncMethodData data = new AsyncMethodData ();
633 data.Method = method;
635 data.Result = new WeakReference (result);
638 if (!ExecutionContext.IsFlowSuppressed ()) {
639 data.Context = ExecutionContext.Capture ();
642 if (SecurityManager.SecurityEnabled) {
643 data.Stack = CompressedStack.GetCompressedStack ();
647 XplatUI.SendAsyncMethod (data);
651 internal Graphics DeviceContext {
654 CreateBuffers(this.Width, this.Height);
660 private Bitmap ImageBuffer {
663 CreateBuffers(this.Width, this.Height);
669 internal void CreateBuffers (int width, int height) {
670 if (dc_mem != null) {
684 bmp_mem = new Bitmap (width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
685 dc_mem = Graphics.FromImage (bmp_mem);
689 internal void InvalidateBuffers ()
691 if (dc_mem != null) {
702 internal static void SetChildColor(Control parent) {
705 for (int i=0; i < parent.child_controls.Count; i++) {
706 child=parent.child_controls[i];
707 if (child.IsHandleCreated) {
708 XplatUI.SetWindowBackground(child.window.Handle, child.BackColor);
710 if (child.child_controls.Count>0) {
711 SetChildColor(child);
717 internal bool Select(Control control) {
719 IContainerControl container;
721 if (control == null) {
725 parent = control.parent;
727 if (((control.control_style & ControlStyles.Selectable) !=0) && (parent != null)) {
728 while (parent != null) {
729 if (!parent.Visible || !parent.is_enabled) {
732 parent = parent.parent;
736 control.is_selected = true;
738 XplatUI.SetFocus(control.window.Handle);
739 container = GetContainerControl();
740 if (container != null) {
741 container.ActiveControl = control;
746 internal virtual void DoDefaultAction() {
747 // Only here to be overriden by our actual controls; this is needed by the accessibility class
750 internal static int LowOrder (int param) {
751 return ((int)(short)(param & 0xffff));
754 internal static int HighOrder (int param) {
755 return ((int)(short)(param >> 16));
758 // This method exists so controls overriding OnPaintBackground can have default background painting done
759 internal void PaintControlBackground (PaintEventArgs pevent)
761 if (background_image != null)
762 pevent.Graphics.DrawImage (background_image, 0, 0);
765 internal void DndEnter (DragEventArgs e)
770 internal void DndOver (DragEventArgs e)
775 internal void DndDrop (DragEventArgs e)
780 internal void DndLeave (DragEventArgs e)
785 internal static MouseButtons FromParamToMouseButtons (int param) {
786 MouseButtons buttons = MouseButtons.None;
788 if ((param & (int) MsgButtons.MK_LBUTTON) != 0)
789 buttons |= MouseButtons.Left;
791 if ((param & (int) MsgButtons.MK_MBUTTON) != 0)
792 buttons |= MouseButtons.Middle;
794 if ((param & (int) MsgButtons.MK_RBUTTON) != 0)
795 buttons |= MouseButtons.Right;
801 internal virtual bool ProcessControlMnemonic(char charCode) {
802 return ProcessMnemonic(charCode);
805 private static Control FindFlatForward(Control container, Control start) {
811 end = container.child_controls.Count;
814 index = start.tab_index;
819 for (int i = 0; i < end; i++) {
821 if (container.child_controls[i].tab_index > index) {
822 found = container.child_controls[i];
824 } else if (found.tab_index > container.child_controls[i].tab_index) {
825 if (container.child_controls[i].tab_index > index) {
826 found = container.child_controls[i];
833 private static Control FindControlForward(Control container, Control start) {
840 if ((start is IContainerControl) || start.GetStyle(ControlStyles.ContainerControl)) {
841 found = FindControlForward(start, null);
848 while (p != container) {
849 found = FindFlatForward(p, start);
857 return FindFlatForward(container, start);
860 private static Control FindFlatBackward(Control container, Control start) {
866 end = container.child_controls.Count;
869 index = start.tab_index;
871 // FIXME: Possible speed-up: Keep the highest taborder index in the container
873 for (int i = 0; i < end; i++) {
874 if (container.child_controls[i].tab_index > index) {
875 index = container.child_controls[i].tab_index;
881 for (int i = 0; i < end; i++) {
883 if (container.child_controls[i].tab_index < index) {
884 found = container.child_controls[i];
886 } else if (found.tab_index < container.child_controls[i].tab_index) {
887 if (container.child_controls[i].tab_index < index) {
888 found = container.child_controls[i];
895 private static Control FindControlBackward(Control container, Control start) {
901 found = FindFlatBackward(start.parent, start);
902 if (found == null && start.parent != container) {
907 found = FindFlatBackward(container, start);
910 while ((found != null) && ((found is IContainerControl) || found.GetStyle(ControlStyles.ContainerControl))) {
911 found = FindControlBackward(found, null);
920 private void HandleClick(int clicks) {
921 if (GetStyle(ControlStyles.StandardClick)) {
923 if (GetStyle(ControlStyles.StandardDoubleClick)) {
924 OnDoubleClick(EventArgs.Empty);
926 OnClick(EventArgs.Empty);
929 OnClick(EventArgs.Empty);
934 private void CheckDataBindings ()
936 if (data_bindings == null)
939 BindingContext binding_context = BindingContext;
940 foreach (Binding binding in data_bindings) {
941 binding.Check (binding_context);
945 #endregion // Private & Internal Methods
947 #region Public Static Properties
948 public static Color DefaultBackColor {
950 return ThemeEngine.Current.DefaultControlBackColor;
954 public static Font DefaultFont {
956 return ThemeEngine.Current.DefaultFont;
960 public static Color DefaultForeColor {
962 return ThemeEngine.Current.DefaultControlForeColor;
966 public static Keys ModifierKeys {
968 return XplatUI.State.ModifierKeys;
972 public static MouseButtons MouseButtons {
974 return XplatUI.State.MouseButtons;
978 public static Point MousePosition {
980 return Cursor.Position;
983 #endregion // Public Static Properties
985 #region Public Instance Properties
986 [EditorBrowsable(EditorBrowsableState.Advanced)]
988 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
989 public AccessibleObject AccessibilityObject {
991 if (accessibility_object==null) {
992 accessibility_object=CreateAccessibilityInstance();
994 return accessibility_object;
998 [EditorBrowsable(EditorBrowsableState.Advanced)]
1000 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1001 public string AccessibleDefaultActionDescription {
1003 return AccessibilityObject.default_action;
1007 AccessibilityObject.default_action=value;
1012 [DefaultValue(null)]
1013 public string AccessibleDescription {
1015 return AccessibilityObject.description;
1019 AccessibilityObject.description=value;
1024 [DefaultValue(null)]
1025 public string AccessibleName {
1027 return AccessibilityObject.Name;
1031 AccessibilityObject.Name=value;
1035 [DefaultValue(AccessibleRole.Default)]
1036 public AccessibleRole AccessibleRole {
1038 return AccessibilityObject.role;
1042 AccessibilityObject.role=value;
1046 [DefaultValue(false)]
1047 public virtual bool AllowDrop {
1053 if (allow_drop == value)
1056 XplatUI.SetAllowDrop (Handle, value);
1061 [RefreshProperties(RefreshProperties.Repaint)]
1062 [DefaultValue(AnchorStyles.Top | AnchorStyles.Left)]
1063 public virtual AnchorStyles Anchor {
1065 return anchor_style;
1071 if (parent != null) {
1072 parent.PerformLayout(this, "Parent");
1078 public virtual Color BackColor {
1080 if (background_color.IsEmpty) {
1082 return parent.BackColor;
1084 return DefaultBackColor;
1086 return background_color;
1090 background_color=value;
1091 if (this.IsHandleCreated) {
1092 XplatUI.SetWindowBackground(this.window.Handle, value);
1094 SetChildColor(this);
1095 OnBackColorChanged(EventArgs.Empty);
1101 [DefaultValue(null)]
1102 public virtual Image BackgroundImage {
1104 return background_image;
1108 if (background_image!=value) {
1109 background_image=value;
1110 OnBackgroundImageChanged(EventArgs.Empty);
1115 [EditorBrowsable(EditorBrowsableState.Advanced)]
1117 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1118 public virtual BindingContext BindingContext {
1120 if (binding_context != null)
1121 return binding_context;
1124 binding_context = Parent.BindingContext;
1125 return binding_context;
1128 if (binding_context != value) {
1129 binding_context = value;
1130 OnBindingContextChanged(EventArgs.Empty);
1135 [EditorBrowsable(EditorBrowsableState.Advanced)]
1137 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1140 return bounds.Y+bounds.Height;
1144 [EditorBrowsable(EditorBrowsableState.Advanced)]
1146 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1147 public Rectangle Bounds {
1153 SetBoundsCore(value.Left, value.Top, value.Width, value.Height, BoundsSpecified.All);
1157 [EditorBrowsable(EditorBrowsableState.Advanced)]
1159 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1160 public bool CanFocus {
1162 if (Visible && is_enabled && GetStyle(ControlStyles.Selectable)) {
1169 [EditorBrowsable(EditorBrowsableState.Advanced)]
1171 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1172 public bool CanSelect {
1176 if (!GetStyle(ControlStyles.Selectable) || this.parent == null) {
1180 parent = this.parent;
1181 while (parent != null) {
1182 if (!parent.is_visible || !parent.is_enabled) {
1186 parent = parent.parent;
1192 [EditorBrowsable(EditorBrowsableState.Advanced)]
1194 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1195 public bool Capture {
1197 return this.is_captured;
1201 if (this.IsHandleCreated) {
1202 if (value && !is_captured) {
1204 XplatUI.GrabWindow(this.window.Handle, IntPtr.Zero);
1205 } else if (!value && is_captured) {
1206 XplatUI.UngrabWindow(this.window.Handle);
1207 is_captured = false;
1213 [DefaultValue(true)]
1214 public bool CausesValidation {
1216 return this.causes_validation;
1220 if (this.causes_validation != value) {
1221 causes_validation = value;
1222 OnCausesValidationChanged(EventArgs.Empty);
1227 [EditorBrowsable(EditorBrowsableState.Advanced)]
1229 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1230 public Rectangle ClientRectangle {
1232 client_rect.Width = client_size.Width;
1233 client_rect.Height = client_size.Height;
1238 [EditorBrowsable(EditorBrowsableState.Advanced)]
1240 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1241 public Size ClientSize {
1244 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1245 return ((Form)this).form_parent_window.ClientSize;
1253 this.SetClientSizeCore(value.Width, value.Height);
1257 [EditorBrowsable(EditorBrowsableState.Advanced)]
1259 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1260 [DescriptionAttribute("ControlCompanyNameDescr")]
1261 public String CompanyName {
1263 return "Mono Project, Novell, Inc.";
1267 [EditorBrowsable(EditorBrowsableState.Advanced)]
1269 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1270 public bool ContainsFocus {
1276 for (int i=0; i < child_controls.Count; i++) {
1277 if (child_controls[i].ContainsFocus) {
1285 [DefaultValue(null)]
1286 public virtual ContextMenu ContextMenu {
1288 return context_menu;
1292 if (context_menu != value) {
1293 context_menu = value;
1294 OnContextMenuChanged(EventArgs.Empty);
1300 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
1301 public ControlCollection Controls {
1303 return this.child_controls;
1307 [EditorBrowsable(EditorBrowsableState.Advanced)]
1309 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1310 public bool Created {
1312 if (!this.is_disposed && (this.window.Handle != IntPtr.Zero)) {
1319 [AmbientValue(null)]
1320 public virtual Cursor Cursor {
1322 if (cursor != null) {
1326 if (parent != null) {
1327 return parent.Cursor;
1330 return Cursors.Default;
1334 if (cursor != value) {
1339 pt = Cursor.Position;
1340 if (bounds.Contains(pt)) {
1341 if (GetChildAtPoint(pt) == null) {
1342 if (cursor != null) {
1343 XplatUI.SetCursor(window.Handle, cursor.handle);
1345 if (parent != null) {
1346 XplatUI.SetCursor(window.Handle, parent.Cursor.handle);
1348 XplatUI.SetCursor(window.Handle, Cursors.def.handle);
1354 OnCursorChanged(EventArgs.Empty);
1360 [EditorBrowsable(EditorBrowsableState.Advanced)]
1362 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1363 public ControlBindingsCollection DataBindings {
1365 if (data_bindings == null)
1366 data_bindings = new ControlBindingsCollection (this);
1367 return data_bindings;
1371 [EditorBrowsable(EditorBrowsableState.Advanced)]
1373 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1374 public virtual Rectangle DisplayRectangle {
1376 return ClientRectangle;
1380 [EditorBrowsable(EditorBrowsableState.Advanced)]
1382 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1383 public bool Disposing {
1390 [RefreshProperties(RefreshProperties.Repaint)]
1391 [DefaultValue(DockStyle.None)]
1392 public virtual DockStyle Dock {
1398 if (dock_style == value) {
1404 if (parent != null) {
1405 parent.PerformLayout(this, "Parent");
1408 OnDockChanged(EventArgs.Empty);
1414 public bool Enabled {
1420 if (is_enabled == value) {
1426 OnEnabledChanged (EventArgs.Empty);
1430 [EditorBrowsable(EditorBrowsableState.Advanced)]
1432 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1433 public virtual bool Focused {
1435 return this.has_focus;
1440 [AmbientValue(null)]
1442 public virtual Font Font {
1448 if (Parent != null && Parent.Font != null) {
1456 if (font != null && font.Equals (value)) {
1462 OnFontChanged (EventArgs.Empty);
1467 public virtual Color ForeColor {
1469 if (foreground_color.IsEmpty) {
1471 return parent.ForeColor;
1473 return DefaultForeColor;
1475 return foreground_color;
1479 if (foreground_color != value) {
1480 foreground_color=value;
1482 OnForeColorChanged(EventArgs.Empty);
1489 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1490 public IntPtr Handle { // IWin32Window
1492 if (!IsHandleCreated) {
1495 return window.Handle;
1499 [EditorBrowsable(EditorBrowsableState.Advanced)]
1501 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1502 public bool HasChildren {
1504 if (this.child_controls.Count>0) {
1511 [EditorBrowsable(EditorBrowsableState.Always)]
1513 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1516 return this.bounds.Height;
1520 SetBoundsCore(bounds.X, bounds.Y, bounds.Width, value, BoundsSpecified.Height);
1524 [AmbientValue(ImeMode.Inherit)]
1526 public ImeMode ImeMode {
1532 if (ime_mode != value) {
1535 OnImeModeChanged(EventArgs.Empty);
1540 [EditorBrowsable(EditorBrowsableState.Advanced)]
1542 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1543 public bool InvokeRequired { // ISynchronizeInvoke
1545 if (creator_thread!=Thread.CurrentThread) {
1552 [EditorBrowsable(EditorBrowsableState.Advanced)]
1554 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1555 public bool IsAccessible {
1557 return is_accessible;
1561 is_accessible = value;
1565 [EditorBrowsable(EditorBrowsableState.Advanced)]
1567 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1568 public bool IsDisposed {
1570 return this.is_disposed;
1574 [EditorBrowsable(EditorBrowsableState.Advanced)]
1576 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1577 public bool IsHandleCreated {
1579 if ((window!=null) && (window.Handle!=IntPtr.Zero)) {
1587 [EditorBrowsable(EditorBrowsableState.Always)]
1589 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1592 return this.bounds.X;
1596 SetBoundsCore(value, bounds.Y, bounds.Width, bounds.Height, BoundsSpecified.X);
1601 public Point Location {
1603 return new Point(bounds.X, bounds.Y);
1607 SetBoundsCore(value.X, value.Y, bounds.Width, bounds.Height, BoundsSpecified.Location);
1612 public string Name {
1623 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1624 public Control Parent {
1630 if (value == this) {
1631 throw new ArgumentException("A circular control reference has been made. A control cannot be owned or parented to itself.");
1634 if (parent!=value) {
1636 parent.Controls.Remove(this);
1642 if (!parent.Controls.Contains(this)) {
1643 parent.Controls.Add(this);
1646 XplatUI.SetParent(Handle, value.Handle);
1650 OnParentChanged(EventArgs.Empty);
1655 [EditorBrowsable(EditorBrowsableState.Advanced)]
1657 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1658 public string ProductName {
1660 Type t = typeof (AssemblyProductAttribute);
1661 Assembly assembly = GetType().Module.Assembly;
1662 object [] attrs = assembly.GetCustomAttributes (t, false);
1663 AssemblyProductAttribute a = null;
1664 // On MS we get a NullRefException if product attribute is not
1666 if (attrs != null && attrs.Length > 0)
1667 a = (AssemblyProductAttribute) attrs [0];
1672 [EditorBrowsable(EditorBrowsableState.Advanced)]
1674 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1675 public string ProductVersion {
1677 Type t = typeof (AssemblyVersionAttribute);
1678 Assembly assembly = GetType().Module.Assembly;
1679 object [] attrs = assembly.GetCustomAttributes (t, false);
1680 if (attrs == null || attrs.Length < 1)
1682 return ((AssemblyVersionAttribute)attrs [0]).Version;
1686 [EditorBrowsable(EditorBrowsableState.Advanced)]
1688 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1689 public bool RecreatingHandle {
1691 return is_recreating;
1695 [EditorBrowsable(EditorBrowsableState.Advanced)]
1697 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1698 public Region Region {
1700 return new Region(this.bounds);
1707 g = this.CreateGraphics();
1708 r = value.GetBounds(g);
1710 SetBounds((int)r.X, (int)r.Y, (int)r.Width, (int)r.Height);
1716 [EditorBrowsable(EditorBrowsableState.Advanced)]
1718 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1721 return this.bounds.X+this.bounds.Width;
1725 [AmbientValue(RightToLeft.Inherit)]
1727 public virtual RightToLeft RightToLeft {
1729 return right_to_left;
1733 if (value != right_to_left) {
1734 right_to_left = value;
1735 OnRightToLeftChanged(EventArgs.Empty);
1740 [EditorBrowsable(EditorBrowsableState.Advanced)]
1741 public override ISite Site {
1754 return new Size(Width, Height);
1758 SetBoundsCore(bounds.X, bounds.Y, value.Width, value.Height, BoundsSpecified.Size);
1763 [MergableProperty(false)]
1764 public int TabIndex {
1766 if (tab_index != -1) {
1773 if (tab_index != value) {
1775 OnTabIndexChanged(EventArgs.Empty);
1781 [DefaultValue(true)]
1782 public bool TabStop {
1788 if (tab_stop != value) {
1790 OnTabStopChanged(EventArgs.Empty);
1795 [Localizable(false)]
1797 [TypeConverter(typeof(StringConverter))]
1798 [DefaultValue(null)]
1805 control_tag = value;
1811 [BindableAttribute(true)]
1812 public virtual string Text {
1818 if (value == null) {
1819 value = String.Empty;
1824 XplatUI.Text(Handle, text);
1825 // FIXME: Do we need a Refresh() here?
1826 OnTextChanged (EventArgs.Empty);
1831 [EditorBrowsable(EditorBrowsableState.Always)]
1833 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1836 return this.bounds.Y;
1840 SetBoundsCore(bounds.X, value, bounds.Width, bounds.Height, BoundsSpecified.Y);
1844 [EditorBrowsable(EditorBrowsableState.Advanced)]
1846 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1847 public Control TopLevelControl {
1851 while (p.parent != null) {
1860 public bool Visible {
1864 } else if (parent != null) {
1865 return parent.Visible;
1872 SetVisibleCore(value);
1876 [EditorBrowsable(EditorBrowsableState.Always)]
1878 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1881 return this.bounds.Width;
1885 SetBoundsCore(bounds.X, bounds.Y, value, bounds.Height, BoundsSpecified.Width);
1889 [EditorBrowsable(EditorBrowsableState.Never)]
1891 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1892 public IWindowTarget WindowTarget {
1901 #endregion // Public Instance Properties
1903 #region Protected Instance Properties
1904 protected virtual CreateParams CreateParams {
1906 CreateParams create_params = new CreateParams();
1908 create_params.Caption = Text;
1909 create_params.X = Left;
1910 create_params.Y = Top;
1911 create_params.Width = Width;
1912 create_params.Height = Height;
1914 create_params.ClassName = XplatUI.DefaultClassName;
1915 create_params.ClassStyle = 0;
1916 create_params.ExStyle = 0;
1917 create_params.Param = 0;
1920 create_params.Parent = parent.Handle;
1923 create_params.Style = (int)WindowStyles.WS_CHILD | (int)WindowStyles.WS_CLIPCHILDREN | (int)WindowStyles.WS_CLIPSIBLINGS;
1926 create_params.Style |= (int)WindowStyles.WS_VISIBLE;
1929 return create_params;
1933 protected virtual ImeMode DefaultImeMode {
1935 return ImeMode.Inherit;
1939 protected virtual Size DefaultSize {
1941 return new Size(100, 23);
1945 protected int FontHeight {
1955 protected bool RenderRightToLeft {
1957 return (this.right_to_left == RightToLeft.Yes);
1961 protected bool ResizeRedraw {
1963 return GetStyle(ControlStyles.ResizeRedraw);
1967 SetStyle(ControlStyles.ResizeRedraw, value);
1971 [EditorBrowsable(EditorBrowsableState.Advanced)]
1973 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1974 protected virtual bool ShowFocusCues {
1980 [EditorBrowsable(EditorBrowsableState.Advanced)]
1982 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1983 protected bool ShowKeyboardCues {
1988 #endregion // Protected Instance Properties
1990 #region Public Static Methods
1991 [EditorBrowsable(EditorBrowsableState.Advanced)]
1992 public static Control FromChildHandle(IntPtr handle) {
1993 IEnumerator control = Control.controls.GetEnumerator();
1995 while (control.MoveNext()) {
1996 if (((Control)control.Current).window.Handle == handle) {
1998 if (((Control)control.Current).Parent != null) {
1999 return ((Control)control.Current).Parent;
2006 [EditorBrowsable(EditorBrowsableState.Advanced)]
2007 public static Control FromHandle(IntPtr handle) {
2008 IEnumerator control = Control.controls.GetEnumerator();
2010 while (control.MoveNext()) {
2011 if (((Control)control.Current).window.Handle == handle) {
2013 return ((Control)control.Current);
2019 public static bool IsMnemonic(char charCode, string text) {
2022 amp = text.IndexOf('&');
2025 if (amp + 1 < text.Length) {
2026 if (text[amp + 1] != '&') {
2027 if (Char.ToUpper(charCode) == Char.ToUpper(text.ToCharArray(amp + 1, 1)[0])) {
2037 #region Protected Static Methods
2038 [EditorBrowsable(EditorBrowsableState.Advanced)]
2039 protected static bool ReflectMessage(IntPtr hWnd, ref Message m) {
2042 c = Control.FromHandle(hWnd);
2052 #region Public Instance Methods
2053 [EditorBrowsable(EditorBrowsableState.Advanced)]
2054 public IAsyncResult BeginInvoke(Delegate method) {
2055 return BeginInvokeInternal(method, null);
2058 [EditorBrowsable(EditorBrowsableState.Advanced)]
2059 public IAsyncResult BeginInvoke (Delegate method, object[] args) {
2060 return BeginInvokeInternal (method, args);
2063 public void BringToFront() {
2064 if ((parent != null) && (parent.child_controls[0]!=this)) {
2065 if (parent.child_controls.Contains(this)) {
2066 parent.child_controls.SetChildIndex(this, 0);
2070 XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, true, false);
2072 if (parent != null) {
2077 public bool Contains(Control ctl) {
2078 while (ctl != null) {
2087 public void CreateControl() {
2089 if (!IsHandleCreated) {
2093 if (!create_handled) {
2094 create_handled = true;
2098 for (int i=0; i<child_controls.Count; i++) {
2099 child_controls[i].CreateControl();
2103 public Graphics CreateGraphics() {
2104 if (!IsHandleCreated) {
2105 this.CreateControl();
2107 return Graphics.FromHwnd(this.window.Handle);
2110 [MonoTODO("Come up with cross platform drag-drop driver interface")]
2111 public DragDropEffects DoDragDrop(object data, DragDropEffects allowedEffects) {
2112 return DragDropEffects.None;
2115 [EditorBrowsable(EditorBrowsableState.Advanced)]
2116 public object EndInvoke (IAsyncResult async_result) {
2117 AsyncMethodResult result = (AsyncMethodResult) async_result;
2118 return result.EndInvoke ();
2121 public Form FindForm() {
2134 public bool Focus() {
2135 if (IsHandleCreated && !has_focus) {
2137 XplatUI.SetFocus(window.Handle);
2142 public Control GetChildAtPoint(Point pt) {
2143 // Microsoft's version of this function doesn't seem to work, so I can't check
2144 // if we only consider children or also grandchildren, etc.
2145 // I'm gonna say 'children only'
2146 for (int i=0; i<child_controls.Count; i++) {
2147 if (child_controls[i].Bounds.Contains(pt)) {
2148 return child_controls[i];
2154 public IContainerControl GetContainerControl() {
2155 Control current = this;
2157 while (current!=null) {
2158 if ((current is IContainerControl) && ((current.control_style & ControlStyles.ContainerControl)!=0)) {
2159 return (IContainerControl)current;
2161 current = current.parent;
2166 public Control GetNextControl(Control ctl, bool forward) {
2167 // If we're not a container we don't play
2168 if (!(this is IContainerControl) && !this.GetStyle(ControlStyles.ContainerControl)) {
2172 // If ctl is not contained by this, we start at the first child of this
2173 if (!this.Contains(ctl)) {
2177 // Search through our controls, starting at ctl, stepping into children as we encounter them
2178 // try to find the control with the tabindex closest to our own, or, if we're looking into
2179 // child controls, the one with the smallest tabindex
2181 return FindControlForward(this, ctl);
2183 return FindControlBackward(this, ctl);
2186 public void Hide() {
2187 this.Visible = false;
2190 public void Invalidate() {
2191 Invalidate(ClientRectangle, false);
2194 public void Invalidate(bool invalidateChildren) {
2195 Invalidate(ClientRectangle, invalidateChildren);
2198 public void Invalidate(System.Drawing.Rectangle rc) {
2199 Invalidate(rc, false);
2202 public void Invalidate(System.Drawing.Rectangle rc, bool invalidateChildren) {
2203 if (!IsHandleCreated || !Visible) {
2207 NotifyInvalidate(rc);
2209 XplatUI.Invalidate(Handle, rc, false);
2211 if (invalidateChildren) {
2212 for (int i=0; i<child_controls.Count; i++) child_controls[i].Invalidate();
2214 OnInvalidated(new InvalidateEventArgs(rc));
2217 public void Invalidate(System.Drawing.Region region) {
2218 Invalidate(region, false);
2221 [MonoTODO("Figure out if GetRegionScans is usable")]
2222 public void Invalidate(System.Drawing.Region region, bool invalidateChildren) {
2223 throw new NotImplementedException();
2225 // FIXME - should use the GetRegionScans function of the region to invalidate each area
2226 //if (invalidateChildren) {
2227 // for (int i=0; i<child_controls.Count; i++) child_controls[i].Invalidate();
2231 public object Invoke (Delegate method) {
2232 return Invoke(method, null);
2235 public object Invoke (Delegate method, object[] args) {
2236 if (!this.InvokeRequired) {
2237 return method.DynamicInvoke(args);
2240 IAsyncResult result = BeginInvoke (method, args);
2241 return EndInvoke(result);
2244 [EditorBrowsable(EditorBrowsableState.Advanced)]
2245 public void PerformLayout() {
2246 PerformLayout(null, null);
2249 [EditorBrowsable(EditorBrowsableState.Advanced)]
2250 public void PerformLayout(Control affectedControl, string affectedProperty) {
2251 LayoutEventArgs levent = new LayoutEventArgs(affectedControl, affectedProperty);
2253 if (layout_suspended>0) {
2254 layout_pending = true;
2258 layout_pending = false;
2260 // Prevent us from getting messed up
2263 // Perform all Dock and Anchor calculations
2266 AnchorStyles anchor;
2271 space=this.DisplayRectangle;
2272 if (prev_size != Size.Empty) {
2273 diff_width = space.Width - prev_size.Width;
2274 diff_height = space.Height - prev_size.Height;
2280 // Deal with docking; go through in reverse, MS docs say that lowest Z-order is closest to edge
2281 for (int i = child_controls.Count - 1; i >= 0; i--) {
2282 child=child_controls[i];
2283 switch (child.Dock) {
2284 case DockStyle.None: {
2289 case DockStyle.Left: {
2290 child.SetBounds(space.Left, space.Y, child.Width, space.Height);
2291 space.X+=child.Width;
2292 space.Width-=child.Width;
2296 case DockStyle.Top: {
2297 child.SetBounds(space.Left, space.Y, space.Width, child.Height);
2298 space.Y+=child.Height;
2299 space.Height-=child.Height;
2303 case DockStyle.Right: {
2304 child.SetBounds(space.Right-child.Width, space.Y, child.Width, space.Height);
2305 space.Width-=child.Width;
2309 case DockStyle.Bottom: {
2310 child.SetBounds(space.Left, space.Bottom-child.Height, space.Width, child.Height);
2311 space.Height-=child.Height;
2317 for (int i = child_controls.Count - 1; i >= 0; i--) {
2318 child=child_controls[i];
2320 if (child.Dock == DockStyle.Fill) {
2321 child.SetBounds(space.Left, space.Top, space.Width, space.Height);
2327 space=this.DisplayRectangle;
2329 // Deal with anchoring
2330 for (int i=0; i < child_controls.Count; i++) {
2336 child=child_controls[i];
2337 anchor=child.Anchor;
2342 height=child.Height;
2344 // If the control is docked we don't need to do anything
2345 if (child.Dock != DockStyle.None) {
2349 if ((anchor & AnchorStyles.Left) !=0 ) {
2350 if ((anchor & AnchorStyles.Right) != 0) {
2351 // Anchoring to left and right
2352 width=width+diff_width;
2356 } else if ((anchor & AnchorStyles.Right) != 0) {
2362 if ((anchor & AnchorStyles.Top) !=0 ) {
2363 if ((anchor & AnchorStyles.Bottom) != 0) {
2364 height+=diff_height;
2368 } else if ((anchor & AnchorStyles.Bottom) != 0) {
2383 child.SetBounds(left, top, width, height);
2386 // Let everyone know
2390 // Need to make sure we decremend layout_suspended
2396 public Point PointToClient (Point p) {
2400 XplatUI.ScreenToClient (Handle, ref x, ref y);
2402 return new Point (x, y);
2405 public Point PointToScreen(Point p) {
2409 XplatUI.ClientToScreen(Handle, ref x, ref y);
2411 return new Point(x, y);
2414 public virtual bool PreProcessMessage(ref Message msg) {
2417 if ((msg.Msg == (int)Msg.WM_KEYDOWN) || (msg.Msg == (int)Msg.WM_SYSKEYDOWN)) {
2418 key_data = (Keys)msg.WParam.ToInt32();
2419 if (!ProcessCmdKey(ref msg, key_data)) {
2420 if (IsInputKey(key_data)) {
2424 return ProcessDialogKey(key_data);
2428 } else if (msg.Msg == (int)Msg.WM_CHAR) {
2429 if (IsInputChar((char)msg.WParam)) {
2432 } else if (msg.Msg == (int)Msg.WM_SYSCHAR) {
2433 if (IsInputChar((char)msg.WParam)) {
2436 return ProcessDialogChar((char)msg.WParam);
2441 public Rectangle RectangleToClient(Rectangle r) {
2442 return new Rectangle(PointToClient(r.Location), r.Size);
2445 public Rectangle RectangleToScreen(Rectangle r) {
2446 return new Rectangle(PointToScreen(r.Location), r.Size);
2449 public virtual void Refresh() {
2450 if (IsHandleCreated == true) {
2452 XplatUI.UpdateWindow(window.Handle);
2456 [EditorBrowsable(EditorBrowsableState.Never)]
2457 public virtual void ResetBackColor() {
2458 background_color = Color.Empty;
2461 #if haveDataBindings
2462 [EditorBrowsable(EditorBrowsableState.Never)]
2464 public void ResetBindings() {
2469 [EditorBrowsable(EditorBrowsableState.Never)]
2470 public virtual void ResetCursor() {
2474 [EditorBrowsable(EditorBrowsableState.Never)]
2475 public virtual void ResetFont() {
2479 [EditorBrowsable(EditorBrowsableState.Never)]
2480 public virtual void ResetForeColor() {
2481 foreground_color = Color.Empty;
2484 [EditorBrowsable(EditorBrowsableState.Never)]
2485 public void ResetImeMode() {
2486 ime_mode = DefaultImeMode;
2489 [EditorBrowsable(EditorBrowsableState.Never)]
2490 public virtual void ResetRightToLeft() {
2491 right_to_left = RightToLeft.Inherit;
2494 public virtual void ResetText() {
2498 public void ResumeLayout() {
2499 ResumeLayout (true);
2502 public void ResumeLayout(bool performLayout) {
2505 if (layout_suspended > 0) {
2509 if (performLayout || layout_pending) {
2514 public void Scale(float ratio) {
2515 ScaleCore(ratio, ratio);
2518 public void Scale(float dx, float dy) {
2522 public void Select() {
2523 Select(false, false);
2526 public bool SelectNextControl(Control ctl, bool forward, bool tabStopOnly, bool nested, bool wrap) {
2531 c = GetNextControl(c, forward);
2540 if (c.CanSelect && ((c.parent == ctl.parent) || nested) && (c.tab_stop || !tabStopOnly)) {
2544 } while (c != ctl); // If we wrap back to ourselves we stop
2549 public void SendToBack() {
2550 if ((parent != null) && (parent.child_controls[parent.child_controls.Count-1]!=this)) {
2551 if (parent.child_controls.Contains(this)) {
2552 parent.child_controls.SetChildIndex(this, parent.child_controls.Count);
2556 XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, false, true);
2557 if (parent != null) {
2562 public void SetBounds(int x, int y, int width, int height) {
2563 SetBoundsCore(x, y, width, height, BoundsSpecified.All);
2566 public void SetBounds(int x, int y, int width, int height, BoundsSpecified specified) {
2567 SetBoundsCore(x, y, width, height, specified);
2570 public void Show() {
2571 if (!IsHandleCreated) {
2572 this.CreateControl();
2578 public void SuspendLayout() {
2582 public void Update() {
2583 needs_redraw = true;
2584 XplatUI.UpdateWindow(window.Handle);
2586 #endregion // Public Instance Methods
2588 #region Protected Instance Methods
2589 [EditorBrowsable(EditorBrowsableState.Advanced)]
2590 [MonoTODO("Implement this and tie it into Control.ControlAccessibleObject.NotifyClients")]
2591 protected void AccessibilityNotifyClients(AccessibleEvents accEvent, int childID) {
2592 throw new NotImplementedException();
2595 [EditorBrowsable(EditorBrowsableState.Advanced)]
2596 protected virtual AccessibleObject CreateAccessibilityInstance() {
2597 return new Control.ControlAccessibleObject(this);
2600 [EditorBrowsable(EditorBrowsableState.Advanced)]
2601 protected virtual ControlCollection CreateControlsInstance() {
2602 return new ControlCollection(this);
2605 [EditorBrowsable(EditorBrowsableState.Advanced)]
2606 protected virtual void CreateHandle() {
2608 throw new ObjectDisposedException(Name);
2611 if (IsHandleCreated) {
2615 window.CreateHandle(CreateParams);
2617 // Find out where the window manager placed us
2621 if (window.Handle!=IntPtr.Zero) {
2622 if (!controls.Contains(window.Handle)) {
2626 creator_thread = Thread.CurrentThread;
2628 XplatUI.SetWindowBackground(window.Handle, this.BackColor);
2630 OnHandleCreated(EventArgs.Empty);
2634 [EditorBrowsable(EditorBrowsableState.Advanced)]
2635 protected virtual void DefWndProc(ref Message m) {
2636 window.DefWndProc(ref m);
2639 [EditorBrowsable(EditorBrowsableState.Advanced)]
2640 protected virtual void DestroyHandle() {
2641 if (IsHandleCreated) {
2642 // Destroy our children before we destroy ourselves, to prevent them from
2643 // being implictly (without us knowing) destroyed
2644 for (int i=0; i < child_controls.Count; i++) {
2645 child_controls[i].DestroyHandle();
2649 if (window != null) {
2650 window.DestroyHandle();
2652 OnHandleDestroyed(EventArgs.Empty);
2656 protected bool GetStyle(ControlStyles flag) {
2657 return (control_style & flag) != 0;
2660 protected bool GetTopLevel() {
2664 [EditorBrowsable(EditorBrowsableState.Advanced)]
2665 protected virtual void InitLayout() {
2666 if (parent != null) {
2667 parent.PerformLayout(this, "parent");
2671 [EditorBrowsable(EditorBrowsableState.Advanced)]
2672 protected void InvokeGotFocus(Control toInvoke, EventArgs e) {
2673 toInvoke.OnGotFocus(e);
2676 [EditorBrowsable(EditorBrowsableState.Advanced)]
2677 protected void InvokeLostFocus(Control toInvoke, EventArgs e) {
2678 toInvoke.OnLostFocus(e);
2681 [EditorBrowsable(EditorBrowsableState.Advanced)]
2682 protected void InvokeOnClick(Control toInvoke, EventArgs e) {
2683 toInvoke.OnClick(e);
2686 protected void InvokePaint(Control toInvoke, PaintEventArgs e) {
2687 toInvoke.OnPaint(e);
2690 protected void InvokePaintBackground(Control toInvoke, PaintEventArgs e) {
2691 toInvoke.OnPaintBackground(e);
2694 protected virtual bool IsInputChar (char charCode) {
2695 if (parent != null) {
2696 return parent.IsInputChar(charCode);
2702 protected virtual bool IsInputKey (Keys keyData) {
2703 // Doc says this one calls IsInputChar; not sure what to do with that
2707 [EditorBrowsable(EditorBrowsableState.Advanced)]
2708 protected virtual void NotifyInvalidate(Rectangle invalidatedArea) {
2712 protected virtual bool ProcessCmdKey(ref Message msg, Keys keyData) {
2713 if ((context_menu != null) && context_menu.ProcessCmdKey(ref msg, keyData)) {
2717 if (parent != null) {
2718 return parent.ProcessCmdKey(ref msg, keyData);
2724 protected virtual bool ProcessDialogChar(char charCode) {
2725 if (parent != null) {
2726 return parent.ProcessDialogChar (charCode);
2732 protected virtual bool ProcessDialogKey (Keys keyData) {
2733 if (parent != null) {
2734 return parent.ProcessDialogKey (keyData);
2740 protected virtual bool ProcessKeyEventArgs (ref Message msg)
2742 KeyEventArgs key_event;
2745 case (int)Msg.WM_KEYDOWN: {
2746 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
2747 OnKeyDown (key_event);
2748 return key_event.Handled;
2750 case (int)Msg.WM_KEYUP: {
2751 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
2752 OnKeyUp (key_event);
2753 return key_event.Handled;
2756 case (int)Msg.WM_CHAR: {
2757 KeyPressEventArgs key_press_event;
2759 key_press_event = new KeyPressEventArgs((char)msg.WParam);
2760 OnKeyPress(key_press_event);
2761 return key_press_event.Handled;
2772 protected internal virtual bool ProcessKeyMessage(ref Message msg) {
2773 if (parent != null) {
2774 if (parent.ProcessKeyPreview(ref msg)) {
2782 protected virtual bool ProcessKeyPreview(ref Message msg) {
2783 if (parent != null) {
2784 return parent.ProcessKeyPreview(ref msg);
2790 protected virtual bool ProcessMnemonic(char charCode) {
2795 [EditorBrowsable(EditorBrowsableState.Advanced)]
2796 protected void RaiseDragEvent(object key, DragEventArgs e) {
2800 [EditorBrowsable(EditorBrowsableState.Advanced)]
2801 protected void RaiseKeyEvent(object key, KeyEventArgs e) {
2805 [EditorBrowsable(EditorBrowsableState.Advanced)]
2806 protected void RaiseMouseEvent(object key, MouseEventArgs e) {
2810 [EditorBrowsable(EditorBrowsableState.Advanced)]
2811 protected void RaisePaintEvent(object key, PaintEventArgs e) {
2815 [EditorBrowsable(EditorBrowsableState.Advanced)]
2816 protected void RecreateHandle() {
2817 IEnumerator child = child_controls.GetEnumerator();
2821 if (IsHandleCreated) {
2827 while (child.MoveNext()) {
2828 ((Control)child.Current).RecreateHandle();
2834 is_recreating = false;
2837 [EditorBrowsable(EditorBrowsableState.Advanced)]
2838 protected void ResetMouseEventArgs() {
2842 [EditorBrowsable(EditorBrowsableState.Advanced)]
2843 protected ContentAlignment RtlTranslateAlignment(ContentAlignment align) {
2844 if (right_to_left == RightToLeft.No) {
2849 case ContentAlignment.TopLeft: {
2850 return ContentAlignment.TopRight;
2853 case ContentAlignment.TopRight: {
2854 return ContentAlignment.TopLeft;
2857 case ContentAlignment.MiddleLeft: {
2858 return ContentAlignment.MiddleRight;
2861 case ContentAlignment.MiddleRight: {
2862 return ContentAlignment.MiddleLeft;
2865 case ContentAlignment.BottomLeft: {
2866 return ContentAlignment.BottomRight;
2869 case ContentAlignment.BottomRight: {
2870 return ContentAlignment.BottomLeft;
2874 // if it's center it doesn't change
2880 [EditorBrowsable(EditorBrowsableState.Advanced)]
2881 protected HorizontalAlignment RtlTranslateAlignment(HorizontalAlignment align) {
2882 if ((right_to_left == RightToLeft.No) || (align == HorizontalAlignment.Center)) {
2886 if (align == HorizontalAlignment.Left) {
2887 return HorizontalAlignment.Right;
2890 // align must be HorizontalAlignment.Right
2891 return HorizontalAlignment.Left;
2894 [EditorBrowsable(EditorBrowsableState.Advanced)]
2895 protected LeftRightAlignment RtlTranslateAlignment(LeftRightAlignment align) {
2896 if (right_to_left == RightToLeft.No) {
2900 if (align == LeftRightAlignment.Left) {
2901 return LeftRightAlignment.Right;
2904 // align must be LeftRightAlignment.Right;
2905 return LeftRightAlignment.Left;
2908 [EditorBrowsable(EditorBrowsableState.Advanced)]
2909 protected ContentAlignment RtlTranslateContent(ContentAlignment align) {
2910 return RtlTranslateAlignment(align);
2913 [EditorBrowsable(EditorBrowsableState.Advanced)]
2914 protected HorizontalAlignment RtlTranslateHorizontal(HorizontalAlignment align) {
2915 return RtlTranslateAlignment(align);
2918 [EditorBrowsable(EditorBrowsableState.Advanced)]
2919 protected LeftRightAlignment RtlTranslateLeftRight(LeftRightAlignment align) {
2920 return RtlTranslateAlignment(align);
2923 [EditorBrowsable(EditorBrowsableState.Advanced)]
2924 protected virtual void ScaleCore(float dx, float dy) {
2930 location = new Point((int)(Left * dx), (int)(Top * dy));
2931 size = this.ClientSize;
2934 if (!GetStyle(ControlStyles.FixedWidth)) {
2935 size.Width = (int)(size.Width * dx);
2938 if (!GetStyle(ControlStyles.FixedHeight)) {
2939 size.Height = (int)(size.Height * dy);
2942 Location = location;
2945 /* Now scale our children */
2946 for (int i=0; i < child_controls.Count; i++) {
2947 child_controls[i].Scale(dx, dy);
2953 protected virtual void Select(bool directed, bool forward) {
2958 // Select this control
2963 if (parent == null) {
2967 // FIXME - this thing is doing the wrong stuff, needs to be similar to SelectNextControl
2969 index = parent.child_controls.IndexOf(this);
2974 if ((index+1) < parent.child_controls.Count) {
2983 index = parent.child_controls.Count-1;
2986 result = Select(parent.child_controls[index]);
2987 } while (!result && parent.child_controls[index] != this);
2990 [EditorBrowsable(EditorBrowsableState.Advanced)]
2991 protected virtual void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
2992 // SetBoundsCore updates the Win32 control itself. UpdateBounds updates the controls variables and fires events, I'm guessing - pdb
2993 if ((specified & BoundsSpecified.X) != BoundsSpecified.X) {
2997 if ((specified & BoundsSpecified.Y) != BoundsSpecified.Y) {
3001 if ((specified & BoundsSpecified.Width) != BoundsSpecified.Width) {
3005 if ((specified & BoundsSpecified.Height) != BoundsSpecified.Height) {
3009 if (IsHandleCreated) {
3010 XplatUI.SetWindowPos(Handle, x, y, width, height);
3012 UpdateBounds(x, y, width, height);
3015 [EditorBrowsable(EditorBrowsableState.Advanced)]
3016 protected virtual void SetClientSizeCore(int x, int y) {
3017 // Calculate the actual window size from the client size (it usually stays the same or grows)
3018 Rectangle ClientRect;
3019 Rectangle WindowRect;
3022 ClientRect = new Rectangle(0, 0, x, y);
3023 cp = this.CreateParams;
3025 if (XplatUI.CalculateWindowRect(Handle, ref ClientRect, cp.Style, cp.ExStyle, IntPtr.Zero, out WindowRect)==false) {
3029 SetBoundsCore(bounds.X, bounds.Y, WindowRect.Width, WindowRect.Height, BoundsSpecified.Size);
3032 [EditorBrowsable(EditorBrowsableState.Advanced)]
3033 protected void SetStyle(ControlStyles flag, bool value) {
3035 control_style |= flag;
3037 control_style &= ~flag;
3039 OnStyleChanged(EventArgs.Empty);
3042 protected void SetTopLevel(bool value) {
3043 if ((GetTopLevel() != value) && (parent != null)) {
3044 throw new Exception();
3048 if (value == true) {
3058 is_toplevel = value;
3061 protected virtual void SetVisibleCore(bool value) {
3062 if (value!=is_visible) {
3064 XplatUI.SetVisible(Handle, value);
3065 // Explicitly move Toplevel windows to where we want them;
3066 // apparently moving unmapped toplevel windows doesn't work
3067 if (is_visible && (this is Form)) {
3068 XplatUI.SetWindowPos(window.Handle, bounds.X, bounds.Y, bounds.Width, bounds.Height);
3070 OnVisibleChanged(EventArgs.Empty);
3073 if (dc_mem != null) {
3078 if (bmp_mem != null) {
3083 this.CreateBuffers(bounds.Width, bounds.Height);
3088 if (value == false && parent != null) {
3091 // Need to start at parent, GetContainerControl might return ourselves if we're a container
3092 container = (Control)parent.GetContainerControl();
3093 if (container != null) {
3094 container.SelectNextControl(this, true, true, true, true);
3098 if (parent != null) {
3099 parent.PerformLayout(this, "visible");
3101 PerformLayout(this, "visible");
3106 [EditorBrowsable(EditorBrowsableState.Advanced)]
3107 protected void UpdateBounds() {
3115 if (!IsHandleCreated) {
3119 XplatUI.GetWindowPos(this.Handle, this is Form, out x, out y, out width, out height, out client_width, out client_height);
3121 UpdateBounds(x, y, width, height, client_width, client_height);
3124 [EditorBrowsable(EditorBrowsableState.Advanced)]
3125 protected void UpdateBounds(int x, int y, int width, int height) {
3126 // UpdateBounds only seems to set our sizes and fire events but not update the GUI window to match
3128 bool resized = false;
3130 int client_x_diff = this.bounds.Width-this.client_size.Width;
3131 int client_y_diff = this.bounds.Height-this.client_size.Height;
3133 // Needed to generate required notifications
3134 if ((this.bounds.X!=x) || (this.bounds.Y!=y)) {
3138 if ((this.Bounds.Width!=width) || (this.Bounds.Height!=height)) {
3145 bounds.Height=height;
3147 // Update client rectangle as well
3148 if (this.layout_suspended==0) {
3149 prev_size.Width=client_size.Width;
3150 prev_size.Height=client_size.Height;
3153 client_size.Width=width-client_x_diff;
3154 client_size.Height=height-client_y_diff;
3157 OnLocationChanged(EventArgs.Empty);
3161 OnSizeChanged(EventArgs.Empty);
3165 [EditorBrowsable(EditorBrowsableState.Advanced)]
3166 protected void UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) {
3167 UpdateBounds(x, y, width, height);
3169 this.client_size.Width=clientWidth;
3170 this.client_size.Height=clientHeight;
3173 [EditorBrowsable(EditorBrowsableState.Advanced)]
3174 protected void UpdateStyles() {
3175 if (!IsHandleCreated) {
3179 XplatUI.SetWindowStyle(window.Handle, CreateParams);
3182 [EditorBrowsable(EditorBrowsableState.Advanced)]
3183 protected void UpdateZOrder() {
3188 if (parent == null) {
3194 children = ctl.child_controls.Count;
3195 for (int i = 1; i < children; i++ ) {
3196 XplatUI.SetZOrder(ctl.child_controls[i].window.Handle, ctl.child_controls[i-1].window.Handle, false, false);
3199 children = child_controls.Count;
3200 for (int i = 1; i < children; i++ ) {
3201 XplatUI.SetZOrder(child_controls[i].window.Handle, child_controls[i-1].window.Handle, false, false);
3206 protected virtual void WndProc(ref Message m) {
3208 Console.WriteLine("Control received message {0}", (Msg)m.Msg);
3210 if ((this.control_style & ControlStyles.EnableNotifyMessage) != 0) {
3214 switch((Msg)m.Msg) {
3215 case Msg.WM_WINDOWPOSCHANGED: {
3218 if (GetStyle(ControlStyles.ResizeRedraw)) {
3225 case Msg.WM_PAINT: {
3226 PaintEventArgs paint_event;
3228 paint_event = XplatUI.PaintEventStart(Handle);
3230 if (!needs_redraw) {
3231 // Just blit the previous image
3232 paint_event.Graphics.DrawImage (ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle, GraphicsUnit.Pixel);
3233 XplatUI.PaintEventEnd(Handle);
3238 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
3239 dc = paint_event.SetGraphics (DeviceContext);
3242 if ((control_style & (ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint)) != (ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint)) {
3243 OnPaintBackground(paint_event);
3246 OnPaint(paint_event);
3248 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
3249 dc.DrawImage (ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle, GraphicsUnit.Pixel);
3250 paint_event.SetGraphics (dc);
3251 needs_redraw = false;
3254 XplatUI.PaintEventEnd(Handle);
3256 if (!GetStyle(ControlStyles.UserPaint)) {
3263 case Msg.WM_ERASEBKGND: {
3264 if (GetStyle (ControlStyles.UserPaint)) {
3265 if (!GetStyle(ControlStyles.AllPaintingInWmPaint)) {
3266 PaintEventArgs eraseEventArgs = new PaintEventArgs (m.WParam == IntPtr.Zero ? Graphics.FromHwnd (m.HWnd) :
3267 Graphics.FromHdc (m.WParam), new Rectangle (new Point (0,0),Size));
3268 OnPaintBackground (eraseEventArgs);
3271 XplatUI.EraseWindowBackground(m.HWnd, m.WParam);
3273 // The DefWndProc will never have to handle this, we don't ever set hbr on the window
3274 m.Result = (IntPtr)1;
3278 case Msg.WM_LBUTTONUP: {
3279 HandleClick(mouse_clicks);
3280 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Left,
3282 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3284 if (mouse_clicks > 1) {
3290 case Msg.WM_LBUTTONDOWN: {
3291 if (CanSelect && !is_selected) {
3294 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3295 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3301 case Msg.WM_LBUTTONDBLCLK: {
3303 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3304 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3310 case Msg.WM_MBUTTONUP: {
3311 HandleClick(mouse_clicks);
3312 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Middle,
3314 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3316 if (mouse_clicks > 1) {
3322 case Msg.WM_MBUTTONDOWN: {
3323 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3324 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3330 case Msg.WM_MBUTTONDBLCLK: {
3332 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3333 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3338 case Msg.WM_RBUTTONUP: {
3339 if (context_menu != null) {
3340 context_menu.Show(this, new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ())));
3343 HandleClick(mouse_clicks);
3344 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Right,
3346 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3348 if (mouse_clicks > 1) {
3354 case Msg.WM_RBUTTONDOWN: {
3355 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3356 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3361 case Msg.WM_RBUTTONDBLCLK: {
3363 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3364 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3369 case Msg.WM_MOUSEWHEEL: {
3371 OnMouseWheel (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3372 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3373 HighOrder(m.WParam.ToInt32())));
3378 case Msg.WM_MOUSEMOVE: {
3379 OnMouseMove (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3381 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3386 case Msg.WM_MOUSE_ENTER: {
3391 OnMouseEnter(EventArgs.Empty);
3395 case Msg.WM_MOUSE_LEAVE: {
3397 OnMouseLeave(EventArgs.Empty);
3401 case Msg.WM_MOUSEHOVER: {
3402 OnMouseHover(EventArgs.Empty);
3406 case Msg.WM_SYSKEYDOWN:
3407 case Msg.WM_KEYDOWN:
3408 case Msg.WM_SYSKEYUP:
3410 case Msg.WM_SYSCHAR:
3412 if (ProcessKeyEventArgs(ref m)) {
3416 if (PreProcessMessage(ref m)) {
3420 if (ProcessKeyMessage(ref m)) {
3429 if (m.LParam != IntPtr.Zero) {
3432 hi = new HELPINFO();
3434 hi = (HELPINFO) Marshal.PtrToStructure (m.LParam, typeof (HELPINFO));
3435 mouse_pos = new Point(hi.MousePos.x, hi.MousePos.y);
3437 mouse_pos = Control.MousePosition;
3439 OnHelpRequested(new HelpEventArgs(mouse_pos));
3440 m.Result = (IntPtr)1;
3444 case Msg.WM_KILLFOCUS: {
3445 OnLeave(EventArgs.Empty);
3446 if (CausesValidation) {
3448 e = new CancelEventArgs(false);
3457 OnValidated(EventArgs.Empty);
3460 this.has_focus = false;
3461 this.is_selected = false;
3462 OnLostFocus(EventArgs.Empty);
3466 case Msg.WM_SETFOCUS: {
3467 OnEnter(EventArgs.Empty);
3468 this.has_focus = true;
3469 OnGotFocus(EventArgs.Empty);
3474 case Msg.WM_SYSCOLORCHANGE: {
3475 ThemeEngine.Current.ResetDefaults();
3476 OnSystemColorsChanged(EventArgs.Empty);
3481 case Msg.WM_SETCURSOR: {
3482 if (cursor == null) {
3487 XplatUI.SetCursor(window.Handle, cursor.handle);
3488 m.Result = (IntPtr)1;
3498 #endregion // Public Instance Methods
3500 #region OnXXX methods
3501 [EditorBrowsable(EditorBrowsableState.Advanced)]
3502 protected virtual void OnBackColorChanged(EventArgs e) {
3503 if (BackColorChanged!=null) BackColorChanged(this, e);
3504 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackColorChanged(e);
3507 [EditorBrowsable(EditorBrowsableState.Advanced)]
3508 protected virtual void OnBackgroundImageChanged(EventArgs e) {
3509 if (BackgroundImageChanged!=null) BackgroundImageChanged(this, e);
3510 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackgroundImageChanged(e);
3513 [EditorBrowsable(EditorBrowsableState.Advanced)]
3514 protected virtual void OnBindingContextChanged(EventArgs e) {
3515 CheckDataBindings ();
3516 if (BindingContextChanged!=null) {
3517 BindingContextChanged(this, e);
3519 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBindingContextChanged(e);
3522 [EditorBrowsable(EditorBrowsableState.Advanced)]
3523 protected virtual void OnCausesValidationChanged(EventArgs e) {
3524 if (CausesValidationChanged!=null) CausesValidationChanged(this, e);
3527 [EditorBrowsable(EditorBrowsableState.Advanced)]
3528 protected virtual void OnChangeUICues(UICuesEventArgs e) {
3529 if (ChangeUICues!=null) ChangeUICues(this, e);
3532 [EditorBrowsable(EditorBrowsableState.Advanced)]
3533 protected virtual void OnClick(EventArgs e) {
3534 if (Click!=null) Click(this, e);
3537 [EditorBrowsable(EditorBrowsableState.Advanced)]
3538 protected virtual void OnContextMenuChanged(EventArgs e) {
3539 if (ContextMenuChanged!=null) ContextMenuChanged(this, e);
3542 [EditorBrowsable(EditorBrowsableState.Advanced)]
3543 protected virtual void OnControlAdded(ControlEventArgs e) {
3544 if (ControlAdded!=null) ControlAdded(this, e);
3547 [EditorBrowsable(EditorBrowsableState.Advanced)]
3548 protected virtual void OnControlRemoved(ControlEventArgs e) {
3549 if (ControlRemoved!=null) ControlRemoved(this, e);
3552 [EditorBrowsable(EditorBrowsableState.Advanced)]
3553 protected virtual void OnCreateControl() {
3557 [EditorBrowsable(EditorBrowsableState.Advanced)]
3558 protected virtual void OnCursorChanged(EventArgs e) {
3559 if (CursorChanged!=null) CursorChanged(this, e);
3562 [EditorBrowsable(EditorBrowsableState.Advanced)]
3563 protected virtual void OnDockChanged(EventArgs e) {
3564 if (DockChanged!=null) DockChanged(this, e);
3567 [EditorBrowsable(EditorBrowsableState.Advanced)]
3568 protected virtual void OnDoubleClick(EventArgs e) {
3569 if (DoubleClick!=null) DoubleClick(this, e);
3572 [EditorBrowsable(EditorBrowsableState.Advanced)]
3573 protected virtual void OnDragDrop(DragEventArgs drgevent) {
3574 if (DragDrop!=null) DragDrop(this, drgevent);
3577 [EditorBrowsable(EditorBrowsableState.Advanced)]
3578 protected virtual void OnDragEnter(DragEventArgs drgevent) {
3579 if (DragEnter!=null) DragEnter(this, drgevent);
3582 [EditorBrowsable(EditorBrowsableState.Advanced)]
3583 protected virtual void OnDragLeave(EventArgs e) {
3584 if (DragLeave!=null) DragLeave(this, e);
3587 [EditorBrowsable(EditorBrowsableState.Advanced)]
3588 protected virtual void OnDragOver(DragEventArgs drgevent) {
3589 if (DragOver!=null) DragOver(this, drgevent);
3592 [EditorBrowsable(EditorBrowsableState.Advanced)]
3593 protected virtual void OnEnabledChanged(EventArgs e) {
3594 if (EnabledChanged!=null) EnabledChanged(this, e);
3595 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentEnabledChanged(e);
3598 [EditorBrowsable(EditorBrowsableState.Advanced)]
3599 protected virtual void OnEnter(EventArgs e) {
3600 if (Enter!=null) Enter(this, e);
3603 [EditorBrowsable(EditorBrowsableState.Advanced)]
3604 protected virtual void OnFontChanged(EventArgs e) {
3605 if (FontChanged!=null) FontChanged(this, e);
3606 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentFontChanged(e);
3609 [EditorBrowsable(EditorBrowsableState.Advanced)]
3610 protected virtual void OnForeColorChanged(EventArgs e) {
3611 if (ForeColorChanged!=null) ForeColorChanged(this, e);
3612 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentForeColorChanged(e);
3615 [EditorBrowsable(EditorBrowsableState.Advanced)]
3616 protected virtual void OnGiveFeedback(GiveFeedbackEventArgs gfbevent) {
3617 if (GiveFeedback!=null) GiveFeedback(this, gfbevent);
3620 [EditorBrowsable(EditorBrowsableState.Advanced)]
3621 protected virtual void OnGotFocus(EventArgs e) {
3622 if (GotFocus!=null) GotFocus(this, e);
3625 [EditorBrowsable(EditorBrowsableState.Advanced)]
3626 protected virtual void OnHandleCreated(EventArgs e) {
3627 if (HandleCreated!=null) HandleCreated(this, e);
3630 [EditorBrowsable(EditorBrowsableState.Advanced)]
3631 protected virtual void OnHandleDestroyed(EventArgs e) {
3632 if (HandleDestroyed!=null) HandleDestroyed(this, e);
3635 [EditorBrowsable(EditorBrowsableState.Advanced)]
3636 protected virtual void OnHelpRequested(HelpEventArgs hevent) {
3637 if (HelpRequested!=null) HelpRequested(this, hevent);
3640 protected virtual void OnImeModeChanged(EventArgs e) {
3641 if (ImeModeChanged!=null) ImeModeChanged(this, e);
3644 [EditorBrowsable(EditorBrowsableState.Advanced)]
3645 protected virtual void OnInvalidated(InvalidateEventArgs e) {
3646 needs_redraw = true;
3647 if (Invalidated!=null) Invalidated(this, e);
3650 [EditorBrowsable(EditorBrowsableState.Advanced)]
3651 protected virtual void OnKeyDown(KeyEventArgs e) {
3652 if (KeyDown!=null) KeyDown(this, e);
3655 [EditorBrowsable(EditorBrowsableState.Advanced)]
3656 protected virtual void OnKeyPress(KeyPressEventArgs e) {
3657 if (KeyPress!=null) KeyPress(this, e);
3660 [EditorBrowsable(EditorBrowsableState.Advanced)]
3661 protected virtual void OnKeyUp(KeyEventArgs e) {
3662 if (KeyUp!=null) KeyUp(this, e);
3665 [EditorBrowsable(EditorBrowsableState.Advanced)]
3666 protected virtual void OnLayout(LayoutEventArgs levent) {
3667 if (Layout!=null) Layout(this, levent);
3670 [EditorBrowsable(EditorBrowsableState.Advanced)]
3671 protected virtual void OnLeave(EventArgs e) {
3672 if (Leave!=null) Leave(this, e);
3675 [EditorBrowsable(EditorBrowsableState.Advanced)]
3676 protected virtual void OnLocationChanged(EventArgs e) {
3678 if (LocationChanged!=null) LocationChanged(this, e);
3681 [EditorBrowsable(EditorBrowsableState.Advanced)]
3682 protected virtual void OnLostFocus(EventArgs e) {
3683 if (LostFocus!=null) LostFocus(this, e);
3686 [EditorBrowsable(EditorBrowsableState.Advanced)]
3687 protected virtual void OnMouseDown(MouseEventArgs e) {
3688 if (MouseDown!=null) MouseDown(this, e);
3691 [EditorBrowsable(EditorBrowsableState.Advanced)]
3692 protected virtual void OnMouseEnter(EventArgs e) {
3693 if (MouseEnter!=null) MouseEnter(this, e);
3696 [EditorBrowsable(EditorBrowsableState.Advanced)]
3697 protected virtual void OnMouseHover(EventArgs e) {
3698 if (MouseHover!=null) MouseHover(this, e);
3701 [EditorBrowsable(EditorBrowsableState.Advanced)]
3702 protected virtual void OnMouseLeave(EventArgs e) {
3703 if (MouseLeave!=null) MouseLeave(this, e);
3706 [EditorBrowsable(EditorBrowsableState.Advanced)]
3707 protected virtual void OnMouseMove(MouseEventArgs e) {
3708 if (MouseMove!=null) MouseMove(this, e);
3711 [EditorBrowsable(EditorBrowsableState.Advanced)]
3712 protected virtual void OnMouseUp(MouseEventArgs e) {
3713 if (MouseUp!=null) MouseUp(this, e);
3716 [EditorBrowsable(EditorBrowsableState.Advanced)]
3717 protected virtual void OnMouseWheel(MouseEventArgs e) {
3718 if (MouseWheel!=null) MouseWheel(this, e);
3721 [EditorBrowsable(EditorBrowsableState.Advanced)]
3722 protected virtual void OnMove(EventArgs e) {
3723 if (Move!=null) Move(this, e);
3726 [EditorBrowsable(EditorBrowsableState.Advanced)]
3727 protected virtual void OnNotifyMessage(Message m) {
3731 [EditorBrowsable(EditorBrowsableState.Advanced)]
3732 protected virtual void OnPaint(PaintEventArgs e) {
3733 if (Paint!=null) Paint(this, e);
3736 [EditorBrowsable(EditorBrowsableState.Advanced)]
3737 protected virtual void OnPaintBackground(PaintEventArgs pevent) {
3738 PaintControlBackground (pevent);
3741 [EditorBrowsable(EditorBrowsableState.Advanced)]
3742 protected virtual void OnParentBackColorChanged(EventArgs e) {
3743 if (background_color.IsEmpty && background_image==null) {
3745 OnBackColorChanged(e);
3749 [EditorBrowsable(EditorBrowsableState.Advanced)]
3750 protected virtual void OnParentBackgroundImageChanged(EventArgs e) {
3751 if (background_color.IsEmpty && background_image==null) {
3753 OnBackgroundImageChanged(e);
3757 [EditorBrowsable(EditorBrowsableState.Advanced)]
3758 protected virtual void OnParentBindingContextChanged(EventArgs e) {
3759 if (binding_context==null) {
3760 binding_context=Parent.binding_context;
3761 OnBindingContextChanged(e);
3765 [EditorBrowsable(EditorBrowsableState.Advanced)]
3766 protected virtual void OnParentChanged(EventArgs e) {
3767 if (ParentChanged!=null) ParentChanged(this, e);
3770 [EditorBrowsable(EditorBrowsableState.Advanced)]
3771 protected virtual void OnParentEnabledChanged(EventArgs e) {
3772 if (is_enabled != Parent.is_enabled) {
3773 is_enabled=Parent.is_enabled;
3775 if (EnabledChanged != null) {
3776 EnabledChanged(this, e);
3781 [EditorBrowsable(EditorBrowsableState.Advanced)]
3782 protected virtual void OnParentFontChanged(EventArgs e) {
3789 [EditorBrowsable(EditorBrowsableState.Advanced)]
3790 protected virtual void OnParentForeColorChanged(EventArgs e) {
3791 if (foreground_color.IsEmpty) {
3793 OnForeColorChanged(e);
3797 [EditorBrowsable(EditorBrowsableState.Advanced)]
3798 protected virtual void OnParentRightToLeftChanged(EventArgs e) {
3799 if (right_to_left==RightToLeft.Inherit) {
3801 OnRightToLeftChanged(e);
3805 [EditorBrowsable(EditorBrowsableState.Advanced)]
3806 protected virtual void OnParentVisibleChanged(EventArgs e) {
3808 OnVisibleChanged(e);
3812 [EditorBrowsable(EditorBrowsableState.Advanced)]
3813 protected virtual void OnQueryContinueDrag(QueryContinueDragEventArgs e) {
3814 if (QueryContinueDrag!=null) QueryContinueDrag(this, e);
3817 [EditorBrowsable(EditorBrowsableState.Advanced)]
3818 protected virtual void OnResize(EventArgs e) {
3819 if (Resize!=null) Resize(this, e);
3821 PerformLayout(this, "bounds");
3823 if (parent != null) {
3824 parent.PerformLayout();
3828 [EditorBrowsable(EditorBrowsableState.Advanced)]
3829 protected virtual void OnRightToLeftChanged(EventArgs e) {
3830 if (RightToLeftChanged!=null) RightToLeftChanged(this, e);
3831 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentRightToLeftChanged(e);
3834 [EditorBrowsable(EditorBrowsableState.Advanced)]
3835 protected virtual void OnSizeChanged(EventArgs e) {
3836 InvalidateBuffers ();
3838 if (SizeChanged!=null) SizeChanged(this, e);
3841 [EditorBrowsable(EditorBrowsableState.Advanced)]
3842 protected virtual void OnStyleChanged(EventArgs e) {
3843 if (StyleChanged!=null) StyleChanged(this, e);
3846 [EditorBrowsable(EditorBrowsableState.Advanced)]
3847 protected virtual void OnSystemColorsChanged(EventArgs e) {
3848 if (SystemColorsChanged!=null) SystemColorsChanged(this, e);
3851 [EditorBrowsable(EditorBrowsableState.Advanced)]
3852 protected virtual void OnTabIndexChanged(EventArgs e) {
3853 if (TabIndexChanged!=null) TabIndexChanged(this, e);
3856 [EditorBrowsable(EditorBrowsableState.Advanced)]
3857 protected virtual void OnTabStopChanged(EventArgs e) {
3858 if (TabStopChanged!=null) TabStopChanged(this, e);
3861 [EditorBrowsable(EditorBrowsableState.Advanced)]
3862 protected virtual void OnTextChanged(EventArgs e) {
3863 if (TextChanged!=null) TextChanged(this, e);
3866 [EditorBrowsable(EditorBrowsableState.Advanced)]
3867 protected virtual void OnValidated(EventArgs e) {
3868 if (Validated!=null) Validated(this, e);
3871 [EditorBrowsable(EditorBrowsableState.Advanced)]
3872 protected virtual void OnValidating(System.ComponentModel.CancelEventArgs e) {
3873 if (Validating!=null) Validating(this, e);
3876 [EditorBrowsable(EditorBrowsableState.Advanced)]
3877 protected virtual void OnVisibleChanged(EventArgs e) {
3884 if (bmp_mem!=null) {
3890 if (!this.IsHandleCreated) {
3891 this.CreateControl();
3897 if (VisibleChanged!=null) VisibleChanged(this, e);
3899 // We need to tell our kids
3900 for (int i=0; i<child_controls.Count; i++) {
3901 child_controls[i].OnParentVisibleChanged(e);
3904 #endregion // OnXXX methods
3907 public event EventHandler BackColorChanged;
3908 public event EventHandler BackgroundImageChanged;
3909 public event EventHandler BindingContextChanged;
3910 public event EventHandler CausesValidationChanged;
3911 public event UICuesEventHandler ChangeUICues;
3912 public event EventHandler Click;
3913 public event EventHandler ContextMenuChanged;
3915 [EditorBrowsable(EditorBrowsableState.Advanced)]
3917 public event ControlEventHandler ControlAdded;
3919 [EditorBrowsable(EditorBrowsableState.Advanced)]
3921 public event ControlEventHandler ControlRemoved;
3923 public event EventHandler CursorChanged;
3924 public event EventHandler DockChanged;
3925 public event EventHandler DoubleClick;
3926 public event DragEventHandler DragDrop;
3927 public event DragEventHandler DragEnter;
3928 public event EventHandler DragLeave;
3929 public event DragEventHandler DragOver;
3930 public event EventHandler EnabledChanged;
3931 public event EventHandler Enter;
3932 public event EventHandler FontChanged;
3933 public event EventHandler ForeColorChanged;
3934 public event GiveFeedbackEventHandler GiveFeedback;
3936 [EditorBrowsable(EditorBrowsableState.Advanced)]
3938 public event EventHandler GotFocus;
3940 [EditorBrowsable(EditorBrowsableState.Advanced)]
3942 public event EventHandler HandleCreated;
3944 [EditorBrowsable(EditorBrowsableState.Advanced)]
3946 public event EventHandler HandleDestroyed;
3948 public event HelpEventHandler HelpRequested;
3949 public event EventHandler ImeModeChanged;
3951 [EditorBrowsable(EditorBrowsableState.Advanced)]
3953 public event InvalidateEventHandler Invalidated;
3955 public event KeyEventHandler KeyDown;
3956 public event KeyPressEventHandler KeyPress;
3957 public event KeyEventHandler KeyUp;
3958 public event LayoutEventHandler Layout;
3959 public event EventHandler Leave;
3960 public event EventHandler LocationChanged;
3962 [EditorBrowsable(EditorBrowsableState.Advanced)]
3964 public event EventHandler LostFocus;
3966 public event MouseEventHandler MouseDown;
3967 public event EventHandler MouseEnter;
3968 public event EventHandler MouseHover;
3969 public event EventHandler MouseLeave;
3970 public event MouseEventHandler MouseMove;
3971 public event MouseEventHandler MouseUp;
3973 [EditorBrowsable(EditorBrowsableState.Advanced)]
3975 public event MouseEventHandler MouseWheel;
3977 public event EventHandler Move;
3978 public event PaintEventHandler Paint;
3979 public event EventHandler ParentChanged;
3980 public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp;
3981 public event QueryContinueDragEventHandler QueryContinueDrag;
3982 public event EventHandler Resize;
3983 public event EventHandler RightToLeftChanged;
3984 public event EventHandler SizeChanged;
3985 public event EventHandler StyleChanged;
3986 public event EventHandler SystemColorsChanged;
3987 public event EventHandler TabIndexChanged;
3988 public event EventHandler TabStopChanged;
3989 public event EventHandler TextChanged;
3990 public event EventHandler Validated;
3991 public event CancelEventHandler Validating;
3992 public event EventHandler VisibleChanged;
3993 #endregion // Events