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 if (!child.GetStyle (ControlStyles.UserPaint)) {
732 XplatUI.SetWindowBackground(child.window.Handle, child.BackColor);
735 if (child.child_controls.Count>0) {
736 SetChildColor(child);
742 internal bool Select(Control control) {
744 IContainerControl container;
746 if (control == null) {
750 parent = control.parent;
752 if (((control.control_style & ControlStyles.Selectable) !=0) && (parent != null)) {
753 while (parent != null) {
754 if (!parent.Visible || !parent.is_enabled) {
757 parent = parent.parent;
761 control.is_selected = true;
763 container = GetContainerControl();
764 if (container != null) {
765 container.ActiveControl = control;
767 if (control.IsHandleCreated) {
768 XplatUI.SetFocus(control.window.Handle);
773 internal virtual void DoDefaultAction() {
774 // Only here to be overriden by our actual controls; this is needed by the accessibility class
777 internal static int LowOrder (int param) {
778 return ((int)(short)(param & 0xffff));
781 internal static int HighOrder (int param) {
782 return ((int)(short)(param >> 16));
785 // This method exists so controls overriding OnPaintBackground can have default background painting done
786 internal void PaintControlBackground (PaintEventArgs pevent)
788 if (background_image == null)
791 DrawBackgroundImage (pevent.Graphics);
794 void DrawBackgroundImage (Graphics g)
796 using (TextureBrush b = new TextureBrush (background_image)) {
797 g.FillRectangle (b, ClientRectangle);
801 internal void DndEnter (DragEventArgs e)
806 internal void DndOver (DragEventArgs e)
811 internal void DndDrop (DragEventArgs e)
816 internal void DndLeave (EventArgs e)
821 internal void DnDFeedback(GiveFeedbackEventArgs e)
826 internal void DnDContinueDrag(QueryContinueDragEventArgs e) {
827 OnQueryContinueDrag(e);
830 internal static MouseButtons FromParamToMouseButtons (int param) {
831 MouseButtons buttons = MouseButtons.None;
833 if ((param & (int) MsgButtons.MK_LBUTTON) != 0)
834 buttons |= MouseButtons.Left;
836 if ((param & (int) MsgButtons.MK_MBUTTON) != 0)
837 buttons |= MouseButtons.Middle;
839 if ((param & (int) MsgButtons.MK_RBUTTON) != 0)
840 buttons |= MouseButtons.Right;
846 internal virtual bool ProcessControlMnemonic(char charCode) {
847 return ProcessMnemonic(charCode);
850 private static Control FindFlatForward(Control container, Control start) {
856 end = container.child_controls.Count;
859 index = start.tab_index;
864 for (int i = 0; i < end; i++) {
866 if (container.child_controls[i].tab_index > index) {
867 found = container.child_controls[i];
869 } else if (found.tab_index > container.child_controls[i].tab_index) {
870 if (container.child_controls[i].tab_index > index) {
871 found = container.child_controls[i];
878 private static Control FindControlForward(Control container, Control start) {
885 if ((start is IContainerControl) || start.GetStyle(ControlStyles.ContainerControl)) {
886 found = FindControlForward(start, null);
893 while (p != container) {
894 found = FindFlatForward(p, start);
902 return FindFlatForward(container, start);
905 private static Control FindFlatBackward(Control container, Control start) {
911 end = container.child_controls.Count;
914 index = start.tab_index;
916 // FIXME: Possible speed-up: Keep the highest taborder index in the container
918 for (int i = 0; i < end; i++) {
919 if (container.child_controls[i].tab_index > index) {
920 index = container.child_controls[i].tab_index;
926 for (int i = 0; i < end; i++) {
928 if (container.child_controls[i].tab_index < index) {
929 found = container.child_controls[i];
931 } else if (found.tab_index < container.child_controls[i].tab_index) {
932 if (container.child_controls[i].tab_index < index) {
933 found = container.child_controls[i];
940 private static Control FindControlBackward(Control container, Control start) {
946 found = FindFlatBackward(start.parent, start);
947 if (found == null && start.parent != container) {
952 found = FindFlatBackward(container, start);
955 while ((found != null) && ((found is IContainerControl) || found.GetStyle(ControlStyles.ContainerControl))) {
956 found = FindControlBackward(found, null);
965 private void HandleClick(int clicks) {
966 if (GetStyle(ControlStyles.StandardClick)) {
968 if (GetStyle(ControlStyles.StandardDoubleClick)) {
969 OnDoubleClick(EventArgs.Empty);
971 OnClick(EventArgs.Empty);
974 OnClick(EventArgs.Empty);
979 private void CheckDataBindings ()
981 if (data_bindings == null)
984 BindingContext binding_context = BindingContext;
985 foreach (Binding binding in data_bindings) {
986 binding.Check (binding_context);
990 #endregion // Private & Internal Methods
992 #region Public Static Properties
993 public static Color DefaultBackColor {
995 return ThemeEngine.Current.DefaultControlBackColor;
999 public static Font DefaultFont {
1001 return ThemeEngine.Current.DefaultFont;
1005 public static Color DefaultForeColor {
1007 return ThemeEngine.Current.DefaultControlForeColor;
1011 public static Keys ModifierKeys {
1013 return XplatUI.State.ModifierKeys;
1017 public static MouseButtons MouseButtons {
1019 return XplatUI.State.MouseButtons;
1023 public static Point MousePosition {
1025 return Cursor.Position;
1031 public static bool CheckForIllegalCrossThreadCalls
1040 #endregion // Public Static Properties
1042 #region Public Instance Properties
1043 [EditorBrowsable(EditorBrowsableState.Advanced)]
1045 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1046 public AccessibleObject AccessibilityObject {
1048 if (accessibility_object==null) {
1049 accessibility_object=CreateAccessibilityInstance();
1051 return accessibility_object;
1055 [EditorBrowsable(EditorBrowsableState.Advanced)]
1057 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1058 public string AccessibleDefaultActionDescription {
1060 return AccessibilityObject.default_action;
1064 AccessibilityObject.default_action=value;
1069 [DefaultValue(null)]
1070 public string AccessibleDescription {
1072 return AccessibilityObject.description;
1076 AccessibilityObject.description=value;
1081 [DefaultValue(null)]
1082 public string AccessibleName {
1084 return AccessibilityObject.Name;
1088 AccessibilityObject.Name=value;
1092 [DefaultValue(AccessibleRole.Default)]
1093 [MWFDescription("Role of the control"), MWFCategory("Accessibility")]
1094 public AccessibleRole AccessibleRole {
1096 return AccessibilityObject.role;
1100 AccessibilityObject.role=value;
1104 [DefaultValue(false)]
1105 public virtual bool AllowDrop {
1111 if (allow_drop == value)
1115 XplatUI.SetAllowDrop (Handle, value);
1120 [RefreshProperties(RefreshProperties.Repaint)]
1121 [DefaultValue(AnchorStyles.Top | AnchorStyles.Left)]
1122 public virtual AnchorStyles Anchor {
1124 return anchor_style;
1130 if (parent != null) {
1131 parent.PerformLayout(this, "Parent");
1137 public virtual Color BackColor {
1139 if (background_color.IsEmpty) {
1141 return parent.BackColor;
1143 return DefaultBackColor;
1145 return background_color;
1149 background_color=value;
1150 if (this.IsHandleCreated && !GetStyle (ControlStyles.UserPaint)) {
1151 XplatUI.SetWindowBackground(this.window.Handle, value);
1153 SetChildColor(this);
1154 OnBackColorChanged(EventArgs.Empty);
1160 [DefaultValue(null)]
1161 public virtual Image BackgroundImage {
1163 return background_image;
1167 if (background_image!=value) {
1168 background_image=value;
1169 OnBackgroundImageChanged(EventArgs.Empty);
1174 [EditorBrowsable(EditorBrowsableState.Advanced)]
1176 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1177 public virtual BindingContext BindingContext {
1179 if (binding_context != null)
1180 return binding_context;
1183 binding_context = Parent.BindingContext;
1184 return binding_context;
1187 if (binding_context != value) {
1188 binding_context = value;
1189 OnBindingContextChanged(EventArgs.Empty);
1194 [EditorBrowsable(EditorBrowsableState.Advanced)]
1196 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1199 return bounds.Y+bounds.Height;
1203 [EditorBrowsable(EditorBrowsableState.Advanced)]
1205 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1206 public Rectangle Bounds {
1212 SetBoundsCore(value.Left, value.Top, value.Width, value.Height, BoundsSpecified.All);
1216 [EditorBrowsable(EditorBrowsableState.Advanced)]
1218 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1219 public bool CanFocus {
1221 if (Visible && is_enabled && GetStyle(ControlStyles.Selectable)) {
1228 [EditorBrowsable(EditorBrowsableState.Advanced)]
1230 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1231 public bool CanSelect {
1235 if (!GetStyle(ControlStyles.Selectable) || this.parent == null) {
1239 parent = this.parent;
1240 while (parent != null) {
1241 if (!parent.is_visible || !parent.is_enabled) {
1245 parent = parent.parent;
1251 [EditorBrowsable(EditorBrowsableState.Advanced)]
1253 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1254 public bool Capture {
1256 return this.is_captured;
1260 if (this.IsHandleCreated) {
1261 if (value && !is_captured) {
1263 XplatUI.GrabWindow(this.window.Handle, IntPtr.Zero);
1264 } else if (!value && is_captured) {
1265 XplatUI.UngrabWindow(this.window.Handle);
1266 is_captured = false;
1272 [DefaultValue(true)]
1273 public bool CausesValidation {
1275 return this.causes_validation;
1279 if (this.causes_validation != value) {
1280 causes_validation = value;
1281 OnCausesValidationChanged(EventArgs.Empty);
1286 [EditorBrowsable(EditorBrowsableState.Advanced)]
1288 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1289 public Rectangle ClientRectangle {
1291 client_rect.Width = client_size.Width;
1292 client_rect.Height = client_size.Height;
1297 [EditorBrowsable(EditorBrowsableState.Advanced)]
1299 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1300 public Size ClientSize {
1303 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1304 return ((Form)this).form_parent_window.ClientSize;
1312 this.SetClientSizeCore(value.Width, value.Height);
1316 [EditorBrowsable(EditorBrowsableState.Advanced)]
1318 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1319 [DescriptionAttribute("ControlCompanyNameDescr")]
1320 public String CompanyName {
1322 return "Mono Project, Novell, Inc.";
1326 [EditorBrowsable(EditorBrowsableState.Advanced)]
1328 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1329 public bool ContainsFocus {
1335 for (int i=0; i < child_controls.Count; i++) {
1336 if (child_controls[i].ContainsFocus) {
1344 [DefaultValue(null)]
1345 public virtual ContextMenu ContextMenu {
1347 return context_menu;
1351 if (context_menu != value) {
1352 context_menu = value;
1353 OnContextMenuChanged(EventArgs.Empty);
1359 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
1360 public ControlCollection Controls {
1362 return this.child_controls;
1366 [EditorBrowsable(EditorBrowsableState.Advanced)]
1368 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1369 public bool Created {
1371 if (!this.is_disposed && (this.window.Handle != IntPtr.Zero)) {
1378 [AmbientValue(null)]
1379 public virtual Cursor Cursor {
1381 if (cursor != null) {
1385 if (parent != null) {
1386 return parent.Cursor;
1389 return Cursors.Default;
1393 if (cursor != value) {
1398 pt = Cursor.Position;
1399 if (bounds.Contains(pt)) {
1400 if (GetChildAtPoint(pt) == null) {
1401 if (cursor != null) {
1402 XplatUI.SetCursor(window.Handle, cursor.handle);
1404 if (parent != null) {
1405 XplatUI.SetCursor(window.Handle, parent.Cursor.handle);
1407 XplatUI.SetCursor(window.Handle, Cursors.def.handle);
1413 OnCursorChanged(EventArgs.Empty);
1419 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
1420 [ParenthesizePropertyName(true)]
1421 [RefreshProperties(RefreshProperties.All)]
1422 public ControlBindingsCollection DataBindings {
1424 if (data_bindings == null)
1425 data_bindings = new ControlBindingsCollection (this);
1426 return data_bindings;
1430 [EditorBrowsable(EditorBrowsableState.Advanced)]
1432 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1433 public virtual Rectangle DisplayRectangle {
1435 return ClientRectangle;
1439 [EditorBrowsable(EditorBrowsableState.Advanced)]
1441 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1442 public bool Disposing {
1449 [RefreshProperties(RefreshProperties.Repaint)]
1450 [DefaultValue(DockStyle.None)]
1451 public virtual DockStyle Dock {
1457 if (dock_style == value) {
1463 if (parent != null) {
1464 parent.PerformLayout(this, "Parent");
1467 OnDockChanged(EventArgs.Empty);
1473 public bool Enabled {
1479 if (is_enabled == value) {
1485 OnEnabledChanged (EventArgs.Empty);
1489 [EditorBrowsable(EditorBrowsableState.Advanced)]
1491 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1492 public virtual bool Focused {
1494 return this.has_focus;
1499 [AmbientValue(null)]
1501 public virtual Font Font {
1507 if (Parent != null && Parent.Font != null) {
1515 if (font != null && font.Equals (value)) {
1521 OnFontChanged (EventArgs.Empty);
1526 public virtual Color ForeColor {
1528 if (foreground_color.IsEmpty) {
1530 return parent.ForeColor;
1532 return DefaultForeColor;
1534 return foreground_color;
1538 if (foreground_color != value) {
1539 foreground_color=value;
1541 OnForeColorChanged(EventArgs.Empty);
1548 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1549 public IntPtr Handle { // IWin32Window
1551 if (!IsHandleCreated) {
1554 return window.Handle;
1558 [EditorBrowsable(EditorBrowsableState.Advanced)]
1560 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1561 public bool HasChildren {
1563 if (this.child_controls.Count>0) {
1570 [EditorBrowsable(EditorBrowsableState.Always)]
1572 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1575 return this.bounds.Height;
1579 SetBoundsCore(bounds.X, bounds.Y, bounds.Width, value, BoundsSpecified.Height);
1583 [AmbientValue(ImeMode.Inherit)]
1585 public ImeMode ImeMode {
1587 if (ime_mode == DefaultImeMode) {
1589 return parent.ImeMode;
1591 return ImeMode.NoControl; // default value
1597 if (ime_mode != value) {
1600 OnImeModeChanged(EventArgs.Empty);
1605 [EditorBrowsable(EditorBrowsableState.Advanced)]
1607 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1608 public bool InvokeRequired { // ISynchronizeInvoke
1610 if (creator_thread!=Thread.CurrentThread) {
1617 [EditorBrowsable(EditorBrowsableState.Advanced)]
1619 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1620 public bool IsAccessible {
1622 return is_accessible;
1626 is_accessible = value;
1630 [EditorBrowsable(EditorBrowsableState.Advanced)]
1632 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1633 public bool IsDisposed {
1635 return this.is_disposed;
1639 [EditorBrowsable(EditorBrowsableState.Advanced)]
1641 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1642 public bool IsHandleCreated {
1644 if ((window!=null) && (window.Handle!=IntPtr.Zero)) {
1652 [EditorBrowsable(EditorBrowsableState.Always)]
1654 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1657 return this.bounds.X;
1661 SetBoundsCore(value, bounds.Y, bounds.Width, bounds.Height, BoundsSpecified.X);
1666 public Point Location {
1668 return new Point(bounds.X, bounds.Y);
1672 SetBoundsCore(value.X, value.Y, bounds.Width, bounds.Height, BoundsSpecified.Location);
1677 public string Name {
1688 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1689 public Control Parent {
1695 if (value == this) {
1696 throw new ArgumentException("A circular control reference has been made. A control cannot be owned or parented to itself.");
1699 if (parent!=value) {
1701 parent.Controls.Remove(this);
1707 if (!parent.Controls.Contains(this)) {
1708 parent.Controls.Add(this);
1711 if (IsHandleCreated) {
1712 XplatUI.SetParent(Handle, value.Handle);
1715 OnParentChanged(EventArgs.Empty);
1721 [EditorBrowsable(EditorBrowsableState.Advanced)]
1723 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1724 public string ProductName {
1726 Type t = typeof (AssemblyProductAttribute);
1727 Assembly assembly = GetType().Module.Assembly;
1728 object [] attrs = assembly.GetCustomAttributes (t, false);
1729 AssemblyProductAttribute a = null;
1730 // On MS we get a NullRefException if product attribute is not
1732 if (attrs != null && attrs.Length > 0)
1733 a = (AssemblyProductAttribute) attrs [0];
1738 [EditorBrowsable(EditorBrowsableState.Advanced)]
1740 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1741 public string ProductVersion {
1743 Type t = typeof (AssemblyVersionAttribute);
1744 Assembly assembly = GetType().Module.Assembly;
1745 object [] attrs = assembly.GetCustomAttributes (t, false);
1746 if (attrs == null || attrs.Length < 1)
1748 return ((AssemblyVersionAttribute)attrs [0]).Version;
1752 [EditorBrowsable(EditorBrowsableState.Advanced)]
1754 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1755 public bool RecreatingHandle {
1757 return is_recreating;
1761 [EditorBrowsable(EditorBrowsableState.Advanced)]
1763 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1764 public Region Region {
1766 return new Region(this.bounds);
1773 g = this.CreateGraphics();
1774 r = value.GetBounds(g);
1776 SetBounds((int)r.X, (int)r.Y, (int)r.Width, (int)r.Height);
1782 [EditorBrowsable(EditorBrowsableState.Advanced)]
1784 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1787 return this.bounds.X+this.bounds.Width;
1791 [AmbientValue(RightToLeft.Inherit)]
1793 public virtual RightToLeft RightToLeft {
1795 if (right_to_left == RightToLeft.Inherit) {
1797 return parent.RightToLeft;
1799 return RightToLeft.No; // default value
1801 return right_to_left;
1805 if (value != right_to_left) {
1806 right_to_left = value;
1807 OnRightToLeftChanged(EventArgs.Empty);
1812 [EditorBrowsable(EditorBrowsableState.Advanced)]
1813 public override ISite Site {
1826 return new Size(Width, Height);
1830 SetBoundsCore(bounds.X, bounds.Y, value.Width, value.Height, BoundsSpecified.Size);
1835 [MergableProperty(false)]
1836 public int TabIndex {
1838 if (tab_index != -1) {
1845 if (tab_index != value) {
1847 OnTabIndexChanged(EventArgs.Empty);
1853 [DefaultValue(true)]
1854 public bool TabStop {
1860 if (tab_stop != value) {
1862 OnTabStopChanged(EventArgs.Empty);
1867 [Localizable(false)]
1869 [TypeConverter(typeof(StringConverter))]
1870 [DefaultValue(null)]
1877 control_tag = value;
1883 [BindableAttribute(true)]
1884 public virtual string Text {
1890 if (value == null) {
1891 value = String.Empty;
1896 if (IsHandleCreated) {
1897 XplatUI.Text(Handle, text);
1899 // FIXME: Do we need a Refresh() here?
1902 OnTextChanged (EventArgs.Empty);
1907 [EditorBrowsable(EditorBrowsableState.Always)]
1909 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1912 return this.bounds.Y;
1916 SetBoundsCore(bounds.X, value, bounds.Width, bounds.Height, BoundsSpecified.Y);
1920 [EditorBrowsable(EditorBrowsableState.Advanced)]
1922 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1923 public Control TopLevelControl {
1927 while (p.parent != null) {
1936 public bool Visible {
1940 } else if (parent != null) {
1941 return parent.Visible;
1948 SetVisibleCore(value);
1952 [EditorBrowsable(EditorBrowsableState.Always)]
1954 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1957 return this.bounds.Width;
1961 SetBoundsCore(bounds.X, bounds.Y, value, bounds.Height, BoundsSpecified.Width);
1965 [EditorBrowsable(EditorBrowsableState.Never)]
1967 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1968 public IWindowTarget WindowTarget {
1977 #endregion // Public Instance Properties
1979 #region Protected Instance Properties
1980 protected virtual CreateParams CreateParams {
1982 CreateParams create_params = new CreateParams();
1985 create_params.Caption = Text;
1988 create_params.Caption = text;
1992 create_params.X = Left;
1995 create_params.X = this.bounds.X;
1999 create_params.Y = Top;
2002 create_params.Y = this.bounds.Y;
2006 create_params.Width = Width;
2009 create_params.Width = this.bounds.Width;
2013 create_params.Height = Height;
2016 create_params.Height = this.bounds.Height;
2020 create_params.ClassName = XplatUI.DefaultClassName;
2021 create_params.ClassStyle = 0;
2022 create_params.ExStyle = 0;
2023 create_params.Param = 0;
2026 create_params.ExStyle |= (int)WindowStyles.WS_EX_ACCEPTFILES;
2030 create_params.Parent = parent.Handle;
2033 create_params.Style = (int)WindowStyles.WS_CHILD | (int)WindowStyles.WS_CLIPCHILDREN | (int)WindowStyles.WS_CLIPSIBLINGS;
2036 create_params.Style |= (int)WindowStyles.WS_VISIBLE;
2039 return create_params;
2043 protected virtual ImeMode DefaultImeMode {
2045 return ImeMode.Inherit;
2049 protected virtual Size DefaultSize {
2051 return new Size(100, 23);
2055 protected int FontHeight {
2065 protected bool RenderRightToLeft {
2067 return (this.right_to_left == RightToLeft.Yes);
2071 protected bool ResizeRedraw {
2073 return GetStyle(ControlStyles.ResizeRedraw);
2077 SetStyle(ControlStyles.ResizeRedraw, value);
2081 [EditorBrowsable(EditorBrowsableState.Advanced)]
2083 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2084 protected virtual bool ShowFocusCues {
2090 [EditorBrowsable(EditorBrowsableState.Advanced)]
2092 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2093 protected bool ShowKeyboardCues {
2098 #endregion // Protected Instance Properties
2100 #region Public Static Methods
2101 [EditorBrowsable(EditorBrowsableState.Advanced)]
2102 public static Control FromChildHandle(IntPtr handle) {
2103 IEnumerator control = Control.controls.GetEnumerator();
2105 while (control.MoveNext()) {
2106 if (((Control)control.Current).window.Handle == handle) {
2108 if (((Control)control.Current).Parent != null) {
2109 return ((Control)control.Current).Parent;
2116 [EditorBrowsable(EditorBrowsableState.Advanced)]
2117 public static Control FromHandle(IntPtr handle) {
2118 IEnumerator control = Control.controls.GetEnumerator();
2120 while (control.MoveNext()) {
2121 if (((Control)control.Current).window.Handle == handle) {
2123 return ((Control)control.Current);
2129 public static bool IsMnemonic(char charCode, string text) {
2132 amp = text.IndexOf('&');
2135 if (amp + 1 < text.Length) {
2136 if (text[amp + 1] != '&') {
2137 if (Char.ToUpper(charCode) == Char.ToUpper(text.ToCharArray(amp + 1, 1)[0])) {
2147 #region Protected Static Methods
2148 [EditorBrowsable(EditorBrowsableState.Advanced)]
2149 protected static bool ReflectMessage(IntPtr hWnd, ref Message m) {
2152 c = Control.FromHandle(hWnd);
2162 #region Public Instance Methods
2163 [EditorBrowsable(EditorBrowsableState.Advanced)]
2164 public IAsyncResult BeginInvoke(Delegate method) {
2165 return BeginInvokeInternal(method, null);
2168 [EditorBrowsable(EditorBrowsableState.Advanced)]
2169 public IAsyncResult BeginInvoke (Delegate method, object[] args) {
2170 return BeginInvokeInternal (method, args);
2173 public void BringToFront() {
2174 if ((parent != null) && (parent.child_controls[0]!=this)) {
2175 if (parent.child_controls.Contains(this)) {
2176 parent.child_controls.SetChildIndex(this, 0);
2180 XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, true, false);
2182 if (parent != null) {
2187 public bool Contains(Control ctl) {
2188 while (ctl != null) {
2197 public void CreateControl() {
2199 if (!IsHandleCreated) {
2203 if (!create_handled) {
2204 create_handled = true;
2208 for (int i=0; i<child_controls.Count; i++) {
2209 child_controls[i].CreateControl();
2213 public Graphics CreateGraphics() {
2214 if (!IsHandleCreated) {
2215 this.CreateControl();
2217 return Graphics.FromHwnd(this.window.Handle);
2220 public DragDropEffects DoDragDrop(object data, DragDropEffects allowedEffects) {
2221 return XplatUI.StartDrag(this.window.Handle, data, allowedEffects);
2224 [EditorBrowsable(EditorBrowsableState.Advanced)]
2225 public object EndInvoke (IAsyncResult async_result) {
2226 AsyncMethodResult result = (AsyncMethodResult) async_result;
2227 return result.EndInvoke ();
2230 public Form FindForm() {
2243 public bool Focus() {
2244 if (IsHandleCreated && !has_focus) {
2246 XplatUI.SetFocus(window.Handle);
2251 public Control GetChildAtPoint(Point pt) {
2252 // Microsoft's version of this function doesn't seem to work, so I can't check
2253 // if we only consider children or also grandchildren, etc.
2254 // I'm gonna say 'children only'
2255 for (int i=0; i<child_controls.Count; i++) {
2256 if (child_controls[i].Bounds.Contains(pt)) {
2257 return child_controls[i];
2263 public IContainerControl GetContainerControl() {
2264 Control current = this;
2266 while (current!=null) {
2267 if ((current is IContainerControl) && ((current.control_style & ControlStyles.ContainerControl)!=0)) {
2268 return (IContainerControl)current;
2270 current = current.parent;
2275 public Control GetNextControl(Control ctl, bool forward) {
2276 // If we're not a container we don't play
2277 if (!(this is IContainerControl) && !this.GetStyle(ControlStyles.ContainerControl)) {
2281 // If ctl is not contained by this, we start at the first child of this
2282 if (!this.Contains(ctl)) {
2286 // Search through our controls, starting at ctl, stepping into children as we encounter them
2287 // try to find the control with the tabindex closest to our own, or, if we're looking into
2288 // child controls, the one with the smallest tabindex
2290 return FindControlForward(this, ctl);
2292 return FindControlBackward(this, ctl);
2295 public void Hide() {
2296 this.Visible = false;
2299 public void Invalidate() {
2300 Invalidate(ClientRectangle, false);
2303 public void Invalidate(bool invalidateChildren) {
2304 Invalidate(ClientRectangle, invalidateChildren);
2307 public void Invalidate(System.Drawing.Rectangle rc) {
2308 Invalidate(rc, false);
2311 public void Invalidate(System.Drawing.Rectangle rc, bool invalidateChildren) {
2312 if (!IsHandleCreated || !Visible) {
2316 NotifyInvalidate(rc);
2318 XplatUI.Invalidate(Handle, rc, false);
2320 if (invalidateChildren) {
2321 for (int i=0; i<child_controls.Count; i++) child_controls[i].Invalidate();
2323 OnInvalidated(new InvalidateEventArgs(rc));
2326 public void Invalidate(System.Drawing.Region region) {
2327 Invalidate(region, false);
2330 [MonoTODO("Figure out if GetRegionScans is usable")]
2331 public void Invalidate(System.Drawing.Region region, bool invalidateChildren) {
2332 throw new NotImplementedException();
2334 // FIXME - should use the GetRegionScans function of the region to invalidate each area
2335 //if (invalidateChildren) {
2336 // for (int i=0; i<child_controls.Count; i++) child_controls[i].Invalidate();
2340 public object Invoke (Delegate method) {
2341 return Invoke(method, null);
2344 public object Invoke (Delegate method, object[] args) {
2345 if (!this.InvokeRequired) {
2346 return method.DynamicInvoke(args);
2349 IAsyncResult result = BeginInvoke (method, args);
2350 return EndInvoke(result);
2353 [EditorBrowsable(EditorBrowsableState.Advanced)]
2354 public void PerformLayout() {
2355 PerformLayout(null, null);
2358 [EditorBrowsable(EditorBrowsableState.Advanced)]
2359 public void PerformLayout(Control affectedControl, string affectedProperty) {
2360 LayoutEventArgs levent = new LayoutEventArgs(affectedControl, affectedProperty);
2362 if (layout_suspended>0) {
2363 layout_pending = true;
2367 layout_pending = false;
2369 // Prevent us from getting messed up
2372 // Perform all Dock and Anchor calculations
2375 AnchorStyles anchor;
2380 space=this.DisplayRectangle;
2381 if (prev_size != Size.Empty) {
2382 diff_width = space.Width - prev_size.Width;
2383 diff_height = space.Height - prev_size.Height;
2389 // Deal with docking; go through in reverse, MS docs say that lowest Z-order is closest to edge
2390 for (int i = child_controls.Count - 1; i >= 0; i--) {
2391 child=child_controls[i];
2392 switch (child.Dock) {
2393 case DockStyle.None: {
2398 case DockStyle.Left: {
2399 child.SetBounds(space.Left, space.Y, child.Width, space.Height);
2400 space.X+=child.Width;
2401 space.Width-=child.Width;
2405 case DockStyle.Top: {
2406 child.SetBounds(space.Left, space.Y, space.Width, child.Height);
2407 space.Y+=child.Height;
2408 space.Height-=child.Height;
2412 case DockStyle.Right: {
2413 child.SetBounds(space.Right-child.Width, space.Y, child.Width, space.Height);
2414 space.Width-=child.Width;
2418 case DockStyle.Bottom: {
2419 child.SetBounds(space.Left, space.Bottom-child.Height, space.Width, child.Height);
2420 space.Height-=child.Height;
2426 for (int i = child_controls.Count - 1; i >= 0; i--) {
2427 child=child_controls[i];
2429 if (child.Dock == DockStyle.Fill) {
2430 child.SetBounds(space.Left, space.Top, space.Width, space.Height);
2436 space=this.DisplayRectangle;
2438 // Deal with anchoring
2439 for (int i=0; i < child_controls.Count; i++) {
2445 child=child_controls[i];
2446 anchor=child.Anchor;
2451 height=child.Height;
2453 // If the control is docked we don't need to do anything
2454 if (child.Dock != DockStyle.None) {
2458 if ((anchor & AnchorStyles.Left) !=0 ) {
2459 if ((anchor & AnchorStyles.Right) != 0) {
2460 // Anchoring to left and right
2461 width=width+diff_width;
2465 } else if ((anchor & AnchorStyles.Right) != 0) {
2471 if ((anchor & AnchorStyles.Top) !=0 ) {
2472 if ((anchor & AnchorStyles.Bottom) != 0) {
2473 height+=diff_height;
2477 } else if ((anchor & AnchorStyles.Bottom) != 0) {
2492 child.SetBounds(left, top, width, height);
2495 // Let everyone know
2499 // Need to make sure we decremend layout_suspended
2505 public Point PointToClient (Point p) {
2509 XplatUI.ScreenToClient (Handle, ref x, ref y);
2511 return new Point (x, y);
2514 public Point PointToScreen(Point p) {
2518 XplatUI.ClientToScreen(Handle, ref x, ref y);
2520 return new Point(x, y);
2523 public virtual bool PreProcessMessage(ref Message msg) {
2526 if ((msg.Msg == (int)Msg.WM_KEYDOWN) || (msg.Msg == (int)Msg.WM_SYSKEYDOWN)) {
2527 key_data = (Keys)msg.WParam.ToInt32();
2528 if (!ProcessCmdKey(ref msg, key_data)) {
2529 if (IsInputKey(key_data)) {
2533 return ProcessDialogKey(key_data);
2537 } else if (msg.Msg == (int)Msg.WM_CHAR) {
2538 if (IsInputChar((char)msg.WParam)) {
2541 } else if (msg.Msg == (int)Msg.WM_SYSCHAR) {
2542 if (IsInputChar((char)msg.WParam)) {
2545 return ProcessDialogChar((char)msg.WParam);
2550 public Rectangle RectangleToClient(Rectangle r) {
2551 return new Rectangle(PointToClient(r.Location), r.Size);
2554 public Rectangle RectangleToScreen(Rectangle r) {
2555 return new Rectangle(PointToScreen(r.Location), r.Size);
2558 public virtual void Refresh() {
2559 if (IsHandleCreated == true) {
2563 XplatUI.UpdateWindow(window.Handle);
2565 end = child_controls.Count;
2566 for (int i=0; i < end; i++) {
2567 child_controls[i].Refresh();
2573 [EditorBrowsable(EditorBrowsableState.Never)]
2574 public virtual void ResetBackColor() {
2575 background_color = Color.Empty;
2578 [EditorBrowsable(EditorBrowsableState.Never)]
2580 public void ResetBindings() {
2584 [EditorBrowsable(EditorBrowsableState.Never)]
2585 public virtual void ResetCursor() {
2589 [EditorBrowsable(EditorBrowsableState.Never)]
2590 public virtual void ResetFont() {
2594 [EditorBrowsable(EditorBrowsableState.Never)]
2595 public virtual void ResetForeColor() {
2596 foreground_color = Color.Empty;
2599 [EditorBrowsable(EditorBrowsableState.Never)]
2600 public void ResetImeMode() {
2601 ime_mode = DefaultImeMode;
2604 [EditorBrowsable(EditorBrowsableState.Never)]
2605 public virtual void ResetRightToLeft() {
2606 right_to_left = RightToLeft.Inherit;
2609 public virtual void ResetText() {
2610 text = String.Empty;
2613 public void ResumeLayout() {
2614 ResumeLayout (true);
2617 public void ResumeLayout(bool performLayout) {
2620 if (layout_suspended > 0) {
2624 if (performLayout || layout_pending) {
2629 public void Scale(float ratio) {
2630 ScaleCore(ratio, ratio);
2633 public void Scale(float dx, float dy) {
2637 public void Select() {
2638 Select(false, false);
2641 public bool SelectNextControl(Control ctl, bool forward, bool tabStopOnly, bool nested, bool wrap) {
2646 c = GetNextControl(c, forward);
2655 if (c.CanSelect && ((c.parent == ctl.parent) || nested) && (c.tab_stop || !tabStopOnly)) {
2659 } while (c != ctl); // If we wrap back to ourselves we stop
2664 public void SendToBack() {
2665 if ((parent != null) && (parent.child_controls[parent.child_controls.Count-1]!=this)) {
2666 if (parent.child_controls.Contains(this)) {
2667 parent.child_controls.SetChildIndex(this, parent.child_controls.Count);
2671 XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, false, true);
2672 if (parent != null) {
2677 public void SetBounds(int x, int y, int width, int height) {
2678 SetBoundsCore(x, y, width, height, BoundsSpecified.All);
2681 public void SetBounds(int x, int y, int width, int height, BoundsSpecified specified) {
2682 SetBoundsCore(x, y, width, height, specified);
2685 public void Show() {
2686 if (!IsHandleCreated) {
2687 this.CreateControl();
2693 public void SuspendLayout() {
2697 public void Update() {
2698 needs_redraw = true;
2699 XplatUI.UpdateWindow(window.Handle);
2701 #endregion // Public Instance Methods
2703 #region Protected Instance Methods
2704 [EditorBrowsable(EditorBrowsableState.Advanced)]
2705 [MonoTODO("Implement this and tie it into Control.ControlAccessibleObject.NotifyClients")]
2706 protected void AccessibilityNotifyClients(AccessibleEvents accEvent, int childID) {
2707 throw new NotImplementedException();
2710 [EditorBrowsable(EditorBrowsableState.Advanced)]
2711 protected virtual AccessibleObject CreateAccessibilityInstance() {
2712 return new Control.ControlAccessibleObject(this);
2715 [EditorBrowsable(EditorBrowsableState.Advanced)]
2716 protected virtual ControlCollection CreateControlsInstance() {
2717 return new ControlCollection(this);
2720 [EditorBrowsable(EditorBrowsableState.Advanced)]
2721 protected virtual void CreateHandle() {
2723 throw new ObjectDisposedException(Name);
2726 if (IsHandleCreated) {
2730 window.CreateHandle(CreateParams);
2732 // Find out where the window manager placed us
2736 if (window.Handle!=IntPtr.Zero) {
2737 if (!controls.Contains(window.Handle)) {
2741 creator_thread = Thread.CurrentThread;
2743 if (!GetStyle (ControlStyles.UserPaint)) {
2744 XplatUI.SetWindowBackground(window.Handle, this.BackColor);
2747 OnHandleCreated(EventArgs.Empty);
2751 [EditorBrowsable(EditorBrowsableState.Advanced)]
2752 protected virtual void DefWndProc(ref Message m) {
2753 window.DefWndProc(ref m);
2756 [EditorBrowsable(EditorBrowsableState.Advanced)]
2757 protected virtual void DestroyHandle() {
2758 if (IsHandleCreated) {
2759 // Destroy our children before we destroy ourselves, to prevent them from
2760 // being implictly (without us knowing) destroyed
2761 for (int i=0; i < child_controls.Count; i++) {
2762 child_controls[i].DestroyHandle();
2766 if (window != null) {
2767 window.DestroyHandle();
2769 OnHandleDestroyed(EventArgs.Empty);
2773 protected bool GetStyle(ControlStyles flag) {
2774 return (control_style & flag) != 0;
2777 protected bool GetTopLevel() {
2781 [EditorBrowsable(EditorBrowsableState.Advanced)]
2782 protected virtual void InitLayout() {
2783 if (parent != null) {
2784 parent.PerformLayout(this, "parent");
2788 [EditorBrowsable(EditorBrowsableState.Advanced)]
2789 protected void InvokeGotFocus(Control toInvoke, EventArgs e) {
2790 toInvoke.OnGotFocus(e);
2793 [EditorBrowsable(EditorBrowsableState.Advanced)]
2794 protected void InvokeLostFocus(Control toInvoke, EventArgs e) {
2795 toInvoke.OnLostFocus(e);
2798 [EditorBrowsable(EditorBrowsableState.Advanced)]
2799 protected void InvokeOnClick(Control toInvoke, EventArgs e) {
2800 toInvoke.OnClick(e);
2803 protected void InvokePaint(Control toInvoke, PaintEventArgs e) {
2804 toInvoke.OnPaint(e);
2807 protected void InvokePaintBackground(Control toInvoke, PaintEventArgs e) {
2808 toInvoke.OnPaintBackground(e);
2811 protected virtual bool IsInputChar (char charCode) {
2812 if (parent != null) {
2813 return parent.IsInputChar(charCode);
2819 protected virtual bool IsInputKey (Keys keyData) {
2820 // Doc says this one calls IsInputChar; not sure what to do with that
2824 [EditorBrowsable(EditorBrowsableState.Advanced)]
2825 protected virtual void NotifyInvalidate(Rectangle invalidatedArea) {
2829 protected virtual bool ProcessCmdKey(ref Message msg, Keys keyData) {
2830 if ((context_menu != null) && context_menu.ProcessCmdKey(ref msg, keyData)) {
2834 if (parent != null) {
2835 return parent.ProcessCmdKey(ref msg, keyData);
2841 protected virtual bool ProcessDialogChar(char charCode) {
2842 if (parent != null) {
2843 return parent.ProcessDialogChar (charCode);
2849 protected virtual bool ProcessDialogKey (Keys keyData) {
2850 if (parent != null) {
2851 return parent.ProcessDialogKey (keyData);
2857 protected virtual bool ProcessKeyEventArgs (ref Message msg)
2859 KeyEventArgs key_event;
2862 case (int)Msg.WM_KEYDOWN: {
2863 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
2864 OnKeyDown (key_event);
2865 return key_event.Handled;
2867 case (int)Msg.WM_KEYUP: {
2868 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
2869 OnKeyUp (key_event);
2870 return key_event.Handled;
2873 case (int)Msg.WM_CHAR: {
2874 KeyPressEventArgs key_press_event;
2876 key_press_event = new KeyPressEventArgs((char)msg.WParam);
2877 OnKeyPress(key_press_event);
2878 return key_press_event.Handled;
2889 protected internal virtual bool ProcessKeyMessage(ref Message msg) {
2890 if (parent != null) {
2891 if (parent.ProcessKeyPreview(ref msg)) {
2899 protected virtual bool ProcessKeyPreview(ref Message msg) {
2900 if (parent != null) {
2901 return parent.ProcessKeyPreview(ref msg);
2907 protected virtual bool ProcessMnemonic(char charCode) {
2912 [EditorBrowsable(EditorBrowsableState.Advanced)]
2913 protected void RaiseDragEvent(object key, DragEventArgs e) {
2917 [EditorBrowsable(EditorBrowsableState.Advanced)]
2918 protected void RaiseKeyEvent(object key, KeyEventArgs e) {
2922 [EditorBrowsable(EditorBrowsableState.Advanced)]
2923 protected void RaiseMouseEvent(object key, MouseEventArgs e) {
2927 [EditorBrowsable(EditorBrowsableState.Advanced)]
2928 protected void RaisePaintEvent(object key, PaintEventArgs e) {
2932 [EditorBrowsable(EditorBrowsableState.Advanced)]
2933 protected void RecreateHandle() {
2934 IEnumerator child = child_controls.GetEnumerator();
2938 if (IsHandleCreated) {
2944 while (child.MoveNext()) {
2945 ((Control)child.Current).RecreateHandle();
2951 is_recreating = false;
2954 [EditorBrowsable(EditorBrowsableState.Advanced)]
2955 protected void ResetMouseEventArgs() {
2959 [EditorBrowsable(EditorBrowsableState.Advanced)]
2960 protected ContentAlignment RtlTranslateAlignment(ContentAlignment align) {
2961 if (right_to_left == RightToLeft.No) {
2966 case ContentAlignment.TopLeft: {
2967 return ContentAlignment.TopRight;
2970 case ContentAlignment.TopRight: {
2971 return ContentAlignment.TopLeft;
2974 case ContentAlignment.MiddleLeft: {
2975 return ContentAlignment.MiddleRight;
2978 case ContentAlignment.MiddleRight: {
2979 return ContentAlignment.MiddleLeft;
2982 case ContentAlignment.BottomLeft: {
2983 return ContentAlignment.BottomRight;
2986 case ContentAlignment.BottomRight: {
2987 return ContentAlignment.BottomLeft;
2991 // if it's center it doesn't change
2997 [EditorBrowsable(EditorBrowsableState.Advanced)]
2998 protected HorizontalAlignment RtlTranslateAlignment(HorizontalAlignment align) {
2999 if ((right_to_left == RightToLeft.No) || (align == HorizontalAlignment.Center)) {
3003 if (align == HorizontalAlignment.Left) {
3004 return HorizontalAlignment.Right;
3007 // align must be HorizontalAlignment.Right
3008 return HorizontalAlignment.Left;
3011 [EditorBrowsable(EditorBrowsableState.Advanced)]
3012 protected LeftRightAlignment RtlTranslateAlignment(LeftRightAlignment align) {
3013 if (right_to_left == RightToLeft.No) {
3017 if (align == LeftRightAlignment.Left) {
3018 return LeftRightAlignment.Right;
3021 // align must be LeftRightAlignment.Right;
3022 return LeftRightAlignment.Left;
3025 [EditorBrowsable(EditorBrowsableState.Advanced)]
3026 protected ContentAlignment RtlTranslateContent(ContentAlignment align) {
3027 return RtlTranslateAlignment(align);
3030 [EditorBrowsable(EditorBrowsableState.Advanced)]
3031 protected HorizontalAlignment RtlTranslateHorizontal(HorizontalAlignment align) {
3032 return RtlTranslateAlignment(align);
3035 [EditorBrowsable(EditorBrowsableState.Advanced)]
3036 protected LeftRightAlignment RtlTranslateLeftRight(LeftRightAlignment align) {
3037 return RtlTranslateAlignment(align);
3040 [EditorBrowsable(EditorBrowsableState.Advanced)]
3041 protected virtual void ScaleCore(float dx, float dy) {
3047 location = new Point((int)(Left * dx), (int)(Top * dy));
3048 size = this.ClientSize;
3051 if (!GetStyle(ControlStyles.FixedWidth)) {
3052 size.Width = (int)(size.Width * dx);
3055 if (!GetStyle(ControlStyles.FixedHeight)) {
3056 size.Height = (int)(size.Height * dy);
3059 Location = location;
3062 /* Now scale our children */
3063 for (int i=0; i < child_controls.Count; i++) {
3064 child_controls[i].Scale(dx, dy);
3070 protected virtual void Select(bool directed, bool forward) {
3075 // Select this control
3080 if (parent == null) {
3084 // FIXME - this thing is doing the wrong stuff, needs to be similar to SelectNextControl
3086 index = parent.child_controls.IndexOf(this);
3091 if ((index+1) < parent.child_controls.Count) {
3100 index = parent.child_controls.Count-1;
3103 result = Select(parent.child_controls[index]);
3104 } while (!result && parent.child_controls[index] != this);
3107 [EditorBrowsable(EditorBrowsableState.Advanced)]
3108 protected virtual void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
3109 // SetBoundsCore updates the Win32 control itself. UpdateBounds updates the controls variables and fires events, I'm guessing - pdb
3110 if ((specified & BoundsSpecified.X) != BoundsSpecified.X) {
3114 if ((specified & BoundsSpecified.Y) != BoundsSpecified.Y) {
3118 if ((specified & BoundsSpecified.Width) != BoundsSpecified.Width) {
3122 if ((specified & BoundsSpecified.Height) != BoundsSpecified.Height) {
3126 if (IsHandleCreated) {
3127 XplatUI.SetWindowPos(Handle, x, y, width, height);
3129 UpdateBounds(x, y, width, height);
3132 [EditorBrowsable(EditorBrowsableState.Advanced)]
3133 protected virtual void SetClientSizeCore(int x, int y) {
3134 // Calculate the actual window size from the client size (it usually stays the same or grows)
3135 Rectangle ClientRect;
3136 Rectangle WindowRect;
3139 ClientRect = new Rectangle(0, 0, x, y);
3140 cp = this.CreateParams;
3142 if (XplatUI.CalculateWindowRect(Handle, ref ClientRect, cp.Style, cp.ExStyle, IntPtr.Zero, out WindowRect)==false) {
3146 SetBoundsCore(bounds.X, bounds.Y, WindowRect.Width, WindowRect.Height, BoundsSpecified.Size);
3149 [EditorBrowsable(EditorBrowsableState.Advanced)]
3150 protected void SetStyle(ControlStyles flag, bool value) {
3152 control_style |= flag;
3154 control_style &= ~flag;
3156 OnStyleChanged(EventArgs.Empty);
3159 protected void SetTopLevel(bool value) {
3160 if ((GetTopLevel() != value) && (parent != null)) {
3161 throw new Exception();
3165 if (value == true) {
3175 is_toplevel = value;
3178 protected virtual void SetVisibleCore(bool value) {
3179 if (value!=is_visible) {
3182 if (IsHandleCreated) {
3183 XplatUI.SetVisible(Handle, value);
3184 // Explicitly move Toplevel windows to where we want them;
3185 // apparently moving unmapped toplevel windows doesn't work
3186 if (is_visible && (this is Form)) {
3187 XplatUI.SetWindowPos(window.Handle, bounds.X, bounds.Y, bounds.Width, bounds.Height);
3191 OnVisibleChanged(EventArgs.Empty);
3194 if (dc_mem != null) {
3199 if (bmp_mem != null) {
3204 this.CreateBuffers(bounds.Width, bounds.Height);
3208 if (value == false && parent != null) {
3211 // Need to start at parent, GetContainerControl might return ourselves if we're a container
3212 container = (Control)parent.GetContainerControl();
3213 if (container != null) {
3214 container.SelectNextControl(this, true, true, true, true);
3218 if (parent != null) {
3219 parent.PerformLayout(this, "visible");
3221 PerformLayout(this, "visible");
3226 [EditorBrowsable(EditorBrowsableState.Advanced)]
3227 protected void UpdateBounds() {
3235 if (!IsHandleCreated) {
3239 XplatUI.GetWindowPos(this.Handle, this is Form, out x, out y, out width, out height, out client_width, out client_height);
3241 UpdateBounds(x, y, width, height, client_width, client_height);
3244 [EditorBrowsable(EditorBrowsableState.Advanced)]
3245 protected void UpdateBounds(int x, int y, int width, int height) {
3246 // UpdateBounds only seems to set our sizes and fire events but not update the GUI window to match
3248 bool resized = false;
3250 int client_x_diff = this.bounds.Width-this.client_size.Width;
3251 int client_y_diff = this.bounds.Height-this.client_size.Height;
3253 // Needed to generate required notifications
3254 if ((this.bounds.X!=x) || (this.bounds.Y!=y)) {
3258 if ((this.Bounds.Width!=width) || (this.Bounds.Height!=height)) {
3265 bounds.Height=height;
3267 // Update client rectangle as well
3268 if (this.layout_suspended==0) {
3269 prev_size.Width=client_size.Width;
3270 prev_size.Height=client_size.Height;
3273 client_size.Width=width-client_x_diff;
3274 client_size.Height=height-client_y_diff;
3277 OnLocationChanged(EventArgs.Empty);
3281 OnSizeChanged(EventArgs.Empty);
3285 [EditorBrowsable(EditorBrowsableState.Advanced)]
3286 protected void UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) {
3287 UpdateBounds(x, y, width, height);
3289 this.client_size.Width=clientWidth;
3290 this.client_size.Height=clientHeight;
3293 [EditorBrowsable(EditorBrowsableState.Advanced)]
3294 protected void UpdateStyles() {
3295 if (!IsHandleCreated) {
3299 XplatUI.SetWindowStyle(window.Handle, CreateParams);
3302 [EditorBrowsable(EditorBrowsableState.Advanced)]
3303 protected void UpdateZOrder() {
3308 if (parent == null) {
3314 children = ctl.child_controls.Count;
3315 for (int i = 1; i < children; i++ ) {
3316 XplatUI.SetZOrder(ctl.child_controls[i].window.Handle, ctl.child_controls[i-1].window.Handle, false, false);
3319 if (!IsHandleCreated) {
3323 children = child_controls.Count;
3324 for (int i = 1; i < children; i++ ) {
3325 XplatUI.SetZOrder(child_controls[i].Handle, child_controls[i-1].Handle, false, false);
3330 protected virtual void WndProc(ref Message m) {
3332 Console.WriteLine("Control received message {0}", (Msg)m.Msg);
3334 if ((this.control_style & ControlStyles.EnableNotifyMessage) != 0) {
3338 switch((Msg)m.Msg) {
3339 case Msg.WM_WINDOWPOSCHANGED: {
3342 if (GetStyle(ControlStyles.ResizeRedraw)) {
3349 case Msg.WM_PAINT: {
3350 PaintEventArgs paint_event;
3352 paint_event = XplatUI.PaintEventStart(Handle, true);
3354 if (!needs_redraw) {
3355 // Just blit the previous image
3356 paint_event.Graphics.DrawImage (ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle, GraphicsUnit.Pixel);
3357 XplatUI.PaintEventEnd(Handle, true);
3362 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
3363 dc = paint_event.SetGraphics (DeviceContext);
3366 if ((control_style & (ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint)) != (ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint)) {
3367 OnPaintBackground(paint_event);
3370 OnPaint(paint_event);
3372 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
3373 dc.DrawImage (ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle, GraphicsUnit.Pixel);
3374 paint_event.SetGraphics (dc);
3375 needs_redraw = false;
3378 XplatUI.PaintEventEnd(Handle, true);
3380 if (!GetStyle(ControlStyles.UserPaint)) {
3387 case Msg.WM_ERASEBKGND: {
3388 if (GetStyle (ControlStyles.UserPaint)) {
3389 if (!GetStyle(ControlStyles.AllPaintingInWmPaint)) {
3390 PaintEventArgs eraseEventArgs = new PaintEventArgs (m.WParam == IntPtr.Zero ? Graphics.FromHwnd (m.HWnd) :
3391 Graphics.FromHdc (m.WParam), new Rectangle (new Point (0,0),Size));
3392 OnPaintBackground (eraseEventArgs);
3395 XplatUI.EraseWindowBackground(m.HWnd, m.WParam);
3397 // The DefWndProc will never have to handle this, we don't ever set hbr on the window
3398 m.Result = (IntPtr)1;
3402 case Msg.WM_LBUTTONUP: {
3403 HandleClick(mouse_clicks);
3404 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Left,
3406 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3408 if (mouse_clicks > 1) {
3414 case Msg.WM_LBUTTONDOWN: {
3415 if (CanSelect && !is_selected) {
3418 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3419 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3425 case Msg.WM_LBUTTONDBLCLK: {
3427 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3428 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3434 case Msg.WM_MBUTTONUP: {
3435 HandleClick(mouse_clicks);
3436 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Middle,
3438 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3440 if (mouse_clicks > 1) {
3446 case Msg.WM_MBUTTONDOWN: {
3447 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3448 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3454 case Msg.WM_MBUTTONDBLCLK: {
3456 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3457 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3462 case Msg.WM_RBUTTONUP: {
3463 if (context_menu != null) {
3464 context_menu.Show(this, new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ())));
3467 HandleClick(mouse_clicks);
3468 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Right,
3470 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3472 if (mouse_clicks > 1) {
3478 case Msg.WM_RBUTTONDOWN: {
3479 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3480 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3485 case Msg.WM_RBUTTONDBLCLK: {
3487 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3488 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3493 case Msg.WM_MOUSEWHEEL: {
3495 OnMouseWheel (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3496 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3497 HighOrder(m.WParam.ToInt32())));
3502 case Msg.WM_MOUSEMOVE: {
3503 OnMouseMove (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3505 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3510 case Msg.WM_MOUSE_ENTER: {
3515 OnMouseEnter(EventArgs.Empty);
3519 case Msg.WM_MOUSE_LEAVE: {
3521 OnMouseLeave(EventArgs.Empty);
3525 case Msg.WM_MOUSEHOVER: {
3526 OnMouseHover(EventArgs.Empty);
3530 case Msg.WM_SYSKEYDOWN:
3531 case Msg.WM_KEYDOWN:
3532 case Msg.WM_SYSKEYUP:
3534 case Msg.WM_SYSCHAR:
3536 Console.WriteLine("Got {0}", (Msg)m.Msg);
3537 if (ProcessKeyEventArgs(ref m)) {
3541 if (PreProcessMessage(ref m)) {
3545 if (ProcessKeyMessage(ref m)) {
3554 if (m.LParam != IntPtr.Zero) {
3557 hi = new HELPINFO();
3559 hi = (HELPINFO) Marshal.PtrToStructure (m.LParam, typeof (HELPINFO));
3560 mouse_pos = new Point(hi.MousePos.x, hi.MousePos.y);
3562 mouse_pos = Control.MousePosition;
3564 OnHelpRequested(new HelpEventArgs(mouse_pos));
3565 m.Result = (IntPtr)1;
3569 case Msg.WM_KILLFOCUS: {
3570 OnLeave(EventArgs.Empty);
3571 if (CausesValidation) {
3573 e = new CancelEventArgs(false);
3582 OnValidated(EventArgs.Empty);
3585 this.has_focus = false;
3586 this.is_selected = false;
3587 OnLostFocus(EventArgs.Empty);
3591 case Msg.WM_SETFOCUS: {
3592 OnEnter(EventArgs.Empty);
3593 this.has_focus = true;
3594 OnGotFocus(EventArgs.Empty);
3599 case Msg.WM_SYSCOLORCHANGE: {
3600 ThemeEngine.Current.ResetDefaults();
3601 OnSystemColorsChanged(EventArgs.Empty);
3606 case Msg.WM_SETCURSOR: {
3607 if (cursor == null) {
3612 XplatUI.SetCursor(window.Handle, cursor.handle);
3613 m.Result = (IntPtr)1;
3624 #endregion // Public Instance Methods
3626 #region OnXXX methods
3627 [EditorBrowsable(EditorBrowsableState.Advanced)]
3628 protected virtual void OnBackColorChanged(EventArgs e) {
3629 if (BackColorChanged!=null) BackColorChanged(this, e);
3630 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackColorChanged(e);
3633 [EditorBrowsable(EditorBrowsableState.Advanced)]
3634 protected virtual void OnBackgroundImageChanged(EventArgs e) {
3635 if (BackgroundImageChanged!=null) BackgroundImageChanged(this, e);
3636 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackgroundImageChanged(e);
3639 [EditorBrowsable(EditorBrowsableState.Advanced)]
3640 protected virtual void OnBindingContextChanged(EventArgs e) {
3641 CheckDataBindings ();
3642 if (BindingContextChanged!=null) {
3643 BindingContextChanged(this, e);
3645 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBindingContextChanged(e);
3648 [EditorBrowsable(EditorBrowsableState.Advanced)]
3649 protected virtual void OnCausesValidationChanged(EventArgs e) {
3650 if (CausesValidationChanged!=null) CausesValidationChanged(this, e);
3653 [EditorBrowsable(EditorBrowsableState.Advanced)]
3654 protected virtual void OnChangeUICues(UICuesEventArgs e) {
3655 if (ChangeUICues!=null) ChangeUICues(this, e);
3658 [EditorBrowsable(EditorBrowsableState.Advanced)]
3659 protected virtual void OnClick(EventArgs e) {
3660 if (Click!=null) Click(this, e);
3663 [EditorBrowsable(EditorBrowsableState.Advanced)]
3664 protected virtual void OnContextMenuChanged(EventArgs e) {
3665 if (ContextMenuChanged!=null) ContextMenuChanged(this, e);
3668 [EditorBrowsable(EditorBrowsableState.Advanced)]
3669 protected virtual void OnControlAdded(ControlEventArgs e) {
3670 if (ControlAdded!=null) ControlAdded(this, e);
3673 [EditorBrowsable(EditorBrowsableState.Advanced)]
3674 protected virtual void OnControlRemoved(ControlEventArgs e) {
3675 if (ControlRemoved!=null) ControlRemoved(this, e);
3678 [EditorBrowsable(EditorBrowsableState.Advanced)]
3679 protected virtual void OnCreateControl() {
3683 [EditorBrowsable(EditorBrowsableState.Advanced)]
3684 protected virtual void OnCursorChanged(EventArgs e) {
3685 if (CursorChanged!=null) CursorChanged(this, e);
3688 [EditorBrowsable(EditorBrowsableState.Advanced)]
3689 protected virtual void OnDockChanged(EventArgs e) {
3690 if (DockChanged!=null) DockChanged(this, e);
3693 [EditorBrowsable(EditorBrowsableState.Advanced)]
3694 protected virtual void OnDoubleClick(EventArgs e) {
3695 if (DoubleClick!=null) DoubleClick(this, e);
3698 [EditorBrowsable(EditorBrowsableState.Advanced)]
3699 protected virtual void OnDragDrop(DragEventArgs drgevent) {
3700 if (DragDrop!=null) DragDrop(this, drgevent);
3703 [EditorBrowsable(EditorBrowsableState.Advanced)]
3704 protected virtual void OnDragEnter(DragEventArgs drgevent) {
3705 if (DragEnter!=null) DragEnter(this, drgevent);
3708 [EditorBrowsable(EditorBrowsableState.Advanced)]
3709 protected virtual void OnDragLeave(EventArgs e) {
3710 if (DragLeave!=null) DragLeave(this, e);
3713 [EditorBrowsable(EditorBrowsableState.Advanced)]
3714 protected virtual void OnDragOver(DragEventArgs drgevent) {
3715 if (DragOver!=null) DragOver(this, drgevent);
3718 [EditorBrowsable(EditorBrowsableState.Advanced)]
3719 protected virtual void OnEnabledChanged(EventArgs e) {
3720 if (EnabledChanged!=null) EnabledChanged(this, e);
3721 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentEnabledChanged(e);
3724 [EditorBrowsable(EditorBrowsableState.Advanced)]
3725 protected virtual void OnEnter(EventArgs e) {
3726 if (Enter!=null) Enter(this, e);
3729 [EditorBrowsable(EditorBrowsableState.Advanced)]
3730 protected virtual void OnFontChanged(EventArgs e) {
3731 if (FontChanged!=null) FontChanged(this, e);
3732 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentFontChanged(e);
3735 [EditorBrowsable(EditorBrowsableState.Advanced)]
3736 protected virtual void OnForeColorChanged(EventArgs e) {
3737 if (ForeColorChanged!=null) ForeColorChanged(this, e);
3738 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentForeColorChanged(e);
3741 [EditorBrowsable(EditorBrowsableState.Advanced)]
3742 protected virtual void OnGiveFeedback(GiveFeedbackEventArgs gfbevent) {
3743 if (GiveFeedback!=null) GiveFeedback(this, gfbevent);
3746 [EditorBrowsable(EditorBrowsableState.Advanced)]
3747 protected virtual void OnGotFocus(EventArgs e) {
3748 if (GotFocus!=null) GotFocus(this, e);
3751 [EditorBrowsable(EditorBrowsableState.Advanced)]
3752 protected virtual void OnHandleCreated(EventArgs e) {
3753 if (HandleCreated!=null) HandleCreated(this, e);
3756 [EditorBrowsable(EditorBrowsableState.Advanced)]
3757 protected virtual void OnHandleDestroyed(EventArgs e) {
3758 if (HandleDestroyed!=null) HandleDestroyed(this, e);
3761 [EditorBrowsable(EditorBrowsableState.Advanced)]
3762 protected virtual void OnHelpRequested(HelpEventArgs hevent) {
3763 if (HelpRequested!=null) HelpRequested(this, hevent);
3766 protected virtual void OnImeModeChanged(EventArgs e) {
3767 if (ImeModeChanged!=null) ImeModeChanged(this, e);
3770 [EditorBrowsable(EditorBrowsableState.Advanced)]
3771 protected virtual void OnInvalidated(InvalidateEventArgs e) {
3772 needs_redraw = true;
3773 if (Invalidated!=null) Invalidated(this, e);
3776 [EditorBrowsable(EditorBrowsableState.Advanced)]
3777 protected virtual void OnKeyDown(KeyEventArgs e) {
3778 if (KeyDown!=null) KeyDown(this, e);
3781 [EditorBrowsable(EditorBrowsableState.Advanced)]
3782 protected virtual void OnKeyPress(KeyPressEventArgs e) {
3783 if (KeyPress!=null) KeyPress(this, e);
3786 [EditorBrowsable(EditorBrowsableState.Advanced)]
3787 protected virtual void OnKeyUp(KeyEventArgs e) {
3788 if (KeyUp!=null) KeyUp(this, e);
3791 [EditorBrowsable(EditorBrowsableState.Advanced)]
3792 protected virtual void OnLayout(LayoutEventArgs levent) {
3793 if (Layout!=null) Layout(this, levent);
3796 [EditorBrowsable(EditorBrowsableState.Advanced)]
3797 protected virtual void OnLeave(EventArgs e) {
3798 if (Leave!=null) Leave(this, e);
3801 [EditorBrowsable(EditorBrowsableState.Advanced)]
3802 protected virtual void OnLocationChanged(EventArgs e) {
3804 if (LocationChanged!=null) LocationChanged(this, e);
3807 [EditorBrowsable(EditorBrowsableState.Advanced)]
3808 protected virtual void OnLostFocus(EventArgs e) {
3809 if (LostFocus!=null) LostFocus(this, e);
3812 [EditorBrowsable(EditorBrowsableState.Advanced)]
3813 protected virtual void OnMouseDown(MouseEventArgs e) {
3814 if (MouseDown!=null) MouseDown(this, e);
3817 [EditorBrowsable(EditorBrowsableState.Advanced)]
3818 protected virtual void OnMouseEnter(EventArgs e) {
3819 if (MouseEnter!=null) MouseEnter(this, e);
3822 [EditorBrowsable(EditorBrowsableState.Advanced)]
3823 protected virtual void OnMouseHover(EventArgs e) {
3824 if (MouseHover!=null) MouseHover(this, e);
3827 [EditorBrowsable(EditorBrowsableState.Advanced)]
3828 protected virtual void OnMouseLeave(EventArgs e) {
3829 if (MouseLeave!=null) MouseLeave(this, e);
3832 [EditorBrowsable(EditorBrowsableState.Advanced)]
3833 protected virtual void OnMouseMove(MouseEventArgs e) {
3834 if (MouseMove!=null) MouseMove(this, e);
3837 [EditorBrowsable(EditorBrowsableState.Advanced)]
3838 protected virtual void OnMouseUp(MouseEventArgs e) {
3839 if (MouseUp!=null) MouseUp(this, e);
3842 [EditorBrowsable(EditorBrowsableState.Advanced)]
3843 protected virtual void OnMouseWheel(MouseEventArgs e) {
3844 if (MouseWheel!=null) MouseWheel(this, e);
3847 [EditorBrowsable(EditorBrowsableState.Advanced)]
3848 protected virtual void OnMove(EventArgs e) {
3849 if (Move!=null) Move(this, e);
3852 [EditorBrowsable(EditorBrowsableState.Advanced)]
3853 protected virtual void OnNotifyMessage(Message m) {
3857 [EditorBrowsable(EditorBrowsableState.Advanced)]
3858 protected virtual void OnPaint(PaintEventArgs e) {
3859 if (Paint!=null) Paint(this, e);
3862 [EditorBrowsable(EditorBrowsableState.Advanced)]
3863 protected virtual void OnPaintBackground(PaintEventArgs pevent) {
3864 PaintControlBackground (pevent);
3867 [EditorBrowsable(EditorBrowsableState.Advanced)]
3868 protected virtual void OnParentBackColorChanged(EventArgs e) {
3869 if (background_color.IsEmpty && background_image==null) {
3871 OnBackColorChanged(e);
3875 [EditorBrowsable(EditorBrowsableState.Advanced)]
3876 protected virtual void OnParentBackgroundImageChanged(EventArgs e) {
3877 if (background_color.IsEmpty && background_image==null) {
3879 OnBackgroundImageChanged(e);
3883 [EditorBrowsable(EditorBrowsableState.Advanced)]
3884 protected virtual void OnParentBindingContextChanged(EventArgs e) {
3885 if (binding_context==null) {
3886 binding_context=Parent.binding_context;
3887 OnBindingContextChanged(e);
3891 [EditorBrowsable(EditorBrowsableState.Advanced)]
3892 protected virtual void OnParentChanged(EventArgs e) {
3893 if (ParentChanged!=null) ParentChanged(this, e);
3896 [EditorBrowsable(EditorBrowsableState.Advanced)]
3897 protected virtual void OnParentEnabledChanged(EventArgs e) {
3898 if (is_enabled != Parent.is_enabled) {
3899 is_enabled=Parent.is_enabled;
3901 if (EnabledChanged != null) {
3902 EnabledChanged(this, e);
3907 [EditorBrowsable(EditorBrowsableState.Advanced)]
3908 protected virtual void OnParentFontChanged(EventArgs e) {
3915 [EditorBrowsable(EditorBrowsableState.Advanced)]
3916 protected virtual void OnParentForeColorChanged(EventArgs e) {
3917 if (foreground_color.IsEmpty) {
3919 OnForeColorChanged(e);
3923 [EditorBrowsable(EditorBrowsableState.Advanced)]
3924 protected virtual void OnParentRightToLeftChanged(EventArgs e) {
3925 if (right_to_left==RightToLeft.Inherit) {
3927 OnRightToLeftChanged(e);
3931 [EditorBrowsable(EditorBrowsableState.Advanced)]
3932 protected virtual void OnParentVisibleChanged(EventArgs e) {
3934 OnVisibleChanged(e);
3938 [EditorBrowsable(EditorBrowsableState.Advanced)]
3939 protected virtual void OnQueryContinueDrag(QueryContinueDragEventArgs e) {
3940 if (QueryContinueDrag!=null) QueryContinueDrag(this, e);
3943 [EditorBrowsable(EditorBrowsableState.Advanced)]
3944 protected virtual void OnResize(EventArgs e) {
3945 if (Resize!=null) Resize(this, e);
3947 PerformLayout(this, "bounds");
3949 if (parent != null) {
3950 parent.PerformLayout();
3954 [EditorBrowsable(EditorBrowsableState.Advanced)]
3955 protected virtual void OnRightToLeftChanged(EventArgs e) {
3956 if (RightToLeftChanged!=null) RightToLeftChanged(this, e);
3957 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentRightToLeftChanged(e);
3960 [EditorBrowsable(EditorBrowsableState.Advanced)]
3961 protected virtual void OnSizeChanged(EventArgs e) {
3962 InvalidateBuffers ();
3964 if (SizeChanged!=null) SizeChanged(this, e);
3967 [EditorBrowsable(EditorBrowsableState.Advanced)]
3968 protected virtual void OnStyleChanged(EventArgs e) {
3969 if (StyleChanged!=null) StyleChanged(this, e);
3972 [EditorBrowsable(EditorBrowsableState.Advanced)]
3973 protected virtual void OnSystemColorsChanged(EventArgs e) {
3974 if (SystemColorsChanged!=null) SystemColorsChanged(this, e);
3977 [EditorBrowsable(EditorBrowsableState.Advanced)]
3978 protected virtual void OnTabIndexChanged(EventArgs e) {
3979 if (TabIndexChanged!=null) TabIndexChanged(this, e);
3982 [EditorBrowsable(EditorBrowsableState.Advanced)]
3983 protected virtual void OnTabStopChanged(EventArgs e) {
3984 if (TabStopChanged!=null) TabStopChanged(this, e);
3987 [EditorBrowsable(EditorBrowsableState.Advanced)]
3988 protected virtual void OnTextChanged(EventArgs e) {
3989 if (TextChanged!=null) TextChanged(this, e);
3992 [EditorBrowsable(EditorBrowsableState.Advanced)]
3993 protected virtual void OnValidated(EventArgs e) {
3994 if (Validated!=null) Validated(this, e);
3997 [EditorBrowsable(EditorBrowsableState.Advanced)]
3998 protected virtual void OnValidating(System.ComponentModel.CancelEventArgs e) {
3999 if (Validating!=null) Validating(this, e);
4002 [EditorBrowsable(EditorBrowsableState.Advanced)]
4003 protected virtual void OnVisibleChanged(EventArgs e) {
4010 if (bmp_mem!=null) {
4016 if (!this.IsHandleCreated) {
4017 this.CreateControl();
4023 if (VisibleChanged!=null) VisibleChanged(this, e);
4025 // We need to tell our kids
4026 for (int i=0; i<child_controls.Count; i++) {
4027 child_controls[i].OnParentVisibleChanged(e);
4030 #endregion // OnXXX methods
4033 public event EventHandler BackColorChanged;
4034 public event EventHandler BackgroundImageChanged;
4035 public event EventHandler BindingContextChanged;
4036 public event EventHandler CausesValidationChanged;
4037 public event UICuesEventHandler ChangeUICues;
4038 public event EventHandler Click;
4039 public event EventHandler ContextMenuChanged;
4041 [EditorBrowsable(EditorBrowsableState.Advanced)]
4043 public event ControlEventHandler ControlAdded;
4045 [EditorBrowsable(EditorBrowsableState.Advanced)]
4047 public event ControlEventHandler ControlRemoved;
4049 [MWFDescription("Fired when the cursor for the control has been changed"), MWFCategory("PropertyChanged")]
4050 public event EventHandler CursorChanged;
4051 public event EventHandler DockChanged;
4052 public event EventHandler DoubleClick;
4053 public event DragEventHandler DragDrop;
4054 public event DragEventHandler DragEnter;
4055 public event EventHandler DragLeave;
4056 public event DragEventHandler DragOver;
4057 public event EventHandler EnabledChanged;
4058 public event EventHandler Enter;
4059 public event EventHandler FontChanged;
4060 public event EventHandler ForeColorChanged;
4061 public event GiveFeedbackEventHandler GiveFeedback;
4063 [EditorBrowsable(EditorBrowsableState.Advanced)]
4065 public event EventHandler GotFocus;
4067 [EditorBrowsable(EditorBrowsableState.Advanced)]
4069 public event EventHandler HandleCreated;
4071 [EditorBrowsable(EditorBrowsableState.Advanced)]
4073 public event EventHandler HandleDestroyed;
4075 public event HelpEventHandler HelpRequested;
4076 public event EventHandler ImeModeChanged;
4078 [EditorBrowsable(EditorBrowsableState.Advanced)]
4080 public event InvalidateEventHandler Invalidated;
4082 public event KeyEventHandler KeyDown;
4083 public event KeyPressEventHandler KeyPress;
4084 public event KeyEventHandler KeyUp;
4085 public event LayoutEventHandler Layout;
4086 public event EventHandler Leave;
4087 public event EventHandler LocationChanged;
4089 [EditorBrowsable(EditorBrowsableState.Advanced)]
4091 public event EventHandler LostFocus;
4093 public event MouseEventHandler MouseDown;
4094 public event EventHandler MouseEnter;
4095 public event EventHandler MouseHover;
4096 public event EventHandler MouseLeave;
4097 public event MouseEventHandler MouseMove;
4098 public event MouseEventHandler MouseUp;
4100 [EditorBrowsable(EditorBrowsableState.Advanced)]
4102 public event MouseEventHandler MouseWheel;
4104 public event EventHandler Move;
4105 public event PaintEventHandler Paint;
4106 public event EventHandler ParentChanged;
4107 public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp;
4108 public event QueryContinueDragEventHandler QueryContinueDrag;
4109 public event EventHandler Resize;
4110 public event EventHandler RightToLeftChanged;
4111 public event EventHandler SizeChanged;
4112 public event EventHandler StyleChanged;
4113 public event EventHandler SystemColorsChanged;
4114 public event EventHandler TabIndexChanged;
4115 public event EventHandler TabStopChanged;
4116 public event EventHandler TextChanged;
4117 public event EventHandler Validated;
4118 public event CancelEventHandler Validating;
4119 public event EventHandler VisibleChanged;
4120 #endregion // Events