1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 // Copyright (c) 2004-2005 Novell, Inc.
23 // Peter Bartok pbartok@novell.com
25 // Partially based on work by:
26 // Aleksey Ryabchuk ryabchuk@yahoo.com
27 // Alexandre Pigolkine pigolkine@gmx.de
28 // Dennis Hayes dennish@raytek.com
29 // Jaak Simm jaaksimm@firm.ee
30 // John Sohn jsohn@columbus.rr.com
36 using System.ComponentModel;
37 using System.ComponentModel.Design;
38 using System.ComponentModel.Design.Serialization;
39 using System.Collections;
40 using System.Diagnostics;
42 using System.Reflection;
43 using System.Runtime.InteropServices;
44 using System.Security;
45 using System.Threading;
48 namespace System.Windows.Forms
50 [Designer("System.Windows.Forms.Design.ControlDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
51 [DefaultProperty("Text")]
52 [DefaultEvent("Click")]
53 [DesignerSerializer("System.Windows.Forms.Design.ControlCodeDomSerializer, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
54 [ToolboxItemFilter("System.Windows.Forms")]
55 public class Control : Component, ISynchronizeInvoke, IWin32Window
57 #region Local Variables
60 internal Rectangle bounds; // bounding rectangle for control (client area + decorations)
61 internal object creator_thread; // thread that created the control
62 internal ControlNativeWindow window; // object for native window handle
63 internal string name; // for object naming
66 private bool create_handled; // true if OnCreateControl has been sent
67 internal bool has_focus; // true if control has focus
68 internal bool is_visible; // true if control is visible
69 internal bool is_entered; // is the mouse inside the control?
70 internal bool is_enabled; // true if control is enabled (usable/not grayed out)
71 internal bool is_selected; // true if control is selected
72 internal bool is_accessible; // true if the control is visible to accessibility applications
73 internal bool is_captured; // tracks if the control has captured the mouse
74 internal bool is_toplevel; // tracks if the control is a toplevel window
75 internal bool is_recreating; // tracks if the handle for the control is being recreated
76 internal bool causes_validation; // tracks if validation is executed on changes
77 internal int tab_index; // position in tab order of siblings
78 internal bool tab_stop = true; // is the control a tab stop?
79 internal bool is_disposed; // has the window already been disposed?
80 internal Size client_size; // size of the client area (window excluding decorations)
81 internal Rectangle client_rect; // rectangle with the client area (window excluding decorations)
82 internal ControlStyles control_style; // rather win32-specific, style bits for control
83 internal ImeMode ime_mode = ImeMode.Inherit;
84 internal bool layout_pending; // true if our parent needs to re-layout us
85 internal object control_tag; // object that contains data about our control
86 internal int mouse_clicks; // Counter for mouse clicks
87 internal Cursor cursor; // Cursor for the window
88 private bool allow_drop; // true if the control accepts droping objects on it
91 internal Color foreground_color; // foreground color for control
92 internal Color background_color; // background color for control
93 internal Image background_image; // background image for control
94 internal Font font; // font for control
95 internal string text; // window/title text for control
96 internal BorderStyle border_style; // Border style of control
99 internal AnchorStyles anchor_style; // anchoring requirements for our control
100 internal DockStyle dock_style; // docking requirements for our control (supercedes anchoring)
101 internal SizeF size_ratio; // size ratio of our control to it's parent; required for anchoring
102 internal Size prev_size; // previous size of the control; required for anchoring
104 // to be categorized...
105 static internal ArrayList controls = new ArrayList(); // All of the application's controls, in a flat list
106 internal ControlCollection child_controls; // our children
107 internal Control parent; // our parent control
108 internal AccessibleObject accessibility_object; // object that contains accessibility information about our control
109 internal BindingContext binding_context; // TODO
110 internal RightToLeft right_to_left; // drawing direction for control
111 internal int layout_suspended;
112 internal ContextMenu context_menu; // Context menu associated with the control
114 private Graphics dc_mem; // Graphics context for double buffering
115 private Bitmap bmp_mem; // Bitmap for double buffering control
116 private bool needs_redraw = true;
118 private ControlBindingsCollection data_bindings;
120 #endregion // Local Variables
122 #region Private Classes
123 // This helper class allows us to dispatch messages to Control.WndProc
124 internal class ControlNativeWindow : NativeWindow {
125 private Control owner;
127 public ControlNativeWindow(Control control) : base() {
132 public Control Owner {
138 static internal Control ControlFromHandle(IntPtr hWnd) {
139 ControlNativeWindow window;
141 window = (ControlNativeWindow)window_collection[hWnd];
146 protected override void WndProc(ref Message m) {
147 owner.WndProc(ref m);
152 #region Public Classes
154 public class ControlAccessibleObject : AccessibleObject {
155 #region ControlAccessibleObject Local Variables
156 private Control owner;
157 #endregion // ControlAccessibleObject Local Variables
159 #region ControlAccessibleObject Constructors
160 public ControlAccessibleObject(Control ownerControl) {
161 this.owner = ownerControl;
163 #endregion // ControlAccessibleObject Constructors
165 #region ControlAccessibleObject Public Instance Properties
166 public override string DefaultAction {
168 return base.DefaultAction;
172 public override string Description {
174 return base.Description;
178 public IntPtr Handle {
184 // We don't want to let them set it
188 public override string Help {
194 public override string KeyboardShortcut {
196 return base.KeyboardShortcut;
200 public override string Name {
210 public Control Owner {
216 public override AccessibleRole Role {
221 #endregion // ControlAccessibleObject Public Instance Properties
223 #region ControlAccessibleObject Public Instance Methods
224 public override int GetHelpTopic(out string FileName) {
225 return base.GetHelpTopic (out FileName);
228 [MonoTODO("Implement this and tie it into Control.AccessibilityNotifyClients")]
229 public void NotifyClients(AccessibleEvents accEvent) {
230 throw new NotImplementedException();
233 [MonoTODO("Implement this and tie it into Control.AccessibilityNotifyClients")]
234 public void NotifyClients(AccessibleEvents accEvent, int childID) {
235 throw new NotImplementedException();
238 public override string ToString() {
239 return "ControlAccessibleObject: Owner = " + owner.ToString() + ", Text: " + owner.text;
242 #endregion // ControlAccessibleObject Public Instance Methods
245 [DesignerSerializer("System.Windows.Forms.Design.ControlCollectionCodeDomSerializer, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
246 [ListBindable(false)]
247 public class ControlCollection : IList, ICollection, ICloneable, IEnumerable {
248 #region ControlCollection Local Variables
249 internal ArrayList list;
250 internal Control owner;
251 #endregion // ControlCollection Local Variables
253 #region ControlCollection Public Constructor
254 public ControlCollection(Control owner) {
256 this.list=new ArrayList();
260 #region ControlCollection Public Instance Properties
267 public bool IsReadOnly {
269 return list.IsReadOnly;
273 public virtual Control this[int index] {
275 if (index < 0 || index >= list.Count) {
276 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
278 return (Control)list[index];
281 #endregion // ControlCollection Public Instance Properties
283 #region ControlCollection Private Instance Methods
284 public virtual void Add (Control value)
287 for (int i = 0; i < list.Count; i++) {
288 if (list [i] == value) {
289 // Do we need to do anything here?
294 if (value.tab_index == -1) {
300 end = owner.child_controls.Count;
301 for (int i = 0; i < end; i++) {
302 index = owner.child_controls[i].tab_index;
307 value.tab_index = use;
311 value.Parent = owner;
312 owner.UpdateZOrder();
313 owner.OnControlAdded(new ControlEventArgs(value));
316 public virtual void AddRange (Control[] controls)
318 if (controls == null)
319 throw new ArgumentNullException ("controls");
321 owner.SuspendLayout ();
324 for (int i = 0; i < controls.Length; i++)
327 owner.ResumeLayout ();
331 public virtual void Clear ()
333 owner.SuspendLayout();
334 for (int i = 0; i < list.Count; i++) {
335 owner.OnControlRemoved(new ControlEventArgs((Control)list[i]));
338 owner.ResumeLayout();
341 public virtual bool Contains (Control value)
343 return list.Contains (value);
346 public void CopyTo (Array array, int index)
348 list.CopyTo(array, index);
351 public override bool Equals(object other) {
352 if (other is ControlCollection && (((ControlCollection)other).owner==this.owner)) {
359 public int GetChildIndex(Control child) {
360 return GetChildIndex(child, false);
363 public int GetChildIndex(Control child, bool throwException) {
366 index=list.IndexOf(child);
368 if (index==-1 && throwException) {
369 throw new ArgumentException("Not a child control", "child");
374 public IEnumerator GetEnumerator() {
375 return list.GetEnumerator();
378 public override int GetHashCode() {
379 return base.GetHashCode();
382 public int IndexOf(Control control) {
383 return list.IndexOf(control);
386 public virtual void Remove(Control value) {
387 owner.OnControlRemoved(new ControlEventArgs(value));
389 owner.UpdateZOrder();
392 public void RemoveAt(int index) {
393 if (index<0 || index>=list.Count) {
394 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
397 owner.OnControlRemoved(new ControlEventArgs((Control)list[index]));
398 list.RemoveAt(index);
399 owner.UpdateZOrder();
402 public void SetChildIndex(Control child, int newIndex) {
405 old_index=list.IndexOf(child);
407 throw new ArgumentException("Not a child control", "child");
410 if (old_index==newIndex) {
416 if (newIndex>list.Count) {
419 list.Insert(newIndex, child);
421 owner.UpdateZOrder();
423 #endregion // ControlCollection Private Instance Methods
425 #region ControlCollection Interface Properties
426 object IList.this[int index] {
428 if (index<0 || index>=list.Count) {
429 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
435 if (!(value is Control)) {
436 throw new ArgumentException("Object of type Control required", "value");
439 list[index]=(Control)value;
443 bool IList.IsFixedSize {
449 bool IList.IsReadOnly {
451 return list.IsReadOnly;
455 bool ICollection.IsSynchronized {
457 return list.IsSynchronized;
461 object ICollection.SyncRoot {
463 return list.SyncRoot;
466 #endregion // ControlCollection Interface Properties
468 #region ControlCollection Interface Methods
469 int IList.Add(object value) {
471 throw new ArgumentNullException("value", "Cannot add null controls");
474 if (!(value is Control)) {
475 throw new ArgumentException("Object of type Control required", "value");
478 return list.Add(value);
481 bool IList.Contains(object value) {
482 if (!(value is Control)) {
483 throw new ArgumentException("Object of type Control required", "value");
486 return this.Contains((Control) value);
489 int IList.IndexOf(object value) {
490 if (!(value is Control)) {
491 throw new ArgumentException("Object of type Control required", "value");
494 return this.IndexOf((Control) value);
497 void IList.Insert(int index, object value) {
498 if (!(value is Control)) {
499 throw new ArgumentException("Object of type Control required", "value");
501 list.Insert(index, value);
504 void IList.Remove(object value) {
505 if (!(value is Control)) {
506 throw new ArgumentException("Object of type Control required", "value");
511 void ICollection.CopyTo(Array array, int index) {
513 list.CopyTo(array, index);
517 Object ICloneable.Clone() {
518 ControlCollection clone = new ControlCollection(this.owner);
519 clone.list=(ArrayList)list.Clone(); // FIXME: Do we need this?
522 #endregion // ControlCollection Interface Methods
524 #endregion // ControlCollection Class
526 #region Public Constructors
528 creator_thread = Thread.CurrentThread;
530 prev_size = Size.Empty;
531 anchor_style = AnchorStyles.Top | AnchorStyles.Left;
533 create_handled = false;
539 layout_pending = false;
541 causes_validation = true;
543 layout_suspended = 0;
547 right_to_left = RightToLeft.Inherit;
549 control_style = ControlStyles.Selectable | ControlStyles.StandardClick | ControlStyles.StandardDoubleClick;
552 background_image = null;
556 window = new ControlNativeWindow(this);
557 child_controls = CreateControlsInstance();
558 client_size = new Size(DefaultSize.Width, DefaultSize.Height);
559 client_rect = new Rectangle(0, 0, DefaultSize.Width, DefaultSize.Height);
560 XplatUI.CalculateWindowRect(IntPtr.Zero, ref client_rect, CreateParams.Style, CreateParams.ExStyle, IntPtr.Zero, out bounds);
561 if ((CreateParams.Style & (int)WindowStyles.WS_CHILD) == 0) {
567 public Control(Control parent, string text) : this() {
572 public Control(Control parent, string text, int left, int top, int width, int height) : this() {
577 bounds.Height=height;
578 SetBoundsCore(left, top, width, height, BoundsSpecified.All);
582 public Control(string text) : this() {
586 public Control(string text, int left, int top, int width, int height) : this() {
590 bounds.Height=height;
591 SetBoundsCore(left, top, width, height, BoundsSpecified.All);
595 protected override void Dispose(bool disposing) {
608 controls.Remove(this);
610 #endregion // Public Constructors
612 #region Internal Properties
613 internal BorderStyle InternalBorderStyle {
619 if (border_style != value) {
620 border_style = value;
622 XplatUI.SetBorderStyle(window.Handle, border_style);
626 #endregion // Internal Properties
628 #region Private & Internal Methods
629 internal static IAsyncResult BeginInvokeInternal (Delegate method, object [] args) {
630 AsyncMethodResult result = new AsyncMethodResult ();
631 AsyncMethodData data = new AsyncMethodData ();
633 data.Method = method;
635 data.Result = new WeakReference (result);
638 if (!ExecutionContext.IsFlowSuppressed ()) {
639 data.Context = ExecutionContext.Capture ();
642 if (SecurityManager.SecurityEnabled) {
643 data.Stack = CompressedStack.GetCompressedStack ();
647 XplatUI.SendAsyncMethod (data);
651 internal Graphics DeviceContext {
654 CreateBuffers(this.Width, this.Height);
660 private Bitmap ImageBuffer {
663 CreateBuffers(this.Width, this.Height);
669 internal void CreateBuffers (int width, int height) {
670 if (dc_mem != null) {
684 bmp_mem = new Bitmap (width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
685 dc_mem = Graphics.FromImage (bmp_mem);
689 internal void InvalidateBuffers ()
691 if (dc_mem != null) {
702 internal static void SetChildColor(Control parent) {
705 for (int i=0; i < parent.child_controls.Count; i++) {
706 child=parent.child_controls[i];
707 if (child.IsHandleCreated) {
708 XplatUI.SetWindowBackground(child.window.Handle, child.BackColor);
710 if (child.child_controls.Count>0) {
711 SetChildColor(child);
717 internal bool Select(Control control) {
719 IContainerControl container;
721 if (control == null) {
725 parent = control.parent;
727 if (((control.control_style & ControlStyles.Selectable) !=0) && (parent != null)) {
728 while (parent != null) {
729 if (!parent.Visible || !parent.is_enabled) {
732 parent = parent.parent;
736 control.is_selected = true;
738 XplatUI.SetFocus(control.window.Handle);
739 container = GetContainerControl();
740 if (container != null) {
741 container.ActiveControl = control;
746 internal virtual void DoDefaultAction() {
747 // Only here to be overriden by our actual controls; this is needed by the accessibility class
750 internal static int LowOrder (int param) {
751 return ((int)(short)(param & 0xffff));
754 internal static int HighOrder (int param) {
755 return ((int)(short)(param >> 16));
758 // This method exists so controls overriding OnPaintBackground can have default background painting done
759 internal void PaintControlBackground (PaintEventArgs pevent)
761 if (background_image != null)
762 pevent.Graphics.DrawImage (background_image, 0, 0);
765 internal void DndEnter (DragEventArgs e)
770 internal void DndOver (DragEventArgs e)
775 internal void DndDrop (DragEventArgs e)
780 internal void DndLeave (EventArgs e)
785 internal void DnDFeedback(GiveFeedbackEventArgs e)
790 internal void DnDContinueDrag(QueryContinueDragEventArgs e) {
791 OnQueryContinueDrag(e);
794 internal static MouseButtons FromParamToMouseButtons (int param) {
795 MouseButtons buttons = MouseButtons.None;
797 if ((param & (int) MsgButtons.MK_LBUTTON) != 0)
798 buttons |= MouseButtons.Left;
800 if ((param & (int) MsgButtons.MK_MBUTTON) != 0)
801 buttons |= MouseButtons.Middle;
803 if ((param & (int) MsgButtons.MK_RBUTTON) != 0)
804 buttons |= MouseButtons.Right;
810 internal virtual bool ProcessControlMnemonic(char charCode) {
811 return ProcessMnemonic(charCode);
814 private static Control FindFlatForward(Control container, Control start) {
820 end = container.child_controls.Count;
823 index = start.tab_index;
828 for (int i = 0; i < end; i++) {
830 if (container.child_controls[i].tab_index > index) {
831 found = container.child_controls[i];
833 } else if (found.tab_index > container.child_controls[i].tab_index) {
834 if (container.child_controls[i].tab_index > index) {
835 found = container.child_controls[i];
842 private static Control FindControlForward(Control container, Control start) {
849 if ((start is IContainerControl) || start.GetStyle(ControlStyles.ContainerControl)) {
850 found = FindControlForward(start, null);
857 while (p != container) {
858 found = FindFlatForward(p, start);
866 return FindFlatForward(container, start);
869 private static Control FindFlatBackward(Control container, Control start) {
875 end = container.child_controls.Count;
878 index = start.tab_index;
880 // FIXME: Possible speed-up: Keep the highest taborder index in the container
882 for (int i = 0; i < end; i++) {
883 if (container.child_controls[i].tab_index > index) {
884 index = container.child_controls[i].tab_index;
890 for (int i = 0; i < end; i++) {
892 if (container.child_controls[i].tab_index < index) {
893 found = container.child_controls[i];
895 } else if (found.tab_index < container.child_controls[i].tab_index) {
896 if (container.child_controls[i].tab_index < index) {
897 found = container.child_controls[i];
904 private static Control FindControlBackward(Control container, Control start) {
910 found = FindFlatBackward(start.parent, start);
911 if (found == null && start.parent != container) {
916 found = FindFlatBackward(container, start);
919 while ((found != null) && ((found is IContainerControl) || found.GetStyle(ControlStyles.ContainerControl))) {
920 found = FindControlBackward(found, null);
929 private void HandleClick(int clicks) {
930 if (GetStyle(ControlStyles.StandardClick)) {
932 if (GetStyle(ControlStyles.StandardDoubleClick)) {
933 OnDoubleClick(EventArgs.Empty);
935 OnClick(EventArgs.Empty);
938 OnClick(EventArgs.Empty);
943 private void CheckDataBindings ()
945 if (data_bindings == null)
948 BindingContext binding_context = BindingContext;
949 foreach (Binding binding in data_bindings) {
950 binding.Check (binding_context);
954 #endregion // Private & Internal Methods
956 #region Public Static Properties
957 public static Color DefaultBackColor {
959 return ThemeEngine.Current.DefaultControlBackColor;
963 public static Font DefaultFont {
965 return ThemeEngine.Current.DefaultFont;
969 public static Color DefaultForeColor {
971 return ThemeEngine.Current.DefaultControlForeColor;
975 public static Keys ModifierKeys {
977 return XplatUI.State.ModifierKeys;
981 public static MouseButtons MouseButtons {
983 return XplatUI.State.MouseButtons;
987 public static Point MousePosition {
989 return Cursor.Position;
992 #endregion // Public Static Properties
994 #region Public Instance Properties
995 [EditorBrowsable(EditorBrowsableState.Advanced)]
997 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
998 public AccessibleObject AccessibilityObject {
1000 if (accessibility_object==null) {
1001 accessibility_object=CreateAccessibilityInstance();
1003 return accessibility_object;
1007 [EditorBrowsable(EditorBrowsableState.Advanced)]
1009 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1010 public string AccessibleDefaultActionDescription {
1012 return AccessibilityObject.default_action;
1016 AccessibilityObject.default_action=value;
1021 [DefaultValue(null)]
1022 public string AccessibleDescription {
1024 return AccessibilityObject.description;
1028 AccessibilityObject.description=value;
1033 [DefaultValue(null)]
1034 public string AccessibleName {
1036 return AccessibilityObject.Name;
1040 AccessibilityObject.Name=value;
1044 [DefaultValue(AccessibleRole.Default)]
1045 public AccessibleRole AccessibleRole {
1047 return AccessibilityObject.role;
1051 AccessibilityObject.role=value;
1055 [DefaultValue(false)]
1056 public virtual bool AllowDrop {
1062 if (allow_drop == value)
1066 XplatUI.SetAllowDrop (Handle, value);
1071 [RefreshProperties(RefreshProperties.Repaint)]
1072 [DefaultValue(AnchorStyles.Top | AnchorStyles.Left)]
1073 public virtual AnchorStyles Anchor {
1075 return anchor_style;
1081 if (parent != null) {
1082 parent.PerformLayout(this, "Parent");
1088 public virtual Color BackColor {
1090 if (background_color.IsEmpty) {
1092 return parent.BackColor;
1094 return DefaultBackColor;
1096 return background_color;
1100 background_color=value;
1101 if (this.IsHandleCreated) {
1102 XplatUI.SetWindowBackground(this.window.Handle, value);
1104 SetChildColor(this);
1105 OnBackColorChanged(EventArgs.Empty);
1111 [DefaultValue(null)]
1112 public virtual Image BackgroundImage {
1114 return background_image;
1118 if (background_image!=value) {
1119 background_image=value;
1120 OnBackgroundImageChanged(EventArgs.Empty);
1125 [EditorBrowsable(EditorBrowsableState.Advanced)]
1127 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1128 public virtual BindingContext BindingContext {
1130 if (binding_context != null)
1131 return binding_context;
1134 binding_context = Parent.BindingContext;
1135 return binding_context;
1138 if (binding_context != value) {
1139 binding_context = value;
1140 OnBindingContextChanged(EventArgs.Empty);
1145 [EditorBrowsable(EditorBrowsableState.Advanced)]
1147 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1150 return bounds.Y+bounds.Height;
1154 [EditorBrowsable(EditorBrowsableState.Advanced)]
1156 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1157 public Rectangle Bounds {
1163 SetBoundsCore(value.Left, value.Top, value.Width, value.Height, BoundsSpecified.All);
1167 [EditorBrowsable(EditorBrowsableState.Advanced)]
1169 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1170 public bool CanFocus {
1172 if (Visible && is_enabled && GetStyle(ControlStyles.Selectable)) {
1179 [EditorBrowsable(EditorBrowsableState.Advanced)]
1181 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1182 public bool CanSelect {
1186 if (!GetStyle(ControlStyles.Selectable) || this.parent == null) {
1190 parent = this.parent;
1191 while (parent != null) {
1192 if (!parent.is_visible || !parent.is_enabled) {
1196 parent = parent.parent;
1202 [EditorBrowsable(EditorBrowsableState.Advanced)]
1204 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1205 public bool Capture {
1207 return this.is_captured;
1211 if (this.IsHandleCreated) {
1212 if (value && !is_captured) {
1214 XplatUI.GrabWindow(this.window.Handle, IntPtr.Zero);
1215 } else if (!value && is_captured) {
1216 XplatUI.UngrabWindow(this.window.Handle);
1217 is_captured = false;
1223 [DefaultValue(true)]
1224 public bool CausesValidation {
1226 return this.causes_validation;
1230 if (this.causes_validation != value) {
1231 causes_validation = value;
1232 OnCausesValidationChanged(EventArgs.Empty);
1237 [EditorBrowsable(EditorBrowsableState.Advanced)]
1239 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1240 public Rectangle ClientRectangle {
1242 client_rect.Width = client_size.Width;
1243 client_rect.Height = client_size.Height;
1248 [EditorBrowsable(EditorBrowsableState.Advanced)]
1250 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1251 public Size ClientSize {
1254 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1255 return ((Form)this).form_parent_window.ClientSize;
1263 this.SetClientSizeCore(value.Width, value.Height);
1267 [EditorBrowsable(EditorBrowsableState.Advanced)]
1269 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1270 [DescriptionAttribute("ControlCompanyNameDescr")]
1271 public String CompanyName {
1273 return "Mono Project, Novell, Inc.";
1277 [EditorBrowsable(EditorBrowsableState.Advanced)]
1279 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1280 public bool ContainsFocus {
1286 for (int i=0; i < child_controls.Count; i++) {
1287 if (child_controls[i].ContainsFocus) {
1295 [DefaultValue(null)]
1296 public virtual ContextMenu ContextMenu {
1298 return context_menu;
1302 if (context_menu != value) {
1303 context_menu = value;
1304 OnContextMenuChanged(EventArgs.Empty);
1310 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
1311 public ControlCollection Controls {
1313 return this.child_controls;
1317 [EditorBrowsable(EditorBrowsableState.Advanced)]
1319 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1320 public bool Created {
1322 if (!this.is_disposed && (this.window.Handle != IntPtr.Zero)) {
1329 [AmbientValue(null)]
1330 public virtual Cursor Cursor {
1332 if (cursor != null) {
1336 if (parent != null) {
1337 return parent.Cursor;
1340 return Cursors.Default;
1344 if (cursor != value) {
1349 pt = Cursor.Position;
1350 if (bounds.Contains(pt)) {
1351 if (GetChildAtPoint(pt) == null) {
1352 if (cursor != null) {
1353 XplatUI.SetCursor(window.Handle, cursor.handle);
1355 if (parent != null) {
1356 XplatUI.SetCursor(window.Handle, parent.Cursor.handle);
1358 XplatUI.SetCursor(window.Handle, Cursors.def.handle);
1364 OnCursorChanged(EventArgs.Empty);
1370 [EditorBrowsable(EditorBrowsableState.Advanced)]
1372 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1373 public ControlBindingsCollection DataBindings {
1375 if (data_bindings == null)
1376 data_bindings = new ControlBindingsCollection (this);
1377 return data_bindings;
1381 [EditorBrowsable(EditorBrowsableState.Advanced)]
1383 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1384 public virtual Rectangle DisplayRectangle {
1386 return ClientRectangle;
1390 [EditorBrowsable(EditorBrowsableState.Advanced)]
1392 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1393 public bool Disposing {
1400 [RefreshProperties(RefreshProperties.Repaint)]
1401 [DefaultValue(DockStyle.None)]
1402 public virtual DockStyle Dock {
1408 if (dock_style == value) {
1414 if (parent != null) {
1415 parent.PerformLayout(this, "Parent");
1418 OnDockChanged(EventArgs.Empty);
1424 public bool Enabled {
1430 if (is_enabled == value) {
1436 OnEnabledChanged (EventArgs.Empty);
1440 [EditorBrowsable(EditorBrowsableState.Advanced)]
1442 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1443 public virtual bool Focused {
1445 return this.has_focus;
1450 [AmbientValue(null)]
1452 public virtual Font Font {
1458 if (Parent != null && Parent.Font != null) {
1466 if (font != null && font.Equals (value)) {
1472 OnFontChanged (EventArgs.Empty);
1477 public virtual Color ForeColor {
1479 if (foreground_color.IsEmpty) {
1481 return parent.ForeColor;
1483 return DefaultForeColor;
1485 return foreground_color;
1489 if (foreground_color != value) {
1490 foreground_color=value;
1492 OnForeColorChanged(EventArgs.Empty);
1499 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1500 public IntPtr Handle { // IWin32Window
1502 if (!IsHandleCreated) {
1505 return window.Handle;
1509 [EditorBrowsable(EditorBrowsableState.Advanced)]
1511 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1512 public bool HasChildren {
1514 if (this.child_controls.Count>0) {
1521 [EditorBrowsable(EditorBrowsableState.Always)]
1523 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1526 return this.bounds.Height;
1530 SetBoundsCore(bounds.X, bounds.Y, bounds.Width, value, BoundsSpecified.Height);
1534 [AmbientValue(ImeMode.Inherit)]
1536 public ImeMode ImeMode {
1542 if (ime_mode != value) {
1545 OnImeModeChanged(EventArgs.Empty);
1550 [EditorBrowsable(EditorBrowsableState.Advanced)]
1552 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1553 public bool InvokeRequired { // ISynchronizeInvoke
1555 if (creator_thread!=Thread.CurrentThread) {
1562 [EditorBrowsable(EditorBrowsableState.Advanced)]
1564 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1565 public bool IsAccessible {
1567 return is_accessible;
1571 is_accessible = value;
1575 [EditorBrowsable(EditorBrowsableState.Advanced)]
1577 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1578 public bool IsDisposed {
1580 return this.is_disposed;
1584 [EditorBrowsable(EditorBrowsableState.Advanced)]
1586 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1587 public bool IsHandleCreated {
1589 if ((window!=null) && (window.Handle!=IntPtr.Zero)) {
1597 [EditorBrowsable(EditorBrowsableState.Always)]
1599 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1602 return this.bounds.X;
1606 SetBoundsCore(value, bounds.Y, bounds.Width, bounds.Height, BoundsSpecified.X);
1611 public Point Location {
1613 return new Point(bounds.X, bounds.Y);
1617 SetBoundsCore(value.X, value.Y, bounds.Width, bounds.Height, BoundsSpecified.Location);
1622 public string Name {
1633 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1634 public Control Parent {
1640 if (value == this) {
1641 throw new ArgumentException("A circular control reference has been made. A control cannot be owned or parented to itself.");
1644 if (parent!=value) {
1646 parent.Controls.Remove(this);
1652 if (!parent.Controls.Contains(this)) {
1653 parent.Controls.Add(this);
1656 XplatUI.SetParent(Handle, value.Handle);
1660 OnParentChanged(EventArgs.Empty);
1665 [EditorBrowsable(EditorBrowsableState.Advanced)]
1667 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1668 public string ProductName {
1670 Type t = typeof (AssemblyProductAttribute);
1671 Assembly assembly = GetType().Module.Assembly;
1672 object [] attrs = assembly.GetCustomAttributes (t, false);
1673 AssemblyProductAttribute a = null;
1674 // On MS we get a NullRefException if product attribute is not
1676 if (attrs != null && attrs.Length > 0)
1677 a = (AssemblyProductAttribute) attrs [0];
1682 [EditorBrowsable(EditorBrowsableState.Advanced)]
1684 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1685 public string ProductVersion {
1687 Type t = typeof (AssemblyVersionAttribute);
1688 Assembly assembly = GetType().Module.Assembly;
1689 object [] attrs = assembly.GetCustomAttributes (t, false);
1690 if (attrs == null || attrs.Length < 1)
1692 return ((AssemblyVersionAttribute)attrs [0]).Version;
1696 [EditorBrowsable(EditorBrowsableState.Advanced)]
1698 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1699 public bool RecreatingHandle {
1701 return is_recreating;
1705 [EditorBrowsable(EditorBrowsableState.Advanced)]
1707 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1708 public Region Region {
1710 return new Region(this.bounds);
1717 g = this.CreateGraphics();
1718 r = value.GetBounds(g);
1720 SetBounds((int)r.X, (int)r.Y, (int)r.Width, (int)r.Height);
1726 [EditorBrowsable(EditorBrowsableState.Advanced)]
1728 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1731 return this.bounds.X+this.bounds.Width;
1735 [AmbientValue(RightToLeft.Inherit)]
1737 public virtual RightToLeft RightToLeft {
1739 return right_to_left;
1743 if (value != right_to_left) {
1744 right_to_left = value;
1745 OnRightToLeftChanged(EventArgs.Empty);
1750 [EditorBrowsable(EditorBrowsableState.Advanced)]
1751 public override ISite Site {
1764 return new Size(Width, Height);
1768 SetBoundsCore(bounds.X, bounds.Y, value.Width, value.Height, BoundsSpecified.Size);
1773 [MergableProperty(false)]
1774 public int TabIndex {
1776 if (tab_index != -1) {
1783 if (tab_index != value) {
1785 OnTabIndexChanged(EventArgs.Empty);
1791 [DefaultValue(true)]
1792 public bool TabStop {
1798 if (tab_stop != value) {
1800 OnTabStopChanged(EventArgs.Empty);
1805 [Localizable(false)]
1807 [TypeConverter(typeof(StringConverter))]
1808 [DefaultValue(null)]
1815 control_tag = value;
1821 [BindableAttribute(true)]
1822 public virtual string Text {
1828 if (value == null) {
1829 value = String.Empty;
1834 XplatUI.Text(Handle, text);
1835 // FIXME: Do we need a Refresh() here?
1836 OnTextChanged (EventArgs.Empty);
1841 [EditorBrowsable(EditorBrowsableState.Always)]
1843 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1846 return this.bounds.Y;
1850 SetBoundsCore(bounds.X, value, bounds.Width, bounds.Height, BoundsSpecified.Y);
1854 [EditorBrowsable(EditorBrowsableState.Advanced)]
1856 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1857 public Control TopLevelControl {
1861 while (p.parent != null) {
1870 public bool Visible {
1874 } else if (parent != null) {
1875 return parent.Visible;
1882 SetVisibleCore(value);
1886 [EditorBrowsable(EditorBrowsableState.Always)]
1888 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1891 return this.bounds.Width;
1895 SetBoundsCore(bounds.X, bounds.Y, value, bounds.Height, BoundsSpecified.Width);
1899 [EditorBrowsable(EditorBrowsableState.Never)]
1901 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1902 public IWindowTarget WindowTarget {
1911 #endregion // Public Instance Properties
1913 #region Protected Instance Properties
1914 protected virtual CreateParams CreateParams {
1916 CreateParams create_params = new CreateParams();
1919 create_params.Caption = Text;
1922 create_params.Caption = text;
1926 create_params.X = Left;
1929 create_params.X = this.bounds.X;
1933 create_params.Y = Top;
1936 create_params.Y = this.bounds.Y;
1940 create_params.Width = Width;
1943 create_params.Width = this.bounds.Width;
1947 create_params.Height = Height;
1950 create_params.Height = this.bounds.Height;
1954 create_params.ClassName = XplatUI.DefaultClassName;
1955 create_params.ClassStyle = 0;
1956 create_params.ExStyle = 0;
1957 create_params.Param = 0;
1960 create_params.ExStyle |= (int)WindowStyles.WS_EX_ACCEPTFILES;
1964 create_params.Parent = parent.Handle;
1967 create_params.Style = (int)WindowStyles.WS_CHILD | (int)WindowStyles.WS_CLIPCHILDREN | (int)WindowStyles.WS_CLIPSIBLINGS;
1970 create_params.Style |= (int)WindowStyles.WS_VISIBLE;
1973 return create_params;
1977 protected virtual ImeMode DefaultImeMode {
1979 return ImeMode.Inherit;
1983 protected virtual Size DefaultSize {
1985 return new Size(100, 23);
1989 protected int FontHeight {
1999 protected bool RenderRightToLeft {
2001 return (this.right_to_left == RightToLeft.Yes);
2005 protected bool ResizeRedraw {
2007 return GetStyle(ControlStyles.ResizeRedraw);
2011 SetStyle(ControlStyles.ResizeRedraw, value);
2015 [EditorBrowsable(EditorBrowsableState.Advanced)]
2017 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2018 protected virtual bool ShowFocusCues {
2024 [EditorBrowsable(EditorBrowsableState.Advanced)]
2026 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2027 protected bool ShowKeyboardCues {
2032 #endregion // Protected Instance Properties
2034 #region Public Static Methods
2035 [EditorBrowsable(EditorBrowsableState.Advanced)]
2036 public static Control FromChildHandle(IntPtr handle) {
2037 IEnumerator control = Control.controls.GetEnumerator();
2039 while (control.MoveNext()) {
2040 if (((Control)control.Current).window.Handle == handle) {
2042 if (((Control)control.Current).Parent != null) {
2043 return ((Control)control.Current).Parent;
2050 [EditorBrowsable(EditorBrowsableState.Advanced)]
2051 public static Control FromHandle(IntPtr handle) {
2052 IEnumerator control = Control.controls.GetEnumerator();
2054 while (control.MoveNext()) {
2055 if (((Control)control.Current).window.Handle == handle) {
2057 return ((Control)control.Current);
2063 public static bool IsMnemonic(char charCode, string text) {
2066 amp = text.IndexOf('&');
2069 if (amp + 1 < text.Length) {
2070 if (text[amp + 1] != '&') {
2071 if (Char.ToUpper(charCode) == Char.ToUpper(text.ToCharArray(amp + 1, 1)[0])) {
2081 #region Protected Static Methods
2082 [EditorBrowsable(EditorBrowsableState.Advanced)]
2083 protected static bool ReflectMessage(IntPtr hWnd, ref Message m) {
2086 c = Control.FromHandle(hWnd);
2096 #region Public Instance Methods
2097 [EditorBrowsable(EditorBrowsableState.Advanced)]
2098 public IAsyncResult BeginInvoke(Delegate method) {
2099 return BeginInvokeInternal(method, null);
2102 [EditorBrowsable(EditorBrowsableState.Advanced)]
2103 public IAsyncResult BeginInvoke (Delegate method, object[] args) {
2104 return BeginInvokeInternal (method, args);
2107 public void BringToFront() {
2108 if ((parent != null) && (parent.child_controls[0]!=this)) {
2109 if (parent.child_controls.Contains(this)) {
2110 parent.child_controls.SetChildIndex(this, 0);
2114 XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, true, false);
2116 if (parent != null) {
2121 public bool Contains(Control ctl) {
2122 while (ctl != null) {
2131 public void CreateControl() {
2133 if (!IsHandleCreated) {
2137 if (!create_handled) {
2138 create_handled = true;
2142 for (int i=0; i<child_controls.Count; i++) {
2143 child_controls[i].CreateControl();
2147 public Graphics CreateGraphics() {
2148 if (!IsHandleCreated) {
2149 this.CreateControl();
2151 return Graphics.FromHwnd(this.window.Handle);
2154 public DragDropEffects DoDragDrop(object data, DragDropEffects allowedEffects) {
2155 return XplatUI.StartDrag(this.window.Handle, data, allowedEffects);
2158 [EditorBrowsable(EditorBrowsableState.Advanced)]
2159 public object EndInvoke (IAsyncResult async_result) {
2160 AsyncMethodResult result = (AsyncMethodResult) async_result;
2161 return result.EndInvoke ();
2164 public Form FindForm() {
2177 public bool Focus() {
2178 if (IsHandleCreated && !has_focus) {
2180 XplatUI.SetFocus(window.Handle);
2185 public Control GetChildAtPoint(Point pt) {
2186 // Microsoft's version of this function doesn't seem to work, so I can't check
2187 // if we only consider children or also grandchildren, etc.
2188 // I'm gonna say 'children only'
2189 for (int i=0; i<child_controls.Count; i++) {
2190 if (child_controls[i].Bounds.Contains(pt)) {
2191 return child_controls[i];
2197 public IContainerControl GetContainerControl() {
2198 Control current = this;
2200 while (current!=null) {
2201 if ((current is IContainerControl) && ((current.control_style & ControlStyles.ContainerControl)!=0)) {
2202 return (IContainerControl)current;
2204 current = current.parent;
2209 public Control GetNextControl(Control ctl, bool forward) {
2210 // If we're not a container we don't play
2211 if (!(this is IContainerControl) && !this.GetStyle(ControlStyles.ContainerControl)) {
2215 // If ctl is not contained by this, we start at the first child of this
2216 if (!this.Contains(ctl)) {
2220 // Search through our controls, starting at ctl, stepping into children as we encounter them
2221 // try to find the control with the tabindex closest to our own, or, if we're looking into
2222 // child controls, the one with the smallest tabindex
2224 return FindControlForward(this, ctl);
2226 return FindControlBackward(this, ctl);
2229 public void Hide() {
2230 this.Visible = false;
2233 public void Invalidate() {
2234 Invalidate(ClientRectangle, false);
2237 public void Invalidate(bool invalidateChildren) {
2238 Invalidate(ClientRectangle, invalidateChildren);
2241 public void Invalidate(System.Drawing.Rectangle rc) {
2242 Invalidate(rc, false);
2245 public void Invalidate(System.Drawing.Rectangle rc, bool invalidateChildren) {
2246 if (!IsHandleCreated || !Visible) {
2250 NotifyInvalidate(rc);
2252 XplatUI.Invalidate(Handle, rc, false);
2254 if (invalidateChildren) {
2255 for (int i=0; i<child_controls.Count; i++) child_controls[i].Invalidate();
2257 OnInvalidated(new InvalidateEventArgs(rc));
2260 public void Invalidate(System.Drawing.Region region) {
2261 Invalidate(region, false);
2264 [MonoTODO("Figure out if GetRegionScans is usable")]
2265 public void Invalidate(System.Drawing.Region region, bool invalidateChildren) {
2266 throw new NotImplementedException();
2268 // FIXME - should use the GetRegionScans function of the region to invalidate each area
2269 //if (invalidateChildren) {
2270 // for (int i=0; i<child_controls.Count; i++) child_controls[i].Invalidate();
2274 public object Invoke (Delegate method) {
2275 return Invoke(method, null);
2278 public object Invoke (Delegate method, object[] args) {
2279 if (!this.InvokeRequired) {
2280 return method.DynamicInvoke(args);
2283 IAsyncResult result = BeginInvoke (method, args);
2284 return EndInvoke(result);
2287 [EditorBrowsable(EditorBrowsableState.Advanced)]
2288 public void PerformLayout() {
2289 PerformLayout(null, null);
2292 [EditorBrowsable(EditorBrowsableState.Advanced)]
2293 public void PerformLayout(Control affectedControl, string affectedProperty) {
2294 LayoutEventArgs levent = new LayoutEventArgs(affectedControl, affectedProperty);
2296 if (layout_suspended>0) {
2297 layout_pending = true;
2301 layout_pending = false;
2303 // Prevent us from getting messed up
2306 // Perform all Dock and Anchor calculations
2309 AnchorStyles anchor;
2314 space=this.DisplayRectangle;
2315 if (prev_size != Size.Empty) {
2316 diff_width = space.Width - prev_size.Width;
2317 diff_height = space.Height - prev_size.Height;
2323 // Deal with docking; go through in reverse, MS docs say that lowest Z-order is closest to edge
2324 for (int i = child_controls.Count - 1; i >= 0; i--) {
2325 child=child_controls[i];
2326 switch (child.Dock) {
2327 case DockStyle.None: {
2332 case DockStyle.Left: {
2333 child.SetBounds(space.Left, space.Y, child.Width, space.Height);
2334 space.X+=child.Width;
2335 space.Width-=child.Width;
2339 case DockStyle.Top: {
2340 child.SetBounds(space.Left, space.Y, space.Width, child.Height);
2341 space.Y+=child.Height;
2342 space.Height-=child.Height;
2346 case DockStyle.Right: {
2347 child.SetBounds(space.Right-child.Width, space.Y, child.Width, space.Height);
2348 space.Width-=child.Width;
2352 case DockStyle.Bottom: {
2353 child.SetBounds(space.Left, space.Bottom-child.Height, space.Width, child.Height);
2354 space.Height-=child.Height;
2360 for (int i = child_controls.Count - 1; i >= 0; i--) {
2361 child=child_controls[i];
2363 if (child.Dock == DockStyle.Fill) {
2364 child.SetBounds(space.Left, space.Top, space.Width, space.Height);
2370 space=this.DisplayRectangle;
2372 // Deal with anchoring
2373 for (int i=0; i < child_controls.Count; i++) {
2379 child=child_controls[i];
2380 anchor=child.Anchor;
2385 height=child.Height;
2387 // If the control is docked we don't need to do anything
2388 if (child.Dock != DockStyle.None) {
2392 if ((anchor & AnchorStyles.Left) !=0 ) {
2393 if ((anchor & AnchorStyles.Right) != 0) {
2394 // Anchoring to left and right
2395 width=width+diff_width;
2399 } else if ((anchor & AnchorStyles.Right) != 0) {
2405 if ((anchor & AnchorStyles.Top) !=0 ) {
2406 if ((anchor & AnchorStyles.Bottom) != 0) {
2407 height+=diff_height;
2411 } else if ((anchor & AnchorStyles.Bottom) != 0) {
2426 child.SetBounds(left, top, width, height);
2429 // Let everyone know
2433 // Need to make sure we decremend layout_suspended
2439 public Point PointToClient (Point p) {
2443 XplatUI.ScreenToClient (Handle, ref x, ref y);
2445 return new Point (x, y);
2448 public Point PointToScreen(Point p) {
2452 XplatUI.ClientToScreen(Handle, ref x, ref y);
2454 return new Point(x, y);
2457 public virtual bool PreProcessMessage(ref Message msg) {
2460 if ((msg.Msg == (int)Msg.WM_KEYDOWN) || (msg.Msg == (int)Msg.WM_SYSKEYDOWN)) {
2461 key_data = (Keys)msg.WParam.ToInt32();
2462 if (!ProcessCmdKey(ref msg, key_data)) {
2463 if (IsInputKey(key_data)) {
2467 return ProcessDialogKey(key_data);
2471 } else if (msg.Msg == (int)Msg.WM_CHAR) {
2472 if (IsInputChar((char)msg.WParam)) {
2475 } else if (msg.Msg == (int)Msg.WM_SYSCHAR) {
2476 if (IsInputChar((char)msg.WParam)) {
2479 return ProcessDialogChar((char)msg.WParam);
2484 public Rectangle RectangleToClient(Rectangle r) {
2485 return new Rectangle(PointToClient(r.Location), r.Size);
2488 public Rectangle RectangleToScreen(Rectangle r) {
2489 return new Rectangle(PointToScreen(r.Location), r.Size);
2492 public virtual void Refresh() {
2493 if (IsHandleCreated == true) {
2495 XplatUI.UpdateWindow(window.Handle);
2499 [EditorBrowsable(EditorBrowsableState.Never)]
2500 public virtual void ResetBackColor() {
2501 background_color = Color.Empty;
2504 #if haveDataBindings
2505 [EditorBrowsable(EditorBrowsableState.Never)]
2507 public void ResetBindings() {
2512 [EditorBrowsable(EditorBrowsableState.Never)]
2513 public virtual void ResetCursor() {
2517 [EditorBrowsable(EditorBrowsableState.Never)]
2518 public virtual void ResetFont() {
2522 [EditorBrowsable(EditorBrowsableState.Never)]
2523 public virtual void ResetForeColor() {
2524 foreground_color = Color.Empty;
2527 [EditorBrowsable(EditorBrowsableState.Never)]
2528 public void ResetImeMode() {
2529 ime_mode = DefaultImeMode;
2532 [EditorBrowsable(EditorBrowsableState.Never)]
2533 public virtual void ResetRightToLeft() {
2534 right_to_left = RightToLeft.Inherit;
2537 public virtual void ResetText() {
2541 public void ResumeLayout() {
2542 ResumeLayout (true);
2545 public void ResumeLayout(bool performLayout) {
2548 if (layout_suspended > 0) {
2552 if (performLayout || layout_pending) {
2557 public void Scale(float ratio) {
2558 ScaleCore(ratio, ratio);
2561 public void Scale(float dx, float dy) {
2565 public void Select() {
2566 Select(false, false);
2569 public bool SelectNextControl(Control ctl, bool forward, bool tabStopOnly, bool nested, bool wrap) {
2574 c = GetNextControl(c, forward);
2583 if (c.CanSelect && ((c.parent == ctl.parent) || nested) && (c.tab_stop || !tabStopOnly)) {
2587 } while (c != ctl); // If we wrap back to ourselves we stop
2592 public void SendToBack() {
2593 if ((parent != null) && (parent.child_controls[parent.child_controls.Count-1]!=this)) {
2594 if (parent.child_controls.Contains(this)) {
2595 parent.child_controls.SetChildIndex(this, parent.child_controls.Count);
2599 XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, false, true);
2600 if (parent != null) {
2605 public void SetBounds(int x, int y, int width, int height) {
2606 SetBoundsCore(x, y, width, height, BoundsSpecified.All);
2609 public void SetBounds(int x, int y, int width, int height, BoundsSpecified specified) {
2610 SetBoundsCore(x, y, width, height, specified);
2613 public void Show() {
2614 if (!IsHandleCreated) {
2615 this.CreateControl();
2621 public void SuspendLayout() {
2625 public void Update() {
2626 needs_redraw = true;
2627 XplatUI.UpdateWindow(window.Handle);
2629 #endregion // Public Instance Methods
2631 #region Protected Instance Methods
2632 [EditorBrowsable(EditorBrowsableState.Advanced)]
2633 [MonoTODO("Implement this and tie it into Control.ControlAccessibleObject.NotifyClients")]
2634 protected void AccessibilityNotifyClients(AccessibleEvents accEvent, int childID) {
2635 throw new NotImplementedException();
2638 [EditorBrowsable(EditorBrowsableState.Advanced)]
2639 protected virtual AccessibleObject CreateAccessibilityInstance() {
2640 return new Control.ControlAccessibleObject(this);
2643 [EditorBrowsable(EditorBrowsableState.Advanced)]
2644 protected virtual ControlCollection CreateControlsInstance() {
2645 return new ControlCollection(this);
2648 [EditorBrowsable(EditorBrowsableState.Advanced)]
2649 protected virtual void CreateHandle() {
2651 throw new ObjectDisposedException(Name);
2654 if (IsHandleCreated) {
2658 window.CreateHandle(CreateParams);
2660 // Find out where the window manager placed us
2664 if (window.Handle!=IntPtr.Zero) {
2665 if (!controls.Contains(window.Handle)) {
2669 creator_thread = Thread.CurrentThread;
2671 XplatUI.SetWindowBackground(window.Handle, this.BackColor);
2673 OnHandleCreated(EventArgs.Empty);
2677 [EditorBrowsable(EditorBrowsableState.Advanced)]
2678 protected virtual void DefWndProc(ref Message m) {
2679 window.DefWndProc(ref m);
2682 [EditorBrowsable(EditorBrowsableState.Advanced)]
2683 protected virtual void DestroyHandle() {
2684 if (IsHandleCreated) {
2685 // Destroy our children before we destroy ourselves, to prevent them from
2686 // being implictly (without us knowing) destroyed
2687 for (int i=0; i < child_controls.Count; i++) {
2688 child_controls[i].DestroyHandle();
2692 if (window != null) {
2693 window.DestroyHandle();
2695 OnHandleDestroyed(EventArgs.Empty);
2699 protected bool GetStyle(ControlStyles flag) {
2700 return (control_style & flag) != 0;
2703 protected bool GetTopLevel() {
2707 [EditorBrowsable(EditorBrowsableState.Advanced)]
2708 protected virtual void InitLayout() {
2709 if (parent != null) {
2710 parent.PerformLayout(this, "parent");
2714 [EditorBrowsable(EditorBrowsableState.Advanced)]
2715 protected void InvokeGotFocus(Control toInvoke, EventArgs e) {
2716 toInvoke.OnGotFocus(e);
2719 [EditorBrowsable(EditorBrowsableState.Advanced)]
2720 protected void InvokeLostFocus(Control toInvoke, EventArgs e) {
2721 toInvoke.OnLostFocus(e);
2724 [EditorBrowsable(EditorBrowsableState.Advanced)]
2725 protected void InvokeOnClick(Control toInvoke, EventArgs e) {
2726 toInvoke.OnClick(e);
2729 protected void InvokePaint(Control toInvoke, PaintEventArgs e) {
2730 toInvoke.OnPaint(e);
2733 protected void InvokePaintBackground(Control toInvoke, PaintEventArgs e) {
2734 toInvoke.OnPaintBackground(e);
2737 protected virtual bool IsInputChar (char charCode) {
2738 if (parent != null) {
2739 return parent.IsInputChar(charCode);
2745 protected virtual bool IsInputKey (Keys keyData) {
2746 // Doc says this one calls IsInputChar; not sure what to do with that
2750 [EditorBrowsable(EditorBrowsableState.Advanced)]
2751 protected virtual void NotifyInvalidate(Rectangle invalidatedArea) {
2755 protected virtual bool ProcessCmdKey(ref Message msg, Keys keyData) {
2756 if ((context_menu != null) && context_menu.ProcessCmdKey(ref msg, keyData)) {
2760 if (parent != null) {
2761 return parent.ProcessCmdKey(ref msg, keyData);
2767 protected virtual bool ProcessDialogChar(char charCode) {
2768 if (parent != null) {
2769 return parent.ProcessDialogChar (charCode);
2775 protected virtual bool ProcessDialogKey (Keys keyData) {
2776 if (parent != null) {
2777 return parent.ProcessDialogKey (keyData);
2783 protected virtual bool ProcessKeyEventArgs (ref Message msg)
2785 KeyEventArgs key_event;
2788 case (int)Msg.WM_KEYDOWN: {
2789 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
2790 OnKeyDown (key_event);
2791 return key_event.Handled;
2793 case (int)Msg.WM_KEYUP: {
2794 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
2795 OnKeyUp (key_event);
2796 return key_event.Handled;
2799 case (int)Msg.WM_CHAR: {
2800 KeyPressEventArgs key_press_event;
2802 key_press_event = new KeyPressEventArgs((char)msg.WParam);
2803 OnKeyPress(key_press_event);
2804 return key_press_event.Handled;
2815 protected internal virtual bool ProcessKeyMessage(ref Message msg) {
2816 if (parent != null) {
2817 if (parent.ProcessKeyPreview(ref msg)) {
2825 protected virtual bool ProcessKeyPreview(ref Message msg) {
2826 if (parent != null) {
2827 return parent.ProcessKeyPreview(ref msg);
2833 protected virtual bool ProcessMnemonic(char charCode) {
2838 [EditorBrowsable(EditorBrowsableState.Advanced)]
2839 protected void RaiseDragEvent(object key, DragEventArgs e) {
2843 [EditorBrowsable(EditorBrowsableState.Advanced)]
2844 protected void RaiseKeyEvent(object key, KeyEventArgs e) {
2848 [EditorBrowsable(EditorBrowsableState.Advanced)]
2849 protected void RaiseMouseEvent(object key, MouseEventArgs e) {
2853 [EditorBrowsable(EditorBrowsableState.Advanced)]
2854 protected void RaisePaintEvent(object key, PaintEventArgs e) {
2858 [EditorBrowsable(EditorBrowsableState.Advanced)]
2859 protected void RecreateHandle() {
2860 IEnumerator child = child_controls.GetEnumerator();
2864 if (IsHandleCreated) {
2870 while (child.MoveNext()) {
2871 ((Control)child.Current).RecreateHandle();
2877 is_recreating = false;
2880 [EditorBrowsable(EditorBrowsableState.Advanced)]
2881 protected void ResetMouseEventArgs() {
2885 [EditorBrowsable(EditorBrowsableState.Advanced)]
2886 protected ContentAlignment RtlTranslateAlignment(ContentAlignment align) {
2887 if (right_to_left == RightToLeft.No) {
2892 case ContentAlignment.TopLeft: {
2893 return ContentAlignment.TopRight;
2896 case ContentAlignment.TopRight: {
2897 return ContentAlignment.TopLeft;
2900 case ContentAlignment.MiddleLeft: {
2901 return ContentAlignment.MiddleRight;
2904 case ContentAlignment.MiddleRight: {
2905 return ContentAlignment.MiddleLeft;
2908 case ContentAlignment.BottomLeft: {
2909 return ContentAlignment.BottomRight;
2912 case ContentAlignment.BottomRight: {
2913 return ContentAlignment.BottomLeft;
2917 // if it's center it doesn't change
2923 [EditorBrowsable(EditorBrowsableState.Advanced)]
2924 protected HorizontalAlignment RtlTranslateAlignment(HorizontalAlignment align) {
2925 if ((right_to_left == RightToLeft.No) || (align == HorizontalAlignment.Center)) {
2929 if (align == HorizontalAlignment.Left) {
2930 return HorizontalAlignment.Right;
2933 // align must be HorizontalAlignment.Right
2934 return HorizontalAlignment.Left;
2937 [EditorBrowsable(EditorBrowsableState.Advanced)]
2938 protected LeftRightAlignment RtlTranslateAlignment(LeftRightAlignment align) {
2939 if (right_to_left == RightToLeft.No) {
2943 if (align == LeftRightAlignment.Left) {
2944 return LeftRightAlignment.Right;
2947 // align must be LeftRightAlignment.Right;
2948 return LeftRightAlignment.Left;
2951 [EditorBrowsable(EditorBrowsableState.Advanced)]
2952 protected ContentAlignment RtlTranslateContent(ContentAlignment align) {
2953 return RtlTranslateAlignment(align);
2956 [EditorBrowsable(EditorBrowsableState.Advanced)]
2957 protected HorizontalAlignment RtlTranslateHorizontal(HorizontalAlignment align) {
2958 return RtlTranslateAlignment(align);
2961 [EditorBrowsable(EditorBrowsableState.Advanced)]
2962 protected LeftRightAlignment RtlTranslateLeftRight(LeftRightAlignment align) {
2963 return RtlTranslateAlignment(align);
2966 [EditorBrowsable(EditorBrowsableState.Advanced)]
2967 protected virtual void ScaleCore(float dx, float dy) {
2973 location = new Point((int)(Left * dx), (int)(Top * dy));
2974 size = this.ClientSize;
2977 if (!GetStyle(ControlStyles.FixedWidth)) {
2978 size.Width = (int)(size.Width * dx);
2981 if (!GetStyle(ControlStyles.FixedHeight)) {
2982 size.Height = (int)(size.Height * dy);
2985 Location = location;
2988 /* Now scale our children */
2989 for (int i=0; i < child_controls.Count; i++) {
2990 child_controls[i].Scale(dx, dy);
2996 protected virtual void Select(bool directed, bool forward) {
3001 // Select this control
3006 if (parent == null) {
3010 // FIXME - this thing is doing the wrong stuff, needs to be similar to SelectNextControl
3012 index = parent.child_controls.IndexOf(this);
3017 if ((index+1) < parent.child_controls.Count) {
3026 index = parent.child_controls.Count-1;
3029 result = Select(parent.child_controls[index]);
3030 } while (!result && parent.child_controls[index] != this);
3033 [EditorBrowsable(EditorBrowsableState.Advanced)]
3034 protected virtual void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
3035 // SetBoundsCore updates the Win32 control itself. UpdateBounds updates the controls variables and fires events, I'm guessing - pdb
3036 if ((specified & BoundsSpecified.X) != BoundsSpecified.X) {
3040 if ((specified & BoundsSpecified.Y) != BoundsSpecified.Y) {
3044 if ((specified & BoundsSpecified.Width) != BoundsSpecified.Width) {
3048 if ((specified & BoundsSpecified.Height) != BoundsSpecified.Height) {
3052 if (IsHandleCreated) {
3053 XplatUI.SetWindowPos(Handle, x, y, width, height);
3055 UpdateBounds(x, y, width, height);
3058 [EditorBrowsable(EditorBrowsableState.Advanced)]
3059 protected virtual void SetClientSizeCore(int x, int y) {
3060 // Calculate the actual window size from the client size (it usually stays the same or grows)
3061 Rectangle ClientRect;
3062 Rectangle WindowRect;
3065 ClientRect = new Rectangle(0, 0, x, y);
3066 cp = this.CreateParams;
3068 if (XplatUI.CalculateWindowRect(Handle, ref ClientRect, cp.Style, cp.ExStyle, IntPtr.Zero, out WindowRect)==false) {
3072 SetBoundsCore(bounds.X, bounds.Y, WindowRect.Width, WindowRect.Height, BoundsSpecified.Size);
3075 [EditorBrowsable(EditorBrowsableState.Advanced)]
3076 protected void SetStyle(ControlStyles flag, bool value) {
3078 control_style |= flag;
3080 control_style &= ~flag;
3082 OnStyleChanged(EventArgs.Empty);
3085 protected void SetTopLevel(bool value) {
3086 if ((GetTopLevel() != value) && (parent != null)) {
3087 throw new Exception();
3091 if (value == true) {
3101 is_toplevel = value;
3104 protected virtual void SetVisibleCore(bool value) {
3105 if (value!=is_visible) {
3107 XplatUI.SetVisible(Handle, value);
3108 // Explicitly move Toplevel windows to where we want them;
3109 // apparently moving unmapped toplevel windows doesn't work
3110 if (is_visible && (this is Form)) {
3111 XplatUI.SetWindowPos(window.Handle, bounds.X, bounds.Y, bounds.Width, bounds.Height);
3113 OnVisibleChanged(EventArgs.Empty);
3116 if (dc_mem != null) {
3121 if (bmp_mem != null) {
3126 this.CreateBuffers(bounds.Width, bounds.Height);
3131 if (value == false && parent != null) {
3134 // Need to start at parent, GetContainerControl might return ourselves if we're a container
3135 container = (Control)parent.GetContainerControl();
3136 if (container != null) {
3137 container.SelectNextControl(this, true, true, true, true);
3141 if (parent != null) {
3142 parent.PerformLayout(this, "visible");
3144 PerformLayout(this, "visible");
3149 [EditorBrowsable(EditorBrowsableState.Advanced)]
3150 protected void UpdateBounds() {
3158 if (!IsHandleCreated) {
3162 XplatUI.GetWindowPos(this.Handle, this is Form, out x, out y, out width, out height, out client_width, out client_height);
3164 UpdateBounds(x, y, width, height, client_width, client_height);
3167 [EditorBrowsable(EditorBrowsableState.Advanced)]
3168 protected void UpdateBounds(int x, int y, int width, int height) {
3169 // UpdateBounds only seems to set our sizes and fire events but not update the GUI window to match
3171 bool resized = false;
3173 int client_x_diff = this.bounds.Width-this.client_size.Width;
3174 int client_y_diff = this.bounds.Height-this.client_size.Height;
3176 // Needed to generate required notifications
3177 if ((this.bounds.X!=x) || (this.bounds.Y!=y)) {
3181 if ((this.Bounds.Width!=width) || (this.Bounds.Height!=height)) {
3188 bounds.Height=height;
3190 // Update client rectangle as well
3191 if (this.layout_suspended==0) {
3192 prev_size.Width=client_size.Width;
3193 prev_size.Height=client_size.Height;
3196 client_size.Width=width-client_x_diff;
3197 client_size.Height=height-client_y_diff;
3200 OnLocationChanged(EventArgs.Empty);
3204 OnSizeChanged(EventArgs.Empty);
3208 [EditorBrowsable(EditorBrowsableState.Advanced)]
3209 protected void UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) {
3210 UpdateBounds(x, y, width, height);
3212 this.client_size.Width=clientWidth;
3213 this.client_size.Height=clientHeight;
3216 [EditorBrowsable(EditorBrowsableState.Advanced)]
3217 protected void UpdateStyles() {
3218 if (!IsHandleCreated) {
3222 XplatUI.SetWindowStyle(window.Handle, CreateParams);
3225 [EditorBrowsable(EditorBrowsableState.Advanced)]
3226 protected void UpdateZOrder() {
3231 if (parent == null) {
3237 children = ctl.child_controls.Count;
3238 for (int i = 1; i < children; i++ ) {
3239 XplatUI.SetZOrder(ctl.child_controls[i].window.Handle, ctl.child_controls[i-1].window.Handle, false, false);
3242 children = child_controls.Count;
3243 for (int i = 1; i < children; i++ ) {
3244 XplatUI.SetZOrder(child_controls[i].window.Handle, child_controls[i-1].window.Handle, false, false);
3249 protected virtual void WndProc(ref Message m) {
3251 Console.WriteLine("Control received message {0}", (Msg)m.Msg);
3253 if ((this.control_style & ControlStyles.EnableNotifyMessage) != 0) {
3257 switch((Msg)m.Msg) {
3258 case Msg.WM_WINDOWPOSCHANGED: {
3261 if (GetStyle(ControlStyles.ResizeRedraw)) {
3268 case Msg.WM_PAINT: {
3269 PaintEventArgs paint_event;
3271 paint_event = XplatUI.PaintEventStart(Handle);
3273 if (!needs_redraw) {
3274 // Just blit the previous image
3275 paint_event.Graphics.DrawImage (ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle, GraphicsUnit.Pixel);
3276 XplatUI.PaintEventEnd(Handle);
3281 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
3282 dc = paint_event.SetGraphics (DeviceContext);
3285 if ((control_style & (ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint)) != (ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint)) {
3286 OnPaintBackground(paint_event);
3289 OnPaint(paint_event);
3291 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
3292 dc.DrawImage (ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle, GraphicsUnit.Pixel);
3293 paint_event.SetGraphics (dc);
3294 needs_redraw = false;
3297 XplatUI.PaintEventEnd(Handle);
3299 if (!GetStyle(ControlStyles.UserPaint)) {
3306 case Msg.WM_ERASEBKGND: {
3307 if (GetStyle (ControlStyles.UserPaint)) {
3308 if (!GetStyle(ControlStyles.AllPaintingInWmPaint)) {
3309 PaintEventArgs eraseEventArgs = new PaintEventArgs (m.WParam == IntPtr.Zero ? Graphics.FromHwnd (m.HWnd) :
3310 Graphics.FromHdc (m.WParam), new Rectangle (new Point (0,0),Size));
3311 OnPaintBackground (eraseEventArgs);
3314 XplatUI.EraseWindowBackground(m.HWnd, m.WParam);
3316 // The DefWndProc will never have to handle this, we don't ever set hbr on the window
3317 m.Result = (IntPtr)1;
3321 case Msg.WM_LBUTTONUP: {
3322 HandleClick(mouse_clicks);
3323 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Left,
3325 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3327 if (mouse_clicks > 1) {
3333 case Msg.WM_LBUTTONDOWN: {
3334 if (CanSelect && !is_selected) {
3337 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3338 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3344 case Msg.WM_LBUTTONDBLCLK: {
3346 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3347 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3353 case Msg.WM_MBUTTONUP: {
3354 HandleClick(mouse_clicks);
3355 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Middle,
3357 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3359 if (mouse_clicks > 1) {
3365 case Msg.WM_MBUTTONDOWN: {
3366 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3367 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3373 case Msg.WM_MBUTTONDBLCLK: {
3375 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3376 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3381 case Msg.WM_RBUTTONUP: {
3382 if (context_menu != null) {
3383 context_menu.Show(this, new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ())));
3386 HandleClick(mouse_clicks);
3387 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Right,
3389 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3391 if (mouse_clicks > 1) {
3397 case Msg.WM_RBUTTONDOWN: {
3398 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3399 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3404 case Msg.WM_RBUTTONDBLCLK: {
3406 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3407 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3412 case Msg.WM_MOUSEWHEEL: {
3414 OnMouseWheel (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3415 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3416 HighOrder(m.WParam.ToInt32())));
3421 case Msg.WM_MOUSEMOVE: {
3422 OnMouseMove (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3424 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3429 case Msg.WM_MOUSE_ENTER: {
3434 OnMouseEnter(EventArgs.Empty);
3438 case Msg.WM_MOUSE_LEAVE: {
3440 OnMouseLeave(EventArgs.Empty);
3444 case Msg.WM_MOUSEHOVER: {
3445 OnMouseHover(EventArgs.Empty);
3449 case Msg.WM_SYSKEYDOWN:
3450 case Msg.WM_KEYDOWN:
3451 case Msg.WM_SYSKEYUP:
3453 case Msg.WM_SYSCHAR:
3455 if (ProcessKeyEventArgs(ref m)) {
3459 if (PreProcessMessage(ref m)) {
3463 if (ProcessKeyMessage(ref m)) {
3472 if (m.LParam != IntPtr.Zero) {
3475 hi = new HELPINFO();
3477 hi = (HELPINFO) Marshal.PtrToStructure (m.LParam, typeof (HELPINFO));
3478 mouse_pos = new Point(hi.MousePos.x, hi.MousePos.y);
3480 mouse_pos = Control.MousePosition;
3482 OnHelpRequested(new HelpEventArgs(mouse_pos));
3483 m.Result = (IntPtr)1;
3487 case Msg.WM_KILLFOCUS: {
3488 OnLeave(EventArgs.Empty);
3489 if (CausesValidation) {
3491 e = new CancelEventArgs(false);
3500 OnValidated(EventArgs.Empty);
3503 this.has_focus = false;
3504 this.is_selected = false;
3505 OnLostFocus(EventArgs.Empty);
3509 case Msg.WM_SETFOCUS: {
3510 OnEnter(EventArgs.Empty);
3511 this.has_focus = true;
3512 OnGotFocus(EventArgs.Empty);
3517 case Msg.WM_SYSCOLORCHANGE: {
3518 ThemeEngine.Current.ResetDefaults();
3519 OnSystemColorsChanged(EventArgs.Empty);
3524 case Msg.WM_SETCURSOR: {
3525 if (cursor == null) {
3530 XplatUI.SetCursor(window.Handle, cursor.handle);
3531 m.Result = (IntPtr)1;
3541 #endregion // Public Instance Methods
3543 #region OnXXX methods
3544 [EditorBrowsable(EditorBrowsableState.Advanced)]
3545 protected virtual void OnBackColorChanged(EventArgs e) {
3546 if (BackColorChanged!=null) BackColorChanged(this, e);
3547 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackColorChanged(e);
3550 [EditorBrowsable(EditorBrowsableState.Advanced)]
3551 protected virtual void OnBackgroundImageChanged(EventArgs e) {
3552 if (BackgroundImageChanged!=null) BackgroundImageChanged(this, e);
3553 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackgroundImageChanged(e);
3556 [EditorBrowsable(EditorBrowsableState.Advanced)]
3557 protected virtual void OnBindingContextChanged(EventArgs e) {
3558 CheckDataBindings ();
3559 if (BindingContextChanged!=null) {
3560 BindingContextChanged(this, e);
3562 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBindingContextChanged(e);
3565 [EditorBrowsable(EditorBrowsableState.Advanced)]
3566 protected virtual void OnCausesValidationChanged(EventArgs e) {
3567 if (CausesValidationChanged!=null) CausesValidationChanged(this, e);
3570 [EditorBrowsable(EditorBrowsableState.Advanced)]
3571 protected virtual void OnChangeUICues(UICuesEventArgs e) {
3572 if (ChangeUICues!=null) ChangeUICues(this, e);
3575 [EditorBrowsable(EditorBrowsableState.Advanced)]
3576 protected virtual void OnClick(EventArgs e) {
3577 if (Click!=null) Click(this, e);
3580 [EditorBrowsable(EditorBrowsableState.Advanced)]
3581 protected virtual void OnContextMenuChanged(EventArgs e) {
3582 if (ContextMenuChanged!=null) ContextMenuChanged(this, e);
3585 [EditorBrowsable(EditorBrowsableState.Advanced)]
3586 protected virtual void OnControlAdded(ControlEventArgs e) {
3587 if (ControlAdded!=null) ControlAdded(this, e);
3590 [EditorBrowsable(EditorBrowsableState.Advanced)]
3591 protected virtual void OnControlRemoved(ControlEventArgs e) {
3592 if (ControlRemoved!=null) ControlRemoved(this, e);
3595 [EditorBrowsable(EditorBrowsableState.Advanced)]
3596 protected virtual void OnCreateControl() {
3600 [EditorBrowsable(EditorBrowsableState.Advanced)]
3601 protected virtual void OnCursorChanged(EventArgs e) {
3602 if (CursorChanged!=null) CursorChanged(this, e);
3605 [EditorBrowsable(EditorBrowsableState.Advanced)]
3606 protected virtual void OnDockChanged(EventArgs e) {
3607 if (DockChanged!=null) DockChanged(this, e);
3610 [EditorBrowsable(EditorBrowsableState.Advanced)]
3611 protected virtual void OnDoubleClick(EventArgs e) {
3612 if (DoubleClick!=null) DoubleClick(this, e);
3615 [EditorBrowsable(EditorBrowsableState.Advanced)]
3616 protected virtual void OnDragDrop(DragEventArgs drgevent) {
3617 if (DragDrop!=null) DragDrop(this, drgevent);
3620 [EditorBrowsable(EditorBrowsableState.Advanced)]
3621 protected virtual void OnDragEnter(DragEventArgs drgevent) {
3622 if (DragEnter!=null) DragEnter(this, drgevent);
3625 [EditorBrowsable(EditorBrowsableState.Advanced)]
3626 protected virtual void OnDragLeave(EventArgs e) {
3627 if (DragLeave!=null) DragLeave(this, e);
3630 [EditorBrowsable(EditorBrowsableState.Advanced)]
3631 protected virtual void OnDragOver(DragEventArgs drgevent) {
3632 if (DragOver!=null) DragOver(this, drgevent);
3635 [EditorBrowsable(EditorBrowsableState.Advanced)]
3636 protected virtual void OnEnabledChanged(EventArgs e) {
3637 if (EnabledChanged!=null) EnabledChanged(this, e);
3638 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentEnabledChanged(e);
3641 [EditorBrowsable(EditorBrowsableState.Advanced)]
3642 protected virtual void OnEnter(EventArgs e) {
3643 if (Enter!=null) Enter(this, e);
3646 [EditorBrowsable(EditorBrowsableState.Advanced)]
3647 protected virtual void OnFontChanged(EventArgs e) {
3648 if (FontChanged!=null) FontChanged(this, e);
3649 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentFontChanged(e);
3652 [EditorBrowsable(EditorBrowsableState.Advanced)]
3653 protected virtual void OnForeColorChanged(EventArgs e) {
3654 if (ForeColorChanged!=null) ForeColorChanged(this, e);
3655 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentForeColorChanged(e);
3658 [EditorBrowsable(EditorBrowsableState.Advanced)]
3659 protected virtual void OnGiveFeedback(GiveFeedbackEventArgs gfbevent) {
3660 if (GiveFeedback!=null) GiveFeedback(this, gfbevent);
3663 [EditorBrowsable(EditorBrowsableState.Advanced)]
3664 protected virtual void OnGotFocus(EventArgs e) {
3665 if (GotFocus!=null) GotFocus(this, e);
3668 [EditorBrowsable(EditorBrowsableState.Advanced)]
3669 protected virtual void OnHandleCreated(EventArgs e) {
3670 if (HandleCreated!=null) HandleCreated(this, e);
3673 [EditorBrowsable(EditorBrowsableState.Advanced)]
3674 protected virtual void OnHandleDestroyed(EventArgs e) {
3675 if (HandleDestroyed!=null) HandleDestroyed(this, e);
3678 [EditorBrowsable(EditorBrowsableState.Advanced)]
3679 protected virtual void OnHelpRequested(HelpEventArgs hevent) {
3680 if (HelpRequested!=null) HelpRequested(this, hevent);
3683 protected virtual void OnImeModeChanged(EventArgs e) {
3684 if (ImeModeChanged!=null) ImeModeChanged(this, e);
3687 [EditorBrowsable(EditorBrowsableState.Advanced)]
3688 protected virtual void OnInvalidated(InvalidateEventArgs e) {
3689 needs_redraw = true;
3690 if (Invalidated!=null) Invalidated(this, e);
3693 [EditorBrowsable(EditorBrowsableState.Advanced)]
3694 protected virtual void OnKeyDown(KeyEventArgs e) {
3695 if (KeyDown!=null) KeyDown(this, e);
3698 [EditorBrowsable(EditorBrowsableState.Advanced)]
3699 protected virtual void OnKeyPress(KeyPressEventArgs e) {
3700 if (KeyPress!=null) KeyPress(this, e);
3703 [EditorBrowsable(EditorBrowsableState.Advanced)]
3704 protected virtual void OnKeyUp(KeyEventArgs e) {
3705 if (KeyUp!=null) KeyUp(this, e);
3708 [EditorBrowsable(EditorBrowsableState.Advanced)]
3709 protected virtual void OnLayout(LayoutEventArgs levent) {
3710 if (Layout!=null) Layout(this, levent);
3713 [EditorBrowsable(EditorBrowsableState.Advanced)]
3714 protected virtual void OnLeave(EventArgs e) {
3715 if (Leave!=null) Leave(this, e);
3718 [EditorBrowsable(EditorBrowsableState.Advanced)]
3719 protected virtual void OnLocationChanged(EventArgs e) {
3721 if (LocationChanged!=null) LocationChanged(this, e);
3724 [EditorBrowsable(EditorBrowsableState.Advanced)]
3725 protected virtual void OnLostFocus(EventArgs e) {
3726 if (LostFocus!=null) LostFocus(this, e);
3729 [EditorBrowsable(EditorBrowsableState.Advanced)]
3730 protected virtual void OnMouseDown(MouseEventArgs e) {
3731 if (MouseDown!=null) MouseDown(this, e);
3734 [EditorBrowsable(EditorBrowsableState.Advanced)]
3735 protected virtual void OnMouseEnter(EventArgs e) {
3736 if (MouseEnter!=null) MouseEnter(this, e);
3739 [EditorBrowsable(EditorBrowsableState.Advanced)]
3740 protected virtual void OnMouseHover(EventArgs e) {
3741 if (MouseHover!=null) MouseHover(this, e);
3744 [EditorBrowsable(EditorBrowsableState.Advanced)]
3745 protected virtual void OnMouseLeave(EventArgs e) {
3746 if (MouseLeave!=null) MouseLeave(this, e);
3749 [EditorBrowsable(EditorBrowsableState.Advanced)]
3750 protected virtual void OnMouseMove(MouseEventArgs e) {
3751 if (MouseMove!=null) MouseMove(this, e);
3754 [EditorBrowsable(EditorBrowsableState.Advanced)]
3755 protected virtual void OnMouseUp(MouseEventArgs e) {
3756 if (MouseUp!=null) MouseUp(this, e);
3759 [EditorBrowsable(EditorBrowsableState.Advanced)]
3760 protected virtual void OnMouseWheel(MouseEventArgs e) {
3761 if (MouseWheel!=null) MouseWheel(this, e);
3764 [EditorBrowsable(EditorBrowsableState.Advanced)]
3765 protected virtual void OnMove(EventArgs e) {
3766 if (Move!=null) Move(this, e);
3769 [EditorBrowsable(EditorBrowsableState.Advanced)]
3770 protected virtual void OnNotifyMessage(Message m) {
3774 [EditorBrowsable(EditorBrowsableState.Advanced)]
3775 protected virtual void OnPaint(PaintEventArgs e) {
3776 if (Paint!=null) Paint(this, e);
3779 [EditorBrowsable(EditorBrowsableState.Advanced)]
3780 protected virtual void OnPaintBackground(PaintEventArgs pevent) {
3781 PaintControlBackground (pevent);
3784 [EditorBrowsable(EditorBrowsableState.Advanced)]
3785 protected virtual void OnParentBackColorChanged(EventArgs e) {
3786 if (background_color.IsEmpty && background_image==null) {
3788 OnBackColorChanged(e);
3792 [EditorBrowsable(EditorBrowsableState.Advanced)]
3793 protected virtual void OnParentBackgroundImageChanged(EventArgs e) {
3794 if (background_color.IsEmpty && background_image==null) {
3796 OnBackgroundImageChanged(e);
3800 [EditorBrowsable(EditorBrowsableState.Advanced)]
3801 protected virtual void OnParentBindingContextChanged(EventArgs e) {
3802 if (binding_context==null) {
3803 binding_context=Parent.binding_context;
3804 OnBindingContextChanged(e);
3808 [EditorBrowsable(EditorBrowsableState.Advanced)]
3809 protected virtual void OnParentChanged(EventArgs e) {
3810 if (ParentChanged!=null) ParentChanged(this, e);
3813 [EditorBrowsable(EditorBrowsableState.Advanced)]
3814 protected virtual void OnParentEnabledChanged(EventArgs e) {
3815 if (is_enabled != Parent.is_enabled) {
3816 is_enabled=Parent.is_enabled;
3818 if (EnabledChanged != null) {
3819 EnabledChanged(this, e);
3824 [EditorBrowsable(EditorBrowsableState.Advanced)]
3825 protected virtual void OnParentFontChanged(EventArgs e) {
3832 [EditorBrowsable(EditorBrowsableState.Advanced)]
3833 protected virtual void OnParentForeColorChanged(EventArgs e) {
3834 if (foreground_color.IsEmpty) {
3836 OnForeColorChanged(e);
3840 [EditorBrowsable(EditorBrowsableState.Advanced)]
3841 protected virtual void OnParentRightToLeftChanged(EventArgs e) {
3842 if (right_to_left==RightToLeft.Inherit) {
3844 OnRightToLeftChanged(e);
3848 [EditorBrowsable(EditorBrowsableState.Advanced)]
3849 protected virtual void OnParentVisibleChanged(EventArgs e) {
3851 OnVisibleChanged(e);
3855 [EditorBrowsable(EditorBrowsableState.Advanced)]
3856 protected virtual void OnQueryContinueDrag(QueryContinueDragEventArgs e) {
3857 if (QueryContinueDrag!=null) QueryContinueDrag(this, e);
3860 [EditorBrowsable(EditorBrowsableState.Advanced)]
3861 protected virtual void OnResize(EventArgs e) {
3862 if (Resize!=null) Resize(this, e);
3864 PerformLayout(this, "bounds");
3866 if (parent != null) {
3867 parent.PerformLayout();
3871 [EditorBrowsable(EditorBrowsableState.Advanced)]
3872 protected virtual void OnRightToLeftChanged(EventArgs e) {
3873 if (RightToLeftChanged!=null) RightToLeftChanged(this, e);
3874 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentRightToLeftChanged(e);
3877 [EditorBrowsable(EditorBrowsableState.Advanced)]
3878 protected virtual void OnSizeChanged(EventArgs e) {
3879 InvalidateBuffers ();
3881 if (SizeChanged!=null) SizeChanged(this, e);
3884 [EditorBrowsable(EditorBrowsableState.Advanced)]
3885 protected virtual void OnStyleChanged(EventArgs e) {
3886 if (StyleChanged!=null) StyleChanged(this, e);
3889 [EditorBrowsable(EditorBrowsableState.Advanced)]
3890 protected virtual void OnSystemColorsChanged(EventArgs e) {
3891 if (SystemColorsChanged!=null) SystemColorsChanged(this, e);
3894 [EditorBrowsable(EditorBrowsableState.Advanced)]
3895 protected virtual void OnTabIndexChanged(EventArgs e) {
3896 if (TabIndexChanged!=null) TabIndexChanged(this, e);
3899 [EditorBrowsable(EditorBrowsableState.Advanced)]
3900 protected virtual void OnTabStopChanged(EventArgs e) {
3901 if (TabStopChanged!=null) TabStopChanged(this, e);
3904 [EditorBrowsable(EditorBrowsableState.Advanced)]
3905 protected virtual void OnTextChanged(EventArgs e) {
3906 if (TextChanged!=null) TextChanged(this, e);
3909 [EditorBrowsable(EditorBrowsableState.Advanced)]
3910 protected virtual void OnValidated(EventArgs e) {
3911 if (Validated!=null) Validated(this, e);
3914 [EditorBrowsable(EditorBrowsableState.Advanced)]
3915 protected virtual void OnValidating(System.ComponentModel.CancelEventArgs e) {
3916 if (Validating!=null) Validating(this, e);
3919 [EditorBrowsable(EditorBrowsableState.Advanced)]
3920 protected virtual void OnVisibleChanged(EventArgs e) {
3927 if (bmp_mem!=null) {
3933 if (!this.IsHandleCreated) {
3934 this.CreateControl();
3940 if (VisibleChanged!=null) VisibleChanged(this, e);
3942 // We need to tell our kids
3943 for (int i=0; i<child_controls.Count; i++) {
3944 child_controls[i].OnParentVisibleChanged(e);
3947 #endregion // OnXXX methods
3950 public event EventHandler BackColorChanged;
3951 public event EventHandler BackgroundImageChanged;
3952 public event EventHandler BindingContextChanged;
3953 public event EventHandler CausesValidationChanged;
3954 public event UICuesEventHandler ChangeUICues;
3955 public event EventHandler Click;
3956 public event EventHandler ContextMenuChanged;
3958 [EditorBrowsable(EditorBrowsableState.Advanced)]
3960 public event ControlEventHandler ControlAdded;
3962 [EditorBrowsable(EditorBrowsableState.Advanced)]
3964 public event ControlEventHandler ControlRemoved;
3966 public event EventHandler CursorChanged;
3967 public event EventHandler DockChanged;
3968 public event EventHandler DoubleClick;
3969 public event DragEventHandler DragDrop;
3970 public event DragEventHandler DragEnter;
3971 public event EventHandler DragLeave;
3972 public event DragEventHandler DragOver;
3973 public event EventHandler EnabledChanged;
3974 public event EventHandler Enter;
3975 public event EventHandler FontChanged;
3976 public event EventHandler ForeColorChanged;
3977 public event GiveFeedbackEventHandler GiveFeedback;
3979 [EditorBrowsable(EditorBrowsableState.Advanced)]
3981 public event EventHandler GotFocus;
3983 [EditorBrowsable(EditorBrowsableState.Advanced)]
3985 public event EventHandler HandleCreated;
3987 [EditorBrowsable(EditorBrowsableState.Advanced)]
3989 public event EventHandler HandleDestroyed;
3991 public event HelpEventHandler HelpRequested;
3992 public event EventHandler ImeModeChanged;
3994 [EditorBrowsable(EditorBrowsableState.Advanced)]
3996 public event InvalidateEventHandler Invalidated;
3998 public event KeyEventHandler KeyDown;
3999 public event KeyPressEventHandler KeyPress;
4000 public event KeyEventHandler KeyUp;
4001 public event LayoutEventHandler Layout;
4002 public event EventHandler Leave;
4003 public event EventHandler LocationChanged;
4005 [EditorBrowsable(EditorBrowsableState.Advanced)]
4007 public event EventHandler LostFocus;
4009 public event MouseEventHandler MouseDown;
4010 public event EventHandler MouseEnter;
4011 public event EventHandler MouseHover;
4012 public event EventHandler MouseLeave;
4013 public event MouseEventHandler MouseMove;
4014 public event MouseEventHandler MouseUp;
4016 [EditorBrowsable(EditorBrowsableState.Advanced)]
4018 public event MouseEventHandler MouseWheel;
4020 public event EventHandler Move;
4021 public event PaintEventHandler Paint;
4022 public event EventHandler ParentChanged;
4023 public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp;
4024 public event QueryContinueDragEventHandler QueryContinueDrag;
4025 public event EventHandler Resize;
4026 public event EventHandler RightToLeftChanged;
4027 public event EventHandler SizeChanged;
4028 public event EventHandler StyleChanged;
4029 public event EventHandler SystemColorsChanged;
4030 public event EventHandler TabIndexChanged;
4031 public event EventHandler TabStopChanged;
4032 public event EventHandler TextChanged;
4033 public event EventHandler Validated;
4034 public event CancelEventHandler Validating;
4035 public event EventHandler VisibleChanged;
4036 #endregion // Events