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));
397 owner.UpdateZOrder();
400 public void RemoveAt(int index) {
401 if (index < 0 || index >= list.Count) {
402 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
404 Remove ((Control)list[index]);
407 public void SetChildIndex(Control child, int newIndex) {
410 old_index=list.IndexOf(child);
412 throw new ArgumentException("Not a child control", "child");
415 if (old_index==newIndex) {
421 if (newIndex>list.Count) {
424 list.Insert(newIndex, child);
426 owner.UpdateZOrder();
428 #endregion // ControlCollection Private Instance Methods
430 #region ControlCollection Interface Properties
431 object IList.this[int index] {
433 if (index<0 || index>=list.Count) {
434 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
440 if (!(value is Control)) {
441 throw new ArgumentException("Object of type Control required", "value");
444 list[index]=(Control)value;
448 bool IList.IsFixedSize {
454 bool IList.IsReadOnly {
456 return list.IsReadOnly;
460 bool ICollection.IsSynchronized {
462 return list.IsSynchronized;
466 object ICollection.SyncRoot {
468 return list.SyncRoot;
471 #endregion // ControlCollection Interface Properties
473 #region ControlCollection Interface Methods
474 int IList.Add(object value) {
476 throw new ArgumentNullException("value", "Cannot add null controls");
479 if (!(value is Control)) {
480 throw new ArgumentException("Object of type Control required", "value");
483 return list.Add(value);
486 bool IList.Contains(object value) {
487 if (!(value is Control)) {
488 throw new ArgumentException("Object of type Control required", "value");
491 return this.Contains((Control) value);
494 int IList.IndexOf(object value) {
495 if (!(value is Control)) {
496 throw new ArgumentException("Object of type Control required", "value");
499 return this.IndexOf((Control) value);
502 void IList.Insert(int index, object value) {
503 if (!(value is Control)) {
504 throw new ArgumentException("Object of type Control required", "value");
506 list.Insert(index, value);
509 void IList.Remove(object value) {
510 if (!(value is Control)) {
511 throw new ArgumentException("Object of type Control required", "value");
516 void ICollection.CopyTo(Array array, int index) {
518 list.CopyTo(array, index);
522 Object ICloneable.Clone() {
523 ControlCollection clone = new ControlCollection(this.owner);
524 clone.list=(ArrayList)list.Clone(); // FIXME: Do we need this?
527 #endregion // ControlCollection Interface Methods
529 #endregion // ControlCollection Class
531 #region Public Constructors
533 creator_thread = Thread.CurrentThread;
535 prev_size = Size.Empty;
536 anchor_style = AnchorStyles.Top | AnchorStyles.Left;
538 create_handled = false;
544 layout_pending = false;
546 causes_validation = true;
548 layout_suspended = 0;
552 right_to_left = RightToLeft.Inherit;
554 control_style = ControlStyles.Selectable | ControlStyles.StandardClick | ControlStyles.StandardDoubleClick;
557 background_image = null;
561 window = new ControlNativeWindow(this);
562 child_controls = CreateControlsInstance();
563 client_size = new Size(DefaultSize.Width, DefaultSize.Height);
564 client_rect = new Rectangle(0, 0, DefaultSize.Width, DefaultSize.Height);
565 XplatUI.CalculateWindowRect(IntPtr.Zero, ref client_rect, CreateParams.Style, CreateParams.ExStyle, IntPtr.Zero, out bounds);
566 if ((CreateParams.Style & (int)WindowStyles.WS_CHILD) == 0) {
572 public Control(Control parent, string text) : this() {
577 public Control(Control parent, string text, int left, int top, int width, int height) : this() {
582 bounds.Height=height;
583 SetBoundsCore(left, top, width, height, BoundsSpecified.All);
587 public Control(string text) : this() {
591 public Control(string text, int left, int top, int width, int height) : this() {
595 bounds.Height=height;
596 SetBoundsCore(left, top, width, height, BoundsSpecified.All);
600 protected override void Dispose(bool disposing) {
613 controls.Remove(this);
615 #endregion // Public Constructors
617 #region Internal Properties
618 internal BorderStyle InternalBorderStyle {
624 if (border_style != value) {
625 border_style = value;
627 XplatUI.SetBorderStyle(window.Handle, border_style);
631 #endregion // Internal Properties
633 #region Private & Internal Methods
634 internal static IAsyncResult BeginInvokeInternal (Delegate method, object [] args) {
635 AsyncMethodResult result = new AsyncMethodResult ();
636 AsyncMethodData data = new AsyncMethodData ();
638 data.Method = method;
640 data.Result = new WeakReference (result);
643 if (!ExecutionContext.IsFlowSuppressed ()) {
644 data.Context = ExecutionContext.Capture ();
647 if (SecurityManager.SecurityEnabled) {
648 data.Stack = CompressedStack.GetCompressedStack ();
652 XplatUI.SendAsyncMethod (data);
656 internal Graphics DeviceContext {
659 CreateBuffers(this.Width, this.Height);
665 private Bitmap ImageBuffer {
668 CreateBuffers(this.Width, this.Height);
674 internal void CreateBuffers (int width, int height) {
675 if (dc_mem != null) {
689 bmp_mem = new Bitmap (width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
690 dc_mem = Graphics.FromImage (bmp_mem);
694 internal void InvalidateBuffers ()
696 if (dc_mem != null) {
707 internal static void SetChildColor(Control parent) {
710 for (int i=0; i < parent.child_controls.Count; i++) {
711 child=parent.child_controls[i];
712 if (child.IsHandleCreated) {
713 XplatUI.SetWindowBackground(child.window.Handle, child.BackColor);
715 if (child.child_controls.Count>0) {
716 SetChildColor(child);
722 internal bool Select(Control control) {
724 IContainerControl container;
726 if (control == null) {
730 parent = control.parent;
732 if (((control.control_style & ControlStyles.Selectable) !=0) && (parent != null)) {
733 while (parent != null) {
734 if (!parent.Visible || !parent.is_enabled) {
737 parent = parent.parent;
741 control.is_selected = true;
743 container = GetContainerControl();
744 if (container != null) {
745 container.ActiveControl = control;
747 XplatUI.SetFocus(control.window.Handle);
751 internal virtual void DoDefaultAction() {
752 // Only here to be overriden by our actual controls; this is needed by the accessibility class
755 internal static int LowOrder (int param) {
756 return ((int)(short)(param & 0xffff));
759 internal static int HighOrder (int param) {
760 return ((int)(short)(param >> 16));
763 // This method exists so controls overriding OnPaintBackground can have default background painting done
764 internal void PaintControlBackground (PaintEventArgs pevent)
766 if (background_image == null)
769 DrawBackgroundImage (pevent.Graphics);
772 void DrawBackgroundImage (Graphics g)
774 using (TextureBrush b = new TextureBrush (background_image)) {
775 g.FillRectangle (b, ClientRectangle);
779 internal void DndEnter (DragEventArgs e)
784 internal void DndOver (DragEventArgs e)
789 internal void DndDrop (DragEventArgs e)
794 internal void DndLeave (EventArgs e)
799 internal void DnDFeedback(GiveFeedbackEventArgs e)
804 internal void DnDContinueDrag(QueryContinueDragEventArgs e) {
805 OnQueryContinueDrag(e);
808 internal static MouseButtons FromParamToMouseButtons (int param) {
809 MouseButtons buttons = MouseButtons.None;
811 if ((param & (int) MsgButtons.MK_LBUTTON) != 0)
812 buttons |= MouseButtons.Left;
814 if ((param & (int) MsgButtons.MK_MBUTTON) != 0)
815 buttons |= MouseButtons.Middle;
817 if ((param & (int) MsgButtons.MK_RBUTTON) != 0)
818 buttons |= MouseButtons.Right;
824 internal virtual bool ProcessControlMnemonic(char charCode) {
825 return ProcessMnemonic(charCode);
828 private static Control FindFlatForward(Control container, Control start) {
834 end = container.child_controls.Count;
837 index = start.tab_index;
842 for (int i = 0; i < end; i++) {
844 if (container.child_controls[i].tab_index > index) {
845 found = container.child_controls[i];
847 } else if (found.tab_index > container.child_controls[i].tab_index) {
848 if (container.child_controls[i].tab_index > index) {
849 found = container.child_controls[i];
856 private static Control FindControlForward(Control container, Control start) {
863 if ((start is IContainerControl) || start.GetStyle(ControlStyles.ContainerControl)) {
864 found = FindControlForward(start, null);
871 while (p != container) {
872 found = FindFlatForward(p, start);
880 return FindFlatForward(container, start);
883 private static Control FindFlatBackward(Control container, Control start) {
889 end = container.child_controls.Count;
892 index = start.tab_index;
894 // FIXME: Possible speed-up: Keep the highest taborder index in the container
896 for (int i = 0; i < end; i++) {
897 if (container.child_controls[i].tab_index > index) {
898 index = container.child_controls[i].tab_index;
904 for (int i = 0; i < end; i++) {
906 if (container.child_controls[i].tab_index < index) {
907 found = container.child_controls[i];
909 } else if (found.tab_index < container.child_controls[i].tab_index) {
910 if (container.child_controls[i].tab_index < index) {
911 found = container.child_controls[i];
918 private static Control FindControlBackward(Control container, Control start) {
924 found = FindFlatBackward(start.parent, start);
925 if (found == null && start.parent != container) {
930 found = FindFlatBackward(container, start);
933 while ((found != null) && ((found is IContainerControl) || found.GetStyle(ControlStyles.ContainerControl))) {
934 found = FindControlBackward(found, null);
943 private void HandleClick(int clicks) {
944 if (GetStyle(ControlStyles.StandardClick)) {
946 if (GetStyle(ControlStyles.StandardDoubleClick)) {
947 OnDoubleClick(EventArgs.Empty);
949 OnClick(EventArgs.Empty);
952 OnClick(EventArgs.Empty);
957 private void CheckDataBindings ()
959 if (data_bindings == null)
962 BindingContext binding_context = BindingContext;
963 foreach (Binding binding in data_bindings) {
964 binding.Check (binding_context);
968 #endregion // Private & Internal Methods
970 #region Public Static Properties
971 public static Color DefaultBackColor {
973 return ThemeEngine.Current.DefaultControlBackColor;
977 public static Font DefaultFont {
979 return ThemeEngine.Current.DefaultFont;
983 public static Color DefaultForeColor {
985 return ThemeEngine.Current.DefaultControlForeColor;
989 public static Keys ModifierKeys {
991 return XplatUI.State.ModifierKeys;
995 public static MouseButtons MouseButtons {
997 return XplatUI.State.MouseButtons;
1001 public static Point MousePosition {
1003 return Cursor.Position;
1009 public static bool CheckForIllegalCrossThreadCalls
1018 #endregion // Public Static Properties
1020 #region Public Instance Properties
1021 [EditorBrowsable(EditorBrowsableState.Advanced)]
1023 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1024 public AccessibleObject AccessibilityObject {
1026 if (accessibility_object==null) {
1027 accessibility_object=CreateAccessibilityInstance();
1029 return accessibility_object;
1033 [EditorBrowsable(EditorBrowsableState.Advanced)]
1035 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1036 public string AccessibleDefaultActionDescription {
1038 return AccessibilityObject.default_action;
1042 AccessibilityObject.default_action=value;
1047 [DefaultValue(null)]
1048 public string AccessibleDescription {
1050 return AccessibilityObject.description;
1054 AccessibilityObject.description=value;
1059 [DefaultValue(null)]
1060 public string AccessibleName {
1062 return AccessibilityObject.Name;
1066 AccessibilityObject.Name=value;
1070 [DefaultValue(AccessibleRole.Default)]
1071 [MWFDescription("Role of the control"), MWFCategory("Accessibility")]
1072 public AccessibleRole AccessibleRole {
1074 return AccessibilityObject.role;
1078 AccessibilityObject.role=value;
1082 [DefaultValue(false)]
1083 public virtual bool AllowDrop {
1089 if (allow_drop == value)
1093 XplatUI.SetAllowDrop (Handle, value);
1098 [RefreshProperties(RefreshProperties.Repaint)]
1099 [DefaultValue(AnchorStyles.Top | AnchorStyles.Left)]
1100 public virtual AnchorStyles Anchor {
1102 return anchor_style;
1108 if (parent != null) {
1109 parent.PerformLayout(this, "Parent");
1115 public virtual Color BackColor {
1117 if (background_color.IsEmpty) {
1119 return parent.BackColor;
1121 return DefaultBackColor;
1123 return background_color;
1127 background_color=value;
1128 if (this.IsHandleCreated) {
1129 XplatUI.SetWindowBackground(this.window.Handle, value);
1131 SetChildColor(this);
1132 OnBackColorChanged(EventArgs.Empty);
1138 [DefaultValue(null)]
1139 public virtual Image BackgroundImage {
1141 return background_image;
1145 if (background_image!=value) {
1146 background_image=value;
1147 OnBackgroundImageChanged(EventArgs.Empty);
1152 [EditorBrowsable(EditorBrowsableState.Advanced)]
1154 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1155 public virtual BindingContext BindingContext {
1157 if (binding_context != null)
1158 return binding_context;
1161 binding_context = Parent.BindingContext;
1162 return binding_context;
1165 if (binding_context != value) {
1166 binding_context = value;
1167 OnBindingContextChanged(EventArgs.Empty);
1172 [EditorBrowsable(EditorBrowsableState.Advanced)]
1174 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1177 return bounds.Y+bounds.Height;
1181 [EditorBrowsable(EditorBrowsableState.Advanced)]
1183 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1184 public Rectangle Bounds {
1190 SetBoundsCore(value.Left, value.Top, value.Width, value.Height, BoundsSpecified.All);
1194 [EditorBrowsable(EditorBrowsableState.Advanced)]
1196 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1197 public bool CanFocus {
1199 if (Visible && is_enabled && GetStyle(ControlStyles.Selectable)) {
1206 [EditorBrowsable(EditorBrowsableState.Advanced)]
1208 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1209 public bool CanSelect {
1213 if (!GetStyle(ControlStyles.Selectable) || this.parent == null) {
1217 parent = this.parent;
1218 while (parent != null) {
1219 if (!parent.is_visible || !parent.is_enabled) {
1223 parent = parent.parent;
1229 [EditorBrowsable(EditorBrowsableState.Advanced)]
1231 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1232 public bool Capture {
1234 return this.is_captured;
1238 if (this.IsHandleCreated) {
1239 if (value && !is_captured) {
1241 XplatUI.GrabWindow(this.window.Handle, IntPtr.Zero);
1242 } else if (!value && is_captured) {
1243 XplatUI.UngrabWindow(this.window.Handle);
1244 is_captured = false;
1250 [DefaultValue(true)]
1251 public bool CausesValidation {
1253 return this.causes_validation;
1257 if (this.causes_validation != value) {
1258 causes_validation = value;
1259 OnCausesValidationChanged(EventArgs.Empty);
1264 [EditorBrowsable(EditorBrowsableState.Advanced)]
1266 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1267 public Rectangle ClientRectangle {
1269 client_rect.Width = client_size.Width;
1270 client_rect.Height = client_size.Height;
1275 [EditorBrowsable(EditorBrowsableState.Advanced)]
1277 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1278 public Size ClientSize {
1281 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1282 return ((Form)this).form_parent_window.ClientSize;
1290 this.SetClientSizeCore(value.Width, value.Height);
1294 [EditorBrowsable(EditorBrowsableState.Advanced)]
1296 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1297 [DescriptionAttribute("ControlCompanyNameDescr")]
1298 public String CompanyName {
1300 return "Mono Project, Novell, Inc.";
1304 [EditorBrowsable(EditorBrowsableState.Advanced)]
1306 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1307 public bool ContainsFocus {
1313 for (int i=0; i < child_controls.Count; i++) {
1314 if (child_controls[i].ContainsFocus) {
1322 [DefaultValue(null)]
1323 public virtual ContextMenu ContextMenu {
1325 return context_menu;
1329 if (context_menu != value) {
1330 context_menu = value;
1331 OnContextMenuChanged(EventArgs.Empty);
1337 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
1338 public ControlCollection Controls {
1340 return this.child_controls;
1344 [EditorBrowsable(EditorBrowsableState.Advanced)]
1346 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1347 public bool Created {
1349 if (!this.is_disposed && (this.window.Handle != IntPtr.Zero)) {
1356 [AmbientValue(null)]
1357 public virtual Cursor Cursor {
1359 if (cursor != null) {
1363 if (parent != null) {
1364 return parent.Cursor;
1367 return Cursors.Default;
1371 if (cursor != value) {
1376 pt = Cursor.Position;
1377 if (bounds.Contains(pt)) {
1378 if (GetChildAtPoint(pt) == null) {
1379 if (cursor != null) {
1380 XplatUI.SetCursor(window.Handle, cursor.handle);
1382 if (parent != null) {
1383 XplatUI.SetCursor(window.Handle, parent.Cursor.handle);
1385 XplatUI.SetCursor(window.Handle, Cursors.def.handle);
1391 OnCursorChanged(EventArgs.Empty);
1397 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
1398 [ParenthesizePropertyName(true)]
1399 [RefreshProperties(RefreshProperties.All)]
1400 public ControlBindingsCollection DataBindings {
1402 if (data_bindings == null)
1403 data_bindings = new ControlBindingsCollection (this);
1404 return data_bindings;
1408 [EditorBrowsable(EditorBrowsableState.Advanced)]
1410 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1411 public virtual Rectangle DisplayRectangle {
1413 return ClientRectangle;
1417 [EditorBrowsable(EditorBrowsableState.Advanced)]
1419 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1420 public bool Disposing {
1427 [RefreshProperties(RefreshProperties.Repaint)]
1428 [DefaultValue(DockStyle.None)]
1429 public virtual DockStyle Dock {
1435 if (dock_style == value) {
1441 if (parent != null) {
1442 parent.PerformLayout(this, "Parent");
1445 OnDockChanged(EventArgs.Empty);
1451 public bool Enabled {
1457 if (is_enabled == value) {
1463 OnEnabledChanged (EventArgs.Empty);
1467 [EditorBrowsable(EditorBrowsableState.Advanced)]
1469 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1470 public virtual bool Focused {
1472 return this.has_focus;
1477 [AmbientValue(null)]
1479 public virtual Font Font {
1485 if (Parent != null && Parent.Font != null) {
1493 if (font != null && font.Equals (value)) {
1499 OnFontChanged (EventArgs.Empty);
1504 public virtual Color ForeColor {
1506 if (foreground_color.IsEmpty) {
1508 return parent.ForeColor;
1510 return DefaultForeColor;
1512 return foreground_color;
1516 if (foreground_color != value) {
1517 foreground_color=value;
1519 OnForeColorChanged(EventArgs.Empty);
1526 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1527 public IntPtr Handle { // IWin32Window
1529 if (!IsHandleCreated) {
1532 return window.Handle;
1536 [EditorBrowsable(EditorBrowsableState.Advanced)]
1538 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1539 public bool HasChildren {
1541 if (this.child_controls.Count>0) {
1548 [EditorBrowsable(EditorBrowsableState.Always)]
1550 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1553 return this.bounds.Height;
1557 SetBoundsCore(bounds.X, bounds.Y, bounds.Width, value, BoundsSpecified.Height);
1561 [AmbientValue(ImeMode.Inherit)]
1563 public ImeMode ImeMode {
1565 if (ime_mode == DefaultImeMode) {
1567 return parent.ImeMode;
1569 return ImeMode.NoControl; // default value
1575 if (ime_mode != value) {
1578 OnImeModeChanged(EventArgs.Empty);
1583 [EditorBrowsable(EditorBrowsableState.Advanced)]
1585 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1586 public bool InvokeRequired { // ISynchronizeInvoke
1588 if (creator_thread!=Thread.CurrentThread) {
1595 [EditorBrowsable(EditorBrowsableState.Advanced)]
1597 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1598 public bool IsAccessible {
1600 return is_accessible;
1604 is_accessible = value;
1608 [EditorBrowsable(EditorBrowsableState.Advanced)]
1610 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1611 public bool IsDisposed {
1613 return this.is_disposed;
1617 [EditorBrowsable(EditorBrowsableState.Advanced)]
1619 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1620 public bool IsHandleCreated {
1622 if ((window!=null) && (window.Handle!=IntPtr.Zero)) {
1630 [EditorBrowsable(EditorBrowsableState.Always)]
1632 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1635 return this.bounds.X;
1639 SetBoundsCore(value, bounds.Y, bounds.Width, bounds.Height, BoundsSpecified.X);
1644 public Point Location {
1646 return new Point(bounds.X, bounds.Y);
1650 SetBoundsCore(value.X, value.Y, bounds.Width, bounds.Height, BoundsSpecified.Location);
1655 public string Name {
1666 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1667 public Control Parent {
1673 if (value == this) {
1674 throw new ArgumentException("A circular control reference has been made. A control cannot be owned or parented to itself.");
1677 if (parent!=value) {
1679 parent.Controls.Remove(this);
1685 if (!parent.Controls.Contains(this)) {
1686 parent.Controls.Add(this);
1689 XplatUI.SetParent(Handle, value.Handle);
1693 OnParentChanged(EventArgs.Empty);
1698 [EditorBrowsable(EditorBrowsableState.Advanced)]
1700 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1701 public string ProductName {
1703 Type t = typeof (AssemblyProductAttribute);
1704 Assembly assembly = GetType().Module.Assembly;
1705 object [] attrs = assembly.GetCustomAttributes (t, false);
1706 AssemblyProductAttribute a = null;
1707 // On MS we get a NullRefException if product attribute is not
1709 if (attrs != null && attrs.Length > 0)
1710 a = (AssemblyProductAttribute) attrs [0];
1715 [EditorBrowsable(EditorBrowsableState.Advanced)]
1717 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1718 public string ProductVersion {
1720 Type t = typeof (AssemblyVersionAttribute);
1721 Assembly assembly = GetType().Module.Assembly;
1722 object [] attrs = assembly.GetCustomAttributes (t, false);
1723 if (attrs == null || attrs.Length < 1)
1725 return ((AssemblyVersionAttribute)attrs [0]).Version;
1729 [EditorBrowsable(EditorBrowsableState.Advanced)]
1731 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1732 public bool RecreatingHandle {
1734 return is_recreating;
1738 [EditorBrowsable(EditorBrowsableState.Advanced)]
1740 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1741 public Region Region {
1743 return new Region(this.bounds);
1750 g = this.CreateGraphics();
1751 r = value.GetBounds(g);
1753 SetBounds((int)r.X, (int)r.Y, (int)r.Width, (int)r.Height);
1759 [EditorBrowsable(EditorBrowsableState.Advanced)]
1761 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1764 return this.bounds.X+this.bounds.Width;
1768 [AmbientValue(RightToLeft.Inherit)]
1770 public virtual RightToLeft RightToLeft {
1772 if (right_to_left == RightToLeft.Inherit) {
1774 return parent.RightToLeft;
1776 return RightToLeft.No; // default value
1778 return right_to_left;
1782 if (value != right_to_left) {
1783 right_to_left = value;
1784 OnRightToLeftChanged(EventArgs.Empty);
1789 [EditorBrowsable(EditorBrowsableState.Advanced)]
1790 public override ISite Site {
1803 return new Size(Width, Height);
1807 SetBoundsCore(bounds.X, bounds.Y, value.Width, value.Height, BoundsSpecified.Size);
1812 [MergableProperty(false)]
1813 public int TabIndex {
1815 if (tab_index != -1) {
1822 if (tab_index != value) {
1824 OnTabIndexChanged(EventArgs.Empty);
1830 [DefaultValue(true)]
1831 public bool TabStop {
1837 if (tab_stop != value) {
1839 OnTabStopChanged(EventArgs.Empty);
1844 [Localizable(false)]
1846 [TypeConverter(typeof(StringConverter))]
1847 [DefaultValue(null)]
1854 control_tag = value;
1860 [BindableAttribute(true)]
1861 public virtual string Text {
1867 if (value == null) {
1868 value = String.Empty;
1873 XplatUI.Text(Handle, text);
1874 // FIXME: Do we need a Refresh() here?
1875 OnTextChanged (EventArgs.Empty);
1880 [EditorBrowsable(EditorBrowsableState.Always)]
1882 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1885 return this.bounds.Y;
1889 SetBoundsCore(bounds.X, value, bounds.Width, bounds.Height, BoundsSpecified.Y);
1893 [EditorBrowsable(EditorBrowsableState.Advanced)]
1895 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1896 public Control TopLevelControl {
1900 while (p.parent != null) {
1909 public bool Visible {
1913 } else if (parent != null) {
1914 return parent.Visible;
1921 SetVisibleCore(value);
1925 [EditorBrowsable(EditorBrowsableState.Always)]
1927 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1930 return this.bounds.Width;
1934 SetBoundsCore(bounds.X, bounds.Y, value, bounds.Height, BoundsSpecified.Width);
1938 [EditorBrowsable(EditorBrowsableState.Never)]
1940 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1941 public IWindowTarget WindowTarget {
1950 #endregion // Public Instance Properties
1952 #region Protected Instance Properties
1953 protected virtual CreateParams CreateParams {
1955 CreateParams create_params = new CreateParams();
1958 create_params.Caption = Text;
1961 create_params.Caption = text;
1965 create_params.X = Left;
1968 create_params.X = this.bounds.X;
1972 create_params.Y = Top;
1975 create_params.Y = this.bounds.Y;
1979 create_params.Width = Width;
1982 create_params.Width = this.bounds.Width;
1986 create_params.Height = Height;
1989 create_params.Height = this.bounds.Height;
1993 create_params.ClassName = XplatUI.DefaultClassName;
1994 create_params.ClassStyle = 0;
1995 create_params.ExStyle = 0;
1996 create_params.Param = 0;
1999 create_params.ExStyle |= (int)WindowStyles.WS_EX_ACCEPTFILES;
2003 create_params.Parent = parent.Handle;
2006 create_params.Style = (int)WindowStyles.WS_CHILD | (int)WindowStyles.WS_CLIPCHILDREN | (int)WindowStyles.WS_CLIPSIBLINGS;
2009 create_params.Style |= (int)WindowStyles.WS_VISIBLE;
2012 return create_params;
2016 protected virtual ImeMode DefaultImeMode {
2018 return ImeMode.Inherit;
2022 protected virtual Size DefaultSize {
2024 return new Size(100, 23);
2028 protected int FontHeight {
2038 protected bool RenderRightToLeft {
2040 return (this.right_to_left == RightToLeft.Yes);
2044 protected bool ResizeRedraw {
2046 return GetStyle(ControlStyles.ResizeRedraw);
2050 SetStyle(ControlStyles.ResizeRedraw, value);
2054 [EditorBrowsable(EditorBrowsableState.Advanced)]
2056 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2057 protected virtual bool ShowFocusCues {
2063 [EditorBrowsable(EditorBrowsableState.Advanced)]
2065 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2066 protected bool ShowKeyboardCues {
2071 #endregion // Protected Instance Properties
2073 #region Public Static Methods
2074 [EditorBrowsable(EditorBrowsableState.Advanced)]
2075 public static Control FromChildHandle(IntPtr handle) {
2076 IEnumerator control = Control.controls.GetEnumerator();
2078 while (control.MoveNext()) {
2079 if (((Control)control.Current).window.Handle == handle) {
2081 if (((Control)control.Current).Parent != null) {
2082 return ((Control)control.Current).Parent;
2089 [EditorBrowsable(EditorBrowsableState.Advanced)]
2090 public static Control FromHandle(IntPtr handle) {
2091 IEnumerator control = Control.controls.GetEnumerator();
2093 while (control.MoveNext()) {
2094 if (((Control)control.Current).window.Handle == handle) {
2096 return ((Control)control.Current);
2102 public static bool IsMnemonic(char charCode, string text) {
2105 amp = text.IndexOf('&');
2108 if (amp + 1 < text.Length) {
2109 if (text[amp + 1] != '&') {
2110 if (Char.ToUpper(charCode) == Char.ToUpper(text.ToCharArray(amp + 1, 1)[0])) {
2120 #region Protected Static Methods
2121 [EditorBrowsable(EditorBrowsableState.Advanced)]
2122 protected static bool ReflectMessage(IntPtr hWnd, ref Message m) {
2125 c = Control.FromHandle(hWnd);
2135 #region Public Instance Methods
2136 [EditorBrowsable(EditorBrowsableState.Advanced)]
2137 public IAsyncResult BeginInvoke(Delegate method) {
2138 return BeginInvokeInternal(method, null);
2141 [EditorBrowsable(EditorBrowsableState.Advanced)]
2142 public IAsyncResult BeginInvoke (Delegate method, object[] args) {
2143 return BeginInvokeInternal (method, args);
2146 public void BringToFront() {
2147 if ((parent != null) && (parent.child_controls[0]!=this)) {
2148 if (parent.child_controls.Contains(this)) {
2149 parent.child_controls.SetChildIndex(this, 0);
2153 XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, true, false);
2155 if (parent != null) {
2160 public bool Contains(Control ctl) {
2161 while (ctl != null) {
2170 public void CreateControl() {
2172 if (!IsHandleCreated) {
2176 if (!create_handled) {
2177 create_handled = true;
2181 for (int i=0; i<child_controls.Count; i++) {
2182 child_controls[i].CreateControl();
2186 public Graphics CreateGraphics() {
2187 if (!IsHandleCreated) {
2188 this.CreateControl();
2190 return Graphics.FromHwnd(this.window.Handle);
2193 public DragDropEffects DoDragDrop(object data, DragDropEffects allowedEffects) {
2194 return XplatUI.StartDrag(this.window.Handle, data, allowedEffects);
2197 [EditorBrowsable(EditorBrowsableState.Advanced)]
2198 public object EndInvoke (IAsyncResult async_result) {
2199 AsyncMethodResult result = (AsyncMethodResult) async_result;
2200 return result.EndInvoke ();
2203 public Form FindForm() {
2216 public bool Focus() {
2217 if (IsHandleCreated && !has_focus) {
2219 XplatUI.SetFocus(window.Handle);
2224 public Control GetChildAtPoint(Point pt) {
2225 // Microsoft's version of this function doesn't seem to work, so I can't check
2226 // if we only consider children or also grandchildren, etc.
2227 // I'm gonna say 'children only'
2228 for (int i=0; i<child_controls.Count; i++) {
2229 if (child_controls[i].Bounds.Contains(pt)) {
2230 return child_controls[i];
2236 public IContainerControl GetContainerControl() {
2237 Control current = this;
2239 while (current!=null) {
2240 if ((current is IContainerControl) && ((current.control_style & ControlStyles.ContainerControl)!=0)) {
2241 return (IContainerControl)current;
2243 current = current.parent;
2248 public Control GetNextControl(Control ctl, bool forward) {
2249 // If we're not a container we don't play
2250 if (!(this is IContainerControl) && !this.GetStyle(ControlStyles.ContainerControl)) {
2254 // If ctl is not contained by this, we start at the first child of this
2255 if (!this.Contains(ctl)) {
2259 // Search through our controls, starting at ctl, stepping into children as we encounter them
2260 // try to find the control with the tabindex closest to our own, or, if we're looking into
2261 // child controls, the one with the smallest tabindex
2263 return FindControlForward(this, ctl);
2265 return FindControlBackward(this, ctl);
2268 public void Hide() {
2269 this.Visible = false;
2272 public void Invalidate() {
2273 Invalidate(ClientRectangle, false);
2276 public void Invalidate(bool invalidateChildren) {
2277 Invalidate(ClientRectangle, invalidateChildren);
2280 public void Invalidate(System.Drawing.Rectangle rc) {
2281 Invalidate(rc, false);
2284 public void Invalidate(System.Drawing.Rectangle rc, bool invalidateChildren) {
2285 if (!IsHandleCreated || !Visible) {
2289 NotifyInvalidate(rc);
2291 XplatUI.Invalidate(Handle, rc, false);
2293 if (invalidateChildren) {
2294 for (int i=0; i<child_controls.Count; i++) child_controls[i].Invalidate();
2296 OnInvalidated(new InvalidateEventArgs(rc));
2299 public void Invalidate(System.Drawing.Region region) {
2300 Invalidate(region, false);
2303 [MonoTODO("Figure out if GetRegionScans is usable")]
2304 public void Invalidate(System.Drawing.Region region, bool invalidateChildren) {
2305 throw new NotImplementedException();
2307 // FIXME - should use the GetRegionScans function of the region to invalidate each area
2308 //if (invalidateChildren) {
2309 // for (int i=0; i<child_controls.Count; i++) child_controls[i].Invalidate();
2313 public object Invoke (Delegate method) {
2314 return Invoke(method, null);
2317 public object Invoke (Delegate method, object[] args) {
2318 if (!this.InvokeRequired) {
2319 return method.DynamicInvoke(args);
2322 IAsyncResult result = BeginInvoke (method, args);
2323 return EndInvoke(result);
2326 [EditorBrowsable(EditorBrowsableState.Advanced)]
2327 public void PerformLayout() {
2328 PerformLayout(null, null);
2331 [EditorBrowsable(EditorBrowsableState.Advanced)]
2332 public void PerformLayout(Control affectedControl, string affectedProperty) {
2333 LayoutEventArgs levent = new LayoutEventArgs(affectedControl, affectedProperty);
2335 if (layout_suspended>0) {
2336 layout_pending = true;
2340 layout_pending = false;
2342 // Prevent us from getting messed up
2345 // Perform all Dock and Anchor calculations
2348 AnchorStyles anchor;
2353 space=this.DisplayRectangle;
2354 if (prev_size != Size.Empty) {
2355 diff_width = space.Width - prev_size.Width;
2356 diff_height = space.Height - prev_size.Height;
2362 // Deal with docking; go through in reverse, MS docs say that lowest Z-order is closest to edge
2363 for (int i = child_controls.Count - 1; i >= 0; i--) {
2364 child=child_controls[i];
2365 switch (child.Dock) {
2366 case DockStyle.None: {
2371 case DockStyle.Left: {
2372 child.SetBounds(space.Left, space.Y, child.Width, space.Height);
2373 space.X+=child.Width;
2374 space.Width-=child.Width;
2378 case DockStyle.Top: {
2379 child.SetBounds(space.Left, space.Y, space.Width, child.Height);
2380 space.Y+=child.Height;
2381 space.Height-=child.Height;
2385 case DockStyle.Right: {
2386 child.SetBounds(space.Right-child.Width, space.Y, child.Width, space.Height);
2387 space.Width-=child.Width;
2391 case DockStyle.Bottom: {
2392 child.SetBounds(space.Left, space.Bottom-child.Height, space.Width, child.Height);
2393 space.Height-=child.Height;
2399 for (int i = child_controls.Count - 1; i >= 0; i--) {
2400 child=child_controls[i];
2402 if (child.Dock == DockStyle.Fill) {
2403 child.SetBounds(space.Left, space.Top, space.Width, space.Height);
2409 space=this.DisplayRectangle;
2411 // Deal with anchoring
2412 for (int i=0; i < child_controls.Count; i++) {
2418 child=child_controls[i];
2419 anchor=child.Anchor;
2424 height=child.Height;
2426 // If the control is docked we don't need to do anything
2427 if (child.Dock != DockStyle.None) {
2431 if ((anchor & AnchorStyles.Left) !=0 ) {
2432 if ((anchor & AnchorStyles.Right) != 0) {
2433 // Anchoring to left and right
2434 width=width+diff_width;
2438 } else if ((anchor & AnchorStyles.Right) != 0) {
2444 if ((anchor & AnchorStyles.Top) !=0 ) {
2445 if ((anchor & AnchorStyles.Bottom) != 0) {
2446 height+=diff_height;
2450 } else if ((anchor & AnchorStyles.Bottom) != 0) {
2465 child.SetBounds(left, top, width, height);
2468 // Let everyone know
2472 // Need to make sure we decremend layout_suspended
2478 public Point PointToClient (Point p) {
2482 XplatUI.ScreenToClient (Handle, ref x, ref y);
2484 return new Point (x, y);
2487 public Point PointToScreen(Point p) {
2491 XplatUI.ClientToScreen(Handle, ref x, ref y);
2493 return new Point(x, y);
2496 public virtual bool PreProcessMessage(ref Message msg) {
2499 if ((msg.Msg == (int)Msg.WM_KEYDOWN) || (msg.Msg == (int)Msg.WM_SYSKEYDOWN)) {
2500 key_data = (Keys)msg.WParam.ToInt32();
2501 if (!ProcessCmdKey(ref msg, key_data)) {
2502 if (IsInputKey(key_data)) {
2506 return ProcessDialogKey(key_data);
2510 } else if (msg.Msg == (int)Msg.WM_CHAR) {
2511 if (IsInputChar((char)msg.WParam)) {
2514 } else if (msg.Msg == (int)Msg.WM_SYSCHAR) {
2515 if (IsInputChar((char)msg.WParam)) {
2518 return ProcessDialogChar((char)msg.WParam);
2523 public Rectangle RectangleToClient(Rectangle r) {
2524 return new Rectangle(PointToClient(r.Location), r.Size);
2527 public Rectangle RectangleToScreen(Rectangle r) {
2528 return new Rectangle(PointToScreen(r.Location), r.Size);
2531 public virtual void Refresh() {
2532 if (IsHandleCreated == true) {
2534 XplatUI.UpdateWindow(window.Handle);
2538 [EditorBrowsable(EditorBrowsableState.Never)]
2539 public virtual void ResetBackColor() {
2540 background_color = Color.Empty;
2543 [EditorBrowsable(EditorBrowsableState.Never)]
2545 public void ResetBindings() {
2549 [EditorBrowsable(EditorBrowsableState.Never)]
2550 public virtual void ResetCursor() {
2554 [EditorBrowsable(EditorBrowsableState.Never)]
2555 public virtual void ResetFont() {
2559 [EditorBrowsable(EditorBrowsableState.Never)]
2560 public virtual void ResetForeColor() {
2561 foreground_color = Color.Empty;
2564 [EditorBrowsable(EditorBrowsableState.Never)]
2565 public void ResetImeMode() {
2566 ime_mode = DefaultImeMode;
2569 [EditorBrowsable(EditorBrowsableState.Never)]
2570 public virtual void ResetRightToLeft() {
2571 right_to_left = RightToLeft.Inherit;
2574 public virtual void ResetText() {
2575 text = String.Empty;
2578 public void ResumeLayout() {
2579 ResumeLayout (true);
2582 public void ResumeLayout(bool performLayout) {
2585 if (layout_suspended > 0) {
2589 if (performLayout || layout_pending) {
2594 public void Scale(float ratio) {
2595 ScaleCore(ratio, ratio);
2598 public void Scale(float dx, float dy) {
2602 public void Select() {
2603 Select(false, false);
2606 public bool SelectNextControl(Control ctl, bool forward, bool tabStopOnly, bool nested, bool wrap) {
2611 c = GetNextControl(c, forward);
2620 if (c.CanSelect && ((c.parent == ctl.parent) || nested) && (c.tab_stop || !tabStopOnly)) {
2624 } while (c != ctl); // If we wrap back to ourselves we stop
2629 public void SendToBack() {
2630 if ((parent != null) && (parent.child_controls[parent.child_controls.Count-1]!=this)) {
2631 if (parent.child_controls.Contains(this)) {
2632 parent.child_controls.SetChildIndex(this, parent.child_controls.Count);
2636 XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, false, true);
2637 if (parent != null) {
2642 public void SetBounds(int x, int y, int width, int height) {
2643 SetBoundsCore(x, y, width, height, BoundsSpecified.All);
2646 public void SetBounds(int x, int y, int width, int height, BoundsSpecified specified) {
2647 SetBoundsCore(x, y, width, height, specified);
2650 public void Show() {
2651 if (!IsHandleCreated) {
2652 this.CreateControl();
2658 public void SuspendLayout() {
2662 public void Update() {
2663 needs_redraw = true;
2664 XplatUI.UpdateWindow(window.Handle);
2666 #endregion // Public Instance Methods
2668 #region Protected Instance Methods
2669 [EditorBrowsable(EditorBrowsableState.Advanced)]
2670 [MonoTODO("Implement this and tie it into Control.ControlAccessibleObject.NotifyClients")]
2671 protected void AccessibilityNotifyClients(AccessibleEvents accEvent, int childID) {
2672 throw new NotImplementedException();
2675 [EditorBrowsable(EditorBrowsableState.Advanced)]
2676 protected virtual AccessibleObject CreateAccessibilityInstance() {
2677 return new Control.ControlAccessibleObject(this);
2680 [EditorBrowsable(EditorBrowsableState.Advanced)]
2681 protected virtual ControlCollection CreateControlsInstance() {
2682 return new ControlCollection(this);
2685 [EditorBrowsable(EditorBrowsableState.Advanced)]
2686 protected virtual void CreateHandle() {
2688 throw new ObjectDisposedException(Name);
2691 if (IsHandleCreated) {
2695 window.CreateHandle(CreateParams);
2697 // Find out where the window manager placed us
2701 if (window.Handle!=IntPtr.Zero) {
2702 if (!controls.Contains(window.Handle)) {
2706 creator_thread = Thread.CurrentThread;
2708 XplatUI.SetWindowBackground(window.Handle, this.BackColor);
2710 OnHandleCreated(EventArgs.Empty);
2714 [EditorBrowsable(EditorBrowsableState.Advanced)]
2715 protected virtual void DefWndProc(ref Message m) {
2716 window.DefWndProc(ref m);
2719 [EditorBrowsable(EditorBrowsableState.Advanced)]
2720 protected virtual void DestroyHandle() {
2721 if (IsHandleCreated) {
2722 // Destroy our children before we destroy ourselves, to prevent them from
2723 // being implictly (without us knowing) destroyed
2724 for (int i=0; i < child_controls.Count; i++) {
2725 child_controls[i].DestroyHandle();
2729 if (window != null) {
2730 window.DestroyHandle();
2732 OnHandleDestroyed(EventArgs.Empty);
2736 protected bool GetStyle(ControlStyles flag) {
2737 return (control_style & flag) != 0;
2740 protected bool GetTopLevel() {
2744 [EditorBrowsable(EditorBrowsableState.Advanced)]
2745 protected virtual void InitLayout() {
2746 if (parent != null) {
2747 parent.PerformLayout(this, "parent");
2751 [EditorBrowsable(EditorBrowsableState.Advanced)]
2752 protected void InvokeGotFocus(Control toInvoke, EventArgs e) {
2753 toInvoke.OnGotFocus(e);
2756 [EditorBrowsable(EditorBrowsableState.Advanced)]
2757 protected void InvokeLostFocus(Control toInvoke, EventArgs e) {
2758 toInvoke.OnLostFocus(e);
2761 [EditorBrowsable(EditorBrowsableState.Advanced)]
2762 protected void InvokeOnClick(Control toInvoke, EventArgs e) {
2763 toInvoke.OnClick(e);
2766 protected void InvokePaint(Control toInvoke, PaintEventArgs e) {
2767 toInvoke.OnPaint(e);
2770 protected void InvokePaintBackground(Control toInvoke, PaintEventArgs e) {
2771 toInvoke.OnPaintBackground(e);
2774 protected virtual bool IsInputChar (char charCode) {
2775 if (parent != null) {
2776 return parent.IsInputChar(charCode);
2782 protected virtual bool IsInputKey (Keys keyData) {
2783 // Doc says this one calls IsInputChar; not sure what to do with that
2787 [EditorBrowsable(EditorBrowsableState.Advanced)]
2788 protected virtual void NotifyInvalidate(Rectangle invalidatedArea) {
2792 protected virtual bool ProcessCmdKey(ref Message msg, Keys keyData) {
2793 if ((context_menu != null) && context_menu.ProcessCmdKey(ref msg, keyData)) {
2797 if (parent != null) {
2798 return parent.ProcessCmdKey(ref msg, keyData);
2804 protected virtual bool ProcessDialogChar(char charCode) {
2805 if (parent != null) {
2806 return parent.ProcessDialogChar (charCode);
2812 protected virtual bool ProcessDialogKey (Keys keyData) {
2813 if (parent != null) {
2814 return parent.ProcessDialogKey (keyData);
2820 protected virtual bool ProcessKeyEventArgs (ref Message msg)
2822 KeyEventArgs key_event;
2825 case (int)Msg.WM_KEYDOWN: {
2826 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
2827 OnKeyDown (key_event);
2828 return key_event.Handled;
2830 case (int)Msg.WM_KEYUP: {
2831 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
2832 OnKeyUp (key_event);
2833 return key_event.Handled;
2836 case (int)Msg.WM_CHAR: {
2837 KeyPressEventArgs key_press_event;
2839 key_press_event = new KeyPressEventArgs((char)msg.WParam);
2840 OnKeyPress(key_press_event);
2841 return key_press_event.Handled;
2852 protected internal virtual bool ProcessKeyMessage(ref Message msg) {
2853 if (parent != null) {
2854 if (parent.ProcessKeyPreview(ref msg)) {
2862 protected virtual bool ProcessKeyPreview(ref Message msg) {
2863 if (parent != null) {
2864 return parent.ProcessKeyPreview(ref msg);
2870 protected virtual bool ProcessMnemonic(char charCode) {
2875 [EditorBrowsable(EditorBrowsableState.Advanced)]
2876 protected void RaiseDragEvent(object key, DragEventArgs e) {
2880 [EditorBrowsable(EditorBrowsableState.Advanced)]
2881 protected void RaiseKeyEvent(object key, KeyEventArgs e) {
2885 [EditorBrowsable(EditorBrowsableState.Advanced)]
2886 protected void RaiseMouseEvent(object key, MouseEventArgs e) {
2890 [EditorBrowsable(EditorBrowsableState.Advanced)]
2891 protected void RaisePaintEvent(object key, PaintEventArgs e) {
2895 [EditorBrowsable(EditorBrowsableState.Advanced)]
2896 protected void RecreateHandle() {
2897 IEnumerator child = child_controls.GetEnumerator();
2901 if (IsHandleCreated) {
2907 while (child.MoveNext()) {
2908 ((Control)child.Current).RecreateHandle();
2914 is_recreating = false;
2917 [EditorBrowsable(EditorBrowsableState.Advanced)]
2918 protected void ResetMouseEventArgs() {
2922 [EditorBrowsable(EditorBrowsableState.Advanced)]
2923 protected ContentAlignment RtlTranslateAlignment(ContentAlignment align) {
2924 if (right_to_left == RightToLeft.No) {
2929 case ContentAlignment.TopLeft: {
2930 return ContentAlignment.TopRight;
2933 case ContentAlignment.TopRight: {
2934 return ContentAlignment.TopLeft;
2937 case ContentAlignment.MiddleLeft: {
2938 return ContentAlignment.MiddleRight;
2941 case ContentAlignment.MiddleRight: {
2942 return ContentAlignment.MiddleLeft;
2945 case ContentAlignment.BottomLeft: {
2946 return ContentAlignment.BottomRight;
2949 case ContentAlignment.BottomRight: {
2950 return ContentAlignment.BottomLeft;
2954 // if it's center it doesn't change
2960 [EditorBrowsable(EditorBrowsableState.Advanced)]
2961 protected HorizontalAlignment RtlTranslateAlignment(HorizontalAlignment align) {
2962 if ((right_to_left == RightToLeft.No) || (align == HorizontalAlignment.Center)) {
2966 if (align == HorizontalAlignment.Left) {
2967 return HorizontalAlignment.Right;
2970 // align must be HorizontalAlignment.Right
2971 return HorizontalAlignment.Left;
2974 [EditorBrowsable(EditorBrowsableState.Advanced)]
2975 protected LeftRightAlignment RtlTranslateAlignment(LeftRightAlignment align) {
2976 if (right_to_left == RightToLeft.No) {
2980 if (align == LeftRightAlignment.Left) {
2981 return LeftRightAlignment.Right;
2984 // align must be LeftRightAlignment.Right;
2985 return LeftRightAlignment.Left;
2988 [EditorBrowsable(EditorBrowsableState.Advanced)]
2989 protected ContentAlignment RtlTranslateContent(ContentAlignment align) {
2990 return RtlTranslateAlignment(align);
2993 [EditorBrowsable(EditorBrowsableState.Advanced)]
2994 protected HorizontalAlignment RtlTranslateHorizontal(HorizontalAlignment align) {
2995 return RtlTranslateAlignment(align);
2998 [EditorBrowsable(EditorBrowsableState.Advanced)]
2999 protected LeftRightAlignment RtlTranslateLeftRight(LeftRightAlignment align) {
3000 return RtlTranslateAlignment(align);
3003 [EditorBrowsable(EditorBrowsableState.Advanced)]
3004 protected virtual void ScaleCore(float dx, float dy) {
3010 location = new Point((int)(Left * dx), (int)(Top * dy));
3011 size = this.ClientSize;
3014 if (!GetStyle(ControlStyles.FixedWidth)) {
3015 size.Width = (int)(size.Width * dx);
3018 if (!GetStyle(ControlStyles.FixedHeight)) {
3019 size.Height = (int)(size.Height * dy);
3022 Location = location;
3025 /* Now scale our children */
3026 for (int i=0; i < child_controls.Count; i++) {
3027 child_controls[i].Scale(dx, dy);
3033 protected virtual void Select(bool directed, bool forward) {
3038 // Select this control
3043 if (parent == null) {
3047 // FIXME - this thing is doing the wrong stuff, needs to be similar to SelectNextControl
3049 index = parent.child_controls.IndexOf(this);
3054 if ((index+1) < parent.child_controls.Count) {
3063 index = parent.child_controls.Count-1;
3066 result = Select(parent.child_controls[index]);
3067 } while (!result && parent.child_controls[index] != this);
3070 [EditorBrowsable(EditorBrowsableState.Advanced)]
3071 protected virtual void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
3072 // SetBoundsCore updates the Win32 control itself. UpdateBounds updates the controls variables and fires events, I'm guessing - pdb
3073 if ((specified & BoundsSpecified.X) != BoundsSpecified.X) {
3077 if ((specified & BoundsSpecified.Y) != BoundsSpecified.Y) {
3081 if ((specified & BoundsSpecified.Width) != BoundsSpecified.Width) {
3085 if ((specified & BoundsSpecified.Height) != BoundsSpecified.Height) {
3089 if (IsHandleCreated) {
3090 XplatUI.SetWindowPos(Handle, x, y, width, height);
3092 UpdateBounds(x, y, width, height);
3095 [EditorBrowsable(EditorBrowsableState.Advanced)]
3096 protected virtual void SetClientSizeCore(int x, int y) {
3097 // Calculate the actual window size from the client size (it usually stays the same or grows)
3098 Rectangle ClientRect;
3099 Rectangle WindowRect;
3102 ClientRect = new Rectangle(0, 0, x, y);
3103 cp = this.CreateParams;
3105 if (XplatUI.CalculateWindowRect(Handle, ref ClientRect, cp.Style, cp.ExStyle, IntPtr.Zero, out WindowRect)==false) {
3109 SetBoundsCore(bounds.X, bounds.Y, WindowRect.Width, WindowRect.Height, BoundsSpecified.Size);
3112 [EditorBrowsable(EditorBrowsableState.Advanced)]
3113 protected void SetStyle(ControlStyles flag, bool value) {
3115 control_style |= flag;
3117 control_style &= ~flag;
3119 OnStyleChanged(EventArgs.Empty);
3122 protected void SetTopLevel(bool value) {
3123 if ((GetTopLevel() != value) && (parent != null)) {
3124 throw new Exception();
3128 if (value == true) {
3138 is_toplevel = value;
3141 protected virtual void SetVisibleCore(bool value) {
3142 if (value!=is_visible) {
3144 XplatUI.SetVisible(Handle, value);
3145 // Explicitly move Toplevel windows to where we want them;
3146 // apparently moving unmapped toplevel windows doesn't work
3147 if (is_visible && (this is Form)) {
3148 XplatUI.SetWindowPos(window.Handle, bounds.X, bounds.Y, bounds.Width, bounds.Height);
3150 OnVisibleChanged(EventArgs.Empty);
3153 if (dc_mem != null) {
3158 if (bmp_mem != null) {
3163 this.CreateBuffers(bounds.Width, bounds.Height);
3168 if (value == false && parent != null) {
3171 // Need to start at parent, GetContainerControl might return ourselves if we're a container
3172 container = (Control)parent.GetContainerControl();
3173 if (container != null) {
3174 container.SelectNextControl(this, true, true, true, true);
3178 if (parent != null) {
3179 parent.PerformLayout(this, "visible");
3181 PerformLayout(this, "visible");
3186 [EditorBrowsable(EditorBrowsableState.Advanced)]
3187 protected void UpdateBounds() {
3195 if (!IsHandleCreated) {
3199 XplatUI.GetWindowPos(this.Handle, this is Form, out x, out y, out width, out height, out client_width, out client_height);
3201 UpdateBounds(x, y, width, height, client_width, client_height);
3204 [EditorBrowsable(EditorBrowsableState.Advanced)]
3205 protected void UpdateBounds(int x, int y, int width, int height) {
3206 // UpdateBounds only seems to set our sizes and fire events but not update the GUI window to match
3208 bool resized = false;
3210 int client_x_diff = this.bounds.Width-this.client_size.Width;
3211 int client_y_diff = this.bounds.Height-this.client_size.Height;
3213 // Needed to generate required notifications
3214 if ((this.bounds.X!=x) || (this.bounds.Y!=y)) {
3218 if ((this.Bounds.Width!=width) || (this.Bounds.Height!=height)) {
3225 bounds.Height=height;
3227 // Update client rectangle as well
3228 if (this.layout_suspended==0) {
3229 prev_size.Width=client_size.Width;
3230 prev_size.Height=client_size.Height;
3233 client_size.Width=width-client_x_diff;
3234 client_size.Height=height-client_y_diff;
3237 OnLocationChanged(EventArgs.Empty);
3241 OnSizeChanged(EventArgs.Empty);
3245 [EditorBrowsable(EditorBrowsableState.Advanced)]
3246 protected void UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) {
3247 UpdateBounds(x, y, width, height);
3249 this.client_size.Width=clientWidth;
3250 this.client_size.Height=clientHeight;
3253 [EditorBrowsable(EditorBrowsableState.Advanced)]
3254 protected void UpdateStyles() {
3255 if (!IsHandleCreated) {
3259 XplatUI.SetWindowStyle(window.Handle, CreateParams);
3262 [EditorBrowsable(EditorBrowsableState.Advanced)]
3263 protected void UpdateZOrder() {
3268 if (parent == null) {
3274 children = ctl.child_controls.Count;
3275 for (int i = 1; i < children; i++ ) {
3276 XplatUI.SetZOrder(ctl.child_controls[i].window.Handle, ctl.child_controls[i-1].window.Handle, false, false);
3279 children = child_controls.Count;
3280 for (int i = 1; i < children; i++ ) {
3281 XplatUI.SetZOrder(child_controls[i].window.Handle, child_controls[i-1].window.Handle, false, false);
3286 protected virtual void WndProc(ref Message m) {
3288 Console.WriteLine("Control received message {0}", (Msg)m.Msg);
3290 if ((this.control_style & ControlStyles.EnableNotifyMessage) != 0) {
3294 switch((Msg)m.Msg) {
3295 case Msg.WM_WINDOWPOSCHANGED: {
3298 if (GetStyle(ControlStyles.ResizeRedraw)) {
3305 case Msg.WM_PAINT: {
3306 PaintEventArgs paint_event;
3308 paint_event = XplatUI.PaintEventStart(Handle);
3310 if (!needs_redraw) {
3311 // Just blit the previous image
3312 paint_event.Graphics.DrawImage (ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle, GraphicsUnit.Pixel);
3313 XplatUI.PaintEventEnd(Handle);
3318 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
3319 dc = paint_event.SetGraphics (DeviceContext);
3322 if ((control_style & (ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint)) != (ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint)) {
3323 OnPaintBackground(paint_event);
3326 OnPaint(paint_event);
3328 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
3329 dc.DrawImage (ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle, GraphicsUnit.Pixel);
3330 paint_event.SetGraphics (dc);
3331 needs_redraw = false;
3334 XplatUI.PaintEventEnd(Handle);
3336 if (!GetStyle(ControlStyles.UserPaint)) {
3343 case Msg.WM_ERASEBKGND: {
3344 if (GetStyle (ControlStyles.UserPaint)) {
3345 if (!GetStyle(ControlStyles.AllPaintingInWmPaint)) {
3346 PaintEventArgs eraseEventArgs = new PaintEventArgs (m.WParam == IntPtr.Zero ? Graphics.FromHwnd (m.HWnd) :
3347 Graphics.FromHdc (m.WParam), new Rectangle (new Point (0,0),Size));
3348 OnPaintBackground (eraseEventArgs);
3351 XplatUI.EraseWindowBackground(m.HWnd, m.WParam);
3353 // The DefWndProc will never have to handle this, we don't ever set hbr on the window
3354 m.Result = (IntPtr)1;
3358 case Msg.WM_LBUTTONUP: {
3359 HandleClick(mouse_clicks);
3360 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Left,
3362 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3364 if (mouse_clicks > 1) {
3370 case Msg.WM_LBUTTONDOWN: {
3371 if (CanSelect && !is_selected) {
3374 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3375 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3381 case Msg.WM_LBUTTONDBLCLK: {
3383 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3384 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3390 case Msg.WM_MBUTTONUP: {
3391 HandleClick(mouse_clicks);
3392 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Middle,
3394 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3396 if (mouse_clicks > 1) {
3402 case Msg.WM_MBUTTONDOWN: {
3403 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3404 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3410 case Msg.WM_MBUTTONDBLCLK: {
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_RBUTTONUP: {
3419 if (context_menu != null) {
3420 context_menu.Show(this, new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ())));
3423 HandleClick(mouse_clicks);
3424 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Right,
3426 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3428 if (mouse_clicks > 1) {
3434 case Msg.WM_RBUTTONDOWN: {
3435 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3436 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3441 case Msg.WM_RBUTTONDBLCLK: {
3443 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3444 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3449 case Msg.WM_MOUSEWHEEL: {
3451 OnMouseWheel (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3452 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3453 HighOrder(m.WParam.ToInt32())));
3458 case Msg.WM_MOUSEMOVE: {
3459 OnMouseMove (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3461 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3466 case Msg.WM_MOUSE_ENTER: {
3471 OnMouseEnter(EventArgs.Empty);
3475 case Msg.WM_MOUSE_LEAVE: {
3477 OnMouseLeave(EventArgs.Empty);
3481 case Msg.WM_MOUSEHOVER: {
3482 OnMouseHover(EventArgs.Empty);
3486 case Msg.WM_SYSKEYDOWN:
3487 case Msg.WM_KEYDOWN:
3488 case Msg.WM_SYSKEYUP:
3490 case Msg.WM_SYSCHAR:
3492 if (ProcessKeyEventArgs(ref m)) {
3496 if (PreProcessMessage(ref m)) {
3500 if (ProcessKeyMessage(ref m)) {
3509 if (m.LParam != IntPtr.Zero) {
3512 hi = new HELPINFO();
3514 hi = (HELPINFO) Marshal.PtrToStructure (m.LParam, typeof (HELPINFO));
3515 mouse_pos = new Point(hi.MousePos.x, hi.MousePos.y);
3517 mouse_pos = Control.MousePosition;
3519 OnHelpRequested(new HelpEventArgs(mouse_pos));
3520 m.Result = (IntPtr)1;
3524 case Msg.WM_KILLFOCUS: {
3525 OnLeave(EventArgs.Empty);
3526 if (CausesValidation) {
3528 e = new CancelEventArgs(false);
3537 OnValidated(EventArgs.Empty);
3540 this.has_focus = false;
3541 this.is_selected = false;
3542 OnLostFocus(EventArgs.Empty);
3546 case Msg.WM_SETFOCUS: {
3547 OnEnter(EventArgs.Empty);
3548 this.has_focus = true;
3549 OnGotFocus(EventArgs.Empty);
3554 case Msg.WM_SYSCOLORCHANGE: {
3555 ThemeEngine.Current.ResetDefaults();
3556 OnSystemColorsChanged(EventArgs.Empty);
3561 case Msg.WM_SETCURSOR: {
3562 if (cursor == null) {
3567 XplatUI.SetCursor(window.Handle, cursor.handle);
3568 m.Result = (IntPtr)1;
3578 #endregion // Public Instance Methods
3580 #region OnXXX methods
3581 [EditorBrowsable(EditorBrowsableState.Advanced)]
3582 protected virtual void OnBackColorChanged(EventArgs e) {
3583 if (BackColorChanged!=null) BackColorChanged(this, e);
3584 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackColorChanged(e);
3587 [EditorBrowsable(EditorBrowsableState.Advanced)]
3588 protected virtual void OnBackgroundImageChanged(EventArgs e) {
3589 if (BackgroundImageChanged!=null) BackgroundImageChanged(this, e);
3590 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackgroundImageChanged(e);
3593 [EditorBrowsable(EditorBrowsableState.Advanced)]
3594 protected virtual void OnBindingContextChanged(EventArgs e) {
3595 CheckDataBindings ();
3596 if (BindingContextChanged!=null) {
3597 BindingContextChanged(this, e);
3599 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBindingContextChanged(e);
3602 [EditorBrowsable(EditorBrowsableState.Advanced)]
3603 protected virtual void OnCausesValidationChanged(EventArgs e) {
3604 if (CausesValidationChanged!=null) CausesValidationChanged(this, e);
3607 [EditorBrowsable(EditorBrowsableState.Advanced)]
3608 protected virtual void OnChangeUICues(UICuesEventArgs e) {
3609 if (ChangeUICues!=null) ChangeUICues(this, e);
3612 [EditorBrowsable(EditorBrowsableState.Advanced)]
3613 protected virtual void OnClick(EventArgs e) {
3614 if (Click!=null) Click(this, e);
3617 [EditorBrowsable(EditorBrowsableState.Advanced)]
3618 protected virtual void OnContextMenuChanged(EventArgs e) {
3619 if (ContextMenuChanged!=null) ContextMenuChanged(this, e);
3622 [EditorBrowsable(EditorBrowsableState.Advanced)]
3623 protected virtual void OnControlAdded(ControlEventArgs e) {
3624 if (ControlAdded!=null) ControlAdded(this, e);
3627 [EditorBrowsable(EditorBrowsableState.Advanced)]
3628 protected virtual void OnControlRemoved(ControlEventArgs e) {
3629 if (ControlRemoved!=null) ControlRemoved(this, e);
3632 [EditorBrowsable(EditorBrowsableState.Advanced)]
3633 protected virtual void OnCreateControl() {
3637 [EditorBrowsable(EditorBrowsableState.Advanced)]
3638 protected virtual void OnCursorChanged(EventArgs e) {
3639 if (CursorChanged!=null) CursorChanged(this, e);
3642 [EditorBrowsable(EditorBrowsableState.Advanced)]
3643 protected virtual void OnDockChanged(EventArgs e) {
3644 if (DockChanged!=null) DockChanged(this, e);
3647 [EditorBrowsable(EditorBrowsableState.Advanced)]
3648 protected virtual void OnDoubleClick(EventArgs e) {
3649 if (DoubleClick!=null) DoubleClick(this, e);
3652 [EditorBrowsable(EditorBrowsableState.Advanced)]
3653 protected virtual void OnDragDrop(DragEventArgs drgevent) {
3654 if (DragDrop!=null) DragDrop(this, drgevent);
3657 [EditorBrowsable(EditorBrowsableState.Advanced)]
3658 protected virtual void OnDragEnter(DragEventArgs drgevent) {
3659 if (DragEnter!=null) DragEnter(this, drgevent);
3662 [EditorBrowsable(EditorBrowsableState.Advanced)]
3663 protected virtual void OnDragLeave(EventArgs e) {
3664 if (DragLeave!=null) DragLeave(this, e);
3667 [EditorBrowsable(EditorBrowsableState.Advanced)]
3668 protected virtual void OnDragOver(DragEventArgs drgevent) {
3669 if (DragOver!=null) DragOver(this, drgevent);
3672 [EditorBrowsable(EditorBrowsableState.Advanced)]
3673 protected virtual void OnEnabledChanged(EventArgs e) {
3674 if (EnabledChanged!=null) EnabledChanged(this, e);
3675 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentEnabledChanged(e);
3678 [EditorBrowsable(EditorBrowsableState.Advanced)]
3679 protected virtual void OnEnter(EventArgs e) {
3680 if (Enter!=null) Enter(this, e);
3683 [EditorBrowsable(EditorBrowsableState.Advanced)]
3684 protected virtual void OnFontChanged(EventArgs e) {
3685 if (FontChanged!=null) FontChanged(this, e);
3686 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentFontChanged(e);
3689 [EditorBrowsable(EditorBrowsableState.Advanced)]
3690 protected virtual void OnForeColorChanged(EventArgs e) {
3691 if (ForeColorChanged!=null) ForeColorChanged(this, e);
3692 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentForeColorChanged(e);
3695 [EditorBrowsable(EditorBrowsableState.Advanced)]
3696 protected virtual void OnGiveFeedback(GiveFeedbackEventArgs gfbevent) {
3697 if (GiveFeedback!=null) GiveFeedback(this, gfbevent);
3700 [EditorBrowsable(EditorBrowsableState.Advanced)]
3701 protected virtual void OnGotFocus(EventArgs e) {
3702 if (GotFocus!=null) GotFocus(this, e);
3705 [EditorBrowsable(EditorBrowsableState.Advanced)]
3706 protected virtual void OnHandleCreated(EventArgs e) {
3707 if (HandleCreated!=null) HandleCreated(this, e);
3710 [EditorBrowsable(EditorBrowsableState.Advanced)]
3711 protected virtual void OnHandleDestroyed(EventArgs e) {
3712 if (HandleDestroyed!=null) HandleDestroyed(this, e);
3715 [EditorBrowsable(EditorBrowsableState.Advanced)]
3716 protected virtual void OnHelpRequested(HelpEventArgs hevent) {
3717 if (HelpRequested!=null) HelpRequested(this, hevent);
3720 protected virtual void OnImeModeChanged(EventArgs e) {
3721 if (ImeModeChanged!=null) ImeModeChanged(this, e);
3724 [EditorBrowsable(EditorBrowsableState.Advanced)]
3725 protected virtual void OnInvalidated(InvalidateEventArgs e) {
3726 needs_redraw = true;
3727 if (Invalidated!=null) Invalidated(this, e);
3730 [EditorBrowsable(EditorBrowsableState.Advanced)]
3731 protected virtual void OnKeyDown(KeyEventArgs e) {
3732 if (KeyDown!=null) KeyDown(this, e);
3735 [EditorBrowsable(EditorBrowsableState.Advanced)]
3736 protected virtual void OnKeyPress(KeyPressEventArgs e) {
3737 if (KeyPress!=null) KeyPress(this, e);
3740 [EditorBrowsable(EditorBrowsableState.Advanced)]
3741 protected virtual void OnKeyUp(KeyEventArgs e) {
3742 if (KeyUp!=null) KeyUp(this, e);
3745 [EditorBrowsable(EditorBrowsableState.Advanced)]
3746 protected virtual void OnLayout(LayoutEventArgs levent) {
3747 if (Layout!=null) Layout(this, levent);
3750 [EditorBrowsable(EditorBrowsableState.Advanced)]
3751 protected virtual void OnLeave(EventArgs e) {
3752 if (Leave!=null) Leave(this, e);
3755 [EditorBrowsable(EditorBrowsableState.Advanced)]
3756 protected virtual void OnLocationChanged(EventArgs e) {
3758 if (LocationChanged!=null) LocationChanged(this, e);
3761 [EditorBrowsable(EditorBrowsableState.Advanced)]
3762 protected virtual void OnLostFocus(EventArgs e) {
3763 if (LostFocus!=null) LostFocus(this, e);
3766 [EditorBrowsable(EditorBrowsableState.Advanced)]
3767 protected virtual void OnMouseDown(MouseEventArgs e) {
3768 if (MouseDown!=null) MouseDown(this, e);
3771 [EditorBrowsable(EditorBrowsableState.Advanced)]
3772 protected virtual void OnMouseEnter(EventArgs e) {
3773 if (MouseEnter!=null) MouseEnter(this, e);
3776 [EditorBrowsable(EditorBrowsableState.Advanced)]
3777 protected virtual void OnMouseHover(EventArgs e) {
3778 if (MouseHover!=null) MouseHover(this, e);
3781 [EditorBrowsable(EditorBrowsableState.Advanced)]
3782 protected virtual void OnMouseLeave(EventArgs e) {
3783 if (MouseLeave!=null) MouseLeave(this, e);
3786 [EditorBrowsable(EditorBrowsableState.Advanced)]
3787 protected virtual void OnMouseMove(MouseEventArgs e) {
3788 if (MouseMove!=null) MouseMove(this, e);
3791 [EditorBrowsable(EditorBrowsableState.Advanced)]
3792 protected virtual void OnMouseUp(MouseEventArgs e) {
3793 if (MouseUp!=null) MouseUp(this, e);
3796 [EditorBrowsable(EditorBrowsableState.Advanced)]
3797 protected virtual void OnMouseWheel(MouseEventArgs e) {
3798 if (MouseWheel!=null) MouseWheel(this, e);
3801 [EditorBrowsable(EditorBrowsableState.Advanced)]
3802 protected virtual void OnMove(EventArgs e) {
3803 if (Move!=null) Move(this, e);
3806 [EditorBrowsable(EditorBrowsableState.Advanced)]
3807 protected virtual void OnNotifyMessage(Message m) {
3811 [EditorBrowsable(EditorBrowsableState.Advanced)]
3812 protected virtual void OnPaint(PaintEventArgs e) {
3813 if (Paint!=null) Paint(this, e);
3816 [EditorBrowsable(EditorBrowsableState.Advanced)]
3817 protected virtual void OnPaintBackground(PaintEventArgs pevent) {
3818 PaintControlBackground (pevent);
3821 [EditorBrowsable(EditorBrowsableState.Advanced)]
3822 protected virtual void OnParentBackColorChanged(EventArgs e) {
3823 if (background_color.IsEmpty && background_image==null) {
3825 OnBackColorChanged(e);
3829 [EditorBrowsable(EditorBrowsableState.Advanced)]
3830 protected virtual void OnParentBackgroundImageChanged(EventArgs e) {
3831 if (background_color.IsEmpty && background_image==null) {
3833 OnBackgroundImageChanged(e);
3837 [EditorBrowsable(EditorBrowsableState.Advanced)]
3838 protected virtual void OnParentBindingContextChanged(EventArgs e) {
3839 if (binding_context==null) {
3840 binding_context=Parent.binding_context;
3841 OnBindingContextChanged(e);
3845 [EditorBrowsable(EditorBrowsableState.Advanced)]
3846 protected virtual void OnParentChanged(EventArgs e) {
3847 if (ParentChanged!=null) ParentChanged(this, e);
3850 [EditorBrowsable(EditorBrowsableState.Advanced)]
3851 protected virtual void OnParentEnabledChanged(EventArgs e) {
3852 if (is_enabled != Parent.is_enabled) {
3853 is_enabled=Parent.is_enabled;
3855 if (EnabledChanged != null) {
3856 EnabledChanged(this, e);
3861 [EditorBrowsable(EditorBrowsableState.Advanced)]
3862 protected virtual void OnParentFontChanged(EventArgs e) {
3869 [EditorBrowsable(EditorBrowsableState.Advanced)]
3870 protected virtual void OnParentForeColorChanged(EventArgs e) {
3871 if (foreground_color.IsEmpty) {
3873 OnForeColorChanged(e);
3877 [EditorBrowsable(EditorBrowsableState.Advanced)]
3878 protected virtual void OnParentRightToLeftChanged(EventArgs e) {
3879 if (right_to_left==RightToLeft.Inherit) {
3881 OnRightToLeftChanged(e);
3885 [EditorBrowsable(EditorBrowsableState.Advanced)]
3886 protected virtual void OnParentVisibleChanged(EventArgs e) {
3888 OnVisibleChanged(e);
3892 [EditorBrowsable(EditorBrowsableState.Advanced)]
3893 protected virtual void OnQueryContinueDrag(QueryContinueDragEventArgs e) {
3894 if (QueryContinueDrag!=null) QueryContinueDrag(this, e);
3897 [EditorBrowsable(EditorBrowsableState.Advanced)]
3898 protected virtual void OnResize(EventArgs e) {
3899 if (Resize!=null) Resize(this, e);
3901 PerformLayout(this, "bounds");
3903 if (parent != null) {
3904 parent.PerformLayout();
3908 [EditorBrowsable(EditorBrowsableState.Advanced)]
3909 protected virtual void OnRightToLeftChanged(EventArgs e) {
3910 if (RightToLeftChanged!=null) RightToLeftChanged(this, e);
3911 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentRightToLeftChanged(e);
3914 [EditorBrowsable(EditorBrowsableState.Advanced)]
3915 protected virtual void OnSizeChanged(EventArgs e) {
3916 InvalidateBuffers ();
3918 if (SizeChanged!=null) SizeChanged(this, e);
3921 [EditorBrowsable(EditorBrowsableState.Advanced)]
3922 protected virtual void OnStyleChanged(EventArgs e) {
3923 if (StyleChanged!=null) StyleChanged(this, e);
3926 [EditorBrowsable(EditorBrowsableState.Advanced)]
3927 protected virtual void OnSystemColorsChanged(EventArgs e) {
3928 if (SystemColorsChanged!=null) SystemColorsChanged(this, e);
3931 [EditorBrowsable(EditorBrowsableState.Advanced)]
3932 protected virtual void OnTabIndexChanged(EventArgs e) {
3933 if (TabIndexChanged!=null) TabIndexChanged(this, e);
3936 [EditorBrowsable(EditorBrowsableState.Advanced)]
3937 protected virtual void OnTabStopChanged(EventArgs e) {
3938 if (TabStopChanged!=null) TabStopChanged(this, e);
3941 [EditorBrowsable(EditorBrowsableState.Advanced)]
3942 protected virtual void OnTextChanged(EventArgs e) {
3943 if (TextChanged!=null) TextChanged(this, e);
3946 [EditorBrowsable(EditorBrowsableState.Advanced)]
3947 protected virtual void OnValidated(EventArgs e) {
3948 if (Validated!=null) Validated(this, e);
3951 [EditorBrowsable(EditorBrowsableState.Advanced)]
3952 protected virtual void OnValidating(System.ComponentModel.CancelEventArgs e) {
3953 if (Validating!=null) Validating(this, e);
3956 [EditorBrowsable(EditorBrowsableState.Advanced)]
3957 protected virtual void OnVisibleChanged(EventArgs e) {
3964 if (bmp_mem!=null) {
3970 if (!this.IsHandleCreated) {
3971 this.CreateControl();
3977 if (VisibleChanged!=null) VisibleChanged(this, e);
3979 // We need to tell our kids
3980 for (int i=0; i<child_controls.Count; i++) {
3981 child_controls[i].OnParentVisibleChanged(e);
3984 #endregion // OnXXX methods
3987 public event EventHandler BackColorChanged;
3988 public event EventHandler BackgroundImageChanged;
3989 public event EventHandler BindingContextChanged;
3990 public event EventHandler CausesValidationChanged;
3991 public event UICuesEventHandler ChangeUICues;
3992 public event EventHandler Click;
3993 public event EventHandler ContextMenuChanged;
3995 [EditorBrowsable(EditorBrowsableState.Advanced)]
3997 public event ControlEventHandler ControlAdded;
3999 [EditorBrowsable(EditorBrowsableState.Advanced)]
4001 public event ControlEventHandler ControlRemoved;
4003 [MWFDescription("Fired when the cursor for the control has been changed"), MWFCategory("PropertyChanged")]
4004 public event EventHandler CursorChanged;
4005 public event EventHandler DockChanged;
4006 public event EventHandler DoubleClick;
4007 public event DragEventHandler DragDrop;
4008 public event DragEventHandler DragEnter;
4009 public event EventHandler DragLeave;
4010 public event DragEventHandler DragOver;
4011 public event EventHandler EnabledChanged;
4012 public event EventHandler Enter;
4013 public event EventHandler FontChanged;
4014 public event EventHandler ForeColorChanged;
4015 public event GiveFeedbackEventHandler GiveFeedback;
4017 [EditorBrowsable(EditorBrowsableState.Advanced)]
4019 public event EventHandler GotFocus;
4021 [EditorBrowsable(EditorBrowsableState.Advanced)]
4023 public event EventHandler HandleCreated;
4025 [EditorBrowsable(EditorBrowsableState.Advanced)]
4027 public event EventHandler HandleDestroyed;
4029 public event HelpEventHandler HelpRequested;
4030 public event EventHandler ImeModeChanged;
4032 [EditorBrowsable(EditorBrowsableState.Advanced)]
4034 public event InvalidateEventHandler Invalidated;
4036 public event KeyEventHandler KeyDown;
4037 public event KeyPressEventHandler KeyPress;
4038 public event KeyEventHandler KeyUp;
4039 public event LayoutEventHandler Layout;
4040 public event EventHandler Leave;
4041 public event EventHandler LocationChanged;
4043 [EditorBrowsable(EditorBrowsableState.Advanced)]
4045 public event EventHandler LostFocus;
4047 public event MouseEventHandler MouseDown;
4048 public event EventHandler MouseEnter;
4049 public event EventHandler MouseHover;
4050 public event EventHandler MouseLeave;
4051 public event MouseEventHandler MouseMove;
4052 public event MouseEventHandler MouseUp;
4054 [EditorBrowsable(EditorBrowsableState.Advanced)]
4056 public event MouseEventHandler MouseWheel;
4058 public event EventHandler Move;
4059 public event PaintEventHandler Paint;
4060 public event EventHandler ParentChanged;
4061 public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp;
4062 public event QueryContinueDragEventHandler QueryContinueDrag;
4063 public event EventHandler Resize;
4064 public event EventHandler RightToLeftChanged;
4065 public event EventHandler SizeChanged;
4066 public event EventHandler StyleChanged;
4067 public event EventHandler SystemColorsChanged;
4068 public event EventHandler TabIndexChanged;
4069 public event EventHandler TabStopChanged;
4070 public event EventHandler TextChanged;
4071 public event EventHandler Validated;
4072 public event CancelEventHandler Validating;
4073 public event EventHandler VisibleChanged;
4074 #endregion // Events