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 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
114 private bool needs_redraw;
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;
545 right_to_left = RightToLeft.Inherit;
547 control_style = ControlStyles.Selectable | ControlStyles.StandardClick | ControlStyles.StandardDoubleClick;
550 background_image = null;
554 child_controls = CreateControlsInstance();
555 client_size = new Size(DefaultSize.Width, DefaultSize.Height);
556 client_rect = new Rectangle(0, 0, DefaultSize.Width, DefaultSize.Height);
557 XplatUI.CalculateWindowRect(IntPtr.Zero, ref client_rect, CreateParams.Style, CreateParams.ExStyle, IntPtr.Zero, out bounds);
558 if ((CreateParams.Style & (int)WindowStyles.WS_CHILD) == 0) {
564 public Control(Control parent, string text) : this() {
569 public Control(Control parent, string text, int left, int top, int width, int height) : this() {
574 bounds.Height=height;
575 SetBoundsCore(left, top, width, height, BoundsSpecified.All);
579 public Control(string text) : this() {
583 public Control(string text, int left, int top, int width, int height) : this() {
587 bounds.Height=height;
588 SetBoundsCore(left, top, width, height, BoundsSpecified.All);
592 protected override void Dispose(bool disposing) {
605 controls.Remove(this);
607 #endregion // Public Constructors
609 #region Internal Properties
610 internal BorderStyle InternalBorderStyle {
616 if (border_style != value) {
617 border_style = value;
619 XplatUI.SetBorderStyle(window.Handle, border_style);
623 #endregion // Internal Properties
625 #region Private & Internal Methods
626 internal static IAsyncResult BeginInvokeInternal (Delegate method, object [] args) {
627 AsyncMethodResult result = new AsyncMethodResult ();
628 AsyncMethodData data = new AsyncMethodData ();
630 data.Method = method;
632 data.Result = new WeakReference (result);
634 XplatUI.SendAsyncMethod (data);
638 internal Graphics DeviceContext {
641 CreateBuffers(this.Width, this.Height);
647 private Bitmap ImageBuffer {
650 CreateBuffers(this.Width, this.Height);
656 internal void CreateBuffers (int width, int height) {
657 if (dc_mem != null) {
671 bmp_mem = new Bitmap (width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
672 dc_mem = Graphics.FromImage (bmp_mem);
676 internal void InvalidateBuffers ()
678 if (dc_mem != null) {
689 internal static void SetChildColor(Control parent) {
692 for (int i=0; i < parent.child_controls.Count; i++) {
693 child=parent.child_controls[i];
694 if (child.IsHandleCreated) {
695 XplatUI.SetWindowBackground(child.window.Handle, child.BackColor);
697 if (child.child_controls.Count>0) {
698 SetChildColor(child);
704 internal bool Select(Control control) {
706 IContainerControl container;
708 if (control == null) {
712 parent = control.parent;
714 if (((control.control_style & ControlStyles.Selectable) !=0) && (parent != null)) {
715 while (parent != null) {
716 if (!parent.Visible || !parent.is_enabled) {
719 parent = parent.parent;
723 control.is_selected = true;
725 XplatUI.SetFocus(control.window.Handle);
726 container = GetContainerControl();
727 if (container != null) {
728 container.ActiveControl = control;
733 internal virtual void DoDefaultAction() {
734 // Only here to be overriden by our actual controls; this is needed by the accessibility class
737 internal static int LowOrder (int param) {
738 return (param & 0xffff);
741 internal static int HighOrder (int param) {
742 return (param >> 16);
745 internal static MouseButtons FromParamToMouseButtons (int param) {
746 MouseButtons buttons = MouseButtons.None;
748 if ((param & (int) MsgButtons.MK_LBUTTON) != 0)
749 buttons |= MouseButtons.Left;
751 if ((param & (int) MsgButtons.MK_MBUTTON) != 0)
752 buttons |= MouseButtons.Middle;
754 if ((param & (int) MsgButtons.MK_RBUTTON) != 0)
755 buttons |= MouseButtons.Right;
761 internal virtual bool ProcessControlMnemonic(char charCode) {
762 return ProcessMnemonic(charCode);
765 private static Control FindFlatForward(Control container, Control start) {
771 end = container.child_controls.Count;
774 index = start.tab_index;
779 for (int i = 0; i < end; i++) {
781 if (container.child_controls[i].tab_index > index) {
782 found = container.child_controls[i];
784 } else if (found.tab_index > container.child_controls[i].tab_index) {
785 if (container.child_controls[i].tab_index > index) {
786 found = container.child_controls[i];
793 private static Control FindControlForward(Control container, Control start) {
800 if ((start is IContainerControl) || start.GetStyle(ControlStyles.ContainerControl)) {
801 found = FindControlForward(start, null);
808 while (p != container) {
809 found = FindFlatForward(p, start);
817 return FindFlatForward(container, start);
820 private static Control FindFlatBackward(Control container, Control start) {
826 end = container.child_controls.Count;
829 index = start.tab_index;
831 // FIXME: Possible speed-up: Keep the highest taborder index in the container
833 for (int i = 0; i < end; i++) {
834 if (container.child_controls[i].tab_index > index) {
835 index = container.child_controls[i].tab_index;
841 for (int i = 0; i < end; i++) {
843 if (container.child_controls[i].tab_index < index) {
844 found = container.child_controls[i];
846 } else if (found.tab_index < container.child_controls[i].tab_index) {
847 if (container.child_controls[i].tab_index < index) {
848 found = container.child_controls[i];
855 private static Control FindControlBackward(Control container, Control start) {
861 found = FindFlatBackward(start.parent, start);
862 if (found == null && start.parent != container) {
867 found = FindFlatBackward(container, start);
870 while ((found != null) && ((found is IContainerControl) || found.GetStyle(ControlStyles.ContainerControl))) {
871 found = FindControlBackward(found, null);
880 private void HandleClick(int clicks) {
881 if (GetStyle(ControlStyles.StandardClick)) {
883 if (GetStyle(ControlStyles.StandardDoubleClick)) {
884 OnDoubleClick(EventArgs.Empty);
886 OnClick(EventArgs.Empty);
889 OnClick(EventArgs.Empty);
894 private void CheckDataBindings ()
896 if (data_bindings == null)
899 BindingContext binding_context = BindingContext;
900 foreach (Binding binding in data_bindings) {
901 binding.Check (binding_context);
905 #endregion // Private & Internal Methods
907 #region Public Static Properties
908 public static Color DefaultBackColor {
910 return ThemeEngine.Current.DefaultControlBackColor;
914 public static Font DefaultFont {
916 return ThemeEngine.Current.DefaultFont;
920 public static Color DefaultForeColor {
922 return ThemeEngine.Current.DefaultControlForeColor;
926 public static Keys ModifierKeys {
928 return XplatUI.State.ModifierKeys;
932 public static MouseButtons MouseButtons {
934 return XplatUI.State.MouseButtons;
938 public static Point MousePosition {
940 return Cursor.Position;
943 #endregion // Public Static Properties
945 #region Public Instance Properties
946 [EditorBrowsable(EditorBrowsableState.Advanced)]
948 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
949 public AccessibleObject AccessibilityObject {
951 if (accessibility_object==null) {
952 accessibility_object=CreateAccessibilityInstance();
954 return accessibility_object;
958 [EditorBrowsable(EditorBrowsableState.Advanced)]
960 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
961 public string AccessibleDefaultActionDescription {
963 return AccessibilityObject.default_action;
967 AccessibilityObject.default_action=value;
973 public string AccessibleDescription {
975 return AccessibilityObject.description;
979 AccessibilityObject.description=value;
985 public string AccessibleName {
987 return AccessibilityObject.Name;
991 AccessibilityObject.Name=value;
995 [DefaultValue(AccessibleRole.Default)]
996 public AccessibleRole AccessibleRole {
998 return AccessibilityObject.role;
1002 AccessibilityObject.role=value;
1006 [DefaultValue(false)]
1007 public virtual bool AllowDrop {
1009 return XplatUI.State.DropTarget;
1014 XplatUI.State.DropTarget=value;
1020 [RefreshProperties(RefreshProperties.Repaint)]
1021 [DefaultValue(AnchorStyles.Top | AnchorStyles.Left)]
1022 public virtual AnchorStyles Anchor {
1024 return anchor_style;
1030 if (parent != null) {
1031 parent.PerformLayout(this, "Parent");
1037 public virtual Color BackColor {
1039 if (background_color.IsEmpty) {
1041 return parent.BackColor;
1043 return DefaultBackColor;
1045 return background_color;
1049 background_color=value;
1050 if (this.IsHandleCreated) {
1051 XplatUI.SetWindowBackground(this.window.Handle, value);
1053 SetChildColor(this);
1054 OnBackColorChanged(EventArgs.Empty);
1060 [DefaultValue(null)]
1061 public virtual Image BackgroundImage {
1063 return background_image;
1067 if (background_image!=value) {
1068 background_image=value;
1069 OnBackgroundImageChanged(EventArgs.Empty);
1074 [EditorBrowsable(EditorBrowsableState.Advanced)]
1076 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1077 public virtual BindingContext BindingContext {
1079 if (binding_context != null)
1080 return binding_context;
1083 binding_context = Parent.BindingContext;
1084 return binding_context;
1087 if (binding_context != value) {
1088 binding_context = value;
1089 OnBindingContextChanged(EventArgs.Empty);
1094 [EditorBrowsable(EditorBrowsableState.Advanced)]
1096 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1099 return bounds.Y+bounds.Height;
1103 [EditorBrowsable(EditorBrowsableState.Advanced)]
1105 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1106 public Rectangle Bounds {
1112 SetBoundsCore(value.Left, value.Top, value.Width, value.Height, BoundsSpecified.All);
1116 [EditorBrowsable(EditorBrowsableState.Advanced)]
1118 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1119 public bool CanFocus {
1121 if (Visible && is_enabled && GetStyle(ControlStyles.Selectable)) {
1128 [EditorBrowsable(EditorBrowsableState.Advanced)]
1130 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1131 public bool CanSelect {
1135 if (!GetStyle(ControlStyles.Selectable) || this.parent == null) {
1139 parent = this.parent;
1140 while (parent != null) {
1141 if (!parent.is_visible || !parent.is_enabled) {
1145 parent = parent.parent;
1151 [EditorBrowsable(EditorBrowsableState.Advanced)]
1153 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1154 public bool Capture {
1156 return this.is_captured;
1160 if (this.IsHandleCreated) {
1161 if (value && !is_captured) {
1163 XplatUI.GrabWindow(this.window.Handle, IntPtr.Zero);
1164 } else if (!value && is_captured) {
1165 XplatUI.UngrabWindow(this.window.Handle);
1166 is_captured = false;
1172 [DefaultValue(true)]
1173 public bool CausesValidation {
1175 return this.causes_validation;
1179 if (this.causes_validation != value) {
1180 causes_validation = value;
1181 OnCausesValidationChanged(EventArgs.Empty);
1186 [EditorBrowsable(EditorBrowsableState.Advanced)]
1188 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1189 public Rectangle ClientRectangle {
1191 client_rect.Width = client_size.Width;
1192 client_rect.Height = client_size.Height;
1197 [EditorBrowsable(EditorBrowsableState.Advanced)]
1199 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1200 public Size ClientSize {
1203 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1204 return ((Form)this).form_parent_window.ClientSize;
1212 this.SetClientSizeCore(value.Width, value.Height);
1216 [EditorBrowsable(EditorBrowsableState.Advanced)]
1218 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1219 [DescriptionAttribute("ControlCompanyNameDescr")]
1220 public String CompanyName {
1222 return "Mono Project, Novell, Inc.";
1226 [EditorBrowsable(EditorBrowsableState.Advanced)]
1228 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1229 public bool ContainsFocus {
1235 for (int i=0; i < child_controls.Count; i++) {
1236 if (child_controls[i].ContainsFocus) {
1244 [DefaultValue(null)]
1245 public virtual ContextMenu ContextMenu {
1247 return context_menu;
1251 if (context_menu != value) {
1252 context_menu = value;
1253 OnContextMenuChanged(EventArgs.Empty);
1259 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
1260 public ControlCollection Controls {
1262 return this.child_controls;
1266 [EditorBrowsable(EditorBrowsableState.Advanced)]
1268 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1269 public bool Created {
1271 if (!this.is_disposed && (this.window.Handle != IntPtr.Zero)) {
1278 [AmbientValue(null)]
1279 public virtual Cursor Cursor {
1281 if (cursor != null) {
1285 if (parent != null) {
1286 return parent.Cursor;
1289 return Cursors.Default;
1293 if (cursor != value) {
1298 pt = Cursor.Position;
1299 if (bounds.Contains(pt)) {
1300 if (GetChildAtPoint(pt) == null) {
1301 if (cursor != null) {
1302 XplatUI.SetCursor(window.Handle, cursor.handle);
1304 if (parent != null) {
1305 XplatUI.SetCursor(window.Handle, parent.Cursor.handle);
1307 XplatUI.SetCursor(window.Handle, Cursors.def.handle);
1313 OnCursorChanged(EventArgs.Empty);
1319 [EditorBrowsable(EditorBrowsableState.Advanced)]
1321 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1322 public ControlBindingsCollection DataBindings {
1324 if (data_bindings == null)
1325 data_bindings = new ControlBindingsCollection (this);
1326 return data_bindings;
1330 [EditorBrowsable(EditorBrowsableState.Advanced)]
1332 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1333 public virtual Rectangle DisplayRectangle {
1335 return ClientRectangle;
1339 [EditorBrowsable(EditorBrowsableState.Advanced)]
1341 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1342 public bool Disposing {
1349 [RefreshProperties(RefreshProperties.Repaint)]
1350 [DefaultValue(DockStyle.None)]
1351 public virtual DockStyle Dock {
1357 if (dock_style == value) {
1363 if (parent != null) {
1364 parent.PerformLayout(this, "Parent");
1367 OnDockChanged(EventArgs.Empty);
1373 public bool Enabled {
1379 if (is_enabled == value) {
1385 OnEnabledChanged (EventArgs.Empty);
1389 [EditorBrowsable(EditorBrowsableState.Advanced)]
1391 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1392 public virtual bool Focused {
1394 return this.has_focus;
1399 [AmbientValue(null)]
1401 public virtual Font Font {
1407 if (Parent != null && Parent.Font != null) {
1415 if (font != null && font.Equals (value)) {
1421 OnFontChanged (EventArgs.Empty);
1426 public virtual Color ForeColor {
1428 if (foreground_color.IsEmpty) {
1430 return parent.ForeColor;
1432 return DefaultForeColor;
1434 return foreground_color;
1438 if (foreground_color != value) {
1439 foreground_color=value;
1441 OnForeColorChanged(EventArgs.Empty);
1448 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1449 public IntPtr Handle { // IWin32Window
1451 if (!IsHandleCreated) {
1454 return window.Handle;
1458 [EditorBrowsable(EditorBrowsableState.Advanced)]
1460 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1461 public bool HasChildren {
1463 if (this.child_controls.Count>0) {
1470 [EditorBrowsable(EditorBrowsableState.Always)]
1472 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1475 return this.bounds.Height;
1479 SetBoundsCore(bounds.X, bounds.Y, bounds.Width, value, BoundsSpecified.Height);
1483 [AmbientValue(ImeMode.Inherit)]
1485 public ImeMode ImeMode {
1491 if (ime_mode != value) {
1494 OnImeModeChanged(EventArgs.Empty);
1499 [EditorBrowsable(EditorBrowsableState.Advanced)]
1501 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1502 public bool InvokeRequired { // ISynchronizeInvoke
1504 if (creator_thread!=Thread.CurrentThread) {
1511 [EditorBrowsable(EditorBrowsableState.Advanced)]
1513 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1514 public bool IsAccessible {
1516 return is_accessible;
1520 is_accessible = value;
1524 [EditorBrowsable(EditorBrowsableState.Advanced)]
1526 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1527 public bool IsDisposed {
1529 return this.is_disposed;
1533 [EditorBrowsable(EditorBrowsableState.Advanced)]
1535 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1536 public bool IsHandleCreated {
1538 if ((window!=null) && (window.Handle!=IntPtr.Zero)) {
1546 [EditorBrowsable(EditorBrowsableState.Always)]
1548 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1551 return this.bounds.X;
1555 SetBoundsCore(value, bounds.Y, bounds.Width, bounds.Height, BoundsSpecified.X);
1560 public Point Location {
1562 return new Point(bounds.X, bounds.Y);
1566 SetBoundsCore(value.X, value.Y, bounds.Width, bounds.Height, BoundsSpecified.Location);
1571 public string Name {
1582 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1583 public Control Parent {
1589 if (value == this) {
1590 throw new ArgumentException("A circular control reference has been made. A control cannot be owned or parented to itself.");
1593 if (parent!=value) {
1595 parent.Controls.Remove(this);
1600 if (!parent.Controls.Contains(this)) {
1601 parent.Controls.Add(this);
1604 XplatUI.SetParent(Handle, value.Handle);
1608 OnParentChanged(EventArgs.Empty);
1613 [EditorBrowsable(EditorBrowsableState.Advanced)]
1615 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1616 public string ProductName {
1618 return "Novell Mono MWF";
1622 [EditorBrowsable(EditorBrowsableState.Advanced)]
1624 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1625 public string ProductVersion {
1627 return "1.1.4322.573";
1631 [EditorBrowsable(EditorBrowsableState.Advanced)]
1633 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1634 public bool RecreatingHandle {
1636 return is_recreating;
1640 [EditorBrowsable(EditorBrowsableState.Advanced)]
1642 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1643 public Region Region {
1645 return new Region(this.bounds);
1652 g = this.CreateGraphics();
1653 r = value.GetBounds(g);
1655 SetBounds((int)r.X, (int)r.Y, (int)r.Width, (int)r.Height);
1661 [EditorBrowsable(EditorBrowsableState.Advanced)]
1663 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1666 return this.bounds.X+this.bounds.Width;
1670 [AmbientValue(RightToLeft.Inherit)]
1672 public virtual RightToLeft RightToLeft {
1674 return right_to_left;
1678 if (value != right_to_left) {
1679 right_to_left = value;
1680 OnRightToLeftChanged(EventArgs.Empty);
1685 [EditorBrowsable(EditorBrowsableState.Advanced)]
1686 public override ISite Site {
1699 return new Size(Width, Height);
1703 SetBoundsCore(bounds.X, bounds.Y, value.Width, value.Height, BoundsSpecified.Size);
1708 [MergableProperty(false)]
1709 public int TabIndex {
1711 if (tab_index != -1) {
1718 if (tab_index != value) {
1720 OnTabIndexChanged(EventArgs.Empty);
1726 [DefaultValue(true)]
1727 public bool TabStop {
1733 if (tab_stop != value) {
1735 OnTabStopChanged(EventArgs.Empty);
1740 [Localizable(false)]
1742 [TypeConverter(typeof(StringConverter))]
1743 [DefaultValue(null)]
1750 control_tag = value;
1756 [BindableAttribute(true)]
1757 public virtual string Text {
1763 if (value == null) {
1764 value = String.Empty;
1769 XplatUI.Text(Handle, text);
1770 // FIXME: Do we need a Refresh() here?
1771 OnTextChanged (EventArgs.Empty);
1776 [EditorBrowsable(EditorBrowsableState.Always)]
1778 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1781 return this.bounds.Y;
1785 SetBoundsCore(bounds.X, value, bounds.Width, bounds.Height, BoundsSpecified.Y);
1789 [EditorBrowsable(EditorBrowsableState.Advanced)]
1791 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1792 public Control TopLevelControl {
1796 while (p.parent != null) {
1805 public bool Visible {
1809 } else if (parent != null) {
1810 return parent.Visible;
1817 SetVisibleCore(value);
1821 [EditorBrowsable(EditorBrowsableState.Always)]
1823 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1826 return this.bounds.Width;
1830 SetBoundsCore(bounds.X, bounds.Y, value, bounds.Height, BoundsSpecified.Width);
1834 [EditorBrowsable(EditorBrowsableState.Never)]
1836 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1837 public IWindowTarget WindowTarget {
1846 #endregion // Public Instance Properties
1848 #region Protected Instance Properties
1849 protected virtual CreateParams CreateParams {
1851 CreateParams create_params = new CreateParams();
1853 create_params.Caption = Text;
1854 create_params.X = Left;
1855 create_params.Y = Top;
1856 create_params.Width = Width;
1857 create_params.Height = Height;
1859 create_params.ClassName = XplatUI.DefaultClassName;
1860 create_params.ClassStyle = 0;
1861 create_params.ExStyle = 0;
1862 create_params.Param = 0;
1865 create_params.Parent = parent.Handle;
1868 create_params.Style = (int)WindowStyles.WS_CHILD | (int)WindowStyles.WS_CLIPCHILDREN | (int)WindowStyles.WS_CLIPSIBLINGS;
1871 create_params.Style |= (int)WindowStyles.WS_VISIBLE;
1874 return create_params;
1878 protected virtual ImeMode DefaultImeMode {
1880 return ImeMode.Inherit;
1884 protected virtual Size DefaultSize {
1886 return new Size(100, 23);
1890 protected int FontHeight {
1900 protected bool RenderRightToLeft {
1902 return (this.right_to_left == RightToLeft.Yes);
1906 protected bool ResizeRedraw {
1908 return GetStyle(ControlStyles.ResizeRedraw);
1912 SetStyle(ControlStyles.ResizeRedraw, value);
1916 [EditorBrowsable(EditorBrowsableState.Advanced)]
1918 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1919 protected virtual bool ShowFocusCues {
1925 [EditorBrowsable(EditorBrowsableState.Advanced)]
1927 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1928 protected bool ShowKeyboardCues {
1933 #endregion // Protected Instance Properties
1935 #region Public Static Methods
1936 [EditorBrowsable(EditorBrowsableState.Advanced)]
1937 public static Control FromChildHandle(IntPtr handle) {
1938 IEnumerator control = Control.controls.GetEnumerator();
1940 while (control.MoveNext()) {
1941 if (((Control)control.Current).window.Handle == handle) {
1943 if (((Control)control.Current).Parent != null) {
1944 return ((Control)control.Current).Parent;
1951 [EditorBrowsable(EditorBrowsableState.Advanced)]
1952 public static Control FromHandle(IntPtr handle) {
1953 IEnumerator control = Control.controls.GetEnumerator();
1955 while (control.MoveNext()) {
1956 if (((Control)control.Current).window.Handle == handle) {
1958 return ((Control)control.Current);
1964 public static bool IsMnemonic(char charCode, string text) {
1967 amp = text.IndexOf('&');
1970 if (amp + 1 < text.Length) {
1971 if (text[amp + 1] != '&') {
1972 if (Char.ToUpper(charCode) == Char.ToUpper(text.ToCharArray(amp + 1, 1)[0])) {
1982 #region Protected Static Methods
1983 [EditorBrowsable(EditorBrowsableState.Advanced)]
1984 protected static bool ReflectMessage(IntPtr hWnd, ref Message m) {
1987 c = Control.FromHandle(hWnd);
1997 #region Public Instance Methods
1998 [EditorBrowsable(EditorBrowsableState.Advanced)]
1999 public IAsyncResult BeginInvoke(Delegate method) {
2000 return BeginInvokeInternal(method, null);
2003 [EditorBrowsable(EditorBrowsableState.Advanced)]
2004 public IAsyncResult BeginInvoke (Delegate method, object[] args) {
2005 return BeginInvokeInternal (method, args);
2008 public void BringToFront() {
2009 if ((parent != null) && (parent.child_controls[0]!=this)) {
2010 if (parent.child_controls.Contains(this)) {
2011 parent.child_controls.SetChildIndex(this, 0);
2015 XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, true, false);
2017 if (parent != null) {
2022 public bool Contains(Control ctl) {
2023 while (ctl != null) {
2032 public void CreateControl() {
2034 if (!IsHandleCreated) {
2038 if (!create_handled) {
2039 create_handled = true;
2043 for (int i=0; i<child_controls.Count; i++) {
2044 child_controls[i].CreateControl();
2048 public Graphics CreateGraphics() {
2049 if (!IsHandleCreated) {
2050 this.CreateControl();
2052 return Graphics.FromHwnd(this.window.Handle);
2055 [MonoTODO("Come up with cross platform drag-drop driver interface")]
2056 public DragDropEffects DoDragDrop(object data, DragDropEffects allowedEffects) {
2057 return DragDropEffects.None;
2060 [EditorBrowsable(EditorBrowsableState.Advanced)]
2061 public object EndInvoke (IAsyncResult async_result) {
2062 AsyncMethodResult result = (AsyncMethodResult) async_result;
2063 return result.EndInvoke ();
2066 public Form FindForm() {
2079 public bool Focus() {
2080 if (IsHandleCreated && !has_focus) {
2082 XplatUI.SetFocus(window.Handle);
2087 public Control GetChildAtPoint(Point pt) {
2088 // Microsoft's version of this function doesn't seem to work, so I can't check
2089 // if we only consider children or also grandchildren, etc.
2090 // I'm gonna say 'children only'
2091 for (int i=0; i<child_controls.Count; i++) {
2092 if (child_controls[i].Bounds.Contains(pt)) {
2093 return child_controls[i];
2099 public IContainerControl GetContainerControl() {
2100 Control current = this;
2102 while (current!=null) {
2103 if ((current is IContainerControl) && ((current.control_style & ControlStyles.ContainerControl)!=0)) {
2104 return (IContainerControl)current;
2106 current = current.parent;
2111 public Control GetNextControl(Control ctl, bool forward) {
2112 // If we're not a container we don't play
2113 if (!(this is IContainerControl) && !this.GetStyle(ControlStyles.ContainerControl)) {
2117 // If ctl is not contained by this, we start at the first child of this
2118 if (!this.Contains(ctl)) {
2122 // Search through our controls, starting at ctl, stepping into children as we encounter them
2123 // try to find the control with the tabindex closest to our own, or, if we're looking into
2124 // child controls, the one with the smallest tabindex
2126 return FindControlForward(this, ctl);
2128 return FindControlBackward(this, ctl);
2131 public void Hide() {
2132 this.Visible = false;
2135 public void Invalidate() {
2136 Invalidate(ClientRectangle, false);
2139 public void Invalidate(bool invalidateChildren) {
2140 Invalidate(ClientRectangle, invalidateChildren);
2143 public void Invalidate(System.Drawing.Rectangle rc) {
2144 Invalidate(rc, false);
2147 public void Invalidate(System.Drawing.Rectangle rc, bool invalidateChildren) {
2148 if (!IsHandleCreated || !Visible) {
2152 NotifyInvalidate(rc);
2154 XplatUI.Invalidate(Handle, rc, false);
2156 if (invalidateChildren) {
2157 for (int i=0; i<child_controls.Count; i++) child_controls[i].Invalidate();
2159 OnInvalidated(new InvalidateEventArgs(rc));
2162 public void Invalidate(System.Drawing.Region region) {
2163 Invalidate(region, false);
2166 [MonoTODO("Figure out if GetRegionScans is usable")]
2167 public void Invalidate(System.Drawing.Region region, bool invalidateChildren) {
2168 throw new NotImplementedException();
2170 // FIXME - should use the GetRegionScans function of the region to invalidate each area
2171 //if (invalidateChildren) {
2172 // for (int i=0; i<child_controls.Count; i++) child_controls[i].Invalidate();
2176 public object Invoke (Delegate method) {
2177 return Invoke(method, null);
2180 public object Invoke (Delegate method, object[] args) {
2181 IAsyncResult result = BeginInvoke (method, args);
2182 return EndInvoke(result);
2185 [EditorBrowsable(EditorBrowsableState.Advanced)]
2186 public void PerformLayout() {
2187 PerformLayout(null, null);
2190 [EditorBrowsable(EditorBrowsableState.Advanced)]
2191 public void PerformLayout(Control affectedControl, string affectedProperty) {
2192 LayoutEventArgs levent = new LayoutEventArgs(affectedControl, affectedProperty);
2194 if (layout_suspended>0) {
2195 layout_pending = true;
2199 layout_pending = false;
2201 // Prevent us from getting messed up
2204 // Perform all Dock and Anchor calculations
2207 AnchorStyles anchor;
2212 space=this.DisplayRectangle;
2213 if (prev_size != Size.Empty) {
2214 diff_width = space.Width - prev_size.Width;
2215 diff_height = space.Height - prev_size.Height;
2221 // Deal with docking; go through in reverse, MS docs say that lowest Z-order is closest to edge
2222 for (int i = child_controls.Count - 1; i >= 0; i--) {
2223 child=child_controls[i];
2224 switch (child.Dock) {
2225 case DockStyle.None: {
2230 case DockStyle.Left: {
2231 child.SetBounds(space.Left, space.Y, child.Width, space.Height);
2232 space.X+=child.Width;
2233 space.Width-=child.Width;
2237 case DockStyle.Top: {
2238 child.SetBounds(space.Left, space.Y, space.Width, child.Height);
2239 space.Y+=child.Height;
2240 space.Height-=child.Height;
2244 case DockStyle.Right: {
2245 child.SetBounds(space.Right-child.Width, space.Y, child.Width, space.Height);
2246 space.Width-=child.Width;
2250 case DockStyle.Bottom: {
2251 child.SetBounds(space.Left, space.Bottom-child.Height, space.Width, child.Height);
2252 space.Height-=child.Height;
2258 for (int i = child_controls.Count - 1; i >= 0; i--) {
2259 child=child_controls[i];
2261 if (child.Dock == DockStyle.Fill) {
2262 child.SetBounds(space.Left, space.Top, space.Width, space.Height);
2268 space=this.DisplayRectangle;
2270 // Deal with anchoring
2271 for (int i=0; i < child_controls.Count; i++) {
2277 child=child_controls[i];
2278 anchor=child.Anchor;
2283 height=child.Height;
2285 // If the control is docked we don't need to do anything
2286 if (child.Dock != DockStyle.None) {
2290 if ((anchor & AnchorStyles.Left) !=0 ) {
2291 if ((anchor & AnchorStyles.Right) != 0) {
2292 // Anchoring to left and right
2293 width=width+diff_width;
2297 } else if ((anchor & AnchorStyles.Right) != 0) {
2303 if ((anchor & AnchorStyles.Top) !=0 ) {
2304 if ((anchor & AnchorStyles.Bottom) != 0) {
2305 height+=diff_height;
2309 } else if ((anchor & AnchorStyles.Bottom) != 0) {
2324 child.SetBounds(left, top, width, height);
2327 // Let everyone know
2331 // Need to make sure we decremend layout_suspended
2337 public Point PointToClient (Point p) {
2341 XplatUI.ScreenToClient (Handle, ref x, ref y);
2343 return new Point (x, y);
2346 public Point PointToScreen(Point p) {
2350 XplatUI.ClientToScreen(Handle, ref x, ref y);
2352 return new Point(x, y);
2355 public virtual bool PreProcessMessage(ref Message msg) {
2358 if ((msg.Msg == (int)Msg.WM_KEYDOWN) || (msg.Msg == (int)Msg.WM_SYSKEYDOWN)) {
2359 key_data = (Keys)msg.WParam.ToInt32();
2360 if (!ProcessCmdKey(ref msg, key_data)) {
2361 if (IsInputKey(key_data)) {
2365 return ProcessDialogKey(key_data);
2369 } else if (msg.Msg == (int)Msg.WM_CHAR) {
2370 if (IsInputChar((char)msg.WParam)) {
2373 } else if (msg.Msg == (int)Msg.WM_SYSCHAR) {
2374 if (IsInputChar((char)msg.WParam)) {
2377 return ProcessDialogChar((char)msg.WParam);
2382 public Rectangle RectangleToClient(Rectangle r) {
2383 return new Rectangle(PointToClient(r.Location), r.Size);
2386 public Rectangle RectangleToScreen(Rectangle r) {
2387 return new Rectangle(PointToScreen(r.Location), r.Size);
2390 public virtual void Refresh() {
2391 if (IsHandleCreated == true) {
2393 XplatUI.UpdateWindow(window.Handle);
2397 [EditorBrowsable(EditorBrowsableState.Never)]
2398 public virtual void ResetBackColor() {
2399 background_color = Color.Empty;
2402 #if haveDataBindings
2403 [EditorBrowsable(EditorBrowsableState.Never)]
2405 public void ResetBindings() {
2410 [EditorBrowsable(EditorBrowsableState.Never)]
2411 public virtual void ResetCursor() {
2415 [EditorBrowsable(EditorBrowsableState.Never)]
2416 public virtual void ResetFont() {
2420 [EditorBrowsable(EditorBrowsableState.Never)]
2421 public virtual void ResetForeColor() {
2422 foreground_color = Color.Empty;
2425 [EditorBrowsable(EditorBrowsableState.Never)]
2426 public void ResetImeMode() {
2427 ime_mode = DefaultImeMode;
2430 [EditorBrowsable(EditorBrowsableState.Never)]
2431 public virtual void ResetRightToLeft() {
2432 right_to_left = RightToLeft.Inherit;
2435 public virtual void ResetText() {
2439 public void ResumeLayout() {
2440 ResumeLayout (true);
2443 public void ResumeLayout(bool performLayout) {
2446 if (layout_suspended > 0) {
2450 if (performLayout || layout_pending) {
2455 public void Scale(float ratio) {
2456 ScaleCore(ratio, ratio);
2459 public void Scale(float dx, float dy) {
2463 public void Select() {
2464 Select(false, false);
2467 public bool SelectNextControl(Control ctl, bool forward, bool tabStopOnly, bool nested, bool wrap) {
2472 c = GetNextControl(c, forward);
2481 if (c.CanSelect && ((c.parent == ctl.parent) || nested) && (c.tab_stop || !tabStopOnly)) {
2485 } while (c != ctl); // If we wrap back to ourselves we stop
2490 public void SendToBack() {
2491 if ((parent != null) && (parent.child_controls[parent.child_controls.Count-1]!=this)) {
2492 if (parent.child_controls.Contains(this)) {
2493 parent.child_controls.SetChildIndex(this, parent.child_controls.Count);
2497 XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, false, true);
2498 if (parent != null) {
2503 public void SetBounds(int x, int y, int width, int height) {
2504 SetBoundsCore(x, y, width, height, BoundsSpecified.All);
2507 public void SetBounds(int x, int y, int width, int height, BoundsSpecified specified) {
2508 SetBoundsCore(x, y, width, height, specified);
2511 public void Show() {
2512 if (!IsHandleCreated) {
2513 this.CreateControl();
2519 public void SuspendLayout() {
2523 public void Update() {
2524 needs_redraw = true;
2525 XplatUI.UpdateWindow(window.Handle);
2527 #endregion // Public Instance Methods
2529 #region Protected Instance Methods
2530 [EditorBrowsable(EditorBrowsableState.Advanced)]
2531 [MonoTODO("Implement this and tie it into Control.ControlAccessibleObject.NotifyClients")]
2532 protected void AccessibilityNotifyClients(AccessibleEvents accEvent, int childID) {
2533 throw new NotImplementedException();
2536 [EditorBrowsable(EditorBrowsableState.Advanced)]
2537 protected virtual AccessibleObject CreateAccessibilityInstance() {
2538 return new Control.ControlAccessibleObject(this);
2541 [EditorBrowsable(EditorBrowsableState.Advanced)]
2542 protected virtual ControlCollection CreateControlsInstance() {
2543 return new ControlCollection(this);
2546 [EditorBrowsable(EditorBrowsableState.Advanced)]
2547 protected virtual void CreateHandle() {
2549 throw new ObjectDisposedException(Name);
2552 if (IsHandleCreated) {
2557 window = new ControlNativeWindow(this);
2558 window.CreateHandle(CreateParams);
2560 // Find out where the window manager placed us
2565 if (window.Handle!=IntPtr.Zero) {
2566 if (!controls.Contains(window.Handle)) {
2570 creator_thread = Thread.CurrentThread;
2572 XplatUI.SetWindowBackground(window.Handle, this.BackColor);
2574 OnHandleCreated(EventArgs.Empty);
2578 [EditorBrowsable(EditorBrowsableState.Advanced)]
2579 protected virtual void DefWndProc(ref Message m) {
2580 window.DefWndProc(ref m);
2583 [EditorBrowsable(EditorBrowsableState.Advanced)]
2584 protected virtual void DestroyHandle() {
2585 if (IsHandleCreated) {
2586 // Destroy our children before we destroy ourselves, to prevent them from
2587 // being implictly (without us knowing) destroyed
2588 for (int i=0; i < child_controls.Count; i++) {
2589 child_controls[i].DestroyHandle();
2593 if (window != null) {
2594 window.DestroyHandle();
2596 OnHandleDestroyed(EventArgs.Empty);
2600 protected bool GetStyle(ControlStyles flag) {
2601 return (control_style & flag) != 0;
2604 protected bool GetTopLevel() {
2608 [EditorBrowsable(EditorBrowsableState.Advanced)]
2609 protected virtual void InitLayout() {
2610 if (parent != null) {
2611 parent.PerformLayout(this, "parent");
2615 [EditorBrowsable(EditorBrowsableState.Advanced)]
2616 protected void InvokeGotFocus(Control toInvoke, EventArgs e) {
2617 toInvoke.OnGotFocus(e);
2620 [EditorBrowsable(EditorBrowsableState.Advanced)]
2621 protected void InvokeLostFocus(Control toInvoke, EventArgs e) {
2622 toInvoke.OnLostFocus(e);
2625 [EditorBrowsable(EditorBrowsableState.Advanced)]
2626 protected void InvokeOnClick(Control toInvoke, EventArgs e) {
2627 toInvoke.OnClick(e);
2630 protected void InvokePaint(Control toInvoke, PaintEventArgs e) {
2631 toInvoke.OnPaint(e);
2634 protected void InvokePaintBackground(Control toInvoke, PaintEventArgs e) {
2635 toInvoke.OnPaintBackground(e);
2638 protected virtual bool IsInputChar (char charCode) {
2639 if (parent != null) {
2640 return parent.IsInputChar(charCode);
2646 protected virtual bool IsInputKey (Keys keyData) {
2647 // Doc says this one calls IsInputChar; not sure what to do with that
2651 [EditorBrowsable(EditorBrowsableState.Advanced)]
2652 protected virtual void NotifyInvalidate(Rectangle invalidatedArea) {
2656 protected virtual bool ProcessCmdKey(ref Message msg, Keys keyData) {
2657 if ((context_menu != null) && context_menu.ProcessCmdKey(ref msg, keyData)) {
2661 if (parent != null) {
2662 return parent.ProcessCmdKey(ref msg, keyData);
2668 protected virtual bool ProcessDialogChar(char charCode) {
2669 if (parent != null) {
2670 return parent.ProcessDialogChar (charCode);
2676 protected virtual bool ProcessDialogKey (Keys keyData) {
2677 if (parent != null) {
2678 return parent.ProcessDialogKey (keyData);
2684 protected virtual bool ProcessKeyEventArgs (ref Message msg)
2686 KeyEventArgs key_event;
2689 case (int)Msg.WM_KEYDOWN: {
2690 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
2691 OnKeyDown (key_event);
2692 return key_event.Handled;
2694 case (int)Msg.WM_KEYUP: {
2695 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
2696 OnKeyUp (key_event);
2697 return key_event.Handled;
2700 case (int)Msg.WM_CHAR: {
2701 KeyPressEventArgs key_press_event;
2703 key_press_event = new KeyPressEventArgs((char)msg.WParam);
2704 OnKeyPress(key_press_event);
2705 return key_press_event.Handled;
2716 protected internal virtual bool ProcessKeyMessage(ref Message msg) {
2717 if (parent != null) {
2718 if (parent.ProcessKeyPreview(ref msg)) {
2726 protected virtual bool ProcessKeyPreview(ref Message msg) {
2727 if (parent != null) {
2728 return parent.ProcessKeyPreview(ref msg);
2734 protected virtual bool ProcessMnemonic(char charCode) {
2739 [EditorBrowsable(EditorBrowsableState.Advanced)]
2740 protected void RaiseDragEvent(object key, DragEventArgs e) {
2744 [EditorBrowsable(EditorBrowsableState.Advanced)]
2745 protected void RaiseKeyEvent(object key, KeyEventArgs e) {
2749 [EditorBrowsable(EditorBrowsableState.Advanced)]
2750 protected void RaiseMouseEvent(object key, MouseEventArgs e) {
2754 [EditorBrowsable(EditorBrowsableState.Advanced)]
2755 protected void RaisePaintEvent(object key, PaintEventArgs e) {
2759 [EditorBrowsable(EditorBrowsableState.Advanced)]
2760 protected void RecreateHandle() {
2761 IEnumerator child = child_controls.GetEnumerator();
2765 if (IsHandleCreated) {
2771 while (child.MoveNext()) {
2772 ((Control)child.Current).RecreateHandle();
2778 is_recreating = false;
2781 [EditorBrowsable(EditorBrowsableState.Advanced)]
2782 protected void ResetMouseEventArgs() {
2786 [EditorBrowsable(EditorBrowsableState.Advanced)]
2787 protected ContentAlignment RtlTranslateAlignment(ContentAlignment align) {
2788 if (right_to_left == RightToLeft.No) {
2793 case ContentAlignment.TopLeft: {
2794 return ContentAlignment.TopRight;
2797 case ContentAlignment.TopRight: {
2798 return ContentAlignment.TopLeft;
2801 case ContentAlignment.MiddleLeft: {
2802 return ContentAlignment.MiddleRight;
2805 case ContentAlignment.MiddleRight: {
2806 return ContentAlignment.MiddleLeft;
2809 case ContentAlignment.BottomLeft: {
2810 return ContentAlignment.BottomRight;
2813 case ContentAlignment.BottomRight: {
2814 return ContentAlignment.BottomLeft;
2818 // if it's center it doesn't change
2824 [EditorBrowsable(EditorBrowsableState.Advanced)]
2825 protected HorizontalAlignment RtlTranslateAlignment(HorizontalAlignment align) {
2826 if ((right_to_left == RightToLeft.No) || (align == HorizontalAlignment.Center)) {
2830 if (align == HorizontalAlignment.Left) {
2831 return HorizontalAlignment.Right;
2834 // align must be HorizontalAlignment.Right
2835 return HorizontalAlignment.Left;
2838 [EditorBrowsable(EditorBrowsableState.Advanced)]
2839 protected LeftRightAlignment RtlTranslateAlignment(LeftRightAlignment align) {
2840 if (right_to_left == RightToLeft.No) {
2844 if (align == LeftRightAlignment.Left) {
2845 return LeftRightAlignment.Right;
2848 // align must be LeftRightAlignment.Right;
2849 return LeftRightAlignment.Left;
2852 [EditorBrowsable(EditorBrowsableState.Advanced)]
2853 protected ContentAlignment RtlTranslateContent(ContentAlignment align) {
2854 return RtlTranslateAlignment(align);
2857 [EditorBrowsable(EditorBrowsableState.Advanced)]
2858 protected HorizontalAlignment RtlTranslateHorizontal(HorizontalAlignment align) {
2859 return RtlTranslateAlignment(align);
2862 [EditorBrowsable(EditorBrowsableState.Advanced)]
2863 protected LeftRightAlignment RtlTranslateLeftRight(LeftRightAlignment align) {
2864 return RtlTranslateAlignment(align);
2867 [EditorBrowsable(EditorBrowsableState.Advanced)]
2868 protected virtual void ScaleCore(float dx, float dy) {
2874 location = new Point((int)(Left * dx), (int)(Top * dy));
2875 size = this.ClientSize;
2878 if (!GetStyle(ControlStyles.FixedWidth)) {
2879 size.Width = (int)(size.Width * dx);
2882 if (!GetStyle(ControlStyles.FixedHeight)) {
2883 size.Height = (int)(size.Height * dy);
2886 Location = location;
2889 /* Now scale our children */
2890 for (int i=0; i < child_controls.Count; i++) {
2891 child_controls[i].Scale(dx, dy);
2897 protected virtual void Select(bool directed, bool forward) {
2902 // Select this control
2907 if (parent == null) {
2911 // FIXME - this thing is doing the wrong stuff, needs to be similar to SelectNextControl
2913 index = parent.child_controls.IndexOf(this);
2918 if ((index+1) < parent.child_controls.Count) {
2927 index = parent.child_controls.Count-1;
2930 result = Select(parent.child_controls[index]);
2931 } while (!result && parent.child_controls[index] != this);
2934 [EditorBrowsable(EditorBrowsableState.Advanced)]
2935 protected virtual void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
2936 // SetBoundsCore updates the Win32 control itself. UpdateBounds updates the controls variables and fires events, I'm guessing - pdb
2937 if ((specified & BoundsSpecified.X) != BoundsSpecified.X) {
2941 if ((specified & BoundsSpecified.Y) != BoundsSpecified.Y) {
2945 if ((specified & BoundsSpecified.Width) != BoundsSpecified.Width) {
2949 if ((specified & BoundsSpecified.Height) != BoundsSpecified.Height) {
2953 if (IsHandleCreated) {
2954 XplatUI.SetWindowPos(Handle, x, y, width, height);
2956 UpdateBounds(x, y, width, height);
2959 [EditorBrowsable(EditorBrowsableState.Advanced)]
2960 protected virtual void SetClientSizeCore(int x, int y) {
2961 // Calculate the actual window size from the client size (it usually stays the same or grows)
2962 Rectangle ClientRect;
2963 Rectangle WindowRect;
2966 ClientRect = new Rectangle(0, 0, x, y);
2967 cp = this.CreateParams;
2969 if (XplatUI.CalculateWindowRect(Handle, ref ClientRect, cp.Style, cp.ExStyle, IntPtr.Zero, out WindowRect)==false) {
2973 SetBoundsCore(bounds.X, bounds.Y, WindowRect.Width, WindowRect.Height, BoundsSpecified.Size);
2976 [EditorBrowsable(EditorBrowsableState.Advanced)]
2977 protected void SetStyle(ControlStyles flag, bool value) {
2979 control_style |= flag;
2981 control_style &= ~flag;
2983 OnStyleChanged(EventArgs.Empty);
2986 protected void SetTopLevel(bool value) {
2987 if ((GetTopLevel() != value) && (parent != null)) {
2988 throw new Exception();
2992 if (value == true) {
3002 is_toplevel = value;
3005 protected virtual void SetVisibleCore(bool value) {
3006 if (value!=is_visible) {
3008 XplatUI.SetVisible(Handle, value);
3009 // Explicitly move Toplevel windows to where we want them;
3010 // apparently moving unmapped toplevel windows doesn't work
3011 if (is_visible && (this is Form)) {
3012 XplatUI.SetWindowPos(window.Handle, bounds.X, bounds.Y, bounds.Width, bounds.Height);
3014 OnVisibleChanged(EventArgs.Empty);
3017 if (dc_mem != null) {
3022 if (bmp_mem != null) {
3027 this.CreateBuffers(bounds.Width, bounds.Height);
3032 if (value == false && parent != null) {
3035 // Need to start at parent, GetContainerControl might return ourselves if we're a container
3036 container = (Control)parent.GetContainerControl();
3037 if (container != null) {
3038 container.SelectNextControl(this, true, true, true, true);
3042 if (parent != null) {
3043 parent.PerformLayout(this, "visible");
3045 PerformLayout(this, "visible");
3050 [EditorBrowsable(EditorBrowsableState.Advanced)]
3051 protected void UpdateBounds() {
3059 if (!IsHandleCreated) {
3063 XplatUI.GetWindowPos(this.Handle, this is Form, out x, out y, out width, out height, out client_width, out client_height);
3065 UpdateBounds(x, y, width, height, client_width, client_height);
3068 [EditorBrowsable(EditorBrowsableState.Advanced)]
3069 protected void UpdateBounds(int x, int y, int width, int height) {
3070 // UpdateBounds only seems to set our sizes and fire events but not update the GUI window to match
3072 bool resized = false;
3074 int client_x_diff = this.bounds.Width-this.client_size.Width;
3075 int client_y_diff = this.bounds.Height-this.client_size.Height;
3077 // Needed to generate required notifications
3078 if ((this.bounds.X!=x) || (this.bounds.Y!=y)) {
3082 if ((this.Bounds.Width!=width) || (this.Bounds.Height!=height)) {
3089 bounds.Height=height;
3091 // Update client rectangle as well
3092 if (this.layout_suspended==0) {
3093 prev_size.Width=client_size.Width;
3094 prev_size.Height=client_size.Height;
3097 client_size.Width=width-client_x_diff;
3098 client_size.Height=height-client_y_diff;
3101 OnLocationChanged(EventArgs.Empty);
3105 OnSizeChanged(EventArgs.Empty);
3109 [EditorBrowsable(EditorBrowsableState.Advanced)]
3110 protected void UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) {
3111 UpdateBounds(x, y, width, height);
3113 this.client_size.Width=clientWidth;
3114 this.client_size.Height=clientHeight;
3117 [EditorBrowsable(EditorBrowsableState.Advanced)]
3118 protected void UpdateStyles() {
3119 if (!IsHandleCreated) {
3123 XplatUI.SetWindowStyle(window.Handle, CreateParams);
3126 [EditorBrowsable(EditorBrowsableState.Advanced)]
3127 protected void UpdateZOrder() {
3132 if (parent == null) {
3138 children = ctl.child_controls.Count;
3139 for (int i = 1; i < children; i++ ) {
3140 XplatUI.SetZOrder(ctl.child_controls[i].window.Handle, ctl.child_controls[i-1].window.Handle, false, false);
3143 children = child_controls.Count;
3144 for (int i = 1; i < children; i++ ) {
3145 XplatUI.SetZOrder(child_controls[i].window.Handle, child_controls[i-1].window.Handle, false, false);
3150 protected virtual void WndProc(ref Message m) {
3152 Console.WriteLine("Control received message {0}", (Msg)m.Msg);
3154 if ((this.control_style & ControlStyles.EnableNotifyMessage) != 0) {
3158 switch((Msg)m.Msg) {
3159 case Msg.WM_WINDOWPOSCHANGED: {
3162 if (GetStyle(ControlStyles.ResizeRedraw)) {
3169 case Msg.WM_PAINT: {
3170 PaintEventArgs paint_event;
3172 paint_event = XplatUI.PaintEventStart(Handle);
3174 if (!needs_redraw) {
3175 // Just blit the previous image
3176 paint_event.Graphics.DrawImage (ImageBuffer, paint_event.ClipRectangle);
3177 needs_redraw = false;
3182 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
3183 dc = paint_event.SetGraphics (DeviceContext);
3186 if ((control_style & (ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint)) == (ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint)) {
3187 OnPaintBackground(paint_event);
3190 OnPaint(paint_event);
3192 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
3193 dc.DrawImage (ImageBuffer, paint_event.ClipRectangle);
3194 paint_event.SetGraphics (dc);
3197 XplatUI.PaintEventEnd(Handle);
3199 if (!GetStyle(ControlStyles.UserPaint)) {
3206 case Msg.WM_ERASEBKGND: {
3207 if (GetStyle (ControlStyles.UserPaint)) {
3208 if (!GetStyle(ControlStyles.AllPaintingInWmPaint)) {
3209 PaintEventArgs eraseEventArgs = new PaintEventArgs (m.WParam == IntPtr.Zero ? Graphics.FromHwnd (m.HWnd) :
3210 Graphics.FromHdc (m.WParam), new Rectangle (new Point (0,0),Size));
3211 OnPaintBackground (eraseEventArgs);
3214 XplatUI.EraseWindowBackground(m.HWnd, m.WParam);
3216 // The DefWndProc will never have to handle this, we don't ever set hbr on the window
3217 m.Result = (IntPtr)1;
3221 case Msg.WM_LBUTTONUP: {
3222 HandleClick(mouse_clicks);
3223 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Left,
3225 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3227 if (mouse_clicks > 1) {
3233 case Msg.WM_LBUTTONDOWN: {
3234 if (CanSelect && !is_selected) {
3237 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3238 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3244 case Msg.WM_LBUTTONDBLCLK: {
3246 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3247 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3253 case Msg.WM_MBUTTONUP: {
3254 HandleClick(mouse_clicks);
3255 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Middle,
3257 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3259 if (mouse_clicks > 1) {
3265 case Msg.WM_MBUTTONDOWN: {
3266 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3267 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3273 case Msg.WM_MBUTTONDBLCLK: {
3275 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3276 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3281 case Msg.WM_RBUTTONUP: {
3282 if (context_menu != null) {
3283 context_menu.Show(this, new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ())));
3286 HandleClick(mouse_clicks);
3287 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Right,
3289 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3291 if (mouse_clicks > 1) {
3297 case Msg.WM_RBUTTONDOWN: {
3298 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3299 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3304 case Msg.WM_RBUTTONDBLCLK: {
3306 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3307 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3312 case Msg.WM_MOUSEWHEEL: {
3314 OnMouseWheel (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3315 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3316 HighOrder(m.WParam.ToInt32())));
3321 case Msg.WM_MOUSEMOVE: {
3322 OnMouseMove (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3324 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3329 case Msg.WM_MOUSE_ENTER: {
3334 OnMouseEnter(EventArgs.Empty);
3338 case Msg.WM_MOUSE_LEAVE: {
3340 OnMouseLeave(EventArgs.Empty);
3344 case Msg.WM_MOUSEHOVER: {
3345 OnMouseHover(EventArgs.Empty);
3349 case Msg.WM_SYSKEYDOWN:
3350 case Msg.WM_KEYDOWN:
3351 case Msg.WM_SYSKEYUP:
3353 case Msg.WM_SYSCHAR:
3355 if (ProcessKeyEventArgs(ref m)) {
3359 if (PreProcessMessage(ref m)) {
3363 if (ProcessKeyMessage(ref m)) {
3372 if (m.LParam != IntPtr.Zero) {
3375 hi = new HELPINFO();
3377 hi = (HELPINFO) Marshal.PtrToStructure (m.LParam, typeof (HELPINFO));
3378 mouse_pos = new Point(hi.MousePos.x, hi.MousePos.y);
3380 mouse_pos = Control.MousePosition;
3382 OnHelpRequested(new HelpEventArgs(mouse_pos));
3383 m.Result = (IntPtr)1;
3387 case Msg.WM_KILLFOCUS: {
3388 OnLeave(EventArgs.Empty);
3389 if (CausesValidation) {
3391 e = new CancelEventArgs(false);
3400 OnValidated(EventArgs.Empty);
3403 this.has_focus = false;
3404 this.is_selected = false;
3405 OnLostFocus(EventArgs.Empty);
3409 case Msg.WM_SETFOCUS: {
3410 OnEnter(EventArgs.Empty);
3411 this.has_focus = true;
3412 OnGotFocus(EventArgs.Empty);
3417 case Msg.WM_SYSCOLORCHANGE: {
3418 ThemeEngine.Current.ResetDefaults();
3419 OnSystemColorsChanged(EventArgs.Empty);
3424 case Msg.WM_SETCURSOR: {
3425 if (cursor == null) {
3430 XplatUI.SetCursor(window.Handle, cursor.handle);
3431 m.Result = (IntPtr)1;
3441 #endregion // Public Instance Methods
3443 #region OnXXX methods
3444 [EditorBrowsable(EditorBrowsableState.Advanced)]
3445 protected virtual void OnBackColorChanged(EventArgs e) {
3446 if (BackColorChanged!=null) BackColorChanged(this, e);
3447 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackColorChanged(e);
3450 [EditorBrowsable(EditorBrowsableState.Advanced)]
3451 protected virtual void OnBackgroundImageChanged(EventArgs e) {
3452 if (BackgroundImageChanged!=null) BackgroundImageChanged(this, e);
3453 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackgroundImageChanged(e);
3456 [EditorBrowsable(EditorBrowsableState.Advanced)]
3457 protected virtual void OnBindingContextChanged(EventArgs e) {
3458 CheckDataBindings ();
3459 if (BindingContextChanged!=null) {
3460 BindingContextChanged(this, e);
3462 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBindingContextChanged(e);
3465 [EditorBrowsable(EditorBrowsableState.Advanced)]
3466 protected virtual void OnCausesValidationChanged(EventArgs e) {
3467 if (CausesValidationChanged!=null) CausesValidationChanged(this, e);
3470 [EditorBrowsable(EditorBrowsableState.Advanced)]
3471 protected virtual void OnChangeUICues(UICuesEventArgs e) {
3472 if (ChangeUICues!=null) ChangeUICues(this, e);
3475 [EditorBrowsable(EditorBrowsableState.Advanced)]
3476 protected virtual void OnClick(EventArgs e) {
3477 if (Click!=null) Click(this, e);
3480 [EditorBrowsable(EditorBrowsableState.Advanced)]
3481 protected virtual void OnContextMenuChanged(EventArgs e) {
3482 if (ContextMenuChanged!=null) ContextMenuChanged(this, e);
3485 [EditorBrowsable(EditorBrowsableState.Advanced)]
3486 protected virtual void OnControlAdded(ControlEventArgs e) {
3487 if (ControlAdded!=null) ControlAdded(this, e);
3490 [EditorBrowsable(EditorBrowsableState.Advanced)]
3491 protected virtual void OnControlRemoved(ControlEventArgs e) {
3492 if (ControlRemoved!=null) ControlRemoved(this, e);
3495 [EditorBrowsable(EditorBrowsableState.Advanced)]
3496 protected virtual void OnCreateControl() {
3500 [EditorBrowsable(EditorBrowsableState.Advanced)]
3501 protected virtual void OnCursorChanged(EventArgs e) {
3502 if (CursorChanged!=null) CursorChanged(this, e);
3505 [EditorBrowsable(EditorBrowsableState.Advanced)]
3506 protected virtual void OnDockChanged(EventArgs e) {
3507 if (DockChanged!=null) DockChanged(this, e);
3510 [EditorBrowsable(EditorBrowsableState.Advanced)]
3511 protected virtual void OnDoubleClick(EventArgs e) {
3512 if (DoubleClick!=null) DoubleClick(this, e);
3515 [EditorBrowsable(EditorBrowsableState.Advanced)]
3516 protected virtual void OnDragDrop(DragEventArgs drgevent) {
3517 if (DragDrop!=null) DragDrop(this, drgevent);
3520 [EditorBrowsable(EditorBrowsableState.Advanced)]
3521 protected virtual void OnDragEnter(DragEventArgs drgevent) {
3522 if (DragEnter!=null) DragEnter(this, drgevent);
3525 [EditorBrowsable(EditorBrowsableState.Advanced)]
3526 protected virtual void OnDragLeave(EventArgs e) {
3527 if (DragLeave!=null) DragLeave(this, e);
3530 [EditorBrowsable(EditorBrowsableState.Advanced)]
3531 protected virtual void OnDragOver(DragEventArgs drgevent) {
3532 if (DragOver!=null) DragOver(this, drgevent);
3535 [EditorBrowsable(EditorBrowsableState.Advanced)]
3536 protected virtual void OnEnabledChanged(EventArgs e) {
3537 if (EnabledChanged!=null) EnabledChanged(this, e);
3538 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentEnabledChanged(e);
3541 [EditorBrowsable(EditorBrowsableState.Advanced)]
3542 protected virtual void OnEnter(EventArgs e) {
3543 if (Enter!=null) Enter(this, e);
3546 [EditorBrowsable(EditorBrowsableState.Advanced)]
3547 protected virtual void OnFontChanged(EventArgs e) {
3548 if (FontChanged!=null) FontChanged(this, e);
3549 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentFontChanged(e);
3552 [EditorBrowsable(EditorBrowsableState.Advanced)]
3553 protected virtual void OnForeColorChanged(EventArgs e) {
3554 if (ForeColorChanged!=null) ForeColorChanged(this, e);
3555 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentForeColorChanged(e);
3558 [EditorBrowsable(EditorBrowsableState.Advanced)]
3559 protected virtual void OnGiveFeedback(GiveFeedbackEventArgs gfbevent) {
3560 if (GiveFeedback!=null) GiveFeedback(this, gfbevent);
3563 [EditorBrowsable(EditorBrowsableState.Advanced)]
3564 protected virtual void OnGotFocus(EventArgs e) {
3565 if (GotFocus!=null) GotFocus(this, e);
3568 [EditorBrowsable(EditorBrowsableState.Advanced)]
3569 protected virtual void OnHandleCreated(EventArgs e) {
3570 if (HandleCreated!=null) HandleCreated(this, e);
3573 [EditorBrowsable(EditorBrowsableState.Advanced)]
3574 protected virtual void OnHandleDestroyed(EventArgs e) {
3575 if (HandleDestroyed!=null) HandleDestroyed(this, e);
3578 [EditorBrowsable(EditorBrowsableState.Advanced)]
3579 protected virtual void OnHelpRequested(HelpEventArgs hevent) {
3580 if (HelpRequested!=null) HelpRequested(this, hevent);
3583 protected virtual void OnImeModeChanged(EventArgs e) {
3584 if (ImeModeChanged!=null) ImeModeChanged(this, e);
3587 [EditorBrowsable(EditorBrowsableState.Advanced)]
3588 protected virtual void OnInvalidated(InvalidateEventArgs e) {
3589 needs_redraw = true;
3590 if (Invalidated!=null) Invalidated(this, e);
3593 [EditorBrowsable(EditorBrowsableState.Advanced)]
3594 protected virtual void OnKeyDown(KeyEventArgs e) {
3595 if (KeyDown!=null) KeyDown(this, e);
3598 [EditorBrowsable(EditorBrowsableState.Advanced)]
3599 protected virtual void OnKeyPress(KeyPressEventArgs e) {
3600 if (KeyPress!=null) KeyPress(this, e);
3603 [EditorBrowsable(EditorBrowsableState.Advanced)]
3604 protected virtual void OnKeyUp(KeyEventArgs e) {
3605 if (KeyUp!=null) KeyUp(this, e);
3608 [EditorBrowsable(EditorBrowsableState.Advanced)]
3609 protected virtual void OnLayout(LayoutEventArgs levent) {
3610 if (Layout!=null) Layout(this, levent);
3613 [EditorBrowsable(EditorBrowsableState.Advanced)]
3614 protected virtual void OnLeave(EventArgs e) {
3615 if (Leave!=null) Leave(this, e);
3618 [EditorBrowsable(EditorBrowsableState.Advanced)]
3619 protected virtual void OnLocationChanged(EventArgs e) {
3621 if (LocationChanged!=null) LocationChanged(this, e);
3624 [EditorBrowsable(EditorBrowsableState.Advanced)]
3625 protected virtual void OnLostFocus(EventArgs e) {
3626 if (LostFocus!=null) LostFocus(this, e);
3629 [EditorBrowsable(EditorBrowsableState.Advanced)]
3630 protected virtual void OnMouseDown(MouseEventArgs e) {
3631 if (MouseDown!=null) MouseDown(this, e);
3634 [EditorBrowsable(EditorBrowsableState.Advanced)]
3635 protected virtual void OnMouseEnter(EventArgs e) {
3636 if (MouseEnter!=null) MouseEnter(this, e);
3639 [EditorBrowsable(EditorBrowsableState.Advanced)]
3640 protected virtual void OnMouseHover(EventArgs e) {
3641 if (MouseHover!=null) MouseHover(this, e);
3644 [EditorBrowsable(EditorBrowsableState.Advanced)]
3645 protected virtual void OnMouseLeave(EventArgs e) {
3646 if (MouseLeave!=null) MouseLeave(this, e);
3649 [EditorBrowsable(EditorBrowsableState.Advanced)]
3650 protected virtual void OnMouseMove(MouseEventArgs e) {
3651 if (MouseMove!=null) MouseMove(this, e);
3654 [EditorBrowsable(EditorBrowsableState.Advanced)]
3655 protected virtual void OnMouseUp(MouseEventArgs e) {
3656 if (MouseUp!=null) MouseUp(this, e);
3659 [EditorBrowsable(EditorBrowsableState.Advanced)]
3660 protected virtual void OnMouseWheel(MouseEventArgs e) {
3661 if (MouseWheel!=null) MouseWheel(this, e);
3664 [EditorBrowsable(EditorBrowsableState.Advanced)]
3665 protected virtual void OnMove(EventArgs e) {
3666 if (Move!=null) Move(this, e);
3669 [EditorBrowsable(EditorBrowsableState.Advanced)]
3670 protected virtual void OnNotifyMessage(Message m) {
3674 [EditorBrowsable(EditorBrowsableState.Advanced)]
3675 protected virtual void OnPaint(PaintEventArgs e) {
3676 if (Paint!=null) Paint(this, e);
3679 [EditorBrowsable(EditorBrowsableState.Advanced)]
3680 protected virtual void OnPaintBackground(PaintEventArgs pevent) {
3684 [EditorBrowsable(EditorBrowsableState.Advanced)]
3685 protected virtual void OnParentBackColorChanged(EventArgs e) {
3686 if (background_color.IsEmpty && background_image==null) {
3688 OnBackColorChanged(e);
3692 [EditorBrowsable(EditorBrowsableState.Advanced)]
3693 protected virtual void OnParentBackgroundImageChanged(EventArgs e) {
3694 if (background_color.IsEmpty && background_image==null) {
3696 OnBackgroundImageChanged(e);
3700 [EditorBrowsable(EditorBrowsableState.Advanced)]
3701 protected virtual void OnParentBindingContextChanged(EventArgs e) {
3702 if (binding_context==null) {
3703 binding_context=Parent.binding_context;
3704 OnBindingContextChanged(e);
3708 [EditorBrowsable(EditorBrowsableState.Advanced)]
3709 protected virtual void OnParentChanged(EventArgs e) {
3710 if (ParentChanged!=null) ParentChanged(this, e);
3713 [EditorBrowsable(EditorBrowsableState.Advanced)]
3714 protected virtual void OnParentEnabledChanged(EventArgs e) {
3715 if (is_enabled != Parent.is_enabled) {
3716 is_enabled=Parent.is_enabled;
3718 if (EnabledChanged != null) {
3719 EnabledChanged(this, e);
3724 [EditorBrowsable(EditorBrowsableState.Advanced)]
3725 protected virtual void OnParentFontChanged(EventArgs e) {
3732 [EditorBrowsable(EditorBrowsableState.Advanced)]
3733 protected virtual void OnParentForeColorChanged(EventArgs e) {
3734 if (foreground_color.IsEmpty) {
3736 OnForeColorChanged(e);
3740 [EditorBrowsable(EditorBrowsableState.Advanced)]
3741 protected virtual void OnParentRightToLeftChanged(EventArgs e) {
3742 if (right_to_left==RightToLeft.Inherit) {
3744 OnRightToLeftChanged(e);
3748 [EditorBrowsable(EditorBrowsableState.Advanced)]
3749 protected virtual void OnParentVisibleChanged(EventArgs e) {
3751 OnVisibleChanged(e);
3755 [EditorBrowsable(EditorBrowsableState.Advanced)]
3756 protected virtual void OnQueryContinueDrag(QueryContinueDragEventArgs e) {
3757 if (QueryContinueDrag!=null) QueryContinueDrag(this, e);
3760 [EditorBrowsable(EditorBrowsableState.Advanced)]
3761 protected virtual void OnResize(EventArgs e) {
3762 if (Resize!=null) Resize(this, e);
3764 PerformLayout(this, "bounds");
3766 if (parent != null) {
3767 parent.PerformLayout();
3771 [EditorBrowsable(EditorBrowsableState.Advanced)]
3772 protected virtual void OnRightToLeftChanged(EventArgs e) {
3773 if (RightToLeftChanged!=null) RightToLeftChanged(this, e);
3774 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentRightToLeftChanged(e);
3777 [EditorBrowsable(EditorBrowsableState.Advanced)]
3778 protected virtual void OnSizeChanged(EventArgs e) {
3779 InvalidateBuffers ();
3781 if (SizeChanged!=null) SizeChanged(this, e);
3784 [EditorBrowsable(EditorBrowsableState.Advanced)]
3785 protected virtual void OnStyleChanged(EventArgs e) {
3786 if (StyleChanged!=null) StyleChanged(this, e);
3789 [EditorBrowsable(EditorBrowsableState.Advanced)]
3790 protected virtual void OnSystemColorsChanged(EventArgs e) {
3791 if (SystemColorsChanged!=null) SystemColorsChanged(this, e);
3794 [EditorBrowsable(EditorBrowsableState.Advanced)]
3795 protected virtual void OnTabIndexChanged(EventArgs e) {
3796 if (TabIndexChanged!=null) TabIndexChanged(this, e);
3799 [EditorBrowsable(EditorBrowsableState.Advanced)]
3800 protected virtual void OnTabStopChanged(EventArgs e) {
3801 if (TabStopChanged!=null) TabStopChanged(this, e);
3804 [EditorBrowsable(EditorBrowsableState.Advanced)]
3805 protected virtual void OnTextChanged(EventArgs e) {
3806 if (TextChanged!=null) TextChanged(this, e);
3809 [EditorBrowsable(EditorBrowsableState.Advanced)]
3810 protected virtual void OnValidated(EventArgs e) {
3811 if (Validated!=null) Validated(this, e);
3814 [EditorBrowsable(EditorBrowsableState.Advanced)]
3815 protected virtual void OnValidating(System.ComponentModel.CancelEventArgs e) {
3816 if (Validating!=null) Validating(this, e);
3819 [EditorBrowsable(EditorBrowsableState.Advanced)]
3820 protected virtual void OnVisibleChanged(EventArgs e) {
3827 if (bmp_mem!=null) {
3833 if (!this.IsHandleCreated) {
3834 this.CreateControl();
3840 if (VisibleChanged!=null) VisibleChanged(this, e);
3842 // We need to tell our kids
3843 for (int i=0; i<child_controls.Count; i++) {
3844 child_controls[i].OnParentVisibleChanged(e);
3847 #endregion // OnXXX methods
3850 public event EventHandler BackColorChanged;
3851 public event EventHandler BackgroundImageChanged;
3852 public event EventHandler BindingContextChanged;
3853 public event EventHandler CausesValidationChanged;
3854 public event UICuesEventHandler ChangeUICues;
3855 public event EventHandler Click;
3856 public event EventHandler ContextMenuChanged;
3858 [EditorBrowsable(EditorBrowsableState.Advanced)]
3860 public event ControlEventHandler ControlAdded;
3862 [EditorBrowsable(EditorBrowsableState.Advanced)]
3864 public event ControlEventHandler ControlRemoved;
3866 public event EventHandler CursorChanged;
3867 public event EventHandler DockChanged;
3868 public event EventHandler DoubleClick;
3869 public event DragEventHandler DragDrop;
3870 public event DragEventHandler DragEnter;
3871 public event EventHandler DragLeave;
3872 public event DragEventHandler DragOver;
3873 public event EventHandler EnabledChanged;
3874 public event EventHandler Enter;
3875 public event EventHandler FontChanged;
3876 public event EventHandler ForeColorChanged;
3877 public event GiveFeedbackEventHandler GiveFeedback;
3879 [EditorBrowsable(EditorBrowsableState.Advanced)]
3881 public event EventHandler GotFocus;
3883 [EditorBrowsable(EditorBrowsableState.Advanced)]
3885 public event EventHandler HandleCreated;
3887 [EditorBrowsable(EditorBrowsableState.Advanced)]
3889 public event EventHandler HandleDestroyed;
3891 public event HelpEventHandler HelpRequested;
3892 public event EventHandler ImeModeChanged;
3894 [EditorBrowsable(EditorBrowsableState.Advanced)]
3896 public event InvalidateEventHandler Invalidated;
3898 public event KeyEventHandler KeyDown;
3899 public event KeyPressEventHandler KeyPress;
3900 public event KeyEventHandler KeyUp;
3901 public event LayoutEventHandler Layout;
3902 public event EventHandler Leave;
3903 public event EventHandler LocationChanged;
3905 [EditorBrowsable(EditorBrowsableState.Advanced)]
3907 public event EventHandler LostFocus;
3909 public event MouseEventHandler MouseDown;
3910 public event EventHandler MouseEnter;
3911 public event EventHandler MouseHover;
3912 public event EventHandler MouseLeave;
3913 public event MouseEventHandler MouseMove;
3914 public event MouseEventHandler MouseUp;
3916 [EditorBrowsable(EditorBrowsableState.Advanced)]
3918 public event MouseEventHandler MouseWheel;
3920 public event EventHandler Move;
3921 public event PaintEventHandler Paint;
3922 public event EventHandler ParentChanged;
3923 public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp;
3924 public event QueryContinueDragEventHandler QueryContinueDrag;
3925 public event EventHandler Resize;
3926 public event EventHandler RightToLeftChanged;
3927 public event EventHandler SizeChanged;
3928 public event EventHandler StyleChanged;
3929 public event EventHandler SystemColorsChanged;
3930 public event EventHandler TabIndexChanged;
3931 public event EventHandler TabStopChanged;
3932 public event EventHandler TextChanged;
3933 public event EventHandler Validated;
3934 public event CancelEventHandler Validating;
3935 public event EventHandler VisibleChanged;
3936 #endregion // Events