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 (EventArgs 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)
1057 XplatUI.SetAllowDrop (Handle, value);
1062 [RefreshProperties(RefreshProperties.Repaint)]
1063 [DefaultValue(AnchorStyles.Top | AnchorStyles.Left)]
1064 public virtual AnchorStyles Anchor {
1066 return anchor_style;
1072 if (parent != null) {
1073 parent.PerformLayout(this, "Parent");
1079 public virtual Color BackColor {
1081 if (background_color.IsEmpty) {
1083 return parent.BackColor;
1085 return DefaultBackColor;
1087 return background_color;
1091 background_color=value;
1092 if (this.IsHandleCreated) {
1093 XplatUI.SetWindowBackground(this.window.Handle, value);
1095 SetChildColor(this);
1096 OnBackColorChanged(EventArgs.Empty);
1102 [DefaultValue(null)]
1103 public virtual Image BackgroundImage {
1105 return background_image;
1109 if (background_image!=value) {
1110 background_image=value;
1111 OnBackgroundImageChanged(EventArgs.Empty);
1116 [EditorBrowsable(EditorBrowsableState.Advanced)]
1118 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1119 public virtual BindingContext BindingContext {
1121 if (binding_context != null)
1122 return binding_context;
1125 binding_context = Parent.BindingContext;
1126 return binding_context;
1129 if (binding_context != value) {
1130 binding_context = value;
1131 OnBindingContextChanged(EventArgs.Empty);
1136 [EditorBrowsable(EditorBrowsableState.Advanced)]
1138 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1141 return bounds.Y+bounds.Height;
1145 [EditorBrowsable(EditorBrowsableState.Advanced)]
1147 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1148 public Rectangle Bounds {
1154 SetBoundsCore(value.Left, value.Top, value.Width, value.Height, BoundsSpecified.All);
1158 [EditorBrowsable(EditorBrowsableState.Advanced)]
1160 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1161 public bool CanFocus {
1163 if (Visible && is_enabled && GetStyle(ControlStyles.Selectable)) {
1170 [EditorBrowsable(EditorBrowsableState.Advanced)]
1172 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1173 public bool CanSelect {
1177 if (!GetStyle(ControlStyles.Selectable) || this.parent == null) {
1181 parent = this.parent;
1182 while (parent != null) {
1183 if (!parent.is_visible || !parent.is_enabled) {
1187 parent = parent.parent;
1193 [EditorBrowsable(EditorBrowsableState.Advanced)]
1195 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1196 public bool Capture {
1198 return this.is_captured;
1202 if (this.IsHandleCreated) {
1203 if (value && !is_captured) {
1205 XplatUI.GrabWindow(this.window.Handle, IntPtr.Zero);
1206 } else if (!value && is_captured) {
1207 XplatUI.UngrabWindow(this.window.Handle);
1208 is_captured = false;
1214 [DefaultValue(true)]
1215 public bool CausesValidation {
1217 return this.causes_validation;
1221 if (this.causes_validation != value) {
1222 causes_validation = value;
1223 OnCausesValidationChanged(EventArgs.Empty);
1228 [EditorBrowsable(EditorBrowsableState.Advanced)]
1230 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1231 public Rectangle ClientRectangle {
1233 client_rect.Width = client_size.Width;
1234 client_rect.Height = client_size.Height;
1239 [EditorBrowsable(EditorBrowsableState.Advanced)]
1241 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1242 public Size ClientSize {
1245 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1246 return ((Form)this).form_parent_window.ClientSize;
1254 this.SetClientSizeCore(value.Width, value.Height);
1258 [EditorBrowsable(EditorBrowsableState.Advanced)]
1260 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1261 [DescriptionAttribute("ControlCompanyNameDescr")]
1262 public String CompanyName {
1264 return "Mono Project, Novell, Inc.";
1268 [EditorBrowsable(EditorBrowsableState.Advanced)]
1270 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1271 public bool ContainsFocus {
1277 for (int i=0; i < child_controls.Count; i++) {
1278 if (child_controls[i].ContainsFocus) {
1286 [DefaultValue(null)]
1287 public virtual ContextMenu ContextMenu {
1289 return context_menu;
1293 if (context_menu != value) {
1294 context_menu = value;
1295 OnContextMenuChanged(EventArgs.Empty);
1301 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
1302 public ControlCollection Controls {
1304 return this.child_controls;
1308 [EditorBrowsable(EditorBrowsableState.Advanced)]
1310 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1311 public bool Created {
1313 if (!this.is_disposed && (this.window.Handle != IntPtr.Zero)) {
1320 [AmbientValue(null)]
1321 public virtual Cursor Cursor {
1323 if (cursor != null) {
1327 if (parent != null) {
1328 return parent.Cursor;
1331 return Cursors.Default;
1335 if (cursor != value) {
1340 pt = Cursor.Position;
1341 if (bounds.Contains(pt)) {
1342 if (GetChildAtPoint(pt) == null) {
1343 if (cursor != null) {
1344 XplatUI.SetCursor(window.Handle, cursor.handle);
1346 if (parent != null) {
1347 XplatUI.SetCursor(window.Handle, parent.Cursor.handle);
1349 XplatUI.SetCursor(window.Handle, Cursors.def.handle);
1355 OnCursorChanged(EventArgs.Empty);
1361 [EditorBrowsable(EditorBrowsableState.Advanced)]
1363 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1364 public ControlBindingsCollection DataBindings {
1366 if (data_bindings == null)
1367 data_bindings = new ControlBindingsCollection (this);
1368 return data_bindings;
1372 [EditorBrowsable(EditorBrowsableState.Advanced)]
1374 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1375 public virtual Rectangle DisplayRectangle {
1377 return ClientRectangle;
1381 [EditorBrowsable(EditorBrowsableState.Advanced)]
1383 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1384 public bool Disposing {
1391 [RefreshProperties(RefreshProperties.Repaint)]
1392 [DefaultValue(DockStyle.None)]
1393 public virtual DockStyle Dock {
1399 if (dock_style == value) {
1405 if (parent != null) {
1406 parent.PerformLayout(this, "Parent");
1409 OnDockChanged(EventArgs.Empty);
1415 public bool Enabled {
1421 if (is_enabled == value) {
1427 OnEnabledChanged (EventArgs.Empty);
1431 [EditorBrowsable(EditorBrowsableState.Advanced)]
1433 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1434 public virtual bool Focused {
1436 return this.has_focus;
1441 [AmbientValue(null)]
1443 public virtual Font Font {
1449 if (Parent != null && Parent.Font != null) {
1457 if (font != null && font.Equals (value)) {
1463 OnFontChanged (EventArgs.Empty);
1468 public virtual Color ForeColor {
1470 if (foreground_color.IsEmpty) {
1472 return parent.ForeColor;
1474 return DefaultForeColor;
1476 return foreground_color;
1480 if (foreground_color != value) {
1481 foreground_color=value;
1483 OnForeColorChanged(EventArgs.Empty);
1490 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1491 public IntPtr Handle { // IWin32Window
1493 if (!IsHandleCreated) {
1496 return window.Handle;
1500 [EditorBrowsable(EditorBrowsableState.Advanced)]
1502 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1503 public bool HasChildren {
1505 if (this.child_controls.Count>0) {
1512 [EditorBrowsable(EditorBrowsableState.Always)]
1514 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1517 return this.bounds.Height;
1521 SetBoundsCore(bounds.X, bounds.Y, bounds.Width, value, BoundsSpecified.Height);
1525 [AmbientValue(ImeMode.Inherit)]
1527 public ImeMode ImeMode {
1533 if (ime_mode != value) {
1536 OnImeModeChanged(EventArgs.Empty);
1541 [EditorBrowsable(EditorBrowsableState.Advanced)]
1543 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1544 public bool InvokeRequired { // ISynchronizeInvoke
1546 if (creator_thread!=Thread.CurrentThread) {
1553 [EditorBrowsable(EditorBrowsableState.Advanced)]
1555 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1556 public bool IsAccessible {
1558 return is_accessible;
1562 is_accessible = value;
1566 [EditorBrowsable(EditorBrowsableState.Advanced)]
1568 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1569 public bool IsDisposed {
1571 return this.is_disposed;
1575 [EditorBrowsable(EditorBrowsableState.Advanced)]
1577 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1578 public bool IsHandleCreated {
1580 if ((window!=null) && (window.Handle!=IntPtr.Zero)) {
1588 [EditorBrowsable(EditorBrowsableState.Always)]
1590 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1593 return this.bounds.X;
1597 SetBoundsCore(value, bounds.Y, bounds.Width, bounds.Height, BoundsSpecified.X);
1602 public Point Location {
1604 return new Point(bounds.X, bounds.Y);
1608 SetBoundsCore(value.X, value.Y, bounds.Width, bounds.Height, BoundsSpecified.Location);
1613 public string Name {
1624 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1625 public Control Parent {
1631 if (value == this) {
1632 throw new ArgumentException("A circular control reference has been made. A control cannot be owned or parented to itself.");
1635 if (parent!=value) {
1637 parent.Controls.Remove(this);
1643 if (!parent.Controls.Contains(this)) {
1644 parent.Controls.Add(this);
1647 XplatUI.SetParent(Handle, value.Handle);
1651 OnParentChanged(EventArgs.Empty);
1656 [EditorBrowsable(EditorBrowsableState.Advanced)]
1658 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1659 public string ProductName {
1661 Type t = typeof (AssemblyProductAttribute);
1662 Assembly assembly = GetType().Module.Assembly;
1663 object [] attrs = assembly.GetCustomAttributes (t, false);
1664 AssemblyProductAttribute a = null;
1665 // On MS we get a NullRefException if product attribute is not
1667 if (attrs != null && attrs.Length > 0)
1668 a = (AssemblyProductAttribute) attrs [0];
1673 [EditorBrowsable(EditorBrowsableState.Advanced)]
1675 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1676 public string ProductVersion {
1678 Type t = typeof (AssemblyVersionAttribute);
1679 Assembly assembly = GetType().Module.Assembly;
1680 object [] attrs = assembly.GetCustomAttributes (t, false);
1681 if (attrs == null || attrs.Length < 1)
1683 return ((AssemblyVersionAttribute)attrs [0]).Version;
1687 [EditorBrowsable(EditorBrowsableState.Advanced)]
1689 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1690 public bool RecreatingHandle {
1692 return is_recreating;
1696 [EditorBrowsable(EditorBrowsableState.Advanced)]
1698 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1699 public Region Region {
1701 return new Region(this.bounds);
1708 g = this.CreateGraphics();
1709 r = value.GetBounds(g);
1711 SetBounds((int)r.X, (int)r.Y, (int)r.Width, (int)r.Height);
1717 [EditorBrowsable(EditorBrowsableState.Advanced)]
1719 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1722 return this.bounds.X+this.bounds.Width;
1726 [AmbientValue(RightToLeft.Inherit)]
1728 public virtual RightToLeft RightToLeft {
1730 return right_to_left;
1734 if (value != right_to_left) {
1735 right_to_left = value;
1736 OnRightToLeftChanged(EventArgs.Empty);
1741 [EditorBrowsable(EditorBrowsableState.Advanced)]
1742 public override ISite Site {
1755 return new Size(Width, Height);
1759 SetBoundsCore(bounds.X, bounds.Y, value.Width, value.Height, BoundsSpecified.Size);
1764 [MergableProperty(false)]
1765 public int TabIndex {
1767 if (tab_index != -1) {
1774 if (tab_index != value) {
1776 OnTabIndexChanged(EventArgs.Empty);
1782 [DefaultValue(true)]
1783 public bool TabStop {
1789 if (tab_stop != value) {
1791 OnTabStopChanged(EventArgs.Empty);
1796 [Localizable(false)]
1798 [TypeConverter(typeof(StringConverter))]
1799 [DefaultValue(null)]
1806 control_tag = value;
1812 [BindableAttribute(true)]
1813 public virtual string Text {
1819 if (value == null) {
1820 value = String.Empty;
1825 XplatUI.Text(Handle, text);
1826 // FIXME: Do we need a Refresh() here?
1827 OnTextChanged (EventArgs.Empty);
1832 [EditorBrowsable(EditorBrowsableState.Always)]
1834 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1837 return this.bounds.Y;
1841 SetBoundsCore(bounds.X, value, bounds.Width, bounds.Height, BoundsSpecified.Y);
1845 [EditorBrowsable(EditorBrowsableState.Advanced)]
1847 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1848 public Control TopLevelControl {
1852 while (p.parent != null) {
1861 public bool Visible {
1865 } else if (parent != null) {
1866 return parent.Visible;
1873 SetVisibleCore(value);
1877 [EditorBrowsable(EditorBrowsableState.Always)]
1879 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1882 return this.bounds.Width;
1886 SetBoundsCore(bounds.X, bounds.Y, value, bounds.Height, BoundsSpecified.Width);
1890 [EditorBrowsable(EditorBrowsableState.Never)]
1892 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1893 public IWindowTarget WindowTarget {
1902 #endregion // Public Instance Properties
1904 #region Protected Instance Properties
1905 protected virtual CreateParams CreateParams {
1907 CreateParams create_params = new CreateParams();
1909 create_params.Caption = Text;
1910 create_params.X = Left;
1911 create_params.Y = Top;
1912 create_params.Width = Width;
1913 create_params.Height = Height;
1915 create_params.ClassName = XplatUI.DefaultClassName;
1916 create_params.ClassStyle = 0;
1917 create_params.ExStyle = 0;
1918 create_params.Param = 0;
1921 create_params.ExStyle |= (int)WindowStyles.WS_EX_ACCEPTFILES;
1925 create_params.Parent = parent.Handle;
1928 create_params.Style = (int)WindowStyles.WS_CHILD | (int)WindowStyles.WS_CLIPCHILDREN | (int)WindowStyles.WS_CLIPSIBLINGS;
1931 create_params.Style |= (int)WindowStyles.WS_VISIBLE;
1934 return create_params;
1938 protected virtual ImeMode DefaultImeMode {
1940 return ImeMode.Inherit;
1944 protected virtual Size DefaultSize {
1946 return new Size(100, 23);
1950 protected int FontHeight {
1960 protected bool RenderRightToLeft {
1962 return (this.right_to_left == RightToLeft.Yes);
1966 protected bool ResizeRedraw {
1968 return GetStyle(ControlStyles.ResizeRedraw);
1972 SetStyle(ControlStyles.ResizeRedraw, value);
1976 [EditorBrowsable(EditorBrowsableState.Advanced)]
1978 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1979 protected virtual bool ShowFocusCues {
1985 [EditorBrowsable(EditorBrowsableState.Advanced)]
1987 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1988 protected bool ShowKeyboardCues {
1993 #endregion // Protected Instance Properties
1995 #region Public Static Methods
1996 [EditorBrowsable(EditorBrowsableState.Advanced)]
1997 public static Control FromChildHandle(IntPtr handle) {
1998 IEnumerator control = Control.controls.GetEnumerator();
2000 while (control.MoveNext()) {
2001 if (((Control)control.Current).window.Handle == handle) {
2003 if (((Control)control.Current).Parent != null) {
2004 return ((Control)control.Current).Parent;
2011 [EditorBrowsable(EditorBrowsableState.Advanced)]
2012 public static Control FromHandle(IntPtr handle) {
2013 IEnumerator control = Control.controls.GetEnumerator();
2015 while (control.MoveNext()) {
2016 if (((Control)control.Current).window.Handle == handle) {
2018 return ((Control)control.Current);
2024 public static bool IsMnemonic(char charCode, string text) {
2027 amp = text.IndexOf('&');
2030 if (amp + 1 < text.Length) {
2031 if (text[amp + 1] != '&') {
2032 if (Char.ToUpper(charCode) == Char.ToUpper(text.ToCharArray(amp + 1, 1)[0])) {
2042 #region Protected Static Methods
2043 [EditorBrowsable(EditorBrowsableState.Advanced)]
2044 protected static bool ReflectMessage(IntPtr hWnd, ref Message m) {
2047 c = Control.FromHandle(hWnd);
2057 #region Public Instance Methods
2058 [EditorBrowsable(EditorBrowsableState.Advanced)]
2059 public IAsyncResult BeginInvoke(Delegate method) {
2060 return BeginInvokeInternal(method, null);
2063 [EditorBrowsable(EditorBrowsableState.Advanced)]
2064 public IAsyncResult BeginInvoke (Delegate method, object[] args) {
2065 return BeginInvokeInternal (method, args);
2068 public void BringToFront() {
2069 if ((parent != null) && (parent.child_controls[0]!=this)) {
2070 if (parent.child_controls.Contains(this)) {
2071 parent.child_controls.SetChildIndex(this, 0);
2075 XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, true, false);
2077 if (parent != null) {
2082 public bool Contains(Control ctl) {
2083 while (ctl != null) {
2092 public void CreateControl() {
2094 if (!IsHandleCreated) {
2098 if (!create_handled) {
2099 create_handled = true;
2103 for (int i=0; i<child_controls.Count; i++) {
2104 child_controls[i].CreateControl();
2108 public Graphics CreateGraphics() {
2109 if (!IsHandleCreated) {
2110 this.CreateControl();
2112 return Graphics.FromHwnd(this.window.Handle);
2115 [MonoTODO("Come up with cross platform drag-drop driver interface")]
2116 public DragDropEffects DoDragDrop(object data, DragDropEffects allowedEffects) {
2117 return DragDropEffects.None;
2120 [EditorBrowsable(EditorBrowsableState.Advanced)]
2121 public object EndInvoke (IAsyncResult async_result) {
2122 AsyncMethodResult result = (AsyncMethodResult) async_result;
2123 return result.EndInvoke ();
2126 public Form FindForm() {
2139 public bool Focus() {
2140 if (IsHandleCreated && !has_focus) {
2142 XplatUI.SetFocus(window.Handle);
2147 public Control GetChildAtPoint(Point pt) {
2148 // Microsoft's version of this function doesn't seem to work, so I can't check
2149 // if we only consider children or also grandchildren, etc.
2150 // I'm gonna say 'children only'
2151 for (int i=0; i<child_controls.Count; i++) {
2152 if (child_controls[i].Bounds.Contains(pt)) {
2153 return child_controls[i];
2159 public IContainerControl GetContainerControl() {
2160 Control current = this;
2162 while (current!=null) {
2163 if ((current is IContainerControl) && ((current.control_style & ControlStyles.ContainerControl)!=0)) {
2164 return (IContainerControl)current;
2166 current = current.parent;
2171 public Control GetNextControl(Control ctl, bool forward) {
2172 // If we're not a container we don't play
2173 if (!(this is IContainerControl) && !this.GetStyle(ControlStyles.ContainerControl)) {
2177 // If ctl is not contained by this, we start at the first child of this
2178 if (!this.Contains(ctl)) {
2182 // Search through our controls, starting at ctl, stepping into children as we encounter them
2183 // try to find the control with the tabindex closest to our own, or, if we're looking into
2184 // child controls, the one with the smallest tabindex
2186 return FindControlForward(this, ctl);
2188 return FindControlBackward(this, ctl);
2191 public void Hide() {
2192 this.Visible = false;
2195 public void Invalidate() {
2196 Invalidate(ClientRectangle, false);
2199 public void Invalidate(bool invalidateChildren) {
2200 Invalidate(ClientRectangle, invalidateChildren);
2203 public void Invalidate(System.Drawing.Rectangle rc) {
2204 Invalidate(rc, false);
2207 public void Invalidate(System.Drawing.Rectangle rc, bool invalidateChildren) {
2208 if (!IsHandleCreated || !Visible) {
2212 NotifyInvalidate(rc);
2214 XplatUI.Invalidate(Handle, rc, false);
2216 if (invalidateChildren) {
2217 for (int i=0; i<child_controls.Count; i++) child_controls[i].Invalidate();
2219 OnInvalidated(new InvalidateEventArgs(rc));
2222 public void Invalidate(System.Drawing.Region region) {
2223 Invalidate(region, false);
2226 [MonoTODO("Figure out if GetRegionScans is usable")]
2227 public void Invalidate(System.Drawing.Region region, bool invalidateChildren) {
2228 throw new NotImplementedException();
2230 // FIXME - should use the GetRegionScans function of the region to invalidate each area
2231 //if (invalidateChildren) {
2232 // for (int i=0; i<child_controls.Count; i++) child_controls[i].Invalidate();
2236 public object Invoke (Delegate method) {
2237 return Invoke(method, null);
2240 public object Invoke (Delegate method, object[] args) {
2241 if (!this.InvokeRequired) {
2242 return method.DynamicInvoke(args);
2245 IAsyncResult result = BeginInvoke (method, args);
2246 return EndInvoke(result);
2249 [EditorBrowsable(EditorBrowsableState.Advanced)]
2250 public void PerformLayout() {
2251 PerformLayout(null, null);
2254 [EditorBrowsable(EditorBrowsableState.Advanced)]
2255 public void PerformLayout(Control affectedControl, string affectedProperty) {
2256 LayoutEventArgs levent = new LayoutEventArgs(affectedControl, affectedProperty);
2258 if (layout_suspended>0) {
2259 layout_pending = true;
2263 layout_pending = false;
2265 // Prevent us from getting messed up
2268 // Perform all Dock and Anchor calculations
2271 AnchorStyles anchor;
2276 space=this.DisplayRectangle;
2277 if (prev_size != Size.Empty) {
2278 diff_width = space.Width - prev_size.Width;
2279 diff_height = space.Height - prev_size.Height;
2285 // Deal with docking; go through in reverse, MS docs say that lowest Z-order is closest to edge
2286 for (int i = child_controls.Count - 1; i >= 0; i--) {
2287 child=child_controls[i];
2288 switch (child.Dock) {
2289 case DockStyle.None: {
2294 case DockStyle.Left: {
2295 child.SetBounds(space.Left, space.Y, child.Width, space.Height);
2296 space.X+=child.Width;
2297 space.Width-=child.Width;
2301 case DockStyle.Top: {
2302 child.SetBounds(space.Left, space.Y, space.Width, child.Height);
2303 space.Y+=child.Height;
2304 space.Height-=child.Height;
2308 case DockStyle.Right: {
2309 child.SetBounds(space.Right-child.Width, space.Y, child.Width, space.Height);
2310 space.Width-=child.Width;
2314 case DockStyle.Bottom: {
2315 child.SetBounds(space.Left, space.Bottom-child.Height, space.Width, child.Height);
2316 space.Height-=child.Height;
2322 for (int i = child_controls.Count - 1; i >= 0; i--) {
2323 child=child_controls[i];
2325 if (child.Dock == DockStyle.Fill) {
2326 child.SetBounds(space.Left, space.Top, space.Width, space.Height);
2332 space=this.DisplayRectangle;
2334 // Deal with anchoring
2335 for (int i=0; i < child_controls.Count; i++) {
2341 child=child_controls[i];
2342 anchor=child.Anchor;
2347 height=child.Height;
2349 // If the control is docked we don't need to do anything
2350 if (child.Dock != DockStyle.None) {
2354 if ((anchor & AnchorStyles.Left) !=0 ) {
2355 if ((anchor & AnchorStyles.Right) != 0) {
2356 // Anchoring to left and right
2357 width=width+diff_width;
2361 } else if ((anchor & AnchorStyles.Right) != 0) {
2367 if ((anchor & AnchorStyles.Top) !=0 ) {
2368 if ((anchor & AnchorStyles.Bottom) != 0) {
2369 height+=diff_height;
2373 } else if ((anchor & AnchorStyles.Bottom) != 0) {
2388 child.SetBounds(left, top, width, height);
2391 // Let everyone know
2395 // Need to make sure we decremend layout_suspended
2401 public Point PointToClient (Point p) {
2405 XplatUI.ScreenToClient (Handle, ref x, ref y);
2407 return new Point (x, y);
2410 public Point PointToScreen(Point p) {
2414 XplatUI.ClientToScreen(Handle, ref x, ref y);
2416 return new Point(x, y);
2419 public virtual bool PreProcessMessage(ref Message msg) {
2422 if ((msg.Msg == (int)Msg.WM_KEYDOWN) || (msg.Msg == (int)Msg.WM_SYSKEYDOWN)) {
2423 key_data = (Keys)msg.WParam.ToInt32();
2424 if (!ProcessCmdKey(ref msg, key_data)) {
2425 if (IsInputKey(key_data)) {
2429 return ProcessDialogKey(key_data);
2433 } else if (msg.Msg == (int)Msg.WM_CHAR) {
2434 if (IsInputChar((char)msg.WParam)) {
2437 } else if (msg.Msg == (int)Msg.WM_SYSCHAR) {
2438 if (IsInputChar((char)msg.WParam)) {
2441 return ProcessDialogChar((char)msg.WParam);
2446 public Rectangle RectangleToClient(Rectangle r) {
2447 return new Rectangle(PointToClient(r.Location), r.Size);
2450 public Rectangle RectangleToScreen(Rectangle r) {
2451 return new Rectangle(PointToScreen(r.Location), r.Size);
2454 public virtual void Refresh() {
2455 if (IsHandleCreated == true) {
2457 XplatUI.UpdateWindow(window.Handle);
2461 [EditorBrowsable(EditorBrowsableState.Never)]
2462 public virtual void ResetBackColor() {
2463 background_color = Color.Empty;
2466 #if haveDataBindings
2467 [EditorBrowsable(EditorBrowsableState.Never)]
2469 public void ResetBindings() {
2474 [EditorBrowsable(EditorBrowsableState.Never)]
2475 public virtual void ResetCursor() {
2479 [EditorBrowsable(EditorBrowsableState.Never)]
2480 public virtual void ResetFont() {
2484 [EditorBrowsable(EditorBrowsableState.Never)]
2485 public virtual void ResetForeColor() {
2486 foreground_color = Color.Empty;
2489 [EditorBrowsable(EditorBrowsableState.Never)]
2490 public void ResetImeMode() {
2491 ime_mode = DefaultImeMode;
2494 [EditorBrowsable(EditorBrowsableState.Never)]
2495 public virtual void ResetRightToLeft() {
2496 right_to_left = RightToLeft.Inherit;
2499 public virtual void ResetText() {
2503 public void ResumeLayout() {
2504 ResumeLayout (true);
2507 public void ResumeLayout(bool performLayout) {
2510 if (layout_suspended > 0) {
2514 if (performLayout || layout_pending) {
2519 public void Scale(float ratio) {
2520 ScaleCore(ratio, ratio);
2523 public void Scale(float dx, float dy) {
2527 public void Select() {
2528 Select(false, false);
2531 public bool SelectNextControl(Control ctl, bool forward, bool tabStopOnly, bool nested, bool wrap) {
2536 c = GetNextControl(c, forward);
2545 if (c.CanSelect && ((c.parent == ctl.parent) || nested) && (c.tab_stop || !tabStopOnly)) {
2549 } while (c != ctl); // If we wrap back to ourselves we stop
2554 public void SendToBack() {
2555 if ((parent != null) && (parent.child_controls[parent.child_controls.Count-1]!=this)) {
2556 if (parent.child_controls.Contains(this)) {
2557 parent.child_controls.SetChildIndex(this, parent.child_controls.Count);
2561 XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, false, true);
2562 if (parent != null) {
2567 public void SetBounds(int x, int y, int width, int height) {
2568 SetBoundsCore(x, y, width, height, BoundsSpecified.All);
2571 public void SetBounds(int x, int y, int width, int height, BoundsSpecified specified) {
2572 SetBoundsCore(x, y, width, height, specified);
2575 public void Show() {
2576 if (!IsHandleCreated) {
2577 this.CreateControl();
2583 public void SuspendLayout() {
2587 public void Update() {
2588 needs_redraw = true;
2589 XplatUI.UpdateWindow(window.Handle);
2591 #endregion // Public Instance Methods
2593 #region Protected Instance Methods
2594 [EditorBrowsable(EditorBrowsableState.Advanced)]
2595 [MonoTODO("Implement this and tie it into Control.ControlAccessibleObject.NotifyClients")]
2596 protected void AccessibilityNotifyClients(AccessibleEvents accEvent, int childID) {
2597 throw new NotImplementedException();
2600 [EditorBrowsable(EditorBrowsableState.Advanced)]
2601 protected virtual AccessibleObject CreateAccessibilityInstance() {
2602 return new Control.ControlAccessibleObject(this);
2605 [EditorBrowsable(EditorBrowsableState.Advanced)]
2606 protected virtual ControlCollection CreateControlsInstance() {
2607 return new ControlCollection(this);
2610 [EditorBrowsable(EditorBrowsableState.Advanced)]
2611 protected virtual void CreateHandle() {
2613 throw new ObjectDisposedException(Name);
2616 if (IsHandleCreated) {
2620 window.CreateHandle(CreateParams);
2622 // Find out where the window manager placed us
2626 if (window.Handle!=IntPtr.Zero) {
2627 if (!controls.Contains(window.Handle)) {
2631 creator_thread = Thread.CurrentThread;
2633 XplatUI.SetWindowBackground(window.Handle, this.BackColor);
2635 OnHandleCreated(EventArgs.Empty);
2639 [EditorBrowsable(EditorBrowsableState.Advanced)]
2640 protected virtual void DefWndProc(ref Message m) {
2641 window.DefWndProc(ref m);
2644 [EditorBrowsable(EditorBrowsableState.Advanced)]
2645 protected virtual void DestroyHandle() {
2646 if (IsHandleCreated) {
2647 // Destroy our children before we destroy ourselves, to prevent them from
2648 // being implictly (without us knowing) destroyed
2649 for (int i=0; i < child_controls.Count; i++) {
2650 child_controls[i].DestroyHandle();
2654 if (window != null) {
2655 window.DestroyHandle();
2657 OnHandleDestroyed(EventArgs.Empty);
2661 protected bool GetStyle(ControlStyles flag) {
2662 return (control_style & flag) != 0;
2665 protected bool GetTopLevel() {
2669 [EditorBrowsable(EditorBrowsableState.Advanced)]
2670 protected virtual void InitLayout() {
2671 if (parent != null) {
2672 parent.PerformLayout(this, "parent");
2676 [EditorBrowsable(EditorBrowsableState.Advanced)]
2677 protected void InvokeGotFocus(Control toInvoke, EventArgs e) {
2678 toInvoke.OnGotFocus(e);
2681 [EditorBrowsable(EditorBrowsableState.Advanced)]
2682 protected void InvokeLostFocus(Control toInvoke, EventArgs e) {
2683 toInvoke.OnLostFocus(e);
2686 [EditorBrowsable(EditorBrowsableState.Advanced)]
2687 protected void InvokeOnClick(Control toInvoke, EventArgs e) {
2688 toInvoke.OnClick(e);
2691 protected void InvokePaint(Control toInvoke, PaintEventArgs e) {
2692 toInvoke.OnPaint(e);
2695 protected void InvokePaintBackground(Control toInvoke, PaintEventArgs e) {
2696 toInvoke.OnPaintBackground(e);
2699 protected virtual bool IsInputChar (char charCode) {
2700 if (parent != null) {
2701 return parent.IsInputChar(charCode);
2707 protected virtual bool IsInputKey (Keys keyData) {
2708 // Doc says this one calls IsInputChar; not sure what to do with that
2712 [EditorBrowsable(EditorBrowsableState.Advanced)]
2713 protected virtual void NotifyInvalidate(Rectangle invalidatedArea) {
2717 protected virtual bool ProcessCmdKey(ref Message msg, Keys keyData) {
2718 if ((context_menu != null) && context_menu.ProcessCmdKey(ref msg, keyData)) {
2722 if (parent != null) {
2723 return parent.ProcessCmdKey(ref msg, keyData);
2729 protected virtual bool ProcessDialogChar(char charCode) {
2730 if (parent != null) {
2731 return parent.ProcessDialogChar (charCode);
2737 protected virtual bool ProcessDialogKey (Keys keyData) {
2738 if (parent != null) {
2739 return parent.ProcessDialogKey (keyData);
2745 protected virtual bool ProcessKeyEventArgs (ref Message msg)
2747 KeyEventArgs key_event;
2750 case (int)Msg.WM_KEYDOWN: {
2751 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
2752 OnKeyDown (key_event);
2753 return key_event.Handled;
2755 case (int)Msg.WM_KEYUP: {
2756 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
2757 OnKeyUp (key_event);
2758 return key_event.Handled;
2761 case (int)Msg.WM_CHAR: {
2762 KeyPressEventArgs key_press_event;
2764 key_press_event = new KeyPressEventArgs((char)msg.WParam);
2765 OnKeyPress(key_press_event);
2766 return key_press_event.Handled;
2777 protected internal virtual bool ProcessKeyMessage(ref Message msg) {
2778 if (parent != null) {
2779 if (parent.ProcessKeyPreview(ref msg)) {
2787 protected virtual bool ProcessKeyPreview(ref Message msg) {
2788 if (parent != null) {
2789 return parent.ProcessKeyPreview(ref msg);
2795 protected virtual bool ProcessMnemonic(char charCode) {
2800 [EditorBrowsable(EditorBrowsableState.Advanced)]
2801 protected void RaiseDragEvent(object key, DragEventArgs e) {
2805 [EditorBrowsable(EditorBrowsableState.Advanced)]
2806 protected void RaiseKeyEvent(object key, KeyEventArgs e) {
2810 [EditorBrowsable(EditorBrowsableState.Advanced)]
2811 protected void RaiseMouseEvent(object key, MouseEventArgs e) {
2815 [EditorBrowsable(EditorBrowsableState.Advanced)]
2816 protected void RaisePaintEvent(object key, PaintEventArgs e) {
2820 [EditorBrowsable(EditorBrowsableState.Advanced)]
2821 protected void RecreateHandle() {
2822 IEnumerator child = child_controls.GetEnumerator();
2826 if (IsHandleCreated) {
2832 while (child.MoveNext()) {
2833 ((Control)child.Current).RecreateHandle();
2839 is_recreating = false;
2842 [EditorBrowsable(EditorBrowsableState.Advanced)]
2843 protected void ResetMouseEventArgs() {
2847 [EditorBrowsable(EditorBrowsableState.Advanced)]
2848 protected ContentAlignment RtlTranslateAlignment(ContentAlignment align) {
2849 if (right_to_left == RightToLeft.No) {
2854 case ContentAlignment.TopLeft: {
2855 return ContentAlignment.TopRight;
2858 case ContentAlignment.TopRight: {
2859 return ContentAlignment.TopLeft;
2862 case ContentAlignment.MiddleLeft: {
2863 return ContentAlignment.MiddleRight;
2866 case ContentAlignment.MiddleRight: {
2867 return ContentAlignment.MiddleLeft;
2870 case ContentAlignment.BottomLeft: {
2871 return ContentAlignment.BottomRight;
2874 case ContentAlignment.BottomRight: {
2875 return ContentAlignment.BottomLeft;
2879 // if it's center it doesn't change
2885 [EditorBrowsable(EditorBrowsableState.Advanced)]
2886 protected HorizontalAlignment RtlTranslateAlignment(HorizontalAlignment align) {
2887 if ((right_to_left == RightToLeft.No) || (align == HorizontalAlignment.Center)) {
2891 if (align == HorizontalAlignment.Left) {
2892 return HorizontalAlignment.Right;
2895 // align must be HorizontalAlignment.Right
2896 return HorizontalAlignment.Left;
2899 [EditorBrowsable(EditorBrowsableState.Advanced)]
2900 protected LeftRightAlignment RtlTranslateAlignment(LeftRightAlignment align) {
2901 if (right_to_left == RightToLeft.No) {
2905 if (align == LeftRightAlignment.Left) {
2906 return LeftRightAlignment.Right;
2909 // align must be LeftRightAlignment.Right;
2910 return LeftRightAlignment.Left;
2913 [EditorBrowsable(EditorBrowsableState.Advanced)]
2914 protected ContentAlignment RtlTranslateContent(ContentAlignment align) {
2915 return RtlTranslateAlignment(align);
2918 [EditorBrowsable(EditorBrowsableState.Advanced)]
2919 protected HorizontalAlignment RtlTranslateHorizontal(HorizontalAlignment align) {
2920 return RtlTranslateAlignment(align);
2923 [EditorBrowsable(EditorBrowsableState.Advanced)]
2924 protected LeftRightAlignment RtlTranslateLeftRight(LeftRightAlignment align) {
2925 return RtlTranslateAlignment(align);
2928 [EditorBrowsable(EditorBrowsableState.Advanced)]
2929 protected virtual void ScaleCore(float dx, float dy) {
2935 location = new Point((int)(Left * dx), (int)(Top * dy));
2936 size = this.ClientSize;
2939 if (!GetStyle(ControlStyles.FixedWidth)) {
2940 size.Width = (int)(size.Width * dx);
2943 if (!GetStyle(ControlStyles.FixedHeight)) {
2944 size.Height = (int)(size.Height * dy);
2947 Location = location;
2950 /* Now scale our children */
2951 for (int i=0; i < child_controls.Count; i++) {
2952 child_controls[i].Scale(dx, dy);
2958 protected virtual void Select(bool directed, bool forward) {
2963 // Select this control
2968 if (parent == null) {
2972 // FIXME - this thing is doing the wrong stuff, needs to be similar to SelectNextControl
2974 index = parent.child_controls.IndexOf(this);
2979 if ((index+1) < parent.child_controls.Count) {
2988 index = parent.child_controls.Count-1;
2991 result = Select(parent.child_controls[index]);
2992 } while (!result && parent.child_controls[index] != this);
2995 [EditorBrowsable(EditorBrowsableState.Advanced)]
2996 protected virtual void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
2997 // SetBoundsCore updates the Win32 control itself. UpdateBounds updates the controls variables and fires events, I'm guessing - pdb
2998 if ((specified & BoundsSpecified.X) != BoundsSpecified.X) {
3002 if ((specified & BoundsSpecified.Y) != BoundsSpecified.Y) {
3006 if ((specified & BoundsSpecified.Width) != BoundsSpecified.Width) {
3010 if ((specified & BoundsSpecified.Height) != BoundsSpecified.Height) {
3014 if (IsHandleCreated) {
3015 XplatUI.SetWindowPos(Handle, x, y, width, height);
3017 UpdateBounds(x, y, width, height);
3020 [EditorBrowsable(EditorBrowsableState.Advanced)]
3021 protected virtual void SetClientSizeCore(int x, int y) {
3022 // Calculate the actual window size from the client size (it usually stays the same or grows)
3023 Rectangle ClientRect;
3024 Rectangle WindowRect;
3027 ClientRect = new Rectangle(0, 0, x, y);
3028 cp = this.CreateParams;
3030 if (XplatUI.CalculateWindowRect(Handle, ref ClientRect, cp.Style, cp.ExStyle, IntPtr.Zero, out WindowRect)==false) {
3034 SetBoundsCore(bounds.X, bounds.Y, WindowRect.Width, WindowRect.Height, BoundsSpecified.Size);
3037 [EditorBrowsable(EditorBrowsableState.Advanced)]
3038 protected void SetStyle(ControlStyles flag, bool value) {
3040 control_style |= flag;
3042 control_style &= ~flag;
3044 OnStyleChanged(EventArgs.Empty);
3047 protected void SetTopLevel(bool value) {
3048 if ((GetTopLevel() != value) && (parent != null)) {
3049 throw new Exception();
3053 if (value == true) {
3063 is_toplevel = value;
3066 protected virtual void SetVisibleCore(bool value) {
3067 if (value!=is_visible) {
3069 XplatUI.SetVisible(Handle, value);
3070 // Explicitly move Toplevel windows to where we want them;
3071 // apparently moving unmapped toplevel windows doesn't work
3072 if (is_visible && (this is Form)) {
3073 XplatUI.SetWindowPos(window.Handle, bounds.X, bounds.Y, bounds.Width, bounds.Height);
3075 OnVisibleChanged(EventArgs.Empty);
3078 if (dc_mem != null) {
3083 if (bmp_mem != null) {
3088 this.CreateBuffers(bounds.Width, bounds.Height);
3093 if (value == false && parent != null) {
3096 // Need to start at parent, GetContainerControl might return ourselves if we're a container
3097 container = (Control)parent.GetContainerControl();
3098 if (container != null) {
3099 container.SelectNextControl(this, true, true, true, true);
3103 if (parent != null) {
3104 parent.PerformLayout(this, "visible");
3106 PerformLayout(this, "visible");
3111 [EditorBrowsable(EditorBrowsableState.Advanced)]
3112 protected void UpdateBounds() {
3120 if (!IsHandleCreated) {
3124 XplatUI.GetWindowPos(this.Handle, this is Form, out x, out y, out width, out height, out client_width, out client_height);
3126 UpdateBounds(x, y, width, height, client_width, client_height);
3129 [EditorBrowsable(EditorBrowsableState.Advanced)]
3130 protected void UpdateBounds(int x, int y, int width, int height) {
3131 // UpdateBounds only seems to set our sizes and fire events but not update the GUI window to match
3133 bool resized = false;
3135 int client_x_diff = this.bounds.Width-this.client_size.Width;
3136 int client_y_diff = this.bounds.Height-this.client_size.Height;
3138 // Needed to generate required notifications
3139 if ((this.bounds.X!=x) || (this.bounds.Y!=y)) {
3143 if ((this.Bounds.Width!=width) || (this.Bounds.Height!=height)) {
3150 bounds.Height=height;
3152 // Update client rectangle as well
3153 if (this.layout_suspended==0) {
3154 prev_size.Width=client_size.Width;
3155 prev_size.Height=client_size.Height;
3158 client_size.Width=width-client_x_diff;
3159 client_size.Height=height-client_y_diff;
3162 OnLocationChanged(EventArgs.Empty);
3166 OnSizeChanged(EventArgs.Empty);
3170 [EditorBrowsable(EditorBrowsableState.Advanced)]
3171 protected void UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) {
3172 UpdateBounds(x, y, width, height);
3174 this.client_size.Width=clientWidth;
3175 this.client_size.Height=clientHeight;
3178 [EditorBrowsable(EditorBrowsableState.Advanced)]
3179 protected void UpdateStyles() {
3180 if (!IsHandleCreated) {
3184 XplatUI.SetWindowStyle(window.Handle, CreateParams);
3187 [EditorBrowsable(EditorBrowsableState.Advanced)]
3188 protected void UpdateZOrder() {
3193 if (parent == null) {
3199 children = ctl.child_controls.Count;
3200 for (int i = 1; i < children; i++ ) {
3201 XplatUI.SetZOrder(ctl.child_controls[i].window.Handle, ctl.child_controls[i-1].window.Handle, false, false);
3204 children = child_controls.Count;
3205 for (int i = 1; i < children; i++ ) {
3206 XplatUI.SetZOrder(child_controls[i].window.Handle, child_controls[i-1].window.Handle, false, false);
3211 protected virtual void WndProc(ref Message m) {
3213 Console.WriteLine("Control received message {0}", (Msg)m.Msg);
3215 if ((this.control_style & ControlStyles.EnableNotifyMessage) != 0) {
3219 switch((Msg)m.Msg) {
3220 case Msg.WM_WINDOWPOSCHANGED: {
3223 if (GetStyle(ControlStyles.ResizeRedraw)) {
3230 case Msg.WM_PAINT: {
3231 PaintEventArgs paint_event;
3233 paint_event = XplatUI.PaintEventStart(Handle);
3235 if (!needs_redraw) {
3236 // Just blit the previous image
3237 paint_event.Graphics.DrawImage (ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle, GraphicsUnit.Pixel);
3238 XplatUI.PaintEventEnd(Handle);
3243 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
3244 dc = paint_event.SetGraphics (DeviceContext);
3247 if ((control_style & (ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint)) != (ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint)) {
3248 OnPaintBackground(paint_event);
3251 OnPaint(paint_event);
3253 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
3254 dc.DrawImage (ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle, GraphicsUnit.Pixel);
3255 paint_event.SetGraphics (dc);
3256 needs_redraw = false;
3259 XplatUI.PaintEventEnd(Handle);
3261 if (!GetStyle(ControlStyles.UserPaint)) {
3268 case Msg.WM_ERASEBKGND: {
3269 if (GetStyle (ControlStyles.UserPaint)) {
3270 if (!GetStyle(ControlStyles.AllPaintingInWmPaint)) {
3271 PaintEventArgs eraseEventArgs = new PaintEventArgs (m.WParam == IntPtr.Zero ? Graphics.FromHwnd (m.HWnd) :
3272 Graphics.FromHdc (m.WParam), new Rectangle (new Point (0,0),Size));
3273 OnPaintBackground (eraseEventArgs);
3276 XplatUI.EraseWindowBackground(m.HWnd, m.WParam);
3278 // The DefWndProc will never have to handle this, we don't ever set hbr on the window
3279 m.Result = (IntPtr)1;
3283 case Msg.WM_LBUTTONUP: {
3284 HandleClick(mouse_clicks);
3285 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Left,
3287 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3289 if (mouse_clicks > 1) {
3295 case Msg.WM_LBUTTONDOWN: {
3296 if (CanSelect && !is_selected) {
3299 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3300 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3306 case Msg.WM_LBUTTONDBLCLK: {
3308 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3309 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3315 case Msg.WM_MBUTTONUP: {
3316 HandleClick(mouse_clicks);
3317 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Middle,
3319 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3321 if (mouse_clicks > 1) {
3327 case Msg.WM_MBUTTONDOWN: {
3328 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3329 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3335 case Msg.WM_MBUTTONDBLCLK: {
3337 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3338 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3343 case Msg.WM_RBUTTONUP: {
3344 if (context_menu != null) {
3345 context_menu.Show(this, new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ())));
3348 HandleClick(mouse_clicks);
3349 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Right,
3351 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3353 if (mouse_clicks > 1) {
3359 case Msg.WM_RBUTTONDOWN: {
3360 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3361 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3366 case Msg.WM_RBUTTONDBLCLK: {
3368 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3369 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3374 case Msg.WM_MOUSEWHEEL: {
3376 OnMouseWheel (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3377 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3378 HighOrder(m.WParam.ToInt32())));
3383 case Msg.WM_MOUSEMOVE: {
3384 OnMouseMove (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3386 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3391 case Msg.WM_MOUSE_ENTER: {
3396 OnMouseEnter(EventArgs.Empty);
3400 case Msg.WM_MOUSE_LEAVE: {
3402 OnMouseLeave(EventArgs.Empty);
3406 case Msg.WM_MOUSEHOVER: {
3407 OnMouseHover(EventArgs.Empty);
3411 case Msg.WM_SYSKEYDOWN:
3412 case Msg.WM_KEYDOWN:
3413 case Msg.WM_SYSKEYUP:
3415 case Msg.WM_SYSCHAR:
3417 if (ProcessKeyEventArgs(ref m)) {
3421 if (PreProcessMessage(ref m)) {
3425 if (ProcessKeyMessage(ref m)) {
3434 if (m.LParam != IntPtr.Zero) {
3437 hi = new HELPINFO();
3439 hi = (HELPINFO) Marshal.PtrToStructure (m.LParam, typeof (HELPINFO));
3440 mouse_pos = new Point(hi.MousePos.x, hi.MousePos.y);
3442 mouse_pos = Control.MousePosition;
3444 OnHelpRequested(new HelpEventArgs(mouse_pos));
3445 m.Result = (IntPtr)1;
3449 case Msg.WM_KILLFOCUS: {
3450 OnLeave(EventArgs.Empty);
3451 if (CausesValidation) {
3453 e = new CancelEventArgs(false);
3462 OnValidated(EventArgs.Empty);
3465 this.has_focus = false;
3466 this.is_selected = false;
3467 OnLostFocus(EventArgs.Empty);
3471 case Msg.WM_SETFOCUS: {
3472 OnEnter(EventArgs.Empty);
3473 this.has_focus = true;
3474 OnGotFocus(EventArgs.Empty);
3479 case Msg.WM_SYSCOLORCHANGE: {
3480 ThemeEngine.Current.ResetDefaults();
3481 OnSystemColorsChanged(EventArgs.Empty);
3486 case Msg.WM_SETCURSOR: {
3487 if (cursor == null) {
3492 XplatUI.SetCursor(window.Handle, cursor.handle);
3493 m.Result = (IntPtr)1;
3503 #endregion // Public Instance Methods
3505 #region OnXXX methods
3506 [EditorBrowsable(EditorBrowsableState.Advanced)]
3507 protected virtual void OnBackColorChanged(EventArgs e) {
3508 if (BackColorChanged!=null) BackColorChanged(this, e);
3509 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackColorChanged(e);
3512 [EditorBrowsable(EditorBrowsableState.Advanced)]
3513 protected virtual void OnBackgroundImageChanged(EventArgs e) {
3514 if (BackgroundImageChanged!=null) BackgroundImageChanged(this, e);
3515 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackgroundImageChanged(e);
3518 [EditorBrowsable(EditorBrowsableState.Advanced)]
3519 protected virtual void OnBindingContextChanged(EventArgs e) {
3520 CheckDataBindings ();
3521 if (BindingContextChanged!=null) {
3522 BindingContextChanged(this, e);
3524 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBindingContextChanged(e);
3527 [EditorBrowsable(EditorBrowsableState.Advanced)]
3528 protected virtual void OnCausesValidationChanged(EventArgs e) {
3529 if (CausesValidationChanged!=null) CausesValidationChanged(this, e);
3532 [EditorBrowsable(EditorBrowsableState.Advanced)]
3533 protected virtual void OnChangeUICues(UICuesEventArgs e) {
3534 if (ChangeUICues!=null) ChangeUICues(this, e);
3537 [EditorBrowsable(EditorBrowsableState.Advanced)]
3538 protected virtual void OnClick(EventArgs e) {
3539 if (Click!=null) Click(this, e);
3542 [EditorBrowsable(EditorBrowsableState.Advanced)]
3543 protected virtual void OnContextMenuChanged(EventArgs e) {
3544 if (ContextMenuChanged!=null) ContextMenuChanged(this, e);
3547 [EditorBrowsable(EditorBrowsableState.Advanced)]
3548 protected virtual void OnControlAdded(ControlEventArgs e) {
3549 if (ControlAdded!=null) ControlAdded(this, e);
3552 [EditorBrowsable(EditorBrowsableState.Advanced)]
3553 protected virtual void OnControlRemoved(ControlEventArgs e) {
3554 if (ControlRemoved!=null) ControlRemoved(this, e);
3557 [EditorBrowsable(EditorBrowsableState.Advanced)]
3558 protected virtual void OnCreateControl() {
3562 [EditorBrowsable(EditorBrowsableState.Advanced)]
3563 protected virtual void OnCursorChanged(EventArgs e) {
3564 if (CursorChanged!=null) CursorChanged(this, e);
3567 [EditorBrowsable(EditorBrowsableState.Advanced)]
3568 protected virtual void OnDockChanged(EventArgs e) {
3569 if (DockChanged!=null) DockChanged(this, e);
3572 [EditorBrowsable(EditorBrowsableState.Advanced)]
3573 protected virtual void OnDoubleClick(EventArgs e) {
3574 if (DoubleClick!=null) DoubleClick(this, e);
3577 [EditorBrowsable(EditorBrowsableState.Advanced)]
3578 protected virtual void OnDragDrop(DragEventArgs drgevent) {
3579 if (DragDrop!=null) DragDrop(this, drgevent);
3582 [EditorBrowsable(EditorBrowsableState.Advanced)]
3583 protected virtual void OnDragEnter(DragEventArgs drgevent) {
3584 if (DragEnter!=null) DragEnter(this, drgevent);
3587 [EditorBrowsable(EditorBrowsableState.Advanced)]
3588 protected virtual void OnDragLeave(EventArgs e) {
3589 if (DragLeave!=null) DragLeave(this, e);
3592 [EditorBrowsable(EditorBrowsableState.Advanced)]
3593 protected virtual void OnDragOver(DragEventArgs drgevent) {
3594 if (DragOver!=null) DragOver(this, drgevent);
3597 [EditorBrowsable(EditorBrowsableState.Advanced)]
3598 protected virtual void OnEnabledChanged(EventArgs e) {
3599 if (EnabledChanged!=null) EnabledChanged(this, e);
3600 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentEnabledChanged(e);
3603 [EditorBrowsable(EditorBrowsableState.Advanced)]
3604 protected virtual void OnEnter(EventArgs e) {
3605 if (Enter!=null) Enter(this, e);
3608 [EditorBrowsable(EditorBrowsableState.Advanced)]
3609 protected virtual void OnFontChanged(EventArgs e) {
3610 if (FontChanged!=null) FontChanged(this, e);
3611 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentFontChanged(e);
3614 [EditorBrowsable(EditorBrowsableState.Advanced)]
3615 protected virtual void OnForeColorChanged(EventArgs e) {
3616 if (ForeColorChanged!=null) ForeColorChanged(this, e);
3617 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentForeColorChanged(e);
3620 [EditorBrowsable(EditorBrowsableState.Advanced)]
3621 protected virtual void OnGiveFeedback(GiveFeedbackEventArgs gfbevent) {
3622 if (GiveFeedback!=null) GiveFeedback(this, gfbevent);
3625 [EditorBrowsable(EditorBrowsableState.Advanced)]
3626 protected virtual void OnGotFocus(EventArgs e) {
3627 if (GotFocus!=null) GotFocus(this, e);
3630 [EditorBrowsable(EditorBrowsableState.Advanced)]
3631 protected virtual void OnHandleCreated(EventArgs e) {
3632 if (HandleCreated!=null) HandleCreated(this, e);
3635 [EditorBrowsable(EditorBrowsableState.Advanced)]
3636 protected virtual void OnHandleDestroyed(EventArgs e) {
3637 if (HandleDestroyed!=null) HandleDestroyed(this, e);
3640 [EditorBrowsable(EditorBrowsableState.Advanced)]
3641 protected virtual void OnHelpRequested(HelpEventArgs hevent) {
3642 if (HelpRequested!=null) HelpRequested(this, hevent);
3645 protected virtual void OnImeModeChanged(EventArgs e) {
3646 if (ImeModeChanged!=null) ImeModeChanged(this, e);
3649 [EditorBrowsable(EditorBrowsableState.Advanced)]
3650 protected virtual void OnInvalidated(InvalidateEventArgs e) {
3651 needs_redraw = true;
3652 if (Invalidated!=null) Invalidated(this, e);
3655 [EditorBrowsable(EditorBrowsableState.Advanced)]
3656 protected virtual void OnKeyDown(KeyEventArgs e) {
3657 if (KeyDown!=null) KeyDown(this, e);
3660 [EditorBrowsable(EditorBrowsableState.Advanced)]
3661 protected virtual void OnKeyPress(KeyPressEventArgs e) {
3662 if (KeyPress!=null) KeyPress(this, e);
3665 [EditorBrowsable(EditorBrowsableState.Advanced)]
3666 protected virtual void OnKeyUp(KeyEventArgs e) {
3667 if (KeyUp!=null) KeyUp(this, e);
3670 [EditorBrowsable(EditorBrowsableState.Advanced)]
3671 protected virtual void OnLayout(LayoutEventArgs levent) {
3672 if (Layout!=null) Layout(this, levent);
3675 [EditorBrowsable(EditorBrowsableState.Advanced)]
3676 protected virtual void OnLeave(EventArgs e) {
3677 if (Leave!=null) Leave(this, e);
3680 [EditorBrowsable(EditorBrowsableState.Advanced)]
3681 protected virtual void OnLocationChanged(EventArgs e) {
3683 if (LocationChanged!=null) LocationChanged(this, e);
3686 [EditorBrowsable(EditorBrowsableState.Advanced)]
3687 protected virtual void OnLostFocus(EventArgs e) {
3688 if (LostFocus!=null) LostFocus(this, e);
3691 [EditorBrowsable(EditorBrowsableState.Advanced)]
3692 protected virtual void OnMouseDown(MouseEventArgs e) {
3693 if (MouseDown!=null) MouseDown(this, e);
3696 [EditorBrowsable(EditorBrowsableState.Advanced)]
3697 protected virtual void OnMouseEnter(EventArgs e) {
3698 if (MouseEnter!=null) MouseEnter(this, e);
3701 [EditorBrowsable(EditorBrowsableState.Advanced)]
3702 protected virtual void OnMouseHover(EventArgs e) {
3703 if (MouseHover!=null) MouseHover(this, e);
3706 [EditorBrowsable(EditorBrowsableState.Advanced)]
3707 protected virtual void OnMouseLeave(EventArgs e) {
3708 if (MouseLeave!=null) MouseLeave(this, e);
3711 [EditorBrowsable(EditorBrowsableState.Advanced)]
3712 protected virtual void OnMouseMove(MouseEventArgs e) {
3713 if (MouseMove!=null) MouseMove(this, e);
3716 [EditorBrowsable(EditorBrowsableState.Advanced)]
3717 protected virtual void OnMouseUp(MouseEventArgs e) {
3718 if (MouseUp!=null) MouseUp(this, e);
3721 [EditorBrowsable(EditorBrowsableState.Advanced)]
3722 protected virtual void OnMouseWheel(MouseEventArgs e) {
3723 if (MouseWheel!=null) MouseWheel(this, e);
3726 [EditorBrowsable(EditorBrowsableState.Advanced)]
3727 protected virtual void OnMove(EventArgs e) {
3728 if (Move!=null) Move(this, e);
3731 [EditorBrowsable(EditorBrowsableState.Advanced)]
3732 protected virtual void OnNotifyMessage(Message m) {
3736 [EditorBrowsable(EditorBrowsableState.Advanced)]
3737 protected virtual void OnPaint(PaintEventArgs e) {
3738 if (Paint!=null) Paint(this, e);
3741 [EditorBrowsable(EditorBrowsableState.Advanced)]
3742 protected virtual void OnPaintBackground(PaintEventArgs pevent) {
3743 PaintControlBackground (pevent);
3746 [EditorBrowsable(EditorBrowsableState.Advanced)]
3747 protected virtual void OnParentBackColorChanged(EventArgs e) {
3748 if (background_color.IsEmpty && background_image==null) {
3750 OnBackColorChanged(e);
3754 [EditorBrowsable(EditorBrowsableState.Advanced)]
3755 protected virtual void OnParentBackgroundImageChanged(EventArgs e) {
3756 if (background_color.IsEmpty && background_image==null) {
3758 OnBackgroundImageChanged(e);
3762 [EditorBrowsable(EditorBrowsableState.Advanced)]
3763 protected virtual void OnParentBindingContextChanged(EventArgs e) {
3764 if (binding_context==null) {
3765 binding_context=Parent.binding_context;
3766 OnBindingContextChanged(e);
3770 [EditorBrowsable(EditorBrowsableState.Advanced)]
3771 protected virtual void OnParentChanged(EventArgs e) {
3772 if (ParentChanged!=null) ParentChanged(this, e);
3775 [EditorBrowsable(EditorBrowsableState.Advanced)]
3776 protected virtual void OnParentEnabledChanged(EventArgs e) {
3777 if (is_enabled != Parent.is_enabled) {
3778 is_enabled=Parent.is_enabled;
3780 if (EnabledChanged != null) {
3781 EnabledChanged(this, e);
3786 [EditorBrowsable(EditorBrowsableState.Advanced)]
3787 protected virtual void OnParentFontChanged(EventArgs e) {
3794 [EditorBrowsable(EditorBrowsableState.Advanced)]
3795 protected virtual void OnParentForeColorChanged(EventArgs e) {
3796 if (foreground_color.IsEmpty) {
3798 OnForeColorChanged(e);
3802 [EditorBrowsable(EditorBrowsableState.Advanced)]
3803 protected virtual void OnParentRightToLeftChanged(EventArgs e) {
3804 if (right_to_left==RightToLeft.Inherit) {
3806 OnRightToLeftChanged(e);
3810 [EditorBrowsable(EditorBrowsableState.Advanced)]
3811 protected virtual void OnParentVisibleChanged(EventArgs e) {
3813 OnVisibleChanged(e);
3817 [EditorBrowsable(EditorBrowsableState.Advanced)]
3818 protected virtual void OnQueryContinueDrag(QueryContinueDragEventArgs e) {
3819 if (QueryContinueDrag!=null) QueryContinueDrag(this, e);
3822 [EditorBrowsable(EditorBrowsableState.Advanced)]
3823 protected virtual void OnResize(EventArgs e) {
3824 if (Resize!=null) Resize(this, e);
3826 PerformLayout(this, "bounds");
3828 if (parent != null) {
3829 parent.PerformLayout();
3833 [EditorBrowsable(EditorBrowsableState.Advanced)]
3834 protected virtual void OnRightToLeftChanged(EventArgs e) {
3835 if (RightToLeftChanged!=null) RightToLeftChanged(this, e);
3836 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentRightToLeftChanged(e);
3839 [EditorBrowsable(EditorBrowsableState.Advanced)]
3840 protected virtual void OnSizeChanged(EventArgs e) {
3841 InvalidateBuffers ();
3843 if (SizeChanged!=null) SizeChanged(this, e);
3846 [EditorBrowsable(EditorBrowsableState.Advanced)]
3847 protected virtual void OnStyleChanged(EventArgs e) {
3848 if (StyleChanged!=null) StyleChanged(this, e);
3851 [EditorBrowsable(EditorBrowsableState.Advanced)]
3852 protected virtual void OnSystemColorsChanged(EventArgs e) {
3853 if (SystemColorsChanged!=null) SystemColorsChanged(this, e);
3856 [EditorBrowsable(EditorBrowsableState.Advanced)]
3857 protected virtual void OnTabIndexChanged(EventArgs e) {
3858 if (TabIndexChanged!=null) TabIndexChanged(this, e);
3861 [EditorBrowsable(EditorBrowsableState.Advanced)]
3862 protected virtual void OnTabStopChanged(EventArgs e) {
3863 if (TabStopChanged!=null) TabStopChanged(this, e);
3866 [EditorBrowsable(EditorBrowsableState.Advanced)]
3867 protected virtual void OnTextChanged(EventArgs e) {
3868 if (TextChanged!=null) TextChanged(this, e);
3871 [EditorBrowsable(EditorBrowsableState.Advanced)]
3872 protected virtual void OnValidated(EventArgs e) {
3873 if (Validated!=null) Validated(this, e);
3876 [EditorBrowsable(EditorBrowsableState.Advanced)]
3877 protected virtual void OnValidating(System.ComponentModel.CancelEventArgs e) {
3878 if (Validating!=null) Validating(this, e);
3881 [EditorBrowsable(EditorBrowsableState.Advanced)]
3882 protected virtual void OnVisibleChanged(EventArgs e) {
3889 if (bmp_mem!=null) {
3895 if (!this.IsHandleCreated) {
3896 this.CreateControl();
3902 if (VisibleChanged!=null) VisibleChanged(this, e);
3904 // We need to tell our kids
3905 for (int i=0; i<child_controls.Count; i++) {
3906 child_controls[i].OnParentVisibleChanged(e);
3909 #endregion // OnXXX methods
3912 public event EventHandler BackColorChanged;
3913 public event EventHandler BackgroundImageChanged;
3914 public event EventHandler BindingContextChanged;
3915 public event EventHandler CausesValidationChanged;
3916 public event UICuesEventHandler ChangeUICues;
3917 public event EventHandler Click;
3918 public event EventHandler ContextMenuChanged;
3920 [EditorBrowsable(EditorBrowsableState.Advanced)]
3922 public event ControlEventHandler ControlAdded;
3924 [EditorBrowsable(EditorBrowsableState.Advanced)]
3926 public event ControlEventHandler ControlRemoved;
3928 public event EventHandler CursorChanged;
3929 public event EventHandler DockChanged;
3930 public event EventHandler DoubleClick;
3931 public event DragEventHandler DragDrop;
3932 public event DragEventHandler DragEnter;
3933 public event EventHandler DragLeave;
3934 public event DragEventHandler DragOver;
3935 public event EventHandler EnabledChanged;
3936 public event EventHandler Enter;
3937 public event EventHandler FontChanged;
3938 public event EventHandler ForeColorChanged;
3939 public event GiveFeedbackEventHandler GiveFeedback;
3941 [EditorBrowsable(EditorBrowsableState.Advanced)]
3943 public event EventHandler GotFocus;
3945 [EditorBrowsable(EditorBrowsableState.Advanced)]
3947 public event EventHandler HandleCreated;
3949 [EditorBrowsable(EditorBrowsableState.Advanced)]
3951 public event EventHandler HandleDestroyed;
3953 public event HelpEventHandler HelpRequested;
3954 public event EventHandler ImeModeChanged;
3956 [EditorBrowsable(EditorBrowsableState.Advanced)]
3958 public event InvalidateEventHandler Invalidated;
3960 public event KeyEventHandler KeyDown;
3961 public event KeyPressEventHandler KeyPress;
3962 public event KeyEventHandler KeyUp;
3963 public event LayoutEventHandler Layout;
3964 public event EventHandler Leave;
3965 public event EventHandler LocationChanged;
3967 [EditorBrowsable(EditorBrowsableState.Advanced)]
3969 public event EventHandler LostFocus;
3971 public event MouseEventHandler MouseDown;
3972 public event EventHandler MouseEnter;
3973 public event EventHandler MouseHover;
3974 public event EventHandler MouseLeave;
3975 public event MouseEventHandler MouseMove;
3976 public event MouseEventHandler MouseUp;
3978 [EditorBrowsable(EditorBrowsableState.Advanced)]
3980 public event MouseEventHandler MouseWheel;
3982 public event EventHandler Move;
3983 public event PaintEventHandler Paint;
3984 public event EventHandler ParentChanged;
3985 public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp;
3986 public event QueryContinueDragEventHandler QueryContinueDrag;
3987 public event EventHandler Resize;
3988 public event EventHandler RightToLeftChanged;
3989 public event EventHandler SizeChanged;
3990 public event EventHandler StyleChanged;
3991 public event EventHandler SystemColorsChanged;
3992 public event EventHandler TabIndexChanged;
3993 public event EventHandler TabStopChanged;
3994 public event EventHandler TextChanged;
3995 public event EventHandler Validated;
3996 public event CancelEventHandler Validating;
3997 public event EventHandler VisibleChanged;
3998 #endregion // Events