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 public AccessibleRole AccessibleRole {
1054 return AccessibilityObject.role;
1058 AccessibilityObject.role=value;
1062 [DefaultValue(false)]
1063 public virtual bool AllowDrop {
1069 if (allow_drop == value)
1073 XplatUI.SetAllowDrop (Handle, value);
1078 [RefreshProperties(RefreshProperties.Repaint)]
1079 [DefaultValue(AnchorStyles.Top | AnchorStyles.Left)]
1080 public virtual AnchorStyles Anchor {
1082 return anchor_style;
1088 if (parent != null) {
1089 parent.PerformLayout(this, "Parent");
1095 public virtual Color BackColor {
1097 if (background_color.IsEmpty) {
1099 return parent.BackColor;
1101 return DefaultBackColor;
1103 return background_color;
1107 background_color=value;
1108 if (this.IsHandleCreated) {
1109 XplatUI.SetWindowBackground(this.window.Handle, value);
1111 SetChildColor(this);
1112 OnBackColorChanged(EventArgs.Empty);
1118 [DefaultValue(null)]
1119 public virtual Image BackgroundImage {
1121 return background_image;
1125 if (background_image!=value) {
1126 background_image=value;
1127 OnBackgroundImageChanged(EventArgs.Empty);
1132 [EditorBrowsable(EditorBrowsableState.Advanced)]
1134 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1135 public virtual BindingContext BindingContext {
1137 if (binding_context != null)
1138 return binding_context;
1141 binding_context = Parent.BindingContext;
1142 return binding_context;
1145 if (binding_context != value) {
1146 binding_context = value;
1147 OnBindingContextChanged(EventArgs.Empty);
1152 [EditorBrowsable(EditorBrowsableState.Advanced)]
1154 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1157 return bounds.Y+bounds.Height;
1161 [EditorBrowsable(EditorBrowsableState.Advanced)]
1163 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1164 public Rectangle Bounds {
1170 SetBoundsCore(value.Left, value.Top, value.Width, value.Height, BoundsSpecified.All);
1174 [EditorBrowsable(EditorBrowsableState.Advanced)]
1176 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1177 public bool CanFocus {
1179 if (Visible && is_enabled && GetStyle(ControlStyles.Selectable)) {
1186 [EditorBrowsable(EditorBrowsableState.Advanced)]
1188 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1189 public bool CanSelect {
1193 if (!GetStyle(ControlStyles.Selectable) || this.parent == null) {
1197 parent = this.parent;
1198 while (parent != null) {
1199 if (!parent.is_visible || !parent.is_enabled) {
1203 parent = parent.parent;
1209 [EditorBrowsable(EditorBrowsableState.Advanced)]
1211 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1212 public bool Capture {
1214 return this.is_captured;
1218 if (this.IsHandleCreated) {
1219 if (value && !is_captured) {
1221 XplatUI.GrabWindow(this.window.Handle, IntPtr.Zero);
1222 } else if (!value && is_captured) {
1223 XplatUI.UngrabWindow(this.window.Handle);
1224 is_captured = false;
1230 [DefaultValue(true)]
1231 public bool CausesValidation {
1233 return this.causes_validation;
1237 if (this.causes_validation != value) {
1238 causes_validation = value;
1239 OnCausesValidationChanged(EventArgs.Empty);
1244 [EditorBrowsable(EditorBrowsableState.Advanced)]
1246 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1247 public Rectangle ClientRectangle {
1249 client_rect.Width = client_size.Width;
1250 client_rect.Height = client_size.Height;
1255 [EditorBrowsable(EditorBrowsableState.Advanced)]
1257 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1258 public Size ClientSize {
1261 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1262 return ((Form)this).form_parent_window.ClientSize;
1270 this.SetClientSizeCore(value.Width, value.Height);
1274 [EditorBrowsable(EditorBrowsableState.Advanced)]
1276 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1277 [DescriptionAttribute("ControlCompanyNameDescr")]
1278 public String CompanyName {
1280 return "Mono Project, Novell, Inc.";
1284 [EditorBrowsable(EditorBrowsableState.Advanced)]
1286 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1287 public bool ContainsFocus {
1293 for (int i=0; i < child_controls.Count; i++) {
1294 if (child_controls[i].ContainsFocus) {
1302 [DefaultValue(null)]
1303 public virtual ContextMenu ContextMenu {
1305 return context_menu;
1309 if (context_menu != value) {
1310 context_menu = value;
1311 OnContextMenuChanged(EventArgs.Empty);
1317 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
1318 public ControlCollection Controls {
1320 return this.child_controls;
1324 [EditorBrowsable(EditorBrowsableState.Advanced)]
1326 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1327 public bool Created {
1329 if (!this.is_disposed && (this.window.Handle != IntPtr.Zero)) {
1336 [AmbientValue(null)]
1337 public virtual Cursor Cursor {
1339 if (cursor != null) {
1343 if (parent != null) {
1344 return parent.Cursor;
1347 return Cursors.Default;
1351 if (cursor != value) {
1356 pt = Cursor.Position;
1357 if (bounds.Contains(pt)) {
1358 if (GetChildAtPoint(pt) == null) {
1359 if (cursor != null) {
1360 XplatUI.SetCursor(window.Handle, cursor.handle);
1362 if (parent != null) {
1363 XplatUI.SetCursor(window.Handle, parent.Cursor.handle);
1365 XplatUI.SetCursor(window.Handle, Cursors.def.handle);
1371 OnCursorChanged(EventArgs.Empty);
1377 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
1378 [ParenthesizePropertyName(true)]
1379 [RefreshProperties(RefreshProperties.All)]
1380 public ControlBindingsCollection DataBindings {
1382 if (data_bindings == null)
1383 data_bindings = new ControlBindingsCollection (this);
1384 return data_bindings;
1388 [EditorBrowsable(EditorBrowsableState.Advanced)]
1390 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1391 public virtual Rectangle DisplayRectangle {
1393 return ClientRectangle;
1397 [EditorBrowsable(EditorBrowsableState.Advanced)]
1399 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1400 public bool Disposing {
1407 [RefreshProperties(RefreshProperties.Repaint)]
1408 [DefaultValue(DockStyle.None)]
1409 public virtual DockStyle Dock {
1415 if (dock_style == value) {
1421 if (parent != null) {
1422 parent.PerformLayout(this, "Parent");
1425 OnDockChanged(EventArgs.Empty);
1431 public bool Enabled {
1437 if (is_enabled == value) {
1443 OnEnabledChanged (EventArgs.Empty);
1447 [EditorBrowsable(EditorBrowsableState.Advanced)]
1449 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1450 public virtual bool Focused {
1452 return this.has_focus;
1457 [AmbientValue(null)]
1459 public virtual Font Font {
1465 if (Parent != null && Parent.Font != null) {
1473 if (font != null && font.Equals (value)) {
1479 OnFontChanged (EventArgs.Empty);
1484 public virtual Color ForeColor {
1486 if (foreground_color.IsEmpty) {
1488 return parent.ForeColor;
1490 return DefaultForeColor;
1492 return foreground_color;
1496 if (foreground_color != value) {
1497 foreground_color=value;
1499 OnForeColorChanged(EventArgs.Empty);
1506 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1507 public IntPtr Handle { // IWin32Window
1509 if (!IsHandleCreated) {
1512 return window.Handle;
1516 [EditorBrowsable(EditorBrowsableState.Advanced)]
1518 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1519 public bool HasChildren {
1521 if (this.child_controls.Count>0) {
1528 [EditorBrowsable(EditorBrowsableState.Always)]
1530 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1533 return this.bounds.Height;
1537 SetBoundsCore(bounds.X, bounds.Y, bounds.Width, value, BoundsSpecified.Height);
1541 [AmbientValue(ImeMode.Inherit)]
1543 public ImeMode ImeMode {
1549 if (ime_mode != value) {
1552 OnImeModeChanged(EventArgs.Empty);
1557 [EditorBrowsable(EditorBrowsableState.Advanced)]
1559 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1560 public bool InvokeRequired { // ISynchronizeInvoke
1562 if (creator_thread!=Thread.CurrentThread) {
1569 [EditorBrowsable(EditorBrowsableState.Advanced)]
1571 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1572 public bool IsAccessible {
1574 return is_accessible;
1578 is_accessible = value;
1582 [EditorBrowsable(EditorBrowsableState.Advanced)]
1584 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1585 public bool IsDisposed {
1587 return this.is_disposed;
1591 [EditorBrowsable(EditorBrowsableState.Advanced)]
1593 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1594 public bool IsHandleCreated {
1596 if ((window!=null) && (window.Handle!=IntPtr.Zero)) {
1604 [EditorBrowsable(EditorBrowsableState.Always)]
1606 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1609 return this.bounds.X;
1613 SetBoundsCore(value, bounds.Y, bounds.Width, bounds.Height, BoundsSpecified.X);
1618 public Point Location {
1620 return new Point(bounds.X, bounds.Y);
1624 SetBoundsCore(value.X, value.Y, bounds.Width, bounds.Height, BoundsSpecified.Location);
1629 public string Name {
1640 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1641 public Control Parent {
1647 if (value == this) {
1648 throw new ArgumentException("A circular control reference has been made. A control cannot be owned or parented to itself.");
1651 if (parent!=value) {
1653 parent.Controls.Remove(this);
1659 if (!parent.Controls.Contains(this)) {
1660 parent.Controls.Add(this);
1663 XplatUI.SetParent(Handle, value.Handle);
1667 OnParentChanged(EventArgs.Empty);
1672 [EditorBrowsable(EditorBrowsableState.Advanced)]
1674 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1675 public string ProductName {
1677 Type t = typeof (AssemblyProductAttribute);
1678 Assembly assembly = GetType().Module.Assembly;
1679 object [] attrs = assembly.GetCustomAttributes (t, false);
1680 AssemblyProductAttribute a = null;
1681 // On MS we get a NullRefException if product attribute is not
1683 if (attrs != null && attrs.Length > 0)
1684 a = (AssemblyProductAttribute) attrs [0];
1689 [EditorBrowsable(EditorBrowsableState.Advanced)]
1691 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1692 public string ProductVersion {
1694 Type t = typeof (AssemblyVersionAttribute);
1695 Assembly assembly = GetType().Module.Assembly;
1696 object [] attrs = assembly.GetCustomAttributes (t, false);
1697 if (attrs == null || attrs.Length < 1)
1699 return ((AssemblyVersionAttribute)attrs [0]).Version;
1703 [EditorBrowsable(EditorBrowsableState.Advanced)]
1705 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1706 public bool RecreatingHandle {
1708 return is_recreating;
1712 [EditorBrowsable(EditorBrowsableState.Advanced)]
1714 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1715 public Region Region {
1717 return new Region(this.bounds);
1724 g = this.CreateGraphics();
1725 r = value.GetBounds(g);
1727 SetBounds((int)r.X, (int)r.Y, (int)r.Width, (int)r.Height);
1733 [EditorBrowsable(EditorBrowsableState.Advanced)]
1735 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1738 return this.bounds.X+this.bounds.Width;
1742 [AmbientValue(RightToLeft.Inherit)]
1744 public virtual RightToLeft RightToLeft {
1746 return right_to_left;
1750 if (value != right_to_left) {
1751 right_to_left = value;
1752 OnRightToLeftChanged(EventArgs.Empty);
1757 [EditorBrowsable(EditorBrowsableState.Advanced)]
1758 public override ISite Site {
1771 return new Size(Width, Height);
1775 SetBoundsCore(bounds.X, bounds.Y, value.Width, value.Height, BoundsSpecified.Size);
1780 [MergableProperty(false)]
1781 public int TabIndex {
1783 if (tab_index != -1) {
1790 if (tab_index != value) {
1792 OnTabIndexChanged(EventArgs.Empty);
1798 [DefaultValue(true)]
1799 public bool TabStop {
1805 if (tab_stop != value) {
1807 OnTabStopChanged(EventArgs.Empty);
1812 [Localizable(false)]
1814 [TypeConverter(typeof(StringConverter))]
1815 [DefaultValue(null)]
1822 control_tag = value;
1828 [BindableAttribute(true)]
1829 public virtual string Text {
1835 if (value == null) {
1836 value = String.Empty;
1841 XplatUI.Text(Handle, text);
1842 // FIXME: Do we need a Refresh() here?
1843 OnTextChanged (EventArgs.Empty);
1848 [EditorBrowsable(EditorBrowsableState.Always)]
1850 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1853 return this.bounds.Y;
1857 SetBoundsCore(bounds.X, value, bounds.Width, bounds.Height, BoundsSpecified.Y);
1861 [EditorBrowsable(EditorBrowsableState.Advanced)]
1863 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1864 public Control TopLevelControl {
1868 while (p.parent != null) {
1877 public bool Visible {
1881 } else if (parent != null) {
1882 return parent.Visible;
1889 SetVisibleCore(value);
1893 [EditorBrowsable(EditorBrowsableState.Always)]
1895 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1898 return this.bounds.Width;
1902 SetBoundsCore(bounds.X, bounds.Y, value, bounds.Height, BoundsSpecified.Width);
1906 [EditorBrowsable(EditorBrowsableState.Never)]
1908 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1909 public IWindowTarget WindowTarget {
1918 #endregion // Public Instance Properties
1920 #region Protected Instance Properties
1921 protected virtual CreateParams CreateParams {
1923 CreateParams create_params = new CreateParams();
1926 create_params.Caption = Text;
1929 create_params.Caption = text;
1933 create_params.X = Left;
1936 create_params.X = this.bounds.X;
1940 create_params.Y = Top;
1943 create_params.Y = this.bounds.Y;
1947 create_params.Width = Width;
1950 create_params.Width = this.bounds.Width;
1954 create_params.Height = Height;
1957 create_params.Height = this.bounds.Height;
1961 create_params.ClassName = XplatUI.DefaultClassName;
1962 create_params.ClassStyle = 0;
1963 create_params.ExStyle = 0;
1964 create_params.Param = 0;
1967 create_params.ExStyle |= (int)WindowStyles.WS_EX_ACCEPTFILES;
1971 create_params.Parent = parent.Handle;
1974 create_params.Style = (int)WindowStyles.WS_CHILD | (int)WindowStyles.WS_CLIPCHILDREN | (int)WindowStyles.WS_CLIPSIBLINGS;
1977 create_params.Style |= (int)WindowStyles.WS_VISIBLE;
1980 return create_params;
1984 protected virtual ImeMode DefaultImeMode {
1986 return ImeMode.Inherit;
1990 protected virtual Size DefaultSize {
1992 return new Size(100, 23);
1996 protected int FontHeight {
2006 protected bool RenderRightToLeft {
2008 return (this.right_to_left == RightToLeft.Yes);
2012 protected bool ResizeRedraw {
2014 return GetStyle(ControlStyles.ResizeRedraw);
2018 SetStyle(ControlStyles.ResizeRedraw, value);
2022 [EditorBrowsable(EditorBrowsableState.Advanced)]
2024 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2025 protected virtual bool ShowFocusCues {
2031 [EditorBrowsable(EditorBrowsableState.Advanced)]
2033 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2034 protected bool ShowKeyboardCues {
2039 #endregion // Protected Instance Properties
2041 #region Public Static Methods
2042 [EditorBrowsable(EditorBrowsableState.Advanced)]
2043 public static Control FromChildHandle(IntPtr handle) {
2044 IEnumerator control = Control.controls.GetEnumerator();
2046 while (control.MoveNext()) {
2047 if (((Control)control.Current).window.Handle == handle) {
2049 if (((Control)control.Current).Parent != null) {
2050 return ((Control)control.Current).Parent;
2057 [EditorBrowsable(EditorBrowsableState.Advanced)]
2058 public static Control FromHandle(IntPtr handle) {
2059 IEnumerator control = Control.controls.GetEnumerator();
2061 while (control.MoveNext()) {
2062 if (((Control)control.Current).window.Handle == handle) {
2064 return ((Control)control.Current);
2070 public static bool IsMnemonic(char charCode, string text) {
2073 amp = text.IndexOf('&');
2076 if (amp + 1 < text.Length) {
2077 if (text[amp + 1] != '&') {
2078 if (Char.ToUpper(charCode) == Char.ToUpper(text.ToCharArray(amp + 1, 1)[0])) {
2088 #region Protected Static Methods
2089 [EditorBrowsable(EditorBrowsableState.Advanced)]
2090 protected static bool ReflectMessage(IntPtr hWnd, ref Message m) {
2093 c = Control.FromHandle(hWnd);
2103 #region Public Instance Methods
2104 [EditorBrowsable(EditorBrowsableState.Advanced)]
2105 public IAsyncResult BeginInvoke(Delegate method) {
2106 return BeginInvokeInternal(method, null);
2109 [EditorBrowsable(EditorBrowsableState.Advanced)]
2110 public IAsyncResult BeginInvoke (Delegate method, object[] args) {
2111 return BeginInvokeInternal (method, args);
2114 public void BringToFront() {
2115 if ((parent != null) && (parent.child_controls[0]!=this)) {
2116 if (parent.child_controls.Contains(this)) {
2117 parent.child_controls.SetChildIndex(this, 0);
2121 XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, true, false);
2123 if (parent != null) {
2128 public bool Contains(Control ctl) {
2129 while (ctl != null) {
2138 public void CreateControl() {
2140 if (!IsHandleCreated) {
2144 if (!create_handled) {
2145 create_handled = true;
2149 for (int i=0; i<child_controls.Count; i++) {
2150 child_controls[i].CreateControl();
2154 public Graphics CreateGraphics() {
2155 if (!IsHandleCreated) {
2156 this.CreateControl();
2158 return Graphics.FromHwnd(this.window.Handle);
2161 public DragDropEffects DoDragDrop(object data, DragDropEffects allowedEffects) {
2162 return XplatUI.StartDrag(this.window.Handle, data, allowedEffects);
2165 [EditorBrowsable(EditorBrowsableState.Advanced)]
2166 public object EndInvoke (IAsyncResult async_result) {
2167 AsyncMethodResult result = (AsyncMethodResult) async_result;
2168 return result.EndInvoke ();
2171 public Form FindForm() {
2184 public bool Focus() {
2185 if (IsHandleCreated && !has_focus) {
2187 XplatUI.SetFocus(window.Handle);
2192 public Control GetChildAtPoint(Point pt) {
2193 // Microsoft's version of this function doesn't seem to work, so I can't check
2194 // if we only consider children or also grandchildren, etc.
2195 // I'm gonna say 'children only'
2196 for (int i=0; i<child_controls.Count; i++) {
2197 if (child_controls[i].Bounds.Contains(pt)) {
2198 return child_controls[i];
2204 public IContainerControl GetContainerControl() {
2205 Control current = this;
2207 while (current!=null) {
2208 if ((current is IContainerControl) && ((current.control_style & ControlStyles.ContainerControl)!=0)) {
2209 return (IContainerControl)current;
2211 current = current.parent;
2216 public Control GetNextControl(Control ctl, bool forward) {
2217 // If we're not a container we don't play
2218 if (!(this is IContainerControl) && !this.GetStyle(ControlStyles.ContainerControl)) {
2222 // If ctl is not contained by this, we start at the first child of this
2223 if (!this.Contains(ctl)) {
2227 // Search through our controls, starting at ctl, stepping into children as we encounter them
2228 // try to find the control with the tabindex closest to our own, or, if we're looking into
2229 // child controls, the one with the smallest tabindex
2231 return FindControlForward(this, ctl);
2233 return FindControlBackward(this, ctl);
2236 public void Hide() {
2237 this.Visible = false;
2240 public void Invalidate() {
2241 Invalidate(ClientRectangle, false);
2244 public void Invalidate(bool invalidateChildren) {
2245 Invalidate(ClientRectangle, invalidateChildren);
2248 public void Invalidate(System.Drawing.Rectangle rc) {
2249 Invalidate(rc, false);
2252 public void Invalidate(System.Drawing.Rectangle rc, bool invalidateChildren) {
2253 if (!IsHandleCreated || !Visible) {
2257 NotifyInvalidate(rc);
2259 XplatUI.Invalidate(Handle, rc, false);
2261 if (invalidateChildren) {
2262 for (int i=0; i<child_controls.Count; i++) child_controls[i].Invalidate();
2264 OnInvalidated(new InvalidateEventArgs(rc));
2267 public void Invalidate(System.Drawing.Region region) {
2268 Invalidate(region, false);
2271 [MonoTODO("Figure out if GetRegionScans is usable")]
2272 public void Invalidate(System.Drawing.Region region, bool invalidateChildren) {
2273 throw new NotImplementedException();
2275 // FIXME - should use the GetRegionScans function of the region to invalidate each area
2276 //if (invalidateChildren) {
2277 // for (int i=0; i<child_controls.Count; i++) child_controls[i].Invalidate();
2281 public object Invoke (Delegate method) {
2282 return Invoke(method, null);
2285 public object Invoke (Delegate method, object[] args) {
2286 if (!this.InvokeRequired) {
2287 return method.DynamicInvoke(args);
2290 IAsyncResult result = BeginInvoke (method, args);
2291 return EndInvoke(result);
2294 [EditorBrowsable(EditorBrowsableState.Advanced)]
2295 public void PerformLayout() {
2296 PerformLayout(null, null);
2299 [EditorBrowsable(EditorBrowsableState.Advanced)]
2300 public void PerformLayout(Control affectedControl, string affectedProperty) {
2301 LayoutEventArgs levent = new LayoutEventArgs(affectedControl, affectedProperty);
2303 if (layout_suspended>0) {
2304 layout_pending = true;
2308 layout_pending = false;
2310 // Prevent us from getting messed up
2313 // Perform all Dock and Anchor calculations
2316 AnchorStyles anchor;
2321 space=this.DisplayRectangle;
2322 if (prev_size != Size.Empty) {
2323 diff_width = space.Width - prev_size.Width;
2324 diff_height = space.Height - prev_size.Height;
2330 // Deal with docking; go through in reverse, MS docs say that lowest Z-order is closest to edge
2331 for (int i = child_controls.Count - 1; i >= 0; i--) {
2332 child=child_controls[i];
2333 switch (child.Dock) {
2334 case DockStyle.None: {
2339 case DockStyle.Left: {
2340 child.SetBounds(space.Left, space.Y, child.Width, space.Height);
2341 space.X+=child.Width;
2342 space.Width-=child.Width;
2346 case DockStyle.Top: {
2347 child.SetBounds(space.Left, space.Y, space.Width, child.Height);
2348 space.Y+=child.Height;
2349 space.Height-=child.Height;
2353 case DockStyle.Right: {
2354 child.SetBounds(space.Right-child.Width, space.Y, child.Width, space.Height);
2355 space.Width-=child.Width;
2359 case DockStyle.Bottom: {
2360 child.SetBounds(space.Left, space.Bottom-child.Height, space.Width, child.Height);
2361 space.Height-=child.Height;
2367 for (int i = child_controls.Count - 1; i >= 0; i--) {
2368 child=child_controls[i];
2370 if (child.Dock == DockStyle.Fill) {
2371 child.SetBounds(space.Left, space.Top, space.Width, space.Height);
2377 space=this.DisplayRectangle;
2379 // Deal with anchoring
2380 for (int i=0; i < child_controls.Count; i++) {
2386 child=child_controls[i];
2387 anchor=child.Anchor;
2392 height=child.Height;
2394 // If the control is docked we don't need to do anything
2395 if (child.Dock != DockStyle.None) {
2399 if ((anchor & AnchorStyles.Left) !=0 ) {
2400 if ((anchor & AnchorStyles.Right) != 0) {
2401 // Anchoring to left and right
2402 width=width+diff_width;
2406 } else if ((anchor & AnchorStyles.Right) != 0) {
2412 if ((anchor & AnchorStyles.Top) !=0 ) {
2413 if ((anchor & AnchorStyles.Bottom) != 0) {
2414 height+=diff_height;
2418 } else if ((anchor & AnchorStyles.Bottom) != 0) {
2433 child.SetBounds(left, top, width, height);
2436 // Let everyone know
2440 // Need to make sure we decremend layout_suspended
2446 public Point PointToClient (Point p) {
2450 XplatUI.ScreenToClient (Handle, ref x, ref y);
2452 return new Point (x, y);
2455 public Point PointToScreen(Point p) {
2459 XplatUI.ClientToScreen(Handle, ref x, ref y);
2461 return new Point(x, y);
2464 public virtual bool PreProcessMessage(ref Message msg) {
2467 if ((msg.Msg == (int)Msg.WM_KEYDOWN) || (msg.Msg == (int)Msg.WM_SYSKEYDOWN)) {
2468 key_data = (Keys)msg.WParam.ToInt32();
2469 if (!ProcessCmdKey(ref msg, key_data)) {
2470 if (IsInputKey(key_data)) {
2474 return ProcessDialogKey(key_data);
2478 } else if (msg.Msg == (int)Msg.WM_CHAR) {
2479 if (IsInputChar((char)msg.WParam)) {
2482 } else if (msg.Msg == (int)Msg.WM_SYSCHAR) {
2483 if (IsInputChar((char)msg.WParam)) {
2486 return ProcessDialogChar((char)msg.WParam);
2491 public Rectangle RectangleToClient(Rectangle r) {
2492 return new Rectangle(PointToClient(r.Location), r.Size);
2495 public Rectangle RectangleToScreen(Rectangle r) {
2496 return new Rectangle(PointToScreen(r.Location), r.Size);
2499 public virtual void Refresh() {
2500 if (IsHandleCreated == true) {
2502 XplatUI.UpdateWindow(window.Handle);
2506 [EditorBrowsable(EditorBrowsableState.Never)]
2507 public virtual void ResetBackColor() {
2508 background_color = Color.Empty;
2511 [EditorBrowsable(EditorBrowsableState.Never)]
2513 public void ResetBindings() {
2517 [EditorBrowsable(EditorBrowsableState.Never)]
2518 public virtual void ResetCursor() {
2522 [EditorBrowsable(EditorBrowsableState.Never)]
2523 public virtual void ResetFont() {
2527 [EditorBrowsable(EditorBrowsableState.Never)]
2528 public virtual void ResetForeColor() {
2529 foreground_color = Color.Empty;
2532 [EditorBrowsable(EditorBrowsableState.Never)]
2533 public void ResetImeMode() {
2534 ime_mode = DefaultImeMode;
2537 [EditorBrowsable(EditorBrowsableState.Never)]
2538 public virtual void ResetRightToLeft() {
2539 right_to_left = RightToLeft.Inherit;
2542 public virtual void ResetText() {
2546 public void ResumeLayout() {
2547 ResumeLayout (true);
2550 public void ResumeLayout(bool performLayout) {
2553 if (layout_suspended > 0) {
2557 if (performLayout || layout_pending) {
2562 public void Scale(float ratio) {
2563 ScaleCore(ratio, ratio);
2566 public void Scale(float dx, float dy) {
2570 public void Select() {
2571 Select(false, false);
2574 public bool SelectNextControl(Control ctl, bool forward, bool tabStopOnly, bool nested, bool wrap) {
2579 c = GetNextControl(c, forward);
2588 if (c.CanSelect && ((c.parent == ctl.parent) || nested) && (c.tab_stop || !tabStopOnly)) {
2592 } while (c != ctl); // If we wrap back to ourselves we stop
2597 public void SendToBack() {
2598 if ((parent != null) && (parent.child_controls[parent.child_controls.Count-1]!=this)) {
2599 if (parent.child_controls.Contains(this)) {
2600 parent.child_controls.SetChildIndex(this, parent.child_controls.Count);
2604 XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, false, true);
2605 if (parent != null) {
2610 public void SetBounds(int x, int y, int width, int height) {
2611 SetBoundsCore(x, y, width, height, BoundsSpecified.All);
2614 public void SetBounds(int x, int y, int width, int height, BoundsSpecified specified) {
2615 SetBoundsCore(x, y, width, height, specified);
2618 public void Show() {
2619 if (!IsHandleCreated) {
2620 this.CreateControl();
2626 public void SuspendLayout() {
2630 public void Update() {
2631 needs_redraw = true;
2632 XplatUI.UpdateWindow(window.Handle);
2634 #endregion // Public Instance Methods
2636 #region Protected Instance Methods
2637 [EditorBrowsable(EditorBrowsableState.Advanced)]
2638 [MonoTODO("Implement this and tie it into Control.ControlAccessibleObject.NotifyClients")]
2639 protected void AccessibilityNotifyClients(AccessibleEvents accEvent, int childID) {
2640 throw new NotImplementedException();
2643 [EditorBrowsable(EditorBrowsableState.Advanced)]
2644 protected virtual AccessibleObject CreateAccessibilityInstance() {
2645 return new Control.ControlAccessibleObject(this);
2648 [EditorBrowsable(EditorBrowsableState.Advanced)]
2649 protected virtual ControlCollection CreateControlsInstance() {
2650 return new ControlCollection(this);
2653 [EditorBrowsable(EditorBrowsableState.Advanced)]
2654 protected virtual void CreateHandle() {
2656 throw new ObjectDisposedException(Name);
2659 if (IsHandleCreated) {
2663 window.CreateHandle(CreateParams);
2665 // Find out where the window manager placed us
2669 if (window.Handle!=IntPtr.Zero) {
2670 if (!controls.Contains(window.Handle)) {
2674 creator_thread = Thread.CurrentThread;
2676 XplatUI.SetWindowBackground(window.Handle, this.BackColor);
2678 OnHandleCreated(EventArgs.Empty);
2682 [EditorBrowsable(EditorBrowsableState.Advanced)]
2683 protected virtual void DefWndProc(ref Message m) {
2684 window.DefWndProc(ref m);
2687 [EditorBrowsable(EditorBrowsableState.Advanced)]
2688 protected virtual void DestroyHandle() {
2689 if (IsHandleCreated) {
2690 // Destroy our children before we destroy ourselves, to prevent them from
2691 // being implictly (without us knowing) destroyed
2692 for (int i=0; i < child_controls.Count; i++) {
2693 child_controls[i].DestroyHandle();
2697 if (window != null) {
2698 window.DestroyHandle();
2700 OnHandleDestroyed(EventArgs.Empty);
2704 protected bool GetStyle(ControlStyles flag) {
2705 return (control_style & flag) != 0;
2708 protected bool GetTopLevel() {
2712 [EditorBrowsable(EditorBrowsableState.Advanced)]
2713 protected virtual void InitLayout() {
2714 if (parent != null) {
2715 parent.PerformLayout(this, "parent");
2719 [EditorBrowsable(EditorBrowsableState.Advanced)]
2720 protected void InvokeGotFocus(Control toInvoke, EventArgs e) {
2721 toInvoke.OnGotFocus(e);
2724 [EditorBrowsable(EditorBrowsableState.Advanced)]
2725 protected void InvokeLostFocus(Control toInvoke, EventArgs e) {
2726 toInvoke.OnLostFocus(e);
2729 [EditorBrowsable(EditorBrowsableState.Advanced)]
2730 protected void InvokeOnClick(Control toInvoke, EventArgs e) {
2731 toInvoke.OnClick(e);
2734 protected void InvokePaint(Control toInvoke, PaintEventArgs e) {
2735 toInvoke.OnPaint(e);
2738 protected void InvokePaintBackground(Control toInvoke, PaintEventArgs e) {
2739 toInvoke.OnPaintBackground(e);
2742 protected virtual bool IsInputChar (char charCode) {
2743 if (parent != null) {
2744 return parent.IsInputChar(charCode);
2750 protected virtual bool IsInputKey (Keys keyData) {
2751 // Doc says this one calls IsInputChar; not sure what to do with that
2755 [EditorBrowsable(EditorBrowsableState.Advanced)]
2756 protected virtual void NotifyInvalidate(Rectangle invalidatedArea) {
2760 protected virtual bool ProcessCmdKey(ref Message msg, Keys keyData) {
2761 if ((context_menu != null) && context_menu.ProcessCmdKey(ref msg, keyData)) {
2765 if (parent != null) {
2766 return parent.ProcessCmdKey(ref msg, keyData);
2772 protected virtual bool ProcessDialogChar(char charCode) {
2773 if (parent != null) {
2774 return parent.ProcessDialogChar (charCode);
2780 protected virtual bool ProcessDialogKey (Keys keyData) {
2781 if (parent != null) {
2782 return parent.ProcessDialogKey (keyData);
2788 protected virtual bool ProcessKeyEventArgs (ref Message msg)
2790 KeyEventArgs key_event;
2793 case (int)Msg.WM_KEYDOWN: {
2794 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
2795 OnKeyDown (key_event);
2796 return key_event.Handled;
2798 case (int)Msg.WM_KEYUP: {
2799 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
2800 OnKeyUp (key_event);
2801 return key_event.Handled;
2804 case (int)Msg.WM_CHAR: {
2805 KeyPressEventArgs key_press_event;
2807 key_press_event = new KeyPressEventArgs((char)msg.WParam);
2808 OnKeyPress(key_press_event);
2809 return key_press_event.Handled;
2820 protected internal virtual bool ProcessKeyMessage(ref Message msg) {
2821 if (parent != null) {
2822 if (parent.ProcessKeyPreview(ref msg)) {
2830 protected virtual bool ProcessKeyPreview(ref Message msg) {
2831 if (parent != null) {
2832 return parent.ProcessKeyPreview(ref msg);
2838 protected virtual bool ProcessMnemonic(char charCode) {
2843 [EditorBrowsable(EditorBrowsableState.Advanced)]
2844 protected void RaiseDragEvent(object key, DragEventArgs e) {
2848 [EditorBrowsable(EditorBrowsableState.Advanced)]
2849 protected void RaiseKeyEvent(object key, KeyEventArgs e) {
2853 [EditorBrowsable(EditorBrowsableState.Advanced)]
2854 protected void RaiseMouseEvent(object key, MouseEventArgs e) {
2858 [EditorBrowsable(EditorBrowsableState.Advanced)]
2859 protected void RaisePaintEvent(object key, PaintEventArgs e) {
2863 [EditorBrowsable(EditorBrowsableState.Advanced)]
2864 protected void RecreateHandle() {
2865 IEnumerator child = child_controls.GetEnumerator();
2869 if (IsHandleCreated) {
2875 while (child.MoveNext()) {
2876 ((Control)child.Current).RecreateHandle();
2882 is_recreating = false;
2885 [EditorBrowsable(EditorBrowsableState.Advanced)]
2886 protected void ResetMouseEventArgs() {
2890 [EditorBrowsable(EditorBrowsableState.Advanced)]
2891 protected ContentAlignment RtlTranslateAlignment(ContentAlignment align) {
2892 if (right_to_left == RightToLeft.No) {
2897 case ContentAlignment.TopLeft: {
2898 return ContentAlignment.TopRight;
2901 case ContentAlignment.TopRight: {
2902 return ContentAlignment.TopLeft;
2905 case ContentAlignment.MiddleLeft: {
2906 return ContentAlignment.MiddleRight;
2909 case ContentAlignment.MiddleRight: {
2910 return ContentAlignment.MiddleLeft;
2913 case ContentAlignment.BottomLeft: {
2914 return ContentAlignment.BottomRight;
2917 case ContentAlignment.BottomRight: {
2918 return ContentAlignment.BottomLeft;
2922 // if it's center it doesn't change
2928 [EditorBrowsable(EditorBrowsableState.Advanced)]
2929 protected HorizontalAlignment RtlTranslateAlignment(HorizontalAlignment align) {
2930 if ((right_to_left == RightToLeft.No) || (align == HorizontalAlignment.Center)) {
2934 if (align == HorizontalAlignment.Left) {
2935 return HorizontalAlignment.Right;
2938 // align must be HorizontalAlignment.Right
2939 return HorizontalAlignment.Left;
2942 [EditorBrowsable(EditorBrowsableState.Advanced)]
2943 protected LeftRightAlignment RtlTranslateAlignment(LeftRightAlignment align) {
2944 if (right_to_left == RightToLeft.No) {
2948 if (align == LeftRightAlignment.Left) {
2949 return LeftRightAlignment.Right;
2952 // align must be LeftRightAlignment.Right;
2953 return LeftRightAlignment.Left;
2956 [EditorBrowsable(EditorBrowsableState.Advanced)]
2957 protected ContentAlignment RtlTranslateContent(ContentAlignment align) {
2958 return RtlTranslateAlignment(align);
2961 [EditorBrowsable(EditorBrowsableState.Advanced)]
2962 protected HorizontalAlignment RtlTranslateHorizontal(HorizontalAlignment align) {
2963 return RtlTranslateAlignment(align);
2966 [EditorBrowsable(EditorBrowsableState.Advanced)]
2967 protected LeftRightAlignment RtlTranslateLeftRight(LeftRightAlignment align) {
2968 return RtlTranslateAlignment(align);
2971 [EditorBrowsable(EditorBrowsableState.Advanced)]
2972 protected virtual void ScaleCore(float dx, float dy) {
2978 location = new Point((int)(Left * dx), (int)(Top * dy));
2979 size = this.ClientSize;
2982 if (!GetStyle(ControlStyles.FixedWidth)) {
2983 size.Width = (int)(size.Width * dx);
2986 if (!GetStyle(ControlStyles.FixedHeight)) {
2987 size.Height = (int)(size.Height * dy);
2990 Location = location;
2993 /* Now scale our children */
2994 for (int i=0; i < child_controls.Count; i++) {
2995 child_controls[i].Scale(dx, dy);
3001 protected virtual void Select(bool directed, bool forward) {
3006 // Select this control
3011 if (parent == null) {
3015 // FIXME - this thing is doing the wrong stuff, needs to be similar to SelectNextControl
3017 index = parent.child_controls.IndexOf(this);
3022 if ((index+1) < parent.child_controls.Count) {
3031 index = parent.child_controls.Count-1;
3034 result = Select(parent.child_controls[index]);
3035 } while (!result && parent.child_controls[index] != this);
3038 [EditorBrowsable(EditorBrowsableState.Advanced)]
3039 protected virtual void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
3040 // SetBoundsCore updates the Win32 control itself. UpdateBounds updates the controls variables and fires events, I'm guessing - pdb
3041 if ((specified & BoundsSpecified.X) != BoundsSpecified.X) {
3045 if ((specified & BoundsSpecified.Y) != BoundsSpecified.Y) {
3049 if ((specified & BoundsSpecified.Width) != BoundsSpecified.Width) {
3053 if ((specified & BoundsSpecified.Height) != BoundsSpecified.Height) {
3057 if (IsHandleCreated) {
3058 XplatUI.SetWindowPos(Handle, x, y, width, height);
3060 UpdateBounds(x, y, width, height);
3063 [EditorBrowsable(EditorBrowsableState.Advanced)]
3064 protected virtual void SetClientSizeCore(int x, int y) {
3065 // Calculate the actual window size from the client size (it usually stays the same or grows)
3066 Rectangle ClientRect;
3067 Rectangle WindowRect;
3070 ClientRect = new Rectangle(0, 0, x, y);
3071 cp = this.CreateParams;
3073 if (XplatUI.CalculateWindowRect(Handle, ref ClientRect, cp.Style, cp.ExStyle, IntPtr.Zero, out WindowRect)==false) {
3077 SetBoundsCore(bounds.X, bounds.Y, WindowRect.Width, WindowRect.Height, BoundsSpecified.Size);
3080 [EditorBrowsable(EditorBrowsableState.Advanced)]
3081 protected void SetStyle(ControlStyles flag, bool value) {
3083 control_style |= flag;
3085 control_style &= ~flag;
3087 OnStyleChanged(EventArgs.Empty);
3090 protected void SetTopLevel(bool value) {
3091 if ((GetTopLevel() != value) && (parent != null)) {
3092 throw new Exception();
3096 if (value == true) {
3106 is_toplevel = value;
3109 protected virtual void SetVisibleCore(bool value) {
3110 if (value!=is_visible) {
3112 XplatUI.SetVisible(Handle, value);
3113 // Explicitly move Toplevel windows to where we want them;
3114 // apparently moving unmapped toplevel windows doesn't work
3115 if (is_visible && (this is Form)) {
3116 XplatUI.SetWindowPos(window.Handle, bounds.X, bounds.Y, bounds.Width, bounds.Height);
3118 OnVisibleChanged(EventArgs.Empty);
3121 if (dc_mem != null) {
3126 if (bmp_mem != null) {
3131 this.CreateBuffers(bounds.Width, bounds.Height);
3136 if (value == false && parent != null) {
3139 // Need to start at parent, GetContainerControl might return ourselves if we're a container
3140 container = (Control)parent.GetContainerControl();
3141 if (container != null) {
3142 container.SelectNextControl(this, true, true, true, true);
3146 if (parent != null) {
3147 parent.PerformLayout(this, "visible");
3149 PerformLayout(this, "visible");
3154 [EditorBrowsable(EditorBrowsableState.Advanced)]
3155 protected void UpdateBounds() {
3163 if (!IsHandleCreated) {
3167 XplatUI.GetWindowPos(this.Handle, this is Form, out x, out y, out width, out height, out client_width, out client_height);
3169 UpdateBounds(x, y, width, height, client_width, client_height);
3172 [EditorBrowsable(EditorBrowsableState.Advanced)]
3173 protected void UpdateBounds(int x, int y, int width, int height) {
3174 // UpdateBounds only seems to set our sizes and fire events but not update the GUI window to match
3176 bool resized = false;
3178 int client_x_diff = this.bounds.Width-this.client_size.Width;
3179 int client_y_diff = this.bounds.Height-this.client_size.Height;
3181 // Needed to generate required notifications
3182 if ((this.bounds.X!=x) || (this.bounds.Y!=y)) {
3186 if ((this.Bounds.Width!=width) || (this.Bounds.Height!=height)) {
3193 bounds.Height=height;
3195 // Update client rectangle as well
3196 if (this.layout_suspended==0) {
3197 prev_size.Width=client_size.Width;
3198 prev_size.Height=client_size.Height;
3201 client_size.Width=width-client_x_diff;
3202 client_size.Height=height-client_y_diff;
3205 OnLocationChanged(EventArgs.Empty);
3209 OnSizeChanged(EventArgs.Empty);
3213 [EditorBrowsable(EditorBrowsableState.Advanced)]
3214 protected void UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) {
3215 UpdateBounds(x, y, width, height);
3217 this.client_size.Width=clientWidth;
3218 this.client_size.Height=clientHeight;
3221 [EditorBrowsable(EditorBrowsableState.Advanced)]
3222 protected void UpdateStyles() {
3223 if (!IsHandleCreated) {
3227 XplatUI.SetWindowStyle(window.Handle, CreateParams);
3230 [EditorBrowsable(EditorBrowsableState.Advanced)]
3231 protected void UpdateZOrder() {
3236 if (parent == null) {
3242 children = ctl.child_controls.Count;
3243 for (int i = 1; i < children; i++ ) {
3244 XplatUI.SetZOrder(ctl.child_controls[i].window.Handle, ctl.child_controls[i-1].window.Handle, false, false);
3247 children = child_controls.Count;
3248 for (int i = 1; i < children; i++ ) {
3249 XplatUI.SetZOrder(child_controls[i].window.Handle, child_controls[i-1].window.Handle, false, false);
3254 protected virtual void WndProc(ref Message m) {
3256 Console.WriteLine("Control received message {0}", (Msg)m.Msg);
3258 if ((this.control_style & ControlStyles.EnableNotifyMessage) != 0) {
3262 switch((Msg)m.Msg) {
3263 case Msg.WM_WINDOWPOSCHANGED: {
3266 if (GetStyle(ControlStyles.ResizeRedraw)) {
3273 case Msg.WM_PAINT: {
3274 PaintEventArgs paint_event;
3276 paint_event = XplatUI.PaintEventStart(Handle);
3278 if (!needs_redraw) {
3279 // Just blit the previous image
3280 paint_event.Graphics.DrawImage (ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle, GraphicsUnit.Pixel);
3281 XplatUI.PaintEventEnd(Handle);
3286 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
3287 dc = paint_event.SetGraphics (DeviceContext);
3290 if ((control_style & (ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint)) != (ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint)) {
3291 OnPaintBackground(paint_event);
3294 OnPaint(paint_event);
3296 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
3297 dc.DrawImage (ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle, GraphicsUnit.Pixel);
3298 paint_event.SetGraphics (dc);
3299 needs_redraw = false;
3302 XplatUI.PaintEventEnd(Handle);
3304 if (!GetStyle(ControlStyles.UserPaint)) {
3311 case Msg.WM_ERASEBKGND: {
3312 if (GetStyle (ControlStyles.UserPaint)) {
3313 if (!GetStyle(ControlStyles.AllPaintingInWmPaint)) {
3314 PaintEventArgs eraseEventArgs = new PaintEventArgs (m.WParam == IntPtr.Zero ? Graphics.FromHwnd (m.HWnd) :
3315 Graphics.FromHdc (m.WParam), new Rectangle (new Point (0,0),Size));
3316 OnPaintBackground (eraseEventArgs);
3319 XplatUI.EraseWindowBackground(m.HWnd, m.WParam);
3321 // The DefWndProc will never have to handle this, we don't ever set hbr on the window
3322 m.Result = (IntPtr)1;
3326 case Msg.WM_LBUTTONUP: {
3327 HandleClick(mouse_clicks);
3328 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Left,
3330 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3332 if (mouse_clicks > 1) {
3338 case Msg.WM_LBUTTONDOWN: {
3339 if (CanSelect && !is_selected) {
3342 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3343 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3349 case Msg.WM_LBUTTONDBLCLK: {
3351 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3352 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3358 case Msg.WM_MBUTTONUP: {
3359 HandleClick(mouse_clicks);
3360 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Middle,
3362 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3364 if (mouse_clicks > 1) {
3370 case Msg.WM_MBUTTONDOWN: {
3371 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3372 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3378 case Msg.WM_MBUTTONDBLCLK: {
3380 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3381 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3386 case Msg.WM_RBUTTONUP: {
3387 if (context_menu != null) {
3388 context_menu.Show(this, new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ())));
3391 HandleClick(mouse_clicks);
3392 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Right,
3394 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3396 if (mouse_clicks > 1) {
3402 case Msg.WM_RBUTTONDOWN: {
3403 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3404 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3409 case Msg.WM_RBUTTONDBLCLK: {
3411 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3412 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3417 case Msg.WM_MOUSEWHEEL: {
3419 OnMouseWheel (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3420 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3421 HighOrder(m.WParam.ToInt32())));
3426 case Msg.WM_MOUSEMOVE: {
3427 OnMouseMove (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3429 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3434 case Msg.WM_MOUSE_ENTER: {
3439 OnMouseEnter(EventArgs.Empty);
3443 case Msg.WM_MOUSE_LEAVE: {
3445 OnMouseLeave(EventArgs.Empty);
3449 case Msg.WM_MOUSEHOVER: {
3450 OnMouseHover(EventArgs.Empty);
3454 case Msg.WM_SYSKEYDOWN:
3455 case Msg.WM_KEYDOWN:
3456 case Msg.WM_SYSKEYUP:
3458 case Msg.WM_SYSCHAR:
3460 if (ProcessKeyEventArgs(ref m)) {
3464 if (PreProcessMessage(ref m)) {
3468 if (ProcessKeyMessage(ref m)) {
3477 if (m.LParam != IntPtr.Zero) {
3480 hi = new HELPINFO();
3482 hi = (HELPINFO) Marshal.PtrToStructure (m.LParam, typeof (HELPINFO));
3483 mouse_pos = new Point(hi.MousePos.x, hi.MousePos.y);
3485 mouse_pos = Control.MousePosition;
3487 OnHelpRequested(new HelpEventArgs(mouse_pos));
3488 m.Result = (IntPtr)1;
3492 case Msg.WM_KILLFOCUS: {
3493 OnLeave(EventArgs.Empty);
3494 if (CausesValidation) {
3496 e = new CancelEventArgs(false);
3505 OnValidated(EventArgs.Empty);
3508 this.has_focus = false;
3509 this.is_selected = false;
3510 OnLostFocus(EventArgs.Empty);
3514 case Msg.WM_SETFOCUS: {
3515 OnEnter(EventArgs.Empty);
3516 this.has_focus = true;
3517 OnGotFocus(EventArgs.Empty);
3522 case Msg.WM_SYSCOLORCHANGE: {
3523 ThemeEngine.Current.ResetDefaults();
3524 OnSystemColorsChanged(EventArgs.Empty);
3529 case Msg.WM_SETCURSOR: {
3530 if (cursor == null) {
3535 XplatUI.SetCursor(window.Handle, cursor.handle);
3536 m.Result = (IntPtr)1;
3546 #endregion // Public Instance Methods
3548 #region OnXXX methods
3549 [EditorBrowsable(EditorBrowsableState.Advanced)]
3550 protected virtual void OnBackColorChanged(EventArgs e) {
3551 if (BackColorChanged!=null) BackColorChanged(this, e);
3552 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackColorChanged(e);
3555 [EditorBrowsable(EditorBrowsableState.Advanced)]
3556 protected virtual void OnBackgroundImageChanged(EventArgs e) {
3557 if (BackgroundImageChanged!=null) BackgroundImageChanged(this, e);
3558 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackgroundImageChanged(e);
3561 [EditorBrowsable(EditorBrowsableState.Advanced)]
3562 protected virtual void OnBindingContextChanged(EventArgs e) {
3563 CheckDataBindings ();
3564 if (BindingContextChanged!=null) {
3565 BindingContextChanged(this, e);
3567 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBindingContextChanged(e);
3570 [EditorBrowsable(EditorBrowsableState.Advanced)]
3571 protected virtual void OnCausesValidationChanged(EventArgs e) {
3572 if (CausesValidationChanged!=null) CausesValidationChanged(this, e);
3575 [EditorBrowsable(EditorBrowsableState.Advanced)]
3576 protected virtual void OnChangeUICues(UICuesEventArgs e) {
3577 if (ChangeUICues!=null) ChangeUICues(this, e);
3580 [EditorBrowsable(EditorBrowsableState.Advanced)]
3581 protected virtual void OnClick(EventArgs e) {
3582 if (Click!=null) Click(this, e);
3585 [EditorBrowsable(EditorBrowsableState.Advanced)]
3586 protected virtual void OnContextMenuChanged(EventArgs e) {
3587 if (ContextMenuChanged!=null) ContextMenuChanged(this, e);
3590 [EditorBrowsable(EditorBrowsableState.Advanced)]
3591 protected virtual void OnControlAdded(ControlEventArgs e) {
3592 if (ControlAdded!=null) ControlAdded(this, e);
3595 [EditorBrowsable(EditorBrowsableState.Advanced)]
3596 protected virtual void OnControlRemoved(ControlEventArgs e) {
3597 if (ControlRemoved!=null) ControlRemoved(this, e);
3600 [EditorBrowsable(EditorBrowsableState.Advanced)]
3601 protected virtual void OnCreateControl() {
3605 [EditorBrowsable(EditorBrowsableState.Advanced)]
3606 protected virtual void OnCursorChanged(EventArgs e) {
3607 if (CursorChanged!=null) CursorChanged(this, e);
3610 [EditorBrowsable(EditorBrowsableState.Advanced)]
3611 protected virtual void OnDockChanged(EventArgs e) {
3612 if (DockChanged!=null) DockChanged(this, e);
3615 [EditorBrowsable(EditorBrowsableState.Advanced)]
3616 protected virtual void OnDoubleClick(EventArgs e) {
3617 if (DoubleClick!=null) DoubleClick(this, e);
3620 [EditorBrowsable(EditorBrowsableState.Advanced)]
3621 protected virtual void OnDragDrop(DragEventArgs drgevent) {
3622 if (DragDrop!=null) DragDrop(this, drgevent);
3625 [EditorBrowsable(EditorBrowsableState.Advanced)]
3626 protected virtual void OnDragEnter(DragEventArgs drgevent) {
3627 if (DragEnter!=null) DragEnter(this, drgevent);
3630 [EditorBrowsable(EditorBrowsableState.Advanced)]
3631 protected virtual void OnDragLeave(EventArgs e) {
3632 if (DragLeave!=null) DragLeave(this, e);
3635 [EditorBrowsable(EditorBrowsableState.Advanced)]
3636 protected virtual void OnDragOver(DragEventArgs drgevent) {
3637 if (DragOver!=null) DragOver(this, drgevent);
3640 [EditorBrowsable(EditorBrowsableState.Advanced)]
3641 protected virtual void OnEnabledChanged(EventArgs e) {
3642 if (EnabledChanged!=null) EnabledChanged(this, e);
3643 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentEnabledChanged(e);
3646 [EditorBrowsable(EditorBrowsableState.Advanced)]
3647 protected virtual void OnEnter(EventArgs e) {
3648 if (Enter!=null) Enter(this, e);
3651 [EditorBrowsable(EditorBrowsableState.Advanced)]
3652 protected virtual void OnFontChanged(EventArgs e) {
3653 if (FontChanged!=null) FontChanged(this, e);
3654 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentFontChanged(e);
3657 [EditorBrowsable(EditorBrowsableState.Advanced)]
3658 protected virtual void OnForeColorChanged(EventArgs e) {
3659 if (ForeColorChanged!=null) ForeColorChanged(this, e);
3660 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentForeColorChanged(e);
3663 [EditorBrowsable(EditorBrowsableState.Advanced)]
3664 protected virtual void OnGiveFeedback(GiveFeedbackEventArgs gfbevent) {
3665 if (GiveFeedback!=null) GiveFeedback(this, gfbevent);
3668 [EditorBrowsable(EditorBrowsableState.Advanced)]
3669 protected virtual void OnGotFocus(EventArgs e) {
3670 if (GotFocus!=null) GotFocus(this, e);
3673 [EditorBrowsable(EditorBrowsableState.Advanced)]
3674 protected virtual void OnHandleCreated(EventArgs e) {
3675 if (HandleCreated!=null) HandleCreated(this, e);
3678 [EditorBrowsable(EditorBrowsableState.Advanced)]
3679 protected virtual void OnHandleDestroyed(EventArgs e) {
3680 if (HandleDestroyed!=null) HandleDestroyed(this, e);
3683 [EditorBrowsable(EditorBrowsableState.Advanced)]
3684 protected virtual void OnHelpRequested(HelpEventArgs hevent) {
3685 if (HelpRequested!=null) HelpRequested(this, hevent);
3688 protected virtual void OnImeModeChanged(EventArgs e) {
3689 if (ImeModeChanged!=null) ImeModeChanged(this, e);
3692 [EditorBrowsable(EditorBrowsableState.Advanced)]
3693 protected virtual void OnInvalidated(InvalidateEventArgs e) {
3694 needs_redraw = true;
3695 if (Invalidated!=null) Invalidated(this, e);
3698 [EditorBrowsable(EditorBrowsableState.Advanced)]
3699 protected virtual void OnKeyDown(KeyEventArgs e) {
3700 if (KeyDown!=null) KeyDown(this, e);
3703 [EditorBrowsable(EditorBrowsableState.Advanced)]
3704 protected virtual void OnKeyPress(KeyPressEventArgs e) {
3705 if (KeyPress!=null) KeyPress(this, e);
3708 [EditorBrowsable(EditorBrowsableState.Advanced)]
3709 protected virtual void OnKeyUp(KeyEventArgs e) {
3710 if (KeyUp!=null) KeyUp(this, e);
3713 [EditorBrowsable(EditorBrowsableState.Advanced)]
3714 protected virtual void OnLayout(LayoutEventArgs levent) {
3715 if (Layout!=null) Layout(this, levent);
3718 [EditorBrowsable(EditorBrowsableState.Advanced)]
3719 protected virtual void OnLeave(EventArgs e) {
3720 if (Leave!=null) Leave(this, e);
3723 [EditorBrowsable(EditorBrowsableState.Advanced)]
3724 protected virtual void OnLocationChanged(EventArgs e) {
3726 if (LocationChanged!=null) LocationChanged(this, e);
3729 [EditorBrowsable(EditorBrowsableState.Advanced)]
3730 protected virtual void OnLostFocus(EventArgs e) {
3731 if (LostFocus!=null) LostFocus(this, e);
3734 [EditorBrowsable(EditorBrowsableState.Advanced)]
3735 protected virtual void OnMouseDown(MouseEventArgs e) {
3736 if (MouseDown!=null) MouseDown(this, e);
3739 [EditorBrowsable(EditorBrowsableState.Advanced)]
3740 protected virtual void OnMouseEnter(EventArgs e) {
3741 if (MouseEnter!=null) MouseEnter(this, e);
3744 [EditorBrowsable(EditorBrowsableState.Advanced)]
3745 protected virtual void OnMouseHover(EventArgs e) {
3746 if (MouseHover!=null) MouseHover(this, e);
3749 [EditorBrowsable(EditorBrowsableState.Advanced)]
3750 protected virtual void OnMouseLeave(EventArgs e) {
3751 if (MouseLeave!=null) MouseLeave(this, e);
3754 [EditorBrowsable(EditorBrowsableState.Advanced)]
3755 protected virtual void OnMouseMove(MouseEventArgs e) {
3756 if (MouseMove!=null) MouseMove(this, e);
3759 [EditorBrowsable(EditorBrowsableState.Advanced)]
3760 protected virtual void OnMouseUp(MouseEventArgs e) {
3761 if (MouseUp!=null) MouseUp(this, e);
3764 [EditorBrowsable(EditorBrowsableState.Advanced)]
3765 protected virtual void OnMouseWheel(MouseEventArgs e) {
3766 if (MouseWheel!=null) MouseWheel(this, e);
3769 [EditorBrowsable(EditorBrowsableState.Advanced)]
3770 protected virtual void OnMove(EventArgs e) {
3771 if (Move!=null) Move(this, e);
3774 [EditorBrowsable(EditorBrowsableState.Advanced)]
3775 protected virtual void OnNotifyMessage(Message m) {
3779 [EditorBrowsable(EditorBrowsableState.Advanced)]
3780 protected virtual void OnPaint(PaintEventArgs e) {
3781 if (Paint!=null) Paint(this, e);
3784 [EditorBrowsable(EditorBrowsableState.Advanced)]
3785 protected virtual void OnPaintBackground(PaintEventArgs pevent) {
3786 PaintControlBackground (pevent);
3789 [EditorBrowsable(EditorBrowsableState.Advanced)]
3790 protected virtual void OnParentBackColorChanged(EventArgs e) {
3791 if (background_color.IsEmpty && background_image==null) {
3793 OnBackColorChanged(e);
3797 [EditorBrowsable(EditorBrowsableState.Advanced)]
3798 protected virtual void OnParentBackgroundImageChanged(EventArgs e) {
3799 if (background_color.IsEmpty && background_image==null) {
3801 OnBackgroundImageChanged(e);
3805 [EditorBrowsable(EditorBrowsableState.Advanced)]
3806 protected virtual void OnParentBindingContextChanged(EventArgs e) {
3807 if (binding_context==null) {
3808 binding_context=Parent.binding_context;
3809 OnBindingContextChanged(e);
3813 [EditorBrowsable(EditorBrowsableState.Advanced)]
3814 protected virtual void OnParentChanged(EventArgs e) {
3815 if (ParentChanged!=null) ParentChanged(this, e);
3818 [EditorBrowsable(EditorBrowsableState.Advanced)]
3819 protected virtual void OnParentEnabledChanged(EventArgs e) {
3820 if (is_enabled != Parent.is_enabled) {
3821 is_enabled=Parent.is_enabled;
3823 if (EnabledChanged != null) {
3824 EnabledChanged(this, e);
3829 [EditorBrowsable(EditorBrowsableState.Advanced)]
3830 protected virtual void OnParentFontChanged(EventArgs e) {
3837 [EditorBrowsable(EditorBrowsableState.Advanced)]
3838 protected virtual void OnParentForeColorChanged(EventArgs e) {
3839 if (foreground_color.IsEmpty) {
3841 OnForeColorChanged(e);
3845 [EditorBrowsable(EditorBrowsableState.Advanced)]
3846 protected virtual void OnParentRightToLeftChanged(EventArgs e) {
3847 if (right_to_left==RightToLeft.Inherit) {
3849 OnRightToLeftChanged(e);
3853 [EditorBrowsable(EditorBrowsableState.Advanced)]
3854 protected virtual void OnParentVisibleChanged(EventArgs e) {
3856 OnVisibleChanged(e);
3860 [EditorBrowsable(EditorBrowsableState.Advanced)]
3861 protected virtual void OnQueryContinueDrag(QueryContinueDragEventArgs e) {
3862 if (QueryContinueDrag!=null) QueryContinueDrag(this, e);
3865 [EditorBrowsable(EditorBrowsableState.Advanced)]
3866 protected virtual void OnResize(EventArgs e) {
3867 if (Resize!=null) Resize(this, e);
3869 PerformLayout(this, "bounds");
3871 if (parent != null) {
3872 parent.PerformLayout();
3876 [EditorBrowsable(EditorBrowsableState.Advanced)]
3877 protected virtual void OnRightToLeftChanged(EventArgs e) {
3878 if (RightToLeftChanged!=null) RightToLeftChanged(this, e);
3879 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentRightToLeftChanged(e);
3882 [EditorBrowsable(EditorBrowsableState.Advanced)]
3883 protected virtual void OnSizeChanged(EventArgs e) {
3884 InvalidateBuffers ();
3886 if (SizeChanged!=null) SizeChanged(this, e);
3889 [EditorBrowsable(EditorBrowsableState.Advanced)]
3890 protected virtual void OnStyleChanged(EventArgs e) {
3891 if (StyleChanged!=null) StyleChanged(this, e);
3894 [EditorBrowsable(EditorBrowsableState.Advanced)]
3895 protected virtual void OnSystemColorsChanged(EventArgs e) {
3896 if (SystemColorsChanged!=null) SystemColorsChanged(this, e);
3899 [EditorBrowsable(EditorBrowsableState.Advanced)]
3900 protected virtual void OnTabIndexChanged(EventArgs e) {
3901 if (TabIndexChanged!=null) TabIndexChanged(this, e);
3904 [EditorBrowsable(EditorBrowsableState.Advanced)]
3905 protected virtual void OnTabStopChanged(EventArgs e) {
3906 if (TabStopChanged!=null) TabStopChanged(this, e);
3909 [EditorBrowsable(EditorBrowsableState.Advanced)]
3910 protected virtual void OnTextChanged(EventArgs e) {
3911 if (TextChanged!=null) TextChanged(this, e);
3914 [EditorBrowsable(EditorBrowsableState.Advanced)]
3915 protected virtual void OnValidated(EventArgs e) {
3916 if (Validated!=null) Validated(this, e);
3919 [EditorBrowsable(EditorBrowsableState.Advanced)]
3920 protected virtual void OnValidating(System.ComponentModel.CancelEventArgs e) {
3921 if (Validating!=null) Validating(this, e);
3924 [EditorBrowsable(EditorBrowsableState.Advanced)]
3925 protected virtual void OnVisibleChanged(EventArgs e) {
3932 if (bmp_mem!=null) {
3938 if (!this.IsHandleCreated) {
3939 this.CreateControl();
3945 if (VisibleChanged!=null) VisibleChanged(this, e);
3947 // We need to tell our kids
3948 for (int i=0; i<child_controls.Count; i++) {
3949 child_controls[i].OnParentVisibleChanged(e);
3952 #endregion // OnXXX methods
3955 public event EventHandler BackColorChanged;
3956 public event EventHandler BackgroundImageChanged;
3957 public event EventHandler BindingContextChanged;
3958 public event EventHandler CausesValidationChanged;
3959 public event UICuesEventHandler ChangeUICues;
3960 public event EventHandler Click;
3961 public event EventHandler ContextMenuChanged;
3963 [EditorBrowsable(EditorBrowsableState.Advanced)]
3965 public event ControlEventHandler ControlAdded;
3967 [EditorBrowsable(EditorBrowsableState.Advanced)]
3969 public event ControlEventHandler ControlRemoved;
3971 public event EventHandler CursorChanged;
3972 public event EventHandler DockChanged;
3973 public event EventHandler DoubleClick;
3974 public event DragEventHandler DragDrop;
3975 public event DragEventHandler DragEnter;
3976 public event EventHandler DragLeave;
3977 public event DragEventHandler DragOver;
3978 public event EventHandler EnabledChanged;
3979 public event EventHandler Enter;
3980 public event EventHandler FontChanged;
3981 public event EventHandler ForeColorChanged;
3982 public event GiveFeedbackEventHandler GiveFeedback;
3984 [EditorBrowsable(EditorBrowsableState.Advanced)]
3986 public event EventHandler GotFocus;
3988 [EditorBrowsable(EditorBrowsableState.Advanced)]
3990 public event EventHandler HandleCreated;
3992 [EditorBrowsable(EditorBrowsableState.Advanced)]
3994 public event EventHandler HandleDestroyed;
3996 public event HelpEventHandler HelpRequested;
3997 public event EventHandler ImeModeChanged;
3999 [EditorBrowsable(EditorBrowsableState.Advanced)]
4001 public event InvalidateEventHandler Invalidated;
4003 public event KeyEventHandler KeyDown;
4004 public event KeyPressEventHandler KeyPress;
4005 public event KeyEventHandler KeyUp;
4006 public event LayoutEventHandler Layout;
4007 public event EventHandler Leave;
4008 public event EventHandler LocationChanged;
4010 [EditorBrowsable(EditorBrowsableState.Advanced)]
4012 public event EventHandler LostFocus;
4014 public event MouseEventHandler MouseDown;
4015 public event EventHandler MouseEnter;
4016 public event EventHandler MouseHover;
4017 public event EventHandler MouseLeave;
4018 public event MouseEventHandler MouseMove;
4019 public event MouseEventHandler MouseUp;
4021 [EditorBrowsable(EditorBrowsableState.Advanced)]
4023 public event MouseEventHandler MouseWheel;
4025 public event EventHandler Move;
4026 public event PaintEventHandler Paint;
4027 public event EventHandler ParentChanged;
4028 public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp;
4029 public event QueryContinueDragEventHandler QueryContinueDrag;
4030 public event EventHandler Resize;
4031 public event EventHandler RightToLeftChanged;
4032 public event EventHandler SizeChanged;
4033 public event EventHandler StyleChanged;
4034 public event EventHandler SystemColorsChanged;
4035 public event EventHandler TabIndexChanged;
4036 public event EventHandler TabStopChanged;
4037 public event EventHandler TextChanged;
4038 public event EventHandler Validated;
4039 public event CancelEventHandler Validating;
4040 public event EventHandler VisibleChanged;
4041 #endregion // Events