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();
1918 create_params.Caption = Text;
1919 create_params.X = Left;
1920 create_params.Y = Top;
1921 create_params.Width = Width;
1922 create_params.Height = Height;
1924 create_params.ClassName = XplatUI.DefaultClassName;
1925 create_params.ClassStyle = 0;
1926 create_params.ExStyle = 0;
1927 create_params.Param = 0;
1930 create_params.ExStyle |= (int)WindowStyles.WS_EX_ACCEPTFILES;
1934 create_params.Parent = parent.Handle;
1937 create_params.Style = (int)WindowStyles.WS_CHILD | (int)WindowStyles.WS_CLIPCHILDREN | (int)WindowStyles.WS_CLIPSIBLINGS;
1940 create_params.Style |= (int)WindowStyles.WS_VISIBLE;
1943 return create_params;
1947 protected virtual ImeMode DefaultImeMode {
1949 return ImeMode.Inherit;
1953 protected virtual Size DefaultSize {
1955 return new Size(100, 23);
1959 protected int FontHeight {
1969 protected bool RenderRightToLeft {
1971 return (this.right_to_left == RightToLeft.Yes);
1975 protected bool ResizeRedraw {
1977 return GetStyle(ControlStyles.ResizeRedraw);
1981 SetStyle(ControlStyles.ResizeRedraw, value);
1985 [EditorBrowsable(EditorBrowsableState.Advanced)]
1987 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1988 protected virtual bool ShowFocusCues {
1994 [EditorBrowsable(EditorBrowsableState.Advanced)]
1996 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1997 protected bool ShowKeyboardCues {
2002 #endregion // Protected Instance Properties
2004 #region Public Static Methods
2005 [EditorBrowsable(EditorBrowsableState.Advanced)]
2006 public static Control FromChildHandle(IntPtr handle) {
2007 IEnumerator control = Control.controls.GetEnumerator();
2009 while (control.MoveNext()) {
2010 if (((Control)control.Current).window.Handle == handle) {
2012 if (((Control)control.Current).Parent != null) {
2013 return ((Control)control.Current).Parent;
2020 [EditorBrowsable(EditorBrowsableState.Advanced)]
2021 public static Control FromHandle(IntPtr handle) {
2022 IEnumerator control = Control.controls.GetEnumerator();
2024 while (control.MoveNext()) {
2025 if (((Control)control.Current).window.Handle == handle) {
2027 return ((Control)control.Current);
2033 public static bool IsMnemonic(char charCode, string text) {
2036 amp = text.IndexOf('&');
2039 if (amp + 1 < text.Length) {
2040 if (text[amp + 1] != '&') {
2041 if (Char.ToUpper(charCode) == Char.ToUpper(text.ToCharArray(amp + 1, 1)[0])) {
2051 #region Protected Static Methods
2052 [EditorBrowsable(EditorBrowsableState.Advanced)]
2053 protected static bool ReflectMessage(IntPtr hWnd, ref Message m) {
2056 c = Control.FromHandle(hWnd);
2066 #region Public Instance Methods
2067 [EditorBrowsable(EditorBrowsableState.Advanced)]
2068 public IAsyncResult BeginInvoke(Delegate method) {
2069 return BeginInvokeInternal(method, null);
2072 [EditorBrowsable(EditorBrowsableState.Advanced)]
2073 public IAsyncResult BeginInvoke (Delegate method, object[] args) {
2074 return BeginInvokeInternal (method, args);
2077 public void BringToFront() {
2078 if ((parent != null) && (parent.child_controls[0]!=this)) {
2079 if (parent.child_controls.Contains(this)) {
2080 parent.child_controls.SetChildIndex(this, 0);
2084 XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, true, false);
2086 if (parent != null) {
2091 public bool Contains(Control ctl) {
2092 while (ctl != null) {
2101 public void CreateControl() {
2103 if (!IsHandleCreated) {
2107 if (!create_handled) {
2108 create_handled = true;
2112 for (int i=0; i<child_controls.Count; i++) {
2113 child_controls[i].CreateControl();
2117 public Graphics CreateGraphics() {
2118 if (!IsHandleCreated) {
2119 this.CreateControl();
2121 return Graphics.FromHwnd(this.window.Handle);
2124 public DragDropEffects DoDragDrop(object data, DragDropEffects allowedEffects) {
2125 return XplatUI.StartDrag(this.window.Handle, data, allowedEffects);
2128 [EditorBrowsable(EditorBrowsableState.Advanced)]
2129 public object EndInvoke (IAsyncResult async_result) {
2130 AsyncMethodResult result = (AsyncMethodResult) async_result;
2131 return result.EndInvoke ();
2134 public Form FindForm() {
2147 public bool Focus() {
2148 if (IsHandleCreated && !has_focus) {
2150 XplatUI.SetFocus(window.Handle);
2155 public Control GetChildAtPoint(Point pt) {
2156 // Microsoft's version of this function doesn't seem to work, so I can't check
2157 // if we only consider children or also grandchildren, etc.
2158 // I'm gonna say 'children only'
2159 for (int i=0; i<child_controls.Count; i++) {
2160 if (child_controls[i].Bounds.Contains(pt)) {
2161 return child_controls[i];
2167 public IContainerControl GetContainerControl() {
2168 Control current = this;
2170 while (current!=null) {
2171 if ((current is IContainerControl) && ((current.control_style & ControlStyles.ContainerControl)!=0)) {
2172 return (IContainerControl)current;
2174 current = current.parent;
2179 public Control GetNextControl(Control ctl, bool forward) {
2180 // If we're not a container we don't play
2181 if (!(this is IContainerControl) && !this.GetStyle(ControlStyles.ContainerControl)) {
2185 // If ctl is not contained by this, we start at the first child of this
2186 if (!this.Contains(ctl)) {
2190 // Search through our controls, starting at ctl, stepping into children as we encounter them
2191 // try to find the control with the tabindex closest to our own, or, if we're looking into
2192 // child controls, the one with the smallest tabindex
2194 return FindControlForward(this, ctl);
2196 return FindControlBackward(this, ctl);
2199 public void Hide() {
2200 this.Visible = false;
2203 public void Invalidate() {
2204 Invalidate(ClientRectangle, false);
2207 public void Invalidate(bool invalidateChildren) {
2208 Invalidate(ClientRectangle, invalidateChildren);
2211 public void Invalidate(System.Drawing.Rectangle rc) {
2212 Invalidate(rc, false);
2215 public void Invalidate(System.Drawing.Rectangle rc, bool invalidateChildren) {
2216 if (!IsHandleCreated || !Visible) {
2220 NotifyInvalidate(rc);
2222 XplatUI.Invalidate(Handle, rc, false);
2224 if (invalidateChildren) {
2225 for (int i=0; i<child_controls.Count; i++) child_controls[i].Invalidate();
2227 OnInvalidated(new InvalidateEventArgs(rc));
2230 public void Invalidate(System.Drawing.Region region) {
2231 Invalidate(region, false);
2234 [MonoTODO("Figure out if GetRegionScans is usable")]
2235 public void Invalidate(System.Drawing.Region region, bool invalidateChildren) {
2236 throw new NotImplementedException();
2238 // FIXME - should use the GetRegionScans function of the region to invalidate each area
2239 //if (invalidateChildren) {
2240 // for (int i=0; i<child_controls.Count; i++) child_controls[i].Invalidate();
2244 public object Invoke (Delegate method) {
2245 return Invoke(method, null);
2248 public object Invoke (Delegate method, object[] args) {
2249 if (!this.InvokeRequired) {
2250 return method.DynamicInvoke(args);
2253 IAsyncResult result = BeginInvoke (method, args);
2254 return EndInvoke(result);
2257 [EditorBrowsable(EditorBrowsableState.Advanced)]
2258 public void PerformLayout() {
2259 PerformLayout(null, null);
2262 [EditorBrowsable(EditorBrowsableState.Advanced)]
2263 public void PerformLayout(Control affectedControl, string affectedProperty) {
2264 LayoutEventArgs levent = new LayoutEventArgs(affectedControl, affectedProperty);
2266 if (layout_suspended>0) {
2267 layout_pending = true;
2271 layout_pending = false;
2273 // Prevent us from getting messed up
2276 // Perform all Dock and Anchor calculations
2279 AnchorStyles anchor;
2284 space=this.DisplayRectangle;
2285 if (prev_size != Size.Empty) {
2286 diff_width = space.Width - prev_size.Width;
2287 diff_height = space.Height - prev_size.Height;
2293 // Deal with docking; go through in reverse, MS docs say that lowest Z-order is closest to edge
2294 for (int i = child_controls.Count - 1; i >= 0; i--) {
2295 child=child_controls[i];
2296 switch (child.Dock) {
2297 case DockStyle.None: {
2302 case DockStyle.Left: {
2303 child.SetBounds(space.Left, space.Y, child.Width, space.Height);
2304 space.X+=child.Width;
2305 space.Width-=child.Width;
2309 case DockStyle.Top: {
2310 child.SetBounds(space.Left, space.Y, space.Width, child.Height);
2311 space.Y+=child.Height;
2312 space.Height-=child.Height;
2316 case DockStyle.Right: {
2317 child.SetBounds(space.Right-child.Width, space.Y, child.Width, space.Height);
2318 space.Width-=child.Width;
2322 case DockStyle.Bottom: {
2323 child.SetBounds(space.Left, space.Bottom-child.Height, space.Width, child.Height);
2324 space.Height-=child.Height;
2330 for (int i = child_controls.Count - 1; i >= 0; i--) {
2331 child=child_controls[i];
2333 if (child.Dock == DockStyle.Fill) {
2334 child.SetBounds(space.Left, space.Top, space.Width, space.Height);
2340 space=this.DisplayRectangle;
2342 // Deal with anchoring
2343 for (int i=0; i < child_controls.Count; i++) {
2349 child=child_controls[i];
2350 anchor=child.Anchor;
2355 height=child.Height;
2357 // If the control is docked we don't need to do anything
2358 if (child.Dock != DockStyle.None) {
2362 if ((anchor & AnchorStyles.Left) !=0 ) {
2363 if ((anchor & AnchorStyles.Right) != 0) {
2364 // Anchoring to left and right
2365 width=width+diff_width;
2369 } else if ((anchor & AnchorStyles.Right) != 0) {
2375 if ((anchor & AnchorStyles.Top) !=0 ) {
2376 if ((anchor & AnchorStyles.Bottom) != 0) {
2377 height+=diff_height;
2381 } else if ((anchor & AnchorStyles.Bottom) != 0) {
2396 child.SetBounds(left, top, width, height);
2399 // Let everyone know
2403 // Need to make sure we decremend layout_suspended
2409 public Point PointToClient (Point p) {
2413 XplatUI.ScreenToClient (Handle, ref x, ref y);
2415 return new Point (x, y);
2418 public Point PointToScreen(Point p) {
2422 XplatUI.ClientToScreen(Handle, ref x, ref y);
2424 return new Point(x, y);
2427 public virtual bool PreProcessMessage(ref Message msg) {
2430 if ((msg.Msg == (int)Msg.WM_KEYDOWN) || (msg.Msg == (int)Msg.WM_SYSKEYDOWN)) {
2431 key_data = (Keys)msg.WParam.ToInt32();
2432 if (!ProcessCmdKey(ref msg, key_data)) {
2433 if (IsInputKey(key_data)) {
2437 return ProcessDialogKey(key_data);
2441 } else if (msg.Msg == (int)Msg.WM_CHAR) {
2442 if (IsInputChar((char)msg.WParam)) {
2445 } else if (msg.Msg == (int)Msg.WM_SYSCHAR) {
2446 if (IsInputChar((char)msg.WParam)) {
2449 return ProcessDialogChar((char)msg.WParam);
2454 public Rectangle RectangleToClient(Rectangle r) {
2455 return new Rectangle(PointToClient(r.Location), r.Size);
2458 public Rectangle RectangleToScreen(Rectangle r) {
2459 return new Rectangle(PointToScreen(r.Location), r.Size);
2462 public virtual void Refresh() {
2463 if (IsHandleCreated == true) {
2465 XplatUI.UpdateWindow(window.Handle);
2469 [EditorBrowsable(EditorBrowsableState.Never)]
2470 public virtual void ResetBackColor() {
2471 background_color = Color.Empty;
2474 #if haveDataBindings
2475 [EditorBrowsable(EditorBrowsableState.Never)]
2477 public void ResetBindings() {
2482 [EditorBrowsable(EditorBrowsableState.Never)]
2483 public virtual void ResetCursor() {
2487 [EditorBrowsable(EditorBrowsableState.Never)]
2488 public virtual void ResetFont() {
2492 [EditorBrowsable(EditorBrowsableState.Never)]
2493 public virtual void ResetForeColor() {
2494 foreground_color = Color.Empty;
2497 [EditorBrowsable(EditorBrowsableState.Never)]
2498 public void ResetImeMode() {
2499 ime_mode = DefaultImeMode;
2502 [EditorBrowsable(EditorBrowsableState.Never)]
2503 public virtual void ResetRightToLeft() {
2504 right_to_left = RightToLeft.Inherit;
2507 public virtual void ResetText() {
2511 public void ResumeLayout() {
2512 ResumeLayout (true);
2515 public void ResumeLayout(bool performLayout) {
2518 if (layout_suspended > 0) {
2522 if (performLayout || layout_pending) {
2527 public void Scale(float ratio) {
2528 ScaleCore(ratio, ratio);
2531 public void Scale(float dx, float dy) {
2535 public void Select() {
2536 Select(false, false);
2539 public bool SelectNextControl(Control ctl, bool forward, bool tabStopOnly, bool nested, bool wrap) {
2544 c = GetNextControl(c, forward);
2553 if (c.CanSelect && ((c.parent == ctl.parent) || nested) && (c.tab_stop || !tabStopOnly)) {
2557 } while (c != ctl); // If we wrap back to ourselves we stop
2562 public void SendToBack() {
2563 if ((parent != null) && (parent.child_controls[parent.child_controls.Count-1]!=this)) {
2564 if (parent.child_controls.Contains(this)) {
2565 parent.child_controls.SetChildIndex(this, parent.child_controls.Count);
2569 XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, false, true);
2570 if (parent != null) {
2575 public void SetBounds(int x, int y, int width, int height) {
2576 SetBoundsCore(x, y, width, height, BoundsSpecified.All);
2579 public void SetBounds(int x, int y, int width, int height, BoundsSpecified specified) {
2580 SetBoundsCore(x, y, width, height, specified);
2583 public void Show() {
2584 if (!IsHandleCreated) {
2585 this.CreateControl();
2591 public void SuspendLayout() {
2595 public void Update() {
2596 needs_redraw = true;
2597 XplatUI.UpdateWindow(window.Handle);
2599 #endregion // Public Instance Methods
2601 #region Protected Instance Methods
2602 [EditorBrowsable(EditorBrowsableState.Advanced)]
2603 [MonoTODO("Implement this and tie it into Control.ControlAccessibleObject.NotifyClients")]
2604 protected void AccessibilityNotifyClients(AccessibleEvents accEvent, int childID) {
2605 throw new NotImplementedException();
2608 [EditorBrowsable(EditorBrowsableState.Advanced)]
2609 protected virtual AccessibleObject CreateAccessibilityInstance() {
2610 return new Control.ControlAccessibleObject(this);
2613 [EditorBrowsable(EditorBrowsableState.Advanced)]
2614 protected virtual ControlCollection CreateControlsInstance() {
2615 return new ControlCollection(this);
2618 [EditorBrowsable(EditorBrowsableState.Advanced)]
2619 protected virtual void CreateHandle() {
2621 throw new ObjectDisposedException(Name);
2624 if (IsHandleCreated) {
2628 window.CreateHandle(CreateParams);
2630 // Find out where the window manager placed us
2634 if (window.Handle!=IntPtr.Zero) {
2635 if (!controls.Contains(window.Handle)) {
2639 creator_thread = Thread.CurrentThread;
2641 XplatUI.SetWindowBackground(window.Handle, this.BackColor);
2643 OnHandleCreated(EventArgs.Empty);
2647 [EditorBrowsable(EditorBrowsableState.Advanced)]
2648 protected virtual void DefWndProc(ref Message m) {
2649 window.DefWndProc(ref m);
2652 [EditorBrowsable(EditorBrowsableState.Advanced)]
2653 protected virtual void DestroyHandle() {
2654 if (IsHandleCreated) {
2655 // Destroy our children before we destroy ourselves, to prevent them from
2656 // being implictly (without us knowing) destroyed
2657 for (int i=0; i < child_controls.Count; i++) {
2658 child_controls[i].DestroyHandle();
2662 if (window != null) {
2663 window.DestroyHandle();
2665 OnHandleDestroyed(EventArgs.Empty);
2669 protected bool GetStyle(ControlStyles flag) {
2670 return (control_style & flag) != 0;
2673 protected bool GetTopLevel() {
2677 [EditorBrowsable(EditorBrowsableState.Advanced)]
2678 protected virtual void InitLayout() {
2679 if (parent != null) {
2680 parent.PerformLayout(this, "parent");
2684 [EditorBrowsable(EditorBrowsableState.Advanced)]
2685 protected void InvokeGotFocus(Control toInvoke, EventArgs e) {
2686 toInvoke.OnGotFocus(e);
2689 [EditorBrowsable(EditorBrowsableState.Advanced)]
2690 protected void InvokeLostFocus(Control toInvoke, EventArgs e) {
2691 toInvoke.OnLostFocus(e);
2694 [EditorBrowsable(EditorBrowsableState.Advanced)]
2695 protected void InvokeOnClick(Control toInvoke, EventArgs e) {
2696 toInvoke.OnClick(e);
2699 protected void InvokePaint(Control toInvoke, PaintEventArgs e) {
2700 toInvoke.OnPaint(e);
2703 protected void InvokePaintBackground(Control toInvoke, PaintEventArgs e) {
2704 toInvoke.OnPaintBackground(e);
2707 protected virtual bool IsInputChar (char charCode) {
2708 if (parent != null) {
2709 return parent.IsInputChar(charCode);
2715 protected virtual bool IsInputKey (Keys keyData) {
2716 // Doc says this one calls IsInputChar; not sure what to do with that
2720 [EditorBrowsable(EditorBrowsableState.Advanced)]
2721 protected virtual void NotifyInvalidate(Rectangle invalidatedArea) {
2725 protected virtual bool ProcessCmdKey(ref Message msg, Keys keyData) {
2726 if ((context_menu != null) && context_menu.ProcessCmdKey(ref msg, keyData)) {
2730 if (parent != null) {
2731 return parent.ProcessCmdKey(ref msg, keyData);
2737 protected virtual bool ProcessDialogChar(char charCode) {
2738 if (parent != null) {
2739 return parent.ProcessDialogChar (charCode);
2745 protected virtual bool ProcessDialogKey (Keys keyData) {
2746 if (parent != null) {
2747 return parent.ProcessDialogKey (keyData);
2753 protected virtual bool ProcessKeyEventArgs (ref Message msg)
2755 KeyEventArgs key_event;
2758 case (int)Msg.WM_KEYDOWN: {
2759 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
2760 OnKeyDown (key_event);
2761 return key_event.Handled;
2763 case (int)Msg.WM_KEYUP: {
2764 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
2765 OnKeyUp (key_event);
2766 return key_event.Handled;
2769 case (int)Msg.WM_CHAR: {
2770 KeyPressEventArgs key_press_event;
2772 key_press_event = new KeyPressEventArgs((char)msg.WParam);
2773 OnKeyPress(key_press_event);
2774 return key_press_event.Handled;
2785 protected internal virtual bool ProcessKeyMessage(ref Message msg) {
2786 if (parent != null) {
2787 if (parent.ProcessKeyPreview(ref msg)) {
2795 protected virtual bool ProcessKeyPreview(ref Message msg) {
2796 if (parent != null) {
2797 return parent.ProcessKeyPreview(ref msg);
2803 protected virtual bool ProcessMnemonic(char charCode) {
2808 [EditorBrowsable(EditorBrowsableState.Advanced)]
2809 protected void RaiseDragEvent(object key, DragEventArgs e) {
2813 [EditorBrowsable(EditorBrowsableState.Advanced)]
2814 protected void RaiseKeyEvent(object key, KeyEventArgs e) {
2818 [EditorBrowsable(EditorBrowsableState.Advanced)]
2819 protected void RaiseMouseEvent(object key, MouseEventArgs e) {
2823 [EditorBrowsable(EditorBrowsableState.Advanced)]
2824 protected void RaisePaintEvent(object key, PaintEventArgs e) {
2828 [EditorBrowsable(EditorBrowsableState.Advanced)]
2829 protected void RecreateHandle() {
2830 IEnumerator child = child_controls.GetEnumerator();
2834 if (IsHandleCreated) {
2840 while (child.MoveNext()) {
2841 ((Control)child.Current).RecreateHandle();
2847 is_recreating = false;
2850 [EditorBrowsable(EditorBrowsableState.Advanced)]
2851 protected void ResetMouseEventArgs() {
2855 [EditorBrowsable(EditorBrowsableState.Advanced)]
2856 protected ContentAlignment RtlTranslateAlignment(ContentAlignment align) {
2857 if (right_to_left == RightToLeft.No) {
2862 case ContentAlignment.TopLeft: {
2863 return ContentAlignment.TopRight;
2866 case ContentAlignment.TopRight: {
2867 return ContentAlignment.TopLeft;
2870 case ContentAlignment.MiddleLeft: {
2871 return ContentAlignment.MiddleRight;
2874 case ContentAlignment.MiddleRight: {
2875 return ContentAlignment.MiddleLeft;
2878 case ContentAlignment.BottomLeft: {
2879 return ContentAlignment.BottomRight;
2882 case ContentAlignment.BottomRight: {
2883 return ContentAlignment.BottomLeft;
2887 // if it's center it doesn't change
2893 [EditorBrowsable(EditorBrowsableState.Advanced)]
2894 protected HorizontalAlignment RtlTranslateAlignment(HorizontalAlignment align) {
2895 if ((right_to_left == RightToLeft.No) || (align == HorizontalAlignment.Center)) {
2899 if (align == HorizontalAlignment.Left) {
2900 return HorizontalAlignment.Right;
2903 // align must be HorizontalAlignment.Right
2904 return HorizontalAlignment.Left;
2907 [EditorBrowsable(EditorBrowsableState.Advanced)]
2908 protected LeftRightAlignment RtlTranslateAlignment(LeftRightAlignment align) {
2909 if (right_to_left == RightToLeft.No) {
2913 if (align == LeftRightAlignment.Left) {
2914 return LeftRightAlignment.Right;
2917 // align must be LeftRightAlignment.Right;
2918 return LeftRightAlignment.Left;
2921 [EditorBrowsable(EditorBrowsableState.Advanced)]
2922 protected ContentAlignment RtlTranslateContent(ContentAlignment align) {
2923 return RtlTranslateAlignment(align);
2926 [EditorBrowsable(EditorBrowsableState.Advanced)]
2927 protected HorizontalAlignment RtlTranslateHorizontal(HorizontalAlignment align) {
2928 return RtlTranslateAlignment(align);
2931 [EditorBrowsable(EditorBrowsableState.Advanced)]
2932 protected LeftRightAlignment RtlTranslateLeftRight(LeftRightAlignment align) {
2933 return RtlTranslateAlignment(align);
2936 [EditorBrowsable(EditorBrowsableState.Advanced)]
2937 protected virtual void ScaleCore(float dx, float dy) {
2943 location = new Point((int)(Left * dx), (int)(Top * dy));
2944 size = this.ClientSize;
2947 if (!GetStyle(ControlStyles.FixedWidth)) {
2948 size.Width = (int)(size.Width * dx);
2951 if (!GetStyle(ControlStyles.FixedHeight)) {
2952 size.Height = (int)(size.Height * dy);
2955 Location = location;
2958 /* Now scale our children */
2959 for (int i=0; i < child_controls.Count; i++) {
2960 child_controls[i].Scale(dx, dy);
2966 protected virtual void Select(bool directed, bool forward) {
2971 // Select this control
2976 if (parent == null) {
2980 // FIXME - this thing is doing the wrong stuff, needs to be similar to SelectNextControl
2982 index = parent.child_controls.IndexOf(this);
2987 if ((index+1) < parent.child_controls.Count) {
2996 index = parent.child_controls.Count-1;
2999 result = Select(parent.child_controls[index]);
3000 } while (!result && parent.child_controls[index] != this);
3003 [EditorBrowsable(EditorBrowsableState.Advanced)]
3004 protected virtual void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
3005 // SetBoundsCore updates the Win32 control itself. UpdateBounds updates the controls variables and fires events, I'm guessing - pdb
3006 if ((specified & BoundsSpecified.X) != BoundsSpecified.X) {
3010 if ((specified & BoundsSpecified.Y) != BoundsSpecified.Y) {
3014 if ((specified & BoundsSpecified.Width) != BoundsSpecified.Width) {
3018 if ((specified & BoundsSpecified.Height) != BoundsSpecified.Height) {
3022 if (IsHandleCreated) {
3023 XplatUI.SetWindowPos(Handle, x, y, width, height);
3025 UpdateBounds(x, y, width, height);
3028 [EditorBrowsable(EditorBrowsableState.Advanced)]
3029 protected virtual void SetClientSizeCore(int x, int y) {
3030 // Calculate the actual window size from the client size (it usually stays the same or grows)
3031 Rectangle ClientRect;
3032 Rectangle WindowRect;
3035 ClientRect = new Rectangle(0, 0, x, y);
3036 cp = this.CreateParams;
3038 if (XplatUI.CalculateWindowRect(Handle, ref ClientRect, cp.Style, cp.ExStyle, IntPtr.Zero, out WindowRect)==false) {
3042 SetBoundsCore(bounds.X, bounds.Y, WindowRect.Width, WindowRect.Height, BoundsSpecified.Size);
3045 [EditorBrowsable(EditorBrowsableState.Advanced)]
3046 protected void SetStyle(ControlStyles flag, bool value) {
3048 control_style |= flag;
3050 control_style &= ~flag;
3052 OnStyleChanged(EventArgs.Empty);
3055 protected void SetTopLevel(bool value) {
3056 if ((GetTopLevel() != value) && (parent != null)) {
3057 throw new Exception();
3061 if (value == true) {
3071 is_toplevel = value;
3074 protected virtual void SetVisibleCore(bool value) {
3075 if (value!=is_visible) {
3077 XplatUI.SetVisible(Handle, value);
3078 // Explicitly move Toplevel windows to where we want them;
3079 // apparently moving unmapped toplevel windows doesn't work
3080 if (is_visible && (this is Form)) {
3081 XplatUI.SetWindowPos(window.Handle, bounds.X, bounds.Y, bounds.Width, bounds.Height);
3083 OnVisibleChanged(EventArgs.Empty);
3086 if (dc_mem != null) {
3091 if (bmp_mem != null) {
3096 this.CreateBuffers(bounds.Width, bounds.Height);
3101 if (value == false && parent != null) {
3104 // Need to start at parent, GetContainerControl might return ourselves if we're a container
3105 container = (Control)parent.GetContainerControl();
3106 if (container != null) {
3107 container.SelectNextControl(this, true, true, true, true);
3111 if (parent != null) {
3112 parent.PerformLayout(this, "visible");
3114 PerformLayout(this, "visible");
3119 [EditorBrowsable(EditorBrowsableState.Advanced)]
3120 protected void UpdateBounds() {
3128 if (!IsHandleCreated) {
3132 XplatUI.GetWindowPos(this.Handle, this is Form, out x, out y, out width, out height, out client_width, out client_height);
3134 UpdateBounds(x, y, width, height, client_width, client_height);
3137 [EditorBrowsable(EditorBrowsableState.Advanced)]
3138 protected void UpdateBounds(int x, int y, int width, int height) {
3139 // UpdateBounds only seems to set our sizes and fire events but not update the GUI window to match
3141 bool resized = false;
3143 int client_x_diff = this.bounds.Width-this.client_size.Width;
3144 int client_y_diff = this.bounds.Height-this.client_size.Height;
3146 // Needed to generate required notifications
3147 if ((this.bounds.X!=x) || (this.bounds.Y!=y)) {
3151 if ((this.Bounds.Width!=width) || (this.Bounds.Height!=height)) {
3158 bounds.Height=height;
3160 // Update client rectangle as well
3161 if (this.layout_suspended==0) {
3162 prev_size.Width=client_size.Width;
3163 prev_size.Height=client_size.Height;
3166 client_size.Width=width-client_x_diff;
3167 client_size.Height=height-client_y_diff;
3170 OnLocationChanged(EventArgs.Empty);
3174 OnSizeChanged(EventArgs.Empty);
3178 [EditorBrowsable(EditorBrowsableState.Advanced)]
3179 protected void UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) {
3180 UpdateBounds(x, y, width, height);
3182 this.client_size.Width=clientWidth;
3183 this.client_size.Height=clientHeight;
3186 [EditorBrowsable(EditorBrowsableState.Advanced)]
3187 protected void UpdateStyles() {
3188 if (!IsHandleCreated) {
3192 XplatUI.SetWindowStyle(window.Handle, CreateParams);
3195 [EditorBrowsable(EditorBrowsableState.Advanced)]
3196 protected void UpdateZOrder() {
3201 if (parent == null) {
3207 children = ctl.child_controls.Count;
3208 for (int i = 1; i < children; i++ ) {
3209 XplatUI.SetZOrder(ctl.child_controls[i].window.Handle, ctl.child_controls[i-1].window.Handle, false, false);
3212 children = child_controls.Count;
3213 for (int i = 1; i < children; i++ ) {
3214 XplatUI.SetZOrder(child_controls[i].window.Handle, child_controls[i-1].window.Handle, false, false);
3219 protected virtual void WndProc(ref Message m) {
3221 Console.WriteLine("Control received message {0}", (Msg)m.Msg);
3223 if ((this.control_style & ControlStyles.EnableNotifyMessage) != 0) {
3227 switch((Msg)m.Msg) {
3228 case Msg.WM_WINDOWPOSCHANGED: {
3231 if (GetStyle(ControlStyles.ResizeRedraw)) {
3238 case Msg.WM_PAINT: {
3239 PaintEventArgs paint_event;
3241 paint_event = XplatUI.PaintEventStart(Handle);
3243 if (!needs_redraw) {
3244 // Just blit the previous image
3245 paint_event.Graphics.DrawImage (ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle, GraphicsUnit.Pixel);
3246 XplatUI.PaintEventEnd(Handle);
3251 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
3252 dc = paint_event.SetGraphics (DeviceContext);
3255 if ((control_style & (ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint)) != (ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint)) {
3256 OnPaintBackground(paint_event);
3259 OnPaint(paint_event);
3261 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
3262 dc.DrawImage (ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle, GraphicsUnit.Pixel);
3263 paint_event.SetGraphics (dc);
3264 needs_redraw = false;
3267 XplatUI.PaintEventEnd(Handle);
3269 if (!GetStyle(ControlStyles.UserPaint)) {
3276 case Msg.WM_ERASEBKGND: {
3277 if (GetStyle (ControlStyles.UserPaint)) {
3278 if (!GetStyle(ControlStyles.AllPaintingInWmPaint)) {
3279 PaintEventArgs eraseEventArgs = new PaintEventArgs (m.WParam == IntPtr.Zero ? Graphics.FromHwnd (m.HWnd) :
3280 Graphics.FromHdc (m.WParam), new Rectangle (new Point (0,0),Size));
3281 OnPaintBackground (eraseEventArgs);
3284 XplatUI.EraseWindowBackground(m.HWnd, m.WParam);
3286 // The DefWndProc will never have to handle this, we don't ever set hbr on the window
3287 m.Result = (IntPtr)1;
3291 case Msg.WM_LBUTTONUP: {
3292 HandleClick(mouse_clicks);
3293 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Left,
3295 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3297 if (mouse_clicks > 1) {
3303 case Msg.WM_LBUTTONDOWN: {
3304 if (CanSelect && !is_selected) {
3307 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3308 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3314 case Msg.WM_LBUTTONDBLCLK: {
3316 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3317 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3323 case Msg.WM_MBUTTONUP: {
3324 HandleClick(mouse_clicks);
3325 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Middle,
3327 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3329 if (mouse_clicks > 1) {
3335 case Msg.WM_MBUTTONDOWN: {
3336 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3337 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3343 case Msg.WM_MBUTTONDBLCLK: {
3345 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3346 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3351 case Msg.WM_RBUTTONUP: {
3352 if (context_menu != null) {
3353 context_menu.Show(this, new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ())));
3356 HandleClick(mouse_clicks);
3357 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Right,
3359 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3361 if (mouse_clicks > 1) {
3367 case Msg.WM_RBUTTONDOWN: {
3368 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3369 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3374 case Msg.WM_RBUTTONDBLCLK: {
3376 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3377 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3382 case Msg.WM_MOUSEWHEEL: {
3384 OnMouseWheel (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3385 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3386 HighOrder(m.WParam.ToInt32())));
3391 case Msg.WM_MOUSEMOVE: {
3392 OnMouseMove (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3394 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3399 case Msg.WM_MOUSE_ENTER: {
3404 OnMouseEnter(EventArgs.Empty);
3408 case Msg.WM_MOUSE_LEAVE: {
3410 OnMouseLeave(EventArgs.Empty);
3414 case Msg.WM_MOUSEHOVER: {
3415 OnMouseHover(EventArgs.Empty);
3419 case Msg.WM_SYSKEYDOWN:
3420 case Msg.WM_KEYDOWN:
3421 case Msg.WM_SYSKEYUP:
3423 case Msg.WM_SYSCHAR:
3425 if (ProcessKeyEventArgs(ref m)) {
3429 if (PreProcessMessage(ref m)) {
3433 if (ProcessKeyMessage(ref m)) {
3442 if (m.LParam != IntPtr.Zero) {
3445 hi = new HELPINFO();
3447 hi = (HELPINFO) Marshal.PtrToStructure (m.LParam, typeof (HELPINFO));
3448 mouse_pos = new Point(hi.MousePos.x, hi.MousePos.y);
3450 mouse_pos = Control.MousePosition;
3452 OnHelpRequested(new HelpEventArgs(mouse_pos));
3453 m.Result = (IntPtr)1;
3457 case Msg.WM_KILLFOCUS: {
3458 OnLeave(EventArgs.Empty);
3459 if (CausesValidation) {
3461 e = new CancelEventArgs(false);
3470 OnValidated(EventArgs.Empty);
3473 this.has_focus = false;
3474 this.is_selected = false;
3475 OnLostFocus(EventArgs.Empty);
3479 case Msg.WM_SETFOCUS: {
3480 OnEnter(EventArgs.Empty);
3481 this.has_focus = true;
3482 OnGotFocus(EventArgs.Empty);
3487 case Msg.WM_SYSCOLORCHANGE: {
3488 ThemeEngine.Current.ResetDefaults();
3489 OnSystemColorsChanged(EventArgs.Empty);
3494 case Msg.WM_SETCURSOR: {
3495 if (cursor == null) {
3500 XplatUI.SetCursor(window.Handle, cursor.handle);
3501 m.Result = (IntPtr)1;
3511 #endregion // Public Instance Methods
3513 #region OnXXX methods
3514 [EditorBrowsable(EditorBrowsableState.Advanced)]
3515 protected virtual void OnBackColorChanged(EventArgs e) {
3516 if (BackColorChanged!=null) BackColorChanged(this, e);
3517 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackColorChanged(e);
3520 [EditorBrowsable(EditorBrowsableState.Advanced)]
3521 protected virtual void OnBackgroundImageChanged(EventArgs e) {
3522 if (BackgroundImageChanged!=null) BackgroundImageChanged(this, e);
3523 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackgroundImageChanged(e);
3526 [EditorBrowsable(EditorBrowsableState.Advanced)]
3527 protected virtual void OnBindingContextChanged(EventArgs e) {
3528 CheckDataBindings ();
3529 if (BindingContextChanged!=null) {
3530 BindingContextChanged(this, e);
3532 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBindingContextChanged(e);
3535 [EditorBrowsable(EditorBrowsableState.Advanced)]
3536 protected virtual void OnCausesValidationChanged(EventArgs e) {
3537 if (CausesValidationChanged!=null) CausesValidationChanged(this, e);
3540 [EditorBrowsable(EditorBrowsableState.Advanced)]
3541 protected virtual void OnChangeUICues(UICuesEventArgs e) {
3542 if (ChangeUICues!=null) ChangeUICues(this, e);
3545 [EditorBrowsable(EditorBrowsableState.Advanced)]
3546 protected virtual void OnClick(EventArgs e) {
3547 if (Click!=null) Click(this, e);
3550 [EditorBrowsable(EditorBrowsableState.Advanced)]
3551 protected virtual void OnContextMenuChanged(EventArgs e) {
3552 if (ContextMenuChanged!=null) ContextMenuChanged(this, e);
3555 [EditorBrowsable(EditorBrowsableState.Advanced)]
3556 protected virtual void OnControlAdded(ControlEventArgs e) {
3557 if (ControlAdded!=null) ControlAdded(this, e);
3560 [EditorBrowsable(EditorBrowsableState.Advanced)]
3561 protected virtual void OnControlRemoved(ControlEventArgs e) {
3562 if (ControlRemoved!=null) ControlRemoved(this, e);
3565 [EditorBrowsable(EditorBrowsableState.Advanced)]
3566 protected virtual void OnCreateControl() {
3570 [EditorBrowsable(EditorBrowsableState.Advanced)]
3571 protected virtual void OnCursorChanged(EventArgs e) {
3572 if (CursorChanged!=null) CursorChanged(this, e);
3575 [EditorBrowsable(EditorBrowsableState.Advanced)]
3576 protected virtual void OnDockChanged(EventArgs e) {
3577 if (DockChanged!=null) DockChanged(this, e);
3580 [EditorBrowsable(EditorBrowsableState.Advanced)]
3581 protected virtual void OnDoubleClick(EventArgs e) {
3582 if (DoubleClick!=null) DoubleClick(this, e);
3585 [EditorBrowsable(EditorBrowsableState.Advanced)]
3586 protected virtual void OnDragDrop(DragEventArgs drgevent) {
3587 if (DragDrop!=null) DragDrop(this, drgevent);
3590 [EditorBrowsable(EditorBrowsableState.Advanced)]
3591 protected virtual void OnDragEnter(DragEventArgs drgevent) {
3592 if (DragEnter!=null) DragEnter(this, drgevent);
3595 [EditorBrowsable(EditorBrowsableState.Advanced)]
3596 protected virtual void OnDragLeave(EventArgs e) {
3597 if (DragLeave!=null) DragLeave(this, e);
3600 [EditorBrowsable(EditorBrowsableState.Advanced)]
3601 protected virtual void OnDragOver(DragEventArgs drgevent) {
3602 if (DragOver!=null) DragOver(this, drgevent);
3605 [EditorBrowsable(EditorBrowsableState.Advanced)]
3606 protected virtual void OnEnabledChanged(EventArgs e) {
3607 if (EnabledChanged!=null) EnabledChanged(this, e);
3608 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentEnabledChanged(e);
3611 [EditorBrowsable(EditorBrowsableState.Advanced)]
3612 protected virtual void OnEnter(EventArgs e) {
3613 if (Enter!=null) Enter(this, e);
3616 [EditorBrowsable(EditorBrowsableState.Advanced)]
3617 protected virtual void OnFontChanged(EventArgs e) {
3618 if (FontChanged!=null) FontChanged(this, e);
3619 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentFontChanged(e);
3622 [EditorBrowsable(EditorBrowsableState.Advanced)]
3623 protected virtual void OnForeColorChanged(EventArgs e) {
3624 if (ForeColorChanged!=null) ForeColorChanged(this, e);
3625 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentForeColorChanged(e);
3628 [EditorBrowsable(EditorBrowsableState.Advanced)]
3629 protected virtual void OnGiveFeedback(GiveFeedbackEventArgs gfbevent) {
3630 if (GiveFeedback!=null) GiveFeedback(this, gfbevent);
3633 [EditorBrowsable(EditorBrowsableState.Advanced)]
3634 protected virtual void OnGotFocus(EventArgs e) {
3635 if (GotFocus!=null) GotFocus(this, e);
3638 [EditorBrowsable(EditorBrowsableState.Advanced)]
3639 protected virtual void OnHandleCreated(EventArgs e) {
3640 if (HandleCreated!=null) HandleCreated(this, e);
3643 [EditorBrowsable(EditorBrowsableState.Advanced)]
3644 protected virtual void OnHandleDestroyed(EventArgs e) {
3645 if (HandleDestroyed!=null) HandleDestroyed(this, e);
3648 [EditorBrowsable(EditorBrowsableState.Advanced)]
3649 protected virtual void OnHelpRequested(HelpEventArgs hevent) {
3650 if (HelpRequested!=null) HelpRequested(this, hevent);
3653 protected virtual void OnImeModeChanged(EventArgs e) {
3654 if (ImeModeChanged!=null) ImeModeChanged(this, e);
3657 [EditorBrowsable(EditorBrowsableState.Advanced)]
3658 protected virtual void OnInvalidated(InvalidateEventArgs e) {
3659 needs_redraw = true;
3660 if (Invalidated!=null) Invalidated(this, e);
3663 [EditorBrowsable(EditorBrowsableState.Advanced)]
3664 protected virtual void OnKeyDown(KeyEventArgs e) {
3665 if (KeyDown!=null) KeyDown(this, e);
3668 [EditorBrowsable(EditorBrowsableState.Advanced)]
3669 protected virtual void OnKeyPress(KeyPressEventArgs e) {
3670 if (KeyPress!=null) KeyPress(this, e);
3673 [EditorBrowsable(EditorBrowsableState.Advanced)]
3674 protected virtual void OnKeyUp(KeyEventArgs e) {
3675 if (KeyUp!=null) KeyUp(this, e);
3678 [EditorBrowsable(EditorBrowsableState.Advanced)]
3679 protected virtual void OnLayout(LayoutEventArgs levent) {
3680 if (Layout!=null) Layout(this, levent);
3683 [EditorBrowsable(EditorBrowsableState.Advanced)]
3684 protected virtual void OnLeave(EventArgs e) {
3685 if (Leave!=null) Leave(this, e);
3688 [EditorBrowsable(EditorBrowsableState.Advanced)]
3689 protected virtual void OnLocationChanged(EventArgs e) {
3691 if (LocationChanged!=null) LocationChanged(this, e);
3694 [EditorBrowsable(EditorBrowsableState.Advanced)]
3695 protected virtual void OnLostFocus(EventArgs e) {
3696 if (LostFocus!=null) LostFocus(this, e);
3699 [EditorBrowsable(EditorBrowsableState.Advanced)]
3700 protected virtual void OnMouseDown(MouseEventArgs e) {
3701 if (MouseDown!=null) MouseDown(this, e);
3704 [EditorBrowsable(EditorBrowsableState.Advanced)]
3705 protected virtual void OnMouseEnter(EventArgs e) {
3706 if (MouseEnter!=null) MouseEnter(this, e);
3709 [EditorBrowsable(EditorBrowsableState.Advanced)]
3710 protected virtual void OnMouseHover(EventArgs e) {
3711 if (MouseHover!=null) MouseHover(this, e);
3714 [EditorBrowsable(EditorBrowsableState.Advanced)]
3715 protected virtual void OnMouseLeave(EventArgs e) {
3716 if (MouseLeave!=null) MouseLeave(this, e);
3719 [EditorBrowsable(EditorBrowsableState.Advanced)]
3720 protected virtual void OnMouseMove(MouseEventArgs e) {
3721 if (MouseMove!=null) MouseMove(this, e);
3724 [EditorBrowsable(EditorBrowsableState.Advanced)]
3725 protected virtual void OnMouseUp(MouseEventArgs e) {
3726 if (MouseUp!=null) MouseUp(this, e);
3729 [EditorBrowsable(EditorBrowsableState.Advanced)]
3730 protected virtual void OnMouseWheel(MouseEventArgs e) {
3731 if (MouseWheel!=null) MouseWheel(this, e);
3734 [EditorBrowsable(EditorBrowsableState.Advanced)]
3735 protected virtual void OnMove(EventArgs e) {
3736 if (Move!=null) Move(this, e);
3739 [EditorBrowsable(EditorBrowsableState.Advanced)]
3740 protected virtual void OnNotifyMessage(Message m) {
3744 [EditorBrowsable(EditorBrowsableState.Advanced)]
3745 protected virtual void OnPaint(PaintEventArgs e) {
3746 if (Paint!=null) Paint(this, e);
3749 [EditorBrowsable(EditorBrowsableState.Advanced)]
3750 protected virtual void OnPaintBackground(PaintEventArgs pevent) {
3751 PaintControlBackground (pevent);
3754 [EditorBrowsable(EditorBrowsableState.Advanced)]
3755 protected virtual void OnParentBackColorChanged(EventArgs e) {
3756 if (background_color.IsEmpty && background_image==null) {
3758 OnBackColorChanged(e);
3762 [EditorBrowsable(EditorBrowsableState.Advanced)]
3763 protected virtual void OnParentBackgroundImageChanged(EventArgs e) {
3764 if (background_color.IsEmpty && background_image==null) {
3766 OnBackgroundImageChanged(e);
3770 [EditorBrowsable(EditorBrowsableState.Advanced)]
3771 protected virtual void OnParentBindingContextChanged(EventArgs e) {
3772 if (binding_context==null) {
3773 binding_context=Parent.binding_context;
3774 OnBindingContextChanged(e);
3778 [EditorBrowsable(EditorBrowsableState.Advanced)]
3779 protected virtual void OnParentChanged(EventArgs e) {
3780 if (ParentChanged!=null) ParentChanged(this, e);
3783 [EditorBrowsable(EditorBrowsableState.Advanced)]
3784 protected virtual void OnParentEnabledChanged(EventArgs e) {
3785 if (is_enabled != Parent.is_enabled) {
3786 is_enabled=Parent.is_enabled;
3788 if (EnabledChanged != null) {
3789 EnabledChanged(this, e);
3794 [EditorBrowsable(EditorBrowsableState.Advanced)]
3795 protected virtual void OnParentFontChanged(EventArgs e) {
3802 [EditorBrowsable(EditorBrowsableState.Advanced)]
3803 protected virtual void OnParentForeColorChanged(EventArgs e) {
3804 if (foreground_color.IsEmpty) {
3806 OnForeColorChanged(e);
3810 [EditorBrowsable(EditorBrowsableState.Advanced)]
3811 protected virtual void OnParentRightToLeftChanged(EventArgs e) {
3812 if (right_to_left==RightToLeft.Inherit) {
3814 OnRightToLeftChanged(e);
3818 [EditorBrowsable(EditorBrowsableState.Advanced)]
3819 protected virtual void OnParentVisibleChanged(EventArgs e) {
3821 OnVisibleChanged(e);
3825 [EditorBrowsable(EditorBrowsableState.Advanced)]
3826 protected virtual void OnQueryContinueDrag(QueryContinueDragEventArgs e) {
3827 if (QueryContinueDrag!=null) QueryContinueDrag(this, e);
3830 [EditorBrowsable(EditorBrowsableState.Advanced)]
3831 protected virtual void OnResize(EventArgs e) {
3832 if (Resize!=null) Resize(this, e);
3834 PerformLayout(this, "bounds");
3836 if (parent != null) {
3837 parent.PerformLayout();
3841 [EditorBrowsable(EditorBrowsableState.Advanced)]
3842 protected virtual void OnRightToLeftChanged(EventArgs e) {
3843 if (RightToLeftChanged!=null) RightToLeftChanged(this, e);
3844 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentRightToLeftChanged(e);
3847 [EditorBrowsable(EditorBrowsableState.Advanced)]
3848 protected virtual void OnSizeChanged(EventArgs e) {
3849 InvalidateBuffers ();
3851 if (SizeChanged!=null) SizeChanged(this, e);
3854 [EditorBrowsable(EditorBrowsableState.Advanced)]
3855 protected virtual void OnStyleChanged(EventArgs e) {
3856 if (StyleChanged!=null) StyleChanged(this, e);
3859 [EditorBrowsable(EditorBrowsableState.Advanced)]
3860 protected virtual void OnSystemColorsChanged(EventArgs e) {
3861 if (SystemColorsChanged!=null) SystemColorsChanged(this, e);
3864 [EditorBrowsable(EditorBrowsableState.Advanced)]
3865 protected virtual void OnTabIndexChanged(EventArgs e) {
3866 if (TabIndexChanged!=null) TabIndexChanged(this, e);
3869 [EditorBrowsable(EditorBrowsableState.Advanced)]
3870 protected virtual void OnTabStopChanged(EventArgs e) {
3871 if (TabStopChanged!=null) TabStopChanged(this, e);
3874 [EditorBrowsable(EditorBrowsableState.Advanced)]
3875 protected virtual void OnTextChanged(EventArgs e) {
3876 if (TextChanged!=null) TextChanged(this, e);
3879 [EditorBrowsable(EditorBrowsableState.Advanced)]
3880 protected virtual void OnValidated(EventArgs e) {
3881 if (Validated!=null) Validated(this, e);
3884 [EditorBrowsable(EditorBrowsableState.Advanced)]
3885 protected virtual void OnValidating(System.ComponentModel.CancelEventArgs e) {
3886 if (Validating!=null) Validating(this, e);
3889 [EditorBrowsable(EditorBrowsableState.Advanced)]
3890 protected virtual void OnVisibleChanged(EventArgs e) {
3897 if (bmp_mem!=null) {
3903 if (!this.IsHandleCreated) {
3904 this.CreateControl();
3910 if (VisibleChanged!=null) VisibleChanged(this, e);
3912 // We need to tell our kids
3913 for (int i=0; i<child_controls.Count; i++) {
3914 child_controls[i].OnParentVisibleChanged(e);
3917 #endregion // OnXXX methods
3920 public event EventHandler BackColorChanged;
3921 public event EventHandler BackgroundImageChanged;
3922 public event EventHandler BindingContextChanged;
3923 public event EventHandler CausesValidationChanged;
3924 public event UICuesEventHandler ChangeUICues;
3925 public event EventHandler Click;
3926 public event EventHandler ContextMenuChanged;
3928 [EditorBrowsable(EditorBrowsableState.Advanced)]
3930 public event ControlEventHandler ControlAdded;
3932 [EditorBrowsable(EditorBrowsableState.Advanced)]
3934 public event ControlEventHandler ControlRemoved;
3936 public event EventHandler CursorChanged;
3937 public event EventHandler DockChanged;
3938 public event EventHandler DoubleClick;
3939 public event DragEventHandler DragDrop;
3940 public event DragEventHandler DragEnter;
3941 public event EventHandler DragLeave;
3942 public event DragEventHandler DragOver;
3943 public event EventHandler EnabledChanged;
3944 public event EventHandler Enter;
3945 public event EventHandler FontChanged;
3946 public event EventHandler ForeColorChanged;
3947 public event GiveFeedbackEventHandler GiveFeedback;
3949 [EditorBrowsable(EditorBrowsableState.Advanced)]
3951 public event EventHandler GotFocus;
3953 [EditorBrowsable(EditorBrowsableState.Advanced)]
3955 public event EventHandler HandleCreated;
3957 [EditorBrowsable(EditorBrowsableState.Advanced)]
3959 public event EventHandler HandleDestroyed;
3961 public event HelpEventHandler HelpRequested;
3962 public event EventHandler ImeModeChanged;
3964 [EditorBrowsable(EditorBrowsableState.Advanced)]
3966 public event InvalidateEventHandler Invalidated;
3968 public event KeyEventHandler KeyDown;
3969 public event KeyPressEventHandler KeyPress;
3970 public event KeyEventHandler KeyUp;
3971 public event LayoutEventHandler Layout;
3972 public event EventHandler Leave;
3973 public event EventHandler LocationChanged;
3975 [EditorBrowsable(EditorBrowsableState.Advanced)]
3977 public event EventHandler LostFocus;
3979 public event MouseEventHandler MouseDown;
3980 public event EventHandler MouseEnter;
3981 public event EventHandler MouseHover;
3982 public event EventHandler MouseLeave;
3983 public event MouseEventHandler MouseMove;
3984 public event MouseEventHandler MouseUp;
3986 [EditorBrowsable(EditorBrowsableState.Advanced)]
3988 public event MouseEventHandler MouseWheel;
3990 public event EventHandler Move;
3991 public event PaintEventHandler Paint;
3992 public event EventHandler ParentChanged;
3993 public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp;
3994 public event QueryContinueDragEventHandler QueryContinueDrag;
3995 public event EventHandler Resize;
3996 public event EventHandler RightToLeftChanged;
3997 public event EventHandler SizeChanged;
3998 public event EventHandler StyleChanged;
3999 public event EventHandler SystemColorsChanged;
4000 public event EventHandler TabIndexChanged;
4001 public event EventHandler TabStopChanged;
4002 public event EventHandler TextChanged;
4003 public event EventHandler Validated;
4004 public event CancelEventHandler Validating;
4005 public event EventHandler VisibleChanged;
4006 #endregion // Events