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.Security;
45 using System.Threading;
48 namespace System.Windows.Forms
50 [Designer("System.Windows.Forms.Design.ControlDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
51 [DefaultProperty("Text")]
52 [DefaultEvent("Click")]
53 [DesignerSerializer("System.Windows.Forms.Design.ControlCodeDomSerializer, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
54 [ToolboxItemFilter("System.Windows.Forms")]
55 public class Control : Component, ISynchronizeInvoke, IWin32Window
57 #region Local Variables
60 internal Rectangle bounds; // bounding rectangle for control (client area + decorations)
61 internal object creator_thread; // thread that created the control
62 internal ControlNativeWindow window; // object for native window handle
63 internal string name; // for object naming
66 private bool create_handled; // true if OnCreateControl has been sent
67 internal bool has_focus; // true if control has focus
68 internal bool is_visible; // true if control is visible
69 internal bool is_entered; // is the mouse inside the control?
70 internal bool is_enabled; // true if control is enabled (usable/not grayed out)
71 internal bool is_selected; // true if control is selected
72 internal bool is_accessible; // true if the control is visible to accessibility applications
73 internal bool is_captured; // tracks if the control has captured the mouse
74 internal bool is_toplevel; // tracks if the control is a toplevel window
75 internal bool is_recreating; // tracks if the handle for the control is being recreated
76 internal bool causes_validation; // tracks if validation is executed on changes
77 internal int tab_index; // position in tab order of siblings
78 internal bool tab_stop = true; // is the control a tab stop?
79 internal bool is_disposed; // has the window already been disposed?
80 internal Size client_size; // size of the client area (window excluding decorations)
81 internal Rectangle client_rect; // rectangle with the client area (window excluding decorations)
82 internal ControlStyles control_style; // rather win32-specific, style bits for control
83 internal ImeMode ime_mode = ImeMode.Inherit;
84 internal bool layout_pending; // true if our parent needs to re-layout us
85 internal object control_tag; // object that contains data about our control
86 internal int mouse_clicks; // Counter for mouse clicks
87 internal Cursor cursor; // Cursor for the window
88 private bool allow_drop; // true if the control accepts droping objects on it
91 internal Color foreground_color; // foreground color for control
92 internal Color background_color; // background color for control
93 internal Image background_image; // background image for control
94 internal Font font; // font for control
95 internal string text; // window/title text for control
96 internal BorderStyle border_style; // Border style of control
99 internal AnchorStyles anchor_style; // anchoring requirements for our control
100 internal DockStyle dock_style; // docking requirements for our control (supercedes anchoring)
101 internal SizeF size_ratio; // size ratio of our control to it's parent; required for anchoring
102 internal Size prev_size; // previous size of the control; required for anchoring
104 // to be categorized...
105 static internal ArrayList controls = new ArrayList(); // All of the application's controls, in a flat list
106 internal ControlCollection child_controls; // our children
107 internal Control parent; // our parent control
108 internal AccessibleObject accessibility_object; // object that contains accessibility information about our control
109 internal BindingContext binding_context; // TODO
110 internal RightToLeft right_to_left; // drawing direction for control
111 internal int layout_suspended;
112 internal ContextMenu context_menu; // Context menu associated with the control
114 private Graphics dc_mem; // Graphics context for double buffering
115 private Bitmap bmp_mem; // Bitmap for double buffering control
116 private bool needs_redraw = true;
118 private ControlBindingsCollection data_bindings;
120 #endregion // Local Variables
122 #region Private Classes
123 // This helper class allows us to dispatch messages to Control.WndProc
124 internal class ControlNativeWindow : NativeWindow {
125 private Control owner;
127 public ControlNativeWindow(Control control) : base() {
132 public Control Owner {
138 static internal Control ControlFromHandle(IntPtr hWnd) {
139 ControlNativeWindow window;
141 window = (ControlNativeWindow)window_collection[hWnd];
146 protected override void WndProc(ref Message m) {
147 owner.WndProc(ref m);
152 #region Public Classes
154 public class ControlAccessibleObject : AccessibleObject {
155 #region ControlAccessibleObject Local Variables
156 private Control owner;
157 #endregion // ControlAccessibleObject Local Variables
159 #region ControlAccessibleObject Constructors
160 public ControlAccessibleObject(Control ownerControl) {
161 this.owner = ownerControl;
163 #endregion // ControlAccessibleObject Constructors
165 #region ControlAccessibleObject Public Instance Properties
166 public override string DefaultAction {
168 return base.DefaultAction;
172 public override string Description {
174 return base.Description;
178 public IntPtr Handle {
184 // We don't want to let them set it
188 public override string Help {
194 public override string KeyboardShortcut {
196 return base.KeyboardShortcut;
200 public override string Name {
210 public Control Owner {
216 public override AccessibleObject Parent {
223 public override AccessibleRole Role {
228 #endregion // ControlAccessibleObject Public Instance Properties
230 #region ControlAccessibleObject Public Instance Methods
231 public override int GetHelpTopic(out string FileName) {
232 return base.GetHelpTopic (out FileName);
235 [MonoTODO("Implement this and tie it into Control.AccessibilityNotifyClients")]
236 public void NotifyClients(AccessibleEvents accEvent) {
237 throw new NotImplementedException();
240 [MonoTODO("Implement this and tie it into Control.AccessibilityNotifyClients")]
241 public void NotifyClients(AccessibleEvents accEvent, int childID) {
242 throw new NotImplementedException();
245 public override string ToString() {
246 return "ControlAccessibleObject: Owner = " + owner.ToString() + ", Text: " + owner.text;
249 #endregion // ControlAccessibleObject Public Instance Methods
252 [DesignerSerializer("System.Windows.Forms.Design.ControlCollectionCodeDomSerializer, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
253 [ListBindable(false)]
254 public class ControlCollection : IList, ICollection, ICloneable, IEnumerable {
255 #region ControlCollection Local Variables
256 internal ArrayList list;
257 internal Control owner;
258 #endregion // ControlCollection Local Variables
260 #region ControlCollection Public Constructor
261 public ControlCollection(Control owner) {
263 this.list=new ArrayList();
267 #region ControlCollection Public Instance Properties
274 public bool IsReadOnly {
276 return list.IsReadOnly;
280 public virtual Control this[int index] {
282 if (index < 0 || index >= list.Count) {
283 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
285 return (Control)list[index];
288 #endregion // ControlCollection Public Instance Properties
290 #region ControlCollection Private Instance Methods
291 public virtual void Add (Control value)
296 for (int i = list.Count; i > 0; ) {
299 if (list [i] == value) {
300 // Do we need to do anything here?
305 if (value.tab_index == -1) {
311 end = owner.child_controls.Count;
312 for (int i = 0; i < end; i++) {
313 index = owner.child_controls[i].tab_index;
318 value.tab_index = use;
322 value.Parent = owner;
323 owner.UpdateZOrder();
324 owner.OnControlAdded(new ControlEventArgs(value));
327 public virtual void AddRange (Control[] controls)
329 if (controls == null)
330 throw new ArgumentNullException ("controls");
332 owner.SuspendLayout ();
335 for (int i = 0; i < controls.Length; i++)
338 owner.ResumeLayout ();
342 public virtual void Clear ()
344 owner.SuspendLayout();
345 for (int i = 0; i < list.Count; i++) {
346 owner.OnControlRemoved(new ControlEventArgs((Control)list[i]));
349 owner.ResumeLayout();
352 public bool Contains (Control value)
354 return list.Contains (value);
357 public void CopyTo (Array array, int index)
359 list.CopyTo(array, index);
362 public override bool Equals(object other) {
363 if (other is ControlCollection && (((ControlCollection)other).owner==this.owner)) {
370 public int GetChildIndex(Control child) {
371 return GetChildIndex(child, false);
374 public int GetChildIndex(Control child, bool throwException) {
377 index=list.IndexOf(child);
379 if (index==-1 && throwException) {
380 throw new ArgumentException("Not a child control", "child");
385 public IEnumerator GetEnumerator() {
386 return list.GetEnumerator();
389 public override int GetHashCode() {
390 return base.GetHashCode();
393 public int IndexOf(Control control) {
394 return list.IndexOf(control);
397 public virtual void Remove(Control value) {
398 owner.OnControlRemoved(new ControlEventArgs(value));
401 owner.UpdateZOrder();
404 public void RemoveAt(int index) {
405 if (index < 0 || index >= list.Count) {
406 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
408 Remove ((Control)list[index]);
411 public void SetChildIndex(Control child, int newIndex) {
414 old_index=list.IndexOf(child);
416 throw new ArgumentException("Not a child control", "child");
419 if (old_index==newIndex) {
425 if (newIndex>list.Count) {
428 list.Insert(newIndex, child);
430 owner.UpdateZOrder();
432 #endregion // ControlCollection Private Instance Methods
434 #region ControlCollection Interface Properties
435 object IList.this[int index] {
437 if (index<0 || index>=list.Count) {
438 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
444 if (!(value is Control)) {
445 throw new ArgumentException("Object of type Control required", "value");
448 list[index]=(Control)value;
452 bool IList.IsFixedSize {
458 bool IList.IsReadOnly {
460 return list.IsReadOnly;
464 bool ICollection.IsSynchronized {
466 return list.IsSynchronized;
470 object ICollection.SyncRoot {
472 return list.SyncRoot;
475 #endregion // ControlCollection Interface Properties
477 #region ControlCollection Interface Methods
478 int IList.Add(object value) {
480 throw new ArgumentNullException("value", "Cannot add null controls");
483 if (!(value is Control)) {
484 throw new ArgumentException("Object of type Control required", "value");
487 return list.Add(value);
490 bool IList.Contains(object value) {
491 if (!(value is Control)) {
492 throw new ArgumentException("Object of type Control required", "value");
495 return this.Contains((Control) value);
498 int IList.IndexOf(object value) {
499 if (!(value is Control)) {
500 throw new ArgumentException("Object of type Control required", "value");
503 return this.IndexOf((Control) value);
506 void IList.Insert(int index, object value) {
507 if (!(value is Control)) {
508 throw new ArgumentException("Object of type Control required", "value");
510 list.Insert(index, value);
513 void IList.Remove(object value) {
514 if (!(value is Control)) {
515 throw new ArgumentException("Object of type Control required", "value");
520 void ICollection.CopyTo(Array array, int index) {
522 list.CopyTo(array, index);
526 Object ICloneable.Clone() {
527 ControlCollection clone = new ControlCollection(this.owner);
528 clone.list=(ArrayList)list.Clone(); // FIXME: Do we need this?
531 #endregion // ControlCollection Interface Methods
533 #endregion // ControlCollection Class
535 #region Public Constructors
537 creator_thread = Thread.CurrentThread;
539 prev_size = Size.Empty;
540 anchor_style = AnchorStyles.Top | AnchorStyles.Left;
542 create_handled = false;
548 layout_pending = false;
550 causes_validation = true;
552 layout_suspended = 0;
556 right_to_left = RightToLeft.Inherit;
558 control_style = ControlStyles.Selectable | ControlStyles.StandardClick | ControlStyles.StandardDoubleClick;
561 background_image = null;
565 window = new ControlNativeWindow(this);
566 child_controls = CreateControlsInstance();
567 client_size = new Size(DefaultSize.Width, DefaultSize.Height);
568 client_rect = new Rectangle(0, 0, DefaultSize.Width, DefaultSize.Height);
569 XplatUI.CalculateWindowRect(IntPtr.Zero, ref client_rect, CreateParams.Style, CreateParams.ExStyle, IntPtr.Zero, out bounds);
570 if ((CreateParams.Style & (int)WindowStyles.WS_CHILD) == 0) {
576 public Control(Control parent, string text) : this() {
581 public Control(Control parent, string text, int left, int top, int width, int height) : this() {
586 bounds.Height=height;
587 SetBoundsCore(left, top, width, height, BoundsSpecified.All);
591 public Control(string text) : this() {
595 public Control(string text, int left, int top, int width, int height) : this() {
599 bounds.Height=height;
600 SetBoundsCore(left, top, width, height, BoundsSpecified.All);
604 protected override void Dispose(bool disposing) {
617 controls.Remove(this);
619 #endregion // Public Constructors
621 #region Internal Properties
622 internal BorderStyle InternalBorderStyle {
628 if (border_style != value) {
629 border_style = value;
631 XplatUI.SetBorderStyle(window.Handle, border_style);
635 #endregion // Internal Properties
637 #region Private & Internal Methods
638 internal IAsyncResult BeginInvokeInternal (Delegate method, object [] args) {
639 AsyncMethodResult result;
640 AsyncMethodData data;
645 if (!p.IsHandleCreated) {
646 throw new InvalidOperationException("Cannot call Invoke or InvokeAsync on a control until the window handle is created");
651 result = new AsyncMethodResult ();
652 data = new AsyncMethodData ();
654 data.Method = method;
656 data.Result = new WeakReference (result);
659 if (!ExecutionContext.IsFlowSuppressed ()) {
660 data.Context = ExecutionContext.Capture ();
663 #if !MWF_ON_MSRUNTIME
664 if (SecurityManager.SecurityEnabled) {
665 data.Stack = CompressedStack.GetCompressedStack ();
670 XplatUI.SendAsyncMethod (data);
674 internal Graphics DeviceContext {
677 CreateBuffers(this.Width, this.Height);
683 private Bitmap ImageBuffer {
686 CreateBuffers(this.Width, this.Height);
692 internal void CreateBuffers (int width, int height) {
693 if (dc_mem != null) {
707 bmp_mem = new Bitmap (width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
708 dc_mem = Graphics.FromImage (bmp_mem);
712 internal void InvalidateBuffers ()
714 if (dc_mem != null) {
725 internal static void SetChildColor(Control parent) {
728 for (int i=0; i < parent.child_controls.Count; i++) {
729 child=parent.child_controls[i];
730 if (child.IsHandleCreated) {
731 XplatUI.SetWindowBackground(child.window.Handle, child.BackColor);
733 if (child.child_controls.Count>0) {
734 SetChildColor(child);
740 internal bool Select(Control control) {
742 IContainerControl container;
744 if (control == null) {
748 parent = control.parent;
750 if (((control.control_style & ControlStyles.Selectable) !=0) && (parent != null)) {
751 while (parent != null) {
752 if (!parent.Visible || !parent.is_enabled) {
755 parent = parent.parent;
759 control.is_selected = true;
761 container = GetContainerControl();
762 if (container != null) {
763 container.ActiveControl = control;
765 if (control.IsHandleCreated) {
766 XplatUI.SetFocus(control.window.Handle);
771 internal virtual void DoDefaultAction() {
772 // Only here to be overriden by our actual controls; this is needed by the accessibility class
775 internal static int LowOrder (int param) {
776 return ((int)(short)(param & 0xffff));
779 internal static int HighOrder (int param) {
780 return ((int)(short)(param >> 16));
783 // This method exists so controls overriding OnPaintBackground can have default background painting done
784 internal void PaintControlBackground (PaintEventArgs pevent)
786 if (background_image == null)
789 DrawBackgroundImage (pevent.Graphics);
792 void DrawBackgroundImage (Graphics g)
794 using (TextureBrush b = new TextureBrush (background_image)) {
795 g.FillRectangle (b, ClientRectangle);
799 internal void DndEnter (DragEventArgs e)
804 internal void DndOver (DragEventArgs e)
809 internal void DndDrop (DragEventArgs e)
814 internal void DndLeave (EventArgs e)
819 internal void DnDFeedback(GiveFeedbackEventArgs e)
824 internal void DnDContinueDrag(QueryContinueDragEventArgs e) {
825 OnQueryContinueDrag(e);
828 internal static MouseButtons FromParamToMouseButtons (int param) {
829 MouseButtons buttons = MouseButtons.None;
831 if ((param & (int) MsgButtons.MK_LBUTTON) != 0)
832 buttons |= MouseButtons.Left;
834 if ((param & (int) MsgButtons.MK_MBUTTON) != 0)
835 buttons |= MouseButtons.Middle;
837 if ((param & (int) MsgButtons.MK_RBUTTON) != 0)
838 buttons |= MouseButtons.Right;
844 internal virtual bool ProcessControlMnemonic(char charCode) {
845 return ProcessMnemonic(charCode);
848 private static Control FindFlatForward(Control container, Control start) {
854 end = container.child_controls.Count;
857 index = start.tab_index;
862 for (int i = 0; i < end; i++) {
864 if (container.child_controls[i].tab_index > index) {
865 found = container.child_controls[i];
867 } else if (found.tab_index > container.child_controls[i].tab_index) {
868 if (container.child_controls[i].tab_index > index) {
869 found = container.child_controls[i];
876 private static Control FindControlForward(Control container, Control start) {
883 if ((start is IContainerControl) || start.GetStyle(ControlStyles.ContainerControl)) {
884 found = FindControlForward(start, null);
891 while (p != container) {
892 found = FindFlatForward(p, start);
900 return FindFlatForward(container, start);
903 private static Control FindFlatBackward(Control container, Control start) {
909 end = container.child_controls.Count;
912 index = start.tab_index;
914 // FIXME: Possible speed-up: Keep the highest taborder index in the container
916 for (int i = 0; i < end; i++) {
917 if (container.child_controls[i].tab_index > index) {
918 index = container.child_controls[i].tab_index;
924 for (int i = 0; i < end; i++) {
926 if (container.child_controls[i].tab_index < index) {
927 found = container.child_controls[i];
929 } else if (found.tab_index < container.child_controls[i].tab_index) {
930 if (container.child_controls[i].tab_index < index) {
931 found = container.child_controls[i];
938 private static Control FindControlBackward(Control container, Control start) {
944 found = FindFlatBackward(start.parent, start);
945 if (found == null && start.parent != container) {
950 found = FindFlatBackward(container, start);
953 while ((found != null) && ((found is IContainerControl) || found.GetStyle(ControlStyles.ContainerControl))) {
954 found = FindControlBackward(found, null);
963 private void HandleClick(int clicks) {
964 if (GetStyle(ControlStyles.StandardClick)) {
966 if (GetStyle(ControlStyles.StandardDoubleClick)) {
967 OnDoubleClick(EventArgs.Empty);
969 OnClick(EventArgs.Empty);
972 OnClick(EventArgs.Empty);
977 private void CheckDataBindings ()
979 if (data_bindings == null)
982 BindingContext binding_context = BindingContext;
983 foreach (Binding binding in data_bindings) {
984 binding.Check (binding_context);
988 #endregion // Private & Internal Methods
990 #region Public Static Properties
991 public static Color DefaultBackColor {
993 return ThemeEngine.Current.DefaultControlBackColor;
997 public static Font DefaultFont {
999 return ThemeEngine.Current.DefaultFont;
1003 public static Color DefaultForeColor {
1005 return ThemeEngine.Current.DefaultControlForeColor;
1009 public static Keys ModifierKeys {
1011 return XplatUI.State.ModifierKeys;
1015 public static MouseButtons MouseButtons {
1017 return XplatUI.State.MouseButtons;
1021 public static Point MousePosition {
1023 return Cursor.Position;
1029 public static bool CheckForIllegalCrossThreadCalls
1038 #endregion // Public Static Properties
1040 #region Public Instance Properties
1041 [EditorBrowsable(EditorBrowsableState.Advanced)]
1043 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1044 public AccessibleObject AccessibilityObject {
1046 if (accessibility_object==null) {
1047 accessibility_object=CreateAccessibilityInstance();
1049 return accessibility_object;
1053 [EditorBrowsable(EditorBrowsableState.Advanced)]
1055 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1056 public string AccessibleDefaultActionDescription {
1058 return AccessibilityObject.default_action;
1062 AccessibilityObject.default_action=value;
1067 [DefaultValue(null)]
1068 public string AccessibleDescription {
1070 return AccessibilityObject.description;
1074 AccessibilityObject.description=value;
1079 [DefaultValue(null)]
1080 public string AccessibleName {
1082 return AccessibilityObject.Name;
1086 AccessibilityObject.Name=value;
1090 [DefaultValue(AccessibleRole.Default)]
1091 [MWFDescription("Role of the control"), MWFCategory("Accessibility")]
1092 public AccessibleRole AccessibleRole {
1094 return AccessibilityObject.role;
1098 AccessibilityObject.role=value;
1102 [DefaultValue(false)]
1103 public virtual bool AllowDrop {
1109 if (allow_drop == value)
1113 XplatUI.SetAllowDrop (Handle, value);
1118 [RefreshProperties(RefreshProperties.Repaint)]
1119 [DefaultValue(AnchorStyles.Top | AnchorStyles.Left)]
1120 public virtual AnchorStyles Anchor {
1122 return anchor_style;
1128 if (parent != null) {
1129 parent.PerformLayout(this, "Parent");
1135 public virtual Color BackColor {
1137 if (background_color.IsEmpty) {
1139 return parent.BackColor;
1141 return DefaultBackColor;
1143 return background_color;
1147 background_color=value;
1148 if (this.IsHandleCreated) {
1149 XplatUI.SetWindowBackground(this.window.Handle, value);
1151 SetChildColor(this);
1152 OnBackColorChanged(EventArgs.Empty);
1158 [DefaultValue(null)]
1159 public virtual Image BackgroundImage {
1161 return background_image;
1165 if (background_image!=value) {
1166 background_image=value;
1167 OnBackgroundImageChanged(EventArgs.Empty);
1172 [EditorBrowsable(EditorBrowsableState.Advanced)]
1174 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1175 public virtual BindingContext BindingContext {
1177 if (binding_context != null)
1178 return binding_context;
1181 binding_context = Parent.BindingContext;
1182 return binding_context;
1185 if (binding_context != value) {
1186 binding_context = value;
1187 OnBindingContextChanged(EventArgs.Empty);
1192 [EditorBrowsable(EditorBrowsableState.Advanced)]
1194 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1197 return bounds.Y+bounds.Height;
1201 [EditorBrowsable(EditorBrowsableState.Advanced)]
1203 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1204 public Rectangle Bounds {
1210 SetBoundsCore(value.Left, value.Top, value.Width, value.Height, BoundsSpecified.All);
1214 [EditorBrowsable(EditorBrowsableState.Advanced)]
1216 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1217 public bool CanFocus {
1219 if (Visible && is_enabled && GetStyle(ControlStyles.Selectable)) {
1226 [EditorBrowsable(EditorBrowsableState.Advanced)]
1228 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1229 public bool CanSelect {
1233 if (!GetStyle(ControlStyles.Selectable) || this.parent == null) {
1237 parent = this.parent;
1238 while (parent != null) {
1239 if (!parent.is_visible || !parent.is_enabled) {
1243 parent = parent.parent;
1249 [EditorBrowsable(EditorBrowsableState.Advanced)]
1251 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1252 public bool Capture {
1254 return this.is_captured;
1258 if (this.IsHandleCreated) {
1259 if (value && !is_captured) {
1261 XplatUI.GrabWindow(this.window.Handle, IntPtr.Zero);
1262 } else if (!value && is_captured) {
1263 XplatUI.UngrabWindow(this.window.Handle);
1264 is_captured = false;
1270 [DefaultValue(true)]
1271 public bool CausesValidation {
1273 return this.causes_validation;
1277 if (this.causes_validation != value) {
1278 causes_validation = value;
1279 OnCausesValidationChanged(EventArgs.Empty);
1284 [EditorBrowsable(EditorBrowsableState.Advanced)]
1286 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1287 public Rectangle ClientRectangle {
1289 client_rect.Width = client_size.Width;
1290 client_rect.Height = client_size.Height;
1295 [EditorBrowsable(EditorBrowsableState.Advanced)]
1297 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1298 public Size ClientSize {
1301 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1302 return ((Form)this).form_parent_window.ClientSize;
1310 this.SetClientSizeCore(value.Width, value.Height);
1314 [EditorBrowsable(EditorBrowsableState.Advanced)]
1316 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1317 [DescriptionAttribute("ControlCompanyNameDescr")]
1318 public String CompanyName {
1320 return "Mono Project, Novell, Inc.";
1324 [EditorBrowsable(EditorBrowsableState.Advanced)]
1326 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1327 public bool ContainsFocus {
1333 for (int i=0; i < child_controls.Count; i++) {
1334 if (child_controls[i].ContainsFocus) {
1342 [DefaultValue(null)]
1343 public virtual ContextMenu ContextMenu {
1345 return context_menu;
1349 if (context_menu != value) {
1350 context_menu = value;
1351 OnContextMenuChanged(EventArgs.Empty);
1357 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
1358 public ControlCollection Controls {
1360 return this.child_controls;
1364 [EditorBrowsable(EditorBrowsableState.Advanced)]
1366 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1367 public bool Created {
1369 if (!this.is_disposed && (this.window.Handle != IntPtr.Zero)) {
1376 [AmbientValue(null)]
1377 public virtual Cursor Cursor {
1379 if (cursor != null) {
1383 if (parent != null) {
1384 return parent.Cursor;
1387 return Cursors.Default;
1391 if (cursor != value) {
1396 pt = Cursor.Position;
1397 if (bounds.Contains(pt)) {
1398 if (GetChildAtPoint(pt) == null) {
1399 if (cursor != null) {
1400 XplatUI.SetCursor(window.Handle, cursor.handle);
1402 if (parent != null) {
1403 XplatUI.SetCursor(window.Handle, parent.Cursor.handle);
1405 XplatUI.SetCursor(window.Handle, Cursors.def.handle);
1411 OnCursorChanged(EventArgs.Empty);
1417 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
1418 [ParenthesizePropertyName(true)]
1419 [RefreshProperties(RefreshProperties.All)]
1420 public ControlBindingsCollection DataBindings {
1422 if (data_bindings == null)
1423 data_bindings = new ControlBindingsCollection (this);
1424 return data_bindings;
1428 [EditorBrowsable(EditorBrowsableState.Advanced)]
1430 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1431 public virtual Rectangle DisplayRectangle {
1433 return ClientRectangle;
1437 [EditorBrowsable(EditorBrowsableState.Advanced)]
1439 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1440 public bool Disposing {
1447 [RefreshProperties(RefreshProperties.Repaint)]
1448 [DefaultValue(DockStyle.None)]
1449 public virtual DockStyle Dock {
1455 if (dock_style == value) {
1461 if (parent != null) {
1462 parent.PerformLayout(this, "Parent");
1465 OnDockChanged(EventArgs.Empty);
1471 public bool Enabled {
1477 if (is_enabled == value) {
1483 OnEnabledChanged (EventArgs.Empty);
1487 [EditorBrowsable(EditorBrowsableState.Advanced)]
1489 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1490 public virtual bool Focused {
1492 return this.has_focus;
1497 [AmbientValue(null)]
1499 public virtual Font Font {
1505 if (Parent != null && Parent.Font != null) {
1513 if (font != null && font.Equals (value)) {
1519 OnFontChanged (EventArgs.Empty);
1524 public virtual Color ForeColor {
1526 if (foreground_color.IsEmpty) {
1528 return parent.ForeColor;
1530 return DefaultForeColor;
1532 return foreground_color;
1536 if (foreground_color != value) {
1537 foreground_color=value;
1539 OnForeColorChanged(EventArgs.Empty);
1546 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1547 public IntPtr Handle { // IWin32Window
1549 if (!IsHandleCreated) {
1552 return window.Handle;
1556 [EditorBrowsable(EditorBrowsableState.Advanced)]
1558 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1559 public bool HasChildren {
1561 if (this.child_controls.Count>0) {
1568 [EditorBrowsable(EditorBrowsableState.Always)]
1570 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1573 return this.bounds.Height;
1577 SetBoundsCore(bounds.X, bounds.Y, bounds.Width, value, BoundsSpecified.Height);
1581 [AmbientValue(ImeMode.Inherit)]
1583 public ImeMode ImeMode {
1585 if (ime_mode == DefaultImeMode) {
1587 return parent.ImeMode;
1589 return ImeMode.NoControl; // default value
1595 if (ime_mode != value) {
1598 OnImeModeChanged(EventArgs.Empty);
1603 [EditorBrowsable(EditorBrowsableState.Advanced)]
1605 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1606 public bool InvokeRequired { // ISynchronizeInvoke
1608 if (creator_thread!=Thread.CurrentThread) {
1615 [EditorBrowsable(EditorBrowsableState.Advanced)]
1617 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1618 public bool IsAccessible {
1620 return is_accessible;
1624 is_accessible = value;
1628 [EditorBrowsable(EditorBrowsableState.Advanced)]
1630 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1631 public bool IsDisposed {
1633 return this.is_disposed;
1637 [EditorBrowsable(EditorBrowsableState.Advanced)]
1639 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1640 public bool IsHandleCreated {
1642 if ((window!=null) && (window.Handle!=IntPtr.Zero)) {
1650 [EditorBrowsable(EditorBrowsableState.Always)]
1652 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1655 return this.bounds.X;
1659 SetBoundsCore(value, bounds.Y, bounds.Width, bounds.Height, BoundsSpecified.X);
1664 public Point Location {
1666 return new Point(bounds.X, bounds.Y);
1670 SetBoundsCore(value.X, value.Y, bounds.Width, bounds.Height, BoundsSpecified.Location);
1675 public string Name {
1686 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1687 public Control Parent {
1693 if (value == this) {
1694 throw new ArgumentException("A circular control reference has been made. A control cannot be owned or parented to itself.");
1697 if (parent!=value) {
1699 parent.Controls.Remove(this);
1705 if (!parent.Controls.Contains(this)) {
1706 parent.Controls.Add(this);
1709 if (IsHandleCreated) {
1710 XplatUI.SetParent(Handle, value.Handle);
1713 OnParentChanged(EventArgs.Empty);
1719 [EditorBrowsable(EditorBrowsableState.Advanced)]
1721 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1722 public string ProductName {
1724 Type t = typeof (AssemblyProductAttribute);
1725 Assembly assembly = GetType().Module.Assembly;
1726 object [] attrs = assembly.GetCustomAttributes (t, false);
1727 AssemblyProductAttribute a = null;
1728 // On MS we get a NullRefException if product attribute is not
1730 if (attrs != null && attrs.Length > 0)
1731 a = (AssemblyProductAttribute) attrs [0];
1736 [EditorBrowsable(EditorBrowsableState.Advanced)]
1738 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1739 public string ProductVersion {
1741 Type t = typeof (AssemblyVersionAttribute);
1742 Assembly assembly = GetType().Module.Assembly;
1743 object [] attrs = assembly.GetCustomAttributes (t, false);
1744 if (attrs == null || attrs.Length < 1)
1746 return ((AssemblyVersionAttribute)attrs [0]).Version;
1750 [EditorBrowsable(EditorBrowsableState.Advanced)]
1752 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1753 public bool RecreatingHandle {
1755 return is_recreating;
1759 [EditorBrowsable(EditorBrowsableState.Advanced)]
1761 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1762 public Region Region {
1764 return new Region(this.bounds);
1771 g = this.CreateGraphics();
1772 r = value.GetBounds(g);
1774 SetBounds((int)r.X, (int)r.Y, (int)r.Width, (int)r.Height);
1780 [EditorBrowsable(EditorBrowsableState.Advanced)]
1782 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1785 return this.bounds.X+this.bounds.Width;
1789 [AmbientValue(RightToLeft.Inherit)]
1791 public virtual RightToLeft RightToLeft {
1793 if (right_to_left == RightToLeft.Inherit) {
1795 return parent.RightToLeft;
1797 return RightToLeft.No; // default value
1799 return right_to_left;
1803 if (value != right_to_left) {
1804 right_to_left = value;
1805 OnRightToLeftChanged(EventArgs.Empty);
1810 [EditorBrowsable(EditorBrowsableState.Advanced)]
1811 public override ISite Site {
1824 return new Size(Width, Height);
1828 SetBoundsCore(bounds.X, bounds.Y, value.Width, value.Height, BoundsSpecified.Size);
1833 [MergableProperty(false)]
1834 public int TabIndex {
1836 if (tab_index != -1) {
1843 if (tab_index != value) {
1845 OnTabIndexChanged(EventArgs.Empty);
1851 [DefaultValue(true)]
1852 public bool TabStop {
1858 if (tab_stop != value) {
1860 OnTabStopChanged(EventArgs.Empty);
1865 [Localizable(false)]
1867 [TypeConverter(typeof(StringConverter))]
1868 [DefaultValue(null)]
1875 control_tag = value;
1881 [BindableAttribute(true)]
1882 public virtual string Text {
1888 if (value == null) {
1889 value = String.Empty;
1894 if (IsHandleCreated) {
1895 XplatUI.Text(Handle, text);
1897 // FIXME: Do we need a Refresh() here?
1900 OnTextChanged (EventArgs.Empty);
1905 [EditorBrowsable(EditorBrowsableState.Always)]
1907 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1910 return this.bounds.Y;
1914 SetBoundsCore(bounds.X, value, bounds.Width, bounds.Height, BoundsSpecified.Y);
1918 [EditorBrowsable(EditorBrowsableState.Advanced)]
1920 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1921 public Control TopLevelControl {
1925 while (p.parent != null) {
1934 public bool Visible {
1938 } else if (parent != null) {
1939 return parent.Visible;
1946 SetVisibleCore(value);
1950 [EditorBrowsable(EditorBrowsableState.Always)]
1952 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1955 return this.bounds.Width;
1959 SetBoundsCore(bounds.X, bounds.Y, value, bounds.Height, BoundsSpecified.Width);
1963 [EditorBrowsable(EditorBrowsableState.Never)]
1965 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1966 public IWindowTarget WindowTarget {
1975 #endregion // Public Instance Properties
1977 #region Protected Instance Properties
1978 protected virtual CreateParams CreateParams {
1980 CreateParams create_params = new CreateParams();
1983 create_params.Caption = Text;
1986 create_params.Caption = text;
1990 create_params.X = Left;
1993 create_params.X = this.bounds.X;
1997 create_params.Y = Top;
2000 create_params.Y = this.bounds.Y;
2004 create_params.Width = Width;
2007 create_params.Width = this.bounds.Width;
2011 create_params.Height = Height;
2014 create_params.Height = this.bounds.Height;
2018 create_params.ClassName = XplatUI.DefaultClassName;
2019 create_params.ClassStyle = 0;
2020 create_params.ExStyle = 0;
2021 create_params.Param = 0;
2024 create_params.ExStyle |= (int)WindowStyles.WS_EX_ACCEPTFILES;
2028 create_params.Parent = parent.Handle;
2031 create_params.Style = (int)WindowStyles.WS_CHILD | (int)WindowStyles.WS_CLIPCHILDREN | (int)WindowStyles.WS_CLIPSIBLINGS;
2034 create_params.Style |= (int)WindowStyles.WS_VISIBLE;
2037 return create_params;
2041 protected virtual ImeMode DefaultImeMode {
2043 return ImeMode.Inherit;
2047 protected virtual Size DefaultSize {
2049 return new Size(100, 23);
2053 protected int FontHeight {
2063 protected bool RenderRightToLeft {
2065 return (this.right_to_left == RightToLeft.Yes);
2069 protected bool ResizeRedraw {
2071 return GetStyle(ControlStyles.ResizeRedraw);
2075 SetStyle(ControlStyles.ResizeRedraw, value);
2079 [EditorBrowsable(EditorBrowsableState.Advanced)]
2081 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2082 protected virtual bool ShowFocusCues {
2088 [EditorBrowsable(EditorBrowsableState.Advanced)]
2090 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2091 protected bool ShowKeyboardCues {
2096 #endregion // Protected Instance Properties
2098 #region Public Static Methods
2099 [EditorBrowsable(EditorBrowsableState.Advanced)]
2100 public static Control FromChildHandle(IntPtr handle) {
2101 IEnumerator control = Control.controls.GetEnumerator();
2103 while (control.MoveNext()) {
2104 if (((Control)control.Current).window.Handle == handle) {
2106 if (((Control)control.Current).Parent != null) {
2107 return ((Control)control.Current).Parent;
2114 [EditorBrowsable(EditorBrowsableState.Advanced)]
2115 public static Control FromHandle(IntPtr handle) {
2116 IEnumerator control = Control.controls.GetEnumerator();
2118 while (control.MoveNext()) {
2119 if (((Control)control.Current).window.Handle == handle) {
2121 return ((Control)control.Current);
2127 public static bool IsMnemonic(char charCode, string text) {
2130 amp = text.IndexOf('&');
2133 if (amp + 1 < text.Length) {
2134 if (text[amp + 1] != '&') {
2135 if (Char.ToUpper(charCode) == Char.ToUpper(text.ToCharArray(amp + 1, 1)[0])) {
2145 #region Protected Static Methods
2146 [EditorBrowsable(EditorBrowsableState.Advanced)]
2147 protected static bool ReflectMessage(IntPtr hWnd, ref Message m) {
2150 c = Control.FromHandle(hWnd);
2160 #region Public Instance Methods
2161 [EditorBrowsable(EditorBrowsableState.Advanced)]
2162 public IAsyncResult BeginInvoke(Delegate method) {
2163 return BeginInvokeInternal(method, null);
2166 [EditorBrowsable(EditorBrowsableState.Advanced)]
2167 public IAsyncResult BeginInvoke (Delegate method, object[] args) {
2168 return BeginInvokeInternal (method, args);
2171 public void BringToFront() {
2172 if ((parent != null) && (parent.child_controls[0]!=this)) {
2173 if (parent.child_controls.Contains(this)) {
2174 parent.child_controls.SetChildIndex(this, 0);
2178 XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, true, false);
2180 if (parent != null) {
2185 public bool Contains(Control ctl) {
2186 while (ctl != null) {
2195 public void CreateControl() {
2197 if (!IsHandleCreated) {
2201 if (!create_handled) {
2202 create_handled = true;
2206 for (int i=0; i<child_controls.Count; i++) {
2207 child_controls[i].CreateControl();
2211 public Graphics CreateGraphics() {
2212 if (!IsHandleCreated) {
2213 this.CreateControl();
2215 return Graphics.FromHwnd(this.window.Handle);
2218 public DragDropEffects DoDragDrop(object data, DragDropEffects allowedEffects) {
2219 return XplatUI.StartDrag(this.window.Handle, data, allowedEffects);
2222 [EditorBrowsable(EditorBrowsableState.Advanced)]
2223 public object EndInvoke (IAsyncResult async_result) {
2224 AsyncMethodResult result = (AsyncMethodResult) async_result;
2225 return result.EndInvoke ();
2228 public Form FindForm() {
2241 public bool Focus() {
2242 if (IsHandleCreated && !has_focus) {
2244 XplatUI.SetFocus(window.Handle);
2249 public Control GetChildAtPoint(Point pt) {
2250 // Microsoft's version of this function doesn't seem to work, so I can't check
2251 // if we only consider children or also grandchildren, etc.
2252 // I'm gonna say 'children only'
2253 for (int i=0; i<child_controls.Count; i++) {
2254 if (child_controls[i].Bounds.Contains(pt)) {
2255 return child_controls[i];
2261 public IContainerControl GetContainerControl() {
2262 Control current = this;
2264 while (current!=null) {
2265 if ((current is IContainerControl) && ((current.control_style & ControlStyles.ContainerControl)!=0)) {
2266 return (IContainerControl)current;
2268 current = current.parent;
2273 public Control GetNextControl(Control ctl, bool forward) {
2274 // If we're not a container we don't play
2275 if (!(this is IContainerControl) && !this.GetStyle(ControlStyles.ContainerControl)) {
2279 // If ctl is not contained by this, we start at the first child of this
2280 if (!this.Contains(ctl)) {
2284 // Search through our controls, starting at ctl, stepping into children as we encounter them
2285 // try to find the control with the tabindex closest to our own, or, if we're looking into
2286 // child controls, the one with the smallest tabindex
2288 return FindControlForward(this, ctl);
2290 return FindControlBackward(this, ctl);
2293 public void Hide() {
2294 this.Visible = false;
2297 public void Invalidate() {
2298 Invalidate(ClientRectangle, false);
2301 public void Invalidate(bool invalidateChildren) {
2302 Invalidate(ClientRectangle, invalidateChildren);
2305 public void Invalidate(System.Drawing.Rectangle rc) {
2306 Invalidate(rc, false);
2309 public void Invalidate(System.Drawing.Rectangle rc, bool invalidateChildren) {
2310 if (!IsHandleCreated || !Visible) {
2314 NotifyInvalidate(rc);
2316 XplatUI.Invalidate(Handle, rc, false);
2318 if (invalidateChildren) {
2319 for (int i=0; i<child_controls.Count; i++) child_controls[i].Invalidate();
2321 OnInvalidated(new InvalidateEventArgs(rc));
2324 public void Invalidate(System.Drawing.Region region) {
2325 Invalidate(region, false);
2328 [MonoTODO("Figure out if GetRegionScans is usable")]
2329 public void Invalidate(System.Drawing.Region region, bool invalidateChildren) {
2330 throw new NotImplementedException();
2332 // FIXME - should use the GetRegionScans function of the region to invalidate each area
2333 //if (invalidateChildren) {
2334 // for (int i=0; i<child_controls.Count; i++) child_controls[i].Invalidate();
2338 public object Invoke (Delegate method) {
2339 return Invoke(method, null);
2342 public object Invoke (Delegate method, object[] args) {
2343 if (!this.InvokeRequired) {
2344 return method.DynamicInvoke(args);
2347 IAsyncResult result = BeginInvoke (method, args);
2348 return EndInvoke(result);
2351 [EditorBrowsable(EditorBrowsableState.Advanced)]
2352 public void PerformLayout() {
2353 PerformLayout(null, null);
2356 [EditorBrowsable(EditorBrowsableState.Advanced)]
2357 public void PerformLayout(Control affectedControl, string affectedProperty) {
2358 LayoutEventArgs levent = new LayoutEventArgs(affectedControl, affectedProperty);
2360 if (layout_suspended>0) {
2361 layout_pending = true;
2365 layout_pending = false;
2367 // Prevent us from getting messed up
2370 // Perform all Dock and Anchor calculations
2373 AnchorStyles anchor;
2378 space=this.DisplayRectangle;
2379 if (prev_size != Size.Empty) {
2380 diff_width = space.Width - prev_size.Width;
2381 diff_height = space.Height - prev_size.Height;
2387 // Deal with docking; go through in reverse, MS docs say that lowest Z-order is closest to edge
2388 for (int i = child_controls.Count - 1; i >= 0; i--) {
2389 child=child_controls[i];
2390 switch (child.Dock) {
2391 case DockStyle.None: {
2396 case DockStyle.Left: {
2397 child.SetBounds(space.Left, space.Y, child.Width, space.Height);
2398 space.X+=child.Width;
2399 space.Width-=child.Width;
2403 case DockStyle.Top: {
2404 child.SetBounds(space.Left, space.Y, space.Width, child.Height);
2405 space.Y+=child.Height;
2406 space.Height-=child.Height;
2410 case DockStyle.Right: {
2411 child.SetBounds(space.Right-child.Width, space.Y, child.Width, space.Height);
2412 space.Width-=child.Width;
2416 case DockStyle.Bottom: {
2417 child.SetBounds(space.Left, space.Bottom-child.Height, space.Width, child.Height);
2418 space.Height-=child.Height;
2424 for (int i = child_controls.Count - 1; i >= 0; i--) {
2425 child=child_controls[i];
2427 if (child.Dock == DockStyle.Fill) {
2428 child.SetBounds(space.Left, space.Top, space.Width, space.Height);
2434 space=this.DisplayRectangle;
2436 // Deal with anchoring
2437 for (int i=0; i < child_controls.Count; i++) {
2443 child=child_controls[i];
2444 anchor=child.Anchor;
2449 height=child.Height;
2451 // If the control is docked we don't need to do anything
2452 if (child.Dock != DockStyle.None) {
2456 if ((anchor & AnchorStyles.Left) !=0 ) {
2457 if ((anchor & AnchorStyles.Right) != 0) {
2458 // Anchoring to left and right
2459 width=width+diff_width;
2463 } else if ((anchor & AnchorStyles.Right) != 0) {
2469 if ((anchor & AnchorStyles.Top) !=0 ) {
2470 if ((anchor & AnchorStyles.Bottom) != 0) {
2471 height+=diff_height;
2475 } else if ((anchor & AnchorStyles.Bottom) != 0) {
2490 child.SetBounds(left, top, width, height);
2493 // Let everyone know
2497 // Need to make sure we decremend layout_suspended
2503 public Point PointToClient (Point p) {
2507 XplatUI.ScreenToClient (Handle, ref x, ref y);
2509 return new Point (x, y);
2512 public Point PointToScreen(Point p) {
2516 XplatUI.ClientToScreen(Handle, ref x, ref y);
2518 return new Point(x, y);
2521 public virtual bool PreProcessMessage(ref Message msg) {
2524 if ((msg.Msg == (int)Msg.WM_KEYDOWN) || (msg.Msg == (int)Msg.WM_SYSKEYDOWN)) {
2525 key_data = (Keys)msg.WParam.ToInt32();
2526 if (!ProcessCmdKey(ref msg, key_data)) {
2527 if (IsInputKey(key_data)) {
2531 return ProcessDialogKey(key_data);
2535 } else if (msg.Msg == (int)Msg.WM_CHAR) {
2536 if (IsInputChar((char)msg.WParam)) {
2539 } else if (msg.Msg == (int)Msg.WM_SYSCHAR) {
2540 if (IsInputChar((char)msg.WParam)) {
2543 return ProcessDialogChar((char)msg.WParam);
2548 public Rectangle RectangleToClient(Rectangle r) {
2549 return new Rectangle(PointToClient(r.Location), r.Size);
2552 public Rectangle RectangleToScreen(Rectangle r) {
2553 return new Rectangle(PointToScreen(r.Location), r.Size);
2556 public virtual void Refresh() {
2557 if (IsHandleCreated == true) {
2561 XplatUI.UpdateWindow(window.Handle);
2563 end = child_controls.Count;
2564 for (int i=0; i < end; i++) {
2565 child_controls[i].Refresh();
2571 [EditorBrowsable(EditorBrowsableState.Never)]
2572 public virtual void ResetBackColor() {
2573 background_color = Color.Empty;
2576 [EditorBrowsable(EditorBrowsableState.Never)]
2578 public void ResetBindings() {
2582 [EditorBrowsable(EditorBrowsableState.Never)]
2583 public virtual void ResetCursor() {
2587 [EditorBrowsable(EditorBrowsableState.Never)]
2588 public virtual void ResetFont() {
2592 [EditorBrowsable(EditorBrowsableState.Never)]
2593 public virtual void ResetForeColor() {
2594 foreground_color = Color.Empty;
2597 [EditorBrowsable(EditorBrowsableState.Never)]
2598 public void ResetImeMode() {
2599 ime_mode = DefaultImeMode;
2602 [EditorBrowsable(EditorBrowsableState.Never)]
2603 public virtual void ResetRightToLeft() {
2604 right_to_left = RightToLeft.Inherit;
2607 public virtual void ResetText() {
2608 text = String.Empty;
2611 public void ResumeLayout() {
2612 ResumeLayout (true);
2615 public void ResumeLayout(bool performLayout) {
2618 if (layout_suspended > 0) {
2622 if (performLayout || layout_pending) {
2627 public void Scale(float ratio) {
2628 ScaleCore(ratio, ratio);
2631 public void Scale(float dx, float dy) {
2635 public void Select() {
2636 Select(false, false);
2639 public bool SelectNextControl(Control ctl, bool forward, bool tabStopOnly, bool nested, bool wrap) {
2644 c = GetNextControl(c, forward);
2653 if (c.CanSelect && ((c.parent == ctl.parent) || nested) && (c.tab_stop || !tabStopOnly)) {
2657 } while (c != ctl); // If we wrap back to ourselves we stop
2662 public void SendToBack() {
2663 if ((parent != null) && (parent.child_controls[parent.child_controls.Count-1]!=this)) {
2664 if (parent.child_controls.Contains(this)) {
2665 parent.child_controls.SetChildIndex(this, parent.child_controls.Count);
2669 XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, false, true);
2670 if (parent != null) {
2675 public void SetBounds(int x, int y, int width, int height) {
2676 SetBoundsCore(x, y, width, height, BoundsSpecified.All);
2679 public void SetBounds(int x, int y, int width, int height, BoundsSpecified specified) {
2680 SetBoundsCore(x, y, width, height, specified);
2683 public void Show() {
2684 if (!IsHandleCreated) {
2685 this.CreateControl();
2691 public void SuspendLayout() {
2695 public void Update() {
2696 needs_redraw = true;
2697 XplatUI.UpdateWindow(window.Handle);
2699 #endregion // Public Instance Methods
2701 #region Protected Instance Methods
2702 [EditorBrowsable(EditorBrowsableState.Advanced)]
2703 [MonoTODO("Implement this and tie it into Control.ControlAccessibleObject.NotifyClients")]
2704 protected void AccessibilityNotifyClients(AccessibleEvents accEvent, int childID) {
2705 throw new NotImplementedException();
2708 [EditorBrowsable(EditorBrowsableState.Advanced)]
2709 protected virtual AccessibleObject CreateAccessibilityInstance() {
2710 return new Control.ControlAccessibleObject(this);
2713 [EditorBrowsable(EditorBrowsableState.Advanced)]
2714 protected virtual ControlCollection CreateControlsInstance() {
2715 return new ControlCollection(this);
2718 [EditorBrowsable(EditorBrowsableState.Advanced)]
2719 protected virtual void CreateHandle() {
2721 throw new ObjectDisposedException(Name);
2724 if (IsHandleCreated) {
2728 window.CreateHandle(CreateParams);
2730 // Find out where the window manager placed us
2734 if (window.Handle!=IntPtr.Zero) {
2735 if (!controls.Contains(window.Handle)) {
2739 creator_thread = Thread.CurrentThread;
2741 XplatUI.SetWindowBackground(window.Handle, this.BackColor);
2743 OnHandleCreated(EventArgs.Empty);
2747 [EditorBrowsable(EditorBrowsableState.Advanced)]
2748 protected virtual void DefWndProc(ref Message m) {
2749 window.DefWndProc(ref m);
2752 [EditorBrowsable(EditorBrowsableState.Advanced)]
2753 protected virtual void DestroyHandle() {
2754 if (IsHandleCreated) {
2755 // Destroy our children before we destroy ourselves, to prevent them from
2756 // being implictly (without us knowing) destroyed
2757 for (int i=0; i < child_controls.Count; i++) {
2758 child_controls[i].DestroyHandle();
2762 if (window != null) {
2763 window.DestroyHandle();
2765 OnHandleDestroyed(EventArgs.Empty);
2769 protected bool GetStyle(ControlStyles flag) {
2770 return (control_style & flag) != 0;
2773 protected bool GetTopLevel() {
2777 [EditorBrowsable(EditorBrowsableState.Advanced)]
2778 protected virtual void InitLayout() {
2779 if (parent != null) {
2780 parent.PerformLayout(this, "parent");
2784 [EditorBrowsable(EditorBrowsableState.Advanced)]
2785 protected void InvokeGotFocus(Control toInvoke, EventArgs e) {
2786 toInvoke.OnGotFocus(e);
2789 [EditorBrowsable(EditorBrowsableState.Advanced)]
2790 protected void InvokeLostFocus(Control toInvoke, EventArgs e) {
2791 toInvoke.OnLostFocus(e);
2794 [EditorBrowsable(EditorBrowsableState.Advanced)]
2795 protected void InvokeOnClick(Control toInvoke, EventArgs e) {
2796 toInvoke.OnClick(e);
2799 protected void InvokePaint(Control toInvoke, PaintEventArgs e) {
2800 toInvoke.OnPaint(e);
2803 protected void InvokePaintBackground(Control toInvoke, PaintEventArgs e) {
2804 toInvoke.OnPaintBackground(e);
2807 protected virtual bool IsInputChar (char charCode) {
2808 if (parent != null) {
2809 return parent.IsInputChar(charCode);
2815 protected virtual bool IsInputKey (Keys keyData) {
2816 // Doc says this one calls IsInputChar; not sure what to do with that
2820 [EditorBrowsable(EditorBrowsableState.Advanced)]
2821 protected virtual void NotifyInvalidate(Rectangle invalidatedArea) {
2825 protected virtual bool ProcessCmdKey(ref Message msg, Keys keyData) {
2826 if ((context_menu != null) && context_menu.ProcessCmdKey(ref msg, keyData)) {
2830 if (parent != null) {
2831 return parent.ProcessCmdKey(ref msg, keyData);
2837 protected virtual bool ProcessDialogChar(char charCode) {
2838 if (parent != null) {
2839 return parent.ProcessDialogChar (charCode);
2845 protected virtual bool ProcessDialogKey (Keys keyData) {
2846 if (parent != null) {
2847 return parent.ProcessDialogKey (keyData);
2853 protected virtual bool ProcessKeyEventArgs (ref Message msg)
2855 KeyEventArgs key_event;
2858 case (int)Msg.WM_KEYDOWN: {
2859 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
2860 OnKeyDown (key_event);
2861 return key_event.Handled;
2863 case (int)Msg.WM_KEYUP: {
2864 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
2865 OnKeyUp (key_event);
2866 return key_event.Handled;
2869 case (int)Msg.WM_CHAR: {
2870 KeyPressEventArgs key_press_event;
2872 key_press_event = new KeyPressEventArgs((char)msg.WParam);
2873 OnKeyPress(key_press_event);
2874 return key_press_event.Handled;
2885 protected internal virtual bool ProcessKeyMessage(ref Message msg) {
2886 if (parent != null) {
2887 if (parent.ProcessKeyPreview(ref msg)) {
2895 protected virtual bool ProcessKeyPreview(ref Message msg) {
2896 if (parent != null) {
2897 return parent.ProcessKeyPreview(ref msg);
2903 protected virtual bool ProcessMnemonic(char charCode) {
2908 [EditorBrowsable(EditorBrowsableState.Advanced)]
2909 protected void RaiseDragEvent(object key, DragEventArgs e) {
2913 [EditorBrowsable(EditorBrowsableState.Advanced)]
2914 protected void RaiseKeyEvent(object key, KeyEventArgs e) {
2918 [EditorBrowsable(EditorBrowsableState.Advanced)]
2919 protected void RaiseMouseEvent(object key, MouseEventArgs e) {
2923 [EditorBrowsable(EditorBrowsableState.Advanced)]
2924 protected void RaisePaintEvent(object key, PaintEventArgs e) {
2928 [EditorBrowsable(EditorBrowsableState.Advanced)]
2929 protected void RecreateHandle() {
2930 IEnumerator child = child_controls.GetEnumerator();
2934 if (IsHandleCreated) {
2940 while (child.MoveNext()) {
2941 ((Control)child.Current).RecreateHandle();
2947 is_recreating = false;
2950 [EditorBrowsable(EditorBrowsableState.Advanced)]
2951 protected void ResetMouseEventArgs() {
2955 [EditorBrowsable(EditorBrowsableState.Advanced)]
2956 protected ContentAlignment RtlTranslateAlignment(ContentAlignment align) {
2957 if (right_to_left == RightToLeft.No) {
2962 case ContentAlignment.TopLeft: {
2963 return ContentAlignment.TopRight;
2966 case ContentAlignment.TopRight: {
2967 return ContentAlignment.TopLeft;
2970 case ContentAlignment.MiddleLeft: {
2971 return ContentAlignment.MiddleRight;
2974 case ContentAlignment.MiddleRight: {
2975 return ContentAlignment.MiddleLeft;
2978 case ContentAlignment.BottomLeft: {
2979 return ContentAlignment.BottomRight;
2982 case ContentAlignment.BottomRight: {
2983 return ContentAlignment.BottomLeft;
2987 // if it's center it doesn't change
2993 [EditorBrowsable(EditorBrowsableState.Advanced)]
2994 protected HorizontalAlignment RtlTranslateAlignment(HorizontalAlignment align) {
2995 if ((right_to_left == RightToLeft.No) || (align == HorizontalAlignment.Center)) {
2999 if (align == HorizontalAlignment.Left) {
3000 return HorizontalAlignment.Right;
3003 // align must be HorizontalAlignment.Right
3004 return HorizontalAlignment.Left;
3007 [EditorBrowsable(EditorBrowsableState.Advanced)]
3008 protected LeftRightAlignment RtlTranslateAlignment(LeftRightAlignment align) {
3009 if (right_to_left == RightToLeft.No) {
3013 if (align == LeftRightAlignment.Left) {
3014 return LeftRightAlignment.Right;
3017 // align must be LeftRightAlignment.Right;
3018 return LeftRightAlignment.Left;
3021 [EditorBrowsable(EditorBrowsableState.Advanced)]
3022 protected ContentAlignment RtlTranslateContent(ContentAlignment align) {
3023 return RtlTranslateAlignment(align);
3026 [EditorBrowsable(EditorBrowsableState.Advanced)]
3027 protected HorizontalAlignment RtlTranslateHorizontal(HorizontalAlignment align) {
3028 return RtlTranslateAlignment(align);
3031 [EditorBrowsable(EditorBrowsableState.Advanced)]
3032 protected LeftRightAlignment RtlTranslateLeftRight(LeftRightAlignment align) {
3033 return RtlTranslateAlignment(align);
3036 [EditorBrowsable(EditorBrowsableState.Advanced)]
3037 protected virtual void ScaleCore(float dx, float dy) {
3043 location = new Point((int)(Left * dx), (int)(Top * dy));
3044 size = this.ClientSize;
3047 if (!GetStyle(ControlStyles.FixedWidth)) {
3048 size.Width = (int)(size.Width * dx);
3051 if (!GetStyle(ControlStyles.FixedHeight)) {
3052 size.Height = (int)(size.Height * dy);
3055 Location = location;
3058 /* Now scale our children */
3059 for (int i=0; i < child_controls.Count; i++) {
3060 child_controls[i].Scale(dx, dy);
3066 protected virtual void Select(bool directed, bool forward) {
3071 // Select this control
3076 if (parent == null) {
3080 // FIXME - this thing is doing the wrong stuff, needs to be similar to SelectNextControl
3082 index = parent.child_controls.IndexOf(this);
3087 if ((index+1) < parent.child_controls.Count) {
3096 index = parent.child_controls.Count-1;
3099 result = Select(parent.child_controls[index]);
3100 } while (!result && parent.child_controls[index] != this);
3103 [EditorBrowsable(EditorBrowsableState.Advanced)]
3104 protected virtual void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
3105 // SetBoundsCore updates the Win32 control itself. UpdateBounds updates the controls variables and fires events, I'm guessing - pdb
3106 if ((specified & BoundsSpecified.X) != BoundsSpecified.X) {
3110 if ((specified & BoundsSpecified.Y) != BoundsSpecified.Y) {
3114 if ((specified & BoundsSpecified.Width) != BoundsSpecified.Width) {
3118 if ((specified & BoundsSpecified.Height) != BoundsSpecified.Height) {
3122 if (IsHandleCreated) {
3123 XplatUI.SetWindowPos(Handle, x, y, width, height);
3125 UpdateBounds(x, y, width, height);
3128 [EditorBrowsable(EditorBrowsableState.Advanced)]
3129 protected virtual void SetClientSizeCore(int x, int y) {
3130 // Calculate the actual window size from the client size (it usually stays the same or grows)
3131 Rectangle ClientRect;
3132 Rectangle WindowRect;
3135 ClientRect = new Rectangle(0, 0, x, y);
3136 cp = this.CreateParams;
3138 if (XplatUI.CalculateWindowRect(Handle, ref ClientRect, cp.Style, cp.ExStyle, IntPtr.Zero, out WindowRect)==false) {
3142 SetBoundsCore(bounds.X, bounds.Y, WindowRect.Width, WindowRect.Height, BoundsSpecified.Size);
3145 [EditorBrowsable(EditorBrowsableState.Advanced)]
3146 protected void SetStyle(ControlStyles flag, bool value) {
3148 control_style |= flag;
3150 control_style &= ~flag;
3152 OnStyleChanged(EventArgs.Empty);
3155 protected void SetTopLevel(bool value) {
3156 if ((GetTopLevel() != value) && (parent != null)) {
3157 throw new Exception();
3161 if (value == true) {
3171 is_toplevel = value;
3174 protected virtual void SetVisibleCore(bool value) {
3175 if (value!=is_visible) {
3177 XplatUI.SetVisible(Handle, value);
3178 // Explicitly move Toplevel windows to where we want them;
3179 // apparently moving unmapped toplevel windows doesn't work
3180 if (is_visible && (this is Form)) {
3181 XplatUI.SetWindowPos(window.Handle, bounds.X, bounds.Y, bounds.Width, bounds.Height);
3183 OnVisibleChanged(EventArgs.Empty);
3186 if (dc_mem != null) {
3191 if (bmp_mem != null) {
3196 this.CreateBuffers(bounds.Width, bounds.Height);
3201 if (value == false && parent != null) {
3204 // Need to start at parent, GetContainerControl might return ourselves if we're a container
3205 container = (Control)parent.GetContainerControl();
3206 if (container != null) {
3207 container.SelectNextControl(this, true, true, true, true);
3211 if (parent != null) {
3212 parent.PerformLayout(this, "visible");
3214 PerformLayout(this, "visible");
3219 [EditorBrowsable(EditorBrowsableState.Advanced)]
3220 protected void UpdateBounds() {
3228 if (!IsHandleCreated) {
3232 XplatUI.GetWindowPos(this.Handle, this is Form, out x, out y, out width, out height, out client_width, out client_height);
3234 UpdateBounds(x, y, width, height, client_width, client_height);
3237 [EditorBrowsable(EditorBrowsableState.Advanced)]
3238 protected void UpdateBounds(int x, int y, int width, int height) {
3239 // UpdateBounds only seems to set our sizes and fire events but not update the GUI window to match
3241 bool resized = false;
3243 int client_x_diff = this.bounds.Width-this.client_size.Width;
3244 int client_y_diff = this.bounds.Height-this.client_size.Height;
3246 // Needed to generate required notifications
3247 if ((this.bounds.X!=x) || (this.bounds.Y!=y)) {
3251 if ((this.Bounds.Width!=width) || (this.Bounds.Height!=height)) {
3258 bounds.Height=height;
3260 // Update client rectangle as well
3261 if (this.layout_suspended==0) {
3262 prev_size.Width=client_size.Width;
3263 prev_size.Height=client_size.Height;
3266 client_size.Width=width-client_x_diff;
3267 client_size.Height=height-client_y_diff;
3270 OnLocationChanged(EventArgs.Empty);
3274 OnSizeChanged(EventArgs.Empty);
3278 [EditorBrowsable(EditorBrowsableState.Advanced)]
3279 protected void UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) {
3280 UpdateBounds(x, y, width, height);
3282 this.client_size.Width=clientWidth;
3283 this.client_size.Height=clientHeight;
3286 [EditorBrowsable(EditorBrowsableState.Advanced)]
3287 protected void UpdateStyles() {
3288 if (!IsHandleCreated) {
3292 XplatUI.SetWindowStyle(window.Handle, CreateParams);
3295 [EditorBrowsable(EditorBrowsableState.Advanced)]
3296 protected void UpdateZOrder() {
3301 if (parent == null) {
3307 children = ctl.child_controls.Count;
3308 for (int i = 1; i < children; i++ ) {
3309 XplatUI.SetZOrder(ctl.child_controls[i].window.Handle, ctl.child_controls[i-1].window.Handle, false, false);
3312 children = child_controls.Count;
3313 for (int i = 1; i < children; i++ ) {
3314 XplatUI.SetZOrder(child_controls[i].Handle, child_controls[i-1].Handle, false, false);
3319 protected virtual void WndProc(ref Message m) {
3321 Console.WriteLine("Control received message {0}", (Msg)m.Msg);
3323 if ((this.control_style & ControlStyles.EnableNotifyMessage) != 0) {
3327 switch((Msg)m.Msg) {
3328 case Msg.WM_WINDOWPOSCHANGED: {
3331 if (GetStyle(ControlStyles.ResizeRedraw)) {
3338 case Msg.WM_PAINT: {
3339 PaintEventArgs paint_event;
3341 paint_event = XplatUI.PaintEventStart(Handle, true);
3343 if (!needs_redraw) {
3344 // Just blit the previous image
3345 paint_event.Graphics.DrawImage (ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle, GraphicsUnit.Pixel);
3346 XplatUI.PaintEventEnd(Handle, true);
3351 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
3352 dc = paint_event.SetGraphics (DeviceContext);
3355 if ((control_style & (ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint)) != (ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint)) {
3356 OnPaintBackground(paint_event);
3359 OnPaint(paint_event);
3361 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
3362 dc.DrawImage (ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle, GraphicsUnit.Pixel);
3363 paint_event.SetGraphics (dc);
3364 needs_redraw = false;
3367 XplatUI.PaintEventEnd(Handle, true);
3369 if (!GetStyle(ControlStyles.UserPaint)) {
3376 case Msg.WM_ERASEBKGND: {
3377 if (GetStyle (ControlStyles.UserPaint)) {
3378 if (!GetStyle(ControlStyles.AllPaintingInWmPaint)) {
3379 PaintEventArgs eraseEventArgs = new PaintEventArgs (m.WParam == IntPtr.Zero ? Graphics.FromHwnd (m.HWnd) :
3380 Graphics.FromHdc (m.WParam), new Rectangle (new Point (0,0),Size));
3381 OnPaintBackground (eraseEventArgs);
3384 XplatUI.EraseWindowBackground(m.HWnd, m.WParam);
3386 // The DefWndProc will never have to handle this, we don't ever set hbr on the window
3387 m.Result = (IntPtr)1;
3391 case Msg.WM_LBUTTONUP: {
3392 HandleClick(mouse_clicks);
3393 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Left,
3395 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3397 if (mouse_clicks > 1) {
3403 case Msg.WM_LBUTTONDOWN: {
3404 if (CanSelect && !is_selected) {
3407 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3408 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3414 case Msg.WM_LBUTTONDBLCLK: {
3416 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3417 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3423 case Msg.WM_MBUTTONUP: {
3424 HandleClick(mouse_clicks);
3425 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Middle,
3427 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3429 if (mouse_clicks > 1) {
3435 case Msg.WM_MBUTTONDOWN: {
3436 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3437 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3443 case Msg.WM_MBUTTONDBLCLK: {
3445 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3446 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3451 case Msg.WM_RBUTTONUP: {
3452 if (context_menu != null) {
3453 context_menu.Show(this, new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ())));
3456 HandleClick(mouse_clicks);
3457 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Right,
3459 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3461 if (mouse_clicks > 1) {
3467 case Msg.WM_RBUTTONDOWN: {
3468 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3469 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3474 case Msg.WM_RBUTTONDBLCLK: {
3476 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3477 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3482 case Msg.WM_MOUSEWHEEL: {
3484 OnMouseWheel (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3485 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3486 HighOrder(m.WParam.ToInt32())));
3491 case Msg.WM_MOUSEMOVE: {
3492 OnMouseMove (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3494 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3499 case Msg.WM_MOUSE_ENTER: {
3504 OnMouseEnter(EventArgs.Empty);
3508 case Msg.WM_MOUSE_LEAVE: {
3510 OnMouseLeave(EventArgs.Empty);
3514 case Msg.WM_MOUSEHOVER: {
3515 OnMouseHover(EventArgs.Empty);
3519 case Msg.WM_SYSKEYDOWN:
3520 case Msg.WM_KEYDOWN:
3521 case Msg.WM_SYSKEYUP:
3523 case Msg.WM_SYSCHAR:
3525 if (ProcessKeyEventArgs(ref m)) {
3529 if (PreProcessMessage(ref m)) {
3533 if (ProcessKeyMessage(ref m)) {
3542 if (m.LParam != IntPtr.Zero) {
3545 hi = new HELPINFO();
3547 hi = (HELPINFO) Marshal.PtrToStructure (m.LParam, typeof (HELPINFO));
3548 mouse_pos = new Point(hi.MousePos.x, hi.MousePos.y);
3550 mouse_pos = Control.MousePosition;
3552 OnHelpRequested(new HelpEventArgs(mouse_pos));
3553 m.Result = (IntPtr)1;
3557 case Msg.WM_KILLFOCUS: {
3558 OnLeave(EventArgs.Empty);
3559 if (CausesValidation) {
3561 e = new CancelEventArgs(false);
3570 OnValidated(EventArgs.Empty);
3573 this.has_focus = false;
3574 this.is_selected = false;
3575 OnLostFocus(EventArgs.Empty);
3579 case Msg.WM_SETFOCUS: {
3580 OnEnter(EventArgs.Empty);
3581 this.has_focus = true;
3582 OnGotFocus(EventArgs.Empty);
3587 case Msg.WM_SYSCOLORCHANGE: {
3588 ThemeEngine.Current.ResetDefaults();
3589 OnSystemColorsChanged(EventArgs.Empty);
3594 case Msg.WM_SETCURSOR: {
3595 if (cursor == null) {
3600 XplatUI.SetCursor(window.Handle, cursor.handle);
3601 m.Result = (IntPtr)1;
3612 #endregion // Public Instance Methods
3614 #region OnXXX methods
3615 [EditorBrowsable(EditorBrowsableState.Advanced)]
3616 protected virtual void OnBackColorChanged(EventArgs e) {
3617 if (BackColorChanged!=null) BackColorChanged(this, e);
3618 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackColorChanged(e);
3621 [EditorBrowsable(EditorBrowsableState.Advanced)]
3622 protected virtual void OnBackgroundImageChanged(EventArgs e) {
3623 if (BackgroundImageChanged!=null) BackgroundImageChanged(this, e);
3624 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackgroundImageChanged(e);
3627 [EditorBrowsable(EditorBrowsableState.Advanced)]
3628 protected virtual void OnBindingContextChanged(EventArgs e) {
3629 CheckDataBindings ();
3630 if (BindingContextChanged!=null) {
3631 BindingContextChanged(this, e);
3633 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBindingContextChanged(e);
3636 [EditorBrowsable(EditorBrowsableState.Advanced)]
3637 protected virtual void OnCausesValidationChanged(EventArgs e) {
3638 if (CausesValidationChanged!=null) CausesValidationChanged(this, e);
3641 [EditorBrowsable(EditorBrowsableState.Advanced)]
3642 protected virtual void OnChangeUICues(UICuesEventArgs e) {
3643 if (ChangeUICues!=null) ChangeUICues(this, e);
3646 [EditorBrowsable(EditorBrowsableState.Advanced)]
3647 protected virtual void OnClick(EventArgs e) {
3648 if (Click!=null) Click(this, e);
3651 [EditorBrowsable(EditorBrowsableState.Advanced)]
3652 protected virtual void OnContextMenuChanged(EventArgs e) {
3653 if (ContextMenuChanged!=null) ContextMenuChanged(this, e);
3656 [EditorBrowsable(EditorBrowsableState.Advanced)]
3657 protected virtual void OnControlAdded(ControlEventArgs e) {
3658 if (ControlAdded!=null) ControlAdded(this, e);
3661 [EditorBrowsable(EditorBrowsableState.Advanced)]
3662 protected virtual void OnControlRemoved(ControlEventArgs e) {
3663 if (ControlRemoved!=null) ControlRemoved(this, e);
3666 [EditorBrowsable(EditorBrowsableState.Advanced)]
3667 protected virtual void OnCreateControl() {
3671 [EditorBrowsable(EditorBrowsableState.Advanced)]
3672 protected virtual void OnCursorChanged(EventArgs e) {
3673 if (CursorChanged!=null) CursorChanged(this, e);
3676 [EditorBrowsable(EditorBrowsableState.Advanced)]
3677 protected virtual void OnDockChanged(EventArgs e) {
3678 if (DockChanged!=null) DockChanged(this, e);
3681 [EditorBrowsable(EditorBrowsableState.Advanced)]
3682 protected virtual void OnDoubleClick(EventArgs e) {
3683 if (DoubleClick!=null) DoubleClick(this, e);
3686 [EditorBrowsable(EditorBrowsableState.Advanced)]
3687 protected virtual void OnDragDrop(DragEventArgs drgevent) {
3688 if (DragDrop!=null) DragDrop(this, drgevent);
3691 [EditorBrowsable(EditorBrowsableState.Advanced)]
3692 protected virtual void OnDragEnter(DragEventArgs drgevent) {
3693 if (DragEnter!=null) DragEnter(this, drgevent);
3696 [EditorBrowsable(EditorBrowsableState.Advanced)]
3697 protected virtual void OnDragLeave(EventArgs e) {
3698 if (DragLeave!=null) DragLeave(this, e);
3701 [EditorBrowsable(EditorBrowsableState.Advanced)]
3702 protected virtual void OnDragOver(DragEventArgs drgevent) {
3703 if (DragOver!=null) DragOver(this, drgevent);
3706 [EditorBrowsable(EditorBrowsableState.Advanced)]
3707 protected virtual void OnEnabledChanged(EventArgs e) {
3708 if (EnabledChanged!=null) EnabledChanged(this, e);
3709 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentEnabledChanged(e);
3712 [EditorBrowsable(EditorBrowsableState.Advanced)]
3713 protected virtual void OnEnter(EventArgs e) {
3714 if (Enter!=null) Enter(this, e);
3717 [EditorBrowsable(EditorBrowsableState.Advanced)]
3718 protected virtual void OnFontChanged(EventArgs e) {
3719 if (FontChanged!=null) FontChanged(this, e);
3720 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentFontChanged(e);
3723 [EditorBrowsable(EditorBrowsableState.Advanced)]
3724 protected virtual void OnForeColorChanged(EventArgs e) {
3725 if (ForeColorChanged!=null) ForeColorChanged(this, e);
3726 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentForeColorChanged(e);
3729 [EditorBrowsable(EditorBrowsableState.Advanced)]
3730 protected virtual void OnGiveFeedback(GiveFeedbackEventArgs gfbevent) {
3731 if (GiveFeedback!=null) GiveFeedback(this, gfbevent);
3734 [EditorBrowsable(EditorBrowsableState.Advanced)]
3735 protected virtual void OnGotFocus(EventArgs e) {
3736 if (GotFocus!=null) GotFocus(this, e);
3739 [EditorBrowsable(EditorBrowsableState.Advanced)]
3740 protected virtual void OnHandleCreated(EventArgs e) {
3741 if (HandleCreated!=null) HandleCreated(this, e);
3744 [EditorBrowsable(EditorBrowsableState.Advanced)]
3745 protected virtual void OnHandleDestroyed(EventArgs e) {
3746 if (HandleDestroyed!=null) HandleDestroyed(this, e);
3749 [EditorBrowsable(EditorBrowsableState.Advanced)]
3750 protected virtual void OnHelpRequested(HelpEventArgs hevent) {
3751 if (HelpRequested!=null) HelpRequested(this, hevent);
3754 protected virtual void OnImeModeChanged(EventArgs e) {
3755 if (ImeModeChanged!=null) ImeModeChanged(this, e);
3758 [EditorBrowsable(EditorBrowsableState.Advanced)]
3759 protected virtual void OnInvalidated(InvalidateEventArgs e) {
3760 needs_redraw = true;
3761 if (Invalidated!=null) Invalidated(this, e);
3764 [EditorBrowsable(EditorBrowsableState.Advanced)]
3765 protected virtual void OnKeyDown(KeyEventArgs e) {
3766 if (KeyDown!=null) KeyDown(this, e);
3769 [EditorBrowsable(EditorBrowsableState.Advanced)]
3770 protected virtual void OnKeyPress(KeyPressEventArgs e) {
3771 if (KeyPress!=null) KeyPress(this, e);
3774 [EditorBrowsable(EditorBrowsableState.Advanced)]
3775 protected virtual void OnKeyUp(KeyEventArgs e) {
3776 if (KeyUp!=null) KeyUp(this, e);
3779 [EditorBrowsable(EditorBrowsableState.Advanced)]
3780 protected virtual void OnLayout(LayoutEventArgs levent) {
3781 if (Layout!=null) Layout(this, levent);
3784 [EditorBrowsable(EditorBrowsableState.Advanced)]
3785 protected virtual void OnLeave(EventArgs e) {
3786 if (Leave!=null) Leave(this, e);
3789 [EditorBrowsable(EditorBrowsableState.Advanced)]
3790 protected virtual void OnLocationChanged(EventArgs e) {
3792 if (LocationChanged!=null) LocationChanged(this, e);
3795 [EditorBrowsable(EditorBrowsableState.Advanced)]
3796 protected virtual void OnLostFocus(EventArgs e) {
3797 if (LostFocus!=null) LostFocus(this, e);
3800 [EditorBrowsable(EditorBrowsableState.Advanced)]
3801 protected virtual void OnMouseDown(MouseEventArgs e) {
3802 if (MouseDown!=null) MouseDown(this, e);
3805 [EditorBrowsable(EditorBrowsableState.Advanced)]
3806 protected virtual void OnMouseEnter(EventArgs e) {
3807 if (MouseEnter!=null) MouseEnter(this, e);
3810 [EditorBrowsable(EditorBrowsableState.Advanced)]
3811 protected virtual void OnMouseHover(EventArgs e) {
3812 if (MouseHover!=null) MouseHover(this, e);
3815 [EditorBrowsable(EditorBrowsableState.Advanced)]
3816 protected virtual void OnMouseLeave(EventArgs e) {
3817 if (MouseLeave!=null) MouseLeave(this, e);
3820 [EditorBrowsable(EditorBrowsableState.Advanced)]
3821 protected virtual void OnMouseMove(MouseEventArgs e) {
3822 if (MouseMove!=null) MouseMove(this, e);
3825 [EditorBrowsable(EditorBrowsableState.Advanced)]
3826 protected virtual void OnMouseUp(MouseEventArgs e) {
3827 if (MouseUp!=null) MouseUp(this, e);
3830 [EditorBrowsable(EditorBrowsableState.Advanced)]
3831 protected virtual void OnMouseWheel(MouseEventArgs e) {
3832 if (MouseWheel!=null) MouseWheel(this, e);
3835 [EditorBrowsable(EditorBrowsableState.Advanced)]
3836 protected virtual void OnMove(EventArgs e) {
3837 if (Move!=null) Move(this, e);
3840 [EditorBrowsable(EditorBrowsableState.Advanced)]
3841 protected virtual void OnNotifyMessage(Message m) {
3845 [EditorBrowsable(EditorBrowsableState.Advanced)]
3846 protected virtual void OnPaint(PaintEventArgs e) {
3847 if (Paint!=null) Paint(this, e);
3850 [EditorBrowsable(EditorBrowsableState.Advanced)]
3851 protected virtual void OnPaintBackground(PaintEventArgs pevent) {
3852 PaintControlBackground (pevent);
3855 [EditorBrowsable(EditorBrowsableState.Advanced)]
3856 protected virtual void OnParentBackColorChanged(EventArgs e) {
3857 if (background_color.IsEmpty && background_image==null) {
3859 OnBackColorChanged(e);
3863 [EditorBrowsable(EditorBrowsableState.Advanced)]
3864 protected virtual void OnParentBackgroundImageChanged(EventArgs e) {
3865 if (background_color.IsEmpty && background_image==null) {
3867 OnBackgroundImageChanged(e);
3871 [EditorBrowsable(EditorBrowsableState.Advanced)]
3872 protected virtual void OnParentBindingContextChanged(EventArgs e) {
3873 if (binding_context==null) {
3874 binding_context=Parent.binding_context;
3875 OnBindingContextChanged(e);
3879 [EditorBrowsable(EditorBrowsableState.Advanced)]
3880 protected virtual void OnParentChanged(EventArgs e) {
3881 if (ParentChanged!=null) ParentChanged(this, e);
3884 [EditorBrowsable(EditorBrowsableState.Advanced)]
3885 protected virtual void OnParentEnabledChanged(EventArgs e) {
3886 if (is_enabled != Parent.is_enabled) {
3887 is_enabled=Parent.is_enabled;
3889 if (EnabledChanged != null) {
3890 EnabledChanged(this, e);
3895 [EditorBrowsable(EditorBrowsableState.Advanced)]
3896 protected virtual void OnParentFontChanged(EventArgs e) {
3903 [EditorBrowsable(EditorBrowsableState.Advanced)]
3904 protected virtual void OnParentForeColorChanged(EventArgs e) {
3905 if (foreground_color.IsEmpty) {
3907 OnForeColorChanged(e);
3911 [EditorBrowsable(EditorBrowsableState.Advanced)]
3912 protected virtual void OnParentRightToLeftChanged(EventArgs e) {
3913 if (right_to_left==RightToLeft.Inherit) {
3915 OnRightToLeftChanged(e);
3919 [EditorBrowsable(EditorBrowsableState.Advanced)]
3920 protected virtual void OnParentVisibleChanged(EventArgs e) {
3922 OnVisibleChanged(e);
3926 [EditorBrowsable(EditorBrowsableState.Advanced)]
3927 protected virtual void OnQueryContinueDrag(QueryContinueDragEventArgs e) {
3928 if (QueryContinueDrag!=null) QueryContinueDrag(this, e);
3931 [EditorBrowsable(EditorBrowsableState.Advanced)]
3932 protected virtual void OnResize(EventArgs e) {
3933 if (Resize!=null) Resize(this, e);
3935 PerformLayout(this, "bounds");
3937 if (parent != null) {
3938 parent.PerformLayout();
3942 [EditorBrowsable(EditorBrowsableState.Advanced)]
3943 protected virtual void OnRightToLeftChanged(EventArgs e) {
3944 if (RightToLeftChanged!=null) RightToLeftChanged(this, e);
3945 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentRightToLeftChanged(e);
3948 [EditorBrowsable(EditorBrowsableState.Advanced)]
3949 protected virtual void OnSizeChanged(EventArgs e) {
3950 InvalidateBuffers ();
3952 if (SizeChanged!=null) SizeChanged(this, e);
3955 [EditorBrowsable(EditorBrowsableState.Advanced)]
3956 protected virtual void OnStyleChanged(EventArgs e) {
3957 if (StyleChanged!=null) StyleChanged(this, e);
3960 [EditorBrowsable(EditorBrowsableState.Advanced)]
3961 protected virtual void OnSystemColorsChanged(EventArgs e) {
3962 if (SystemColorsChanged!=null) SystemColorsChanged(this, e);
3965 [EditorBrowsable(EditorBrowsableState.Advanced)]
3966 protected virtual void OnTabIndexChanged(EventArgs e) {
3967 if (TabIndexChanged!=null) TabIndexChanged(this, e);
3970 [EditorBrowsable(EditorBrowsableState.Advanced)]
3971 protected virtual void OnTabStopChanged(EventArgs e) {
3972 if (TabStopChanged!=null) TabStopChanged(this, e);
3975 [EditorBrowsable(EditorBrowsableState.Advanced)]
3976 protected virtual void OnTextChanged(EventArgs e) {
3977 if (TextChanged!=null) TextChanged(this, e);
3980 [EditorBrowsable(EditorBrowsableState.Advanced)]
3981 protected virtual void OnValidated(EventArgs e) {
3982 if (Validated!=null) Validated(this, e);
3985 [EditorBrowsable(EditorBrowsableState.Advanced)]
3986 protected virtual void OnValidating(System.ComponentModel.CancelEventArgs e) {
3987 if (Validating!=null) Validating(this, e);
3990 [EditorBrowsable(EditorBrowsableState.Advanced)]
3991 protected virtual void OnVisibleChanged(EventArgs e) {
3998 if (bmp_mem!=null) {
4004 if (!this.IsHandleCreated) {
4005 this.CreateControl();
4011 if (VisibleChanged!=null) VisibleChanged(this, e);
4013 // We need to tell our kids
4014 for (int i=0; i<child_controls.Count; i++) {
4015 child_controls[i].OnParentVisibleChanged(e);
4018 #endregion // OnXXX methods
4021 public event EventHandler BackColorChanged;
4022 public event EventHandler BackgroundImageChanged;
4023 public event EventHandler BindingContextChanged;
4024 public event EventHandler CausesValidationChanged;
4025 public event UICuesEventHandler ChangeUICues;
4026 public event EventHandler Click;
4027 public event EventHandler ContextMenuChanged;
4029 [EditorBrowsable(EditorBrowsableState.Advanced)]
4031 public event ControlEventHandler ControlAdded;
4033 [EditorBrowsable(EditorBrowsableState.Advanced)]
4035 public event ControlEventHandler ControlRemoved;
4037 [MWFDescription("Fired when the cursor for the control has been changed"), MWFCategory("PropertyChanged")]
4038 public event EventHandler CursorChanged;
4039 public event EventHandler DockChanged;
4040 public event EventHandler DoubleClick;
4041 public event DragEventHandler DragDrop;
4042 public event DragEventHandler DragEnter;
4043 public event EventHandler DragLeave;
4044 public event DragEventHandler DragOver;
4045 public event EventHandler EnabledChanged;
4046 public event EventHandler Enter;
4047 public event EventHandler FontChanged;
4048 public event EventHandler ForeColorChanged;
4049 public event GiveFeedbackEventHandler GiveFeedback;
4051 [EditorBrowsable(EditorBrowsableState.Advanced)]
4053 public event EventHandler GotFocus;
4055 [EditorBrowsable(EditorBrowsableState.Advanced)]
4057 public event EventHandler HandleCreated;
4059 [EditorBrowsable(EditorBrowsableState.Advanced)]
4061 public event EventHandler HandleDestroyed;
4063 public event HelpEventHandler HelpRequested;
4064 public event EventHandler ImeModeChanged;
4066 [EditorBrowsable(EditorBrowsableState.Advanced)]
4068 public event InvalidateEventHandler Invalidated;
4070 public event KeyEventHandler KeyDown;
4071 public event KeyPressEventHandler KeyPress;
4072 public event KeyEventHandler KeyUp;
4073 public event LayoutEventHandler Layout;
4074 public event EventHandler Leave;
4075 public event EventHandler LocationChanged;
4077 [EditorBrowsable(EditorBrowsableState.Advanced)]
4079 public event EventHandler LostFocus;
4081 public event MouseEventHandler MouseDown;
4082 public event EventHandler MouseEnter;
4083 public event EventHandler MouseHover;
4084 public event EventHandler MouseLeave;
4085 public event MouseEventHandler MouseMove;
4086 public event MouseEventHandler MouseUp;
4088 [EditorBrowsable(EditorBrowsableState.Advanced)]
4090 public event MouseEventHandler MouseWheel;
4092 public event EventHandler Move;
4093 public event PaintEventHandler Paint;
4094 public event EventHandler ParentChanged;
4095 public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp;
4096 public event QueryContinueDragEventHandler QueryContinueDrag;
4097 public event EventHandler Resize;
4098 public event EventHandler RightToLeftChanged;
4099 public event EventHandler SizeChanged;
4100 public event EventHandler StyleChanged;
4101 public event EventHandler SystemColorsChanged;
4102 public event EventHandler TabIndexChanged;
4103 public event EventHandler TabStopChanged;
4104 public event EventHandler TextChanged;
4105 public event EventHandler Validated;
4106 public event CancelEventHandler Validating;
4107 public event EventHandler VisibleChanged;
4108 #endregion // Events