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 AccessibleObject Parent {
223 public override AccessibleRole Role {
228 #endregion // ControlAccessibleObject Public Instance Properties
230 #region ControlAccessibleObject Public Instance Methods
231 public override int GetHelpTopic(out string FileName) {
232 return base.GetHelpTopic (out FileName);
235 [MonoTODO("Implement this and tie it into Control.AccessibilityNotifyClients")]
236 public void NotifyClients(AccessibleEvents accEvent) {
237 throw new NotImplementedException();
240 [MonoTODO("Implement this and tie it into Control.AccessibilityNotifyClients")]
241 public void NotifyClients(AccessibleEvents accEvent, int childID) {
242 throw new NotImplementedException();
245 public override string ToString() {
246 return "ControlAccessibleObject: Owner = " + owner.ToString() + ", Text: " + owner.text;
249 #endregion // ControlAccessibleObject Public Instance Methods
252 [DesignerSerializer("System.Windows.Forms.Design.ControlCollectionCodeDomSerializer, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
253 [ListBindable(false)]
254 public class ControlCollection : IList, ICollection, ICloneable, IEnumerable {
255 #region ControlCollection Local Variables
256 internal ArrayList list;
257 internal Control owner;
258 #endregion // ControlCollection Local Variables
260 #region ControlCollection Public Constructor
261 public ControlCollection(Control owner) {
263 this.list=new ArrayList();
267 #region ControlCollection Public Instance Properties
274 public bool IsReadOnly {
276 return list.IsReadOnly;
280 public virtual Control this[int index] {
282 if (index < 0 || index >= list.Count) {
283 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
285 return (Control)list[index];
288 #endregion // ControlCollection Public Instance Properties
290 #region ControlCollection Private Instance Methods
291 public virtual void Add (Control value)
294 for (int i = 0; i < list.Count; i++) {
295 if (list [i] == value) {
296 // Do we need to do anything here?
301 if (value.tab_index == -1) {
307 end = owner.child_controls.Count;
308 for (int i = 0; i < end; i++) {
309 index = owner.child_controls[i].tab_index;
314 value.tab_index = use;
318 value.Parent = owner;
319 owner.UpdateZOrder();
320 owner.OnControlAdded(new ControlEventArgs(value));
323 public virtual void AddRange (Control[] controls)
325 if (controls == null)
326 throw new ArgumentNullException ("controls");
328 owner.SuspendLayout ();
331 for (int i = 0; i < controls.Length; i++)
334 owner.ResumeLayout ();
338 public virtual void Clear ()
340 owner.SuspendLayout();
341 for (int i = 0; i < list.Count; i++) {
342 owner.OnControlRemoved(new ControlEventArgs((Control)list[i]));
345 owner.ResumeLayout();
348 public bool Contains (Control value)
350 return list.Contains (value);
353 public void CopyTo (Array array, int index)
355 list.CopyTo(array, index);
358 public override bool Equals(object other) {
359 if (other is ControlCollection && (((ControlCollection)other).owner==this.owner)) {
366 public int GetChildIndex(Control child) {
367 return GetChildIndex(child, false);
370 public int GetChildIndex(Control child, bool throwException) {
373 index=list.IndexOf(child);
375 if (index==-1 && throwException) {
376 throw new ArgumentException("Not a child control", "child");
381 public IEnumerator GetEnumerator() {
382 return list.GetEnumerator();
385 public override int GetHashCode() {
386 return base.GetHashCode();
389 public int IndexOf(Control control) {
390 return list.IndexOf(control);
393 public virtual void Remove(Control value) {
394 owner.OnControlRemoved(new ControlEventArgs(value));
396 owner.UpdateZOrder();
399 public void RemoveAt(int index) {
400 if (index<0 || index>=list.Count) {
401 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
404 owner.OnControlRemoved(new ControlEventArgs((Control)list[index]));
405 list.RemoveAt(index);
406 owner.UpdateZOrder();
409 public void SetChildIndex(Control child, int newIndex) {
412 old_index=list.IndexOf(child);
414 throw new ArgumentException("Not a child control", "child");
417 if (old_index==newIndex) {
423 if (newIndex>list.Count) {
426 list.Insert(newIndex, child);
428 owner.UpdateZOrder();
430 #endregion // ControlCollection Private Instance Methods
432 #region ControlCollection Interface Properties
433 object IList.this[int index] {
435 if (index<0 || index>=list.Count) {
436 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
442 if (!(value is Control)) {
443 throw new ArgumentException("Object of type Control required", "value");
446 list[index]=(Control)value;
450 bool IList.IsFixedSize {
456 bool IList.IsReadOnly {
458 return list.IsReadOnly;
462 bool ICollection.IsSynchronized {
464 return list.IsSynchronized;
468 object ICollection.SyncRoot {
470 return list.SyncRoot;
473 #endregion // ControlCollection Interface Properties
475 #region ControlCollection Interface Methods
476 int IList.Add(object value) {
478 throw new ArgumentNullException("value", "Cannot add null controls");
481 if (!(value is Control)) {
482 throw new ArgumentException("Object of type Control required", "value");
485 return list.Add(value);
488 bool IList.Contains(object value) {
489 if (!(value is Control)) {
490 throw new ArgumentException("Object of type Control required", "value");
493 return this.Contains((Control) value);
496 int IList.IndexOf(object value) {
497 if (!(value is Control)) {
498 throw new ArgumentException("Object of type Control required", "value");
501 return this.IndexOf((Control) value);
504 void IList.Insert(int index, object value) {
505 if (!(value is Control)) {
506 throw new ArgumentException("Object of type Control required", "value");
508 list.Insert(index, value);
511 void IList.Remove(object value) {
512 if (!(value is Control)) {
513 throw new ArgumentException("Object of type Control required", "value");
518 void ICollection.CopyTo(Array array, int index) {
520 list.CopyTo(array, index);
524 Object ICloneable.Clone() {
525 ControlCollection clone = new ControlCollection(this.owner);
526 clone.list=(ArrayList)list.Clone(); // FIXME: Do we need this?
529 #endregion // ControlCollection Interface Methods
531 #endregion // ControlCollection Class
533 #region Public Constructors
535 creator_thread = Thread.CurrentThread;
537 prev_size = Size.Empty;
538 anchor_style = AnchorStyles.Top | AnchorStyles.Left;
540 create_handled = false;
546 layout_pending = false;
548 causes_validation = true;
550 layout_suspended = 0;
554 right_to_left = RightToLeft.Inherit;
556 control_style = ControlStyles.Selectable | ControlStyles.StandardClick | ControlStyles.StandardDoubleClick;
559 background_image = null;
563 window = new ControlNativeWindow(this);
564 child_controls = CreateControlsInstance();
565 client_size = new Size(DefaultSize.Width, DefaultSize.Height);
566 client_rect = new Rectangle(0, 0, DefaultSize.Width, DefaultSize.Height);
567 XplatUI.CalculateWindowRect(IntPtr.Zero, ref client_rect, CreateParams.Style, CreateParams.ExStyle, IntPtr.Zero, out bounds);
568 if ((CreateParams.Style & (int)WindowStyles.WS_CHILD) == 0) {
574 public Control(Control parent, string text) : this() {
579 public Control(Control parent, string text, int left, int top, int width, int height) : this() {
584 bounds.Height=height;
585 SetBoundsCore(left, top, width, height, BoundsSpecified.All);
589 public Control(string text) : this() {
593 public Control(string text, int left, int top, int width, int height) : this() {
597 bounds.Height=height;
598 SetBoundsCore(left, top, width, height, BoundsSpecified.All);
602 protected override void Dispose(bool disposing) {
615 controls.Remove(this);
617 #endregion // Public Constructors
619 #region Internal Properties
620 internal BorderStyle InternalBorderStyle {
626 if (border_style != value) {
627 border_style = value;
629 XplatUI.SetBorderStyle(window.Handle, border_style);
633 #endregion // Internal Properties
635 #region Private & Internal Methods
636 internal static IAsyncResult BeginInvokeInternal (Delegate method, object [] args) {
637 AsyncMethodResult result = new AsyncMethodResult ();
638 AsyncMethodData data = new AsyncMethodData ();
640 data.Method = method;
642 data.Result = new WeakReference (result);
645 if (!ExecutionContext.IsFlowSuppressed ()) {
646 data.Context = ExecutionContext.Capture ();
649 if (SecurityManager.SecurityEnabled) {
650 data.Stack = CompressedStack.GetCompressedStack ();
654 XplatUI.SendAsyncMethod (data);
658 internal Graphics DeviceContext {
661 CreateBuffers(this.Width, this.Height);
667 private Bitmap ImageBuffer {
670 CreateBuffers(this.Width, this.Height);
676 internal void CreateBuffers (int width, int height) {
677 if (dc_mem != null) {
691 bmp_mem = new Bitmap (width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
692 dc_mem = Graphics.FromImage (bmp_mem);
696 internal void InvalidateBuffers ()
698 if (dc_mem != null) {
709 internal static void SetChildColor(Control parent) {
712 for (int i=0; i < parent.child_controls.Count; i++) {
713 child=parent.child_controls[i];
714 if (child.IsHandleCreated) {
715 XplatUI.SetWindowBackground(child.window.Handle, child.BackColor);
717 if (child.child_controls.Count>0) {
718 SetChildColor(child);
724 internal bool Select(Control control) {
726 IContainerControl container;
728 if (control == null) {
732 parent = control.parent;
734 if (((control.control_style & ControlStyles.Selectable) !=0) && (parent != null)) {
735 while (parent != null) {
736 if (!parent.Visible || !parent.is_enabled) {
739 parent = parent.parent;
743 control.is_selected = true;
745 container = GetContainerControl();
746 if (container != null) {
747 container.ActiveControl = control;
749 XplatUI.SetFocus(control.window.Handle);
753 internal virtual void DoDefaultAction() {
754 // Only here to be overriden by our actual controls; this is needed by the accessibility class
757 internal static int LowOrder (int param) {
758 return ((int)(short)(param & 0xffff));
761 internal static int HighOrder (int param) {
762 return ((int)(short)(param >> 16));
765 // This method exists so controls overriding OnPaintBackground can have default background painting done
766 internal void PaintControlBackground (PaintEventArgs pevent)
768 if (background_image != null)
769 pevent.Graphics.DrawImage (background_image, 0, 0);
772 internal void DndEnter (DragEventArgs e)
777 internal void DndOver (DragEventArgs e)
782 internal void DndDrop (DragEventArgs e)
787 internal void DndLeave (EventArgs e)
792 internal void DnDFeedback(GiveFeedbackEventArgs e)
797 internal void DnDContinueDrag(QueryContinueDragEventArgs e) {
798 OnQueryContinueDrag(e);
801 internal static MouseButtons FromParamToMouseButtons (int param) {
802 MouseButtons buttons = MouseButtons.None;
804 if ((param & (int) MsgButtons.MK_LBUTTON) != 0)
805 buttons |= MouseButtons.Left;
807 if ((param & (int) MsgButtons.MK_MBUTTON) != 0)
808 buttons |= MouseButtons.Middle;
810 if ((param & (int) MsgButtons.MK_RBUTTON) != 0)
811 buttons |= MouseButtons.Right;
817 internal virtual bool ProcessControlMnemonic(char charCode) {
818 return ProcessMnemonic(charCode);
821 private static Control FindFlatForward(Control container, Control start) {
827 end = container.child_controls.Count;
830 index = start.tab_index;
835 for (int i = 0; i < end; i++) {
837 if (container.child_controls[i].tab_index > index) {
838 found = container.child_controls[i];
840 } else if (found.tab_index > container.child_controls[i].tab_index) {
841 if (container.child_controls[i].tab_index > index) {
842 found = container.child_controls[i];
849 private static Control FindControlForward(Control container, Control start) {
856 if ((start is IContainerControl) || start.GetStyle(ControlStyles.ContainerControl)) {
857 found = FindControlForward(start, null);
864 while (p != container) {
865 found = FindFlatForward(p, start);
873 return FindFlatForward(container, start);
876 private static Control FindFlatBackward(Control container, Control start) {
882 end = container.child_controls.Count;
885 index = start.tab_index;
887 // FIXME: Possible speed-up: Keep the highest taborder index in the container
889 for (int i = 0; i < end; i++) {
890 if (container.child_controls[i].tab_index > index) {
891 index = container.child_controls[i].tab_index;
897 for (int i = 0; i < end; i++) {
899 if (container.child_controls[i].tab_index < index) {
900 found = container.child_controls[i];
902 } else if (found.tab_index < container.child_controls[i].tab_index) {
903 if (container.child_controls[i].tab_index < index) {
904 found = container.child_controls[i];
911 private static Control FindControlBackward(Control container, Control start) {
917 found = FindFlatBackward(start.parent, start);
918 if (found == null && start.parent != container) {
923 found = FindFlatBackward(container, start);
926 while ((found != null) && ((found is IContainerControl) || found.GetStyle(ControlStyles.ContainerControl))) {
927 found = FindControlBackward(found, null);
936 private void HandleClick(int clicks) {
937 if (GetStyle(ControlStyles.StandardClick)) {
939 if (GetStyle(ControlStyles.StandardDoubleClick)) {
940 OnDoubleClick(EventArgs.Empty);
942 OnClick(EventArgs.Empty);
945 OnClick(EventArgs.Empty);
950 private void CheckDataBindings ()
952 if (data_bindings == null)
955 BindingContext binding_context = BindingContext;
956 foreach (Binding binding in data_bindings) {
957 binding.Check (binding_context);
961 #endregion // Private & Internal Methods
963 #region Public Static Properties
964 public static Color DefaultBackColor {
966 return ThemeEngine.Current.DefaultControlBackColor;
970 public static Font DefaultFont {
972 return ThemeEngine.Current.DefaultFont;
976 public static Color DefaultForeColor {
978 return ThemeEngine.Current.DefaultControlForeColor;
982 public static Keys ModifierKeys {
984 return XplatUI.State.ModifierKeys;
988 public static MouseButtons MouseButtons {
990 return XplatUI.State.MouseButtons;
994 public static Point MousePosition {
996 return Cursor.Position;
999 #endregion // Public Static Properties
1001 #region Public Instance Properties
1002 [EditorBrowsable(EditorBrowsableState.Advanced)]
1004 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1005 public AccessibleObject AccessibilityObject {
1007 if (accessibility_object==null) {
1008 accessibility_object=CreateAccessibilityInstance();
1010 return accessibility_object;
1014 [EditorBrowsable(EditorBrowsableState.Advanced)]
1016 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1017 public string AccessibleDefaultActionDescription {
1019 return AccessibilityObject.default_action;
1023 AccessibilityObject.default_action=value;
1028 [DefaultValue(null)]
1029 public string AccessibleDescription {
1031 return AccessibilityObject.description;
1035 AccessibilityObject.description=value;
1040 [DefaultValue(null)]
1041 public string AccessibleName {
1043 return AccessibilityObject.Name;
1047 AccessibilityObject.Name=value;
1051 [DefaultValue(AccessibleRole.Default)]
1052 [MWFDescription("Role of the control"), MWFCategory("Accessibility")]
1053 public AccessibleRole AccessibleRole {
1055 return AccessibilityObject.role;
1059 AccessibilityObject.role=value;
1063 [DefaultValue(false)]
1064 public virtual bool AllowDrop {
1070 if (allow_drop == value)
1074 XplatUI.SetAllowDrop (Handle, value);
1079 [RefreshProperties(RefreshProperties.Repaint)]
1080 [DefaultValue(AnchorStyles.Top | AnchorStyles.Left)]
1081 public virtual AnchorStyles Anchor {
1083 return anchor_style;
1089 if (parent != null) {
1090 parent.PerformLayout(this, "Parent");
1096 public virtual Color BackColor {
1098 if (background_color.IsEmpty) {
1100 return parent.BackColor;
1102 return DefaultBackColor;
1104 return background_color;
1108 background_color=value;
1109 if (this.IsHandleCreated) {
1110 XplatUI.SetWindowBackground(this.window.Handle, value);
1112 SetChildColor(this);
1113 OnBackColorChanged(EventArgs.Empty);
1119 [DefaultValue(null)]
1120 public virtual Image BackgroundImage {
1122 return background_image;
1126 if (background_image!=value) {
1127 background_image=value;
1128 OnBackgroundImageChanged(EventArgs.Empty);
1133 [EditorBrowsable(EditorBrowsableState.Advanced)]
1135 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1136 public virtual BindingContext BindingContext {
1138 if (binding_context != null)
1139 return binding_context;
1142 binding_context = Parent.BindingContext;
1143 return binding_context;
1146 if (binding_context != value) {
1147 binding_context = value;
1148 OnBindingContextChanged(EventArgs.Empty);
1153 [EditorBrowsable(EditorBrowsableState.Advanced)]
1155 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1158 return bounds.Y+bounds.Height;
1162 [EditorBrowsable(EditorBrowsableState.Advanced)]
1164 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1165 public Rectangle Bounds {
1171 SetBoundsCore(value.Left, value.Top, value.Width, value.Height, BoundsSpecified.All);
1175 [EditorBrowsable(EditorBrowsableState.Advanced)]
1177 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1178 public bool CanFocus {
1180 if (Visible && is_enabled && GetStyle(ControlStyles.Selectable)) {
1187 [EditorBrowsable(EditorBrowsableState.Advanced)]
1189 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1190 public bool CanSelect {
1194 if (!GetStyle(ControlStyles.Selectable) || this.parent == null) {
1198 parent = this.parent;
1199 while (parent != null) {
1200 if (!parent.is_visible || !parent.is_enabled) {
1204 parent = parent.parent;
1210 [EditorBrowsable(EditorBrowsableState.Advanced)]
1212 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1213 public bool Capture {
1215 return this.is_captured;
1219 if (this.IsHandleCreated) {
1220 if (value && !is_captured) {
1222 XplatUI.GrabWindow(this.window.Handle, IntPtr.Zero);
1223 } else if (!value && is_captured) {
1224 XplatUI.UngrabWindow(this.window.Handle);
1225 is_captured = false;
1231 [DefaultValue(true)]
1232 public bool CausesValidation {
1234 return this.causes_validation;
1238 if (this.causes_validation != value) {
1239 causes_validation = value;
1240 OnCausesValidationChanged(EventArgs.Empty);
1245 [EditorBrowsable(EditorBrowsableState.Advanced)]
1247 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1248 public Rectangle ClientRectangle {
1250 client_rect.Width = client_size.Width;
1251 client_rect.Height = client_size.Height;
1256 [EditorBrowsable(EditorBrowsableState.Advanced)]
1258 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1259 public Size ClientSize {
1262 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1263 return ((Form)this).form_parent_window.ClientSize;
1271 this.SetClientSizeCore(value.Width, value.Height);
1275 [EditorBrowsable(EditorBrowsableState.Advanced)]
1277 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1278 [DescriptionAttribute("ControlCompanyNameDescr")]
1279 public String CompanyName {
1281 return "Mono Project, Novell, Inc.";
1285 [EditorBrowsable(EditorBrowsableState.Advanced)]
1287 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1288 public bool ContainsFocus {
1294 for (int i=0; i < child_controls.Count; i++) {
1295 if (child_controls[i].ContainsFocus) {
1303 [DefaultValue(null)]
1304 public virtual ContextMenu ContextMenu {
1306 return context_menu;
1310 if (context_menu != value) {
1311 context_menu = value;
1312 OnContextMenuChanged(EventArgs.Empty);
1318 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
1319 public ControlCollection Controls {
1321 return this.child_controls;
1325 [EditorBrowsable(EditorBrowsableState.Advanced)]
1327 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1328 public bool Created {
1330 if (!this.is_disposed && (this.window.Handle != IntPtr.Zero)) {
1337 [AmbientValue(null)]
1338 public virtual Cursor Cursor {
1340 if (cursor != null) {
1344 if (parent != null) {
1345 return parent.Cursor;
1348 return Cursors.Default;
1352 if (cursor != value) {
1357 pt = Cursor.Position;
1358 if (bounds.Contains(pt)) {
1359 if (GetChildAtPoint(pt) == null) {
1360 if (cursor != null) {
1361 XplatUI.SetCursor(window.Handle, cursor.handle);
1363 if (parent != null) {
1364 XplatUI.SetCursor(window.Handle, parent.Cursor.handle);
1366 XplatUI.SetCursor(window.Handle, Cursors.def.handle);
1372 OnCursorChanged(EventArgs.Empty);
1378 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
1379 [ParenthesizePropertyName(true)]
1380 [RefreshProperties(RefreshProperties.All)]
1381 public ControlBindingsCollection DataBindings {
1383 if (data_bindings == null)
1384 data_bindings = new ControlBindingsCollection (this);
1385 return data_bindings;
1389 [EditorBrowsable(EditorBrowsableState.Advanced)]
1391 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1392 public virtual Rectangle DisplayRectangle {
1394 return ClientRectangle;
1398 [EditorBrowsable(EditorBrowsableState.Advanced)]
1400 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1401 public bool Disposing {
1408 [RefreshProperties(RefreshProperties.Repaint)]
1409 [DefaultValue(DockStyle.None)]
1410 public virtual DockStyle Dock {
1416 if (dock_style == value) {
1422 if (parent != null) {
1423 parent.PerformLayout(this, "Parent");
1426 OnDockChanged(EventArgs.Empty);
1432 public bool Enabled {
1438 if (is_enabled == value) {
1444 OnEnabledChanged (EventArgs.Empty);
1448 [EditorBrowsable(EditorBrowsableState.Advanced)]
1450 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1451 public virtual bool Focused {
1453 return this.has_focus;
1458 [AmbientValue(null)]
1460 public virtual Font Font {
1466 if (Parent != null && Parent.Font != null) {
1474 if (font != null && font.Equals (value)) {
1480 OnFontChanged (EventArgs.Empty);
1485 public virtual Color ForeColor {
1487 if (foreground_color.IsEmpty) {
1489 return parent.ForeColor;
1491 return DefaultForeColor;
1493 return foreground_color;
1497 if (foreground_color != value) {
1498 foreground_color=value;
1500 OnForeColorChanged(EventArgs.Empty);
1507 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1508 public IntPtr Handle { // IWin32Window
1510 if (!IsHandleCreated) {
1513 return window.Handle;
1517 [EditorBrowsable(EditorBrowsableState.Advanced)]
1519 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1520 public bool HasChildren {
1522 if (this.child_controls.Count>0) {
1529 [EditorBrowsable(EditorBrowsableState.Always)]
1531 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1534 return this.bounds.Height;
1538 SetBoundsCore(bounds.X, bounds.Y, bounds.Width, value, BoundsSpecified.Height);
1542 [AmbientValue(ImeMode.Inherit)]
1544 public ImeMode ImeMode {
1550 if (ime_mode != value) {
1553 OnImeModeChanged(EventArgs.Empty);
1558 [EditorBrowsable(EditorBrowsableState.Advanced)]
1560 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1561 public bool InvokeRequired { // ISynchronizeInvoke
1563 if (creator_thread!=Thread.CurrentThread) {
1570 [EditorBrowsable(EditorBrowsableState.Advanced)]
1572 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1573 public bool IsAccessible {
1575 return is_accessible;
1579 is_accessible = value;
1583 [EditorBrowsable(EditorBrowsableState.Advanced)]
1585 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1586 public bool IsDisposed {
1588 return this.is_disposed;
1592 [EditorBrowsable(EditorBrowsableState.Advanced)]
1594 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1595 public bool IsHandleCreated {
1597 if ((window!=null) && (window.Handle!=IntPtr.Zero)) {
1605 [EditorBrowsable(EditorBrowsableState.Always)]
1607 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1610 return this.bounds.X;
1614 SetBoundsCore(value, bounds.Y, bounds.Width, bounds.Height, BoundsSpecified.X);
1619 public Point Location {
1621 return new Point(bounds.X, bounds.Y);
1625 SetBoundsCore(value.X, value.Y, bounds.Width, bounds.Height, BoundsSpecified.Location);
1630 public string Name {
1641 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1642 public Control Parent {
1648 if (value == this) {
1649 throw new ArgumentException("A circular control reference has been made. A control cannot be owned or parented to itself.");
1652 if (parent!=value) {
1654 parent.Controls.Remove(this);
1660 if (!parent.Controls.Contains(this)) {
1661 parent.Controls.Add(this);
1664 XplatUI.SetParent(Handle, value.Handle);
1668 OnParentChanged(EventArgs.Empty);
1673 [EditorBrowsable(EditorBrowsableState.Advanced)]
1675 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1676 public string ProductName {
1678 Type t = typeof (AssemblyProductAttribute);
1679 Assembly assembly = GetType().Module.Assembly;
1680 object [] attrs = assembly.GetCustomAttributes (t, false);
1681 AssemblyProductAttribute a = null;
1682 // On MS we get a NullRefException if product attribute is not
1684 if (attrs != null && attrs.Length > 0)
1685 a = (AssemblyProductAttribute) attrs [0];
1690 [EditorBrowsable(EditorBrowsableState.Advanced)]
1692 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1693 public string ProductVersion {
1695 Type t = typeof (AssemblyVersionAttribute);
1696 Assembly assembly = GetType().Module.Assembly;
1697 object [] attrs = assembly.GetCustomAttributes (t, false);
1698 if (attrs == null || attrs.Length < 1)
1700 return ((AssemblyVersionAttribute)attrs [0]).Version;
1704 [EditorBrowsable(EditorBrowsableState.Advanced)]
1706 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1707 public bool RecreatingHandle {
1709 return is_recreating;
1713 [EditorBrowsable(EditorBrowsableState.Advanced)]
1715 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1716 public Region Region {
1718 return new Region(this.bounds);
1725 g = this.CreateGraphics();
1726 r = value.GetBounds(g);
1728 SetBounds((int)r.X, (int)r.Y, (int)r.Width, (int)r.Height);
1734 [EditorBrowsable(EditorBrowsableState.Advanced)]
1736 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1739 return this.bounds.X+this.bounds.Width;
1743 [AmbientValue(RightToLeft.Inherit)]
1745 public virtual RightToLeft RightToLeft {
1747 return right_to_left;
1751 if (value != right_to_left) {
1752 right_to_left = value;
1753 OnRightToLeftChanged(EventArgs.Empty);
1758 [EditorBrowsable(EditorBrowsableState.Advanced)]
1759 public override ISite Site {
1772 return new Size(Width, Height);
1776 SetBoundsCore(bounds.X, bounds.Y, value.Width, value.Height, BoundsSpecified.Size);
1781 [MergableProperty(false)]
1782 public int TabIndex {
1784 if (tab_index != -1) {
1791 if (tab_index != value) {
1793 OnTabIndexChanged(EventArgs.Empty);
1799 [DefaultValue(true)]
1800 public bool TabStop {
1806 if (tab_stop != value) {
1808 OnTabStopChanged(EventArgs.Empty);
1813 [Localizable(false)]
1815 [TypeConverter(typeof(StringConverter))]
1816 [DefaultValue(null)]
1823 control_tag = value;
1829 [BindableAttribute(true)]
1830 public virtual string Text {
1836 if (value == null) {
1837 value = String.Empty;
1842 XplatUI.Text(Handle, text);
1843 // FIXME: Do we need a Refresh() here?
1844 OnTextChanged (EventArgs.Empty);
1849 [EditorBrowsable(EditorBrowsableState.Always)]
1851 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1854 return this.bounds.Y;
1858 SetBoundsCore(bounds.X, value, bounds.Width, bounds.Height, BoundsSpecified.Y);
1862 [EditorBrowsable(EditorBrowsableState.Advanced)]
1864 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1865 public Control TopLevelControl {
1869 while (p.parent != null) {
1878 public bool Visible {
1882 } else if (parent != null) {
1883 return parent.Visible;
1890 SetVisibleCore(value);
1894 [EditorBrowsable(EditorBrowsableState.Always)]
1896 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1899 return this.bounds.Width;
1903 SetBoundsCore(bounds.X, bounds.Y, value, bounds.Height, BoundsSpecified.Width);
1907 [EditorBrowsable(EditorBrowsableState.Never)]
1909 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1910 public IWindowTarget WindowTarget {
1919 #endregion // Public Instance Properties
1921 #region Protected Instance Properties
1922 protected virtual CreateParams CreateParams {
1924 CreateParams create_params = new CreateParams();
1927 create_params.Caption = Text;
1930 create_params.Caption = text;
1934 create_params.X = Left;
1937 create_params.X = this.bounds.X;
1941 create_params.Y = Top;
1944 create_params.Y = this.bounds.Y;
1948 create_params.Width = Width;
1951 create_params.Width = this.bounds.Width;
1955 create_params.Height = Height;
1958 create_params.Height = this.bounds.Height;
1962 create_params.ClassName = XplatUI.DefaultClassName;
1963 create_params.ClassStyle = 0;
1964 create_params.ExStyle = 0;
1965 create_params.Param = 0;
1968 create_params.ExStyle |= (int)WindowStyles.WS_EX_ACCEPTFILES;
1972 create_params.Parent = parent.Handle;
1975 create_params.Style = (int)WindowStyles.WS_CHILD | (int)WindowStyles.WS_CLIPCHILDREN | (int)WindowStyles.WS_CLIPSIBLINGS;
1978 create_params.Style |= (int)WindowStyles.WS_VISIBLE;
1981 return create_params;
1985 protected virtual ImeMode DefaultImeMode {
1987 return ImeMode.Inherit;
1991 protected virtual Size DefaultSize {
1993 return new Size(100, 23);
1997 protected int FontHeight {
2007 protected bool RenderRightToLeft {
2009 return (this.right_to_left == RightToLeft.Yes);
2013 protected bool ResizeRedraw {
2015 return GetStyle(ControlStyles.ResizeRedraw);
2019 SetStyle(ControlStyles.ResizeRedraw, value);
2023 [EditorBrowsable(EditorBrowsableState.Advanced)]
2025 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2026 protected virtual bool ShowFocusCues {
2032 [EditorBrowsable(EditorBrowsableState.Advanced)]
2034 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2035 protected bool ShowKeyboardCues {
2040 #endregion // Protected Instance Properties
2042 #region Public Static Methods
2043 [EditorBrowsable(EditorBrowsableState.Advanced)]
2044 public static Control FromChildHandle(IntPtr handle) {
2045 IEnumerator control = Control.controls.GetEnumerator();
2047 while (control.MoveNext()) {
2048 if (((Control)control.Current).window.Handle == handle) {
2050 if (((Control)control.Current).Parent != null) {
2051 return ((Control)control.Current).Parent;
2058 [EditorBrowsable(EditorBrowsableState.Advanced)]
2059 public static Control FromHandle(IntPtr handle) {
2060 IEnumerator control = Control.controls.GetEnumerator();
2062 while (control.MoveNext()) {
2063 if (((Control)control.Current).window.Handle == handle) {
2065 return ((Control)control.Current);
2071 public static bool IsMnemonic(char charCode, string text) {
2074 amp = text.IndexOf('&');
2077 if (amp + 1 < text.Length) {
2078 if (text[amp + 1] != '&') {
2079 if (Char.ToUpper(charCode) == Char.ToUpper(text.ToCharArray(amp + 1, 1)[0])) {
2089 #region Protected Static Methods
2090 [EditorBrowsable(EditorBrowsableState.Advanced)]
2091 protected static bool ReflectMessage(IntPtr hWnd, ref Message m) {
2094 c = Control.FromHandle(hWnd);
2104 #region Public Instance Methods
2105 [EditorBrowsable(EditorBrowsableState.Advanced)]
2106 public IAsyncResult BeginInvoke(Delegate method) {
2107 return BeginInvokeInternal(method, null);
2110 [EditorBrowsable(EditorBrowsableState.Advanced)]
2111 public IAsyncResult BeginInvoke (Delegate method, object[] args) {
2112 return BeginInvokeInternal (method, args);
2115 public void BringToFront() {
2116 if ((parent != null) && (parent.child_controls[0]!=this)) {
2117 if (parent.child_controls.Contains(this)) {
2118 parent.child_controls.SetChildIndex(this, 0);
2122 XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, true, false);
2124 if (parent != null) {
2129 public bool Contains(Control ctl) {
2130 while (ctl != null) {
2139 public void CreateControl() {
2141 if (!IsHandleCreated) {
2145 if (!create_handled) {
2146 create_handled = true;
2150 for (int i=0; i<child_controls.Count; i++) {
2151 child_controls[i].CreateControl();
2155 public Graphics CreateGraphics() {
2156 if (!IsHandleCreated) {
2157 this.CreateControl();
2159 return Graphics.FromHwnd(this.window.Handle);
2162 public DragDropEffects DoDragDrop(object data, DragDropEffects allowedEffects) {
2163 return XplatUI.StartDrag(this.window.Handle, data, allowedEffects);
2166 [EditorBrowsable(EditorBrowsableState.Advanced)]
2167 public object EndInvoke (IAsyncResult async_result) {
2168 AsyncMethodResult result = (AsyncMethodResult) async_result;
2169 return result.EndInvoke ();
2172 public Form FindForm() {
2185 public bool Focus() {
2186 if (IsHandleCreated && !has_focus) {
2188 XplatUI.SetFocus(window.Handle);
2193 public Control GetChildAtPoint(Point pt) {
2194 // Microsoft's version of this function doesn't seem to work, so I can't check
2195 // if we only consider children or also grandchildren, etc.
2196 // I'm gonna say 'children only'
2197 for (int i=0; i<child_controls.Count; i++) {
2198 if (child_controls[i].Bounds.Contains(pt)) {
2199 return child_controls[i];
2205 public IContainerControl GetContainerControl() {
2206 Control current = this;
2208 while (current!=null) {
2209 if ((current is IContainerControl) && ((current.control_style & ControlStyles.ContainerControl)!=0)) {
2210 return (IContainerControl)current;
2212 current = current.parent;
2217 public Control GetNextControl(Control ctl, bool forward) {
2218 // If we're not a container we don't play
2219 if (!(this is IContainerControl) && !this.GetStyle(ControlStyles.ContainerControl)) {
2223 // If ctl is not contained by this, we start at the first child of this
2224 if (!this.Contains(ctl)) {
2228 // Search through our controls, starting at ctl, stepping into children as we encounter them
2229 // try to find the control with the tabindex closest to our own, or, if we're looking into
2230 // child controls, the one with the smallest tabindex
2232 return FindControlForward(this, ctl);
2234 return FindControlBackward(this, ctl);
2237 public void Hide() {
2238 this.Visible = false;
2241 public void Invalidate() {
2242 Invalidate(ClientRectangle, false);
2245 public void Invalidate(bool invalidateChildren) {
2246 Invalidate(ClientRectangle, invalidateChildren);
2249 public void Invalidate(System.Drawing.Rectangle rc) {
2250 Invalidate(rc, false);
2253 public void Invalidate(System.Drawing.Rectangle rc, bool invalidateChildren) {
2254 if (!IsHandleCreated || !Visible) {
2258 NotifyInvalidate(rc);
2260 XplatUI.Invalidate(Handle, rc, false);
2262 if (invalidateChildren) {
2263 for (int i=0; i<child_controls.Count; i++) child_controls[i].Invalidate();
2265 OnInvalidated(new InvalidateEventArgs(rc));
2268 public void Invalidate(System.Drawing.Region region) {
2269 Invalidate(region, false);
2272 [MonoTODO("Figure out if GetRegionScans is usable")]
2273 public void Invalidate(System.Drawing.Region region, bool invalidateChildren) {
2274 throw new NotImplementedException();
2276 // FIXME - should use the GetRegionScans function of the region to invalidate each area
2277 //if (invalidateChildren) {
2278 // for (int i=0; i<child_controls.Count; i++) child_controls[i].Invalidate();
2282 public object Invoke (Delegate method) {
2283 return Invoke(method, null);
2286 public object Invoke (Delegate method, object[] args) {
2287 if (!this.InvokeRequired) {
2288 return method.DynamicInvoke(args);
2291 IAsyncResult result = BeginInvoke (method, args);
2292 return EndInvoke(result);
2295 [EditorBrowsable(EditorBrowsableState.Advanced)]
2296 public void PerformLayout() {
2297 PerformLayout(null, null);
2300 [EditorBrowsable(EditorBrowsableState.Advanced)]
2301 public void PerformLayout(Control affectedControl, string affectedProperty) {
2302 LayoutEventArgs levent = new LayoutEventArgs(affectedControl, affectedProperty);
2304 if (layout_suspended>0) {
2305 layout_pending = true;
2309 layout_pending = false;
2311 // Prevent us from getting messed up
2314 // Perform all Dock and Anchor calculations
2317 AnchorStyles anchor;
2322 space=this.DisplayRectangle;
2323 if (prev_size != Size.Empty) {
2324 diff_width = space.Width - prev_size.Width;
2325 diff_height = space.Height - prev_size.Height;
2331 // Deal with docking; go through in reverse, MS docs say that lowest Z-order is closest to edge
2332 for (int i = child_controls.Count - 1; i >= 0; i--) {
2333 child=child_controls[i];
2334 switch (child.Dock) {
2335 case DockStyle.None: {
2340 case DockStyle.Left: {
2341 child.SetBounds(space.Left, space.Y, child.Width, space.Height);
2342 space.X+=child.Width;
2343 space.Width-=child.Width;
2347 case DockStyle.Top: {
2348 child.SetBounds(space.Left, space.Y, space.Width, child.Height);
2349 space.Y+=child.Height;
2350 space.Height-=child.Height;
2354 case DockStyle.Right: {
2355 child.SetBounds(space.Right-child.Width, space.Y, child.Width, space.Height);
2356 space.Width-=child.Width;
2360 case DockStyle.Bottom: {
2361 child.SetBounds(space.Left, space.Bottom-child.Height, space.Width, child.Height);
2362 space.Height-=child.Height;
2368 for (int i = child_controls.Count - 1; i >= 0; i--) {
2369 child=child_controls[i];
2371 if (child.Dock == DockStyle.Fill) {
2372 child.SetBounds(space.Left, space.Top, space.Width, space.Height);
2378 space=this.DisplayRectangle;
2380 // Deal with anchoring
2381 for (int i=0; i < child_controls.Count; i++) {
2387 child=child_controls[i];
2388 anchor=child.Anchor;
2393 height=child.Height;
2395 // If the control is docked we don't need to do anything
2396 if (child.Dock != DockStyle.None) {
2400 if ((anchor & AnchorStyles.Left) !=0 ) {
2401 if ((anchor & AnchorStyles.Right) != 0) {
2402 // Anchoring to left and right
2403 width=width+diff_width;
2407 } else if ((anchor & AnchorStyles.Right) != 0) {
2413 if ((anchor & AnchorStyles.Top) !=0 ) {
2414 if ((anchor & AnchorStyles.Bottom) != 0) {
2415 height+=diff_height;
2419 } else if ((anchor & AnchorStyles.Bottom) != 0) {
2434 child.SetBounds(left, top, width, height);
2437 // Let everyone know
2441 // Need to make sure we decremend layout_suspended
2447 public Point PointToClient (Point p) {
2451 XplatUI.ScreenToClient (Handle, ref x, ref y);
2453 return new Point (x, y);
2456 public Point PointToScreen(Point p) {
2460 XplatUI.ClientToScreen(Handle, ref x, ref y);
2462 return new Point(x, y);
2465 public virtual bool PreProcessMessage(ref Message msg) {
2468 if ((msg.Msg == (int)Msg.WM_KEYDOWN) || (msg.Msg == (int)Msg.WM_SYSKEYDOWN)) {
2469 key_data = (Keys)msg.WParam.ToInt32();
2470 if (!ProcessCmdKey(ref msg, key_data)) {
2471 if (IsInputKey(key_data)) {
2475 return ProcessDialogKey(key_data);
2479 } else if (msg.Msg == (int)Msg.WM_CHAR) {
2480 if (IsInputChar((char)msg.WParam)) {
2483 } else if (msg.Msg == (int)Msg.WM_SYSCHAR) {
2484 if (IsInputChar((char)msg.WParam)) {
2487 return ProcessDialogChar((char)msg.WParam);
2492 public Rectangle RectangleToClient(Rectangle r) {
2493 return new Rectangle(PointToClient(r.Location), r.Size);
2496 public Rectangle RectangleToScreen(Rectangle r) {
2497 return new Rectangle(PointToScreen(r.Location), r.Size);
2500 public virtual void Refresh() {
2501 if (IsHandleCreated == true) {
2503 XplatUI.UpdateWindow(window.Handle);
2507 [EditorBrowsable(EditorBrowsableState.Never)]
2508 public virtual void ResetBackColor() {
2509 background_color = Color.Empty;
2512 [EditorBrowsable(EditorBrowsableState.Never)]
2514 public void ResetBindings() {
2518 [EditorBrowsable(EditorBrowsableState.Never)]
2519 public virtual void ResetCursor() {
2523 [EditorBrowsable(EditorBrowsableState.Never)]
2524 public virtual void ResetFont() {
2528 [EditorBrowsable(EditorBrowsableState.Never)]
2529 public virtual void ResetForeColor() {
2530 foreground_color = Color.Empty;
2533 [EditorBrowsable(EditorBrowsableState.Never)]
2534 public void ResetImeMode() {
2535 ime_mode = DefaultImeMode;
2538 [EditorBrowsable(EditorBrowsableState.Never)]
2539 public virtual void ResetRightToLeft() {
2540 right_to_left = RightToLeft.Inherit;
2543 public virtual void ResetText() {
2547 public void ResumeLayout() {
2548 ResumeLayout (true);
2551 public void ResumeLayout(bool performLayout) {
2554 if (layout_suspended > 0) {
2558 if (performLayout || layout_pending) {
2563 public void Scale(float ratio) {
2564 ScaleCore(ratio, ratio);
2567 public void Scale(float dx, float dy) {
2571 public void Select() {
2572 Select(false, false);
2575 public bool SelectNextControl(Control ctl, bool forward, bool tabStopOnly, bool nested, bool wrap) {
2580 c = GetNextControl(c, forward);
2589 if (c.CanSelect && ((c.parent == ctl.parent) || nested) && (c.tab_stop || !tabStopOnly)) {
2593 } while (c != ctl); // If we wrap back to ourselves we stop
2598 public void SendToBack() {
2599 if ((parent != null) && (parent.child_controls[parent.child_controls.Count-1]!=this)) {
2600 if (parent.child_controls.Contains(this)) {
2601 parent.child_controls.SetChildIndex(this, parent.child_controls.Count);
2605 XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, false, true);
2606 if (parent != null) {
2611 public void SetBounds(int x, int y, int width, int height) {
2612 SetBoundsCore(x, y, width, height, BoundsSpecified.All);
2615 public void SetBounds(int x, int y, int width, int height, BoundsSpecified specified) {
2616 SetBoundsCore(x, y, width, height, specified);
2619 public void Show() {
2620 if (!IsHandleCreated) {
2621 this.CreateControl();
2627 public void SuspendLayout() {
2631 public void Update() {
2632 needs_redraw = true;
2633 XplatUI.UpdateWindow(window.Handle);
2635 #endregion // Public Instance Methods
2637 #region Protected Instance Methods
2638 [EditorBrowsable(EditorBrowsableState.Advanced)]
2639 [MonoTODO("Implement this and tie it into Control.ControlAccessibleObject.NotifyClients")]
2640 protected void AccessibilityNotifyClients(AccessibleEvents accEvent, int childID) {
2641 throw new NotImplementedException();
2644 [EditorBrowsable(EditorBrowsableState.Advanced)]
2645 protected virtual AccessibleObject CreateAccessibilityInstance() {
2646 return new Control.ControlAccessibleObject(this);
2649 [EditorBrowsable(EditorBrowsableState.Advanced)]
2650 protected virtual ControlCollection CreateControlsInstance() {
2651 return new ControlCollection(this);
2654 [EditorBrowsable(EditorBrowsableState.Advanced)]
2655 protected virtual void CreateHandle() {
2657 throw new ObjectDisposedException(Name);
2660 if (IsHandleCreated) {
2664 window.CreateHandle(CreateParams);
2666 // Find out where the window manager placed us
2670 if (window.Handle!=IntPtr.Zero) {
2671 if (!controls.Contains(window.Handle)) {
2675 creator_thread = Thread.CurrentThread;
2677 XplatUI.SetWindowBackground(window.Handle, this.BackColor);
2679 OnHandleCreated(EventArgs.Empty);
2683 [EditorBrowsable(EditorBrowsableState.Advanced)]
2684 protected virtual void DefWndProc(ref Message m) {
2685 window.DefWndProc(ref m);
2688 [EditorBrowsable(EditorBrowsableState.Advanced)]
2689 protected virtual void DestroyHandle() {
2690 if (IsHandleCreated) {
2691 // Destroy our children before we destroy ourselves, to prevent them from
2692 // being implictly (without us knowing) destroyed
2693 for (int i=0; i < child_controls.Count; i++) {
2694 child_controls[i].DestroyHandle();
2698 if (window != null) {
2699 window.DestroyHandle();
2701 OnHandleDestroyed(EventArgs.Empty);
2705 protected bool GetStyle(ControlStyles flag) {
2706 return (control_style & flag) != 0;
2709 protected bool GetTopLevel() {
2713 [EditorBrowsable(EditorBrowsableState.Advanced)]
2714 protected virtual void InitLayout() {
2715 if (parent != null) {
2716 parent.PerformLayout(this, "parent");
2720 [EditorBrowsable(EditorBrowsableState.Advanced)]
2721 protected void InvokeGotFocus(Control toInvoke, EventArgs e) {
2722 toInvoke.OnGotFocus(e);
2725 [EditorBrowsable(EditorBrowsableState.Advanced)]
2726 protected void InvokeLostFocus(Control toInvoke, EventArgs e) {
2727 toInvoke.OnLostFocus(e);
2730 [EditorBrowsable(EditorBrowsableState.Advanced)]
2731 protected void InvokeOnClick(Control toInvoke, EventArgs e) {
2732 toInvoke.OnClick(e);
2735 protected void InvokePaint(Control toInvoke, PaintEventArgs e) {
2736 toInvoke.OnPaint(e);
2739 protected void InvokePaintBackground(Control toInvoke, PaintEventArgs e) {
2740 toInvoke.OnPaintBackground(e);
2743 protected virtual bool IsInputChar (char charCode) {
2744 if (parent != null) {
2745 return parent.IsInputChar(charCode);
2751 protected virtual bool IsInputKey (Keys keyData) {
2752 // Doc says this one calls IsInputChar; not sure what to do with that
2756 [EditorBrowsable(EditorBrowsableState.Advanced)]
2757 protected virtual void NotifyInvalidate(Rectangle invalidatedArea) {
2761 protected virtual bool ProcessCmdKey(ref Message msg, Keys keyData) {
2762 if ((context_menu != null) && context_menu.ProcessCmdKey(ref msg, keyData)) {
2766 if (parent != null) {
2767 return parent.ProcessCmdKey(ref msg, keyData);
2773 protected virtual bool ProcessDialogChar(char charCode) {
2774 if (parent != null) {
2775 return parent.ProcessDialogChar (charCode);
2781 protected virtual bool ProcessDialogKey (Keys keyData) {
2782 if (parent != null) {
2783 return parent.ProcessDialogKey (keyData);
2789 protected virtual bool ProcessKeyEventArgs (ref Message msg)
2791 KeyEventArgs key_event;
2794 case (int)Msg.WM_KEYDOWN: {
2795 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
2796 OnKeyDown (key_event);
2797 return key_event.Handled;
2799 case (int)Msg.WM_KEYUP: {
2800 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
2801 OnKeyUp (key_event);
2802 return key_event.Handled;
2805 case (int)Msg.WM_CHAR: {
2806 KeyPressEventArgs key_press_event;
2808 key_press_event = new KeyPressEventArgs((char)msg.WParam);
2809 OnKeyPress(key_press_event);
2810 return key_press_event.Handled;
2821 protected internal virtual bool ProcessKeyMessage(ref Message msg) {
2822 if (parent != null) {
2823 if (parent.ProcessKeyPreview(ref msg)) {
2831 protected virtual bool ProcessKeyPreview(ref Message msg) {
2832 if (parent != null) {
2833 return parent.ProcessKeyPreview(ref msg);
2839 protected virtual bool ProcessMnemonic(char charCode) {
2844 [EditorBrowsable(EditorBrowsableState.Advanced)]
2845 protected void RaiseDragEvent(object key, DragEventArgs e) {
2849 [EditorBrowsable(EditorBrowsableState.Advanced)]
2850 protected void RaiseKeyEvent(object key, KeyEventArgs e) {
2854 [EditorBrowsable(EditorBrowsableState.Advanced)]
2855 protected void RaiseMouseEvent(object key, MouseEventArgs e) {
2859 [EditorBrowsable(EditorBrowsableState.Advanced)]
2860 protected void RaisePaintEvent(object key, PaintEventArgs e) {
2864 [EditorBrowsable(EditorBrowsableState.Advanced)]
2865 protected void RecreateHandle() {
2866 IEnumerator child = child_controls.GetEnumerator();
2870 if (IsHandleCreated) {
2876 while (child.MoveNext()) {
2877 ((Control)child.Current).RecreateHandle();
2883 is_recreating = false;
2886 [EditorBrowsable(EditorBrowsableState.Advanced)]
2887 protected void ResetMouseEventArgs() {
2891 [EditorBrowsable(EditorBrowsableState.Advanced)]
2892 protected ContentAlignment RtlTranslateAlignment(ContentAlignment align) {
2893 if (right_to_left == RightToLeft.No) {
2898 case ContentAlignment.TopLeft: {
2899 return ContentAlignment.TopRight;
2902 case ContentAlignment.TopRight: {
2903 return ContentAlignment.TopLeft;
2906 case ContentAlignment.MiddleLeft: {
2907 return ContentAlignment.MiddleRight;
2910 case ContentAlignment.MiddleRight: {
2911 return ContentAlignment.MiddleLeft;
2914 case ContentAlignment.BottomLeft: {
2915 return ContentAlignment.BottomRight;
2918 case ContentAlignment.BottomRight: {
2919 return ContentAlignment.BottomLeft;
2923 // if it's center it doesn't change
2929 [EditorBrowsable(EditorBrowsableState.Advanced)]
2930 protected HorizontalAlignment RtlTranslateAlignment(HorizontalAlignment align) {
2931 if ((right_to_left == RightToLeft.No) || (align == HorizontalAlignment.Center)) {
2935 if (align == HorizontalAlignment.Left) {
2936 return HorizontalAlignment.Right;
2939 // align must be HorizontalAlignment.Right
2940 return HorizontalAlignment.Left;
2943 [EditorBrowsable(EditorBrowsableState.Advanced)]
2944 protected LeftRightAlignment RtlTranslateAlignment(LeftRightAlignment align) {
2945 if (right_to_left == RightToLeft.No) {
2949 if (align == LeftRightAlignment.Left) {
2950 return LeftRightAlignment.Right;
2953 // align must be LeftRightAlignment.Right;
2954 return LeftRightAlignment.Left;
2957 [EditorBrowsable(EditorBrowsableState.Advanced)]
2958 protected ContentAlignment RtlTranslateContent(ContentAlignment align) {
2959 return RtlTranslateAlignment(align);
2962 [EditorBrowsable(EditorBrowsableState.Advanced)]
2963 protected HorizontalAlignment RtlTranslateHorizontal(HorizontalAlignment align) {
2964 return RtlTranslateAlignment(align);
2967 [EditorBrowsable(EditorBrowsableState.Advanced)]
2968 protected LeftRightAlignment RtlTranslateLeftRight(LeftRightAlignment align) {
2969 return RtlTranslateAlignment(align);
2972 [EditorBrowsable(EditorBrowsableState.Advanced)]
2973 protected virtual void ScaleCore(float dx, float dy) {
2979 location = new Point((int)(Left * dx), (int)(Top * dy));
2980 size = this.ClientSize;
2983 if (!GetStyle(ControlStyles.FixedWidth)) {
2984 size.Width = (int)(size.Width * dx);
2987 if (!GetStyle(ControlStyles.FixedHeight)) {
2988 size.Height = (int)(size.Height * dy);
2991 Location = location;
2994 /* Now scale our children */
2995 for (int i=0; i < child_controls.Count; i++) {
2996 child_controls[i].Scale(dx, dy);
3002 protected virtual void Select(bool directed, bool forward) {
3007 // Select this control
3012 if (parent == null) {
3016 // FIXME - this thing is doing the wrong stuff, needs to be similar to SelectNextControl
3018 index = parent.child_controls.IndexOf(this);
3023 if ((index+1) < parent.child_controls.Count) {
3032 index = parent.child_controls.Count-1;
3035 result = Select(parent.child_controls[index]);
3036 } while (!result && parent.child_controls[index] != this);
3039 [EditorBrowsable(EditorBrowsableState.Advanced)]
3040 protected virtual void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
3041 // SetBoundsCore updates the Win32 control itself. UpdateBounds updates the controls variables and fires events, I'm guessing - pdb
3042 if ((specified & BoundsSpecified.X) != BoundsSpecified.X) {
3046 if ((specified & BoundsSpecified.Y) != BoundsSpecified.Y) {
3050 if ((specified & BoundsSpecified.Width) != BoundsSpecified.Width) {
3054 if ((specified & BoundsSpecified.Height) != BoundsSpecified.Height) {
3058 if (IsHandleCreated) {
3059 XplatUI.SetWindowPos(Handle, x, y, width, height);
3061 UpdateBounds(x, y, width, height);
3064 [EditorBrowsable(EditorBrowsableState.Advanced)]
3065 protected virtual void SetClientSizeCore(int x, int y) {
3066 // Calculate the actual window size from the client size (it usually stays the same or grows)
3067 Rectangle ClientRect;
3068 Rectangle WindowRect;
3071 ClientRect = new Rectangle(0, 0, x, y);
3072 cp = this.CreateParams;
3074 if (XplatUI.CalculateWindowRect(Handle, ref ClientRect, cp.Style, cp.ExStyle, IntPtr.Zero, out WindowRect)==false) {
3078 SetBoundsCore(bounds.X, bounds.Y, WindowRect.Width, WindowRect.Height, BoundsSpecified.Size);
3081 [EditorBrowsable(EditorBrowsableState.Advanced)]
3082 protected void SetStyle(ControlStyles flag, bool value) {
3084 control_style |= flag;
3086 control_style &= ~flag;
3088 OnStyleChanged(EventArgs.Empty);
3091 protected void SetTopLevel(bool value) {
3092 if ((GetTopLevel() != value) && (parent != null)) {
3093 throw new Exception();
3097 if (value == true) {
3107 is_toplevel = value;
3110 protected virtual void SetVisibleCore(bool value) {
3111 if (value!=is_visible) {
3113 XplatUI.SetVisible(Handle, value);
3114 // Explicitly move Toplevel windows to where we want them;
3115 // apparently moving unmapped toplevel windows doesn't work
3116 if (is_visible && (this is Form)) {
3117 XplatUI.SetWindowPos(window.Handle, bounds.X, bounds.Y, bounds.Width, bounds.Height);
3119 OnVisibleChanged(EventArgs.Empty);
3122 if (dc_mem != null) {
3127 if (bmp_mem != null) {
3132 this.CreateBuffers(bounds.Width, bounds.Height);
3137 if (value == false && parent != null) {
3140 // Need to start at parent, GetContainerControl might return ourselves if we're a container
3141 container = (Control)parent.GetContainerControl();
3142 if (container != null) {
3143 container.SelectNextControl(this, true, true, true, true);
3147 if (parent != null) {
3148 parent.PerformLayout(this, "visible");
3150 PerformLayout(this, "visible");
3155 [EditorBrowsable(EditorBrowsableState.Advanced)]
3156 protected void UpdateBounds() {
3164 if (!IsHandleCreated) {
3168 XplatUI.GetWindowPos(this.Handle, this is Form, out x, out y, out width, out height, out client_width, out client_height);
3170 UpdateBounds(x, y, width, height, client_width, client_height);
3173 [EditorBrowsable(EditorBrowsableState.Advanced)]
3174 protected void UpdateBounds(int x, int y, int width, int height) {
3175 // UpdateBounds only seems to set our sizes and fire events but not update the GUI window to match
3177 bool resized = false;
3179 int client_x_diff = this.bounds.Width-this.client_size.Width;
3180 int client_y_diff = this.bounds.Height-this.client_size.Height;
3182 // Needed to generate required notifications
3183 if ((this.bounds.X!=x) || (this.bounds.Y!=y)) {
3187 if ((this.Bounds.Width!=width) || (this.Bounds.Height!=height)) {
3194 bounds.Height=height;
3196 // Update client rectangle as well
3197 if (this.layout_suspended==0) {
3198 prev_size.Width=client_size.Width;
3199 prev_size.Height=client_size.Height;
3202 client_size.Width=width-client_x_diff;
3203 client_size.Height=height-client_y_diff;
3206 OnLocationChanged(EventArgs.Empty);
3210 OnSizeChanged(EventArgs.Empty);
3214 [EditorBrowsable(EditorBrowsableState.Advanced)]
3215 protected void UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) {
3216 UpdateBounds(x, y, width, height);
3218 this.client_size.Width=clientWidth;
3219 this.client_size.Height=clientHeight;
3222 [EditorBrowsable(EditorBrowsableState.Advanced)]
3223 protected void UpdateStyles() {
3224 if (!IsHandleCreated) {
3228 XplatUI.SetWindowStyle(window.Handle, CreateParams);
3231 [EditorBrowsable(EditorBrowsableState.Advanced)]
3232 protected void UpdateZOrder() {
3237 if (parent == null) {
3243 children = ctl.child_controls.Count;
3244 for (int i = 1; i < children; i++ ) {
3245 XplatUI.SetZOrder(ctl.child_controls[i].window.Handle, ctl.child_controls[i-1].window.Handle, false, false);
3248 children = child_controls.Count;
3249 for (int i = 1; i < children; i++ ) {
3250 XplatUI.SetZOrder(child_controls[i].window.Handle, child_controls[i-1].window.Handle, false, false);
3255 protected virtual void WndProc(ref Message m) {
3257 Console.WriteLine("Control received message {0}", (Msg)m.Msg);
3259 if ((this.control_style & ControlStyles.EnableNotifyMessage) != 0) {
3263 switch((Msg)m.Msg) {
3264 case Msg.WM_WINDOWPOSCHANGED: {
3267 if (GetStyle(ControlStyles.ResizeRedraw)) {
3274 case Msg.WM_PAINT: {
3275 PaintEventArgs paint_event;
3277 paint_event = XplatUI.PaintEventStart(Handle);
3279 if (!needs_redraw) {
3280 // Just blit the previous image
3281 paint_event.Graphics.DrawImage (ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle, GraphicsUnit.Pixel);
3282 XplatUI.PaintEventEnd(Handle);
3287 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
3288 dc = paint_event.SetGraphics (DeviceContext);
3291 if ((control_style & (ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint)) != (ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint)) {
3292 OnPaintBackground(paint_event);
3295 OnPaint(paint_event);
3297 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
3298 dc.DrawImage (ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle, GraphicsUnit.Pixel);
3299 paint_event.SetGraphics (dc);
3300 needs_redraw = false;
3303 XplatUI.PaintEventEnd(Handle);
3305 if (!GetStyle(ControlStyles.UserPaint)) {
3312 case Msg.WM_ERASEBKGND: {
3313 if (GetStyle (ControlStyles.UserPaint)) {
3314 if (!GetStyle(ControlStyles.AllPaintingInWmPaint)) {
3315 PaintEventArgs eraseEventArgs = new PaintEventArgs (m.WParam == IntPtr.Zero ? Graphics.FromHwnd (m.HWnd) :
3316 Graphics.FromHdc (m.WParam), new Rectangle (new Point (0,0),Size));
3317 OnPaintBackground (eraseEventArgs);
3320 XplatUI.EraseWindowBackground(m.HWnd, m.WParam);
3322 // The DefWndProc will never have to handle this, we don't ever set hbr on the window
3323 m.Result = (IntPtr)1;
3327 case Msg.WM_LBUTTONUP: {
3328 HandleClick(mouse_clicks);
3329 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Left,
3331 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3333 if (mouse_clicks > 1) {
3339 case Msg.WM_LBUTTONDOWN: {
3340 if (CanSelect && !is_selected) {
3343 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3344 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3350 case Msg.WM_LBUTTONDBLCLK: {
3352 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3353 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3359 case Msg.WM_MBUTTONUP: {
3360 HandleClick(mouse_clicks);
3361 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Middle,
3363 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3365 if (mouse_clicks > 1) {
3371 case Msg.WM_MBUTTONDOWN: {
3372 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3373 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3379 case Msg.WM_MBUTTONDBLCLK: {
3381 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3382 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3387 case Msg.WM_RBUTTONUP: {
3388 if (context_menu != null) {
3389 context_menu.Show(this, new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ())));
3392 HandleClick(mouse_clicks);
3393 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Right,
3395 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3397 if (mouse_clicks > 1) {
3403 case Msg.WM_RBUTTONDOWN: {
3404 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3405 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3410 case Msg.WM_RBUTTONDBLCLK: {
3412 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3413 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3418 case Msg.WM_MOUSEWHEEL: {
3420 OnMouseWheel (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3421 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3422 HighOrder(m.WParam.ToInt32())));
3427 case Msg.WM_MOUSEMOVE: {
3428 OnMouseMove (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3430 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3435 case Msg.WM_MOUSE_ENTER: {
3440 OnMouseEnter(EventArgs.Empty);
3444 case Msg.WM_MOUSE_LEAVE: {
3446 OnMouseLeave(EventArgs.Empty);
3450 case Msg.WM_MOUSEHOVER: {
3451 OnMouseHover(EventArgs.Empty);
3455 case Msg.WM_SYSKEYDOWN:
3456 case Msg.WM_KEYDOWN:
3457 case Msg.WM_SYSKEYUP:
3459 case Msg.WM_SYSCHAR:
3461 if (ProcessKeyEventArgs(ref m)) {
3465 if (PreProcessMessage(ref m)) {
3469 if (ProcessKeyMessage(ref m)) {
3478 if (m.LParam != IntPtr.Zero) {
3481 hi = new HELPINFO();
3483 hi = (HELPINFO) Marshal.PtrToStructure (m.LParam, typeof (HELPINFO));
3484 mouse_pos = new Point(hi.MousePos.x, hi.MousePos.y);
3486 mouse_pos = Control.MousePosition;
3488 OnHelpRequested(new HelpEventArgs(mouse_pos));
3489 m.Result = (IntPtr)1;
3493 case Msg.WM_KILLFOCUS: {
3494 OnLeave(EventArgs.Empty);
3495 if (CausesValidation) {
3497 e = new CancelEventArgs(false);
3506 OnValidated(EventArgs.Empty);
3509 this.has_focus = false;
3510 this.is_selected = false;
3511 OnLostFocus(EventArgs.Empty);
3515 case Msg.WM_SETFOCUS: {
3516 OnEnter(EventArgs.Empty);
3517 this.has_focus = true;
3518 OnGotFocus(EventArgs.Empty);
3523 case Msg.WM_SYSCOLORCHANGE: {
3524 ThemeEngine.Current.ResetDefaults();
3525 OnSystemColorsChanged(EventArgs.Empty);
3530 case Msg.WM_SETCURSOR: {
3531 if (cursor == null) {
3536 XplatUI.SetCursor(window.Handle, cursor.handle);
3537 m.Result = (IntPtr)1;
3547 #endregion // Public Instance Methods
3549 #region OnXXX methods
3550 [EditorBrowsable(EditorBrowsableState.Advanced)]
3551 protected virtual void OnBackColorChanged(EventArgs e) {
3552 if (BackColorChanged!=null) BackColorChanged(this, e);
3553 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackColorChanged(e);
3556 [EditorBrowsable(EditorBrowsableState.Advanced)]
3557 protected virtual void OnBackgroundImageChanged(EventArgs e) {
3558 if (BackgroundImageChanged!=null) BackgroundImageChanged(this, e);
3559 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackgroundImageChanged(e);
3562 [EditorBrowsable(EditorBrowsableState.Advanced)]
3563 protected virtual void OnBindingContextChanged(EventArgs e) {
3564 CheckDataBindings ();
3565 if (BindingContextChanged!=null) {
3566 BindingContextChanged(this, e);
3568 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBindingContextChanged(e);
3571 [EditorBrowsable(EditorBrowsableState.Advanced)]
3572 protected virtual void OnCausesValidationChanged(EventArgs e) {
3573 if (CausesValidationChanged!=null) CausesValidationChanged(this, e);
3576 [EditorBrowsable(EditorBrowsableState.Advanced)]
3577 protected virtual void OnChangeUICues(UICuesEventArgs e) {
3578 if (ChangeUICues!=null) ChangeUICues(this, e);
3581 [EditorBrowsable(EditorBrowsableState.Advanced)]
3582 protected virtual void OnClick(EventArgs e) {
3583 if (Click!=null) Click(this, e);
3586 [EditorBrowsable(EditorBrowsableState.Advanced)]
3587 protected virtual void OnContextMenuChanged(EventArgs e) {
3588 if (ContextMenuChanged!=null) ContextMenuChanged(this, e);
3591 [EditorBrowsable(EditorBrowsableState.Advanced)]
3592 protected virtual void OnControlAdded(ControlEventArgs e) {
3593 if (ControlAdded!=null) ControlAdded(this, e);
3596 [EditorBrowsable(EditorBrowsableState.Advanced)]
3597 protected virtual void OnControlRemoved(ControlEventArgs e) {
3598 if (ControlRemoved!=null) ControlRemoved(this, e);
3601 [EditorBrowsable(EditorBrowsableState.Advanced)]
3602 protected virtual void OnCreateControl() {
3606 [EditorBrowsable(EditorBrowsableState.Advanced)]
3607 protected virtual void OnCursorChanged(EventArgs e) {
3608 if (CursorChanged!=null) CursorChanged(this, e);
3611 [EditorBrowsable(EditorBrowsableState.Advanced)]
3612 protected virtual void OnDockChanged(EventArgs e) {
3613 if (DockChanged!=null) DockChanged(this, e);
3616 [EditorBrowsable(EditorBrowsableState.Advanced)]
3617 protected virtual void OnDoubleClick(EventArgs e) {
3618 if (DoubleClick!=null) DoubleClick(this, e);
3621 [EditorBrowsable(EditorBrowsableState.Advanced)]
3622 protected virtual void OnDragDrop(DragEventArgs drgevent) {
3623 if (DragDrop!=null) DragDrop(this, drgevent);
3626 [EditorBrowsable(EditorBrowsableState.Advanced)]
3627 protected virtual void OnDragEnter(DragEventArgs drgevent) {
3628 if (DragEnter!=null) DragEnter(this, drgevent);
3631 [EditorBrowsable(EditorBrowsableState.Advanced)]
3632 protected virtual void OnDragLeave(EventArgs e) {
3633 if (DragLeave!=null) DragLeave(this, e);
3636 [EditorBrowsable(EditorBrowsableState.Advanced)]
3637 protected virtual void OnDragOver(DragEventArgs drgevent) {
3638 if (DragOver!=null) DragOver(this, drgevent);
3641 [EditorBrowsable(EditorBrowsableState.Advanced)]
3642 protected virtual void OnEnabledChanged(EventArgs e) {
3643 if (EnabledChanged!=null) EnabledChanged(this, e);
3644 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentEnabledChanged(e);
3647 [EditorBrowsable(EditorBrowsableState.Advanced)]
3648 protected virtual void OnEnter(EventArgs e) {
3649 if (Enter!=null) Enter(this, e);
3652 [EditorBrowsable(EditorBrowsableState.Advanced)]
3653 protected virtual void OnFontChanged(EventArgs e) {
3654 if (FontChanged!=null) FontChanged(this, e);
3655 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentFontChanged(e);
3658 [EditorBrowsable(EditorBrowsableState.Advanced)]
3659 protected virtual void OnForeColorChanged(EventArgs e) {
3660 if (ForeColorChanged!=null) ForeColorChanged(this, e);
3661 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentForeColorChanged(e);
3664 [EditorBrowsable(EditorBrowsableState.Advanced)]
3665 protected virtual void OnGiveFeedback(GiveFeedbackEventArgs gfbevent) {
3666 if (GiveFeedback!=null) GiveFeedback(this, gfbevent);
3669 [EditorBrowsable(EditorBrowsableState.Advanced)]
3670 protected virtual void OnGotFocus(EventArgs e) {
3671 if (GotFocus!=null) GotFocus(this, e);
3674 [EditorBrowsable(EditorBrowsableState.Advanced)]
3675 protected virtual void OnHandleCreated(EventArgs e) {
3676 if (HandleCreated!=null) HandleCreated(this, e);
3679 [EditorBrowsable(EditorBrowsableState.Advanced)]
3680 protected virtual void OnHandleDestroyed(EventArgs e) {
3681 if (HandleDestroyed!=null) HandleDestroyed(this, e);
3684 [EditorBrowsable(EditorBrowsableState.Advanced)]
3685 protected virtual void OnHelpRequested(HelpEventArgs hevent) {
3686 if (HelpRequested!=null) HelpRequested(this, hevent);
3689 protected virtual void OnImeModeChanged(EventArgs e) {
3690 if (ImeModeChanged!=null) ImeModeChanged(this, e);
3693 [EditorBrowsable(EditorBrowsableState.Advanced)]
3694 protected virtual void OnInvalidated(InvalidateEventArgs e) {
3695 needs_redraw = true;
3696 if (Invalidated!=null) Invalidated(this, e);
3699 [EditorBrowsable(EditorBrowsableState.Advanced)]
3700 protected virtual void OnKeyDown(KeyEventArgs e) {
3701 if (KeyDown!=null) KeyDown(this, e);
3704 [EditorBrowsable(EditorBrowsableState.Advanced)]
3705 protected virtual void OnKeyPress(KeyPressEventArgs e) {
3706 if (KeyPress!=null) KeyPress(this, e);
3709 [EditorBrowsable(EditorBrowsableState.Advanced)]
3710 protected virtual void OnKeyUp(KeyEventArgs e) {
3711 if (KeyUp!=null) KeyUp(this, e);
3714 [EditorBrowsable(EditorBrowsableState.Advanced)]
3715 protected virtual void OnLayout(LayoutEventArgs levent) {
3716 if (Layout!=null) Layout(this, levent);
3719 [EditorBrowsable(EditorBrowsableState.Advanced)]
3720 protected virtual void OnLeave(EventArgs e) {
3721 if (Leave!=null) Leave(this, e);
3724 [EditorBrowsable(EditorBrowsableState.Advanced)]
3725 protected virtual void OnLocationChanged(EventArgs e) {
3727 if (LocationChanged!=null) LocationChanged(this, e);
3730 [EditorBrowsable(EditorBrowsableState.Advanced)]
3731 protected virtual void OnLostFocus(EventArgs e) {
3732 if (LostFocus!=null) LostFocus(this, e);
3735 [EditorBrowsable(EditorBrowsableState.Advanced)]
3736 protected virtual void OnMouseDown(MouseEventArgs e) {
3737 if (MouseDown!=null) MouseDown(this, e);
3740 [EditorBrowsable(EditorBrowsableState.Advanced)]
3741 protected virtual void OnMouseEnter(EventArgs e) {
3742 if (MouseEnter!=null) MouseEnter(this, e);
3745 [EditorBrowsable(EditorBrowsableState.Advanced)]
3746 protected virtual void OnMouseHover(EventArgs e) {
3747 if (MouseHover!=null) MouseHover(this, e);
3750 [EditorBrowsable(EditorBrowsableState.Advanced)]
3751 protected virtual void OnMouseLeave(EventArgs e) {
3752 if (MouseLeave!=null) MouseLeave(this, e);
3755 [EditorBrowsable(EditorBrowsableState.Advanced)]
3756 protected virtual void OnMouseMove(MouseEventArgs e) {
3757 if (MouseMove!=null) MouseMove(this, e);
3760 [EditorBrowsable(EditorBrowsableState.Advanced)]
3761 protected virtual void OnMouseUp(MouseEventArgs e) {
3762 if (MouseUp!=null) MouseUp(this, e);
3765 [EditorBrowsable(EditorBrowsableState.Advanced)]
3766 protected virtual void OnMouseWheel(MouseEventArgs e) {
3767 if (MouseWheel!=null) MouseWheel(this, e);
3770 [EditorBrowsable(EditorBrowsableState.Advanced)]
3771 protected virtual void OnMove(EventArgs e) {
3772 if (Move!=null) Move(this, e);
3775 [EditorBrowsable(EditorBrowsableState.Advanced)]
3776 protected virtual void OnNotifyMessage(Message m) {
3780 [EditorBrowsable(EditorBrowsableState.Advanced)]
3781 protected virtual void OnPaint(PaintEventArgs e) {
3782 if (Paint!=null) Paint(this, e);
3785 [EditorBrowsable(EditorBrowsableState.Advanced)]
3786 protected virtual void OnPaintBackground(PaintEventArgs pevent) {
3787 PaintControlBackground (pevent);
3790 [EditorBrowsable(EditorBrowsableState.Advanced)]
3791 protected virtual void OnParentBackColorChanged(EventArgs e) {
3792 if (background_color.IsEmpty && background_image==null) {
3794 OnBackColorChanged(e);
3798 [EditorBrowsable(EditorBrowsableState.Advanced)]
3799 protected virtual void OnParentBackgroundImageChanged(EventArgs e) {
3800 if (background_color.IsEmpty && background_image==null) {
3802 OnBackgroundImageChanged(e);
3806 [EditorBrowsable(EditorBrowsableState.Advanced)]
3807 protected virtual void OnParentBindingContextChanged(EventArgs e) {
3808 if (binding_context==null) {
3809 binding_context=Parent.binding_context;
3810 OnBindingContextChanged(e);
3814 [EditorBrowsable(EditorBrowsableState.Advanced)]
3815 protected virtual void OnParentChanged(EventArgs e) {
3816 if (ParentChanged!=null) ParentChanged(this, e);
3819 [EditorBrowsable(EditorBrowsableState.Advanced)]
3820 protected virtual void OnParentEnabledChanged(EventArgs e) {
3821 if (is_enabled != Parent.is_enabled) {
3822 is_enabled=Parent.is_enabled;
3824 if (EnabledChanged != null) {
3825 EnabledChanged(this, e);
3830 [EditorBrowsable(EditorBrowsableState.Advanced)]
3831 protected virtual void OnParentFontChanged(EventArgs e) {
3838 [EditorBrowsable(EditorBrowsableState.Advanced)]
3839 protected virtual void OnParentForeColorChanged(EventArgs e) {
3840 if (foreground_color.IsEmpty) {
3842 OnForeColorChanged(e);
3846 [EditorBrowsable(EditorBrowsableState.Advanced)]
3847 protected virtual void OnParentRightToLeftChanged(EventArgs e) {
3848 if (right_to_left==RightToLeft.Inherit) {
3850 OnRightToLeftChanged(e);
3854 [EditorBrowsable(EditorBrowsableState.Advanced)]
3855 protected virtual void OnParentVisibleChanged(EventArgs e) {
3857 OnVisibleChanged(e);
3861 [EditorBrowsable(EditorBrowsableState.Advanced)]
3862 protected virtual void OnQueryContinueDrag(QueryContinueDragEventArgs e) {
3863 if (QueryContinueDrag!=null) QueryContinueDrag(this, e);
3866 [EditorBrowsable(EditorBrowsableState.Advanced)]
3867 protected virtual void OnResize(EventArgs e) {
3868 if (Resize!=null) Resize(this, e);
3870 PerformLayout(this, "bounds");
3872 if (parent != null) {
3873 parent.PerformLayout();
3877 [EditorBrowsable(EditorBrowsableState.Advanced)]
3878 protected virtual void OnRightToLeftChanged(EventArgs e) {
3879 if (RightToLeftChanged!=null) RightToLeftChanged(this, e);
3880 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentRightToLeftChanged(e);
3883 [EditorBrowsable(EditorBrowsableState.Advanced)]
3884 protected virtual void OnSizeChanged(EventArgs e) {
3885 InvalidateBuffers ();
3887 if (SizeChanged!=null) SizeChanged(this, e);
3890 [EditorBrowsable(EditorBrowsableState.Advanced)]
3891 protected virtual void OnStyleChanged(EventArgs e) {
3892 if (StyleChanged!=null) StyleChanged(this, e);
3895 [EditorBrowsable(EditorBrowsableState.Advanced)]
3896 protected virtual void OnSystemColorsChanged(EventArgs e) {
3897 if (SystemColorsChanged!=null) SystemColorsChanged(this, e);
3900 [EditorBrowsable(EditorBrowsableState.Advanced)]
3901 protected virtual void OnTabIndexChanged(EventArgs e) {
3902 if (TabIndexChanged!=null) TabIndexChanged(this, e);
3905 [EditorBrowsable(EditorBrowsableState.Advanced)]
3906 protected virtual void OnTabStopChanged(EventArgs e) {
3907 if (TabStopChanged!=null) TabStopChanged(this, e);
3910 [EditorBrowsable(EditorBrowsableState.Advanced)]
3911 protected virtual void OnTextChanged(EventArgs e) {
3912 if (TextChanged!=null) TextChanged(this, e);
3915 [EditorBrowsable(EditorBrowsableState.Advanced)]
3916 protected virtual void OnValidated(EventArgs e) {
3917 if (Validated!=null) Validated(this, e);
3920 [EditorBrowsable(EditorBrowsableState.Advanced)]
3921 protected virtual void OnValidating(System.ComponentModel.CancelEventArgs e) {
3922 if (Validating!=null) Validating(this, e);
3925 [EditorBrowsable(EditorBrowsableState.Advanced)]
3926 protected virtual void OnVisibleChanged(EventArgs e) {
3933 if (bmp_mem!=null) {
3939 if (!this.IsHandleCreated) {
3940 this.CreateControl();
3946 if (VisibleChanged!=null) VisibleChanged(this, e);
3948 // We need to tell our kids
3949 for (int i=0; i<child_controls.Count; i++) {
3950 child_controls[i].OnParentVisibleChanged(e);
3953 #endregion // OnXXX methods
3956 public event EventHandler BackColorChanged;
3957 public event EventHandler BackgroundImageChanged;
3958 public event EventHandler BindingContextChanged;
3959 public event EventHandler CausesValidationChanged;
3960 public event UICuesEventHandler ChangeUICues;
3961 public event EventHandler Click;
3962 public event EventHandler ContextMenuChanged;
3964 [EditorBrowsable(EditorBrowsableState.Advanced)]
3966 public event ControlEventHandler ControlAdded;
3968 [EditorBrowsable(EditorBrowsableState.Advanced)]
3970 public event ControlEventHandler ControlRemoved;
3972 [MWFDescription("Fired when the cursor for the control has been changed"), MWFCategory("PropertyChanged")]
3973 public event EventHandler CursorChanged;
3974 public event EventHandler DockChanged;
3975 public event EventHandler DoubleClick;
3976 public event DragEventHandler DragDrop;
3977 public event DragEventHandler DragEnter;
3978 public event EventHandler DragLeave;
3979 public event DragEventHandler DragOver;
3980 public event EventHandler EnabledChanged;
3981 public event EventHandler Enter;
3982 public event EventHandler FontChanged;
3983 public event EventHandler ForeColorChanged;
3984 public event GiveFeedbackEventHandler GiveFeedback;
3986 [EditorBrowsable(EditorBrowsableState.Advanced)]
3988 public event EventHandler GotFocus;
3990 [EditorBrowsable(EditorBrowsableState.Advanced)]
3992 public event EventHandler HandleCreated;
3994 [EditorBrowsable(EditorBrowsableState.Advanced)]
3996 public event EventHandler HandleDestroyed;
3998 public event HelpEventHandler HelpRequested;
3999 public event EventHandler ImeModeChanged;
4001 [EditorBrowsable(EditorBrowsableState.Advanced)]
4003 public event InvalidateEventHandler Invalidated;
4005 public event KeyEventHandler KeyDown;
4006 public event KeyPressEventHandler KeyPress;
4007 public event KeyEventHandler KeyUp;
4008 public event LayoutEventHandler Layout;
4009 public event EventHandler Leave;
4010 public event EventHandler LocationChanged;
4012 [EditorBrowsable(EditorBrowsableState.Advanced)]
4014 public event EventHandler LostFocus;
4016 public event MouseEventHandler MouseDown;
4017 public event EventHandler MouseEnter;
4018 public event EventHandler MouseHover;
4019 public event EventHandler MouseLeave;
4020 public event MouseEventHandler MouseMove;
4021 public event MouseEventHandler MouseUp;
4023 [EditorBrowsable(EditorBrowsableState.Advanced)]
4025 public event MouseEventHandler MouseWheel;
4027 public event EventHandler Move;
4028 public event PaintEventHandler Paint;
4029 public event EventHandler ParentChanged;
4030 public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp;
4031 public event QueryContinueDragEventHandler QueryContinueDrag;
4032 public event EventHandler Resize;
4033 public event EventHandler RightToLeftChanged;
4034 public event EventHandler SizeChanged;
4035 public event EventHandler StyleChanged;
4036 public event EventHandler SystemColorsChanged;
4037 public event EventHandler TabIndexChanged;
4038 public event EventHandler TabStopChanged;
4039 public event EventHandler TextChanged;
4040 public event EventHandler Validated;
4041 public event CancelEventHandler Validating;
4042 public event EventHandler VisibleChanged;
4043 #endregion // Events