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)
294 for (int i = 0; i < list.Count; i++) {
295 if (list [i] == value) {
296 // Do we need to do anything here?
301 if (value.tab_index == -1) {
307 end = owner.child_controls.Count;
308 for (int i = 0; i < end; i++) {
309 index = owner.child_controls[i].tab_index;
314 value.tab_index = use;
318 value.Parent = owner;
319 owner.UpdateZOrder();
320 owner.OnControlAdded(new ControlEventArgs(value));
323 public virtual void AddRange (Control[] controls)
325 if (controls == null)
326 throw new ArgumentNullException ("controls");
328 owner.SuspendLayout ();
331 for (int i = 0; i < controls.Length; i++)
334 owner.ResumeLayout ();
338 public virtual void Clear ()
340 owner.SuspendLayout();
341 for (int i = 0; i < list.Count; i++) {
342 owner.OnControlRemoved(new ControlEventArgs((Control)list[i]));
345 owner.ResumeLayout();
348 public bool Contains (Control value)
350 return list.Contains (value);
353 public void CopyTo (Array array, int index)
355 list.CopyTo(array, index);
358 public override bool Equals(object other) {
359 if (other is ControlCollection && (((ControlCollection)other).owner==this.owner)) {
366 public int GetChildIndex(Control child) {
367 return GetChildIndex(child, false);
370 public int GetChildIndex(Control child, bool throwException) {
373 index=list.IndexOf(child);
375 if (index==-1 && throwException) {
376 throw new ArgumentException("Not a child control", "child");
381 public IEnumerator GetEnumerator() {
382 return list.GetEnumerator();
385 public override int GetHashCode() {
386 return base.GetHashCode();
389 public int IndexOf(Control control) {
390 return list.IndexOf(control);
393 public virtual void Remove(Control value) {
394 owner.OnControlRemoved(new ControlEventArgs(value));
397 owner.UpdateZOrder();
400 public void RemoveAt(int index) {
401 if (index < 0 || index >= list.Count) {
402 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
404 Remove ((Control)list[index]);
407 public void SetChildIndex(Control child, int newIndex) {
410 old_index=list.IndexOf(child);
412 throw new ArgumentException("Not a child control", "child");
415 if (old_index==newIndex) {
421 if (newIndex>list.Count) {
424 list.Insert(newIndex, child);
426 owner.UpdateZOrder();
428 #endregion // ControlCollection Private Instance Methods
430 #region ControlCollection Interface Properties
431 object IList.this[int index] {
433 if (index<0 || index>=list.Count) {
434 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
440 if (!(value is Control)) {
441 throw new ArgumentException("Object of type Control required", "value");
444 list[index]=(Control)value;
448 bool IList.IsFixedSize {
454 bool IList.IsReadOnly {
456 return list.IsReadOnly;
460 bool ICollection.IsSynchronized {
462 return list.IsSynchronized;
466 object ICollection.SyncRoot {
468 return list.SyncRoot;
471 #endregion // ControlCollection Interface Properties
473 #region ControlCollection Interface Methods
474 int IList.Add(object value) {
476 throw new ArgumentNullException("value", "Cannot add null controls");
479 if (!(value is Control)) {
480 throw new ArgumentException("Object of type Control required", "value");
483 return list.Add(value);
486 bool IList.Contains(object value) {
487 if (!(value is Control)) {
488 throw new ArgumentException("Object of type Control required", "value");
491 return this.Contains((Control) value);
494 int IList.IndexOf(object value) {
495 if (!(value is Control)) {
496 throw new ArgumentException("Object of type Control required", "value");
499 return this.IndexOf((Control) value);
502 void IList.Insert(int index, object value) {
503 if (!(value is Control)) {
504 throw new ArgumentException("Object of type Control required", "value");
506 list.Insert(index, value);
509 void IList.Remove(object value) {
510 if (!(value is Control)) {
511 throw new ArgumentException("Object of type Control required", "value");
516 void ICollection.CopyTo(Array array, int index) {
518 list.CopyTo(array, index);
522 Object ICloneable.Clone() {
523 ControlCollection clone = new ControlCollection(this.owner);
524 clone.list=(ArrayList)list.Clone(); // FIXME: Do we need this?
527 #endregion // ControlCollection Interface Methods
529 #endregion // ControlCollection Class
531 #region Public Constructors
533 creator_thread = Thread.CurrentThread;
535 prev_size = Size.Empty;
536 anchor_style = AnchorStyles.Top | AnchorStyles.Left;
538 create_handled = false;
544 layout_pending = false;
546 causes_validation = true;
548 layout_suspended = 0;
552 right_to_left = RightToLeft.Inherit;
554 control_style = ControlStyles.Selectable | ControlStyles.StandardClick | ControlStyles.StandardDoubleClick;
557 background_image = null;
561 window = new ControlNativeWindow(this);
562 child_controls = CreateControlsInstance();
563 client_size = new Size(DefaultSize.Width, DefaultSize.Height);
564 client_rect = new Rectangle(0, 0, DefaultSize.Width, DefaultSize.Height);
565 XplatUI.CalculateWindowRect(IntPtr.Zero, ref client_rect, CreateParams.Style, CreateParams.ExStyle, IntPtr.Zero, out bounds);
566 if ((CreateParams.Style & (int)WindowStyles.WS_CHILD) == 0) {
572 public Control(Control parent, string text) : this() {
577 public Control(Control parent, string text, int left, int top, int width, int height) : this() {
582 bounds.Height=height;
583 SetBoundsCore(left, top, width, height, BoundsSpecified.All);
587 public Control(string text) : this() {
591 public Control(string text, int left, int top, int width, int height) : this() {
595 bounds.Height=height;
596 SetBoundsCore(left, top, width, height, BoundsSpecified.All);
600 protected override void Dispose(bool disposing) {
613 controls.Remove(this);
615 #endregion // Public Constructors
617 #region Internal Properties
618 internal BorderStyle InternalBorderStyle {
624 if (border_style != value) {
625 border_style = value;
627 XplatUI.SetBorderStyle(window.Handle, border_style);
631 #endregion // Internal Properties
633 #region Private & Internal Methods
634 internal IAsyncResult BeginInvokeInternal (Delegate method, object [] args) {
635 AsyncMethodResult result;
636 AsyncMethodData data;
641 if (!p.IsHandleCreated) {
642 throw new InvalidOperationException("Cannot call Invoke or InvokeAsync on a control until the window handle is created");
647 result = new AsyncMethodResult ();
648 data = new AsyncMethodData ();
650 data.Method = method;
652 data.Result = new WeakReference (result);
655 if (!ExecutionContext.IsFlowSuppressed ()) {
656 data.Context = ExecutionContext.Capture ();
659 #if !MWF_ON_MSRUNTIME
660 if (SecurityManager.SecurityEnabled) {
661 data.Stack = CompressedStack.GetCompressedStack ();
666 XplatUI.SendAsyncMethod (data);
670 internal Graphics DeviceContext {
673 CreateBuffers(this.Width, this.Height);
679 private Bitmap ImageBuffer {
682 CreateBuffers(this.Width, this.Height);
688 internal void CreateBuffers (int width, int height) {
689 if (dc_mem != null) {
703 bmp_mem = new Bitmap (width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
704 dc_mem = Graphics.FromImage (bmp_mem);
708 internal void InvalidateBuffers ()
710 if (dc_mem != null) {
721 internal static void SetChildColor(Control parent) {
724 for (int i=0; i < parent.child_controls.Count; i++) {
725 child=parent.child_controls[i];
726 if (child.IsHandleCreated) {
727 XplatUI.SetWindowBackground(child.window.Handle, child.BackColor);
729 if (child.child_controls.Count>0) {
730 SetChildColor(child);
736 internal bool Select(Control control) {
738 IContainerControl container;
740 if (control == null) {
744 parent = control.parent;
746 if (((control.control_style & ControlStyles.Selectable) !=0) && (parent != null)) {
747 while (parent != null) {
748 if (!parent.Visible || !parent.is_enabled) {
751 parent = parent.parent;
755 control.is_selected = true;
757 container = GetContainerControl();
758 if (container != null) {
759 container.ActiveControl = control;
761 if (control.IsHandleCreated) {
762 XplatUI.SetFocus(control.window.Handle);
767 internal virtual void DoDefaultAction() {
768 // Only here to be overriden by our actual controls; this is needed by the accessibility class
771 internal static int LowOrder (int param) {
772 return ((int)(short)(param & 0xffff));
775 internal static int HighOrder (int param) {
776 return ((int)(short)(param >> 16));
779 // This method exists so controls overriding OnPaintBackground can have default background painting done
780 internal void PaintControlBackground (PaintEventArgs pevent)
782 if (background_image == null)
785 DrawBackgroundImage (pevent.Graphics);
788 void DrawBackgroundImage (Graphics g)
790 using (TextureBrush b = new TextureBrush (background_image)) {
791 g.FillRectangle (b, ClientRectangle);
795 internal void DndEnter (DragEventArgs e)
800 internal void DndOver (DragEventArgs e)
805 internal void DndDrop (DragEventArgs e)
810 internal void DndLeave (EventArgs e)
815 internal void DnDFeedback(GiveFeedbackEventArgs e)
820 internal void DnDContinueDrag(QueryContinueDragEventArgs e) {
821 OnQueryContinueDrag(e);
824 internal static MouseButtons FromParamToMouseButtons (int param) {
825 MouseButtons buttons = MouseButtons.None;
827 if ((param & (int) MsgButtons.MK_LBUTTON) != 0)
828 buttons |= MouseButtons.Left;
830 if ((param & (int) MsgButtons.MK_MBUTTON) != 0)
831 buttons |= MouseButtons.Middle;
833 if ((param & (int) MsgButtons.MK_RBUTTON) != 0)
834 buttons |= MouseButtons.Right;
840 internal virtual bool ProcessControlMnemonic(char charCode) {
841 return ProcessMnemonic(charCode);
844 private static Control FindFlatForward(Control container, Control start) {
850 end = container.child_controls.Count;
853 index = start.tab_index;
858 for (int i = 0; i < end; i++) {
860 if (container.child_controls[i].tab_index > index) {
861 found = container.child_controls[i];
863 } else if (found.tab_index > container.child_controls[i].tab_index) {
864 if (container.child_controls[i].tab_index > index) {
865 found = container.child_controls[i];
872 private static Control FindControlForward(Control container, Control start) {
879 if ((start is IContainerControl) || start.GetStyle(ControlStyles.ContainerControl)) {
880 found = FindControlForward(start, null);
887 while (p != container) {
888 found = FindFlatForward(p, start);
896 return FindFlatForward(container, start);
899 private static Control FindFlatBackward(Control container, Control start) {
905 end = container.child_controls.Count;
908 index = start.tab_index;
910 // FIXME: Possible speed-up: Keep the highest taborder index in the container
912 for (int i = 0; i < end; i++) {
913 if (container.child_controls[i].tab_index > index) {
914 index = container.child_controls[i].tab_index;
920 for (int i = 0; i < end; i++) {
922 if (container.child_controls[i].tab_index < index) {
923 found = container.child_controls[i];
925 } else if (found.tab_index < container.child_controls[i].tab_index) {
926 if (container.child_controls[i].tab_index < index) {
927 found = container.child_controls[i];
934 private static Control FindControlBackward(Control container, Control start) {
940 found = FindFlatBackward(start.parent, start);
941 if (found == null && start.parent != container) {
946 found = FindFlatBackward(container, start);
949 while ((found != null) && ((found is IContainerControl) || found.GetStyle(ControlStyles.ContainerControl))) {
950 found = FindControlBackward(found, null);
959 private void HandleClick(int clicks) {
960 if (GetStyle(ControlStyles.StandardClick)) {
962 if (GetStyle(ControlStyles.StandardDoubleClick)) {
963 OnDoubleClick(EventArgs.Empty);
965 OnClick(EventArgs.Empty);
968 OnClick(EventArgs.Empty);
973 private void CheckDataBindings ()
975 if (data_bindings == null)
978 BindingContext binding_context = BindingContext;
979 foreach (Binding binding in data_bindings) {
980 binding.Check (binding_context);
984 #endregion // Private & Internal Methods
986 #region Public Static Properties
987 public static Color DefaultBackColor {
989 return ThemeEngine.Current.DefaultControlBackColor;
993 public static Font DefaultFont {
995 return ThemeEngine.Current.DefaultFont;
999 public static Color DefaultForeColor {
1001 return ThemeEngine.Current.DefaultControlForeColor;
1005 public static Keys ModifierKeys {
1007 return XplatUI.State.ModifierKeys;
1011 public static MouseButtons MouseButtons {
1013 return XplatUI.State.MouseButtons;
1017 public static Point MousePosition {
1019 return Cursor.Position;
1025 public static bool CheckForIllegalCrossThreadCalls
1034 #endregion // Public Static Properties
1036 #region Public Instance Properties
1037 [EditorBrowsable(EditorBrowsableState.Advanced)]
1039 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1040 public AccessibleObject AccessibilityObject {
1042 if (accessibility_object==null) {
1043 accessibility_object=CreateAccessibilityInstance();
1045 return accessibility_object;
1049 [EditorBrowsable(EditorBrowsableState.Advanced)]
1051 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1052 public string AccessibleDefaultActionDescription {
1054 return AccessibilityObject.default_action;
1058 AccessibilityObject.default_action=value;
1063 [DefaultValue(null)]
1064 public string AccessibleDescription {
1066 return AccessibilityObject.description;
1070 AccessibilityObject.description=value;
1075 [DefaultValue(null)]
1076 public string AccessibleName {
1078 return AccessibilityObject.Name;
1082 AccessibilityObject.Name=value;
1086 [DefaultValue(AccessibleRole.Default)]
1087 [MWFDescription("Role of the control"), MWFCategory("Accessibility")]
1088 public AccessibleRole AccessibleRole {
1090 return AccessibilityObject.role;
1094 AccessibilityObject.role=value;
1098 [DefaultValue(false)]
1099 public virtual bool AllowDrop {
1105 if (allow_drop == value)
1109 XplatUI.SetAllowDrop (Handle, value);
1114 [RefreshProperties(RefreshProperties.Repaint)]
1115 [DefaultValue(AnchorStyles.Top | AnchorStyles.Left)]
1116 public virtual AnchorStyles Anchor {
1118 return anchor_style;
1124 if (parent != null) {
1125 parent.PerformLayout(this, "Parent");
1131 public virtual Color BackColor {
1133 if (background_color.IsEmpty) {
1135 return parent.BackColor;
1137 return DefaultBackColor;
1139 return background_color;
1143 background_color=value;
1144 if (this.IsHandleCreated) {
1145 XplatUI.SetWindowBackground(this.window.Handle, value);
1147 SetChildColor(this);
1148 OnBackColorChanged(EventArgs.Empty);
1154 [DefaultValue(null)]
1155 public virtual Image BackgroundImage {
1157 return background_image;
1161 if (background_image!=value) {
1162 background_image=value;
1163 OnBackgroundImageChanged(EventArgs.Empty);
1168 [EditorBrowsable(EditorBrowsableState.Advanced)]
1170 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1171 public virtual BindingContext BindingContext {
1173 if (binding_context != null)
1174 return binding_context;
1177 binding_context = Parent.BindingContext;
1178 return binding_context;
1181 if (binding_context != value) {
1182 binding_context = value;
1183 OnBindingContextChanged(EventArgs.Empty);
1188 [EditorBrowsable(EditorBrowsableState.Advanced)]
1190 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1193 return bounds.Y+bounds.Height;
1197 [EditorBrowsable(EditorBrowsableState.Advanced)]
1199 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1200 public Rectangle Bounds {
1206 SetBoundsCore(value.Left, value.Top, value.Width, value.Height, BoundsSpecified.All);
1210 [EditorBrowsable(EditorBrowsableState.Advanced)]
1212 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1213 public bool CanFocus {
1215 if (Visible && is_enabled && GetStyle(ControlStyles.Selectable)) {
1222 [EditorBrowsable(EditorBrowsableState.Advanced)]
1224 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1225 public bool CanSelect {
1229 if (!GetStyle(ControlStyles.Selectable) || this.parent == null) {
1233 parent = this.parent;
1234 while (parent != null) {
1235 if (!parent.is_visible || !parent.is_enabled) {
1239 parent = parent.parent;
1245 [EditorBrowsable(EditorBrowsableState.Advanced)]
1247 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1248 public bool Capture {
1250 return this.is_captured;
1254 if (this.IsHandleCreated) {
1255 if (value && !is_captured) {
1257 XplatUI.GrabWindow(this.window.Handle, IntPtr.Zero);
1258 } else if (!value && is_captured) {
1259 XplatUI.UngrabWindow(this.window.Handle);
1260 is_captured = false;
1266 [DefaultValue(true)]
1267 public bool CausesValidation {
1269 return this.causes_validation;
1273 if (this.causes_validation != value) {
1274 causes_validation = value;
1275 OnCausesValidationChanged(EventArgs.Empty);
1280 [EditorBrowsable(EditorBrowsableState.Advanced)]
1282 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1283 public Rectangle ClientRectangle {
1285 client_rect.Width = client_size.Width;
1286 client_rect.Height = client_size.Height;
1291 [EditorBrowsable(EditorBrowsableState.Advanced)]
1293 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1294 public Size ClientSize {
1297 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1298 return ((Form)this).form_parent_window.ClientSize;
1306 this.SetClientSizeCore(value.Width, value.Height);
1310 [EditorBrowsable(EditorBrowsableState.Advanced)]
1312 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1313 [DescriptionAttribute("ControlCompanyNameDescr")]
1314 public String CompanyName {
1316 return "Mono Project, Novell, Inc.";
1320 [EditorBrowsable(EditorBrowsableState.Advanced)]
1322 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1323 public bool ContainsFocus {
1329 for (int i=0; i < child_controls.Count; i++) {
1330 if (child_controls[i].ContainsFocus) {
1338 [DefaultValue(null)]
1339 public virtual ContextMenu ContextMenu {
1341 return context_menu;
1345 if (context_menu != value) {
1346 context_menu = value;
1347 OnContextMenuChanged(EventArgs.Empty);
1353 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
1354 public ControlCollection Controls {
1356 return this.child_controls;
1360 [EditorBrowsable(EditorBrowsableState.Advanced)]
1362 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1363 public bool Created {
1365 if (!this.is_disposed && (this.window.Handle != IntPtr.Zero)) {
1372 [AmbientValue(null)]
1373 public virtual Cursor Cursor {
1375 if (cursor != null) {
1379 if (parent != null) {
1380 return parent.Cursor;
1383 return Cursors.Default;
1387 if (cursor != value) {
1392 pt = Cursor.Position;
1393 if (bounds.Contains(pt)) {
1394 if (GetChildAtPoint(pt) == null) {
1395 if (cursor != null) {
1396 XplatUI.SetCursor(window.Handle, cursor.handle);
1398 if (parent != null) {
1399 XplatUI.SetCursor(window.Handle, parent.Cursor.handle);
1401 XplatUI.SetCursor(window.Handle, Cursors.def.handle);
1407 OnCursorChanged(EventArgs.Empty);
1413 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
1414 [ParenthesizePropertyName(true)]
1415 [RefreshProperties(RefreshProperties.All)]
1416 public ControlBindingsCollection DataBindings {
1418 if (data_bindings == null)
1419 data_bindings = new ControlBindingsCollection (this);
1420 return data_bindings;
1424 [EditorBrowsable(EditorBrowsableState.Advanced)]
1426 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1427 public virtual Rectangle DisplayRectangle {
1429 return ClientRectangle;
1433 [EditorBrowsable(EditorBrowsableState.Advanced)]
1435 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1436 public bool Disposing {
1443 [RefreshProperties(RefreshProperties.Repaint)]
1444 [DefaultValue(DockStyle.None)]
1445 public virtual DockStyle Dock {
1451 if (dock_style == value) {
1457 if (parent != null) {
1458 parent.PerformLayout(this, "Parent");
1461 OnDockChanged(EventArgs.Empty);
1467 public bool Enabled {
1473 if (is_enabled == value) {
1479 OnEnabledChanged (EventArgs.Empty);
1483 [EditorBrowsable(EditorBrowsableState.Advanced)]
1485 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1486 public virtual bool Focused {
1488 return this.has_focus;
1493 [AmbientValue(null)]
1495 public virtual Font Font {
1501 if (Parent != null && Parent.Font != null) {
1509 if (font != null && font.Equals (value)) {
1515 OnFontChanged (EventArgs.Empty);
1520 public virtual Color ForeColor {
1522 if (foreground_color.IsEmpty) {
1524 return parent.ForeColor;
1526 return DefaultForeColor;
1528 return foreground_color;
1532 if (foreground_color != value) {
1533 foreground_color=value;
1535 OnForeColorChanged(EventArgs.Empty);
1542 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1543 public IntPtr Handle { // IWin32Window
1545 if (!IsHandleCreated) {
1548 return window.Handle;
1552 [EditorBrowsable(EditorBrowsableState.Advanced)]
1554 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1555 public bool HasChildren {
1557 if (this.child_controls.Count>0) {
1564 [EditorBrowsable(EditorBrowsableState.Always)]
1566 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1569 return this.bounds.Height;
1573 SetBoundsCore(bounds.X, bounds.Y, bounds.Width, value, BoundsSpecified.Height);
1577 [AmbientValue(ImeMode.Inherit)]
1579 public ImeMode ImeMode {
1581 if (ime_mode == DefaultImeMode) {
1583 return parent.ImeMode;
1585 return ImeMode.NoControl; // default value
1591 if (ime_mode != value) {
1594 OnImeModeChanged(EventArgs.Empty);
1599 [EditorBrowsable(EditorBrowsableState.Advanced)]
1601 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1602 public bool InvokeRequired { // ISynchronizeInvoke
1604 if (creator_thread!=Thread.CurrentThread) {
1611 [EditorBrowsable(EditorBrowsableState.Advanced)]
1613 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1614 public bool IsAccessible {
1616 return is_accessible;
1620 is_accessible = value;
1624 [EditorBrowsable(EditorBrowsableState.Advanced)]
1626 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1627 public bool IsDisposed {
1629 return this.is_disposed;
1633 [EditorBrowsable(EditorBrowsableState.Advanced)]
1635 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1636 public bool IsHandleCreated {
1638 if ((window!=null) && (window.Handle!=IntPtr.Zero)) {
1646 [EditorBrowsable(EditorBrowsableState.Always)]
1648 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1651 return this.bounds.X;
1655 SetBoundsCore(value, bounds.Y, bounds.Width, bounds.Height, BoundsSpecified.X);
1660 public Point Location {
1662 return new Point(bounds.X, bounds.Y);
1666 SetBoundsCore(value.X, value.Y, bounds.Width, bounds.Height, BoundsSpecified.Location);
1671 public string Name {
1682 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1683 public Control Parent {
1689 if (value == this) {
1690 throw new ArgumentException("A circular control reference has been made. A control cannot be owned or parented to itself.");
1693 if (parent!=value) {
1695 parent.Controls.Remove(this);
1701 if (!parent.Controls.Contains(this)) {
1702 parent.Controls.Add(this);
1705 if (IsHandleCreated) {
1706 XplatUI.SetParent(Handle, value.Handle);
1709 OnParentChanged(EventArgs.Empty);
1715 [EditorBrowsable(EditorBrowsableState.Advanced)]
1717 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1718 public string ProductName {
1720 Type t = typeof (AssemblyProductAttribute);
1721 Assembly assembly = GetType().Module.Assembly;
1722 object [] attrs = assembly.GetCustomAttributes (t, false);
1723 AssemblyProductAttribute a = null;
1724 // On MS we get a NullRefException if product attribute is not
1726 if (attrs != null && attrs.Length > 0)
1727 a = (AssemblyProductAttribute) attrs [0];
1732 [EditorBrowsable(EditorBrowsableState.Advanced)]
1734 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1735 public string ProductVersion {
1737 Type t = typeof (AssemblyVersionAttribute);
1738 Assembly assembly = GetType().Module.Assembly;
1739 object [] attrs = assembly.GetCustomAttributes (t, false);
1740 if (attrs == null || attrs.Length < 1)
1742 return ((AssemblyVersionAttribute)attrs [0]).Version;
1746 [EditorBrowsable(EditorBrowsableState.Advanced)]
1748 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1749 public bool RecreatingHandle {
1751 return is_recreating;
1755 [EditorBrowsable(EditorBrowsableState.Advanced)]
1757 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1758 public Region Region {
1760 return new Region(this.bounds);
1767 g = this.CreateGraphics();
1768 r = value.GetBounds(g);
1770 SetBounds((int)r.X, (int)r.Y, (int)r.Width, (int)r.Height);
1776 [EditorBrowsable(EditorBrowsableState.Advanced)]
1778 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1781 return this.bounds.X+this.bounds.Width;
1785 [AmbientValue(RightToLeft.Inherit)]
1787 public virtual RightToLeft RightToLeft {
1789 if (right_to_left == RightToLeft.Inherit) {
1791 return parent.RightToLeft;
1793 return RightToLeft.No; // default value
1795 return right_to_left;
1799 if (value != right_to_left) {
1800 right_to_left = value;
1801 OnRightToLeftChanged(EventArgs.Empty);
1806 [EditorBrowsable(EditorBrowsableState.Advanced)]
1807 public override ISite Site {
1820 return new Size(Width, Height);
1824 SetBoundsCore(bounds.X, bounds.Y, value.Width, value.Height, BoundsSpecified.Size);
1829 [MergableProperty(false)]
1830 public int TabIndex {
1832 if (tab_index != -1) {
1839 if (tab_index != value) {
1841 OnTabIndexChanged(EventArgs.Empty);
1847 [DefaultValue(true)]
1848 public bool TabStop {
1854 if (tab_stop != value) {
1856 OnTabStopChanged(EventArgs.Empty);
1861 [Localizable(false)]
1863 [TypeConverter(typeof(StringConverter))]
1864 [DefaultValue(null)]
1871 control_tag = value;
1877 [BindableAttribute(true)]
1878 public virtual string Text {
1884 if (value == null) {
1885 value = String.Empty;
1890 if (IsHandleCreated) {
1891 XplatUI.Text(Handle, text);
1893 // FIXME: Do we need a Refresh() here?
1896 OnTextChanged (EventArgs.Empty);
1901 [EditorBrowsable(EditorBrowsableState.Always)]
1903 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1906 return this.bounds.Y;
1910 SetBoundsCore(bounds.X, value, bounds.Width, bounds.Height, BoundsSpecified.Y);
1914 [EditorBrowsable(EditorBrowsableState.Advanced)]
1916 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1917 public Control TopLevelControl {
1921 while (p.parent != null) {
1930 public bool Visible {
1934 } else if (parent != null) {
1935 return parent.Visible;
1942 SetVisibleCore(value);
1946 [EditorBrowsable(EditorBrowsableState.Always)]
1948 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1951 return this.bounds.Width;
1955 SetBoundsCore(bounds.X, bounds.Y, value, bounds.Height, BoundsSpecified.Width);
1959 [EditorBrowsable(EditorBrowsableState.Never)]
1961 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1962 public IWindowTarget WindowTarget {
1971 #endregion // Public Instance Properties
1973 #region Protected Instance Properties
1974 protected virtual CreateParams CreateParams {
1976 CreateParams create_params = new CreateParams();
1979 create_params.Caption = Text;
1982 create_params.Caption = text;
1986 create_params.X = Left;
1989 create_params.X = this.bounds.X;
1993 create_params.Y = Top;
1996 create_params.Y = this.bounds.Y;
2000 create_params.Width = Width;
2003 create_params.Width = this.bounds.Width;
2007 create_params.Height = Height;
2010 create_params.Height = this.bounds.Height;
2014 create_params.ClassName = XplatUI.DefaultClassName;
2015 create_params.ClassStyle = 0;
2016 create_params.ExStyle = 0;
2017 create_params.Param = 0;
2020 create_params.ExStyle |= (int)WindowStyles.WS_EX_ACCEPTFILES;
2024 create_params.Parent = parent.Handle;
2027 create_params.Style = (int)WindowStyles.WS_CHILD | (int)WindowStyles.WS_CLIPCHILDREN | (int)WindowStyles.WS_CLIPSIBLINGS;
2030 create_params.Style |= (int)WindowStyles.WS_VISIBLE;
2033 return create_params;
2037 protected virtual ImeMode DefaultImeMode {
2039 return ImeMode.Inherit;
2043 protected virtual Size DefaultSize {
2045 return new Size(100, 23);
2049 protected int FontHeight {
2059 protected bool RenderRightToLeft {
2061 return (this.right_to_left == RightToLeft.Yes);
2065 protected bool ResizeRedraw {
2067 return GetStyle(ControlStyles.ResizeRedraw);
2071 SetStyle(ControlStyles.ResizeRedraw, value);
2075 [EditorBrowsable(EditorBrowsableState.Advanced)]
2077 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2078 protected virtual bool ShowFocusCues {
2084 [EditorBrowsable(EditorBrowsableState.Advanced)]
2086 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2087 protected bool ShowKeyboardCues {
2092 #endregion // Protected Instance Properties
2094 #region Public Static Methods
2095 [EditorBrowsable(EditorBrowsableState.Advanced)]
2096 public static Control FromChildHandle(IntPtr handle) {
2097 IEnumerator control = Control.controls.GetEnumerator();
2099 while (control.MoveNext()) {
2100 if (((Control)control.Current).window.Handle == handle) {
2102 if (((Control)control.Current).Parent != null) {
2103 return ((Control)control.Current).Parent;
2110 [EditorBrowsable(EditorBrowsableState.Advanced)]
2111 public static Control FromHandle(IntPtr handle) {
2112 IEnumerator control = Control.controls.GetEnumerator();
2114 while (control.MoveNext()) {
2115 if (((Control)control.Current).window.Handle == handle) {
2117 return ((Control)control.Current);
2123 public static bool IsMnemonic(char charCode, string text) {
2126 amp = text.IndexOf('&');
2129 if (amp + 1 < text.Length) {
2130 if (text[amp + 1] != '&') {
2131 if (Char.ToUpper(charCode) == Char.ToUpper(text.ToCharArray(amp + 1, 1)[0])) {
2141 #region Protected Static Methods
2142 [EditorBrowsable(EditorBrowsableState.Advanced)]
2143 protected static bool ReflectMessage(IntPtr hWnd, ref Message m) {
2146 c = Control.FromHandle(hWnd);
2156 #region Public Instance Methods
2157 [EditorBrowsable(EditorBrowsableState.Advanced)]
2158 public IAsyncResult BeginInvoke(Delegate method) {
2159 return BeginInvokeInternal(method, null);
2162 [EditorBrowsable(EditorBrowsableState.Advanced)]
2163 public IAsyncResult BeginInvoke (Delegate method, object[] args) {
2164 return BeginInvokeInternal (method, args);
2167 public void BringToFront() {
2168 if ((parent != null) && (parent.child_controls[0]!=this)) {
2169 if (parent.child_controls.Contains(this)) {
2170 parent.child_controls.SetChildIndex(this, 0);
2174 XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, true, false);
2176 if (parent != null) {
2181 public bool Contains(Control ctl) {
2182 while (ctl != null) {
2191 public void CreateControl() {
2193 if (!IsHandleCreated) {
2197 if (!create_handled) {
2198 create_handled = true;
2202 for (int i=0; i<child_controls.Count; i++) {
2203 child_controls[i].CreateControl();
2207 public Graphics CreateGraphics() {
2208 if (!IsHandleCreated) {
2209 this.CreateControl();
2211 return Graphics.FromHwnd(this.window.Handle);
2214 public DragDropEffects DoDragDrop(object data, DragDropEffects allowedEffects) {
2215 return XplatUI.StartDrag(this.window.Handle, data, allowedEffects);
2218 [EditorBrowsable(EditorBrowsableState.Advanced)]
2219 public object EndInvoke (IAsyncResult async_result) {
2220 AsyncMethodResult result = (AsyncMethodResult) async_result;
2221 return result.EndInvoke ();
2224 public Form FindForm() {
2237 public bool Focus() {
2238 if (IsHandleCreated && !has_focus) {
2240 XplatUI.SetFocus(window.Handle);
2245 public Control GetChildAtPoint(Point pt) {
2246 // Microsoft's version of this function doesn't seem to work, so I can't check
2247 // if we only consider children or also grandchildren, etc.
2248 // I'm gonna say 'children only'
2249 for (int i=0; i<child_controls.Count; i++) {
2250 if (child_controls[i].Bounds.Contains(pt)) {
2251 return child_controls[i];
2257 public IContainerControl GetContainerControl() {
2258 Control current = this;
2260 while (current!=null) {
2261 if ((current is IContainerControl) && ((current.control_style & ControlStyles.ContainerControl)!=0)) {
2262 return (IContainerControl)current;
2264 current = current.parent;
2269 public Control GetNextControl(Control ctl, bool forward) {
2270 // If we're not a container we don't play
2271 if (!(this is IContainerControl) && !this.GetStyle(ControlStyles.ContainerControl)) {
2275 // If ctl is not contained by this, we start at the first child of this
2276 if (!this.Contains(ctl)) {
2280 // Search through our controls, starting at ctl, stepping into children as we encounter them
2281 // try to find the control with the tabindex closest to our own, or, if we're looking into
2282 // child controls, the one with the smallest tabindex
2284 return FindControlForward(this, ctl);
2286 return FindControlBackward(this, ctl);
2289 public void Hide() {
2290 this.Visible = false;
2293 public void Invalidate() {
2294 Invalidate(ClientRectangle, false);
2297 public void Invalidate(bool invalidateChildren) {
2298 Invalidate(ClientRectangle, invalidateChildren);
2301 public void Invalidate(System.Drawing.Rectangle rc) {
2302 Invalidate(rc, false);
2305 public void Invalidate(System.Drawing.Rectangle rc, bool invalidateChildren) {
2306 if (!IsHandleCreated || !Visible) {
2310 NotifyInvalidate(rc);
2312 XplatUI.Invalidate(Handle, rc, false);
2314 if (invalidateChildren) {
2315 for (int i=0; i<child_controls.Count; i++) child_controls[i].Invalidate();
2317 OnInvalidated(new InvalidateEventArgs(rc));
2320 public void Invalidate(System.Drawing.Region region) {
2321 Invalidate(region, false);
2324 [MonoTODO("Figure out if GetRegionScans is usable")]
2325 public void Invalidate(System.Drawing.Region region, bool invalidateChildren) {
2326 throw new NotImplementedException();
2328 // FIXME - should use the GetRegionScans function of the region to invalidate each area
2329 //if (invalidateChildren) {
2330 // for (int i=0; i<child_controls.Count; i++) child_controls[i].Invalidate();
2334 public object Invoke (Delegate method) {
2335 return Invoke(method, null);
2338 public object Invoke (Delegate method, object[] args) {
2339 if (!this.InvokeRequired) {
2340 return method.DynamicInvoke(args);
2343 IAsyncResult result = BeginInvoke (method, args);
2344 return EndInvoke(result);
2347 [EditorBrowsable(EditorBrowsableState.Advanced)]
2348 public void PerformLayout() {
2349 PerformLayout(null, null);
2352 [EditorBrowsable(EditorBrowsableState.Advanced)]
2353 public void PerformLayout(Control affectedControl, string affectedProperty) {
2354 LayoutEventArgs levent = new LayoutEventArgs(affectedControl, affectedProperty);
2356 if (layout_suspended>0) {
2357 layout_pending = true;
2361 layout_pending = false;
2363 // Prevent us from getting messed up
2366 // Perform all Dock and Anchor calculations
2369 AnchorStyles anchor;
2374 space=this.DisplayRectangle;
2375 if (prev_size != Size.Empty) {
2376 diff_width = space.Width - prev_size.Width;
2377 diff_height = space.Height - prev_size.Height;
2383 // Deal with docking; go through in reverse, MS docs say that lowest Z-order is closest to edge
2384 for (int i = child_controls.Count - 1; i >= 0; i--) {
2385 child=child_controls[i];
2386 switch (child.Dock) {
2387 case DockStyle.None: {
2392 case DockStyle.Left: {
2393 child.SetBounds(space.Left, space.Y, child.Width, space.Height);
2394 space.X+=child.Width;
2395 space.Width-=child.Width;
2399 case DockStyle.Top: {
2400 child.SetBounds(space.Left, space.Y, space.Width, child.Height);
2401 space.Y+=child.Height;
2402 space.Height-=child.Height;
2406 case DockStyle.Right: {
2407 child.SetBounds(space.Right-child.Width, space.Y, child.Width, space.Height);
2408 space.Width-=child.Width;
2412 case DockStyle.Bottom: {
2413 child.SetBounds(space.Left, space.Bottom-child.Height, space.Width, child.Height);
2414 space.Height-=child.Height;
2420 for (int i = child_controls.Count - 1; i >= 0; i--) {
2421 child=child_controls[i];
2423 if (child.Dock == DockStyle.Fill) {
2424 child.SetBounds(space.Left, space.Top, space.Width, space.Height);
2430 space=this.DisplayRectangle;
2432 // Deal with anchoring
2433 for (int i=0; i < child_controls.Count; i++) {
2439 child=child_controls[i];
2440 anchor=child.Anchor;
2445 height=child.Height;
2447 // If the control is docked we don't need to do anything
2448 if (child.Dock != DockStyle.None) {
2452 if ((anchor & AnchorStyles.Left) !=0 ) {
2453 if ((anchor & AnchorStyles.Right) != 0) {
2454 // Anchoring to left and right
2455 width=width+diff_width;
2459 } else if ((anchor & AnchorStyles.Right) != 0) {
2465 if ((anchor & AnchorStyles.Top) !=0 ) {
2466 if ((anchor & AnchorStyles.Bottom) != 0) {
2467 height+=diff_height;
2471 } else if ((anchor & AnchorStyles.Bottom) != 0) {
2486 child.SetBounds(left, top, width, height);
2489 // Let everyone know
2493 // Need to make sure we decremend layout_suspended
2499 public Point PointToClient (Point p) {
2503 XplatUI.ScreenToClient (Handle, ref x, ref y);
2505 return new Point (x, y);
2508 public Point PointToScreen(Point p) {
2512 XplatUI.ClientToScreen(Handle, ref x, ref y);
2514 return new Point(x, y);
2517 public virtual bool PreProcessMessage(ref Message msg) {
2520 if ((msg.Msg == (int)Msg.WM_KEYDOWN) || (msg.Msg == (int)Msg.WM_SYSKEYDOWN)) {
2521 key_data = (Keys)msg.WParam.ToInt32();
2522 if (!ProcessCmdKey(ref msg, key_data)) {
2523 if (IsInputKey(key_data)) {
2527 return ProcessDialogKey(key_data);
2531 } else if (msg.Msg == (int)Msg.WM_CHAR) {
2532 if (IsInputChar((char)msg.WParam)) {
2535 } else if (msg.Msg == (int)Msg.WM_SYSCHAR) {
2536 if (IsInputChar((char)msg.WParam)) {
2539 return ProcessDialogChar((char)msg.WParam);
2544 public Rectangle RectangleToClient(Rectangle r) {
2545 return new Rectangle(PointToClient(r.Location), r.Size);
2548 public Rectangle RectangleToScreen(Rectangle r) {
2549 return new Rectangle(PointToScreen(r.Location), r.Size);
2552 public virtual void Refresh() {
2553 if (IsHandleCreated == true) {
2557 XplatUI.UpdateWindow(window.Handle);
2559 end = child_controls.Count;
2560 for (int i=0; i < end; i++) {
2561 child_controls[i].Refresh();
2567 [EditorBrowsable(EditorBrowsableState.Never)]
2568 public virtual void ResetBackColor() {
2569 background_color = Color.Empty;
2572 [EditorBrowsable(EditorBrowsableState.Never)]
2574 public void ResetBindings() {
2578 [EditorBrowsable(EditorBrowsableState.Never)]
2579 public virtual void ResetCursor() {
2583 [EditorBrowsable(EditorBrowsableState.Never)]
2584 public virtual void ResetFont() {
2588 [EditorBrowsable(EditorBrowsableState.Never)]
2589 public virtual void ResetForeColor() {
2590 foreground_color = Color.Empty;
2593 [EditorBrowsable(EditorBrowsableState.Never)]
2594 public void ResetImeMode() {
2595 ime_mode = DefaultImeMode;
2598 [EditorBrowsable(EditorBrowsableState.Never)]
2599 public virtual void ResetRightToLeft() {
2600 right_to_left = RightToLeft.Inherit;
2603 public virtual void ResetText() {
2604 text = String.Empty;
2607 public void ResumeLayout() {
2608 ResumeLayout (true);
2611 public void ResumeLayout(bool performLayout) {
2614 if (layout_suspended > 0) {
2618 if (performLayout || layout_pending) {
2623 public void Scale(float ratio) {
2624 ScaleCore(ratio, ratio);
2627 public void Scale(float dx, float dy) {
2631 public void Select() {
2632 Select(false, false);
2635 public bool SelectNextControl(Control ctl, bool forward, bool tabStopOnly, bool nested, bool wrap) {
2640 c = GetNextControl(c, forward);
2649 if (c.CanSelect && ((c.parent == ctl.parent) || nested) && (c.tab_stop || !tabStopOnly)) {
2653 } while (c != ctl); // If we wrap back to ourselves we stop
2658 public void SendToBack() {
2659 if ((parent != null) && (parent.child_controls[parent.child_controls.Count-1]!=this)) {
2660 if (parent.child_controls.Contains(this)) {
2661 parent.child_controls.SetChildIndex(this, parent.child_controls.Count);
2665 XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, false, true);
2666 if (parent != null) {
2671 public void SetBounds(int x, int y, int width, int height) {
2672 SetBoundsCore(x, y, width, height, BoundsSpecified.All);
2675 public void SetBounds(int x, int y, int width, int height, BoundsSpecified specified) {
2676 SetBoundsCore(x, y, width, height, specified);
2679 public void Show() {
2680 if (!IsHandleCreated) {
2681 this.CreateControl();
2687 public void SuspendLayout() {
2691 public void Update() {
2692 needs_redraw = true;
2693 XplatUI.UpdateWindow(window.Handle);
2695 #endregion // Public Instance Methods
2697 #region Protected Instance Methods
2698 [EditorBrowsable(EditorBrowsableState.Advanced)]
2699 [MonoTODO("Implement this and tie it into Control.ControlAccessibleObject.NotifyClients")]
2700 protected void AccessibilityNotifyClients(AccessibleEvents accEvent, int childID) {
2701 throw new NotImplementedException();
2704 [EditorBrowsable(EditorBrowsableState.Advanced)]
2705 protected virtual AccessibleObject CreateAccessibilityInstance() {
2706 return new Control.ControlAccessibleObject(this);
2709 [EditorBrowsable(EditorBrowsableState.Advanced)]
2710 protected virtual ControlCollection CreateControlsInstance() {
2711 return new ControlCollection(this);
2714 [EditorBrowsable(EditorBrowsableState.Advanced)]
2715 protected virtual void CreateHandle() {
2717 throw new ObjectDisposedException(Name);
2720 if (IsHandleCreated) {
2724 window.CreateHandle(CreateParams);
2726 // Find out where the window manager placed us
2730 if (window.Handle!=IntPtr.Zero) {
2731 if (!controls.Contains(window.Handle)) {
2735 creator_thread = Thread.CurrentThread;
2737 XplatUI.SetWindowBackground(window.Handle, this.BackColor);
2739 OnHandleCreated(EventArgs.Empty);
2743 [EditorBrowsable(EditorBrowsableState.Advanced)]
2744 protected virtual void DefWndProc(ref Message m) {
2745 window.DefWndProc(ref m);
2748 [EditorBrowsable(EditorBrowsableState.Advanced)]
2749 protected virtual void DestroyHandle() {
2750 if (IsHandleCreated) {
2751 // Destroy our children before we destroy ourselves, to prevent them from
2752 // being implictly (without us knowing) destroyed
2753 for (int i=0; i < child_controls.Count; i++) {
2754 child_controls[i].DestroyHandle();
2758 if (window != null) {
2759 window.DestroyHandle();
2761 OnHandleDestroyed(EventArgs.Empty);
2765 protected bool GetStyle(ControlStyles flag) {
2766 return (control_style & flag) != 0;
2769 protected bool GetTopLevel() {
2773 [EditorBrowsable(EditorBrowsableState.Advanced)]
2774 protected virtual void InitLayout() {
2775 if (parent != null) {
2776 parent.PerformLayout(this, "parent");
2780 [EditorBrowsable(EditorBrowsableState.Advanced)]
2781 protected void InvokeGotFocus(Control toInvoke, EventArgs e) {
2782 toInvoke.OnGotFocus(e);
2785 [EditorBrowsable(EditorBrowsableState.Advanced)]
2786 protected void InvokeLostFocus(Control toInvoke, EventArgs e) {
2787 toInvoke.OnLostFocus(e);
2790 [EditorBrowsable(EditorBrowsableState.Advanced)]
2791 protected void InvokeOnClick(Control toInvoke, EventArgs e) {
2792 toInvoke.OnClick(e);
2795 protected void InvokePaint(Control toInvoke, PaintEventArgs e) {
2796 toInvoke.OnPaint(e);
2799 protected void InvokePaintBackground(Control toInvoke, PaintEventArgs e) {
2800 toInvoke.OnPaintBackground(e);
2803 protected virtual bool IsInputChar (char charCode) {
2804 if (parent != null) {
2805 return parent.IsInputChar(charCode);
2811 protected virtual bool IsInputKey (Keys keyData) {
2812 // Doc says this one calls IsInputChar; not sure what to do with that
2816 [EditorBrowsable(EditorBrowsableState.Advanced)]
2817 protected virtual void NotifyInvalidate(Rectangle invalidatedArea) {
2821 protected virtual bool ProcessCmdKey(ref Message msg, Keys keyData) {
2822 if ((context_menu != null) && context_menu.ProcessCmdKey(ref msg, keyData)) {
2826 if (parent != null) {
2827 return parent.ProcessCmdKey(ref msg, keyData);
2833 protected virtual bool ProcessDialogChar(char charCode) {
2834 if (parent != null) {
2835 return parent.ProcessDialogChar (charCode);
2841 protected virtual bool ProcessDialogKey (Keys keyData) {
2842 if (parent != null) {
2843 return parent.ProcessDialogKey (keyData);
2849 protected virtual bool ProcessKeyEventArgs (ref Message msg)
2851 KeyEventArgs key_event;
2854 case (int)Msg.WM_KEYDOWN: {
2855 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
2856 OnKeyDown (key_event);
2857 return key_event.Handled;
2859 case (int)Msg.WM_KEYUP: {
2860 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
2861 OnKeyUp (key_event);
2862 return key_event.Handled;
2865 case (int)Msg.WM_CHAR: {
2866 KeyPressEventArgs key_press_event;
2868 key_press_event = new KeyPressEventArgs((char)msg.WParam);
2869 OnKeyPress(key_press_event);
2870 return key_press_event.Handled;
2881 protected internal virtual bool ProcessKeyMessage(ref Message msg) {
2882 if (parent != null) {
2883 if (parent.ProcessKeyPreview(ref msg)) {
2891 protected virtual bool ProcessKeyPreview(ref Message msg) {
2892 if (parent != null) {
2893 return parent.ProcessKeyPreview(ref msg);
2899 protected virtual bool ProcessMnemonic(char charCode) {
2904 [EditorBrowsable(EditorBrowsableState.Advanced)]
2905 protected void RaiseDragEvent(object key, DragEventArgs e) {
2909 [EditorBrowsable(EditorBrowsableState.Advanced)]
2910 protected void RaiseKeyEvent(object key, KeyEventArgs e) {
2914 [EditorBrowsable(EditorBrowsableState.Advanced)]
2915 protected void RaiseMouseEvent(object key, MouseEventArgs e) {
2919 [EditorBrowsable(EditorBrowsableState.Advanced)]
2920 protected void RaisePaintEvent(object key, PaintEventArgs e) {
2924 [EditorBrowsable(EditorBrowsableState.Advanced)]
2925 protected void RecreateHandle() {
2926 IEnumerator child = child_controls.GetEnumerator();
2930 if (IsHandleCreated) {
2936 while (child.MoveNext()) {
2937 ((Control)child.Current).RecreateHandle();
2943 is_recreating = false;
2946 [EditorBrowsable(EditorBrowsableState.Advanced)]
2947 protected void ResetMouseEventArgs() {
2951 [EditorBrowsable(EditorBrowsableState.Advanced)]
2952 protected ContentAlignment RtlTranslateAlignment(ContentAlignment align) {
2953 if (right_to_left == RightToLeft.No) {
2958 case ContentAlignment.TopLeft: {
2959 return ContentAlignment.TopRight;
2962 case ContentAlignment.TopRight: {
2963 return ContentAlignment.TopLeft;
2966 case ContentAlignment.MiddleLeft: {
2967 return ContentAlignment.MiddleRight;
2970 case ContentAlignment.MiddleRight: {
2971 return ContentAlignment.MiddleLeft;
2974 case ContentAlignment.BottomLeft: {
2975 return ContentAlignment.BottomRight;
2978 case ContentAlignment.BottomRight: {
2979 return ContentAlignment.BottomLeft;
2983 // if it's center it doesn't change
2989 [EditorBrowsable(EditorBrowsableState.Advanced)]
2990 protected HorizontalAlignment RtlTranslateAlignment(HorizontalAlignment align) {
2991 if ((right_to_left == RightToLeft.No) || (align == HorizontalAlignment.Center)) {
2995 if (align == HorizontalAlignment.Left) {
2996 return HorizontalAlignment.Right;
2999 // align must be HorizontalAlignment.Right
3000 return HorizontalAlignment.Left;
3003 [EditorBrowsable(EditorBrowsableState.Advanced)]
3004 protected LeftRightAlignment RtlTranslateAlignment(LeftRightAlignment align) {
3005 if (right_to_left == RightToLeft.No) {
3009 if (align == LeftRightAlignment.Left) {
3010 return LeftRightAlignment.Right;
3013 // align must be LeftRightAlignment.Right;
3014 return LeftRightAlignment.Left;
3017 [EditorBrowsable(EditorBrowsableState.Advanced)]
3018 protected ContentAlignment RtlTranslateContent(ContentAlignment align) {
3019 return RtlTranslateAlignment(align);
3022 [EditorBrowsable(EditorBrowsableState.Advanced)]
3023 protected HorizontalAlignment RtlTranslateHorizontal(HorizontalAlignment align) {
3024 return RtlTranslateAlignment(align);
3027 [EditorBrowsable(EditorBrowsableState.Advanced)]
3028 protected LeftRightAlignment RtlTranslateLeftRight(LeftRightAlignment align) {
3029 return RtlTranslateAlignment(align);
3032 [EditorBrowsable(EditorBrowsableState.Advanced)]
3033 protected virtual void ScaleCore(float dx, float dy) {
3039 location = new Point((int)(Left * dx), (int)(Top * dy));
3040 size = this.ClientSize;
3043 if (!GetStyle(ControlStyles.FixedWidth)) {
3044 size.Width = (int)(size.Width * dx);
3047 if (!GetStyle(ControlStyles.FixedHeight)) {
3048 size.Height = (int)(size.Height * dy);
3051 Location = location;
3054 /* Now scale our children */
3055 for (int i=0; i < child_controls.Count; i++) {
3056 child_controls[i].Scale(dx, dy);
3062 protected virtual void Select(bool directed, bool forward) {
3067 // Select this control
3072 if (parent == null) {
3076 // FIXME - this thing is doing the wrong stuff, needs to be similar to SelectNextControl
3078 index = parent.child_controls.IndexOf(this);
3083 if ((index+1) < parent.child_controls.Count) {
3092 index = parent.child_controls.Count-1;
3095 result = Select(parent.child_controls[index]);
3096 } while (!result && parent.child_controls[index] != this);
3099 [EditorBrowsable(EditorBrowsableState.Advanced)]
3100 protected virtual void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
3101 // SetBoundsCore updates the Win32 control itself. UpdateBounds updates the controls variables and fires events, I'm guessing - pdb
3102 if ((specified & BoundsSpecified.X) != BoundsSpecified.X) {
3106 if ((specified & BoundsSpecified.Y) != BoundsSpecified.Y) {
3110 if ((specified & BoundsSpecified.Width) != BoundsSpecified.Width) {
3114 if ((specified & BoundsSpecified.Height) != BoundsSpecified.Height) {
3118 if (IsHandleCreated) {
3119 XplatUI.SetWindowPos(Handle, x, y, width, height);
3121 UpdateBounds(x, y, width, height);
3124 [EditorBrowsable(EditorBrowsableState.Advanced)]
3125 protected virtual void SetClientSizeCore(int x, int y) {
3126 // Calculate the actual window size from the client size (it usually stays the same or grows)
3127 Rectangle ClientRect;
3128 Rectangle WindowRect;
3131 ClientRect = new Rectangle(0, 0, x, y);
3132 cp = this.CreateParams;
3134 if (XplatUI.CalculateWindowRect(Handle, ref ClientRect, cp.Style, cp.ExStyle, IntPtr.Zero, out WindowRect)==false) {
3138 SetBoundsCore(bounds.X, bounds.Y, WindowRect.Width, WindowRect.Height, BoundsSpecified.Size);
3141 [EditorBrowsable(EditorBrowsableState.Advanced)]
3142 protected void SetStyle(ControlStyles flag, bool value) {
3144 control_style |= flag;
3146 control_style &= ~flag;
3148 OnStyleChanged(EventArgs.Empty);
3151 protected void SetTopLevel(bool value) {
3152 if ((GetTopLevel() != value) && (parent != null)) {
3153 throw new Exception();
3157 if (value == true) {
3167 is_toplevel = value;
3170 protected virtual void SetVisibleCore(bool value) {
3171 if (value!=is_visible) {
3173 XplatUI.SetVisible(Handle, value);
3174 // Explicitly move Toplevel windows to where we want them;
3175 // apparently moving unmapped toplevel windows doesn't work
3176 if (is_visible && (this is Form)) {
3177 XplatUI.SetWindowPos(window.Handle, bounds.X, bounds.Y, bounds.Width, bounds.Height);
3179 OnVisibleChanged(EventArgs.Empty);
3182 if (dc_mem != null) {
3187 if (bmp_mem != null) {
3192 this.CreateBuffers(bounds.Width, bounds.Height);
3197 if (value == false && parent != null) {
3200 // Need to start at parent, GetContainerControl might return ourselves if we're a container
3201 container = (Control)parent.GetContainerControl();
3202 if (container != null) {
3203 container.SelectNextControl(this, true, true, true, true);
3207 if (parent != null) {
3208 parent.PerformLayout(this, "visible");
3210 PerformLayout(this, "visible");
3215 [EditorBrowsable(EditorBrowsableState.Advanced)]
3216 protected void UpdateBounds() {
3224 if (!IsHandleCreated) {
3228 XplatUI.GetWindowPos(this.Handle, this is Form, out x, out y, out width, out height, out client_width, out client_height);
3230 UpdateBounds(x, y, width, height, client_width, client_height);
3233 [EditorBrowsable(EditorBrowsableState.Advanced)]
3234 protected void UpdateBounds(int x, int y, int width, int height) {
3235 // UpdateBounds only seems to set our sizes and fire events but not update the GUI window to match
3237 bool resized = false;
3239 int client_x_diff = this.bounds.Width-this.client_size.Width;
3240 int client_y_diff = this.bounds.Height-this.client_size.Height;
3242 // Needed to generate required notifications
3243 if ((this.bounds.X!=x) || (this.bounds.Y!=y)) {
3247 if ((this.Bounds.Width!=width) || (this.Bounds.Height!=height)) {
3254 bounds.Height=height;
3256 // Update client rectangle as well
3257 if (this.layout_suspended==0) {
3258 prev_size.Width=client_size.Width;
3259 prev_size.Height=client_size.Height;
3262 client_size.Width=width-client_x_diff;
3263 client_size.Height=height-client_y_diff;
3266 OnLocationChanged(EventArgs.Empty);
3270 OnSizeChanged(EventArgs.Empty);
3274 [EditorBrowsable(EditorBrowsableState.Advanced)]
3275 protected void UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) {
3276 UpdateBounds(x, y, width, height);
3278 this.client_size.Width=clientWidth;
3279 this.client_size.Height=clientHeight;
3282 [EditorBrowsable(EditorBrowsableState.Advanced)]
3283 protected void UpdateStyles() {
3284 if (!IsHandleCreated) {
3288 XplatUI.SetWindowStyle(window.Handle, CreateParams);
3291 [EditorBrowsable(EditorBrowsableState.Advanced)]
3292 protected void UpdateZOrder() {
3297 if (parent == null) {
3303 children = ctl.child_controls.Count;
3304 for (int i = 1; i < children; i++ ) {
3305 XplatUI.SetZOrder(ctl.child_controls[i].window.Handle, ctl.child_controls[i-1].window.Handle, false, false);
3308 children = child_controls.Count;
3309 for (int i = 1; i < children; i++ ) {
3310 XplatUI.SetZOrder(child_controls[i].Handle, child_controls[i-1].Handle, false, false);
3315 protected virtual void WndProc(ref Message m) {
3317 Console.WriteLine("Control received message {0}", (Msg)m.Msg);
3319 if ((this.control_style & ControlStyles.EnableNotifyMessage) != 0) {
3323 switch((Msg)m.Msg) {
3324 case Msg.WM_WINDOWPOSCHANGED: {
3327 if (GetStyle(ControlStyles.ResizeRedraw)) {
3334 case Msg.WM_PAINT: {
3335 PaintEventArgs paint_event;
3337 paint_event = XplatUI.PaintEventStart(Handle, true);
3339 if (!needs_redraw) {
3340 // Just blit the previous image
3341 paint_event.Graphics.DrawImage (ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle, GraphicsUnit.Pixel);
3342 XplatUI.PaintEventEnd(Handle, true);
3347 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
3348 dc = paint_event.SetGraphics (DeviceContext);
3351 if ((control_style & (ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint)) != (ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint)) {
3352 OnPaintBackground(paint_event);
3355 OnPaint(paint_event);
3357 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
3358 dc.DrawImage (ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle, GraphicsUnit.Pixel);
3359 paint_event.SetGraphics (dc);
3360 needs_redraw = false;
3363 XplatUI.PaintEventEnd(Handle, true);
3365 if (!GetStyle(ControlStyles.UserPaint)) {
3372 case Msg.WM_ERASEBKGND: {
3373 if (GetStyle (ControlStyles.UserPaint)) {
3374 if (!GetStyle(ControlStyles.AllPaintingInWmPaint)) {
3375 PaintEventArgs eraseEventArgs = new PaintEventArgs (m.WParam == IntPtr.Zero ? Graphics.FromHwnd (m.HWnd) :
3376 Graphics.FromHdc (m.WParam), new Rectangle (new Point (0,0),Size));
3377 OnPaintBackground (eraseEventArgs);
3380 XplatUI.EraseWindowBackground(m.HWnd, m.WParam);
3382 // The DefWndProc will never have to handle this, we don't ever set hbr on the window
3383 m.Result = (IntPtr)1;
3387 case Msg.WM_LBUTTONUP: {
3388 HandleClick(mouse_clicks);
3389 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Left,
3391 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3393 if (mouse_clicks > 1) {
3399 case Msg.WM_LBUTTONDOWN: {
3400 if (CanSelect && !is_selected) {
3403 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3404 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3410 case Msg.WM_LBUTTONDBLCLK: {
3412 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3413 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3419 case Msg.WM_MBUTTONUP: {
3420 HandleClick(mouse_clicks);
3421 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Middle,
3423 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3425 if (mouse_clicks > 1) {
3431 case Msg.WM_MBUTTONDOWN: {
3432 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3433 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3439 case Msg.WM_MBUTTONDBLCLK: {
3441 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3442 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3447 case Msg.WM_RBUTTONUP: {
3448 if (context_menu != null) {
3449 context_menu.Show(this, new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ())));
3452 HandleClick(mouse_clicks);
3453 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Right,
3455 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3457 if (mouse_clicks > 1) {
3463 case Msg.WM_RBUTTONDOWN: {
3464 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3465 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3470 case Msg.WM_RBUTTONDBLCLK: {
3472 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3473 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3478 case Msg.WM_MOUSEWHEEL: {
3480 OnMouseWheel (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3481 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3482 HighOrder(m.WParam.ToInt32())));
3487 case Msg.WM_MOUSEMOVE: {
3488 OnMouseMove (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3490 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3495 case Msg.WM_MOUSE_ENTER: {
3500 OnMouseEnter(EventArgs.Empty);
3504 case Msg.WM_MOUSE_LEAVE: {
3506 OnMouseLeave(EventArgs.Empty);
3510 case Msg.WM_MOUSEHOVER: {
3511 OnMouseHover(EventArgs.Empty);
3515 case Msg.WM_SYSKEYDOWN:
3516 case Msg.WM_KEYDOWN:
3517 case Msg.WM_SYSKEYUP:
3519 case Msg.WM_SYSCHAR:
3521 if (ProcessKeyEventArgs(ref m)) {
3525 if (PreProcessMessage(ref m)) {
3529 if (ProcessKeyMessage(ref m)) {
3538 if (m.LParam != IntPtr.Zero) {
3541 hi = new HELPINFO();
3543 hi = (HELPINFO) Marshal.PtrToStructure (m.LParam, typeof (HELPINFO));
3544 mouse_pos = new Point(hi.MousePos.x, hi.MousePos.y);
3546 mouse_pos = Control.MousePosition;
3548 OnHelpRequested(new HelpEventArgs(mouse_pos));
3549 m.Result = (IntPtr)1;
3553 case Msg.WM_KILLFOCUS: {
3554 OnLeave(EventArgs.Empty);
3555 if (CausesValidation) {
3557 e = new CancelEventArgs(false);
3566 OnValidated(EventArgs.Empty);
3569 this.has_focus = false;
3570 this.is_selected = false;
3571 OnLostFocus(EventArgs.Empty);
3575 case Msg.WM_SETFOCUS: {
3576 OnEnter(EventArgs.Empty);
3577 this.has_focus = true;
3578 OnGotFocus(EventArgs.Empty);
3583 case Msg.WM_SYSCOLORCHANGE: {
3584 ThemeEngine.Current.ResetDefaults();
3585 OnSystemColorsChanged(EventArgs.Empty);
3590 case Msg.WM_SETCURSOR: {
3591 if (cursor == null) {
3596 XplatUI.SetCursor(window.Handle, cursor.handle);
3597 m.Result = (IntPtr)1;
3608 #endregion // Public Instance Methods
3610 #region OnXXX methods
3611 [EditorBrowsable(EditorBrowsableState.Advanced)]
3612 protected virtual void OnBackColorChanged(EventArgs e) {
3613 if (BackColorChanged!=null) BackColorChanged(this, e);
3614 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackColorChanged(e);
3617 [EditorBrowsable(EditorBrowsableState.Advanced)]
3618 protected virtual void OnBackgroundImageChanged(EventArgs e) {
3619 if (BackgroundImageChanged!=null) BackgroundImageChanged(this, e);
3620 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackgroundImageChanged(e);
3623 [EditorBrowsable(EditorBrowsableState.Advanced)]
3624 protected virtual void OnBindingContextChanged(EventArgs e) {
3625 CheckDataBindings ();
3626 if (BindingContextChanged!=null) {
3627 BindingContextChanged(this, e);
3629 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBindingContextChanged(e);
3632 [EditorBrowsable(EditorBrowsableState.Advanced)]
3633 protected virtual void OnCausesValidationChanged(EventArgs e) {
3634 if (CausesValidationChanged!=null) CausesValidationChanged(this, e);
3637 [EditorBrowsable(EditorBrowsableState.Advanced)]
3638 protected virtual void OnChangeUICues(UICuesEventArgs e) {
3639 if (ChangeUICues!=null) ChangeUICues(this, e);
3642 [EditorBrowsable(EditorBrowsableState.Advanced)]
3643 protected virtual void OnClick(EventArgs e) {
3644 if (Click!=null) Click(this, e);
3647 [EditorBrowsable(EditorBrowsableState.Advanced)]
3648 protected virtual void OnContextMenuChanged(EventArgs e) {
3649 if (ContextMenuChanged!=null) ContextMenuChanged(this, e);
3652 [EditorBrowsable(EditorBrowsableState.Advanced)]
3653 protected virtual void OnControlAdded(ControlEventArgs e) {
3654 if (ControlAdded!=null) ControlAdded(this, e);
3657 [EditorBrowsable(EditorBrowsableState.Advanced)]
3658 protected virtual void OnControlRemoved(ControlEventArgs e) {
3659 if (ControlRemoved!=null) ControlRemoved(this, e);
3662 [EditorBrowsable(EditorBrowsableState.Advanced)]
3663 protected virtual void OnCreateControl() {
3667 [EditorBrowsable(EditorBrowsableState.Advanced)]
3668 protected virtual void OnCursorChanged(EventArgs e) {
3669 if (CursorChanged!=null) CursorChanged(this, e);
3672 [EditorBrowsable(EditorBrowsableState.Advanced)]
3673 protected virtual void OnDockChanged(EventArgs e) {
3674 if (DockChanged!=null) DockChanged(this, e);
3677 [EditorBrowsable(EditorBrowsableState.Advanced)]
3678 protected virtual void OnDoubleClick(EventArgs e) {
3679 if (DoubleClick!=null) DoubleClick(this, e);
3682 [EditorBrowsable(EditorBrowsableState.Advanced)]
3683 protected virtual void OnDragDrop(DragEventArgs drgevent) {
3684 if (DragDrop!=null) DragDrop(this, drgevent);
3687 [EditorBrowsable(EditorBrowsableState.Advanced)]
3688 protected virtual void OnDragEnter(DragEventArgs drgevent) {
3689 if (DragEnter!=null) DragEnter(this, drgevent);
3692 [EditorBrowsable(EditorBrowsableState.Advanced)]
3693 protected virtual void OnDragLeave(EventArgs e) {
3694 if (DragLeave!=null) DragLeave(this, e);
3697 [EditorBrowsable(EditorBrowsableState.Advanced)]
3698 protected virtual void OnDragOver(DragEventArgs drgevent) {
3699 if (DragOver!=null) DragOver(this, drgevent);
3702 [EditorBrowsable(EditorBrowsableState.Advanced)]
3703 protected virtual void OnEnabledChanged(EventArgs e) {
3704 if (EnabledChanged!=null) EnabledChanged(this, e);
3705 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentEnabledChanged(e);
3708 [EditorBrowsable(EditorBrowsableState.Advanced)]
3709 protected virtual void OnEnter(EventArgs e) {
3710 if (Enter!=null) Enter(this, e);
3713 [EditorBrowsable(EditorBrowsableState.Advanced)]
3714 protected virtual void OnFontChanged(EventArgs e) {
3715 if (FontChanged!=null) FontChanged(this, e);
3716 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentFontChanged(e);
3719 [EditorBrowsable(EditorBrowsableState.Advanced)]
3720 protected virtual void OnForeColorChanged(EventArgs e) {
3721 if (ForeColorChanged!=null) ForeColorChanged(this, e);
3722 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentForeColorChanged(e);
3725 [EditorBrowsable(EditorBrowsableState.Advanced)]
3726 protected virtual void OnGiveFeedback(GiveFeedbackEventArgs gfbevent) {
3727 if (GiveFeedback!=null) GiveFeedback(this, gfbevent);
3730 [EditorBrowsable(EditorBrowsableState.Advanced)]
3731 protected virtual void OnGotFocus(EventArgs e) {
3732 if (GotFocus!=null) GotFocus(this, e);
3735 [EditorBrowsable(EditorBrowsableState.Advanced)]
3736 protected virtual void OnHandleCreated(EventArgs e) {
3737 if (HandleCreated!=null) HandleCreated(this, e);
3740 [EditorBrowsable(EditorBrowsableState.Advanced)]
3741 protected virtual void OnHandleDestroyed(EventArgs e) {
3742 if (HandleDestroyed!=null) HandleDestroyed(this, e);
3745 [EditorBrowsable(EditorBrowsableState.Advanced)]
3746 protected virtual void OnHelpRequested(HelpEventArgs hevent) {
3747 if (HelpRequested!=null) HelpRequested(this, hevent);
3750 protected virtual void OnImeModeChanged(EventArgs e) {
3751 if (ImeModeChanged!=null) ImeModeChanged(this, e);
3754 [EditorBrowsable(EditorBrowsableState.Advanced)]
3755 protected virtual void OnInvalidated(InvalidateEventArgs e) {
3756 needs_redraw = true;
3757 if (Invalidated!=null) Invalidated(this, e);
3760 [EditorBrowsable(EditorBrowsableState.Advanced)]
3761 protected virtual void OnKeyDown(KeyEventArgs e) {
3762 if (KeyDown!=null) KeyDown(this, e);
3765 [EditorBrowsable(EditorBrowsableState.Advanced)]
3766 protected virtual void OnKeyPress(KeyPressEventArgs e) {
3767 if (KeyPress!=null) KeyPress(this, e);
3770 [EditorBrowsable(EditorBrowsableState.Advanced)]
3771 protected virtual void OnKeyUp(KeyEventArgs e) {
3772 if (KeyUp!=null) KeyUp(this, e);
3775 [EditorBrowsable(EditorBrowsableState.Advanced)]
3776 protected virtual void OnLayout(LayoutEventArgs levent) {
3777 if (Layout!=null) Layout(this, levent);
3780 [EditorBrowsable(EditorBrowsableState.Advanced)]
3781 protected virtual void OnLeave(EventArgs e) {
3782 if (Leave!=null) Leave(this, e);
3785 [EditorBrowsable(EditorBrowsableState.Advanced)]
3786 protected virtual void OnLocationChanged(EventArgs e) {
3788 if (LocationChanged!=null) LocationChanged(this, e);
3791 [EditorBrowsable(EditorBrowsableState.Advanced)]
3792 protected virtual void OnLostFocus(EventArgs e) {
3793 if (LostFocus!=null) LostFocus(this, e);
3796 [EditorBrowsable(EditorBrowsableState.Advanced)]
3797 protected virtual void OnMouseDown(MouseEventArgs e) {
3798 if (MouseDown!=null) MouseDown(this, e);
3801 [EditorBrowsable(EditorBrowsableState.Advanced)]
3802 protected virtual void OnMouseEnter(EventArgs e) {
3803 if (MouseEnter!=null) MouseEnter(this, e);
3806 [EditorBrowsable(EditorBrowsableState.Advanced)]
3807 protected virtual void OnMouseHover(EventArgs e) {
3808 if (MouseHover!=null) MouseHover(this, e);
3811 [EditorBrowsable(EditorBrowsableState.Advanced)]
3812 protected virtual void OnMouseLeave(EventArgs e) {
3813 if (MouseLeave!=null) MouseLeave(this, e);
3816 [EditorBrowsable(EditorBrowsableState.Advanced)]
3817 protected virtual void OnMouseMove(MouseEventArgs e) {
3818 if (MouseMove!=null) MouseMove(this, e);
3821 [EditorBrowsable(EditorBrowsableState.Advanced)]
3822 protected virtual void OnMouseUp(MouseEventArgs e) {
3823 if (MouseUp!=null) MouseUp(this, e);
3826 [EditorBrowsable(EditorBrowsableState.Advanced)]
3827 protected virtual void OnMouseWheel(MouseEventArgs e) {
3828 if (MouseWheel!=null) MouseWheel(this, e);
3831 [EditorBrowsable(EditorBrowsableState.Advanced)]
3832 protected virtual void OnMove(EventArgs e) {
3833 if (Move!=null) Move(this, e);
3836 [EditorBrowsable(EditorBrowsableState.Advanced)]
3837 protected virtual void OnNotifyMessage(Message m) {
3841 [EditorBrowsable(EditorBrowsableState.Advanced)]
3842 protected virtual void OnPaint(PaintEventArgs e) {
3843 if (Paint!=null) Paint(this, e);
3846 [EditorBrowsable(EditorBrowsableState.Advanced)]
3847 protected virtual void OnPaintBackground(PaintEventArgs pevent) {
3848 PaintControlBackground (pevent);
3851 [EditorBrowsable(EditorBrowsableState.Advanced)]
3852 protected virtual void OnParentBackColorChanged(EventArgs e) {
3853 if (background_color.IsEmpty && background_image==null) {
3855 OnBackColorChanged(e);
3859 [EditorBrowsable(EditorBrowsableState.Advanced)]
3860 protected virtual void OnParentBackgroundImageChanged(EventArgs e) {
3861 if (background_color.IsEmpty && background_image==null) {
3863 OnBackgroundImageChanged(e);
3867 [EditorBrowsable(EditorBrowsableState.Advanced)]
3868 protected virtual void OnParentBindingContextChanged(EventArgs e) {
3869 if (binding_context==null) {
3870 binding_context=Parent.binding_context;
3871 OnBindingContextChanged(e);
3875 [EditorBrowsable(EditorBrowsableState.Advanced)]
3876 protected virtual void OnParentChanged(EventArgs e) {
3877 if (ParentChanged!=null) ParentChanged(this, e);
3880 [EditorBrowsable(EditorBrowsableState.Advanced)]
3881 protected virtual void OnParentEnabledChanged(EventArgs e) {
3882 if (is_enabled != Parent.is_enabled) {
3883 is_enabled=Parent.is_enabled;
3885 if (EnabledChanged != null) {
3886 EnabledChanged(this, e);
3891 [EditorBrowsable(EditorBrowsableState.Advanced)]
3892 protected virtual void OnParentFontChanged(EventArgs e) {
3899 [EditorBrowsable(EditorBrowsableState.Advanced)]
3900 protected virtual void OnParentForeColorChanged(EventArgs e) {
3901 if (foreground_color.IsEmpty) {
3903 OnForeColorChanged(e);
3907 [EditorBrowsable(EditorBrowsableState.Advanced)]
3908 protected virtual void OnParentRightToLeftChanged(EventArgs e) {
3909 if (right_to_left==RightToLeft.Inherit) {
3911 OnRightToLeftChanged(e);
3915 [EditorBrowsable(EditorBrowsableState.Advanced)]
3916 protected virtual void OnParentVisibleChanged(EventArgs e) {
3918 OnVisibleChanged(e);
3922 [EditorBrowsable(EditorBrowsableState.Advanced)]
3923 protected virtual void OnQueryContinueDrag(QueryContinueDragEventArgs e) {
3924 if (QueryContinueDrag!=null) QueryContinueDrag(this, e);
3927 [EditorBrowsable(EditorBrowsableState.Advanced)]
3928 protected virtual void OnResize(EventArgs e) {
3929 if (Resize!=null) Resize(this, e);
3931 PerformLayout(this, "bounds");
3933 if (parent != null) {
3934 parent.PerformLayout();
3938 [EditorBrowsable(EditorBrowsableState.Advanced)]
3939 protected virtual void OnRightToLeftChanged(EventArgs e) {
3940 if (RightToLeftChanged!=null) RightToLeftChanged(this, e);
3941 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentRightToLeftChanged(e);
3944 [EditorBrowsable(EditorBrowsableState.Advanced)]
3945 protected virtual void OnSizeChanged(EventArgs e) {
3946 InvalidateBuffers ();
3948 if (SizeChanged!=null) SizeChanged(this, e);
3951 [EditorBrowsable(EditorBrowsableState.Advanced)]
3952 protected virtual void OnStyleChanged(EventArgs e) {
3953 if (StyleChanged!=null) StyleChanged(this, e);
3956 [EditorBrowsable(EditorBrowsableState.Advanced)]
3957 protected virtual void OnSystemColorsChanged(EventArgs e) {
3958 if (SystemColorsChanged!=null) SystemColorsChanged(this, e);
3961 [EditorBrowsable(EditorBrowsableState.Advanced)]
3962 protected virtual void OnTabIndexChanged(EventArgs e) {
3963 if (TabIndexChanged!=null) TabIndexChanged(this, e);
3966 [EditorBrowsable(EditorBrowsableState.Advanced)]
3967 protected virtual void OnTabStopChanged(EventArgs e) {
3968 if (TabStopChanged!=null) TabStopChanged(this, e);
3971 [EditorBrowsable(EditorBrowsableState.Advanced)]
3972 protected virtual void OnTextChanged(EventArgs e) {
3973 if (TextChanged!=null) TextChanged(this, e);
3976 [EditorBrowsable(EditorBrowsableState.Advanced)]
3977 protected virtual void OnValidated(EventArgs e) {
3978 if (Validated!=null) Validated(this, e);
3981 [EditorBrowsable(EditorBrowsableState.Advanced)]
3982 protected virtual void OnValidating(System.ComponentModel.CancelEventArgs e) {
3983 if (Validating!=null) Validating(this, e);
3986 [EditorBrowsable(EditorBrowsableState.Advanced)]
3987 protected virtual void OnVisibleChanged(EventArgs e) {
3994 if (bmp_mem!=null) {
4000 if (!this.IsHandleCreated) {
4001 this.CreateControl();
4007 if (VisibleChanged!=null) VisibleChanged(this, e);
4009 // We need to tell our kids
4010 for (int i=0; i<child_controls.Count; i++) {
4011 child_controls[i].OnParentVisibleChanged(e);
4014 #endregion // OnXXX methods
4017 public event EventHandler BackColorChanged;
4018 public event EventHandler BackgroundImageChanged;
4019 public event EventHandler BindingContextChanged;
4020 public event EventHandler CausesValidationChanged;
4021 public event UICuesEventHandler ChangeUICues;
4022 public event EventHandler Click;
4023 public event EventHandler ContextMenuChanged;
4025 [EditorBrowsable(EditorBrowsableState.Advanced)]
4027 public event ControlEventHandler ControlAdded;
4029 [EditorBrowsable(EditorBrowsableState.Advanced)]
4031 public event ControlEventHandler ControlRemoved;
4033 [MWFDescription("Fired when the cursor for the control has been changed"), MWFCategory("PropertyChanged")]
4034 public event EventHandler CursorChanged;
4035 public event EventHandler DockChanged;
4036 public event EventHandler DoubleClick;
4037 public event DragEventHandler DragDrop;
4038 public event DragEventHandler DragEnter;
4039 public event EventHandler DragLeave;
4040 public event DragEventHandler DragOver;
4041 public event EventHandler EnabledChanged;
4042 public event EventHandler Enter;
4043 public event EventHandler FontChanged;
4044 public event EventHandler ForeColorChanged;
4045 public event GiveFeedbackEventHandler GiveFeedback;
4047 [EditorBrowsable(EditorBrowsableState.Advanced)]
4049 public event EventHandler GotFocus;
4051 [EditorBrowsable(EditorBrowsableState.Advanced)]
4053 public event EventHandler HandleCreated;
4055 [EditorBrowsable(EditorBrowsableState.Advanced)]
4057 public event EventHandler HandleDestroyed;
4059 public event HelpEventHandler HelpRequested;
4060 public event EventHandler ImeModeChanged;
4062 [EditorBrowsable(EditorBrowsableState.Advanced)]
4064 public event InvalidateEventHandler Invalidated;
4066 public event KeyEventHandler KeyDown;
4067 public event KeyPressEventHandler KeyPress;
4068 public event KeyEventHandler KeyUp;
4069 public event LayoutEventHandler Layout;
4070 public event EventHandler Leave;
4071 public event EventHandler LocationChanged;
4073 [EditorBrowsable(EditorBrowsableState.Advanced)]
4075 public event EventHandler LostFocus;
4077 public event MouseEventHandler MouseDown;
4078 public event EventHandler MouseEnter;
4079 public event EventHandler MouseHover;
4080 public event EventHandler MouseLeave;
4081 public event MouseEventHandler MouseMove;
4082 public event MouseEventHandler MouseUp;
4084 [EditorBrowsable(EditorBrowsableState.Advanced)]
4086 public event MouseEventHandler MouseWheel;
4088 public event EventHandler Move;
4089 public event PaintEventHandler Paint;
4090 public event EventHandler ParentChanged;
4091 public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp;
4092 public event QueryContinueDragEventHandler QueryContinueDrag;
4093 public event EventHandler Resize;
4094 public event EventHandler RightToLeftChanged;
4095 public event EventHandler SizeChanged;
4096 public event EventHandler StyleChanged;
4097 public event EventHandler SystemColorsChanged;
4098 public event EventHandler TabIndexChanged;
4099 public event EventHandler TabStopChanged;
4100 public event EventHandler TextChanged;
4101 public event EventHandler Validated;
4102 public event CancelEventHandler Validating;
4103 public event EventHandler VisibleChanged;
4104 #endregion // Events