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 internal static MouseButtons FromParamToMouseButtons (int param) {
758 MouseButtons buttons = MouseButtons.None;
760 if ((param & (int) MsgButtons.MK_LBUTTON) != 0)
761 buttons |= MouseButtons.Left;
763 if ((param & (int) MsgButtons.MK_MBUTTON) != 0)
764 buttons |= MouseButtons.Middle;
766 if ((param & (int) MsgButtons.MK_RBUTTON) != 0)
767 buttons |= MouseButtons.Right;
773 internal virtual bool ProcessControlMnemonic(char charCode) {
774 return ProcessMnemonic(charCode);
777 private static Control FindFlatForward(Control container, Control start) {
783 end = container.child_controls.Count;
786 index = start.tab_index;
791 for (int i = 0; i < end; i++) {
793 if (container.child_controls[i].tab_index > index) {
794 found = container.child_controls[i];
796 } else if (found.tab_index > container.child_controls[i].tab_index) {
797 if (container.child_controls[i].tab_index > index) {
798 found = container.child_controls[i];
805 private static Control FindControlForward(Control container, Control start) {
812 if ((start is IContainerControl) || start.GetStyle(ControlStyles.ContainerControl)) {
813 found = FindControlForward(start, null);
820 while (p != container) {
821 found = FindFlatForward(p, start);
829 return FindFlatForward(container, start);
832 private static Control FindFlatBackward(Control container, Control start) {
838 end = container.child_controls.Count;
841 index = start.tab_index;
843 // FIXME: Possible speed-up: Keep the highest taborder index in the container
845 for (int i = 0; i < end; i++) {
846 if (container.child_controls[i].tab_index > index) {
847 index = container.child_controls[i].tab_index;
853 for (int i = 0; i < end; i++) {
855 if (container.child_controls[i].tab_index < index) {
856 found = container.child_controls[i];
858 } else if (found.tab_index < container.child_controls[i].tab_index) {
859 if (container.child_controls[i].tab_index < index) {
860 found = container.child_controls[i];
867 private static Control FindControlBackward(Control container, Control start) {
873 found = FindFlatBackward(start.parent, start);
874 if (found == null && start.parent != container) {
879 found = FindFlatBackward(container, start);
882 while ((found != null) && ((found is IContainerControl) || found.GetStyle(ControlStyles.ContainerControl))) {
883 found = FindControlBackward(found, null);
892 private void HandleClick(int clicks) {
893 if (GetStyle(ControlStyles.StandardClick)) {
895 if (GetStyle(ControlStyles.StandardDoubleClick)) {
896 OnDoubleClick(EventArgs.Empty);
898 OnClick(EventArgs.Empty);
901 OnClick(EventArgs.Empty);
906 private void CheckDataBindings ()
908 if (data_bindings == null)
911 BindingContext binding_context = BindingContext;
912 foreach (Binding binding in data_bindings) {
913 binding.Check (binding_context);
917 #endregion // Private & Internal Methods
919 #region Public Static Properties
920 public static Color DefaultBackColor {
922 return ThemeEngine.Current.DefaultControlBackColor;
926 public static Font DefaultFont {
928 return ThemeEngine.Current.DefaultFont;
932 public static Color DefaultForeColor {
934 return ThemeEngine.Current.DefaultControlForeColor;
938 public static Keys ModifierKeys {
940 return XplatUI.State.ModifierKeys;
944 public static MouseButtons MouseButtons {
946 return XplatUI.State.MouseButtons;
950 public static Point MousePosition {
952 return Cursor.Position;
955 #endregion // Public Static Properties
957 #region Public Instance Properties
958 [EditorBrowsable(EditorBrowsableState.Advanced)]
960 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
961 public AccessibleObject AccessibilityObject {
963 if (accessibility_object==null) {
964 accessibility_object=CreateAccessibilityInstance();
966 return accessibility_object;
970 [EditorBrowsable(EditorBrowsableState.Advanced)]
972 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
973 public string AccessibleDefaultActionDescription {
975 return AccessibilityObject.default_action;
979 AccessibilityObject.default_action=value;
985 public string AccessibleDescription {
987 return AccessibilityObject.description;
991 AccessibilityObject.description=value;
997 public string AccessibleName {
999 return AccessibilityObject.Name;
1003 AccessibilityObject.Name=value;
1007 [DefaultValue(AccessibleRole.Default)]
1008 public AccessibleRole AccessibleRole {
1010 return AccessibilityObject.role;
1014 AccessibilityObject.role=value;
1018 [DefaultValue(false)]
1019 public virtual bool AllowDrop {
1021 return XplatUI.State.DropTarget;
1026 XplatUI.State.DropTarget=value;
1032 [RefreshProperties(RefreshProperties.Repaint)]
1033 [DefaultValue(AnchorStyles.Top | AnchorStyles.Left)]
1034 public virtual AnchorStyles Anchor {
1036 return anchor_style;
1042 if (parent != null) {
1043 parent.PerformLayout(this, "Parent");
1049 public virtual Color BackColor {
1051 if (background_color.IsEmpty) {
1053 return parent.BackColor;
1055 return DefaultBackColor;
1057 return background_color;
1061 background_color=value;
1062 if (this.IsHandleCreated) {
1063 XplatUI.SetWindowBackground(this.window.Handle, value);
1065 SetChildColor(this);
1066 OnBackColorChanged(EventArgs.Empty);
1072 [DefaultValue(null)]
1073 public virtual Image BackgroundImage {
1075 return background_image;
1079 if (background_image!=value) {
1080 background_image=value;
1081 OnBackgroundImageChanged(EventArgs.Empty);
1086 [EditorBrowsable(EditorBrowsableState.Advanced)]
1088 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1089 public virtual BindingContext BindingContext {
1091 if (binding_context != null)
1092 return binding_context;
1095 binding_context = Parent.BindingContext;
1096 return binding_context;
1099 if (binding_context != value) {
1100 binding_context = value;
1101 OnBindingContextChanged(EventArgs.Empty);
1106 [EditorBrowsable(EditorBrowsableState.Advanced)]
1108 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1111 return bounds.Y+bounds.Height;
1115 [EditorBrowsable(EditorBrowsableState.Advanced)]
1117 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1118 public Rectangle Bounds {
1124 SetBoundsCore(value.Left, value.Top, value.Width, value.Height, BoundsSpecified.All);
1128 [EditorBrowsable(EditorBrowsableState.Advanced)]
1130 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1131 public bool CanFocus {
1133 if (Visible && is_enabled && GetStyle(ControlStyles.Selectable)) {
1140 [EditorBrowsable(EditorBrowsableState.Advanced)]
1142 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1143 public bool CanSelect {
1147 if (!GetStyle(ControlStyles.Selectable) || this.parent == null) {
1151 parent = this.parent;
1152 while (parent != null) {
1153 if (!parent.is_visible || !parent.is_enabled) {
1157 parent = parent.parent;
1163 [EditorBrowsable(EditorBrowsableState.Advanced)]
1165 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1166 public bool Capture {
1168 return this.is_captured;
1172 if (this.IsHandleCreated) {
1173 if (value && !is_captured) {
1175 XplatUI.GrabWindow(this.window.Handle, IntPtr.Zero);
1176 } else if (!value && is_captured) {
1177 XplatUI.UngrabWindow(this.window.Handle);
1178 is_captured = false;
1184 [DefaultValue(true)]
1185 public bool CausesValidation {
1187 return this.causes_validation;
1191 if (this.causes_validation != value) {
1192 causes_validation = value;
1193 OnCausesValidationChanged(EventArgs.Empty);
1198 [EditorBrowsable(EditorBrowsableState.Advanced)]
1200 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1201 public Rectangle ClientRectangle {
1203 client_rect.Width = client_size.Width;
1204 client_rect.Height = client_size.Height;
1209 [EditorBrowsable(EditorBrowsableState.Advanced)]
1211 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1212 public Size ClientSize {
1215 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1216 return ((Form)this).form_parent_window.ClientSize;
1224 this.SetClientSizeCore(value.Width, value.Height);
1228 [EditorBrowsable(EditorBrowsableState.Advanced)]
1230 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1231 [DescriptionAttribute("ControlCompanyNameDescr")]
1232 public String CompanyName {
1234 return "Mono Project, Novell, Inc.";
1238 [EditorBrowsable(EditorBrowsableState.Advanced)]
1240 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1241 public bool ContainsFocus {
1247 for (int i=0; i < child_controls.Count; i++) {
1248 if (child_controls[i].ContainsFocus) {
1256 [DefaultValue(null)]
1257 public virtual ContextMenu ContextMenu {
1259 return context_menu;
1263 if (context_menu != value) {
1264 context_menu = value;
1265 OnContextMenuChanged(EventArgs.Empty);
1271 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
1272 public ControlCollection Controls {
1274 return this.child_controls;
1278 [EditorBrowsable(EditorBrowsableState.Advanced)]
1280 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1281 public bool Created {
1283 if (!this.is_disposed && (this.window.Handle != IntPtr.Zero)) {
1290 [AmbientValue(null)]
1291 public virtual Cursor Cursor {
1293 if (cursor != null) {
1297 if (parent != null) {
1298 return parent.Cursor;
1301 return Cursors.Default;
1305 if (cursor != value) {
1310 pt = Cursor.Position;
1311 if (bounds.Contains(pt)) {
1312 if (GetChildAtPoint(pt) == null) {
1313 if (cursor != null) {
1314 XplatUI.SetCursor(window.Handle, cursor.handle);
1316 if (parent != null) {
1317 XplatUI.SetCursor(window.Handle, parent.Cursor.handle);
1319 XplatUI.SetCursor(window.Handle, Cursors.def.handle);
1325 OnCursorChanged(EventArgs.Empty);
1331 [EditorBrowsable(EditorBrowsableState.Advanced)]
1333 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1334 public ControlBindingsCollection DataBindings {
1336 if (data_bindings == null)
1337 data_bindings = new ControlBindingsCollection (this);
1338 return data_bindings;
1342 [EditorBrowsable(EditorBrowsableState.Advanced)]
1344 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1345 public virtual Rectangle DisplayRectangle {
1347 return ClientRectangle;
1351 [EditorBrowsable(EditorBrowsableState.Advanced)]
1353 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1354 public bool Disposing {
1361 [RefreshProperties(RefreshProperties.Repaint)]
1362 [DefaultValue(DockStyle.None)]
1363 public virtual DockStyle Dock {
1369 if (dock_style == value) {
1375 if (parent != null) {
1376 parent.PerformLayout(this, "Parent");
1379 OnDockChanged(EventArgs.Empty);
1385 public bool Enabled {
1391 if (is_enabled == value) {
1397 OnEnabledChanged (EventArgs.Empty);
1401 [EditorBrowsable(EditorBrowsableState.Advanced)]
1403 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1404 public virtual bool Focused {
1406 return this.has_focus;
1411 [AmbientValue(null)]
1413 public virtual Font Font {
1419 if (Parent != null && Parent.Font != null) {
1427 if (font != null && font.Equals (value)) {
1433 OnFontChanged (EventArgs.Empty);
1438 public virtual Color ForeColor {
1440 if (foreground_color.IsEmpty) {
1442 return parent.ForeColor;
1444 return DefaultForeColor;
1446 return foreground_color;
1450 if (foreground_color != value) {
1451 foreground_color=value;
1453 OnForeColorChanged(EventArgs.Empty);
1460 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1461 public IntPtr Handle { // IWin32Window
1463 if (!IsHandleCreated) {
1466 return window.Handle;
1470 [EditorBrowsable(EditorBrowsableState.Advanced)]
1472 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1473 public bool HasChildren {
1475 if (this.child_controls.Count>0) {
1482 [EditorBrowsable(EditorBrowsableState.Always)]
1484 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1487 return this.bounds.Height;
1491 SetBoundsCore(bounds.X, bounds.Y, bounds.Width, value, BoundsSpecified.Height);
1495 [AmbientValue(ImeMode.Inherit)]
1497 public ImeMode ImeMode {
1503 if (ime_mode != value) {
1506 OnImeModeChanged(EventArgs.Empty);
1511 [EditorBrowsable(EditorBrowsableState.Advanced)]
1513 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1514 public bool InvokeRequired { // ISynchronizeInvoke
1516 if (creator_thread!=Thread.CurrentThread) {
1523 [EditorBrowsable(EditorBrowsableState.Advanced)]
1525 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1526 public bool IsAccessible {
1528 return is_accessible;
1532 is_accessible = value;
1536 [EditorBrowsable(EditorBrowsableState.Advanced)]
1538 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1539 public bool IsDisposed {
1541 return this.is_disposed;
1545 [EditorBrowsable(EditorBrowsableState.Advanced)]
1547 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1548 public bool IsHandleCreated {
1550 if ((window!=null) && (window.Handle!=IntPtr.Zero)) {
1558 [EditorBrowsable(EditorBrowsableState.Always)]
1560 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1563 return this.bounds.X;
1567 SetBoundsCore(value, bounds.Y, bounds.Width, bounds.Height, BoundsSpecified.X);
1572 public Point Location {
1574 return new Point(bounds.X, bounds.Y);
1578 SetBoundsCore(value.X, value.Y, bounds.Width, bounds.Height, BoundsSpecified.Location);
1583 public string Name {
1594 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1595 public Control Parent {
1601 if (value == this) {
1602 throw new ArgumentException("A circular control reference has been made. A control cannot be owned or parented to itself.");
1605 if (parent!=value) {
1607 parent.Controls.Remove(this);
1613 if (!parent.Controls.Contains(this)) {
1614 parent.Controls.Add(this);
1617 XplatUI.SetParent(Handle, value.Handle);
1621 OnParentChanged(EventArgs.Empty);
1626 [EditorBrowsable(EditorBrowsableState.Advanced)]
1628 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1629 public string ProductName {
1631 return "Novell Mono MWF";
1635 [EditorBrowsable(EditorBrowsableState.Advanced)]
1637 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1638 public string ProductVersion {
1640 return "1.1.4322.573";
1644 [EditorBrowsable(EditorBrowsableState.Advanced)]
1646 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1647 public bool RecreatingHandle {
1649 return is_recreating;
1653 [EditorBrowsable(EditorBrowsableState.Advanced)]
1655 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1656 public Region Region {
1658 return new Region(this.bounds);
1665 g = this.CreateGraphics();
1666 r = value.GetBounds(g);
1668 SetBounds((int)r.X, (int)r.Y, (int)r.Width, (int)r.Height);
1674 [EditorBrowsable(EditorBrowsableState.Advanced)]
1676 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1679 return this.bounds.X+this.bounds.Width;
1683 [AmbientValue(RightToLeft.Inherit)]
1685 public virtual RightToLeft RightToLeft {
1687 return right_to_left;
1691 if (value != right_to_left) {
1692 right_to_left = value;
1693 OnRightToLeftChanged(EventArgs.Empty);
1698 [EditorBrowsable(EditorBrowsableState.Advanced)]
1699 public override ISite Site {
1712 return new Size(Width, Height);
1716 SetBoundsCore(bounds.X, bounds.Y, value.Width, value.Height, BoundsSpecified.Size);
1721 [MergableProperty(false)]
1722 public int TabIndex {
1724 if (tab_index != -1) {
1731 if (tab_index != value) {
1733 OnTabIndexChanged(EventArgs.Empty);
1739 [DefaultValue(true)]
1740 public bool TabStop {
1746 if (tab_stop != value) {
1748 OnTabStopChanged(EventArgs.Empty);
1753 [Localizable(false)]
1755 [TypeConverter(typeof(StringConverter))]
1756 [DefaultValue(null)]
1763 control_tag = value;
1769 [BindableAttribute(true)]
1770 public virtual string Text {
1776 if (value == null) {
1777 value = String.Empty;
1782 XplatUI.Text(Handle, text);
1783 // FIXME: Do we need a Refresh() here?
1784 OnTextChanged (EventArgs.Empty);
1789 [EditorBrowsable(EditorBrowsableState.Always)]
1791 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1794 return this.bounds.Y;
1798 SetBoundsCore(bounds.X, value, bounds.Width, bounds.Height, BoundsSpecified.Y);
1802 [EditorBrowsable(EditorBrowsableState.Advanced)]
1804 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1805 public Control TopLevelControl {
1809 while (p.parent != null) {
1818 public bool Visible {
1822 } else if (parent != null) {
1823 return parent.Visible;
1830 SetVisibleCore(value);
1834 [EditorBrowsable(EditorBrowsableState.Always)]
1836 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1839 return this.bounds.Width;
1843 SetBoundsCore(bounds.X, bounds.Y, value, bounds.Height, BoundsSpecified.Width);
1847 [EditorBrowsable(EditorBrowsableState.Never)]
1849 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1850 public IWindowTarget WindowTarget {
1859 #endregion // Public Instance Properties
1861 #region Protected Instance Properties
1862 protected virtual CreateParams CreateParams {
1864 CreateParams create_params = new CreateParams();
1866 create_params.Caption = Text;
1867 create_params.X = Left;
1868 create_params.Y = Top;
1869 create_params.Width = Width;
1870 create_params.Height = Height;
1872 create_params.ClassName = XplatUI.DefaultClassName;
1873 create_params.ClassStyle = 0;
1874 create_params.ExStyle = 0;
1875 create_params.Param = 0;
1878 create_params.Parent = parent.Handle;
1881 create_params.Style = (int)WindowStyles.WS_CHILD | (int)WindowStyles.WS_CLIPCHILDREN | (int)WindowStyles.WS_CLIPSIBLINGS;
1884 create_params.Style |= (int)WindowStyles.WS_VISIBLE;
1887 return create_params;
1891 protected virtual ImeMode DefaultImeMode {
1893 return ImeMode.Inherit;
1897 protected virtual Size DefaultSize {
1899 return new Size(100, 23);
1903 protected int FontHeight {
1913 protected bool RenderRightToLeft {
1915 return (this.right_to_left == RightToLeft.Yes);
1919 protected bool ResizeRedraw {
1921 return GetStyle(ControlStyles.ResizeRedraw);
1925 SetStyle(ControlStyles.ResizeRedraw, value);
1929 [EditorBrowsable(EditorBrowsableState.Advanced)]
1931 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1932 protected virtual bool ShowFocusCues {
1938 [EditorBrowsable(EditorBrowsableState.Advanced)]
1940 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1941 protected bool ShowKeyboardCues {
1946 #endregion // Protected Instance Properties
1948 #region Public Static Methods
1949 [EditorBrowsable(EditorBrowsableState.Advanced)]
1950 public static Control FromChildHandle(IntPtr handle) {
1951 IEnumerator control = Control.controls.GetEnumerator();
1953 while (control.MoveNext()) {
1954 if (((Control)control.Current).window.Handle == handle) {
1956 if (((Control)control.Current).Parent != null) {
1957 return ((Control)control.Current).Parent;
1964 [EditorBrowsable(EditorBrowsableState.Advanced)]
1965 public static Control FromHandle(IntPtr handle) {
1966 IEnumerator control = Control.controls.GetEnumerator();
1968 while (control.MoveNext()) {
1969 if (((Control)control.Current).window.Handle == handle) {
1971 return ((Control)control.Current);
1977 public static bool IsMnemonic(char charCode, string text) {
1980 amp = text.IndexOf('&');
1983 if (amp + 1 < text.Length) {
1984 if (text[amp + 1] != '&') {
1985 if (Char.ToUpper(charCode) == Char.ToUpper(text.ToCharArray(amp + 1, 1)[0])) {
1995 #region Protected Static Methods
1996 [EditorBrowsable(EditorBrowsableState.Advanced)]
1997 protected static bool ReflectMessage(IntPtr hWnd, ref Message m) {
2000 c = Control.FromHandle(hWnd);
2010 #region Public Instance Methods
2011 [EditorBrowsable(EditorBrowsableState.Advanced)]
2012 public IAsyncResult BeginInvoke(Delegate method) {
2013 return BeginInvokeInternal(method, null);
2016 [EditorBrowsable(EditorBrowsableState.Advanced)]
2017 public IAsyncResult BeginInvoke (Delegate method, object[] args) {
2018 return BeginInvokeInternal (method, args);
2021 public void BringToFront() {
2022 if ((parent != null) && (parent.child_controls[0]!=this)) {
2023 if (parent.child_controls.Contains(this)) {
2024 parent.child_controls.SetChildIndex(this, 0);
2028 XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, true, false);
2030 if (parent != null) {
2035 public bool Contains(Control ctl) {
2036 while (ctl != null) {
2045 public void CreateControl() {
2047 if (!IsHandleCreated) {
2051 if (!create_handled) {
2052 create_handled = true;
2056 for (int i=0; i<child_controls.Count; i++) {
2057 child_controls[i].CreateControl();
2061 public Graphics CreateGraphics() {
2062 if (!IsHandleCreated) {
2063 this.CreateControl();
2065 return Graphics.FromHwnd(this.window.Handle);
2068 [MonoTODO("Come up with cross platform drag-drop driver interface")]
2069 public DragDropEffects DoDragDrop(object data, DragDropEffects allowedEffects) {
2070 return DragDropEffects.None;
2073 [EditorBrowsable(EditorBrowsableState.Advanced)]
2074 public object EndInvoke (IAsyncResult async_result) {
2075 AsyncMethodResult result = (AsyncMethodResult) async_result;
2076 return result.EndInvoke ();
2079 public Form FindForm() {
2092 public bool Focus() {
2093 if (IsHandleCreated && !has_focus) {
2095 XplatUI.SetFocus(window.Handle);
2100 public Control GetChildAtPoint(Point pt) {
2101 // Microsoft's version of this function doesn't seem to work, so I can't check
2102 // if we only consider children or also grandchildren, etc.
2103 // I'm gonna say 'children only'
2104 for (int i=0; i<child_controls.Count; i++) {
2105 if (child_controls[i].Bounds.Contains(pt)) {
2106 return child_controls[i];
2112 public IContainerControl GetContainerControl() {
2113 Control current = this;
2115 while (current!=null) {
2116 if ((current is IContainerControl) && ((current.control_style & ControlStyles.ContainerControl)!=0)) {
2117 return (IContainerControl)current;
2119 current = current.parent;
2124 public Control GetNextControl(Control ctl, bool forward) {
2125 // If we're not a container we don't play
2126 if (!(this is IContainerControl) && !this.GetStyle(ControlStyles.ContainerControl)) {
2130 // If ctl is not contained by this, we start at the first child of this
2131 if (!this.Contains(ctl)) {
2135 // Search through our controls, starting at ctl, stepping into children as we encounter them
2136 // try to find the control with the tabindex closest to our own, or, if we're looking into
2137 // child controls, the one with the smallest tabindex
2139 return FindControlForward(this, ctl);
2141 return FindControlBackward(this, ctl);
2144 public void Hide() {
2145 this.Visible = false;
2148 public void Invalidate() {
2149 Invalidate(ClientRectangle, false);
2152 public void Invalidate(bool invalidateChildren) {
2153 Invalidate(ClientRectangle, invalidateChildren);
2156 public void Invalidate(System.Drawing.Rectangle rc) {
2157 Invalidate(rc, false);
2160 public void Invalidate(System.Drawing.Rectangle rc, bool invalidateChildren) {
2161 if (!IsHandleCreated || !Visible) {
2165 NotifyInvalidate(rc);
2167 XplatUI.Invalidate(Handle, rc, false);
2169 if (invalidateChildren) {
2170 for (int i=0; i<child_controls.Count; i++) child_controls[i].Invalidate();
2172 OnInvalidated(new InvalidateEventArgs(rc));
2175 public void Invalidate(System.Drawing.Region region) {
2176 Invalidate(region, false);
2179 [MonoTODO("Figure out if GetRegionScans is usable")]
2180 public void Invalidate(System.Drawing.Region region, bool invalidateChildren) {
2181 throw new NotImplementedException();
2183 // FIXME - should use the GetRegionScans function of the region to invalidate each area
2184 //if (invalidateChildren) {
2185 // for (int i=0; i<child_controls.Count; i++) child_controls[i].Invalidate();
2189 public object Invoke (Delegate method) {
2190 return Invoke(method, null);
2193 public object Invoke (Delegate method, object[] args) {
2194 if (!this.InvokeRequired) {
2195 return method.DynamicInvoke(args);
2198 IAsyncResult result = BeginInvoke (method, args);
2199 return EndInvoke(result);
2202 [EditorBrowsable(EditorBrowsableState.Advanced)]
2203 public void PerformLayout() {
2204 PerformLayout(null, null);
2207 [EditorBrowsable(EditorBrowsableState.Advanced)]
2208 public void PerformLayout(Control affectedControl, string affectedProperty) {
2209 LayoutEventArgs levent = new LayoutEventArgs(affectedControl, affectedProperty);
2211 if (layout_suspended>0) {
2212 layout_pending = true;
2216 layout_pending = false;
2218 // Prevent us from getting messed up
2221 // Perform all Dock and Anchor calculations
2224 AnchorStyles anchor;
2229 space=this.DisplayRectangle;
2230 if (prev_size != Size.Empty) {
2231 diff_width = space.Width - prev_size.Width;
2232 diff_height = space.Height - prev_size.Height;
2238 // Deal with docking; go through in reverse, MS docs say that lowest Z-order is closest to edge
2239 for (int i = child_controls.Count - 1; i >= 0; i--) {
2240 child=child_controls[i];
2241 switch (child.Dock) {
2242 case DockStyle.None: {
2247 case DockStyle.Left: {
2248 child.SetBounds(space.Left, space.Y, child.Width, space.Height);
2249 space.X+=child.Width;
2250 space.Width-=child.Width;
2254 case DockStyle.Top: {
2255 child.SetBounds(space.Left, space.Y, space.Width, child.Height);
2256 space.Y+=child.Height;
2257 space.Height-=child.Height;
2261 case DockStyle.Right: {
2262 child.SetBounds(space.Right-child.Width, space.Y, child.Width, space.Height);
2263 space.Width-=child.Width;
2267 case DockStyle.Bottom: {
2268 child.SetBounds(space.Left, space.Bottom-child.Height, space.Width, child.Height);
2269 space.Height-=child.Height;
2275 for (int i = child_controls.Count - 1; i >= 0; i--) {
2276 child=child_controls[i];
2278 if (child.Dock == DockStyle.Fill) {
2279 child.SetBounds(space.Left, space.Top, space.Width, space.Height);
2285 space=this.DisplayRectangle;
2287 // Deal with anchoring
2288 for (int i=0; i < child_controls.Count; i++) {
2294 child=child_controls[i];
2295 anchor=child.Anchor;
2300 height=child.Height;
2302 // If the control is docked we don't need to do anything
2303 if (child.Dock != DockStyle.None) {
2307 if ((anchor & AnchorStyles.Left) !=0 ) {
2308 if ((anchor & AnchorStyles.Right) != 0) {
2309 // Anchoring to left and right
2310 width=width+diff_width;
2314 } else if ((anchor & AnchorStyles.Right) != 0) {
2320 if ((anchor & AnchorStyles.Top) !=0 ) {
2321 if ((anchor & AnchorStyles.Bottom) != 0) {
2322 height+=diff_height;
2326 } else if ((anchor & AnchorStyles.Bottom) != 0) {
2341 child.SetBounds(left, top, width, height);
2344 // Let everyone know
2348 // Need to make sure we decremend layout_suspended
2354 public Point PointToClient (Point p) {
2358 XplatUI.ScreenToClient (Handle, ref x, ref y);
2360 return new Point (x, y);
2363 public Point PointToScreen(Point p) {
2367 XplatUI.ClientToScreen(Handle, ref x, ref y);
2369 return new Point(x, y);
2372 public virtual bool PreProcessMessage(ref Message msg) {
2375 if ((msg.Msg == (int)Msg.WM_KEYDOWN) || (msg.Msg == (int)Msg.WM_SYSKEYDOWN)) {
2376 key_data = (Keys)msg.WParam.ToInt32();
2377 if (!ProcessCmdKey(ref msg, key_data)) {
2378 if (IsInputKey(key_data)) {
2382 return ProcessDialogKey(key_data);
2386 } else if (msg.Msg == (int)Msg.WM_CHAR) {
2387 if (IsInputChar((char)msg.WParam)) {
2390 } else if (msg.Msg == (int)Msg.WM_SYSCHAR) {
2391 if (IsInputChar((char)msg.WParam)) {
2394 return ProcessDialogChar((char)msg.WParam);
2399 public Rectangle RectangleToClient(Rectangle r) {
2400 return new Rectangle(PointToClient(r.Location), r.Size);
2403 public Rectangle RectangleToScreen(Rectangle r) {
2404 return new Rectangle(PointToScreen(r.Location), r.Size);
2407 public virtual void Refresh() {
2408 if (IsHandleCreated == true) {
2410 XplatUI.UpdateWindow(window.Handle);
2414 [EditorBrowsable(EditorBrowsableState.Never)]
2415 public virtual void ResetBackColor() {
2416 background_color = Color.Empty;
2419 #if haveDataBindings
2420 [EditorBrowsable(EditorBrowsableState.Never)]
2422 public void ResetBindings() {
2427 [EditorBrowsable(EditorBrowsableState.Never)]
2428 public virtual void ResetCursor() {
2432 [EditorBrowsable(EditorBrowsableState.Never)]
2433 public virtual void ResetFont() {
2437 [EditorBrowsable(EditorBrowsableState.Never)]
2438 public virtual void ResetForeColor() {
2439 foreground_color = Color.Empty;
2442 [EditorBrowsable(EditorBrowsableState.Never)]
2443 public void ResetImeMode() {
2444 ime_mode = DefaultImeMode;
2447 [EditorBrowsable(EditorBrowsableState.Never)]
2448 public virtual void ResetRightToLeft() {
2449 right_to_left = RightToLeft.Inherit;
2452 public virtual void ResetText() {
2456 public void ResumeLayout() {
2457 ResumeLayout (true);
2460 public void ResumeLayout(bool performLayout) {
2463 if (layout_suspended > 0) {
2467 if (performLayout || layout_pending) {
2472 public void Scale(float ratio) {
2473 ScaleCore(ratio, ratio);
2476 public void Scale(float dx, float dy) {
2480 public void Select() {
2481 Select(false, false);
2484 public bool SelectNextControl(Control ctl, bool forward, bool tabStopOnly, bool nested, bool wrap) {
2489 c = GetNextControl(c, forward);
2498 if (c.CanSelect && ((c.parent == ctl.parent) || nested) && (c.tab_stop || !tabStopOnly)) {
2502 } while (c != ctl); // If we wrap back to ourselves we stop
2507 public void SendToBack() {
2508 if ((parent != null) && (parent.child_controls[parent.child_controls.Count-1]!=this)) {
2509 if (parent.child_controls.Contains(this)) {
2510 parent.child_controls.SetChildIndex(this, parent.child_controls.Count);
2514 XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, false, true);
2515 if (parent != null) {
2520 public void SetBounds(int x, int y, int width, int height) {
2521 SetBoundsCore(x, y, width, height, BoundsSpecified.All);
2524 public void SetBounds(int x, int y, int width, int height, BoundsSpecified specified) {
2525 SetBoundsCore(x, y, width, height, specified);
2528 public void Show() {
2529 if (!IsHandleCreated) {
2530 this.CreateControl();
2536 public void SuspendLayout() {
2540 public void Update() {
2541 needs_redraw = true;
2542 XplatUI.UpdateWindow(window.Handle);
2544 #endregion // Public Instance Methods
2546 #region Protected Instance Methods
2547 [EditorBrowsable(EditorBrowsableState.Advanced)]
2548 [MonoTODO("Implement this and tie it into Control.ControlAccessibleObject.NotifyClients")]
2549 protected void AccessibilityNotifyClients(AccessibleEvents accEvent, int childID) {
2550 throw new NotImplementedException();
2553 [EditorBrowsable(EditorBrowsableState.Advanced)]
2554 protected virtual AccessibleObject CreateAccessibilityInstance() {
2555 return new Control.ControlAccessibleObject(this);
2558 [EditorBrowsable(EditorBrowsableState.Advanced)]
2559 protected virtual ControlCollection CreateControlsInstance() {
2560 return new ControlCollection(this);
2563 [EditorBrowsable(EditorBrowsableState.Advanced)]
2564 protected virtual void CreateHandle() {
2566 throw new ObjectDisposedException(Name);
2569 if (IsHandleCreated) {
2573 window.CreateHandle(CreateParams);
2575 // Find out where the window manager placed us
2579 if (window.Handle!=IntPtr.Zero) {
2580 if (!controls.Contains(window.Handle)) {
2584 creator_thread = Thread.CurrentThread;
2586 XplatUI.SetWindowBackground(window.Handle, this.BackColor);
2588 OnHandleCreated(EventArgs.Empty);
2592 [EditorBrowsable(EditorBrowsableState.Advanced)]
2593 protected virtual void DefWndProc(ref Message m) {
2594 window.DefWndProc(ref m);
2597 [EditorBrowsable(EditorBrowsableState.Advanced)]
2598 protected virtual void DestroyHandle() {
2599 if (IsHandleCreated) {
2600 // Destroy our children before we destroy ourselves, to prevent them from
2601 // being implictly (without us knowing) destroyed
2602 for (int i=0; i < child_controls.Count; i++) {
2603 child_controls[i].DestroyHandle();
2607 if (window != null) {
2608 window.DestroyHandle();
2610 OnHandleDestroyed(EventArgs.Empty);
2614 protected bool GetStyle(ControlStyles flag) {
2615 return (control_style & flag) != 0;
2618 protected bool GetTopLevel() {
2622 [EditorBrowsable(EditorBrowsableState.Advanced)]
2623 protected virtual void InitLayout() {
2624 if (parent != null) {
2625 parent.PerformLayout(this, "parent");
2629 [EditorBrowsable(EditorBrowsableState.Advanced)]
2630 protected void InvokeGotFocus(Control toInvoke, EventArgs e) {
2631 toInvoke.OnGotFocus(e);
2634 [EditorBrowsable(EditorBrowsableState.Advanced)]
2635 protected void InvokeLostFocus(Control toInvoke, EventArgs e) {
2636 toInvoke.OnLostFocus(e);
2639 [EditorBrowsable(EditorBrowsableState.Advanced)]
2640 protected void InvokeOnClick(Control toInvoke, EventArgs e) {
2641 toInvoke.OnClick(e);
2644 protected void InvokePaint(Control toInvoke, PaintEventArgs e) {
2645 toInvoke.OnPaint(e);
2648 protected void InvokePaintBackground(Control toInvoke, PaintEventArgs e) {
2649 toInvoke.OnPaintBackground(e);
2652 protected virtual bool IsInputChar (char charCode) {
2653 if (parent != null) {
2654 return parent.IsInputChar(charCode);
2660 protected virtual bool IsInputKey (Keys keyData) {
2661 // Doc says this one calls IsInputChar; not sure what to do with that
2665 [EditorBrowsable(EditorBrowsableState.Advanced)]
2666 protected virtual void NotifyInvalidate(Rectangle invalidatedArea) {
2670 protected virtual bool ProcessCmdKey(ref Message msg, Keys keyData) {
2671 if ((context_menu != null) && context_menu.ProcessCmdKey(ref msg, keyData)) {
2675 if (parent != null) {
2676 return parent.ProcessCmdKey(ref msg, keyData);
2682 protected virtual bool ProcessDialogChar(char charCode) {
2683 if (parent != null) {
2684 return parent.ProcessDialogChar (charCode);
2690 protected virtual bool ProcessDialogKey (Keys keyData) {
2691 if (parent != null) {
2692 return parent.ProcessDialogKey (keyData);
2698 protected virtual bool ProcessKeyEventArgs (ref Message msg)
2700 KeyEventArgs key_event;
2703 case (int)Msg.WM_KEYDOWN: {
2704 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
2705 OnKeyDown (key_event);
2706 return key_event.Handled;
2708 case (int)Msg.WM_KEYUP: {
2709 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
2710 OnKeyUp (key_event);
2711 return key_event.Handled;
2714 case (int)Msg.WM_CHAR: {
2715 KeyPressEventArgs key_press_event;
2717 key_press_event = new KeyPressEventArgs((char)msg.WParam);
2718 OnKeyPress(key_press_event);
2719 return key_press_event.Handled;
2730 protected internal virtual bool ProcessKeyMessage(ref Message msg) {
2731 if (parent != null) {
2732 if (parent.ProcessKeyPreview(ref msg)) {
2740 protected virtual bool ProcessKeyPreview(ref Message msg) {
2741 if (parent != null) {
2742 return parent.ProcessKeyPreview(ref msg);
2748 protected virtual bool ProcessMnemonic(char charCode) {
2753 [EditorBrowsable(EditorBrowsableState.Advanced)]
2754 protected void RaiseDragEvent(object key, DragEventArgs e) {
2758 [EditorBrowsable(EditorBrowsableState.Advanced)]
2759 protected void RaiseKeyEvent(object key, KeyEventArgs e) {
2763 [EditorBrowsable(EditorBrowsableState.Advanced)]
2764 protected void RaiseMouseEvent(object key, MouseEventArgs e) {
2768 [EditorBrowsable(EditorBrowsableState.Advanced)]
2769 protected void RaisePaintEvent(object key, PaintEventArgs e) {
2773 [EditorBrowsable(EditorBrowsableState.Advanced)]
2774 protected void RecreateHandle() {
2775 IEnumerator child = child_controls.GetEnumerator();
2779 if (IsHandleCreated) {
2785 while (child.MoveNext()) {
2786 ((Control)child.Current).RecreateHandle();
2792 is_recreating = false;
2795 [EditorBrowsable(EditorBrowsableState.Advanced)]
2796 protected void ResetMouseEventArgs() {
2800 [EditorBrowsable(EditorBrowsableState.Advanced)]
2801 protected ContentAlignment RtlTranslateAlignment(ContentAlignment align) {
2802 if (right_to_left == RightToLeft.No) {
2807 case ContentAlignment.TopLeft: {
2808 return ContentAlignment.TopRight;
2811 case ContentAlignment.TopRight: {
2812 return ContentAlignment.TopLeft;
2815 case ContentAlignment.MiddleLeft: {
2816 return ContentAlignment.MiddleRight;
2819 case ContentAlignment.MiddleRight: {
2820 return ContentAlignment.MiddleLeft;
2823 case ContentAlignment.BottomLeft: {
2824 return ContentAlignment.BottomRight;
2827 case ContentAlignment.BottomRight: {
2828 return ContentAlignment.BottomLeft;
2832 // if it's center it doesn't change
2838 [EditorBrowsable(EditorBrowsableState.Advanced)]
2839 protected HorizontalAlignment RtlTranslateAlignment(HorizontalAlignment align) {
2840 if ((right_to_left == RightToLeft.No) || (align == HorizontalAlignment.Center)) {
2844 if (align == HorizontalAlignment.Left) {
2845 return HorizontalAlignment.Right;
2848 // align must be HorizontalAlignment.Right
2849 return HorizontalAlignment.Left;
2852 [EditorBrowsable(EditorBrowsableState.Advanced)]
2853 protected LeftRightAlignment RtlTranslateAlignment(LeftRightAlignment align) {
2854 if (right_to_left == RightToLeft.No) {
2858 if (align == LeftRightAlignment.Left) {
2859 return LeftRightAlignment.Right;
2862 // align must be LeftRightAlignment.Right;
2863 return LeftRightAlignment.Left;
2866 [EditorBrowsable(EditorBrowsableState.Advanced)]
2867 protected ContentAlignment RtlTranslateContent(ContentAlignment align) {
2868 return RtlTranslateAlignment(align);
2871 [EditorBrowsable(EditorBrowsableState.Advanced)]
2872 protected HorizontalAlignment RtlTranslateHorizontal(HorizontalAlignment align) {
2873 return RtlTranslateAlignment(align);
2876 [EditorBrowsable(EditorBrowsableState.Advanced)]
2877 protected LeftRightAlignment RtlTranslateLeftRight(LeftRightAlignment align) {
2878 return RtlTranslateAlignment(align);
2881 [EditorBrowsable(EditorBrowsableState.Advanced)]
2882 protected virtual void ScaleCore(float dx, float dy) {
2888 location = new Point((int)(Left * dx), (int)(Top * dy));
2889 size = this.ClientSize;
2892 if (!GetStyle(ControlStyles.FixedWidth)) {
2893 size.Width = (int)(size.Width * dx);
2896 if (!GetStyle(ControlStyles.FixedHeight)) {
2897 size.Height = (int)(size.Height * dy);
2900 Location = location;
2903 /* Now scale our children */
2904 for (int i=0; i < child_controls.Count; i++) {
2905 child_controls[i].Scale(dx, dy);
2911 protected virtual void Select(bool directed, bool forward) {
2916 // Select this control
2921 if (parent == null) {
2925 // FIXME - this thing is doing the wrong stuff, needs to be similar to SelectNextControl
2927 index = parent.child_controls.IndexOf(this);
2932 if ((index+1) < parent.child_controls.Count) {
2941 index = parent.child_controls.Count-1;
2944 result = Select(parent.child_controls[index]);
2945 } while (!result && parent.child_controls[index] != this);
2948 [EditorBrowsable(EditorBrowsableState.Advanced)]
2949 protected virtual void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
2950 // SetBoundsCore updates the Win32 control itself. UpdateBounds updates the controls variables and fires events, I'm guessing - pdb
2951 if ((specified & BoundsSpecified.X) != BoundsSpecified.X) {
2955 if ((specified & BoundsSpecified.Y) != BoundsSpecified.Y) {
2959 if ((specified & BoundsSpecified.Width) != BoundsSpecified.Width) {
2963 if ((specified & BoundsSpecified.Height) != BoundsSpecified.Height) {
2967 if (IsHandleCreated) {
2968 XplatUI.SetWindowPos(Handle, x, y, width, height);
2970 UpdateBounds(x, y, width, height);
2973 [EditorBrowsable(EditorBrowsableState.Advanced)]
2974 protected virtual void SetClientSizeCore(int x, int y) {
2975 // Calculate the actual window size from the client size (it usually stays the same or grows)
2976 Rectangle ClientRect;
2977 Rectangle WindowRect;
2980 ClientRect = new Rectangle(0, 0, x, y);
2981 cp = this.CreateParams;
2983 if (XplatUI.CalculateWindowRect(Handle, ref ClientRect, cp.Style, cp.ExStyle, IntPtr.Zero, out WindowRect)==false) {
2987 SetBoundsCore(bounds.X, bounds.Y, WindowRect.Width, WindowRect.Height, BoundsSpecified.Size);
2990 [EditorBrowsable(EditorBrowsableState.Advanced)]
2991 protected void SetStyle(ControlStyles flag, bool value) {
2993 control_style |= flag;
2995 control_style &= ~flag;
2997 OnStyleChanged(EventArgs.Empty);
3000 protected void SetTopLevel(bool value) {
3001 if ((GetTopLevel() != value) && (parent != null)) {
3002 throw new Exception();
3006 if (value == true) {
3016 is_toplevel = value;
3019 protected virtual void SetVisibleCore(bool value) {
3020 if (value!=is_visible) {
3022 XplatUI.SetVisible(Handle, value);
3023 // Explicitly move Toplevel windows to where we want them;
3024 // apparently moving unmapped toplevel windows doesn't work
3025 if (is_visible && (this is Form)) {
3026 XplatUI.SetWindowPos(window.Handle, bounds.X, bounds.Y, bounds.Width, bounds.Height);
3028 OnVisibleChanged(EventArgs.Empty);
3031 if (dc_mem != null) {
3036 if (bmp_mem != null) {
3041 this.CreateBuffers(bounds.Width, bounds.Height);
3046 if (value == false && parent != null) {
3049 // Need to start at parent, GetContainerControl might return ourselves if we're a container
3050 container = (Control)parent.GetContainerControl();
3051 if (container != null) {
3052 container.SelectNextControl(this, true, true, true, true);
3056 if (parent != null) {
3057 parent.PerformLayout(this, "visible");
3059 PerformLayout(this, "visible");
3064 [EditorBrowsable(EditorBrowsableState.Advanced)]
3065 protected void UpdateBounds() {
3073 if (!IsHandleCreated) {
3077 XplatUI.GetWindowPos(this.Handle, this is Form, out x, out y, out width, out height, out client_width, out client_height);
3079 UpdateBounds(x, y, width, height, client_width, client_height);
3082 [EditorBrowsable(EditorBrowsableState.Advanced)]
3083 protected void UpdateBounds(int x, int y, int width, int height) {
3084 // UpdateBounds only seems to set our sizes and fire events but not update the GUI window to match
3086 bool resized = false;
3088 int client_x_diff = this.bounds.Width-this.client_size.Width;
3089 int client_y_diff = this.bounds.Height-this.client_size.Height;
3091 // Needed to generate required notifications
3092 if ((this.bounds.X!=x) || (this.bounds.Y!=y)) {
3096 if ((this.Bounds.Width!=width) || (this.Bounds.Height!=height)) {
3103 bounds.Height=height;
3105 // Update client rectangle as well
3106 if (this.layout_suspended==0) {
3107 prev_size.Width=client_size.Width;
3108 prev_size.Height=client_size.Height;
3111 client_size.Width=width-client_x_diff;
3112 client_size.Height=height-client_y_diff;
3115 OnLocationChanged(EventArgs.Empty);
3119 OnSizeChanged(EventArgs.Empty);
3123 [EditorBrowsable(EditorBrowsableState.Advanced)]
3124 protected void UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) {
3125 UpdateBounds(x, y, width, height);
3127 this.client_size.Width=clientWidth;
3128 this.client_size.Height=clientHeight;
3131 [EditorBrowsable(EditorBrowsableState.Advanced)]
3132 protected void UpdateStyles() {
3133 if (!IsHandleCreated) {
3137 XplatUI.SetWindowStyle(window.Handle, CreateParams);
3140 [EditorBrowsable(EditorBrowsableState.Advanced)]
3141 protected void UpdateZOrder() {
3146 if (parent == null) {
3152 children = ctl.child_controls.Count;
3153 for (int i = 1; i < children; i++ ) {
3154 XplatUI.SetZOrder(ctl.child_controls[i].window.Handle, ctl.child_controls[i-1].window.Handle, false, false);
3157 children = child_controls.Count;
3158 for (int i = 1; i < children; i++ ) {
3159 XplatUI.SetZOrder(child_controls[i].window.Handle, child_controls[i-1].window.Handle, false, false);
3164 protected virtual void WndProc(ref Message m) {
3166 Console.WriteLine("Control received message {0}", (Msg)m.Msg);
3168 if ((this.control_style & ControlStyles.EnableNotifyMessage) != 0) {
3172 switch((Msg)m.Msg) {
3173 case Msg.WM_WINDOWPOSCHANGED: {
3176 if (GetStyle(ControlStyles.ResizeRedraw)) {
3183 case Msg.WM_PAINT: {
3184 PaintEventArgs paint_event;
3186 paint_event = XplatUI.PaintEventStart(Handle);
3188 if (!needs_redraw) {
3189 // Just blit the previous image
3190 paint_event.Graphics.DrawImage (ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle, GraphicsUnit.Pixel);
3191 XplatUI.PaintEventEnd(Handle);
3196 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
3197 dc = paint_event.SetGraphics (DeviceContext);
3200 if ((control_style & (ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint)) == (ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint)) {
3201 OnPaintBackground(paint_event);
3204 OnPaint(paint_event);
3206 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
3207 dc.DrawImage (ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle, GraphicsUnit.Pixel);
3208 paint_event.SetGraphics (dc);
3209 needs_redraw = false;
3212 XplatUI.PaintEventEnd(Handle);
3214 if (!GetStyle(ControlStyles.UserPaint)) {
3221 case Msg.WM_ERASEBKGND: {
3222 if (GetStyle (ControlStyles.UserPaint)) {
3223 if (!GetStyle(ControlStyles.AllPaintingInWmPaint)) {
3224 PaintEventArgs eraseEventArgs = new PaintEventArgs (m.WParam == IntPtr.Zero ? Graphics.FromHwnd (m.HWnd) :
3225 Graphics.FromHdc (m.WParam), new Rectangle (new Point (0,0),Size));
3226 OnPaintBackground (eraseEventArgs);
3229 XplatUI.EraseWindowBackground(m.HWnd, m.WParam);
3231 // The DefWndProc will never have to handle this, we don't ever set hbr on the window
3232 m.Result = (IntPtr)1;
3236 case Msg.WM_LBUTTONUP: {
3237 HandleClick(mouse_clicks);
3238 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Left,
3240 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3242 if (mouse_clicks > 1) {
3248 case Msg.WM_LBUTTONDOWN: {
3249 if (CanSelect && !is_selected) {
3252 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3253 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3259 case Msg.WM_LBUTTONDBLCLK: {
3261 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3262 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3268 case Msg.WM_MBUTTONUP: {
3269 HandleClick(mouse_clicks);
3270 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Middle,
3272 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3274 if (mouse_clicks > 1) {
3280 case Msg.WM_MBUTTONDOWN: {
3281 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3282 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3288 case Msg.WM_MBUTTONDBLCLK: {
3290 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3291 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3296 case Msg.WM_RBUTTONUP: {
3297 if (context_menu != null) {
3298 context_menu.Show(this, new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ())));
3301 HandleClick(mouse_clicks);
3302 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Right,
3304 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3306 if (mouse_clicks > 1) {
3312 case Msg.WM_RBUTTONDOWN: {
3313 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3314 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3319 case Msg.WM_RBUTTONDBLCLK: {
3321 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3322 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3327 case Msg.WM_MOUSEWHEEL: {
3329 OnMouseWheel (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3330 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3331 HighOrder(m.WParam.ToInt32())));
3336 case Msg.WM_MOUSEMOVE: {
3337 OnMouseMove (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3339 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3344 case Msg.WM_MOUSE_ENTER: {
3349 OnMouseEnter(EventArgs.Empty);
3353 case Msg.WM_MOUSE_LEAVE: {
3355 OnMouseLeave(EventArgs.Empty);
3359 case Msg.WM_MOUSEHOVER: {
3360 OnMouseHover(EventArgs.Empty);
3364 case Msg.WM_SYSKEYDOWN:
3365 case Msg.WM_KEYDOWN:
3366 case Msg.WM_SYSKEYUP:
3368 case Msg.WM_SYSCHAR:
3370 if (ProcessKeyEventArgs(ref m)) {
3374 if (PreProcessMessage(ref m)) {
3378 if (ProcessKeyMessage(ref m)) {
3387 if (m.LParam != IntPtr.Zero) {
3390 hi = new HELPINFO();
3392 hi = (HELPINFO) Marshal.PtrToStructure (m.LParam, typeof (HELPINFO));
3393 mouse_pos = new Point(hi.MousePos.x, hi.MousePos.y);
3395 mouse_pos = Control.MousePosition;
3397 OnHelpRequested(new HelpEventArgs(mouse_pos));
3398 m.Result = (IntPtr)1;
3402 case Msg.WM_KILLFOCUS: {
3403 OnLeave(EventArgs.Empty);
3404 if (CausesValidation) {
3406 e = new CancelEventArgs(false);
3415 OnValidated(EventArgs.Empty);
3418 this.has_focus = false;
3419 this.is_selected = false;
3420 OnLostFocus(EventArgs.Empty);
3424 case Msg.WM_SETFOCUS: {
3425 OnEnter(EventArgs.Empty);
3426 this.has_focus = true;
3427 OnGotFocus(EventArgs.Empty);
3432 case Msg.WM_SYSCOLORCHANGE: {
3433 ThemeEngine.Current.ResetDefaults();
3434 OnSystemColorsChanged(EventArgs.Empty);
3439 case Msg.WM_SETCURSOR: {
3440 if (cursor == null) {
3445 XplatUI.SetCursor(window.Handle, cursor.handle);
3446 m.Result = (IntPtr)1;
3456 #endregion // Public Instance Methods
3458 #region OnXXX methods
3459 [EditorBrowsable(EditorBrowsableState.Advanced)]
3460 protected virtual void OnBackColorChanged(EventArgs e) {
3461 if (BackColorChanged!=null) BackColorChanged(this, e);
3462 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackColorChanged(e);
3465 [EditorBrowsable(EditorBrowsableState.Advanced)]
3466 protected virtual void OnBackgroundImageChanged(EventArgs e) {
3467 if (BackgroundImageChanged!=null) BackgroundImageChanged(this, e);
3468 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackgroundImageChanged(e);
3471 [EditorBrowsable(EditorBrowsableState.Advanced)]
3472 protected virtual void OnBindingContextChanged(EventArgs e) {
3473 CheckDataBindings ();
3474 if (BindingContextChanged!=null) {
3475 BindingContextChanged(this, e);
3477 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBindingContextChanged(e);
3480 [EditorBrowsable(EditorBrowsableState.Advanced)]
3481 protected virtual void OnCausesValidationChanged(EventArgs e) {
3482 if (CausesValidationChanged!=null) CausesValidationChanged(this, e);
3485 [EditorBrowsable(EditorBrowsableState.Advanced)]
3486 protected virtual void OnChangeUICues(UICuesEventArgs e) {
3487 if (ChangeUICues!=null) ChangeUICues(this, e);
3490 [EditorBrowsable(EditorBrowsableState.Advanced)]
3491 protected virtual void OnClick(EventArgs e) {
3492 if (Click!=null) Click(this, e);
3495 [EditorBrowsable(EditorBrowsableState.Advanced)]
3496 protected virtual void OnContextMenuChanged(EventArgs e) {
3497 if (ContextMenuChanged!=null) ContextMenuChanged(this, e);
3500 [EditorBrowsable(EditorBrowsableState.Advanced)]
3501 protected virtual void OnControlAdded(ControlEventArgs e) {
3502 if (ControlAdded!=null) ControlAdded(this, e);
3505 [EditorBrowsable(EditorBrowsableState.Advanced)]
3506 protected virtual void OnControlRemoved(ControlEventArgs e) {
3507 if (ControlRemoved!=null) ControlRemoved(this, e);
3510 [EditorBrowsable(EditorBrowsableState.Advanced)]
3511 protected virtual void OnCreateControl() {
3515 [EditorBrowsable(EditorBrowsableState.Advanced)]
3516 protected virtual void OnCursorChanged(EventArgs e) {
3517 if (CursorChanged!=null) CursorChanged(this, e);
3520 [EditorBrowsable(EditorBrowsableState.Advanced)]
3521 protected virtual void OnDockChanged(EventArgs e) {
3522 if (DockChanged!=null) DockChanged(this, e);
3525 [EditorBrowsable(EditorBrowsableState.Advanced)]
3526 protected virtual void OnDoubleClick(EventArgs e) {
3527 if (DoubleClick!=null) DoubleClick(this, e);
3530 [EditorBrowsable(EditorBrowsableState.Advanced)]
3531 protected virtual void OnDragDrop(DragEventArgs drgevent) {
3532 if (DragDrop!=null) DragDrop(this, drgevent);
3535 [EditorBrowsable(EditorBrowsableState.Advanced)]
3536 protected virtual void OnDragEnter(DragEventArgs drgevent) {
3537 if (DragEnter!=null) DragEnter(this, drgevent);
3540 [EditorBrowsable(EditorBrowsableState.Advanced)]
3541 protected virtual void OnDragLeave(EventArgs e) {
3542 if (DragLeave!=null) DragLeave(this, e);
3545 [EditorBrowsable(EditorBrowsableState.Advanced)]
3546 protected virtual void OnDragOver(DragEventArgs drgevent) {
3547 if (DragOver!=null) DragOver(this, drgevent);
3550 [EditorBrowsable(EditorBrowsableState.Advanced)]
3551 protected virtual void OnEnabledChanged(EventArgs e) {
3552 if (EnabledChanged!=null) EnabledChanged(this, e);
3553 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentEnabledChanged(e);
3556 [EditorBrowsable(EditorBrowsableState.Advanced)]
3557 protected virtual void OnEnter(EventArgs e) {
3558 if (Enter!=null) Enter(this, e);
3561 [EditorBrowsable(EditorBrowsableState.Advanced)]
3562 protected virtual void OnFontChanged(EventArgs e) {
3563 if (FontChanged!=null) FontChanged(this, e);
3564 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentFontChanged(e);
3567 [EditorBrowsable(EditorBrowsableState.Advanced)]
3568 protected virtual void OnForeColorChanged(EventArgs e) {
3569 if (ForeColorChanged!=null) ForeColorChanged(this, e);
3570 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentForeColorChanged(e);
3573 [EditorBrowsable(EditorBrowsableState.Advanced)]
3574 protected virtual void OnGiveFeedback(GiveFeedbackEventArgs gfbevent) {
3575 if (GiveFeedback!=null) GiveFeedback(this, gfbevent);
3578 [EditorBrowsable(EditorBrowsableState.Advanced)]
3579 protected virtual void OnGotFocus(EventArgs e) {
3580 if (GotFocus!=null) GotFocus(this, e);
3583 [EditorBrowsable(EditorBrowsableState.Advanced)]
3584 protected virtual void OnHandleCreated(EventArgs e) {
3585 if (HandleCreated!=null) HandleCreated(this, e);
3588 [EditorBrowsable(EditorBrowsableState.Advanced)]
3589 protected virtual void OnHandleDestroyed(EventArgs e) {
3590 if (HandleDestroyed!=null) HandleDestroyed(this, e);
3593 [EditorBrowsable(EditorBrowsableState.Advanced)]
3594 protected virtual void OnHelpRequested(HelpEventArgs hevent) {
3595 if (HelpRequested!=null) HelpRequested(this, hevent);
3598 protected virtual void OnImeModeChanged(EventArgs e) {
3599 if (ImeModeChanged!=null) ImeModeChanged(this, e);
3602 [EditorBrowsable(EditorBrowsableState.Advanced)]
3603 protected virtual void OnInvalidated(InvalidateEventArgs e) {
3604 needs_redraw = true;
3605 if (Invalidated!=null) Invalidated(this, e);
3608 [EditorBrowsable(EditorBrowsableState.Advanced)]
3609 protected virtual void OnKeyDown(KeyEventArgs e) {
3610 if (KeyDown!=null) KeyDown(this, e);
3613 [EditorBrowsable(EditorBrowsableState.Advanced)]
3614 protected virtual void OnKeyPress(KeyPressEventArgs e) {
3615 if (KeyPress!=null) KeyPress(this, e);
3618 [EditorBrowsable(EditorBrowsableState.Advanced)]
3619 protected virtual void OnKeyUp(KeyEventArgs e) {
3620 if (KeyUp!=null) KeyUp(this, e);
3623 [EditorBrowsable(EditorBrowsableState.Advanced)]
3624 protected virtual void OnLayout(LayoutEventArgs levent) {
3625 if (Layout!=null) Layout(this, levent);
3628 [EditorBrowsable(EditorBrowsableState.Advanced)]
3629 protected virtual void OnLeave(EventArgs e) {
3630 if (Leave!=null) Leave(this, e);
3633 [EditorBrowsable(EditorBrowsableState.Advanced)]
3634 protected virtual void OnLocationChanged(EventArgs e) {
3636 if (LocationChanged!=null) LocationChanged(this, e);
3639 [EditorBrowsable(EditorBrowsableState.Advanced)]
3640 protected virtual void OnLostFocus(EventArgs e) {
3641 if (LostFocus!=null) LostFocus(this, e);
3644 [EditorBrowsable(EditorBrowsableState.Advanced)]
3645 protected virtual void OnMouseDown(MouseEventArgs e) {
3646 if (MouseDown!=null) MouseDown(this, e);
3649 [EditorBrowsable(EditorBrowsableState.Advanced)]
3650 protected virtual void OnMouseEnter(EventArgs e) {
3651 if (MouseEnter!=null) MouseEnter(this, e);
3654 [EditorBrowsable(EditorBrowsableState.Advanced)]
3655 protected virtual void OnMouseHover(EventArgs e) {
3656 if (MouseHover!=null) MouseHover(this, e);
3659 [EditorBrowsable(EditorBrowsableState.Advanced)]
3660 protected virtual void OnMouseLeave(EventArgs e) {
3661 if (MouseLeave!=null) MouseLeave(this, e);
3664 [EditorBrowsable(EditorBrowsableState.Advanced)]
3665 protected virtual void OnMouseMove(MouseEventArgs e) {
3666 if (MouseMove!=null) MouseMove(this, e);
3669 [EditorBrowsable(EditorBrowsableState.Advanced)]
3670 protected virtual void OnMouseUp(MouseEventArgs e) {
3671 if (MouseUp!=null) MouseUp(this, e);
3674 [EditorBrowsable(EditorBrowsableState.Advanced)]
3675 protected virtual void OnMouseWheel(MouseEventArgs e) {
3676 if (MouseWheel!=null) MouseWheel(this, e);
3679 [EditorBrowsable(EditorBrowsableState.Advanced)]
3680 protected virtual void OnMove(EventArgs e) {
3681 if (Move!=null) Move(this, e);
3684 [EditorBrowsable(EditorBrowsableState.Advanced)]
3685 protected virtual void OnNotifyMessage(Message m) {
3689 [EditorBrowsable(EditorBrowsableState.Advanced)]
3690 protected virtual void OnPaint(PaintEventArgs e) {
3691 if (Paint!=null) Paint(this, e);
3694 [EditorBrowsable(EditorBrowsableState.Advanced)]
3695 protected virtual void OnPaintBackground(PaintEventArgs pevent) {
3699 [EditorBrowsable(EditorBrowsableState.Advanced)]
3700 protected virtual void OnParentBackColorChanged(EventArgs e) {
3701 if (background_color.IsEmpty && background_image==null) {
3703 OnBackColorChanged(e);
3707 [EditorBrowsable(EditorBrowsableState.Advanced)]
3708 protected virtual void OnParentBackgroundImageChanged(EventArgs e) {
3709 if (background_color.IsEmpty && background_image==null) {
3711 OnBackgroundImageChanged(e);
3715 [EditorBrowsable(EditorBrowsableState.Advanced)]
3716 protected virtual void OnParentBindingContextChanged(EventArgs e) {
3717 if (binding_context==null) {
3718 binding_context=Parent.binding_context;
3719 OnBindingContextChanged(e);
3723 [EditorBrowsable(EditorBrowsableState.Advanced)]
3724 protected virtual void OnParentChanged(EventArgs e) {
3725 if (ParentChanged!=null) ParentChanged(this, e);
3728 [EditorBrowsable(EditorBrowsableState.Advanced)]
3729 protected virtual void OnParentEnabledChanged(EventArgs e) {
3730 if (is_enabled != Parent.is_enabled) {
3731 is_enabled=Parent.is_enabled;
3733 if (EnabledChanged != null) {
3734 EnabledChanged(this, e);
3739 [EditorBrowsable(EditorBrowsableState.Advanced)]
3740 protected virtual void OnParentFontChanged(EventArgs e) {
3747 [EditorBrowsable(EditorBrowsableState.Advanced)]
3748 protected virtual void OnParentForeColorChanged(EventArgs e) {
3749 if (foreground_color.IsEmpty) {
3751 OnForeColorChanged(e);
3755 [EditorBrowsable(EditorBrowsableState.Advanced)]
3756 protected virtual void OnParentRightToLeftChanged(EventArgs e) {
3757 if (right_to_left==RightToLeft.Inherit) {
3759 OnRightToLeftChanged(e);
3763 [EditorBrowsable(EditorBrowsableState.Advanced)]
3764 protected virtual void OnParentVisibleChanged(EventArgs e) {
3766 OnVisibleChanged(e);
3770 [EditorBrowsable(EditorBrowsableState.Advanced)]
3771 protected virtual void OnQueryContinueDrag(QueryContinueDragEventArgs e) {
3772 if (QueryContinueDrag!=null) QueryContinueDrag(this, e);
3775 [EditorBrowsable(EditorBrowsableState.Advanced)]
3776 protected virtual void OnResize(EventArgs e) {
3777 if (Resize!=null) Resize(this, e);
3779 PerformLayout(this, "bounds");
3781 if (parent != null) {
3782 parent.PerformLayout();
3786 [EditorBrowsable(EditorBrowsableState.Advanced)]
3787 protected virtual void OnRightToLeftChanged(EventArgs e) {
3788 if (RightToLeftChanged!=null) RightToLeftChanged(this, e);
3789 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentRightToLeftChanged(e);
3792 [EditorBrowsable(EditorBrowsableState.Advanced)]
3793 protected virtual void OnSizeChanged(EventArgs e) {
3794 InvalidateBuffers ();
3796 if (SizeChanged!=null) SizeChanged(this, e);
3799 [EditorBrowsable(EditorBrowsableState.Advanced)]
3800 protected virtual void OnStyleChanged(EventArgs e) {
3801 if (StyleChanged!=null) StyleChanged(this, e);
3804 [EditorBrowsable(EditorBrowsableState.Advanced)]
3805 protected virtual void OnSystemColorsChanged(EventArgs e) {
3806 if (SystemColorsChanged!=null) SystemColorsChanged(this, e);
3809 [EditorBrowsable(EditorBrowsableState.Advanced)]
3810 protected virtual void OnTabIndexChanged(EventArgs e) {
3811 if (TabIndexChanged!=null) TabIndexChanged(this, e);
3814 [EditorBrowsable(EditorBrowsableState.Advanced)]
3815 protected virtual void OnTabStopChanged(EventArgs e) {
3816 if (TabStopChanged!=null) TabStopChanged(this, e);
3819 [EditorBrowsable(EditorBrowsableState.Advanced)]
3820 protected virtual void OnTextChanged(EventArgs e) {
3821 if (TextChanged!=null) TextChanged(this, e);
3824 [EditorBrowsable(EditorBrowsableState.Advanced)]
3825 protected virtual void OnValidated(EventArgs e) {
3826 if (Validated!=null) Validated(this, e);
3829 [EditorBrowsable(EditorBrowsableState.Advanced)]
3830 protected virtual void OnValidating(System.ComponentModel.CancelEventArgs e) {
3831 if (Validating!=null) Validating(this, e);
3834 [EditorBrowsable(EditorBrowsableState.Advanced)]
3835 protected virtual void OnVisibleChanged(EventArgs e) {
3842 if (bmp_mem!=null) {
3848 if (!this.IsHandleCreated) {
3849 this.CreateControl();
3855 if (VisibleChanged!=null) VisibleChanged(this, e);
3857 // We need to tell our kids
3858 for (int i=0; i<child_controls.Count; i++) {
3859 child_controls[i].OnParentVisibleChanged(e);
3862 #endregion // OnXXX methods
3865 public event EventHandler BackColorChanged;
3866 public event EventHandler BackgroundImageChanged;
3867 public event EventHandler BindingContextChanged;
3868 public event EventHandler CausesValidationChanged;
3869 public event UICuesEventHandler ChangeUICues;
3870 public event EventHandler Click;
3871 public event EventHandler ContextMenuChanged;
3873 [EditorBrowsable(EditorBrowsableState.Advanced)]
3875 public event ControlEventHandler ControlAdded;
3877 [EditorBrowsable(EditorBrowsableState.Advanced)]
3879 public event ControlEventHandler ControlRemoved;
3881 public event EventHandler CursorChanged;
3882 public event EventHandler DockChanged;
3883 public event EventHandler DoubleClick;
3884 public event DragEventHandler DragDrop;
3885 public event DragEventHandler DragEnter;
3886 public event EventHandler DragLeave;
3887 public event DragEventHandler DragOver;
3888 public event EventHandler EnabledChanged;
3889 public event EventHandler Enter;
3890 public event EventHandler FontChanged;
3891 public event EventHandler ForeColorChanged;
3892 public event GiveFeedbackEventHandler GiveFeedback;
3894 [EditorBrowsable(EditorBrowsableState.Advanced)]
3896 public event EventHandler GotFocus;
3898 [EditorBrowsable(EditorBrowsableState.Advanced)]
3900 public event EventHandler HandleCreated;
3902 [EditorBrowsable(EditorBrowsableState.Advanced)]
3904 public event EventHandler HandleDestroyed;
3906 public event HelpEventHandler HelpRequested;
3907 public event EventHandler ImeModeChanged;
3909 [EditorBrowsable(EditorBrowsableState.Advanced)]
3911 public event InvalidateEventHandler Invalidated;
3913 public event KeyEventHandler KeyDown;
3914 public event KeyPressEventHandler KeyPress;
3915 public event KeyEventHandler KeyUp;
3916 public event LayoutEventHandler Layout;
3917 public event EventHandler Leave;
3918 public event EventHandler LocationChanged;
3920 [EditorBrowsable(EditorBrowsableState.Advanced)]
3922 public event EventHandler LostFocus;
3924 public event MouseEventHandler MouseDown;
3925 public event EventHandler MouseEnter;
3926 public event EventHandler MouseHover;
3927 public event EventHandler MouseLeave;
3928 public event MouseEventHandler MouseMove;
3929 public event MouseEventHandler MouseUp;
3931 [EditorBrowsable(EditorBrowsableState.Advanced)]
3933 public event MouseEventHandler MouseWheel;
3935 public event EventHandler Move;
3936 public event PaintEventHandler Paint;
3937 public event EventHandler ParentChanged;
3938 public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp;
3939 public event QueryContinueDragEventHandler QueryContinueDrag;
3940 public event EventHandler Resize;
3941 public event EventHandler RightToLeftChanged;
3942 public event EventHandler SizeChanged;
3943 public event EventHandler StyleChanged;
3944 public event EventHandler SystemColorsChanged;
3945 public event EventHandler TabIndexChanged;
3946 public event EventHandler TabStopChanged;
3947 public event EventHandler TextChanged;
3948 public event EventHandler Validated;
3949 public event CancelEventHandler Validating;
3950 public event EventHandler VisibleChanged;
3951 #endregion // Events