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
37 using System.ComponentModel;
38 using System.ComponentModel.Design;
39 using System.ComponentModel.Design.Serialization;
40 using System.Collections;
41 using System.Diagnostics;
42 using System.Runtime.InteropServices;
43 using System.Threading;
46 namespace System.Windows.Forms
49 [Designer("System.Windows.Forms.Design.ContolDesigner, System.Design")]
50 [DefaultProperty("Text")]
51 [DefaultEvent("Click")]
52 [DesignerSerializer("System.Windows.Forms.Design.ControlCodeDomSerializer, System.Design", "System.ComponentModel.Design.Serialization.CodeDomSerializer, System.Design")]
53 [ToolboxItemFilter("System.Windows.Forms")]
54 public class Control : Component, ISynchronizeInvoke, IWin32Window
56 #region Local Variables
59 internal Rectangle bounds; // bounding rectangle for control (client area + decorations)
60 internal object creator_thread; // thread that created the control
61 internal ControlNativeWindow window; // object for native window handle
62 internal string name; // for object naming
65 internal bool has_focus; // true if control has focus
66 internal bool is_visible; // true if control is visible
67 internal bool is_entered; // is the mouse inside the control?
68 internal bool is_enabled; // true if control is enabled (usable/not grayed out)
69 internal bool is_selected; // true if control is selected
70 internal bool is_accessible; // true if the control is visible to accessibility applications
71 internal bool is_captured; // tracks if the control has captured the mouse
72 internal bool is_toplevel; // tracks if the control is a toplevel window
73 internal bool is_recreating; // tracks if the handle for the control is being recreated
74 internal bool causes_validation; // tracks if validation is executed on changes
75 internal int tab_index; // position in tab order of siblings
76 internal bool tab_stop = true; // is the control a tab stop?
77 internal bool is_disposed; // has the window already been disposed?
78 internal Size client_size; // size of the client area (window excluding decorations)
79 internal Rectangle client_rect; // rectangle with the client area (window excluding decorations)
80 internal ControlStyles control_style; // rather win32-specific, style bits for control
81 internal ImeMode ime_mode = ImeMode.Inherit;
82 internal bool layout_pending; // true if our parent needs to re-layout us
83 internal object control_tag; // object that contains data about our control
84 internal int mouse_clicks; // Counter for mouse clicks
85 internal Cursor cursor; // Cursor for the window
88 internal Color foreground_color; // foreground color for control
89 internal Color background_color; // background color for control
90 internal Image background_image; // background image for control
91 internal Font font; // font for control
92 internal string text; // window/title text for control
93 internal BorderStyle border_style; // Border style of control
96 internal AnchorStyles anchor_style; // anchoring requirements for our control
97 internal DockStyle dock_style; // docking requirements for our control (supercedes anchoring)
98 internal SizeF size_ratio; // size ratio of our control to it's parent; required for anchoring
99 internal Size prev_size; // previous size of the control; required for anchoring
101 // to be categorized...
102 static internal ArrayList controls = new ArrayList(); // All of the applications controls, in a flat list
103 internal ControlCollection child_controls; // our children
104 internal Control parent; // our parent control
105 internal AccessibleObject accessibility_object; // object that contains accessibility information about our control
106 internal BindingContext binding_context; // TODO
107 internal RightToLeft right_to_left; // drawing direction for control
108 internal int layout_suspended;
109 internal bool double_buffering;
110 internal ContextMenu context_menu; // Context menu associated with the control
112 private Graphics dc_mem; // Graphics context for double buffering
113 private Bitmap bmp_mem; // Bitmap for double buffering control
115 #endregion // Local Variables
117 #region Private Classes
118 // This helper class allows us to dispatch messages to Control.WndProc
119 internal class ControlNativeWindow : NativeWindow {
120 private Control owner;
122 public ControlNativeWindow(Control control) : base() {
127 public Control Owner {
133 static internal Control ControlFromHandle(IntPtr hWnd) {
134 ControlNativeWindow window;
136 window = (ControlNativeWindow)window_collection[hWnd];
141 protected override void WndProc(ref Message m) {
142 owner.WndProc(ref m);
147 #region Public Classes
148 public class ControlAccessibleObject : AccessibleObject {
149 #region ControlAccessibleObject Local Variables
150 private Control owner;
151 #endregion // ControlAccessibleObject Local Variables
153 #region ControlAccessibleObject Constructors
154 public ControlAccessibleObject(Control ownerControl) {
155 this.owner = ownerControl;
157 #endregion // ControlAccessibleObject Constructors
159 #region ControlAccessibleObject Public Instance Properties
160 public override string DefaultAction {
162 return base.DefaultAction;
166 public override string Description {
168 return base.Description;
172 public IntPtr Handle {
178 // We don't want to let them set it
182 public override string Help {
188 public override string KeyboardShortcut {
190 return base.KeyboardShortcut;
194 public override string Name {
204 public Control Owner {
210 public override AccessibleRole Role {
215 #endregion // ControlAccessibleObject Public Instance Properties
217 #region ControlAccessibleObject Public Instance Methods
218 public override int GetHelpTopic(out string FileName) {
219 return base.GetHelpTopic (out FileName);
222 [MonoTODO("Implement this and tie it into Control.AccessibilityNotifyClients")]
223 public void NotifyClients(AccessibleEvents accEvent) {
224 throw new NotImplementedException();
227 [MonoTODO("Implement this and tie it into Control.AccessibilityNotifyClients")]
228 public void NotifyClients(AccessibleEvents accEvent, int childID) {
229 throw new NotImplementedException();
232 public override string ToString() {
233 return "ControlAccessibleObject: Owner = " + owner.ToString() + ", Text: " + owner.text;
236 #endregion // ControlAccessibleObject Public Instance Methods
239 public class ControlCollection : IList, ICollection, ICloneable, IEnumerable {
240 #region ControlCollection Local Variables
241 internal ArrayList list;
242 internal Control owner;
243 #endregion // ControlCollection Local Variables
245 #region ControlCollection Public Constructor
246 public ControlCollection(Control owner) {
248 this.list=new ArrayList();
252 #region ControlCollection Public Instance Properties
259 public bool IsReadOnly {
261 return list.IsReadOnly;
265 public virtual Control this[int index] {
267 if (index < 0 || index >= list.Count) {
268 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
270 return (Control)list[index];
273 #endregion // ControlCollection Public Instance Properties
275 #region ControlCollection Private Instance Methods
276 public virtual void Add (Control value)
279 for (int i = 0; i < list.Count; i++) {
280 if (list [i] == value) {
281 // Do we need to do anything here?
286 if (value.tab_index == -1) {
292 end = owner.child_controls.Count;
293 for (int i = 0; i < end; i++) {
294 index = owner.child_controls[i].tab_index;
299 value.tab_index = use;
303 value.Parent = owner;
304 owner.UpdateZOrder();
305 owner.OnControlAdded(new ControlEventArgs(value));
308 public virtual void AddRange (Control[] controls)
310 if (controls == null)
311 throw new ArgumentNullException ("controls");
313 owner.SuspendLayout ();
316 for (int i = 0; i < controls.Length; i++)
319 owner.ResumeLayout ();
323 public virtual void Clear ()
325 owner.SuspendLayout();
326 for (int i = 0; i < list.Count; i++) {
327 owner.OnControlRemoved(new ControlEventArgs((Control)list[i]));
330 owner.ResumeLayout();
333 public virtual bool Contains (Control value)
335 return list.Contains (value);
338 public void CopyTo (Array array, int index)
340 list.CopyTo(array, index);
343 public override bool Equals(object other) {
344 if (other is ControlCollection && (((ControlCollection)other).owner==this.owner)) {
351 public int GetChildIndex(Control child) {
352 return GetChildIndex(child, false);
355 public int GetChildIndex(Control child, bool throwException) {
358 index=list.IndexOf(child);
360 if (index==-1 && throwException) {
361 throw new ArgumentException("Not a child control", "child");
366 public IEnumerator GetEnumerator() {
367 return list.GetEnumerator();
370 public override int GetHashCode() {
371 return base.GetHashCode();
374 public int IndexOf(Control control) {
375 return list.IndexOf(control);
378 public virtual void Remove(Control value) {
379 owner.OnControlRemoved(new ControlEventArgs(value));
381 owner.UpdateZOrder();
384 public void RemoveAt(int index) {
385 if (index<0 || index>=list.Count) {
386 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
389 owner.OnControlRemoved(new ControlEventArgs((Control)list[index]));
390 list.RemoveAt(index);
391 owner.UpdateZOrder();
394 public void SetChildIndex(Control child, int newIndex) {
397 old_index=list.IndexOf(child);
399 throw new ArgumentException("Not a child control", "child");
402 if (old_index==newIndex) {
408 if (newIndex>list.Count) {
411 list.Insert(newIndex, child);
413 owner.UpdateZOrder();
415 #endregion // ControlCollection Private Instance Methods
417 #region ControlCollection Interface Properties
418 object IList.this[int index] {
420 if (index<0 || index>=list.Count) {
421 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
427 if (!(value is Control)) {
428 throw new ArgumentException("Object of type Control required", "value");
431 list[index]=(Control)value;
435 bool IList.IsFixedSize {
441 bool IList.IsReadOnly {
443 return list.IsReadOnly;
447 bool ICollection.IsSynchronized {
449 return list.IsSynchronized;
453 object ICollection.SyncRoot {
455 return list.SyncRoot;
458 #endregion // ControlCollection Interface Properties
460 #region ControlCollection Interface Methods
461 int IList.Add(object value) {
463 throw new ArgumentNullException("value", "Cannot add null controls");
466 if (!(value is Control)) {
467 throw new ArgumentException("Object of type Control required", "value");
470 return list.Add(value);
473 bool IList.Contains(object value) {
474 if (!(value is Control)) {
475 throw new ArgumentException("Object of type Control required", "value");
478 return this.Contains((Control) value);
481 int IList.IndexOf(object value) {
482 if (!(value is Control)) {
483 throw new ArgumentException("Object of type Control required", "value");
486 return this.IndexOf((Control) value);
489 void IList.Insert(int index, object value) {
490 if (!(value is Control)) {
491 throw new ArgumentException("Object of type Control required", "value");
493 list.Insert(index, value);
496 void IList.Remove(object value) {
497 if (!(value is Control)) {
498 throw new ArgumentException("Object of type Control required", "value");
503 void ICollection.CopyTo(Array array, int index) {
505 list.CopyTo(array, index);
509 Object ICloneable.Clone() {
510 ControlCollection clone = new ControlCollection(this.owner);
511 clone.list=(ArrayList)list.Clone(); // FIXME: Do we need this?
514 #endregion // ControlCollection Interface Methods
516 #endregion // ControlCollection Class
518 #region Public Constructors
520 creator_thread = Thread.CurrentThread;
522 prev_size = Size.Empty;
523 anchor_style = AnchorStyles.Top | AnchorStyles.Left;
530 layout_pending = false;
532 causes_validation = true;
534 layout_suspended = 0;
535 double_buffering = true;
539 right_to_left = RightToLeft.Inherit;
541 control_style = ControlStyles.Selectable | ControlStyles.StandardClick | ControlStyles.StandardDoubleClick;
544 background_image = null;
548 child_controls = CreateControlsInstance();
549 client_size = new Size(DefaultSize.Width, DefaultSize.Height);
550 client_rect = new Rectangle(0, 0, DefaultSize.Width, DefaultSize.Height);
551 XplatUI.CalculateWindowRect(IntPtr.Zero, ref client_rect, CreateParams.Style, CreateParams.ExStyle, IntPtr.Zero, out bounds);
552 if ((CreateParams.Style & (int)WindowStyles.WS_CHILD) == 0) {
558 public Control(Control parent, string text) : this() {
563 public Control(Control parent, string text, int left, int top, int width, int height) : this() {
568 bounds.Height=height;
569 SetBoundsCore(left, top, width, height, BoundsSpecified.All);
573 public Control(string text) : this() {
577 public Control(string text, int left, int top, int width, int height) : this() {
581 bounds.Height=height;
582 SetBoundsCore(left, top, width, height, BoundsSpecified.All);
586 protected override void Dispose(bool disposing) {
599 OnHandleDestroyed(EventArgs.Empty);
600 controls.Remove(this);
602 #endregion // Public Constructors
604 #region Internal Properties
605 internal BorderStyle InternalBorderStyle {
611 if (border_style != value) {
612 border_style = value;
614 XplatUI.SetBorderStyle(window.Handle, border_style);
618 #endregion // Internal Properties
620 #region Private & Internal Methods
621 internal static IAsyncResult BeginInvokeInternal (Delegate method, object [] args) {
622 AsyncMethodResult result = new AsyncMethodResult ();
623 AsyncMethodData data = new AsyncMethodData ();
625 data.Method = method;
627 data.Result = new WeakReference (result);
629 XplatUI.SendAsyncMethod (data);
633 internal Graphics DeviceContext {
636 CreateBuffers(this.Width, this.Height);
642 internal Bitmap ImageBuffer {
645 CreateBuffers(this.Width, this.Height);
651 internal void CreateBuffers (int width, int height) {
652 if (double_buffering == false)
655 if (dc_mem != null) {
669 bmp_mem = new Bitmap (width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
670 dc_mem = Graphics.FromImage (bmp_mem);
673 internal void InvalidateBuffers ()
675 if (double_buffering == false)
678 if (dc_mem != null) {
688 internal static void SetChildColor(Control parent) {
691 for (int i=0; i < parent.child_controls.Count; i++) {
692 child=parent.child_controls[i];
693 if (child.IsHandleCreated) {
694 XplatUI.SetWindowBackground(child.window.Handle, child.BackColor);
696 if (child.child_controls.Count>0) {
697 SetChildColor(child);
703 internal bool Select(Control control) {
705 IContainerControl container;
707 if (control == null) {
711 parent = control.parent;
713 if (((control.control_style & ControlStyles.Selectable) !=0) && (parent != null)) {
714 while (parent != null) {
715 if (!parent.is_visible || !parent.is_enabled) {
718 parent = parent.parent;
722 control.is_selected = true;
724 XplatUI.SetFocus(control.window.Handle);
725 container = GetContainerControl();
726 if (container != null) {
727 container.ActiveControl = control;
732 internal virtual void DoDefaultAction() {
733 // Only here to be overriden by our actual controls; this is needed by the accessibility class
736 internal static int LowOrder (int param) {
737 return (param & 0xffff);
740 internal static int HighOrder (int param) {
741 return (param >> 16);
744 internal static MouseButtons FromParamToMouseButtons (int param) {
745 MouseButtons buttons = MouseButtons.None;
747 if ((param & (int) MsgButtons.MK_LBUTTON) != 0)
748 buttons |= MouseButtons.Left;
750 if ((param & (int) MsgButtons.MK_MBUTTON) != 0)
751 buttons |= MouseButtons.Middle;
753 if ((param & (int) MsgButtons.MK_RBUTTON) != 0)
754 buttons |= MouseButtons.Right;
760 private static Control FindFlatForward(Control container, Control start) {
766 end = container.child_controls.Count;
769 index = start.tab_index;
774 for (int i = 0; i < end; i++) {
776 if (container.child_controls[i].tab_index > index) {
777 found = container.child_controls[i];
779 } else if (found.tab_index > container.child_controls[i].tab_index) {
780 if (container.child_controls[i].tab_index > index) {
781 found = container.child_controls[i];
788 private static Control FindControlForward(Control container, Control start) {
795 if ((start is IContainerControl) || start.GetStyle(ControlStyles.ContainerControl)) {
796 found = FindControlForward(start, null);
803 while (p != container) {
804 found = FindFlatForward(p, start);
812 return FindFlatForward(container, start);
815 private static Control FindFlatBackward(Control container, Control start) {
821 end = container.child_controls.Count;
824 index = start.tab_index;
826 // FIXME: Possible speed-up: Keep the highest taborder index in the container
828 for (int i = 0; i < end; i++) {
829 if (container.child_controls[i].tab_index > index) {
830 index = container.child_controls[i].tab_index;
836 for (int i = 0; i < end; i++) {
838 if (container.child_controls[i].tab_index < index) {
839 found = container.child_controls[i];
841 } else if (found.tab_index < container.child_controls[i].tab_index) {
842 if (container.child_controls[i].tab_index < index) {
843 found = container.child_controls[i];
850 private static Control FindControlBackward(Control container, Control start) {
856 found = FindFlatBackward(start.parent, start);
857 if (found == null && start.parent != container) {
862 found = FindFlatBackward(container, start);
865 while ((found != null) && ((found is IContainerControl) || found.GetStyle(ControlStyles.ContainerControl))) {
866 found = FindControlBackward(found, null);
875 private void HandleClick(int clicks) {
876 if (GetStyle(ControlStyles.StandardClick)) {
878 if (GetStyle(ControlStyles.StandardDoubleClick)) {
879 OnDoubleClick(EventArgs.Empty);
881 OnClick(EventArgs.Empty);
884 OnClick(EventArgs.Empty);
888 #endregion // Private & Internal Methods
890 #region Public Static Properties
891 public static Color DefaultBackColor {
893 return ThemeEngine.Current.DefaultControlBackColor;
897 public static Font DefaultFont {
899 return ThemeEngine.Current.DefaultFont;
903 public static Color DefaultForeColor {
905 return ThemeEngine.Current.DefaultControlForeColor;
909 public static Keys ModifierKeys {
911 return XplatUI.State.ModifierKeys;
915 public static MouseButtons MouseButtons {
917 return XplatUI.State.MouseButtons;
921 public static Point MousePosition {
923 return Cursor.Position;
926 #endregion // Public Static Properties
928 #region Public Instance Properties
929 [EditorBrowsable(EditorBrowsableState.Advanced)]
931 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
932 public AccessibleObject AccessibilityObject {
934 if (accessibility_object==null) {
935 accessibility_object=CreateAccessibilityInstance();
937 return accessibility_object;
941 [EditorBrowsable(EditorBrowsableState.Advanced)]
943 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
944 public string AccessibleDefaultActionDescription {
946 return AccessibilityObject.default_action;
950 AccessibilityObject.default_action=value;
956 public string AccessibleDescription {
958 return AccessibilityObject.description;
962 AccessibilityObject.description=value;
968 public string AccessibleName {
970 return AccessibilityObject.Name;
974 AccessibilityObject.Name=value;
979 public AccessibleRole AccessibleRole {
981 return AccessibilityObject.role;
985 AccessibilityObject.role=value;
989 [DefaultValue(false)]
990 public virtual bool AllowDrop {
992 return XplatUI.State.DropTarget;
996 XplatUI.State.DropTarget=value;
1001 [RefreshProperties(RefreshProperties.Repaint)]
1002 [DefaultValue(AnchorStyles.Top | AnchorStyles.Left)]
1003 public virtual AnchorStyles Anchor {
1005 return anchor_style;
1011 if (parent != null) {
1012 parent.PerformLayout(this, "Parent");
1018 public virtual Color BackColor {
1020 if (background_color.IsEmpty) {
1022 return parent.BackColor;
1024 return DefaultBackColor;
1026 return background_color;
1030 background_color=value;
1031 if (this.IsHandleCreated) {
1032 XplatUI.SetWindowBackground(this.window.Handle, value);
1034 SetChildColor(this);
1035 OnBackColorChanged(EventArgs.Empty);
1041 [DefaultValue(null)]
1042 public virtual Image BackgroundImage {
1044 return background_image;
1048 if (background_image!=value) {
1049 background_image=value;
1050 OnBackgroundImageChanged(EventArgs.Empty);
1055 [EditorBrowsable(EditorBrowsableState.Advanced)]
1057 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1058 public virtual BindingContext BindingContext {
1060 return binding_context;
1064 if (binding_context != value) {
1065 binding_context = value;
1066 OnBindingContextChanged(EventArgs.Empty);
1071 [EditorBrowsable(EditorBrowsableState.Advanced)]
1073 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1076 return bounds.Y+bounds.Height;
1080 [EditorBrowsable(EditorBrowsableState.Advanced)]
1082 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1083 public Rectangle Bounds {
1089 SetBoundsCore(value.Left, value.Top, value.Width, value.Height, BoundsSpecified.All);
1093 [EditorBrowsable(EditorBrowsableState.Advanced)]
1095 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1096 public bool CanFocus {
1098 if (is_visible && is_enabled && GetStyle(ControlStyles.Selectable)) {
1105 [EditorBrowsable(EditorBrowsableState.Advanced)]
1107 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1108 public bool CanSelect {
1112 if (!GetStyle(ControlStyles.Selectable) || this.parent == null) {
1116 parent = this.parent;
1117 while (parent != null) {
1118 if (!parent.is_visible || !parent.is_enabled) {
1122 parent = parent.parent;
1128 [EditorBrowsable(EditorBrowsableState.Advanced)]
1130 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1131 public bool Capture {
1133 return this.is_captured;
1137 if (this.IsHandleCreated) {
1138 if (value && !is_captured) {
1140 XplatUI.GrabWindow(this.window.Handle, IntPtr.Zero);
1141 } else if (!value && is_captured) {
1142 XplatUI.UngrabWindow(this.window.Handle);
1143 is_captured = false;
1149 [DefaultValue(true)]
1150 public bool CausesValidation {
1152 return this.causes_validation;
1156 if (this.causes_validation != value) {
1157 causes_validation = value;
1158 OnCausesValidationChanged(EventArgs.Empty);
1163 [EditorBrowsable(EditorBrowsableState.Advanced)]
1165 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1166 public Rectangle ClientRectangle {
1168 client_rect.Width = client_size.Width;
1169 client_rect.Height = client_size.Height;
1174 [EditorBrowsable(EditorBrowsableState.Advanced)]
1176 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1177 public Size ClientSize {
1180 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1181 return ((Form)this).form_parent_window.ClientSize;
1189 this.SetClientSizeCore(value.Width, value.Height);
1193 [EditorBrowsable(EditorBrowsableState.Advanced)]
1195 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1196 [DescriptionAttribute("ControlCompanyNameDescr")]
1197 public String CompanyName {
1199 return "Mono Project, Novell, Inc.";
1203 [EditorBrowsable(EditorBrowsableState.Advanced)]
1205 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1206 public bool ContainsFocus {
1212 for (int i=0; i < child_controls.Count; i++) {
1213 if (child_controls[i].ContainsFocus) {
1221 [DefaultValue(null)]
1222 public virtual ContextMenu ContextMenu {
1224 return context_menu;
1228 if (context_menu != value) {
1229 context_menu = value;
1230 OnContextMenuChanged(EventArgs.Empty);
1236 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
1237 public ControlCollection Controls {
1239 return this.child_controls;
1243 [EditorBrowsable(EditorBrowsableState.Advanced)]
1245 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1246 public bool Created {
1248 if (!this.is_disposed && (this.window.Handle != IntPtr.Zero)) {
1255 [AmbientValue(null)]
1256 public virtual Cursor Cursor {
1258 if (cursor != null) {
1262 if (parent != null) {
1263 return parent.Cursor;
1266 return Cursors.Default;
1270 if (cursor != value) {
1275 pt = Cursor.Position;
1276 if (bounds.Contains(pt)) {
1277 if (GetChildAtPoint(pt) == null) {
1278 if (cursor != null) {
1279 XplatUI.SetCursor(window.Handle, cursor.handle);
1281 if (parent != null) {
1282 XplatUI.SetCursor(window.Handle, parent.Cursor.handle);
1284 XplatUI.SetCursor(window.Handle, Cursors.def.handle);
1290 OnCursorChanged(EventArgs.Empty);
1295 #if haveDataBindings
1296 [EditorBrowsable(EditorBrowsableState.Advanced)]
1298 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1299 public ControlBindingsCollection DataBindings {
1301 throw new NotImplementedException();
1306 [EditorBrowsable(EditorBrowsableState.Advanced)]
1308 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1309 public virtual Rectangle DisplayRectangle {
1311 return ClientRectangle;
1315 [EditorBrowsable(EditorBrowsableState.Advanced)]
1317 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1318 public bool Disposing {
1325 [RefreshProperties(RefreshProperties.Repaint)]
1326 [DefaultValue(DockStyle.None)]
1327 public virtual DockStyle Dock {
1333 if (dock_style == value) {
1339 if (parent != null) {
1340 parent.PerformLayout(this, "Parent");
1343 OnDockChanged(EventArgs.Empty);
1349 public bool Enabled {
1355 if (is_enabled == value) {
1361 OnEnabledChanged (EventArgs.Empty);
1365 [EditorBrowsable(EditorBrowsableState.Advanced)]
1367 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1368 public virtual bool Focused {
1370 return this.has_focus;
1375 [AmbientValue(null)]
1377 public virtual Font Font {
1383 if (Parent != null && Parent.Font != null) {
1391 if (font == value) {
1397 OnFontChanged (EventArgs.Empty);
1402 public virtual Color ForeColor {
1404 if (foreground_color.IsEmpty) {
1406 return parent.ForeColor;
1408 return DefaultForeColor;
1410 return foreground_color;
1414 if (foreground_color != value) {
1415 foreground_color=value;
1417 OnForeColorChanged(EventArgs.Empty);
1424 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1425 public IntPtr Handle { // IWin32Window
1427 if (!IsHandleCreated) {
1430 return window.Handle;
1434 [EditorBrowsable(EditorBrowsableState.Advanced)]
1436 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1437 public bool HasChildren {
1439 if (this.child_controls.Count>0) {
1446 [EditorBrowsable(EditorBrowsableState.Always)]
1448 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1451 return this.bounds.Height;
1455 SetBoundsCore(bounds.X, bounds.Y, bounds.Width, value, BoundsSpecified.Height);
1459 [AmbientValue(ImeMode.Inherit)]
1461 public ImeMode ImeMode {
1467 if (ime_mode != value) {
1470 OnImeModeChanged(EventArgs.Empty);
1475 [EditorBrowsable(EditorBrowsableState.Advanced)]
1477 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1478 public bool InvokeRequired { // ISynchronizeInvoke
1480 if (creator_thread!=Thread.CurrentThread) {
1487 [EditorBrowsable(EditorBrowsableState.Advanced)]
1489 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1490 public bool IsAccessible {
1492 return is_accessible;
1496 is_accessible = value;
1500 [EditorBrowsable(EditorBrowsableState.Advanced)]
1502 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1503 public bool IsDisposed {
1505 return this.is_disposed;
1509 [EditorBrowsable(EditorBrowsableState.Advanced)]
1511 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1512 public bool IsHandleCreated {
1514 if ((window!=null) && (window.Handle!=IntPtr.Zero)) {
1522 [EditorBrowsable(EditorBrowsableState.Always)]
1524 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1527 return this.bounds.X;
1531 SetBoundsCore(value, bounds.Y, bounds.Width, bounds.Height, BoundsSpecified.X);
1536 public Point Location {
1538 return new Point(bounds.X, bounds.Y);
1542 SetBoundsCore(value.X, value.Y, bounds.Width, bounds.Height, BoundsSpecified.Location);
1547 public string Name {
1558 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1559 public Control Parent {
1565 if (value == this) {
1566 throw new ArgumentException("A circular control reference has been made. A control cannot be owned or parented to itself.");
1569 if (parent!=value) {
1571 parent.Controls.Remove(this);
1576 if (!parent.Controls.Contains(this)) {
1577 parent.Controls.Add(this);
1580 XplatUI.SetParent(Handle, value.Handle);
1584 OnParentChanged(EventArgs.Empty);
1589 [EditorBrowsable(EditorBrowsableState.Advanced)]
1591 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1592 public string ProductName {
1594 return "Novell Mono MWF";
1598 [EditorBrowsable(EditorBrowsableState.Advanced)]
1600 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1601 public string ProductVersion {
1603 return "1.1.4322.573";
1607 [EditorBrowsable(EditorBrowsableState.Advanced)]
1609 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1610 public bool RecreatingHandle {
1612 return is_recreating;
1616 [EditorBrowsable(EditorBrowsableState.Advanced)]
1618 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1619 public Region Region {
1621 return new Region(this.bounds);
1628 g = this.CreateGraphics();
1629 r = value.GetBounds(g);
1631 SetBounds((int)r.X, (int)r.Y, (int)r.Width, (int)r.Height);
1637 [EditorBrowsable(EditorBrowsableState.Advanced)]
1639 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1642 return this.bounds.X+this.bounds.Width;
1646 [AmbientValue(RightToLeft.Inherit)]
1648 public virtual RightToLeft RightToLeft {
1650 return right_to_left;
1654 if (value != right_to_left) {
1655 right_to_left = value;
1656 OnRightToLeftChanged(EventArgs.Empty);
1661 [EditorBrowsable(EditorBrowsableState.Advanced)]
1662 public override ISite Site {
1675 return new Size(Width, Height);
1679 SetBoundsCore(bounds.X, bounds.Y, value.Width, value.Height, BoundsSpecified.Size);
1684 [MergableProperty(false)]
1685 public int TabIndex {
1687 if (tab_index != -1) {
1694 if (tab_index != value) {
1696 OnTabIndexChanged(EventArgs.Empty);
1702 [DefaultValue(true)]
1703 public bool TabStop {
1709 if (tab_stop != value) {
1711 OnTabStopChanged(EventArgs.Empty);
1716 [Localizable(false)]
1718 [TypeConverter(typeof(StringConverter))]
1719 [DefaultValue(null)]
1726 control_tag = value;
1732 [BindableAttribute(true)]
1733 public virtual string Text {
1739 if (value == null) {
1740 value = String.Empty;
1745 XplatUI.Text(Handle, text);
1746 // FIXME: Do we need a Refresh() here?
1747 OnTextChanged (EventArgs.Empty);
1752 [EditorBrowsable(EditorBrowsableState.Advanced)]
1754 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1757 return this.bounds.Y;
1761 SetBoundsCore(bounds.X, value, bounds.Width, bounds.Height, BoundsSpecified.Y);
1765 [EditorBrowsable(EditorBrowsableState.Advanced)]
1767 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1768 public Control TopLevelControl {
1772 while (p.parent != null) {
1781 public bool Visible {
1791 SetVisibleCore(value);
1795 [EditorBrowsable(EditorBrowsableState.Always)]
1797 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1800 return this.bounds.Width;
1804 SetBoundsCore(bounds.X, bounds.Y, value, bounds.Height, BoundsSpecified.Width);
1808 [EditorBrowsable(EditorBrowsableState.Never)]
1810 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1811 public IWindowTarget WindowTarget {
1820 #endregion // Public Instance Properties
1822 #region Protected Instance Properties
1823 protected virtual CreateParams CreateParams {
1825 CreateParams create_params = new CreateParams();
1827 create_params.Caption = Text;
1828 create_params.X = Left;
1829 create_params.Y = Top;
1830 create_params.Width = Width;
1831 create_params.Height = Height;
1833 create_params.ClassName = XplatUI.DefaultClassName;
1834 create_params.ClassStyle = 0;
1835 create_params.ExStyle = 0;
1836 create_params.Param = 0;
1839 create_params.Parent = parent.Handle;
1842 create_params.Style = (int)WindowStyles.WS_CHILD | (int)WindowStyles.WS_CLIPCHILDREN | (int)WindowStyles.WS_CLIPSIBLINGS;
1845 create_params.Style |= (int)WindowStyles.WS_VISIBLE;
1848 return create_params;
1852 protected virtual ImeMode DefaultImeMode {
1854 return ImeMode.Inherit;
1858 protected virtual Size DefaultSize {
1860 return new Size(100, 23);
1864 protected int FontHeight {
1874 protected bool RenderRightToLeft {
1876 return (this.right_to_left == RightToLeft.Yes);
1880 protected bool ResizeRedraw {
1882 return GetStyle(ControlStyles.ResizeRedraw);
1886 SetStyle(ControlStyles.ResizeRedraw, value);
1890 [EditorBrowsable(EditorBrowsableState.Advanced)]
1892 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1893 protected virtual bool ShowFocusCues {
1899 [EditorBrowsable(EditorBrowsableState.Advanced)]
1901 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1902 protected bool ShowKeyboardCues {
1907 #endregion // Protected Instance Properties
1909 #region Public Static Methods
1910 [EditorBrowsable(EditorBrowsableState.Advanced)]
1911 public static Control FromChildHandle(IntPtr handle) {
1912 IEnumerator control = Control.controls.GetEnumerator();
1914 while (control.MoveNext()) {
1915 if (((Control)control.Current).window.Handle == handle) {
1917 if (((Control)control.Current).Parent != null) {
1918 return ((Control)control.Current).Parent;
1925 [EditorBrowsable(EditorBrowsableState.Advanced)]
1926 public static Control FromHandle(IntPtr handle) {
1927 IEnumerator control = Control.controls.GetEnumerator();
1929 while (control.MoveNext()) {
1930 if (((Control)control.Current).window.Handle == handle) {
1932 return ((Control)control.Current);
1938 public static bool IsMnemonic(char charCode, string text) {
1941 amp = text.IndexOf('&');
1944 if (amp + 1 < text.Length) {
1945 if (text[amp + 1] != '&') {
1946 if (Char.ToUpper(charCode) == Char.ToUpper(text.ToCharArray(amp + 1, 1)[0])) {
1956 #region Protected Static Methods
1957 [EditorBrowsable(EditorBrowsableState.Advanced)]
1958 protected static bool ReflectMessage(IntPtr hWnd, ref Message m) {
1961 c = Control.FromHandle(hWnd);
1971 #region Public Instance Methods
1972 [EditorBrowsable(EditorBrowsableState.Advanced)]
1973 public IAsyncResult BeginInvoke(Delegate method) {
1974 return BeginInvokeInternal(method, null);
1977 [EditorBrowsable(EditorBrowsableState.Advanced)]
1978 public IAsyncResult BeginInvoke (Delegate method, object[] args) {
1979 return BeginInvokeInternal (method, args);
1982 public void BringToFront() {
1983 if ((parent != null) && (parent.child_controls[0]!=this)) {
1984 if (parent.child_controls.Contains(this)) {
1985 parent.child_controls.SetChildIndex(this, 0);
1989 XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, true, false);
1991 if (parent != null) {
1996 public bool Contains(Control ctl) {
1997 while (ctl != null) {
2006 public void CreateControl() {
2008 if (!IsHandleCreated)
2011 for (int i=0; i<child_controls.Count; i++) {
2012 child_controls[i].CreateControl();
2017 public Graphics CreateGraphics() {
2018 if (!IsHandleCreated) {
2019 this.CreateHandle();
2021 return Graphics.FromHwnd(this.window.Handle);
2024 [MonoTODO("Come up with cross platform drag-drop driver interface")]
2025 public DragDropEffects DoDragDrop(object data, DragDropEffects allowedEffects) {
2026 return DragDropEffects.None;
2029 [EditorBrowsable(EditorBrowsableState.Advanced)]
2030 public object EndInvoke (IAsyncResult async_result) {
2031 AsyncMethodResult result = (AsyncMethodResult) async_result;
2032 return result.EndInvoke ();
2035 public Form FindForm() {
2048 public bool Focus() {
2049 if (IsHandleCreated && !has_focus) {
2050 XplatUI.SetFocus(window.Handle);
2056 public Control GetChildAtPoint(Point pt) {
2057 // Microsoft's version of this function doesn't seem to work, so I can't check
2058 // if we only consider children or also grandchildren, etc.
2059 // I'm gonna say 'children only'
2060 for (int i=0; i<child_controls.Count; i++) {
2061 if (child_controls[i].Bounds.Contains(pt)) {
2062 return child_controls[i];
2068 public IContainerControl GetContainerControl() {
2069 Control current = this;
2071 while (current!=null) {
2072 if ((current is IContainerControl) && ((current.control_style & ControlStyles.ContainerControl)!=0)) {
2073 return (IContainerControl)current;
2075 current = current.parent;
2080 public Control GetNextControl(Control ctl, bool forward) {
2081 // If we're not a container we don't play
2082 if (!(this is IContainerControl) && !this.GetStyle(ControlStyles.ContainerControl)) {
2086 // If ctl is not contained by this, we start at the first child of this
2087 if (!this.Contains(ctl)) {
2091 // Search through our controls, starting at ctl, stepping into children as we encounter them
2092 // try to find the control with the tabindex closest to our own, or, if we're looking into
2093 // child controls, the one with the smallest tabindex
2095 return FindControlForward(this, ctl);
2097 return FindControlBackward(this, ctl);
2100 public void Hide() {
2101 this.Visible = false;
2104 public void Invalidate() {
2105 Invalidate(ClientRectangle, false);
2108 public void Invalidate(bool invalidateChildren) {
2109 Invalidate(ClientRectangle, invalidateChildren);
2112 public void Invalidate(System.Drawing.Rectangle rc) {
2113 Invalidate(rc, false);
2116 public void Invalidate(System.Drawing.Rectangle rc, bool invalidateChildren) {
2117 if (!IsHandleCreated || !Visible) {
2121 NotifyInvalidate(rc);
2123 XplatUI.Invalidate(Handle, rc, !GetStyle (ControlStyles.AllPaintingInWmPaint));
2125 if (invalidateChildren) {
2126 for (int i=0; i<child_controls.Count; i++) child_controls[i].Invalidate();
2128 OnInvalidated(new InvalidateEventArgs(rc));
2131 public void Invalidate(System.Drawing.Region region) {
2132 Invalidate(region, false);
2135 [MonoTODO("Figure out if GetRegionScans is usable")]
2136 public void Invalidate(System.Drawing.Region region, bool invalidateChildren) {
2137 throw new NotImplementedException();
2139 // FIXME - should use the GetRegionScans function of the region to invalidate each area
2140 //if (invalidateChildren) {
2141 // for (int i=0; i<child_controls.Count; i++) child_controls[i].Invalidate();
2145 public object Invoke (Delegate method) {
2146 return Invoke(method, null);
2149 public object Invoke (Delegate method, object[] args) {
2150 IAsyncResult result = BeginInvoke (method, args);
2151 return EndInvoke(result);
2154 [EditorBrowsable(EditorBrowsableState.Advanced)]
2155 public void PerformLayout() {
2156 PerformLayout(null, null);
2159 [EditorBrowsable(EditorBrowsableState.Advanced)]
2160 public void PerformLayout(Control affectedControl, string affectedProperty) {
2161 LayoutEventArgs levent = new LayoutEventArgs(affectedControl, affectedProperty);
2163 if (layout_suspended>0) {
2164 layout_pending = true;
2168 layout_pending = false;
2170 // Prevent us from getting messed up
2173 // Perform all Dock and Anchor calculations
2176 AnchorStyles anchor;
2181 space=this.DisplayRectangle;
2182 if (prev_size != Size.Empty) {
2183 diff_width = space.Width - prev_size.Width;
2184 diff_height = space.Height - prev_size.Height;
2190 // Deal with docking; go through in reverse, MS docs say that lowest Z-order is closest to edge
2191 for (int i = child_controls.Count - 1; i >= 0; i--) {
2192 child=child_controls[i];
2193 switch (child.Dock) {
2194 case DockStyle.None: {
2199 case DockStyle.Left: {
2200 child.SetBounds(space.Left, space.Y, child.Width, space.Height);
2201 space.X+=child.Width;
2202 space.Width-=child.Width;
2206 case DockStyle.Top: {
2207 child.SetBounds(space.Left, space.Y, space.Width, child.Height);
2208 space.Y+=child.Height;
2209 space.Height-=child.Height;
2213 case DockStyle.Right: {
2214 child.SetBounds(space.Right-child.Width, space.Y, child.Width, space.Height);
2215 space.Width-=child.Width;
2219 case DockStyle.Bottom: {
2220 child.SetBounds(space.Left, space.Bottom-child.Height, space.Width, child.Height);
2221 space.Height-=child.Height;
2227 for (int i = child_controls.Count - 1; i >= 0; i--) {
2228 child=child_controls[i];
2230 if (child.Dock == DockStyle.Fill) {
2231 child.SetBounds(space.Left, space.Top, space.Width, space.Height);
2237 space=this.DisplayRectangle;
2239 // Deal with anchoring
2240 for (int i=0; i < child_controls.Count; i++) {
2246 child=child_controls[i];
2247 anchor=child.Anchor;
2252 height=child.Height;
2254 // If the control is docked we don't need to do anything
2255 if (child.Dock != DockStyle.None) {
2259 if ((anchor & AnchorStyles.Left) !=0 ) {
2260 if ((anchor & AnchorStyles.Right) != 0) {
2261 // Anchoring to left and right
2262 width=width+diff_width;
2266 } else if ((anchor & AnchorStyles.Right) != 0) {
2272 if ((anchor & AnchorStyles.Top) !=0 ) {
2273 if ((anchor & AnchorStyles.Bottom) != 0) {
2274 height+=diff_height;
2278 } else if ((anchor & AnchorStyles.Bottom) != 0) {
2293 child.SetBounds(left, top, width, height);
2296 // Let everyone know
2300 // Need to make sure we decremend layout_suspended
2306 public Point PointToClient (Point p) {
2310 XplatUI.ScreenToClient (Handle, ref x, ref y);
2312 return new Point (x, y);
2315 public Point PointToScreen(Point p) {
2319 XplatUI.ClientToScreen(Handle, ref x, ref y);
2321 return new Point(x, y);
2324 public virtual bool PreProcessMessage(ref Message msg) {
2327 if (msg.Msg == (int)Msg.WM_KEYDOWN) {
2328 key_data = (Keys)msg.WParam.ToInt32();
2329 if (!ProcessCmdKey(ref msg, key_data)) {
2330 if (IsInputKey(key_data)) {
2334 return ProcessDialogKey(key_data);
2338 } else if (msg.Msg == (int)Msg.WM_CHAR) {
2339 if (IsInputChar((char)msg.WParam)) {
2343 return ProcessDialogChar((char)msg.WParam);
2349 public Rectangle RectangleToClient(Rectangle r) {
2350 return new Rectangle(PointToClient(r.Location), r.Size);
2353 public Rectangle RectangleToScreen(Rectangle r) {
2354 return new Rectangle(PointToScreen(r.Location), r.Size);
2357 public virtual void Refresh() {
2358 if (IsHandleCreated == true) {
2360 XplatUI.UpdateWindow(window.Handle);
2364 [EditorBrowsable(EditorBrowsableState.Never)]
2365 public virtual void ResetBackColor() {
2366 background_color = Color.Empty;
2369 #if haveDataBindings
2370 [EditorBrowsable(EditorBrowsableState.Never)]
2372 public void ResetBindings() {
2377 [EditorBrowsable(EditorBrowsableState.Never)]
2378 public virtual void ResetCursor() {
2382 [EditorBrowsable(EditorBrowsableState.Never)]
2383 public virtual void ResetFont() {
2387 [EditorBrowsable(EditorBrowsableState.Never)]
2388 public virtual void ResetForeColor() {
2389 foreground_color = Color.Empty;
2392 [EditorBrowsable(EditorBrowsableState.Never)]
2393 public void ResetImeMode() {
2394 ime_mode = DefaultImeMode;
2397 [EditorBrowsable(EditorBrowsableState.Never)]
2398 public virtual void ResetRightToLeft() {
2399 right_to_left = RightToLeft.Inherit;
2402 public virtual void ResetText() {
2406 public void ResumeLayout() {
2407 ResumeLayout (true);
2410 public void ResumeLayout(bool performLayout) {
2413 if (layout_suspended > 0) {
2417 if (performLayout || layout_pending) {
2422 public void Scale(float ratio) {
2423 ScaleCore(ratio, ratio);
2426 public void Scale(float dx, float dy) {
2430 public void Select() {
2431 Select(false, false);
2434 public bool SelectNextControl(Control ctl, bool forward, bool tabStopOnly, bool nested, bool wrap) {
2439 c = GetNextControl(c, forward);
2448 if (c.CanSelect && ((c.parent == ctl.parent) || nested) && (c.tab_stop || !tabStopOnly)) {
2452 } while (c != ctl); // If we wrap back to ourselves we stop
2457 public void SendToBack() {
2458 if ((parent != null) && (parent.child_controls[parent.child_controls.Count-1]!=this)) {
2459 if (parent.child_controls.Contains(this)) {
2460 parent.child_controls.SetChildIndex(this, parent.child_controls.Count);
2464 XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, false, true);
2465 if (parent != null) {
2470 public void SetBounds(int x, int y, int width, int height) {
2471 SetBoundsCore(x, y, width, height, BoundsSpecified.All);
2474 public void SetBounds(int x, int y, int width, int height, BoundsSpecified specified) {
2475 SetBoundsCore(x, y, width, height, specified);
2478 public void Show() {
2479 if (!IsHandleCreated) {
2480 this.CreateHandle();
2486 public void SuspendLayout() {
2490 public void Update() {
2491 XplatUI.UpdateWindow(window.Handle);
2493 #endregion // Public Instance Methods
2495 #region Protected Instance Methods
2496 [EditorBrowsable(EditorBrowsableState.Advanced)]
2497 [MonoTODO("Implement this and tie it into Control.ControlAccessibleObject.NotifyClients")]
2498 protected void AccessibilityNotifyClients(AccessibleEvents accEvent, int childID) {
2499 throw new NotImplementedException();
2502 [EditorBrowsable(EditorBrowsableState.Advanced)]
2503 protected virtual AccessibleObject CreateAccessibilityInstance() {
2504 return new Control.ControlAccessibleObject(this);
2507 [EditorBrowsable(EditorBrowsableState.Advanced)]
2508 protected virtual ControlCollection CreateControlsInstance() {
2509 return new ControlCollection(this);
2512 [EditorBrowsable(EditorBrowsableState.Advanced)]
2513 protected virtual void CreateHandle() {
2515 throw new ObjectDisposedException(Name);
2518 if (IsHandleCreated) {
2523 window = new ControlNativeWindow(this);
2524 window.CreateHandle(CreateParams);
2526 // Find out where the window manager placed us
2531 if (window.Handle!=IntPtr.Zero) {
2532 if (!controls.Contains(window.Handle)) {
2536 creator_thread = Thread.CurrentThread;
2538 XplatUI.SetWindowBackground(window.Handle, this.BackColor);
2540 OnHandleCreated(EventArgs.Empty);
2544 [EditorBrowsable(EditorBrowsableState.Advanced)]
2545 protected virtual void DefWndProc(ref Message m) {
2546 window.DefWndProc(ref m);
2549 [EditorBrowsable(EditorBrowsableState.Advanced)]
2550 protected virtual void DestroyHandle() {
2551 if (IsHandleCreated) {
2552 if (Handle != IntPtr.Zero) {
2553 controls.Remove(Handle);
2556 if (window != null) {
2557 window.DestroyHandle();
2562 protected bool GetStyle(ControlStyles flag) {
2563 return (control_style & flag) != 0;
2566 protected bool GetTopLevel() {
2570 [EditorBrowsable(EditorBrowsableState.Advanced)]
2571 protected virtual void InitLayout() {
2572 if (parent != null) {
2573 parent.PerformLayout(this, "parent");
2577 [EditorBrowsable(EditorBrowsableState.Advanced)]
2578 protected void InvokeGotFocus(Control toInvoke, EventArgs e) {
2579 toInvoke.OnGotFocus(e);
2582 [EditorBrowsable(EditorBrowsableState.Advanced)]
2583 protected void InvokeLostFocus(Control toInvoke, EventArgs e) {
2584 toInvoke.OnLostFocus(e);
2587 [EditorBrowsable(EditorBrowsableState.Advanced)]
2588 protected void InvokeOnClick(Control toInvoke, EventArgs e) {
2589 toInvoke.OnClick(e);
2592 protected void InvokePaint(Control toInvoke, PaintEventArgs e) {
2593 toInvoke.OnPaint(e);
2596 protected void InvokePaintBackground(Control toInvoke, PaintEventArgs e) {
2597 toInvoke.OnPaintBackground(e);
2600 protected virtual bool IsInputChar (char charCode) {
2601 if (parent != null) {
2602 return parent.IsInputChar(charCode);
2608 protected virtual bool IsInputKey (Keys keyData) {
2609 // Doc says this one calls IsInputChar; not sure what to do with that
2613 [EditorBrowsable(EditorBrowsableState.Advanced)]
2614 protected virtual void NotifyInvalidate(Rectangle invalidatedArea) {
2618 protected virtual bool ProcessCmdKey(ref Message msg, Keys keyData) {
2619 if ((context_menu != null) && context_menu.ProcessCmdKey(ref msg, keyData)) {
2623 if (parent != null) {
2624 return parent.ProcessCmdKey(ref msg, keyData);
2630 protected virtual bool ProcessDialogChar(char charCode) {
2631 if (parent != null) {
2632 return parent.ProcessDialogChar (charCode);
2638 protected virtual bool ProcessDialogKey (Keys keyData) {
2639 if (parent != null) {
2640 return parent.ProcessDialogKey (keyData);
2646 protected virtual bool ProcessKeyEventArgs (ref Message msg)
2648 KeyEventArgs key_event;
2650 PreProcessMessage(ref msg);
2653 case (int)Msg.WM_KEYDOWN: {
2654 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
2655 OnKeyDown (key_event);
2656 return key_event.Handled;
2658 case (int)Msg.WM_KEYUP: {
2659 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
2660 OnKeyUp (key_event);
2661 return key_event.Handled;
2664 case (int)Msg.WM_CHAR: {
2665 KeyPressEventArgs key_press_event;
2667 key_press_event = new KeyPressEventArgs((char)msg.WParam);
2668 OnKeyPress(key_press_event);
2669 return key_press_event.Handled;
2680 protected internal virtual bool ProcessKeyMessage(ref Message msg) {
2681 if (parent != null) {
2682 if (parent.ProcessKeyPreview(ref msg)) {
2687 return ProcessKeyEventArgs(ref msg);
2690 protected virtual bool ProcessKeyPreview(ref Message msg) {
2691 if (parent != null) {
2692 return parent.ProcessKeyPreview(ref msg);
2698 protected virtual bool ProcessMnemonic(char charCode) {
2703 [EditorBrowsable(EditorBrowsableState.Advanced)]
2704 protected void RaiseDragEvent(object key, DragEventArgs e) {
2708 [EditorBrowsable(EditorBrowsableState.Advanced)]
2709 protected void RaiseKeyEvent(object key, KeyEventArgs e) {
2713 [EditorBrowsable(EditorBrowsableState.Advanced)]
2714 protected void RaiseMouseEvent(object key, MouseEventArgs e) {
2718 [EditorBrowsable(EditorBrowsableState.Advanced)]
2719 protected void RaisePaintEvent(object key, PaintEventArgs e) {
2723 [EditorBrowsable(EditorBrowsableState.Advanced)]
2724 protected void RecreateHandle() {
2725 IEnumerator child = child_controls.GetEnumerator();
2729 if (IsHandleCreated) {
2735 while (child.MoveNext()) {
2736 ((Control)child.Current).RecreateHandle();
2742 is_recreating = false;
2745 [EditorBrowsable(EditorBrowsableState.Advanced)]
2746 protected void ResetMouseEventArgs() {
2750 [EditorBrowsable(EditorBrowsableState.Advanced)]
2751 protected ContentAlignment RtlTranslateAlignment(ContentAlignment align) {
2752 if (right_to_left == RightToLeft.No) {
2757 case ContentAlignment.TopLeft: {
2758 return ContentAlignment.TopRight;
2761 case ContentAlignment.TopRight: {
2762 return ContentAlignment.TopLeft;
2765 case ContentAlignment.MiddleLeft: {
2766 return ContentAlignment.MiddleRight;
2769 case ContentAlignment.MiddleRight: {
2770 return ContentAlignment.MiddleLeft;
2773 case ContentAlignment.BottomLeft: {
2774 return ContentAlignment.BottomRight;
2777 case ContentAlignment.BottomRight: {
2778 return ContentAlignment.BottomLeft;
2782 // if it's center it doesn't change
2788 [EditorBrowsable(EditorBrowsableState.Advanced)]
2789 protected HorizontalAlignment RtlTranslateAlignment(HorizontalAlignment align) {
2790 if ((right_to_left == RightToLeft.No) || (align == HorizontalAlignment.Center)) {
2794 if (align == HorizontalAlignment.Left) {
2795 return HorizontalAlignment.Right;
2798 // align must be HorizontalAlignment.Right
2799 return HorizontalAlignment.Left;
2802 [EditorBrowsable(EditorBrowsableState.Advanced)]
2803 protected LeftRightAlignment RtlTranslateAlignment(LeftRightAlignment align) {
2804 if (right_to_left == RightToLeft.No) {
2808 if (align == LeftRightAlignment.Left) {
2809 return LeftRightAlignment.Right;
2812 // align must be LeftRightAlignment.Right;
2813 return LeftRightAlignment.Left;
2816 [EditorBrowsable(EditorBrowsableState.Advanced)]
2817 protected ContentAlignment RtlTranslateContent(ContentAlignment align) {
2818 return RtlTranslateAlignment(align);
2821 [EditorBrowsable(EditorBrowsableState.Advanced)]
2822 protected HorizontalAlignment RtlTranslateHorizontal(HorizontalAlignment align) {
2823 return RtlTranslateAlignment(align);
2826 [EditorBrowsable(EditorBrowsableState.Advanced)]
2827 protected LeftRightAlignment RtlTranslateLeftRight(LeftRightAlignment align) {
2828 return RtlTranslateAlignment(align);
2831 [EditorBrowsable(EditorBrowsableState.Advanced)]
2832 protected virtual void ScaleCore(float dx, float dy) {
2838 location = new Point((int)(Left * dx), (int)(Top * dy));
2839 size = this.ClientSize;
2842 if (!GetStyle(ControlStyles.FixedWidth)) {
2843 size.Width = (int)(size.Width * dx);
2846 if (!GetStyle(ControlStyles.FixedHeight)) {
2847 size.Height = (int)(size.Height * dy);
2850 Location = location;
2853 /* Now scale our children */
2854 for (int i=0; i < child_controls.Count; i++) {
2855 child_controls[i].Scale(dx, dy);
2861 protected virtual void Select(bool directed, bool forward) {
2866 // Select this control
2871 if (parent == null) {
2875 index = parent.child_controls.IndexOf(this);
2880 if ((index+1) < parent.child_controls.Count) {
2889 index = parent.child_controls.Count-1;
2892 result = Select(parent.child_controls[index]);
2893 } while (!result && parent.child_controls[index] != this);
2896 [EditorBrowsable(EditorBrowsableState.Advanced)]
2897 protected virtual void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
2898 // SetBoundsCore updates the Win32 control itself. UpdateBounds updates the controls variables and fires events, I'm guessing - pdb
2899 if ((specified & BoundsSpecified.X) != BoundsSpecified.X) {
2903 if ((specified & BoundsSpecified.Y) != BoundsSpecified.Y) {
2907 if ((specified & BoundsSpecified.Width)!= BoundsSpecified.Width) {
2911 if ((specified & BoundsSpecified.Height) != BoundsSpecified.Height) {
2915 if (IsHandleCreated) {
2916 XplatUI.SetWindowPos(Handle, x, y, width, height);
2918 UpdateBounds(x, y, width, height);
2921 [EditorBrowsable(EditorBrowsableState.Advanced)]
2922 protected virtual void SetClientSizeCore(int x, int y) {
2923 // Calculate the actual window size from the client size (it usually stays the same or grows)
2924 Rectangle ClientRect;
2925 Rectangle WindowRect;
2928 ClientRect = new Rectangle(0, 0, x, y);
2929 cp = this.CreateParams;
2931 if (XplatUI.CalculateWindowRect(Handle, ref ClientRect, cp.Style, cp.ExStyle, IntPtr.Zero, out WindowRect)==false) {
2935 SetBoundsCore(bounds.X, bounds.Y, WindowRect.Width, WindowRect.Height, BoundsSpecified.Size);
2938 [EditorBrowsable(EditorBrowsableState.Advanced)]
2939 protected void SetStyle(ControlStyles flag, bool value) {
2941 control_style |= flag;
2943 control_style &= ~flag;
2947 protected void SetTopLevel(bool value) {
2948 if ((GetTopLevel() != value) && (parent != null)) {
2949 throw new Exception();
2953 if (value == true) {
2963 is_toplevel = value;
2966 protected virtual void SetVisibleCore(bool value) {
2967 if (value!=is_visible) {
2969 XplatUI.SetVisible(Handle, value);
2970 // Explicitly move Toplevel windows to where we want them;
2971 // apparently moving unmapped toplevel windows doesn't work
2972 if (is_visible && (this is Form)) {
2973 XplatUI.SetWindowPos(window.Handle, bounds.X, bounds.Y, bounds.Width, bounds.Height);
2975 OnVisibleChanged(EventArgs.Empty);
2978 if (dc_mem != null) {
2983 if (bmp_mem != null) {
2988 this.CreateBuffers(bounds.Width, bounds.Height);
2991 // FIXME - deal with focus
2993 if (parent != null) {
2994 parent.PerformLayout(this, "visible");
2996 PerformLayout(this, "visible");
3001 [EditorBrowsable(EditorBrowsableState.Advanced)]
3002 protected void UpdateBounds() {
3010 if (!IsHandleCreated) {
3014 XplatUI.GetWindowPos(this.Handle, this is Form, out x, out y, out width, out height, out client_width, out client_height);
3015 UpdateBounds(x, y, width, height, client_width, client_height);
3018 [EditorBrowsable(EditorBrowsableState.Advanced)]
3019 protected void UpdateBounds(int x, int y, int width, int height) {
3020 // UpdateBounds only seems to set our sizes and fire events but not update the GUI window to match
3022 bool resized = false;
3024 int client_x_diff = this.bounds.Width-this.client_size.Width;
3025 int client_y_diff = this.bounds.Height-this.client_size.Height;
3027 // Needed to generate required notifications
3028 if ((this.bounds.X!=x) || (this.bounds.Y!=y)) {
3032 if ((this.Bounds.Width!=width) || (this.Bounds.Height!=height)) {
3039 bounds.Height=height;
3041 // Update client rectangle as well
3042 if (this.layout_suspended==0) {
3043 prev_size.Width=client_size.Width;
3044 prev_size.Height=client_size.Height;
3047 client_size.Width=width-client_x_diff;
3048 client_size.Height=height-client_y_diff;
3051 OnLocationChanged(EventArgs.Empty);
3055 OnSizeChanged(EventArgs.Empty);
3059 [EditorBrowsable(EditorBrowsableState.Advanced)]
3060 protected void UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) {
3061 UpdateBounds(x, y, width, height);
3063 this.client_size.Width=clientWidth;
3064 this.client_size.Height=clientHeight;
3067 [EditorBrowsable(EditorBrowsableState.Advanced)]
3068 protected void UpdateStyles() {
3069 if (!IsHandleCreated) {
3073 XplatUI.SetWindowStyle(window.Handle, CreateParams);
3076 protected void UpdateZOrder() {
3081 if (parent == null) {
3087 children = ctl.child_controls.Count;
3088 for (int i = 1; i < children; i++ ) {
3089 XplatUI.SetZOrder(ctl.child_controls[i].window.Handle, ctl.child_controls[i-1].window.Handle, false, false);
3092 children = child_controls.Count;
3093 for (int i = 1; i < children; i++ ) {
3094 XplatUI.SetZOrder(child_controls[i].window.Handle, child_controls[i-1].window.Handle, false, false);
3099 protected virtual void WndProc(ref Message m) {
3101 Console.WriteLine("Control received message {0}", (Msg)m.Msg);
3103 if ((this.control_style & ControlStyles.EnableNotifyMessage) != 0) {
3107 switch((Msg)m.Msg) {
3108 case Msg.WM_WINDOWPOSCHANGED: {
3111 if (GetStyle(ControlStyles.ResizeRedraw)) {
3118 case Msg.WM_PAINT: {
3119 PaintEventArgs paint_event;
3121 paint_event = XplatUI.PaintEventStart(Handle);
3123 if (GetStyle(ControlStyles.AllPaintingInWmPaint)) {
3124 OnPaintBackground(paint_event);
3126 OnPaint(paint_event);
3127 XplatUI.PaintEventEnd(Handle);
3132 case Msg.WM_ERASEBKGND: {
3133 if (GetStyle (ControlStyles.UserPaint)) {
3134 if (!GetStyle(ControlStyles.AllPaintingInWmPaint)) {
3135 PaintEventArgs eraseEventArgs = new PaintEventArgs (m.WParam == IntPtr.Zero ? Graphics.FromHwnd (m.HWnd) :
3136 Graphics.FromHdc (m.WParam), new Rectangle (new Point (0,0),Size));
3137 OnPaintBackground (eraseEventArgs);
3139 m.Result = (IntPtr)1;
3141 m.Result = IntPtr.Zero;
3148 case Msg.WM_LBUTTONUP: {
3149 HandleClick(mouse_clicks);
3150 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Left,
3152 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3154 if (mouse_clicks > 1) {
3160 case Msg.WM_LBUTTONDOWN: {
3161 if (CanSelect && !is_selected) {
3164 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3165 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3171 case Msg.WM_LBUTTONDBLCLK: {
3173 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3174 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3180 case Msg.WM_MBUTTONUP: {
3181 HandleClick(mouse_clicks);
3182 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Middle,
3184 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3186 if (mouse_clicks > 1) {
3192 case Msg.WM_MBUTTONDOWN: {
3193 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3194 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3200 case Msg.WM_MBUTTONDBLCLK: {
3202 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3203 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3208 case Msg.WM_RBUTTONUP: {
3209 HandleClick(mouse_clicks);
3210 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Right,
3212 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3214 if (mouse_clicks > 1) {
3220 case Msg.WM_RBUTTONDOWN: {
3221 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3222 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3227 case Msg.WM_RBUTTONDBLCLK: {
3229 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3230 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3235 case Msg.WM_MOUSEWHEEL: {
3237 OnMouseWheel (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3238 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3239 HighOrder(m.WParam.ToInt32())));
3244 case Msg.WM_MOUSEMOVE: {
3245 OnMouseMove (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3247 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3252 case Msg.WM_MOUSE_ENTER: {
3257 OnMouseEnter(EventArgs.Empty);
3261 case Msg.WM_MOUSE_LEAVE: {
3263 OnMouseLeave(EventArgs.Empty);
3267 case Msg.WM_MOUSEHOVER: {
3268 OnMouseHover(EventArgs.Empty);
3272 case Msg.WM_KEYDOWN: {
3273 if (!ProcessKeyMessage(ref m)) {
3279 case Msg.WM_KEYUP: {
3280 if (!ProcessKeyMessage(ref m)) {
3287 if (!ProcessKeyMessage(ref m)) {
3295 if (m.LParam != IntPtr.Zero) {
3298 hi = new HELPINFO();
3300 hi = (HELPINFO) Marshal.PtrToStructure (m.LParam, typeof (HELPINFO));
3301 mouse_pos = new Point(hi.MousePos.x, hi.MousePos.y);
3303 mouse_pos = Control.MousePosition;
3305 OnHelpRequested(new HelpEventArgs(mouse_pos));
3306 m.Result = (IntPtr)1;
3310 case Msg.WM_KILLFOCUS: {
3311 OnLeave(EventArgs.Empty);
3312 if (CausesValidation) {
3314 e = new CancelEventArgs(false);
3323 OnValidated(EventArgs.Empty);
3326 this.has_focus = false;
3327 this.is_selected = false;
3328 OnLostFocus(EventArgs.Empty);
3332 case Msg.WM_SETFOCUS: {
3333 OnEnter(EventArgs.Empty);
3334 this.has_focus = true;
3335 OnGotFocus(EventArgs.Empty);
3340 case Msg.WM_SYSCOLORCHANGE: {
3341 ThemeEngine.Current.ResetDefaults();
3342 OnSystemColorsChanged(EventArgs.Empty);
3347 case Msg.WM_SETCURSOR: {
3348 if (cursor == null) {
3353 XplatUI.SetCursor(window.Handle, cursor.handle);
3354 m.Result = (IntPtr)1;
3364 #endregion // Public Instance Methods
3366 #region OnXXX methods
3367 [EditorBrowsable(EditorBrowsableState.Advanced)]
3368 protected virtual void OnBackColorChanged(EventArgs e) {
3369 if (BackColorChanged!=null) BackColorChanged(this, e);
3370 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackColorChanged(e);
3373 [EditorBrowsable(EditorBrowsableState.Advanced)]
3374 protected virtual void OnBackgroundImageChanged(EventArgs e) {
3375 if (BackgroundImageChanged!=null) BackgroundImageChanged(this, e);
3376 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackgroundImageChanged(e);
3379 [EditorBrowsable(EditorBrowsableState.Advanced)]
3380 protected virtual void OnBindingContextChanged(EventArgs e) {
3381 if (BindingContextChanged!=null) BindingContextChanged(this, e);
3382 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBindingContextChanged(e);
3385 [EditorBrowsable(EditorBrowsableState.Advanced)]
3386 protected virtual void OnCausesValidationChanged(EventArgs e) {
3387 if (CausesValidationChanged!=null) CausesValidationChanged(this, e);
3390 [EditorBrowsable(EditorBrowsableState.Advanced)]
3391 protected virtual void OnChangeUICues(UICuesEventArgs e) {
3392 if (ChangeUICues!=null) ChangeUICues(this, e);
3395 [EditorBrowsable(EditorBrowsableState.Advanced)]
3396 protected virtual void OnClick(EventArgs e) {
3397 if (Click!=null) Click(this, e);
3400 [EditorBrowsable(EditorBrowsableState.Advanced)]
3401 protected virtual void OnContextMenuChanged(EventArgs e) {
3402 if (ContextMenuChanged!=null) ContextMenuChanged(this, e);
3405 [EditorBrowsable(EditorBrowsableState.Advanced)]
3406 protected virtual void OnControlAdded(ControlEventArgs e) {
3407 if (ControlAdded!=null) ControlAdded(this, e);
3410 [EditorBrowsable(EditorBrowsableState.Advanced)]
3411 protected virtual void OnControlRemoved(ControlEventArgs e) {
3412 if (ControlRemoved!=null) ControlRemoved(this, e);
3415 [EditorBrowsable(EditorBrowsableState.Advanced)]
3416 protected virtual void OnCreateControl() {
3420 [EditorBrowsable(EditorBrowsableState.Advanced)]
3421 protected virtual void OnCursorChanged(EventArgs e) {
3422 if (CursorChanged!=null) CursorChanged(this, e);
3425 [EditorBrowsable(EditorBrowsableState.Advanced)]
3426 protected virtual void OnDockChanged(EventArgs e) {
3427 if (DockChanged!=null) DockChanged(this, e);
3430 [EditorBrowsable(EditorBrowsableState.Advanced)]
3431 protected virtual void OnDoubleClick(EventArgs e) {
3432 if (DoubleClick!=null) DoubleClick(this, e);
3435 [EditorBrowsable(EditorBrowsableState.Advanced)]
3436 protected virtual void OnDragDrop(DragEventArgs drgevent) {
3437 if (DragDrop!=null) DragDrop(this, drgevent);
3440 [EditorBrowsable(EditorBrowsableState.Advanced)]
3441 protected virtual void OnDragEnter(DragEventArgs drgevent) {
3442 if (DragEnter!=null) DragEnter(this, drgevent);
3445 [EditorBrowsable(EditorBrowsableState.Advanced)]
3446 protected virtual void OnDragLeave(EventArgs e) {
3447 if (DragLeave!=null) DragLeave(this, e);
3450 [EditorBrowsable(EditorBrowsableState.Advanced)]
3451 protected virtual void OnDragOver(DragEventArgs drgevent) {
3452 if (DragOver!=null) DragOver(this, drgevent);
3455 [EditorBrowsable(EditorBrowsableState.Advanced)]
3456 protected virtual void OnEnabledChanged(EventArgs e) {
3457 if (EnabledChanged!=null) EnabledChanged(this, e);
3458 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentEnabledChanged(e);
3461 [EditorBrowsable(EditorBrowsableState.Advanced)]
3462 protected virtual void OnEnter(EventArgs e) {
3463 if (Enter!=null) Enter(this, e);
3466 [EditorBrowsable(EditorBrowsableState.Advanced)]
3467 protected virtual void OnFontChanged(EventArgs e) {
3468 if (FontChanged!=null) FontChanged(this, e);
3469 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentFontChanged(e);
3472 [EditorBrowsable(EditorBrowsableState.Advanced)]
3473 protected virtual void OnForeColorChanged(EventArgs e) {
3474 if (ForeColorChanged!=null) ForeColorChanged(this, e);
3475 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentForeColorChanged(e);
3478 [EditorBrowsable(EditorBrowsableState.Advanced)]
3479 protected virtual void OnGiveFeedback(GiveFeedbackEventArgs gfbevent) {
3480 if (GiveFeedback!=null) GiveFeedback(this, gfbevent);
3483 [EditorBrowsable(EditorBrowsableState.Advanced)]
3484 protected virtual void OnGotFocus(EventArgs e) {
3485 if (GotFocus!=null) GotFocus(this, e);
3488 [EditorBrowsable(EditorBrowsableState.Advanced)]
3489 protected virtual void OnHandleCreated(EventArgs e) {
3490 if (HandleCreated!=null) HandleCreated(this, e);
3493 [EditorBrowsable(EditorBrowsableState.Advanced)]
3494 protected virtual void OnHandleDestroyed(EventArgs e) {
3495 if (HandleDestroyed!=null) HandleDestroyed(this, e);
3498 [EditorBrowsable(EditorBrowsableState.Advanced)]
3499 protected virtual void OnHelpRequested(HelpEventArgs hevent) {
3500 if (HelpRequested!=null) HelpRequested(this, hevent);
3503 protected virtual void OnImeModeChanged(EventArgs e) {
3504 if (ImeModeChanged!=null) ImeModeChanged(this, e);
3507 [EditorBrowsable(EditorBrowsableState.Advanced)]
3508 protected virtual void OnInvalidated(InvalidateEventArgs e) {
3509 if (Invalidated!=null) Invalidated(this, e);
3512 [EditorBrowsable(EditorBrowsableState.Advanced)]
3513 protected virtual void OnKeyDown(KeyEventArgs e) {
3514 if (KeyDown!=null) KeyDown(this, e);
3517 [EditorBrowsable(EditorBrowsableState.Advanced)]
3518 protected virtual void OnKeyPress(KeyPressEventArgs e) {
3519 if (KeyPress!=null) KeyPress(this, e);
3522 [EditorBrowsable(EditorBrowsableState.Advanced)]
3523 protected virtual void OnKeyUp(KeyEventArgs e) {
3524 if (KeyUp!=null) KeyUp(this, e);
3527 [EditorBrowsable(EditorBrowsableState.Advanced)]
3528 protected virtual void OnLayout(LayoutEventArgs levent) {
3529 if (Layout!=null) Layout(this, levent);
3532 [EditorBrowsable(EditorBrowsableState.Advanced)]
3533 protected virtual void OnLeave(EventArgs e) {
3534 if (Leave!=null) Leave(this, e);
3537 [EditorBrowsable(EditorBrowsableState.Advanced)]
3538 protected virtual void OnLocationChanged(EventArgs e) {
3540 if (LocationChanged!=null) LocationChanged(this, e);
3543 [EditorBrowsable(EditorBrowsableState.Advanced)]
3544 protected virtual void OnLostFocus(EventArgs e) {
3545 if (LostFocus!=null) LostFocus(this, e);
3548 [EditorBrowsable(EditorBrowsableState.Advanced)]
3549 protected virtual void OnMouseDown(MouseEventArgs e) {
3550 if (MouseDown!=null) MouseDown(this, e);
3553 [EditorBrowsable(EditorBrowsableState.Advanced)]
3554 protected virtual void OnMouseEnter(EventArgs e) {
3555 if (MouseEnter!=null) MouseEnter(this, e);
3558 [EditorBrowsable(EditorBrowsableState.Advanced)]
3559 protected virtual void OnMouseHover(EventArgs e) {
3560 if (MouseHover!=null) MouseHover(this, e);
3563 [EditorBrowsable(EditorBrowsableState.Advanced)]
3564 protected virtual void OnMouseLeave(EventArgs e) {
3565 if (MouseLeave!=null) MouseLeave(this, e);
3568 [EditorBrowsable(EditorBrowsableState.Advanced)]
3569 protected virtual void OnMouseMove(MouseEventArgs e) {
3570 if (MouseMove!=null) MouseMove(this, e);
3573 [EditorBrowsable(EditorBrowsableState.Advanced)]
3574 protected virtual void OnMouseUp(MouseEventArgs e) {
3575 if (MouseUp!=null) MouseUp(this, e);
3578 [EditorBrowsable(EditorBrowsableState.Advanced)]
3579 protected virtual void OnMouseWheel(MouseEventArgs e) {
3580 if (MouseWheel!=null) MouseWheel(this, e);
3583 [EditorBrowsable(EditorBrowsableState.Advanced)]
3584 protected virtual void OnMove(EventArgs e) {
3585 if (Move!=null) Move(this, e);
3588 [EditorBrowsable(EditorBrowsableState.Advanced)]
3589 protected virtual void OnNotifyMessage(Message m) {
3593 [EditorBrowsable(EditorBrowsableState.Advanced)]
3594 protected virtual void OnPaint(PaintEventArgs e) {
3595 if (Paint!=null) Paint(this, e);
3598 [EditorBrowsable(EditorBrowsableState.Advanced)]
3599 protected virtual void OnPaintBackground(PaintEventArgs pevent) {
3603 [EditorBrowsable(EditorBrowsableState.Advanced)]
3604 protected virtual void OnParentBackColorChanged(EventArgs e) {
3605 if (background_color.IsEmpty && background_image==null) {
3607 OnBackColorChanged(e);
3611 [EditorBrowsable(EditorBrowsableState.Advanced)]
3612 protected virtual void OnParentBackgroundImageChanged(EventArgs e) {
3613 if (background_color.IsEmpty && background_image==null) {
3615 OnBackgroundImageChanged(e);
3619 [EditorBrowsable(EditorBrowsableState.Advanced)]
3620 protected virtual void OnParentBindingContextChanged(EventArgs e) {
3621 if (binding_context==null) {
3622 binding_context=Parent.binding_context;
3623 OnBindingContextChanged(e);
3627 [EditorBrowsable(EditorBrowsableState.Advanced)]
3628 protected virtual void OnParentChanged(EventArgs e) {
3629 if (ParentChanged!=null) ParentChanged(this, e);
3632 [EditorBrowsable(EditorBrowsableState.Advanced)]
3633 protected virtual void OnParentEnabledChanged(EventArgs e) {
3634 if (is_enabled != Parent.is_enabled) {
3635 is_enabled=Parent.is_enabled;
3637 if (EnabledChanged != null) {
3638 EnabledChanged(this, e);
3643 [EditorBrowsable(EditorBrowsableState.Advanced)]
3644 protected virtual void OnParentFontChanged(EventArgs e) {
3651 [EditorBrowsable(EditorBrowsableState.Advanced)]
3652 protected virtual void OnParentForeColorChanged(EventArgs e) {
3653 if (foreground_color.IsEmpty) {
3655 OnForeColorChanged(e);
3659 [EditorBrowsable(EditorBrowsableState.Advanced)]
3660 protected virtual void OnParentRightToLeftChanged(EventArgs e) {
3661 if (right_to_left==RightToLeft.Inherit) {
3663 OnRightToLeftChanged(e);
3667 [EditorBrowsable(EditorBrowsableState.Advanced)]
3668 protected virtual void OnParentVisibleChanged(EventArgs e) {
3669 if (is_visible!=Parent.is_visible) {
3672 OnVisibleChanged(e);
3676 [EditorBrowsable(EditorBrowsableState.Advanced)]
3677 protected virtual void OnQueryContinueDrag(QueryContinueDragEventArgs e) {
3678 if (QueryContinueDrag!=null) QueryContinueDrag(this, e);
3681 [EditorBrowsable(EditorBrowsableState.Advanced)]
3682 protected virtual void OnResize(EventArgs e) {
3683 if (Resize!=null) Resize(this, e);
3685 PerformLayout(this, "bounds");
3687 if (parent != null) {
3688 parent.PerformLayout();
3692 [EditorBrowsable(EditorBrowsableState.Advanced)]
3693 protected virtual void OnRightToLeftChanged(EventArgs e) {
3694 if (RightToLeftChanged!=null) RightToLeftChanged(this, e);
3695 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentRightToLeftChanged(e);
3698 [EditorBrowsable(EditorBrowsableState.Advanced)]
3699 protected virtual void OnSizeChanged(EventArgs e) {
3700 InvalidateBuffers ();
3702 if (SizeChanged!=null) SizeChanged(this, e);
3705 [EditorBrowsable(EditorBrowsableState.Advanced)]
3706 protected virtual void OnStyleChanged(EventArgs e) {
3707 if (StyleChanged!=null) StyleChanged(this, e);
3710 [EditorBrowsable(EditorBrowsableState.Advanced)]
3711 protected virtual void OnSystemColorsChanged(EventArgs e) {
3712 if (SystemColorsChanged!=null) SystemColorsChanged(this, e);
3715 [EditorBrowsable(EditorBrowsableState.Advanced)]
3716 protected virtual void OnTabIndexChanged(EventArgs e) {
3717 if (TabIndexChanged!=null) TabIndexChanged(this, e);
3720 [EditorBrowsable(EditorBrowsableState.Advanced)]
3721 protected virtual void OnTabStopChanged(EventArgs e) {
3722 if (TabStopChanged!=null) TabStopChanged(this, e);
3725 [EditorBrowsable(EditorBrowsableState.Advanced)]
3726 protected virtual void OnTextChanged(EventArgs e) {
3727 if (TextChanged!=null) TextChanged(this, e);
3730 [EditorBrowsable(EditorBrowsableState.Advanced)]
3731 protected virtual void OnValidated(EventArgs e) {
3732 if (Validated!=null) Validated(this, e);
3735 [EditorBrowsable(EditorBrowsableState.Advanced)]
3736 protected virtual void OnValidating(System.ComponentModel.CancelEventArgs e) {
3737 if (Validating!=null) Validating(this, e);
3740 [EditorBrowsable(EditorBrowsableState.Advanced)]
3741 protected virtual void OnVisibleChanged(EventArgs e) {
3748 if (bmp_mem!=null) {
3754 if (!this.IsHandleCreated) {
3755 this.CreateHandle();
3761 if (VisibleChanged!=null) VisibleChanged(this, e);
3763 // We need to tell our kids
3764 for (int i=0; i<child_controls.Count; i++) {
3765 child_controls[i].OnParentVisibleChanged(e);
3768 #endregion // OnXXX methods
3771 public event EventHandler BackColorChanged;
3772 public event EventHandler BackgroundImageChanged;
3773 public event EventHandler BindingContextChanged;
3774 public event EventHandler CausesValidationChanged;
3775 public event UICuesEventHandler ChangeUICues;
3776 public event EventHandler Click;
3777 public event EventHandler ContextMenuChanged;
3779 [EditorBrowsable(EditorBrowsableState.Advanced)]
3781 public event ControlEventHandler ControlAdded;
3783 [EditorBrowsable(EditorBrowsableState.Advanced)]
3785 public event ControlEventHandler ControlRemoved;
3787 public event EventHandler CursorChanged;
3788 public event EventHandler DockChanged;
3789 public event EventHandler DoubleClick;
3790 public event DragEventHandler DragDrop;
3791 public event DragEventHandler DragEnter;
3792 public event EventHandler DragLeave;
3793 public event DragEventHandler DragOver;
3794 public event EventHandler EnabledChanged;
3795 public event EventHandler Enter;
3796 public event EventHandler FontChanged;
3797 public event EventHandler ForeColorChanged;
3798 public event GiveFeedbackEventHandler GiveFeedback;
3800 [EditorBrowsable(EditorBrowsableState.Advanced)]
3802 public event EventHandler GotFocus;
3804 [EditorBrowsable(EditorBrowsableState.Advanced)]
3806 public event EventHandler HandleCreated;
3808 [EditorBrowsable(EditorBrowsableState.Advanced)]
3810 public event EventHandler HandleDestroyed;
3812 public event HelpEventHandler HelpRequested;
3813 public event EventHandler ImeModeChanged;
3815 [EditorBrowsable(EditorBrowsableState.Advanced)]
3817 public event InvalidateEventHandler Invalidated;
3819 public event KeyEventHandler KeyDown;
3820 public event KeyPressEventHandler KeyPress;
3821 public event KeyEventHandler KeyUp;
3822 public event LayoutEventHandler Layout;
3823 public event EventHandler Leave;
3824 public event EventHandler LocationChanged;
3826 [EditorBrowsable(EditorBrowsableState.Advanced)]
3828 public event EventHandler LostFocus;
3830 public event MouseEventHandler MouseDown;
3831 public event EventHandler MouseEnter;
3832 public event EventHandler MouseHover;
3833 public event EventHandler MouseLeave;
3834 public event MouseEventHandler MouseMove;
3835 public event MouseEventHandler MouseUp;
3837 [EditorBrowsable(EditorBrowsableState.Advanced)]
3839 public event MouseEventHandler MouseWheel;
3841 public event EventHandler Move;
3842 public event PaintEventHandler Paint;
3843 public event EventHandler ParentChanged;
3844 public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp;
3845 public event QueryContinueDragEventHandler QueryContinueDrag;
3846 public event EventHandler Resize;
3847 public event EventHandler RightToLeftChanged;
3848 public event EventHandler SizeChanged;
3849 public event EventHandler StyleChanged;
3850 public event EventHandler SystemColorsChanged;
3851 public event EventHandler TabIndexChanged;
3852 public event EventHandler TabStopChanged;
3853 public event EventHandler TextChanged;
3854 public event EventHandler Validated;
3855 public event CancelEventHandler Validating;
3856 public event EventHandler VisibleChanged;
3857 #endregion // Events