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 if (IsHandleCreated) {
2700 XplatUI.UpdateWindow(window.Handle);
2703 #endregion // Public Instance Methods
2705 #region Protected Instance Methods
2706 [EditorBrowsable(EditorBrowsableState.Advanced)]
2707 [MonoTODO("Implement this and tie it into Control.ControlAccessibleObject.NotifyClients")]
2708 protected void AccessibilityNotifyClients(AccessibleEvents accEvent, int childID) {
2709 throw new NotImplementedException();
2712 [EditorBrowsable(EditorBrowsableState.Advanced)]
2713 protected virtual AccessibleObject CreateAccessibilityInstance() {
2714 return new Control.ControlAccessibleObject(this);
2717 [EditorBrowsable(EditorBrowsableState.Advanced)]
2718 protected virtual ControlCollection CreateControlsInstance() {
2719 return new ControlCollection(this);
2722 [EditorBrowsable(EditorBrowsableState.Advanced)]
2723 protected virtual void CreateHandle() {
2725 throw new ObjectDisposedException(Name);
2728 if (IsHandleCreated) {
2732 window.CreateHandle(CreateParams);
2734 // Find out where the window manager placed us
2738 if (window.Handle!=IntPtr.Zero) {
2739 if (!controls.Contains(window.Handle)) {
2743 creator_thread = Thread.CurrentThread;
2745 if (!GetStyle (ControlStyles.UserPaint)) {
2746 XplatUI.SetWindowBackground(window.Handle, this.BackColor);
2749 OnHandleCreated(EventArgs.Empty);
2753 [EditorBrowsable(EditorBrowsableState.Advanced)]
2754 protected virtual void DefWndProc(ref Message m) {
2755 window.DefWndProc(ref m);
2758 [EditorBrowsable(EditorBrowsableState.Advanced)]
2759 protected virtual void DestroyHandle() {
2760 if (IsHandleCreated) {
2761 // Destroy our children before we destroy ourselves, to prevent them from
2762 // being implictly (without us knowing) destroyed
2763 for (int i=0; i < child_controls.Count; i++) {
2764 child_controls[i].DestroyHandle();
2768 if (window != null) {
2769 window.DestroyHandle();
2771 OnHandleDestroyed(EventArgs.Empty);
2775 protected bool GetStyle(ControlStyles flag) {
2776 return (control_style & flag) != 0;
2779 protected bool GetTopLevel() {
2783 [EditorBrowsable(EditorBrowsableState.Advanced)]
2784 protected virtual void InitLayout() {
2785 if (parent != null) {
2786 parent.PerformLayout(this, "parent");
2790 [EditorBrowsable(EditorBrowsableState.Advanced)]
2791 protected void InvokeGotFocus(Control toInvoke, EventArgs e) {
2792 toInvoke.OnGotFocus(e);
2795 [EditorBrowsable(EditorBrowsableState.Advanced)]
2796 protected void InvokeLostFocus(Control toInvoke, EventArgs e) {
2797 toInvoke.OnLostFocus(e);
2800 [EditorBrowsable(EditorBrowsableState.Advanced)]
2801 protected void InvokeOnClick(Control toInvoke, EventArgs e) {
2802 toInvoke.OnClick(e);
2805 protected void InvokePaint(Control toInvoke, PaintEventArgs e) {
2806 toInvoke.OnPaint(e);
2809 protected void InvokePaintBackground(Control toInvoke, PaintEventArgs e) {
2810 toInvoke.OnPaintBackground(e);
2813 protected virtual bool IsInputChar (char charCode) {
2814 if (parent != null) {
2815 return parent.IsInputChar(charCode);
2821 protected virtual bool IsInputKey (Keys keyData) {
2822 // Doc says this one calls IsInputChar; not sure what to do with that
2826 [EditorBrowsable(EditorBrowsableState.Advanced)]
2827 protected virtual void NotifyInvalidate(Rectangle invalidatedArea) {
2831 protected virtual bool ProcessCmdKey(ref Message msg, Keys keyData) {
2832 if ((context_menu != null) && context_menu.ProcessCmdKey(ref msg, keyData)) {
2836 if (parent != null) {
2837 return parent.ProcessCmdKey(ref msg, keyData);
2843 protected virtual bool ProcessDialogChar(char charCode) {
2844 if (parent != null) {
2845 return parent.ProcessDialogChar (charCode);
2851 protected virtual bool ProcessDialogKey (Keys keyData) {
2852 if (parent != null) {
2853 return parent.ProcessDialogKey (keyData);
2859 protected virtual bool ProcessKeyEventArgs (ref Message msg)
2861 KeyEventArgs key_event;
2864 case (int)Msg.WM_KEYDOWN: {
2865 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
2866 OnKeyDown (key_event);
2867 return key_event.Handled;
2869 case (int)Msg.WM_KEYUP: {
2870 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
2871 OnKeyUp (key_event);
2872 return key_event.Handled;
2875 case (int)Msg.WM_CHAR: {
2876 KeyPressEventArgs key_press_event;
2878 key_press_event = new KeyPressEventArgs((char)msg.WParam);
2879 OnKeyPress(key_press_event);
2880 return key_press_event.Handled;
2891 protected internal virtual bool ProcessKeyMessage(ref Message msg) {
2892 if (parent != null) {
2893 if (parent.ProcessKeyPreview(ref msg)) {
2901 protected virtual bool ProcessKeyPreview(ref Message msg) {
2902 if (parent != null) {
2903 return parent.ProcessKeyPreview(ref msg);
2909 protected virtual bool ProcessMnemonic(char charCode) {
2914 [EditorBrowsable(EditorBrowsableState.Advanced)]
2915 protected void RaiseDragEvent(object key, DragEventArgs e) {
2919 [EditorBrowsable(EditorBrowsableState.Advanced)]
2920 protected void RaiseKeyEvent(object key, KeyEventArgs e) {
2924 [EditorBrowsable(EditorBrowsableState.Advanced)]
2925 protected void RaiseMouseEvent(object key, MouseEventArgs e) {
2929 [EditorBrowsable(EditorBrowsableState.Advanced)]
2930 protected void RaisePaintEvent(object key, PaintEventArgs e) {
2934 [EditorBrowsable(EditorBrowsableState.Advanced)]
2935 protected void RecreateHandle() {
2936 IEnumerator child = child_controls.GetEnumerator();
2940 if (IsHandleCreated) {
2946 while (child.MoveNext()) {
2947 ((Control)child.Current).RecreateHandle();
2953 is_recreating = false;
2956 [EditorBrowsable(EditorBrowsableState.Advanced)]
2957 protected void ResetMouseEventArgs() {
2961 [EditorBrowsable(EditorBrowsableState.Advanced)]
2962 protected ContentAlignment RtlTranslateAlignment(ContentAlignment align) {
2963 if (right_to_left == RightToLeft.No) {
2968 case ContentAlignment.TopLeft: {
2969 return ContentAlignment.TopRight;
2972 case ContentAlignment.TopRight: {
2973 return ContentAlignment.TopLeft;
2976 case ContentAlignment.MiddleLeft: {
2977 return ContentAlignment.MiddleRight;
2980 case ContentAlignment.MiddleRight: {
2981 return ContentAlignment.MiddleLeft;
2984 case ContentAlignment.BottomLeft: {
2985 return ContentAlignment.BottomRight;
2988 case ContentAlignment.BottomRight: {
2989 return ContentAlignment.BottomLeft;
2993 // if it's center it doesn't change
2999 [EditorBrowsable(EditorBrowsableState.Advanced)]
3000 protected HorizontalAlignment RtlTranslateAlignment(HorizontalAlignment align) {
3001 if ((right_to_left == RightToLeft.No) || (align == HorizontalAlignment.Center)) {
3005 if (align == HorizontalAlignment.Left) {
3006 return HorizontalAlignment.Right;
3009 // align must be HorizontalAlignment.Right
3010 return HorizontalAlignment.Left;
3013 [EditorBrowsable(EditorBrowsableState.Advanced)]
3014 protected LeftRightAlignment RtlTranslateAlignment(LeftRightAlignment align) {
3015 if (right_to_left == RightToLeft.No) {
3019 if (align == LeftRightAlignment.Left) {
3020 return LeftRightAlignment.Right;
3023 // align must be LeftRightAlignment.Right;
3024 return LeftRightAlignment.Left;
3027 [EditorBrowsable(EditorBrowsableState.Advanced)]
3028 protected ContentAlignment RtlTranslateContent(ContentAlignment align) {
3029 return RtlTranslateAlignment(align);
3032 [EditorBrowsable(EditorBrowsableState.Advanced)]
3033 protected HorizontalAlignment RtlTranslateHorizontal(HorizontalAlignment align) {
3034 return RtlTranslateAlignment(align);
3037 [EditorBrowsable(EditorBrowsableState.Advanced)]
3038 protected LeftRightAlignment RtlTranslateLeftRight(LeftRightAlignment align) {
3039 return RtlTranslateAlignment(align);
3042 [EditorBrowsable(EditorBrowsableState.Advanced)]
3043 protected virtual void ScaleCore(float dx, float dy) {
3049 location = new Point((int)(Left * dx), (int)(Top * dy));
3050 size = this.ClientSize;
3053 if (!GetStyle(ControlStyles.FixedWidth)) {
3054 size.Width = (int)(size.Width * dx);
3057 if (!GetStyle(ControlStyles.FixedHeight)) {
3058 size.Height = (int)(size.Height * dy);
3061 Location = location;
3064 /* Now scale our children */
3065 for (int i=0; i < child_controls.Count; i++) {
3066 child_controls[i].Scale(dx, dy);
3072 protected virtual void Select(bool directed, bool forward) {
3077 // Select this control
3082 if (parent == null) {
3086 // FIXME - this thing is doing the wrong stuff, needs to be similar to SelectNextControl
3088 index = parent.child_controls.IndexOf(this);
3093 if ((index+1) < parent.child_controls.Count) {
3102 index = parent.child_controls.Count-1;
3105 result = Select(parent.child_controls[index]);
3106 } while (!result && parent.child_controls[index] != this);
3109 [EditorBrowsable(EditorBrowsableState.Advanced)]
3110 protected virtual void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
3111 // SetBoundsCore updates the Win32 control itself. UpdateBounds updates the controls variables and fires events, I'm guessing - pdb
3112 if ((specified & BoundsSpecified.X) != BoundsSpecified.X) {
3116 if ((specified & BoundsSpecified.Y) != BoundsSpecified.Y) {
3120 if ((specified & BoundsSpecified.Width) != BoundsSpecified.Width) {
3124 if ((specified & BoundsSpecified.Height) != BoundsSpecified.Height) {
3128 if (IsHandleCreated) {
3129 XplatUI.SetWindowPos(Handle, x, y, width, height);
3131 UpdateBounds(x, y, width, height);
3134 [EditorBrowsable(EditorBrowsableState.Advanced)]
3135 protected virtual void SetClientSizeCore(int x, int y) {
3136 // Calculate the actual window size from the client size (it usually stays the same or grows)
3137 Rectangle ClientRect;
3138 Rectangle WindowRect;
3141 ClientRect = new Rectangle(0, 0, x, y);
3142 cp = this.CreateParams;
3144 if (XplatUI.CalculateWindowRect(Handle, ref ClientRect, cp.Style, cp.ExStyle, IntPtr.Zero, out WindowRect)==false) {
3148 SetBoundsCore(bounds.X, bounds.Y, WindowRect.Width, WindowRect.Height, BoundsSpecified.Size);
3151 [EditorBrowsable(EditorBrowsableState.Advanced)]
3152 protected void SetStyle(ControlStyles flag, bool value) {
3154 control_style |= flag;
3156 control_style &= ~flag;
3158 OnStyleChanged(EventArgs.Empty);
3161 protected void SetTopLevel(bool value) {
3162 if ((GetTopLevel() != value) && (parent != null)) {
3163 throw new Exception();
3167 if (value == true) {
3177 is_toplevel = value;
3180 protected virtual void SetVisibleCore(bool value) {
3181 if (value!=is_visible) {
3184 if (IsHandleCreated) {
3185 XplatUI.SetVisible(Handle, value);
3186 // Explicitly move Toplevel windows to where we want them;
3187 // apparently moving unmapped toplevel windows doesn't work
3188 if (is_visible && (this is Form)) {
3189 XplatUI.SetWindowPos(window.Handle, bounds.X, bounds.Y, bounds.Width, bounds.Height);
3193 OnVisibleChanged(EventArgs.Empty);
3196 if (dc_mem != null) {
3201 if (bmp_mem != null) {
3206 this.CreateBuffers(bounds.Width, bounds.Height);
3210 if (value == false && parent != null) {
3213 // Need to start at parent, GetContainerControl might return ourselves if we're a container
3214 container = (Control)parent.GetContainerControl();
3215 if (container != null) {
3216 container.SelectNextControl(this, true, true, true, true);
3220 if (parent != null) {
3221 parent.PerformLayout(this, "visible");
3223 PerformLayout(this, "visible");
3228 [EditorBrowsable(EditorBrowsableState.Advanced)]
3229 protected void UpdateBounds() {
3237 if (!IsHandleCreated) {
3241 XplatUI.GetWindowPos(this.Handle, this is Form, out x, out y, out width, out height, out client_width, out client_height);
3243 UpdateBounds(x, y, width, height, client_width, client_height);
3246 [EditorBrowsable(EditorBrowsableState.Advanced)]
3247 protected void UpdateBounds(int x, int y, int width, int height) {
3248 // UpdateBounds only seems to set our sizes and fire events but not update the GUI window to match
3250 bool resized = false;
3252 int client_x_diff = this.bounds.Width-this.client_size.Width;
3253 int client_y_diff = this.bounds.Height-this.client_size.Height;
3255 // Needed to generate required notifications
3256 if ((this.bounds.X!=x) || (this.bounds.Y!=y)) {
3260 if ((this.Bounds.Width!=width) || (this.Bounds.Height!=height)) {
3267 bounds.Height=height;
3269 // Update client rectangle as well
3270 if (this.layout_suspended==0) {
3271 prev_size.Width=client_size.Width;
3272 prev_size.Height=client_size.Height;
3275 client_size.Width=width-client_x_diff;
3276 client_size.Height=height-client_y_diff;
3279 OnLocationChanged(EventArgs.Empty);
3283 OnSizeChanged(EventArgs.Empty);
3287 [EditorBrowsable(EditorBrowsableState.Advanced)]
3288 protected void UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) {
3289 UpdateBounds(x, y, width, height);
3291 this.client_size.Width=clientWidth;
3292 this.client_size.Height=clientHeight;
3295 [EditorBrowsable(EditorBrowsableState.Advanced)]
3296 protected void UpdateStyles() {
3297 if (!IsHandleCreated) {
3301 XplatUI.SetWindowStyle(window.Handle, CreateParams);
3304 [EditorBrowsable(EditorBrowsableState.Advanced)]
3305 protected void UpdateZOrder() {
3310 if (parent == null) {
3316 children = ctl.child_controls.Count;
3317 for (int i = 1; i < children; i++ ) {
3318 XplatUI.SetZOrder(ctl.child_controls[i].window.Handle, ctl.child_controls[i-1].window.Handle, false, false);
3321 if (!IsHandleCreated) {
3325 children = child_controls.Count;
3326 for (int i = 1; i < children; i++ ) {
3327 XplatUI.SetZOrder(child_controls[i].Handle, child_controls[i-1].Handle, false, false);
3332 protected virtual void WndProc(ref Message m) {
3334 Console.WriteLine("Control received message {0}", (Msg)m.Msg);
3336 if ((this.control_style & ControlStyles.EnableNotifyMessage) != 0) {
3340 switch((Msg)m.Msg) {
3341 case Msg.WM_WINDOWPOSCHANGED: {
3344 if (GetStyle(ControlStyles.ResizeRedraw)) {
3351 case Msg.WM_PAINT: {
3352 PaintEventArgs paint_event;
3354 paint_event = XplatUI.PaintEventStart(Handle, true);
3356 if (!needs_redraw) {
3357 // Just blit the previous image
3358 paint_event.Graphics.DrawImage (ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle, GraphicsUnit.Pixel);
3359 XplatUI.PaintEventEnd(Handle, true);
3364 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
3365 dc = paint_event.SetGraphics (DeviceContext);
3368 if ((control_style & (ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint)) != (ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint)) {
3369 OnPaintBackground(paint_event);
3372 OnPaint(paint_event);
3374 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
3375 dc.DrawImage (ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle, GraphicsUnit.Pixel);
3376 paint_event.SetGraphics (dc);
3377 needs_redraw = false;
3380 XplatUI.PaintEventEnd(Handle, true);
3382 if (!GetStyle(ControlStyles.UserPaint)) {
3389 case Msg.WM_ERASEBKGND: {
3390 if (GetStyle (ControlStyles.UserPaint)) {
3391 if (!GetStyle(ControlStyles.AllPaintingInWmPaint)) {
3392 PaintEventArgs eraseEventArgs = new PaintEventArgs (m.WParam == IntPtr.Zero ? Graphics.FromHwnd (m.HWnd) :
3393 Graphics.FromHdc (m.WParam), new Rectangle (new Point (0,0),Size));
3394 OnPaintBackground (eraseEventArgs);
3397 XplatUI.EraseWindowBackground(m.HWnd, m.WParam);
3399 // The DefWndProc will never have to handle this, we don't ever set hbr on the window
3400 m.Result = (IntPtr)1;
3404 case Msg.WM_LBUTTONUP: {
3405 HandleClick(mouse_clicks);
3406 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Left,
3408 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3410 if (mouse_clicks > 1) {
3416 case Msg.WM_LBUTTONDOWN: {
3417 if (CanSelect && !is_selected) {
3420 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3421 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3427 case Msg.WM_LBUTTONDBLCLK: {
3429 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3430 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3436 case Msg.WM_MBUTTONUP: {
3437 HandleClick(mouse_clicks);
3438 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Middle,
3440 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3442 if (mouse_clicks > 1) {
3448 case Msg.WM_MBUTTONDOWN: {
3449 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3450 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3456 case Msg.WM_MBUTTONDBLCLK: {
3458 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3459 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3464 case Msg.WM_RBUTTONUP: {
3465 if (context_menu != null) {
3466 context_menu.Show(this, new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ())));
3469 HandleClick(mouse_clicks);
3470 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Right,
3472 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3474 if (mouse_clicks > 1) {
3480 case Msg.WM_RBUTTONDOWN: {
3481 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3482 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3487 case Msg.WM_RBUTTONDBLCLK: {
3489 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3490 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3495 case Msg.WM_MOUSEWHEEL: {
3497 OnMouseWheel (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3498 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3499 HighOrder(m.WParam.ToInt32())));
3504 case Msg.WM_MOUSEMOVE: {
3505 OnMouseMove (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3507 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3512 case Msg.WM_MOUSE_ENTER: {
3517 OnMouseEnter(EventArgs.Empty);
3521 case Msg.WM_MOUSE_LEAVE: {
3523 OnMouseLeave(EventArgs.Empty);
3527 case Msg.WM_MOUSEHOVER: {
3528 OnMouseHover(EventArgs.Empty);
3532 case Msg.WM_SYSKEYDOWN:
3533 case Msg.WM_KEYDOWN:
3534 case Msg.WM_SYSKEYUP:
3536 case Msg.WM_SYSCHAR:
3538 Console.WriteLine("Got {0}", (Msg)m.Msg);
3539 if (ProcessKeyEventArgs(ref m)) {
3543 if (PreProcessMessage(ref m)) {
3547 if (ProcessKeyMessage(ref m)) {
3556 if (m.LParam != IntPtr.Zero) {
3559 hi = new HELPINFO();
3561 hi = (HELPINFO) Marshal.PtrToStructure (m.LParam, typeof (HELPINFO));
3562 mouse_pos = new Point(hi.MousePos.x, hi.MousePos.y);
3564 mouse_pos = Control.MousePosition;
3566 OnHelpRequested(new HelpEventArgs(mouse_pos));
3567 m.Result = (IntPtr)1;
3571 case Msg.WM_KILLFOCUS: {
3572 OnLeave(EventArgs.Empty);
3573 if (CausesValidation) {
3575 e = new CancelEventArgs(false);
3584 OnValidated(EventArgs.Empty);
3587 this.has_focus = false;
3588 this.is_selected = false;
3589 OnLostFocus(EventArgs.Empty);
3593 case Msg.WM_SETFOCUS: {
3594 OnEnter(EventArgs.Empty);
3595 this.has_focus = true;
3596 OnGotFocus(EventArgs.Empty);
3601 case Msg.WM_SYSCOLORCHANGE: {
3602 ThemeEngine.Current.ResetDefaults();
3603 OnSystemColorsChanged(EventArgs.Empty);
3608 case Msg.WM_SETCURSOR: {
3609 if (cursor == null) {
3614 XplatUI.SetCursor(window.Handle, cursor.handle);
3615 m.Result = (IntPtr)1;
3626 #endregion // Public Instance Methods
3628 #region OnXXX methods
3629 [EditorBrowsable(EditorBrowsableState.Advanced)]
3630 protected virtual void OnBackColorChanged(EventArgs e) {
3631 if (BackColorChanged!=null) BackColorChanged(this, e);
3632 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackColorChanged(e);
3635 [EditorBrowsable(EditorBrowsableState.Advanced)]
3636 protected virtual void OnBackgroundImageChanged(EventArgs e) {
3637 if (BackgroundImageChanged!=null) BackgroundImageChanged(this, e);
3638 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackgroundImageChanged(e);
3641 [EditorBrowsable(EditorBrowsableState.Advanced)]
3642 protected virtual void OnBindingContextChanged(EventArgs e) {
3643 CheckDataBindings ();
3644 if (BindingContextChanged!=null) {
3645 BindingContextChanged(this, e);
3647 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBindingContextChanged(e);
3650 [EditorBrowsable(EditorBrowsableState.Advanced)]
3651 protected virtual void OnCausesValidationChanged(EventArgs e) {
3652 if (CausesValidationChanged!=null) CausesValidationChanged(this, e);
3655 [EditorBrowsable(EditorBrowsableState.Advanced)]
3656 protected virtual void OnChangeUICues(UICuesEventArgs e) {
3657 if (ChangeUICues!=null) ChangeUICues(this, e);
3660 [EditorBrowsable(EditorBrowsableState.Advanced)]
3661 protected virtual void OnClick(EventArgs e) {
3662 if (Click!=null) Click(this, e);
3665 [EditorBrowsable(EditorBrowsableState.Advanced)]
3666 protected virtual void OnContextMenuChanged(EventArgs e) {
3667 if (ContextMenuChanged!=null) ContextMenuChanged(this, e);
3670 [EditorBrowsable(EditorBrowsableState.Advanced)]
3671 protected virtual void OnControlAdded(ControlEventArgs e) {
3672 if (ControlAdded!=null) ControlAdded(this, e);
3675 [EditorBrowsable(EditorBrowsableState.Advanced)]
3676 protected virtual void OnControlRemoved(ControlEventArgs e) {
3677 if (ControlRemoved!=null) ControlRemoved(this, e);
3680 [EditorBrowsable(EditorBrowsableState.Advanced)]
3681 protected virtual void OnCreateControl() {
3685 [EditorBrowsable(EditorBrowsableState.Advanced)]
3686 protected virtual void OnCursorChanged(EventArgs e) {
3687 if (CursorChanged!=null) CursorChanged(this, e);
3690 [EditorBrowsable(EditorBrowsableState.Advanced)]
3691 protected virtual void OnDockChanged(EventArgs e) {
3692 if (DockChanged!=null) DockChanged(this, e);
3695 [EditorBrowsable(EditorBrowsableState.Advanced)]
3696 protected virtual void OnDoubleClick(EventArgs e) {
3697 if (DoubleClick!=null) DoubleClick(this, e);
3700 [EditorBrowsable(EditorBrowsableState.Advanced)]
3701 protected virtual void OnDragDrop(DragEventArgs drgevent) {
3702 if (DragDrop!=null) DragDrop(this, drgevent);
3705 [EditorBrowsable(EditorBrowsableState.Advanced)]
3706 protected virtual void OnDragEnter(DragEventArgs drgevent) {
3707 if (DragEnter!=null) DragEnter(this, drgevent);
3710 [EditorBrowsable(EditorBrowsableState.Advanced)]
3711 protected virtual void OnDragLeave(EventArgs e) {
3712 if (DragLeave!=null) DragLeave(this, e);
3715 [EditorBrowsable(EditorBrowsableState.Advanced)]
3716 protected virtual void OnDragOver(DragEventArgs drgevent) {
3717 if (DragOver!=null) DragOver(this, drgevent);
3720 [EditorBrowsable(EditorBrowsableState.Advanced)]
3721 protected virtual void OnEnabledChanged(EventArgs e) {
3722 if (EnabledChanged!=null) EnabledChanged(this, e);
3723 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentEnabledChanged(e);
3726 [EditorBrowsable(EditorBrowsableState.Advanced)]
3727 protected virtual void OnEnter(EventArgs e) {
3728 if (Enter!=null) Enter(this, e);
3731 [EditorBrowsable(EditorBrowsableState.Advanced)]
3732 protected virtual void OnFontChanged(EventArgs e) {
3733 if (FontChanged!=null) FontChanged(this, e);
3734 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentFontChanged(e);
3737 [EditorBrowsable(EditorBrowsableState.Advanced)]
3738 protected virtual void OnForeColorChanged(EventArgs e) {
3739 if (ForeColorChanged!=null) ForeColorChanged(this, e);
3740 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentForeColorChanged(e);
3743 [EditorBrowsable(EditorBrowsableState.Advanced)]
3744 protected virtual void OnGiveFeedback(GiveFeedbackEventArgs gfbevent) {
3745 if (GiveFeedback!=null) GiveFeedback(this, gfbevent);
3748 [EditorBrowsable(EditorBrowsableState.Advanced)]
3749 protected virtual void OnGotFocus(EventArgs e) {
3750 if (GotFocus!=null) GotFocus(this, e);
3753 [EditorBrowsable(EditorBrowsableState.Advanced)]
3754 protected virtual void OnHandleCreated(EventArgs e) {
3755 if (HandleCreated!=null) HandleCreated(this, e);
3758 [EditorBrowsable(EditorBrowsableState.Advanced)]
3759 protected virtual void OnHandleDestroyed(EventArgs e) {
3760 if (HandleDestroyed!=null) HandleDestroyed(this, e);
3763 [EditorBrowsable(EditorBrowsableState.Advanced)]
3764 protected virtual void OnHelpRequested(HelpEventArgs hevent) {
3765 if (HelpRequested!=null) HelpRequested(this, hevent);
3768 protected virtual void OnImeModeChanged(EventArgs e) {
3769 if (ImeModeChanged!=null) ImeModeChanged(this, e);
3772 [EditorBrowsable(EditorBrowsableState.Advanced)]
3773 protected virtual void OnInvalidated(InvalidateEventArgs e) {
3774 needs_redraw = true;
3775 if (Invalidated!=null) Invalidated(this, e);
3778 [EditorBrowsable(EditorBrowsableState.Advanced)]
3779 protected virtual void OnKeyDown(KeyEventArgs e) {
3780 if (KeyDown!=null) KeyDown(this, e);
3783 [EditorBrowsable(EditorBrowsableState.Advanced)]
3784 protected virtual void OnKeyPress(KeyPressEventArgs e) {
3785 if (KeyPress!=null) KeyPress(this, e);
3788 [EditorBrowsable(EditorBrowsableState.Advanced)]
3789 protected virtual void OnKeyUp(KeyEventArgs e) {
3790 if (KeyUp!=null) KeyUp(this, e);
3793 [EditorBrowsable(EditorBrowsableState.Advanced)]
3794 protected virtual void OnLayout(LayoutEventArgs levent) {
3795 if (Layout!=null) Layout(this, levent);
3798 [EditorBrowsable(EditorBrowsableState.Advanced)]
3799 protected virtual void OnLeave(EventArgs e) {
3800 if (Leave!=null) Leave(this, e);
3803 [EditorBrowsable(EditorBrowsableState.Advanced)]
3804 protected virtual void OnLocationChanged(EventArgs e) {
3806 if (LocationChanged!=null) LocationChanged(this, e);
3809 [EditorBrowsable(EditorBrowsableState.Advanced)]
3810 protected virtual void OnLostFocus(EventArgs e) {
3811 if (LostFocus!=null) LostFocus(this, e);
3814 [EditorBrowsable(EditorBrowsableState.Advanced)]
3815 protected virtual void OnMouseDown(MouseEventArgs e) {
3816 if (MouseDown!=null) MouseDown(this, e);
3819 [EditorBrowsable(EditorBrowsableState.Advanced)]
3820 protected virtual void OnMouseEnter(EventArgs e) {
3821 if (MouseEnter!=null) MouseEnter(this, e);
3824 [EditorBrowsable(EditorBrowsableState.Advanced)]
3825 protected virtual void OnMouseHover(EventArgs e) {
3826 if (MouseHover!=null) MouseHover(this, e);
3829 [EditorBrowsable(EditorBrowsableState.Advanced)]
3830 protected virtual void OnMouseLeave(EventArgs e) {
3831 if (MouseLeave!=null) MouseLeave(this, e);
3834 [EditorBrowsable(EditorBrowsableState.Advanced)]
3835 protected virtual void OnMouseMove(MouseEventArgs e) {
3836 if (MouseMove!=null) MouseMove(this, e);
3839 [EditorBrowsable(EditorBrowsableState.Advanced)]
3840 protected virtual void OnMouseUp(MouseEventArgs e) {
3841 if (MouseUp!=null) MouseUp(this, e);
3844 [EditorBrowsable(EditorBrowsableState.Advanced)]
3845 protected virtual void OnMouseWheel(MouseEventArgs e) {
3846 if (MouseWheel!=null) MouseWheel(this, e);
3849 [EditorBrowsable(EditorBrowsableState.Advanced)]
3850 protected virtual void OnMove(EventArgs e) {
3851 if (Move!=null) Move(this, e);
3854 [EditorBrowsable(EditorBrowsableState.Advanced)]
3855 protected virtual void OnNotifyMessage(Message m) {
3859 [EditorBrowsable(EditorBrowsableState.Advanced)]
3860 protected virtual void OnPaint(PaintEventArgs e) {
3861 if (Paint!=null) Paint(this, e);
3864 [EditorBrowsable(EditorBrowsableState.Advanced)]
3865 protected virtual void OnPaintBackground(PaintEventArgs pevent) {
3866 PaintControlBackground (pevent);
3869 [EditorBrowsable(EditorBrowsableState.Advanced)]
3870 protected virtual void OnParentBackColorChanged(EventArgs e) {
3871 if (background_color.IsEmpty && background_image==null) {
3873 OnBackColorChanged(e);
3877 [EditorBrowsable(EditorBrowsableState.Advanced)]
3878 protected virtual void OnParentBackgroundImageChanged(EventArgs e) {
3879 if (background_color.IsEmpty && background_image==null) {
3881 OnBackgroundImageChanged(e);
3885 [EditorBrowsable(EditorBrowsableState.Advanced)]
3886 protected virtual void OnParentBindingContextChanged(EventArgs e) {
3887 if (binding_context==null) {
3888 binding_context=Parent.binding_context;
3889 OnBindingContextChanged(e);
3893 [EditorBrowsable(EditorBrowsableState.Advanced)]
3894 protected virtual void OnParentChanged(EventArgs e) {
3895 if (ParentChanged!=null) ParentChanged(this, e);
3898 [EditorBrowsable(EditorBrowsableState.Advanced)]
3899 protected virtual void OnParentEnabledChanged(EventArgs e) {
3900 if (is_enabled != Parent.is_enabled) {
3901 is_enabled=Parent.is_enabled;
3903 if (EnabledChanged != null) {
3904 EnabledChanged(this, e);
3909 [EditorBrowsable(EditorBrowsableState.Advanced)]
3910 protected virtual void OnParentFontChanged(EventArgs e) {
3917 [EditorBrowsable(EditorBrowsableState.Advanced)]
3918 protected virtual void OnParentForeColorChanged(EventArgs e) {
3919 if (foreground_color.IsEmpty) {
3921 OnForeColorChanged(e);
3925 [EditorBrowsable(EditorBrowsableState.Advanced)]
3926 protected virtual void OnParentRightToLeftChanged(EventArgs e) {
3927 if (right_to_left==RightToLeft.Inherit) {
3929 OnRightToLeftChanged(e);
3933 [EditorBrowsable(EditorBrowsableState.Advanced)]
3934 protected virtual void OnParentVisibleChanged(EventArgs e) {
3936 OnVisibleChanged(e);
3940 [EditorBrowsable(EditorBrowsableState.Advanced)]
3941 protected virtual void OnQueryContinueDrag(QueryContinueDragEventArgs e) {
3942 if (QueryContinueDrag!=null) QueryContinueDrag(this, e);
3945 [EditorBrowsable(EditorBrowsableState.Advanced)]
3946 protected virtual void OnResize(EventArgs e) {
3947 if (Resize!=null) Resize(this, e);
3949 PerformLayout(this, "bounds");
3951 if (parent != null) {
3952 parent.PerformLayout();
3956 [EditorBrowsable(EditorBrowsableState.Advanced)]
3957 protected virtual void OnRightToLeftChanged(EventArgs e) {
3958 if (RightToLeftChanged!=null) RightToLeftChanged(this, e);
3959 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentRightToLeftChanged(e);
3962 [EditorBrowsable(EditorBrowsableState.Advanced)]
3963 protected virtual void OnSizeChanged(EventArgs e) {
3964 InvalidateBuffers ();
3966 if (SizeChanged!=null) SizeChanged(this, e);
3969 [EditorBrowsable(EditorBrowsableState.Advanced)]
3970 protected virtual void OnStyleChanged(EventArgs e) {
3971 if (StyleChanged!=null) StyleChanged(this, e);
3974 [EditorBrowsable(EditorBrowsableState.Advanced)]
3975 protected virtual void OnSystemColorsChanged(EventArgs e) {
3976 if (SystemColorsChanged!=null) SystemColorsChanged(this, e);
3979 [EditorBrowsable(EditorBrowsableState.Advanced)]
3980 protected virtual void OnTabIndexChanged(EventArgs e) {
3981 if (TabIndexChanged!=null) TabIndexChanged(this, e);
3984 [EditorBrowsable(EditorBrowsableState.Advanced)]
3985 protected virtual void OnTabStopChanged(EventArgs e) {
3986 if (TabStopChanged!=null) TabStopChanged(this, e);
3989 [EditorBrowsable(EditorBrowsableState.Advanced)]
3990 protected virtual void OnTextChanged(EventArgs e) {
3991 if (TextChanged!=null) TextChanged(this, e);
3994 [EditorBrowsable(EditorBrowsableState.Advanced)]
3995 protected virtual void OnValidated(EventArgs e) {
3996 if (Validated!=null) Validated(this, e);
3999 [EditorBrowsable(EditorBrowsableState.Advanced)]
4000 protected virtual void OnValidating(System.ComponentModel.CancelEventArgs e) {
4001 if (Validating!=null) Validating(this, e);
4004 [EditorBrowsable(EditorBrowsableState.Advanced)]
4005 protected virtual void OnVisibleChanged(EventArgs e) {
4012 if (bmp_mem!=null) {
4018 if (!this.IsHandleCreated) {
4019 this.CreateControl();
4025 if (VisibleChanged!=null) VisibleChanged(this, e);
4027 // We need to tell our kids
4028 for (int i=0; i<child_controls.Count; i++) {
4029 child_controls[i].OnParentVisibleChanged(e);
4032 #endregion // OnXXX methods
4035 public event EventHandler BackColorChanged;
4036 public event EventHandler BackgroundImageChanged;
4037 public event EventHandler BindingContextChanged;
4038 public event EventHandler CausesValidationChanged;
4039 public event UICuesEventHandler ChangeUICues;
4040 public event EventHandler Click;
4041 public event EventHandler ContextMenuChanged;
4043 [EditorBrowsable(EditorBrowsableState.Advanced)]
4045 public event ControlEventHandler ControlAdded;
4047 [EditorBrowsable(EditorBrowsableState.Advanced)]
4049 public event ControlEventHandler ControlRemoved;
4051 [MWFDescription("Fired when the cursor for the control has been changed"), MWFCategory("PropertyChanged")]
4052 public event EventHandler CursorChanged;
4053 public event EventHandler DockChanged;
4054 public event EventHandler DoubleClick;
4055 public event DragEventHandler DragDrop;
4056 public event DragEventHandler DragEnter;
4057 public event EventHandler DragLeave;
4058 public event DragEventHandler DragOver;
4059 public event EventHandler EnabledChanged;
4060 public event EventHandler Enter;
4061 public event EventHandler FontChanged;
4062 public event EventHandler ForeColorChanged;
4063 public event GiveFeedbackEventHandler GiveFeedback;
4065 [EditorBrowsable(EditorBrowsableState.Advanced)]
4067 public event EventHandler GotFocus;
4069 [EditorBrowsable(EditorBrowsableState.Advanced)]
4071 public event EventHandler HandleCreated;
4073 [EditorBrowsable(EditorBrowsableState.Advanced)]
4075 public event EventHandler HandleDestroyed;
4077 public event HelpEventHandler HelpRequested;
4078 public event EventHandler ImeModeChanged;
4080 [EditorBrowsable(EditorBrowsableState.Advanced)]
4082 public event InvalidateEventHandler Invalidated;
4084 public event KeyEventHandler KeyDown;
4085 public event KeyPressEventHandler KeyPress;
4086 public event KeyEventHandler KeyUp;
4087 public event LayoutEventHandler Layout;
4088 public event EventHandler Leave;
4089 public event EventHandler LocationChanged;
4091 [EditorBrowsable(EditorBrowsableState.Advanced)]
4093 public event EventHandler LostFocus;
4095 public event MouseEventHandler MouseDown;
4096 public event EventHandler MouseEnter;
4097 public event EventHandler MouseHover;
4098 public event EventHandler MouseLeave;
4099 public event MouseEventHandler MouseMove;
4100 public event MouseEventHandler MouseUp;
4102 [EditorBrowsable(EditorBrowsableState.Advanced)]
4104 public event MouseEventHandler MouseWheel;
4106 public event EventHandler Move;
4107 public event PaintEventHandler Paint;
4108 public event EventHandler ParentChanged;
4109 public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp;
4110 public event QueryContinueDragEventHandler QueryContinueDrag;
4111 public event EventHandler Resize;
4112 public event EventHandler RightToLeftChanged;
4113 public event EventHandler SizeChanged;
4114 public event EventHandler StyleChanged;
4115 public event EventHandler SystemColorsChanged;
4116 public event EventHandler TabIndexChanged;
4117 public event EventHandler TabStopChanged;
4118 public event EventHandler TextChanged;
4119 public event EventHandler Validated;
4120 public event CancelEventHandler Validating;
4121 public event EventHandler VisibleChanged;
4122 #endregion // Events