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.Threading;
47 namespace System.Windows.Forms
49 [Designer("System.Windows.Forms.Design.ControlDesigner, " + Consts.AssemblySystem_Design)]
50 [DefaultProperty("Text")]
51 [DefaultEvent("Click")]
52 [DesignerSerializer("System.Windows.Forms.Design.ControlCodeDomSerializer, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
53 [ToolboxItemFilter("System.Windows.Forms")]
54 public class Control : Component, ISynchronizeInvoke, IWin32Window
56 #region Local Variables
59 internal Rectangle bounds; // bounding rectangle for control (client area + decorations)
60 internal object creator_thread; // thread that created the control
61 internal ControlNativeWindow window; // object for native window handle
62 internal string name; // for object naming
65 internal bool has_focus; // true if control has focus
66 internal bool is_visible; // true if control is visible
67 internal bool is_entered; // is the mouse inside the control?
68 internal bool is_enabled; // true if control is enabled (usable/not grayed out)
69 internal bool is_selected; // true if control is selected
70 internal bool is_accessible; // true if the control is visible to accessibility applications
71 internal bool is_captured; // tracks if the control has captured the mouse
72 internal bool is_toplevel; // tracks if the control is a toplevel window
73 internal bool is_recreating; // tracks if the handle for the control is being recreated
74 internal bool causes_validation; // tracks if validation is executed on changes
75 internal int tab_index; // position in tab order of siblings
76 internal bool tab_stop = true; // is the control a tab stop?
77 internal bool is_disposed; // has the window already been disposed?
78 internal Size client_size; // size of the client area (window excluding decorations)
79 internal Rectangle client_rect; // rectangle with the client area (window excluding decorations)
80 internal ControlStyles control_style; // rather win32-specific, style bits for control
81 internal ImeMode ime_mode = ImeMode.Inherit;
82 internal bool layout_pending; // true if our parent needs to re-layout us
83 internal object control_tag; // object that contains data about our control
84 internal int mouse_clicks; // Counter for mouse clicks
85 internal Cursor cursor; // Cursor for the window
88 internal Color foreground_color; // foreground color for control
89 internal Color background_color; // background color for control
90 internal Image background_image; // background image for control
91 internal Font font; // font for control
92 internal string text; // window/title text for control
93 internal BorderStyle border_style; // Border style of control
96 internal AnchorStyles anchor_style; // anchoring requirements for our control
97 internal DockStyle dock_style; // docking requirements for our control (supercedes anchoring)
98 internal SizeF size_ratio; // size ratio of our control to it's parent; required for anchoring
99 internal Size prev_size; // previous size of the control; required for anchoring
101 // to be categorized...
102 static internal ArrayList controls = new ArrayList(); // All of the applications controls, in a flat list
103 internal ControlCollection child_controls; // our children
104 internal Control parent; // our parent control
105 internal AccessibleObject accessibility_object; // object that contains accessibility information about our control
106 internal BindingContext binding_context; // TODO
107 internal RightToLeft right_to_left; // drawing direction for control
108 internal int layout_suspended;
109 internal bool double_buffering;
110 internal ContextMenu context_menu; // Context menu associated with the control
112 private Graphics dc_mem; // Graphics context for double buffering
113 private Bitmap bmp_mem; // Bitmap for double buffering control
115 private ControlBindingsCollection data_bindings;
117 #endregion // Local Variables
119 #region Private Classes
120 // This helper class allows us to dispatch messages to Control.WndProc
121 internal class ControlNativeWindow : NativeWindow {
122 private Control owner;
124 public ControlNativeWindow(Control control) : base() {
129 public Control Owner {
135 static internal Control ControlFromHandle(IntPtr hWnd) {
136 ControlNativeWindow window;
138 window = (ControlNativeWindow)window_collection[hWnd];
143 protected override void WndProc(ref Message m) {
144 owner.WndProc(ref m);
149 #region Public Classes
151 public class ControlAccessibleObject : AccessibleObject {
152 #region ControlAccessibleObject Local Variables
153 private Control owner;
154 #endregion // ControlAccessibleObject Local Variables
156 #region ControlAccessibleObject Constructors
157 public ControlAccessibleObject(Control ownerControl) {
158 this.owner = ownerControl;
160 #endregion // ControlAccessibleObject Constructors
162 #region ControlAccessibleObject Public Instance Properties
163 public override string DefaultAction {
165 return base.DefaultAction;
169 public override string Description {
171 return base.Description;
175 public IntPtr Handle {
181 // We don't want to let them set it
185 public override string Help {
191 public override string KeyboardShortcut {
193 return base.KeyboardShortcut;
197 public override string Name {
207 public Control Owner {
213 public override AccessibleRole Role {
218 #endregion // ControlAccessibleObject Public Instance Properties
220 #region ControlAccessibleObject Public Instance Methods
221 public override int GetHelpTopic(out string FileName) {
222 return base.GetHelpTopic (out FileName);
225 [MonoTODO("Implement this and tie it into Control.AccessibilityNotifyClients")]
226 public void NotifyClients(AccessibleEvents accEvent) {
227 throw new NotImplementedException();
230 [MonoTODO("Implement this and tie it into Control.AccessibilityNotifyClients")]
231 public void NotifyClients(AccessibleEvents accEvent, int childID) {
232 throw new NotImplementedException();
235 public override string ToString() {
236 return "ControlAccessibleObject: Owner = " + owner.ToString() + ", Text: " + owner.text;
239 #endregion // ControlAccessibleObject Public Instance Methods
242 [DesignerSerializer("System.Windows.Forms.Design.ControlCollectionCodeDomSerializer, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
243 [ListBindable(false)]
244 public class ControlCollection : IList, ICollection, ICloneable, IEnumerable {
245 #region ControlCollection Local Variables
246 internal ArrayList list;
247 internal Control owner;
248 #endregion // ControlCollection Local Variables
250 #region ControlCollection Public Constructor
251 public ControlCollection(Control owner) {
253 this.list=new ArrayList();
257 #region ControlCollection Public Instance Properties
264 public bool IsReadOnly {
266 return list.IsReadOnly;
270 public virtual Control this[int index] {
272 if (index < 0 || index >= list.Count) {
273 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
275 return (Control)list[index];
278 #endregion // ControlCollection Public Instance Properties
280 #region ControlCollection Private Instance Methods
281 public virtual void Add (Control value)
284 for (int i = 0; i < list.Count; i++) {
285 if (list [i] == value) {
286 // Do we need to do anything here?
291 if (value.tab_index == -1) {
297 end = owner.child_controls.Count;
298 for (int i = 0; i < end; i++) {
299 index = owner.child_controls[i].tab_index;
304 value.tab_index = use;
308 value.Parent = owner;
309 owner.UpdateZOrder();
310 owner.OnControlAdded(new ControlEventArgs(value));
313 public virtual void AddRange (Control[] controls)
315 if (controls == null)
316 throw new ArgumentNullException ("controls");
318 owner.SuspendLayout ();
321 for (int i = 0; i < controls.Length; i++)
324 owner.ResumeLayout ();
328 public virtual void Clear ()
330 owner.SuspendLayout();
331 for (int i = 0; i < list.Count; i++) {
332 owner.OnControlRemoved(new ControlEventArgs((Control)list[i]));
335 owner.ResumeLayout();
338 public virtual bool Contains (Control value)
340 return list.Contains (value);
343 public void CopyTo (Array array, int index)
345 list.CopyTo(array, index);
348 public override bool Equals(object other) {
349 if (other is ControlCollection && (((ControlCollection)other).owner==this.owner)) {
356 public int GetChildIndex(Control child) {
357 return GetChildIndex(child, false);
360 public int GetChildIndex(Control child, bool throwException) {
363 index=list.IndexOf(child);
365 if (index==-1 && throwException) {
366 throw new ArgumentException("Not a child control", "child");
371 public IEnumerator GetEnumerator() {
372 return list.GetEnumerator();
375 public override int GetHashCode() {
376 return base.GetHashCode();
379 public int IndexOf(Control control) {
380 return list.IndexOf(control);
383 public virtual void Remove(Control value) {
384 owner.OnControlRemoved(new ControlEventArgs(value));
386 owner.UpdateZOrder();
389 public void RemoveAt(int index) {
390 if (index<0 || index>=list.Count) {
391 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
394 owner.OnControlRemoved(new ControlEventArgs((Control)list[index]));
395 list.RemoveAt(index);
396 owner.UpdateZOrder();
399 public void SetChildIndex(Control child, int newIndex) {
402 old_index=list.IndexOf(child);
404 throw new ArgumentException("Not a child control", "child");
407 if (old_index==newIndex) {
413 if (newIndex>list.Count) {
416 list.Insert(newIndex, child);
418 owner.UpdateZOrder();
420 #endregion // ControlCollection Private Instance Methods
422 #region ControlCollection Interface Properties
423 object IList.this[int index] {
425 if (index<0 || index>=list.Count) {
426 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
432 if (!(value is Control)) {
433 throw new ArgumentException("Object of type Control required", "value");
436 list[index]=(Control)value;
440 bool IList.IsFixedSize {
446 bool IList.IsReadOnly {
448 return list.IsReadOnly;
452 bool ICollection.IsSynchronized {
454 return list.IsSynchronized;
458 object ICollection.SyncRoot {
460 return list.SyncRoot;
463 #endregion // ControlCollection Interface Properties
465 #region ControlCollection Interface Methods
466 int IList.Add(object value) {
468 throw new ArgumentNullException("value", "Cannot add null controls");
471 if (!(value is Control)) {
472 throw new ArgumentException("Object of type Control required", "value");
475 return list.Add(value);
478 bool IList.Contains(object value) {
479 if (!(value is Control)) {
480 throw new ArgumentException("Object of type Control required", "value");
483 return this.Contains((Control) value);
486 int IList.IndexOf(object value) {
487 if (!(value is Control)) {
488 throw new ArgumentException("Object of type Control required", "value");
491 return this.IndexOf((Control) value);
494 void IList.Insert(int index, object value) {
495 if (!(value is Control)) {
496 throw new ArgumentException("Object of type Control required", "value");
498 list.Insert(index, value);
501 void IList.Remove(object value) {
502 if (!(value is Control)) {
503 throw new ArgumentException("Object of type Control required", "value");
508 void ICollection.CopyTo(Array array, int index) {
510 list.CopyTo(array, index);
514 Object ICloneable.Clone() {
515 ControlCollection clone = new ControlCollection(this.owner);
516 clone.list=(ArrayList)list.Clone(); // FIXME: Do we need this?
519 #endregion // ControlCollection Interface Methods
521 #endregion // ControlCollection Class
523 #region Public Constructors
525 creator_thread = Thread.CurrentThread;
527 prev_size = Size.Empty;
528 anchor_style = AnchorStyles.Top | AnchorStyles.Left;
535 layout_pending = false;
537 causes_validation = true;
539 layout_suspended = 0;
540 double_buffering = true;
544 right_to_left = RightToLeft.Inherit;
546 control_style = ControlStyles.Selectable | ControlStyles.StandardClick | ControlStyles.StandardDoubleClick;
549 background_image = null;
553 child_controls = CreateControlsInstance();
554 client_size = new Size(DefaultSize.Width, DefaultSize.Height);
555 client_rect = new Rectangle(0, 0, DefaultSize.Width, DefaultSize.Height);
556 XplatUI.CalculateWindowRect(IntPtr.Zero, ref client_rect, CreateParams.Style, CreateParams.ExStyle, IntPtr.Zero, out bounds);
557 if ((CreateParams.Style & (int)WindowStyles.WS_CHILD) == 0) {
563 public Control(Control parent, string text) : this() {
568 public Control(Control parent, string text, int left, int top, int width, int height) : this() {
573 bounds.Height=height;
574 SetBoundsCore(left, top, width, height, BoundsSpecified.All);
578 public Control(string text) : this() {
582 public Control(string text, int left, int top, int width, int height) : this() {
586 bounds.Height=height;
587 SetBoundsCore(left, top, width, height, BoundsSpecified.All);
591 protected override void Dispose(bool disposing) {
604 OnHandleDestroyed(EventArgs.Empty);
605 controls.Remove(this);
607 #endregion // Public Constructors
609 #region Internal Properties
610 internal BorderStyle InternalBorderStyle {
616 if (border_style != value) {
617 border_style = value;
619 XplatUI.SetBorderStyle(window.Handle, border_style);
623 #endregion // Internal Properties
625 #region Private & Internal Methods
626 internal static IAsyncResult BeginInvokeInternal (Delegate method, object [] args) {
627 AsyncMethodResult result = new AsyncMethodResult ();
628 AsyncMethodData data = new AsyncMethodData ();
630 data.Method = method;
632 data.Result = new WeakReference (result);
634 XplatUI.SendAsyncMethod (data);
638 internal Graphics DeviceContext {
641 CreateBuffers(this.Width, this.Height);
647 internal Bitmap ImageBuffer {
650 CreateBuffers(this.Width, this.Height);
656 internal void CreateBuffers (int width, int height) {
657 if (double_buffering == false)
660 if (dc_mem != null) {
674 bmp_mem = new Bitmap (width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
675 dc_mem = Graphics.FromImage (bmp_mem);
678 internal void InvalidateBuffers ()
680 if (double_buffering == false)
683 if (dc_mem != null) {
693 internal static void SetChildColor(Control parent) {
696 for (int i=0; i < parent.child_controls.Count; i++) {
697 child=parent.child_controls[i];
698 if (child.IsHandleCreated) {
699 XplatUI.SetWindowBackground(child.window.Handle, child.BackColor);
701 if (child.child_controls.Count>0) {
702 SetChildColor(child);
708 internal bool Select(Control control) {
710 IContainerControl container;
712 if (control == null) {
716 parent = control.parent;
718 if (((control.control_style & ControlStyles.Selectable) !=0) && (parent != null)) {
719 while (parent != null) {
720 if (!parent.is_visible || !parent.is_enabled) {
723 parent = parent.parent;
727 control.is_selected = true;
729 XplatUI.SetFocus(control.window.Handle);
730 container = GetContainerControl();
731 if (container != null) {
732 container.ActiveControl = control;
737 internal virtual void DoDefaultAction() {
738 // Only here to be overriden by our actual controls; this is needed by the accessibility class
741 internal static int LowOrder (int param) {
742 return (param & 0xffff);
745 internal static int HighOrder (int param) {
746 return (param >> 16);
749 internal static MouseButtons FromParamToMouseButtons (int param) {
750 MouseButtons buttons = MouseButtons.None;
752 if ((param & (int) MsgButtons.MK_LBUTTON) != 0)
753 buttons |= MouseButtons.Left;
755 if ((param & (int) MsgButtons.MK_MBUTTON) != 0)
756 buttons |= MouseButtons.Middle;
758 if ((param & (int) MsgButtons.MK_RBUTTON) != 0)
759 buttons |= MouseButtons.Right;
765 internal virtual bool ProcessControlMnemonic(char charCode) {
766 return ProcessMnemonic(charCode);
769 private static Control FindFlatForward(Control container, Control start) {
775 end = container.child_controls.Count;
778 index = start.tab_index;
783 for (int i = 0; i < end; i++) {
785 if (container.child_controls[i].tab_index > index) {
786 found = container.child_controls[i];
788 } else if (found.tab_index > container.child_controls[i].tab_index) {
789 if (container.child_controls[i].tab_index > index) {
790 found = container.child_controls[i];
797 private static Control FindControlForward(Control container, Control start) {
804 if ((start is IContainerControl) || start.GetStyle(ControlStyles.ContainerControl)) {
805 found = FindControlForward(start, null);
812 while (p != container) {
813 found = FindFlatForward(p, start);
821 return FindFlatForward(container, start);
824 private static Control FindFlatBackward(Control container, Control start) {
830 end = container.child_controls.Count;
833 index = start.tab_index;
835 // FIXME: Possible speed-up: Keep the highest taborder index in the container
837 for (int i = 0; i < end; i++) {
838 if (container.child_controls[i].tab_index > index) {
839 index = container.child_controls[i].tab_index;
845 for (int i = 0; i < end; i++) {
847 if (container.child_controls[i].tab_index < index) {
848 found = container.child_controls[i];
850 } else if (found.tab_index < container.child_controls[i].tab_index) {
851 if (container.child_controls[i].tab_index < index) {
852 found = container.child_controls[i];
859 private static Control FindControlBackward(Control container, Control start) {
865 found = FindFlatBackward(start.parent, start);
866 if (found == null && start.parent != container) {
871 found = FindFlatBackward(container, start);
874 while ((found != null) && ((found is IContainerControl) || found.GetStyle(ControlStyles.ContainerControl))) {
875 found = FindControlBackward(found, null);
884 private void HandleClick(int clicks) {
885 if (GetStyle(ControlStyles.StandardClick)) {
887 if (GetStyle(ControlStyles.StandardDoubleClick)) {
888 OnDoubleClick(EventArgs.Empty);
890 OnClick(EventArgs.Empty);
893 OnClick(EventArgs.Empty);
898 private void CheckDataBindings ()
900 if (data_bindings == null)
903 BindingContext binding_context = BindingContext;
904 foreach (Binding binding in data_bindings) {
905 binding.Check (binding_context);
909 #endregion // Private & Internal Methods
911 #region Public Static Properties
912 public static Color DefaultBackColor {
914 return ThemeEngine.Current.DefaultControlBackColor;
918 public static Font DefaultFont {
920 return ThemeEngine.Current.DefaultFont;
924 public static Color DefaultForeColor {
926 return ThemeEngine.Current.DefaultControlForeColor;
930 public static Keys ModifierKeys {
932 return XplatUI.State.ModifierKeys;
936 public static MouseButtons MouseButtons {
938 return XplatUI.State.MouseButtons;
942 public static Point MousePosition {
944 return Cursor.Position;
947 #endregion // Public Static Properties
949 #region Public Instance Properties
950 [EditorBrowsable(EditorBrowsableState.Advanced)]
952 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
953 public AccessibleObject AccessibilityObject {
955 if (accessibility_object==null) {
956 accessibility_object=CreateAccessibilityInstance();
958 return accessibility_object;
962 [EditorBrowsable(EditorBrowsableState.Advanced)]
964 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
965 public string AccessibleDefaultActionDescription {
967 return AccessibilityObject.default_action;
971 AccessibilityObject.default_action=value;
977 public string AccessibleDescription {
979 return AccessibilityObject.description;
983 AccessibilityObject.description=value;
989 public string AccessibleName {
991 return AccessibilityObject.Name;
995 AccessibilityObject.Name=value;
999 [DefaultValue(AccessibleRole.Default)]
1000 public AccessibleRole AccessibleRole {
1002 return AccessibilityObject.role;
1006 AccessibilityObject.role=value;
1010 [DefaultValue(false)]
1011 public virtual bool AllowDrop {
1013 return XplatUI.State.DropTarget;
1017 XplatUI.State.DropTarget=value;
1022 [RefreshProperties(RefreshProperties.Repaint)]
1023 [DefaultValue(AnchorStyles.Top | AnchorStyles.Left)]
1024 public virtual AnchorStyles Anchor {
1026 return anchor_style;
1032 if (parent != null) {
1033 parent.PerformLayout(this, "Parent");
1039 public virtual Color BackColor {
1041 if (background_color.IsEmpty) {
1043 return parent.BackColor;
1045 return DefaultBackColor;
1047 return background_color;
1051 background_color=value;
1052 if (this.IsHandleCreated) {
1053 XplatUI.SetWindowBackground(this.window.Handle, value);
1055 SetChildColor(this);
1056 OnBackColorChanged(EventArgs.Empty);
1062 [DefaultValue(null)]
1063 public virtual Image BackgroundImage {
1065 return background_image;
1069 if (background_image!=value) {
1070 background_image=value;
1071 OnBackgroundImageChanged(EventArgs.Empty);
1076 [EditorBrowsable(EditorBrowsableState.Advanced)]
1078 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1079 public virtual BindingContext BindingContext {
1081 if (binding_context != null)
1082 return binding_context;
1085 binding_context = Parent.BindingContext;
1086 return binding_context;
1089 if (binding_context != value) {
1090 binding_context = value;
1091 OnBindingContextChanged(EventArgs.Empty);
1096 [EditorBrowsable(EditorBrowsableState.Advanced)]
1098 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1101 return bounds.Y+bounds.Height;
1105 [EditorBrowsable(EditorBrowsableState.Advanced)]
1107 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1108 public Rectangle Bounds {
1114 SetBoundsCore(value.Left, value.Top, value.Width, value.Height, BoundsSpecified.All);
1118 [EditorBrowsable(EditorBrowsableState.Advanced)]
1120 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1121 public bool CanFocus {
1123 if (is_visible && is_enabled && GetStyle(ControlStyles.Selectable)) {
1130 [EditorBrowsable(EditorBrowsableState.Advanced)]
1132 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1133 public bool CanSelect {
1137 if (!GetStyle(ControlStyles.Selectable) || this.parent == null) {
1141 parent = this.parent;
1142 while (parent != null) {
1143 if (!parent.is_visible || !parent.is_enabled) {
1147 parent = parent.parent;
1153 [EditorBrowsable(EditorBrowsableState.Advanced)]
1155 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1156 public bool Capture {
1158 return this.is_captured;
1162 if (this.IsHandleCreated) {
1163 if (value && !is_captured) {
1165 XplatUI.GrabWindow(this.window.Handle, IntPtr.Zero);
1166 } else if (!value && is_captured) {
1167 XplatUI.UngrabWindow(this.window.Handle);
1168 is_captured = false;
1174 [DefaultValue(true)]
1175 public bool CausesValidation {
1177 return this.causes_validation;
1181 if (this.causes_validation != value) {
1182 causes_validation = value;
1183 OnCausesValidationChanged(EventArgs.Empty);
1188 [EditorBrowsable(EditorBrowsableState.Advanced)]
1190 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1191 public Rectangle ClientRectangle {
1193 client_rect.Width = client_size.Width;
1194 client_rect.Height = client_size.Height;
1199 [EditorBrowsable(EditorBrowsableState.Advanced)]
1201 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1202 public Size ClientSize {
1205 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1206 return ((Form)this).form_parent_window.ClientSize;
1214 this.SetClientSizeCore(value.Width, value.Height);
1218 [EditorBrowsable(EditorBrowsableState.Advanced)]
1220 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1221 [DescriptionAttribute("ControlCompanyNameDescr")]
1222 public String CompanyName {
1224 return "Mono Project, Novell, Inc.";
1228 [EditorBrowsable(EditorBrowsableState.Advanced)]
1230 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1231 public bool ContainsFocus {
1237 for (int i=0; i < child_controls.Count; i++) {
1238 if (child_controls[i].ContainsFocus) {
1246 [DefaultValue(null)]
1247 public virtual ContextMenu ContextMenu {
1249 return context_menu;
1253 if (context_menu != value) {
1254 context_menu = value;
1255 OnContextMenuChanged(EventArgs.Empty);
1261 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
1262 public ControlCollection Controls {
1264 return this.child_controls;
1268 [EditorBrowsable(EditorBrowsableState.Advanced)]
1270 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1271 public bool Created {
1273 if (!this.is_disposed && (this.window.Handle != IntPtr.Zero)) {
1280 [AmbientValue(null)]
1281 public virtual Cursor Cursor {
1283 if (cursor != null) {
1287 if (parent != null) {
1288 return parent.Cursor;
1291 return Cursors.Default;
1295 if (cursor != value) {
1300 pt = Cursor.Position;
1301 if (bounds.Contains(pt)) {
1302 if (GetChildAtPoint(pt) == null) {
1303 if (cursor != null) {
1304 XplatUI.SetCursor(window.Handle, cursor.handle);
1306 if (parent != null) {
1307 XplatUI.SetCursor(window.Handle, parent.Cursor.handle);
1309 XplatUI.SetCursor(window.Handle, Cursors.def.handle);
1315 OnCursorChanged(EventArgs.Empty);
1321 [EditorBrowsable(EditorBrowsableState.Advanced)]
1323 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1324 public ControlBindingsCollection DataBindings {
1326 if (data_bindings == null)
1327 data_bindings = new ControlBindingsCollection (this);
1328 return data_bindings;
1332 [EditorBrowsable(EditorBrowsableState.Advanced)]
1334 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1335 public virtual Rectangle DisplayRectangle {
1337 return ClientRectangle;
1341 [EditorBrowsable(EditorBrowsableState.Advanced)]
1343 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1344 public bool Disposing {
1351 [RefreshProperties(RefreshProperties.Repaint)]
1352 [DefaultValue(DockStyle.None)]
1353 public virtual DockStyle Dock {
1359 if (dock_style == value) {
1365 if (parent != null) {
1366 parent.PerformLayout(this, "Parent");
1369 OnDockChanged(EventArgs.Empty);
1375 public bool Enabled {
1381 if (is_enabled == value) {
1387 OnEnabledChanged (EventArgs.Empty);
1391 [EditorBrowsable(EditorBrowsableState.Advanced)]
1393 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1394 public virtual bool Focused {
1396 return this.has_focus;
1401 [AmbientValue(null)]
1403 public virtual Font Font {
1409 if (Parent != null && Parent.Font != null) {
1417 if (font == value) {
1423 OnFontChanged (EventArgs.Empty);
1428 public virtual Color ForeColor {
1430 if (foreground_color.IsEmpty) {
1432 return parent.ForeColor;
1434 return DefaultForeColor;
1436 return foreground_color;
1440 if (foreground_color != value) {
1441 foreground_color=value;
1443 OnForeColorChanged(EventArgs.Empty);
1450 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1451 public IntPtr Handle { // IWin32Window
1453 if (!IsHandleCreated) {
1456 return window.Handle;
1460 [EditorBrowsable(EditorBrowsableState.Advanced)]
1462 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1463 public bool HasChildren {
1465 if (this.child_controls.Count>0) {
1472 [EditorBrowsable(EditorBrowsableState.Always)]
1474 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1477 return this.bounds.Height;
1481 SetBoundsCore(bounds.X, bounds.Y, bounds.Width, value, BoundsSpecified.Height);
1485 [AmbientValue(ImeMode.Inherit)]
1487 public ImeMode ImeMode {
1493 if (ime_mode != value) {
1496 OnImeModeChanged(EventArgs.Empty);
1501 [EditorBrowsable(EditorBrowsableState.Advanced)]
1503 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1504 public bool InvokeRequired { // ISynchronizeInvoke
1506 if (creator_thread!=Thread.CurrentThread) {
1513 [EditorBrowsable(EditorBrowsableState.Advanced)]
1515 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1516 public bool IsAccessible {
1518 return is_accessible;
1522 is_accessible = value;
1526 [EditorBrowsable(EditorBrowsableState.Advanced)]
1528 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1529 public bool IsDisposed {
1531 return this.is_disposed;
1535 [EditorBrowsable(EditorBrowsableState.Advanced)]
1537 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1538 public bool IsHandleCreated {
1540 if ((window!=null) && (window.Handle!=IntPtr.Zero)) {
1548 [EditorBrowsable(EditorBrowsableState.Always)]
1550 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1553 return this.bounds.X;
1557 SetBoundsCore(value, bounds.Y, bounds.Width, bounds.Height, BoundsSpecified.X);
1562 public Point Location {
1564 return new Point(bounds.X, bounds.Y);
1568 SetBoundsCore(value.X, value.Y, bounds.Width, bounds.Height, BoundsSpecified.Location);
1573 public string Name {
1584 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1585 public Control Parent {
1591 if (value == this) {
1592 throw new ArgumentException("A circular control reference has been made. A control cannot be owned or parented to itself.");
1595 if (parent!=value) {
1597 parent.Controls.Remove(this);
1602 if (!parent.Controls.Contains(this)) {
1603 parent.Controls.Add(this);
1606 XplatUI.SetParent(Handle, value.Handle);
1610 OnParentChanged(EventArgs.Empty);
1615 [EditorBrowsable(EditorBrowsableState.Advanced)]
1617 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1618 public string ProductName {
1620 return "Novell Mono MWF";
1624 [EditorBrowsable(EditorBrowsableState.Advanced)]
1626 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1627 public string ProductVersion {
1629 return "1.1.4322.573";
1633 [EditorBrowsable(EditorBrowsableState.Advanced)]
1635 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1636 public bool RecreatingHandle {
1638 return is_recreating;
1642 [EditorBrowsable(EditorBrowsableState.Advanced)]
1644 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1645 public Region Region {
1647 return new Region(this.bounds);
1654 g = this.CreateGraphics();
1655 r = value.GetBounds(g);
1657 SetBounds((int)r.X, (int)r.Y, (int)r.Width, (int)r.Height);
1663 [EditorBrowsable(EditorBrowsableState.Advanced)]
1665 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1668 return this.bounds.X+this.bounds.Width;
1672 [AmbientValue(RightToLeft.Inherit)]
1674 public virtual RightToLeft RightToLeft {
1676 return right_to_left;
1680 if (value != right_to_left) {
1681 right_to_left = value;
1682 OnRightToLeftChanged(EventArgs.Empty);
1687 [EditorBrowsable(EditorBrowsableState.Advanced)]
1688 public override ISite Site {
1701 return new Size(Width, Height);
1705 SetBoundsCore(bounds.X, bounds.Y, value.Width, value.Height, BoundsSpecified.Size);
1710 [MergableProperty(false)]
1711 public int TabIndex {
1713 if (tab_index != -1) {
1720 if (tab_index != value) {
1722 OnTabIndexChanged(EventArgs.Empty);
1728 [DefaultValue(true)]
1729 public bool TabStop {
1735 if (tab_stop != value) {
1737 OnTabStopChanged(EventArgs.Empty);
1742 [Localizable(false)]
1744 [TypeConverter(typeof(StringConverter))]
1745 [DefaultValue(null)]
1752 control_tag = value;
1758 [BindableAttribute(true)]
1759 public virtual string Text {
1765 if (value == null) {
1766 value = String.Empty;
1771 XplatUI.Text(Handle, text);
1772 // FIXME: Do we need a Refresh() here?
1773 OnTextChanged (EventArgs.Empty);
1778 [EditorBrowsable(EditorBrowsableState.Always)]
1780 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1783 return this.bounds.Y;
1787 SetBoundsCore(bounds.X, value, bounds.Width, bounds.Height, BoundsSpecified.Y);
1791 [EditorBrowsable(EditorBrowsableState.Advanced)]
1793 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1794 public Control TopLevelControl {
1798 while (p.parent != null) {
1807 public bool Visible {
1817 SetVisibleCore(value);
1821 [EditorBrowsable(EditorBrowsableState.Always)]
1823 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1826 return this.bounds.Width;
1830 SetBoundsCore(bounds.X, bounds.Y, value, bounds.Height, BoundsSpecified.Width);
1834 [EditorBrowsable(EditorBrowsableState.Never)]
1836 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1837 public IWindowTarget WindowTarget {
1846 #endregion // Public Instance Properties
1848 #region Protected Instance Properties
1849 protected virtual CreateParams CreateParams {
1851 CreateParams create_params = new CreateParams();
1853 create_params.Caption = Text;
1854 create_params.X = Left;
1855 create_params.Y = Top;
1856 create_params.Width = Width;
1857 create_params.Height = Height;
1859 create_params.ClassName = XplatUI.DefaultClassName;
1860 create_params.ClassStyle = 0;
1861 create_params.ExStyle = 0;
1862 create_params.Param = 0;
1865 create_params.Parent = parent.Handle;
1868 create_params.Style = (int)WindowStyles.WS_CHILD | (int)WindowStyles.WS_CLIPCHILDREN | (int)WindowStyles.WS_CLIPSIBLINGS;
1871 create_params.Style |= (int)WindowStyles.WS_VISIBLE;
1874 return create_params;
1878 protected virtual ImeMode DefaultImeMode {
1880 return ImeMode.Inherit;
1884 protected virtual Size DefaultSize {
1886 return new Size(100, 23);
1890 protected int FontHeight {
1900 protected bool RenderRightToLeft {
1902 return (this.right_to_left == RightToLeft.Yes);
1906 protected bool ResizeRedraw {
1908 return GetStyle(ControlStyles.ResizeRedraw);
1912 SetStyle(ControlStyles.ResizeRedraw, value);
1916 [EditorBrowsable(EditorBrowsableState.Advanced)]
1918 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1919 protected virtual bool ShowFocusCues {
1925 [EditorBrowsable(EditorBrowsableState.Advanced)]
1927 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1928 protected bool ShowKeyboardCues {
1933 #endregion // Protected Instance Properties
1935 #region Public Static Methods
1936 [EditorBrowsable(EditorBrowsableState.Advanced)]
1937 public static Control FromChildHandle(IntPtr handle) {
1938 IEnumerator control = Control.controls.GetEnumerator();
1940 while (control.MoveNext()) {
1941 if (((Control)control.Current).window.Handle == handle) {
1943 if (((Control)control.Current).Parent != null) {
1944 return ((Control)control.Current).Parent;
1951 [EditorBrowsable(EditorBrowsableState.Advanced)]
1952 public static Control FromHandle(IntPtr handle) {
1953 IEnumerator control = Control.controls.GetEnumerator();
1955 while (control.MoveNext()) {
1956 if (((Control)control.Current).window.Handle == handle) {
1958 return ((Control)control.Current);
1964 public static bool IsMnemonic(char charCode, string text) {
1967 amp = text.IndexOf('&');
1970 if (amp + 1 < text.Length) {
1971 if (text[amp + 1] != '&') {
1972 if (Char.ToUpper(charCode) == Char.ToUpper(text.ToCharArray(amp + 1, 1)[0])) {
1982 #region Protected Static Methods
1983 [EditorBrowsable(EditorBrowsableState.Advanced)]
1984 protected static bool ReflectMessage(IntPtr hWnd, ref Message m) {
1987 c = Control.FromHandle(hWnd);
1997 #region Public Instance Methods
1998 [EditorBrowsable(EditorBrowsableState.Advanced)]
1999 public IAsyncResult BeginInvoke(Delegate method) {
2000 return BeginInvokeInternal(method, null);
2003 [EditorBrowsable(EditorBrowsableState.Advanced)]
2004 public IAsyncResult BeginInvoke (Delegate method, object[] args) {
2005 return BeginInvokeInternal (method, args);
2008 public void BringToFront() {
2009 if ((parent != null) && (parent.child_controls[0]!=this)) {
2010 if (parent.child_controls.Contains(this)) {
2011 parent.child_controls.SetChildIndex(this, 0);
2015 XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, true, false);
2017 if (parent != null) {
2022 public bool Contains(Control ctl) {
2023 while (ctl != null) {
2032 public void CreateControl() {
2034 if (!IsHandleCreated)
2037 for (int i=0; i<child_controls.Count; i++) {
2038 child_controls[i].CreateControl();
2043 public Graphics CreateGraphics() {
2044 if (!IsHandleCreated) {
2045 this.CreateHandle();
2047 return Graphics.FromHwnd(this.window.Handle);
2050 [MonoTODO("Come up with cross platform drag-drop driver interface")]
2051 public DragDropEffects DoDragDrop(object data, DragDropEffects allowedEffects) {
2052 return DragDropEffects.None;
2055 [EditorBrowsable(EditorBrowsableState.Advanced)]
2056 public object EndInvoke (IAsyncResult async_result) {
2057 AsyncMethodResult result = (AsyncMethodResult) async_result;
2058 return result.EndInvoke ();
2061 public Form FindForm() {
2074 public bool Focus() {
2075 if (IsHandleCreated && !has_focus) {
2076 XplatUI.SetFocus(window.Handle);
2082 public Control GetChildAtPoint(Point pt) {
2083 // Microsoft's version of this function doesn't seem to work, so I can't check
2084 // if we only consider children or also grandchildren, etc.
2085 // I'm gonna say 'children only'
2086 for (int i=0; i<child_controls.Count; i++) {
2087 if (child_controls[i].Bounds.Contains(pt)) {
2088 return child_controls[i];
2094 public IContainerControl GetContainerControl() {
2095 Control current = this;
2097 while (current!=null) {
2098 if ((current is IContainerControl) && ((current.control_style & ControlStyles.ContainerControl)!=0)) {
2099 return (IContainerControl)current;
2101 current = current.parent;
2106 public Control GetNextControl(Control ctl, bool forward) {
2107 // If we're not a container we don't play
2108 if (!(this is IContainerControl) && !this.GetStyle(ControlStyles.ContainerControl)) {
2112 // If ctl is not contained by this, we start at the first child of this
2113 if (!this.Contains(ctl)) {
2117 // Search through our controls, starting at ctl, stepping into children as we encounter them
2118 // try to find the control with the tabindex closest to our own, or, if we're looking into
2119 // child controls, the one with the smallest tabindex
2121 return FindControlForward(this, ctl);
2123 return FindControlBackward(this, ctl);
2126 public void Hide() {
2127 this.Visible = false;
2130 public void Invalidate() {
2131 Invalidate(ClientRectangle, false);
2134 public void Invalidate(bool invalidateChildren) {
2135 Invalidate(ClientRectangle, invalidateChildren);
2138 public void Invalidate(System.Drawing.Rectangle rc) {
2139 Invalidate(rc, false);
2142 public void Invalidate(System.Drawing.Rectangle rc, bool invalidateChildren) {
2143 if (!IsHandleCreated || !Visible) {
2147 NotifyInvalidate(rc);
2149 XplatUI.Invalidate(Handle, rc, !GetStyle (ControlStyles.AllPaintingInWmPaint));
2151 if (invalidateChildren) {
2152 for (int i=0; i<child_controls.Count; i++) child_controls[i].Invalidate();
2154 OnInvalidated(new InvalidateEventArgs(rc));
2157 public void Invalidate(System.Drawing.Region region) {
2158 Invalidate(region, false);
2161 [MonoTODO("Figure out if GetRegionScans is usable")]
2162 public void Invalidate(System.Drawing.Region region, bool invalidateChildren) {
2163 throw new NotImplementedException();
2165 // FIXME - should use the GetRegionScans function of the region to invalidate each area
2166 //if (invalidateChildren) {
2167 // for (int i=0; i<child_controls.Count; i++) child_controls[i].Invalidate();
2171 public object Invoke (Delegate method) {
2172 return Invoke(method, null);
2175 public object Invoke (Delegate method, object[] args) {
2176 IAsyncResult result = BeginInvoke (method, args);
2177 return EndInvoke(result);
2180 [EditorBrowsable(EditorBrowsableState.Advanced)]
2181 public void PerformLayout() {
2182 PerformLayout(null, null);
2185 [EditorBrowsable(EditorBrowsableState.Advanced)]
2186 public void PerformLayout(Control affectedControl, string affectedProperty) {
2187 LayoutEventArgs levent = new LayoutEventArgs(affectedControl, affectedProperty);
2189 if (layout_suspended>0) {
2190 layout_pending = true;
2194 layout_pending = false;
2196 // Prevent us from getting messed up
2199 // Perform all Dock and Anchor calculations
2202 AnchorStyles anchor;
2207 space=this.DisplayRectangle;
2208 if (prev_size != Size.Empty) {
2209 diff_width = space.Width - prev_size.Width;
2210 diff_height = space.Height - prev_size.Height;
2216 // Deal with docking; go through in reverse, MS docs say that lowest Z-order is closest to edge
2217 for (int i = child_controls.Count - 1; i >= 0; i--) {
2218 child=child_controls[i];
2219 switch (child.Dock) {
2220 case DockStyle.None: {
2225 case DockStyle.Left: {
2226 child.SetBounds(space.Left, space.Y, child.Width, space.Height);
2227 space.X+=child.Width;
2228 space.Width-=child.Width;
2232 case DockStyle.Top: {
2233 child.SetBounds(space.Left, space.Y, space.Width, child.Height);
2234 space.Y+=child.Height;
2235 space.Height-=child.Height;
2239 case DockStyle.Right: {
2240 child.SetBounds(space.Right-child.Width, space.Y, child.Width, space.Height);
2241 space.Width-=child.Width;
2245 case DockStyle.Bottom: {
2246 child.SetBounds(space.Left, space.Bottom-child.Height, space.Width, child.Height);
2247 space.Height-=child.Height;
2253 for (int i = child_controls.Count - 1; i >= 0; i--) {
2254 child=child_controls[i];
2256 if (child.Dock == DockStyle.Fill) {
2257 child.SetBounds(space.Left, space.Top, space.Width, space.Height);
2263 space=this.DisplayRectangle;
2265 // Deal with anchoring
2266 for (int i=0; i < child_controls.Count; i++) {
2272 child=child_controls[i];
2273 anchor=child.Anchor;
2278 height=child.Height;
2280 // If the control is docked we don't need to do anything
2281 if (child.Dock != DockStyle.None) {
2285 if ((anchor & AnchorStyles.Left) !=0 ) {
2286 if ((anchor & AnchorStyles.Right) != 0) {
2287 // Anchoring to left and right
2288 width=width+diff_width;
2292 } else if ((anchor & AnchorStyles.Right) != 0) {
2298 if ((anchor & AnchorStyles.Top) !=0 ) {
2299 if ((anchor & AnchorStyles.Bottom) != 0) {
2300 height+=diff_height;
2304 } else if ((anchor & AnchorStyles.Bottom) != 0) {
2319 child.SetBounds(left, top, width, height);
2322 // Let everyone know
2326 // Need to make sure we decremend layout_suspended
2332 public Point PointToClient (Point p) {
2336 XplatUI.ScreenToClient (Handle, ref x, ref y);
2338 return new Point (x, y);
2341 public Point PointToScreen(Point p) {
2345 XplatUI.ClientToScreen(Handle, ref x, ref y);
2347 return new Point(x, y);
2350 public virtual bool PreProcessMessage(ref Message msg) {
2353 if ((msg.Msg == (int)Msg.WM_KEYDOWN) || (msg.Msg == (int)Msg.WM_SYSKEYDOWN)) {
2354 key_data = (Keys)msg.WParam.ToInt32();
2355 if (!ProcessCmdKey(ref msg, key_data)) {
2356 if (IsInputKey(key_data)) {
2360 return ProcessDialogKey(key_data);
2364 } else if (msg.Msg == (int)Msg.WM_CHAR) {
2365 if (IsInputChar((char)msg.WParam)) {
2368 } else if (msg.Msg == (int)Msg.WM_SYSCHAR) {
2369 if (IsInputChar((char)msg.WParam)) {
2372 return ProcessDialogChar((char)msg.WParam);
2377 public Rectangle RectangleToClient(Rectangle r) {
2378 return new Rectangle(PointToClient(r.Location), r.Size);
2381 public Rectangle RectangleToScreen(Rectangle r) {
2382 return new Rectangle(PointToScreen(r.Location), r.Size);
2385 public virtual void Refresh() {
2386 if (IsHandleCreated == true) {
2388 XplatUI.UpdateWindow(window.Handle);
2392 [EditorBrowsable(EditorBrowsableState.Never)]
2393 public virtual void ResetBackColor() {
2394 background_color = Color.Empty;
2397 #if haveDataBindings
2398 [EditorBrowsable(EditorBrowsableState.Never)]
2400 public void ResetBindings() {
2405 [EditorBrowsable(EditorBrowsableState.Never)]
2406 public virtual void ResetCursor() {
2410 [EditorBrowsable(EditorBrowsableState.Never)]
2411 public virtual void ResetFont() {
2415 [EditorBrowsable(EditorBrowsableState.Never)]
2416 public virtual void ResetForeColor() {
2417 foreground_color = Color.Empty;
2420 [EditorBrowsable(EditorBrowsableState.Never)]
2421 public void ResetImeMode() {
2422 ime_mode = DefaultImeMode;
2425 [EditorBrowsable(EditorBrowsableState.Never)]
2426 public virtual void ResetRightToLeft() {
2427 right_to_left = RightToLeft.Inherit;
2430 public virtual void ResetText() {
2434 public void ResumeLayout() {
2435 ResumeLayout (true);
2438 public void ResumeLayout(bool performLayout) {
2441 if (layout_suspended > 0) {
2445 if (performLayout || layout_pending) {
2450 public void Scale(float ratio) {
2451 ScaleCore(ratio, ratio);
2454 public void Scale(float dx, float dy) {
2458 public void Select() {
2459 Select(false, false);
2462 public bool SelectNextControl(Control ctl, bool forward, bool tabStopOnly, bool nested, bool wrap) {
2467 c = GetNextControl(c, forward);
2476 if (c.CanSelect && ((c.parent == ctl.parent) || nested) && (c.tab_stop || !tabStopOnly)) {
2480 } while (c != ctl); // If we wrap back to ourselves we stop
2485 public void SendToBack() {
2486 if ((parent != null) && (parent.child_controls[parent.child_controls.Count-1]!=this)) {
2487 if (parent.child_controls.Contains(this)) {
2488 parent.child_controls.SetChildIndex(this, parent.child_controls.Count);
2492 XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, false, true);
2493 if (parent != null) {
2498 public void SetBounds(int x, int y, int width, int height) {
2499 SetBoundsCore(x, y, width, height, BoundsSpecified.All);
2502 public void SetBounds(int x, int y, int width, int height, BoundsSpecified specified) {
2503 SetBoundsCore(x, y, width, height, specified);
2506 public void Show() {
2507 if (!IsHandleCreated) {
2508 this.CreateHandle();
2514 public void SuspendLayout() {
2518 public void Update() {
2519 XplatUI.UpdateWindow(window.Handle);
2521 #endregion // Public Instance Methods
2523 #region Protected Instance Methods
2524 [EditorBrowsable(EditorBrowsableState.Advanced)]
2525 [MonoTODO("Implement this and tie it into Control.ControlAccessibleObject.NotifyClients")]
2526 protected void AccessibilityNotifyClients(AccessibleEvents accEvent, int childID) {
2527 throw new NotImplementedException();
2530 [EditorBrowsable(EditorBrowsableState.Advanced)]
2531 protected virtual AccessibleObject CreateAccessibilityInstance() {
2532 return new Control.ControlAccessibleObject(this);
2535 [EditorBrowsable(EditorBrowsableState.Advanced)]
2536 protected virtual ControlCollection CreateControlsInstance() {
2537 return new ControlCollection(this);
2540 [EditorBrowsable(EditorBrowsableState.Advanced)]
2541 protected virtual void CreateHandle() {
2543 throw new ObjectDisposedException(Name);
2546 if (IsHandleCreated) {
2551 window = new ControlNativeWindow(this);
2552 window.CreateHandle(CreateParams);
2554 // Find out where the window manager placed us
2559 if (window.Handle!=IntPtr.Zero) {
2560 if (!controls.Contains(window.Handle)) {
2564 creator_thread = Thread.CurrentThread;
2566 XplatUI.SetWindowBackground(window.Handle, this.BackColor);
2568 OnHandleCreated(EventArgs.Empty);
2572 [EditorBrowsable(EditorBrowsableState.Advanced)]
2573 protected virtual void DefWndProc(ref Message m) {
2574 window.DefWndProc(ref m);
2577 [EditorBrowsable(EditorBrowsableState.Advanced)]
2578 protected virtual void DestroyHandle() {
2579 if (IsHandleCreated) {
2580 if (Handle != IntPtr.Zero) {
2581 controls.Remove(Handle);
2584 if (window != null) {
2585 window.DestroyHandle();
2590 protected bool GetStyle(ControlStyles flag) {
2591 return (control_style & flag) != 0;
2594 protected bool GetTopLevel() {
2598 [EditorBrowsable(EditorBrowsableState.Advanced)]
2599 protected virtual void InitLayout() {
2600 if (parent != null) {
2601 parent.PerformLayout(this, "parent");
2605 [EditorBrowsable(EditorBrowsableState.Advanced)]
2606 protected void InvokeGotFocus(Control toInvoke, EventArgs e) {
2607 toInvoke.OnGotFocus(e);
2610 [EditorBrowsable(EditorBrowsableState.Advanced)]
2611 protected void InvokeLostFocus(Control toInvoke, EventArgs e) {
2612 toInvoke.OnLostFocus(e);
2615 [EditorBrowsable(EditorBrowsableState.Advanced)]
2616 protected void InvokeOnClick(Control toInvoke, EventArgs e) {
2617 toInvoke.OnClick(e);
2620 protected void InvokePaint(Control toInvoke, PaintEventArgs e) {
2621 toInvoke.OnPaint(e);
2624 protected void InvokePaintBackground(Control toInvoke, PaintEventArgs e) {
2625 toInvoke.OnPaintBackground(e);
2628 protected virtual bool IsInputChar (char charCode) {
2629 if (parent != null) {
2630 return parent.IsInputChar(charCode);
2636 protected virtual bool IsInputKey (Keys keyData) {
2637 // Doc says this one calls IsInputChar; not sure what to do with that
2641 [EditorBrowsable(EditorBrowsableState.Advanced)]
2642 protected virtual void NotifyInvalidate(Rectangle invalidatedArea) {
2646 protected virtual bool ProcessCmdKey(ref Message msg, Keys keyData) {
2647 if ((context_menu != null) && context_menu.ProcessCmdKey(ref msg, keyData)) {
2651 if (parent != null) {
2652 return parent.ProcessCmdKey(ref msg, keyData);
2658 protected virtual bool ProcessDialogChar(char charCode) {
2659 if (parent != null) {
2660 return parent.ProcessDialogChar (charCode);
2666 protected virtual bool ProcessDialogKey (Keys keyData) {
2667 if (parent != null) {
2668 return parent.ProcessDialogKey (keyData);
2674 protected virtual bool ProcessKeyEventArgs (ref Message msg)
2676 KeyEventArgs key_event;
2679 case (int)Msg.WM_KEYDOWN: {
2680 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
2681 OnKeyDown (key_event);
2682 return key_event.Handled;
2684 case (int)Msg.WM_KEYUP: {
2685 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
2686 OnKeyUp (key_event);
2687 return key_event.Handled;
2690 case (int)Msg.WM_CHAR: {
2691 KeyPressEventArgs key_press_event;
2693 key_press_event = new KeyPressEventArgs((char)msg.WParam);
2694 OnKeyPress(key_press_event);
2695 return key_press_event.Handled;
2706 protected internal virtual bool ProcessKeyMessage(ref Message msg) {
2707 if (parent != null) {
2708 if (parent.ProcessKeyPreview(ref msg)) {
2716 protected virtual bool ProcessKeyPreview(ref Message msg) {
2717 if (parent != null) {
2718 return parent.ProcessKeyPreview(ref msg);
2724 protected virtual bool ProcessMnemonic(char charCode) {
2729 [EditorBrowsable(EditorBrowsableState.Advanced)]
2730 protected void RaiseDragEvent(object key, DragEventArgs e) {
2734 [EditorBrowsable(EditorBrowsableState.Advanced)]
2735 protected void RaiseKeyEvent(object key, KeyEventArgs e) {
2739 [EditorBrowsable(EditorBrowsableState.Advanced)]
2740 protected void RaiseMouseEvent(object key, MouseEventArgs e) {
2744 [EditorBrowsable(EditorBrowsableState.Advanced)]
2745 protected void RaisePaintEvent(object key, PaintEventArgs e) {
2749 [EditorBrowsable(EditorBrowsableState.Advanced)]
2750 protected void RecreateHandle() {
2751 IEnumerator child = child_controls.GetEnumerator();
2755 if (IsHandleCreated) {
2761 while (child.MoveNext()) {
2762 ((Control)child.Current).RecreateHandle();
2768 is_recreating = false;
2771 [EditorBrowsable(EditorBrowsableState.Advanced)]
2772 protected void ResetMouseEventArgs() {
2776 [EditorBrowsable(EditorBrowsableState.Advanced)]
2777 protected ContentAlignment RtlTranslateAlignment(ContentAlignment align) {
2778 if (right_to_left == RightToLeft.No) {
2783 case ContentAlignment.TopLeft: {
2784 return ContentAlignment.TopRight;
2787 case ContentAlignment.TopRight: {
2788 return ContentAlignment.TopLeft;
2791 case ContentAlignment.MiddleLeft: {
2792 return ContentAlignment.MiddleRight;
2795 case ContentAlignment.MiddleRight: {
2796 return ContentAlignment.MiddleLeft;
2799 case ContentAlignment.BottomLeft: {
2800 return ContentAlignment.BottomRight;
2803 case ContentAlignment.BottomRight: {
2804 return ContentAlignment.BottomLeft;
2808 // if it's center it doesn't change
2814 [EditorBrowsable(EditorBrowsableState.Advanced)]
2815 protected HorizontalAlignment RtlTranslateAlignment(HorizontalAlignment align) {
2816 if ((right_to_left == RightToLeft.No) || (align == HorizontalAlignment.Center)) {
2820 if (align == HorizontalAlignment.Left) {
2821 return HorizontalAlignment.Right;
2824 // align must be HorizontalAlignment.Right
2825 return HorizontalAlignment.Left;
2828 [EditorBrowsable(EditorBrowsableState.Advanced)]
2829 protected LeftRightAlignment RtlTranslateAlignment(LeftRightAlignment align) {
2830 if (right_to_left == RightToLeft.No) {
2834 if (align == LeftRightAlignment.Left) {
2835 return LeftRightAlignment.Right;
2838 // align must be LeftRightAlignment.Right;
2839 return LeftRightAlignment.Left;
2842 [EditorBrowsable(EditorBrowsableState.Advanced)]
2843 protected ContentAlignment RtlTranslateContent(ContentAlignment align) {
2844 return RtlTranslateAlignment(align);
2847 [EditorBrowsable(EditorBrowsableState.Advanced)]
2848 protected HorizontalAlignment RtlTranslateHorizontal(HorizontalAlignment align) {
2849 return RtlTranslateAlignment(align);
2852 [EditorBrowsable(EditorBrowsableState.Advanced)]
2853 protected LeftRightAlignment RtlTranslateLeftRight(LeftRightAlignment align) {
2854 return RtlTranslateAlignment(align);
2857 [EditorBrowsable(EditorBrowsableState.Advanced)]
2858 protected virtual void ScaleCore(float dx, float dy) {
2864 location = new Point((int)(Left * dx), (int)(Top * dy));
2865 size = this.ClientSize;
2868 if (!GetStyle(ControlStyles.FixedWidth)) {
2869 size.Width = (int)(size.Width * dx);
2872 if (!GetStyle(ControlStyles.FixedHeight)) {
2873 size.Height = (int)(size.Height * dy);
2876 Location = location;
2879 /* Now scale our children */
2880 for (int i=0; i < child_controls.Count; i++) {
2881 child_controls[i].Scale(dx, dy);
2887 protected virtual void Select(bool directed, bool forward) {
2892 // Select this control
2897 if (parent == null) {
2901 // FIXME - this thing is doing the wrong stuff, needs to be similar to SelectNextControl
2903 index = parent.child_controls.IndexOf(this);
2908 if ((index+1) < parent.child_controls.Count) {
2917 index = parent.child_controls.Count-1;
2920 result = Select(parent.child_controls[index]);
2921 } while (!result && parent.child_controls[index] != this);
2924 [EditorBrowsable(EditorBrowsableState.Advanced)]
2925 protected virtual void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
2926 // SetBoundsCore updates the Win32 control itself. UpdateBounds updates the controls variables and fires events, I'm guessing - pdb
2927 if ((specified & BoundsSpecified.X) != BoundsSpecified.X) {
2931 if ((specified & BoundsSpecified.Y) != BoundsSpecified.Y) {
2935 if ((specified & BoundsSpecified.Width) != BoundsSpecified.Width) {
2939 if ((specified & BoundsSpecified.Height) != BoundsSpecified.Height) {
2943 if (IsHandleCreated) {
2944 XplatUI.SetWindowPos(Handle, x, y, width, height);
2946 UpdateBounds(x, y, width, height);
2949 [EditorBrowsable(EditorBrowsableState.Advanced)]
2950 protected virtual void SetClientSizeCore(int x, int y) {
2951 // Calculate the actual window size from the client size (it usually stays the same or grows)
2952 Rectangle ClientRect;
2953 Rectangle WindowRect;
2956 ClientRect = new Rectangle(0, 0, x, y);
2957 cp = this.CreateParams;
2959 if (XplatUI.CalculateWindowRect(Handle, ref ClientRect, cp.Style, cp.ExStyle, IntPtr.Zero, out WindowRect)==false) {
2963 SetBoundsCore(bounds.X, bounds.Y, WindowRect.Width, WindowRect.Height, BoundsSpecified.Size);
2966 [EditorBrowsable(EditorBrowsableState.Advanced)]
2967 protected void SetStyle(ControlStyles flag, bool value) {
2969 control_style |= flag;
2971 control_style &= ~flag;
2975 protected void SetTopLevel(bool value) {
2976 if ((GetTopLevel() != value) && (parent != null)) {
2977 throw new Exception();
2981 if (value == true) {
2991 is_toplevel = value;
2994 protected virtual void SetVisibleCore(bool value) {
2995 if (value!=is_visible) {
2997 XplatUI.SetVisible(Handle, value);
2998 // Explicitly move Toplevel windows to where we want them;
2999 // apparently moving unmapped toplevel windows doesn't work
3000 if (is_visible && (this is Form)) {
3001 XplatUI.SetWindowPos(window.Handle, bounds.X, bounds.Y, bounds.Width, bounds.Height);
3003 OnVisibleChanged(EventArgs.Empty);
3006 if (dc_mem != null) {
3011 if (bmp_mem != null) {
3016 this.CreateBuffers(bounds.Width, bounds.Height);
3019 // FIXME - deal with focus
3021 if (parent != null) {
3022 parent.PerformLayout(this, "visible");
3024 PerformLayout(this, "visible");
3029 [EditorBrowsable(EditorBrowsableState.Advanced)]
3030 protected void UpdateBounds() {
3038 if (!IsHandleCreated) {
3042 XplatUI.GetWindowPos(this.Handle, this is Form, out x, out y, out width, out height, out client_width, out client_height);
3044 UpdateBounds(x, y, width, height, client_width, client_height);
3047 [EditorBrowsable(EditorBrowsableState.Advanced)]
3048 protected void UpdateBounds(int x, int y, int width, int height) {
3049 // UpdateBounds only seems to set our sizes and fire events but not update the GUI window to match
3051 bool resized = false;
3053 int client_x_diff = this.bounds.Width-this.client_size.Width;
3054 int client_y_diff = this.bounds.Height-this.client_size.Height;
3056 // Needed to generate required notifications
3057 if ((this.bounds.X!=x) || (this.bounds.Y!=y)) {
3061 if ((this.Bounds.Width!=width) || (this.Bounds.Height!=height)) {
3068 bounds.Height=height;
3070 // Update client rectangle as well
3071 if (this.layout_suspended==0) {
3072 prev_size.Width=client_size.Width;
3073 prev_size.Height=client_size.Height;
3076 client_size.Width=width-client_x_diff;
3077 client_size.Height=height-client_y_diff;
3080 OnLocationChanged(EventArgs.Empty);
3084 OnSizeChanged(EventArgs.Empty);
3088 [EditorBrowsable(EditorBrowsableState.Advanced)]
3089 protected void UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) {
3090 UpdateBounds(x, y, width, height);
3092 this.client_size.Width=clientWidth;
3093 this.client_size.Height=clientHeight;
3096 [EditorBrowsable(EditorBrowsableState.Advanced)]
3097 protected void UpdateStyles() {
3098 if (!IsHandleCreated) {
3102 XplatUI.SetWindowStyle(window.Handle, CreateParams);
3105 [EditorBrowsable(EditorBrowsableState.Advanced)]
3106 protected void UpdateZOrder() {
3111 if (parent == null) {
3117 children = ctl.child_controls.Count;
3118 for (int i = 1; i < children; i++ ) {
3119 XplatUI.SetZOrder(ctl.child_controls[i].window.Handle, ctl.child_controls[i-1].window.Handle, false, false);
3122 children = child_controls.Count;
3123 for (int i = 1; i < children; i++ ) {
3124 XplatUI.SetZOrder(child_controls[i].window.Handle, child_controls[i-1].window.Handle, false, false);
3129 protected virtual void WndProc(ref Message m) {
3131 Console.WriteLine("Control received message {0}", (Msg)m.Msg);
3133 if ((this.control_style & ControlStyles.EnableNotifyMessage) != 0) {
3137 switch((Msg)m.Msg) {
3138 case Msg.WM_WINDOWPOSCHANGED: {
3141 if (GetStyle(ControlStyles.ResizeRedraw)) {
3148 case Msg.WM_PAINT: {
3149 PaintEventArgs paint_event;
3151 paint_event = XplatUI.PaintEventStart(Handle);
3153 if (GetStyle(ControlStyles.AllPaintingInWmPaint)) {
3154 OnPaintBackground(paint_event);
3156 OnPaint(paint_event);
3157 XplatUI.PaintEventEnd(Handle);
3162 case Msg.WM_ERASEBKGND: {
3163 if (GetStyle (ControlStyles.UserPaint)) {
3164 if (!GetStyle(ControlStyles.AllPaintingInWmPaint)) {
3165 PaintEventArgs eraseEventArgs = new PaintEventArgs (m.WParam == IntPtr.Zero ? Graphics.FromHwnd (m.HWnd) :
3166 Graphics.FromHdc (m.WParam), new Rectangle (new Point (0,0),Size));
3167 OnPaintBackground (eraseEventArgs);
3169 m.Result = (IntPtr)1;
3171 m.Result = IntPtr.Zero;
3178 case Msg.WM_LBUTTONUP: {
3179 HandleClick(mouse_clicks);
3180 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Left,
3182 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3184 if (mouse_clicks > 1) {
3190 case Msg.WM_LBUTTONDOWN: {
3191 if (CanSelect && !is_selected) {
3194 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3195 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3201 case Msg.WM_LBUTTONDBLCLK: {
3203 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3204 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3210 case Msg.WM_MBUTTONUP: {
3211 HandleClick(mouse_clicks);
3212 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Middle,
3214 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3216 if (mouse_clicks > 1) {
3222 case Msg.WM_MBUTTONDOWN: {
3223 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3224 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3230 case Msg.WM_MBUTTONDBLCLK: {
3232 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3233 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3238 case Msg.WM_RBUTTONUP: {
3239 HandleClick(mouse_clicks);
3240 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Right,
3242 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3244 if (mouse_clicks > 1) {
3250 case Msg.WM_RBUTTONDOWN: {
3251 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3252 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3257 case Msg.WM_RBUTTONDBLCLK: {
3259 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3260 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3265 case Msg.WM_MOUSEWHEEL: {
3267 OnMouseWheel (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3268 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3269 HighOrder(m.WParam.ToInt32())));
3274 case Msg.WM_MOUSEMOVE: {
3275 OnMouseMove (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3277 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3282 case Msg.WM_MOUSE_ENTER: {
3287 OnMouseEnter(EventArgs.Empty);
3291 case Msg.WM_MOUSE_LEAVE: {
3293 OnMouseLeave(EventArgs.Empty);
3297 case Msg.WM_MOUSEHOVER: {
3298 OnMouseHover(EventArgs.Empty);
3302 case Msg.WM_SYSKEYDOWN:
3303 case Msg.WM_KEYDOWN:
3304 case Msg.WM_SYSKEYUP:
3306 case Msg.WM_SYSCHAR:
3308 if (ProcessKeyEventArgs(ref m)) {
3312 if (PreProcessMessage(ref m)) {
3316 if (ProcessKeyMessage(ref m)) {
3325 if (m.LParam != IntPtr.Zero) {
3328 hi = new HELPINFO();
3330 hi = (HELPINFO) Marshal.PtrToStructure (m.LParam, typeof (HELPINFO));
3331 mouse_pos = new Point(hi.MousePos.x, hi.MousePos.y);
3333 mouse_pos = Control.MousePosition;
3335 OnHelpRequested(new HelpEventArgs(mouse_pos));
3336 m.Result = (IntPtr)1;
3340 case Msg.WM_KILLFOCUS: {
3341 OnLeave(EventArgs.Empty);
3342 if (CausesValidation) {
3344 e = new CancelEventArgs(false);
3353 OnValidated(EventArgs.Empty);
3356 this.has_focus = false;
3357 this.is_selected = false;
3358 OnLostFocus(EventArgs.Empty);
3362 case Msg.WM_SETFOCUS: {
3363 OnEnter(EventArgs.Empty);
3364 this.has_focus = true;
3365 OnGotFocus(EventArgs.Empty);
3370 case Msg.WM_SYSCOLORCHANGE: {
3371 ThemeEngine.Current.ResetDefaults();
3372 OnSystemColorsChanged(EventArgs.Empty);
3377 case Msg.WM_SETCURSOR: {
3378 if (cursor == null) {
3383 XplatUI.SetCursor(window.Handle, cursor.handle);
3384 m.Result = (IntPtr)1;
3394 #endregion // Public Instance Methods
3396 #region OnXXX methods
3397 [EditorBrowsable(EditorBrowsableState.Advanced)]
3398 protected virtual void OnBackColorChanged(EventArgs e) {
3399 if (BackColorChanged!=null) BackColorChanged(this, e);
3400 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackColorChanged(e);
3403 [EditorBrowsable(EditorBrowsableState.Advanced)]
3404 protected virtual void OnBackgroundImageChanged(EventArgs e) {
3405 if (BackgroundImageChanged!=null) BackgroundImageChanged(this, e);
3406 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackgroundImageChanged(e);
3409 [EditorBrowsable(EditorBrowsableState.Advanced)]
3410 protected virtual void OnBindingContextChanged(EventArgs e) {
3411 CheckDataBindings ();
3412 if (BindingContextChanged!=null) {
3413 BindingContextChanged(this, e);
3415 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBindingContextChanged(e);
3418 [EditorBrowsable(EditorBrowsableState.Advanced)]
3419 protected virtual void OnCausesValidationChanged(EventArgs e) {
3420 if (CausesValidationChanged!=null) CausesValidationChanged(this, e);
3423 [EditorBrowsable(EditorBrowsableState.Advanced)]
3424 protected virtual void OnChangeUICues(UICuesEventArgs e) {
3425 if (ChangeUICues!=null) ChangeUICues(this, e);
3428 [EditorBrowsable(EditorBrowsableState.Advanced)]
3429 protected virtual void OnClick(EventArgs e) {
3430 if (Click!=null) Click(this, e);
3433 [EditorBrowsable(EditorBrowsableState.Advanced)]
3434 protected virtual void OnContextMenuChanged(EventArgs e) {
3435 if (ContextMenuChanged!=null) ContextMenuChanged(this, e);
3438 [EditorBrowsable(EditorBrowsableState.Advanced)]
3439 protected virtual void OnControlAdded(ControlEventArgs e) {
3440 if (ControlAdded!=null) ControlAdded(this, e);
3443 [EditorBrowsable(EditorBrowsableState.Advanced)]
3444 protected virtual void OnControlRemoved(ControlEventArgs e) {
3445 if (ControlRemoved!=null) ControlRemoved(this, e);
3448 [EditorBrowsable(EditorBrowsableState.Advanced)]
3449 protected virtual void OnCreateControl() {
3453 [EditorBrowsable(EditorBrowsableState.Advanced)]
3454 protected virtual void OnCursorChanged(EventArgs e) {
3455 if (CursorChanged!=null) CursorChanged(this, e);
3458 [EditorBrowsable(EditorBrowsableState.Advanced)]
3459 protected virtual void OnDockChanged(EventArgs e) {
3460 if (DockChanged!=null) DockChanged(this, e);
3463 [EditorBrowsable(EditorBrowsableState.Advanced)]
3464 protected virtual void OnDoubleClick(EventArgs e) {
3465 if (DoubleClick!=null) DoubleClick(this, e);
3468 [EditorBrowsable(EditorBrowsableState.Advanced)]
3469 protected virtual void OnDragDrop(DragEventArgs drgevent) {
3470 if (DragDrop!=null) DragDrop(this, drgevent);
3473 [EditorBrowsable(EditorBrowsableState.Advanced)]
3474 protected virtual void OnDragEnter(DragEventArgs drgevent) {
3475 if (DragEnter!=null) DragEnter(this, drgevent);
3478 [EditorBrowsable(EditorBrowsableState.Advanced)]
3479 protected virtual void OnDragLeave(EventArgs e) {
3480 if (DragLeave!=null) DragLeave(this, e);
3483 [EditorBrowsable(EditorBrowsableState.Advanced)]
3484 protected virtual void OnDragOver(DragEventArgs drgevent) {
3485 if (DragOver!=null) DragOver(this, drgevent);
3488 [EditorBrowsable(EditorBrowsableState.Advanced)]
3489 protected virtual void OnEnabledChanged(EventArgs e) {
3490 if (EnabledChanged!=null) EnabledChanged(this, e);
3491 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentEnabledChanged(e);
3494 [EditorBrowsable(EditorBrowsableState.Advanced)]
3495 protected virtual void OnEnter(EventArgs e) {
3496 if (Enter!=null) Enter(this, e);
3499 [EditorBrowsable(EditorBrowsableState.Advanced)]
3500 protected virtual void OnFontChanged(EventArgs e) {
3501 if (FontChanged!=null) FontChanged(this, e);
3502 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentFontChanged(e);
3505 [EditorBrowsable(EditorBrowsableState.Advanced)]
3506 protected virtual void OnForeColorChanged(EventArgs e) {
3507 if (ForeColorChanged!=null) ForeColorChanged(this, e);
3508 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentForeColorChanged(e);
3511 [EditorBrowsable(EditorBrowsableState.Advanced)]
3512 protected virtual void OnGiveFeedback(GiveFeedbackEventArgs gfbevent) {
3513 if (GiveFeedback!=null) GiveFeedback(this, gfbevent);
3516 [EditorBrowsable(EditorBrowsableState.Advanced)]
3517 protected virtual void OnGotFocus(EventArgs e) {
3518 if (GotFocus!=null) GotFocus(this, e);
3521 [EditorBrowsable(EditorBrowsableState.Advanced)]
3522 protected virtual void OnHandleCreated(EventArgs e) {
3523 if (HandleCreated!=null) HandleCreated(this, e);
3526 [EditorBrowsable(EditorBrowsableState.Advanced)]
3527 protected virtual void OnHandleDestroyed(EventArgs e) {
3528 if (HandleDestroyed!=null) HandleDestroyed(this, e);
3531 [EditorBrowsable(EditorBrowsableState.Advanced)]
3532 protected virtual void OnHelpRequested(HelpEventArgs hevent) {
3533 if (HelpRequested!=null) HelpRequested(this, hevent);
3536 protected virtual void OnImeModeChanged(EventArgs e) {
3537 if (ImeModeChanged!=null) ImeModeChanged(this, e);
3540 [EditorBrowsable(EditorBrowsableState.Advanced)]
3541 protected virtual void OnInvalidated(InvalidateEventArgs e) {
3542 if (Invalidated!=null) Invalidated(this, e);
3545 [EditorBrowsable(EditorBrowsableState.Advanced)]
3546 protected virtual void OnKeyDown(KeyEventArgs e) {
3547 if (KeyDown!=null) KeyDown(this, e);
3550 [EditorBrowsable(EditorBrowsableState.Advanced)]
3551 protected virtual void OnKeyPress(KeyPressEventArgs e) {
3552 if (KeyPress!=null) KeyPress(this, e);
3555 [EditorBrowsable(EditorBrowsableState.Advanced)]
3556 protected virtual void OnKeyUp(KeyEventArgs e) {
3557 if (KeyUp!=null) KeyUp(this, e);
3560 [EditorBrowsable(EditorBrowsableState.Advanced)]
3561 protected virtual void OnLayout(LayoutEventArgs levent) {
3562 if (Layout!=null) Layout(this, levent);
3565 [EditorBrowsable(EditorBrowsableState.Advanced)]
3566 protected virtual void OnLeave(EventArgs e) {
3567 if (Leave!=null) Leave(this, e);
3570 [EditorBrowsable(EditorBrowsableState.Advanced)]
3571 protected virtual void OnLocationChanged(EventArgs e) {
3573 if (LocationChanged!=null) LocationChanged(this, e);
3576 [EditorBrowsable(EditorBrowsableState.Advanced)]
3577 protected virtual void OnLostFocus(EventArgs e) {
3578 if (LostFocus!=null) LostFocus(this, e);
3581 [EditorBrowsable(EditorBrowsableState.Advanced)]
3582 protected virtual void OnMouseDown(MouseEventArgs e) {
3583 if (MouseDown!=null) MouseDown(this, e);
3586 [EditorBrowsable(EditorBrowsableState.Advanced)]
3587 protected virtual void OnMouseEnter(EventArgs e) {
3588 if (MouseEnter!=null) MouseEnter(this, e);
3591 [EditorBrowsable(EditorBrowsableState.Advanced)]
3592 protected virtual void OnMouseHover(EventArgs e) {
3593 if (MouseHover!=null) MouseHover(this, e);
3596 [EditorBrowsable(EditorBrowsableState.Advanced)]
3597 protected virtual void OnMouseLeave(EventArgs e) {
3598 if (MouseLeave!=null) MouseLeave(this, e);
3601 [EditorBrowsable(EditorBrowsableState.Advanced)]
3602 protected virtual void OnMouseMove(MouseEventArgs e) {
3603 if (MouseMove!=null) MouseMove(this, e);
3606 [EditorBrowsable(EditorBrowsableState.Advanced)]
3607 protected virtual void OnMouseUp(MouseEventArgs e) {
3608 if (MouseUp!=null) MouseUp(this, e);
3611 [EditorBrowsable(EditorBrowsableState.Advanced)]
3612 protected virtual void OnMouseWheel(MouseEventArgs e) {
3613 if (MouseWheel!=null) MouseWheel(this, e);
3616 [EditorBrowsable(EditorBrowsableState.Advanced)]
3617 protected virtual void OnMove(EventArgs e) {
3618 if (Move!=null) Move(this, e);
3621 [EditorBrowsable(EditorBrowsableState.Advanced)]
3622 protected virtual void OnNotifyMessage(Message m) {
3626 [EditorBrowsable(EditorBrowsableState.Advanced)]
3627 protected virtual void OnPaint(PaintEventArgs e) {
3628 if (Paint!=null) Paint(this, e);
3631 [EditorBrowsable(EditorBrowsableState.Advanced)]
3632 protected virtual void OnPaintBackground(PaintEventArgs pevent) {
3636 [EditorBrowsable(EditorBrowsableState.Advanced)]
3637 protected virtual void OnParentBackColorChanged(EventArgs e) {
3638 if (background_color.IsEmpty && background_image==null) {
3640 OnBackColorChanged(e);
3644 [EditorBrowsable(EditorBrowsableState.Advanced)]
3645 protected virtual void OnParentBackgroundImageChanged(EventArgs e) {
3646 if (background_color.IsEmpty && background_image==null) {
3648 OnBackgroundImageChanged(e);
3652 [EditorBrowsable(EditorBrowsableState.Advanced)]
3653 protected virtual void OnParentBindingContextChanged(EventArgs e) {
3654 if (binding_context==null) {
3655 binding_context=Parent.binding_context;
3656 OnBindingContextChanged(e);
3660 [EditorBrowsable(EditorBrowsableState.Advanced)]
3661 protected virtual void OnParentChanged(EventArgs e) {
3662 if (ParentChanged!=null) ParentChanged(this, e);
3665 [EditorBrowsable(EditorBrowsableState.Advanced)]
3666 protected virtual void OnParentEnabledChanged(EventArgs e) {
3667 if (is_enabled != Parent.is_enabled) {
3668 is_enabled=Parent.is_enabled;
3670 if (EnabledChanged != null) {
3671 EnabledChanged(this, e);
3676 [EditorBrowsable(EditorBrowsableState.Advanced)]
3677 protected virtual void OnParentFontChanged(EventArgs e) {
3684 [EditorBrowsable(EditorBrowsableState.Advanced)]
3685 protected virtual void OnParentForeColorChanged(EventArgs e) {
3686 if (foreground_color.IsEmpty) {
3688 OnForeColorChanged(e);
3692 [EditorBrowsable(EditorBrowsableState.Advanced)]
3693 protected virtual void OnParentRightToLeftChanged(EventArgs e) {
3694 if (right_to_left==RightToLeft.Inherit) {
3696 OnRightToLeftChanged(e);
3700 [EditorBrowsable(EditorBrowsableState.Advanced)]
3701 protected virtual void OnParentVisibleChanged(EventArgs e) {
3702 if (is_visible!=Parent.is_visible) {
3705 OnVisibleChanged(e);
3709 [EditorBrowsable(EditorBrowsableState.Advanced)]
3710 protected virtual void OnQueryContinueDrag(QueryContinueDragEventArgs e) {
3711 if (QueryContinueDrag!=null) QueryContinueDrag(this, e);
3714 [EditorBrowsable(EditorBrowsableState.Advanced)]
3715 protected virtual void OnResize(EventArgs e) {
3716 if (Resize!=null) Resize(this, e);
3718 PerformLayout(this, "bounds");
3720 if (parent != null) {
3721 parent.PerformLayout();
3725 [EditorBrowsable(EditorBrowsableState.Advanced)]
3726 protected virtual void OnRightToLeftChanged(EventArgs e) {
3727 if (RightToLeftChanged!=null) RightToLeftChanged(this, e);
3728 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentRightToLeftChanged(e);
3731 [EditorBrowsable(EditorBrowsableState.Advanced)]
3732 protected virtual void OnSizeChanged(EventArgs e) {
3733 InvalidateBuffers ();
3735 if (SizeChanged!=null) SizeChanged(this, e);
3738 [EditorBrowsable(EditorBrowsableState.Advanced)]
3739 protected virtual void OnStyleChanged(EventArgs e) {
3740 if (StyleChanged!=null) StyleChanged(this, e);
3743 [EditorBrowsable(EditorBrowsableState.Advanced)]
3744 protected virtual void OnSystemColorsChanged(EventArgs e) {
3745 if (SystemColorsChanged!=null) SystemColorsChanged(this, e);
3748 [EditorBrowsable(EditorBrowsableState.Advanced)]
3749 protected virtual void OnTabIndexChanged(EventArgs e) {
3750 if (TabIndexChanged!=null) TabIndexChanged(this, e);
3753 [EditorBrowsable(EditorBrowsableState.Advanced)]
3754 protected virtual void OnTabStopChanged(EventArgs e) {
3755 if (TabStopChanged!=null) TabStopChanged(this, e);
3758 [EditorBrowsable(EditorBrowsableState.Advanced)]
3759 protected virtual void OnTextChanged(EventArgs e) {
3760 if (TextChanged!=null) TextChanged(this, e);
3763 [EditorBrowsable(EditorBrowsableState.Advanced)]
3764 protected virtual void OnValidated(EventArgs e) {
3765 if (Validated!=null) Validated(this, e);
3768 [EditorBrowsable(EditorBrowsableState.Advanced)]
3769 protected virtual void OnValidating(System.ComponentModel.CancelEventArgs e) {
3770 if (Validating!=null) Validating(this, e);
3773 [EditorBrowsable(EditorBrowsableState.Advanced)]
3774 protected virtual void OnVisibleChanged(EventArgs e) {
3781 if (bmp_mem!=null) {
3787 if (!this.IsHandleCreated) {
3788 this.CreateHandle();
3794 if (VisibleChanged!=null) VisibleChanged(this, e);
3796 // We need to tell our kids
3797 for (int i=0; i<child_controls.Count; i++) {
3798 child_controls[i].OnParentVisibleChanged(e);
3801 #endregion // OnXXX methods
3804 public event EventHandler BackColorChanged;
3805 public event EventHandler BackgroundImageChanged;
3806 public event EventHandler BindingContextChanged;
3807 public event EventHandler CausesValidationChanged;
3808 public event UICuesEventHandler ChangeUICues;
3809 public event EventHandler Click;
3810 public event EventHandler ContextMenuChanged;
3812 [EditorBrowsable(EditorBrowsableState.Advanced)]
3814 public event ControlEventHandler ControlAdded;
3816 [EditorBrowsable(EditorBrowsableState.Advanced)]
3818 public event ControlEventHandler ControlRemoved;
3820 public event EventHandler CursorChanged;
3821 public event EventHandler DockChanged;
3822 public event EventHandler DoubleClick;
3823 public event DragEventHandler DragDrop;
3824 public event DragEventHandler DragEnter;
3825 public event EventHandler DragLeave;
3826 public event DragEventHandler DragOver;
3827 public event EventHandler EnabledChanged;
3828 public event EventHandler Enter;
3829 public event EventHandler FontChanged;
3830 public event EventHandler ForeColorChanged;
3831 public event GiveFeedbackEventHandler GiveFeedback;
3833 [EditorBrowsable(EditorBrowsableState.Advanced)]
3835 public event EventHandler GotFocus;
3837 [EditorBrowsable(EditorBrowsableState.Advanced)]
3839 public event EventHandler HandleCreated;
3841 [EditorBrowsable(EditorBrowsableState.Advanced)]
3843 public event EventHandler HandleDestroyed;
3845 public event HelpEventHandler HelpRequested;
3846 public event EventHandler ImeModeChanged;
3848 [EditorBrowsable(EditorBrowsableState.Advanced)]
3850 public event InvalidateEventHandler Invalidated;
3852 public event KeyEventHandler KeyDown;
3853 public event KeyPressEventHandler KeyPress;
3854 public event KeyEventHandler KeyUp;
3855 public event LayoutEventHandler Layout;
3856 public event EventHandler Leave;
3857 public event EventHandler LocationChanged;
3859 [EditorBrowsable(EditorBrowsableState.Advanced)]
3861 public event EventHandler LostFocus;
3863 public event MouseEventHandler MouseDown;
3864 public event EventHandler MouseEnter;
3865 public event EventHandler MouseHover;
3866 public event EventHandler MouseLeave;
3867 public event MouseEventHandler MouseMove;
3868 public event MouseEventHandler MouseUp;
3870 [EditorBrowsable(EditorBrowsableState.Advanced)]
3872 public event MouseEventHandler MouseWheel;
3874 public event EventHandler Move;
3875 public event PaintEventHandler Paint;
3876 public event EventHandler ParentChanged;
3877 public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp;
3878 public event QueryContinueDragEventHandler QueryContinueDrag;
3879 public event EventHandler Resize;
3880 public event EventHandler RightToLeftChanged;
3881 public event EventHandler SizeChanged;
3882 public event EventHandler StyleChanged;
3883 public event EventHandler SystemColorsChanged;
3884 public event EventHandler TabIndexChanged;
3885 public event EventHandler TabStopChanged;
3886 public event EventHandler TextChanged;
3887 public event EventHandler Validated;
3888 public event CancelEventHandler Validating;
3889 public event EventHandler VisibleChanged;
3890 #endregion // Events