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 child_controls = CreateControlsInstance();
556 client_size = new Size(DefaultSize.Width, DefaultSize.Height);
557 client_rect = new Rectangle(0, 0, DefaultSize.Width, DefaultSize.Height);
558 XplatUI.CalculateWindowRect(IntPtr.Zero, ref client_rect, CreateParams.Style, CreateParams.ExStyle, IntPtr.Zero, out bounds);
559 if ((CreateParams.Style & (int)WindowStyles.WS_CHILD) == 0) {
565 public Control(Control parent, string text) : this() {
570 public Control(Control parent, string text, int left, int top, int width, int height) : this() {
575 bounds.Height=height;
576 SetBoundsCore(left, top, width, height, BoundsSpecified.All);
580 public Control(string text) : this() {
584 public Control(string text, int left, int top, int width, int height) : this() {
588 bounds.Height=height;
589 SetBoundsCore(left, top, width, height, BoundsSpecified.All);
593 protected override void Dispose(bool disposing) {
606 controls.Remove(this);
608 #endregion // Public Constructors
610 #region Internal Properties
611 internal BorderStyle InternalBorderStyle {
617 if (border_style != value) {
618 border_style = value;
620 XplatUI.SetBorderStyle(window.Handle, border_style);
624 #endregion // Internal Properties
626 #region Private & Internal Methods
627 internal static IAsyncResult BeginInvokeInternal (Delegate method, object [] args) {
628 AsyncMethodResult result = new AsyncMethodResult ();
629 AsyncMethodData data = new AsyncMethodData ();
631 data.Method = method;
633 data.Result = new WeakReference (result);
636 if (!ExecutionContext.IsFlowSuppressed ()) {
637 data.Context = ExecutionContext.Capture ();
640 if (SecurityManager.SecurityEnabled) {
641 data.Stack = CompressedStack.GetCompressedStack ();
645 XplatUI.SendAsyncMethod (data);
649 internal Graphics DeviceContext {
652 CreateBuffers(this.Width, this.Height);
658 private Bitmap ImageBuffer {
661 CreateBuffers(this.Width, this.Height);
667 internal void CreateBuffers (int width, int height) {
668 if (dc_mem != null) {
682 bmp_mem = new Bitmap (width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
683 dc_mem = Graphics.FromImage (bmp_mem);
687 internal void InvalidateBuffers ()
689 if (dc_mem != null) {
700 internal static void SetChildColor(Control parent) {
703 for (int i=0; i < parent.child_controls.Count; i++) {
704 child=parent.child_controls[i];
705 if (child.IsHandleCreated) {
706 XplatUI.SetWindowBackground(child.window.Handle, child.BackColor);
708 if (child.child_controls.Count>0) {
709 SetChildColor(child);
715 internal bool Select(Control control) {
717 IContainerControl container;
719 if (control == null) {
723 parent = control.parent;
725 if (((control.control_style & ControlStyles.Selectable) !=0) && (parent != null)) {
726 while (parent != null) {
727 if (!parent.Visible || !parent.is_enabled) {
730 parent = parent.parent;
734 control.is_selected = true;
736 XplatUI.SetFocus(control.window.Handle);
737 container = GetContainerControl();
738 if (container != null) {
739 container.ActiveControl = control;
744 internal virtual void DoDefaultAction() {
745 // Only here to be overriden by our actual controls; this is needed by the accessibility class
748 internal static int LowOrder (int param) {
749 return (param & 0xffff);
752 internal static int HighOrder (int param) {
753 return (param >> 16);
756 internal static MouseButtons FromParamToMouseButtons (int param) {
757 MouseButtons buttons = MouseButtons.None;
759 if ((param & (int) MsgButtons.MK_LBUTTON) != 0)
760 buttons |= MouseButtons.Left;
762 if ((param & (int) MsgButtons.MK_MBUTTON) != 0)
763 buttons |= MouseButtons.Middle;
765 if ((param & (int) MsgButtons.MK_RBUTTON) != 0)
766 buttons |= MouseButtons.Right;
772 internal virtual bool ProcessControlMnemonic(char charCode) {
773 return ProcessMnemonic(charCode);
776 private static Control FindFlatForward(Control container, Control start) {
782 end = container.child_controls.Count;
785 index = start.tab_index;
790 for (int i = 0; i < end; i++) {
792 if (container.child_controls[i].tab_index > index) {
793 found = container.child_controls[i];
795 } else if (found.tab_index > container.child_controls[i].tab_index) {
796 if (container.child_controls[i].tab_index > index) {
797 found = container.child_controls[i];
804 private static Control FindControlForward(Control container, Control start) {
811 if ((start is IContainerControl) || start.GetStyle(ControlStyles.ContainerControl)) {
812 found = FindControlForward(start, null);
819 while (p != container) {
820 found = FindFlatForward(p, start);
828 return FindFlatForward(container, start);
831 private static Control FindFlatBackward(Control container, Control start) {
837 end = container.child_controls.Count;
840 index = start.tab_index;
842 // FIXME: Possible speed-up: Keep the highest taborder index in the container
844 for (int i = 0; i < end; i++) {
845 if (container.child_controls[i].tab_index > index) {
846 index = container.child_controls[i].tab_index;
852 for (int i = 0; i < end; i++) {
854 if (container.child_controls[i].tab_index < index) {
855 found = container.child_controls[i];
857 } else if (found.tab_index < container.child_controls[i].tab_index) {
858 if (container.child_controls[i].tab_index < index) {
859 found = container.child_controls[i];
866 private static Control FindControlBackward(Control container, Control start) {
872 found = FindFlatBackward(start.parent, start);
873 if (found == null && start.parent != container) {
878 found = FindFlatBackward(container, start);
881 while ((found != null) && ((found is IContainerControl) || found.GetStyle(ControlStyles.ContainerControl))) {
882 found = FindControlBackward(found, null);
891 private void HandleClick(int clicks) {
892 if (GetStyle(ControlStyles.StandardClick)) {
894 if (GetStyle(ControlStyles.StandardDoubleClick)) {
895 OnDoubleClick(EventArgs.Empty);
897 OnClick(EventArgs.Empty);
900 OnClick(EventArgs.Empty);
905 private void CheckDataBindings ()
907 if (data_bindings == null)
910 BindingContext binding_context = BindingContext;
911 foreach (Binding binding in data_bindings) {
912 binding.Check (binding_context);
916 #endregion // Private & Internal Methods
918 #region Public Static Properties
919 public static Color DefaultBackColor {
921 return ThemeEngine.Current.DefaultControlBackColor;
925 public static Font DefaultFont {
927 return ThemeEngine.Current.DefaultFont;
931 public static Color DefaultForeColor {
933 return ThemeEngine.Current.DefaultControlForeColor;
937 public static Keys ModifierKeys {
939 return XplatUI.State.ModifierKeys;
943 public static MouseButtons MouseButtons {
945 return XplatUI.State.MouseButtons;
949 public static Point MousePosition {
951 return Cursor.Position;
954 #endregion // Public Static Properties
956 #region Public Instance Properties
957 [EditorBrowsable(EditorBrowsableState.Advanced)]
959 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
960 public AccessibleObject AccessibilityObject {
962 if (accessibility_object==null) {
963 accessibility_object=CreateAccessibilityInstance();
965 return accessibility_object;
969 [EditorBrowsable(EditorBrowsableState.Advanced)]
971 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
972 public string AccessibleDefaultActionDescription {
974 return AccessibilityObject.default_action;
978 AccessibilityObject.default_action=value;
984 public string AccessibleDescription {
986 return AccessibilityObject.description;
990 AccessibilityObject.description=value;
996 public string AccessibleName {
998 return AccessibilityObject.Name;
1002 AccessibilityObject.Name=value;
1006 [DefaultValue(AccessibleRole.Default)]
1007 public AccessibleRole AccessibleRole {
1009 return AccessibilityObject.role;
1013 AccessibilityObject.role=value;
1017 [DefaultValue(false)]
1018 public virtual bool AllowDrop {
1020 return XplatUI.State.DropTarget;
1025 XplatUI.State.DropTarget=value;
1031 [RefreshProperties(RefreshProperties.Repaint)]
1032 [DefaultValue(AnchorStyles.Top | AnchorStyles.Left)]
1033 public virtual AnchorStyles Anchor {
1035 return anchor_style;
1041 if (parent != null) {
1042 parent.PerformLayout(this, "Parent");
1048 public virtual Color BackColor {
1050 if (background_color.IsEmpty) {
1052 return parent.BackColor;
1054 return DefaultBackColor;
1056 return background_color;
1060 background_color=value;
1061 if (this.IsHandleCreated) {
1062 XplatUI.SetWindowBackground(this.window.Handle, value);
1064 SetChildColor(this);
1065 OnBackColorChanged(EventArgs.Empty);
1071 [DefaultValue(null)]
1072 public virtual Image BackgroundImage {
1074 return background_image;
1078 if (background_image!=value) {
1079 background_image=value;
1080 OnBackgroundImageChanged(EventArgs.Empty);
1085 [EditorBrowsable(EditorBrowsableState.Advanced)]
1087 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1088 public virtual BindingContext BindingContext {
1090 if (binding_context != null)
1091 return binding_context;
1094 binding_context = Parent.BindingContext;
1095 return binding_context;
1098 if (binding_context != value) {
1099 binding_context = value;
1100 OnBindingContextChanged(EventArgs.Empty);
1105 [EditorBrowsable(EditorBrowsableState.Advanced)]
1107 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1110 return bounds.Y+bounds.Height;
1114 [EditorBrowsable(EditorBrowsableState.Advanced)]
1116 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1117 public Rectangle Bounds {
1123 SetBoundsCore(value.Left, value.Top, value.Width, value.Height, BoundsSpecified.All);
1127 [EditorBrowsable(EditorBrowsableState.Advanced)]
1129 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1130 public bool CanFocus {
1132 if (Visible && is_enabled && GetStyle(ControlStyles.Selectable)) {
1139 [EditorBrowsable(EditorBrowsableState.Advanced)]
1141 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1142 public bool CanSelect {
1146 if (!GetStyle(ControlStyles.Selectable) || this.parent == null) {
1150 parent = this.parent;
1151 while (parent != null) {
1152 if (!parent.is_visible || !parent.is_enabled) {
1156 parent = parent.parent;
1162 [EditorBrowsable(EditorBrowsableState.Advanced)]
1164 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1165 public bool Capture {
1167 return this.is_captured;
1171 if (this.IsHandleCreated) {
1172 if (value && !is_captured) {
1174 XplatUI.GrabWindow(this.window.Handle, IntPtr.Zero);
1175 } else if (!value && is_captured) {
1176 XplatUI.UngrabWindow(this.window.Handle);
1177 is_captured = false;
1183 [DefaultValue(true)]
1184 public bool CausesValidation {
1186 return this.causes_validation;
1190 if (this.causes_validation != value) {
1191 causes_validation = value;
1192 OnCausesValidationChanged(EventArgs.Empty);
1197 [EditorBrowsable(EditorBrowsableState.Advanced)]
1199 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1200 public Rectangle ClientRectangle {
1202 client_rect.Width = client_size.Width;
1203 client_rect.Height = client_size.Height;
1208 [EditorBrowsable(EditorBrowsableState.Advanced)]
1210 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1211 public Size ClientSize {
1214 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1215 return ((Form)this).form_parent_window.ClientSize;
1223 this.SetClientSizeCore(value.Width, value.Height);
1227 [EditorBrowsable(EditorBrowsableState.Advanced)]
1229 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1230 [DescriptionAttribute("ControlCompanyNameDescr")]
1231 public String CompanyName {
1233 return "Mono Project, Novell, Inc.";
1237 [EditorBrowsable(EditorBrowsableState.Advanced)]
1239 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1240 public bool ContainsFocus {
1246 for (int i=0; i < child_controls.Count; i++) {
1247 if (child_controls[i].ContainsFocus) {
1255 [DefaultValue(null)]
1256 public virtual ContextMenu ContextMenu {
1258 return context_menu;
1262 if (context_menu != value) {
1263 context_menu = value;
1264 OnContextMenuChanged(EventArgs.Empty);
1270 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
1271 public ControlCollection Controls {
1273 return this.child_controls;
1277 [EditorBrowsable(EditorBrowsableState.Advanced)]
1279 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1280 public bool Created {
1282 if (!this.is_disposed && (this.window.Handle != IntPtr.Zero)) {
1289 [AmbientValue(null)]
1290 public virtual Cursor Cursor {
1292 if (cursor != null) {
1296 if (parent != null) {
1297 return parent.Cursor;
1300 return Cursors.Default;
1304 if (cursor != value) {
1309 pt = Cursor.Position;
1310 if (bounds.Contains(pt)) {
1311 if (GetChildAtPoint(pt) == null) {
1312 if (cursor != null) {
1313 XplatUI.SetCursor(window.Handle, cursor.handle);
1315 if (parent != null) {
1316 XplatUI.SetCursor(window.Handle, parent.Cursor.handle);
1318 XplatUI.SetCursor(window.Handle, Cursors.def.handle);
1324 OnCursorChanged(EventArgs.Empty);
1330 [EditorBrowsable(EditorBrowsableState.Advanced)]
1332 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1333 public ControlBindingsCollection DataBindings {
1335 if (data_bindings == null)
1336 data_bindings = new ControlBindingsCollection (this);
1337 return data_bindings;
1341 [EditorBrowsable(EditorBrowsableState.Advanced)]
1343 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1344 public virtual Rectangle DisplayRectangle {
1346 return ClientRectangle;
1350 [EditorBrowsable(EditorBrowsableState.Advanced)]
1352 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1353 public bool Disposing {
1360 [RefreshProperties(RefreshProperties.Repaint)]
1361 [DefaultValue(DockStyle.None)]
1362 public virtual DockStyle Dock {
1368 if (dock_style == value) {
1374 if (parent != null) {
1375 parent.PerformLayout(this, "Parent");
1378 OnDockChanged(EventArgs.Empty);
1384 public bool Enabled {
1390 if (is_enabled == value) {
1396 OnEnabledChanged (EventArgs.Empty);
1400 [EditorBrowsable(EditorBrowsableState.Advanced)]
1402 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1403 public virtual bool Focused {
1405 return this.has_focus;
1410 [AmbientValue(null)]
1412 public virtual Font Font {
1418 if (Parent != null && Parent.Font != null) {
1426 if (font != null && font.Equals (value)) {
1432 OnFontChanged (EventArgs.Empty);
1437 public virtual Color ForeColor {
1439 if (foreground_color.IsEmpty) {
1441 return parent.ForeColor;
1443 return DefaultForeColor;
1445 return foreground_color;
1449 if (foreground_color != value) {
1450 foreground_color=value;
1452 OnForeColorChanged(EventArgs.Empty);
1459 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1460 public IntPtr Handle { // IWin32Window
1462 if (!IsHandleCreated) {
1465 return window.Handle;
1469 [EditorBrowsable(EditorBrowsableState.Advanced)]
1471 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1472 public bool HasChildren {
1474 if (this.child_controls.Count>0) {
1481 [EditorBrowsable(EditorBrowsableState.Always)]
1483 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1486 return this.bounds.Height;
1490 SetBoundsCore(bounds.X, bounds.Y, bounds.Width, value, BoundsSpecified.Height);
1494 [AmbientValue(ImeMode.Inherit)]
1496 public ImeMode ImeMode {
1502 if (ime_mode != value) {
1505 OnImeModeChanged(EventArgs.Empty);
1510 [EditorBrowsable(EditorBrowsableState.Advanced)]
1512 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1513 public bool InvokeRequired { // ISynchronizeInvoke
1515 if (creator_thread!=Thread.CurrentThread) {
1522 [EditorBrowsable(EditorBrowsableState.Advanced)]
1524 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1525 public bool IsAccessible {
1527 return is_accessible;
1531 is_accessible = value;
1535 [EditorBrowsable(EditorBrowsableState.Advanced)]
1537 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1538 public bool IsDisposed {
1540 return this.is_disposed;
1544 [EditorBrowsable(EditorBrowsableState.Advanced)]
1546 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1547 public bool IsHandleCreated {
1549 if ((window!=null) && (window.Handle!=IntPtr.Zero)) {
1557 [EditorBrowsable(EditorBrowsableState.Always)]
1559 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1562 return this.bounds.X;
1566 SetBoundsCore(value, bounds.Y, bounds.Width, bounds.Height, BoundsSpecified.X);
1571 public Point Location {
1573 return new Point(bounds.X, bounds.Y);
1577 SetBoundsCore(value.X, value.Y, bounds.Width, bounds.Height, BoundsSpecified.Location);
1582 public string Name {
1593 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1594 public Control Parent {
1600 if (value == this) {
1601 throw new ArgumentException("A circular control reference has been made. A control cannot be owned or parented to itself.");
1604 if (parent!=value) {
1606 parent.Controls.Remove(this);
1611 if (!parent.Controls.Contains(this)) {
1612 parent.Controls.Add(this);
1615 XplatUI.SetParent(Handle, value.Handle);
1619 OnParentChanged(EventArgs.Empty);
1624 [EditorBrowsable(EditorBrowsableState.Advanced)]
1626 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1627 public string ProductName {
1629 return "Novell Mono MWF";
1633 [EditorBrowsable(EditorBrowsableState.Advanced)]
1635 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1636 public string ProductVersion {
1638 return "1.1.4322.573";
1642 [EditorBrowsable(EditorBrowsableState.Advanced)]
1644 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1645 public bool RecreatingHandle {
1647 return is_recreating;
1651 [EditorBrowsable(EditorBrowsableState.Advanced)]
1653 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1654 public Region Region {
1656 return new Region(this.bounds);
1663 g = this.CreateGraphics();
1664 r = value.GetBounds(g);
1666 SetBounds((int)r.X, (int)r.Y, (int)r.Width, (int)r.Height);
1672 [EditorBrowsable(EditorBrowsableState.Advanced)]
1674 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1677 return this.bounds.X+this.bounds.Width;
1681 [AmbientValue(RightToLeft.Inherit)]
1683 public virtual RightToLeft RightToLeft {
1685 return right_to_left;
1689 if (value != right_to_left) {
1690 right_to_left = value;
1691 OnRightToLeftChanged(EventArgs.Empty);
1696 [EditorBrowsable(EditorBrowsableState.Advanced)]
1697 public override ISite Site {
1710 return new Size(Width, Height);
1714 SetBoundsCore(bounds.X, bounds.Y, value.Width, value.Height, BoundsSpecified.Size);
1719 [MergableProperty(false)]
1720 public int TabIndex {
1722 if (tab_index != -1) {
1729 if (tab_index != value) {
1731 OnTabIndexChanged(EventArgs.Empty);
1737 [DefaultValue(true)]
1738 public bool TabStop {
1744 if (tab_stop != value) {
1746 OnTabStopChanged(EventArgs.Empty);
1751 [Localizable(false)]
1753 [TypeConverter(typeof(StringConverter))]
1754 [DefaultValue(null)]
1761 control_tag = value;
1767 [BindableAttribute(true)]
1768 public virtual string Text {
1774 if (value == null) {
1775 value = String.Empty;
1780 XplatUI.Text(Handle, text);
1781 // FIXME: Do we need a Refresh() here?
1782 OnTextChanged (EventArgs.Empty);
1787 [EditorBrowsable(EditorBrowsableState.Always)]
1789 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1792 return this.bounds.Y;
1796 SetBoundsCore(bounds.X, value, bounds.Width, bounds.Height, BoundsSpecified.Y);
1800 [EditorBrowsable(EditorBrowsableState.Advanced)]
1802 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1803 public Control TopLevelControl {
1807 while (p.parent != null) {
1816 public bool Visible {
1820 } else if (parent != null) {
1821 return parent.Visible;
1828 SetVisibleCore(value);
1832 [EditorBrowsable(EditorBrowsableState.Always)]
1834 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1837 return this.bounds.Width;
1841 SetBoundsCore(bounds.X, bounds.Y, value, bounds.Height, BoundsSpecified.Width);
1845 [EditorBrowsable(EditorBrowsableState.Never)]
1847 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1848 public IWindowTarget WindowTarget {
1857 #endregion // Public Instance Properties
1859 #region Protected Instance Properties
1860 protected virtual CreateParams CreateParams {
1862 CreateParams create_params = new CreateParams();
1864 create_params.Caption = Text;
1865 create_params.X = Left;
1866 create_params.Y = Top;
1867 create_params.Width = Width;
1868 create_params.Height = Height;
1870 create_params.ClassName = XplatUI.DefaultClassName;
1871 create_params.ClassStyle = 0;
1872 create_params.ExStyle = 0;
1873 create_params.Param = 0;
1876 create_params.Parent = parent.Handle;
1879 create_params.Style = (int)WindowStyles.WS_CHILD | (int)WindowStyles.WS_CLIPCHILDREN | (int)WindowStyles.WS_CLIPSIBLINGS;
1882 create_params.Style |= (int)WindowStyles.WS_VISIBLE;
1885 return create_params;
1889 protected virtual ImeMode DefaultImeMode {
1891 return ImeMode.Inherit;
1895 protected virtual Size DefaultSize {
1897 return new Size(100, 23);
1901 protected int FontHeight {
1911 protected bool RenderRightToLeft {
1913 return (this.right_to_left == RightToLeft.Yes);
1917 protected bool ResizeRedraw {
1919 return GetStyle(ControlStyles.ResizeRedraw);
1923 SetStyle(ControlStyles.ResizeRedraw, value);
1927 [EditorBrowsable(EditorBrowsableState.Advanced)]
1929 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1930 protected virtual bool ShowFocusCues {
1936 [EditorBrowsable(EditorBrowsableState.Advanced)]
1938 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1939 protected bool ShowKeyboardCues {
1944 #endregion // Protected Instance Properties
1946 #region Public Static Methods
1947 [EditorBrowsable(EditorBrowsableState.Advanced)]
1948 public static Control FromChildHandle(IntPtr handle) {
1949 IEnumerator control = Control.controls.GetEnumerator();
1951 while (control.MoveNext()) {
1952 if (((Control)control.Current).window.Handle == handle) {
1954 if (((Control)control.Current).Parent != null) {
1955 return ((Control)control.Current).Parent;
1962 [EditorBrowsable(EditorBrowsableState.Advanced)]
1963 public static Control FromHandle(IntPtr handle) {
1964 IEnumerator control = Control.controls.GetEnumerator();
1966 while (control.MoveNext()) {
1967 if (((Control)control.Current).window.Handle == handle) {
1969 return ((Control)control.Current);
1975 public static bool IsMnemonic(char charCode, string text) {
1978 amp = text.IndexOf('&');
1981 if (amp + 1 < text.Length) {
1982 if (text[amp + 1] != '&') {
1983 if (Char.ToUpper(charCode) == Char.ToUpper(text.ToCharArray(amp + 1, 1)[0])) {
1993 #region Protected Static Methods
1994 [EditorBrowsable(EditorBrowsableState.Advanced)]
1995 protected static bool ReflectMessage(IntPtr hWnd, ref Message m) {
1998 c = Control.FromHandle(hWnd);
2008 #region Public Instance Methods
2009 [EditorBrowsable(EditorBrowsableState.Advanced)]
2010 public IAsyncResult BeginInvoke(Delegate method) {
2011 return BeginInvokeInternal(method, null);
2014 [EditorBrowsable(EditorBrowsableState.Advanced)]
2015 public IAsyncResult BeginInvoke (Delegate method, object[] args) {
2016 return BeginInvokeInternal (method, args);
2019 public void BringToFront() {
2020 if ((parent != null) && (parent.child_controls[0]!=this)) {
2021 if (parent.child_controls.Contains(this)) {
2022 parent.child_controls.SetChildIndex(this, 0);
2026 XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, true, false);
2028 if (parent != null) {
2033 public bool Contains(Control ctl) {
2034 while (ctl != null) {
2043 public void CreateControl() {
2045 if (!IsHandleCreated) {
2049 if (!create_handled) {
2050 create_handled = true;
2054 for (int i=0; i<child_controls.Count; i++) {
2055 child_controls[i].CreateControl();
2059 public Graphics CreateGraphics() {
2060 if (!IsHandleCreated) {
2061 this.CreateControl();
2063 return Graphics.FromHwnd(this.window.Handle);
2066 [MonoTODO("Come up with cross platform drag-drop driver interface")]
2067 public DragDropEffects DoDragDrop(object data, DragDropEffects allowedEffects) {
2068 return DragDropEffects.None;
2071 [EditorBrowsable(EditorBrowsableState.Advanced)]
2072 public object EndInvoke (IAsyncResult async_result) {
2073 AsyncMethodResult result = (AsyncMethodResult) async_result;
2074 return result.EndInvoke ();
2077 public Form FindForm() {
2090 public bool Focus() {
2091 if (IsHandleCreated && !has_focus) {
2093 XplatUI.SetFocus(window.Handle);
2098 public Control GetChildAtPoint(Point pt) {
2099 // Microsoft's version of this function doesn't seem to work, so I can't check
2100 // if we only consider children or also grandchildren, etc.
2101 // I'm gonna say 'children only'
2102 for (int i=0; i<child_controls.Count; i++) {
2103 if (child_controls[i].Bounds.Contains(pt)) {
2104 return child_controls[i];
2110 public IContainerControl GetContainerControl() {
2111 Control current = this;
2113 while (current!=null) {
2114 if ((current is IContainerControl) && ((current.control_style & ControlStyles.ContainerControl)!=0)) {
2115 return (IContainerControl)current;
2117 current = current.parent;
2122 public Control GetNextControl(Control ctl, bool forward) {
2123 // If we're not a container we don't play
2124 if (!(this is IContainerControl) && !this.GetStyle(ControlStyles.ContainerControl)) {
2128 // If ctl is not contained by this, we start at the first child of this
2129 if (!this.Contains(ctl)) {
2133 // Search through our controls, starting at ctl, stepping into children as we encounter them
2134 // try to find the control with the tabindex closest to our own, or, if we're looking into
2135 // child controls, the one with the smallest tabindex
2137 return FindControlForward(this, ctl);
2139 return FindControlBackward(this, ctl);
2142 public void Hide() {
2143 this.Visible = false;
2146 public void Invalidate() {
2147 Invalidate(ClientRectangle, false);
2150 public void Invalidate(bool invalidateChildren) {
2151 Invalidate(ClientRectangle, invalidateChildren);
2154 public void Invalidate(System.Drawing.Rectangle rc) {
2155 Invalidate(rc, false);
2158 public void Invalidate(System.Drawing.Rectangle rc, bool invalidateChildren) {
2159 if (!IsHandleCreated || !Visible) {
2163 NotifyInvalidate(rc);
2165 XplatUI.Invalidate(Handle, rc, false);
2167 if (invalidateChildren) {
2168 for (int i=0; i<child_controls.Count; i++) child_controls[i].Invalidate();
2170 OnInvalidated(new InvalidateEventArgs(rc));
2173 public void Invalidate(System.Drawing.Region region) {
2174 Invalidate(region, false);
2177 [MonoTODO("Figure out if GetRegionScans is usable")]
2178 public void Invalidate(System.Drawing.Region region, bool invalidateChildren) {
2179 throw new NotImplementedException();
2181 // FIXME - should use the GetRegionScans function of the region to invalidate each area
2182 //if (invalidateChildren) {
2183 // for (int i=0; i<child_controls.Count; i++) child_controls[i].Invalidate();
2187 public object Invoke (Delegate method) {
2188 return Invoke(method, null);
2191 public object Invoke (Delegate method, object[] args) {
2192 if (!this.InvokeRequired) {
2193 return method.DynamicInvoke(args);
2196 IAsyncResult result = BeginInvoke (method, args);
2197 return EndInvoke(result);
2200 [EditorBrowsable(EditorBrowsableState.Advanced)]
2201 public void PerformLayout() {
2202 PerformLayout(null, null);
2205 [EditorBrowsable(EditorBrowsableState.Advanced)]
2206 public void PerformLayout(Control affectedControl, string affectedProperty) {
2207 LayoutEventArgs levent = new LayoutEventArgs(affectedControl, affectedProperty);
2209 if (layout_suspended>0) {
2210 layout_pending = true;
2214 layout_pending = false;
2216 // Prevent us from getting messed up
2219 // Perform all Dock and Anchor calculations
2222 AnchorStyles anchor;
2227 space=this.DisplayRectangle;
2228 if (prev_size != Size.Empty) {
2229 diff_width = space.Width - prev_size.Width;
2230 diff_height = space.Height - prev_size.Height;
2236 // Deal with docking; go through in reverse, MS docs say that lowest Z-order is closest to edge
2237 for (int i = child_controls.Count - 1; i >= 0; i--) {
2238 child=child_controls[i];
2239 switch (child.Dock) {
2240 case DockStyle.None: {
2245 case DockStyle.Left: {
2246 child.SetBounds(space.Left, space.Y, child.Width, space.Height);
2247 space.X+=child.Width;
2248 space.Width-=child.Width;
2252 case DockStyle.Top: {
2253 child.SetBounds(space.Left, space.Y, space.Width, child.Height);
2254 space.Y+=child.Height;
2255 space.Height-=child.Height;
2259 case DockStyle.Right: {
2260 child.SetBounds(space.Right-child.Width, space.Y, child.Width, space.Height);
2261 space.Width-=child.Width;
2265 case DockStyle.Bottom: {
2266 child.SetBounds(space.Left, space.Bottom-child.Height, space.Width, child.Height);
2267 space.Height-=child.Height;
2273 for (int i = child_controls.Count - 1; i >= 0; i--) {
2274 child=child_controls[i];
2276 if (child.Dock == DockStyle.Fill) {
2277 child.SetBounds(space.Left, space.Top, space.Width, space.Height);
2283 space=this.DisplayRectangle;
2285 // Deal with anchoring
2286 for (int i=0; i < child_controls.Count; i++) {
2292 child=child_controls[i];
2293 anchor=child.Anchor;
2298 height=child.Height;
2300 // If the control is docked we don't need to do anything
2301 if (child.Dock != DockStyle.None) {
2305 if ((anchor & AnchorStyles.Left) !=0 ) {
2306 if ((anchor & AnchorStyles.Right) != 0) {
2307 // Anchoring to left and right
2308 width=width+diff_width;
2312 } else if ((anchor & AnchorStyles.Right) != 0) {
2318 if ((anchor & AnchorStyles.Top) !=0 ) {
2319 if ((anchor & AnchorStyles.Bottom) != 0) {
2320 height+=diff_height;
2324 } else if ((anchor & AnchorStyles.Bottom) != 0) {
2339 child.SetBounds(left, top, width, height);
2342 // Let everyone know
2346 // Need to make sure we decremend layout_suspended
2352 public Point PointToClient (Point p) {
2356 XplatUI.ScreenToClient (Handle, ref x, ref y);
2358 return new Point (x, y);
2361 public Point PointToScreen(Point p) {
2365 XplatUI.ClientToScreen(Handle, ref x, ref y);
2367 return new Point(x, y);
2370 public virtual bool PreProcessMessage(ref Message msg) {
2373 if ((msg.Msg == (int)Msg.WM_KEYDOWN) || (msg.Msg == (int)Msg.WM_SYSKEYDOWN)) {
2374 key_data = (Keys)msg.WParam.ToInt32();
2375 if (!ProcessCmdKey(ref msg, key_data)) {
2376 if (IsInputKey(key_data)) {
2380 return ProcessDialogKey(key_data);
2384 } else if (msg.Msg == (int)Msg.WM_CHAR) {
2385 if (IsInputChar((char)msg.WParam)) {
2388 } else if (msg.Msg == (int)Msg.WM_SYSCHAR) {
2389 if (IsInputChar((char)msg.WParam)) {
2392 return ProcessDialogChar((char)msg.WParam);
2397 public Rectangle RectangleToClient(Rectangle r) {
2398 return new Rectangle(PointToClient(r.Location), r.Size);
2401 public Rectangle RectangleToScreen(Rectangle r) {
2402 return new Rectangle(PointToScreen(r.Location), r.Size);
2405 public virtual void Refresh() {
2406 if (IsHandleCreated == true) {
2408 XplatUI.UpdateWindow(window.Handle);
2412 [EditorBrowsable(EditorBrowsableState.Never)]
2413 public virtual void ResetBackColor() {
2414 background_color = Color.Empty;
2417 #if haveDataBindings
2418 [EditorBrowsable(EditorBrowsableState.Never)]
2420 public void ResetBindings() {
2425 [EditorBrowsable(EditorBrowsableState.Never)]
2426 public virtual void ResetCursor() {
2430 [EditorBrowsable(EditorBrowsableState.Never)]
2431 public virtual void ResetFont() {
2435 [EditorBrowsable(EditorBrowsableState.Never)]
2436 public virtual void ResetForeColor() {
2437 foreground_color = Color.Empty;
2440 [EditorBrowsable(EditorBrowsableState.Never)]
2441 public void ResetImeMode() {
2442 ime_mode = DefaultImeMode;
2445 [EditorBrowsable(EditorBrowsableState.Never)]
2446 public virtual void ResetRightToLeft() {
2447 right_to_left = RightToLeft.Inherit;
2450 public virtual void ResetText() {
2454 public void ResumeLayout() {
2455 ResumeLayout (true);
2458 public void ResumeLayout(bool performLayout) {
2461 if (layout_suspended > 0) {
2465 if (performLayout || layout_pending) {
2470 public void Scale(float ratio) {
2471 ScaleCore(ratio, ratio);
2474 public void Scale(float dx, float dy) {
2478 public void Select() {
2479 Select(false, false);
2482 public bool SelectNextControl(Control ctl, bool forward, bool tabStopOnly, bool nested, bool wrap) {
2487 c = GetNextControl(c, forward);
2496 if (c.CanSelect && ((c.parent == ctl.parent) || nested) && (c.tab_stop || !tabStopOnly)) {
2500 } while (c != ctl); // If we wrap back to ourselves we stop
2505 public void SendToBack() {
2506 if ((parent != null) && (parent.child_controls[parent.child_controls.Count-1]!=this)) {
2507 if (parent.child_controls.Contains(this)) {
2508 parent.child_controls.SetChildIndex(this, parent.child_controls.Count);
2512 XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, false, true);
2513 if (parent != null) {
2518 public void SetBounds(int x, int y, int width, int height) {
2519 SetBoundsCore(x, y, width, height, BoundsSpecified.All);
2522 public void SetBounds(int x, int y, int width, int height, BoundsSpecified specified) {
2523 SetBoundsCore(x, y, width, height, specified);
2526 public void Show() {
2527 if (!IsHandleCreated) {
2528 this.CreateControl();
2534 public void SuspendLayout() {
2538 public void Update() {
2539 needs_redraw = true;
2540 XplatUI.UpdateWindow(window.Handle);
2542 #endregion // Public Instance Methods
2544 #region Protected Instance Methods
2545 [EditorBrowsable(EditorBrowsableState.Advanced)]
2546 [MonoTODO("Implement this and tie it into Control.ControlAccessibleObject.NotifyClients")]
2547 protected void AccessibilityNotifyClients(AccessibleEvents accEvent, int childID) {
2548 throw new NotImplementedException();
2551 [EditorBrowsable(EditorBrowsableState.Advanced)]
2552 protected virtual AccessibleObject CreateAccessibilityInstance() {
2553 return new Control.ControlAccessibleObject(this);
2556 [EditorBrowsable(EditorBrowsableState.Advanced)]
2557 protected virtual ControlCollection CreateControlsInstance() {
2558 return new ControlCollection(this);
2561 [EditorBrowsable(EditorBrowsableState.Advanced)]
2562 protected virtual void CreateHandle() {
2564 throw new ObjectDisposedException(Name);
2567 if (IsHandleCreated) {
2572 window = new ControlNativeWindow(this);
2573 window.CreateHandle(CreateParams);
2575 // Find out where the window manager placed us
2580 if (window.Handle!=IntPtr.Zero) {
2581 if (!controls.Contains(window.Handle)) {
2585 creator_thread = Thread.CurrentThread;
2587 XplatUI.SetWindowBackground(window.Handle, this.BackColor);
2589 OnHandleCreated(EventArgs.Empty);
2593 [EditorBrowsable(EditorBrowsableState.Advanced)]
2594 protected virtual void DefWndProc(ref Message m) {
2595 window.DefWndProc(ref m);
2598 [EditorBrowsable(EditorBrowsableState.Advanced)]
2599 protected virtual void DestroyHandle() {
2600 if (IsHandleCreated) {
2601 // Destroy our children before we destroy ourselves, to prevent them from
2602 // being implictly (without us knowing) destroyed
2603 for (int i=0; i < child_controls.Count; i++) {
2604 child_controls[i].DestroyHandle();
2608 if (window != null) {
2609 window.DestroyHandle();
2611 OnHandleDestroyed(EventArgs.Empty);
2615 protected bool GetStyle(ControlStyles flag) {
2616 return (control_style & flag) != 0;
2619 protected bool GetTopLevel() {
2623 [EditorBrowsable(EditorBrowsableState.Advanced)]
2624 protected virtual void InitLayout() {
2625 if (parent != null) {
2626 parent.PerformLayout(this, "parent");
2630 [EditorBrowsable(EditorBrowsableState.Advanced)]
2631 protected void InvokeGotFocus(Control toInvoke, EventArgs e) {
2632 toInvoke.OnGotFocus(e);
2635 [EditorBrowsable(EditorBrowsableState.Advanced)]
2636 protected void InvokeLostFocus(Control toInvoke, EventArgs e) {
2637 toInvoke.OnLostFocus(e);
2640 [EditorBrowsable(EditorBrowsableState.Advanced)]
2641 protected void InvokeOnClick(Control toInvoke, EventArgs e) {
2642 toInvoke.OnClick(e);
2645 protected void InvokePaint(Control toInvoke, PaintEventArgs e) {
2646 toInvoke.OnPaint(e);
2649 protected void InvokePaintBackground(Control toInvoke, PaintEventArgs e) {
2650 toInvoke.OnPaintBackground(e);
2653 protected virtual bool IsInputChar (char charCode) {
2654 if (parent != null) {
2655 return parent.IsInputChar(charCode);
2661 protected virtual bool IsInputKey (Keys keyData) {
2662 // Doc says this one calls IsInputChar; not sure what to do with that
2666 [EditorBrowsable(EditorBrowsableState.Advanced)]
2667 protected virtual void NotifyInvalidate(Rectangle invalidatedArea) {
2671 protected virtual bool ProcessCmdKey(ref Message msg, Keys keyData) {
2672 if ((context_menu != null) && context_menu.ProcessCmdKey(ref msg, keyData)) {
2676 if (parent != null) {
2677 return parent.ProcessCmdKey(ref msg, keyData);
2683 protected virtual bool ProcessDialogChar(char charCode) {
2684 if (parent != null) {
2685 return parent.ProcessDialogChar (charCode);
2691 protected virtual bool ProcessDialogKey (Keys keyData) {
2692 if (parent != null) {
2693 return parent.ProcessDialogKey (keyData);
2699 protected virtual bool ProcessKeyEventArgs (ref Message msg)
2701 KeyEventArgs key_event;
2704 case (int)Msg.WM_KEYDOWN: {
2705 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
2706 OnKeyDown (key_event);
2707 return key_event.Handled;
2709 case (int)Msg.WM_KEYUP: {
2710 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
2711 OnKeyUp (key_event);
2712 return key_event.Handled;
2715 case (int)Msg.WM_CHAR: {
2716 KeyPressEventArgs key_press_event;
2718 key_press_event = new KeyPressEventArgs((char)msg.WParam);
2719 OnKeyPress(key_press_event);
2720 return key_press_event.Handled;
2731 protected internal virtual bool ProcessKeyMessage(ref Message msg) {
2732 if (parent != null) {
2733 if (parent.ProcessKeyPreview(ref msg)) {
2741 protected virtual bool ProcessKeyPreview(ref Message msg) {
2742 if (parent != null) {
2743 return parent.ProcessKeyPreview(ref msg);
2749 protected virtual bool ProcessMnemonic(char charCode) {
2754 [EditorBrowsable(EditorBrowsableState.Advanced)]
2755 protected void RaiseDragEvent(object key, DragEventArgs e) {
2759 [EditorBrowsable(EditorBrowsableState.Advanced)]
2760 protected void RaiseKeyEvent(object key, KeyEventArgs e) {
2764 [EditorBrowsable(EditorBrowsableState.Advanced)]
2765 protected void RaiseMouseEvent(object key, MouseEventArgs e) {
2769 [EditorBrowsable(EditorBrowsableState.Advanced)]
2770 protected void RaisePaintEvent(object key, PaintEventArgs e) {
2774 [EditorBrowsable(EditorBrowsableState.Advanced)]
2775 protected void RecreateHandle() {
2776 IEnumerator child = child_controls.GetEnumerator();
2780 if (IsHandleCreated) {
2786 while (child.MoveNext()) {
2787 ((Control)child.Current).RecreateHandle();
2793 is_recreating = false;
2796 [EditorBrowsable(EditorBrowsableState.Advanced)]
2797 protected void ResetMouseEventArgs() {
2801 [EditorBrowsable(EditorBrowsableState.Advanced)]
2802 protected ContentAlignment RtlTranslateAlignment(ContentAlignment align) {
2803 if (right_to_left == RightToLeft.No) {
2808 case ContentAlignment.TopLeft: {
2809 return ContentAlignment.TopRight;
2812 case ContentAlignment.TopRight: {
2813 return ContentAlignment.TopLeft;
2816 case ContentAlignment.MiddleLeft: {
2817 return ContentAlignment.MiddleRight;
2820 case ContentAlignment.MiddleRight: {
2821 return ContentAlignment.MiddleLeft;
2824 case ContentAlignment.BottomLeft: {
2825 return ContentAlignment.BottomRight;
2828 case ContentAlignment.BottomRight: {
2829 return ContentAlignment.BottomLeft;
2833 // if it's center it doesn't change
2839 [EditorBrowsable(EditorBrowsableState.Advanced)]
2840 protected HorizontalAlignment RtlTranslateAlignment(HorizontalAlignment align) {
2841 if ((right_to_left == RightToLeft.No) || (align == HorizontalAlignment.Center)) {
2845 if (align == HorizontalAlignment.Left) {
2846 return HorizontalAlignment.Right;
2849 // align must be HorizontalAlignment.Right
2850 return HorizontalAlignment.Left;
2853 [EditorBrowsable(EditorBrowsableState.Advanced)]
2854 protected LeftRightAlignment RtlTranslateAlignment(LeftRightAlignment align) {
2855 if (right_to_left == RightToLeft.No) {
2859 if (align == LeftRightAlignment.Left) {
2860 return LeftRightAlignment.Right;
2863 // align must be LeftRightAlignment.Right;
2864 return LeftRightAlignment.Left;
2867 [EditorBrowsable(EditorBrowsableState.Advanced)]
2868 protected ContentAlignment RtlTranslateContent(ContentAlignment align) {
2869 return RtlTranslateAlignment(align);
2872 [EditorBrowsable(EditorBrowsableState.Advanced)]
2873 protected HorizontalAlignment RtlTranslateHorizontal(HorizontalAlignment align) {
2874 return RtlTranslateAlignment(align);
2877 [EditorBrowsable(EditorBrowsableState.Advanced)]
2878 protected LeftRightAlignment RtlTranslateLeftRight(LeftRightAlignment align) {
2879 return RtlTranslateAlignment(align);
2882 [EditorBrowsable(EditorBrowsableState.Advanced)]
2883 protected virtual void ScaleCore(float dx, float dy) {
2889 location = new Point((int)(Left * dx), (int)(Top * dy));
2890 size = this.ClientSize;
2893 if (!GetStyle(ControlStyles.FixedWidth)) {
2894 size.Width = (int)(size.Width * dx);
2897 if (!GetStyle(ControlStyles.FixedHeight)) {
2898 size.Height = (int)(size.Height * dy);
2901 Location = location;
2904 /* Now scale our children */
2905 for (int i=0; i < child_controls.Count; i++) {
2906 child_controls[i].Scale(dx, dy);
2912 protected virtual void Select(bool directed, bool forward) {
2917 // Select this control
2922 if (parent == null) {
2926 // FIXME - this thing is doing the wrong stuff, needs to be similar to SelectNextControl
2928 index = parent.child_controls.IndexOf(this);
2933 if ((index+1) < parent.child_controls.Count) {
2942 index = parent.child_controls.Count-1;
2945 result = Select(parent.child_controls[index]);
2946 } while (!result && parent.child_controls[index] != this);
2949 [EditorBrowsable(EditorBrowsableState.Advanced)]
2950 protected virtual void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
2951 // SetBoundsCore updates the Win32 control itself. UpdateBounds updates the controls variables and fires events, I'm guessing - pdb
2952 if ((specified & BoundsSpecified.X) != BoundsSpecified.X) {
2956 if ((specified & BoundsSpecified.Y) != BoundsSpecified.Y) {
2960 if ((specified & BoundsSpecified.Width) != BoundsSpecified.Width) {
2964 if ((specified & BoundsSpecified.Height) != BoundsSpecified.Height) {
2968 if (IsHandleCreated) {
2969 XplatUI.SetWindowPos(Handle, x, y, width, height);
2971 UpdateBounds(x, y, width, height);
2974 [EditorBrowsable(EditorBrowsableState.Advanced)]
2975 protected virtual void SetClientSizeCore(int x, int y) {
2976 // Calculate the actual window size from the client size (it usually stays the same or grows)
2977 Rectangle ClientRect;
2978 Rectangle WindowRect;
2981 ClientRect = new Rectangle(0, 0, x, y);
2982 cp = this.CreateParams;
2984 if (XplatUI.CalculateWindowRect(Handle, ref ClientRect, cp.Style, cp.ExStyle, IntPtr.Zero, out WindowRect)==false) {
2988 SetBoundsCore(bounds.X, bounds.Y, WindowRect.Width, WindowRect.Height, BoundsSpecified.Size);
2991 [EditorBrowsable(EditorBrowsableState.Advanced)]
2992 protected void SetStyle(ControlStyles flag, bool value) {
2994 control_style |= flag;
2996 control_style &= ~flag;
2998 OnStyleChanged(EventArgs.Empty);
3001 protected void SetTopLevel(bool value) {
3002 if ((GetTopLevel() != value) && (parent != null)) {
3003 throw new Exception();
3007 if (value == true) {
3017 is_toplevel = value;
3020 protected virtual void SetVisibleCore(bool value) {
3021 if (value!=is_visible) {
3023 XplatUI.SetVisible(Handle, value);
3024 // Explicitly move Toplevel windows to where we want them;
3025 // apparently moving unmapped toplevel windows doesn't work
3026 if (is_visible && (this is Form)) {
3027 XplatUI.SetWindowPos(window.Handle, bounds.X, bounds.Y, bounds.Width, bounds.Height);
3029 OnVisibleChanged(EventArgs.Empty);
3032 if (dc_mem != null) {
3037 if (bmp_mem != null) {
3042 this.CreateBuffers(bounds.Width, bounds.Height);
3047 if (value == false && parent != null) {
3050 // Need to start at parent, GetContainerControl might return ourselves if we're a container
3051 container = (Control)parent.GetContainerControl();
3052 if (container != null) {
3053 container.SelectNextControl(this, true, true, true, true);
3057 if (parent != null) {
3058 parent.PerformLayout(this, "visible");
3060 PerformLayout(this, "visible");
3065 [EditorBrowsable(EditorBrowsableState.Advanced)]
3066 protected void UpdateBounds() {
3074 if (!IsHandleCreated) {
3078 XplatUI.GetWindowPos(this.Handle, this is Form, out x, out y, out width, out height, out client_width, out client_height);
3080 UpdateBounds(x, y, width, height, client_width, client_height);
3083 [EditorBrowsable(EditorBrowsableState.Advanced)]
3084 protected void UpdateBounds(int x, int y, int width, int height) {
3085 // UpdateBounds only seems to set our sizes and fire events but not update the GUI window to match
3087 bool resized = false;
3089 int client_x_diff = this.bounds.Width-this.client_size.Width;
3090 int client_y_diff = this.bounds.Height-this.client_size.Height;
3092 // Needed to generate required notifications
3093 if ((this.bounds.X!=x) || (this.bounds.Y!=y)) {
3097 if ((this.Bounds.Width!=width) || (this.Bounds.Height!=height)) {
3104 bounds.Height=height;
3106 // Update client rectangle as well
3107 if (this.layout_suspended==0) {
3108 prev_size.Width=client_size.Width;
3109 prev_size.Height=client_size.Height;
3112 client_size.Width=width-client_x_diff;
3113 client_size.Height=height-client_y_diff;
3116 OnLocationChanged(EventArgs.Empty);
3120 OnSizeChanged(EventArgs.Empty);
3124 [EditorBrowsable(EditorBrowsableState.Advanced)]
3125 protected void UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) {
3126 UpdateBounds(x, y, width, height);
3128 this.client_size.Width=clientWidth;
3129 this.client_size.Height=clientHeight;
3132 [EditorBrowsable(EditorBrowsableState.Advanced)]
3133 protected void UpdateStyles() {
3134 if (!IsHandleCreated) {
3138 XplatUI.SetWindowStyle(window.Handle, CreateParams);
3141 [EditorBrowsable(EditorBrowsableState.Advanced)]
3142 protected void UpdateZOrder() {
3147 if (parent == null) {
3153 children = ctl.child_controls.Count;
3154 for (int i = 1; i < children; i++ ) {
3155 XplatUI.SetZOrder(ctl.child_controls[i].window.Handle, ctl.child_controls[i-1].window.Handle, false, false);
3158 children = child_controls.Count;
3159 for (int i = 1; i < children; i++ ) {
3160 XplatUI.SetZOrder(child_controls[i].window.Handle, child_controls[i-1].window.Handle, false, false);
3165 protected virtual void WndProc(ref Message m) {
3167 Console.WriteLine("Control received message {0}", (Msg)m.Msg);
3169 if ((this.control_style & ControlStyles.EnableNotifyMessage) != 0) {
3173 switch((Msg)m.Msg) {
3174 case Msg.WM_WINDOWPOSCHANGED: {
3177 if (GetStyle(ControlStyles.ResizeRedraw)) {
3184 case Msg.WM_PAINT: {
3185 PaintEventArgs paint_event;
3187 paint_event = XplatUI.PaintEventStart(Handle);
3189 if (!needs_redraw) {
3190 // Just blit the previous image
3191 paint_event.Graphics.DrawImage (ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle, GraphicsUnit.Pixel);
3192 XplatUI.PaintEventEnd(Handle);
3197 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
3198 dc = paint_event.SetGraphics (DeviceContext);
3201 if ((control_style & (ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint)) == (ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint)) {
3202 OnPaintBackground(paint_event);
3205 OnPaint(paint_event);
3207 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
3208 dc.DrawImage (ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle, GraphicsUnit.Pixel);
3209 paint_event.SetGraphics (dc);
3210 needs_redraw = false;
3213 XplatUI.PaintEventEnd(Handle);
3215 if (!GetStyle(ControlStyles.UserPaint)) {
3222 case Msg.WM_ERASEBKGND: {
3223 if (GetStyle (ControlStyles.UserPaint)) {
3224 if (!GetStyle(ControlStyles.AllPaintingInWmPaint)) {
3225 PaintEventArgs eraseEventArgs = new PaintEventArgs (m.WParam == IntPtr.Zero ? Graphics.FromHwnd (m.HWnd) :
3226 Graphics.FromHdc (m.WParam), new Rectangle (new Point (0,0),Size));
3227 OnPaintBackground (eraseEventArgs);
3230 XplatUI.EraseWindowBackground(m.HWnd, m.WParam);
3232 // The DefWndProc will never have to handle this, we don't ever set hbr on the window
3233 m.Result = (IntPtr)1;
3237 case Msg.WM_LBUTTONUP: {
3238 HandleClick(mouse_clicks);
3239 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Left,
3241 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3243 if (mouse_clicks > 1) {
3249 case Msg.WM_LBUTTONDOWN: {
3250 if (CanSelect && !is_selected) {
3253 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3254 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3260 case Msg.WM_LBUTTONDBLCLK: {
3262 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3263 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3269 case Msg.WM_MBUTTONUP: {
3270 HandleClick(mouse_clicks);
3271 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Middle,
3273 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3275 if (mouse_clicks > 1) {
3281 case Msg.WM_MBUTTONDOWN: {
3282 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3283 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3289 case Msg.WM_MBUTTONDBLCLK: {
3291 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3292 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3297 case Msg.WM_RBUTTONUP: {
3298 if (context_menu != null) {
3299 context_menu.Show(this, new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ())));
3302 HandleClick(mouse_clicks);
3303 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Right,
3305 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3307 if (mouse_clicks > 1) {
3313 case Msg.WM_RBUTTONDOWN: {
3314 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3315 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3320 case Msg.WM_RBUTTONDBLCLK: {
3322 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3323 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3328 case Msg.WM_MOUSEWHEEL: {
3330 OnMouseWheel (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3331 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3332 HighOrder(m.WParam.ToInt32())));
3337 case Msg.WM_MOUSEMOVE: {
3338 OnMouseMove (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3340 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3345 case Msg.WM_MOUSE_ENTER: {
3350 OnMouseEnter(EventArgs.Empty);
3354 case Msg.WM_MOUSE_LEAVE: {
3356 OnMouseLeave(EventArgs.Empty);
3360 case Msg.WM_MOUSEHOVER: {
3361 OnMouseHover(EventArgs.Empty);
3365 case Msg.WM_SYSKEYDOWN:
3366 case Msg.WM_KEYDOWN:
3367 case Msg.WM_SYSKEYUP:
3369 case Msg.WM_SYSCHAR:
3371 if (ProcessKeyEventArgs(ref m)) {
3375 if (PreProcessMessage(ref m)) {
3379 if (ProcessKeyMessage(ref m)) {
3388 if (m.LParam != IntPtr.Zero) {
3391 hi = new HELPINFO();
3393 hi = (HELPINFO) Marshal.PtrToStructure (m.LParam, typeof (HELPINFO));
3394 mouse_pos = new Point(hi.MousePos.x, hi.MousePos.y);
3396 mouse_pos = Control.MousePosition;
3398 OnHelpRequested(new HelpEventArgs(mouse_pos));
3399 m.Result = (IntPtr)1;
3403 case Msg.WM_KILLFOCUS: {
3404 OnLeave(EventArgs.Empty);
3405 if (CausesValidation) {
3407 e = new CancelEventArgs(false);
3416 OnValidated(EventArgs.Empty);
3419 this.has_focus = false;
3420 this.is_selected = false;
3421 OnLostFocus(EventArgs.Empty);
3425 case Msg.WM_SETFOCUS: {
3426 OnEnter(EventArgs.Empty);
3427 this.has_focus = true;
3428 OnGotFocus(EventArgs.Empty);
3433 case Msg.WM_SYSCOLORCHANGE: {
3434 ThemeEngine.Current.ResetDefaults();
3435 OnSystemColorsChanged(EventArgs.Empty);
3440 case Msg.WM_SETCURSOR: {
3441 if (cursor == null) {
3446 XplatUI.SetCursor(window.Handle, cursor.handle);
3447 m.Result = (IntPtr)1;
3457 #endregion // Public Instance Methods
3459 #region OnXXX methods
3460 [EditorBrowsable(EditorBrowsableState.Advanced)]
3461 protected virtual void OnBackColorChanged(EventArgs e) {
3462 if (BackColorChanged!=null) BackColorChanged(this, e);
3463 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackColorChanged(e);
3466 [EditorBrowsable(EditorBrowsableState.Advanced)]
3467 protected virtual void OnBackgroundImageChanged(EventArgs e) {
3468 if (BackgroundImageChanged!=null) BackgroundImageChanged(this, e);
3469 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackgroundImageChanged(e);
3472 [EditorBrowsable(EditorBrowsableState.Advanced)]
3473 protected virtual void OnBindingContextChanged(EventArgs e) {
3474 CheckDataBindings ();
3475 if (BindingContextChanged!=null) {
3476 BindingContextChanged(this, e);
3478 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBindingContextChanged(e);
3481 [EditorBrowsable(EditorBrowsableState.Advanced)]
3482 protected virtual void OnCausesValidationChanged(EventArgs e) {
3483 if (CausesValidationChanged!=null) CausesValidationChanged(this, e);
3486 [EditorBrowsable(EditorBrowsableState.Advanced)]
3487 protected virtual void OnChangeUICues(UICuesEventArgs e) {
3488 if (ChangeUICues!=null) ChangeUICues(this, e);
3491 [EditorBrowsable(EditorBrowsableState.Advanced)]
3492 protected virtual void OnClick(EventArgs e) {
3493 if (Click!=null) Click(this, e);
3496 [EditorBrowsable(EditorBrowsableState.Advanced)]
3497 protected virtual void OnContextMenuChanged(EventArgs e) {
3498 if (ContextMenuChanged!=null) ContextMenuChanged(this, e);
3501 [EditorBrowsable(EditorBrowsableState.Advanced)]
3502 protected virtual void OnControlAdded(ControlEventArgs e) {
3503 if (ControlAdded!=null) ControlAdded(this, e);
3506 [EditorBrowsable(EditorBrowsableState.Advanced)]
3507 protected virtual void OnControlRemoved(ControlEventArgs e) {
3508 if (ControlRemoved!=null) ControlRemoved(this, e);
3511 [EditorBrowsable(EditorBrowsableState.Advanced)]
3512 protected virtual void OnCreateControl() {
3516 [EditorBrowsable(EditorBrowsableState.Advanced)]
3517 protected virtual void OnCursorChanged(EventArgs e) {
3518 if (CursorChanged!=null) CursorChanged(this, e);
3521 [EditorBrowsable(EditorBrowsableState.Advanced)]
3522 protected virtual void OnDockChanged(EventArgs e) {
3523 if (DockChanged!=null) DockChanged(this, e);
3526 [EditorBrowsable(EditorBrowsableState.Advanced)]
3527 protected virtual void OnDoubleClick(EventArgs e) {
3528 if (DoubleClick!=null) DoubleClick(this, e);
3531 [EditorBrowsable(EditorBrowsableState.Advanced)]
3532 protected virtual void OnDragDrop(DragEventArgs drgevent) {
3533 if (DragDrop!=null) DragDrop(this, drgevent);
3536 [EditorBrowsable(EditorBrowsableState.Advanced)]
3537 protected virtual void OnDragEnter(DragEventArgs drgevent) {
3538 if (DragEnter!=null) DragEnter(this, drgevent);
3541 [EditorBrowsable(EditorBrowsableState.Advanced)]
3542 protected virtual void OnDragLeave(EventArgs e) {
3543 if (DragLeave!=null) DragLeave(this, e);
3546 [EditorBrowsable(EditorBrowsableState.Advanced)]
3547 protected virtual void OnDragOver(DragEventArgs drgevent) {
3548 if (DragOver!=null) DragOver(this, drgevent);
3551 [EditorBrowsable(EditorBrowsableState.Advanced)]
3552 protected virtual void OnEnabledChanged(EventArgs e) {
3553 if (EnabledChanged!=null) EnabledChanged(this, e);
3554 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentEnabledChanged(e);
3557 [EditorBrowsable(EditorBrowsableState.Advanced)]
3558 protected virtual void OnEnter(EventArgs e) {
3559 if (Enter!=null) Enter(this, e);
3562 [EditorBrowsable(EditorBrowsableState.Advanced)]
3563 protected virtual void OnFontChanged(EventArgs e) {
3564 if (FontChanged!=null) FontChanged(this, e);
3565 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentFontChanged(e);
3568 [EditorBrowsable(EditorBrowsableState.Advanced)]
3569 protected virtual void OnForeColorChanged(EventArgs e) {
3570 if (ForeColorChanged!=null) ForeColorChanged(this, e);
3571 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentForeColorChanged(e);
3574 [EditorBrowsable(EditorBrowsableState.Advanced)]
3575 protected virtual void OnGiveFeedback(GiveFeedbackEventArgs gfbevent) {
3576 if (GiveFeedback!=null) GiveFeedback(this, gfbevent);
3579 [EditorBrowsable(EditorBrowsableState.Advanced)]
3580 protected virtual void OnGotFocus(EventArgs e) {
3581 if (GotFocus!=null) GotFocus(this, e);
3584 [EditorBrowsable(EditorBrowsableState.Advanced)]
3585 protected virtual void OnHandleCreated(EventArgs e) {
3586 if (HandleCreated!=null) HandleCreated(this, e);
3589 [EditorBrowsable(EditorBrowsableState.Advanced)]
3590 protected virtual void OnHandleDestroyed(EventArgs e) {
3591 if (HandleDestroyed!=null) HandleDestroyed(this, e);
3594 [EditorBrowsable(EditorBrowsableState.Advanced)]
3595 protected virtual void OnHelpRequested(HelpEventArgs hevent) {
3596 if (HelpRequested!=null) HelpRequested(this, hevent);
3599 protected virtual void OnImeModeChanged(EventArgs e) {
3600 if (ImeModeChanged!=null) ImeModeChanged(this, e);
3603 [EditorBrowsable(EditorBrowsableState.Advanced)]
3604 protected virtual void OnInvalidated(InvalidateEventArgs e) {
3605 needs_redraw = true;
3606 if (Invalidated!=null) Invalidated(this, e);
3609 [EditorBrowsable(EditorBrowsableState.Advanced)]
3610 protected virtual void OnKeyDown(KeyEventArgs e) {
3611 if (KeyDown!=null) KeyDown(this, e);
3614 [EditorBrowsable(EditorBrowsableState.Advanced)]
3615 protected virtual void OnKeyPress(KeyPressEventArgs e) {
3616 if (KeyPress!=null) KeyPress(this, e);
3619 [EditorBrowsable(EditorBrowsableState.Advanced)]
3620 protected virtual void OnKeyUp(KeyEventArgs e) {
3621 if (KeyUp!=null) KeyUp(this, e);
3624 [EditorBrowsable(EditorBrowsableState.Advanced)]
3625 protected virtual void OnLayout(LayoutEventArgs levent) {
3626 if (Layout!=null) Layout(this, levent);
3629 [EditorBrowsable(EditorBrowsableState.Advanced)]
3630 protected virtual void OnLeave(EventArgs e) {
3631 if (Leave!=null) Leave(this, e);
3634 [EditorBrowsable(EditorBrowsableState.Advanced)]
3635 protected virtual void OnLocationChanged(EventArgs e) {
3637 if (LocationChanged!=null) LocationChanged(this, e);
3640 [EditorBrowsable(EditorBrowsableState.Advanced)]
3641 protected virtual void OnLostFocus(EventArgs e) {
3642 if (LostFocus!=null) LostFocus(this, e);
3645 [EditorBrowsable(EditorBrowsableState.Advanced)]
3646 protected virtual void OnMouseDown(MouseEventArgs e) {
3647 if (MouseDown!=null) MouseDown(this, e);
3650 [EditorBrowsable(EditorBrowsableState.Advanced)]
3651 protected virtual void OnMouseEnter(EventArgs e) {
3652 if (MouseEnter!=null) MouseEnter(this, e);
3655 [EditorBrowsable(EditorBrowsableState.Advanced)]
3656 protected virtual void OnMouseHover(EventArgs e) {
3657 if (MouseHover!=null) MouseHover(this, e);
3660 [EditorBrowsable(EditorBrowsableState.Advanced)]
3661 protected virtual void OnMouseLeave(EventArgs e) {
3662 if (MouseLeave!=null) MouseLeave(this, e);
3665 [EditorBrowsable(EditorBrowsableState.Advanced)]
3666 protected virtual void OnMouseMove(MouseEventArgs e) {
3667 if (MouseMove!=null) MouseMove(this, e);
3670 [EditorBrowsable(EditorBrowsableState.Advanced)]
3671 protected virtual void OnMouseUp(MouseEventArgs e) {
3672 if (MouseUp!=null) MouseUp(this, e);
3675 [EditorBrowsable(EditorBrowsableState.Advanced)]
3676 protected virtual void OnMouseWheel(MouseEventArgs e) {
3677 if (MouseWheel!=null) MouseWheel(this, e);
3680 [EditorBrowsable(EditorBrowsableState.Advanced)]
3681 protected virtual void OnMove(EventArgs e) {
3682 if (Move!=null) Move(this, e);
3685 [EditorBrowsable(EditorBrowsableState.Advanced)]
3686 protected virtual void OnNotifyMessage(Message m) {
3690 [EditorBrowsable(EditorBrowsableState.Advanced)]
3691 protected virtual void OnPaint(PaintEventArgs e) {
3692 if (Paint!=null) Paint(this, e);
3695 [EditorBrowsable(EditorBrowsableState.Advanced)]
3696 protected virtual void OnPaintBackground(PaintEventArgs pevent) {
3700 [EditorBrowsable(EditorBrowsableState.Advanced)]
3701 protected virtual void OnParentBackColorChanged(EventArgs e) {
3702 if (background_color.IsEmpty && background_image==null) {
3704 OnBackColorChanged(e);
3708 [EditorBrowsable(EditorBrowsableState.Advanced)]
3709 protected virtual void OnParentBackgroundImageChanged(EventArgs e) {
3710 if (background_color.IsEmpty && background_image==null) {
3712 OnBackgroundImageChanged(e);
3716 [EditorBrowsable(EditorBrowsableState.Advanced)]
3717 protected virtual void OnParentBindingContextChanged(EventArgs e) {
3718 if (binding_context==null) {
3719 binding_context=Parent.binding_context;
3720 OnBindingContextChanged(e);
3724 [EditorBrowsable(EditorBrowsableState.Advanced)]
3725 protected virtual void OnParentChanged(EventArgs e) {
3726 if (ParentChanged!=null) ParentChanged(this, e);
3729 [EditorBrowsable(EditorBrowsableState.Advanced)]
3730 protected virtual void OnParentEnabledChanged(EventArgs e) {
3731 if (is_enabled != Parent.is_enabled) {
3732 is_enabled=Parent.is_enabled;
3734 if (EnabledChanged != null) {
3735 EnabledChanged(this, e);
3740 [EditorBrowsable(EditorBrowsableState.Advanced)]
3741 protected virtual void OnParentFontChanged(EventArgs e) {
3748 [EditorBrowsable(EditorBrowsableState.Advanced)]
3749 protected virtual void OnParentForeColorChanged(EventArgs e) {
3750 if (foreground_color.IsEmpty) {
3752 OnForeColorChanged(e);
3756 [EditorBrowsable(EditorBrowsableState.Advanced)]
3757 protected virtual void OnParentRightToLeftChanged(EventArgs e) {
3758 if (right_to_left==RightToLeft.Inherit) {
3760 OnRightToLeftChanged(e);
3764 [EditorBrowsable(EditorBrowsableState.Advanced)]
3765 protected virtual void OnParentVisibleChanged(EventArgs e) {
3767 OnVisibleChanged(e);
3771 [EditorBrowsable(EditorBrowsableState.Advanced)]
3772 protected virtual void OnQueryContinueDrag(QueryContinueDragEventArgs e) {
3773 if (QueryContinueDrag!=null) QueryContinueDrag(this, e);
3776 [EditorBrowsable(EditorBrowsableState.Advanced)]
3777 protected virtual void OnResize(EventArgs e) {
3778 if (Resize!=null) Resize(this, e);
3780 PerformLayout(this, "bounds");
3782 if (parent != null) {
3783 parent.PerformLayout();
3787 [EditorBrowsable(EditorBrowsableState.Advanced)]
3788 protected virtual void OnRightToLeftChanged(EventArgs e) {
3789 if (RightToLeftChanged!=null) RightToLeftChanged(this, e);
3790 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentRightToLeftChanged(e);
3793 [EditorBrowsable(EditorBrowsableState.Advanced)]
3794 protected virtual void OnSizeChanged(EventArgs e) {
3795 InvalidateBuffers ();
3797 if (SizeChanged!=null) SizeChanged(this, e);
3800 [EditorBrowsable(EditorBrowsableState.Advanced)]
3801 protected virtual void OnStyleChanged(EventArgs e) {
3802 if (StyleChanged!=null) StyleChanged(this, e);
3805 [EditorBrowsable(EditorBrowsableState.Advanced)]
3806 protected virtual void OnSystemColorsChanged(EventArgs e) {
3807 if (SystemColorsChanged!=null) SystemColorsChanged(this, e);
3810 [EditorBrowsable(EditorBrowsableState.Advanced)]
3811 protected virtual void OnTabIndexChanged(EventArgs e) {
3812 if (TabIndexChanged!=null) TabIndexChanged(this, e);
3815 [EditorBrowsable(EditorBrowsableState.Advanced)]
3816 protected virtual void OnTabStopChanged(EventArgs e) {
3817 if (TabStopChanged!=null) TabStopChanged(this, e);
3820 [EditorBrowsable(EditorBrowsableState.Advanced)]
3821 protected virtual void OnTextChanged(EventArgs e) {
3822 if (TextChanged!=null) TextChanged(this, e);
3825 [EditorBrowsable(EditorBrowsableState.Advanced)]
3826 protected virtual void OnValidated(EventArgs e) {
3827 if (Validated!=null) Validated(this, e);
3830 [EditorBrowsable(EditorBrowsableState.Advanced)]
3831 protected virtual void OnValidating(System.ComponentModel.CancelEventArgs e) {
3832 if (Validating!=null) Validating(this, e);
3835 [EditorBrowsable(EditorBrowsableState.Advanced)]
3836 protected virtual void OnVisibleChanged(EventArgs e) {
3843 if (bmp_mem!=null) {
3849 if (!this.IsHandleCreated) {
3850 this.CreateControl();
3856 if (VisibleChanged!=null) VisibleChanged(this, e);
3858 // We need to tell our kids
3859 for (int i=0; i<child_controls.Count; i++) {
3860 child_controls[i].OnParentVisibleChanged(e);
3863 #endregion // OnXXX methods
3866 public event EventHandler BackColorChanged;
3867 public event EventHandler BackgroundImageChanged;
3868 public event EventHandler BindingContextChanged;
3869 public event EventHandler CausesValidationChanged;
3870 public event UICuesEventHandler ChangeUICues;
3871 public event EventHandler Click;
3872 public event EventHandler ContextMenuChanged;
3874 [EditorBrowsable(EditorBrowsableState.Advanced)]
3876 public event ControlEventHandler ControlAdded;
3878 [EditorBrowsable(EditorBrowsableState.Advanced)]
3880 public event ControlEventHandler ControlRemoved;
3882 public event EventHandler CursorChanged;
3883 public event EventHandler DockChanged;
3884 public event EventHandler DoubleClick;
3885 public event DragEventHandler DragDrop;
3886 public event DragEventHandler DragEnter;
3887 public event EventHandler DragLeave;
3888 public event DragEventHandler DragOver;
3889 public event EventHandler EnabledChanged;
3890 public event EventHandler Enter;
3891 public event EventHandler FontChanged;
3892 public event EventHandler ForeColorChanged;
3893 public event GiveFeedbackEventHandler GiveFeedback;
3895 [EditorBrowsable(EditorBrowsableState.Advanced)]
3897 public event EventHandler GotFocus;
3899 [EditorBrowsable(EditorBrowsableState.Advanced)]
3901 public event EventHandler HandleCreated;
3903 [EditorBrowsable(EditorBrowsableState.Advanced)]
3905 public event EventHandler HandleDestroyed;
3907 public event HelpEventHandler HelpRequested;
3908 public event EventHandler ImeModeChanged;
3910 [EditorBrowsable(EditorBrowsableState.Advanced)]
3912 public event InvalidateEventHandler Invalidated;
3914 public event KeyEventHandler KeyDown;
3915 public event KeyPressEventHandler KeyPress;
3916 public event KeyEventHandler KeyUp;
3917 public event LayoutEventHandler Layout;
3918 public event EventHandler Leave;
3919 public event EventHandler LocationChanged;
3921 [EditorBrowsable(EditorBrowsableState.Advanced)]
3923 public event EventHandler LostFocus;
3925 public event MouseEventHandler MouseDown;
3926 public event EventHandler MouseEnter;
3927 public event EventHandler MouseHover;
3928 public event EventHandler MouseLeave;
3929 public event MouseEventHandler MouseMove;
3930 public event MouseEventHandler MouseUp;
3932 [EditorBrowsable(EditorBrowsableState.Advanced)]
3934 public event MouseEventHandler MouseWheel;
3936 public event EventHandler Move;
3937 public event PaintEventHandler Paint;
3938 public event EventHandler ParentChanged;
3939 public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp;
3940 public event QueryContinueDragEventHandler QueryContinueDrag;
3941 public event EventHandler Resize;
3942 public event EventHandler RightToLeftChanged;
3943 public event EventHandler SizeChanged;
3944 public event EventHandler StyleChanged;
3945 public event EventHandler SystemColorsChanged;
3946 public event EventHandler TabIndexChanged;
3947 public event EventHandler TabStopChanged;
3948 public event EventHandler TextChanged;
3949 public event EventHandler Validated;
3950 public event CancelEventHandler Validating;
3951 public event EventHandler VisibleChanged;
3952 #endregion // Events