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;
1019 XplatUI.State.DropTarget=value;
1025 [RefreshProperties(RefreshProperties.Repaint)]
1026 [DefaultValue(AnchorStyles.Top | AnchorStyles.Left)]
1027 public virtual AnchorStyles Anchor {
1029 return anchor_style;
1035 if (parent != null) {
1036 parent.PerformLayout(this, "Parent");
1042 public virtual Color BackColor {
1044 if (background_color.IsEmpty) {
1046 return parent.BackColor;
1048 return DefaultBackColor;
1050 return background_color;
1054 background_color=value;
1055 if (this.IsHandleCreated) {
1056 XplatUI.SetWindowBackground(this.window.Handle, value);
1058 SetChildColor(this);
1059 OnBackColorChanged(EventArgs.Empty);
1065 [DefaultValue(null)]
1066 public virtual Image BackgroundImage {
1068 return background_image;
1072 if (background_image!=value) {
1073 background_image=value;
1074 OnBackgroundImageChanged(EventArgs.Empty);
1079 [EditorBrowsable(EditorBrowsableState.Advanced)]
1081 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1082 public virtual BindingContext BindingContext {
1084 if (binding_context != null)
1085 return binding_context;
1088 binding_context = Parent.BindingContext;
1089 return binding_context;
1092 if (binding_context != value) {
1093 binding_context = value;
1094 OnBindingContextChanged(EventArgs.Empty);
1099 [EditorBrowsable(EditorBrowsableState.Advanced)]
1101 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1104 return bounds.Y+bounds.Height;
1108 [EditorBrowsable(EditorBrowsableState.Advanced)]
1110 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1111 public Rectangle Bounds {
1117 SetBoundsCore(value.Left, value.Top, value.Width, value.Height, BoundsSpecified.All);
1121 [EditorBrowsable(EditorBrowsableState.Advanced)]
1123 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1124 public bool CanFocus {
1126 if (Visible && is_enabled && GetStyle(ControlStyles.Selectable)) {
1133 [EditorBrowsable(EditorBrowsableState.Advanced)]
1135 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1136 public bool CanSelect {
1140 if (!GetStyle(ControlStyles.Selectable) || this.parent == null) {
1144 parent = this.parent;
1145 while (parent != null) {
1146 if (!parent.is_visible || !parent.is_enabled) {
1150 parent = parent.parent;
1156 [EditorBrowsable(EditorBrowsableState.Advanced)]
1158 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1159 public bool Capture {
1161 return this.is_captured;
1165 if (this.IsHandleCreated) {
1166 if (value && !is_captured) {
1168 XplatUI.GrabWindow(this.window.Handle, IntPtr.Zero);
1169 } else if (!value && is_captured) {
1170 XplatUI.UngrabWindow(this.window.Handle);
1171 is_captured = false;
1177 [DefaultValue(true)]
1178 public bool CausesValidation {
1180 return this.causes_validation;
1184 if (this.causes_validation != value) {
1185 causes_validation = value;
1186 OnCausesValidationChanged(EventArgs.Empty);
1191 [EditorBrowsable(EditorBrowsableState.Advanced)]
1193 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1194 public Rectangle ClientRectangle {
1196 client_rect.Width = client_size.Width;
1197 client_rect.Height = client_size.Height;
1202 [EditorBrowsable(EditorBrowsableState.Advanced)]
1204 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1205 public Size ClientSize {
1208 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1209 return ((Form)this).form_parent_window.ClientSize;
1217 this.SetClientSizeCore(value.Width, value.Height);
1221 [EditorBrowsable(EditorBrowsableState.Advanced)]
1223 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1224 [DescriptionAttribute("ControlCompanyNameDescr")]
1225 public String CompanyName {
1227 return "Mono Project, Novell, Inc.";
1231 [EditorBrowsable(EditorBrowsableState.Advanced)]
1233 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1234 public bool ContainsFocus {
1240 for (int i=0; i < child_controls.Count; i++) {
1241 if (child_controls[i].ContainsFocus) {
1249 [DefaultValue(null)]
1250 public virtual ContextMenu ContextMenu {
1252 return context_menu;
1256 if (context_menu != value) {
1257 context_menu = value;
1258 OnContextMenuChanged(EventArgs.Empty);
1264 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
1265 public ControlCollection Controls {
1267 return this.child_controls;
1271 [EditorBrowsable(EditorBrowsableState.Advanced)]
1273 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1274 public bool Created {
1276 if (!this.is_disposed && (this.window.Handle != IntPtr.Zero)) {
1283 [AmbientValue(null)]
1284 public virtual Cursor Cursor {
1286 if (cursor != null) {
1290 if (parent != null) {
1291 return parent.Cursor;
1294 return Cursors.Default;
1298 if (cursor != value) {
1303 pt = Cursor.Position;
1304 if (bounds.Contains(pt)) {
1305 if (GetChildAtPoint(pt) == null) {
1306 if (cursor != null) {
1307 XplatUI.SetCursor(window.Handle, cursor.handle);
1309 if (parent != null) {
1310 XplatUI.SetCursor(window.Handle, parent.Cursor.handle);
1312 XplatUI.SetCursor(window.Handle, Cursors.def.handle);
1318 OnCursorChanged(EventArgs.Empty);
1324 [EditorBrowsable(EditorBrowsableState.Advanced)]
1326 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1327 public ControlBindingsCollection DataBindings {
1329 if (data_bindings == null)
1330 data_bindings = new ControlBindingsCollection (this);
1331 return data_bindings;
1335 [EditorBrowsable(EditorBrowsableState.Advanced)]
1337 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1338 public virtual Rectangle DisplayRectangle {
1340 return ClientRectangle;
1344 [EditorBrowsable(EditorBrowsableState.Advanced)]
1346 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1347 public bool Disposing {
1354 [RefreshProperties(RefreshProperties.Repaint)]
1355 [DefaultValue(DockStyle.None)]
1356 public virtual DockStyle Dock {
1362 if (dock_style == value) {
1368 if (parent != null) {
1369 parent.PerformLayout(this, "Parent");
1372 OnDockChanged(EventArgs.Empty);
1378 public bool Enabled {
1384 if (is_enabled == value) {
1390 OnEnabledChanged (EventArgs.Empty);
1394 [EditorBrowsable(EditorBrowsableState.Advanced)]
1396 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1397 public virtual bool Focused {
1399 return this.has_focus;
1404 [AmbientValue(null)]
1406 public virtual Font Font {
1412 if (Parent != null && Parent.Font != null) {
1420 if (font.Equals (value)) {
1426 OnFontChanged (EventArgs.Empty);
1431 public virtual Color ForeColor {
1433 if (foreground_color.IsEmpty) {
1435 return parent.ForeColor;
1437 return DefaultForeColor;
1439 return foreground_color;
1443 if (foreground_color != value) {
1444 foreground_color=value;
1446 OnForeColorChanged(EventArgs.Empty);
1453 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1454 public IntPtr Handle { // IWin32Window
1456 if (!IsHandleCreated) {
1459 return window.Handle;
1463 [EditorBrowsable(EditorBrowsableState.Advanced)]
1465 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1466 public bool HasChildren {
1468 if (this.child_controls.Count>0) {
1475 [EditorBrowsable(EditorBrowsableState.Always)]
1477 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1480 return this.bounds.Height;
1484 SetBoundsCore(bounds.X, bounds.Y, bounds.Width, value, BoundsSpecified.Height);
1488 [AmbientValue(ImeMode.Inherit)]
1490 public ImeMode ImeMode {
1496 if (ime_mode != value) {
1499 OnImeModeChanged(EventArgs.Empty);
1504 [EditorBrowsable(EditorBrowsableState.Advanced)]
1506 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1507 public bool InvokeRequired { // ISynchronizeInvoke
1509 if (creator_thread!=Thread.CurrentThread) {
1516 [EditorBrowsable(EditorBrowsableState.Advanced)]
1518 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1519 public bool IsAccessible {
1521 return is_accessible;
1525 is_accessible = value;
1529 [EditorBrowsable(EditorBrowsableState.Advanced)]
1531 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1532 public bool IsDisposed {
1534 return this.is_disposed;
1538 [EditorBrowsable(EditorBrowsableState.Advanced)]
1540 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1541 public bool IsHandleCreated {
1543 if ((window!=null) && (window.Handle!=IntPtr.Zero)) {
1551 [EditorBrowsable(EditorBrowsableState.Always)]
1553 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1556 return this.bounds.X;
1560 SetBoundsCore(value, bounds.Y, bounds.Width, bounds.Height, BoundsSpecified.X);
1565 public Point Location {
1567 return new Point(bounds.X, bounds.Y);
1571 SetBoundsCore(value.X, value.Y, bounds.Width, bounds.Height, BoundsSpecified.Location);
1576 public string Name {
1587 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1588 public Control Parent {
1594 if (value == this) {
1595 throw new ArgumentException("A circular control reference has been made. A control cannot be owned or parented to itself.");
1598 if (parent!=value) {
1600 parent.Controls.Remove(this);
1605 if (!parent.Controls.Contains(this)) {
1606 parent.Controls.Add(this);
1609 XplatUI.SetParent(Handle, value.Handle);
1613 OnParentChanged(EventArgs.Empty);
1618 [EditorBrowsable(EditorBrowsableState.Advanced)]
1620 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1621 public string ProductName {
1623 return "Novell Mono MWF";
1627 [EditorBrowsable(EditorBrowsableState.Advanced)]
1629 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1630 public string ProductVersion {
1632 return "1.1.4322.573";
1636 [EditorBrowsable(EditorBrowsableState.Advanced)]
1638 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1639 public bool RecreatingHandle {
1641 return is_recreating;
1645 [EditorBrowsable(EditorBrowsableState.Advanced)]
1647 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1648 public Region Region {
1650 return new Region(this.bounds);
1657 g = this.CreateGraphics();
1658 r = value.GetBounds(g);
1660 SetBounds((int)r.X, (int)r.Y, (int)r.Width, (int)r.Height);
1666 [EditorBrowsable(EditorBrowsableState.Advanced)]
1668 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1671 return this.bounds.X+this.bounds.Width;
1675 [AmbientValue(RightToLeft.Inherit)]
1677 public virtual RightToLeft RightToLeft {
1679 return right_to_left;
1683 if (value != right_to_left) {
1684 right_to_left = value;
1685 OnRightToLeftChanged(EventArgs.Empty);
1690 [EditorBrowsable(EditorBrowsableState.Advanced)]
1691 public override ISite Site {
1704 return new Size(Width, Height);
1708 SetBoundsCore(bounds.X, bounds.Y, value.Width, value.Height, BoundsSpecified.Size);
1713 [MergableProperty(false)]
1714 public int TabIndex {
1716 if (tab_index != -1) {
1723 if (tab_index != value) {
1725 OnTabIndexChanged(EventArgs.Empty);
1731 [DefaultValue(true)]
1732 public bool TabStop {
1738 if (tab_stop != value) {
1740 OnTabStopChanged(EventArgs.Empty);
1745 [Localizable(false)]
1747 [TypeConverter(typeof(StringConverter))]
1748 [DefaultValue(null)]
1755 control_tag = value;
1761 [BindableAttribute(true)]
1762 public virtual string Text {
1768 if (value == null) {
1769 value = String.Empty;
1774 XplatUI.Text(Handle, text);
1775 // FIXME: Do we need a Refresh() here?
1776 OnTextChanged (EventArgs.Empty);
1781 [EditorBrowsable(EditorBrowsableState.Always)]
1783 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1786 return this.bounds.Y;
1790 SetBoundsCore(bounds.X, value, bounds.Width, bounds.Height, BoundsSpecified.Y);
1794 [EditorBrowsable(EditorBrowsableState.Advanced)]
1796 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1797 public Control TopLevelControl {
1801 while (p.parent != null) {
1810 public bool Visible {
1814 } else if (parent != null) {
1815 return parent.Visible;
1822 SetVisibleCore(value);
1826 [EditorBrowsable(EditorBrowsableState.Always)]
1828 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1831 return this.bounds.Width;
1835 SetBoundsCore(bounds.X, bounds.Y, value, bounds.Height, BoundsSpecified.Width);
1839 [EditorBrowsable(EditorBrowsableState.Never)]
1841 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1842 public IWindowTarget WindowTarget {
1851 #endregion // Public Instance Properties
1853 #region Protected Instance Properties
1854 protected virtual CreateParams CreateParams {
1856 CreateParams create_params = new CreateParams();
1858 create_params.Caption = Text;
1859 create_params.X = Left;
1860 create_params.Y = Top;
1861 create_params.Width = Width;
1862 create_params.Height = Height;
1864 create_params.ClassName = XplatUI.DefaultClassName;
1865 create_params.ClassStyle = 0;
1866 create_params.ExStyle = 0;
1867 create_params.Param = 0;
1870 create_params.Parent = parent.Handle;
1873 create_params.Style = (int)WindowStyles.WS_CHILD | (int)WindowStyles.WS_CLIPCHILDREN | (int)WindowStyles.WS_CLIPSIBLINGS;
1876 create_params.Style |= (int)WindowStyles.WS_VISIBLE;
1879 return create_params;
1883 protected virtual ImeMode DefaultImeMode {
1885 return ImeMode.Inherit;
1889 protected virtual Size DefaultSize {
1891 return new Size(100, 23);
1895 protected int FontHeight {
1905 protected bool RenderRightToLeft {
1907 return (this.right_to_left == RightToLeft.Yes);
1911 protected bool ResizeRedraw {
1913 return GetStyle(ControlStyles.ResizeRedraw);
1917 SetStyle(ControlStyles.ResizeRedraw, value);
1921 [EditorBrowsable(EditorBrowsableState.Advanced)]
1923 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1924 protected virtual bool ShowFocusCues {
1930 [EditorBrowsable(EditorBrowsableState.Advanced)]
1932 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1933 protected bool ShowKeyboardCues {
1938 #endregion // Protected Instance Properties
1940 #region Public Static Methods
1941 [EditorBrowsable(EditorBrowsableState.Advanced)]
1942 public static Control FromChildHandle(IntPtr handle) {
1943 IEnumerator control = Control.controls.GetEnumerator();
1945 while (control.MoveNext()) {
1946 if (((Control)control.Current).window.Handle == handle) {
1948 if (((Control)control.Current).Parent != null) {
1949 return ((Control)control.Current).Parent;
1956 [EditorBrowsable(EditorBrowsableState.Advanced)]
1957 public static Control FromHandle(IntPtr handle) {
1958 IEnumerator control = Control.controls.GetEnumerator();
1960 while (control.MoveNext()) {
1961 if (((Control)control.Current).window.Handle == handle) {
1963 return ((Control)control.Current);
1969 public static bool IsMnemonic(char charCode, string text) {
1972 amp = text.IndexOf('&');
1975 if (amp + 1 < text.Length) {
1976 if (text[amp + 1] != '&') {
1977 if (Char.ToUpper(charCode) == Char.ToUpper(text.ToCharArray(amp + 1, 1)[0])) {
1987 #region Protected Static Methods
1988 [EditorBrowsable(EditorBrowsableState.Advanced)]
1989 protected static bool ReflectMessage(IntPtr hWnd, ref Message m) {
1992 c = Control.FromHandle(hWnd);
2002 #region Public Instance Methods
2003 [EditorBrowsable(EditorBrowsableState.Advanced)]
2004 public IAsyncResult BeginInvoke(Delegate method) {
2005 return BeginInvokeInternal(method, null);
2008 [EditorBrowsable(EditorBrowsableState.Advanced)]
2009 public IAsyncResult BeginInvoke (Delegate method, object[] args) {
2010 return BeginInvokeInternal (method, args);
2013 public void BringToFront() {
2014 if ((parent != null) && (parent.child_controls[0]!=this)) {
2015 if (parent.child_controls.Contains(this)) {
2016 parent.child_controls.SetChildIndex(this, 0);
2020 XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, true, false);
2022 if (parent != null) {
2027 public bool Contains(Control ctl) {
2028 while (ctl != null) {
2037 public void CreateControl() {
2039 if (!IsHandleCreated) {
2043 if (!create_handled) {
2044 create_handled = true;
2048 for (int i=0; i<child_controls.Count; i++) {
2049 child_controls[i].CreateControl();
2053 public Graphics CreateGraphics() {
2054 if (!IsHandleCreated) {
2055 this.CreateControl();
2057 return Graphics.FromHwnd(this.window.Handle);
2060 [MonoTODO("Come up with cross platform drag-drop driver interface")]
2061 public DragDropEffects DoDragDrop(object data, DragDropEffects allowedEffects) {
2062 return DragDropEffects.None;
2065 [EditorBrowsable(EditorBrowsableState.Advanced)]
2066 public object EndInvoke (IAsyncResult async_result) {
2067 AsyncMethodResult result = (AsyncMethodResult) async_result;
2068 return result.EndInvoke ();
2071 public Form FindForm() {
2084 public bool Focus() {
2085 if (IsHandleCreated && !has_focus) {
2087 XplatUI.SetFocus(window.Handle);
2092 public Control GetChildAtPoint(Point pt) {
2093 // Microsoft's version of this function doesn't seem to work, so I can't check
2094 // if we only consider children or also grandchildren, etc.
2095 // I'm gonna say 'children only'
2096 for (int i=0; i<child_controls.Count; i++) {
2097 if (child_controls[i].Bounds.Contains(pt)) {
2098 return child_controls[i];
2104 public IContainerControl GetContainerControl() {
2105 Control current = this;
2107 while (current!=null) {
2108 if ((current is IContainerControl) && ((current.control_style & ControlStyles.ContainerControl)!=0)) {
2109 return (IContainerControl)current;
2111 current = current.parent;
2116 public Control GetNextControl(Control ctl, bool forward) {
2117 // If we're not a container we don't play
2118 if (!(this is IContainerControl) && !this.GetStyle(ControlStyles.ContainerControl)) {
2122 // If ctl is not contained by this, we start at the first child of this
2123 if (!this.Contains(ctl)) {
2127 // Search through our controls, starting at ctl, stepping into children as we encounter them
2128 // try to find the control with the tabindex closest to our own, or, if we're looking into
2129 // child controls, the one with the smallest tabindex
2131 return FindControlForward(this, ctl);
2133 return FindControlBackward(this, ctl);
2136 public void Hide() {
2137 this.Visible = false;
2140 public void Invalidate() {
2141 Invalidate(ClientRectangle, false);
2144 public void Invalidate(bool invalidateChildren) {
2145 Invalidate(ClientRectangle, invalidateChildren);
2148 public void Invalidate(System.Drawing.Rectangle rc) {
2149 Invalidate(rc, false);
2152 public void Invalidate(System.Drawing.Rectangle rc, bool invalidateChildren) {
2153 if (!IsHandleCreated || !Visible) {
2157 NotifyInvalidate(rc);
2159 XplatUI.Invalidate(Handle, rc, false);
2161 if (invalidateChildren) {
2162 for (int i=0; i<child_controls.Count; i++) child_controls[i].Invalidate();
2164 OnInvalidated(new InvalidateEventArgs(rc));
2167 public void Invalidate(System.Drawing.Region region) {
2168 Invalidate(region, false);
2171 [MonoTODO("Figure out if GetRegionScans is usable")]
2172 public void Invalidate(System.Drawing.Region region, bool invalidateChildren) {
2173 throw new NotImplementedException();
2175 // FIXME - should use the GetRegionScans function of the region to invalidate each area
2176 //if (invalidateChildren) {
2177 // for (int i=0; i<child_controls.Count; i++) child_controls[i].Invalidate();
2181 public object Invoke (Delegate method) {
2182 return Invoke(method, null);
2185 public object Invoke (Delegate method, object[] args) {
2186 IAsyncResult result = BeginInvoke (method, args);
2187 return EndInvoke(result);
2190 [EditorBrowsable(EditorBrowsableState.Advanced)]
2191 public void PerformLayout() {
2192 PerformLayout(null, null);
2195 [EditorBrowsable(EditorBrowsableState.Advanced)]
2196 public void PerformLayout(Control affectedControl, string affectedProperty) {
2197 LayoutEventArgs levent = new LayoutEventArgs(affectedControl, affectedProperty);
2199 if (layout_suspended>0) {
2200 layout_pending = true;
2204 layout_pending = false;
2206 // Prevent us from getting messed up
2209 // Perform all Dock and Anchor calculations
2212 AnchorStyles anchor;
2217 space=this.DisplayRectangle;
2218 if (prev_size != Size.Empty) {
2219 diff_width = space.Width - prev_size.Width;
2220 diff_height = space.Height - prev_size.Height;
2226 // Deal with docking; go through in reverse, MS docs say that lowest Z-order is closest to edge
2227 for (int i = child_controls.Count - 1; i >= 0; i--) {
2228 child=child_controls[i];
2229 switch (child.Dock) {
2230 case DockStyle.None: {
2235 case DockStyle.Left: {
2236 child.SetBounds(space.Left, space.Y, child.Width, space.Height);
2237 space.X+=child.Width;
2238 space.Width-=child.Width;
2242 case DockStyle.Top: {
2243 child.SetBounds(space.Left, space.Y, space.Width, child.Height);
2244 space.Y+=child.Height;
2245 space.Height-=child.Height;
2249 case DockStyle.Right: {
2250 child.SetBounds(space.Right-child.Width, space.Y, child.Width, space.Height);
2251 space.Width-=child.Width;
2255 case DockStyle.Bottom: {
2256 child.SetBounds(space.Left, space.Bottom-child.Height, space.Width, child.Height);
2257 space.Height-=child.Height;
2263 for (int i = child_controls.Count - 1; i >= 0; i--) {
2264 child=child_controls[i];
2266 if (child.Dock == DockStyle.Fill) {
2267 child.SetBounds(space.Left, space.Top, space.Width, space.Height);
2273 space=this.DisplayRectangle;
2275 // Deal with anchoring
2276 for (int i=0; i < child_controls.Count; i++) {
2282 child=child_controls[i];
2283 anchor=child.Anchor;
2288 height=child.Height;
2290 // If the control is docked we don't need to do anything
2291 if (child.Dock != DockStyle.None) {
2295 if ((anchor & AnchorStyles.Left) !=0 ) {
2296 if ((anchor & AnchorStyles.Right) != 0) {
2297 // Anchoring to left and right
2298 width=width+diff_width;
2302 } else if ((anchor & AnchorStyles.Right) != 0) {
2308 if ((anchor & AnchorStyles.Top) !=0 ) {
2309 if ((anchor & AnchorStyles.Bottom) != 0) {
2310 height+=diff_height;
2314 } else if ((anchor & AnchorStyles.Bottom) != 0) {
2329 child.SetBounds(left, top, width, height);
2332 // Let everyone know
2336 // Need to make sure we decremend layout_suspended
2342 public Point PointToClient (Point p) {
2346 XplatUI.ScreenToClient (Handle, ref x, ref y);
2348 return new Point (x, y);
2351 public Point PointToScreen(Point p) {
2355 XplatUI.ClientToScreen(Handle, ref x, ref y);
2357 return new Point(x, y);
2360 public virtual bool PreProcessMessage(ref Message msg) {
2363 if ((msg.Msg == (int)Msg.WM_KEYDOWN) || (msg.Msg == (int)Msg.WM_SYSKEYDOWN)) {
2364 key_data = (Keys)msg.WParam.ToInt32();
2365 if (!ProcessCmdKey(ref msg, key_data)) {
2366 if (IsInputKey(key_data)) {
2370 return ProcessDialogKey(key_data);
2374 } else if (msg.Msg == (int)Msg.WM_CHAR) {
2375 if (IsInputChar((char)msg.WParam)) {
2378 } else if (msg.Msg == (int)Msg.WM_SYSCHAR) {
2379 if (IsInputChar((char)msg.WParam)) {
2382 return ProcessDialogChar((char)msg.WParam);
2387 public Rectangle RectangleToClient(Rectangle r) {
2388 return new Rectangle(PointToClient(r.Location), r.Size);
2391 public Rectangle RectangleToScreen(Rectangle r) {
2392 return new Rectangle(PointToScreen(r.Location), r.Size);
2395 public virtual void Refresh() {
2396 if (IsHandleCreated == true) {
2398 XplatUI.UpdateWindow(window.Handle);
2402 [EditorBrowsable(EditorBrowsableState.Never)]
2403 public virtual void ResetBackColor() {
2404 background_color = Color.Empty;
2407 #if haveDataBindings
2408 [EditorBrowsable(EditorBrowsableState.Never)]
2410 public void ResetBindings() {
2415 [EditorBrowsable(EditorBrowsableState.Never)]
2416 public virtual void ResetCursor() {
2420 [EditorBrowsable(EditorBrowsableState.Never)]
2421 public virtual void ResetFont() {
2425 [EditorBrowsable(EditorBrowsableState.Never)]
2426 public virtual void ResetForeColor() {
2427 foreground_color = Color.Empty;
2430 [EditorBrowsable(EditorBrowsableState.Never)]
2431 public void ResetImeMode() {
2432 ime_mode = DefaultImeMode;
2435 [EditorBrowsable(EditorBrowsableState.Never)]
2436 public virtual void ResetRightToLeft() {
2437 right_to_left = RightToLeft.Inherit;
2440 public virtual void ResetText() {
2444 public void ResumeLayout() {
2445 ResumeLayout (true);
2448 public void ResumeLayout(bool performLayout) {
2451 if (layout_suspended > 0) {
2455 if (performLayout || layout_pending) {
2460 public void Scale(float ratio) {
2461 ScaleCore(ratio, ratio);
2464 public void Scale(float dx, float dy) {
2468 public void Select() {
2469 Select(false, false);
2472 public bool SelectNextControl(Control ctl, bool forward, bool tabStopOnly, bool nested, bool wrap) {
2477 c = GetNextControl(c, forward);
2486 if (c.CanSelect && ((c.parent == ctl.parent) || nested) && (c.tab_stop || !tabStopOnly)) {
2490 } while (c != ctl); // If we wrap back to ourselves we stop
2495 public void SendToBack() {
2496 if ((parent != null) && (parent.child_controls[parent.child_controls.Count-1]!=this)) {
2497 if (parent.child_controls.Contains(this)) {
2498 parent.child_controls.SetChildIndex(this, parent.child_controls.Count);
2502 XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, false, true);
2503 if (parent != null) {
2508 public void SetBounds(int x, int y, int width, int height) {
2509 SetBoundsCore(x, y, width, height, BoundsSpecified.All);
2512 public void SetBounds(int x, int y, int width, int height, BoundsSpecified specified) {
2513 SetBoundsCore(x, y, width, height, specified);
2516 public void Show() {
2517 if (!IsHandleCreated) {
2518 this.CreateControl();
2524 public void SuspendLayout() {
2528 public void Update() {
2529 XplatUI.UpdateWindow(window.Handle);
2531 #endregion // Public Instance Methods
2533 #region Protected Instance Methods
2534 [EditorBrowsable(EditorBrowsableState.Advanced)]
2535 [MonoTODO("Implement this and tie it into Control.ControlAccessibleObject.NotifyClients")]
2536 protected void AccessibilityNotifyClients(AccessibleEvents accEvent, int childID) {
2537 throw new NotImplementedException();
2540 [EditorBrowsable(EditorBrowsableState.Advanced)]
2541 protected virtual AccessibleObject CreateAccessibilityInstance() {
2542 return new Control.ControlAccessibleObject(this);
2545 [EditorBrowsable(EditorBrowsableState.Advanced)]
2546 protected virtual ControlCollection CreateControlsInstance() {
2547 return new ControlCollection(this);
2550 [EditorBrowsable(EditorBrowsableState.Advanced)]
2551 protected virtual void CreateHandle() {
2553 throw new ObjectDisposedException(Name);
2556 if (IsHandleCreated) {
2561 window = new ControlNativeWindow(this);
2562 window.CreateHandle(CreateParams);
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);
3036 if (value == false && parent != null) {
3039 // Need to start at parent, GetContainerControl might return ourselves if we're a container
3040 container = (Control)parent.GetContainerControl();
3041 if (container != null) {
3042 container.SelectNextControl(this, true, true, true, true);
3046 if (parent != null) {
3047 parent.PerformLayout(this, "visible");
3049 PerformLayout(this, "visible");
3054 [EditorBrowsable(EditorBrowsableState.Advanced)]
3055 protected void UpdateBounds() {
3063 if (!IsHandleCreated) {
3067 XplatUI.GetWindowPos(this.Handle, this is Form, out x, out y, out width, out height, out client_width, out client_height);
3069 UpdateBounds(x, y, width, height, client_width, client_height);
3072 [EditorBrowsable(EditorBrowsableState.Advanced)]
3073 protected void UpdateBounds(int x, int y, int width, int height) {
3074 // UpdateBounds only seems to set our sizes and fire events but not update the GUI window to match
3076 bool resized = false;
3078 int client_x_diff = this.bounds.Width-this.client_size.Width;
3079 int client_y_diff = this.bounds.Height-this.client_size.Height;
3081 // Needed to generate required notifications
3082 if ((this.bounds.X!=x) || (this.bounds.Y!=y)) {
3086 if ((this.Bounds.Width!=width) || (this.Bounds.Height!=height)) {
3093 bounds.Height=height;
3095 // Update client rectangle as well
3096 if (this.layout_suspended==0) {
3097 prev_size.Width=client_size.Width;
3098 prev_size.Height=client_size.Height;
3101 client_size.Width=width-client_x_diff;
3102 client_size.Height=height-client_y_diff;
3105 OnLocationChanged(EventArgs.Empty);
3109 OnSizeChanged(EventArgs.Empty);
3113 [EditorBrowsable(EditorBrowsableState.Advanced)]
3114 protected void UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) {
3115 UpdateBounds(x, y, width, height);
3117 this.client_size.Width=clientWidth;
3118 this.client_size.Height=clientHeight;
3121 [EditorBrowsable(EditorBrowsableState.Advanced)]
3122 protected void UpdateStyles() {
3123 if (!IsHandleCreated) {
3127 XplatUI.SetWindowStyle(window.Handle, CreateParams);
3130 [EditorBrowsable(EditorBrowsableState.Advanced)]
3131 protected void UpdateZOrder() {
3136 if (parent == null) {
3142 children = ctl.child_controls.Count;
3143 for (int i = 1; i < children; i++ ) {
3144 XplatUI.SetZOrder(ctl.child_controls[i].window.Handle, ctl.child_controls[i-1].window.Handle, false, false);
3147 children = child_controls.Count;
3148 for (int i = 1; i < children; i++ ) {
3149 XplatUI.SetZOrder(child_controls[i].window.Handle, child_controls[i-1].window.Handle, false, false);
3154 protected virtual void WndProc(ref Message m) {
3156 Console.WriteLine("Control received message {0}", (Msg)m.Msg);
3158 if ((this.control_style & ControlStyles.EnableNotifyMessage) != 0) {
3162 switch((Msg)m.Msg) {
3163 case Msg.WM_WINDOWPOSCHANGED: {
3166 if (GetStyle(ControlStyles.ResizeRedraw)) {
3173 case Msg.WM_PAINT: {
3174 PaintEventArgs paint_event;
3176 paint_event = XplatUI.PaintEventStart(Handle);
3178 if ((control_style & (ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint)) == (ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint)) {
3179 OnPaintBackground(paint_event);
3182 OnPaint(paint_event);
3183 XplatUI.PaintEventEnd(Handle);
3185 if (!GetStyle(ControlStyles.UserPaint)) {
3192 case Msg.WM_ERASEBKGND: {
3193 if (GetStyle (ControlStyles.UserPaint)) {
3194 if (!GetStyle(ControlStyles.AllPaintingInWmPaint)) {
3195 PaintEventArgs eraseEventArgs = new PaintEventArgs (m.WParam == IntPtr.Zero ? Graphics.FromHwnd (m.HWnd) :
3196 Graphics.FromHdc (m.WParam), new Rectangle (new Point (0,0),Size));
3197 OnPaintBackground (eraseEventArgs);
3200 XplatUI.EraseWindowBackground(m.HWnd, m.WParam);
3202 // The DefWndProc will never have to handle this, we don't ever set hbr on the window
3203 m.Result = (IntPtr)1;
3207 case Msg.WM_LBUTTONUP: {
3208 HandleClick(mouse_clicks);
3209 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Left,
3211 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3213 if (mouse_clicks > 1) {
3219 case Msg.WM_LBUTTONDOWN: {
3220 if (CanSelect && !is_selected) {
3223 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3224 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3230 case Msg.WM_LBUTTONDBLCLK: {
3232 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3233 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3239 case Msg.WM_MBUTTONUP: {
3240 HandleClick(mouse_clicks);
3241 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Middle,
3243 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3245 if (mouse_clicks > 1) {
3251 case Msg.WM_MBUTTONDOWN: {
3252 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3253 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3259 case Msg.WM_MBUTTONDBLCLK: {
3261 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3262 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3267 case Msg.WM_RBUTTONUP: {
3268 if (context_menu != null) {
3269 context_menu.Show(this, new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ())));
3272 HandleClick(mouse_clicks);
3273 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Right,
3275 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3277 if (mouse_clicks > 1) {
3283 case Msg.WM_RBUTTONDOWN: {
3284 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3285 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3290 case Msg.WM_RBUTTONDBLCLK: {
3292 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3293 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3298 case Msg.WM_MOUSEWHEEL: {
3300 OnMouseWheel (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3301 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3302 HighOrder(m.WParam.ToInt32())));
3307 case Msg.WM_MOUSEMOVE: {
3308 OnMouseMove (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3310 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3315 case Msg.WM_MOUSE_ENTER: {
3320 OnMouseEnter(EventArgs.Empty);
3324 case Msg.WM_MOUSE_LEAVE: {
3326 OnMouseLeave(EventArgs.Empty);
3330 case Msg.WM_MOUSEHOVER: {
3331 OnMouseHover(EventArgs.Empty);
3335 case Msg.WM_SYSKEYDOWN:
3336 case Msg.WM_KEYDOWN:
3337 case Msg.WM_SYSKEYUP:
3339 case Msg.WM_SYSCHAR:
3341 if (ProcessKeyEventArgs(ref m)) {
3345 if (PreProcessMessage(ref m)) {
3349 if (ProcessKeyMessage(ref m)) {
3358 if (m.LParam != IntPtr.Zero) {
3361 hi = new HELPINFO();
3363 hi = (HELPINFO) Marshal.PtrToStructure (m.LParam, typeof (HELPINFO));
3364 mouse_pos = new Point(hi.MousePos.x, hi.MousePos.y);
3366 mouse_pos = Control.MousePosition;
3368 OnHelpRequested(new HelpEventArgs(mouse_pos));
3369 m.Result = (IntPtr)1;
3373 case Msg.WM_KILLFOCUS: {
3374 OnLeave(EventArgs.Empty);
3375 if (CausesValidation) {
3377 e = new CancelEventArgs(false);
3386 OnValidated(EventArgs.Empty);
3389 this.has_focus = false;
3390 this.is_selected = false;
3391 OnLostFocus(EventArgs.Empty);
3395 case Msg.WM_SETFOCUS: {
3396 OnEnter(EventArgs.Empty);
3397 this.has_focus = true;
3398 OnGotFocus(EventArgs.Empty);
3403 case Msg.WM_SYSCOLORCHANGE: {
3404 ThemeEngine.Current.ResetDefaults();
3405 OnSystemColorsChanged(EventArgs.Empty);
3410 case Msg.WM_SETCURSOR: {
3411 if (cursor == null) {
3416 XplatUI.SetCursor(window.Handle, cursor.handle);
3417 m.Result = (IntPtr)1;
3427 #endregion // Public Instance Methods
3429 #region OnXXX methods
3430 [EditorBrowsable(EditorBrowsableState.Advanced)]
3431 protected virtual void OnBackColorChanged(EventArgs e) {
3432 if (BackColorChanged!=null) BackColorChanged(this, e);
3433 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackColorChanged(e);
3436 [EditorBrowsable(EditorBrowsableState.Advanced)]
3437 protected virtual void OnBackgroundImageChanged(EventArgs e) {
3438 if (BackgroundImageChanged!=null) BackgroundImageChanged(this, e);
3439 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackgroundImageChanged(e);
3442 [EditorBrowsable(EditorBrowsableState.Advanced)]
3443 protected virtual void OnBindingContextChanged(EventArgs e) {
3444 CheckDataBindings ();
3445 if (BindingContextChanged!=null) {
3446 BindingContextChanged(this, e);
3448 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBindingContextChanged(e);
3451 [EditorBrowsable(EditorBrowsableState.Advanced)]
3452 protected virtual void OnCausesValidationChanged(EventArgs e) {
3453 if (CausesValidationChanged!=null) CausesValidationChanged(this, e);
3456 [EditorBrowsable(EditorBrowsableState.Advanced)]
3457 protected virtual void OnChangeUICues(UICuesEventArgs e) {
3458 if (ChangeUICues!=null) ChangeUICues(this, e);
3461 [EditorBrowsable(EditorBrowsableState.Advanced)]
3462 protected virtual void OnClick(EventArgs e) {
3463 if (Click!=null) Click(this, e);
3466 [EditorBrowsable(EditorBrowsableState.Advanced)]
3467 protected virtual void OnContextMenuChanged(EventArgs e) {
3468 if (ContextMenuChanged!=null) ContextMenuChanged(this, e);
3471 [EditorBrowsable(EditorBrowsableState.Advanced)]
3472 protected virtual void OnControlAdded(ControlEventArgs e) {
3473 if (ControlAdded!=null) ControlAdded(this, e);
3476 [EditorBrowsable(EditorBrowsableState.Advanced)]
3477 protected virtual void OnControlRemoved(ControlEventArgs e) {
3478 if (ControlRemoved!=null) ControlRemoved(this, e);
3481 [EditorBrowsable(EditorBrowsableState.Advanced)]
3482 protected virtual void OnCreateControl() {
3486 [EditorBrowsable(EditorBrowsableState.Advanced)]
3487 protected virtual void OnCursorChanged(EventArgs e) {
3488 if (CursorChanged!=null) CursorChanged(this, e);
3491 [EditorBrowsable(EditorBrowsableState.Advanced)]
3492 protected virtual void OnDockChanged(EventArgs e) {
3493 if (DockChanged!=null) DockChanged(this, e);
3496 [EditorBrowsable(EditorBrowsableState.Advanced)]
3497 protected virtual void OnDoubleClick(EventArgs e) {
3498 if (DoubleClick!=null) DoubleClick(this, e);
3501 [EditorBrowsable(EditorBrowsableState.Advanced)]
3502 protected virtual void OnDragDrop(DragEventArgs drgevent) {
3503 if (DragDrop!=null) DragDrop(this, drgevent);
3506 [EditorBrowsable(EditorBrowsableState.Advanced)]
3507 protected virtual void OnDragEnter(DragEventArgs drgevent) {
3508 if (DragEnter!=null) DragEnter(this, drgevent);
3511 [EditorBrowsable(EditorBrowsableState.Advanced)]
3512 protected virtual void OnDragLeave(EventArgs e) {
3513 if (DragLeave!=null) DragLeave(this, e);
3516 [EditorBrowsable(EditorBrowsableState.Advanced)]
3517 protected virtual void OnDragOver(DragEventArgs drgevent) {
3518 if (DragOver!=null) DragOver(this, drgevent);
3521 [EditorBrowsable(EditorBrowsableState.Advanced)]
3522 protected virtual void OnEnabledChanged(EventArgs e) {
3523 if (EnabledChanged!=null) EnabledChanged(this, e);
3524 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentEnabledChanged(e);
3527 [EditorBrowsable(EditorBrowsableState.Advanced)]
3528 protected virtual void OnEnter(EventArgs e) {
3529 if (Enter!=null) Enter(this, e);
3532 [EditorBrowsable(EditorBrowsableState.Advanced)]
3533 protected virtual void OnFontChanged(EventArgs e) {
3534 if (FontChanged!=null) FontChanged(this, e);
3535 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentFontChanged(e);
3538 [EditorBrowsable(EditorBrowsableState.Advanced)]
3539 protected virtual void OnForeColorChanged(EventArgs e) {
3540 if (ForeColorChanged!=null) ForeColorChanged(this, e);
3541 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentForeColorChanged(e);
3544 [EditorBrowsable(EditorBrowsableState.Advanced)]
3545 protected virtual void OnGiveFeedback(GiveFeedbackEventArgs gfbevent) {
3546 if (GiveFeedback!=null) GiveFeedback(this, gfbevent);
3549 [EditorBrowsable(EditorBrowsableState.Advanced)]
3550 protected virtual void OnGotFocus(EventArgs e) {
3551 if (GotFocus!=null) GotFocus(this, e);
3554 [EditorBrowsable(EditorBrowsableState.Advanced)]
3555 protected virtual void OnHandleCreated(EventArgs e) {
3556 if (HandleCreated!=null) HandleCreated(this, e);
3559 [EditorBrowsable(EditorBrowsableState.Advanced)]
3560 protected virtual void OnHandleDestroyed(EventArgs e) {
3561 if (HandleDestroyed!=null) HandleDestroyed(this, e);
3564 [EditorBrowsable(EditorBrowsableState.Advanced)]
3565 protected virtual void OnHelpRequested(HelpEventArgs hevent) {
3566 if (HelpRequested!=null) HelpRequested(this, hevent);
3569 protected virtual void OnImeModeChanged(EventArgs e) {
3570 if (ImeModeChanged!=null) ImeModeChanged(this, e);
3573 [EditorBrowsable(EditorBrowsableState.Advanced)]
3574 protected virtual void OnInvalidated(InvalidateEventArgs e) {
3575 if (Invalidated!=null) Invalidated(this, e);
3578 [EditorBrowsable(EditorBrowsableState.Advanced)]
3579 protected virtual void OnKeyDown(KeyEventArgs e) {
3580 if (KeyDown!=null) KeyDown(this, e);
3583 [EditorBrowsable(EditorBrowsableState.Advanced)]
3584 protected virtual void OnKeyPress(KeyPressEventArgs e) {
3585 if (KeyPress!=null) KeyPress(this, e);
3588 [EditorBrowsable(EditorBrowsableState.Advanced)]
3589 protected virtual void OnKeyUp(KeyEventArgs e) {
3590 if (KeyUp!=null) KeyUp(this, e);
3593 [EditorBrowsable(EditorBrowsableState.Advanced)]
3594 protected virtual void OnLayout(LayoutEventArgs levent) {
3595 if (Layout!=null) Layout(this, levent);
3598 [EditorBrowsable(EditorBrowsableState.Advanced)]
3599 protected virtual void OnLeave(EventArgs e) {
3600 if (Leave!=null) Leave(this, e);
3603 [EditorBrowsable(EditorBrowsableState.Advanced)]
3604 protected virtual void OnLocationChanged(EventArgs e) {
3606 if (LocationChanged!=null) LocationChanged(this, e);
3609 [EditorBrowsable(EditorBrowsableState.Advanced)]
3610 protected virtual void OnLostFocus(EventArgs e) {
3611 if (LostFocus!=null) LostFocus(this, e);
3614 [EditorBrowsable(EditorBrowsableState.Advanced)]
3615 protected virtual void OnMouseDown(MouseEventArgs e) {
3616 if (MouseDown!=null) MouseDown(this, e);
3619 [EditorBrowsable(EditorBrowsableState.Advanced)]
3620 protected virtual void OnMouseEnter(EventArgs e) {
3621 if (MouseEnter!=null) MouseEnter(this, e);
3624 [EditorBrowsable(EditorBrowsableState.Advanced)]
3625 protected virtual void OnMouseHover(EventArgs e) {
3626 if (MouseHover!=null) MouseHover(this, e);
3629 [EditorBrowsable(EditorBrowsableState.Advanced)]
3630 protected virtual void OnMouseLeave(EventArgs e) {
3631 if (MouseLeave!=null) MouseLeave(this, e);
3634 [EditorBrowsable(EditorBrowsableState.Advanced)]
3635 protected virtual void OnMouseMove(MouseEventArgs e) {
3636 if (MouseMove!=null) MouseMove(this, e);
3639 [EditorBrowsable(EditorBrowsableState.Advanced)]
3640 protected virtual void OnMouseUp(MouseEventArgs e) {
3641 if (MouseUp!=null) MouseUp(this, e);
3644 [EditorBrowsable(EditorBrowsableState.Advanced)]
3645 protected virtual void OnMouseWheel(MouseEventArgs e) {
3646 if (MouseWheel!=null) MouseWheel(this, e);
3649 [EditorBrowsable(EditorBrowsableState.Advanced)]
3650 protected virtual void OnMove(EventArgs e) {
3651 if (Move!=null) Move(this, e);
3654 [EditorBrowsable(EditorBrowsableState.Advanced)]
3655 protected virtual void OnNotifyMessage(Message m) {
3659 [EditorBrowsable(EditorBrowsableState.Advanced)]
3660 protected virtual void OnPaint(PaintEventArgs e) {
3661 if (Paint!=null) Paint(this, e);
3664 [EditorBrowsable(EditorBrowsableState.Advanced)]
3665 protected virtual void OnPaintBackground(PaintEventArgs pevent) {
3669 [EditorBrowsable(EditorBrowsableState.Advanced)]
3670 protected virtual void OnParentBackColorChanged(EventArgs e) {
3671 if (background_color.IsEmpty && background_image==null) {
3673 OnBackColorChanged(e);
3677 [EditorBrowsable(EditorBrowsableState.Advanced)]
3678 protected virtual void OnParentBackgroundImageChanged(EventArgs e) {
3679 if (background_color.IsEmpty && background_image==null) {
3681 OnBackgroundImageChanged(e);
3685 [EditorBrowsable(EditorBrowsableState.Advanced)]
3686 protected virtual void OnParentBindingContextChanged(EventArgs e) {
3687 if (binding_context==null) {
3688 binding_context=Parent.binding_context;
3689 OnBindingContextChanged(e);
3693 [EditorBrowsable(EditorBrowsableState.Advanced)]
3694 protected virtual void OnParentChanged(EventArgs e) {
3695 if (ParentChanged!=null) ParentChanged(this, e);
3698 [EditorBrowsable(EditorBrowsableState.Advanced)]
3699 protected virtual void OnParentEnabledChanged(EventArgs e) {
3700 if (is_enabled != Parent.is_enabled) {
3701 is_enabled=Parent.is_enabled;
3703 if (EnabledChanged != null) {
3704 EnabledChanged(this, e);
3709 [EditorBrowsable(EditorBrowsableState.Advanced)]
3710 protected virtual void OnParentFontChanged(EventArgs e) {
3717 [EditorBrowsable(EditorBrowsableState.Advanced)]
3718 protected virtual void OnParentForeColorChanged(EventArgs e) {
3719 if (foreground_color.IsEmpty) {
3721 OnForeColorChanged(e);
3725 [EditorBrowsable(EditorBrowsableState.Advanced)]
3726 protected virtual void OnParentRightToLeftChanged(EventArgs e) {
3727 if (right_to_left==RightToLeft.Inherit) {
3729 OnRightToLeftChanged(e);
3733 [EditorBrowsable(EditorBrowsableState.Advanced)]
3734 protected virtual void OnParentVisibleChanged(EventArgs e) {
3736 OnVisibleChanged(e);
3740 [EditorBrowsable(EditorBrowsableState.Advanced)]
3741 protected virtual void OnQueryContinueDrag(QueryContinueDragEventArgs e) {
3742 if (QueryContinueDrag!=null) QueryContinueDrag(this, e);
3745 [EditorBrowsable(EditorBrowsableState.Advanced)]
3746 protected virtual void OnResize(EventArgs e) {
3747 if (Resize!=null) Resize(this, e);
3749 PerformLayout(this, "bounds");
3751 if (parent != null) {
3752 parent.PerformLayout();
3756 [EditorBrowsable(EditorBrowsableState.Advanced)]
3757 protected virtual void OnRightToLeftChanged(EventArgs e) {
3758 if (RightToLeftChanged!=null) RightToLeftChanged(this, e);
3759 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentRightToLeftChanged(e);
3762 [EditorBrowsable(EditorBrowsableState.Advanced)]
3763 protected virtual void OnSizeChanged(EventArgs e) {
3764 InvalidateBuffers ();
3766 if (SizeChanged!=null) SizeChanged(this, e);
3769 [EditorBrowsable(EditorBrowsableState.Advanced)]
3770 protected virtual void OnStyleChanged(EventArgs e) {
3771 if (StyleChanged!=null) StyleChanged(this, e);
3774 [EditorBrowsable(EditorBrowsableState.Advanced)]
3775 protected virtual void OnSystemColorsChanged(EventArgs e) {
3776 if (SystemColorsChanged!=null) SystemColorsChanged(this, e);
3779 [EditorBrowsable(EditorBrowsableState.Advanced)]
3780 protected virtual void OnTabIndexChanged(EventArgs e) {
3781 if (TabIndexChanged!=null) TabIndexChanged(this, e);
3784 [EditorBrowsable(EditorBrowsableState.Advanced)]
3785 protected virtual void OnTabStopChanged(EventArgs e) {
3786 if (TabStopChanged!=null) TabStopChanged(this, e);
3789 [EditorBrowsable(EditorBrowsableState.Advanced)]
3790 protected virtual void OnTextChanged(EventArgs e) {
3791 if (TextChanged!=null) TextChanged(this, e);
3794 [EditorBrowsable(EditorBrowsableState.Advanced)]
3795 protected virtual void OnValidated(EventArgs e) {
3796 if (Validated!=null) Validated(this, e);
3799 [EditorBrowsable(EditorBrowsableState.Advanced)]
3800 protected virtual void OnValidating(System.ComponentModel.CancelEventArgs e) {
3801 if (Validating!=null) Validating(this, e);
3804 [EditorBrowsable(EditorBrowsableState.Advanced)]
3805 protected virtual void OnVisibleChanged(EventArgs e) {
3812 if (bmp_mem!=null) {
3818 if (!this.IsHandleCreated) {
3819 this.CreateControl();
3825 if (VisibleChanged!=null) VisibleChanged(this, e);
3827 // We need to tell our kids
3828 for (int i=0; i<child_controls.Count; i++) {
3829 child_controls[i].OnParentVisibleChanged(e);
3832 #endregion // OnXXX methods
3835 public event EventHandler BackColorChanged;
3836 public event EventHandler BackgroundImageChanged;
3837 public event EventHandler BindingContextChanged;
3838 public event EventHandler CausesValidationChanged;
3839 public event UICuesEventHandler ChangeUICues;
3840 public event EventHandler Click;
3841 public event EventHandler ContextMenuChanged;
3843 [EditorBrowsable(EditorBrowsableState.Advanced)]
3845 public event ControlEventHandler ControlAdded;
3847 [EditorBrowsable(EditorBrowsableState.Advanced)]
3849 public event ControlEventHandler ControlRemoved;
3851 public event EventHandler CursorChanged;
3852 public event EventHandler DockChanged;
3853 public event EventHandler DoubleClick;
3854 public event DragEventHandler DragDrop;
3855 public event DragEventHandler DragEnter;
3856 public event EventHandler DragLeave;
3857 public event DragEventHandler DragOver;
3858 public event EventHandler EnabledChanged;
3859 public event EventHandler Enter;
3860 public event EventHandler FontChanged;
3861 public event EventHandler ForeColorChanged;
3862 public event GiveFeedbackEventHandler GiveFeedback;
3864 [EditorBrowsable(EditorBrowsableState.Advanced)]
3866 public event EventHandler GotFocus;
3868 [EditorBrowsable(EditorBrowsableState.Advanced)]
3870 public event EventHandler HandleCreated;
3872 [EditorBrowsable(EditorBrowsableState.Advanced)]
3874 public event EventHandler HandleDestroyed;
3876 public event HelpEventHandler HelpRequested;
3877 public event EventHandler ImeModeChanged;
3879 [EditorBrowsable(EditorBrowsableState.Advanced)]
3881 public event InvalidateEventHandler Invalidated;
3883 public event KeyEventHandler KeyDown;
3884 public event KeyPressEventHandler KeyPress;
3885 public event KeyEventHandler KeyUp;
3886 public event LayoutEventHandler Layout;
3887 public event EventHandler Leave;
3888 public event EventHandler LocationChanged;
3890 [EditorBrowsable(EditorBrowsableState.Advanced)]
3892 public event EventHandler LostFocus;
3894 public event MouseEventHandler MouseDown;
3895 public event EventHandler MouseEnter;
3896 public event EventHandler MouseHover;
3897 public event EventHandler MouseLeave;
3898 public event MouseEventHandler MouseMove;
3899 public event MouseEventHandler MouseUp;
3901 [EditorBrowsable(EditorBrowsableState.Advanced)]
3903 public event MouseEventHandler MouseWheel;
3905 public event EventHandler Move;
3906 public event PaintEventHandler Paint;
3907 public event EventHandler ParentChanged;
3908 public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp;
3909 public event QueryContinueDragEventHandler QueryContinueDrag;
3910 public event EventHandler Resize;
3911 public event EventHandler RightToLeftChanged;
3912 public event EventHandler SizeChanged;
3913 public event EventHandler StyleChanged;
3914 public event EventHandler SystemColorsChanged;
3915 public event EventHandler TabIndexChanged;
3916 public event EventHandler TabStopChanged;
3917 public event EventHandler TextChanged;
3918 public event EventHandler Validated;
3919 public event CancelEventHandler Validating;
3920 public event EventHandler VisibleChanged;
3921 #endregion // Events