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)]
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
90 internal Color foreground_color; // foreground color for control
91 internal Color background_color; // background color for control
92 internal Image background_image; // background image for control
93 internal Font font; // font for control
94 internal string text; // window/title text for control
95 internal BorderStyle border_style; // Border style of control
98 internal AnchorStyles anchor_style; // anchoring requirements for our control
99 internal DockStyle dock_style; // docking requirements for our control (supercedes anchoring)
100 internal SizeF size_ratio; // size ratio of our control to it's parent; required for anchoring
101 internal Size prev_size; // previous size of the control; required for anchoring
103 // to be categorized...
104 static internal ArrayList controls = new ArrayList(); // All of the application's controls, in a flat list
105 internal ControlCollection child_controls; // our children
106 internal Control parent; // our parent control
107 internal AccessibleObject accessibility_object; // object that contains accessibility information about our control
108 internal BindingContext binding_context; // TODO
109 internal RightToLeft right_to_left; // drawing direction for control
110 internal int layout_suspended;
111 internal ContextMenu context_menu; // Context menu associated with the control
113 private Graphics dc_mem; // Graphics context for double buffering
114 private Bitmap bmp_mem; // Bitmap for double buffering control
115 private bool needs_redraw = true;
117 private ControlBindingsCollection data_bindings;
119 #endregion // Local Variables
121 #region Private Classes
122 // This helper class allows us to dispatch messages to Control.WndProc
123 internal class ControlNativeWindow : NativeWindow {
124 private Control owner;
126 public ControlNativeWindow(Control control) : base() {
131 public Control Owner {
137 static internal Control ControlFromHandle(IntPtr hWnd) {
138 ControlNativeWindow window;
140 window = (ControlNativeWindow)window_collection[hWnd];
145 protected override void WndProc(ref Message m) {
146 owner.WndProc(ref m);
151 #region Public Classes
153 public class ControlAccessibleObject : AccessibleObject {
154 #region ControlAccessibleObject Local Variables
155 private Control owner;
156 #endregion // ControlAccessibleObject Local Variables
158 #region ControlAccessibleObject Constructors
159 public ControlAccessibleObject(Control ownerControl) {
160 this.owner = ownerControl;
162 #endregion // ControlAccessibleObject Constructors
164 #region ControlAccessibleObject Public Instance Properties
165 public override string DefaultAction {
167 return base.DefaultAction;
171 public override string Description {
173 return base.Description;
177 public IntPtr Handle {
183 // We don't want to let them set it
187 public override string Help {
193 public override string KeyboardShortcut {
195 return base.KeyboardShortcut;
199 public override string Name {
209 public Control Owner {
215 public override AccessibleRole Role {
220 #endregion // ControlAccessibleObject Public Instance Properties
222 #region ControlAccessibleObject Public Instance Methods
223 public override int GetHelpTopic(out string FileName) {
224 return base.GetHelpTopic (out FileName);
227 [MonoTODO("Implement this and tie it into Control.AccessibilityNotifyClients")]
228 public void NotifyClients(AccessibleEvents accEvent) {
229 throw new NotImplementedException();
232 [MonoTODO("Implement this and tie it into Control.AccessibilityNotifyClients")]
233 public void NotifyClients(AccessibleEvents accEvent, int childID) {
234 throw new NotImplementedException();
237 public override string ToString() {
238 return "ControlAccessibleObject: Owner = " + owner.ToString() + ", Text: " + owner.text;
241 #endregion // ControlAccessibleObject Public Instance Methods
244 [DesignerSerializer("System.Windows.Forms.Design.ControlCollectionCodeDomSerializer, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
245 [ListBindable(false)]
246 public class ControlCollection : IList, ICollection, ICloneable, IEnumerable {
247 #region ControlCollection Local Variables
248 internal ArrayList list;
249 internal Control owner;
250 #endregion // ControlCollection Local Variables
252 #region ControlCollection Public Constructor
253 public ControlCollection(Control owner) {
255 this.list=new ArrayList();
259 #region ControlCollection Public Instance Properties
266 public bool IsReadOnly {
268 return list.IsReadOnly;
272 public virtual Control this[int index] {
274 if (index < 0 || index >= list.Count) {
275 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
277 return (Control)list[index];
280 #endregion // ControlCollection Public Instance Properties
282 #region ControlCollection Private Instance Methods
283 public virtual void Add (Control value)
286 for (int i = 0; i < list.Count; i++) {
287 if (list [i] == value) {
288 // Do we need to do anything here?
293 if (value.tab_index == -1) {
299 end = owner.child_controls.Count;
300 for (int i = 0; i < end; i++) {
301 index = owner.child_controls[i].tab_index;
306 value.tab_index = use;
310 value.Parent = owner;
311 owner.UpdateZOrder();
312 owner.OnControlAdded(new ControlEventArgs(value));
315 public virtual void AddRange (Control[] controls)
317 if (controls == null)
318 throw new ArgumentNullException ("controls");
320 owner.SuspendLayout ();
323 for (int i = 0; i < controls.Length; i++)
326 owner.ResumeLayout ();
330 public virtual void Clear ()
332 owner.SuspendLayout();
333 for (int i = 0; i < list.Count; i++) {
334 owner.OnControlRemoved(new ControlEventArgs((Control)list[i]));
337 owner.ResumeLayout();
340 public virtual bool Contains (Control value)
342 return list.Contains (value);
345 public void CopyTo (Array array, int index)
347 list.CopyTo(array, index);
350 public override bool Equals(object other) {
351 if (other is ControlCollection && (((ControlCollection)other).owner==this.owner)) {
358 public int GetChildIndex(Control child) {
359 return GetChildIndex(child, false);
362 public int GetChildIndex(Control child, bool throwException) {
365 index=list.IndexOf(child);
367 if (index==-1 && throwException) {
368 throw new ArgumentException("Not a child control", "child");
373 public IEnumerator GetEnumerator() {
374 return list.GetEnumerator();
377 public override int GetHashCode() {
378 return base.GetHashCode();
381 public int IndexOf(Control control) {
382 return list.IndexOf(control);
385 public virtual void Remove(Control value) {
386 owner.OnControlRemoved(new ControlEventArgs(value));
388 owner.UpdateZOrder();
391 public void RemoveAt(int index) {
392 if (index<0 || index>=list.Count) {
393 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
396 owner.OnControlRemoved(new ControlEventArgs((Control)list[index]));
397 list.RemoveAt(index);
398 owner.UpdateZOrder();
401 public void SetChildIndex(Control child, int newIndex) {
404 old_index=list.IndexOf(child);
406 throw new ArgumentException("Not a child control", "child");
409 if (old_index==newIndex) {
415 if (newIndex>list.Count) {
418 list.Insert(newIndex, child);
420 owner.UpdateZOrder();
422 #endregion // ControlCollection Private Instance Methods
424 #region ControlCollection Interface Properties
425 object IList.this[int index] {
427 if (index<0 || index>=list.Count) {
428 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
434 if (!(value is Control)) {
435 throw new ArgumentException("Object of type Control required", "value");
438 list[index]=(Control)value;
442 bool IList.IsFixedSize {
448 bool IList.IsReadOnly {
450 return list.IsReadOnly;
454 bool ICollection.IsSynchronized {
456 return list.IsSynchronized;
460 object ICollection.SyncRoot {
462 return list.SyncRoot;
465 #endregion // ControlCollection Interface Properties
467 #region ControlCollection Interface Methods
468 int IList.Add(object value) {
470 throw new ArgumentNullException("value", "Cannot add null controls");
473 if (!(value is Control)) {
474 throw new ArgumentException("Object of type Control required", "value");
477 return list.Add(value);
480 bool IList.Contains(object value) {
481 if (!(value is Control)) {
482 throw new ArgumentException("Object of type Control required", "value");
485 return this.Contains((Control) value);
488 int IList.IndexOf(object value) {
489 if (!(value is Control)) {
490 throw new ArgumentException("Object of type Control required", "value");
493 return this.IndexOf((Control) value);
496 void IList.Insert(int index, object value) {
497 if (!(value is Control)) {
498 throw new ArgumentException("Object of type Control required", "value");
500 list.Insert(index, value);
503 void IList.Remove(object value) {
504 if (!(value is Control)) {
505 throw new ArgumentException("Object of type Control required", "value");
510 void ICollection.CopyTo(Array array, int index) {
512 list.CopyTo(array, index);
516 Object ICloneable.Clone() {
517 ControlCollection clone = new ControlCollection(this.owner);
518 clone.list=(ArrayList)list.Clone(); // FIXME: Do we need this?
521 #endregion // ControlCollection Interface Methods
523 #endregion // ControlCollection Class
525 #region Public Constructors
527 creator_thread = Thread.CurrentThread;
529 prev_size = Size.Empty;
530 anchor_style = AnchorStyles.Top | AnchorStyles.Left;
532 create_handled = false;
538 layout_pending = false;
540 causes_validation = true;
542 layout_suspended = 0;
546 right_to_left = RightToLeft.Inherit;
548 control_style = ControlStyles.Selectable | ControlStyles.StandardClick | ControlStyles.StandardDoubleClick;
551 background_image = null;
555 window = new ControlNativeWindow(this);
556 child_controls = CreateControlsInstance();
557 client_size = new Size(DefaultSize.Width, DefaultSize.Height);
558 client_rect = new Rectangle(0, 0, DefaultSize.Width, DefaultSize.Height);
559 XplatUI.CalculateWindowRect(IntPtr.Zero, ref client_rect, CreateParams.Style, CreateParams.ExStyle, IntPtr.Zero, out bounds);
560 if ((CreateParams.Style & (int)WindowStyles.WS_CHILD) == 0) {
566 public Control(Control parent, string text) : this() {
571 public Control(Control parent, string text, int left, int top, int width, int height) : this() {
576 bounds.Height=height;
577 SetBoundsCore(left, top, width, height, BoundsSpecified.All);
581 public Control(string text) : this() {
585 public Control(string text, int left, int top, int width, int height) : this() {
589 bounds.Height=height;
590 SetBoundsCore(left, top, width, height, BoundsSpecified.All);
594 protected override void Dispose(bool disposing) {
607 controls.Remove(this);
609 #endregion // Public Constructors
611 #region Internal Properties
612 internal BorderStyle InternalBorderStyle {
618 if (border_style != value) {
619 border_style = value;
621 XplatUI.SetBorderStyle(window.Handle, border_style);
625 #endregion // Internal Properties
627 #region Private & Internal Methods
628 internal static IAsyncResult BeginInvokeInternal (Delegate method, object [] args) {
629 AsyncMethodResult result = new AsyncMethodResult ();
630 AsyncMethodData data = new AsyncMethodData ();
632 data.Method = method;
634 data.Result = new WeakReference (result);
637 if (!ExecutionContext.IsFlowSuppressed ()) {
638 data.Context = ExecutionContext.Capture ();
641 if (SecurityManager.SecurityEnabled) {
642 data.Stack = CompressedStack.GetCompressedStack ();
646 XplatUI.SendAsyncMethod (data);
650 internal Graphics DeviceContext {
653 CreateBuffers(this.Width, this.Height);
659 private Bitmap ImageBuffer {
662 CreateBuffers(this.Width, this.Height);
668 internal void CreateBuffers (int width, int height) {
669 if (dc_mem != null) {
683 bmp_mem = new Bitmap (width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
684 dc_mem = Graphics.FromImage (bmp_mem);
688 internal void InvalidateBuffers ()
690 if (dc_mem != null) {
701 internal static void SetChildColor(Control parent) {
704 for (int i=0; i < parent.child_controls.Count; i++) {
705 child=parent.child_controls[i];
706 if (child.IsHandleCreated) {
707 XplatUI.SetWindowBackground(child.window.Handle, child.BackColor);
709 if (child.child_controls.Count>0) {
710 SetChildColor(child);
716 internal bool Select(Control control) {
718 IContainerControl container;
720 if (control == null) {
724 parent = control.parent;
726 if (((control.control_style & ControlStyles.Selectable) !=0) && (parent != null)) {
727 while (parent != null) {
728 if (!parent.Visible || !parent.is_enabled) {
731 parent = parent.parent;
735 control.is_selected = true;
737 XplatUI.SetFocus(control.window.Handle);
738 container = GetContainerControl();
739 if (container != null) {
740 container.ActiveControl = control;
745 internal virtual void DoDefaultAction() {
746 // Only here to be overriden by our actual controls; this is needed by the accessibility class
749 internal static int LowOrder (int param) {
750 return (param & 0xffff);
753 internal static int HighOrder (int param) {
754 return (param >> 16);
757 // This method exists so controls overriding OnPaintBackground can have default background painting done
758 internal void PaintControlBackground (PaintEventArgs pevent)
760 if (background_image != null)
761 pevent.Graphics.DrawImage (background_image, 0, 0);
764 internal static MouseButtons FromParamToMouseButtons (int param) {
765 MouseButtons buttons = MouseButtons.None;
767 if ((param & (int) MsgButtons.MK_LBUTTON) != 0)
768 buttons |= MouseButtons.Left;
770 if ((param & (int) MsgButtons.MK_MBUTTON) != 0)
771 buttons |= MouseButtons.Middle;
773 if ((param & (int) MsgButtons.MK_RBUTTON) != 0)
774 buttons |= MouseButtons.Right;
780 internal virtual bool ProcessControlMnemonic(char charCode) {
781 return ProcessMnemonic(charCode);
784 private static Control FindFlatForward(Control container, Control start) {
790 end = container.child_controls.Count;
793 index = start.tab_index;
798 for (int i = 0; i < end; i++) {
800 if (container.child_controls[i].tab_index > index) {
801 found = container.child_controls[i];
803 } else if (found.tab_index > container.child_controls[i].tab_index) {
804 if (container.child_controls[i].tab_index > index) {
805 found = container.child_controls[i];
812 private static Control FindControlForward(Control container, Control start) {
819 if ((start is IContainerControl) || start.GetStyle(ControlStyles.ContainerControl)) {
820 found = FindControlForward(start, null);
827 while (p != container) {
828 found = FindFlatForward(p, start);
836 return FindFlatForward(container, start);
839 private static Control FindFlatBackward(Control container, Control start) {
845 end = container.child_controls.Count;
848 index = start.tab_index;
850 // FIXME: Possible speed-up: Keep the highest taborder index in the container
852 for (int i = 0; i < end; i++) {
853 if (container.child_controls[i].tab_index > index) {
854 index = container.child_controls[i].tab_index;
860 for (int i = 0; i < end; i++) {
862 if (container.child_controls[i].tab_index < index) {
863 found = container.child_controls[i];
865 } else if (found.tab_index < container.child_controls[i].tab_index) {
866 if (container.child_controls[i].tab_index < index) {
867 found = container.child_controls[i];
874 private static Control FindControlBackward(Control container, Control start) {
880 found = FindFlatBackward(start.parent, start);
881 if (found == null && start.parent != container) {
886 found = FindFlatBackward(container, start);
889 while ((found != null) && ((found is IContainerControl) || found.GetStyle(ControlStyles.ContainerControl))) {
890 found = FindControlBackward(found, null);
899 private void HandleClick(int clicks) {
900 if (GetStyle(ControlStyles.StandardClick)) {
902 if (GetStyle(ControlStyles.StandardDoubleClick)) {
903 OnDoubleClick(EventArgs.Empty);
905 OnClick(EventArgs.Empty);
908 OnClick(EventArgs.Empty);
913 private void CheckDataBindings ()
915 if (data_bindings == null)
918 BindingContext binding_context = BindingContext;
919 foreach (Binding binding in data_bindings) {
920 binding.Check (binding_context);
924 #endregion // Private & Internal Methods
926 #region Public Static Properties
927 public static Color DefaultBackColor {
929 return ThemeEngine.Current.DefaultControlBackColor;
933 public static Font DefaultFont {
935 return ThemeEngine.Current.DefaultFont;
939 public static Color DefaultForeColor {
941 return ThemeEngine.Current.DefaultControlForeColor;
945 public static Keys ModifierKeys {
947 return XplatUI.State.ModifierKeys;
951 public static MouseButtons MouseButtons {
953 return XplatUI.State.MouseButtons;
957 public static Point MousePosition {
959 return Cursor.Position;
962 #endregion // Public Static Properties
964 #region Public Instance Properties
965 [EditorBrowsable(EditorBrowsableState.Advanced)]
967 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
968 public AccessibleObject AccessibilityObject {
970 if (accessibility_object==null) {
971 accessibility_object=CreateAccessibilityInstance();
973 return accessibility_object;
977 [EditorBrowsable(EditorBrowsableState.Advanced)]
979 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
980 public string AccessibleDefaultActionDescription {
982 return AccessibilityObject.default_action;
986 AccessibilityObject.default_action=value;
992 public string AccessibleDescription {
994 return AccessibilityObject.description;
998 AccessibilityObject.description=value;
1003 [DefaultValue(null)]
1004 public string AccessibleName {
1006 return AccessibilityObject.Name;
1010 AccessibilityObject.Name=value;
1014 [DefaultValue(AccessibleRole.Default)]
1015 public AccessibleRole AccessibleRole {
1017 return AccessibilityObject.role;
1021 AccessibilityObject.role=value;
1025 [DefaultValue(false)]
1026 public virtual bool AllowDrop {
1028 return XplatUI.State.DropTarget;
1033 XplatUI.State.DropTarget=value;
1039 [RefreshProperties(RefreshProperties.Repaint)]
1040 [DefaultValue(AnchorStyles.Top | AnchorStyles.Left)]
1041 public virtual AnchorStyles Anchor {
1043 return anchor_style;
1049 if (parent != null) {
1050 parent.PerformLayout(this, "Parent");
1056 public virtual Color BackColor {
1058 if (background_color.IsEmpty) {
1060 return parent.BackColor;
1062 return DefaultBackColor;
1064 return background_color;
1068 background_color=value;
1069 if (this.IsHandleCreated) {
1070 XplatUI.SetWindowBackground(this.window.Handle, value);
1072 SetChildColor(this);
1073 OnBackColorChanged(EventArgs.Empty);
1079 [DefaultValue(null)]
1080 public virtual Image BackgroundImage {
1082 return background_image;
1086 if (background_image!=value) {
1087 background_image=value;
1088 OnBackgroundImageChanged(EventArgs.Empty);
1093 [EditorBrowsable(EditorBrowsableState.Advanced)]
1095 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1096 public virtual BindingContext BindingContext {
1098 if (binding_context != null)
1099 return binding_context;
1102 binding_context = Parent.BindingContext;
1103 return binding_context;
1106 if (binding_context != value) {
1107 binding_context = value;
1108 OnBindingContextChanged(EventArgs.Empty);
1113 [EditorBrowsable(EditorBrowsableState.Advanced)]
1115 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1118 return bounds.Y+bounds.Height;
1122 [EditorBrowsable(EditorBrowsableState.Advanced)]
1124 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1125 public Rectangle Bounds {
1131 SetBoundsCore(value.Left, value.Top, value.Width, value.Height, BoundsSpecified.All);
1135 [EditorBrowsable(EditorBrowsableState.Advanced)]
1137 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1138 public bool CanFocus {
1140 if (Visible && is_enabled && GetStyle(ControlStyles.Selectable)) {
1147 [EditorBrowsable(EditorBrowsableState.Advanced)]
1149 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1150 public bool CanSelect {
1154 if (!GetStyle(ControlStyles.Selectable) || this.parent == null) {
1158 parent = this.parent;
1159 while (parent != null) {
1160 if (!parent.is_visible || !parent.is_enabled) {
1164 parent = parent.parent;
1170 [EditorBrowsable(EditorBrowsableState.Advanced)]
1172 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1173 public bool Capture {
1175 return this.is_captured;
1179 if (this.IsHandleCreated) {
1180 if (value && !is_captured) {
1182 XplatUI.GrabWindow(this.window.Handle, IntPtr.Zero);
1183 } else if (!value && is_captured) {
1184 XplatUI.UngrabWindow(this.window.Handle);
1185 is_captured = false;
1191 [DefaultValue(true)]
1192 public bool CausesValidation {
1194 return this.causes_validation;
1198 if (this.causes_validation != value) {
1199 causes_validation = value;
1200 OnCausesValidationChanged(EventArgs.Empty);
1205 [EditorBrowsable(EditorBrowsableState.Advanced)]
1207 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1208 public Rectangle ClientRectangle {
1210 client_rect.Width = client_size.Width;
1211 client_rect.Height = client_size.Height;
1216 [EditorBrowsable(EditorBrowsableState.Advanced)]
1218 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1219 public Size ClientSize {
1222 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1223 return ((Form)this).form_parent_window.ClientSize;
1231 this.SetClientSizeCore(value.Width, value.Height);
1235 [EditorBrowsable(EditorBrowsableState.Advanced)]
1237 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1238 [DescriptionAttribute("ControlCompanyNameDescr")]
1239 public String CompanyName {
1241 return "Mono Project, Novell, Inc.";
1245 [EditorBrowsable(EditorBrowsableState.Advanced)]
1247 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1248 public bool ContainsFocus {
1254 for (int i=0; i < child_controls.Count; i++) {
1255 if (child_controls[i].ContainsFocus) {
1263 [DefaultValue(null)]
1264 public virtual ContextMenu ContextMenu {
1266 return context_menu;
1270 if (context_menu != value) {
1271 context_menu = value;
1272 OnContextMenuChanged(EventArgs.Empty);
1278 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
1279 public ControlCollection Controls {
1281 return this.child_controls;
1285 [EditorBrowsable(EditorBrowsableState.Advanced)]
1287 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1288 public bool Created {
1290 if (!this.is_disposed && (this.window.Handle != IntPtr.Zero)) {
1297 [AmbientValue(null)]
1298 public virtual Cursor Cursor {
1300 if (cursor != null) {
1304 if (parent != null) {
1305 return parent.Cursor;
1308 return Cursors.Default;
1312 if (cursor != value) {
1317 pt = Cursor.Position;
1318 if (bounds.Contains(pt)) {
1319 if (GetChildAtPoint(pt) == null) {
1320 if (cursor != null) {
1321 XplatUI.SetCursor(window.Handle, cursor.handle);
1323 if (parent != null) {
1324 XplatUI.SetCursor(window.Handle, parent.Cursor.handle);
1326 XplatUI.SetCursor(window.Handle, Cursors.def.handle);
1332 OnCursorChanged(EventArgs.Empty);
1338 [EditorBrowsable(EditorBrowsableState.Advanced)]
1340 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1341 public ControlBindingsCollection DataBindings {
1343 if (data_bindings == null)
1344 data_bindings = new ControlBindingsCollection (this);
1345 return data_bindings;
1349 [EditorBrowsable(EditorBrowsableState.Advanced)]
1351 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1352 public virtual Rectangle DisplayRectangle {
1354 return ClientRectangle;
1358 [EditorBrowsable(EditorBrowsableState.Advanced)]
1360 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1361 public bool Disposing {
1368 [RefreshProperties(RefreshProperties.Repaint)]
1369 [DefaultValue(DockStyle.None)]
1370 public virtual DockStyle Dock {
1376 if (dock_style == value) {
1382 if (parent != null) {
1383 parent.PerformLayout(this, "Parent");
1386 OnDockChanged(EventArgs.Empty);
1392 public bool Enabled {
1398 if (is_enabled == value) {
1404 OnEnabledChanged (EventArgs.Empty);
1408 [EditorBrowsable(EditorBrowsableState.Advanced)]
1410 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1411 public virtual bool Focused {
1413 return this.has_focus;
1418 [AmbientValue(null)]
1420 public virtual Font Font {
1426 if (Parent != null && Parent.Font != null) {
1434 if (font != null && font.Equals (value)) {
1440 OnFontChanged (EventArgs.Empty);
1445 public virtual Color ForeColor {
1447 if (foreground_color.IsEmpty) {
1449 return parent.ForeColor;
1451 return DefaultForeColor;
1453 return foreground_color;
1457 if (foreground_color != value) {
1458 foreground_color=value;
1460 OnForeColorChanged(EventArgs.Empty);
1467 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1468 public IntPtr Handle { // IWin32Window
1470 if (!IsHandleCreated) {
1473 return window.Handle;
1477 [EditorBrowsable(EditorBrowsableState.Advanced)]
1479 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1480 public bool HasChildren {
1482 if (this.child_controls.Count>0) {
1489 [EditorBrowsable(EditorBrowsableState.Always)]
1491 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1494 return this.bounds.Height;
1498 SetBoundsCore(bounds.X, bounds.Y, bounds.Width, value, BoundsSpecified.Height);
1502 [AmbientValue(ImeMode.Inherit)]
1504 public ImeMode ImeMode {
1510 if (ime_mode != value) {
1513 OnImeModeChanged(EventArgs.Empty);
1518 [EditorBrowsable(EditorBrowsableState.Advanced)]
1520 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1521 public bool InvokeRequired { // ISynchronizeInvoke
1523 if (creator_thread!=Thread.CurrentThread) {
1530 [EditorBrowsable(EditorBrowsableState.Advanced)]
1532 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1533 public bool IsAccessible {
1535 return is_accessible;
1539 is_accessible = value;
1543 [EditorBrowsable(EditorBrowsableState.Advanced)]
1545 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1546 public bool IsDisposed {
1548 return this.is_disposed;
1552 [EditorBrowsable(EditorBrowsableState.Advanced)]
1554 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1555 public bool IsHandleCreated {
1557 if ((window!=null) && (window.Handle!=IntPtr.Zero)) {
1565 [EditorBrowsable(EditorBrowsableState.Always)]
1567 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1570 return this.bounds.X;
1574 SetBoundsCore(value, bounds.Y, bounds.Width, bounds.Height, BoundsSpecified.X);
1579 public Point Location {
1581 return new Point(bounds.X, bounds.Y);
1585 SetBoundsCore(value.X, value.Y, bounds.Width, bounds.Height, BoundsSpecified.Location);
1590 public string Name {
1601 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1602 public Control Parent {
1608 if (value == this) {
1609 throw new ArgumentException("A circular control reference has been made. A control cannot be owned or parented to itself.");
1612 if (parent!=value) {
1614 parent.Controls.Remove(this);
1620 if (!parent.Controls.Contains(this)) {
1621 parent.Controls.Add(this);
1624 XplatUI.SetParent(Handle, value.Handle);
1628 OnParentChanged(EventArgs.Empty);
1633 [EditorBrowsable(EditorBrowsableState.Advanced)]
1635 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1636 public string ProductName {
1638 return "Novell Mono MWF";
1642 [EditorBrowsable(EditorBrowsableState.Advanced)]
1644 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1645 public string ProductVersion {
1647 return "1.1.4322.573";
1651 [EditorBrowsable(EditorBrowsableState.Advanced)]
1653 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1654 public bool RecreatingHandle {
1656 return is_recreating;
1660 [EditorBrowsable(EditorBrowsableState.Advanced)]
1662 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1663 public Region Region {
1665 return new Region(this.bounds);
1672 g = this.CreateGraphics();
1673 r = value.GetBounds(g);
1675 SetBounds((int)r.X, (int)r.Y, (int)r.Width, (int)r.Height);
1681 [EditorBrowsable(EditorBrowsableState.Advanced)]
1683 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1686 return this.bounds.X+this.bounds.Width;
1690 [AmbientValue(RightToLeft.Inherit)]
1692 public virtual RightToLeft RightToLeft {
1694 return right_to_left;
1698 if (value != right_to_left) {
1699 right_to_left = value;
1700 OnRightToLeftChanged(EventArgs.Empty);
1705 [EditorBrowsable(EditorBrowsableState.Advanced)]
1706 public override ISite Site {
1719 return new Size(Width, Height);
1723 SetBoundsCore(bounds.X, bounds.Y, value.Width, value.Height, BoundsSpecified.Size);
1728 [MergableProperty(false)]
1729 public int TabIndex {
1731 if (tab_index != -1) {
1738 if (tab_index != value) {
1740 OnTabIndexChanged(EventArgs.Empty);
1746 [DefaultValue(true)]
1747 public bool TabStop {
1753 if (tab_stop != value) {
1755 OnTabStopChanged(EventArgs.Empty);
1760 [Localizable(false)]
1762 [TypeConverter(typeof(StringConverter))]
1763 [DefaultValue(null)]
1770 control_tag = value;
1776 [BindableAttribute(true)]
1777 public virtual string Text {
1783 if (value == null) {
1784 value = String.Empty;
1789 XplatUI.Text(Handle, text);
1790 // FIXME: Do we need a Refresh() here?
1791 OnTextChanged (EventArgs.Empty);
1796 [EditorBrowsable(EditorBrowsableState.Always)]
1798 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1801 return this.bounds.Y;
1805 SetBoundsCore(bounds.X, value, bounds.Width, bounds.Height, BoundsSpecified.Y);
1809 [EditorBrowsable(EditorBrowsableState.Advanced)]
1811 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1812 public Control TopLevelControl {
1816 while (p.parent != null) {
1825 public bool Visible {
1829 } else if (parent != null) {
1830 return parent.Visible;
1837 SetVisibleCore(value);
1841 [EditorBrowsable(EditorBrowsableState.Always)]
1843 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1846 return this.bounds.Width;
1850 SetBoundsCore(bounds.X, bounds.Y, value, bounds.Height, BoundsSpecified.Width);
1854 [EditorBrowsable(EditorBrowsableState.Never)]
1856 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1857 public IWindowTarget WindowTarget {
1866 #endregion // Public Instance Properties
1868 #region Protected Instance Properties
1869 protected virtual CreateParams CreateParams {
1871 CreateParams create_params = new CreateParams();
1873 create_params.Caption = Text;
1874 create_params.X = Left;
1875 create_params.Y = Top;
1876 create_params.Width = Width;
1877 create_params.Height = Height;
1879 create_params.ClassName = XplatUI.DefaultClassName;
1880 create_params.ClassStyle = 0;
1881 create_params.ExStyle = 0;
1882 create_params.Param = 0;
1885 create_params.Parent = parent.Handle;
1888 create_params.Style = (int)WindowStyles.WS_CHILD | (int)WindowStyles.WS_CLIPCHILDREN | (int)WindowStyles.WS_CLIPSIBLINGS;
1891 create_params.Style |= (int)WindowStyles.WS_VISIBLE;
1894 return create_params;
1898 protected virtual ImeMode DefaultImeMode {
1900 return ImeMode.Inherit;
1904 protected virtual Size DefaultSize {
1906 return new Size(100, 23);
1910 protected int FontHeight {
1920 protected bool RenderRightToLeft {
1922 return (this.right_to_left == RightToLeft.Yes);
1926 protected bool ResizeRedraw {
1928 return GetStyle(ControlStyles.ResizeRedraw);
1932 SetStyle(ControlStyles.ResizeRedraw, value);
1936 [EditorBrowsable(EditorBrowsableState.Advanced)]
1938 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1939 protected virtual bool ShowFocusCues {
1945 [EditorBrowsable(EditorBrowsableState.Advanced)]
1947 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1948 protected bool ShowKeyboardCues {
1953 #endregion // Protected Instance Properties
1955 #region Public Static Methods
1956 [EditorBrowsable(EditorBrowsableState.Advanced)]
1957 public static Control FromChildHandle(IntPtr handle) {
1958 IEnumerator control = Control.controls.GetEnumerator();
1960 while (control.MoveNext()) {
1961 if (((Control)control.Current).window.Handle == handle) {
1963 if (((Control)control.Current).Parent != null) {
1964 return ((Control)control.Current).Parent;
1971 [EditorBrowsable(EditorBrowsableState.Advanced)]
1972 public static Control FromHandle(IntPtr handle) {
1973 IEnumerator control = Control.controls.GetEnumerator();
1975 while (control.MoveNext()) {
1976 if (((Control)control.Current).window.Handle == handle) {
1978 return ((Control)control.Current);
1984 public static bool IsMnemonic(char charCode, string text) {
1987 amp = text.IndexOf('&');
1990 if (amp + 1 < text.Length) {
1991 if (text[amp + 1] != '&') {
1992 if (Char.ToUpper(charCode) == Char.ToUpper(text.ToCharArray(amp + 1, 1)[0])) {
2002 #region Protected Static Methods
2003 [EditorBrowsable(EditorBrowsableState.Advanced)]
2004 protected static bool ReflectMessage(IntPtr hWnd, ref Message m) {
2007 c = Control.FromHandle(hWnd);
2017 #region Public Instance Methods
2018 [EditorBrowsable(EditorBrowsableState.Advanced)]
2019 public IAsyncResult BeginInvoke(Delegate method) {
2020 return BeginInvokeInternal(method, null);
2023 [EditorBrowsable(EditorBrowsableState.Advanced)]
2024 public IAsyncResult BeginInvoke (Delegate method, object[] args) {
2025 return BeginInvokeInternal (method, args);
2028 public void BringToFront() {
2029 if ((parent != null) && (parent.child_controls[0]!=this)) {
2030 if (parent.child_controls.Contains(this)) {
2031 parent.child_controls.SetChildIndex(this, 0);
2035 XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, true, false);
2037 if (parent != null) {
2042 public bool Contains(Control ctl) {
2043 while (ctl != null) {
2052 public void CreateControl() {
2054 if (!IsHandleCreated) {
2058 if (!create_handled) {
2059 create_handled = true;
2063 for (int i=0; i<child_controls.Count; i++) {
2064 child_controls[i].CreateControl();
2068 public Graphics CreateGraphics() {
2069 if (!IsHandleCreated) {
2070 this.CreateControl();
2072 return Graphics.FromHwnd(this.window.Handle);
2075 [MonoTODO("Come up with cross platform drag-drop driver interface")]
2076 public DragDropEffects DoDragDrop(object data, DragDropEffects allowedEffects) {
2077 return DragDropEffects.None;
2080 [EditorBrowsable(EditorBrowsableState.Advanced)]
2081 public object EndInvoke (IAsyncResult async_result) {
2082 AsyncMethodResult result = (AsyncMethodResult) async_result;
2083 return result.EndInvoke ();
2086 public Form FindForm() {
2099 public bool Focus() {
2100 if (IsHandleCreated && !has_focus) {
2102 XplatUI.SetFocus(window.Handle);
2107 public Control GetChildAtPoint(Point pt) {
2108 // Microsoft's version of this function doesn't seem to work, so I can't check
2109 // if we only consider children or also grandchildren, etc.
2110 // I'm gonna say 'children only'
2111 for (int i=0; i<child_controls.Count; i++) {
2112 if (child_controls[i].Bounds.Contains(pt)) {
2113 return child_controls[i];
2119 public IContainerControl GetContainerControl() {
2120 Control current = this;
2122 while (current!=null) {
2123 if ((current is IContainerControl) && ((current.control_style & ControlStyles.ContainerControl)!=0)) {
2124 return (IContainerControl)current;
2126 current = current.parent;
2131 public Control GetNextControl(Control ctl, bool forward) {
2132 // If we're not a container we don't play
2133 if (!(this is IContainerControl) && !this.GetStyle(ControlStyles.ContainerControl)) {
2137 // If ctl is not contained by this, we start at the first child of this
2138 if (!this.Contains(ctl)) {
2142 // Search through our controls, starting at ctl, stepping into children as we encounter them
2143 // try to find the control with the tabindex closest to our own, or, if we're looking into
2144 // child controls, the one with the smallest tabindex
2146 return FindControlForward(this, ctl);
2148 return FindControlBackward(this, ctl);
2151 public void Hide() {
2152 this.Visible = false;
2155 public void Invalidate() {
2156 Invalidate(ClientRectangle, false);
2159 public void Invalidate(bool invalidateChildren) {
2160 Invalidate(ClientRectangle, invalidateChildren);
2163 public void Invalidate(System.Drawing.Rectangle rc) {
2164 Invalidate(rc, false);
2167 public void Invalidate(System.Drawing.Rectangle rc, bool invalidateChildren) {
2168 if (!IsHandleCreated || !Visible) {
2172 NotifyInvalidate(rc);
2174 XplatUI.Invalidate(Handle, rc, false);
2176 if (invalidateChildren) {
2177 for (int i=0; i<child_controls.Count; i++) child_controls[i].Invalidate();
2179 OnInvalidated(new InvalidateEventArgs(rc));
2182 public void Invalidate(System.Drawing.Region region) {
2183 Invalidate(region, false);
2186 [MonoTODO("Figure out if GetRegionScans is usable")]
2187 public void Invalidate(System.Drawing.Region region, bool invalidateChildren) {
2188 throw new NotImplementedException();
2190 // FIXME - should use the GetRegionScans function of the region to invalidate each area
2191 //if (invalidateChildren) {
2192 // for (int i=0; i<child_controls.Count; i++) child_controls[i].Invalidate();
2196 public object Invoke (Delegate method) {
2197 return Invoke(method, null);
2200 public object Invoke (Delegate method, object[] args) {
2201 if (!this.InvokeRequired) {
2202 return method.DynamicInvoke(args);
2205 IAsyncResult result = BeginInvoke (method, args);
2206 return EndInvoke(result);
2209 [EditorBrowsable(EditorBrowsableState.Advanced)]
2210 public void PerformLayout() {
2211 PerformLayout(null, null);
2214 [EditorBrowsable(EditorBrowsableState.Advanced)]
2215 public void PerformLayout(Control affectedControl, string affectedProperty) {
2216 LayoutEventArgs levent = new LayoutEventArgs(affectedControl, affectedProperty);
2218 if (layout_suspended>0) {
2219 layout_pending = true;
2223 layout_pending = false;
2225 // Prevent us from getting messed up
2228 // Perform all Dock and Anchor calculations
2231 AnchorStyles anchor;
2236 space=this.DisplayRectangle;
2237 if (prev_size != Size.Empty) {
2238 diff_width = space.Width - prev_size.Width;
2239 diff_height = space.Height - prev_size.Height;
2245 // Deal with docking; go through in reverse, MS docs say that lowest Z-order is closest to edge
2246 for (int i = child_controls.Count - 1; i >= 0; i--) {
2247 child=child_controls[i];
2248 switch (child.Dock) {
2249 case DockStyle.None: {
2254 case DockStyle.Left: {
2255 child.SetBounds(space.Left, space.Y, child.Width, space.Height);
2256 space.X+=child.Width;
2257 space.Width-=child.Width;
2261 case DockStyle.Top: {
2262 child.SetBounds(space.Left, space.Y, space.Width, child.Height);
2263 space.Y+=child.Height;
2264 space.Height-=child.Height;
2268 case DockStyle.Right: {
2269 child.SetBounds(space.Right-child.Width, space.Y, child.Width, space.Height);
2270 space.Width-=child.Width;
2274 case DockStyle.Bottom: {
2275 child.SetBounds(space.Left, space.Bottom-child.Height, space.Width, child.Height);
2276 space.Height-=child.Height;
2282 for (int i = child_controls.Count - 1; i >= 0; i--) {
2283 child=child_controls[i];
2285 if (child.Dock == DockStyle.Fill) {
2286 child.SetBounds(space.Left, space.Top, space.Width, space.Height);
2292 space=this.DisplayRectangle;
2294 // Deal with anchoring
2295 for (int i=0; i < child_controls.Count; i++) {
2301 child=child_controls[i];
2302 anchor=child.Anchor;
2307 height=child.Height;
2309 // If the control is docked we don't need to do anything
2310 if (child.Dock != DockStyle.None) {
2314 if ((anchor & AnchorStyles.Left) !=0 ) {
2315 if ((anchor & AnchorStyles.Right) != 0) {
2316 // Anchoring to left and right
2317 width=width+diff_width;
2321 } else if ((anchor & AnchorStyles.Right) != 0) {
2327 if ((anchor & AnchorStyles.Top) !=0 ) {
2328 if ((anchor & AnchorStyles.Bottom) != 0) {
2329 height+=diff_height;
2333 } else if ((anchor & AnchorStyles.Bottom) != 0) {
2348 child.SetBounds(left, top, width, height);
2351 // Let everyone know
2355 // Need to make sure we decremend layout_suspended
2361 public Point PointToClient (Point p) {
2365 XplatUI.ScreenToClient (Handle, ref x, ref y);
2367 return new Point (x, y);
2370 public Point PointToScreen(Point p) {
2374 XplatUI.ClientToScreen(Handle, ref x, ref y);
2376 return new Point(x, y);
2379 public virtual bool PreProcessMessage(ref Message msg) {
2382 if ((msg.Msg == (int)Msg.WM_KEYDOWN) || (msg.Msg == (int)Msg.WM_SYSKEYDOWN)) {
2383 key_data = (Keys)msg.WParam.ToInt32();
2384 if (!ProcessCmdKey(ref msg, key_data)) {
2385 if (IsInputKey(key_data)) {
2389 return ProcessDialogKey(key_data);
2393 } else if (msg.Msg == (int)Msg.WM_CHAR) {
2394 if (IsInputChar((char)msg.WParam)) {
2397 } else if (msg.Msg == (int)Msg.WM_SYSCHAR) {
2398 if (IsInputChar((char)msg.WParam)) {
2401 return ProcessDialogChar((char)msg.WParam);
2406 public Rectangle RectangleToClient(Rectangle r) {
2407 return new Rectangle(PointToClient(r.Location), r.Size);
2410 public Rectangle RectangleToScreen(Rectangle r) {
2411 return new Rectangle(PointToScreen(r.Location), r.Size);
2414 public virtual void Refresh() {
2415 if (IsHandleCreated == true) {
2417 XplatUI.UpdateWindow(window.Handle);
2421 [EditorBrowsable(EditorBrowsableState.Never)]
2422 public virtual void ResetBackColor() {
2423 background_color = Color.Empty;
2426 #if haveDataBindings
2427 [EditorBrowsable(EditorBrowsableState.Never)]
2429 public void ResetBindings() {
2434 [EditorBrowsable(EditorBrowsableState.Never)]
2435 public virtual void ResetCursor() {
2439 [EditorBrowsable(EditorBrowsableState.Never)]
2440 public virtual void ResetFont() {
2444 [EditorBrowsable(EditorBrowsableState.Never)]
2445 public virtual void ResetForeColor() {
2446 foreground_color = Color.Empty;
2449 [EditorBrowsable(EditorBrowsableState.Never)]
2450 public void ResetImeMode() {
2451 ime_mode = DefaultImeMode;
2454 [EditorBrowsable(EditorBrowsableState.Never)]
2455 public virtual void ResetRightToLeft() {
2456 right_to_left = RightToLeft.Inherit;
2459 public virtual void ResetText() {
2463 public void ResumeLayout() {
2464 ResumeLayout (true);
2467 public void ResumeLayout(bool performLayout) {
2470 if (layout_suspended > 0) {
2474 if (performLayout || layout_pending) {
2479 public void Scale(float ratio) {
2480 ScaleCore(ratio, ratio);
2483 public void Scale(float dx, float dy) {
2487 public void Select() {
2488 Select(false, false);
2491 public bool SelectNextControl(Control ctl, bool forward, bool tabStopOnly, bool nested, bool wrap) {
2496 c = GetNextControl(c, forward);
2505 if (c.CanSelect && ((c.parent == ctl.parent) || nested) && (c.tab_stop || !tabStopOnly)) {
2509 } while (c != ctl); // If we wrap back to ourselves we stop
2514 public void SendToBack() {
2515 if ((parent != null) && (parent.child_controls[parent.child_controls.Count-1]!=this)) {
2516 if (parent.child_controls.Contains(this)) {
2517 parent.child_controls.SetChildIndex(this, parent.child_controls.Count);
2521 XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, false, true);
2522 if (parent != null) {
2527 public void SetBounds(int x, int y, int width, int height) {
2528 SetBoundsCore(x, y, width, height, BoundsSpecified.All);
2531 public void SetBounds(int x, int y, int width, int height, BoundsSpecified specified) {
2532 SetBoundsCore(x, y, width, height, specified);
2535 public void Show() {
2536 if (!IsHandleCreated) {
2537 this.CreateControl();
2543 public void SuspendLayout() {
2547 public void Update() {
2548 needs_redraw = true;
2549 XplatUI.UpdateWindow(window.Handle);
2551 #endregion // Public Instance Methods
2553 #region Protected Instance Methods
2554 [EditorBrowsable(EditorBrowsableState.Advanced)]
2555 [MonoTODO("Implement this and tie it into Control.ControlAccessibleObject.NotifyClients")]
2556 protected void AccessibilityNotifyClients(AccessibleEvents accEvent, int childID) {
2557 throw new NotImplementedException();
2560 [EditorBrowsable(EditorBrowsableState.Advanced)]
2561 protected virtual AccessibleObject CreateAccessibilityInstance() {
2562 return new Control.ControlAccessibleObject(this);
2565 [EditorBrowsable(EditorBrowsableState.Advanced)]
2566 protected virtual ControlCollection CreateControlsInstance() {
2567 return new ControlCollection(this);
2570 [EditorBrowsable(EditorBrowsableState.Advanced)]
2571 protected virtual void CreateHandle() {
2573 throw new ObjectDisposedException(Name);
2576 if (IsHandleCreated) {
2580 window.CreateHandle(CreateParams);
2582 // Find out where the window manager placed us
2586 if (window.Handle!=IntPtr.Zero) {
2587 if (!controls.Contains(window.Handle)) {
2591 creator_thread = Thread.CurrentThread;
2593 XplatUI.SetWindowBackground(window.Handle, this.BackColor);
2595 OnHandleCreated(EventArgs.Empty);
2599 [EditorBrowsable(EditorBrowsableState.Advanced)]
2600 protected virtual void DefWndProc(ref Message m) {
2601 window.DefWndProc(ref m);
2604 [EditorBrowsable(EditorBrowsableState.Advanced)]
2605 protected virtual void DestroyHandle() {
2606 if (IsHandleCreated) {
2607 // Destroy our children before we destroy ourselves, to prevent them from
2608 // being implictly (without us knowing) destroyed
2609 for (int i=0; i < child_controls.Count; i++) {
2610 child_controls[i].DestroyHandle();
2614 if (window != null) {
2615 window.DestroyHandle();
2617 OnHandleDestroyed(EventArgs.Empty);
2621 protected bool GetStyle(ControlStyles flag) {
2622 return (control_style & flag) != 0;
2625 protected bool GetTopLevel() {
2629 [EditorBrowsable(EditorBrowsableState.Advanced)]
2630 protected virtual void InitLayout() {
2631 if (parent != null) {
2632 parent.PerformLayout(this, "parent");
2636 [EditorBrowsable(EditorBrowsableState.Advanced)]
2637 protected void InvokeGotFocus(Control toInvoke, EventArgs e) {
2638 toInvoke.OnGotFocus(e);
2641 [EditorBrowsable(EditorBrowsableState.Advanced)]
2642 protected void InvokeLostFocus(Control toInvoke, EventArgs e) {
2643 toInvoke.OnLostFocus(e);
2646 [EditorBrowsable(EditorBrowsableState.Advanced)]
2647 protected void InvokeOnClick(Control toInvoke, EventArgs e) {
2648 toInvoke.OnClick(e);
2651 protected void InvokePaint(Control toInvoke, PaintEventArgs e) {
2652 toInvoke.OnPaint(e);
2655 protected void InvokePaintBackground(Control toInvoke, PaintEventArgs e) {
2656 toInvoke.OnPaintBackground(e);
2659 protected virtual bool IsInputChar (char charCode) {
2660 if (parent != null) {
2661 return parent.IsInputChar(charCode);
2667 protected virtual bool IsInputKey (Keys keyData) {
2668 // Doc says this one calls IsInputChar; not sure what to do with that
2672 [EditorBrowsable(EditorBrowsableState.Advanced)]
2673 protected virtual void NotifyInvalidate(Rectangle invalidatedArea) {
2677 protected virtual bool ProcessCmdKey(ref Message msg, Keys keyData) {
2678 if ((context_menu != null) && context_menu.ProcessCmdKey(ref msg, keyData)) {
2682 if (parent != null) {
2683 return parent.ProcessCmdKey(ref msg, keyData);
2689 protected virtual bool ProcessDialogChar(char charCode) {
2690 if (parent != null) {
2691 return parent.ProcessDialogChar (charCode);
2697 protected virtual bool ProcessDialogKey (Keys keyData) {
2698 if (parent != null) {
2699 return parent.ProcessDialogKey (keyData);
2705 protected virtual bool ProcessKeyEventArgs (ref Message msg)
2707 KeyEventArgs key_event;
2710 case (int)Msg.WM_KEYDOWN: {
2711 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
2712 OnKeyDown (key_event);
2713 return key_event.Handled;
2715 case (int)Msg.WM_KEYUP: {
2716 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
2717 OnKeyUp (key_event);
2718 return key_event.Handled;
2721 case (int)Msg.WM_CHAR: {
2722 KeyPressEventArgs key_press_event;
2724 key_press_event = new KeyPressEventArgs((char)msg.WParam);
2725 OnKeyPress(key_press_event);
2726 return key_press_event.Handled;
2737 protected internal virtual bool ProcessKeyMessage(ref Message msg) {
2738 if (parent != null) {
2739 if (parent.ProcessKeyPreview(ref msg)) {
2747 protected virtual bool ProcessKeyPreview(ref Message msg) {
2748 if (parent != null) {
2749 return parent.ProcessKeyPreview(ref msg);
2755 protected virtual bool ProcessMnemonic(char charCode) {
2760 [EditorBrowsable(EditorBrowsableState.Advanced)]
2761 protected void RaiseDragEvent(object key, DragEventArgs e) {
2765 [EditorBrowsable(EditorBrowsableState.Advanced)]
2766 protected void RaiseKeyEvent(object key, KeyEventArgs e) {
2770 [EditorBrowsable(EditorBrowsableState.Advanced)]
2771 protected void RaiseMouseEvent(object key, MouseEventArgs e) {
2775 [EditorBrowsable(EditorBrowsableState.Advanced)]
2776 protected void RaisePaintEvent(object key, PaintEventArgs e) {
2780 [EditorBrowsable(EditorBrowsableState.Advanced)]
2781 protected void RecreateHandle() {
2782 IEnumerator child = child_controls.GetEnumerator();
2786 if (IsHandleCreated) {
2792 while (child.MoveNext()) {
2793 ((Control)child.Current).RecreateHandle();
2799 is_recreating = false;
2802 [EditorBrowsable(EditorBrowsableState.Advanced)]
2803 protected void ResetMouseEventArgs() {
2807 [EditorBrowsable(EditorBrowsableState.Advanced)]
2808 protected ContentAlignment RtlTranslateAlignment(ContentAlignment align) {
2809 if (right_to_left == RightToLeft.No) {
2814 case ContentAlignment.TopLeft: {
2815 return ContentAlignment.TopRight;
2818 case ContentAlignment.TopRight: {
2819 return ContentAlignment.TopLeft;
2822 case ContentAlignment.MiddleLeft: {
2823 return ContentAlignment.MiddleRight;
2826 case ContentAlignment.MiddleRight: {
2827 return ContentAlignment.MiddleLeft;
2830 case ContentAlignment.BottomLeft: {
2831 return ContentAlignment.BottomRight;
2834 case ContentAlignment.BottomRight: {
2835 return ContentAlignment.BottomLeft;
2839 // if it's center it doesn't change
2845 [EditorBrowsable(EditorBrowsableState.Advanced)]
2846 protected HorizontalAlignment RtlTranslateAlignment(HorizontalAlignment align) {
2847 if ((right_to_left == RightToLeft.No) || (align == HorizontalAlignment.Center)) {
2851 if (align == HorizontalAlignment.Left) {
2852 return HorizontalAlignment.Right;
2855 // align must be HorizontalAlignment.Right
2856 return HorizontalAlignment.Left;
2859 [EditorBrowsable(EditorBrowsableState.Advanced)]
2860 protected LeftRightAlignment RtlTranslateAlignment(LeftRightAlignment align) {
2861 if (right_to_left == RightToLeft.No) {
2865 if (align == LeftRightAlignment.Left) {
2866 return LeftRightAlignment.Right;
2869 // align must be LeftRightAlignment.Right;
2870 return LeftRightAlignment.Left;
2873 [EditorBrowsable(EditorBrowsableState.Advanced)]
2874 protected ContentAlignment RtlTranslateContent(ContentAlignment align) {
2875 return RtlTranslateAlignment(align);
2878 [EditorBrowsable(EditorBrowsableState.Advanced)]
2879 protected HorizontalAlignment RtlTranslateHorizontal(HorizontalAlignment align) {
2880 return RtlTranslateAlignment(align);
2883 [EditorBrowsable(EditorBrowsableState.Advanced)]
2884 protected LeftRightAlignment RtlTranslateLeftRight(LeftRightAlignment align) {
2885 return RtlTranslateAlignment(align);
2888 [EditorBrowsable(EditorBrowsableState.Advanced)]
2889 protected virtual void ScaleCore(float dx, float dy) {
2895 location = new Point((int)(Left * dx), (int)(Top * dy));
2896 size = this.ClientSize;
2899 if (!GetStyle(ControlStyles.FixedWidth)) {
2900 size.Width = (int)(size.Width * dx);
2903 if (!GetStyle(ControlStyles.FixedHeight)) {
2904 size.Height = (int)(size.Height * dy);
2907 Location = location;
2910 /* Now scale our children */
2911 for (int i=0; i < child_controls.Count; i++) {
2912 child_controls[i].Scale(dx, dy);
2918 protected virtual void Select(bool directed, bool forward) {
2923 // Select this control
2928 if (parent == null) {
2932 // FIXME - this thing is doing the wrong stuff, needs to be similar to SelectNextControl
2934 index = parent.child_controls.IndexOf(this);
2939 if ((index+1) < parent.child_controls.Count) {
2948 index = parent.child_controls.Count-1;
2951 result = Select(parent.child_controls[index]);
2952 } while (!result && parent.child_controls[index] != this);
2955 [EditorBrowsable(EditorBrowsableState.Advanced)]
2956 protected virtual void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
2957 // SetBoundsCore updates the Win32 control itself. UpdateBounds updates the controls variables and fires events, I'm guessing - pdb
2958 if ((specified & BoundsSpecified.X) != BoundsSpecified.X) {
2962 if ((specified & BoundsSpecified.Y) != BoundsSpecified.Y) {
2966 if ((specified & BoundsSpecified.Width) != BoundsSpecified.Width) {
2970 if ((specified & BoundsSpecified.Height) != BoundsSpecified.Height) {
2974 if (IsHandleCreated) {
2975 XplatUI.SetWindowPos(Handle, x, y, width, height);
2977 UpdateBounds(x, y, width, height);
2980 [EditorBrowsable(EditorBrowsableState.Advanced)]
2981 protected virtual void SetClientSizeCore(int x, int y) {
2982 // Calculate the actual window size from the client size (it usually stays the same or grows)
2983 Rectangle ClientRect;
2984 Rectangle WindowRect;
2987 ClientRect = new Rectangle(0, 0, x, y);
2988 cp = this.CreateParams;
2990 if (XplatUI.CalculateWindowRect(Handle, ref ClientRect, cp.Style, cp.ExStyle, IntPtr.Zero, out WindowRect)==false) {
2994 SetBoundsCore(bounds.X, bounds.Y, WindowRect.Width, WindowRect.Height, BoundsSpecified.Size);
2997 [EditorBrowsable(EditorBrowsableState.Advanced)]
2998 protected void SetStyle(ControlStyles flag, bool value) {
3000 control_style |= flag;
3002 control_style &= ~flag;
3004 OnStyleChanged(EventArgs.Empty);
3007 protected void SetTopLevel(bool value) {
3008 if ((GetTopLevel() != value) && (parent != null)) {
3009 throw new Exception();
3013 if (value == true) {
3023 is_toplevel = value;
3026 protected virtual void SetVisibleCore(bool value) {
3027 if (value!=is_visible) {
3029 XplatUI.SetVisible(Handle, value);
3030 // Explicitly move Toplevel windows to where we want them;
3031 // apparently moving unmapped toplevel windows doesn't work
3032 if (is_visible && (this is Form)) {
3033 XplatUI.SetWindowPos(window.Handle, bounds.X, bounds.Y, bounds.Width, bounds.Height);
3035 OnVisibleChanged(EventArgs.Empty);
3038 if (dc_mem != null) {
3043 if (bmp_mem != null) {
3048 this.CreateBuffers(bounds.Width, bounds.Height);
3053 if (value == false && parent != null) {
3056 // Need to start at parent, GetContainerControl might return ourselves if we're a container
3057 container = (Control)parent.GetContainerControl();
3058 if (container != null) {
3059 container.SelectNextControl(this, true, true, true, true);
3063 if (parent != null) {
3064 parent.PerformLayout(this, "visible");
3066 PerformLayout(this, "visible");
3071 [EditorBrowsable(EditorBrowsableState.Advanced)]
3072 protected void UpdateBounds() {
3080 if (!IsHandleCreated) {
3084 XplatUI.GetWindowPos(this.Handle, this is Form, out x, out y, out width, out height, out client_width, out client_height);
3086 UpdateBounds(x, y, width, height, client_width, client_height);
3089 [EditorBrowsable(EditorBrowsableState.Advanced)]
3090 protected void UpdateBounds(int x, int y, int width, int height) {
3091 // UpdateBounds only seems to set our sizes and fire events but not update the GUI window to match
3093 bool resized = false;
3095 int client_x_diff = this.bounds.Width-this.client_size.Width;
3096 int client_y_diff = this.bounds.Height-this.client_size.Height;
3098 // Needed to generate required notifications
3099 if ((this.bounds.X!=x) || (this.bounds.Y!=y)) {
3103 if ((this.Bounds.Width!=width) || (this.Bounds.Height!=height)) {
3110 bounds.Height=height;
3112 // Update client rectangle as well
3113 if (this.layout_suspended==0) {
3114 prev_size.Width=client_size.Width;
3115 prev_size.Height=client_size.Height;
3118 client_size.Width=width-client_x_diff;
3119 client_size.Height=height-client_y_diff;
3122 OnLocationChanged(EventArgs.Empty);
3126 OnSizeChanged(EventArgs.Empty);
3130 [EditorBrowsable(EditorBrowsableState.Advanced)]
3131 protected void UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) {
3132 UpdateBounds(x, y, width, height);
3134 this.client_size.Width=clientWidth;
3135 this.client_size.Height=clientHeight;
3138 [EditorBrowsable(EditorBrowsableState.Advanced)]
3139 protected void UpdateStyles() {
3140 if (!IsHandleCreated) {
3144 XplatUI.SetWindowStyle(window.Handle, CreateParams);
3147 [EditorBrowsable(EditorBrowsableState.Advanced)]
3148 protected void UpdateZOrder() {
3153 if (parent == null) {
3159 children = ctl.child_controls.Count;
3160 for (int i = 1; i < children; i++ ) {
3161 XplatUI.SetZOrder(ctl.child_controls[i].window.Handle, ctl.child_controls[i-1].window.Handle, false, false);
3164 children = child_controls.Count;
3165 for (int i = 1; i < children; i++ ) {
3166 XplatUI.SetZOrder(child_controls[i].window.Handle, child_controls[i-1].window.Handle, false, false);
3171 protected virtual void WndProc(ref Message m) {
3173 Console.WriteLine("Control received message {0}", (Msg)m.Msg);
3175 if ((this.control_style & ControlStyles.EnableNotifyMessage) != 0) {
3179 switch((Msg)m.Msg) {
3180 case Msg.WM_WINDOWPOSCHANGED: {
3183 if (GetStyle(ControlStyles.ResizeRedraw)) {
3190 case Msg.WM_PAINT: {
3191 PaintEventArgs paint_event;
3193 paint_event = XplatUI.PaintEventStart(Handle);
3195 if (!needs_redraw) {
3196 // Just blit the previous image
3197 paint_event.Graphics.DrawImage (ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle, GraphicsUnit.Pixel);
3198 XplatUI.PaintEventEnd(Handle);
3203 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
3204 dc = paint_event.SetGraphics (DeviceContext);
3207 if ((control_style & (ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint)) != (ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint)) {
3208 OnPaintBackground(paint_event);
3211 OnPaint(paint_event);
3213 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
3214 dc.DrawImage (ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle, GraphicsUnit.Pixel);
3215 paint_event.SetGraphics (dc);
3216 needs_redraw = false;
3219 XplatUI.PaintEventEnd(Handle);
3221 if (!GetStyle(ControlStyles.UserPaint)) {
3228 case Msg.WM_ERASEBKGND: {
3229 if (GetStyle (ControlStyles.UserPaint)) {
3230 if (!GetStyle(ControlStyles.AllPaintingInWmPaint)) {
3231 PaintEventArgs eraseEventArgs = new PaintEventArgs (m.WParam == IntPtr.Zero ? Graphics.FromHwnd (m.HWnd) :
3232 Graphics.FromHdc (m.WParam), new Rectangle (new Point (0,0),Size));
3233 OnPaintBackground (eraseEventArgs);
3236 XplatUI.EraseWindowBackground(m.HWnd, m.WParam);
3238 // The DefWndProc will never have to handle this, we don't ever set hbr on the window
3239 m.Result = (IntPtr)1;
3243 case Msg.WM_LBUTTONUP: {
3244 HandleClick(mouse_clicks);
3245 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Left,
3247 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3249 if (mouse_clicks > 1) {
3255 case Msg.WM_LBUTTONDOWN: {
3256 if (CanSelect && !is_selected) {
3259 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3260 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3266 case Msg.WM_LBUTTONDBLCLK: {
3268 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3269 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3275 case Msg.WM_MBUTTONUP: {
3276 HandleClick(mouse_clicks);
3277 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Middle,
3279 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3281 if (mouse_clicks > 1) {
3287 case Msg.WM_MBUTTONDOWN: {
3288 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3289 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3295 case Msg.WM_MBUTTONDBLCLK: {
3297 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3298 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3303 case Msg.WM_RBUTTONUP: {
3304 if (context_menu != null) {
3305 context_menu.Show(this, new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ())));
3308 HandleClick(mouse_clicks);
3309 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Right,
3311 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3313 if (mouse_clicks > 1) {
3319 case Msg.WM_RBUTTONDOWN: {
3320 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3321 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3326 case Msg.WM_RBUTTONDBLCLK: {
3328 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3329 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3334 case Msg.WM_MOUSEWHEEL: {
3336 OnMouseWheel (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3337 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3338 HighOrder(m.WParam.ToInt32())));
3343 case Msg.WM_MOUSEMOVE: {
3344 OnMouseMove (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3346 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3351 case Msg.WM_MOUSE_ENTER: {
3356 OnMouseEnter(EventArgs.Empty);
3360 case Msg.WM_MOUSE_LEAVE: {
3362 OnMouseLeave(EventArgs.Empty);
3366 case Msg.WM_MOUSEHOVER: {
3367 OnMouseHover(EventArgs.Empty);
3371 case Msg.WM_SYSKEYDOWN:
3372 case Msg.WM_KEYDOWN:
3373 case Msg.WM_SYSKEYUP:
3375 case Msg.WM_SYSCHAR:
3377 if (ProcessKeyEventArgs(ref m)) {
3381 if (PreProcessMessage(ref m)) {
3385 if (ProcessKeyMessage(ref m)) {
3394 if (m.LParam != IntPtr.Zero) {
3397 hi = new HELPINFO();
3399 hi = (HELPINFO) Marshal.PtrToStructure (m.LParam, typeof (HELPINFO));
3400 mouse_pos = new Point(hi.MousePos.x, hi.MousePos.y);
3402 mouse_pos = Control.MousePosition;
3404 OnHelpRequested(new HelpEventArgs(mouse_pos));
3405 m.Result = (IntPtr)1;
3409 case Msg.WM_KILLFOCUS: {
3410 OnLeave(EventArgs.Empty);
3411 if (CausesValidation) {
3413 e = new CancelEventArgs(false);
3422 OnValidated(EventArgs.Empty);
3425 this.has_focus = false;
3426 this.is_selected = false;
3427 OnLostFocus(EventArgs.Empty);
3431 case Msg.WM_SETFOCUS: {
3432 OnEnter(EventArgs.Empty);
3433 this.has_focus = true;
3434 OnGotFocus(EventArgs.Empty);
3439 case Msg.WM_SYSCOLORCHANGE: {
3440 ThemeEngine.Current.ResetDefaults();
3441 OnSystemColorsChanged(EventArgs.Empty);
3446 case Msg.WM_SETCURSOR: {
3447 if (cursor == null) {
3452 XplatUI.SetCursor(window.Handle, cursor.handle);
3453 m.Result = (IntPtr)1;
3463 #endregion // Public Instance Methods
3465 #region OnXXX methods
3466 [EditorBrowsable(EditorBrowsableState.Advanced)]
3467 protected virtual void OnBackColorChanged(EventArgs e) {
3468 if (BackColorChanged!=null) BackColorChanged(this, e);
3469 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackColorChanged(e);
3472 [EditorBrowsable(EditorBrowsableState.Advanced)]
3473 protected virtual void OnBackgroundImageChanged(EventArgs e) {
3474 if (BackgroundImageChanged!=null) BackgroundImageChanged(this, e);
3475 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackgroundImageChanged(e);
3478 [EditorBrowsable(EditorBrowsableState.Advanced)]
3479 protected virtual void OnBindingContextChanged(EventArgs e) {
3480 CheckDataBindings ();
3481 if (BindingContextChanged!=null) {
3482 BindingContextChanged(this, e);
3484 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBindingContextChanged(e);
3487 [EditorBrowsable(EditorBrowsableState.Advanced)]
3488 protected virtual void OnCausesValidationChanged(EventArgs e) {
3489 if (CausesValidationChanged!=null) CausesValidationChanged(this, e);
3492 [EditorBrowsable(EditorBrowsableState.Advanced)]
3493 protected virtual void OnChangeUICues(UICuesEventArgs e) {
3494 if (ChangeUICues!=null) ChangeUICues(this, e);
3497 [EditorBrowsable(EditorBrowsableState.Advanced)]
3498 protected virtual void OnClick(EventArgs e) {
3499 if (Click!=null) Click(this, e);
3502 [EditorBrowsable(EditorBrowsableState.Advanced)]
3503 protected virtual void OnContextMenuChanged(EventArgs e) {
3504 if (ContextMenuChanged!=null) ContextMenuChanged(this, e);
3507 [EditorBrowsable(EditorBrowsableState.Advanced)]
3508 protected virtual void OnControlAdded(ControlEventArgs e) {
3509 if (ControlAdded!=null) ControlAdded(this, e);
3512 [EditorBrowsable(EditorBrowsableState.Advanced)]
3513 protected virtual void OnControlRemoved(ControlEventArgs e) {
3514 if (ControlRemoved!=null) ControlRemoved(this, e);
3517 [EditorBrowsable(EditorBrowsableState.Advanced)]
3518 protected virtual void OnCreateControl() {
3522 [EditorBrowsable(EditorBrowsableState.Advanced)]
3523 protected virtual void OnCursorChanged(EventArgs e) {
3524 if (CursorChanged!=null) CursorChanged(this, e);
3527 [EditorBrowsable(EditorBrowsableState.Advanced)]
3528 protected virtual void OnDockChanged(EventArgs e) {
3529 if (DockChanged!=null) DockChanged(this, e);
3532 [EditorBrowsable(EditorBrowsableState.Advanced)]
3533 protected virtual void OnDoubleClick(EventArgs e) {
3534 if (DoubleClick!=null) DoubleClick(this, e);
3537 [EditorBrowsable(EditorBrowsableState.Advanced)]
3538 protected virtual void OnDragDrop(DragEventArgs drgevent) {
3539 if (DragDrop!=null) DragDrop(this, drgevent);
3542 [EditorBrowsable(EditorBrowsableState.Advanced)]
3543 protected virtual void OnDragEnter(DragEventArgs drgevent) {
3544 if (DragEnter!=null) DragEnter(this, drgevent);
3547 [EditorBrowsable(EditorBrowsableState.Advanced)]
3548 protected virtual void OnDragLeave(EventArgs e) {
3549 if (DragLeave!=null) DragLeave(this, e);
3552 [EditorBrowsable(EditorBrowsableState.Advanced)]
3553 protected virtual void OnDragOver(DragEventArgs drgevent) {
3554 if (DragOver!=null) DragOver(this, drgevent);
3557 [EditorBrowsable(EditorBrowsableState.Advanced)]
3558 protected virtual void OnEnabledChanged(EventArgs e) {
3559 if (EnabledChanged!=null) EnabledChanged(this, e);
3560 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentEnabledChanged(e);
3563 [EditorBrowsable(EditorBrowsableState.Advanced)]
3564 protected virtual void OnEnter(EventArgs e) {
3565 if (Enter!=null) Enter(this, e);
3568 [EditorBrowsable(EditorBrowsableState.Advanced)]
3569 protected virtual void OnFontChanged(EventArgs e) {
3570 if (FontChanged!=null) FontChanged(this, e);
3571 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentFontChanged(e);
3574 [EditorBrowsable(EditorBrowsableState.Advanced)]
3575 protected virtual void OnForeColorChanged(EventArgs e) {
3576 if (ForeColorChanged!=null) ForeColorChanged(this, e);
3577 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentForeColorChanged(e);
3580 [EditorBrowsable(EditorBrowsableState.Advanced)]
3581 protected virtual void OnGiveFeedback(GiveFeedbackEventArgs gfbevent) {
3582 if (GiveFeedback!=null) GiveFeedback(this, gfbevent);
3585 [EditorBrowsable(EditorBrowsableState.Advanced)]
3586 protected virtual void OnGotFocus(EventArgs e) {
3587 if (GotFocus!=null) GotFocus(this, e);
3590 [EditorBrowsable(EditorBrowsableState.Advanced)]
3591 protected virtual void OnHandleCreated(EventArgs e) {
3592 if (HandleCreated!=null) HandleCreated(this, e);
3595 [EditorBrowsable(EditorBrowsableState.Advanced)]
3596 protected virtual void OnHandleDestroyed(EventArgs e) {
3597 if (HandleDestroyed!=null) HandleDestroyed(this, e);
3600 [EditorBrowsable(EditorBrowsableState.Advanced)]
3601 protected virtual void OnHelpRequested(HelpEventArgs hevent) {
3602 if (HelpRequested!=null) HelpRequested(this, hevent);
3605 protected virtual void OnImeModeChanged(EventArgs e) {
3606 if (ImeModeChanged!=null) ImeModeChanged(this, e);
3609 [EditorBrowsable(EditorBrowsableState.Advanced)]
3610 protected virtual void OnInvalidated(InvalidateEventArgs e) {
3611 needs_redraw = true;
3612 if (Invalidated!=null) Invalidated(this, e);
3615 [EditorBrowsable(EditorBrowsableState.Advanced)]
3616 protected virtual void OnKeyDown(KeyEventArgs e) {
3617 if (KeyDown!=null) KeyDown(this, e);
3620 [EditorBrowsable(EditorBrowsableState.Advanced)]
3621 protected virtual void OnKeyPress(KeyPressEventArgs e) {
3622 if (KeyPress!=null) KeyPress(this, e);
3625 [EditorBrowsable(EditorBrowsableState.Advanced)]
3626 protected virtual void OnKeyUp(KeyEventArgs e) {
3627 if (KeyUp!=null) KeyUp(this, e);
3630 [EditorBrowsable(EditorBrowsableState.Advanced)]
3631 protected virtual void OnLayout(LayoutEventArgs levent) {
3632 if (Layout!=null) Layout(this, levent);
3635 [EditorBrowsable(EditorBrowsableState.Advanced)]
3636 protected virtual void OnLeave(EventArgs e) {
3637 if (Leave!=null) Leave(this, e);
3640 [EditorBrowsable(EditorBrowsableState.Advanced)]
3641 protected virtual void OnLocationChanged(EventArgs e) {
3643 if (LocationChanged!=null) LocationChanged(this, e);
3646 [EditorBrowsable(EditorBrowsableState.Advanced)]
3647 protected virtual void OnLostFocus(EventArgs e) {
3648 if (LostFocus!=null) LostFocus(this, e);
3651 [EditorBrowsable(EditorBrowsableState.Advanced)]
3652 protected virtual void OnMouseDown(MouseEventArgs e) {
3653 if (MouseDown!=null) MouseDown(this, e);
3656 [EditorBrowsable(EditorBrowsableState.Advanced)]
3657 protected virtual void OnMouseEnter(EventArgs e) {
3658 if (MouseEnter!=null) MouseEnter(this, e);
3661 [EditorBrowsable(EditorBrowsableState.Advanced)]
3662 protected virtual void OnMouseHover(EventArgs e) {
3663 if (MouseHover!=null) MouseHover(this, e);
3666 [EditorBrowsable(EditorBrowsableState.Advanced)]
3667 protected virtual void OnMouseLeave(EventArgs e) {
3668 if (MouseLeave!=null) MouseLeave(this, e);
3671 [EditorBrowsable(EditorBrowsableState.Advanced)]
3672 protected virtual void OnMouseMove(MouseEventArgs e) {
3673 if (MouseMove!=null) MouseMove(this, e);
3676 [EditorBrowsable(EditorBrowsableState.Advanced)]
3677 protected virtual void OnMouseUp(MouseEventArgs e) {
3678 if (MouseUp!=null) MouseUp(this, e);
3681 [EditorBrowsable(EditorBrowsableState.Advanced)]
3682 protected virtual void OnMouseWheel(MouseEventArgs e) {
3683 if (MouseWheel!=null) MouseWheel(this, e);
3686 [EditorBrowsable(EditorBrowsableState.Advanced)]
3687 protected virtual void OnMove(EventArgs e) {
3688 if (Move!=null) Move(this, e);
3691 [EditorBrowsable(EditorBrowsableState.Advanced)]
3692 protected virtual void OnNotifyMessage(Message m) {
3696 [EditorBrowsable(EditorBrowsableState.Advanced)]
3697 protected virtual void OnPaint(PaintEventArgs e) {
3698 if (Paint!=null) Paint(this, e);
3701 [EditorBrowsable(EditorBrowsableState.Advanced)]
3702 protected virtual void OnPaintBackground(PaintEventArgs pevent) {
3703 PaintControlBackground (pevent);
3706 [EditorBrowsable(EditorBrowsableState.Advanced)]
3707 protected virtual void OnParentBackColorChanged(EventArgs e) {
3708 if (background_color.IsEmpty && background_image==null) {
3710 OnBackColorChanged(e);
3714 [EditorBrowsable(EditorBrowsableState.Advanced)]
3715 protected virtual void OnParentBackgroundImageChanged(EventArgs e) {
3716 if (background_color.IsEmpty && background_image==null) {
3718 OnBackgroundImageChanged(e);
3722 [EditorBrowsable(EditorBrowsableState.Advanced)]
3723 protected virtual void OnParentBindingContextChanged(EventArgs e) {
3724 if (binding_context==null) {
3725 binding_context=Parent.binding_context;
3726 OnBindingContextChanged(e);
3730 [EditorBrowsable(EditorBrowsableState.Advanced)]
3731 protected virtual void OnParentChanged(EventArgs e) {
3732 if (ParentChanged!=null) ParentChanged(this, e);
3735 [EditorBrowsable(EditorBrowsableState.Advanced)]
3736 protected virtual void OnParentEnabledChanged(EventArgs e) {
3737 if (is_enabled != Parent.is_enabled) {
3738 is_enabled=Parent.is_enabled;
3740 if (EnabledChanged != null) {
3741 EnabledChanged(this, e);
3746 [EditorBrowsable(EditorBrowsableState.Advanced)]
3747 protected virtual void OnParentFontChanged(EventArgs e) {
3754 [EditorBrowsable(EditorBrowsableState.Advanced)]
3755 protected virtual void OnParentForeColorChanged(EventArgs e) {
3756 if (foreground_color.IsEmpty) {
3758 OnForeColorChanged(e);
3762 [EditorBrowsable(EditorBrowsableState.Advanced)]
3763 protected virtual void OnParentRightToLeftChanged(EventArgs e) {
3764 if (right_to_left==RightToLeft.Inherit) {
3766 OnRightToLeftChanged(e);
3770 [EditorBrowsable(EditorBrowsableState.Advanced)]
3771 protected virtual void OnParentVisibleChanged(EventArgs e) {
3773 OnVisibleChanged(e);
3777 [EditorBrowsable(EditorBrowsableState.Advanced)]
3778 protected virtual void OnQueryContinueDrag(QueryContinueDragEventArgs e) {
3779 if (QueryContinueDrag!=null) QueryContinueDrag(this, e);
3782 [EditorBrowsable(EditorBrowsableState.Advanced)]
3783 protected virtual void OnResize(EventArgs e) {
3784 if (Resize!=null) Resize(this, e);
3786 PerformLayout(this, "bounds");
3788 if (parent != null) {
3789 parent.PerformLayout();
3793 [EditorBrowsable(EditorBrowsableState.Advanced)]
3794 protected virtual void OnRightToLeftChanged(EventArgs e) {
3795 if (RightToLeftChanged!=null) RightToLeftChanged(this, e);
3796 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentRightToLeftChanged(e);
3799 [EditorBrowsable(EditorBrowsableState.Advanced)]
3800 protected virtual void OnSizeChanged(EventArgs e) {
3801 InvalidateBuffers ();
3803 if (SizeChanged!=null) SizeChanged(this, e);
3806 [EditorBrowsable(EditorBrowsableState.Advanced)]
3807 protected virtual void OnStyleChanged(EventArgs e) {
3808 if (StyleChanged!=null) StyleChanged(this, e);
3811 [EditorBrowsable(EditorBrowsableState.Advanced)]
3812 protected virtual void OnSystemColorsChanged(EventArgs e) {
3813 if (SystemColorsChanged!=null) SystemColorsChanged(this, e);
3816 [EditorBrowsable(EditorBrowsableState.Advanced)]
3817 protected virtual void OnTabIndexChanged(EventArgs e) {
3818 if (TabIndexChanged!=null) TabIndexChanged(this, e);
3821 [EditorBrowsable(EditorBrowsableState.Advanced)]
3822 protected virtual void OnTabStopChanged(EventArgs e) {
3823 if (TabStopChanged!=null) TabStopChanged(this, e);
3826 [EditorBrowsable(EditorBrowsableState.Advanced)]
3827 protected virtual void OnTextChanged(EventArgs e) {
3828 if (TextChanged!=null) TextChanged(this, e);
3831 [EditorBrowsable(EditorBrowsableState.Advanced)]
3832 protected virtual void OnValidated(EventArgs e) {
3833 if (Validated!=null) Validated(this, e);
3836 [EditorBrowsable(EditorBrowsableState.Advanced)]
3837 protected virtual void OnValidating(System.ComponentModel.CancelEventArgs e) {
3838 if (Validating!=null) Validating(this, e);
3841 [EditorBrowsable(EditorBrowsableState.Advanced)]
3842 protected virtual void OnVisibleChanged(EventArgs e) {
3849 if (bmp_mem!=null) {
3855 if (!this.IsHandleCreated) {
3856 this.CreateControl();
3862 if (VisibleChanged!=null) VisibleChanged(this, e);
3864 // We need to tell our kids
3865 for (int i=0; i<child_controls.Count; i++) {
3866 child_controls[i].OnParentVisibleChanged(e);
3869 #endregion // OnXXX methods
3872 public event EventHandler BackColorChanged;
3873 public event EventHandler BackgroundImageChanged;
3874 public event EventHandler BindingContextChanged;
3875 public event EventHandler CausesValidationChanged;
3876 public event UICuesEventHandler ChangeUICues;
3877 public event EventHandler Click;
3878 public event EventHandler ContextMenuChanged;
3880 [EditorBrowsable(EditorBrowsableState.Advanced)]
3882 public event ControlEventHandler ControlAdded;
3884 [EditorBrowsable(EditorBrowsableState.Advanced)]
3886 public event ControlEventHandler ControlRemoved;
3888 public event EventHandler CursorChanged;
3889 public event EventHandler DockChanged;
3890 public event EventHandler DoubleClick;
3891 public event DragEventHandler DragDrop;
3892 public event DragEventHandler DragEnter;
3893 public event EventHandler DragLeave;
3894 public event DragEventHandler DragOver;
3895 public event EventHandler EnabledChanged;
3896 public event EventHandler Enter;
3897 public event EventHandler FontChanged;
3898 public event EventHandler ForeColorChanged;
3899 public event GiveFeedbackEventHandler GiveFeedback;
3901 [EditorBrowsable(EditorBrowsableState.Advanced)]
3903 public event EventHandler GotFocus;
3905 [EditorBrowsable(EditorBrowsableState.Advanced)]
3907 public event EventHandler HandleCreated;
3909 [EditorBrowsable(EditorBrowsableState.Advanced)]
3911 public event EventHandler HandleDestroyed;
3913 public event HelpEventHandler HelpRequested;
3914 public event EventHandler ImeModeChanged;
3916 [EditorBrowsable(EditorBrowsableState.Advanced)]
3918 public event InvalidateEventHandler Invalidated;
3920 public event KeyEventHandler KeyDown;
3921 public event KeyPressEventHandler KeyPress;
3922 public event KeyEventHandler KeyUp;
3923 public event LayoutEventHandler Layout;
3924 public event EventHandler Leave;
3925 public event EventHandler LocationChanged;
3927 [EditorBrowsable(EditorBrowsableState.Advanced)]
3929 public event EventHandler LostFocus;
3931 public event MouseEventHandler MouseDown;
3932 public event EventHandler MouseEnter;
3933 public event EventHandler MouseHover;
3934 public event EventHandler MouseLeave;
3935 public event MouseEventHandler MouseMove;
3936 public event MouseEventHandler MouseUp;
3938 [EditorBrowsable(EditorBrowsableState.Advanced)]
3940 public event MouseEventHandler MouseWheel;
3942 public event EventHandler Move;
3943 public event PaintEventHandler Paint;
3944 public event EventHandler ParentChanged;
3945 public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp;
3946 public event QueryContinueDragEventHandler QueryContinueDrag;
3947 public event EventHandler Resize;
3948 public event EventHandler RightToLeftChanged;
3949 public event EventHandler SizeChanged;
3950 public event EventHandler StyleChanged;
3951 public event EventHandler SystemColorsChanged;
3952 public event EventHandler TabIndexChanged;
3953 public event EventHandler TabStopChanged;
3954 public event EventHandler TextChanged;
3955 public event EventHandler Validated;
3956 public event CancelEventHandler Validating;
3957 public event EventHandler VisibleChanged;
3958 #endregion // Events