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 private bool create_handled; // true if OnCreateControl has been sent
66 internal bool has_focus; // true if control has focus
67 internal bool is_visible; // true if control is visible
68 internal bool is_entered; // is the mouse inside the control?
69 internal bool is_enabled; // true if control is enabled (usable/not grayed out)
70 internal bool is_selected; // true if control is selected
71 internal bool is_accessible; // true if the control is visible to accessibility applications
72 internal bool is_captured; // tracks if the control has captured the mouse
73 internal bool is_toplevel; // tracks if the control is a toplevel window
74 internal bool is_recreating; // tracks if the handle for the control is being recreated
75 internal bool causes_validation; // tracks if validation is executed on changes
76 internal int tab_index; // position in tab order of siblings
77 internal bool tab_stop = true; // is the control a tab stop?
78 internal bool is_disposed; // has the window already been disposed?
79 internal Size client_size; // size of the client area (window excluding decorations)
80 internal Rectangle client_rect; // rectangle with the client area (window excluding decorations)
81 internal ControlStyles control_style; // rather win32-specific, style bits for control
82 internal ImeMode ime_mode = ImeMode.Inherit;
83 internal bool layout_pending; // true if our parent needs to re-layout us
84 internal object control_tag; // object that contains data about our control
85 internal int mouse_clicks; // Counter for mouse clicks
86 internal Cursor cursor; // Cursor for the window
89 internal Color foreground_color; // foreground color for control
90 internal Color background_color; // background color for control
91 internal Image background_image; // background image for control
92 internal Font font; // font for control
93 internal string text; // window/title text for control
94 internal BorderStyle border_style; // Border style of control
97 internal AnchorStyles anchor_style; // anchoring requirements for our control
98 internal DockStyle dock_style; // docking requirements for our control (supercedes anchoring)
99 internal SizeF size_ratio; // size ratio of our control to it's parent; required for anchoring
100 internal Size prev_size; // previous size of the control; required for anchoring
102 // to be categorized...
103 static internal ArrayList controls = new ArrayList(); // All of the application's controls, in a flat list
104 internal ControlCollection child_controls; // our children
105 internal Control parent; // our parent control
106 internal AccessibleObject accessibility_object; // object that contains accessibility information about our control
107 internal BindingContext binding_context; // TODO
108 internal RightToLeft right_to_left; // drawing direction for control
109 internal int layout_suspended;
110 internal bool double_buffering;
111 internal ContextMenu context_menu; // Context menu associated with the control
113 private Graphics dc_mem; // Graphics context for double buffering
114 private Bitmap bmp_mem; // Bitmap for double buffering control
116 private ControlBindingsCollection data_bindings;
118 #endregion // Local Variables
120 #region Private Classes
121 // This helper class allows us to dispatch messages to Control.WndProc
122 internal class ControlNativeWindow : NativeWindow {
123 private Control owner;
125 public ControlNativeWindow(Control control) : base() {
130 public Control Owner {
136 static internal Control ControlFromHandle(IntPtr hWnd) {
137 ControlNativeWindow window;
139 window = (ControlNativeWindow)window_collection[hWnd];
144 protected override void WndProc(ref Message m) {
145 owner.WndProc(ref m);
150 #region Public Classes
152 public class ControlAccessibleObject : AccessibleObject {
153 #region ControlAccessibleObject Local Variables
154 private Control owner;
155 #endregion // ControlAccessibleObject Local Variables
157 #region ControlAccessibleObject Constructors
158 public ControlAccessibleObject(Control ownerControl) {
159 this.owner = ownerControl;
161 #endregion // ControlAccessibleObject Constructors
163 #region ControlAccessibleObject Public Instance Properties
164 public override string DefaultAction {
166 return base.DefaultAction;
170 public override string Description {
172 return base.Description;
176 public IntPtr Handle {
182 // We don't want to let them set it
186 public override string Help {
192 public override string KeyboardShortcut {
194 return base.KeyboardShortcut;
198 public override string Name {
208 public Control Owner {
214 public override AccessibleRole Role {
219 #endregion // ControlAccessibleObject Public Instance Properties
221 #region ControlAccessibleObject Public Instance Methods
222 public override int GetHelpTopic(out string FileName) {
223 return base.GetHelpTopic (out FileName);
226 [MonoTODO("Implement this and tie it into Control.AccessibilityNotifyClients")]
227 public void NotifyClients(AccessibleEvents accEvent) {
228 throw new NotImplementedException();
231 [MonoTODO("Implement this and tie it into Control.AccessibilityNotifyClients")]
232 public void NotifyClients(AccessibleEvents accEvent, int childID) {
233 throw new NotImplementedException();
236 public override string ToString() {
237 return "ControlAccessibleObject: Owner = " + owner.ToString() + ", Text: " + owner.text;
240 #endregion // ControlAccessibleObject Public Instance Methods
243 [DesignerSerializer("System.Windows.Forms.Design.ControlCollectionCodeDomSerializer, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
244 [ListBindable(false)]
245 public class ControlCollection : IList, ICollection, ICloneable, IEnumerable {
246 #region ControlCollection Local Variables
247 internal ArrayList list;
248 internal Control owner;
249 #endregion // ControlCollection Local Variables
251 #region ControlCollection Public Constructor
252 public ControlCollection(Control owner) {
254 this.list=new ArrayList();
258 #region ControlCollection Public Instance Properties
265 public bool IsReadOnly {
267 return list.IsReadOnly;
271 public virtual Control this[int index] {
273 if (index < 0 || index >= list.Count) {
274 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
276 return (Control)list[index];
279 #endregion // ControlCollection Public Instance Properties
281 #region ControlCollection Private Instance Methods
282 public virtual void Add (Control value)
285 for (int i = 0; i < list.Count; i++) {
286 if (list [i] == value) {
287 // Do we need to do anything here?
292 if (value.tab_index == -1) {
298 end = owner.child_controls.Count;
299 for (int i = 0; i < end; i++) {
300 index = owner.child_controls[i].tab_index;
305 value.tab_index = use;
309 value.Parent = owner;
310 owner.UpdateZOrder();
311 owner.OnControlAdded(new ControlEventArgs(value));
314 public virtual void AddRange (Control[] controls)
316 if (controls == null)
317 throw new ArgumentNullException ("controls");
319 owner.SuspendLayout ();
322 for (int i = 0; i < controls.Length; i++)
325 owner.ResumeLayout ();
329 public virtual void Clear ()
331 owner.SuspendLayout();
332 for (int i = 0; i < list.Count; i++) {
333 owner.OnControlRemoved(new ControlEventArgs((Control)list[i]));
336 owner.ResumeLayout();
339 public virtual bool Contains (Control value)
341 return list.Contains (value);
344 public void CopyTo (Array array, int index)
346 list.CopyTo(array, index);
349 public override bool Equals(object other) {
350 if (other is ControlCollection && (((ControlCollection)other).owner==this.owner)) {
357 public int GetChildIndex(Control child) {
358 return GetChildIndex(child, false);
361 public int GetChildIndex(Control child, bool throwException) {
364 index=list.IndexOf(child);
366 if (index==-1 && throwException) {
367 throw new ArgumentException("Not a child control", "child");
372 public IEnumerator GetEnumerator() {
373 return list.GetEnumerator();
376 public override int GetHashCode() {
377 return base.GetHashCode();
380 public int IndexOf(Control control) {
381 return list.IndexOf(control);
384 public virtual void Remove(Control value) {
385 owner.OnControlRemoved(new ControlEventArgs(value));
387 owner.UpdateZOrder();
390 public void RemoveAt(int index) {
391 if (index<0 || index>=list.Count) {
392 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
395 owner.OnControlRemoved(new ControlEventArgs((Control)list[index]));
396 list.RemoveAt(index);
397 owner.UpdateZOrder();
400 public void SetChildIndex(Control child, int newIndex) {
403 old_index=list.IndexOf(child);
405 throw new ArgumentException("Not a child control", "child");
408 if (old_index==newIndex) {
414 if (newIndex>list.Count) {
417 list.Insert(newIndex, child);
419 owner.UpdateZOrder();
421 #endregion // ControlCollection Private Instance Methods
423 #region ControlCollection Interface Properties
424 object IList.this[int index] {
426 if (index<0 || index>=list.Count) {
427 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
433 if (!(value is Control)) {
434 throw new ArgumentException("Object of type Control required", "value");
437 list[index]=(Control)value;
441 bool IList.IsFixedSize {
447 bool IList.IsReadOnly {
449 return list.IsReadOnly;
453 bool ICollection.IsSynchronized {
455 return list.IsSynchronized;
459 object ICollection.SyncRoot {
461 return list.SyncRoot;
464 #endregion // ControlCollection Interface Properties
466 #region ControlCollection Interface Methods
467 int IList.Add(object value) {
469 throw new ArgumentNullException("value", "Cannot add null controls");
472 if (!(value is Control)) {
473 throw new ArgumentException("Object of type Control required", "value");
476 return list.Add(value);
479 bool IList.Contains(object value) {
480 if (!(value is Control)) {
481 throw new ArgumentException("Object of type Control required", "value");
484 return this.Contains((Control) value);
487 int IList.IndexOf(object value) {
488 if (!(value is Control)) {
489 throw new ArgumentException("Object of type Control required", "value");
492 return this.IndexOf((Control) value);
495 void IList.Insert(int index, object value) {
496 if (!(value is Control)) {
497 throw new ArgumentException("Object of type Control required", "value");
499 list.Insert(index, value);
502 void IList.Remove(object value) {
503 if (!(value is Control)) {
504 throw new ArgumentException("Object of type Control required", "value");
509 void ICollection.CopyTo(Array array, int index) {
511 list.CopyTo(array, index);
515 Object ICloneable.Clone() {
516 ControlCollection clone = new ControlCollection(this.owner);
517 clone.list=(ArrayList)list.Clone(); // FIXME: Do we need this?
520 #endregion // ControlCollection Interface Methods
522 #endregion // ControlCollection Class
524 #region Public Constructors
526 creator_thread = Thread.CurrentThread;
528 prev_size = Size.Empty;
529 anchor_style = AnchorStyles.Top | AnchorStyles.Left;
531 create_handled = false;
537 layout_pending = false;
539 causes_validation = true;
541 layout_suspended = 0;
542 double_buffering = true;
546 right_to_left = RightToLeft.Inherit;
548 control_style = ControlStyles.Selectable | ControlStyles.StandardClick | ControlStyles.StandardDoubleClick;
551 background_image = null;
555 child_controls = CreateControlsInstance();
556 client_size = new Size(DefaultSize.Width, DefaultSize.Height);
557 client_rect = new Rectangle(0, 0, DefaultSize.Width, DefaultSize.Height);
558 XplatUI.CalculateWindowRect(IntPtr.Zero, ref client_rect, CreateParams.Style, CreateParams.ExStyle, IntPtr.Zero, out bounds);
559 if ((CreateParams.Style & (int)WindowStyles.WS_CHILD) == 0) {
565 public Control(Control parent, string text) : this() {
570 public Control(Control parent, string text, int left, int top, int width, int height) : this() {
575 bounds.Height=height;
576 SetBoundsCore(left, top, width, height, BoundsSpecified.All);
580 public Control(string text) : this() {
584 public Control(string text, int left, int top, int width, int height) : this() {
588 bounds.Height=height;
589 SetBoundsCore(left, top, width, height, BoundsSpecified.All);
593 protected override void Dispose(bool disposing) {
606 controls.Remove(this);
608 #endregion // Public Constructors
610 #region Internal Properties
611 internal BorderStyle InternalBorderStyle {
617 if (border_style != value) {
618 border_style = value;
620 XplatUI.SetBorderStyle(window.Handle, border_style);
624 #endregion // Internal Properties
626 #region Private & Internal Methods
627 internal static IAsyncResult BeginInvokeInternal (Delegate method, object [] args) {
628 AsyncMethodResult result = new AsyncMethodResult ();
629 AsyncMethodData data = new AsyncMethodData ();
631 data.Method = method;
633 data.Result = new WeakReference (result);
635 XplatUI.SendAsyncMethod (data);
639 internal Graphics DeviceContext {
642 CreateBuffers(this.Width, this.Height);
648 internal Bitmap ImageBuffer {
651 CreateBuffers(this.Width, this.Height);
657 internal void CreateBuffers (int width, int height) {
658 if (double_buffering == false)
661 if (dc_mem != null) {
675 bmp_mem = new Bitmap (width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
676 dc_mem = Graphics.FromImage (bmp_mem);
679 internal void InvalidateBuffers ()
681 if (double_buffering == false)
684 if (dc_mem != null) {
694 internal static void SetChildColor(Control parent) {
697 for (int i=0; i < parent.child_controls.Count; i++) {
698 child=parent.child_controls[i];
699 if (child.IsHandleCreated) {
700 XplatUI.SetWindowBackground(child.window.Handle, child.BackColor);
702 if (child.child_controls.Count>0) {
703 SetChildColor(child);
709 internal bool Select(Control control) {
711 IContainerControl container;
713 if (control == null) {
717 parent = control.parent;
719 if (((control.control_style & ControlStyles.Selectable) !=0) && (parent != null)) {
720 while (parent != null) {
721 if (!parent.Visible || !parent.is_enabled) {
724 parent = parent.parent;
728 control.is_selected = true;
730 XplatUI.SetFocus(control.window.Handle);
731 container = GetContainerControl();
732 if (container != null) {
733 container.ActiveControl = control;
738 internal virtual void DoDefaultAction() {
739 // Only here to be overriden by our actual controls; this is needed by the accessibility class
742 internal static int LowOrder (int param) {
743 return (param & 0xffff);
746 internal static int HighOrder (int param) {
747 return (param >> 16);
750 internal static MouseButtons FromParamToMouseButtons (int param) {
751 MouseButtons buttons = MouseButtons.None;
753 if ((param & (int) MsgButtons.MK_LBUTTON) != 0)
754 buttons |= MouseButtons.Left;
756 if ((param & (int) MsgButtons.MK_MBUTTON) != 0)
757 buttons |= MouseButtons.Middle;
759 if ((param & (int) MsgButtons.MK_RBUTTON) != 0)
760 buttons |= MouseButtons.Right;
766 internal virtual bool ProcessControlMnemonic(char charCode) {
767 return ProcessMnemonic(charCode);
770 private static Control FindFlatForward(Control container, Control start) {
776 end = container.child_controls.Count;
779 index = start.tab_index;
784 for (int i = 0; i < end; i++) {
786 if (container.child_controls[i].tab_index > index) {
787 found = container.child_controls[i];
789 } else if (found.tab_index > container.child_controls[i].tab_index) {
790 if (container.child_controls[i].tab_index > index) {
791 found = container.child_controls[i];
798 private static Control FindControlForward(Control container, Control start) {
805 if ((start is IContainerControl) || start.GetStyle(ControlStyles.ContainerControl)) {
806 found = FindControlForward(start, null);
813 while (p != container) {
814 found = FindFlatForward(p, start);
822 return FindFlatForward(container, start);
825 private static Control FindFlatBackward(Control container, Control start) {
831 end = container.child_controls.Count;
834 index = start.tab_index;
836 // FIXME: Possible speed-up: Keep the highest taborder index in the container
838 for (int i = 0; i < end; i++) {
839 if (container.child_controls[i].tab_index > index) {
840 index = container.child_controls[i].tab_index;
846 for (int i = 0; i < end; i++) {
848 if (container.child_controls[i].tab_index < index) {
849 found = container.child_controls[i];
851 } else if (found.tab_index < container.child_controls[i].tab_index) {
852 if (container.child_controls[i].tab_index < index) {
853 found = container.child_controls[i];
860 private static Control FindControlBackward(Control container, Control start) {
866 found = FindFlatBackward(start.parent, start);
867 if (found == null && start.parent != container) {
872 found = FindFlatBackward(container, start);
875 while ((found != null) && ((found is IContainerControl) || found.GetStyle(ControlStyles.ContainerControl))) {
876 found = FindControlBackward(found, null);
885 private void HandleClick(int clicks) {
886 if (GetStyle(ControlStyles.StandardClick)) {
888 if (GetStyle(ControlStyles.StandardDoubleClick)) {
889 OnDoubleClick(EventArgs.Empty);
891 OnClick(EventArgs.Empty);
894 OnClick(EventArgs.Empty);
899 private void CheckDataBindings ()
901 if (data_bindings == null)
904 BindingContext binding_context = BindingContext;
905 foreach (Binding binding in data_bindings) {
906 binding.Check (binding_context);
910 #endregion // Private & Internal Methods
912 #region Public Static Properties
913 public static Color DefaultBackColor {
915 return ThemeEngine.Current.DefaultControlBackColor;
919 public static Font DefaultFont {
921 return ThemeEngine.Current.DefaultFont;
925 public static Color DefaultForeColor {
927 return ThemeEngine.Current.DefaultControlForeColor;
931 public static Keys ModifierKeys {
933 return XplatUI.State.ModifierKeys;
937 public static MouseButtons MouseButtons {
939 return XplatUI.State.MouseButtons;
943 public static Point MousePosition {
945 return Cursor.Position;
948 #endregion // Public Static Properties
950 #region Public Instance Properties
951 [EditorBrowsable(EditorBrowsableState.Advanced)]
953 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
954 public AccessibleObject AccessibilityObject {
956 if (accessibility_object==null) {
957 accessibility_object=CreateAccessibilityInstance();
959 return accessibility_object;
963 [EditorBrowsable(EditorBrowsableState.Advanced)]
965 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
966 public string AccessibleDefaultActionDescription {
968 return AccessibilityObject.default_action;
972 AccessibilityObject.default_action=value;
978 public string AccessibleDescription {
980 return AccessibilityObject.description;
984 AccessibilityObject.description=value;
990 public string AccessibleName {
992 return AccessibilityObject.Name;
996 AccessibilityObject.Name=value;
1000 [DefaultValue(AccessibleRole.Default)]
1001 public AccessibleRole AccessibleRole {
1003 return AccessibilityObject.role;
1007 AccessibilityObject.role=value;
1011 [DefaultValue(false)]
1012 public virtual bool AllowDrop {
1014 return XplatUI.State.DropTarget;
1018 XplatUI.State.DropTarget=value;
1023 [RefreshProperties(RefreshProperties.Repaint)]
1024 [DefaultValue(AnchorStyles.Top | AnchorStyles.Left)]
1025 public virtual AnchorStyles Anchor {
1027 return anchor_style;
1033 if (parent != null) {
1034 parent.PerformLayout(this, "Parent");
1040 public virtual Color BackColor {
1042 if (background_color.IsEmpty) {
1044 return parent.BackColor;
1046 return DefaultBackColor;
1048 return background_color;
1052 background_color=value;
1053 if (this.IsHandleCreated) {
1054 XplatUI.SetWindowBackground(this.window.Handle, value);
1056 SetChildColor(this);
1057 OnBackColorChanged(EventArgs.Empty);
1063 [DefaultValue(null)]
1064 public virtual Image BackgroundImage {
1066 return background_image;
1070 if (background_image!=value) {
1071 background_image=value;
1072 OnBackgroundImageChanged(EventArgs.Empty);
1077 [EditorBrowsable(EditorBrowsableState.Advanced)]
1079 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1080 public virtual BindingContext BindingContext {
1082 if (binding_context != null)
1083 return binding_context;
1086 binding_context = Parent.BindingContext;
1087 return binding_context;
1090 if (binding_context != value) {
1091 binding_context = value;
1092 OnBindingContextChanged(EventArgs.Empty);
1097 [EditorBrowsable(EditorBrowsableState.Advanced)]
1099 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1102 return bounds.Y+bounds.Height;
1106 [EditorBrowsable(EditorBrowsableState.Advanced)]
1108 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1109 public Rectangle Bounds {
1115 SetBoundsCore(value.Left, value.Top, value.Width, value.Height, BoundsSpecified.All);
1119 [EditorBrowsable(EditorBrowsableState.Advanced)]
1121 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1122 public bool CanFocus {
1124 if (Visible && is_enabled && GetStyle(ControlStyles.Selectable)) {
1131 [EditorBrowsable(EditorBrowsableState.Advanced)]
1133 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1134 public bool CanSelect {
1138 if (!GetStyle(ControlStyles.Selectable) || this.parent == null) {
1142 parent = this.parent;
1143 while (parent != null) {
1144 if (!parent.Visible || !parent.is_enabled) {
1148 parent = parent.parent;
1154 [EditorBrowsable(EditorBrowsableState.Advanced)]
1156 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1157 public bool Capture {
1159 return this.is_captured;
1163 if (this.IsHandleCreated) {
1164 if (value && !is_captured) {
1166 XplatUI.GrabWindow(this.window.Handle, IntPtr.Zero);
1167 } else if (!value && is_captured) {
1168 XplatUI.UngrabWindow(this.window.Handle);
1169 is_captured = false;
1175 [DefaultValue(true)]
1176 public bool CausesValidation {
1178 return this.causes_validation;
1182 if (this.causes_validation != value) {
1183 causes_validation = value;
1184 OnCausesValidationChanged(EventArgs.Empty);
1189 [EditorBrowsable(EditorBrowsableState.Advanced)]
1191 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1192 public Rectangle ClientRectangle {
1194 client_rect.Width = client_size.Width;
1195 client_rect.Height = client_size.Height;
1200 [EditorBrowsable(EditorBrowsableState.Advanced)]
1202 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1203 public Size ClientSize {
1206 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1207 return ((Form)this).form_parent_window.ClientSize;
1215 this.SetClientSizeCore(value.Width, value.Height);
1219 [EditorBrowsable(EditorBrowsableState.Advanced)]
1221 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1222 [DescriptionAttribute("ControlCompanyNameDescr")]
1223 public String CompanyName {
1225 return "Mono Project, Novell, Inc.";
1229 [EditorBrowsable(EditorBrowsableState.Advanced)]
1231 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1232 public bool ContainsFocus {
1238 for (int i=0; i < child_controls.Count; i++) {
1239 if (child_controls[i].ContainsFocus) {
1247 [DefaultValue(null)]
1248 public virtual ContextMenu ContextMenu {
1250 return context_menu;
1254 if (context_menu != value) {
1255 context_menu = value;
1256 OnContextMenuChanged(EventArgs.Empty);
1262 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
1263 public ControlCollection Controls {
1265 return this.child_controls;
1269 [EditorBrowsable(EditorBrowsableState.Advanced)]
1271 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1272 public bool Created {
1274 if (!this.is_disposed && (this.window.Handle != IntPtr.Zero)) {
1281 [AmbientValue(null)]
1282 public virtual Cursor Cursor {
1284 if (cursor != null) {
1288 if (parent != null) {
1289 return parent.Cursor;
1292 return Cursors.Default;
1296 if (cursor != value) {
1301 pt = Cursor.Position;
1302 if (bounds.Contains(pt)) {
1303 if (GetChildAtPoint(pt) == null) {
1304 if (cursor != null) {
1305 XplatUI.SetCursor(window.Handle, cursor.handle);
1307 if (parent != null) {
1308 XplatUI.SetCursor(window.Handle, parent.Cursor.handle);
1310 XplatUI.SetCursor(window.Handle, Cursors.def.handle);
1316 OnCursorChanged(EventArgs.Empty);
1322 [EditorBrowsable(EditorBrowsableState.Advanced)]
1324 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1325 public ControlBindingsCollection DataBindings {
1327 if (data_bindings == null)
1328 data_bindings = new ControlBindingsCollection (this);
1329 return data_bindings;
1333 [EditorBrowsable(EditorBrowsableState.Advanced)]
1335 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1336 public virtual Rectangle DisplayRectangle {
1338 return ClientRectangle;
1342 [EditorBrowsable(EditorBrowsableState.Advanced)]
1344 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1345 public bool Disposing {
1352 [RefreshProperties(RefreshProperties.Repaint)]
1353 [DefaultValue(DockStyle.None)]
1354 public virtual DockStyle Dock {
1360 if (dock_style == value) {
1366 if (parent != null) {
1367 parent.PerformLayout(this, "Parent");
1370 OnDockChanged(EventArgs.Empty);
1376 public bool Enabled {
1382 if (is_enabled == value) {
1388 OnEnabledChanged (EventArgs.Empty);
1392 [EditorBrowsable(EditorBrowsableState.Advanced)]
1394 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1395 public virtual bool Focused {
1397 return this.has_focus;
1402 [AmbientValue(null)]
1404 public virtual Font Font {
1410 if (Parent != null && Parent.Font != null) {
1418 if (font == value) {
1424 OnFontChanged (EventArgs.Empty);
1429 public virtual Color ForeColor {
1431 if (foreground_color.IsEmpty) {
1433 return parent.ForeColor;
1435 return DefaultForeColor;
1437 return foreground_color;
1441 if (foreground_color != value) {
1442 foreground_color=value;
1444 OnForeColorChanged(EventArgs.Empty);
1451 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1452 public IntPtr Handle { // IWin32Window
1454 if (!IsHandleCreated) {
1457 return window.Handle;
1461 [EditorBrowsable(EditorBrowsableState.Advanced)]
1463 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1464 public bool HasChildren {
1466 if (this.child_controls.Count>0) {
1473 [EditorBrowsable(EditorBrowsableState.Always)]
1475 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1478 return this.bounds.Height;
1482 SetBoundsCore(bounds.X, bounds.Y, bounds.Width, value, BoundsSpecified.Height);
1486 [AmbientValue(ImeMode.Inherit)]
1488 public ImeMode ImeMode {
1494 if (ime_mode != value) {
1497 OnImeModeChanged(EventArgs.Empty);
1502 [EditorBrowsable(EditorBrowsableState.Advanced)]
1504 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1505 public bool InvokeRequired { // ISynchronizeInvoke
1507 if (creator_thread!=Thread.CurrentThread) {
1514 [EditorBrowsable(EditorBrowsableState.Advanced)]
1516 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1517 public bool IsAccessible {
1519 return is_accessible;
1523 is_accessible = value;
1527 [EditorBrowsable(EditorBrowsableState.Advanced)]
1529 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1530 public bool IsDisposed {
1532 return this.is_disposed;
1536 [EditorBrowsable(EditorBrowsableState.Advanced)]
1538 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1539 public bool IsHandleCreated {
1541 if ((window!=null) && (window.Handle!=IntPtr.Zero)) {
1549 [EditorBrowsable(EditorBrowsableState.Always)]
1551 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1554 return this.bounds.X;
1558 SetBoundsCore(value, bounds.Y, bounds.Width, bounds.Height, BoundsSpecified.X);
1563 public Point Location {
1565 return new Point(bounds.X, bounds.Y);
1569 SetBoundsCore(value.X, value.Y, bounds.Width, bounds.Height, BoundsSpecified.Location);
1574 public string Name {
1585 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1586 public Control Parent {
1592 if (value == this) {
1593 throw new ArgumentException("A circular control reference has been made. A control cannot be owned or parented to itself.");
1596 if (parent!=value) {
1598 parent.Controls.Remove(this);
1603 if (!parent.Controls.Contains(this)) {
1604 parent.Controls.Add(this);
1607 XplatUI.SetParent(Handle, value.Handle);
1611 OnParentChanged(EventArgs.Empty);
1616 [EditorBrowsable(EditorBrowsableState.Advanced)]
1618 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1619 public string ProductName {
1621 return "Novell Mono MWF";
1625 [EditorBrowsable(EditorBrowsableState.Advanced)]
1627 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1628 public string ProductVersion {
1630 return "1.1.4322.573";
1634 [EditorBrowsable(EditorBrowsableState.Advanced)]
1636 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1637 public bool RecreatingHandle {
1639 return is_recreating;
1643 [EditorBrowsable(EditorBrowsableState.Advanced)]
1645 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1646 public Region Region {
1648 return new Region(this.bounds);
1655 g = this.CreateGraphics();
1656 r = value.GetBounds(g);
1658 SetBounds((int)r.X, (int)r.Y, (int)r.Width, (int)r.Height);
1664 [EditorBrowsable(EditorBrowsableState.Advanced)]
1666 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1669 return this.bounds.X+this.bounds.Width;
1673 [AmbientValue(RightToLeft.Inherit)]
1675 public virtual RightToLeft RightToLeft {
1677 return right_to_left;
1681 if (value != right_to_left) {
1682 right_to_left = value;
1683 OnRightToLeftChanged(EventArgs.Empty);
1688 [EditorBrowsable(EditorBrowsableState.Advanced)]
1689 public override ISite Site {
1702 return new Size(Width, Height);
1706 SetBoundsCore(bounds.X, bounds.Y, value.Width, value.Height, BoundsSpecified.Size);
1711 [MergableProperty(false)]
1712 public int TabIndex {
1714 if (tab_index != -1) {
1721 if (tab_index != value) {
1723 OnTabIndexChanged(EventArgs.Empty);
1729 [DefaultValue(true)]
1730 public bool TabStop {
1736 if (tab_stop != value) {
1738 OnTabStopChanged(EventArgs.Empty);
1743 [Localizable(false)]
1745 [TypeConverter(typeof(StringConverter))]
1746 [DefaultValue(null)]
1753 control_tag = value;
1759 [BindableAttribute(true)]
1760 public virtual string Text {
1766 if (value == null) {
1767 value = String.Empty;
1772 XplatUI.Text(Handle, text);
1773 // FIXME: Do we need a Refresh() here?
1774 OnTextChanged (EventArgs.Empty);
1779 [EditorBrowsable(EditorBrowsableState.Always)]
1781 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1784 return this.bounds.Y;
1788 SetBoundsCore(bounds.X, value, bounds.Width, bounds.Height, BoundsSpecified.Y);
1792 [EditorBrowsable(EditorBrowsableState.Advanced)]
1794 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1795 public Control TopLevelControl {
1799 while (p.parent != null) {
1808 public bool Visible {
1812 } else if (parent != null) {
1813 return parent.Visible;
1820 SetVisibleCore(value);
1824 [EditorBrowsable(EditorBrowsableState.Always)]
1826 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1829 return this.bounds.Width;
1833 SetBoundsCore(bounds.X, bounds.Y, value, bounds.Height, BoundsSpecified.Width);
1837 [EditorBrowsable(EditorBrowsableState.Never)]
1839 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1840 public IWindowTarget WindowTarget {
1849 #endregion // Public Instance Properties
1851 #region Protected Instance Properties
1852 protected virtual CreateParams CreateParams {
1854 CreateParams create_params = new CreateParams();
1856 create_params.Caption = Text;
1857 create_params.X = Left;
1858 create_params.Y = Top;
1859 create_params.Width = Width;
1860 create_params.Height = Height;
1862 create_params.ClassName = XplatUI.DefaultClassName;
1863 create_params.ClassStyle = 0;
1864 create_params.ExStyle = 0;
1865 create_params.Param = 0;
1868 create_params.Parent = parent.Handle;
1871 create_params.Style = (int)WindowStyles.WS_CHILD | (int)WindowStyles.WS_CLIPCHILDREN | (int)WindowStyles.WS_CLIPSIBLINGS;
1874 create_params.Style |= (int)WindowStyles.WS_VISIBLE;
1877 return create_params;
1881 protected virtual ImeMode DefaultImeMode {
1883 return ImeMode.Inherit;
1887 protected virtual Size DefaultSize {
1889 return new Size(100, 23);
1893 protected int FontHeight {
1903 protected bool RenderRightToLeft {
1905 return (this.right_to_left == RightToLeft.Yes);
1909 protected bool ResizeRedraw {
1911 return GetStyle(ControlStyles.ResizeRedraw);
1915 SetStyle(ControlStyles.ResizeRedraw, value);
1919 [EditorBrowsable(EditorBrowsableState.Advanced)]
1921 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1922 protected virtual bool ShowFocusCues {
1928 [EditorBrowsable(EditorBrowsableState.Advanced)]
1930 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1931 protected bool ShowKeyboardCues {
1936 #endregion // Protected Instance Properties
1938 #region Public Static Methods
1939 [EditorBrowsable(EditorBrowsableState.Advanced)]
1940 public static Control FromChildHandle(IntPtr handle) {
1941 IEnumerator control = Control.controls.GetEnumerator();
1943 while (control.MoveNext()) {
1944 if (((Control)control.Current).window.Handle == handle) {
1946 if (((Control)control.Current).Parent != null) {
1947 return ((Control)control.Current).Parent;
1954 [EditorBrowsable(EditorBrowsableState.Advanced)]
1955 public static Control FromHandle(IntPtr handle) {
1956 IEnumerator control = Control.controls.GetEnumerator();
1958 while (control.MoveNext()) {
1959 if (((Control)control.Current).window.Handle == handle) {
1961 return ((Control)control.Current);
1967 public static bool IsMnemonic(char charCode, string text) {
1970 amp = text.IndexOf('&');
1973 if (amp + 1 < text.Length) {
1974 if (text[amp + 1] != '&') {
1975 if (Char.ToUpper(charCode) == Char.ToUpper(text.ToCharArray(amp + 1, 1)[0])) {
1985 #region Protected Static Methods
1986 [EditorBrowsable(EditorBrowsableState.Advanced)]
1987 protected static bool ReflectMessage(IntPtr hWnd, ref Message m) {
1990 c = Control.FromHandle(hWnd);
2000 #region Public Instance Methods
2001 [EditorBrowsable(EditorBrowsableState.Advanced)]
2002 public IAsyncResult BeginInvoke(Delegate method) {
2003 return BeginInvokeInternal(method, null);
2006 [EditorBrowsable(EditorBrowsableState.Advanced)]
2007 public IAsyncResult BeginInvoke (Delegate method, object[] args) {
2008 return BeginInvokeInternal (method, args);
2011 public void BringToFront() {
2012 if ((parent != null) && (parent.child_controls[0]!=this)) {
2013 if (parent.child_controls.Contains(this)) {
2014 parent.child_controls.SetChildIndex(this, 0);
2018 XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, true, false);
2020 if (parent != null) {
2025 public bool Contains(Control ctl) {
2026 while (ctl != null) {
2035 public void CreateControl() {
2037 if (!IsHandleCreated) {
2041 if (!create_handled) {
2042 create_handled = true;
2046 for (int i=0; i<child_controls.Count; i++) {
2047 child_controls[i].CreateControl();
2051 public Graphics CreateGraphics() {
2052 if (!IsHandleCreated) {
2053 this.CreateControl();
2055 return Graphics.FromHwnd(this.window.Handle);
2058 [MonoTODO("Come up with cross platform drag-drop driver interface")]
2059 public DragDropEffects DoDragDrop(object data, DragDropEffects allowedEffects) {
2060 return DragDropEffects.None;
2063 [EditorBrowsable(EditorBrowsableState.Advanced)]
2064 public object EndInvoke (IAsyncResult async_result) {
2065 AsyncMethodResult result = (AsyncMethodResult) async_result;
2066 return result.EndInvoke ();
2069 public Form FindForm() {
2082 public bool Focus() {
2083 if (IsHandleCreated && !has_focus) {
2084 XplatUI.SetFocus(window.Handle);
2090 public Control GetChildAtPoint(Point pt) {
2091 // Microsoft's version of this function doesn't seem to work, so I can't check
2092 // if we only consider children or also grandchildren, etc.
2093 // I'm gonna say 'children only'
2094 for (int i=0; i<child_controls.Count; i++) {
2095 if (child_controls[i].Bounds.Contains(pt)) {
2096 return child_controls[i];
2102 public IContainerControl GetContainerControl() {
2103 Control current = this;
2105 while (current!=null) {
2106 if ((current is IContainerControl) && ((current.control_style & ControlStyles.ContainerControl)!=0)) {
2107 return (IContainerControl)current;
2109 current = current.parent;
2114 public Control GetNextControl(Control ctl, bool forward) {
2115 // If we're not a container we don't play
2116 if (!(this is IContainerControl) && !this.GetStyle(ControlStyles.ContainerControl)) {
2120 // If ctl is not contained by this, we start at the first child of this
2121 if (!this.Contains(ctl)) {
2125 // Search through our controls, starting at ctl, stepping into children as we encounter them
2126 // try to find the control with the tabindex closest to our own, or, if we're looking into
2127 // child controls, the one with the smallest tabindex
2129 return FindControlForward(this, ctl);
2131 return FindControlBackward(this, ctl);
2134 public void Hide() {
2135 this.Visible = false;
2138 public void Invalidate() {
2139 Invalidate(ClientRectangle, false);
2142 public void Invalidate(bool invalidateChildren) {
2143 Invalidate(ClientRectangle, invalidateChildren);
2146 public void Invalidate(System.Drawing.Rectangle rc) {
2147 Invalidate(rc, false);
2150 public void Invalidate(System.Drawing.Rectangle rc, bool invalidateChildren) {
2151 if (!IsHandleCreated || !Visible) {
2155 NotifyInvalidate(rc);
2157 XplatUI.Invalidate(Handle, rc, !GetStyle (ControlStyles.AllPaintingInWmPaint));
2159 if (invalidateChildren) {
2160 for (int i=0; i<child_controls.Count; i++) child_controls[i].Invalidate();
2162 OnInvalidated(new InvalidateEventArgs(rc));
2165 public void Invalidate(System.Drawing.Region region) {
2166 Invalidate(region, false);
2169 [MonoTODO("Figure out if GetRegionScans is usable")]
2170 public void Invalidate(System.Drawing.Region region, bool invalidateChildren) {
2171 throw new NotImplementedException();
2173 // FIXME - should use the GetRegionScans function of the region to invalidate each area
2174 //if (invalidateChildren) {
2175 // for (int i=0; i<child_controls.Count; i++) child_controls[i].Invalidate();
2179 public object Invoke (Delegate method) {
2180 return Invoke(method, null);
2183 public object Invoke (Delegate method, object[] args) {
2184 IAsyncResult result = BeginInvoke (method, args);
2185 return EndInvoke(result);
2188 [EditorBrowsable(EditorBrowsableState.Advanced)]
2189 public void PerformLayout() {
2190 PerformLayout(null, null);
2193 [EditorBrowsable(EditorBrowsableState.Advanced)]
2194 public void PerformLayout(Control affectedControl, string affectedProperty) {
2195 LayoutEventArgs levent = new LayoutEventArgs(affectedControl, affectedProperty);
2197 if (layout_suspended>0) {
2198 layout_pending = true;
2202 layout_pending = false;
2204 // Prevent us from getting messed up
2207 // Perform all Dock and Anchor calculations
2210 AnchorStyles anchor;
2215 space=this.DisplayRectangle;
2216 if (prev_size != Size.Empty) {
2217 diff_width = space.Width - prev_size.Width;
2218 diff_height = space.Height - prev_size.Height;
2224 // Deal with docking; go through in reverse, MS docs say that lowest Z-order is closest to edge
2225 for (int i = child_controls.Count - 1; i >= 0; i--) {
2226 child=child_controls[i];
2227 switch (child.Dock) {
2228 case DockStyle.None: {
2233 case DockStyle.Left: {
2234 child.SetBounds(space.Left, space.Y, child.Width, space.Height);
2235 space.X+=child.Width;
2236 space.Width-=child.Width;
2240 case DockStyle.Top: {
2241 child.SetBounds(space.Left, space.Y, space.Width, child.Height);
2242 space.Y+=child.Height;
2243 space.Height-=child.Height;
2247 case DockStyle.Right: {
2248 child.SetBounds(space.Right-child.Width, space.Y, child.Width, space.Height);
2249 space.Width-=child.Width;
2253 case DockStyle.Bottom: {
2254 child.SetBounds(space.Left, space.Bottom-child.Height, space.Width, child.Height);
2255 space.Height-=child.Height;
2261 for (int i = child_controls.Count - 1; i >= 0; i--) {
2262 child=child_controls[i];
2264 if (child.Dock == DockStyle.Fill) {
2265 child.SetBounds(space.Left, space.Top, space.Width, space.Height);
2271 space=this.DisplayRectangle;
2273 // Deal with anchoring
2274 for (int i=0; i < child_controls.Count; i++) {
2280 child=child_controls[i];
2281 anchor=child.Anchor;
2286 height=child.Height;
2288 // If the control is docked we don't need to do anything
2289 if (child.Dock != DockStyle.None) {
2293 if ((anchor & AnchorStyles.Left) !=0 ) {
2294 if ((anchor & AnchorStyles.Right) != 0) {
2295 // Anchoring to left and right
2296 width=width+diff_width;
2300 } else if ((anchor & AnchorStyles.Right) != 0) {
2306 if ((anchor & AnchorStyles.Top) !=0 ) {
2307 if ((anchor & AnchorStyles.Bottom) != 0) {
2308 height+=diff_height;
2312 } else if ((anchor & AnchorStyles.Bottom) != 0) {
2327 child.SetBounds(left, top, width, height);
2330 // Let everyone know
2334 // Need to make sure we decremend layout_suspended
2340 public Point PointToClient (Point p) {
2344 XplatUI.ScreenToClient (Handle, ref x, ref y);
2346 return new Point (x, y);
2349 public Point PointToScreen(Point p) {
2353 XplatUI.ClientToScreen(Handle, ref x, ref y);
2355 return new Point(x, y);
2358 public virtual bool PreProcessMessage(ref Message msg) {
2361 if ((msg.Msg == (int)Msg.WM_KEYDOWN) || (msg.Msg == (int)Msg.WM_SYSKEYDOWN)) {
2362 key_data = (Keys)msg.WParam.ToInt32();
2363 if (!ProcessCmdKey(ref msg, key_data)) {
2364 if (IsInputKey(key_data)) {
2368 return ProcessDialogKey(key_data);
2372 } else if (msg.Msg == (int)Msg.WM_CHAR) {
2373 if (IsInputChar((char)msg.WParam)) {
2376 } else if (msg.Msg == (int)Msg.WM_SYSCHAR) {
2377 if (IsInputChar((char)msg.WParam)) {
2380 return ProcessDialogChar((char)msg.WParam);
2385 public Rectangle RectangleToClient(Rectangle r) {
2386 return new Rectangle(PointToClient(r.Location), r.Size);
2389 public Rectangle RectangleToScreen(Rectangle r) {
2390 return new Rectangle(PointToScreen(r.Location), r.Size);
2393 public virtual void Refresh() {
2394 if (IsHandleCreated == true) {
2396 XplatUI.UpdateWindow(window.Handle);
2400 [EditorBrowsable(EditorBrowsableState.Never)]
2401 public virtual void ResetBackColor() {
2402 background_color = Color.Empty;
2405 #if haveDataBindings
2406 [EditorBrowsable(EditorBrowsableState.Never)]
2408 public void ResetBindings() {
2413 [EditorBrowsable(EditorBrowsableState.Never)]
2414 public virtual void ResetCursor() {
2418 [EditorBrowsable(EditorBrowsableState.Never)]
2419 public virtual void ResetFont() {
2423 [EditorBrowsable(EditorBrowsableState.Never)]
2424 public virtual void ResetForeColor() {
2425 foreground_color = Color.Empty;
2428 [EditorBrowsable(EditorBrowsableState.Never)]
2429 public void ResetImeMode() {
2430 ime_mode = DefaultImeMode;
2433 [EditorBrowsable(EditorBrowsableState.Never)]
2434 public virtual void ResetRightToLeft() {
2435 right_to_left = RightToLeft.Inherit;
2438 public virtual void ResetText() {
2442 public void ResumeLayout() {
2443 ResumeLayout (true);
2446 public void ResumeLayout(bool performLayout) {
2449 if (layout_suspended > 0) {
2453 if (performLayout || layout_pending) {
2458 public void Scale(float ratio) {
2459 ScaleCore(ratio, ratio);
2462 public void Scale(float dx, float dy) {
2466 public void Select() {
2467 Select(false, false);
2470 public bool SelectNextControl(Control ctl, bool forward, bool tabStopOnly, bool nested, bool wrap) {
2475 c = GetNextControl(c, forward);
2484 if (c.CanSelect && ((c.parent == ctl.parent) || nested) && (c.tab_stop || !tabStopOnly)) {
2488 } while (c != ctl); // If we wrap back to ourselves we stop
2493 public void SendToBack() {
2494 if ((parent != null) && (parent.child_controls[parent.child_controls.Count-1]!=this)) {
2495 if (parent.child_controls.Contains(this)) {
2496 parent.child_controls.SetChildIndex(this, parent.child_controls.Count);
2500 XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, false, true);
2501 if (parent != null) {
2506 public void SetBounds(int x, int y, int width, int height) {
2507 SetBoundsCore(x, y, width, height, BoundsSpecified.All);
2510 public void SetBounds(int x, int y, int width, int height, BoundsSpecified specified) {
2511 SetBoundsCore(x, y, width, height, specified);
2514 public void Show() {
2515 if (!IsHandleCreated) {
2516 this.CreateControl();
2522 public void SuspendLayout() {
2526 public void Update() {
2527 XplatUI.UpdateWindow(window.Handle);
2529 #endregion // Public Instance Methods
2531 #region Protected Instance Methods
2532 [EditorBrowsable(EditorBrowsableState.Advanced)]
2533 [MonoTODO("Implement this and tie it into Control.ControlAccessibleObject.NotifyClients")]
2534 protected void AccessibilityNotifyClients(AccessibleEvents accEvent, int childID) {
2535 throw new NotImplementedException();
2538 [EditorBrowsable(EditorBrowsableState.Advanced)]
2539 protected virtual AccessibleObject CreateAccessibilityInstance() {
2540 return new Control.ControlAccessibleObject(this);
2543 [EditorBrowsable(EditorBrowsableState.Advanced)]
2544 protected virtual ControlCollection CreateControlsInstance() {
2545 return new ControlCollection(this);
2548 [EditorBrowsable(EditorBrowsableState.Advanced)]
2549 protected virtual void CreateHandle() {
2551 throw new ObjectDisposedException(Name);
2554 if (IsHandleCreated) {
2559 window = new ControlNativeWindow(this);
2560 window.CreateHandle(CreateParams);
2562 // Find out where the window manager placed us
2567 if (window.Handle!=IntPtr.Zero) {
2568 if (!controls.Contains(window.Handle)) {
2572 creator_thread = Thread.CurrentThread;
2574 XplatUI.SetWindowBackground(window.Handle, this.BackColor);
2576 OnHandleCreated(EventArgs.Empty);
2580 [EditorBrowsable(EditorBrowsableState.Advanced)]
2581 protected virtual void DefWndProc(ref Message m) {
2582 window.DefWndProc(ref m);
2585 [EditorBrowsable(EditorBrowsableState.Advanced)]
2586 protected virtual void DestroyHandle() {
2587 if (IsHandleCreated) {
2588 // Destroy our children before we destroy ourselves, to prevent them from
2589 // being implictly (without us knowing) destroyed
2590 for (int i=0; i < child_controls.Count; i++) {
2591 child_controls[i].DestroyHandle();
2595 if (window != null) {
2596 window.DestroyHandle();
2598 OnHandleDestroyed(EventArgs.Empty);
2602 protected bool GetStyle(ControlStyles flag) {
2603 return (control_style & flag) != 0;
2606 protected bool GetTopLevel() {
2610 [EditorBrowsable(EditorBrowsableState.Advanced)]
2611 protected virtual void InitLayout() {
2612 if (parent != null) {
2613 parent.PerformLayout(this, "parent");
2617 [EditorBrowsable(EditorBrowsableState.Advanced)]
2618 protected void InvokeGotFocus(Control toInvoke, EventArgs e) {
2619 toInvoke.OnGotFocus(e);
2622 [EditorBrowsable(EditorBrowsableState.Advanced)]
2623 protected void InvokeLostFocus(Control toInvoke, EventArgs e) {
2624 toInvoke.OnLostFocus(e);
2627 [EditorBrowsable(EditorBrowsableState.Advanced)]
2628 protected void InvokeOnClick(Control toInvoke, EventArgs e) {
2629 toInvoke.OnClick(e);
2632 protected void InvokePaint(Control toInvoke, PaintEventArgs e) {
2633 toInvoke.OnPaint(e);
2636 protected void InvokePaintBackground(Control toInvoke, PaintEventArgs e) {
2637 toInvoke.OnPaintBackground(e);
2640 protected virtual bool IsInputChar (char charCode) {
2641 if (parent != null) {
2642 return parent.IsInputChar(charCode);
2648 protected virtual bool IsInputKey (Keys keyData) {
2649 // Doc says this one calls IsInputChar; not sure what to do with that
2653 [EditorBrowsable(EditorBrowsableState.Advanced)]
2654 protected virtual void NotifyInvalidate(Rectangle invalidatedArea) {
2658 protected virtual bool ProcessCmdKey(ref Message msg, Keys keyData) {
2659 if ((context_menu != null) && context_menu.ProcessCmdKey(ref msg, keyData)) {
2663 if (parent != null) {
2664 return parent.ProcessCmdKey(ref msg, keyData);
2670 protected virtual bool ProcessDialogChar(char charCode) {
2671 if (parent != null) {
2672 return parent.ProcessDialogChar (charCode);
2678 protected virtual bool ProcessDialogKey (Keys keyData) {
2679 if (parent != null) {
2680 return parent.ProcessDialogKey (keyData);
2686 protected virtual bool ProcessKeyEventArgs (ref Message msg)
2688 KeyEventArgs key_event;
2691 case (int)Msg.WM_KEYDOWN: {
2692 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
2693 OnKeyDown (key_event);
2694 return key_event.Handled;
2696 case (int)Msg.WM_KEYUP: {
2697 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
2698 OnKeyUp (key_event);
2699 return key_event.Handled;
2702 case (int)Msg.WM_CHAR: {
2703 KeyPressEventArgs key_press_event;
2705 key_press_event = new KeyPressEventArgs((char)msg.WParam);
2706 OnKeyPress(key_press_event);
2707 return key_press_event.Handled;
2718 protected internal virtual bool ProcessKeyMessage(ref Message msg) {
2719 if (parent != null) {
2720 if (parent.ProcessKeyPreview(ref msg)) {
2728 protected virtual bool ProcessKeyPreview(ref Message msg) {
2729 if (parent != null) {
2730 return parent.ProcessKeyPreview(ref msg);
2736 protected virtual bool ProcessMnemonic(char charCode) {
2741 [EditorBrowsable(EditorBrowsableState.Advanced)]
2742 protected void RaiseDragEvent(object key, DragEventArgs e) {
2746 [EditorBrowsable(EditorBrowsableState.Advanced)]
2747 protected void RaiseKeyEvent(object key, KeyEventArgs e) {
2751 [EditorBrowsable(EditorBrowsableState.Advanced)]
2752 protected void RaiseMouseEvent(object key, MouseEventArgs e) {
2756 [EditorBrowsable(EditorBrowsableState.Advanced)]
2757 protected void RaisePaintEvent(object key, PaintEventArgs e) {
2761 [EditorBrowsable(EditorBrowsableState.Advanced)]
2762 protected void RecreateHandle() {
2763 IEnumerator child = child_controls.GetEnumerator();
2767 if (IsHandleCreated) {
2773 while (child.MoveNext()) {
2774 ((Control)child.Current).RecreateHandle();
2780 is_recreating = false;
2783 [EditorBrowsable(EditorBrowsableState.Advanced)]
2784 protected void ResetMouseEventArgs() {
2788 [EditorBrowsable(EditorBrowsableState.Advanced)]
2789 protected ContentAlignment RtlTranslateAlignment(ContentAlignment align) {
2790 if (right_to_left == RightToLeft.No) {
2795 case ContentAlignment.TopLeft: {
2796 return ContentAlignment.TopRight;
2799 case ContentAlignment.TopRight: {
2800 return ContentAlignment.TopLeft;
2803 case ContentAlignment.MiddleLeft: {
2804 return ContentAlignment.MiddleRight;
2807 case ContentAlignment.MiddleRight: {
2808 return ContentAlignment.MiddleLeft;
2811 case ContentAlignment.BottomLeft: {
2812 return ContentAlignment.BottomRight;
2815 case ContentAlignment.BottomRight: {
2816 return ContentAlignment.BottomLeft;
2820 // if it's center it doesn't change
2826 [EditorBrowsable(EditorBrowsableState.Advanced)]
2827 protected HorizontalAlignment RtlTranslateAlignment(HorizontalAlignment align) {
2828 if ((right_to_left == RightToLeft.No) || (align == HorizontalAlignment.Center)) {
2832 if (align == HorizontalAlignment.Left) {
2833 return HorizontalAlignment.Right;
2836 // align must be HorizontalAlignment.Right
2837 return HorizontalAlignment.Left;
2840 [EditorBrowsable(EditorBrowsableState.Advanced)]
2841 protected LeftRightAlignment RtlTranslateAlignment(LeftRightAlignment align) {
2842 if (right_to_left == RightToLeft.No) {
2846 if (align == LeftRightAlignment.Left) {
2847 return LeftRightAlignment.Right;
2850 // align must be LeftRightAlignment.Right;
2851 return LeftRightAlignment.Left;
2854 [EditorBrowsable(EditorBrowsableState.Advanced)]
2855 protected ContentAlignment RtlTranslateContent(ContentAlignment align) {
2856 return RtlTranslateAlignment(align);
2859 [EditorBrowsable(EditorBrowsableState.Advanced)]
2860 protected HorizontalAlignment RtlTranslateHorizontal(HorizontalAlignment align) {
2861 return RtlTranslateAlignment(align);
2864 [EditorBrowsable(EditorBrowsableState.Advanced)]
2865 protected LeftRightAlignment RtlTranslateLeftRight(LeftRightAlignment align) {
2866 return RtlTranslateAlignment(align);
2869 [EditorBrowsable(EditorBrowsableState.Advanced)]
2870 protected virtual void ScaleCore(float dx, float dy) {
2876 location = new Point((int)(Left * dx), (int)(Top * dy));
2877 size = this.ClientSize;
2880 if (!GetStyle(ControlStyles.FixedWidth)) {
2881 size.Width = (int)(size.Width * dx);
2884 if (!GetStyle(ControlStyles.FixedHeight)) {
2885 size.Height = (int)(size.Height * dy);
2888 Location = location;
2891 /* Now scale our children */
2892 for (int i=0; i < child_controls.Count; i++) {
2893 child_controls[i].Scale(dx, dy);
2899 protected virtual void Select(bool directed, bool forward) {
2904 // Select this control
2909 if (parent == null) {
2913 // FIXME - this thing is doing the wrong stuff, needs to be similar to SelectNextControl
2915 index = parent.child_controls.IndexOf(this);
2920 if ((index+1) < parent.child_controls.Count) {
2929 index = parent.child_controls.Count-1;
2932 result = Select(parent.child_controls[index]);
2933 } while (!result && parent.child_controls[index] != this);
2936 [EditorBrowsable(EditorBrowsableState.Advanced)]
2937 protected virtual void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
2938 // SetBoundsCore updates the Win32 control itself. UpdateBounds updates the controls variables and fires events, I'm guessing - pdb
2939 if ((specified & BoundsSpecified.X) != BoundsSpecified.X) {
2943 if ((specified & BoundsSpecified.Y) != BoundsSpecified.Y) {
2947 if ((specified & BoundsSpecified.Width) != BoundsSpecified.Width) {
2951 if ((specified & BoundsSpecified.Height) != BoundsSpecified.Height) {
2955 if (IsHandleCreated) {
2956 XplatUI.SetWindowPos(Handle, x, y, width, height);
2958 UpdateBounds(x, y, width, height);
2961 [EditorBrowsable(EditorBrowsableState.Advanced)]
2962 protected virtual void SetClientSizeCore(int x, int y) {
2963 // Calculate the actual window size from the client size (it usually stays the same or grows)
2964 Rectangle ClientRect;
2965 Rectangle WindowRect;
2968 ClientRect = new Rectangle(0, 0, x, y);
2969 cp = this.CreateParams;
2971 if (XplatUI.CalculateWindowRect(Handle, ref ClientRect, cp.Style, cp.ExStyle, IntPtr.Zero, out WindowRect)==false) {
2975 SetBoundsCore(bounds.X, bounds.Y, WindowRect.Width, WindowRect.Height, BoundsSpecified.Size);
2978 [EditorBrowsable(EditorBrowsableState.Advanced)]
2979 protected void SetStyle(ControlStyles flag, bool value) {
2981 control_style |= flag;
2983 control_style &= ~flag;
2985 OnStyleChanged(EventArgs.Empty);
2988 protected void SetTopLevel(bool value) {
2989 if ((GetTopLevel() != value) && (parent != null)) {
2990 throw new Exception();
2994 if (value == true) {
3004 is_toplevel = value;
3007 protected virtual void SetVisibleCore(bool value) {
3008 if (value!=is_visible) {
3010 XplatUI.SetVisible(Handle, value);
3011 // Explicitly move Toplevel windows to where we want them;
3012 // apparently moving unmapped toplevel windows doesn't work
3013 if (is_visible && (this is Form)) {
3014 XplatUI.SetWindowPos(window.Handle, bounds.X, bounds.Y, bounds.Width, bounds.Height);
3016 OnVisibleChanged(EventArgs.Empty);
3019 if (dc_mem != null) {
3024 if (bmp_mem != null) {
3029 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.CreateControl();
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