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)
771 DrawBackgroundImage (pevent.Graphics);
774 void DrawBackgroundImage (Graphics g)
776 using (TextureBrush b = new TextureBrush (background_image)) {
777 g.FillRectangle (b, ClientRectangle);
781 internal void DndEnter (DragEventArgs e)
786 internal void DndOver (DragEventArgs e)
791 internal void DndDrop (DragEventArgs e)
796 internal void DndLeave (EventArgs e)
801 internal void DnDFeedback(GiveFeedbackEventArgs e)
806 internal void DnDContinueDrag(QueryContinueDragEventArgs e) {
807 OnQueryContinueDrag(e);
810 internal static MouseButtons FromParamToMouseButtons (int param) {
811 MouseButtons buttons = MouseButtons.None;
813 if ((param & (int) MsgButtons.MK_LBUTTON) != 0)
814 buttons |= MouseButtons.Left;
816 if ((param & (int) MsgButtons.MK_MBUTTON) != 0)
817 buttons |= MouseButtons.Middle;
819 if ((param & (int) MsgButtons.MK_RBUTTON) != 0)
820 buttons |= MouseButtons.Right;
826 internal virtual bool ProcessControlMnemonic(char charCode) {
827 return ProcessMnemonic(charCode);
830 private static Control FindFlatForward(Control container, Control start) {
836 end = container.child_controls.Count;
839 index = start.tab_index;
844 for (int i = 0; i < end; i++) {
846 if (container.child_controls[i].tab_index > index) {
847 found = container.child_controls[i];
849 } else if (found.tab_index > container.child_controls[i].tab_index) {
850 if (container.child_controls[i].tab_index > index) {
851 found = container.child_controls[i];
858 private static Control FindControlForward(Control container, Control start) {
865 if ((start is IContainerControl) || start.GetStyle(ControlStyles.ContainerControl)) {
866 found = FindControlForward(start, null);
873 while (p != container) {
874 found = FindFlatForward(p, start);
882 return FindFlatForward(container, start);
885 private static Control FindFlatBackward(Control container, Control start) {
891 end = container.child_controls.Count;
894 index = start.tab_index;
896 // FIXME: Possible speed-up: Keep the highest taborder index in the container
898 for (int i = 0; i < end; i++) {
899 if (container.child_controls[i].tab_index > index) {
900 index = container.child_controls[i].tab_index;
906 for (int i = 0; i < end; i++) {
908 if (container.child_controls[i].tab_index < index) {
909 found = container.child_controls[i];
911 } else if (found.tab_index < container.child_controls[i].tab_index) {
912 if (container.child_controls[i].tab_index < index) {
913 found = container.child_controls[i];
920 private static Control FindControlBackward(Control container, Control start) {
926 found = FindFlatBackward(start.parent, start);
927 if (found == null && start.parent != container) {
932 found = FindFlatBackward(container, start);
935 while ((found != null) && ((found is IContainerControl) || found.GetStyle(ControlStyles.ContainerControl))) {
936 found = FindControlBackward(found, null);
945 private void HandleClick(int clicks) {
946 if (GetStyle(ControlStyles.StandardClick)) {
948 if (GetStyle(ControlStyles.StandardDoubleClick)) {
949 OnDoubleClick(EventArgs.Empty);
951 OnClick(EventArgs.Empty);
954 OnClick(EventArgs.Empty);
959 private void CheckDataBindings ()
961 if (data_bindings == null)
964 BindingContext binding_context = BindingContext;
965 foreach (Binding binding in data_bindings) {
966 binding.Check (binding_context);
970 #endregion // Private & Internal Methods
972 #region Public Static Properties
973 public static Color DefaultBackColor {
975 return ThemeEngine.Current.DefaultControlBackColor;
979 public static Font DefaultFont {
981 return ThemeEngine.Current.DefaultFont;
985 public static Color DefaultForeColor {
987 return ThemeEngine.Current.DefaultControlForeColor;
991 public static Keys ModifierKeys {
993 return XplatUI.State.ModifierKeys;
997 public static MouseButtons MouseButtons {
999 return XplatUI.State.MouseButtons;
1003 public static Point MousePosition {
1005 return Cursor.Position;
1011 public static bool CheckForIllegalCrossThreadCalls
1020 #endregion // Public Static Properties
1022 #region Public Instance Properties
1023 [EditorBrowsable(EditorBrowsableState.Advanced)]
1025 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1026 public AccessibleObject AccessibilityObject {
1028 if (accessibility_object==null) {
1029 accessibility_object=CreateAccessibilityInstance();
1031 return accessibility_object;
1035 [EditorBrowsable(EditorBrowsableState.Advanced)]
1037 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1038 public string AccessibleDefaultActionDescription {
1040 return AccessibilityObject.default_action;
1044 AccessibilityObject.default_action=value;
1049 [DefaultValue(null)]
1050 public string AccessibleDescription {
1052 return AccessibilityObject.description;
1056 AccessibilityObject.description=value;
1061 [DefaultValue(null)]
1062 public string AccessibleName {
1064 return AccessibilityObject.Name;
1068 AccessibilityObject.Name=value;
1072 [DefaultValue(AccessibleRole.Default)]
1073 [MWFDescription("Role of the control"), MWFCategory("Accessibility")]
1074 public AccessibleRole AccessibleRole {
1076 return AccessibilityObject.role;
1080 AccessibilityObject.role=value;
1084 [DefaultValue(false)]
1085 public virtual bool AllowDrop {
1091 if (allow_drop == value)
1095 XplatUI.SetAllowDrop (Handle, value);
1100 [RefreshProperties(RefreshProperties.Repaint)]
1101 [DefaultValue(AnchorStyles.Top | AnchorStyles.Left)]
1102 public virtual AnchorStyles Anchor {
1104 return anchor_style;
1110 if (parent != null) {
1111 parent.PerformLayout(this, "Parent");
1117 public virtual Color BackColor {
1119 if (background_color.IsEmpty) {
1121 return parent.BackColor;
1123 return DefaultBackColor;
1125 return background_color;
1129 background_color=value;
1130 if (this.IsHandleCreated) {
1131 XplatUI.SetWindowBackground(this.window.Handle, value);
1133 SetChildColor(this);
1134 OnBackColorChanged(EventArgs.Empty);
1140 [DefaultValue(null)]
1141 public virtual Image BackgroundImage {
1143 return background_image;
1147 if (background_image!=value) {
1148 background_image=value;
1149 OnBackgroundImageChanged(EventArgs.Empty);
1154 [EditorBrowsable(EditorBrowsableState.Advanced)]
1156 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1157 public virtual BindingContext BindingContext {
1159 if (binding_context != null)
1160 return binding_context;
1163 binding_context = Parent.BindingContext;
1164 return binding_context;
1167 if (binding_context != value) {
1168 binding_context = value;
1169 OnBindingContextChanged(EventArgs.Empty);
1174 [EditorBrowsable(EditorBrowsableState.Advanced)]
1176 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1179 return bounds.Y+bounds.Height;
1183 [EditorBrowsable(EditorBrowsableState.Advanced)]
1185 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1186 public Rectangle Bounds {
1192 SetBoundsCore(value.Left, value.Top, value.Width, value.Height, BoundsSpecified.All);
1196 [EditorBrowsable(EditorBrowsableState.Advanced)]
1198 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1199 public bool CanFocus {
1201 if (Visible && is_enabled && GetStyle(ControlStyles.Selectable)) {
1208 [EditorBrowsable(EditorBrowsableState.Advanced)]
1210 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1211 public bool CanSelect {
1215 if (!GetStyle(ControlStyles.Selectable) || this.parent == null) {
1219 parent = this.parent;
1220 while (parent != null) {
1221 if (!parent.is_visible || !parent.is_enabled) {
1225 parent = parent.parent;
1231 [EditorBrowsable(EditorBrowsableState.Advanced)]
1233 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1234 public bool Capture {
1236 return this.is_captured;
1240 if (this.IsHandleCreated) {
1241 if (value && !is_captured) {
1243 XplatUI.GrabWindow(this.window.Handle, IntPtr.Zero);
1244 } else if (!value && is_captured) {
1245 XplatUI.UngrabWindow(this.window.Handle);
1246 is_captured = false;
1252 [DefaultValue(true)]
1253 public bool CausesValidation {
1255 return this.causes_validation;
1259 if (this.causes_validation != value) {
1260 causes_validation = value;
1261 OnCausesValidationChanged(EventArgs.Empty);
1266 [EditorBrowsable(EditorBrowsableState.Advanced)]
1268 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1269 public Rectangle ClientRectangle {
1271 client_rect.Width = client_size.Width;
1272 client_rect.Height = client_size.Height;
1277 [EditorBrowsable(EditorBrowsableState.Advanced)]
1279 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1280 public Size ClientSize {
1283 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1284 return ((Form)this).form_parent_window.ClientSize;
1292 this.SetClientSizeCore(value.Width, value.Height);
1296 [EditorBrowsable(EditorBrowsableState.Advanced)]
1298 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1299 [DescriptionAttribute("ControlCompanyNameDescr")]
1300 public String CompanyName {
1302 return "Mono Project, Novell, Inc.";
1306 [EditorBrowsable(EditorBrowsableState.Advanced)]
1308 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1309 public bool ContainsFocus {
1315 for (int i=0; i < child_controls.Count; i++) {
1316 if (child_controls[i].ContainsFocus) {
1324 [DefaultValue(null)]
1325 public virtual ContextMenu ContextMenu {
1327 return context_menu;
1331 if (context_menu != value) {
1332 context_menu = value;
1333 OnContextMenuChanged(EventArgs.Empty);
1339 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
1340 public ControlCollection Controls {
1342 return this.child_controls;
1346 [EditorBrowsable(EditorBrowsableState.Advanced)]
1348 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1349 public bool Created {
1351 if (!this.is_disposed && (this.window.Handle != IntPtr.Zero)) {
1358 [AmbientValue(null)]
1359 public virtual Cursor Cursor {
1361 if (cursor != null) {
1365 if (parent != null) {
1366 return parent.Cursor;
1369 return Cursors.Default;
1373 if (cursor != value) {
1378 pt = Cursor.Position;
1379 if (bounds.Contains(pt)) {
1380 if (GetChildAtPoint(pt) == null) {
1381 if (cursor != null) {
1382 XplatUI.SetCursor(window.Handle, cursor.handle);
1384 if (parent != null) {
1385 XplatUI.SetCursor(window.Handle, parent.Cursor.handle);
1387 XplatUI.SetCursor(window.Handle, Cursors.def.handle);
1393 OnCursorChanged(EventArgs.Empty);
1399 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
1400 [ParenthesizePropertyName(true)]
1401 [RefreshProperties(RefreshProperties.All)]
1402 public ControlBindingsCollection DataBindings {
1404 if (data_bindings == null)
1405 data_bindings = new ControlBindingsCollection (this);
1406 return data_bindings;
1410 [EditorBrowsable(EditorBrowsableState.Advanced)]
1412 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1413 public virtual Rectangle DisplayRectangle {
1415 return ClientRectangle;
1419 [EditorBrowsable(EditorBrowsableState.Advanced)]
1421 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1422 public bool Disposing {
1429 [RefreshProperties(RefreshProperties.Repaint)]
1430 [DefaultValue(DockStyle.None)]
1431 public virtual DockStyle Dock {
1437 if (dock_style == value) {
1443 if (parent != null) {
1444 parent.PerformLayout(this, "Parent");
1447 OnDockChanged(EventArgs.Empty);
1453 public bool Enabled {
1459 if (is_enabled == value) {
1465 OnEnabledChanged (EventArgs.Empty);
1469 [EditorBrowsable(EditorBrowsableState.Advanced)]
1471 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1472 public virtual bool Focused {
1474 return this.has_focus;
1479 [AmbientValue(null)]
1481 public virtual Font Font {
1487 if (Parent != null && Parent.Font != null) {
1495 if (font != null && font.Equals (value)) {
1501 OnFontChanged (EventArgs.Empty);
1506 public virtual Color ForeColor {
1508 if (foreground_color.IsEmpty) {
1510 return parent.ForeColor;
1512 return DefaultForeColor;
1514 return foreground_color;
1518 if (foreground_color != value) {
1519 foreground_color=value;
1521 OnForeColorChanged(EventArgs.Empty);
1528 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1529 public IntPtr Handle { // IWin32Window
1531 if (!IsHandleCreated) {
1534 return window.Handle;
1538 [EditorBrowsable(EditorBrowsableState.Advanced)]
1540 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1541 public bool HasChildren {
1543 if (this.child_controls.Count>0) {
1550 [EditorBrowsable(EditorBrowsableState.Always)]
1552 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1555 return this.bounds.Height;
1559 SetBoundsCore(bounds.X, bounds.Y, bounds.Width, value, BoundsSpecified.Height);
1563 [AmbientValue(ImeMode.Inherit)]
1565 public ImeMode ImeMode {
1567 if (ime_mode == DefaultImeMode) {
1569 return parent.ImeMode;
1571 return ImeMode.NoControl; // default value
1577 if (ime_mode != value) {
1580 OnImeModeChanged(EventArgs.Empty);
1585 [EditorBrowsable(EditorBrowsableState.Advanced)]
1587 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1588 public bool InvokeRequired { // ISynchronizeInvoke
1590 if (creator_thread!=Thread.CurrentThread) {
1597 [EditorBrowsable(EditorBrowsableState.Advanced)]
1599 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1600 public bool IsAccessible {
1602 return is_accessible;
1606 is_accessible = value;
1610 [EditorBrowsable(EditorBrowsableState.Advanced)]
1612 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1613 public bool IsDisposed {
1615 return this.is_disposed;
1619 [EditorBrowsable(EditorBrowsableState.Advanced)]
1621 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1622 public bool IsHandleCreated {
1624 if ((window!=null) && (window.Handle!=IntPtr.Zero)) {
1632 [EditorBrowsable(EditorBrowsableState.Always)]
1634 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1637 return this.bounds.X;
1641 SetBoundsCore(value, bounds.Y, bounds.Width, bounds.Height, BoundsSpecified.X);
1646 public Point Location {
1648 return new Point(bounds.X, bounds.Y);
1652 SetBoundsCore(value.X, value.Y, bounds.Width, bounds.Height, BoundsSpecified.Location);
1657 public string Name {
1668 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1669 public Control Parent {
1675 if (value == this) {
1676 throw new ArgumentException("A circular control reference has been made. A control cannot be owned or parented to itself.");
1679 if (parent!=value) {
1681 parent.Controls.Remove(this);
1687 if (!parent.Controls.Contains(this)) {
1688 parent.Controls.Add(this);
1691 XplatUI.SetParent(Handle, value.Handle);
1695 OnParentChanged(EventArgs.Empty);
1700 [EditorBrowsable(EditorBrowsableState.Advanced)]
1702 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1703 public string ProductName {
1705 Type t = typeof (AssemblyProductAttribute);
1706 Assembly assembly = GetType().Module.Assembly;
1707 object [] attrs = assembly.GetCustomAttributes (t, false);
1708 AssemblyProductAttribute a = null;
1709 // On MS we get a NullRefException if product attribute is not
1711 if (attrs != null && attrs.Length > 0)
1712 a = (AssemblyProductAttribute) attrs [0];
1717 [EditorBrowsable(EditorBrowsableState.Advanced)]
1719 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1720 public string ProductVersion {
1722 Type t = typeof (AssemblyVersionAttribute);
1723 Assembly assembly = GetType().Module.Assembly;
1724 object [] attrs = assembly.GetCustomAttributes (t, false);
1725 if (attrs == null || attrs.Length < 1)
1727 return ((AssemblyVersionAttribute)attrs [0]).Version;
1731 [EditorBrowsable(EditorBrowsableState.Advanced)]
1733 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1734 public bool RecreatingHandle {
1736 return is_recreating;
1740 [EditorBrowsable(EditorBrowsableState.Advanced)]
1742 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1743 public Region Region {
1745 return new Region(this.bounds);
1752 g = this.CreateGraphics();
1753 r = value.GetBounds(g);
1755 SetBounds((int)r.X, (int)r.Y, (int)r.Width, (int)r.Height);
1761 [EditorBrowsable(EditorBrowsableState.Advanced)]
1763 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1766 return this.bounds.X+this.bounds.Width;
1770 [AmbientValue(RightToLeft.Inherit)]
1772 public virtual RightToLeft RightToLeft {
1774 if (right_to_left == RightToLeft.Inherit) {
1776 return parent.RightToLeft;
1778 return RightToLeft.No; // default value
1780 return right_to_left;
1784 if (value != right_to_left) {
1785 right_to_left = value;
1786 OnRightToLeftChanged(EventArgs.Empty);
1791 [EditorBrowsable(EditorBrowsableState.Advanced)]
1792 public override ISite Site {
1805 return new Size(Width, Height);
1809 SetBoundsCore(bounds.X, bounds.Y, value.Width, value.Height, BoundsSpecified.Size);
1814 [MergableProperty(false)]
1815 public int TabIndex {
1817 if (tab_index != -1) {
1824 if (tab_index != value) {
1826 OnTabIndexChanged(EventArgs.Empty);
1832 [DefaultValue(true)]
1833 public bool TabStop {
1839 if (tab_stop != value) {
1841 OnTabStopChanged(EventArgs.Empty);
1846 [Localizable(false)]
1848 [TypeConverter(typeof(StringConverter))]
1849 [DefaultValue(null)]
1856 control_tag = value;
1862 [BindableAttribute(true)]
1863 public virtual string Text {
1869 if (value == null) {
1870 value = String.Empty;
1875 XplatUI.Text(Handle, text);
1876 // FIXME: Do we need a Refresh() here?
1877 OnTextChanged (EventArgs.Empty);
1882 [EditorBrowsable(EditorBrowsableState.Always)]
1884 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1887 return this.bounds.Y;
1891 SetBoundsCore(bounds.X, value, bounds.Width, bounds.Height, BoundsSpecified.Y);
1895 [EditorBrowsable(EditorBrowsableState.Advanced)]
1897 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1898 public Control TopLevelControl {
1902 while (p.parent != null) {
1911 public bool Visible {
1915 } else if (parent != null) {
1916 return parent.Visible;
1923 SetVisibleCore(value);
1927 [EditorBrowsable(EditorBrowsableState.Always)]
1929 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1932 return this.bounds.Width;
1936 SetBoundsCore(bounds.X, bounds.Y, value, bounds.Height, BoundsSpecified.Width);
1940 [EditorBrowsable(EditorBrowsableState.Never)]
1942 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1943 public IWindowTarget WindowTarget {
1952 #endregion // Public Instance Properties
1954 #region Protected Instance Properties
1955 protected virtual CreateParams CreateParams {
1957 CreateParams create_params = new CreateParams();
1960 create_params.Caption = Text;
1963 create_params.Caption = text;
1967 create_params.X = Left;
1970 create_params.X = this.bounds.X;
1974 create_params.Y = Top;
1977 create_params.Y = this.bounds.Y;
1981 create_params.Width = Width;
1984 create_params.Width = this.bounds.Width;
1988 create_params.Height = Height;
1991 create_params.Height = this.bounds.Height;
1995 create_params.ClassName = XplatUI.DefaultClassName;
1996 create_params.ClassStyle = 0;
1997 create_params.ExStyle = 0;
1998 create_params.Param = 0;
2001 create_params.ExStyle |= (int)WindowStyles.WS_EX_ACCEPTFILES;
2005 create_params.Parent = parent.Handle;
2008 create_params.Style = (int)WindowStyles.WS_CHILD | (int)WindowStyles.WS_CLIPCHILDREN | (int)WindowStyles.WS_CLIPSIBLINGS;
2011 create_params.Style |= (int)WindowStyles.WS_VISIBLE;
2014 return create_params;
2018 protected virtual ImeMode DefaultImeMode {
2020 return ImeMode.Inherit;
2024 protected virtual Size DefaultSize {
2026 return new Size(100, 23);
2030 protected int FontHeight {
2040 protected bool RenderRightToLeft {
2042 return (this.right_to_left == RightToLeft.Yes);
2046 protected bool ResizeRedraw {
2048 return GetStyle(ControlStyles.ResizeRedraw);
2052 SetStyle(ControlStyles.ResizeRedraw, value);
2056 [EditorBrowsable(EditorBrowsableState.Advanced)]
2058 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2059 protected virtual bool ShowFocusCues {
2065 [EditorBrowsable(EditorBrowsableState.Advanced)]
2067 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2068 protected bool ShowKeyboardCues {
2073 #endregion // Protected Instance Properties
2075 #region Public Static Methods
2076 [EditorBrowsable(EditorBrowsableState.Advanced)]
2077 public static Control FromChildHandle(IntPtr handle) {
2078 IEnumerator control = Control.controls.GetEnumerator();
2080 while (control.MoveNext()) {
2081 if (((Control)control.Current).window.Handle == handle) {
2083 if (((Control)control.Current).Parent != null) {
2084 return ((Control)control.Current).Parent;
2091 [EditorBrowsable(EditorBrowsableState.Advanced)]
2092 public static Control FromHandle(IntPtr handle) {
2093 IEnumerator control = Control.controls.GetEnumerator();
2095 while (control.MoveNext()) {
2096 if (((Control)control.Current).window.Handle == handle) {
2098 return ((Control)control.Current);
2104 public static bool IsMnemonic(char charCode, string text) {
2107 amp = text.IndexOf('&');
2110 if (amp + 1 < text.Length) {
2111 if (text[amp + 1] != '&') {
2112 if (Char.ToUpper(charCode) == Char.ToUpper(text.ToCharArray(amp + 1, 1)[0])) {
2122 #region Protected Static Methods
2123 [EditorBrowsable(EditorBrowsableState.Advanced)]
2124 protected static bool ReflectMessage(IntPtr hWnd, ref Message m) {
2127 c = Control.FromHandle(hWnd);
2137 #region Public Instance Methods
2138 [EditorBrowsable(EditorBrowsableState.Advanced)]
2139 public IAsyncResult BeginInvoke(Delegate method) {
2140 return BeginInvokeInternal(method, null);
2143 [EditorBrowsable(EditorBrowsableState.Advanced)]
2144 public IAsyncResult BeginInvoke (Delegate method, object[] args) {
2145 return BeginInvokeInternal (method, args);
2148 public void BringToFront() {
2149 if ((parent != null) && (parent.child_controls[0]!=this)) {
2150 if (parent.child_controls.Contains(this)) {
2151 parent.child_controls.SetChildIndex(this, 0);
2155 XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, true, false);
2157 if (parent != null) {
2162 public bool Contains(Control ctl) {
2163 while (ctl != null) {
2172 public void CreateControl() {
2174 if (!IsHandleCreated) {
2178 if (!create_handled) {
2179 create_handled = true;
2183 for (int i=0; i<child_controls.Count; i++) {
2184 child_controls[i].CreateControl();
2188 public Graphics CreateGraphics() {
2189 if (!IsHandleCreated) {
2190 this.CreateControl();
2192 return Graphics.FromHwnd(this.window.Handle);
2195 public DragDropEffects DoDragDrop(object data, DragDropEffects allowedEffects) {
2196 return XplatUI.StartDrag(this.window.Handle, data, allowedEffects);
2199 [EditorBrowsable(EditorBrowsableState.Advanced)]
2200 public object EndInvoke (IAsyncResult async_result) {
2201 AsyncMethodResult result = (AsyncMethodResult) async_result;
2202 return result.EndInvoke ();
2205 public Form FindForm() {
2218 public bool Focus() {
2219 if (IsHandleCreated && !has_focus) {
2221 XplatUI.SetFocus(window.Handle);
2226 public Control GetChildAtPoint(Point pt) {
2227 // Microsoft's version of this function doesn't seem to work, so I can't check
2228 // if we only consider children or also grandchildren, etc.
2229 // I'm gonna say 'children only'
2230 for (int i=0; i<child_controls.Count; i++) {
2231 if (child_controls[i].Bounds.Contains(pt)) {
2232 return child_controls[i];
2238 public IContainerControl GetContainerControl() {
2239 Control current = this;
2241 while (current!=null) {
2242 if ((current is IContainerControl) && ((current.control_style & ControlStyles.ContainerControl)!=0)) {
2243 return (IContainerControl)current;
2245 current = current.parent;
2250 public Control GetNextControl(Control ctl, bool forward) {
2251 // If we're not a container we don't play
2252 if (!(this is IContainerControl) && !this.GetStyle(ControlStyles.ContainerControl)) {
2256 // If ctl is not contained by this, we start at the first child of this
2257 if (!this.Contains(ctl)) {
2261 // Search through our controls, starting at ctl, stepping into children as we encounter them
2262 // try to find the control with the tabindex closest to our own, or, if we're looking into
2263 // child controls, the one with the smallest tabindex
2265 return FindControlForward(this, ctl);
2267 return FindControlBackward(this, ctl);
2270 public void Hide() {
2271 this.Visible = false;
2274 public void Invalidate() {
2275 Invalidate(ClientRectangle, false);
2278 public void Invalidate(bool invalidateChildren) {
2279 Invalidate(ClientRectangle, invalidateChildren);
2282 public void Invalidate(System.Drawing.Rectangle rc) {
2283 Invalidate(rc, false);
2286 public void Invalidate(System.Drawing.Rectangle rc, bool invalidateChildren) {
2287 if (!IsHandleCreated || !Visible) {
2291 NotifyInvalidate(rc);
2293 XplatUI.Invalidate(Handle, rc, false);
2295 if (invalidateChildren) {
2296 for (int i=0; i<child_controls.Count; i++) child_controls[i].Invalidate();
2298 OnInvalidated(new InvalidateEventArgs(rc));
2301 public void Invalidate(System.Drawing.Region region) {
2302 Invalidate(region, false);
2305 [MonoTODO("Figure out if GetRegionScans is usable")]
2306 public void Invalidate(System.Drawing.Region region, bool invalidateChildren) {
2307 throw new NotImplementedException();
2309 // FIXME - should use the GetRegionScans function of the region to invalidate each area
2310 //if (invalidateChildren) {
2311 // for (int i=0; i<child_controls.Count; i++) child_controls[i].Invalidate();
2315 public object Invoke (Delegate method) {
2316 return Invoke(method, null);
2319 public object Invoke (Delegate method, object[] args) {
2320 if (!this.InvokeRequired) {
2321 return method.DynamicInvoke(args);
2324 IAsyncResult result = BeginInvoke (method, args);
2325 return EndInvoke(result);
2328 [EditorBrowsable(EditorBrowsableState.Advanced)]
2329 public void PerformLayout() {
2330 PerformLayout(null, null);
2333 [EditorBrowsable(EditorBrowsableState.Advanced)]
2334 public void PerformLayout(Control affectedControl, string affectedProperty) {
2335 LayoutEventArgs levent = new LayoutEventArgs(affectedControl, affectedProperty);
2337 if (layout_suspended>0) {
2338 layout_pending = true;
2342 layout_pending = false;
2344 // Prevent us from getting messed up
2347 // Perform all Dock and Anchor calculations
2350 AnchorStyles anchor;
2355 space=this.DisplayRectangle;
2356 if (prev_size != Size.Empty) {
2357 diff_width = space.Width - prev_size.Width;
2358 diff_height = space.Height - prev_size.Height;
2364 // Deal with docking; go through in reverse, MS docs say that lowest Z-order is closest to edge
2365 for (int i = child_controls.Count - 1; i >= 0; i--) {
2366 child=child_controls[i];
2367 switch (child.Dock) {
2368 case DockStyle.None: {
2373 case DockStyle.Left: {
2374 child.SetBounds(space.Left, space.Y, child.Width, space.Height);
2375 space.X+=child.Width;
2376 space.Width-=child.Width;
2380 case DockStyle.Top: {
2381 child.SetBounds(space.Left, space.Y, space.Width, child.Height);
2382 space.Y+=child.Height;
2383 space.Height-=child.Height;
2387 case DockStyle.Right: {
2388 child.SetBounds(space.Right-child.Width, space.Y, child.Width, space.Height);
2389 space.Width-=child.Width;
2393 case DockStyle.Bottom: {
2394 child.SetBounds(space.Left, space.Bottom-child.Height, space.Width, child.Height);
2395 space.Height-=child.Height;
2401 for (int i = child_controls.Count - 1; i >= 0; i--) {
2402 child=child_controls[i];
2404 if (child.Dock == DockStyle.Fill) {
2405 child.SetBounds(space.Left, space.Top, space.Width, space.Height);
2411 space=this.DisplayRectangle;
2413 // Deal with anchoring
2414 for (int i=0; i < child_controls.Count; i++) {
2420 child=child_controls[i];
2421 anchor=child.Anchor;
2426 height=child.Height;
2428 // If the control is docked we don't need to do anything
2429 if (child.Dock != DockStyle.None) {
2433 if ((anchor & AnchorStyles.Left) !=0 ) {
2434 if ((anchor & AnchorStyles.Right) != 0) {
2435 // Anchoring to left and right
2436 width=width+diff_width;
2440 } else if ((anchor & AnchorStyles.Right) != 0) {
2446 if ((anchor & AnchorStyles.Top) !=0 ) {
2447 if ((anchor & AnchorStyles.Bottom) != 0) {
2448 height+=diff_height;
2452 } else if ((anchor & AnchorStyles.Bottom) != 0) {
2467 child.SetBounds(left, top, width, height);
2470 // Let everyone know
2474 // Need to make sure we decremend layout_suspended
2480 public Point PointToClient (Point p) {
2484 XplatUI.ScreenToClient (Handle, ref x, ref y);
2486 return new Point (x, y);
2489 public Point PointToScreen(Point p) {
2493 XplatUI.ClientToScreen(Handle, ref x, ref y);
2495 return new Point(x, y);
2498 public virtual bool PreProcessMessage(ref Message msg) {
2501 if ((msg.Msg == (int)Msg.WM_KEYDOWN) || (msg.Msg == (int)Msg.WM_SYSKEYDOWN)) {
2502 key_data = (Keys)msg.WParam.ToInt32();
2503 if (!ProcessCmdKey(ref msg, key_data)) {
2504 if (IsInputKey(key_data)) {
2508 return ProcessDialogKey(key_data);
2512 } else if (msg.Msg == (int)Msg.WM_CHAR) {
2513 if (IsInputChar((char)msg.WParam)) {
2516 } else if (msg.Msg == (int)Msg.WM_SYSCHAR) {
2517 if (IsInputChar((char)msg.WParam)) {
2520 return ProcessDialogChar((char)msg.WParam);
2525 public Rectangle RectangleToClient(Rectangle r) {
2526 return new Rectangle(PointToClient(r.Location), r.Size);
2529 public Rectangle RectangleToScreen(Rectangle r) {
2530 return new Rectangle(PointToScreen(r.Location), r.Size);
2533 public virtual void Refresh() {
2534 if (IsHandleCreated == true) {
2536 XplatUI.UpdateWindow(window.Handle);
2540 [EditorBrowsable(EditorBrowsableState.Never)]
2541 public virtual void ResetBackColor() {
2542 background_color = Color.Empty;
2545 [EditorBrowsable(EditorBrowsableState.Never)]
2547 public void ResetBindings() {
2551 [EditorBrowsable(EditorBrowsableState.Never)]
2552 public virtual void ResetCursor() {
2556 [EditorBrowsable(EditorBrowsableState.Never)]
2557 public virtual void ResetFont() {
2561 [EditorBrowsable(EditorBrowsableState.Never)]
2562 public virtual void ResetForeColor() {
2563 foreground_color = Color.Empty;
2566 [EditorBrowsable(EditorBrowsableState.Never)]
2567 public void ResetImeMode() {
2568 ime_mode = DefaultImeMode;
2571 [EditorBrowsable(EditorBrowsableState.Never)]
2572 public virtual void ResetRightToLeft() {
2573 right_to_left = RightToLeft.Inherit;
2576 public virtual void ResetText() {
2580 public void ResumeLayout() {
2581 ResumeLayout (true);
2584 public void ResumeLayout(bool performLayout) {
2587 if (layout_suspended > 0) {
2591 if (performLayout || layout_pending) {
2596 public void Scale(float ratio) {
2597 ScaleCore(ratio, ratio);
2600 public void Scale(float dx, float dy) {
2604 public void Select() {
2605 Select(false, false);
2608 public bool SelectNextControl(Control ctl, bool forward, bool tabStopOnly, bool nested, bool wrap) {
2613 c = GetNextControl(c, forward);
2622 if (c.CanSelect && ((c.parent == ctl.parent) || nested) && (c.tab_stop || !tabStopOnly)) {
2626 } while (c != ctl); // If we wrap back to ourselves we stop
2631 public void SendToBack() {
2632 if ((parent != null) && (parent.child_controls[parent.child_controls.Count-1]!=this)) {
2633 if (parent.child_controls.Contains(this)) {
2634 parent.child_controls.SetChildIndex(this, parent.child_controls.Count);
2638 XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, false, true);
2639 if (parent != null) {
2644 public void SetBounds(int x, int y, int width, int height) {
2645 SetBoundsCore(x, y, width, height, BoundsSpecified.All);
2648 public void SetBounds(int x, int y, int width, int height, BoundsSpecified specified) {
2649 SetBoundsCore(x, y, width, height, specified);
2652 public void Show() {
2653 if (!IsHandleCreated) {
2654 this.CreateControl();
2660 public void SuspendLayout() {
2664 public void Update() {
2665 needs_redraw = true;
2666 XplatUI.UpdateWindow(window.Handle);
2668 #endregion // Public Instance Methods
2670 #region Protected Instance Methods
2671 [EditorBrowsable(EditorBrowsableState.Advanced)]
2672 [MonoTODO("Implement this and tie it into Control.ControlAccessibleObject.NotifyClients")]
2673 protected void AccessibilityNotifyClients(AccessibleEvents accEvent, int childID) {
2674 throw new NotImplementedException();
2677 [EditorBrowsable(EditorBrowsableState.Advanced)]
2678 protected virtual AccessibleObject CreateAccessibilityInstance() {
2679 return new Control.ControlAccessibleObject(this);
2682 [EditorBrowsable(EditorBrowsableState.Advanced)]
2683 protected virtual ControlCollection CreateControlsInstance() {
2684 return new ControlCollection(this);
2687 [EditorBrowsable(EditorBrowsableState.Advanced)]
2688 protected virtual void CreateHandle() {
2690 throw new ObjectDisposedException(Name);
2693 if (IsHandleCreated) {
2697 window.CreateHandle(CreateParams);
2699 // Find out where the window manager placed us
2703 if (window.Handle!=IntPtr.Zero) {
2704 if (!controls.Contains(window.Handle)) {
2708 creator_thread = Thread.CurrentThread;
2710 XplatUI.SetWindowBackground(window.Handle, this.BackColor);
2712 OnHandleCreated(EventArgs.Empty);
2716 [EditorBrowsable(EditorBrowsableState.Advanced)]
2717 protected virtual void DefWndProc(ref Message m) {
2718 window.DefWndProc(ref m);
2721 [EditorBrowsable(EditorBrowsableState.Advanced)]
2722 protected virtual void DestroyHandle() {
2723 if (IsHandleCreated) {
2724 // Destroy our children before we destroy ourselves, to prevent them from
2725 // being implictly (without us knowing) destroyed
2726 for (int i=0; i < child_controls.Count; i++) {
2727 child_controls[i].DestroyHandle();
2731 if (window != null) {
2732 window.DestroyHandle();
2734 OnHandleDestroyed(EventArgs.Empty);
2738 protected bool GetStyle(ControlStyles flag) {
2739 return (control_style & flag) != 0;
2742 protected bool GetTopLevel() {
2746 [EditorBrowsable(EditorBrowsableState.Advanced)]
2747 protected virtual void InitLayout() {
2748 if (parent != null) {
2749 parent.PerformLayout(this, "parent");
2753 [EditorBrowsable(EditorBrowsableState.Advanced)]
2754 protected void InvokeGotFocus(Control toInvoke, EventArgs e) {
2755 toInvoke.OnGotFocus(e);
2758 [EditorBrowsable(EditorBrowsableState.Advanced)]
2759 protected void InvokeLostFocus(Control toInvoke, EventArgs e) {
2760 toInvoke.OnLostFocus(e);
2763 [EditorBrowsable(EditorBrowsableState.Advanced)]
2764 protected void InvokeOnClick(Control toInvoke, EventArgs e) {
2765 toInvoke.OnClick(e);
2768 protected void InvokePaint(Control toInvoke, PaintEventArgs e) {
2769 toInvoke.OnPaint(e);
2772 protected void InvokePaintBackground(Control toInvoke, PaintEventArgs e) {
2773 toInvoke.OnPaintBackground(e);
2776 protected virtual bool IsInputChar (char charCode) {
2777 if (parent != null) {
2778 return parent.IsInputChar(charCode);
2784 protected virtual bool IsInputKey (Keys keyData) {
2785 // Doc says this one calls IsInputChar; not sure what to do with that
2789 [EditorBrowsable(EditorBrowsableState.Advanced)]
2790 protected virtual void NotifyInvalidate(Rectangle invalidatedArea) {
2794 protected virtual bool ProcessCmdKey(ref Message msg, Keys keyData) {
2795 if ((context_menu != null) && context_menu.ProcessCmdKey(ref msg, keyData)) {
2799 if (parent != null) {
2800 return parent.ProcessCmdKey(ref msg, keyData);
2806 protected virtual bool ProcessDialogChar(char charCode) {
2807 if (parent != null) {
2808 return parent.ProcessDialogChar (charCode);
2814 protected virtual bool ProcessDialogKey (Keys keyData) {
2815 if (parent != null) {
2816 return parent.ProcessDialogKey (keyData);
2822 protected virtual bool ProcessKeyEventArgs (ref Message msg)
2824 KeyEventArgs key_event;
2827 case (int)Msg.WM_KEYDOWN: {
2828 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
2829 OnKeyDown (key_event);
2830 return key_event.Handled;
2832 case (int)Msg.WM_KEYUP: {
2833 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
2834 OnKeyUp (key_event);
2835 return key_event.Handled;
2838 case (int)Msg.WM_CHAR: {
2839 KeyPressEventArgs key_press_event;
2841 key_press_event = new KeyPressEventArgs((char)msg.WParam);
2842 OnKeyPress(key_press_event);
2843 return key_press_event.Handled;
2854 protected internal virtual bool ProcessKeyMessage(ref Message msg) {
2855 if (parent != null) {
2856 if (parent.ProcessKeyPreview(ref msg)) {
2864 protected virtual bool ProcessKeyPreview(ref Message msg) {
2865 if (parent != null) {
2866 return parent.ProcessKeyPreview(ref msg);
2872 protected virtual bool ProcessMnemonic(char charCode) {
2877 [EditorBrowsable(EditorBrowsableState.Advanced)]
2878 protected void RaiseDragEvent(object key, DragEventArgs e) {
2882 [EditorBrowsable(EditorBrowsableState.Advanced)]
2883 protected void RaiseKeyEvent(object key, KeyEventArgs e) {
2887 [EditorBrowsable(EditorBrowsableState.Advanced)]
2888 protected void RaiseMouseEvent(object key, MouseEventArgs e) {
2892 [EditorBrowsable(EditorBrowsableState.Advanced)]
2893 protected void RaisePaintEvent(object key, PaintEventArgs e) {
2897 [EditorBrowsable(EditorBrowsableState.Advanced)]
2898 protected void RecreateHandle() {
2899 IEnumerator child = child_controls.GetEnumerator();
2903 if (IsHandleCreated) {
2909 while (child.MoveNext()) {
2910 ((Control)child.Current).RecreateHandle();
2916 is_recreating = false;
2919 [EditorBrowsable(EditorBrowsableState.Advanced)]
2920 protected void ResetMouseEventArgs() {
2924 [EditorBrowsable(EditorBrowsableState.Advanced)]
2925 protected ContentAlignment RtlTranslateAlignment(ContentAlignment align) {
2926 if (right_to_left == RightToLeft.No) {
2931 case ContentAlignment.TopLeft: {
2932 return ContentAlignment.TopRight;
2935 case ContentAlignment.TopRight: {
2936 return ContentAlignment.TopLeft;
2939 case ContentAlignment.MiddleLeft: {
2940 return ContentAlignment.MiddleRight;
2943 case ContentAlignment.MiddleRight: {
2944 return ContentAlignment.MiddleLeft;
2947 case ContentAlignment.BottomLeft: {
2948 return ContentAlignment.BottomRight;
2951 case ContentAlignment.BottomRight: {
2952 return ContentAlignment.BottomLeft;
2956 // if it's center it doesn't change
2962 [EditorBrowsable(EditorBrowsableState.Advanced)]
2963 protected HorizontalAlignment RtlTranslateAlignment(HorizontalAlignment align) {
2964 if ((right_to_left == RightToLeft.No) || (align == HorizontalAlignment.Center)) {
2968 if (align == HorizontalAlignment.Left) {
2969 return HorizontalAlignment.Right;
2972 // align must be HorizontalAlignment.Right
2973 return HorizontalAlignment.Left;
2976 [EditorBrowsable(EditorBrowsableState.Advanced)]
2977 protected LeftRightAlignment RtlTranslateAlignment(LeftRightAlignment align) {
2978 if (right_to_left == RightToLeft.No) {
2982 if (align == LeftRightAlignment.Left) {
2983 return LeftRightAlignment.Right;
2986 // align must be LeftRightAlignment.Right;
2987 return LeftRightAlignment.Left;
2990 [EditorBrowsable(EditorBrowsableState.Advanced)]
2991 protected ContentAlignment RtlTranslateContent(ContentAlignment align) {
2992 return RtlTranslateAlignment(align);
2995 [EditorBrowsable(EditorBrowsableState.Advanced)]
2996 protected HorizontalAlignment RtlTranslateHorizontal(HorizontalAlignment align) {
2997 return RtlTranslateAlignment(align);
3000 [EditorBrowsable(EditorBrowsableState.Advanced)]
3001 protected LeftRightAlignment RtlTranslateLeftRight(LeftRightAlignment align) {
3002 return RtlTranslateAlignment(align);
3005 [EditorBrowsable(EditorBrowsableState.Advanced)]
3006 protected virtual void ScaleCore(float dx, float dy) {
3012 location = new Point((int)(Left * dx), (int)(Top * dy));
3013 size = this.ClientSize;
3016 if (!GetStyle(ControlStyles.FixedWidth)) {
3017 size.Width = (int)(size.Width * dx);
3020 if (!GetStyle(ControlStyles.FixedHeight)) {
3021 size.Height = (int)(size.Height * dy);
3024 Location = location;
3027 /* Now scale our children */
3028 for (int i=0; i < child_controls.Count; i++) {
3029 child_controls[i].Scale(dx, dy);
3035 protected virtual void Select(bool directed, bool forward) {
3040 // Select this control
3045 if (parent == null) {
3049 // FIXME - this thing is doing the wrong stuff, needs to be similar to SelectNextControl
3051 index = parent.child_controls.IndexOf(this);
3056 if ((index+1) < parent.child_controls.Count) {
3065 index = parent.child_controls.Count-1;
3068 result = Select(parent.child_controls[index]);
3069 } while (!result && parent.child_controls[index] != this);
3072 [EditorBrowsable(EditorBrowsableState.Advanced)]
3073 protected virtual void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
3074 // SetBoundsCore updates the Win32 control itself. UpdateBounds updates the controls variables and fires events, I'm guessing - pdb
3075 if ((specified & BoundsSpecified.X) != BoundsSpecified.X) {
3079 if ((specified & BoundsSpecified.Y) != BoundsSpecified.Y) {
3083 if ((specified & BoundsSpecified.Width) != BoundsSpecified.Width) {
3087 if ((specified & BoundsSpecified.Height) != BoundsSpecified.Height) {
3091 if (IsHandleCreated) {
3092 XplatUI.SetWindowPos(Handle, x, y, width, height);
3094 UpdateBounds(x, y, width, height);
3097 [EditorBrowsable(EditorBrowsableState.Advanced)]
3098 protected virtual void SetClientSizeCore(int x, int y) {
3099 // Calculate the actual window size from the client size (it usually stays the same or grows)
3100 Rectangle ClientRect;
3101 Rectangle WindowRect;
3104 ClientRect = new Rectangle(0, 0, x, y);
3105 cp = this.CreateParams;
3107 if (XplatUI.CalculateWindowRect(Handle, ref ClientRect, cp.Style, cp.ExStyle, IntPtr.Zero, out WindowRect)==false) {
3111 SetBoundsCore(bounds.X, bounds.Y, WindowRect.Width, WindowRect.Height, BoundsSpecified.Size);
3114 [EditorBrowsable(EditorBrowsableState.Advanced)]
3115 protected void SetStyle(ControlStyles flag, bool value) {
3117 control_style |= flag;
3119 control_style &= ~flag;
3121 OnStyleChanged(EventArgs.Empty);
3124 protected void SetTopLevel(bool value) {
3125 if ((GetTopLevel() != value) && (parent != null)) {
3126 throw new Exception();
3130 if (value == true) {
3140 is_toplevel = value;
3143 protected virtual void SetVisibleCore(bool value) {
3144 if (value!=is_visible) {
3146 XplatUI.SetVisible(Handle, value);
3147 // Explicitly move Toplevel windows to where we want them;
3148 // apparently moving unmapped toplevel windows doesn't work
3149 if (is_visible && (this is Form)) {
3150 XplatUI.SetWindowPos(window.Handle, bounds.X, bounds.Y, bounds.Width, bounds.Height);
3152 OnVisibleChanged(EventArgs.Empty);
3155 if (dc_mem != null) {
3160 if (bmp_mem != null) {
3165 this.CreateBuffers(bounds.Width, bounds.Height);
3170 if (value == false && parent != null) {
3173 // Need to start at parent, GetContainerControl might return ourselves if we're a container
3174 container = (Control)parent.GetContainerControl();
3175 if (container != null) {
3176 container.SelectNextControl(this, true, true, true, true);
3180 if (parent != null) {
3181 parent.PerformLayout(this, "visible");
3183 PerformLayout(this, "visible");
3188 [EditorBrowsable(EditorBrowsableState.Advanced)]
3189 protected void UpdateBounds() {
3197 if (!IsHandleCreated) {
3201 XplatUI.GetWindowPos(this.Handle, this is Form, out x, out y, out width, out height, out client_width, out client_height);
3203 UpdateBounds(x, y, width, height, client_width, client_height);
3206 [EditorBrowsable(EditorBrowsableState.Advanced)]
3207 protected void UpdateBounds(int x, int y, int width, int height) {
3208 // UpdateBounds only seems to set our sizes and fire events but not update the GUI window to match
3210 bool resized = false;
3212 int client_x_diff = this.bounds.Width-this.client_size.Width;
3213 int client_y_diff = this.bounds.Height-this.client_size.Height;
3215 // Needed to generate required notifications
3216 if ((this.bounds.X!=x) || (this.bounds.Y!=y)) {
3220 if ((this.Bounds.Width!=width) || (this.Bounds.Height!=height)) {
3227 bounds.Height=height;
3229 // Update client rectangle as well
3230 if (this.layout_suspended==0) {
3231 prev_size.Width=client_size.Width;
3232 prev_size.Height=client_size.Height;
3235 client_size.Width=width-client_x_diff;
3236 client_size.Height=height-client_y_diff;
3239 OnLocationChanged(EventArgs.Empty);
3243 OnSizeChanged(EventArgs.Empty);
3247 [EditorBrowsable(EditorBrowsableState.Advanced)]
3248 protected void UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) {
3249 UpdateBounds(x, y, width, height);
3251 this.client_size.Width=clientWidth;
3252 this.client_size.Height=clientHeight;
3255 [EditorBrowsable(EditorBrowsableState.Advanced)]
3256 protected void UpdateStyles() {
3257 if (!IsHandleCreated) {
3261 XplatUI.SetWindowStyle(window.Handle, CreateParams);
3264 [EditorBrowsable(EditorBrowsableState.Advanced)]
3265 protected void UpdateZOrder() {
3270 if (parent == null) {
3276 children = ctl.child_controls.Count;
3277 for (int i = 1; i < children; i++ ) {
3278 XplatUI.SetZOrder(ctl.child_controls[i].window.Handle, ctl.child_controls[i-1].window.Handle, false, false);
3281 children = child_controls.Count;
3282 for (int i = 1; i < children; i++ ) {
3283 XplatUI.SetZOrder(child_controls[i].window.Handle, child_controls[i-1].window.Handle, false, false);
3288 protected virtual void WndProc(ref Message m) {
3290 Console.WriteLine("Control received message {0}", (Msg)m.Msg);
3292 if ((this.control_style & ControlStyles.EnableNotifyMessage) != 0) {
3296 switch((Msg)m.Msg) {
3297 case Msg.WM_WINDOWPOSCHANGED: {
3300 if (GetStyle(ControlStyles.ResizeRedraw)) {
3307 case Msg.WM_PAINT: {
3308 PaintEventArgs paint_event;
3310 paint_event = XplatUI.PaintEventStart(Handle);
3312 if (!needs_redraw) {
3313 // Just blit the previous image
3314 paint_event.Graphics.DrawImage (ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle, GraphicsUnit.Pixel);
3315 XplatUI.PaintEventEnd(Handle);
3320 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
3321 dc = paint_event.SetGraphics (DeviceContext);
3324 if ((control_style & (ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint)) != (ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint)) {
3325 OnPaintBackground(paint_event);
3328 OnPaint(paint_event);
3330 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
3331 dc.DrawImage (ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle, GraphicsUnit.Pixel);
3332 paint_event.SetGraphics (dc);
3333 needs_redraw = false;
3336 XplatUI.PaintEventEnd(Handle);
3338 if (!GetStyle(ControlStyles.UserPaint)) {
3345 case Msg.WM_ERASEBKGND: {
3346 if (GetStyle (ControlStyles.UserPaint)) {
3347 if (!GetStyle(ControlStyles.AllPaintingInWmPaint)) {
3348 PaintEventArgs eraseEventArgs = new PaintEventArgs (m.WParam == IntPtr.Zero ? Graphics.FromHwnd (m.HWnd) :
3349 Graphics.FromHdc (m.WParam), new Rectangle (new Point (0,0),Size));
3350 OnPaintBackground (eraseEventArgs);
3353 XplatUI.EraseWindowBackground(m.HWnd, m.WParam);
3355 // The DefWndProc will never have to handle this, we don't ever set hbr on the window
3356 m.Result = (IntPtr)1;
3360 case Msg.WM_LBUTTONUP: {
3361 HandleClick(mouse_clicks);
3362 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Left,
3364 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3366 if (mouse_clicks > 1) {
3372 case Msg.WM_LBUTTONDOWN: {
3373 if (CanSelect && !is_selected) {
3376 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3377 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3383 case Msg.WM_LBUTTONDBLCLK: {
3385 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3386 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3392 case Msg.WM_MBUTTONUP: {
3393 HandleClick(mouse_clicks);
3394 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Middle,
3396 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3398 if (mouse_clicks > 1) {
3404 case Msg.WM_MBUTTONDOWN: {
3405 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3406 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3412 case Msg.WM_MBUTTONDBLCLK: {
3414 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3415 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3420 case Msg.WM_RBUTTONUP: {
3421 if (context_menu != null) {
3422 context_menu.Show(this, new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ())));
3425 HandleClick(mouse_clicks);
3426 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Right,
3428 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3430 if (mouse_clicks > 1) {
3436 case Msg.WM_RBUTTONDOWN: {
3437 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3438 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3443 case Msg.WM_RBUTTONDBLCLK: {
3445 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3446 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3451 case Msg.WM_MOUSEWHEEL: {
3453 OnMouseWheel (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3454 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3455 HighOrder(m.WParam.ToInt32())));
3460 case Msg.WM_MOUSEMOVE: {
3461 OnMouseMove (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3463 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3468 case Msg.WM_MOUSE_ENTER: {
3473 OnMouseEnter(EventArgs.Empty);
3477 case Msg.WM_MOUSE_LEAVE: {
3479 OnMouseLeave(EventArgs.Empty);
3483 case Msg.WM_MOUSEHOVER: {
3484 OnMouseHover(EventArgs.Empty);
3488 case Msg.WM_SYSKEYDOWN:
3489 case Msg.WM_KEYDOWN:
3490 case Msg.WM_SYSKEYUP:
3492 case Msg.WM_SYSCHAR:
3494 if (ProcessKeyEventArgs(ref m)) {
3498 if (PreProcessMessage(ref m)) {
3502 if (ProcessKeyMessage(ref m)) {
3511 if (m.LParam != IntPtr.Zero) {
3514 hi = new HELPINFO();
3516 hi = (HELPINFO) Marshal.PtrToStructure (m.LParam, typeof (HELPINFO));
3517 mouse_pos = new Point(hi.MousePos.x, hi.MousePos.y);
3519 mouse_pos = Control.MousePosition;
3521 OnHelpRequested(new HelpEventArgs(mouse_pos));
3522 m.Result = (IntPtr)1;
3526 case Msg.WM_KILLFOCUS: {
3527 OnLeave(EventArgs.Empty);
3528 if (CausesValidation) {
3530 e = new CancelEventArgs(false);
3539 OnValidated(EventArgs.Empty);
3542 this.has_focus = false;
3543 this.is_selected = false;
3544 OnLostFocus(EventArgs.Empty);
3548 case Msg.WM_SETFOCUS: {
3549 OnEnter(EventArgs.Empty);
3550 this.has_focus = true;
3551 OnGotFocus(EventArgs.Empty);
3556 case Msg.WM_SYSCOLORCHANGE: {
3557 ThemeEngine.Current.ResetDefaults();
3558 OnSystemColorsChanged(EventArgs.Empty);
3563 case Msg.WM_SETCURSOR: {
3564 if (cursor == null) {
3569 XplatUI.SetCursor(window.Handle, cursor.handle);
3570 m.Result = (IntPtr)1;
3580 #endregion // Public Instance Methods
3582 #region OnXXX methods
3583 [EditorBrowsable(EditorBrowsableState.Advanced)]
3584 protected virtual void OnBackColorChanged(EventArgs e) {
3585 if (BackColorChanged!=null) BackColorChanged(this, e);
3586 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackColorChanged(e);
3589 [EditorBrowsable(EditorBrowsableState.Advanced)]
3590 protected virtual void OnBackgroundImageChanged(EventArgs e) {
3591 if (BackgroundImageChanged!=null) BackgroundImageChanged(this, e);
3592 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackgroundImageChanged(e);
3595 [EditorBrowsable(EditorBrowsableState.Advanced)]
3596 protected virtual void OnBindingContextChanged(EventArgs e) {
3597 CheckDataBindings ();
3598 if (BindingContextChanged!=null) {
3599 BindingContextChanged(this, e);
3601 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBindingContextChanged(e);
3604 [EditorBrowsable(EditorBrowsableState.Advanced)]
3605 protected virtual void OnCausesValidationChanged(EventArgs e) {
3606 if (CausesValidationChanged!=null) CausesValidationChanged(this, e);
3609 [EditorBrowsable(EditorBrowsableState.Advanced)]
3610 protected virtual void OnChangeUICues(UICuesEventArgs e) {
3611 if (ChangeUICues!=null) ChangeUICues(this, e);
3614 [EditorBrowsable(EditorBrowsableState.Advanced)]
3615 protected virtual void OnClick(EventArgs e) {
3616 if (Click!=null) Click(this, e);
3619 [EditorBrowsable(EditorBrowsableState.Advanced)]
3620 protected virtual void OnContextMenuChanged(EventArgs e) {
3621 if (ContextMenuChanged!=null) ContextMenuChanged(this, e);
3624 [EditorBrowsable(EditorBrowsableState.Advanced)]
3625 protected virtual void OnControlAdded(ControlEventArgs e) {
3626 if (ControlAdded!=null) ControlAdded(this, e);
3629 [EditorBrowsable(EditorBrowsableState.Advanced)]
3630 protected virtual void OnControlRemoved(ControlEventArgs e) {
3631 if (ControlRemoved!=null) ControlRemoved(this, e);
3634 [EditorBrowsable(EditorBrowsableState.Advanced)]
3635 protected virtual void OnCreateControl() {
3639 [EditorBrowsable(EditorBrowsableState.Advanced)]
3640 protected virtual void OnCursorChanged(EventArgs e) {
3641 if (CursorChanged!=null) CursorChanged(this, e);
3644 [EditorBrowsable(EditorBrowsableState.Advanced)]
3645 protected virtual void OnDockChanged(EventArgs e) {
3646 if (DockChanged!=null) DockChanged(this, e);
3649 [EditorBrowsable(EditorBrowsableState.Advanced)]
3650 protected virtual void OnDoubleClick(EventArgs e) {
3651 if (DoubleClick!=null) DoubleClick(this, e);
3654 [EditorBrowsable(EditorBrowsableState.Advanced)]
3655 protected virtual void OnDragDrop(DragEventArgs drgevent) {
3656 if (DragDrop!=null) DragDrop(this, drgevent);
3659 [EditorBrowsable(EditorBrowsableState.Advanced)]
3660 protected virtual void OnDragEnter(DragEventArgs drgevent) {
3661 if (DragEnter!=null) DragEnter(this, drgevent);
3664 [EditorBrowsable(EditorBrowsableState.Advanced)]
3665 protected virtual void OnDragLeave(EventArgs e) {
3666 if (DragLeave!=null) DragLeave(this, e);
3669 [EditorBrowsable(EditorBrowsableState.Advanced)]
3670 protected virtual void OnDragOver(DragEventArgs drgevent) {
3671 if (DragOver!=null) DragOver(this, drgevent);
3674 [EditorBrowsable(EditorBrowsableState.Advanced)]
3675 protected virtual void OnEnabledChanged(EventArgs e) {
3676 if (EnabledChanged!=null) EnabledChanged(this, e);
3677 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentEnabledChanged(e);
3680 [EditorBrowsable(EditorBrowsableState.Advanced)]
3681 protected virtual void OnEnter(EventArgs e) {
3682 if (Enter!=null) Enter(this, e);
3685 [EditorBrowsable(EditorBrowsableState.Advanced)]
3686 protected virtual void OnFontChanged(EventArgs e) {
3687 if (FontChanged!=null) FontChanged(this, e);
3688 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentFontChanged(e);
3691 [EditorBrowsable(EditorBrowsableState.Advanced)]
3692 protected virtual void OnForeColorChanged(EventArgs e) {
3693 if (ForeColorChanged!=null) ForeColorChanged(this, e);
3694 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentForeColorChanged(e);
3697 [EditorBrowsable(EditorBrowsableState.Advanced)]
3698 protected virtual void OnGiveFeedback(GiveFeedbackEventArgs gfbevent) {
3699 if (GiveFeedback!=null) GiveFeedback(this, gfbevent);
3702 [EditorBrowsable(EditorBrowsableState.Advanced)]
3703 protected virtual void OnGotFocus(EventArgs e) {
3704 if (GotFocus!=null) GotFocus(this, e);
3707 [EditorBrowsable(EditorBrowsableState.Advanced)]
3708 protected virtual void OnHandleCreated(EventArgs e) {
3709 if (HandleCreated!=null) HandleCreated(this, e);
3712 [EditorBrowsable(EditorBrowsableState.Advanced)]
3713 protected virtual void OnHandleDestroyed(EventArgs e) {
3714 if (HandleDestroyed!=null) HandleDestroyed(this, e);
3717 [EditorBrowsable(EditorBrowsableState.Advanced)]
3718 protected virtual void OnHelpRequested(HelpEventArgs hevent) {
3719 if (HelpRequested!=null) HelpRequested(this, hevent);
3722 protected virtual void OnImeModeChanged(EventArgs e) {
3723 if (ImeModeChanged!=null) ImeModeChanged(this, e);
3726 [EditorBrowsable(EditorBrowsableState.Advanced)]
3727 protected virtual void OnInvalidated(InvalidateEventArgs e) {
3728 needs_redraw = true;
3729 if (Invalidated!=null) Invalidated(this, e);
3732 [EditorBrowsable(EditorBrowsableState.Advanced)]
3733 protected virtual void OnKeyDown(KeyEventArgs e) {
3734 if (KeyDown!=null) KeyDown(this, e);
3737 [EditorBrowsable(EditorBrowsableState.Advanced)]
3738 protected virtual void OnKeyPress(KeyPressEventArgs e) {
3739 if (KeyPress!=null) KeyPress(this, e);
3742 [EditorBrowsable(EditorBrowsableState.Advanced)]
3743 protected virtual void OnKeyUp(KeyEventArgs e) {
3744 if (KeyUp!=null) KeyUp(this, e);
3747 [EditorBrowsable(EditorBrowsableState.Advanced)]
3748 protected virtual void OnLayout(LayoutEventArgs levent) {
3749 if (Layout!=null) Layout(this, levent);
3752 [EditorBrowsable(EditorBrowsableState.Advanced)]
3753 protected virtual void OnLeave(EventArgs e) {
3754 if (Leave!=null) Leave(this, e);
3757 [EditorBrowsable(EditorBrowsableState.Advanced)]
3758 protected virtual void OnLocationChanged(EventArgs e) {
3760 if (LocationChanged!=null) LocationChanged(this, e);
3763 [EditorBrowsable(EditorBrowsableState.Advanced)]
3764 protected virtual void OnLostFocus(EventArgs e) {
3765 if (LostFocus!=null) LostFocus(this, e);
3768 [EditorBrowsable(EditorBrowsableState.Advanced)]
3769 protected virtual void OnMouseDown(MouseEventArgs e) {
3770 if (MouseDown!=null) MouseDown(this, e);
3773 [EditorBrowsable(EditorBrowsableState.Advanced)]
3774 protected virtual void OnMouseEnter(EventArgs e) {
3775 if (MouseEnter!=null) MouseEnter(this, e);
3778 [EditorBrowsable(EditorBrowsableState.Advanced)]
3779 protected virtual void OnMouseHover(EventArgs e) {
3780 if (MouseHover!=null) MouseHover(this, e);
3783 [EditorBrowsable(EditorBrowsableState.Advanced)]
3784 protected virtual void OnMouseLeave(EventArgs e) {
3785 if (MouseLeave!=null) MouseLeave(this, e);
3788 [EditorBrowsable(EditorBrowsableState.Advanced)]
3789 protected virtual void OnMouseMove(MouseEventArgs e) {
3790 if (MouseMove!=null) MouseMove(this, e);
3793 [EditorBrowsable(EditorBrowsableState.Advanced)]
3794 protected virtual void OnMouseUp(MouseEventArgs e) {
3795 if (MouseUp!=null) MouseUp(this, e);
3798 [EditorBrowsable(EditorBrowsableState.Advanced)]
3799 protected virtual void OnMouseWheel(MouseEventArgs e) {
3800 if (MouseWheel!=null) MouseWheel(this, e);
3803 [EditorBrowsable(EditorBrowsableState.Advanced)]
3804 protected virtual void OnMove(EventArgs e) {
3805 if (Move!=null) Move(this, e);
3808 [EditorBrowsable(EditorBrowsableState.Advanced)]
3809 protected virtual void OnNotifyMessage(Message m) {
3813 [EditorBrowsable(EditorBrowsableState.Advanced)]
3814 protected virtual void OnPaint(PaintEventArgs e) {
3815 if (Paint!=null) Paint(this, e);
3818 [EditorBrowsable(EditorBrowsableState.Advanced)]
3819 protected virtual void OnPaintBackground(PaintEventArgs pevent) {
3820 PaintControlBackground (pevent);
3823 [EditorBrowsable(EditorBrowsableState.Advanced)]
3824 protected virtual void OnParentBackColorChanged(EventArgs e) {
3825 if (background_color.IsEmpty && background_image==null) {
3827 OnBackColorChanged(e);
3831 [EditorBrowsable(EditorBrowsableState.Advanced)]
3832 protected virtual void OnParentBackgroundImageChanged(EventArgs e) {
3833 if (background_color.IsEmpty && background_image==null) {
3835 OnBackgroundImageChanged(e);
3839 [EditorBrowsable(EditorBrowsableState.Advanced)]
3840 protected virtual void OnParentBindingContextChanged(EventArgs e) {
3841 if (binding_context==null) {
3842 binding_context=Parent.binding_context;
3843 OnBindingContextChanged(e);
3847 [EditorBrowsable(EditorBrowsableState.Advanced)]
3848 protected virtual void OnParentChanged(EventArgs e) {
3849 if (ParentChanged!=null) ParentChanged(this, e);
3852 [EditorBrowsable(EditorBrowsableState.Advanced)]
3853 protected virtual void OnParentEnabledChanged(EventArgs e) {
3854 if (is_enabled != Parent.is_enabled) {
3855 is_enabled=Parent.is_enabled;
3857 if (EnabledChanged != null) {
3858 EnabledChanged(this, e);
3863 [EditorBrowsable(EditorBrowsableState.Advanced)]
3864 protected virtual void OnParentFontChanged(EventArgs e) {
3871 [EditorBrowsable(EditorBrowsableState.Advanced)]
3872 protected virtual void OnParentForeColorChanged(EventArgs e) {
3873 if (foreground_color.IsEmpty) {
3875 OnForeColorChanged(e);
3879 [EditorBrowsable(EditorBrowsableState.Advanced)]
3880 protected virtual void OnParentRightToLeftChanged(EventArgs e) {
3881 if (right_to_left==RightToLeft.Inherit) {
3883 OnRightToLeftChanged(e);
3887 [EditorBrowsable(EditorBrowsableState.Advanced)]
3888 protected virtual void OnParentVisibleChanged(EventArgs e) {
3890 OnVisibleChanged(e);
3894 [EditorBrowsable(EditorBrowsableState.Advanced)]
3895 protected virtual void OnQueryContinueDrag(QueryContinueDragEventArgs e) {
3896 if (QueryContinueDrag!=null) QueryContinueDrag(this, e);
3899 [EditorBrowsable(EditorBrowsableState.Advanced)]
3900 protected virtual void OnResize(EventArgs e) {
3901 if (Resize!=null) Resize(this, e);
3903 PerformLayout(this, "bounds");
3905 if (parent != null) {
3906 parent.PerformLayout();
3910 [EditorBrowsable(EditorBrowsableState.Advanced)]
3911 protected virtual void OnRightToLeftChanged(EventArgs e) {
3912 if (RightToLeftChanged!=null) RightToLeftChanged(this, e);
3913 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentRightToLeftChanged(e);
3916 [EditorBrowsable(EditorBrowsableState.Advanced)]
3917 protected virtual void OnSizeChanged(EventArgs e) {
3918 InvalidateBuffers ();
3920 if (SizeChanged!=null) SizeChanged(this, e);
3923 [EditorBrowsable(EditorBrowsableState.Advanced)]
3924 protected virtual void OnStyleChanged(EventArgs e) {
3925 if (StyleChanged!=null) StyleChanged(this, e);
3928 [EditorBrowsable(EditorBrowsableState.Advanced)]
3929 protected virtual void OnSystemColorsChanged(EventArgs e) {
3930 if (SystemColorsChanged!=null) SystemColorsChanged(this, e);
3933 [EditorBrowsable(EditorBrowsableState.Advanced)]
3934 protected virtual void OnTabIndexChanged(EventArgs e) {
3935 if (TabIndexChanged!=null) TabIndexChanged(this, e);
3938 [EditorBrowsable(EditorBrowsableState.Advanced)]
3939 protected virtual void OnTabStopChanged(EventArgs e) {
3940 if (TabStopChanged!=null) TabStopChanged(this, e);
3943 [EditorBrowsable(EditorBrowsableState.Advanced)]
3944 protected virtual void OnTextChanged(EventArgs e) {
3945 if (TextChanged!=null) TextChanged(this, e);
3948 [EditorBrowsable(EditorBrowsableState.Advanced)]
3949 protected virtual void OnValidated(EventArgs e) {
3950 if (Validated!=null) Validated(this, e);
3953 [EditorBrowsable(EditorBrowsableState.Advanced)]
3954 protected virtual void OnValidating(System.ComponentModel.CancelEventArgs e) {
3955 if (Validating!=null) Validating(this, e);
3958 [EditorBrowsable(EditorBrowsableState.Advanced)]
3959 protected virtual void OnVisibleChanged(EventArgs e) {
3966 if (bmp_mem!=null) {
3972 if (!this.IsHandleCreated) {
3973 this.CreateControl();
3979 if (VisibleChanged!=null) VisibleChanged(this, e);
3981 // We need to tell our kids
3982 for (int i=0; i<child_controls.Count; i++) {
3983 child_controls[i].OnParentVisibleChanged(e);
3986 #endregion // OnXXX methods
3989 public event EventHandler BackColorChanged;
3990 public event EventHandler BackgroundImageChanged;
3991 public event EventHandler BindingContextChanged;
3992 public event EventHandler CausesValidationChanged;
3993 public event UICuesEventHandler ChangeUICues;
3994 public event EventHandler Click;
3995 public event EventHandler ContextMenuChanged;
3997 [EditorBrowsable(EditorBrowsableState.Advanced)]
3999 public event ControlEventHandler ControlAdded;
4001 [EditorBrowsable(EditorBrowsableState.Advanced)]
4003 public event ControlEventHandler ControlRemoved;
4005 [MWFDescription("Fired when the cursor for the control has been changed"), MWFCategory("PropertyChanged")]
4006 public event EventHandler CursorChanged;
4007 public event EventHandler DockChanged;
4008 public event EventHandler DoubleClick;
4009 public event DragEventHandler DragDrop;
4010 public event DragEventHandler DragEnter;
4011 public event EventHandler DragLeave;
4012 public event DragEventHandler DragOver;
4013 public event EventHandler EnabledChanged;
4014 public event EventHandler Enter;
4015 public event EventHandler FontChanged;
4016 public event EventHandler ForeColorChanged;
4017 public event GiveFeedbackEventHandler GiveFeedback;
4019 [EditorBrowsable(EditorBrowsableState.Advanced)]
4021 public event EventHandler GotFocus;
4023 [EditorBrowsable(EditorBrowsableState.Advanced)]
4025 public event EventHandler HandleCreated;
4027 [EditorBrowsable(EditorBrowsableState.Advanced)]
4029 public event EventHandler HandleDestroyed;
4031 public event HelpEventHandler HelpRequested;
4032 public event EventHandler ImeModeChanged;
4034 [EditorBrowsable(EditorBrowsableState.Advanced)]
4036 public event InvalidateEventHandler Invalidated;
4038 public event KeyEventHandler KeyDown;
4039 public event KeyPressEventHandler KeyPress;
4040 public event KeyEventHandler KeyUp;
4041 public event LayoutEventHandler Layout;
4042 public event EventHandler Leave;
4043 public event EventHandler LocationChanged;
4045 [EditorBrowsable(EditorBrowsableState.Advanced)]
4047 public event EventHandler LostFocus;
4049 public event MouseEventHandler MouseDown;
4050 public event EventHandler MouseEnter;
4051 public event EventHandler MouseHover;
4052 public event EventHandler MouseLeave;
4053 public event MouseEventHandler MouseMove;
4054 public event MouseEventHandler MouseUp;
4056 [EditorBrowsable(EditorBrowsableState.Advanced)]
4058 public event MouseEventHandler MouseWheel;
4060 public event EventHandler Move;
4061 public event PaintEventHandler Paint;
4062 public event EventHandler ParentChanged;
4063 public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp;
4064 public event QueryContinueDragEventHandler QueryContinueDrag;
4065 public event EventHandler Resize;
4066 public event EventHandler RightToLeftChanged;
4067 public event EventHandler SizeChanged;
4068 public event EventHandler StyleChanged;
4069 public event EventHandler SystemColorsChanged;
4070 public event EventHandler TabIndexChanged;
4071 public event EventHandler TabStopChanged;
4072 public event EventHandler TextChanged;
4073 public event EventHandler Validated;
4074 public event CancelEventHandler Validating;
4075 public event EventHandler VisibleChanged;
4076 #endregion // Events