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.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 (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.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 {
1810 } else if (parent != null) {
1811 return parent.Visible;
1818 SetVisibleCore(value);
1822 [EditorBrowsable(EditorBrowsableState.Always)]
1824 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1827 return this.bounds.Width;
1831 SetBoundsCore(bounds.X, bounds.Y, value, bounds.Height, BoundsSpecified.Width);
1835 [EditorBrowsable(EditorBrowsableState.Never)]
1837 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1838 public IWindowTarget WindowTarget {
1847 #endregion // Public Instance Properties
1849 #region Protected Instance Properties
1850 protected virtual CreateParams CreateParams {
1852 CreateParams create_params = new CreateParams();
1854 create_params.Caption = Text;
1855 create_params.X = Left;
1856 create_params.Y = Top;
1857 create_params.Width = Width;
1858 create_params.Height = Height;
1860 create_params.ClassName = XplatUI.DefaultClassName;
1861 create_params.ClassStyle = 0;
1862 create_params.ExStyle = 0;
1863 create_params.Param = 0;
1866 create_params.Parent = parent.Handle;
1869 create_params.Style = (int)WindowStyles.WS_CHILD | (int)WindowStyles.WS_CLIPCHILDREN | (int)WindowStyles.WS_CLIPSIBLINGS;
1872 create_params.Style |= (int)WindowStyles.WS_VISIBLE;
1875 return create_params;
1879 protected virtual ImeMode DefaultImeMode {
1881 return ImeMode.Inherit;
1885 protected virtual Size DefaultSize {
1887 return new Size(100, 23);
1891 protected int FontHeight {
1901 protected bool RenderRightToLeft {
1903 return (this.right_to_left == RightToLeft.Yes);
1907 protected bool ResizeRedraw {
1909 return GetStyle(ControlStyles.ResizeRedraw);
1913 SetStyle(ControlStyles.ResizeRedraw, value);
1917 [EditorBrowsable(EditorBrowsableState.Advanced)]
1919 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1920 protected virtual bool ShowFocusCues {
1926 [EditorBrowsable(EditorBrowsableState.Advanced)]
1928 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1929 protected bool ShowKeyboardCues {
1934 #endregion // Protected Instance Properties
1936 #region Public Static Methods
1937 [EditorBrowsable(EditorBrowsableState.Advanced)]
1938 public static Control FromChildHandle(IntPtr handle) {
1939 IEnumerator control = Control.controls.GetEnumerator();
1941 while (control.MoveNext()) {
1942 if (((Control)control.Current).window.Handle == handle) {
1944 if (((Control)control.Current).Parent != null) {
1945 return ((Control)control.Current).Parent;
1952 [EditorBrowsable(EditorBrowsableState.Advanced)]
1953 public static Control FromHandle(IntPtr handle) {
1954 IEnumerator control = Control.controls.GetEnumerator();
1956 while (control.MoveNext()) {
1957 if (((Control)control.Current).window.Handle == handle) {
1959 return ((Control)control.Current);
1965 public static bool IsMnemonic(char charCode, string text) {
1968 amp = text.IndexOf('&');
1971 if (amp + 1 < text.Length) {
1972 if (text[amp + 1] != '&') {
1973 if (Char.ToUpper(charCode) == Char.ToUpper(text.ToCharArray(amp + 1, 1)[0])) {
1983 #region Protected Static Methods
1984 [EditorBrowsable(EditorBrowsableState.Advanced)]
1985 protected static bool ReflectMessage(IntPtr hWnd, ref Message m) {
1988 c = Control.FromHandle(hWnd);
1998 #region Public Instance Methods
1999 [EditorBrowsable(EditorBrowsableState.Advanced)]
2000 public IAsyncResult BeginInvoke(Delegate method) {
2001 return BeginInvokeInternal(method, null);
2004 [EditorBrowsable(EditorBrowsableState.Advanced)]
2005 public IAsyncResult BeginInvoke (Delegate method, object[] args) {
2006 return BeginInvokeInternal (method, args);
2009 public void BringToFront() {
2010 if ((parent != null) && (parent.child_controls[0]!=this)) {
2011 if (parent.child_controls.Contains(this)) {
2012 parent.child_controls.SetChildIndex(this, 0);
2016 XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, true, false);
2018 if (parent != null) {
2023 public bool Contains(Control ctl) {
2024 while (ctl != null) {
2033 public void CreateControl() {
2035 if (!IsHandleCreated) {
2039 for (int i=0; i<child_controls.Count; i++) {
2040 if (!child_controls[i].IsHandleCreated) {
2041 child_controls[i].CreateHandle();
2048 public Graphics CreateGraphics() {
2049 if (!IsHandleCreated) {
2050 this.CreateHandle();
2052 return Graphics.FromHwnd(this.window.Handle);
2055 [MonoTODO("Come up with cross platform drag-drop driver interface")]
2056 public DragDropEffects DoDragDrop(object data, DragDropEffects allowedEffects) {
2057 return DragDropEffects.None;
2060 [EditorBrowsable(EditorBrowsableState.Advanced)]
2061 public object EndInvoke (IAsyncResult async_result) {
2062 AsyncMethodResult result = (AsyncMethodResult) async_result;
2063 return result.EndInvoke ();
2066 public Form FindForm() {
2079 public bool Focus() {
2080 if (IsHandleCreated && !has_focus) {
2081 XplatUI.SetFocus(window.Handle);
2087 public Control GetChildAtPoint(Point pt) {
2088 // Microsoft's version of this function doesn't seem to work, so I can't check
2089 // if we only consider children or also grandchildren, etc.
2090 // I'm gonna say 'children only'
2091 for (int i=0; i<child_controls.Count; i++) {
2092 if (child_controls[i].Bounds.Contains(pt)) {
2093 return child_controls[i];
2099 public IContainerControl GetContainerControl() {
2100 Control current = this;
2102 while (current!=null) {
2103 if ((current is IContainerControl) && ((current.control_style & ControlStyles.ContainerControl)!=0)) {
2104 return (IContainerControl)current;
2106 current = current.parent;
2111 public Control GetNextControl(Control ctl, bool forward) {
2112 // If we're not a container we don't play
2113 if (!(this is IContainerControl) && !this.GetStyle(ControlStyles.ContainerControl)) {
2117 // If ctl is not contained by this, we start at the first child of this
2118 if (!this.Contains(ctl)) {
2122 // Search through our controls, starting at ctl, stepping into children as we encounter them
2123 // try to find the control with the tabindex closest to our own, or, if we're looking into
2124 // child controls, the one with the smallest tabindex
2126 return FindControlForward(this, ctl);
2128 return FindControlBackward(this, ctl);
2131 public void Hide() {
2132 this.Visible = false;
2135 public void Invalidate() {
2136 Invalidate(ClientRectangle, false);
2139 public void Invalidate(bool invalidateChildren) {
2140 Invalidate(ClientRectangle, invalidateChildren);
2143 public void Invalidate(System.Drawing.Rectangle rc) {
2144 Invalidate(rc, false);
2147 public void Invalidate(System.Drawing.Rectangle rc, bool invalidateChildren) {
2148 if (!IsHandleCreated || !Visible) {
2152 NotifyInvalidate(rc);
2154 XplatUI.Invalidate(Handle, rc, !GetStyle (ControlStyles.AllPaintingInWmPaint));
2156 if (invalidateChildren) {
2157 for (int i=0; i<child_controls.Count; i++) child_controls[i].Invalidate();
2159 OnInvalidated(new InvalidateEventArgs(rc));
2162 public void Invalidate(System.Drawing.Region region) {
2163 Invalidate(region, false);
2166 [MonoTODO("Figure out if GetRegionScans is usable")]
2167 public void Invalidate(System.Drawing.Region region, bool invalidateChildren) {
2168 throw new NotImplementedException();
2170 // FIXME - should use the GetRegionScans function of the region to invalidate each area
2171 //if (invalidateChildren) {
2172 // for (int i=0; i<child_controls.Count; i++) child_controls[i].Invalidate();
2176 public object Invoke (Delegate method) {
2177 return Invoke(method, null);
2180 public object Invoke (Delegate method, object[] args) {
2181 IAsyncResult result = BeginInvoke (method, args);
2182 return EndInvoke(result);
2185 [EditorBrowsable(EditorBrowsableState.Advanced)]
2186 public void PerformLayout() {
2187 PerformLayout(null, null);
2190 [EditorBrowsable(EditorBrowsableState.Advanced)]
2191 public void PerformLayout(Control affectedControl, string affectedProperty) {
2192 LayoutEventArgs levent = new LayoutEventArgs(affectedControl, affectedProperty);
2194 if (layout_suspended>0) {
2195 layout_pending = true;
2199 layout_pending = false;
2201 // Prevent us from getting messed up
2204 // Perform all Dock and Anchor calculations
2207 AnchorStyles anchor;
2212 space=this.DisplayRectangle;
2213 if (prev_size != Size.Empty) {
2214 diff_width = space.Width - prev_size.Width;
2215 diff_height = space.Height - prev_size.Height;
2221 // Deal with docking; go through in reverse, MS docs say that lowest Z-order is closest to edge
2222 for (int i = child_controls.Count - 1; i >= 0; i--) {
2223 child=child_controls[i];
2224 switch (child.Dock) {
2225 case DockStyle.None: {
2230 case DockStyle.Left: {
2231 child.SetBounds(space.Left, space.Y, child.Width, space.Height);
2232 space.X+=child.Width;
2233 space.Width-=child.Width;
2237 case DockStyle.Top: {
2238 child.SetBounds(space.Left, space.Y, space.Width, child.Height);
2239 space.Y+=child.Height;
2240 space.Height-=child.Height;
2244 case DockStyle.Right: {
2245 child.SetBounds(space.Right-child.Width, space.Y, child.Width, space.Height);
2246 space.Width-=child.Width;
2250 case DockStyle.Bottom: {
2251 child.SetBounds(space.Left, space.Bottom-child.Height, space.Width, child.Height);
2252 space.Height-=child.Height;
2258 for (int i = child_controls.Count - 1; i >= 0; i--) {
2259 child=child_controls[i];
2261 if (child.Dock == DockStyle.Fill) {
2262 child.SetBounds(space.Left, space.Top, space.Width, space.Height);
2268 space=this.DisplayRectangle;
2270 // Deal with anchoring
2271 for (int i=0; i < child_controls.Count; i++) {
2277 child=child_controls[i];
2278 anchor=child.Anchor;
2283 height=child.Height;
2285 // If the control is docked we don't need to do anything
2286 if (child.Dock != DockStyle.None) {
2290 if ((anchor & AnchorStyles.Left) !=0 ) {
2291 if ((anchor & AnchorStyles.Right) != 0) {
2292 // Anchoring to left and right
2293 width=width+diff_width;
2297 } else if ((anchor & AnchorStyles.Right) != 0) {
2303 if ((anchor & AnchorStyles.Top) !=0 ) {
2304 if ((anchor & AnchorStyles.Bottom) != 0) {
2305 height+=diff_height;
2309 } else if ((anchor & AnchorStyles.Bottom) != 0) {
2324 child.SetBounds(left, top, width, height);
2327 // Let everyone know
2331 // Need to make sure we decremend layout_suspended
2337 public Point PointToClient (Point p) {
2341 XplatUI.ScreenToClient (Handle, ref x, ref y);
2343 return new Point (x, y);
2346 public Point PointToScreen(Point p) {
2350 XplatUI.ClientToScreen(Handle, ref x, ref y);
2352 return new Point(x, y);
2355 public virtual bool PreProcessMessage(ref Message msg) {
2358 if ((msg.Msg == (int)Msg.WM_KEYDOWN) || (msg.Msg == (int)Msg.WM_SYSKEYDOWN)) {
2359 key_data = (Keys)msg.WParam.ToInt32();
2360 if (!ProcessCmdKey(ref msg, key_data)) {
2361 if (IsInputKey(key_data)) {
2365 return ProcessDialogKey(key_data);
2369 } else if (msg.Msg == (int)Msg.WM_CHAR) {
2370 if (IsInputChar((char)msg.WParam)) {
2373 } else if (msg.Msg == (int)Msg.WM_SYSCHAR) {
2374 if (IsInputChar((char)msg.WParam)) {
2377 return ProcessDialogChar((char)msg.WParam);
2382 public Rectangle RectangleToClient(Rectangle r) {
2383 return new Rectangle(PointToClient(r.Location), r.Size);
2386 public Rectangle RectangleToScreen(Rectangle r) {
2387 return new Rectangle(PointToScreen(r.Location), r.Size);
2390 public virtual void Refresh() {
2391 if (IsHandleCreated == true) {
2393 XplatUI.UpdateWindow(window.Handle);
2397 [EditorBrowsable(EditorBrowsableState.Never)]
2398 public virtual void ResetBackColor() {
2399 background_color = Color.Empty;
2402 #if haveDataBindings
2403 [EditorBrowsable(EditorBrowsableState.Never)]
2405 public void ResetBindings() {
2410 [EditorBrowsable(EditorBrowsableState.Never)]
2411 public virtual void ResetCursor() {
2415 [EditorBrowsable(EditorBrowsableState.Never)]
2416 public virtual void ResetFont() {
2420 [EditorBrowsable(EditorBrowsableState.Never)]
2421 public virtual void ResetForeColor() {
2422 foreground_color = Color.Empty;
2425 [EditorBrowsable(EditorBrowsableState.Never)]
2426 public void ResetImeMode() {
2427 ime_mode = DefaultImeMode;
2430 [EditorBrowsable(EditorBrowsableState.Never)]
2431 public virtual void ResetRightToLeft() {
2432 right_to_left = RightToLeft.Inherit;
2435 public virtual void ResetText() {
2439 public void ResumeLayout() {
2440 ResumeLayout (true);
2443 public void ResumeLayout(bool performLayout) {
2446 if (layout_suspended > 0) {
2450 if (performLayout || layout_pending) {
2455 public void Scale(float ratio) {
2456 ScaleCore(ratio, ratio);
2459 public void Scale(float dx, float dy) {
2463 public void Select() {
2464 Select(false, false);
2467 public bool SelectNextControl(Control ctl, bool forward, bool tabStopOnly, bool nested, bool wrap) {
2472 c = GetNextControl(c, forward);
2481 if (c.CanSelect && ((c.parent == ctl.parent) || nested) && (c.tab_stop || !tabStopOnly)) {
2485 } while (c != ctl); // If we wrap back to ourselves we stop
2490 public void SendToBack() {
2491 if ((parent != null) && (parent.child_controls[parent.child_controls.Count-1]!=this)) {
2492 if (parent.child_controls.Contains(this)) {
2493 parent.child_controls.SetChildIndex(this, parent.child_controls.Count);
2497 XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, false, true);
2498 if (parent != null) {
2503 public void SetBounds(int x, int y, int width, int height) {
2504 SetBoundsCore(x, y, width, height, BoundsSpecified.All);
2507 public void SetBounds(int x, int y, int width, int height, BoundsSpecified specified) {
2508 SetBoundsCore(x, y, width, height, specified);
2511 public void Show() {
2512 if (!IsHandleCreated) {
2513 this.CreateHandle();
2519 public void SuspendLayout() {
2523 public void Update() {
2524 XplatUI.UpdateWindow(window.Handle);
2526 #endregion // Public Instance Methods
2528 #region Protected Instance Methods
2529 [EditorBrowsable(EditorBrowsableState.Advanced)]
2530 [MonoTODO("Implement this and tie it into Control.ControlAccessibleObject.NotifyClients")]
2531 protected void AccessibilityNotifyClients(AccessibleEvents accEvent, int childID) {
2532 throw new NotImplementedException();
2535 [EditorBrowsable(EditorBrowsableState.Advanced)]
2536 protected virtual AccessibleObject CreateAccessibilityInstance() {
2537 return new Control.ControlAccessibleObject(this);
2540 [EditorBrowsable(EditorBrowsableState.Advanced)]
2541 protected virtual ControlCollection CreateControlsInstance() {
2542 return new ControlCollection(this);
2545 [EditorBrowsable(EditorBrowsableState.Advanced)]
2546 protected virtual void CreateHandle() {
2548 throw new ObjectDisposedException(Name);
2551 if (IsHandleCreated) {
2556 window = new ControlNativeWindow(this);
2557 window.CreateHandle(CreateParams);
2559 // window is only null if the handle is created for the first time; make sure OnCreateControl is triggered
2560 // This also causes our children to be created ona CreateHandle call, which shouldn't really be a problem
2561 // but may not match MS
2564 // Find out where the window manager placed us
2569 if (window.Handle!=IntPtr.Zero) {
2570 if (!controls.Contains(window.Handle)) {
2574 creator_thread = Thread.CurrentThread;
2576 XplatUI.SetWindowBackground(window.Handle, this.BackColor);
2578 OnHandleCreated(EventArgs.Empty);
2582 [EditorBrowsable(EditorBrowsableState.Advanced)]
2583 protected virtual void DefWndProc(ref Message m) {
2584 window.DefWndProc(ref m);
2587 [EditorBrowsable(EditorBrowsableState.Advanced)]
2588 protected virtual void DestroyHandle() {
2589 if (IsHandleCreated) {
2590 // Destroy our children before we destroy ourselves, to prevent them from
2591 // being implictly (without us knowing) destroyed
2592 for (int i=0; i < child_controls.Count; i++) {
2593 child_controls[i].DestroyHandle();
2597 if (window != null) {
2598 window.DestroyHandle();
2600 OnHandleDestroyed(EventArgs.Empty);
2604 protected bool GetStyle(ControlStyles flag) {
2605 return (control_style & flag) != 0;
2608 protected bool GetTopLevel() {
2612 [EditorBrowsable(EditorBrowsableState.Advanced)]
2613 protected virtual void InitLayout() {
2614 if (parent != null) {
2615 parent.PerformLayout(this, "parent");
2619 [EditorBrowsable(EditorBrowsableState.Advanced)]
2620 protected void InvokeGotFocus(Control toInvoke, EventArgs e) {
2621 toInvoke.OnGotFocus(e);
2624 [EditorBrowsable(EditorBrowsableState.Advanced)]
2625 protected void InvokeLostFocus(Control toInvoke, EventArgs e) {
2626 toInvoke.OnLostFocus(e);
2629 [EditorBrowsable(EditorBrowsableState.Advanced)]
2630 protected void InvokeOnClick(Control toInvoke, EventArgs e) {
2631 toInvoke.OnClick(e);
2634 protected void InvokePaint(Control toInvoke, PaintEventArgs e) {
2635 toInvoke.OnPaint(e);
2638 protected void InvokePaintBackground(Control toInvoke, PaintEventArgs e) {
2639 toInvoke.OnPaintBackground(e);
2642 protected virtual bool IsInputChar (char charCode) {
2643 if (parent != null) {
2644 return parent.IsInputChar(charCode);
2650 protected virtual bool IsInputKey (Keys keyData) {
2651 // Doc says this one calls IsInputChar; not sure what to do with that
2655 [EditorBrowsable(EditorBrowsableState.Advanced)]
2656 protected virtual void NotifyInvalidate(Rectangle invalidatedArea) {
2660 protected virtual bool ProcessCmdKey(ref Message msg, Keys keyData) {
2661 if ((context_menu != null) && context_menu.ProcessCmdKey(ref msg, keyData)) {
2665 if (parent != null) {
2666 return parent.ProcessCmdKey(ref msg, keyData);
2672 protected virtual bool ProcessDialogChar(char charCode) {
2673 if (parent != null) {
2674 return parent.ProcessDialogChar (charCode);
2680 protected virtual bool ProcessDialogKey (Keys keyData) {
2681 if (parent != null) {
2682 return parent.ProcessDialogKey (keyData);
2688 protected virtual bool ProcessKeyEventArgs (ref Message msg)
2690 KeyEventArgs key_event;
2693 case (int)Msg.WM_KEYDOWN: {
2694 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
2695 OnKeyDown (key_event);
2696 return key_event.Handled;
2698 case (int)Msg.WM_KEYUP: {
2699 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
2700 OnKeyUp (key_event);
2701 return key_event.Handled;
2704 case (int)Msg.WM_CHAR: {
2705 KeyPressEventArgs key_press_event;
2707 key_press_event = new KeyPressEventArgs((char)msg.WParam);
2708 OnKeyPress(key_press_event);
2709 return key_press_event.Handled;
2720 protected internal virtual bool ProcessKeyMessage(ref Message msg) {
2721 if (parent != null) {
2722 if (parent.ProcessKeyPreview(ref msg)) {
2730 protected virtual bool ProcessKeyPreview(ref Message msg) {
2731 if (parent != null) {
2732 return parent.ProcessKeyPreview(ref msg);
2738 protected virtual bool ProcessMnemonic(char charCode) {
2743 [EditorBrowsable(EditorBrowsableState.Advanced)]
2744 protected void RaiseDragEvent(object key, DragEventArgs e) {
2748 [EditorBrowsable(EditorBrowsableState.Advanced)]
2749 protected void RaiseKeyEvent(object key, KeyEventArgs e) {
2753 [EditorBrowsable(EditorBrowsableState.Advanced)]
2754 protected void RaiseMouseEvent(object key, MouseEventArgs e) {
2758 [EditorBrowsable(EditorBrowsableState.Advanced)]
2759 protected void RaisePaintEvent(object key, PaintEventArgs e) {
2763 [EditorBrowsable(EditorBrowsableState.Advanced)]
2764 protected void RecreateHandle() {
2765 IEnumerator child = child_controls.GetEnumerator();
2769 if (IsHandleCreated) {
2775 while (child.MoveNext()) {
2776 ((Control)child.Current).RecreateHandle();
2782 is_recreating = false;
2785 [EditorBrowsable(EditorBrowsableState.Advanced)]
2786 protected void ResetMouseEventArgs() {
2790 [EditorBrowsable(EditorBrowsableState.Advanced)]
2791 protected ContentAlignment RtlTranslateAlignment(ContentAlignment align) {
2792 if (right_to_left == RightToLeft.No) {
2797 case ContentAlignment.TopLeft: {
2798 return ContentAlignment.TopRight;
2801 case ContentAlignment.TopRight: {
2802 return ContentAlignment.TopLeft;
2805 case ContentAlignment.MiddleLeft: {
2806 return ContentAlignment.MiddleRight;
2809 case ContentAlignment.MiddleRight: {
2810 return ContentAlignment.MiddleLeft;
2813 case ContentAlignment.BottomLeft: {
2814 return ContentAlignment.BottomRight;
2817 case ContentAlignment.BottomRight: {
2818 return ContentAlignment.BottomLeft;
2822 // if it's center it doesn't change
2828 [EditorBrowsable(EditorBrowsableState.Advanced)]
2829 protected HorizontalAlignment RtlTranslateAlignment(HorizontalAlignment align) {
2830 if ((right_to_left == RightToLeft.No) || (align == HorizontalAlignment.Center)) {
2834 if (align == HorizontalAlignment.Left) {
2835 return HorizontalAlignment.Right;
2838 // align must be HorizontalAlignment.Right
2839 return HorizontalAlignment.Left;
2842 [EditorBrowsable(EditorBrowsableState.Advanced)]
2843 protected LeftRightAlignment RtlTranslateAlignment(LeftRightAlignment align) {
2844 if (right_to_left == RightToLeft.No) {
2848 if (align == LeftRightAlignment.Left) {
2849 return LeftRightAlignment.Right;
2852 // align must be LeftRightAlignment.Right;
2853 return LeftRightAlignment.Left;
2856 [EditorBrowsable(EditorBrowsableState.Advanced)]
2857 protected ContentAlignment RtlTranslateContent(ContentAlignment align) {
2858 return RtlTranslateAlignment(align);
2861 [EditorBrowsable(EditorBrowsableState.Advanced)]
2862 protected HorizontalAlignment RtlTranslateHorizontal(HorizontalAlignment align) {
2863 return RtlTranslateAlignment(align);
2866 [EditorBrowsable(EditorBrowsableState.Advanced)]
2867 protected LeftRightAlignment RtlTranslateLeftRight(LeftRightAlignment align) {
2868 return RtlTranslateAlignment(align);
2871 [EditorBrowsable(EditorBrowsableState.Advanced)]
2872 protected virtual void ScaleCore(float dx, float dy) {
2878 location = new Point((int)(Left * dx), (int)(Top * dy));
2879 size = this.ClientSize;
2882 if (!GetStyle(ControlStyles.FixedWidth)) {
2883 size.Width = (int)(size.Width * dx);
2886 if (!GetStyle(ControlStyles.FixedHeight)) {
2887 size.Height = (int)(size.Height * dy);
2890 Location = location;
2893 /* Now scale our children */
2894 for (int i=0; i < child_controls.Count; i++) {
2895 child_controls[i].Scale(dx, dy);
2901 protected virtual void Select(bool directed, bool forward) {
2906 // Select this control
2911 if (parent == null) {
2915 // FIXME - this thing is doing the wrong stuff, needs to be similar to SelectNextControl
2917 index = parent.child_controls.IndexOf(this);
2922 if ((index+1) < parent.child_controls.Count) {
2931 index = parent.child_controls.Count-1;
2934 result = Select(parent.child_controls[index]);
2935 } while (!result && parent.child_controls[index] != this);
2938 [EditorBrowsable(EditorBrowsableState.Advanced)]
2939 protected virtual void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
2940 // SetBoundsCore updates the Win32 control itself. UpdateBounds updates the controls variables and fires events, I'm guessing - pdb
2941 if ((specified & BoundsSpecified.X) != BoundsSpecified.X) {
2945 if ((specified & BoundsSpecified.Y) != BoundsSpecified.Y) {
2949 if ((specified & BoundsSpecified.Width) != BoundsSpecified.Width) {
2953 if ((specified & BoundsSpecified.Height) != BoundsSpecified.Height) {
2957 if (IsHandleCreated) {
2958 XplatUI.SetWindowPos(Handle, x, y, width, height);
2960 UpdateBounds(x, y, width, height);
2963 [EditorBrowsable(EditorBrowsableState.Advanced)]
2964 protected virtual void SetClientSizeCore(int x, int y) {
2965 // Calculate the actual window size from the client size (it usually stays the same or grows)
2966 Rectangle ClientRect;
2967 Rectangle WindowRect;
2970 ClientRect = new Rectangle(0, 0, x, y);
2971 cp = this.CreateParams;
2973 if (XplatUI.CalculateWindowRect(Handle, ref ClientRect, cp.Style, cp.ExStyle, IntPtr.Zero, out WindowRect)==false) {
2977 SetBoundsCore(bounds.X, bounds.Y, WindowRect.Width, WindowRect.Height, BoundsSpecified.Size);
2980 [EditorBrowsable(EditorBrowsableState.Advanced)]
2981 protected void SetStyle(ControlStyles flag, bool value) {
2983 control_style |= flag;
2985 control_style &= ~flag;
2987 OnStyleChanged(EventArgs.Empty);
2990 protected void SetTopLevel(bool value) {
2991 if ((GetTopLevel() != value) && (parent != null)) {
2992 throw new Exception();
2996 if (value == true) {
3006 is_toplevel = value;
3009 protected virtual void SetVisibleCore(bool value) {
3010 if (value!=is_visible) {
3012 XplatUI.SetVisible(Handle, value);
3013 // Explicitly move Toplevel windows to where we want them;
3014 // apparently moving unmapped toplevel windows doesn't work
3015 if (is_visible && (this is Form)) {
3016 XplatUI.SetWindowPos(window.Handle, bounds.X, bounds.Y, bounds.Width, bounds.Height);
3018 OnVisibleChanged(EventArgs.Empty);
3021 if (dc_mem != null) {
3026 if (bmp_mem != null) {
3031 this.CreateBuffers(bounds.Width, bounds.Height);
3034 if (value == false && parent != null) {
3037 // Need to start at parent, GetContainerControl might return ourselves if we're a container
3038 container = (Control)parent.GetContainerControl();
3039 if (container != null) {
3040 container.SelectNextControl(this, true, true, true, true);
3044 if (parent != null) {
3045 parent.PerformLayout(this, "visible");
3047 PerformLayout(this, "visible");
3052 [EditorBrowsable(EditorBrowsableState.Advanced)]
3053 protected void UpdateBounds() {
3061 if (!IsHandleCreated) {
3065 XplatUI.GetWindowPos(this.Handle, this is Form, out x, out y, out width, out height, out client_width, out client_height);
3067 UpdateBounds(x, y, width, height, client_width, client_height);
3070 [EditorBrowsable(EditorBrowsableState.Advanced)]
3071 protected void UpdateBounds(int x, int y, int width, int height) {
3072 // UpdateBounds only seems to set our sizes and fire events but not update the GUI window to match
3074 bool resized = false;
3076 int client_x_diff = this.bounds.Width-this.client_size.Width;
3077 int client_y_diff = this.bounds.Height-this.client_size.Height;
3079 // Needed to generate required notifications
3080 if ((this.bounds.X!=x) || (this.bounds.Y!=y)) {
3084 if ((this.Bounds.Width!=width) || (this.Bounds.Height!=height)) {
3091 bounds.Height=height;
3093 // Update client rectangle as well
3094 if (this.layout_suspended==0) {
3095 prev_size.Width=client_size.Width;
3096 prev_size.Height=client_size.Height;
3099 client_size.Width=width-client_x_diff;
3100 client_size.Height=height-client_y_diff;
3103 OnLocationChanged(EventArgs.Empty);
3107 OnSizeChanged(EventArgs.Empty);
3111 [EditorBrowsable(EditorBrowsableState.Advanced)]
3112 protected void UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) {
3113 UpdateBounds(x, y, width, height);
3115 this.client_size.Width=clientWidth;
3116 this.client_size.Height=clientHeight;
3119 [EditorBrowsable(EditorBrowsableState.Advanced)]
3120 protected void UpdateStyles() {
3121 if (!IsHandleCreated) {
3125 XplatUI.SetWindowStyle(window.Handle, CreateParams);
3128 [EditorBrowsable(EditorBrowsableState.Advanced)]
3129 protected void UpdateZOrder() {
3134 if (parent == null) {
3140 children = ctl.child_controls.Count;
3141 for (int i = 1; i < children; i++ ) {
3142 XplatUI.SetZOrder(ctl.child_controls[i].window.Handle, ctl.child_controls[i-1].window.Handle, false, false);
3145 children = child_controls.Count;
3146 for (int i = 1; i < children; i++ ) {
3147 XplatUI.SetZOrder(child_controls[i].window.Handle, child_controls[i-1].window.Handle, false, false);
3152 protected virtual void WndProc(ref Message m) {
3154 Console.WriteLine("Control received message {0}", (Msg)m.Msg);
3156 if ((this.control_style & ControlStyles.EnableNotifyMessage) != 0) {
3160 switch((Msg)m.Msg) {
3161 case Msg.WM_WINDOWPOSCHANGED: {
3164 if (GetStyle(ControlStyles.ResizeRedraw)) {
3171 case Msg.WM_PAINT: {
3172 PaintEventArgs paint_event;
3174 paint_event = XplatUI.PaintEventStart(Handle);
3176 if (GetStyle(ControlStyles.AllPaintingInWmPaint)) {
3177 OnPaintBackground(paint_event);
3179 OnPaint(paint_event);
3180 XplatUI.PaintEventEnd(Handle);
3182 if (!GetStyle(ControlStyles.UserPaint)) {
3189 case Msg.WM_ERASEBKGND: {
3190 if (GetStyle (ControlStyles.UserPaint)) {
3191 if (!GetStyle(ControlStyles.AllPaintingInWmPaint)) {
3192 PaintEventArgs eraseEventArgs = new PaintEventArgs (m.WParam == IntPtr.Zero ? Graphics.FromHwnd (m.HWnd) :
3193 Graphics.FromHdc (m.WParam), new Rectangle (new Point (0,0),Size));
3194 OnPaintBackground (eraseEventArgs);
3196 m.Result = (IntPtr)1;
3198 m.Result = IntPtr.Zero;
3205 case Msg.WM_LBUTTONUP: {
3206 HandleClick(mouse_clicks);
3207 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Left,
3209 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3211 if (mouse_clicks > 1) {
3217 case Msg.WM_LBUTTONDOWN: {
3218 if (CanSelect && !is_selected) {
3221 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3222 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3228 case Msg.WM_LBUTTONDBLCLK: {
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_MBUTTONUP: {
3238 HandleClick(mouse_clicks);
3239 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Middle,
3241 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3243 if (mouse_clicks > 1) {
3249 case Msg.WM_MBUTTONDOWN: {
3250 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3251 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3257 case Msg.WM_MBUTTONDBLCLK: {
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_RBUTTONUP: {
3266 HandleClick(mouse_clicks);
3267 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Right,
3269 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3271 if (mouse_clicks > 1) {
3277 case Msg.WM_RBUTTONDOWN: {
3278 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3279 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3284 case Msg.WM_RBUTTONDBLCLK: {
3286 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3287 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3292 case Msg.WM_MOUSEWHEEL: {
3294 OnMouseWheel (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3295 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3296 HighOrder(m.WParam.ToInt32())));
3301 case Msg.WM_MOUSEMOVE: {
3302 OnMouseMove (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3304 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3309 case Msg.WM_MOUSE_ENTER: {
3314 OnMouseEnter(EventArgs.Empty);
3318 case Msg.WM_MOUSE_LEAVE: {
3320 OnMouseLeave(EventArgs.Empty);
3324 case Msg.WM_MOUSEHOVER: {
3325 OnMouseHover(EventArgs.Empty);
3329 case Msg.WM_SYSKEYDOWN:
3330 case Msg.WM_KEYDOWN:
3331 case Msg.WM_SYSKEYUP:
3333 case Msg.WM_SYSCHAR:
3335 if (ProcessKeyEventArgs(ref m)) {
3339 if (PreProcessMessage(ref m)) {
3343 if (ProcessKeyMessage(ref m)) {
3352 if (m.LParam != IntPtr.Zero) {
3355 hi = new HELPINFO();
3357 hi = (HELPINFO) Marshal.PtrToStructure (m.LParam, typeof (HELPINFO));
3358 mouse_pos = new Point(hi.MousePos.x, hi.MousePos.y);
3360 mouse_pos = Control.MousePosition;
3362 OnHelpRequested(new HelpEventArgs(mouse_pos));
3363 m.Result = (IntPtr)1;
3367 case Msg.WM_KILLFOCUS: {
3368 OnLeave(EventArgs.Empty);
3369 if (CausesValidation) {
3371 e = new CancelEventArgs(false);
3380 OnValidated(EventArgs.Empty);
3383 this.has_focus = false;
3384 this.is_selected = false;
3385 OnLostFocus(EventArgs.Empty);
3389 case Msg.WM_SETFOCUS: {
3390 OnEnter(EventArgs.Empty);
3391 this.has_focus = true;
3392 OnGotFocus(EventArgs.Empty);
3397 case Msg.WM_SYSCOLORCHANGE: {
3398 ThemeEngine.Current.ResetDefaults();
3399 OnSystemColorsChanged(EventArgs.Empty);
3404 case Msg.WM_SETCURSOR: {
3405 if (cursor == null) {
3410 XplatUI.SetCursor(window.Handle, cursor.handle);
3411 m.Result = (IntPtr)1;
3421 #endregion // Public Instance Methods
3423 #region OnXXX methods
3424 [EditorBrowsable(EditorBrowsableState.Advanced)]
3425 protected virtual void OnBackColorChanged(EventArgs e) {
3426 if (BackColorChanged!=null) BackColorChanged(this, e);
3427 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackColorChanged(e);
3430 [EditorBrowsable(EditorBrowsableState.Advanced)]
3431 protected virtual void OnBackgroundImageChanged(EventArgs e) {
3432 if (BackgroundImageChanged!=null) BackgroundImageChanged(this, e);
3433 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackgroundImageChanged(e);
3436 [EditorBrowsable(EditorBrowsableState.Advanced)]
3437 protected virtual void OnBindingContextChanged(EventArgs e) {
3438 CheckDataBindings ();
3439 if (BindingContextChanged!=null) {
3440 BindingContextChanged(this, e);
3442 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBindingContextChanged(e);
3445 [EditorBrowsable(EditorBrowsableState.Advanced)]
3446 protected virtual void OnCausesValidationChanged(EventArgs e) {
3447 if (CausesValidationChanged!=null) CausesValidationChanged(this, e);
3450 [EditorBrowsable(EditorBrowsableState.Advanced)]
3451 protected virtual void OnChangeUICues(UICuesEventArgs e) {
3452 if (ChangeUICues!=null) ChangeUICues(this, e);
3455 [EditorBrowsable(EditorBrowsableState.Advanced)]
3456 protected virtual void OnClick(EventArgs e) {
3457 if (Click!=null) Click(this, e);
3460 [EditorBrowsable(EditorBrowsableState.Advanced)]
3461 protected virtual void OnContextMenuChanged(EventArgs e) {
3462 if (ContextMenuChanged!=null) ContextMenuChanged(this, e);
3465 [EditorBrowsable(EditorBrowsableState.Advanced)]
3466 protected virtual void OnControlAdded(ControlEventArgs e) {
3467 if (ControlAdded!=null) ControlAdded(this, e);
3470 [EditorBrowsable(EditorBrowsableState.Advanced)]
3471 protected virtual void OnControlRemoved(ControlEventArgs e) {
3472 if (ControlRemoved!=null) ControlRemoved(this, e);
3475 [EditorBrowsable(EditorBrowsableState.Advanced)]
3476 protected virtual void OnCreateControl() {
3480 [EditorBrowsable(EditorBrowsableState.Advanced)]
3481 protected virtual void OnCursorChanged(EventArgs e) {
3482 if (CursorChanged!=null) CursorChanged(this, e);
3485 [EditorBrowsable(EditorBrowsableState.Advanced)]
3486 protected virtual void OnDockChanged(EventArgs e) {
3487 if (DockChanged!=null) DockChanged(this, e);
3490 [EditorBrowsable(EditorBrowsableState.Advanced)]
3491 protected virtual void OnDoubleClick(EventArgs e) {
3492 if (DoubleClick!=null) DoubleClick(this, e);
3495 [EditorBrowsable(EditorBrowsableState.Advanced)]
3496 protected virtual void OnDragDrop(DragEventArgs drgevent) {
3497 if (DragDrop!=null) DragDrop(this, drgevent);
3500 [EditorBrowsable(EditorBrowsableState.Advanced)]
3501 protected virtual void OnDragEnter(DragEventArgs drgevent) {
3502 if (DragEnter!=null) DragEnter(this, drgevent);
3505 [EditorBrowsable(EditorBrowsableState.Advanced)]
3506 protected virtual void OnDragLeave(EventArgs e) {
3507 if (DragLeave!=null) DragLeave(this, e);
3510 [EditorBrowsable(EditorBrowsableState.Advanced)]
3511 protected virtual void OnDragOver(DragEventArgs drgevent) {
3512 if (DragOver!=null) DragOver(this, drgevent);
3515 [EditorBrowsable(EditorBrowsableState.Advanced)]
3516 protected virtual void OnEnabledChanged(EventArgs e) {
3517 if (EnabledChanged!=null) EnabledChanged(this, e);
3518 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentEnabledChanged(e);
3521 [EditorBrowsable(EditorBrowsableState.Advanced)]
3522 protected virtual void OnEnter(EventArgs e) {
3523 if (Enter!=null) Enter(this, e);
3526 [EditorBrowsable(EditorBrowsableState.Advanced)]
3527 protected virtual void OnFontChanged(EventArgs e) {
3528 if (FontChanged!=null) FontChanged(this, e);
3529 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentFontChanged(e);
3532 [EditorBrowsable(EditorBrowsableState.Advanced)]
3533 protected virtual void OnForeColorChanged(EventArgs e) {
3534 if (ForeColorChanged!=null) ForeColorChanged(this, e);
3535 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentForeColorChanged(e);
3538 [EditorBrowsable(EditorBrowsableState.Advanced)]
3539 protected virtual void OnGiveFeedback(GiveFeedbackEventArgs gfbevent) {
3540 if (GiveFeedback!=null) GiveFeedback(this, gfbevent);
3543 [EditorBrowsable(EditorBrowsableState.Advanced)]
3544 protected virtual void OnGotFocus(EventArgs e) {
3545 if (GotFocus!=null) GotFocus(this, e);
3548 [EditorBrowsable(EditorBrowsableState.Advanced)]
3549 protected virtual void OnHandleCreated(EventArgs e) {
3550 if (HandleCreated!=null) HandleCreated(this, e);
3553 [EditorBrowsable(EditorBrowsableState.Advanced)]
3554 protected virtual void OnHandleDestroyed(EventArgs e) {
3555 if (HandleDestroyed!=null) HandleDestroyed(this, e);
3558 [EditorBrowsable(EditorBrowsableState.Advanced)]
3559 protected virtual void OnHelpRequested(HelpEventArgs hevent) {
3560 if (HelpRequested!=null) HelpRequested(this, hevent);
3563 protected virtual void OnImeModeChanged(EventArgs e) {
3564 if (ImeModeChanged!=null) ImeModeChanged(this, e);
3567 [EditorBrowsable(EditorBrowsableState.Advanced)]
3568 protected virtual void OnInvalidated(InvalidateEventArgs e) {
3569 if (Invalidated!=null) Invalidated(this, e);
3572 [EditorBrowsable(EditorBrowsableState.Advanced)]
3573 protected virtual void OnKeyDown(KeyEventArgs e) {
3574 if (KeyDown!=null) KeyDown(this, e);
3577 [EditorBrowsable(EditorBrowsableState.Advanced)]
3578 protected virtual void OnKeyPress(KeyPressEventArgs e) {
3579 if (KeyPress!=null) KeyPress(this, e);
3582 [EditorBrowsable(EditorBrowsableState.Advanced)]
3583 protected virtual void OnKeyUp(KeyEventArgs e) {
3584 if (KeyUp!=null) KeyUp(this, e);
3587 [EditorBrowsable(EditorBrowsableState.Advanced)]
3588 protected virtual void OnLayout(LayoutEventArgs levent) {
3589 if (Layout!=null) Layout(this, levent);
3592 [EditorBrowsable(EditorBrowsableState.Advanced)]
3593 protected virtual void OnLeave(EventArgs e) {
3594 if (Leave!=null) Leave(this, e);
3597 [EditorBrowsable(EditorBrowsableState.Advanced)]
3598 protected virtual void OnLocationChanged(EventArgs e) {
3600 if (LocationChanged!=null) LocationChanged(this, e);
3603 [EditorBrowsable(EditorBrowsableState.Advanced)]
3604 protected virtual void OnLostFocus(EventArgs e) {
3605 if (LostFocus!=null) LostFocus(this, e);
3608 [EditorBrowsable(EditorBrowsableState.Advanced)]
3609 protected virtual void OnMouseDown(MouseEventArgs e) {
3610 if (MouseDown!=null) MouseDown(this, e);
3613 [EditorBrowsable(EditorBrowsableState.Advanced)]
3614 protected virtual void OnMouseEnter(EventArgs e) {
3615 if (MouseEnter!=null) MouseEnter(this, e);
3618 [EditorBrowsable(EditorBrowsableState.Advanced)]
3619 protected virtual void OnMouseHover(EventArgs e) {
3620 if (MouseHover!=null) MouseHover(this, e);
3623 [EditorBrowsable(EditorBrowsableState.Advanced)]
3624 protected virtual void OnMouseLeave(EventArgs e) {
3625 if (MouseLeave!=null) MouseLeave(this, e);
3628 [EditorBrowsable(EditorBrowsableState.Advanced)]
3629 protected virtual void OnMouseMove(MouseEventArgs e) {
3630 if (MouseMove!=null) MouseMove(this, e);
3633 [EditorBrowsable(EditorBrowsableState.Advanced)]
3634 protected virtual void OnMouseUp(MouseEventArgs e) {
3635 if (MouseUp!=null) MouseUp(this, e);
3638 [EditorBrowsable(EditorBrowsableState.Advanced)]
3639 protected virtual void OnMouseWheel(MouseEventArgs e) {
3640 if (MouseWheel!=null) MouseWheel(this, e);
3643 [EditorBrowsable(EditorBrowsableState.Advanced)]
3644 protected virtual void OnMove(EventArgs e) {
3645 if (Move!=null) Move(this, e);
3648 [EditorBrowsable(EditorBrowsableState.Advanced)]
3649 protected virtual void OnNotifyMessage(Message m) {
3653 [EditorBrowsable(EditorBrowsableState.Advanced)]
3654 protected virtual void OnPaint(PaintEventArgs e) {
3655 if (Paint!=null) Paint(this, e);
3658 [EditorBrowsable(EditorBrowsableState.Advanced)]
3659 protected virtual void OnPaintBackground(PaintEventArgs pevent) {
3663 [EditorBrowsable(EditorBrowsableState.Advanced)]
3664 protected virtual void OnParentBackColorChanged(EventArgs e) {
3665 if (background_color.IsEmpty && background_image==null) {
3667 OnBackColorChanged(e);
3671 [EditorBrowsable(EditorBrowsableState.Advanced)]
3672 protected virtual void OnParentBackgroundImageChanged(EventArgs e) {
3673 if (background_color.IsEmpty && background_image==null) {
3675 OnBackgroundImageChanged(e);
3679 [EditorBrowsable(EditorBrowsableState.Advanced)]
3680 protected virtual void OnParentBindingContextChanged(EventArgs e) {
3681 if (binding_context==null) {
3682 binding_context=Parent.binding_context;
3683 OnBindingContextChanged(e);
3687 [EditorBrowsable(EditorBrowsableState.Advanced)]
3688 protected virtual void OnParentChanged(EventArgs e) {
3689 if (ParentChanged!=null) ParentChanged(this, e);
3692 [EditorBrowsable(EditorBrowsableState.Advanced)]
3693 protected virtual void OnParentEnabledChanged(EventArgs e) {
3694 if (is_enabled != Parent.is_enabled) {
3695 is_enabled=Parent.is_enabled;
3697 if (EnabledChanged != null) {
3698 EnabledChanged(this, e);
3703 [EditorBrowsable(EditorBrowsableState.Advanced)]
3704 protected virtual void OnParentFontChanged(EventArgs e) {
3711 [EditorBrowsable(EditorBrowsableState.Advanced)]
3712 protected virtual void OnParentForeColorChanged(EventArgs e) {
3713 if (foreground_color.IsEmpty) {
3715 OnForeColorChanged(e);
3719 [EditorBrowsable(EditorBrowsableState.Advanced)]
3720 protected virtual void OnParentRightToLeftChanged(EventArgs e) {
3721 if (right_to_left==RightToLeft.Inherit) {
3723 OnRightToLeftChanged(e);
3727 [EditorBrowsable(EditorBrowsableState.Advanced)]
3728 protected virtual void OnParentVisibleChanged(EventArgs e) {
3730 OnVisibleChanged(e);
3734 [EditorBrowsable(EditorBrowsableState.Advanced)]
3735 protected virtual void OnQueryContinueDrag(QueryContinueDragEventArgs e) {
3736 if (QueryContinueDrag!=null) QueryContinueDrag(this, e);
3739 [EditorBrowsable(EditorBrowsableState.Advanced)]
3740 protected virtual void OnResize(EventArgs e) {
3741 if (Resize!=null) Resize(this, e);
3743 PerformLayout(this, "bounds");
3745 if (parent != null) {
3746 parent.PerformLayout();
3750 [EditorBrowsable(EditorBrowsableState.Advanced)]
3751 protected virtual void OnRightToLeftChanged(EventArgs e) {
3752 if (RightToLeftChanged!=null) RightToLeftChanged(this, e);
3753 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentRightToLeftChanged(e);
3756 [EditorBrowsable(EditorBrowsableState.Advanced)]
3757 protected virtual void OnSizeChanged(EventArgs e) {
3758 InvalidateBuffers ();
3760 if (SizeChanged!=null) SizeChanged(this, e);
3763 [EditorBrowsable(EditorBrowsableState.Advanced)]
3764 protected virtual void OnStyleChanged(EventArgs e) {
3765 if (StyleChanged!=null) StyleChanged(this, e);
3768 [EditorBrowsable(EditorBrowsableState.Advanced)]
3769 protected virtual void OnSystemColorsChanged(EventArgs e) {
3770 if (SystemColorsChanged!=null) SystemColorsChanged(this, e);
3773 [EditorBrowsable(EditorBrowsableState.Advanced)]
3774 protected virtual void OnTabIndexChanged(EventArgs e) {
3775 if (TabIndexChanged!=null) TabIndexChanged(this, e);
3778 [EditorBrowsable(EditorBrowsableState.Advanced)]
3779 protected virtual void OnTabStopChanged(EventArgs e) {
3780 if (TabStopChanged!=null) TabStopChanged(this, e);
3783 [EditorBrowsable(EditorBrowsableState.Advanced)]
3784 protected virtual void OnTextChanged(EventArgs e) {
3785 if (TextChanged!=null) TextChanged(this, e);
3788 [EditorBrowsable(EditorBrowsableState.Advanced)]
3789 protected virtual void OnValidated(EventArgs e) {
3790 if (Validated!=null) Validated(this, e);
3793 [EditorBrowsable(EditorBrowsableState.Advanced)]
3794 protected virtual void OnValidating(System.ComponentModel.CancelEventArgs e) {
3795 if (Validating!=null) Validating(this, e);
3798 [EditorBrowsable(EditorBrowsableState.Advanced)]
3799 protected virtual void OnVisibleChanged(EventArgs e) {
3806 if (bmp_mem!=null) {
3812 if (!this.IsHandleCreated) {
3813 this.CreateHandle();
3819 if (VisibleChanged!=null) VisibleChanged(this, e);
3821 // We need to tell our kids
3822 for (int i=0; i<child_controls.Count; i++) {
3823 child_controls[i].OnParentVisibleChanged(e);
3826 #endregion // OnXXX methods
3829 public event EventHandler BackColorChanged;
3830 public event EventHandler BackgroundImageChanged;
3831 public event EventHandler BindingContextChanged;
3832 public event EventHandler CausesValidationChanged;
3833 public event UICuesEventHandler ChangeUICues;
3834 public event EventHandler Click;
3835 public event EventHandler ContextMenuChanged;
3837 [EditorBrowsable(EditorBrowsableState.Advanced)]
3839 public event ControlEventHandler ControlAdded;
3841 [EditorBrowsable(EditorBrowsableState.Advanced)]
3843 public event ControlEventHandler ControlRemoved;
3845 public event EventHandler CursorChanged;
3846 public event EventHandler DockChanged;
3847 public event EventHandler DoubleClick;
3848 public event DragEventHandler DragDrop;
3849 public event DragEventHandler DragEnter;
3850 public event EventHandler DragLeave;
3851 public event DragEventHandler DragOver;
3852 public event EventHandler EnabledChanged;
3853 public event EventHandler Enter;
3854 public event EventHandler FontChanged;
3855 public event EventHandler ForeColorChanged;
3856 public event GiveFeedbackEventHandler GiveFeedback;
3858 [EditorBrowsable(EditorBrowsableState.Advanced)]
3860 public event EventHandler GotFocus;
3862 [EditorBrowsable(EditorBrowsableState.Advanced)]
3864 public event EventHandler HandleCreated;
3866 [EditorBrowsable(EditorBrowsableState.Advanced)]
3868 public event EventHandler HandleDestroyed;
3870 public event HelpEventHandler HelpRequested;
3871 public event EventHandler ImeModeChanged;
3873 [EditorBrowsable(EditorBrowsableState.Advanced)]
3875 public event InvalidateEventHandler Invalidated;
3877 public event KeyEventHandler KeyDown;
3878 public event KeyPressEventHandler KeyPress;
3879 public event KeyEventHandler KeyUp;
3880 public event LayoutEventHandler Layout;
3881 public event EventHandler Leave;
3882 public event EventHandler LocationChanged;
3884 [EditorBrowsable(EditorBrowsableState.Advanced)]
3886 public event EventHandler LostFocus;
3888 public event MouseEventHandler MouseDown;
3889 public event EventHandler MouseEnter;
3890 public event EventHandler MouseHover;
3891 public event EventHandler MouseLeave;
3892 public event MouseEventHandler MouseMove;
3893 public event MouseEventHandler MouseUp;
3895 [EditorBrowsable(EditorBrowsableState.Advanced)]
3897 public event MouseEventHandler MouseWheel;
3899 public event EventHandler Move;
3900 public event PaintEventHandler Paint;
3901 public event EventHandler ParentChanged;
3902 public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp;
3903 public event QueryContinueDragEventHandler QueryContinueDrag;
3904 public event EventHandler Resize;
3905 public event EventHandler RightToLeftChanged;
3906 public event EventHandler SizeChanged;
3907 public event EventHandler StyleChanged;
3908 public event EventHandler SystemColorsChanged;
3909 public event EventHandler TabIndexChanged;
3910 public event EventHandler TabStopChanged;
3911 public event EventHandler TextChanged;
3912 public event EventHandler Validated;
3913 public event CancelEventHandler Validating;
3914 public event EventHandler VisibleChanged;
3915 #endregion // Events