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;
632 XplatUI.SetBorderStyle(window.Handle,
637 #endregion // Internal Properties
639 #region Private & Internal Methods
640 internal IAsyncResult BeginInvokeInternal (Delegate method, object [] args) {
641 AsyncMethodResult result;
642 AsyncMethodData data;
647 if (!p.IsHandleCreated) {
648 throw new InvalidOperationException("Cannot call Invoke or InvokeAsync on a control until the window handle is created");
653 result = new AsyncMethodResult ();
654 data = new AsyncMethodData ();
656 data.Method = method;
658 data.Result = new WeakReference (result);
661 if (!ExecutionContext.IsFlowSuppressed ()) {
662 data.Context = ExecutionContext.Capture ();
665 #if !MWF_ON_MSRUNTIME
666 if (SecurityManager.SecurityEnabled) {
667 data.Stack = CompressedStack.GetCompressedStack ();
672 XplatUI.SendAsyncMethod (data);
676 internal Graphics DeviceContext {
679 CreateBuffers(this.Width, this.Height);
685 private Bitmap ImageBuffer {
688 CreateBuffers(this.Width, this.Height);
694 internal void CreateBuffers (int width, int height) {
695 if (dc_mem != null) {
709 bmp_mem = new Bitmap (width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
710 dc_mem = Graphics.FromImage (bmp_mem);
714 internal void InvalidateBuffers ()
716 if (dc_mem != null) {
727 internal static void SetChildColor(Control parent) {
730 for (int i=0; i < parent.child_controls.Count; i++) {
731 child=parent.child_controls[i];
732 if (child.IsHandleCreated) {
733 if (!child.GetStyle (ControlStyles.UserPaint)) {
734 XplatUI.SetWindowBackground(child.window.Handle, child.BackColor);
737 if (child.child_controls.Count>0) {
738 SetChildColor(child);
744 internal bool Select(Control control) {
746 IContainerControl container;
748 if (control == null) {
752 parent = control.parent;
754 if (((control.control_style & ControlStyles.Selectable) !=0) && (parent != null)) {
755 while (parent != null) {
756 if (!parent.Visible || !parent.is_enabled) {
759 parent = parent.parent;
763 control.is_selected = true;
765 container = GetContainerControl();
766 if (container != null) {
767 container.ActiveControl = control;
769 if (control.IsHandleCreated) {
770 XplatUI.SetFocus(control.window.Handle);
775 internal virtual void DoDefaultAction() {
776 // Only here to be overriden by our actual controls; this is needed by the accessibility class
779 internal static int LowOrder (int param) {
780 return ((int)(short)(param & 0xffff));
783 internal static int HighOrder (int param) {
784 return ((int)(short)(param >> 16));
787 // This method exists so controls overriding OnPaintBackground can have default background painting done
788 internal void PaintControlBackground (PaintEventArgs pevent)
790 if (background_image == null)
793 DrawBackgroundImage (pevent.Graphics);
796 void DrawBackgroundImage (Graphics g)
798 using (TextureBrush b = new TextureBrush (background_image)) {
799 g.FillRectangle (b, ClientRectangle);
803 internal void DndEnter (DragEventArgs e)
808 internal void DndOver (DragEventArgs e)
813 internal void DndDrop (DragEventArgs e)
818 internal void DndLeave (EventArgs e)
823 internal void DnDFeedback(GiveFeedbackEventArgs e)
828 internal void DnDContinueDrag(QueryContinueDragEventArgs e) {
829 OnQueryContinueDrag(e);
832 internal static MouseButtons FromParamToMouseButtons (int param) {
833 MouseButtons buttons = MouseButtons.None;
835 if ((param & (int) MsgButtons.MK_LBUTTON) != 0)
836 buttons |= MouseButtons.Left;
838 if ((param & (int) MsgButtons.MK_MBUTTON) != 0)
839 buttons |= MouseButtons.Middle;
841 if ((param & (int) MsgButtons.MK_RBUTTON) != 0)
842 buttons |= MouseButtons.Right;
848 internal virtual bool ProcessControlMnemonic(char charCode) {
849 return ProcessMnemonic(charCode);
852 private static Control FindFlatForward(Control container, Control start) {
858 end = container.child_controls.Count;
861 index = start.tab_index;
866 for (int i = 0; i < end; i++) {
868 if (container.child_controls[i].tab_index > index) {
869 found = container.child_controls[i];
871 } else if (found.tab_index > container.child_controls[i].tab_index) {
872 if (container.child_controls[i].tab_index > index) {
873 found = container.child_controls[i];
880 private static Control FindControlForward(Control container, Control start) {
887 if ((start is IContainerControl) || start.GetStyle(ControlStyles.ContainerControl)) {
888 found = FindControlForward(start, null);
895 while (p != container) {
896 found = FindFlatForward(p, start);
904 return FindFlatForward(container, start);
907 private static Control FindFlatBackward(Control container, Control start) {
913 end = container.child_controls.Count;
916 index = start.tab_index;
918 // FIXME: Possible speed-up: Keep the highest taborder index in the container
920 for (int i = 0; i < end; i++) {
921 if (container.child_controls[i].tab_index > index) {
922 index = container.child_controls[i].tab_index;
928 for (int i = 0; i < end; i++) {
930 if (container.child_controls[i].tab_index < index) {
931 found = container.child_controls[i];
933 } else if (found.tab_index < container.child_controls[i].tab_index) {
934 if (container.child_controls[i].tab_index < index) {
935 found = container.child_controls[i];
942 private static Control FindControlBackward(Control container, Control start) {
948 found = FindFlatBackward(start.parent, start);
949 if (found == null && start.parent != container) {
954 found = FindFlatBackward(container, start);
957 while ((found != null) && ((found is IContainerControl) || found.GetStyle(ControlStyles.ContainerControl))) {
958 found = FindControlBackward(found, null);
967 private void HandleClick(int clicks) {
968 if (GetStyle(ControlStyles.StandardClick)) {
970 if (GetStyle(ControlStyles.StandardDoubleClick)) {
971 OnDoubleClick(EventArgs.Empty);
973 OnClick(EventArgs.Empty);
976 OnClick(EventArgs.Empty);
981 private void CheckDataBindings ()
983 if (data_bindings == null)
986 BindingContext binding_context = BindingContext;
987 foreach (Binding binding in data_bindings) {
988 binding.Check (binding_context);
992 #endregion // Private & Internal Methods
994 #region Public Static Properties
995 public static Color DefaultBackColor {
997 return ThemeEngine.Current.DefaultControlBackColor;
1001 public static Font DefaultFont {
1003 return ThemeEngine.Current.DefaultFont;
1007 public static Color DefaultForeColor {
1009 return ThemeEngine.Current.DefaultControlForeColor;
1013 public static Keys ModifierKeys {
1015 return XplatUI.State.ModifierKeys;
1019 public static MouseButtons MouseButtons {
1021 return XplatUI.State.MouseButtons;
1025 public static Point MousePosition {
1027 return Cursor.Position;
1033 public static bool CheckForIllegalCrossThreadCalls
1042 #endregion // Public Static Properties
1044 #region Public Instance Properties
1045 [EditorBrowsable(EditorBrowsableState.Advanced)]
1047 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1048 public AccessibleObject AccessibilityObject {
1050 if (accessibility_object==null) {
1051 accessibility_object=CreateAccessibilityInstance();
1053 return accessibility_object;
1057 [EditorBrowsable(EditorBrowsableState.Advanced)]
1059 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1060 public string AccessibleDefaultActionDescription {
1062 return AccessibilityObject.default_action;
1066 AccessibilityObject.default_action=value;
1071 [DefaultValue(null)]
1072 public string AccessibleDescription {
1074 return AccessibilityObject.description;
1078 AccessibilityObject.description=value;
1083 [DefaultValue(null)]
1084 public string AccessibleName {
1086 return AccessibilityObject.Name;
1090 AccessibilityObject.Name=value;
1094 [DefaultValue(AccessibleRole.Default)]
1095 [MWFDescription("Role of the control"), MWFCategory("Accessibility")]
1096 public AccessibleRole AccessibleRole {
1098 return AccessibilityObject.role;
1102 AccessibilityObject.role=value;
1106 [DefaultValue(false)]
1107 public virtual bool AllowDrop {
1113 if (allow_drop == value)
1117 XplatUI.SetAllowDrop (Handle, value);
1122 [RefreshProperties(RefreshProperties.Repaint)]
1123 [DefaultValue(AnchorStyles.Top | AnchorStyles.Left)]
1124 public virtual AnchorStyles Anchor {
1126 return anchor_style;
1132 if (parent != null) {
1133 parent.PerformLayout(this, "Parent");
1139 public virtual Color BackColor {
1141 if (background_color.IsEmpty) {
1143 return parent.BackColor;
1145 return DefaultBackColor;
1147 return background_color;
1151 background_color=value;
1152 if (this.IsHandleCreated && !GetStyle (ControlStyles.UserPaint)) {
1153 XplatUI.SetWindowBackground(this.window.Handle, value);
1155 SetChildColor(this);
1156 OnBackColorChanged(EventArgs.Empty);
1162 [DefaultValue(null)]
1163 public virtual Image BackgroundImage {
1165 return background_image;
1169 if (background_image!=value) {
1170 background_image=value;
1171 OnBackgroundImageChanged(EventArgs.Empty);
1176 [EditorBrowsable(EditorBrowsableState.Advanced)]
1178 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1179 public virtual BindingContext BindingContext {
1181 if (binding_context != null)
1182 return binding_context;
1185 binding_context = Parent.BindingContext;
1186 return binding_context;
1189 if (binding_context != value) {
1190 binding_context = value;
1191 OnBindingContextChanged(EventArgs.Empty);
1196 [EditorBrowsable(EditorBrowsableState.Advanced)]
1198 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1201 return bounds.Y+bounds.Height;
1205 [EditorBrowsable(EditorBrowsableState.Advanced)]
1207 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1208 public Rectangle Bounds {
1214 SetBoundsCore(value.Left, value.Top, value.Width, value.Height, BoundsSpecified.All);
1218 [EditorBrowsable(EditorBrowsableState.Advanced)]
1220 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1221 public bool CanFocus {
1223 if (Visible && is_enabled && GetStyle(ControlStyles.Selectable)) {
1230 [EditorBrowsable(EditorBrowsableState.Advanced)]
1232 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1233 public bool CanSelect {
1237 if (!GetStyle(ControlStyles.Selectable) || this.parent == null) {
1241 parent = this.parent;
1242 while (parent != null) {
1243 if (!parent.is_visible || !parent.is_enabled) {
1247 parent = parent.parent;
1253 [EditorBrowsable(EditorBrowsableState.Advanced)]
1255 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1256 public bool Capture {
1258 return this.is_captured;
1262 if (this.IsHandleCreated) {
1263 if (value && !is_captured) {
1265 XplatUI.GrabWindow(this.window.Handle, IntPtr.Zero);
1266 } else if (!value && is_captured) {
1267 XplatUI.UngrabWindow(this.window.Handle);
1268 is_captured = false;
1274 [DefaultValue(true)]
1275 public bool CausesValidation {
1277 return this.causes_validation;
1281 if (this.causes_validation != value) {
1282 causes_validation = value;
1283 OnCausesValidationChanged(EventArgs.Empty);
1288 [EditorBrowsable(EditorBrowsableState.Advanced)]
1290 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1291 public Rectangle ClientRectangle {
1293 client_rect.Width = client_size.Width;
1294 client_rect.Height = client_size.Height;
1299 [EditorBrowsable(EditorBrowsableState.Advanced)]
1301 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1302 public Size ClientSize {
1305 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1306 return ((Form)this).form_parent_window.ClientSize;
1314 this.SetClientSizeCore(value.Width, value.Height);
1318 [EditorBrowsable(EditorBrowsableState.Advanced)]
1320 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1321 [DescriptionAttribute("ControlCompanyNameDescr")]
1322 public String CompanyName {
1324 return "Mono Project, Novell, Inc.";
1328 [EditorBrowsable(EditorBrowsableState.Advanced)]
1330 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1331 public bool ContainsFocus {
1337 for (int i=0; i < child_controls.Count; i++) {
1338 if (child_controls[i].ContainsFocus) {
1346 [DefaultValue(null)]
1347 public virtual ContextMenu ContextMenu {
1349 return context_menu;
1353 if (context_menu != value) {
1354 context_menu = value;
1355 OnContextMenuChanged(EventArgs.Empty);
1361 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
1362 public ControlCollection Controls {
1364 return this.child_controls;
1368 [EditorBrowsable(EditorBrowsableState.Advanced)]
1370 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1371 public bool Created {
1373 if (!this.is_disposed && (this.window.Handle != IntPtr.Zero)) {
1380 [AmbientValue(null)]
1381 public virtual Cursor Cursor {
1383 if (cursor != null) {
1387 if (parent != null) {
1388 return parent.Cursor;
1391 return Cursors.Default;
1395 if (cursor != value) {
1400 pt = Cursor.Position;
1401 if (bounds.Contains(pt)) {
1402 if (GetChildAtPoint(pt) == null) {
1403 if (cursor != null) {
1404 XplatUI.SetCursor(window.Handle, cursor.handle);
1406 if (parent != null) {
1407 XplatUI.SetCursor(window.Handle, parent.Cursor.handle);
1409 XplatUI.SetCursor(window.Handle, Cursors.def.handle);
1415 OnCursorChanged(EventArgs.Empty);
1421 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
1422 [ParenthesizePropertyName(true)]
1423 [RefreshProperties(RefreshProperties.All)]
1424 public ControlBindingsCollection DataBindings {
1426 if (data_bindings == null)
1427 data_bindings = new ControlBindingsCollection (this);
1428 return data_bindings;
1432 [EditorBrowsable(EditorBrowsableState.Advanced)]
1434 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1435 public virtual Rectangle DisplayRectangle {
1437 return ClientRectangle;
1441 [EditorBrowsable(EditorBrowsableState.Advanced)]
1443 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1444 public bool Disposing {
1451 [RefreshProperties(RefreshProperties.Repaint)]
1452 [DefaultValue(DockStyle.None)]
1453 public virtual DockStyle Dock {
1459 if (dock_style == value) {
1465 if (parent != null) {
1466 parent.PerformLayout(this, "Parent");
1469 OnDockChanged(EventArgs.Empty);
1475 public bool Enabled {
1481 if (is_enabled == value) {
1487 OnEnabledChanged (EventArgs.Empty);
1491 [EditorBrowsable(EditorBrowsableState.Advanced)]
1493 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1494 public virtual bool Focused {
1496 return this.has_focus;
1501 [AmbientValue(null)]
1503 public virtual Font Font {
1509 if (Parent != null && Parent.Font != null) {
1517 if (font != null && font.Equals (value)) {
1523 OnFontChanged (EventArgs.Empty);
1528 public virtual Color ForeColor {
1530 if (foreground_color.IsEmpty) {
1532 return parent.ForeColor;
1534 return DefaultForeColor;
1536 return foreground_color;
1540 if (foreground_color != value) {
1541 foreground_color=value;
1543 OnForeColorChanged(EventArgs.Empty);
1550 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1551 public IntPtr Handle { // IWin32Window
1553 if (!IsHandleCreated) {
1556 return window.Handle;
1560 [EditorBrowsable(EditorBrowsableState.Advanced)]
1562 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1563 public bool HasChildren {
1565 if (this.child_controls.Count>0) {
1572 [EditorBrowsable(EditorBrowsableState.Always)]
1574 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1577 return this.bounds.Height;
1581 SetBoundsCore(bounds.X, bounds.Y, bounds.Width, value, BoundsSpecified.Height);
1585 [AmbientValue(ImeMode.Inherit)]
1587 public ImeMode ImeMode {
1589 if (ime_mode == DefaultImeMode) {
1591 return parent.ImeMode;
1593 return ImeMode.NoControl; // default value
1599 if (ime_mode != value) {
1602 OnImeModeChanged(EventArgs.Empty);
1607 [EditorBrowsable(EditorBrowsableState.Advanced)]
1609 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1610 public bool InvokeRequired { // ISynchronizeInvoke
1612 if (creator_thread!=Thread.CurrentThread) {
1619 [EditorBrowsable(EditorBrowsableState.Advanced)]
1621 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1622 public bool IsAccessible {
1624 return is_accessible;
1628 is_accessible = value;
1632 [EditorBrowsable(EditorBrowsableState.Advanced)]
1634 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1635 public bool IsDisposed {
1637 return this.is_disposed;
1641 [EditorBrowsable(EditorBrowsableState.Advanced)]
1643 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1644 public bool IsHandleCreated {
1646 if ((window!=null) && (window.Handle!=IntPtr.Zero)) {
1654 [EditorBrowsable(EditorBrowsableState.Always)]
1656 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1659 return this.bounds.X;
1663 SetBoundsCore(value, bounds.Y, bounds.Width, bounds.Height, BoundsSpecified.X);
1668 public Point Location {
1670 return new Point(bounds.X, bounds.Y);
1674 SetBoundsCore(value.X, value.Y, bounds.Width, bounds.Height, BoundsSpecified.Location);
1679 public string Name {
1690 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1691 public Control Parent {
1697 if (value == this) {
1698 throw new ArgumentException("A circular control reference has been made. A control cannot be owned or parented to itself.");
1701 if (parent!=value) {
1703 parent.Controls.Remove(this);
1709 if (!parent.Controls.Contains(this)) {
1710 parent.Controls.Add(this);
1713 if (IsHandleCreated) {
1714 XplatUI.SetParent(Handle, value.Handle);
1717 OnParentChanged(EventArgs.Empty);
1723 [EditorBrowsable(EditorBrowsableState.Advanced)]
1725 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1726 public string ProductName {
1728 Type t = typeof (AssemblyProductAttribute);
1729 Assembly assembly = GetType().Module.Assembly;
1730 object [] attrs = assembly.GetCustomAttributes (t, false);
1731 AssemblyProductAttribute a = null;
1732 // On MS we get a NullRefException if product attribute is not
1734 if (attrs != null && attrs.Length > 0)
1735 a = (AssemblyProductAttribute) attrs [0];
1740 [EditorBrowsable(EditorBrowsableState.Advanced)]
1742 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1743 public string ProductVersion {
1745 Type t = typeof (AssemblyVersionAttribute);
1746 Assembly assembly = GetType().Module.Assembly;
1747 object [] attrs = assembly.GetCustomAttributes (t, false);
1748 if (attrs == null || attrs.Length < 1)
1750 return ((AssemblyVersionAttribute)attrs [0]).Version;
1754 [EditorBrowsable(EditorBrowsableState.Advanced)]
1756 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1757 public bool RecreatingHandle {
1759 return is_recreating;
1763 [EditorBrowsable(EditorBrowsableState.Advanced)]
1765 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1766 public Region Region {
1768 return new Region(this.bounds);
1775 g = this.CreateGraphics();
1776 r = value.GetBounds(g);
1778 SetBounds((int)r.X, (int)r.Y, (int)r.Width, (int)r.Height);
1784 [EditorBrowsable(EditorBrowsableState.Advanced)]
1786 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1789 return this.bounds.X+this.bounds.Width;
1793 [AmbientValue(RightToLeft.Inherit)]
1795 public virtual RightToLeft RightToLeft {
1797 if (right_to_left == RightToLeft.Inherit) {
1799 return parent.RightToLeft;
1801 return RightToLeft.No; // default value
1803 return right_to_left;
1807 if (value != right_to_left) {
1808 right_to_left = value;
1809 OnRightToLeftChanged(EventArgs.Empty);
1814 [EditorBrowsable(EditorBrowsableState.Advanced)]
1815 public override ISite Site {
1828 return new Size(Width, Height);
1832 SetBoundsCore(bounds.X, bounds.Y, value.Width, value.Height, BoundsSpecified.Size);
1837 [MergableProperty(false)]
1838 public int TabIndex {
1840 if (tab_index != -1) {
1847 if (tab_index != value) {
1849 OnTabIndexChanged(EventArgs.Empty);
1855 [DefaultValue(true)]
1856 public bool TabStop {
1862 if (tab_stop != value) {
1864 OnTabStopChanged(EventArgs.Empty);
1869 [Localizable(false)]
1871 [TypeConverter(typeof(StringConverter))]
1872 [DefaultValue(null)]
1879 control_tag = value;
1885 [BindableAttribute(true)]
1886 public virtual string Text {
1892 if (value == null) {
1893 value = String.Empty;
1898 if (IsHandleCreated) {
1899 XplatUI.Text(Handle, text);
1901 // FIXME: Do we need a Refresh() here?
1904 OnTextChanged (EventArgs.Empty);
1909 [EditorBrowsable(EditorBrowsableState.Always)]
1911 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1914 return this.bounds.Y;
1918 SetBoundsCore(bounds.X, value, bounds.Width, bounds.Height, BoundsSpecified.Y);
1922 [EditorBrowsable(EditorBrowsableState.Advanced)]
1924 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1925 public Control TopLevelControl {
1929 while (p.parent != null) {
1938 public bool Visible {
1942 } else if (parent != null) {
1943 return parent.Visible;
1950 SetVisibleCore(value);
1954 [EditorBrowsable(EditorBrowsableState.Always)]
1956 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1959 return this.bounds.Width;
1963 SetBoundsCore(bounds.X, bounds.Y, value, bounds.Height, BoundsSpecified.Width);
1967 [EditorBrowsable(EditorBrowsableState.Never)]
1969 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1970 public IWindowTarget WindowTarget {
1979 #endregion // Public Instance Properties
1981 #region Protected Instance Properties
1982 protected virtual CreateParams CreateParams {
1984 CreateParams create_params = new CreateParams();
1987 create_params.Caption = Text;
1990 create_params.Caption = text;
1994 create_params.X = Left;
1997 create_params.X = this.bounds.X;
2001 create_params.Y = Top;
2004 create_params.Y = this.bounds.Y;
2008 create_params.Width = Width;
2011 create_params.Width = this.bounds.Width;
2015 create_params.Height = Height;
2018 create_params.Height = this.bounds.Height;
2022 create_params.ClassName = XplatUI.DefaultClassName;
2023 create_params.ClassStyle = 0;
2024 create_params.ExStyle = 0;
2025 create_params.Param = 0;
2028 create_params.ExStyle |= (int)WindowStyles.WS_EX_ACCEPTFILES;
2032 create_params.Parent = parent.Handle;
2035 create_params.Style = (int)WindowStyles.WS_CHILD | (int)WindowStyles.WS_CLIPCHILDREN | (int)WindowStyles.WS_CLIPSIBLINGS;
2038 create_params.Style |= (int)WindowStyles.WS_VISIBLE;
2041 return create_params;
2045 protected virtual ImeMode DefaultImeMode {
2047 return ImeMode.Inherit;
2051 protected virtual Size DefaultSize {
2053 return new Size(100, 23);
2057 protected int FontHeight {
2067 protected bool RenderRightToLeft {
2069 return (this.right_to_left == RightToLeft.Yes);
2073 protected bool ResizeRedraw {
2075 return GetStyle(ControlStyles.ResizeRedraw);
2079 SetStyle(ControlStyles.ResizeRedraw, value);
2083 [EditorBrowsable(EditorBrowsableState.Advanced)]
2085 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2086 protected virtual bool ShowFocusCues {
2092 [EditorBrowsable(EditorBrowsableState.Advanced)]
2094 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2095 protected bool ShowKeyboardCues {
2100 #endregion // Protected Instance Properties
2102 #region Public Static Methods
2103 [EditorBrowsable(EditorBrowsableState.Advanced)]
2104 public static Control FromChildHandle(IntPtr handle) {
2105 IEnumerator control = Control.controls.GetEnumerator();
2107 while (control.MoveNext()) {
2108 if (((Control)control.Current).window.Handle == handle) {
2110 if (((Control)control.Current).Parent != null) {
2111 return ((Control)control.Current).Parent;
2118 [EditorBrowsable(EditorBrowsableState.Advanced)]
2119 public static Control FromHandle(IntPtr handle) {
2120 IEnumerator control = Control.controls.GetEnumerator();
2122 while (control.MoveNext()) {
2123 if (((Control)control.Current).window.Handle == handle) {
2125 return ((Control)control.Current);
2131 public static bool IsMnemonic(char charCode, string text) {
2134 amp = text.IndexOf('&');
2137 if (amp + 1 < text.Length) {
2138 if (text[amp + 1] != '&') {
2139 if (Char.ToUpper(charCode) == Char.ToUpper(text.ToCharArray(amp + 1, 1)[0])) {
2149 #region Protected Static Methods
2150 [EditorBrowsable(EditorBrowsableState.Advanced)]
2151 protected static bool ReflectMessage(IntPtr hWnd, ref Message m) {
2154 c = Control.FromHandle(hWnd);
2164 #region Public Instance Methods
2165 [EditorBrowsable(EditorBrowsableState.Advanced)]
2166 public IAsyncResult BeginInvoke(Delegate method) {
2167 return BeginInvokeInternal(method, null);
2170 [EditorBrowsable(EditorBrowsableState.Advanced)]
2171 public IAsyncResult BeginInvoke (Delegate method, object[] args) {
2172 return BeginInvokeInternal (method, args);
2175 public void BringToFront() {
2176 if ((parent != null) && (parent.child_controls[0]!=this)) {
2177 if (parent.child_controls.Contains(this)) {
2178 parent.child_controls.SetChildIndex(this, 0);
2182 XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, true, false);
2184 if (parent != null) {
2189 public bool Contains(Control ctl) {
2190 while (ctl != null) {
2199 public void CreateControl() {
2201 if (!IsHandleCreated) {
2205 if (!create_handled) {
2206 create_handled = true;
2210 for (int i=0; i<child_controls.Count; i++) {
2211 child_controls[i].CreateControl();
2215 public Graphics CreateGraphics() {
2216 if (!IsHandleCreated) {
2217 this.CreateControl();
2219 return Graphics.FromHwnd(this.window.Handle);
2222 public DragDropEffects DoDragDrop(object data, DragDropEffects allowedEffects) {
2223 return XplatUI.StartDrag(this.window.Handle, data, allowedEffects);
2226 [EditorBrowsable(EditorBrowsableState.Advanced)]
2227 public object EndInvoke (IAsyncResult async_result) {
2228 AsyncMethodResult result = (AsyncMethodResult) async_result;
2229 return result.EndInvoke ();
2232 public Form FindForm() {
2245 public bool Focus() {
2246 if (IsHandleCreated && !has_focus) {
2248 XplatUI.SetFocus(window.Handle);
2253 public Control GetChildAtPoint(Point pt) {
2254 // Microsoft's version of this function doesn't seem to work, so I can't check
2255 // if we only consider children or also grandchildren, etc.
2256 // I'm gonna say 'children only'
2257 for (int i=0; i<child_controls.Count; i++) {
2258 if (child_controls[i].Bounds.Contains(pt)) {
2259 return child_controls[i];
2265 public IContainerControl GetContainerControl() {
2266 Control current = this;
2268 while (current!=null) {
2269 if ((current is IContainerControl) && ((current.control_style & ControlStyles.ContainerControl)!=0)) {
2270 return (IContainerControl)current;
2272 current = current.parent;
2277 public Control GetNextControl(Control ctl, bool forward) {
2278 // If we're not a container we don't play
2279 if (!(this is IContainerControl) && !this.GetStyle(ControlStyles.ContainerControl)) {
2283 // If ctl is not contained by this, we start at the first child of this
2284 if (!this.Contains(ctl)) {
2288 // Search through our controls, starting at ctl, stepping into children as we encounter them
2289 // try to find the control with the tabindex closest to our own, or, if we're looking into
2290 // child controls, the one with the smallest tabindex
2292 return FindControlForward(this, ctl);
2294 return FindControlBackward(this, ctl);
2297 public void Hide() {
2298 this.Visible = false;
2301 public void Invalidate() {
2302 Invalidate(ClientRectangle, false);
2305 public void Invalidate(bool invalidateChildren) {
2306 Invalidate(ClientRectangle, invalidateChildren);
2309 public void Invalidate(System.Drawing.Rectangle rc) {
2310 Invalidate(rc, false);
2313 public void Invalidate(System.Drawing.Rectangle rc, bool invalidateChildren) {
2314 if (!IsHandleCreated || !Visible) {
2318 NotifyInvalidate(rc);
2320 XplatUI.Invalidate(Handle, rc, false);
2322 if (invalidateChildren) {
2323 for (int i=0; i<child_controls.Count; i++) child_controls[i].Invalidate();
2325 OnInvalidated(new InvalidateEventArgs(rc));
2328 public void Invalidate(System.Drawing.Region region) {
2329 Invalidate(region, false);
2332 [MonoTODO("Figure out if GetRegionScans is usable")]
2333 public void Invalidate(System.Drawing.Region region, bool invalidateChildren) {
2334 throw new NotImplementedException();
2336 // FIXME - should use the GetRegionScans function of the region to invalidate each area
2337 //if (invalidateChildren) {
2338 // for (int i=0; i<child_controls.Count; i++) child_controls[i].Invalidate();
2342 public object Invoke (Delegate method) {
2343 return Invoke(method, null);
2346 public object Invoke (Delegate method, object[] args) {
2347 if (!this.InvokeRequired) {
2348 return method.DynamicInvoke(args);
2351 IAsyncResult result = BeginInvoke (method, args);
2352 return EndInvoke(result);
2355 [EditorBrowsable(EditorBrowsableState.Advanced)]
2356 public void PerformLayout() {
2357 PerformLayout(null, null);
2360 [EditorBrowsable(EditorBrowsableState.Advanced)]
2361 public void PerformLayout(Control affectedControl, string affectedProperty) {
2362 LayoutEventArgs levent = new LayoutEventArgs(affectedControl, affectedProperty);
2364 if (layout_suspended>0) {
2365 layout_pending = true;
2369 layout_pending = false;
2371 // Prevent us from getting messed up
2374 // Perform all Dock and Anchor calculations
2377 AnchorStyles anchor;
2382 space=this.DisplayRectangle;
2383 if (prev_size != Size.Empty) {
2384 diff_width = space.Width - prev_size.Width;
2385 diff_height = space.Height - prev_size.Height;
2391 // Deal with docking; go through in reverse, MS docs say that lowest Z-order is closest to edge
2392 for (int i = child_controls.Count - 1; i >= 0; i--) {
2393 child=child_controls[i];
2394 switch (child.Dock) {
2395 case DockStyle.None: {
2400 case DockStyle.Left: {
2401 child.SetBounds(space.Left, space.Y, child.Width, space.Height);
2402 space.X+=child.Width;
2403 space.Width-=child.Width;
2407 case DockStyle.Top: {
2408 child.SetBounds(space.Left, space.Y, space.Width, child.Height);
2409 space.Y+=child.Height;
2410 space.Height-=child.Height;
2414 case DockStyle.Right: {
2415 child.SetBounds(space.Right-child.Width, space.Y, child.Width, space.Height);
2416 space.Width-=child.Width;
2420 case DockStyle.Bottom: {
2421 child.SetBounds(space.Left, space.Bottom-child.Height, space.Width, child.Height);
2422 space.Height-=child.Height;
2428 for (int i = child_controls.Count - 1; i >= 0; i--) {
2429 child=child_controls[i];
2431 if (child.Dock == DockStyle.Fill) {
2432 child.SetBounds(space.Left, space.Top, space.Width, space.Height);
2438 space=this.DisplayRectangle;
2440 // Deal with anchoring
2441 for (int i=0; i < child_controls.Count; i++) {
2447 child=child_controls[i];
2448 anchor=child.Anchor;
2453 height=child.Height;
2455 // If the control is docked we don't need to do anything
2456 if (child.Dock != DockStyle.None) {
2460 if ((anchor & AnchorStyles.Left) !=0 ) {
2461 if ((anchor & AnchorStyles.Right) != 0) {
2462 // Anchoring to left and right
2463 width=width+diff_width;
2467 } else if ((anchor & AnchorStyles.Right) != 0) {
2473 if ((anchor & AnchorStyles.Top) !=0 ) {
2474 if ((anchor & AnchorStyles.Bottom) != 0) {
2475 height+=diff_height;
2479 } else if ((anchor & AnchorStyles.Bottom) != 0) {
2494 child.SetBounds(left, top, width, height);
2497 // Let everyone know
2501 // Need to make sure we decremend layout_suspended
2507 public Point PointToClient (Point p) {
2511 XplatUI.ScreenToClient (Handle, ref x, ref y);
2513 return new Point (x, y);
2516 public Point PointToScreen(Point p) {
2520 XplatUI.ClientToScreen(Handle, ref x, ref y);
2522 return new Point(x, y);
2525 public virtual bool PreProcessMessage(ref Message msg) {
2528 if ((msg.Msg == (int)Msg.WM_KEYDOWN) || (msg.Msg == (int)Msg.WM_SYSKEYDOWN)) {
2529 key_data = (Keys)msg.WParam.ToInt32();
2530 if (!ProcessCmdKey(ref msg, key_data)) {
2531 if (IsInputKey(key_data)) {
2535 return ProcessDialogKey(key_data);
2539 } else if (msg.Msg == (int)Msg.WM_CHAR) {
2540 if (IsInputChar((char)msg.WParam)) {
2543 } else if (msg.Msg == (int)Msg.WM_SYSCHAR) {
2544 if (IsInputChar((char)msg.WParam)) {
2547 return ProcessDialogChar((char)msg.WParam);
2552 public Rectangle RectangleToClient(Rectangle r) {
2553 return new Rectangle(PointToClient(r.Location), r.Size);
2556 public Rectangle RectangleToScreen(Rectangle r) {
2557 return new Rectangle(PointToScreen(r.Location), r.Size);
2560 public virtual void Refresh() {
2561 if (IsHandleCreated == true) {
2565 XplatUI.UpdateWindow(window.Handle);
2567 end = child_controls.Count;
2568 for (int i=0; i < end; i++) {
2569 child_controls[i].Refresh();
2575 [EditorBrowsable(EditorBrowsableState.Never)]
2576 public virtual void ResetBackColor() {
2577 background_color = Color.Empty;
2580 [EditorBrowsable(EditorBrowsableState.Never)]
2582 public void ResetBindings() {
2586 [EditorBrowsable(EditorBrowsableState.Never)]
2587 public virtual void ResetCursor() {
2591 [EditorBrowsable(EditorBrowsableState.Never)]
2592 public virtual void ResetFont() {
2596 [EditorBrowsable(EditorBrowsableState.Never)]
2597 public virtual void ResetForeColor() {
2598 foreground_color = Color.Empty;
2601 [EditorBrowsable(EditorBrowsableState.Never)]
2602 public void ResetImeMode() {
2603 ime_mode = DefaultImeMode;
2606 [EditorBrowsable(EditorBrowsableState.Never)]
2607 public virtual void ResetRightToLeft() {
2608 right_to_left = RightToLeft.Inherit;
2611 public virtual void ResetText() {
2612 text = String.Empty;
2615 public void ResumeLayout() {
2616 ResumeLayout (true);
2619 public void ResumeLayout(bool performLayout) {
2622 if (layout_suspended > 0) {
2626 if (performLayout || layout_pending) {
2631 public void Scale(float ratio) {
2632 ScaleCore(ratio, ratio);
2635 public void Scale(float dx, float dy) {
2639 public void Select() {
2640 Select(false, false);
2643 public bool SelectNextControl(Control ctl, bool forward, bool tabStopOnly, bool nested, bool wrap) {
2648 c = GetNextControl(c, forward);
2657 if (c.CanSelect && ((c.parent == ctl.parent) || nested) && (c.tab_stop || !tabStopOnly)) {
2661 } while (c != ctl); // If we wrap back to ourselves we stop
2666 public void SendToBack() {
2667 if ((parent != null) && (parent.child_controls[parent.child_controls.Count-1]!=this)) {
2668 if (parent.child_controls.Contains(this)) {
2669 parent.child_controls.SetChildIndex(this, parent.child_controls.Count);
2673 XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, false, true);
2674 if (parent != null) {
2679 public void SetBounds(int x, int y, int width, int height) {
2680 SetBoundsCore(x, y, width, height, BoundsSpecified.All);
2683 public void SetBounds(int x, int y, int width, int height, BoundsSpecified specified) {
2684 SetBoundsCore(x, y, width, height, specified);
2687 public void Show() {
2688 if (!IsHandleCreated) {
2689 this.CreateControl();
2695 public void SuspendLayout() {
2699 public void Update() {
2700 needs_redraw = true;
2701 if (IsHandleCreated) {
2702 XplatUI.UpdateWindow(window.Handle);
2705 #endregion // Public Instance Methods
2707 #region Protected Instance Methods
2708 [EditorBrowsable(EditorBrowsableState.Advanced)]
2709 [MonoTODO("Implement this and tie it into Control.ControlAccessibleObject.NotifyClients")]
2710 protected void AccessibilityNotifyClients(AccessibleEvents accEvent, int childID) {
2711 throw new NotImplementedException();
2714 [EditorBrowsable(EditorBrowsableState.Advanced)]
2715 protected virtual AccessibleObject CreateAccessibilityInstance() {
2716 return new Control.ControlAccessibleObject(this);
2719 [EditorBrowsable(EditorBrowsableState.Advanced)]
2720 protected virtual ControlCollection CreateControlsInstance() {
2721 return new ControlCollection(this);
2724 [EditorBrowsable(EditorBrowsableState.Advanced)]
2725 protected virtual void CreateHandle() {
2727 throw new ObjectDisposedException(Name);
2730 if (IsHandleCreated) {
2734 window.CreateHandle(CreateParams);
2736 // Find out where the window manager placed us
2740 if (window.Handle!=IntPtr.Zero) {
2741 if (!controls.Contains(window.Handle)) {
2745 creator_thread = Thread.CurrentThread;
2747 if (!GetStyle (ControlStyles.UserPaint)) {
2748 XplatUI.SetWindowBackground(window.Handle, this.BackColor);
2751 OnHandleCreated(EventArgs.Empty);
2755 [EditorBrowsable(EditorBrowsableState.Advanced)]
2756 protected virtual void DefWndProc(ref Message m) {
2757 window.DefWndProc(ref m);
2760 [EditorBrowsable(EditorBrowsableState.Advanced)]
2761 protected virtual void DestroyHandle() {
2762 if (IsHandleCreated) {
2763 // Destroy our children before we destroy ourselves, to prevent them from
2764 // being implictly (without us knowing) destroyed
2765 for (int i=0; i < child_controls.Count; i++) {
2766 child_controls[i].DestroyHandle();
2770 if (window != null) {
2771 window.DestroyHandle();
2773 OnHandleDestroyed(EventArgs.Empty);
2777 protected bool GetStyle(ControlStyles flag) {
2778 return (control_style & flag) != 0;
2781 protected bool GetTopLevel() {
2785 [EditorBrowsable(EditorBrowsableState.Advanced)]
2786 protected virtual void InitLayout() {
2787 if (parent != null) {
2788 parent.PerformLayout(this, "parent");
2792 [EditorBrowsable(EditorBrowsableState.Advanced)]
2793 protected void InvokeGotFocus(Control toInvoke, EventArgs e) {
2794 toInvoke.OnGotFocus(e);
2797 [EditorBrowsable(EditorBrowsableState.Advanced)]
2798 protected void InvokeLostFocus(Control toInvoke, EventArgs e) {
2799 toInvoke.OnLostFocus(e);
2802 [EditorBrowsable(EditorBrowsableState.Advanced)]
2803 protected void InvokeOnClick(Control toInvoke, EventArgs e) {
2804 toInvoke.OnClick(e);
2807 protected void InvokePaint(Control toInvoke, PaintEventArgs e) {
2808 toInvoke.OnPaint(e);
2811 protected void InvokePaintBackground(Control toInvoke, PaintEventArgs e) {
2812 toInvoke.OnPaintBackground(e);
2815 protected virtual bool IsInputChar (char charCode) {
2816 if (parent != null) {
2817 return parent.IsInputChar(charCode);
2823 protected virtual bool IsInputKey (Keys keyData) {
2824 // Doc says this one calls IsInputChar; not sure what to do with that
2828 [EditorBrowsable(EditorBrowsableState.Advanced)]
2829 protected virtual void NotifyInvalidate(Rectangle invalidatedArea) {
2833 protected virtual bool ProcessCmdKey(ref Message msg, Keys keyData) {
2834 if ((context_menu != null) && context_menu.ProcessCmdKey(ref msg, keyData)) {
2838 if (parent != null) {
2839 return parent.ProcessCmdKey(ref msg, keyData);
2845 protected virtual bool ProcessDialogChar(char charCode) {
2846 if (parent != null) {
2847 return parent.ProcessDialogChar (charCode);
2853 protected virtual bool ProcessDialogKey (Keys keyData) {
2854 if (parent != null) {
2855 return parent.ProcessDialogKey (keyData);
2861 protected virtual bool ProcessKeyEventArgs (ref Message msg)
2863 KeyEventArgs key_event;
2866 case (int)Msg.WM_KEYDOWN: {
2867 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
2868 OnKeyDown (key_event);
2869 return key_event.Handled;
2871 case (int)Msg.WM_KEYUP: {
2872 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
2873 OnKeyUp (key_event);
2874 return key_event.Handled;
2877 case (int)Msg.WM_CHAR: {
2878 KeyPressEventArgs key_press_event;
2880 key_press_event = new KeyPressEventArgs((char)msg.WParam);
2881 OnKeyPress(key_press_event);
2882 return key_press_event.Handled;
2893 protected internal virtual bool ProcessKeyMessage(ref Message msg) {
2894 if (parent != null) {
2895 if (parent.ProcessKeyPreview(ref msg)) {
2903 protected virtual bool ProcessKeyPreview(ref Message msg) {
2904 if (parent != null) {
2905 return parent.ProcessKeyPreview(ref msg);
2911 protected virtual bool ProcessMnemonic(char charCode) {
2916 [EditorBrowsable(EditorBrowsableState.Advanced)]
2917 protected void RaiseDragEvent(object key, DragEventArgs e) {
2921 [EditorBrowsable(EditorBrowsableState.Advanced)]
2922 protected void RaiseKeyEvent(object key, KeyEventArgs e) {
2926 [EditorBrowsable(EditorBrowsableState.Advanced)]
2927 protected void RaiseMouseEvent(object key, MouseEventArgs e) {
2931 [EditorBrowsable(EditorBrowsableState.Advanced)]
2932 protected void RaisePaintEvent(object key, PaintEventArgs e) {
2936 [EditorBrowsable(EditorBrowsableState.Advanced)]
2937 protected void RecreateHandle() {
2938 IEnumerator child = child_controls.GetEnumerator();
2942 if (IsHandleCreated) {
2948 while (child.MoveNext()) {
2949 ((Control)child.Current).RecreateHandle();
2955 is_recreating = false;
2958 [EditorBrowsable(EditorBrowsableState.Advanced)]
2959 protected void ResetMouseEventArgs() {
2963 [EditorBrowsable(EditorBrowsableState.Advanced)]
2964 protected ContentAlignment RtlTranslateAlignment(ContentAlignment align) {
2965 if (right_to_left == RightToLeft.No) {
2970 case ContentAlignment.TopLeft: {
2971 return ContentAlignment.TopRight;
2974 case ContentAlignment.TopRight: {
2975 return ContentAlignment.TopLeft;
2978 case ContentAlignment.MiddleLeft: {
2979 return ContentAlignment.MiddleRight;
2982 case ContentAlignment.MiddleRight: {
2983 return ContentAlignment.MiddleLeft;
2986 case ContentAlignment.BottomLeft: {
2987 return ContentAlignment.BottomRight;
2990 case ContentAlignment.BottomRight: {
2991 return ContentAlignment.BottomLeft;
2995 // if it's center it doesn't change
3001 [EditorBrowsable(EditorBrowsableState.Advanced)]
3002 protected HorizontalAlignment RtlTranslateAlignment(HorizontalAlignment align) {
3003 if ((right_to_left == RightToLeft.No) || (align == HorizontalAlignment.Center)) {
3007 if (align == HorizontalAlignment.Left) {
3008 return HorizontalAlignment.Right;
3011 // align must be HorizontalAlignment.Right
3012 return HorizontalAlignment.Left;
3015 [EditorBrowsable(EditorBrowsableState.Advanced)]
3016 protected LeftRightAlignment RtlTranslateAlignment(LeftRightAlignment align) {
3017 if (right_to_left == RightToLeft.No) {
3021 if (align == LeftRightAlignment.Left) {
3022 return LeftRightAlignment.Right;
3025 // align must be LeftRightAlignment.Right;
3026 return LeftRightAlignment.Left;
3029 [EditorBrowsable(EditorBrowsableState.Advanced)]
3030 protected ContentAlignment RtlTranslateContent(ContentAlignment align) {
3031 return RtlTranslateAlignment(align);
3034 [EditorBrowsable(EditorBrowsableState.Advanced)]
3035 protected HorizontalAlignment RtlTranslateHorizontal(HorizontalAlignment align) {
3036 return RtlTranslateAlignment(align);
3039 [EditorBrowsable(EditorBrowsableState.Advanced)]
3040 protected LeftRightAlignment RtlTranslateLeftRight(LeftRightAlignment align) {
3041 return RtlTranslateAlignment(align);
3044 [EditorBrowsable(EditorBrowsableState.Advanced)]
3045 protected virtual void ScaleCore(float dx, float dy) {
3051 location = new Point((int)(Left * dx), (int)(Top * dy));
3052 size = this.ClientSize;
3055 if (!GetStyle(ControlStyles.FixedWidth)) {
3056 size.Width = (int)(size.Width * dx);
3059 if (!GetStyle(ControlStyles.FixedHeight)) {
3060 size.Height = (int)(size.Height * dy);
3063 Location = location;
3066 /* Now scale our children */
3067 for (int i=0; i < child_controls.Count; i++) {
3068 child_controls[i].Scale(dx, dy);
3074 protected virtual void Select(bool directed, bool forward) {
3079 // Select this control
3084 if (parent == null) {
3088 // FIXME - this thing is doing the wrong stuff, needs to be similar to SelectNextControl
3090 index = parent.child_controls.IndexOf(this);
3095 if ((index+1) < parent.child_controls.Count) {
3104 index = parent.child_controls.Count-1;
3107 result = Select(parent.child_controls[index]);
3108 } while (!result && parent.child_controls[index] != this);
3111 [EditorBrowsable(EditorBrowsableState.Advanced)]
3112 protected virtual void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
3113 // SetBoundsCore updates the Win32 control itself. UpdateBounds updates the controls variables and fires events, I'm guessing - pdb
3114 if ((specified & BoundsSpecified.X) != BoundsSpecified.X) {
3118 if ((specified & BoundsSpecified.Y) != BoundsSpecified.Y) {
3122 if ((specified & BoundsSpecified.Width) != BoundsSpecified.Width) {
3126 if ((specified & BoundsSpecified.Height) != BoundsSpecified.Height) {
3130 if (IsHandleCreated) {
3131 XplatUI.SetWindowPos(Handle, x, y, width, height);
3133 UpdateBounds(x, y, width, height);
3136 [EditorBrowsable(EditorBrowsableState.Advanced)]
3137 protected virtual void SetClientSizeCore(int x, int y) {
3138 // Calculate the actual window size from the client size (it usually stays the same or grows)
3139 Rectangle ClientRect;
3140 Rectangle WindowRect;
3143 ClientRect = new Rectangle(0, 0, x, y);
3144 cp = this.CreateParams;
3146 if (XplatUI.CalculateWindowRect(Handle, ref ClientRect, cp.Style, cp.ExStyle, IntPtr.Zero, out WindowRect)==false) {
3150 SetBoundsCore(bounds.X, bounds.Y, WindowRect.Width, WindowRect.Height, BoundsSpecified.Size);
3153 [EditorBrowsable(EditorBrowsableState.Advanced)]
3154 protected void SetStyle(ControlStyles flag, bool value) {
3156 control_style |= flag;
3158 control_style &= ~flag;
3160 OnStyleChanged(EventArgs.Empty);
3163 protected void SetTopLevel(bool value) {
3164 if ((GetTopLevel() != value) && (parent != null)) {
3165 throw new Exception();
3169 if (value == true) {
3179 is_toplevel = value;
3182 protected virtual void SetVisibleCore(bool value) {
3183 if (value!=is_visible) {
3186 if (IsHandleCreated) {
3187 XplatUI.SetVisible(Handle, value);
3188 // Explicitly move Toplevel windows to where we want them;
3189 // apparently moving unmapped toplevel windows doesn't work
3190 if (is_visible && (this is Form)) {
3191 XplatUI.SetWindowPos(window.Handle, bounds.X, bounds.Y, bounds.Width, bounds.Height);
3195 OnVisibleChanged(EventArgs.Empty);
3198 if (dc_mem != null) {
3203 if (bmp_mem != null) {
3208 this.CreateBuffers(bounds.Width, bounds.Height);
3212 if (value == false && parent != null) {
3215 // Need to start at parent, GetContainerControl might return ourselves if we're a container
3216 container = (Control)parent.GetContainerControl();
3217 if (container != null) {
3218 container.SelectNextControl(this, true, true, true, true);
3222 if (parent != null) {
3223 parent.PerformLayout(this, "visible");
3225 PerformLayout(this, "visible");
3230 [EditorBrowsable(EditorBrowsableState.Advanced)]
3231 protected void UpdateBounds() {
3239 if (!IsHandleCreated) {
3243 XplatUI.GetWindowPos(this.Handle, this is Form, out x, out y, out width, out height, out client_width, out client_height);
3245 UpdateBounds(x, y, width, height, client_width, client_height);
3248 [EditorBrowsable(EditorBrowsableState.Advanced)]
3249 protected void UpdateBounds(int x, int y, int width, int height) {
3250 // UpdateBounds only seems to set our sizes and fire events but not update the GUI window to match
3252 bool resized = false;
3254 int client_x_diff = this.bounds.Width-this.client_size.Width;
3255 int client_y_diff = this.bounds.Height-this.client_size.Height;
3257 // Needed to generate required notifications
3258 if ((this.bounds.X!=x) || (this.bounds.Y!=y)) {
3262 if ((this.Bounds.Width!=width) || (this.Bounds.Height!=height)) {
3269 bounds.Height=height;
3271 // Update client rectangle as well
3272 if (this.layout_suspended==0) {
3273 prev_size.Width=client_size.Width;
3274 prev_size.Height=client_size.Height;
3277 client_size.Width=width-client_x_diff;
3278 client_size.Height=height-client_y_diff;
3281 OnLocationChanged(EventArgs.Empty);
3285 OnSizeChanged(EventArgs.Empty);
3289 [EditorBrowsable(EditorBrowsableState.Advanced)]
3290 protected void UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) {
3291 UpdateBounds(x, y, width, height);
3293 this.client_size.Width=clientWidth;
3294 this.client_size.Height=clientHeight;
3297 [EditorBrowsable(EditorBrowsableState.Advanced)]
3298 protected void UpdateStyles() {
3299 if (!IsHandleCreated) {
3303 XplatUI.SetWindowStyle(window.Handle, CreateParams);
3306 [EditorBrowsable(EditorBrowsableState.Advanced)]
3307 protected void UpdateZOrder() {
3312 if (parent == null) {
3318 children = ctl.child_controls.Count;
3319 for (int i = 1; i < children; i++ ) {
3320 XplatUI.SetZOrder(ctl.child_controls[i].window.Handle, ctl.child_controls[i-1].window.Handle, false, false);
3323 if (!IsHandleCreated) {
3327 children = child_controls.Count;
3328 for (int i = 1; i < children; i++ ) {
3329 XplatUI.SetZOrder(child_controls[i].Handle, child_controls[i-1].Handle, false, false);
3334 protected virtual void WndProc(ref Message m) {
3336 Console.WriteLine("Control received message {0}", (Msg)m.Msg);
3338 if ((this.control_style & ControlStyles.EnableNotifyMessage) != 0) {
3342 switch((Msg)m.Msg) {
3343 case Msg.WM_WINDOWPOSCHANGED: {
3346 if (GetStyle(ControlStyles.ResizeRedraw)) {
3353 case Msg.WM_PAINT: {
3354 PaintEventArgs paint_event;
3356 paint_event = XplatUI.PaintEventStart(Handle, true);
3358 if (!needs_redraw) {
3359 // Just blit the previous image
3360 paint_event.Graphics.DrawImage (ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle, GraphicsUnit.Pixel);
3361 XplatUI.PaintEventEnd(Handle, true);
3366 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
3367 dc = paint_event.SetGraphics (DeviceContext);
3370 if ((control_style & (ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint)) != (ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint)) {
3371 OnPaintBackground(paint_event);
3374 OnPaint(paint_event);
3376 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
3377 dc.DrawImage (ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle, GraphicsUnit.Pixel);
3378 paint_event.SetGraphics (dc);
3379 needs_redraw = false;
3382 XplatUI.PaintEventEnd(Handle, true);
3384 if (!GetStyle(ControlStyles.UserPaint)) {
3391 case Msg.WM_ERASEBKGND: {
3392 if (GetStyle (ControlStyles.UserPaint)) {
3393 if (!GetStyle(ControlStyles.AllPaintingInWmPaint)) {
3394 PaintEventArgs eraseEventArgs = new PaintEventArgs (m.WParam == IntPtr.Zero ? Graphics.FromHwnd (m.HWnd) :
3395 Graphics.FromHdc (m.WParam), new Rectangle (new Point (0,0),Size));
3396 OnPaintBackground (eraseEventArgs);
3399 XplatUI.EraseWindowBackground(m.HWnd, m.WParam);
3401 // The DefWndProc will never have to handle this, we don't ever set hbr on the window
3402 m.Result = (IntPtr)1;
3406 case Msg.WM_LBUTTONUP: {
3407 HandleClick(mouse_clicks);
3408 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Left,
3410 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3412 if (mouse_clicks > 1) {
3418 case Msg.WM_LBUTTONDOWN: {
3419 if (CanSelect && !is_selected) {
3422 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3423 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3429 case Msg.WM_LBUTTONDBLCLK: {
3431 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3432 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3438 case Msg.WM_MBUTTONUP: {
3439 HandleClick(mouse_clicks);
3440 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Middle,
3442 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3444 if (mouse_clicks > 1) {
3450 case Msg.WM_MBUTTONDOWN: {
3451 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3452 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3458 case Msg.WM_MBUTTONDBLCLK: {
3460 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3461 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3466 case Msg.WM_RBUTTONUP: {
3467 if (context_menu != null) {
3468 context_menu.Show(this, new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ())));
3471 HandleClick(mouse_clicks);
3472 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Right,
3474 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3476 if (mouse_clicks > 1) {
3482 case Msg.WM_RBUTTONDOWN: {
3483 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3484 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3489 case Msg.WM_RBUTTONDBLCLK: {
3491 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3492 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3497 case Msg.WM_MOUSEWHEEL: {
3499 OnMouseWheel (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3500 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3501 HighOrder(m.WParam.ToInt32())));
3506 case Msg.WM_MOUSEMOVE: {
3507 OnMouseMove (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3509 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3514 case Msg.WM_MOUSE_ENTER: {
3519 OnMouseEnter(EventArgs.Empty);
3523 case Msg.WM_MOUSE_LEAVE: {
3525 OnMouseLeave(EventArgs.Empty);
3529 case Msg.WM_MOUSEHOVER: {
3530 OnMouseHover(EventArgs.Empty);
3534 case Msg.WM_SYSKEYDOWN:
3535 case Msg.WM_KEYDOWN:
3536 case Msg.WM_SYSKEYUP:
3538 case Msg.WM_SYSCHAR:
3540 Console.WriteLine("Got {0}", (Msg)m.Msg);
3541 if (ProcessKeyEventArgs(ref m)) {
3545 if (PreProcessMessage(ref m)) {
3549 if (ProcessKeyMessage(ref m)) {
3558 if (m.LParam != IntPtr.Zero) {
3561 hi = new HELPINFO();
3563 hi = (HELPINFO) Marshal.PtrToStructure (m.LParam, typeof (HELPINFO));
3564 mouse_pos = new Point(hi.MousePos.x, hi.MousePos.y);
3566 mouse_pos = Control.MousePosition;
3568 OnHelpRequested(new HelpEventArgs(mouse_pos));
3569 m.Result = (IntPtr)1;
3573 case Msg.WM_KILLFOCUS: {
3574 OnLeave(EventArgs.Empty);
3575 if (CausesValidation) {
3577 e = new CancelEventArgs(false);
3586 OnValidated(EventArgs.Empty);
3589 this.has_focus = false;
3590 this.is_selected = false;
3591 OnLostFocus(EventArgs.Empty);
3595 case Msg.WM_SETFOCUS: {
3596 OnEnter(EventArgs.Empty);
3597 this.has_focus = true;
3598 OnGotFocus(EventArgs.Empty);
3603 case Msg.WM_SYSCOLORCHANGE: {
3604 ThemeEngine.Current.ResetDefaults();
3605 OnSystemColorsChanged(EventArgs.Empty);
3610 case Msg.WM_SETCURSOR: {
3611 if (cursor == null) {
3616 XplatUI.SetCursor(window.Handle, cursor.handle);
3617 m.Result = (IntPtr)1;
3628 #endregion // Public Instance Methods
3630 #region OnXXX methods
3631 [EditorBrowsable(EditorBrowsableState.Advanced)]
3632 protected virtual void OnBackColorChanged(EventArgs e) {
3633 if (BackColorChanged!=null) BackColorChanged(this, e);
3634 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackColorChanged(e);
3637 [EditorBrowsable(EditorBrowsableState.Advanced)]
3638 protected virtual void OnBackgroundImageChanged(EventArgs e) {
3639 if (BackgroundImageChanged!=null) BackgroundImageChanged(this, e);
3640 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackgroundImageChanged(e);
3643 [EditorBrowsable(EditorBrowsableState.Advanced)]
3644 protected virtual void OnBindingContextChanged(EventArgs e) {
3645 CheckDataBindings ();
3646 if (BindingContextChanged!=null) {
3647 BindingContextChanged(this, e);
3649 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBindingContextChanged(e);
3652 [EditorBrowsable(EditorBrowsableState.Advanced)]
3653 protected virtual void OnCausesValidationChanged(EventArgs e) {
3654 if (CausesValidationChanged!=null) CausesValidationChanged(this, e);
3657 [EditorBrowsable(EditorBrowsableState.Advanced)]
3658 protected virtual void OnChangeUICues(UICuesEventArgs e) {
3659 if (ChangeUICues!=null) ChangeUICues(this, e);
3662 [EditorBrowsable(EditorBrowsableState.Advanced)]
3663 protected virtual void OnClick(EventArgs e) {
3664 if (Click!=null) Click(this, e);
3667 [EditorBrowsable(EditorBrowsableState.Advanced)]
3668 protected virtual void OnContextMenuChanged(EventArgs e) {
3669 if (ContextMenuChanged!=null) ContextMenuChanged(this, e);
3672 [EditorBrowsable(EditorBrowsableState.Advanced)]
3673 protected virtual void OnControlAdded(ControlEventArgs e) {
3674 if (ControlAdded!=null) ControlAdded(this, e);
3677 [EditorBrowsable(EditorBrowsableState.Advanced)]
3678 protected virtual void OnControlRemoved(ControlEventArgs e) {
3679 if (ControlRemoved!=null) ControlRemoved(this, e);
3682 [EditorBrowsable(EditorBrowsableState.Advanced)]
3683 protected virtual void OnCreateControl() {
3687 [EditorBrowsable(EditorBrowsableState.Advanced)]
3688 protected virtual void OnCursorChanged(EventArgs e) {
3689 if (CursorChanged!=null) CursorChanged(this, e);
3692 [EditorBrowsable(EditorBrowsableState.Advanced)]
3693 protected virtual void OnDockChanged(EventArgs e) {
3694 if (DockChanged!=null) DockChanged(this, e);
3697 [EditorBrowsable(EditorBrowsableState.Advanced)]
3698 protected virtual void OnDoubleClick(EventArgs e) {
3699 if (DoubleClick!=null) DoubleClick(this, e);
3702 [EditorBrowsable(EditorBrowsableState.Advanced)]
3703 protected virtual void OnDragDrop(DragEventArgs drgevent) {
3704 if (DragDrop!=null) DragDrop(this, drgevent);
3707 [EditorBrowsable(EditorBrowsableState.Advanced)]
3708 protected virtual void OnDragEnter(DragEventArgs drgevent) {
3709 if (DragEnter!=null) DragEnter(this, drgevent);
3712 [EditorBrowsable(EditorBrowsableState.Advanced)]
3713 protected virtual void OnDragLeave(EventArgs e) {
3714 if (DragLeave!=null) DragLeave(this, e);
3717 [EditorBrowsable(EditorBrowsableState.Advanced)]
3718 protected virtual void OnDragOver(DragEventArgs drgevent) {
3719 if (DragOver!=null) DragOver(this, drgevent);
3722 [EditorBrowsable(EditorBrowsableState.Advanced)]
3723 protected virtual void OnEnabledChanged(EventArgs e) {
3724 if (EnabledChanged!=null) EnabledChanged(this, e);
3725 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentEnabledChanged(e);
3728 [EditorBrowsable(EditorBrowsableState.Advanced)]
3729 protected virtual void OnEnter(EventArgs e) {
3730 if (Enter!=null) Enter(this, e);
3733 [EditorBrowsable(EditorBrowsableState.Advanced)]
3734 protected virtual void OnFontChanged(EventArgs e) {
3735 if (FontChanged!=null) FontChanged(this, e);
3736 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentFontChanged(e);
3739 [EditorBrowsable(EditorBrowsableState.Advanced)]
3740 protected virtual void OnForeColorChanged(EventArgs e) {
3741 if (ForeColorChanged!=null) ForeColorChanged(this, e);
3742 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentForeColorChanged(e);
3745 [EditorBrowsable(EditorBrowsableState.Advanced)]
3746 protected virtual void OnGiveFeedback(GiveFeedbackEventArgs gfbevent) {
3747 if (GiveFeedback!=null) GiveFeedback(this, gfbevent);
3750 [EditorBrowsable(EditorBrowsableState.Advanced)]
3751 protected virtual void OnGotFocus(EventArgs e) {
3752 if (GotFocus!=null) GotFocus(this, e);
3755 [EditorBrowsable(EditorBrowsableState.Advanced)]
3756 protected virtual void OnHandleCreated(EventArgs e) {
3757 if (HandleCreated!=null) HandleCreated(this, e);
3760 [EditorBrowsable(EditorBrowsableState.Advanced)]
3761 protected virtual void OnHandleDestroyed(EventArgs e) {
3762 if (HandleDestroyed!=null) HandleDestroyed(this, e);
3765 [EditorBrowsable(EditorBrowsableState.Advanced)]
3766 protected virtual void OnHelpRequested(HelpEventArgs hevent) {
3767 if (HelpRequested!=null) HelpRequested(this, hevent);
3770 protected virtual void OnImeModeChanged(EventArgs e) {
3771 if (ImeModeChanged!=null) ImeModeChanged(this, e);
3774 [EditorBrowsable(EditorBrowsableState.Advanced)]
3775 protected virtual void OnInvalidated(InvalidateEventArgs e) {
3776 needs_redraw = true;
3777 if (Invalidated!=null) Invalidated(this, e);
3780 [EditorBrowsable(EditorBrowsableState.Advanced)]
3781 protected virtual void OnKeyDown(KeyEventArgs e) {
3782 if (KeyDown!=null) KeyDown(this, e);
3785 [EditorBrowsable(EditorBrowsableState.Advanced)]
3786 protected virtual void OnKeyPress(KeyPressEventArgs e) {
3787 if (KeyPress!=null) KeyPress(this, e);
3790 [EditorBrowsable(EditorBrowsableState.Advanced)]
3791 protected virtual void OnKeyUp(KeyEventArgs e) {
3792 if (KeyUp!=null) KeyUp(this, e);
3795 [EditorBrowsable(EditorBrowsableState.Advanced)]
3796 protected virtual void OnLayout(LayoutEventArgs levent) {
3797 if (Layout!=null) Layout(this, levent);
3800 [EditorBrowsable(EditorBrowsableState.Advanced)]
3801 protected virtual void OnLeave(EventArgs e) {
3802 if (Leave!=null) Leave(this, e);
3805 [EditorBrowsable(EditorBrowsableState.Advanced)]
3806 protected virtual void OnLocationChanged(EventArgs e) {
3808 if (LocationChanged!=null) LocationChanged(this, e);
3811 [EditorBrowsable(EditorBrowsableState.Advanced)]
3812 protected virtual void OnLostFocus(EventArgs e) {
3813 if (LostFocus!=null) LostFocus(this, e);
3816 [EditorBrowsable(EditorBrowsableState.Advanced)]
3817 protected virtual void OnMouseDown(MouseEventArgs e) {
3818 if (MouseDown!=null) MouseDown(this, e);
3821 [EditorBrowsable(EditorBrowsableState.Advanced)]
3822 protected virtual void OnMouseEnter(EventArgs e) {
3823 if (MouseEnter!=null) MouseEnter(this, e);
3826 [EditorBrowsable(EditorBrowsableState.Advanced)]
3827 protected virtual void OnMouseHover(EventArgs e) {
3828 if (MouseHover!=null) MouseHover(this, e);
3831 [EditorBrowsable(EditorBrowsableState.Advanced)]
3832 protected virtual void OnMouseLeave(EventArgs e) {
3833 if (MouseLeave!=null) MouseLeave(this, e);
3836 [EditorBrowsable(EditorBrowsableState.Advanced)]
3837 protected virtual void OnMouseMove(MouseEventArgs e) {
3838 if (MouseMove!=null) MouseMove(this, e);
3841 [EditorBrowsable(EditorBrowsableState.Advanced)]
3842 protected virtual void OnMouseUp(MouseEventArgs e) {
3843 if (MouseUp!=null) MouseUp(this, e);
3846 [EditorBrowsable(EditorBrowsableState.Advanced)]
3847 protected virtual void OnMouseWheel(MouseEventArgs e) {
3848 if (MouseWheel!=null) MouseWheel(this, e);
3851 [EditorBrowsable(EditorBrowsableState.Advanced)]
3852 protected virtual void OnMove(EventArgs e) {
3853 if (Move!=null) Move(this, e);
3856 [EditorBrowsable(EditorBrowsableState.Advanced)]
3857 protected virtual void OnNotifyMessage(Message m) {
3861 [EditorBrowsable(EditorBrowsableState.Advanced)]
3862 protected virtual void OnPaint(PaintEventArgs e) {
3863 if (Paint!=null) Paint(this, e);
3866 [EditorBrowsable(EditorBrowsableState.Advanced)]
3867 protected virtual void OnPaintBackground(PaintEventArgs pevent) {
3868 PaintControlBackground (pevent);
3871 [EditorBrowsable(EditorBrowsableState.Advanced)]
3872 protected virtual void OnParentBackColorChanged(EventArgs e) {
3873 if (background_color.IsEmpty && background_image==null) {
3875 OnBackColorChanged(e);
3879 [EditorBrowsable(EditorBrowsableState.Advanced)]
3880 protected virtual void OnParentBackgroundImageChanged(EventArgs e) {
3881 if (background_color.IsEmpty && background_image==null) {
3883 OnBackgroundImageChanged(e);
3887 [EditorBrowsable(EditorBrowsableState.Advanced)]
3888 protected virtual void OnParentBindingContextChanged(EventArgs e) {
3889 if (binding_context==null) {
3890 binding_context=Parent.binding_context;
3891 OnBindingContextChanged(e);
3895 [EditorBrowsable(EditorBrowsableState.Advanced)]
3896 protected virtual void OnParentChanged(EventArgs e) {
3897 if (ParentChanged!=null) ParentChanged(this, e);
3900 [EditorBrowsable(EditorBrowsableState.Advanced)]
3901 protected virtual void OnParentEnabledChanged(EventArgs e) {
3902 if (is_enabled != Parent.is_enabled) {
3903 is_enabled=Parent.is_enabled;
3905 if (EnabledChanged != null) {
3906 EnabledChanged(this, e);
3911 [EditorBrowsable(EditorBrowsableState.Advanced)]
3912 protected virtual void OnParentFontChanged(EventArgs e) {
3919 [EditorBrowsable(EditorBrowsableState.Advanced)]
3920 protected virtual void OnParentForeColorChanged(EventArgs e) {
3921 if (foreground_color.IsEmpty) {
3923 OnForeColorChanged(e);
3927 [EditorBrowsable(EditorBrowsableState.Advanced)]
3928 protected virtual void OnParentRightToLeftChanged(EventArgs e) {
3929 if (right_to_left==RightToLeft.Inherit) {
3931 OnRightToLeftChanged(e);
3935 [EditorBrowsable(EditorBrowsableState.Advanced)]
3936 protected virtual void OnParentVisibleChanged(EventArgs e) {
3938 OnVisibleChanged(e);
3942 [EditorBrowsable(EditorBrowsableState.Advanced)]
3943 protected virtual void OnQueryContinueDrag(QueryContinueDragEventArgs e) {
3944 if (QueryContinueDrag!=null) QueryContinueDrag(this, e);
3947 [EditorBrowsable(EditorBrowsableState.Advanced)]
3948 protected virtual void OnResize(EventArgs e) {
3949 if (Resize!=null) Resize(this, e);
3951 PerformLayout(this, "bounds");
3953 if (parent != null) {
3954 parent.PerformLayout();
3958 [EditorBrowsable(EditorBrowsableState.Advanced)]
3959 protected virtual void OnRightToLeftChanged(EventArgs e) {
3960 if (RightToLeftChanged!=null) RightToLeftChanged(this, e);
3961 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentRightToLeftChanged(e);
3964 [EditorBrowsable(EditorBrowsableState.Advanced)]
3965 protected virtual void OnSizeChanged(EventArgs e) {
3966 InvalidateBuffers ();
3968 if (SizeChanged!=null) SizeChanged(this, e);
3971 [EditorBrowsable(EditorBrowsableState.Advanced)]
3972 protected virtual void OnStyleChanged(EventArgs e) {
3973 if (StyleChanged!=null) StyleChanged(this, e);
3976 [EditorBrowsable(EditorBrowsableState.Advanced)]
3977 protected virtual void OnSystemColorsChanged(EventArgs e) {
3978 if (SystemColorsChanged!=null) SystemColorsChanged(this, e);
3981 [EditorBrowsable(EditorBrowsableState.Advanced)]
3982 protected virtual void OnTabIndexChanged(EventArgs e) {
3983 if (TabIndexChanged!=null) TabIndexChanged(this, e);
3986 [EditorBrowsable(EditorBrowsableState.Advanced)]
3987 protected virtual void OnTabStopChanged(EventArgs e) {
3988 if (TabStopChanged!=null) TabStopChanged(this, e);
3991 [EditorBrowsable(EditorBrowsableState.Advanced)]
3992 protected virtual void OnTextChanged(EventArgs e) {
3993 if (TextChanged!=null) TextChanged(this, e);
3996 [EditorBrowsable(EditorBrowsableState.Advanced)]
3997 protected virtual void OnValidated(EventArgs e) {
3998 if (Validated!=null) Validated(this, e);
4001 [EditorBrowsable(EditorBrowsableState.Advanced)]
4002 protected virtual void OnValidating(System.ComponentModel.CancelEventArgs e) {
4003 if (Validating!=null) Validating(this, e);
4006 [EditorBrowsable(EditorBrowsableState.Advanced)]
4007 protected virtual void OnVisibleChanged(EventArgs e) {
4014 if (bmp_mem!=null) {
4020 if (!this.IsHandleCreated) {
4021 this.CreateControl();
4027 if (VisibleChanged!=null) VisibleChanged(this, e);
4029 // We need to tell our kids
4030 for (int i=0; i<child_controls.Count; i++) {
4031 child_controls[i].OnParentVisibleChanged(e);
4034 #endregion // OnXXX methods
4037 public event EventHandler BackColorChanged;
4038 public event EventHandler BackgroundImageChanged;
4039 public event EventHandler BindingContextChanged;
4040 public event EventHandler CausesValidationChanged;
4041 public event UICuesEventHandler ChangeUICues;
4042 public event EventHandler Click;
4043 public event EventHandler ContextMenuChanged;
4045 [EditorBrowsable(EditorBrowsableState.Advanced)]
4047 public event ControlEventHandler ControlAdded;
4049 [EditorBrowsable(EditorBrowsableState.Advanced)]
4051 public event ControlEventHandler ControlRemoved;
4053 [MWFDescription("Fired when the cursor for the control has been changed"), MWFCategory("PropertyChanged")]
4054 public event EventHandler CursorChanged;
4055 public event EventHandler DockChanged;
4056 public event EventHandler DoubleClick;
4057 public event DragEventHandler DragDrop;
4058 public event DragEventHandler DragEnter;
4059 public event EventHandler DragLeave;
4060 public event DragEventHandler DragOver;
4061 public event EventHandler EnabledChanged;
4062 public event EventHandler Enter;
4063 public event EventHandler FontChanged;
4064 public event EventHandler ForeColorChanged;
4065 public event GiveFeedbackEventHandler GiveFeedback;
4067 [EditorBrowsable(EditorBrowsableState.Advanced)]
4069 public event EventHandler GotFocus;
4071 [EditorBrowsable(EditorBrowsableState.Advanced)]
4073 public event EventHandler HandleCreated;
4075 [EditorBrowsable(EditorBrowsableState.Advanced)]
4077 public event EventHandler HandleDestroyed;
4079 public event HelpEventHandler HelpRequested;
4080 public event EventHandler ImeModeChanged;
4082 [EditorBrowsable(EditorBrowsableState.Advanced)]
4084 public event InvalidateEventHandler Invalidated;
4086 public event KeyEventHandler KeyDown;
4087 public event KeyPressEventHandler KeyPress;
4088 public event KeyEventHandler KeyUp;
4089 public event LayoutEventHandler Layout;
4090 public event EventHandler Leave;
4091 public event EventHandler LocationChanged;
4093 [EditorBrowsable(EditorBrowsableState.Advanced)]
4095 public event EventHandler LostFocus;
4097 public event MouseEventHandler MouseDown;
4098 public event EventHandler MouseEnter;
4099 public event EventHandler MouseHover;
4100 public event EventHandler MouseLeave;
4101 public event MouseEventHandler MouseMove;
4102 public event MouseEventHandler MouseUp;
4104 [EditorBrowsable(EditorBrowsableState.Advanced)]
4106 public event MouseEventHandler MouseWheel;
4108 public event EventHandler Move;
4109 public event PaintEventHandler Paint;
4110 public event EventHandler ParentChanged;
4111 public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp;
4112 public event QueryContinueDragEventHandler QueryContinueDrag;
4113 public event EventHandler Resize;
4114 public event EventHandler RightToLeftChanged;
4115 public event EventHandler SizeChanged;
4116 public event EventHandler StyleChanged;
4117 public event EventHandler SystemColorsChanged;
4118 public event EventHandler TabIndexChanged;
4119 public event EventHandler TabStopChanged;
4120 public event EventHandler TextChanged;
4121 public event EventHandler Validated;
4122 public event CancelEventHandler Validating;
4123 public event EventHandler VisibleChanged;
4124 #endregion // Events