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 application's 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 controls.Remove(this);
606 #endregion // Public Constructors
608 #region Internal Properties
609 internal BorderStyle InternalBorderStyle {
615 if (border_style != value) {
616 border_style = value;
618 XplatUI.SetBorderStyle(window.Handle, border_style);
622 #endregion // Internal Properties
624 #region Private & Internal Methods
625 internal static IAsyncResult BeginInvokeInternal (Delegate method, object [] args) {
626 AsyncMethodResult result = new AsyncMethodResult ();
627 AsyncMethodData data = new AsyncMethodData ();
629 data.Method = method;
631 data.Result = new WeakReference (result);
633 XplatUI.SendAsyncMethod (data);
637 internal Graphics DeviceContext {
640 CreateBuffers(this.Width, this.Height);
646 internal Bitmap ImageBuffer {
649 CreateBuffers(this.Width, this.Height);
655 internal void CreateBuffers (int width, int height) {
656 if (double_buffering == false)
659 if (dc_mem != null) {
673 bmp_mem = new Bitmap (width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
674 dc_mem = Graphics.FromImage (bmp_mem);
677 internal void InvalidateBuffers ()
679 if (double_buffering == false)
682 if (dc_mem != null) {
692 internal static void SetChildColor(Control parent) {
695 for (int i=0; i < parent.child_controls.Count; i++) {
696 child=parent.child_controls[i];
697 if (child.IsHandleCreated) {
698 XplatUI.SetWindowBackground(child.window.Handle, child.BackColor);
700 if (child.child_controls.Count>0) {
701 SetChildColor(child);
707 internal bool Select(Control control) {
709 IContainerControl container;
711 if (control == null) {
715 parent = control.parent;
717 if (((control.control_style & ControlStyles.Selectable) !=0) && (parent != null)) {
718 while (parent != null) {
719 if (!parent.is_visible || !parent.is_enabled) {
722 parent = parent.parent;
726 control.is_selected = true;
728 XplatUI.SetFocus(control.window.Handle);
729 container = GetContainerControl();
730 if (container != null) {
731 container.ActiveControl = control;
736 internal virtual void DoDefaultAction() {
737 // Only here to be overriden by our actual controls; this is needed by the accessibility class
740 internal static int LowOrder (int param) {
741 return (param & 0xffff);
744 internal static int HighOrder (int param) {
745 return (param >> 16);
748 internal static MouseButtons FromParamToMouseButtons (int param) {
749 MouseButtons buttons = MouseButtons.None;
751 if ((param & (int) MsgButtons.MK_LBUTTON) != 0)
752 buttons |= MouseButtons.Left;
754 if ((param & (int) MsgButtons.MK_MBUTTON) != 0)
755 buttons |= MouseButtons.Middle;
757 if ((param & (int) MsgButtons.MK_RBUTTON) != 0)
758 buttons |= MouseButtons.Right;
764 internal virtual bool ProcessControlMnemonic(char charCode) {
765 return ProcessMnemonic(charCode);
768 private static Control FindFlatForward(Control container, Control start) {
774 end = container.child_controls.Count;
777 index = start.tab_index;
782 for (int i = 0; i < end; i++) {
784 if (container.child_controls[i].tab_index > index) {
785 found = container.child_controls[i];
787 } else if (found.tab_index > container.child_controls[i].tab_index) {
788 if (container.child_controls[i].tab_index > index) {
789 found = container.child_controls[i];
796 private static Control FindControlForward(Control container, Control start) {
803 if ((start is IContainerControl) || start.GetStyle(ControlStyles.ContainerControl)) {
804 found = FindControlForward(start, null);
811 while (p != container) {
812 found = FindFlatForward(p, start);
820 return FindFlatForward(container, start);
823 private static Control FindFlatBackward(Control container, Control start) {
829 end = container.child_controls.Count;
832 index = start.tab_index;
834 // FIXME: Possible speed-up: Keep the highest taborder index in the container
836 for (int i = 0; i < end; i++) {
837 if (container.child_controls[i].tab_index > index) {
838 index = container.child_controls[i].tab_index;
844 for (int i = 0; i < end; i++) {
846 if (container.child_controls[i].tab_index < index) {
847 found = container.child_controls[i];
849 } else if (found.tab_index < container.child_controls[i].tab_index) {
850 if (container.child_controls[i].tab_index < index) {
851 found = container.child_controls[i];
858 private static Control FindControlBackward(Control container, Control start) {
864 found = FindFlatBackward(start.parent, start);
865 if (found == null && start.parent != container) {
870 found = FindFlatBackward(container, start);
873 while ((found != null) && ((found is IContainerControl) || found.GetStyle(ControlStyles.ContainerControl))) {
874 found = FindControlBackward(found, null);
883 private void HandleClick(int clicks) {
884 if (GetStyle(ControlStyles.StandardClick)) {
886 if (GetStyle(ControlStyles.StandardDoubleClick)) {
887 OnDoubleClick(EventArgs.Empty);
889 OnClick(EventArgs.Empty);
892 OnClick(EventArgs.Empty);
897 private void CheckDataBindings ()
899 if (data_bindings == null)
902 BindingContext binding_context = BindingContext;
903 foreach (Binding binding in data_bindings) {
904 binding.Check (binding_context);
908 #endregion // Private & Internal Methods
910 #region Public Static Properties
911 public static Color DefaultBackColor {
913 return ThemeEngine.Current.DefaultControlBackColor;
917 public static Font DefaultFont {
919 return ThemeEngine.Current.DefaultFont;
923 public static Color DefaultForeColor {
925 return ThemeEngine.Current.DefaultControlForeColor;
929 public static Keys ModifierKeys {
931 return XplatUI.State.ModifierKeys;
935 public static MouseButtons MouseButtons {
937 return XplatUI.State.MouseButtons;
941 public static Point MousePosition {
943 return Cursor.Position;
946 #endregion // Public Static Properties
948 #region Public Instance Properties
949 [EditorBrowsable(EditorBrowsableState.Advanced)]
951 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
952 public AccessibleObject AccessibilityObject {
954 if (accessibility_object==null) {
955 accessibility_object=CreateAccessibilityInstance();
957 return accessibility_object;
961 [EditorBrowsable(EditorBrowsableState.Advanced)]
963 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
964 public string AccessibleDefaultActionDescription {
966 return AccessibilityObject.default_action;
970 AccessibilityObject.default_action=value;
976 public string AccessibleDescription {
978 return AccessibilityObject.description;
982 AccessibilityObject.description=value;
988 public string AccessibleName {
990 return AccessibilityObject.Name;
994 AccessibilityObject.Name=value;
998 [DefaultValue(AccessibleRole.Default)]
999 public AccessibleRole AccessibleRole {
1001 return AccessibilityObject.role;
1005 AccessibilityObject.role=value;
1009 [DefaultValue(false)]
1010 public virtual bool AllowDrop {
1012 return XplatUI.State.DropTarget;
1016 XplatUI.State.DropTarget=value;
1021 [RefreshProperties(RefreshProperties.Repaint)]
1022 [DefaultValue(AnchorStyles.Top | AnchorStyles.Left)]
1023 public virtual AnchorStyles Anchor {
1025 return anchor_style;
1031 if (parent != null) {
1032 parent.PerformLayout(this, "Parent");
1038 public virtual Color BackColor {
1040 if (background_color.IsEmpty) {
1042 return parent.BackColor;
1044 return DefaultBackColor;
1046 return background_color;
1050 background_color=value;
1051 if (this.IsHandleCreated) {
1052 XplatUI.SetWindowBackground(this.window.Handle, value);
1054 SetChildColor(this);
1055 OnBackColorChanged(EventArgs.Empty);
1061 [DefaultValue(null)]
1062 public virtual Image BackgroundImage {
1064 return background_image;
1068 if (background_image!=value) {
1069 background_image=value;
1070 OnBackgroundImageChanged(EventArgs.Empty);
1075 [EditorBrowsable(EditorBrowsableState.Advanced)]
1077 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1078 public virtual BindingContext BindingContext {
1080 if (binding_context != null)
1081 return binding_context;
1084 binding_context = Parent.BindingContext;
1085 return binding_context;
1088 if (binding_context != value) {
1089 binding_context = value;
1090 OnBindingContextChanged(EventArgs.Empty);
1095 [EditorBrowsable(EditorBrowsableState.Advanced)]
1097 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1100 return bounds.Y+bounds.Height;
1104 [EditorBrowsable(EditorBrowsableState.Advanced)]
1106 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1107 public Rectangle Bounds {
1113 SetBoundsCore(value.Left, value.Top, value.Width, value.Height, BoundsSpecified.All);
1117 [EditorBrowsable(EditorBrowsableState.Advanced)]
1119 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1120 public bool CanFocus {
1122 if (is_visible && is_enabled && GetStyle(ControlStyles.Selectable)) {
1129 [EditorBrowsable(EditorBrowsableState.Advanced)]
1131 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1132 public bool CanSelect {
1136 if (!GetStyle(ControlStyles.Selectable) || this.parent == null) {
1140 parent = this.parent;
1141 while (parent != null) {
1142 if (!parent.is_visible || !parent.is_enabled) {
1146 parent = parent.parent;
1152 [EditorBrowsable(EditorBrowsableState.Advanced)]
1154 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1155 public bool Capture {
1157 return this.is_captured;
1161 if (this.IsHandleCreated) {
1162 if (value && !is_captured) {
1164 XplatUI.GrabWindow(this.window.Handle, IntPtr.Zero);
1165 } else if (!value && is_captured) {
1166 XplatUI.UngrabWindow(this.window.Handle);
1167 is_captured = false;
1173 [DefaultValue(true)]
1174 public bool CausesValidation {
1176 return this.causes_validation;
1180 if (this.causes_validation != value) {
1181 causes_validation = value;
1182 OnCausesValidationChanged(EventArgs.Empty);
1187 [EditorBrowsable(EditorBrowsableState.Advanced)]
1189 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1190 public Rectangle ClientRectangle {
1192 client_rect.Width = client_size.Width;
1193 client_rect.Height = client_size.Height;
1198 [EditorBrowsable(EditorBrowsableState.Advanced)]
1200 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1201 public Size ClientSize {
1204 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1205 return ((Form)this).form_parent_window.ClientSize;
1213 this.SetClientSizeCore(value.Width, value.Height);
1217 [EditorBrowsable(EditorBrowsableState.Advanced)]
1219 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1220 [DescriptionAttribute("ControlCompanyNameDescr")]
1221 public String CompanyName {
1223 return "Mono Project, Novell, Inc.";
1227 [EditorBrowsable(EditorBrowsableState.Advanced)]
1229 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1230 public bool ContainsFocus {
1236 for (int i=0; i < child_controls.Count; i++) {
1237 if (child_controls[i].ContainsFocus) {
1245 [DefaultValue(null)]
1246 public virtual ContextMenu ContextMenu {
1248 return context_menu;
1252 if (context_menu != value) {
1253 context_menu = value;
1254 OnContextMenuChanged(EventArgs.Empty);
1260 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
1261 public ControlCollection Controls {
1263 return this.child_controls;
1267 [EditorBrowsable(EditorBrowsableState.Advanced)]
1269 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1270 public bool Created {
1272 if (!this.is_disposed && (this.window.Handle != IntPtr.Zero)) {
1279 [AmbientValue(null)]
1280 public virtual Cursor Cursor {
1282 if (cursor != null) {
1286 if (parent != null) {
1287 return parent.Cursor;
1290 return Cursors.Default;
1294 if (cursor != value) {
1299 pt = Cursor.Position;
1300 if (bounds.Contains(pt)) {
1301 if (GetChildAtPoint(pt) == null) {
1302 if (cursor != null) {
1303 XplatUI.SetCursor(window.Handle, cursor.handle);
1305 if (parent != null) {
1306 XplatUI.SetCursor(window.Handle, parent.Cursor.handle);
1308 XplatUI.SetCursor(window.Handle, Cursors.def.handle);
1314 OnCursorChanged(EventArgs.Empty);
1320 [EditorBrowsable(EditorBrowsableState.Advanced)]
1322 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1323 public ControlBindingsCollection DataBindings {
1325 if (data_bindings == null)
1326 data_bindings = new ControlBindingsCollection (this);
1327 return data_bindings;
1331 [EditorBrowsable(EditorBrowsableState.Advanced)]
1333 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1334 public virtual Rectangle DisplayRectangle {
1336 return ClientRectangle;
1340 [EditorBrowsable(EditorBrowsableState.Advanced)]
1342 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1343 public bool Disposing {
1350 [RefreshProperties(RefreshProperties.Repaint)]
1351 [DefaultValue(DockStyle.None)]
1352 public virtual DockStyle Dock {
1358 if (dock_style == value) {
1364 if (parent != null) {
1365 parent.PerformLayout(this, "Parent");
1368 OnDockChanged(EventArgs.Empty);
1374 public bool Enabled {
1380 if (is_enabled == value) {
1386 OnEnabledChanged (EventArgs.Empty);
1390 [EditorBrowsable(EditorBrowsableState.Advanced)]
1392 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1393 public virtual bool Focused {
1395 return this.has_focus;
1400 [AmbientValue(null)]
1402 public virtual Font Font {
1408 if (Parent != null && Parent.Font != null) {
1416 if (font == value) {
1422 OnFontChanged (EventArgs.Empty);
1427 public virtual Color ForeColor {
1429 if (foreground_color.IsEmpty) {
1431 return parent.ForeColor;
1433 return DefaultForeColor;
1435 return foreground_color;
1439 if (foreground_color != value) {
1440 foreground_color=value;
1442 OnForeColorChanged(EventArgs.Empty);
1449 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1450 public IntPtr Handle { // IWin32Window
1452 if (!IsHandleCreated) {
1455 return window.Handle;
1459 [EditorBrowsable(EditorBrowsableState.Advanced)]
1461 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1462 public bool HasChildren {
1464 if (this.child_controls.Count>0) {
1471 [EditorBrowsable(EditorBrowsableState.Always)]
1473 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1476 return this.bounds.Height;
1480 SetBoundsCore(bounds.X, bounds.Y, bounds.Width, value, BoundsSpecified.Height);
1484 [AmbientValue(ImeMode.Inherit)]
1486 public ImeMode ImeMode {
1492 if (ime_mode != value) {
1495 OnImeModeChanged(EventArgs.Empty);
1500 [EditorBrowsable(EditorBrowsableState.Advanced)]
1502 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1503 public bool InvokeRequired { // ISynchronizeInvoke
1505 if (creator_thread!=Thread.CurrentThread) {
1512 [EditorBrowsable(EditorBrowsableState.Advanced)]
1514 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1515 public bool IsAccessible {
1517 return is_accessible;
1521 is_accessible = value;
1525 [EditorBrowsable(EditorBrowsableState.Advanced)]
1527 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1528 public bool IsDisposed {
1530 return this.is_disposed;
1534 [EditorBrowsable(EditorBrowsableState.Advanced)]
1536 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1537 public bool IsHandleCreated {
1539 if ((window!=null) && (window.Handle!=IntPtr.Zero)) {
1547 [EditorBrowsable(EditorBrowsableState.Always)]
1549 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1552 return this.bounds.X;
1556 SetBoundsCore(value, bounds.Y, bounds.Width, bounds.Height, BoundsSpecified.X);
1561 public Point Location {
1563 return new Point(bounds.X, bounds.Y);
1567 SetBoundsCore(value.X, value.Y, bounds.Width, bounds.Height, BoundsSpecified.Location);
1572 public string Name {
1583 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1584 public Control Parent {
1590 if (value == this) {
1591 throw new ArgumentException("A circular control reference has been made. A control cannot be owned or parented to itself.");
1594 if (parent!=value) {
1596 parent.Controls.Remove(this);
1601 if (!parent.Controls.Contains(this)) {
1602 parent.Controls.Add(this);
1605 XplatUI.SetParent(Handle, value.Handle);
1609 OnParentChanged(EventArgs.Empty);
1614 [EditorBrowsable(EditorBrowsableState.Advanced)]
1616 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1617 public string ProductName {
1619 return "Novell Mono MWF";
1623 [EditorBrowsable(EditorBrowsableState.Advanced)]
1625 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1626 public string ProductVersion {
1628 return "1.1.4322.573";
1632 [EditorBrowsable(EditorBrowsableState.Advanced)]
1634 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1635 public bool RecreatingHandle {
1637 return is_recreating;
1641 [EditorBrowsable(EditorBrowsableState.Advanced)]
1643 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1644 public Region Region {
1646 return new Region(this.bounds);
1653 g = this.CreateGraphics();
1654 r = value.GetBounds(g);
1656 SetBounds((int)r.X, (int)r.Y, (int)r.Width, (int)r.Height);
1662 [EditorBrowsable(EditorBrowsableState.Advanced)]
1664 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1667 return this.bounds.X+this.bounds.Width;
1671 [AmbientValue(RightToLeft.Inherit)]
1673 public virtual RightToLeft RightToLeft {
1675 return right_to_left;
1679 if (value != right_to_left) {
1680 right_to_left = value;
1681 OnRightToLeftChanged(EventArgs.Empty);
1686 [EditorBrowsable(EditorBrowsableState.Advanced)]
1687 public override ISite Site {
1700 return new Size(Width, Height);
1704 SetBoundsCore(bounds.X, bounds.Y, value.Width, value.Height, BoundsSpecified.Size);
1709 [MergableProperty(false)]
1710 public int TabIndex {
1712 if (tab_index != -1) {
1719 if (tab_index != value) {
1721 OnTabIndexChanged(EventArgs.Empty);
1727 [DefaultValue(true)]
1728 public bool TabStop {
1734 if (tab_stop != value) {
1736 OnTabStopChanged(EventArgs.Empty);
1741 [Localizable(false)]
1743 [TypeConverter(typeof(StringConverter))]
1744 [DefaultValue(null)]
1751 control_tag = value;
1757 [BindableAttribute(true)]
1758 public virtual string Text {
1764 if (value == null) {
1765 value = String.Empty;
1770 XplatUI.Text(Handle, text);
1771 // FIXME: Do we need a Refresh() here?
1772 OnTextChanged (EventArgs.Empty);
1777 [EditorBrowsable(EditorBrowsableState.Always)]
1779 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1782 return this.bounds.Y;
1786 SetBoundsCore(bounds.X, value, bounds.Width, bounds.Height, BoundsSpecified.Y);
1790 [EditorBrowsable(EditorBrowsableState.Advanced)]
1792 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1793 public Control TopLevelControl {
1797 while (p.parent != null) {
1806 public bool Visible {
1816 SetVisibleCore(value);
1820 [EditorBrowsable(EditorBrowsableState.Always)]
1822 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1825 return this.bounds.Width;
1829 SetBoundsCore(bounds.X, bounds.Y, value, bounds.Height, BoundsSpecified.Width);
1833 [EditorBrowsable(EditorBrowsableState.Never)]
1835 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1836 public IWindowTarget WindowTarget {
1845 #endregion // Public Instance Properties
1847 #region Protected Instance Properties
1848 protected virtual CreateParams CreateParams {
1850 CreateParams create_params = new CreateParams();
1852 create_params.Caption = Text;
1853 create_params.X = Left;
1854 create_params.Y = Top;
1855 create_params.Width = Width;
1856 create_params.Height = Height;
1858 create_params.ClassName = XplatUI.DefaultClassName;
1859 create_params.ClassStyle = 0;
1860 create_params.ExStyle = 0;
1861 create_params.Param = 0;
1864 create_params.Parent = parent.Handle;
1867 create_params.Style = (int)WindowStyles.WS_CHILD | (int)WindowStyles.WS_CLIPCHILDREN | (int)WindowStyles.WS_CLIPSIBLINGS;
1870 create_params.Style |= (int)WindowStyles.WS_VISIBLE;
1873 return create_params;
1877 protected virtual ImeMode DefaultImeMode {
1879 return ImeMode.Inherit;
1883 protected virtual Size DefaultSize {
1885 return new Size(100, 23);
1889 protected int FontHeight {
1899 protected bool RenderRightToLeft {
1901 return (this.right_to_left == RightToLeft.Yes);
1905 protected bool ResizeRedraw {
1907 return GetStyle(ControlStyles.ResizeRedraw);
1911 SetStyle(ControlStyles.ResizeRedraw, value);
1915 [EditorBrowsable(EditorBrowsableState.Advanced)]
1917 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1918 protected virtual bool ShowFocusCues {
1924 [EditorBrowsable(EditorBrowsableState.Advanced)]
1926 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1927 protected bool ShowKeyboardCues {
1932 #endregion // Protected Instance Properties
1934 #region Public Static Methods
1935 [EditorBrowsable(EditorBrowsableState.Advanced)]
1936 public static Control FromChildHandle(IntPtr handle) {
1937 IEnumerator control = Control.controls.GetEnumerator();
1939 while (control.MoveNext()) {
1940 if (((Control)control.Current).window.Handle == handle) {
1942 if (((Control)control.Current).Parent != null) {
1943 return ((Control)control.Current).Parent;
1950 [EditorBrowsable(EditorBrowsableState.Advanced)]
1951 public static Control FromHandle(IntPtr handle) {
1952 IEnumerator control = Control.controls.GetEnumerator();
1954 while (control.MoveNext()) {
1955 if (((Control)control.Current).window.Handle == handle) {
1957 return ((Control)control.Current);
1963 public static bool IsMnemonic(char charCode, string text) {
1966 amp = text.IndexOf('&');
1969 if (amp + 1 < text.Length) {
1970 if (text[amp + 1] != '&') {
1971 if (Char.ToUpper(charCode) == Char.ToUpper(text.ToCharArray(amp + 1, 1)[0])) {
1981 #region Protected Static Methods
1982 [EditorBrowsable(EditorBrowsableState.Advanced)]
1983 protected static bool ReflectMessage(IntPtr hWnd, ref Message m) {
1986 c = Control.FromHandle(hWnd);
1996 #region Public Instance Methods
1997 [EditorBrowsable(EditorBrowsableState.Advanced)]
1998 public IAsyncResult BeginInvoke(Delegate method) {
1999 return BeginInvokeInternal(method, null);
2002 [EditorBrowsable(EditorBrowsableState.Advanced)]
2003 public IAsyncResult BeginInvoke (Delegate method, object[] args) {
2004 return BeginInvokeInternal (method, args);
2007 public void BringToFront() {
2008 if ((parent != null) && (parent.child_controls[0]!=this)) {
2009 if (parent.child_controls.Contains(this)) {
2010 parent.child_controls.SetChildIndex(this, 0);
2014 XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, true, false);
2016 if (parent != null) {
2021 public bool Contains(Control ctl) {
2022 while (ctl != null) {
2031 public void CreateControl() {
2033 if (!IsHandleCreated)
2036 for (int i=0; i<child_controls.Count; i++) {
2037 child_controls[i].CreateControl();
2042 public Graphics CreateGraphics() {
2043 if (!IsHandleCreated) {
2044 this.CreateHandle();
2046 return Graphics.FromHwnd(this.window.Handle);
2049 [MonoTODO("Come up with cross platform drag-drop driver interface")]
2050 public DragDropEffects DoDragDrop(object data, DragDropEffects allowedEffects) {
2051 return DragDropEffects.None;
2054 [EditorBrowsable(EditorBrowsableState.Advanced)]
2055 public object EndInvoke (IAsyncResult async_result) {
2056 AsyncMethodResult result = (AsyncMethodResult) async_result;
2057 return result.EndInvoke ();
2060 public Form FindForm() {
2073 public bool Focus() {
2074 if (IsHandleCreated && !has_focus) {
2075 XplatUI.SetFocus(window.Handle);
2081 public Control GetChildAtPoint(Point pt) {
2082 // Microsoft's version of this function doesn't seem to work, so I can't check
2083 // if we only consider children or also grandchildren, etc.
2084 // I'm gonna say 'children only'
2085 for (int i=0; i<child_controls.Count; i++) {
2086 if (child_controls[i].Bounds.Contains(pt)) {
2087 return child_controls[i];
2093 public IContainerControl GetContainerControl() {
2094 Control current = this;
2096 while (current!=null) {
2097 if ((current is IContainerControl) && ((current.control_style & ControlStyles.ContainerControl)!=0)) {
2098 return (IContainerControl)current;
2100 current = current.parent;
2105 public Control GetNextControl(Control ctl, bool forward) {
2106 // If we're not a container we don't play
2107 if (!(this is IContainerControl) && !this.GetStyle(ControlStyles.ContainerControl)) {
2111 // If ctl is not contained by this, we start at the first child of this
2112 if (!this.Contains(ctl)) {
2116 // Search through our controls, starting at ctl, stepping into children as we encounter them
2117 // try to find the control with the tabindex closest to our own, or, if we're looking into
2118 // child controls, the one with the smallest tabindex
2120 return FindControlForward(this, ctl);
2122 return FindControlBackward(this, ctl);
2125 public void Hide() {
2126 this.Visible = false;
2129 public void Invalidate() {
2130 Invalidate(ClientRectangle, false);
2133 public void Invalidate(bool invalidateChildren) {
2134 Invalidate(ClientRectangle, invalidateChildren);
2137 public void Invalidate(System.Drawing.Rectangle rc) {
2138 Invalidate(rc, false);
2141 public void Invalidate(System.Drawing.Rectangle rc, bool invalidateChildren) {
2142 if (!IsHandleCreated || !Visible) {
2146 NotifyInvalidate(rc);
2148 XplatUI.Invalidate(Handle, rc, !GetStyle (ControlStyles.AllPaintingInWmPaint));
2150 if (invalidateChildren) {
2151 for (int i=0; i<child_controls.Count; i++) child_controls[i].Invalidate();
2153 OnInvalidated(new InvalidateEventArgs(rc));
2156 public void Invalidate(System.Drawing.Region region) {
2157 Invalidate(region, false);
2160 [MonoTODO("Figure out if GetRegionScans is usable")]
2161 public void Invalidate(System.Drawing.Region region, bool invalidateChildren) {
2162 throw new NotImplementedException();
2164 // FIXME - should use the GetRegionScans function of the region to invalidate each area
2165 //if (invalidateChildren) {
2166 // for (int i=0; i<child_controls.Count; i++) child_controls[i].Invalidate();
2170 public object Invoke (Delegate method) {
2171 return Invoke(method, null);
2174 public object Invoke (Delegate method, object[] args) {
2175 IAsyncResult result = BeginInvoke (method, args);
2176 return EndInvoke(result);
2179 [EditorBrowsable(EditorBrowsableState.Advanced)]
2180 public void PerformLayout() {
2181 PerformLayout(null, null);
2184 [EditorBrowsable(EditorBrowsableState.Advanced)]
2185 public void PerformLayout(Control affectedControl, string affectedProperty) {
2186 LayoutEventArgs levent = new LayoutEventArgs(affectedControl, affectedProperty);
2188 if (layout_suspended>0) {
2189 layout_pending = true;
2193 layout_pending = false;
2195 // Prevent us from getting messed up
2198 // Perform all Dock and Anchor calculations
2201 AnchorStyles anchor;
2206 space=this.DisplayRectangle;
2207 if (prev_size != Size.Empty) {
2208 diff_width = space.Width - prev_size.Width;
2209 diff_height = space.Height - prev_size.Height;
2215 // Deal with docking; go through in reverse, MS docs say that lowest Z-order is closest to edge
2216 for (int i = child_controls.Count - 1; i >= 0; i--) {
2217 child=child_controls[i];
2218 switch (child.Dock) {
2219 case DockStyle.None: {
2224 case DockStyle.Left: {
2225 child.SetBounds(space.Left, space.Y, child.Width, space.Height);
2226 space.X+=child.Width;
2227 space.Width-=child.Width;
2231 case DockStyle.Top: {
2232 child.SetBounds(space.Left, space.Y, space.Width, child.Height);
2233 space.Y+=child.Height;
2234 space.Height-=child.Height;
2238 case DockStyle.Right: {
2239 child.SetBounds(space.Right-child.Width, space.Y, child.Width, space.Height);
2240 space.Width-=child.Width;
2244 case DockStyle.Bottom: {
2245 child.SetBounds(space.Left, space.Bottom-child.Height, space.Width, child.Height);
2246 space.Height-=child.Height;
2252 for (int i = child_controls.Count - 1; i >= 0; i--) {
2253 child=child_controls[i];
2255 if (child.Dock == DockStyle.Fill) {
2256 child.SetBounds(space.Left, space.Top, space.Width, space.Height);
2262 space=this.DisplayRectangle;
2264 // Deal with anchoring
2265 for (int i=0; i < child_controls.Count; i++) {
2271 child=child_controls[i];
2272 anchor=child.Anchor;
2277 height=child.Height;
2279 // If the control is docked we don't need to do anything
2280 if (child.Dock != DockStyle.None) {
2284 if ((anchor & AnchorStyles.Left) !=0 ) {
2285 if ((anchor & AnchorStyles.Right) != 0) {
2286 // Anchoring to left and right
2287 width=width+diff_width;
2291 } else if ((anchor & AnchorStyles.Right) != 0) {
2297 if ((anchor & AnchorStyles.Top) !=0 ) {
2298 if ((anchor & AnchorStyles.Bottom) != 0) {
2299 height+=diff_height;
2303 } else if ((anchor & AnchorStyles.Bottom) != 0) {
2318 child.SetBounds(left, top, width, height);
2321 // Let everyone know
2325 // Need to make sure we decremend layout_suspended
2331 public Point PointToClient (Point p) {
2335 XplatUI.ScreenToClient (Handle, ref x, ref y);
2337 return new Point (x, y);
2340 public Point PointToScreen(Point p) {
2344 XplatUI.ClientToScreen(Handle, ref x, ref y);
2346 return new Point(x, y);
2349 public virtual bool PreProcessMessage(ref Message msg) {
2352 if ((msg.Msg == (int)Msg.WM_KEYDOWN) || (msg.Msg == (int)Msg.WM_SYSKEYDOWN)) {
2353 key_data = (Keys)msg.WParam.ToInt32();
2354 if (!ProcessCmdKey(ref msg, key_data)) {
2355 if (IsInputKey(key_data)) {
2359 return ProcessDialogKey(key_data);
2363 } else if (msg.Msg == (int)Msg.WM_CHAR) {
2364 if (IsInputChar((char)msg.WParam)) {
2367 } else if (msg.Msg == (int)Msg.WM_SYSCHAR) {
2368 if (IsInputChar((char)msg.WParam)) {
2371 return ProcessDialogChar((char)msg.WParam);
2376 public Rectangle RectangleToClient(Rectangle r) {
2377 return new Rectangle(PointToClient(r.Location), r.Size);
2380 public Rectangle RectangleToScreen(Rectangle r) {
2381 return new Rectangle(PointToScreen(r.Location), r.Size);
2384 public virtual void Refresh() {
2385 if (IsHandleCreated == true) {
2387 XplatUI.UpdateWindow(window.Handle);
2391 [EditorBrowsable(EditorBrowsableState.Never)]
2392 public virtual void ResetBackColor() {
2393 background_color = Color.Empty;
2396 #if haveDataBindings
2397 [EditorBrowsable(EditorBrowsableState.Never)]
2399 public void ResetBindings() {
2404 [EditorBrowsable(EditorBrowsableState.Never)]
2405 public virtual void ResetCursor() {
2409 [EditorBrowsable(EditorBrowsableState.Never)]
2410 public virtual void ResetFont() {
2414 [EditorBrowsable(EditorBrowsableState.Never)]
2415 public virtual void ResetForeColor() {
2416 foreground_color = Color.Empty;
2419 [EditorBrowsable(EditorBrowsableState.Never)]
2420 public void ResetImeMode() {
2421 ime_mode = DefaultImeMode;
2424 [EditorBrowsable(EditorBrowsableState.Never)]
2425 public virtual void ResetRightToLeft() {
2426 right_to_left = RightToLeft.Inherit;
2429 public virtual void ResetText() {
2433 public void ResumeLayout() {
2434 ResumeLayout (true);
2437 public void ResumeLayout(bool performLayout) {
2440 if (layout_suspended > 0) {
2444 if (performLayout || layout_pending) {
2449 public void Scale(float ratio) {
2450 ScaleCore(ratio, ratio);
2453 public void Scale(float dx, float dy) {
2457 public void Select() {
2458 Select(false, false);
2461 public bool SelectNextControl(Control ctl, bool forward, bool tabStopOnly, bool nested, bool wrap) {
2466 c = GetNextControl(c, forward);
2475 if (c.CanSelect && ((c.parent == ctl.parent) || nested) && (c.tab_stop || !tabStopOnly)) {
2479 } while (c != ctl); // If we wrap back to ourselves we stop
2484 public void SendToBack() {
2485 if ((parent != null) && (parent.child_controls[parent.child_controls.Count-1]!=this)) {
2486 if (parent.child_controls.Contains(this)) {
2487 parent.child_controls.SetChildIndex(this, parent.child_controls.Count);
2491 XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, false, true);
2492 if (parent != null) {
2497 public void SetBounds(int x, int y, int width, int height) {
2498 SetBoundsCore(x, y, width, height, BoundsSpecified.All);
2501 public void SetBounds(int x, int y, int width, int height, BoundsSpecified specified) {
2502 SetBoundsCore(x, y, width, height, specified);
2505 public void Show() {
2506 if (!IsHandleCreated) {
2507 this.CreateHandle();
2513 public void SuspendLayout() {
2517 public void Update() {
2518 XplatUI.UpdateWindow(window.Handle);
2520 #endregion // Public Instance Methods
2522 #region Protected Instance Methods
2523 [EditorBrowsable(EditorBrowsableState.Advanced)]
2524 [MonoTODO("Implement this and tie it into Control.ControlAccessibleObject.NotifyClients")]
2525 protected void AccessibilityNotifyClients(AccessibleEvents accEvent, int childID) {
2526 throw new NotImplementedException();
2529 [EditorBrowsable(EditorBrowsableState.Advanced)]
2530 protected virtual AccessibleObject CreateAccessibilityInstance() {
2531 return new Control.ControlAccessibleObject(this);
2534 [EditorBrowsable(EditorBrowsableState.Advanced)]
2535 protected virtual ControlCollection CreateControlsInstance() {
2536 return new ControlCollection(this);
2539 [EditorBrowsable(EditorBrowsableState.Advanced)]
2540 protected virtual void CreateHandle() {
2542 throw new ObjectDisposedException(Name);
2545 if (IsHandleCreated) {
2550 window = new ControlNativeWindow(this);
2551 window.CreateHandle(CreateParams);
2553 // Find out where the window manager placed us
2558 if (window.Handle!=IntPtr.Zero) {
2559 if (!controls.Contains(window.Handle)) {
2563 creator_thread = Thread.CurrentThread;
2565 XplatUI.SetWindowBackground(window.Handle, this.BackColor);
2567 OnHandleCreated(EventArgs.Empty);
2571 [EditorBrowsable(EditorBrowsableState.Advanced)]
2572 protected virtual void DefWndProc(ref Message m) {
2573 window.DefWndProc(ref m);
2576 [EditorBrowsable(EditorBrowsableState.Advanced)]
2577 protected virtual void DestroyHandle() {
2578 if (IsHandleCreated) {
2579 // Destroy our children before we destroy ourselves, to prevent them from
2580 // being implictly (without us knowing) destroyed
2581 for (int i=0; i < child_controls.Count; i++) {
2582 child_controls[i].DestroyHandle();
2586 if (window != null) {
2587 window.DestroyHandle();
2589 OnHandleDestroyed(EventArgs.Empty);
2593 protected bool GetStyle(ControlStyles flag) {
2594 return (control_style & flag) != 0;
2597 protected bool GetTopLevel() {
2601 [EditorBrowsable(EditorBrowsableState.Advanced)]
2602 protected virtual void InitLayout() {
2603 if (parent != null) {
2604 parent.PerformLayout(this, "parent");
2608 [EditorBrowsable(EditorBrowsableState.Advanced)]
2609 protected void InvokeGotFocus(Control toInvoke, EventArgs e) {
2610 toInvoke.OnGotFocus(e);
2613 [EditorBrowsable(EditorBrowsableState.Advanced)]
2614 protected void InvokeLostFocus(Control toInvoke, EventArgs e) {
2615 toInvoke.OnLostFocus(e);
2618 [EditorBrowsable(EditorBrowsableState.Advanced)]
2619 protected void InvokeOnClick(Control toInvoke, EventArgs e) {
2620 toInvoke.OnClick(e);
2623 protected void InvokePaint(Control toInvoke, PaintEventArgs e) {
2624 toInvoke.OnPaint(e);
2627 protected void InvokePaintBackground(Control toInvoke, PaintEventArgs e) {
2628 toInvoke.OnPaintBackground(e);
2631 protected virtual bool IsInputChar (char charCode) {
2632 if (parent != null) {
2633 return parent.IsInputChar(charCode);
2639 protected virtual bool IsInputKey (Keys keyData) {
2640 // Doc says this one calls IsInputChar; not sure what to do with that
2644 [EditorBrowsable(EditorBrowsableState.Advanced)]
2645 protected virtual void NotifyInvalidate(Rectangle invalidatedArea) {
2649 protected virtual bool ProcessCmdKey(ref Message msg, Keys keyData) {
2650 if ((context_menu != null) && context_menu.ProcessCmdKey(ref msg, keyData)) {
2654 if (parent != null) {
2655 return parent.ProcessCmdKey(ref msg, keyData);
2661 protected virtual bool ProcessDialogChar(char charCode) {
2662 if (parent != null) {
2663 return parent.ProcessDialogChar (charCode);
2669 protected virtual bool ProcessDialogKey (Keys keyData) {
2670 if (parent != null) {
2671 return parent.ProcessDialogKey (keyData);
2677 protected virtual bool ProcessKeyEventArgs (ref Message msg)
2679 KeyEventArgs key_event;
2682 case (int)Msg.WM_KEYDOWN: {
2683 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
2684 OnKeyDown (key_event);
2685 return key_event.Handled;
2687 case (int)Msg.WM_KEYUP: {
2688 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
2689 OnKeyUp (key_event);
2690 return key_event.Handled;
2693 case (int)Msg.WM_CHAR: {
2694 KeyPressEventArgs key_press_event;
2696 key_press_event = new KeyPressEventArgs((char)msg.WParam);
2697 OnKeyPress(key_press_event);
2698 return key_press_event.Handled;
2709 protected internal virtual bool ProcessKeyMessage(ref Message msg) {
2710 if (parent != null) {
2711 if (parent.ProcessKeyPreview(ref msg)) {
2719 protected virtual bool ProcessKeyPreview(ref Message msg) {
2720 if (parent != null) {
2721 return parent.ProcessKeyPreview(ref msg);
2727 protected virtual bool ProcessMnemonic(char charCode) {
2732 [EditorBrowsable(EditorBrowsableState.Advanced)]
2733 protected void RaiseDragEvent(object key, DragEventArgs e) {
2737 [EditorBrowsable(EditorBrowsableState.Advanced)]
2738 protected void RaiseKeyEvent(object key, KeyEventArgs e) {
2742 [EditorBrowsable(EditorBrowsableState.Advanced)]
2743 protected void RaiseMouseEvent(object key, MouseEventArgs e) {
2747 [EditorBrowsable(EditorBrowsableState.Advanced)]
2748 protected void RaisePaintEvent(object key, PaintEventArgs e) {
2752 [EditorBrowsable(EditorBrowsableState.Advanced)]
2753 protected void RecreateHandle() {
2754 IEnumerator child = child_controls.GetEnumerator();
2758 if (IsHandleCreated) {
2764 while (child.MoveNext()) {
2765 ((Control)child.Current).RecreateHandle();
2771 is_recreating = false;
2774 [EditorBrowsable(EditorBrowsableState.Advanced)]
2775 protected void ResetMouseEventArgs() {
2779 [EditorBrowsable(EditorBrowsableState.Advanced)]
2780 protected ContentAlignment RtlTranslateAlignment(ContentAlignment align) {
2781 if (right_to_left == RightToLeft.No) {
2786 case ContentAlignment.TopLeft: {
2787 return ContentAlignment.TopRight;
2790 case ContentAlignment.TopRight: {
2791 return ContentAlignment.TopLeft;
2794 case ContentAlignment.MiddleLeft: {
2795 return ContentAlignment.MiddleRight;
2798 case ContentAlignment.MiddleRight: {
2799 return ContentAlignment.MiddleLeft;
2802 case ContentAlignment.BottomLeft: {
2803 return ContentAlignment.BottomRight;
2806 case ContentAlignment.BottomRight: {
2807 return ContentAlignment.BottomLeft;
2811 // if it's center it doesn't change
2817 [EditorBrowsable(EditorBrowsableState.Advanced)]
2818 protected HorizontalAlignment RtlTranslateAlignment(HorizontalAlignment align) {
2819 if ((right_to_left == RightToLeft.No) || (align == HorizontalAlignment.Center)) {
2823 if (align == HorizontalAlignment.Left) {
2824 return HorizontalAlignment.Right;
2827 // align must be HorizontalAlignment.Right
2828 return HorizontalAlignment.Left;
2831 [EditorBrowsable(EditorBrowsableState.Advanced)]
2832 protected LeftRightAlignment RtlTranslateAlignment(LeftRightAlignment align) {
2833 if (right_to_left == RightToLeft.No) {
2837 if (align == LeftRightAlignment.Left) {
2838 return LeftRightAlignment.Right;
2841 // align must be LeftRightAlignment.Right;
2842 return LeftRightAlignment.Left;
2845 [EditorBrowsable(EditorBrowsableState.Advanced)]
2846 protected ContentAlignment RtlTranslateContent(ContentAlignment align) {
2847 return RtlTranslateAlignment(align);
2850 [EditorBrowsable(EditorBrowsableState.Advanced)]
2851 protected HorizontalAlignment RtlTranslateHorizontal(HorizontalAlignment align) {
2852 return RtlTranslateAlignment(align);
2855 [EditorBrowsable(EditorBrowsableState.Advanced)]
2856 protected LeftRightAlignment RtlTranslateLeftRight(LeftRightAlignment align) {
2857 return RtlTranslateAlignment(align);
2860 [EditorBrowsable(EditorBrowsableState.Advanced)]
2861 protected virtual void ScaleCore(float dx, float dy) {
2867 location = new Point((int)(Left * dx), (int)(Top * dy));
2868 size = this.ClientSize;
2871 if (!GetStyle(ControlStyles.FixedWidth)) {
2872 size.Width = (int)(size.Width * dx);
2875 if (!GetStyle(ControlStyles.FixedHeight)) {
2876 size.Height = (int)(size.Height * dy);
2879 Location = location;
2882 /* Now scale our children */
2883 for (int i=0; i < child_controls.Count; i++) {
2884 child_controls[i].Scale(dx, dy);
2890 protected virtual void Select(bool directed, bool forward) {
2895 // Select this control
2900 if (parent == null) {
2904 // FIXME - this thing is doing the wrong stuff, needs to be similar to SelectNextControl
2906 index = parent.child_controls.IndexOf(this);
2911 if ((index+1) < parent.child_controls.Count) {
2920 index = parent.child_controls.Count-1;
2923 result = Select(parent.child_controls[index]);
2924 } while (!result && parent.child_controls[index] != this);
2927 [EditorBrowsable(EditorBrowsableState.Advanced)]
2928 protected virtual void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
2929 // SetBoundsCore updates the Win32 control itself. UpdateBounds updates the controls variables and fires events, I'm guessing - pdb
2930 if ((specified & BoundsSpecified.X) != BoundsSpecified.X) {
2934 if ((specified & BoundsSpecified.Y) != BoundsSpecified.Y) {
2938 if ((specified & BoundsSpecified.Width) != BoundsSpecified.Width) {
2942 if ((specified & BoundsSpecified.Height) != BoundsSpecified.Height) {
2946 if (IsHandleCreated) {
2947 XplatUI.SetWindowPos(Handle, x, y, width, height);
2949 UpdateBounds(x, y, width, height);
2952 [EditorBrowsable(EditorBrowsableState.Advanced)]
2953 protected virtual void SetClientSizeCore(int x, int y) {
2954 // Calculate the actual window size from the client size (it usually stays the same or grows)
2955 Rectangle ClientRect;
2956 Rectangle WindowRect;
2959 ClientRect = new Rectangle(0, 0, x, y);
2960 cp = this.CreateParams;
2962 if (XplatUI.CalculateWindowRect(Handle, ref ClientRect, cp.Style, cp.ExStyle, IntPtr.Zero, out WindowRect)==false) {
2966 SetBoundsCore(bounds.X, bounds.Y, WindowRect.Width, WindowRect.Height, BoundsSpecified.Size);
2969 [EditorBrowsable(EditorBrowsableState.Advanced)]
2970 protected void SetStyle(ControlStyles flag, bool value) {
2972 control_style |= flag;
2974 control_style &= ~flag;
2978 protected void SetTopLevel(bool value) {
2979 if ((GetTopLevel() != value) && (parent != null)) {
2980 throw new Exception();
2984 if (value == true) {
2994 is_toplevel = value;
2997 protected virtual void SetVisibleCore(bool value) {
2998 if (value!=is_visible) {
3000 XplatUI.SetVisible(Handle, value);
3001 // Explicitly move Toplevel windows to where we want them;
3002 // apparently moving unmapped toplevel windows doesn't work
3003 if (is_visible && (this is Form)) {
3004 XplatUI.SetWindowPos(window.Handle, bounds.X, bounds.Y, bounds.Width, bounds.Height);
3006 OnVisibleChanged(EventArgs.Empty);
3009 if (dc_mem != null) {
3014 if (bmp_mem != null) {
3019 this.CreateBuffers(bounds.Width, bounds.Height);
3022 // FIXME - deal with focus
3024 if (parent != null) {
3025 parent.PerformLayout(this, "visible");
3027 PerformLayout(this, "visible");
3032 [EditorBrowsable(EditorBrowsableState.Advanced)]
3033 protected void UpdateBounds() {
3041 if (!IsHandleCreated) {
3045 XplatUI.GetWindowPos(this.Handle, this is Form, out x, out y, out width, out height, out client_width, out client_height);
3047 UpdateBounds(x, y, width, height, client_width, client_height);
3050 [EditorBrowsable(EditorBrowsableState.Advanced)]
3051 protected void UpdateBounds(int x, int y, int width, int height) {
3052 // UpdateBounds only seems to set our sizes and fire events but not update the GUI window to match
3054 bool resized = false;
3056 int client_x_diff = this.bounds.Width-this.client_size.Width;
3057 int client_y_diff = this.bounds.Height-this.client_size.Height;
3059 // Needed to generate required notifications
3060 if ((this.bounds.X!=x) || (this.bounds.Y!=y)) {
3064 if ((this.Bounds.Width!=width) || (this.Bounds.Height!=height)) {
3071 bounds.Height=height;
3073 // Update client rectangle as well
3074 if (this.layout_suspended==0) {
3075 prev_size.Width=client_size.Width;
3076 prev_size.Height=client_size.Height;
3079 client_size.Width=width-client_x_diff;
3080 client_size.Height=height-client_y_diff;
3083 OnLocationChanged(EventArgs.Empty);
3087 OnSizeChanged(EventArgs.Empty);
3091 [EditorBrowsable(EditorBrowsableState.Advanced)]
3092 protected void UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) {
3093 UpdateBounds(x, y, width, height);
3095 this.client_size.Width=clientWidth;
3096 this.client_size.Height=clientHeight;
3099 [EditorBrowsable(EditorBrowsableState.Advanced)]
3100 protected void UpdateStyles() {
3101 if (!IsHandleCreated) {
3105 XplatUI.SetWindowStyle(window.Handle, CreateParams);
3108 [EditorBrowsable(EditorBrowsableState.Advanced)]
3109 protected void UpdateZOrder() {
3114 if (parent == null) {
3120 children = ctl.child_controls.Count;
3121 for (int i = 1; i < children; i++ ) {
3122 XplatUI.SetZOrder(ctl.child_controls[i].window.Handle, ctl.child_controls[i-1].window.Handle, false, false);
3125 children = child_controls.Count;
3126 for (int i = 1; i < children; i++ ) {
3127 XplatUI.SetZOrder(child_controls[i].window.Handle, child_controls[i-1].window.Handle, false, false);
3132 protected virtual void WndProc(ref Message m) {
3134 Console.WriteLine("Control received message {0}", (Msg)m.Msg);
3136 if ((this.control_style & ControlStyles.EnableNotifyMessage) != 0) {
3140 switch((Msg)m.Msg) {
3141 case Msg.WM_WINDOWPOSCHANGED: {
3144 if (GetStyle(ControlStyles.ResizeRedraw)) {
3151 case Msg.WM_PAINT: {
3152 PaintEventArgs paint_event;
3154 paint_event = XplatUI.PaintEventStart(Handle);
3156 if (GetStyle(ControlStyles.AllPaintingInWmPaint)) {
3157 OnPaintBackground(paint_event);
3159 OnPaint(paint_event);
3160 XplatUI.PaintEventEnd(Handle);
3162 if (!GetStyle(ControlStyles.UserPaint)) {
3169 case Msg.WM_ERASEBKGND: {
3170 if (GetStyle (ControlStyles.UserPaint)) {
3171 if (!GetStyle(ControlStyles.AllPaintingInWmPaint)) {
3172 PaintEventArgs eraseEventArgs = new PaintEventArgs (m.WParam == IntPtr.Zero ? Graphics.FromHwnd (m.HWnd) :
3173 Graphics.FromHdc (m.WParam), new Rectangle (new Point (0,0),Size));
3174 OnPaintBackground (eraseEventArgs);
3176 m.Result = (IntPtr)1;
3178 m.Result = IntPtr.Zero;
3185 case Msg.WM_LBUTTONUP: {
3186 HandleClick(mouse_clicks);
3187 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Left,
3189 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3191 if (mouse_clicks > 1) {
3197 case Msg.WM_LBUTTONDOWN: {
3198 if (CanSelect && !is_selected) {
3201 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3202 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3208 case Msg.WM_LBUTTONDBLCLK: {
3210 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3211 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3217 case Msg.WM_MBUTTONUP: {
3218 HandleClick(mouse_clicks);
3219 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Middle,
3221 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3223 if (mouse_clicks > 1) {
3229 case Msg.WM_MBUTTONDOWN: {
3230 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3231 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3237 case Msg.WM_MBUTTONDBLCLK: {
3239 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3240 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3245 case Msg.WM_RBUTTONUP: {
3246 HandleClick(mouse_clicks);
3247 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Right,
3249 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3251 if (mouse_clicks > 1) {
3257 case Msg.WM_RBUTTONDOWN: {
3258 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3259 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3264 case Msg.WM_RBUTTONDBLCLK: {
3266 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3267 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3272 case Msg.WM_MOUSEWHEEL: {
3274 OnMouseWheel (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3275 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3276 HighOrder(m.WParam.ToInt32())));
3281 case Msg.WM_MOUSEMOVE: {
3282 OnMouseMove (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3284 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3289 case Msg.WM_MOUSE_ENTER: {
3294 OnMouseEnter(EventArgs.Empty);
3298 case Msg.WM_MOUSE_LEAVE: {
3300 OnMouseLeave(EventArgs.Empty);
3304 case Msg.WM_MOUSEHOVER: {
3305 OnMouseHover(EventArgs.Empty);
3309 case Msg.WM_SYSKEYDOWN:
3310 case Msg.WM_KEYDOWN:
3311 case Msg.WM_SYSKEYUP:
3313 case Msg.WM_SYSCHAR:
3315 if (ProcessKeyEventArgs(ref m)) {
3319 if (PreProcessMessage(ref m)) {
3323 if (ProcessKeyMessage(ref m)) {
3332 if (m.LParam != IntPtr.Zero) {
3335 hi = new HELPINFO();
3337 hi = (HELPINFO) Marshal.PtrToStructure (m.LParam, typeof (HELPINFO));
3338 mouse_pos = new Point(hi.MousePos.x, hi.MousePos.y);
3340 mouse_pos = Control.MousePosition;
3342 OnHelpRequested(new HelpEventArgs(mouse_pos));
3343 m.Result = (IntPtr)1;
3347 case Msg.WM_KILLFOCUS: {
3348 OnLeave(EventArgs.Empty);
3349 if (CausesValidation) {
3351 e = new CancelEventArgs(false);
3360 OnValidated(EventArgs.Empty);
3363 this.has_focus = false;
3364 this.is_selected = false;
3365 OnLostFocus(EventArgs.Empty);
3369 case Msg.WM_SETFOCUS: {
3370 OnEnter(EventArgs.Empty);
3371 this.has_focus = true;
3372 OnGotFocus(EventArgs.Empty);
3377 case Msg.WM_SYSCOLORCHANGE: {
3378 ThemeEngine.Current.ResetDefaults();
3379 OnSystemColorsChanged(EventArgs.Empty);
3384 case Msg.WM_SETCURSOR: {
3385 if (cursor == null) {
3390 XplatUI.SetCursor(window.Handle, cursor.handle);
3391 m.Result = (IntPtr)1;
3401 #endregion // Public Instance Methods
3403 #region OnXXX methods
3404 [EditorBrowsable(EditorBrowsableState.Advanced)]
3405 protected virtual void OnBackColorChanged(EventArgs e) {
3406 if (BackColorChanged!=null) BackColorChanged(this, e);
3407 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackColorChanged(e);
3410 [EditorBrowsable(EditorBrowsableState.Advanced)]
3411 protected virtual void OnBackgroundImageChanged(EventArgs e) {
3412 if (BackgroundImageChanged!=null) BackgroundImageChanged(this, e);
3413 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackgroundImageChanged(e);
3416 [EditorBrowsable(EditorBrowsableState.Advanced)]
3417 protected virtual void OnBindingContextChanged(EventArgs e) {
3418 CheckDataBindings ();
3419 if (BindingContextChanged!=null) {
3420 BindingContextChanged(this, e);
3422 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBindingContextChanged(e);
3425 [EditorBrowsable(EditorBrowsableState.Advanced)]
3426 protected virtual void OnCausesValidationChanged(EventArgs e) {
3427 if (CausesValidationChanged!=null) CausesValidationChanged(this, e);
3430 [EditorBrowsable(EditorBrowsableState.Advanced)]
3431 protected virtual void OnChangeUICues(UICuesEventArgs e) {
3432 if (ChangeUICues!=null) ChangeUICues(this, e);
3435 [EditorBrowsable(EditorBrowsableState.Advanced)]
3436 protected virtual void OnClick(EventArgs e) {
3437 if (Click!=null) Click(this, e);
3440 [EditorBrowsable(EditorBrowsableState.Advanced)]
3441 protected virtual void OnContextMenuChanged(EventArgs e) {
3442 if (ContextMenuChanged!=null) ContextMenuChanged(this, e);
3445 [EditorBrowsable(EditorBrowsableState.Advanced)]
3446 protected virtual void OnControlAdded(ControlEventArgs e) {
3447 if (ControlAdded!=null) ControlAdded(this, e);
3450 [EditorBrowsable(EditorBrowsableState.Advanced)]
3451 protected virtual void OnControlRemoved(ControlEventArgs e) {
3452 if (ControlRemoved!=null) ControlRemoved(this, e);
3455 [EditorBrowsable(EditorBrowsableState.Advanced)]
3456 protected virtual void OnCreateControl() {
3460 [EditorBrowsable(EditorBrowsableState.Advanced)]
3461 protected virtual void OnCursorChanged(EventArgs e) {
3462 if (CursorChanged!=null) CursorChanged(this, e);
3465 [EditorBrowsable(EditorBrowsableState.Advanced)]
3466 protected virtual void OnDockChanged(EventArgs e) {
3467 if (DockChanged!=null) DockChanged(this, e);
3470 [EditorBrowsable(EditorBrowsableState.Advanced)]
3471 protected virtual void OnDoubleClick(EventArgs e) {
3472 if (DoubleClick!=null) DoubleClick(this, e);
3475 [EditorBrowsable(EditorBrowsableState.Advanced)]
3476 protected virtual void OnDragDrop(DragEventArgs drgevent) {
3477 if (DragDrop!=null) DragDrop(this, drgevent);
3480 [EditorBrowsable(EditorBrowsableState.Advanced)]
3481 protected virtual void OnDragEnter(DragEventArgs drgevent) {
3482 if (DragEnter!=null) DragEnter(this, drgevent);
3485 [EditorBrowsable(EditorBrowsableState.Advanced)]
3486 protected virtual void OnDragLeave(EventArgs e) {
3487 if (DragLeave!=null) DragLeave(this, e);
3490 [EditorBrowsable(EditorBrowsableState.Advanced)]
3491 protected virtual void OnDragOver(DragEventArgs drgevent) {
3492 if (DragOver!=null) DragOver(this, drgevent);
3495 [EditorBrowsable(EditorBrowsableState.Advanced)]
3496 protected virtual void OnEnabledChanged(EventArgs e) {
3497 if (EnabledChanged!=null) EnabledChanged(this, e);
3498 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentEnabledChanged(e);
3501 [EditorBrowsable(EditorBrowsableState.Advanced)]
3502 protected virtual void OnEnter(EventArgs e) {
3503 if (Enter!=null) Enter(this, e);
3506 [EditorBrowsable(EditorBrowsableState.Advanced)]
3507 protected virtual void OnFontChanged(EventArgs e) {
3508 if (FontChanged!=null) FontChanged(this, e);
3509 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentFontChanged(e);
3512 [EditorBrowsable(EditorBrowsableState.Advanced)]
3513 protected virtual void OnForeColorChanged(EventArgs e) {
3514 if (ForeColorChanged!=null) ForeColorChanged(this, e);
3515 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentForeColorChanged(e);
3518 [EditorBrowsable(EditorBrowsableState.Advanced)]
3519 protected virtual void OnGiveFeedback(GiveFeedbackEventArgs gfbevent) {
3520 if (GiveFeedback!=null) GiveFeedback(this, gfbevent);
3523 [EditorBrowsable(EditorBrowsableState.Advanced)]
3524 protected virtual void OnGotFocus(EventArgs e) {
3525 if (GotFocus!=null) GotFocus(this, e);
3528 [EditorBrowsable(EditorBrowsableState.Advanced)]
3529 protected virtual void OnHandleCreated(EventArgs e) {
3530 if (HandleCreated!=null) HandleCreated(this, e);
3533 [EditorBrowsable(EditorBrowsableState.Advanced)]
3534 protected virtual void OnHandleDestroyed(EventArgs e) {
3535 if (HandleDestroyed!=null) HandleDestroyed(this, e);
3538 [EditorBrowsable(EditorBrowsableState.Advanced)]
3539 protected virtual void OnHelpRequested(HelpEventArgs hevent) {
3540 if (HelpRequested!=null) HelpRequested(this, hevent);
3543 protected virtual void OnImeModeChanged(EventArgs e) {
3544 if (ImeModeChanged!=null) ImeModeChanged(this, e);
3547 [EditorBrowsable(EditorBrowsableState.Advanced)]
3548 protected virtual void OnInvalidated(InvalidateEventArgs e) {
3549 if (Invalidated!=null) Invalidated(this, e);
3552 [EditorBrowsable(EditorBrowsableState.Advanced)]
3553 protected virtual void OnKeyDown(KeyEventArgs e) {
3554 if (KeyDown!=null) KeyDown(this, e);
3557 [EditorBrowsable(EditorBrowsableState.Advanced)]
3558 protected virtual void OnKeyPress(KeyPressEventArgs e) {
3559 if (KeyPress!=null) KeyPress(this, e);
3562 [EditorBrowsable(EditorBrowsableState.Advanced)]
3563 protected virtual void OnKeyUp(KeyEventArgs e) {
3564 if (KeyUp!=null) KeyUp(this, e);
3567 [EditorBrowsable(EditorBrowsableState.Advanced)]
3568 protected virtual void OnLayout(LayoutEventArgs levent) {
3569 if (Layout!=null) Layout(this, levent);
3572 [EditorBrowsable(EditorBrowsableState.Advanced)]
3573 protected virtual void OnLeave(EventArgs e) {
3574 if (Leave!=null) Leave(this, e);
3577 [EditorBrowsable(EditorBrowsableState.Advanced)]
3578 protected virtual void OnLocationChanged(EventArgs e) {
3580 if (LocationChanged!=null) LocationChanged(this, e);
3583 [EditorBrowsable(EditorBrowsableState.Advanced)]
3584 protected virtual void OnLostFocus(EventArgs e) {
3585 if (LostFocus!=null) LostFocus(this, e);
3588 [EditorBrowsable(EditorBrowsableState.Advanced)]
3589 protected virtual void OnMouseDown(MouseEventArgs e) {
3590 if (MouseDown!=null) MouseDown(this, e);
3593 [EditorBrowsable(EditorBrowsableState.Advanced)]
3594 protected virtual void OnMouseEnter(EventArgs e) {
3595 if (MouseEnter!=null) MouseEnter(this, e);
3598 [EditorBrowsable(EditorBrowsableState.Advanced)]
3599 protected virtual void OnMouseHover(EventArgs e) {
3600 if (MouseHover!=null) MouseHover(this, e);
3603 [EditorBrowsable(EditorBrowsableState.Advanced)]
3604 protected virtual void OnMouseLeave(EventArgs e) {
3605 if (MouseLeave!=null) MouseLeave(this, e);
3608 [EditorBrowsable(EditorBrowsableState.Advanced)]
3609 protected virtual void OnMouseMove(MouseEventArgs e) {
3610 if (MouseMove!=null) MouseMove(this, e);
3613 [EditorBrowsable(EditorBrowsableState.Advanced)]
3614 protected virtual void OnMouseUp(MouseEventArgs e) {
3615 if (MouseUp!=null) MouseUp(this, e);
3618 [EditorBrowsable(EditorBrowsableState.Advanced)]
3619 protected virtual void OnMouseWheel(MouseEventArgs e) {
3620 if (MouseWheel!=null) MouseWheel(this, e);
3623 [EditorBrowsable(EditorBrowsableState.Advanced)]
3624 protected virtual void OnMove(EventArgs e) {
3625 if (Move!=null) Move(this, e);
3628 [EditorBrowsable(EditorBrowsableState.Advanced)]
3629 protected virtual void OnNotifyMessage(Message m) {
3633 [EditorBrowsable(EditorBrowsableState.Advanced)]
3634 protected virtual void OnPaint(PaintEventArgs e) {
3635 if (Paint!=null) Paint(this, e);
3638 [EditorBrowsable(EditorBrowsableState.Advanced)]
3639 protected virtual void OnPaintBackground(PaintEventArgs pevent) {
3643 [EditorBrowsable(EditorBrowsableState.Advanced)]
3644 protected virtual void OnParentBackColorChanged(EventArgs e) {
3645 if (background_color.IsEmpty && background_image==null) {
3647 OnBackColorChanged(e);
3651 [EditorBrowsable(EditorBrowsableState.Advanced)]
3652 protected virtual void OnParentBackgroundImageChanged(EventArgs e) {
3653 if (background_color.IsEmpty && background_image==null) {
3655 OnBackgroundImageChanged(e);
3659 [EditorBrowsable(EditorBrowsableState.Advanced)]
3660 protected virtual void OnParentBindingContextChanged(EventArgs e) {
3661 if (binding_context==null) {
3662 binding_context=Parent.binding_context;
3663 OnBindingContextChanged(e);
3667 [EditorBrowsable(EditorBrowsableState.Advanced)]
3668 protected virtual void OnParentChanged(EventArgs e) {
3669 if (ParentChanged!=null) ParentChanged(this, e);
3672 [EditorBrowsable(EditorBrowsableState.Advanced)]
3673 protected virtual void OnParentEnabledChanged(EventArgs e) {
3674 if (is_enabled != Parent.is_enabled) {
3675 is_enabled=Parent.is_enabled;
3677 if (EnabledChanged != null) {
3678 EnabledChanged(this, e);
3683 [EditorBrowsable(EditorBrowsableState.Advanced)]
3684 protected virtual void OnParentFontChanged(EventArgs e) {
3691 [EditorBrowsable(EditorBrowsableState.Advanced)]
3692 protected virtual void OnParentForeColorChanged(EventArgs e) {
3693 if (foreground_color.IsEmpty) {
3695 OnForeColorChanged(e);
3699 [EditorBrowsable(EditorBrowsableState.Advanced)]
3700 protected virtual void OnParentRightToLeftChanged(EventArgs e) {
3701 if (right_to_left==RightToLeft.Inherit) {
3703 OnRightToLeftChanged(e);
3707 [EditorBrowsable(EditorBrowsableState.Advanced)]
3708 protected virtual void OnParentVisibleChanged(EventArgs e) {
3709 if (is_visible!=Parent.is_visible) {
3712 OnVisibleChanged(e);
3716 [EditorBrowsable(EditorBrowsableState.Advanced)]
3717 protected virtual void OnQueryContinueDrag(QueryContinueDragEventArgs e) {
3718 if (QueryContinueDrag!=null) QueryContinueDrag(this, e);
3721 [EditorBrowsable(EditorBrowsableState.Advanced)]
3722 protected virtual void OnResize(EventArgs e) {
3723 if (Resize!=null) Resize(this, e);
3725 PerformLayout(this, "bounds");
3727 if (parent != null) {
3728 parent.PerformLayout();
3732 [EditorBrowsable(EditorBrowsableState.Advanced)]
3733 protected virtual void OnRightToLeftChanged(EventArgs e) {
3734 if (RightToLeftChanged!=null) RightToLeftChanged(this, e);
3735 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentRightToLeftChanged(e);
3738 [EditorBrowsable(EditorBrowsableState.Advanced)]
3739 protected virtual void OnSizeChanged(EventArgs e) {
3740 InvalidateBuffers ();
3742 if (SizeChanged!=null) SizeChanged(this, e);
3745 [EditorBrowsable(EditorBrowsableState.Advanced)]
3746 protected virtual void OnStyleChanged(EventArgs e) {
3747 if (StyleChanged!=null) StyleChanged(this, e);
3750 [EditorBrowsable(EditorBrowsableState.Advanced)]
3751 protected virtual void OnSystemColorsChanged(EventArgs e) {
3752 if (SystemColorsChanged!=null) SystemColorsChanged(this, e);
3755 [EditorBrowsable(EditorBrowsableState.Advanced)]
3756 protected virtual void OnTabIndexChanged(EventArgs e) {
3757 if (TabIndexChanged!=null) TabIndexChanged(this, e);
3760 [EditorBrowsable(EditorBrowsableState.Advanced)]
3761 protected virtual void OnTabStopChanged(EventArgs e) {
3762 if (TabStopChanged!=null) TabStopChanged(this, e);
3765 [EditorBrowsable(EditorBrowsableState.Advanced)]
3766 protected virtual void OnTextChanged(EventArgs e) {
3767 if (TextChanged!=null) TextChanged(this, e);
3770 [EditorBrowsable(EditorBrowsableState.Advanced)]
3771 protected virtual void OnValidated(EventArgs e) {
3772 if (Validated!=null) Validated(this, e);
3775 [EditorBrowsable(EditorBrowsableState.Advanced)]
3776 protected virtual void OnValidating(System.ComponentModel.CancelEventArgs e) {
3777 if (Validating!=null) Validating(this, e);
3780 [EditorBrowsable(EditorBrowsableState.Advanced)]
3781 protected virtual void OnVisibleChanged(EventArgs e) {
3788 if (bmp_mem!=null) {
3794 if (!this.IsHandleCreated) {
3795 this.CreateHandle();
3801 if (VisibleChanged!=null) VisibleChanged(this, e);
3803 // We need to tell our kids
3804 for (int i=0; i<child_controls.Count; i++) {
3805 child_controls[i].OnParentVisibleChanged(e);
3808 #endregion // OnXXX methods
3811 public event EventHandler BackColorChanged;
3812 public event EventHandler BackgroundImageChanged;
3813 public event EventHandler BindingContextChanged;
3814 public event EventHandler CausesValidationChanged;
3815 public event UICuesEventHandler ChangeUICues;
3816 public event EventHandler Click;
3817 public event EventHandler ContextMenuChanged;
3819 [EditorBrowsable(EditorBrowsableState.Advanced)]
3821 public event ControlEventHandler ControlAdded;
3823 [EditorBrowsable(EditorBrowsableState.Advanced)]
3825 public event ControlEventHandler ControlRemoved;
3827 public event EventHandler CursorChanged;
3828 public event EventHandler DockChanged;
3829 public event EventHandler DoubleClick;
3830 public event DragEventHandler DragDrop;
3831 public event DragEventHandler DragEnter;
3832 public event EventHandler DragLeave;
3833 public event DragEventHandler DragOver;
3834 public event EventHandler EnabledChanged;
3835 public event EventHandler Enter;
3836 public event EventHandler FontChanged;
3837 public event EventHandler ForeColorChanged;
3838 public event GiveFeedbackEventHandler GiveFeedback;
3840 [EditorBrowsable(EditorBrowsableState.Advanced)]
3842 public event EventHandler GotFocus;
3844 [EditorBrowsable(EditorBrowsableState.Advanced)]
3846 public event EventHandler HandleCreated;
3848 [EditorBrowsable(EditorBrowsableState.Advanced)]
3850 public event EventHandler HandleDestroyed;
3852 public event HelpEventHandler HelpRequested;
3853 public event EventHandler ImeModeChanged;
3855 [EditorBrowsable(EditorBrowsableState.Advanced)]
3857 public event InvalidateEventHandler Invalidated;
3859 public event KeyEventHandler KeyDown;
3860 public event KeyPressEventHandler KeyPress;
3861 public event KeyEventHandler KeyUp;
3862 public event LayoutEventHandler Layout;
3863 public event EventHandler Leave;
3864 public event EventHandler LocationChanged;
3866 [EditorBrowsable(EditorBrowsableState.Advanced)]
3868 public event EventHandler LostFocus;
3870 public event MouseEventHandler MouseDown;
3871 public event EventHandler MouseEnter;
3872 public event EventHandler MouseHover;
3873 public event EventHandler MouseLeave;
3874 public event MouseEventHandler MouseMove;
3875 public event MouseEventHandler MouseUp;
3877 [EditorBrowsable(EditorBrowsableState.Advanced)]
3879 public event MouseEventHandler MouseWheel;
3881 public event EventHandler Move;
3882 public event PaintEventHandler Paint;
3883 public event EventHandler ParentChanged;
3884 public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp;
3885 public event QueryContinueDragEventHandler QueryContinueDrag;
3886 public event EventHandler Resize;
3887 public event EventHandler RightToLeftChanged;
3888 public event EventHandler SizeChanged;
3889 public event EventHandler StyleChanged;
3890 public event EventHandler SystemColorsChanged;
3891 public event EventHandler TabIndexChanged;
3892 public event EventHandler TabStopChanged;
3893 public event EventHandler TextChanged;
3894 public event EventHandler Validated;
3895 public event CancelEventHandler Validating;
3896 public event EventHandler VisibleChanged;
3897 #endregion // Events