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 child.parent = owner;
431 owner.UpdateZOrder();
433 #endregion // ControlCollection Private Instance Methods
435 #region ControlCollection Interface Properties
436 object IList.this[int index] {
438 if (index<0 || index>=list.Count) {
439 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
445 if (!(value is Control)) {
446 throw new ArgumentException("Object of type Control required", "value");
449 list[index]=(Control)value;
453 bool IList.IsFixedSize {
459 bool IList.IsReadOnly {
461 return list.IsReadOnly;
465 bool ICollection.IsSynchronized {
467 return list.IsSynchronized;
471 object ICollection.SyncRoot {
473 return list.SyncRoot;
476 #endregion // ControlCollection Interface Properties
478 #region ControlCollection Interface Methods
479 int IList.Add(object value) {
481 throw new ArgumentNullException("value", "Cannot add null controls");
484 if (!(value is Control)) {
485 throw new ArgumentException("Object of type Control required", "value");
488 return list.Add(value);
491 bool IList.Contains(object value) {
492 if (!(value is Control)) {
493 throw new ArgumentException("Object of type Control required", "value");
496 return this.Contains((Control) value);
499 int IList.IndexOf(object value) {
500 if (!(value is Control)) {
501 throw new ArgumentException("Object of type Control required", "value");
504 return this.IndexOf((Control) value);
507 void IList.Insert(int index, object value) {
508 if (!(value is Control)) {
509 throw new ArgumentException("Object of type Control required", "value");
511 list.Insert(index, value);
514 void IList.Remove(object value) {
515 if (!(value is Control)) {
516 throw new ArgumentException("Object of type Control required", "value");
521 void ICollection.CopyTo(Array array, int index) {
523 list.CopyTo(array, index);
527 Object ICloneable.Clone() {
528 ControlCollection clone = new ControlCollection(this.owner);
529 clone.list=(ArrayList)list.Clone(); // FIXME: Do we need this?
532 #endregion // ControlCollection Interface Methods
534 #endregion // ControlCollection Class
536 #region Public Constructors
538 creator_thread = Thread.CurrentThread;
540 prev_size = Size.Empty;
541 anchor_style = AnchorStyles.Top | AnchorStyles.Left;
543 create_handled = false;
549 layout_pending = false;
551 causes_validation = true;
553 layout_suspended = 0;
557 right_to_left = RightToLeft.Inherit;
559 control_style = ControlStyles.Selectable | ControlStyles.StandardClick | ControlStyles.StandardDoubleClick;
562 background_image = null;
566 window = new ControlNativeWindow(this);
567 child_controls = CreateControlsInstance();
568 client_size = new Size(DefaultSize.Width, DefaultSize.Height);
569 client_rect = new Rectangle(0, 0, DefaultSize.Width, DefaultSize.Height);
570 XplatUI.CalculateWindowRect(IntPtr.Zero, ref client_rect, CreateParams.Style, CreateParams.ExStyle, IntPtr.Zero, out bounds);
571 if ((CreateParams.Style & (int)WindowStyles.WS_CHILD) == 0) {
577 public Control(Control parent, string text) : this() {
582 public Control(Control parent, string text, int left, int top, int width, int height) : this() {
587 bounds.Height=height;
588 SetBoundsCore(left, top, width, height, BoundsSpecified.All);
592 public Control(string text) : this() {
596 public Control(string text, int left, int top, int width, int height) : this() {
600 bounds.Height=height;
601 SetBoundsCore(left, top, width, height, BoundsSpecified.All);
605 protected override void Dispose(bool disposing) {
618 controls.Remove(this);
620 #endregion // Public Constructors
622 #region Internal Properties
623 internal BorderStyle InternalBorderStyle {
629 if (border_style != value) {
630 border_style = value;
633 XplatUI.SetBorderStyle(window.Handle,
638 #endregion // Internal Properties
640 #region Private & Internal Methods
641 internal IAsyncResult BeginInvokeInternal (Delegate method, object [] args) {
642 AsyncMethodResult result;
643 AsyncMethodData data;
648 if (!p.IsHandleCreated) {
649 throw new InvalidOperationException("Cannot call Invoke or InvokeAsync on a control until the window handle is created");
654 result = new AsyncMethodResult ();
655 data = new AsyncMethodData ();
657 data.Method = method;
659 data.Result = new WeakReference (result);
662 if (!ExecutionContext.IsFlowSuppressed ()) {
663 data.Context = ExecutionContext.Capture ();
666 #if !MWF_ON_MSRUNTIME
667 if (SecurityManager.SecurityEnabled) {
668 data.Stack = CompressedStack.GetCompressedStack ();
673 XplatUI.SendAsyncMethod (data);
677 internal Graphics DeviceContext {
680 CreateBuffers(this.Width, this.Height);
686 private Bitmap ImageBuffer {
689 CreateBuffers(this.Width, this.Height);
695 internal void CreateBuffers (int width, int height) {
696 if (dc_mem != null) {
710 bmp_mem = new Bitmap (width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
711 dc_mem = Graphics.FromImage (bmp_mem);
715 internal void InvalidateBuffers ()
717 if (dc_mem != null) {
728 internal static void SetChildColor(Control parent) {
731 for (int i=0; i < parent.child_controls.Count; i++) {
732 child=parent.child_controls[i];
733 if (child.IsHandleCreated) {
734 if (!child.GetStyle (ControlStyles.UserPaint)) {
735 XplatUI.SetWindowBackground(child.window.Handle, child.BackColor);
738 if (child.child_controls.Count>0) {
739 SetChildColor(child);
745 internal bool Select(Control control) {
747 IContainerControl container;
749 if (control == null) {
753 parent = control.parent;
755 if (((control.control_style & ControlStyles.Selectable) !=0) && (parent != null)) {
756 while (parent != null) {
757 if (!parent.Visible || !parent.is_enabled) {
760 parent = parent.parent;
764 control.is_selected = true;
766 container = GetContainerControl();
767 if (container != null) {
768 container.ActiveControl = control;
770 if (control.IsHandleCreated) {
771 XplatUI.SetFocus(control.window.Handle);
776 internal virtual void DoDefaultAction() {
777 // Only here to be overriden by our actual controls; this is needed by the accessibility class
780 internal static int LowOrder (int param) {
781 return ((int)(short)(param & 0xffff));
784 internal static int HighOrder (int param) {
785 return ((int)(short)(param >> 16));
788 // This method exists so controls overriding OnPaintBackground can have default background painting done
789 internal void PaintControlBackground (PaintEventArgs pevent)
791 if (background_image == null)
794 DrawBackgroundImage (pevent.Graphics);
797 void DrawBackgroundImage (Graphics g)
799 using (TextureBrush b = new TextureBrush (background_image)) {
800 g.FillRectangle (b, ClientRectangle);
804 internal void DndEnter (DragEventArgs e)
809 internal void DndOver (DragEventArgs e)
814 internal void DndDrop (DragEventArgs e)
819 internal void DndLeave (EventArgs e)
824 internal void DnDFeedback(GiveFeedbackEventArgs e)
829 internal void DnDContinueDrag(QueryContinueDragEventArgs e) {
830 OnQueryContinueDrag(e);
833 internal static MouseButtons FromParamToMouseButtons (int param) {
834 MouseButtons buttons = MouseButtons.None;
836 if ((param & (int) MsgButtons.MK_LBUTTON) != 0)
837 buttons |= MouseButtons.Left;
839 if ((param & (int) MsgButtons.MK_MBUTTON) != 0)
840 buttons |= MouseButtons.Middle;
842 if ((param & (int) MsgButtons.MK_RBUTTON) != 0)
843 buttons |= MouseButtons.Right;
849 internal virtual bool ProcessControlMnemonic(char charCode) {
850 return ProcessMnemonic(charCode);
853 private static Control FindFlatForward(Control container, Control start) {
859 end = container.child_controls.Count;
862 index = start.tab_index;
867 for (int i = 0; i < end; i++) {
869 if (container.child_controls[i].tab_index > index) {
870 found = container.child_controls[i];
872 } else if (found.tab_index > container.child_controls[i].tab_index) {
873 if (container.child_controls[i].tab_index > index) {
874 found = container.child_controls[i];
881 private static Control FindControlForward(Control container, Control start) {
888 if ((start is IContainerControl) || start.GetStyle(ControlStyles.ContainerControl)) {
889 found = FindControlForward(start, null);
896 while (p != container) {
897 found = FindFlatForward(p, start);
905 return FindFlatForward(container, start);
908 private static Control FindFlatBackward(Control container, Control start) {
914 end = container.child_controls.Count;
917 index = start.tab_index;
919 // FIXME: Possible speed-up: Keep the highest taborder index in the container
921 for (int i = 0; i < end; i++) {
922 if (container.child_controls[i].tab_index > index) {
923 index = container.child_controls[i].tab_index;
929 for (int i = 0; i < end; i++) {
931 if (container.child_controls[i].tab_index < index) {
932 found = container.child_controls[i];
934 } else if (found.tab_index < container.child_controls[i].tab_index) {
935 if (container.child_controls[i].tab_index < index) {
936 found = container.child_controls[i];
943 private static Control FindControlBackward(Control container, Control start) {
949 found = FindFlatBackward(start.parent, start);
950 if (found == null && start.parent != container) {
955 found = FindFlatBackward(container, start);
958 while ((found != null) && ((found is IContainerControl) || found.GetStyle(ControlStyles.ContainerControl))) {
959 found = FindControlBackward(found, null);
968 private void HandleClick(int clicks) {
969 if (GetStyle(ControlStyles.StandardClick)) {
971 if (GetStyle(ControlStyles.StandardDoubleClick)) {
972 OnDoubleClick(EventArgs.Empty);
974 OnClick(EventArgs.Empty);
977 OnClick(EventArgs.Empty);
982 private void CheckDataBindings ()
984 if (data_bindings == null)
987 BindingContext binding_context = BindingContext;
988 foreach (Binding binding in data_bindings) {
989 binding.Check (binding_context);
993 #endregion // Private & Internal Methods
995 #region Public Static Properties
996 public static Color DefaultBackColor {
998 return ThemeEngine.Current.DefaultControlBackColor;
1002 public static Font DefaultFont {
1004 return ThemeEngine.Current.DefaultFont;
1008 public static Color DefaultForeColor {
1010 return ThemeEngine.Current.DefaultControlForeColor;
1014 public static Keys ModifierKeys {
1016 return XplatUI.State.ModifierKeys;
1020 public static MouseButtons MouseButtons {
1022 return XplatUI.State.MouseButtons;
1026 public static Point MousePosition {
1028 return Cursor.Position;
1034 public static bool CheckForIllegalCrossThreadCalls
1043 #endregion // Public Static Properties
1045 #region Public Instance Properties
1046 [EditorBrowsable(EditorBrowsableState.Advanced)]
1048 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1049 public AccessibleObject AccessibilityObject {
1051 if (accessibility_object==null) {
1052 accessibility_object=CreateAccessibilityInstance();
1054 return accessibility_object;
1058 [EditorBrowsable(EditorBrowsableState.Advanced)]
1060 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1061 public string AccessibleDefaultActionDescription {
1063 return AccessibilityObject.default_action;
1067 AccessibilityObject.default_action=value;
1072 [DefaultValue(null)]
1073 public string AccessibleDescription {
1075 return AccessibilityObject.description;
1079 AccessibilityObject.description=value;
1084 [DefaultValue(null)]
1085 public string AccessibleName {
1087 return AccessibilityObject.Name;
1091 AccessibilityObject.Name=value;
1095 [DefaultValue(AccessibleRole.Default)]
1096 [MWFDescription("Role of the control"), MWFCategory("Accessibility")]
1097 public AccessibleRole AccessibleRole {
1099 return AccessibilityObject.role;
1103 AccessibilityObject.role=value;
1107 [DefaultValue(false)]
1108 public virtual bool AllowDrop {
1114 if (allow_drop == value)
1118 XplatUI.SetAllowDrop (Handle, value);
1123 [RefreshProperties(RefreshProperties.Repaint)]
1124 [DefaultValue(AnchorStyles.Top | AnchorStyles.Left)]
1125 public virtual AnchorStyles Anchor {
1127 return anchor_style;
1133 if (parent != null) {
1134 parent.PerformLayout(this, "Parent");
1140 public virtual Color BackColor {
1142 if (background_color.IsEmpty) {
1144 return parent.BackColor;
1146 return DefaultBackColor;
1148 return background_color;
1152 background_color=value;
1153 if (this.IsHandleCreated && !GetStyle (ControlStyles.UserPaint)) {
1154 XplatUI.SetWindowBackground(this.window.Handle, value);
1156 SetChildColor(this);
1157 OnBackColorChanged(EventArgs.Empty);
1163 [DefaultValue(null)]
1164 public virtual Image BackgroundImage {
1166 return background_image;
1170 if (background_image!=value) {
1171 background_image=value;
1172 OnBackgroundImageChanged(EventArgs.Empty);
1177 [EditorBrowsable(EditorBrowsableState.Advanced)]
1179 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1180 public virtual BindingContext BindingContext {
1182 if (binding_context != null)
1183 return binding_context;
1186 binding_context = Parent.BindingContext;
1187 return binding_context;
1190 if (binding_context != value) {
1191 binding_context = value;
1192 OnBindingContextChanged(EventArgs.Empty);
1197 [EditorBrowsable(EditorBrowsableState.Advanced)]
1199 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1202 return bounds.Y+bounds.Height;
1206 [EditorBrowsable(EditorBrowsableState.Advanced)]
1208 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1209 public Rectangle Bounds {
1215 SetBoundsCore(value.Left, value.Top, value.Width, value.Height, BoundsSpecified.All);
1219 [EditorBrowsable(EditorBrowsableState.Advanced)]
1221 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1222 public bool CanFocus {
1224 if (Visible && is_enabled && GetStyle(ControlStyles.Selectable)) {
1231 [EditorBrowsable(EditorBrowsableState.Advanced)]
1233 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1234 public bool CanSelect {
1238 if (!GetStyle(ControlStyles.Selectable) || this.parent == null) {
1242 parent = this.parent;
1243 while (parent != null) {
1244 if (!parent.is_visible || !parent.is_enabled) {
1248 parent = parent.parent;
1254 [EditorBrowsable(EditorBrowsableState.Advanced)]
1256 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1257 public bool Capture {
1259 return this.is_captured;
1263 if (this.IsHandleCreated) {
1264 if (value && !is_captured) {
1266 XplatUI.GrabWindow(this.window.Handle, IntPtr.Zero);
1267 } else if (!value && is_captured) {
1268 XplatUI.UngrabWindow(this.window.Handle);
1269 is_captured = false;
1275 [DefaultValue(true)]
1276 public bool CausesValidation {
1278 return this.causes_validation;
1282 if (this.causes_validation != value) {
1283 causes_validation = value;
1284 OnCausesValidationChanged(EventArgs.Empty);
1289 [EditorBrowsable(EditorBrowsableState.Advanced)]
1291 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1292 public Rectangle ClientRectangle {
1294 client_rect.Width = client_size.Width;
1295 client_rect.Height = client_size.Height;
1300 [EditorBrowsable(EditorBrowsableState.Advanced)]
1302 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1303 public Size ClientSize {
1306 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1307 return ((Form)this).form_parent_window.ClientSize;
1315 this.SetClientSizeCore(value.Width, value.Height);
1319 [EditorBrowsable(EditorBrowsableState.Advanced)]
1321 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1322 [DescriptionAttribute("ControlCompanyNameDescr")]
1323 public String CompanyName {
1325 return "Mono Project, Novell, Inc.";
1329 [EditorBrowsable(EditorBrowsableState.Advanced)]
1331 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1332 public bool ContainsFocus {
1338 for (int i=0; i < child_controls.Count; i++) {
1339 if (child_controls[i].ContainsFocus) {
1347 [DefaultValue(null)]
1348 public virtual ContextMenu ContextMenu {
1350 return context_menu;
1354 if (context_menu != value) {
1355 context_menu = value;
1356 OnContextMenuChanged(EventArgs.Empty);
1362 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
1363 public ControlCollection Controls {
1365 return this.child_controls;
1369 [EditorBrowsable(EditorBrowsableState.Advanced)]
1371 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1372 public bool Created {
1374 if (!this.is_disposed && (this.window.Handle != IntPtr.Zero)) {
1381 [AmbientValue(null)]
1382 public virtual Cursor Cursor {
1384 if (cursor != null) {
1388 if (parent != null) {
1389 return parent.Cursor;
1392 return Cursors.Default;
1396 if (cursor != value) {
1401 pt = Cursor.Position;
1402 if (bounds.Contains(pt)) {
1403 if (GetChildAtPoint(pt) == null) {
1404 if (cursor != null) {
1405 XplatUI.SetCursor(window.Handle, cursor.handle);
1407 if (parent != null) {
1408 XplatUI.SetCursor(window.Handle, parent.Cursor.handle);
1410 XplatUI.SetCursor(window.Handle, Cursors.def.handle);
1416 OnCursorChanged(EventArgs.Empty);
1422 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
1423 [ParenthesizePropertyName(true)]
1424 [RefreshProperties(RefreshProperties.All)]
1425 public ControlBindingsCollection DataBindings {
1427 if (data_bindings == null)
1428 data_bindings = new ControlBindingsCollection (this);
1429 return data_bindings;
1433 [EditorBrowsable(EditorBrowsableState.Advanced)]
1435 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1436 public virtual Rectangle DisplayRectangle {
1438 return ClientRectangle;
1442 [EditorBrowsable(EditorBrowsableState.Advanced)]
1444 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1445 public bool Disposing {
1452 [RefreshProperties(RefreshProperties.Repaint)]
1453 [DefaultValue(DockStyle.None)]
1454 public virtual DockStyle Dock {
1460 if (dock_style == value) {
1466 if (parent != null) {
1467 parent.PerformLayout(this, "Parent");
1470 OnDockChanged(EventArgs.Empty);
1476 public bool Enabled {
1482 if (is_enabled == value) {
1488 OnEnabledChanged (EventArgs.Empty);
1492 [EditorBrowsable(EditorBrowsableState.Advanced)]
1494 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1495 public virtual bool Focused {
1497 return this.has_focus;
1502 [AmbientValue(null)]
1504 public virtual Font Font {
1510 if (Parent != null && Parent.Font != null) {
1518 if (font != null && font.Equals (value)) {
1524 OnFontChanged (EventArgs.Empty);
1529 public virtual Color ForeColor {
1531 if (foreground_color.IsEmpty) {
1533 return parent.ForeColor;
1535 return DefaultForeColor;
1537 return foreground_color;
1541 if (foreground_color != value) {
1542 foreground_color=value;
1544 OnForeColorChanged(EventArgs.Empty);
1551 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1552 public IntPtr Handle { // IWin32Window
1554 if (!IsHandleCreated) {
1557 return window.Handle;
1561 [EditorBrowsable(EditorBrowsableState.Advanced)]
1563 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1564 public bool HasChildren {
1566 if (this.child_controls.Count>0) {
1573 [EditorBrowsable(EditorBrowsableState.Always)]
1575 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1578 return this.bounds.Height;
1582 SetBoundsCore(bounds.X, bounds.Y, bounds.Width, value, BoundsSpecified.Height);
1586 [AmbientValue(ImeMode.Inherit)]
1588 public ImeMode ImeMode {
1590 if (ime_mode == DefaultImeMode) {
1592 return parent.ImeMode;
1594 return ImeMode.NoControl; // default value
1600 if (ime_mode != value) {
1603 OnImeModeChanged(EventArgs.Empty);
1608 [EditorBrowsable(EditorBrowsableState.Advanced)]
1610 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1611 public bool InvokeRequired { // ISynchronizeInvoke
1613 if (creator_thread!=Thread.CurrentThread) {
1620 [EditorBrowsable(EditorBrowsableState.Advanced)]
1622 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1623 public bool IsAccessible {
1625 return is_accessible;
1629 is_accessible = value;
1633 [EditorBrowsable(EditorBrowsableState.Advanced)]
1635 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1636 public bool IsDisposed {
1638 return this.is_disposed;
1642 [EditorBrowsable(EditorBrowsableState.Advanced)]
1644 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1645 public bool IsHandleCreated {
1647 if ((window!=null) && (window.Handle!=IntPtr.Zero)) {
1655 [EditorBrowsable(EditorBrowsableState.Always)]
1657 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1660 return this.bounds.X;
1664 SetBoundsCore(value, bounds.Y, bounds.Width, bounds.Height, BoundsSpecified.X);
1669 public Point Location {
1671 return new Point(bounds.X, bounds.Y);
1675 SetBoundsCore(value.X, value.Y, bounds.Width, bounds.Height, BoundsSpecified.Location);
1680 public string Name {
1691 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1692 public Control Parent {
1698 if (value == this) {
1699 throw new ArgumentException("A circular control reference has been made. A control cannot be owned or parented to itself.");
1702 if (parent!=value) {
1704 parent.Controls.Remove(this);
1710 if (!parent.Controls.Contains(this)) {
1711 parent.Controls.Add(this);
1714 if (IsHandleCreated) {
1715 XplatUI.SetParent(Handle, value.Handle);
1718 OnParentChanged(EventArgs.Empty);
1724 [EditorBrowsable(EditorBrowsableState.Advanced)]
1726 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1727 public string ProductName {
1729 Type t = typeof (AssemblyProductAttribute);
1730 Assembly assembly = GetType().Module.Assembly;
1731 object [] attrs = assembly.GetCustomAttributes (t, false);
1732 AssemblyProductAttribute a = null;
1733 // On MS we get a NullRefException if product attribute is not
1735 if (attrs != null && attrs.Length > 0)
1736 a = (AssemblyProductAttribute) attrs [0];
1741 [EditorBrowsable(EditorBrowsableState.Advanced)]
1743 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1744 public string ProductVersion {
1746 Type t = typeof (AssemblyVersionAttribute);
1747 Assembly assembly = GetType().Module.Assembly;
1748 object [] attrs = assembly.GetCustomAttributes (t, false);
1749 if (attrs == null || attrs.Length < 1)
1751 return ((AssemblyVersionAttribute)attrs [0]).Version;
1755 [EditorBrowsable(EditorBrowsableState.Advanced)]
1757 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1758 public bool RecreatingHandle {
1760 return is_recreating;
1764 [EditorBrowsable(EditorBrowsableState.Advanced)]
1766 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1767 public Region Region {
1769 return new Region(this.bounds);
1776 g = this.CreateGraphics();
1777 r = value.GetBounds(g);
1779 SetBounds((int)r.X, (int)r.Y, (int)r.Width, (int)r.Height);
1785 [EditorBrowsable(EditorBrowsableState.Advanced)]
1787 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1790 return this.bounds.X+this.bounds.Width;
1794 [AmbientValue(RightToLeft.Inherit)]
1796 public virtual RightToLeft RightToLeft {
1798 if (right_to_left == RightToLeft.Inherit) {
1800 return parent.RightToLeft;
1802 return RightToLeft.No; // default value
1804 return right_to_left;
1808 if (value != right_to_left) {
1809 right_to_left = value;
1810 OnRightToLeftChanged(EventArgs.Empty);
1815 [EditorBrowsable(EditorBrowsableState.Advanced)]
1816 public override ISite Site {
1829 return new Size(Width, Height);
1833 SetBoundsCore(bounds.X, bounds.Y, value.Width, value.Height, BoundsSpecified.Size);
1838 [MergableProperty(false)]
1839 public int TabIndex {
1841 if (tab_index != -1) {
1848 if (tab_index != value) {
1850 OnTabIndexChanged(EventArgs.Empty);
1856 [DefaultValue(true)]
1857 public bool TabStop {
1863 if (tab_stop != value) {
1865 OnTabStopChanged(EventArgs.Empty);
1870 [Localizable(false)]
1872 [TypeConverter(typeof(StringConverter))]
1873 [DefaultValue(null)]
1880 control_tag = value;
1886 [BindableAttribute(true)]
1887 public virtual string Text {
1893 if (value == null) {
1894 value = String.Empty;
1899 if (IsHandleCreated) {
1900 XplatUI.Text(Handle, text);
1902 // FIXME: Do we need a Refresh() here?
1905 OnTextChanged (EventArgs.Empty);
1910 [EditorBrowsable(EditorBrowsableState.Always)]
1912 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1915 return this.bounds.Y;
1919 SetBoundsCore(bounds.X, value, bounds.Width, bounds.Height, BoundsSpecified.Y);
1923 [EditorBrowsable(EditorBrowsableState.Advanced)]
1925 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1926 public Control TopLevelControl {
1930 while (p.parent != null) {
1939 public bool Visible {
1943 } else if (parent != null) {
1944 return parent.Visible;
1951 SetVisibleCore(value);
1955 [EditorBrowsable(EditorBrowsableState.Always)]
1957 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1960 return this.bounds.Width;
1964 SetBoundsCore(bounds.X, bounds.Y, value, bounds.Height, BoundsSpecified.Width);
1968 [EditorBrowsable(EditorBrowsableState.Never)]
1970 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1971 public IWindowTarget WindowTarget {
1980 #endregion // Public Instance Properties
1982 #region Protected Instance Properties
1983 protected virtual CreateParams CreateParams {
1985 CreateParams create_params = new CreateParams();
1988 create_params.Caption = Text;
1991 create_params.Caption = text;
1995 create_params.X = Left;
1998 create_params.X = this.bounds.X;
2002 create_params.Y = Top;
2005 create_params.Y = this.bounds.Y;
2009 create_params.Width = Width;
2012 create_params.Width = this.bounds.Width;
2016 create_params.Height = Height;
2019 create_params.Height = this.bounds.Height;
2023 create_params.ClassName = XplatUI.DefaultClassName;
2024 create_params.ClassStyle = 0;
2025 create_params.ExStyle = 0;
2026 create_params.Param = 0;
2029 create_params.ExStyle |= (int)WindowStyles.WS_EX_ACCEPTFILES;
2033 create_params.Parent = parent.Handle;
2036 create_params.Style = (int)WindowStyles.WS_CHILD | (int)WindowStyles.WS_CLIPCHILDREN | (int)WindowStyles.WS_CLIPSIBLINGS;
2039 create_params.Style |= (int)WindowStyles.WS_VISIBLE;
2042 return create_params;
2046 protected virtual ImeMode DefaultImeMode {
2048 return ImeMode.Inherit;
2052 protected virtual Size DefaultSize {
2054 return new Size(100, 23);
2058 protected int FontHeight {
2068 protected bool RenderRightToLeft {
2070 return (this.right_to_left == RightToLeft.Yes);
2074 protected bool ResizeRedraw {
2076 return GetStyle(ControlStyles.ResizeRedraw);
2080 SetStyle(ControlStyles.ResizeRedraw, value);
2084 [EditorBrowsable(EditorBrowsableState.Advanced)]
2086 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2087 protected virtual bool ShowFocusCues {
2093 [EditorBrowsable(EditorBrowsableState.Advanced)]
2095 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2096 protected bool ShowKeyboardCues {
2101 #endregion // Protected Instance Properties
2103 #region Public Static Methods
2104 [EditorBrowsable(EditorBrowsableState.Advanced)]
2105 public static Control FromChildHandle(IntPtr handle) {
2106 IEnumerator control = Control.controls.GetEnumerator();
2108 while (control.MoveNext()) {
2109 if (((Control)control.Current).window.Handle == handle) {
2111 if (((Control)control.Current).Parent != null) {
2112 return ((Control)control.Current).Parent;
2119 [EditorBrowsable(EditorBrowsableState.Advanced)]
2120 public static Control FromHandle(IntPtr handle) {
2121 IEnumerator control = Control.controls.GetEnumerator();
2123 while (control.MoveNext()) {
2124 if (((Control)control.Current).window.Handle == handle) {
2126 return ((Control)control.Current);
2132 public static bool IsMnemonic(char charCode, string text) {
2135 amp = text.IndexOf('&');
2138 if (amp + 1 < text.Length) {
2139 if (text[amp + 1] != '&') {
2140 if (Char.ToUpper(charCode) == Char.ToUpper(text.ToCharArray(amp + 1, 1)[0])) {
2150 #region Protected Static Methods
2151 [EditorBrowsable(EditorBrowsableState.Advanced)]
2152 protected static bool ReflectMessage(IntPtr hWnd, ref Message m) {
2155 c = Control.FromHandle(hWnd);
2165 #region Public Instance Methods
2166 [EditorBrowsable(EditorBrowsableState.Advanced)]
2167 public IAsyncResult BeginInvoke(Delegate method) {
2168 return BeginInvokeInternal(method, null);
2171 [EditorBrowsable(EditorBrowsableState.Advanced)]
2172 public IAsyncResult BeginInvoke (Delegate method, object[] args) {
2173 return BeginInvokeInternal (method, args);
2176 public void BringToFront() {
2177 if ((parent != null) && (parent.child_controls[0]!=this)) {
2178 if (parent.child_controls.Contains(this)) {
2179 parent.child_controls.SetChildIndex(this, 0);
2183 XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, true, false);
2185 if (parent != null) {
2190 public bool Contains(Control ctl) {
2191 while (ctl != null) {
2200 public void CreateControl() {
2202 if (!IsHandleCreated) {
2206 if (!create_handled) {
2207 create_handled = true;
2211 for (int i=0; i<child_controls.Count; i++) {
2212 child_controls[i].CreateControl();
2216 public Graphics CreateGraphics() {
2217 if (!IsHandleCreated) {
2218 this.CreateControl();
2220 return Graphics.FromHwnd(this.window.Handle);
2223 public DragDropEffects DoDragDrop(object data, DragDropEffects allowedEffects) {
2224 return XplatUI.StartDrag(this.window.Handle, data, allowedEffects);
2227 [EditorBrowsable(EditorBrowsableState.Advanced)]
2228 public object EndInvoke (IAsyncResult async_result) {
2229 AsyncMethodResult result = (AsyncMethodResult) async_result;
2230 return result.EndInvoke ();
2233 public Form FindForm() {
2246 public bool Focus() {
2247 if (IsHandleCreated && !has_focus) {
2249 XplatUI.SetFocus(window.Handle);
2254 public Control GetChildAtPoint(Point pt) {
2255 // Microsoft's version of this function doesn't seem to work, so I can't check
2256 // if we only consider children or also grandchildren, etc.
2257 // I'm gonna say 'children only'
2258 for (int i=0; i<child_controls.Count; i++) {
2259 if (child_controls[i].Bounds.Contains(pt)) {
2260 return child_controls[i];
2266 public IContainerControl GetContainerControl() {
2267 Control current = this;
2269 while (current!=null) {
2270 if ((current is IContainerControl) && ((current.control_style & ControlStyles.ContainerControl)!=0)) {
2271 return (IContainerControl)current;
2273 current = current.parent;
2278 public Control GetNextControl(Control ctl, bool forward) {
2279 // If we're not a container we don't play
2280 if (!(this is IContainerControl) && !this.GetStyle(ControlStyles.ContainerControl)) {
2284 // If ctl is not contained by this, we start at the first child of this
2285 if (!this.Contains(ctl)) {
2289 // Search through our controls, starting at ctl, stepping into children as we encounter them
2290 // try to find the control with the tabindex closest to our own, or, if we're looking into
2291 // child controls, the one with the smallest tabindex
2293 return FindControlForward(this, ctl);
2295 return FindControlBackward(this, ctl);
2298 public void Hide() {
2299 this.Visible = false;
2302 public void Invalidate() {
2303 Invalidate(ClientRectangle, false);
2306 public void Invalidate(bool invalidateChildren) {
2307 Invalidate(ClientRectangle, invalidateChildren);
2310 public void Invalidate(System.Drawing.Rectangle rc) {
2311 Invalidate(rc, false);
2314 public void Invalidate(System.Drawing.Rectangle rc, bool invalidateChildren) {
2315 if (!IsHandleCreated || !Visible) {
2319 NotifyInvalidate(rc);
2321 XplatUI.Invalidate(Handle, rc, false);
2323 if (invalidateChildren) {
2324 for (int i=0; i<child_controls.Count; i++) child_controls[i].Invalidate();
2326 OnInvalidated(new InvalidateEventArgs(rc));
2329 public void Invalidate(System.Drawing.Region region) {
2330 Invalidate(region, false);
2333 [MonoTODO("Figure out if GetRegionScans is usable")]
2334 public void Invalidate(System.Drawing.Region region, bool invalidateChildren) {
2335 throw new NotImplementedException();
2337 // FIXME - should use the GetRegionScans function of the region to invalidate each area
2338 //if (invalidateChildren) {
2339 // for (int i=0; i<child_controls.Count; i++) child_controls[i].Invalidate();
2343 public object Invoke (Delegate method) {
2344 return Invoke(method, null);
2347 public object Invoke (Delegate method, object[] args) {
2348 if (!this.InvokeRequired) {
2349 return method.DynamicInvoke(args);
2352 IAsyncResult result = BeginInvoke (method, args);
2353 return EndInvoke(result);
2356 [EditorBrowsable(EditorBrowsableState.Advanced)]
2357 public void PerformLayout() {
2358 PerformLayout(null, null);
2361 [EditorBrowsable(EditorBrowsableState.Advanced)]
2362 public void PerformLayout(Control affectedControl, string affectedProperty) {
2363 LayoutEventArgs levent = new LayoutEventArgs(affectedControl, affectedProperty);
2365 if (layout_suspended>0) {
2366 layout_pending = true;
2370 layout_pending = false;
2372 // Prevent us from getting messed up
2375 // Perform all Dock and Anchor calculations
2378 AnchorStyles anchor;
2383 space=this.DisplayRectangle;
2384 if (prev_size != Size.Empty) {
2385 diff_width = space.Width - prev_size.Width;
2386 diff_height = space.Height - prev_size.Height;
2392 // Deal with docking; go through in reverse, MS docs say that lowest Z-order is closest to edge
2393 for (int i = child_controls.Count - 1; i >= 0; i--) {
2394 child=child_controls[i];
2395 switch (child.Dock) {
2396 case DockStyle.None: {
2401 case DockStyle.Left: {
2402 child.SetBounds(space.Left, space.Y, child.Width, space.Height);
2403 space.X+=child.Width;
2404 space.Width-=child.Width;
2408 case DockStyle.Top: {
2409 child.SetBounds(space.Left, space.Y, space.Width, child.Height);
2410 space.Y+=child.Height;
2411 space.Height-=child.Height;
2415 case DockStyle.Right: {
2416 child.SetBounds(space.Right-child.Width, space.Y, child.Width, space.Height);
2417 space.Width-=child.Width;
2421 case DockStyle.Bottom: {
2422 child.SetBounds(space.Left, space.Bottom-child.Height, space.Width, child.Height);
2423 space.Height-=child.Height;
2429 for (int i = child_controls.Count - 1; i >= 0; i--) {
2430 child=child_controls[i];
2432 if (child.Dock == DockStyle.Fill) {
2433 child.SetBounds(space.Left, space.Top, space.Width, space.Height);
2439 space=this.DisplayRectangle;
2441 // Deal with anchoring
2442 for (int i=0; i < child_controls.Count; i++) {
2448 child=child_controls[i];
2449 anchor=child.Anchor;
2454 height=child.Height;
2456 // If the control is docked we don't need to do anything
2457 if (child.Dock != DockStyle.None) {
2461 if ((anchor & AnchorStyles.Left) !=0 ) {
2462 if ((anchor & AnchorStyles.Right) != 0) {
2463 // Anchoring to left and right
2464 width=width+diff_width;
2468 } else if ((anchor & AnchorStyles.Right) != 0) {
2474 if ((anchor & AnchorStyles.Top) !=0 ) {
2475 if ((anchor & AnchorStyles.Bottom) != 0) {
2476 height+=diff_height;
2480 } else if ((anchor & AnchorStyles.Bottom) != 0) {
2495 child.SetBounds(left, top, width, height);
2498 // Let everyone know
2502 // Need to make sure we decremend layout_suspended
2508 public Point PointToClient (Point p) {
2512 XplatUI.ScreenToClient (Handle, ref x, ref y);
2514 return new Point (x, y);
2517 public Point PointToScreen(Point p) {
2521 XplatUI.ClientToScreen(Handle, ref x, ref y);
2523 return new Point(x, y);
2526 public virtual bool PreProcessMessage(ref Message msg) {
2529 if ((msg.Msg == (int)Msg.WM_KEYDOWN) || (msg.Msg == (int)Msg.WM_SYSKEYDOWN)) {
2530 key_data = (Keys)msg.WParam.ToInt32();
2531 if (!ProcessCmdKey(ref msg, key_data)) {
2532 if (IsInputKey(key_data)) {
2536 return ProcessDialogKey(key_data);
2540 } else if (msg.Msg == (int)Msg.WM_CHAR) {
2541 if (IsInputChar((char)msg.WParam)) {
2544 } else if (msg.Msg == (int)Msg.WM_SYSCHAR) {
2545 if (IsInputChar((char)msg.WParam)) {
2548 return ProcessDialogChar((char)msg.WParam);
2553 public Rectangle RectangleToClient(Rectangle r) {
2554 return new Rectangle(PointToClient(r.Location), r.Size);
2557 public Rectangle RectangleToScreen(Rectangle r) {
2558 return new Rectangle(PointToScreen(r.Location), r.Size);
2561 public virtual void Refresh() {
2562 if (IsHandleCreated == true) {
2566 XplatUI.UpdateWindow(window.Handle);
2568 end = child_controls.Count;
2569 for (int i=0; i < end; i++) {
2570 child_controls[i].Refresh();
2576 [EditorBrowsable(EditorBrowsableState.Never)]
2577 public virtual void ResetBackColor() {
2578 background_color = Color.Empty;
2581 [EditorBrowsable(EditorBrowsableState.Never)]
2583 public void ResetBindings() {
2587 [EditorBrowsable(EditorBrowsableState.Never)]
2588 public virtual void ResetCursor() {
2592 [EditorBrowsable(EditorBrowsableState.Never)]
2593 public virtual void ResetFont() {
2597 [EditorBrowsable(EditorBrowsableState.Never)]
2598 public virtual void ResetForeColor() {
2599 foreground_color = Color.Empty;
2602 [EditorBrowsable(EditorBrowsableState.Never)]
2603 public void ResetImeMode() {
2604 ime_mode = DefaultImeMode;
2607 [EditorBrowsable(EditorBrowsableState.Never)]
2608 public virtual void ResetRightToLeft() {
2609 right_to_left = RightToLeft.Inherit;
2612 public virtual void ResetText() {
2613 text = String.Empty;
2616 public void ResumeLayout() {
2617 ResumeLayout (true);
2620 public void ResumeLayout(bool performLayout) {
2623 if (layout_suspended > 0) {
2627 if (performLayout || layout_pending) {
2632 public void Scale(float ratio) {
2633 ScaleCore(ratio, ratio);
2636 public void Scale(float dx, float dy) {
2640 public void Select() {
2641 Select(false, false);
2644 public bool SelectNextControl(Control ctl, bool forward, bool tabStopOnly, bool nested, bool wrap) {
2649 c = GetNextControl(c, forward);
2658 if (c.CanSelect && ((c.parent == ctl.parent) || nested) && (c.tab_stop || !tabStopOnly)) {
2662 } while (c != ctl); // If we wrap back to ourselves we stop
2667 public void SendToBack() {
2668 if ((parent != null) && (parent.child_controls[parent.child_controls.Count-1]!=this)) {
2669 if (parent.child_controls.Contains(this)) {
2670 parent.child_controls.SetChildIndex(this, parent.child_controls.Count);
2674 XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, false, true);
2675 if (parent != null) {
2680 public void SetBounds(int x, int y, int width, int height) {
2681 SetBoundsCore(x, y, width, height, BoundsSpecified.All);
2684 public void SetBounds(int x, int y, int width, int height, BoundsSpecified specified) {
2685 SetBoundsCore(x, y, width, height, specified);
2688 public void Show() {
2689 if (!IsHandleCreated) {
2690 this.CreateControl();
2696 public void SuspendLayout() {
2700 public void Update() {
2701 needs_redraw = true;
2702 if (IsHandleCreated) {
2703 XplatUI.UpdateWindow(window.Handle);
2706 #endregion // Public Instance Methods
2708 #region Protected Instance Methods
2709 [EditorBrowsable(EditorBrowsableState.Advanced)]
2710 [MonoTODO("Implement this and tie it into Control.ControlAccessibleObject.NotifyClients")]
2711 protected void AccessibilityNotifyClients(AccessibleEvents accEvent, int childID) {
2712 throw new NotImplementedException();
2715 [EditorBrowsable(EditorBrowsableState.Advanced)]
2716 protected virtual AccessibleObject CreateAccessibilityInstance() {
2717 return new Control.ControlAccessibleObject(this);
2720 [EditorBrowsable(EditorBrowsableState.Advanced)]
2721 protected virtual ControlCollection CreateControlsInstance() {
2722 return new ControlCollection(this);
2725 [EditorBrowsable(EditorBrowsableState.Advanced)]
2726 protected virtual void CreateHandle() {
2728 throw new ObjectDisposedException(Name);
2731 if (IsHandleCreated) {
2735 window.CreateHandle(CreateParams);
2737 // Find out where the window manager placed us
2741 if (window.Handle!=IntPtr.Zero) {
2742 if (!controls.Contains(window.Handle)) {
2746 creator_thread = Thread.CurrentThread;
2748 if (!GetStyle (ControlStyles.UserPaint)) {
2749 XplatUI.SetWindowBackground(window.Handle, this.BackColor);
2752 OnHandleCreated(EventArgs.Empty);
2756 [EditorBrowsable(EditorBrowsableState.Advanced)]
2757 protected virtual void DefWndProc(ref Message m) {
2758 window.DefWndProc(ref m);
2761 [EditorBrowsable(EditorBrowsableState.Advanced)]
2762 protected virtual void DestroyHandle() {
2763 if (IsHandleCreated) {
2764 // Destroy our children before we destroy ourselves, to prevent them from
2765 // being implictly (without us knowing) destroyed
2766 for (int i=0; i < child_controls.Count; i++) {
2767 child_controls[i].DestroyHandle();
2771 if (window != null) {
2772 window.DestroyHandle();
2774 OnHandleDestroyed(EventArgs.Empty);
2778 protected bool GetStyle(ControlStyles flag) {
2779 return (control_style & flag) != 0;
2782 protected bool GetTopLevel() {
2786 [EditorBrowsable(EditorBrowsableState.Advanced)]
2787 protected virtual void InitLayout() {
2788 if (parent != null) {
2789 parent.PerformLayout(this, "parent");
2793 [EditorBrowsable(EditorBrowsableState.Advanced)]
2794 protected void InvokeGotFocus(Control toInvoke, EventArgs e) {
2795 toInvoke.OnGotFocus(e);
2798 [EditorBrowsable(EditorBrowsableState.Advanced)]
2799 protected void InvokeLostFocus(Control toInvoke, EventArgs e) {
2800 toInvoke.OnLostFocus(e);
2803 [EditorBrowsable(EditorBrowsableState.Advanced)]
2804 protected void InvokeOnClick(Control toInvoke, EventArgs e) {
2805 toInvoke.OnClick(e);
2808 protected void InvokePaint(Control toInvoke, PaintEventArgs e) {
2809 toInvoke.OnPaint(e);
2812 protected void InvokePaintBackground(Control toInvoke, PaintEventArgs e) {
2813 toInvoke.OnPaintBackground(e);
2816 protected virtual bool IsInputChar (char charCode) {
2817 if (parent != null) {
2818 return parent.IsInputChar(charCode);
2824 protected virtual bool IsInputKey (Keys keyData) {
2825 // Doc says this one calls IsInputChar; not sure what to do with that
2829 [EditorBrowsable(EditorBrowsableState.Advanced)]
2830 protected virtual void NotifyInvalidate(Rectangle invalidatedArea) {
2834 protected virtual bool ProcessCmdKey(ref Message msg, Keys keyData) {
2835 if ((context_menu != null) && context_menu.ProcessCmdKey(ref msg, keyData)) {
2839 if (parent != null) {
2840 return parent.ProcessCmdKey(ref msg, keyData);
2846 protected virtual bool ProcessDialogChar(char charCode) {
2847 if (parent != null) {
2848 return parent.ProcessDialogChar (charCode);
2854 protected virtual bool ProcessDialogKey (Keys keyData) {
2855 if (parent != null) {
2856 return parent.ProcessDialogKey (keyData);
2862 protected virtual bool ProcessKeyEventArgs (ref Message msg)
2864 KeyEventArgs key_event;
2867 case (int)Msg.WM_KEYDOWN: {
2868 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
2869 OnKeyDown (key_event);
2870 return key_event.Handled;
2872 case (int)Msg.WM_KEYUP: {
2873 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
2874 OnKeyUp (key_event);
2875 return key_event.Handled;
2878 case (int)Msg.WM_CHAR: {
2879 KeyPressEventArgs key_press_event;
2881 key_press_event = new KeyPressEventArgs((char)msg.WParam);
2882 OnKeyPress(key_press_event);
2883 return key_press_event.Handled;
2894 protected internal virtual bool ProcessKeyMessage(ref Message msg) {
2895 if (parent != null) {
2896 if (parent.ProcessKeyPreview(ref msg)) {
2904 protected virtual bool ProcessKeyPreview(ref Message msg) {
2905 if (parent != null) {
2906 return parent.ProcessKeyPreview(ref msg);
2912 protected virtual bool ProcessMnemonic(char charCode) {
2917 [EditorBrowsable(EditorBrowsableState.Advanced)]
2918 protected void RaiseDragEvent(object key, DragEventArgs e) {
2922 [EditorBrowsable(EditorBrowsableState.Advanced)]
2923 protected void RaiseKeyEvent(object key, KeyEventArgs e) {
2927 [EditorBrowsable(EditorBrowsableState.Advanced)]
2928 protected void RaiseMouseEvent(object key, MouseEventArgs e) {
2932 [EditorBrowsable(EditorBrowsableState.Advanced)]
2933 protected void RaisePaintEvent(object key, PaintEventArgs e) {
2937 [EditorBrowsable(EditorBrowsableState.Advanced)]
2938 protected void RecreateHandle() {
2939 IEnumerator child = child_controls.GetEnumerator();
2943 if (IsHandleCreated) {
2949 while (child.MoveNext()) {
2950 ((Control)child.Current).RecreateHandle();
2956 is_recreating = false;
2959 [EditorBrowsable(EditorBrowsableState.Advanced)]
2960 protected void ResetMouseEventArgs() {
2964 [EditorBrowsable(EditorBrowsableState.Advanced)]
2965 protected ContentAlignment RtlTranslateAlignment(ContentAlignment align) {
2966 if (right_to_left == RightToLeft.No) {
2971 case ContentAlignment.TopLeft: {
2972 return ContentAlignment.TopRight;
2975 case ContentAlignment.TopRight: {
2976 return ContentAlignment.TopLeft;
2979 case ContentAlignment.MiddleLeft: {
2980 return ContentAlignment.MiddleRight;
2983 case ContentAlignment.MiddleRight: {
2984 return ContentAlignment.MiddleLeft;
2987 case ContentAlignment.BottomLeft: {
2988 return ContentAlignment.BottomRight;
2991 case ContentAlignment.BottomRight: {
2992 return ContentAlignment.BottomLeft;
2996 // if it's center it doesn't change
3002 [EditorBrowsable(EditorBrowsableState.Advanced)]
3003 protected HorizontalAlignment RtlTranslateAlignment(HorizontalAlignment align) {
3004 if ((right_to_left == RightToLeft.No) || (align == HorizontalAlignment.Center)) {
3008 if (align == HorizontalAlignment.Left) {
3009 return HorizontalAlignment.Right;
3012 // align must be HorizontalAlignment.Right
3013 return HorizontalAlignment.Left;
3016 [EditorBrowsable(EditorBrowsableState.Advanced)]
3017 protected LeftRightAlignment RtlTranslateAlignment(LeftRightAlignment align) {
3018 if (right_to_left == RightToLeft.No) {
3022 if (align == LeftRightAlignment.Left) {
3023 return LeftRightAlignment.Right;
3026 // align must be LeftRightAlignment.Right;
3027 return LeftRightAlignment.Left;
3030 [EditorBrowsable(EditorBrowsableState.Advanced)]
3031 protected ContentAlignment RtlTranslateContent(ContentAlignment align) {
3032 return RtlTranslateAlignment(align);
3035 [EditorBrowsable(EditorBrowsableState.Advanced)]
3036 protected HorizontalAlignment RtlTranslateHorizontal(HorizontalAlignment align) {
3037 return RtlTranslateAlignment(align);
3040 [EditorBrowsable(EditorBrowsableState.Advanced)]
3041 protected LeftRightAlignment RtlTranslateLeftRight(LeftRightAlignment align) {
3042 return RtlTranslateAlignment(align);
3045 [EditorBrowsable(EditorBrowsableState.Advanced)]
3046 protected virtual void ScaleCore(float dx, float dy) {
3052 location = new Point((int)(Left * dx), (int)(Top * dy));
3053 size = this.ClientSize;
3056 if (!GetStyle(ControlStyles.FixedWidth)) {
3057 size.Width = (int)(size.Width * dx);
3060 if (!GetStyle(ControlStyles.FixedHeight)) {
3061 size.Height = (int)(size.Height * dy);
3064 Location = location;
3067 /* Now scale our children */
3068 for (int i=0; i < child_controls.Count; i++) {
3069 child_controls[i].Scale(dx, dy);
3075 protected virtual void Select(bool directed, bool forward) {
3080 // Select this control
3085 if (parent == null) {
3089 // FIXME - this thing is doing the wrong stuff, needs to be similar to SelectNextControl
3091 index = parent.child_controls.IndexOf(this);
3096 if ((index+1) < parent.child_controls.Count) {
3105 index = parent.child_controls.Count-1;
3108 result = Select(parent.child_controls[index]);
3109 } while (!result && parent.child_controls[index] != this);
3112 [EditorBrowsable(EditorBrowsableState.Advanced)]
3113 protected virtual void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
3114 // SetBoundsCore updates the Win32 control itself. UpdateBounds updates the controls variables and fires events, I'm guessing - pdb
3115 if ((specified & BoundsSpecified.X) != BoundsSpecified.X) {
3119 if ((specified & BoundsSpecified.Y) != BoundsSpecified.Y) {
3123 if ((specified & BoundsSpecified.Width) != BoundsSpecified.Width) {
3127 if ((specified & BoundsSpecified.Height) != BoundsSpecified.Height) {
3131 if (IsHandleCreated) {
3132 XplatUI.SetWindowPos(Handle, x, y, width, height);
3134 UpdateBounds(x, y, width, height);
3137 [EditorBrowsable(EditorBrowsableState.Advanced)]
3138 protected virtual void SetClientSizeCore(int x, int y) {
3139 // Calculate the actual window size from the client size (it usually stays the same or grows)
3140 Rectangle ClientRect;
3141 Rectangle WindowRect;
3144 ClientRect = new Rectangle(0, 0, x, y);
3145 cp = this.CreateParams;
3147 if (XplatUI.CalculateWindowRect(Handle, ref ClientRect, cp.Style, cp.ExStyle, IntPtr.Zero, out WindowRect)==false) {
3151 SetBoundsCore(bounds.X, bounds.Y, WindowRect.Width, WindowRect.Height, BoundsSpecified.Size);
3154 [EditorBrowsable(EditorBrowsableState.Advanced)]
3155 protected void SetStyle(ControlStyles flag, bool value) {
3157 control_style |= flag;
3159 control_style &= ~flag;
3161 OnStyleChanged(EventArgs.Empty);
3164 protected void SetTopLevel(bool value) {
3165 if ((GetTopLevel() != value) && (parent != null)) {
3166 throw new Exception();
3170 if (value == true) {
3180 is_toplevel = value;
3183 protected virtual void SetVisibleCore(bool value) {
3184 if (value!=is_visible) {
3187 if (IsHandleCreated) {
3188 XplatUI.SetVisible(Handle, value);
3189 // Explicitly move Toplevel windows to where we want them;
3190 // apparently moving unmapped toplevel windows doesn't work
3191 if (is_visible && (this is Form)) {
3192 XplatUI.SetWindowPos(window.Handle, bounds.X, bounds.Y, bounds.Width, bounds.Height);
3196 OnVisibleChanged(EventArgs.Empty);
3199 if (dc_mem != null) {
3204 if (bmp_mem != null) {
3209 this.CreateBuffers(bounds.Width, bounds.Height);
3213 if (value == false && parent != null) {
3216 // Need to start at parent, GetContainerControl might return ourselves if we're a container
3217 container = (Control)parent.GetContainerControl();
3218 if (container != null) {
3219 container.SelectNextControl(this, true, true, true, true);
3223 if (parent != null) {
3224 parent.PerformLayout(this, "visible");
3226 PerformLayout(this, "visible");
3231 [EditorBrowsable(EditorBrowsableState.Advanced)]
3232 protected void UpdateBounds() {
3240 if (!IsHandleCreated) {
3244 XplatUI.GetWindowPos(this.Handle, this is Form, out x, out y, out width, out height, out client_width, out client_height);
3246 UpdateBounds(x, y, width, height, client_width, client_height);
3249 [EditorBrowsable(EditorBrowsableState.Advanced)]
3250 protected void UpdateBounds(int x, int y, int width, int height) {
3251 // UpdateBounds only seems to set our sizes and fire events but not update the GUI window to match
3253 bool resized = false;
3255 int client_x_diff = this.bounds.Width-this.client_size.Width;
3256 int client_y_diff = this.bounds.Height-this.client_size.Height;
3258 // Needed to generate required notifications
3259 if ((this.bounds.X!=x) || (this.bounds.Y!=y)) {
3263 if ((this.Bounds.Width!=width) || (this.Bounds.Height!=height)) {
3270 bounds.Height=height;
3272 // Update client rectangle as well
3273 if (this.layout_suspended==0) {
3274 prev_size.Width=client_size.Width;
3275 prev_size.Height=client_size.Height;
3278 client_size.Width=width-client_x_diff;
3279 client_size.Height=height-client_y_diff;
3282 OnLocationChanged(EventArgs.Empty);
3286 OnSizeChanged(EventArgs.Empty);
3290 [EditorBrowsable(EditorBrowsableState.Advanced)]
3291 protected void UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) {
3292 UpdateBounds(x, y, width, height);
3294 this.client_size.Width=clientWidth;
3295 this.client_size.Height=clientHeight;
3298 [EditorBrowsable(EditorBrowsableState.Advanced)]
3299 protected void UpdateStyles() {
3300 if (!IsHandleCreated) {
3304 XplatUI.SetWindowStyle(window.Handle, CreateParams);
3307 [EditorBrowsable(EditorBrowsableState.Advanced)]
3308 protected void UpdateZOrder() {
3313 if (parent == null) {
3319 children = ctl.child_controls.Count;
3320 for (int i = 1; i < children; i++ ) {
3321 XplatUI.SetZOrder(ctl.child_controls[i].window.Handle, ctl.child_controls[i-1].window.Handle, false, false);
3324 if (!IsHandleCreated) {
3328 children = child_controls.Count;
3329 for (int i = 1; i < children; i++ ) {
3330 XplatUI.SetZOrder(child_controls[i].Handle, child_controls[i-1].Handle, false, false);
3335 protected virtual void WndProc(ref Message m) {
3337 Console.WriteLine("Control received message {0}", (Msg)m.Msg);
3339 if ((this.control_style & ControlStyles.EnableNotifyMessage) != 0) {
3343 switch((Msg)m.Msg) {
3344 case Msg.WM_WINDOWPOSCHANGED: {
3347 if (GetStyle(ControlStyles.ResizeRedraw)) {
3354 case Msg.WM_PAINT: {
3355 PaintEventArgs paint_event;
3357 paint_event = XplatUI.PaintEventStart(Handle, true);
3359 if (!needs_redraw) {
3360 // Just blit the previous image
3361 paint_event.Graphics.DrawImage (ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle, GraphicsUnit.Pixel);
3362 XplatUI.PaintEventEnd(Handle, true);
3367 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
3368 dc = paint_event.SetGraphics (DeviceContext);
3371 if ((control_style & (ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint)) != (ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint)) {
3372 OnPaintBackground(paint_event);
3375 OnPaint(paint_event);
3377 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
3378 dc.DrawImage (ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle, GraphicsUnit.Pixel);
3379 paint_event.SetGraphics (dc);
3380 needs_redraw = false;
3383 XplatUI.PaintEventEnd(Handle, true);
3385 if (!GetStyle(ControlStyles.UserPaint)) {
3392 case Msg.WM_ERASEBKGND: {
3393 if (GetStyle (ControlStyles.UserPaint)) {
3394 if (!GetStyle(ControlStyles.AllPaintingInWmPaint)) {
3395 PaintEventArgs eraseEventArgs = new PaintEventArgs (m.WParam == IntPtr.Zero ? Graphics.FromHwnd (m.HWnd) :
3396 Graphics.FromHdc (m.WParam), new Rectangle (new Point (0,0),Size));
3397 OnPaintBackground (eraseEventArgs);
3400 XplatUI.EraseWindowBackground(m.HWnd, m.WParam);
3402 // The DefWndProc will never have to handle this, we don't ever set hbr on the window
3403 m.Result = (IntPtr)1;
3407 case Msg.WM_LBUTTONUP: {
3408 HandleClick(mouse_clicks);
3409 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Left,
3411 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3413 if (mouse_clicks > 1) {
3419 case Msg.WM_LBUTTONDOWN: {
3420 if (CanSelect && !is_selected) {
3423 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3424 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3430 case Msg.WM_LBUTTONDBLCLK: {
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_MBUTTONUP: {
3440 HandleClick(mouse_clicks);
3441 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Middle,
3443 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3445 if (mouse_clicks > 1) {
3451 case Msg.WM_MBUTTONDOWN: {
3452 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3453 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3459 case Msg.WM_MBUTTONDBLCLK: {
3461 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3462 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3467 case Msg.WM_RBUTTONUP: {
3468 if (context_menu != null) {
3469 context_menu.Show(this, new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ())));
3472 HandleClick(mouse_clicks);
3473 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Right,
3475 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3477 if (mouse_clicks > 1) {
3483 case Msg.WM_RBUTTONDOWN: {
3484 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3485 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3490 case Msg.WM_RBUTTONDBLCLK: {
3492 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3493 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3498 case Msg.WM_MOUSEWHEEL: {
3500 OnMouseWheel (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3501 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3502 HighOrder(m.WParam.ToInt32())));
3507 case Msg.WM_MOUSEMOVE: {
3508 OnMouseMove (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3510 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3515 case Msg.WM_MOUSE_ENTER: {
3520 OnMouseEnter(EventArgs.Empty);
3524 case Msg.WM_MOUSE_LEAVE: {
3526 OnMouseLeave(EventArgs.Empty);
3530 case Msg.WM_MOUSEHOVER: {
3531 OnMouseHover(EventArgs.Empty);
3535 case Msg.WM_SYSKEYDOWN:
3536 case Msg.WM_KEYDOWN:
3537 case Msg.WM_SYSKEYUP:
3539 case Msg.WM_SYSCHAR:
3541 Console.WriteLine("Got {0}", (Msg)m.Msg);
3542 if (ProcessKeyEventArgs(ref m)) {
3546 if (PreProcessMessage(ref m)) {
3550 if (ProcessKeyMessage(ref m)) {
3559 if (m.LParam != IntPtr.Zero) {
3562 hi = new HELPINFO();
3564 hi = (HELPINFO) Marshal.PtrToStructure (m.LParam, typeof (HELPINFO));
3565 mouse_pos = new Point(hi.MousePos.x, hi.MousePos.y);
3567 mouse_pos = Control.MousePosition;
3569 OnHelpRequested(new HelpEventArgs(mouse_pos));
3570 m.Result = (IntPtr)1;
3574 case Msg.WM_KILLFOCUS: {
3575 OnLeave(EventArgs.Empty);
3576 if (CausesValidation) {
3578 e = new CancelEventArgs(false);
3587 OnValidated(EventArgs.Empty);
3590 this.has_focus = false;
3591 this.is_selected = false;
3592 OnLostFocus(EventArgs.Empty);
3596 case Msg.WM_SETFOCUS: {
3597 OnEnter(EventArgs.Empty);
3598 this.has_focus = true;
3599 OnGotFocus(EventArgs.Empty);
3604 case Msg.WM_SYSCOLORCHANGE: {
3605 ThemeEngine.Current.ResetDefaults();
3606 OnSystemColorsChanged(EventArgs.Empty);
3611 case Msg.WM_SETCURSOR: {
3612 if (cursor == null) {
3617 XplatUI.SetCursor(window.Handle, cursor.handle);
3618 m.Result = (IntPtr)1;
3629 #endregion // Public Instance Methods
3631 #region OnXXX methods
3632 [EditorBrowsable(EditorBrowsableState.Advanced)]
3633 protected virtual void OnBackColorChanged(EventArgs e) {
3634 if (BackColorChanged!=null) BackColorChanged(this, e);
3635 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackColorChanged(e);
3638 [EditorBrowsable(EditorBrowsableState.Advanced)]
3639 protected virtual void OnBackgroundImageChanged(EventArgs e) {
3640 if (BackgroundImageChanged!=null) BackgroundImageChanged(this, e);
3641 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackgroundImageChanged(e);
3644 [EditorBrowsable(EditorBrowsableState.Advanced)]
3645 protected virtual void OnBindingContextChanged(EventArgs e) {
3646 CheckDataBindings ();
3647 if (BindingContextChanged!=null) {
3648 BindingContextChanged(this, e);
3650 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBindingContextChanged(e);
3653 [EditorBrowsable(EditorBrowsableState.Advanced)]
3654 protected virtual void OnCausesValidationChanged(EventArgs e) {
3655 if (CausesValidationChanged!=null) CausesValidationChanged(this, e);
3658 [EditorBrowsable(EditorBrowsableState.Advanced)]
3659 protected virtual void OnChangeUICues(UICuesEventArgs e) {
3660 if (ChangeUICues!=null) ChangeUICues(this, e);
3663 [EditorBrowsable(EditorBrowsableState.Advanced)]
3664 protected virtual void OnClick(EventArgs e) {
3665 if (Click!=null) Click(this, e);
3668 [EditorBrowsable(EditorBrowsableState.Advanced)]
3669 protected virtual void OnContextMenuChanged(EventArgs e) {
3670 if (ContextMenuChanged!=null) ContextMenuChanged(this, e);
3673 [EditorBrowsable(EditorBrowsableState.Advanced)]
3674 protected virtual void OnControlAdded(ControlEventArgs e) {
3675 if (ControlAdded!=null) ControlAdded(this, e);
3678 [EditorBrowsable(EditorBrowsableState.Advanced)]
3679 protected virtual void OnControlRemoved(ControlEventArgs e) {
3680 if (ControlRemoved!=null) ControlRemoved(this, e);
3683 [EditorBrowsable(EditorBrowsableState.Advanced)]
3684 protected virtual void OnCreateControl() {
3688 [EditorBrowsable(EditorBrowsableState.Advanced)]
3689 protected virtual void OnCursorChanged(EventArgs e) {
3690 if (CursorChanged!=null) CursorChanged(this, e);
3693 [EditorBrowsable(EditorBrowsableState.Advanced)]
3694 protected virtual void OnDockChanged(EventArgs e) {
3695 if (DockChanged!=null) DockChanged(this, e);
3698 [EditorBrowsable(EditorBrowsableState.Advanced)]
3699 protected virtual void OnDoubleClick(EventArgs e) {
3700 if (DoubleClick!=null) DoubleClick(this, e);
3703 [EditorBrowsable(EditorBrowsableState.Advanced)]
3704 protected virtual void OnDragDrop(DragEventArgs drgevent) {
3705 if (DragDrop!=null) DragDrop(this, drgevent);
3708 [EditorBrowsable(EditorBrowsableState.Advanced)]
3709 protected virtual void OnDragEnter(DragEventArgs drgevent) {
3710 if (DragEnter!=null) DragEnter(this, drgevent);
3713 [EditorBrowsable(EditorBrowsableState.Advanced)]
3714 protected virtual void OnDragLeave(EventArgs e) {
3715 if (DragLeave!=null) DragLeave(this, e);
3718 [EditorBrowsable(EditorBrowsableState.Advanced)]
3719 protected virtual void OnDragOver(DragEventArgs drgevent) {
3720 if (DragOver!=null) DragOver(this, drgevent);
3723 [EditorBrowsable(EditorBrowsableState.Advanced)]
3724 protected virtual void OnEnabledChanged(EventArgs e) {
3725 if (EnabledChanged!=null) EnabledChanged(this, e);
3726 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentEnabledChanged(e);
3729 [EditorBrowsable(EditorBrowsableState.Advanced)]
3730 protected virtual void OnEnter(EventArgs e) {
3731 if (Enter!=null) Enter(this, e);
3734 [EditorBrowsable(EditorBrowsableState.Advanced)]
3735 protected virtual void OnFontChanged(EventArgs e) {
3736 if (FontChanged!=null) FontChanged(this, e);
3737 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentFontChanged(e);
3740 [EditorBrowsable(EditorBrowsableState.Advanced)]
3741 protected virtual void OnForeColorChanged(EventArgs e) {
3742 if (ForeColorChanged!=null) ForeColorChanged(this, e);
3743 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentForeColorChanged(e);
3746 [EditorBrowsable(EditorBrowsableState.Advanced)]
3747 protected virtual void OnGiveFeedback(GiveFeedbackEventArgs gfbevent) {
3748 if (GiveFeedback!=null) GiveFeedback(this, gfbevent);
3751 [EditorBrowsable(EditorBrowsableState.Advanced)]
3752 protected virtual void OnGotFocus(EventArgs e) {
3753 if (GotFocus!=null) GotFocus(this, e);
3756 [EditorBrowsable(EditorBrowsableState.Advanced)]
3757 protected virtual void OnHandleCreated(EventArgs e) {
3758 if (HandleCreated!=null) HandleCreated(this, e);
3761 [EditorBrowsable(EditorBrowsableState.Advanced)]
3762 protected virtual void OnHandleDestroyed(EventArgs e) {
3763 if (HandleDestroyed!=null) HandleDestroyed(this, e);
3766 [EditorBrowsable(EditorBrowsableState.Advanced)]
3767 protected virtual void OnHelpRequested(HelpEventArgs hevent) {
3768 if (HelpRequested!=null) HelpRequested(this, hevent);
3771 protected virtual void OnImeModeChanged(EventArgs e) {
3772 if (ImeModeChanged!=null) ImeModeChanged(this, e);
3775 [EditorBrowsable(EditorBrowsableState.Advanced)]
3776 protected virtual void OnInvalidated(InvalidateEventArgs e) {
3777 needs_redraw = true;
3778 if (Invalidated!=null) Invalidated(this, e);
3781 [EditorBrowsable(EditorBrowsableState.Advanced)]
3782 protected virtual void OnKeyDown(KeyEventArgs e) {
3783 if (KeyDown!=null) KeyDown(this, e);
3786 [EditorBrowsable(EditorBrowsableState.Advanced)]
3787 protected virtual void OnKeyPress(KeyPressEventArgs e) {
3788 if (KeyPress!=null) KeyPress(this, e);
3791 [EditorBrowsable(EditorBrowsableState.Advanced)]
3792 protected virtual void OnKeyUp(KeyEventArgs e) {
3793 if (KeyUp!=null) KeyUp(this, e);
3796 [EditorBrowsable(EditorBrowsableState.Advanced)]
3797 protected virtual void OnLayout(LayoutEventArgs levent) {
3798 if (Layout!=null) Layout(this, levent);
3801 [EditorBrowsable(EditorBrowsableState.Advanced)]
3802 protected virtual void OnLeave(EventArgs e) {
3803 if (Leave!=null) Leave(this, e);
3806 [EditorBrowsable(EditorBrowsableState.Advanced)]
3807 protected virtual void OnLocationChanged(EventArgs e) {
3809 if (LocationChanged!=null) LocationChanged(this, e);
3812 [EditorBrowsable(EditorBrowsableState.Advanced)]
3813 protected virtual void OnLostFocus(EventArgs e) {
3814 if (LostFocus!=null) LostFocus(this, e);
3817 [EditorBrowsable(EditorBrowsableState.Advanced)]
3818 protected virtual void OnMouseDown(MouseEventArgs e) {
3819 if (MouseDown!=null) MouseDown(this, e);
3822 [EditorBrowsable(EditorBrowsableState.Advanced)]
3823 protected virtual void OnMouseEnter(EventArgs e) {
3824 if (MouseEnter!=null) MouseEnter(this, e);
3827 [EditorBrowsable(EditorBrowsableState.Advanced)]
3828 protected virtual void OnMouseHover(EventArgs e) {
3829 if (MouseHover!=null) MouseHover(this, e);
3832 [EditorBrowsable(EditorBrowsableState.Advanced)]
3833 protected virtual void OnMouseLeave(EventArgs e) {
3834 if (MouseLeave!=null) MouseLeave(this, e);
3837 [EditorBrowsable(EditorBrowsableState.Advanced)]
3838 protected virtual void OnMouseMove(MouseEventArgs e) {
3839 if (MouseMove!=null) MouseMove(this, e);
3842 [EditorBrowsable(EditorBrowsableState.Advanced)]
3843 protected virtual void OnMouseUp(MouseEventArgs e) {
3844 if (MouseUp!=null) MouseUp(this, e);
3847 [EditorBrowsable(EditorBrowsableState.Advanced)]
3848 protected virtual void OnMouseWheel(MouseEventArgs e) {
3849 if (MouseWheel!=null) MouseWheel(this, e);
3852 [EditorBrowsable(EditorBrowsableState.Advanced)]
3853 protected virtual void OnMove(EventArgs e) {
3854 if (Move!=null) Move(this, e);
3857 [EditorBrowsable(EditorBrowsableState.Advanced)]
3858 protected virtual void OnNotifyMessage(Message m) {
3862 [EditorBrowsable(EditorBrowsableState.Advanced)]
3863 protected virtual void OnPaint(PaintEventArgs e) {
3864 if (Paint!=null) Paint(this, e);
3867 [EditorBrowsable(EditorBrowsableState.Advanced)]
3868 protected virtual void OnPaintBackground(PaintEventArgs pevent) {
3869 PaintControlBackground (pevent);
3872 [EditorBrowsable(EditorBrowsableState.Advanced)]
3873 protected virtual void OnParentBackColorChanged(EventArgs e) {
3874 if (background_color.IsEmpty && background_image==null) {
3876 OnBackColorChanged(e);
3880 [EditorBrowsable(EditorBrowsableState.Advanced)]
3881 protected virtual void OnParentBackgroundImageChanged(EventArgs e) {
3882 if (background_color.IsEmpty && background_image==null) {
3884 OnBackgroundImageChanged(e);
3888 [EditorBrowsable(EditorBrowsableState.Advanced)]
3889 protected virtual void OnParentBindingContextChanged(EventArgs e) {
3890 if (binding_context==null) {
3891 binding_context=Parent.binding_context;
3892 OnBindingContextChanged(e);
3896 [EditorBrowsable(EditorBrowsableState.Advanced)]
3897 protected virtual void OnParentChanged(EventArgs e) {
3898 if (ParentChanged!=null) ParentChanged(this, e);
3901 [EditorBrowsable(EditorBrowsableState.Advanced)]
3902 protected virtual void OnParentEnabledChanged(EventArgs e) {
3903 if (is_enabled != Parent.is_enabled) {
3904 is_enabled=Parent.is_enabled;
3906 if (EnabledChanged != null) {
3907 EnabledChanged(this, e);
3912 [EditorBrowsable(EditorBrowsableState.Advanced)]
3913 protected virtual void OnParentFontChanged(EventArgs e) {
3920 [EditorBrowsable(EditorBrowsableState.Advanced)]
3921 protected virtual void OnParentForeColorChanged(EventArgs e) {
3922 if (foreground_color.IsEmpty) {
3924 OnForeColorChanged(e);
3928 [EditorBrowsable(EditorBrowsableState.Advanced)]
3929 protected virtual void OnParentRightToLeftChanged(EventArgs e) {
3930 if (right_to_left==RightToLeft.Inherit) {
3932 OnRightToLeftChanged(e);
3936 [EditorBrowsable(EditorBrowsableState.Advanced)]
3937 protected virtual void OnParentVisibleChanged(EventArgs e) {
3939 OnVisibleChanged(e);
3943 [EditorBrowsable(EditorBrowsableState.Advanced)]
3944 protected virtual void OnQueryContinueDrag(QueryContinueDragEventArgs e) {
3945 if (QueryContinueDrag!=null) QueryContinueDrag(this, e);
3948 [EditorBrowsable(EditorBrowsableState.Advanced)]
3949 protected virtual void OnResize(EventArgs e) {
3950 if (Resize!=null) Resize(this, e);
3952 PerformLayout(this, "bounds");
3954 if (parent != null) {
3955 parent.PerformLayout();
3959 [EditorBrowsable(EditorBrowsableState.Advanced)]
3960 protected virtual void OnRightToLeftChanged(EventArgs e) {
3961 if (RightToLeftChanged!=null) RightToLeftChanged(this, e);
3962 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentRightToLeftChanged(e);
3965 [EditorBrowsable(EditorBrowsableState.Advanced)]
3966 protected virtual void OnSizeChanged(EventArgs e) {
3967 InvalidateBuffers ();
3969 if (SizeChanged!=null) SizeChanged(this, e);
3972 [EditorBrowsable(EditorBrowsableState.Advanced)]
3973 protected virtual void OnStyleChanged(EventArgs e) {
3974 if (StyleChanged!=null) StyleChanged(this, e);
3977 [EditorBrowsable(EditorBrowsableState.Advanced)]
3978 protected virtual void OnSystemColorsChanged(EventArgs e) {
3979 if (SystemColorsChanged!=null) SystemColorsChanged(this, e);
3982 [EditorBrowsable(EditorBrowsableState.Advanced)]
3983 protected virtual void OnTabIndexChanged(EventArgs e) {
3984 if (TabIndexChanged!=null) TabIndexChanged(this, e);
3987 [EditorBrowsable(EditorBrowsableState.Advanced)]
3988 protected virtual void OnTabStopChanged(EventArgs e) {
3989 if (TabStopChanged!=null) TabStopChanged(this, e);
3992 [EditorBrowsable(EditorBrowsableState.Advanced)]
3993 protected virtual void OnTextChanged(EventArgs e) {
3994 if (TextChanged!=null) TextChanged(this, e);
3997 [EditorBrowsable(EditorBrowsableState.Advanced)]
3998 protected virtual void OnValidated(EventArgs e) {
3999 if (Validated!=null) Validated(this, e);
4002 [EditorBrowsable(EditorBrowsableState.Advanced)]
4003 protected virtual void OnValidating(System.ComponentModel.CancelEventArgs e) {
4004 if (Validating!=null) Validating(this, e);
4007 [EditorBrowsable(EditorBrowsableState.Advanced)]
4008 protected virtual void OnVisibleChanged(EventArgs e) {
4015 if (bmp_mem!=null) {
4021 if (!this.IsHandleCreated) {
4022 this.CreateControl();
4028 if (VisibleChanged!=null) VisibleChanged(this, e);
4030 // We need to tell our kids
4031 for (int i=0; i<child_controls.Count; i++) {
4032 child_controls[i].OnParentVisibleChanged(e);
4035 #endregion // OnXXX methods
4038 public event EventHandler BackColorChanged;
4039 public event EventHandler BackgroundImageChanged;
4040 public event EventHandler BindingContextChanged;
4041 public event EventHandler CausesValidationChanged;
4042 public event UICuesEventHandler ChangeUICues;
4043 public event EventHandler Click;
4044 public event EventHandler ContextMenuChanged;
4046 [EditorBrowsable(EditorBrowsableState.Advanced)]
4048 public event ControlEventHandler ControlAdded;
4050 [EditorBrowsable(EditorBrowsableState.Advanced)]
4052 public event ControlEventHandler ControlRemoved;
4054 [MWFDescription("Fired when the cursor for the control has been changed"), MWFCategory("PropertyChanged")]
4055 public event EventHandler CursorChanged;
4056 public event EventHandler DockChanged;
4057 public event EventHandler DoubleClick;
4058 public event DragEventHandler DragDrop;
4059 public event DragEventHandler DragEnter;
4060 public event EventHandler DragLeave;
4061 public event DragEventHandler DragOver;
4062 public event EventHandler EnabledChanged;
4063 public event EventHandler Enter;
4064 public event EventHandler FontChanged;
4065 public event EventHandler ForeColorChanged;
4066 public event GiveFeedbackEventHandler GiveFeedback;
4068 [EditorBrowsable(EditorBrowsableState.Advanced)]
4070 public event EventHandler GotFocus;
4072 [EditorBrowsable(EditorBrowsableState.Advanced)]
4074 public event EventHandler HandleCreated;
4076 [EditorBrowsable(EditorBrowsableState.Advanced)]
4078 public event EventHandler HandleDestroyed;
4080 public event HelpEventHandler HelpRequested;
4081 public event EventHandler ImeModeChanged;
4083 [EditorBrowsable(EditorBrowsableState.Advanced)]
4085 public event InvalidateEventHandler Invalidated;
4087 public event KeyEventHandler KeyDown;
4088 public event KeyPressEventHandler KeyPress;
4089 public event KeyEventHandler KeyUp;
4090 public event LayoutEventHandler Layout;
4091 public event EventHandler Leave;
4092 public event EventHandler LocationChanged;
4094 [EditorBrowsable(EditorBrowsableState.Advanced)]
4096 public event EventHandler LostFocus;
4098 public event MouseEventHandler MouseDown;
4099 public event EventHandler MouseEnter;
4100 public event EventHandler MouseHover;
4101 public event EventHandler MouseLeave;
4102 public event MouseEventHandler MouseMove;
4103 public event MouseEventHandler MouseUp;
4105 [EditorBrowsable(EditorBrowsableState.Advanced)]
4107 public event MouseEventHandler MouseWheel;
4109 public event EventHandler Move;
4110 public event PaintEventHandler Paint;
4111 public event EventHandler ParentChanged;
4112 public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp;
4113 public event QueryContinueDragEventHandler QueryContinueDrag;
4114 public event EventHandler Resize;
4115 public event EventHandler RightToLeftChanged;
4116 public event EventHandler SizeChanged;
4117 public event EventHandler StyleChanged;
4118 public event EventHandler SystemColorsChanged;
4119 public event EventHandler TabIndexChanged;
4120 public event EventHandler TabStopChanged;
4121 public event EventHandler TextChanged;
4122 public event EventHandler Validated;
4123 public event CancelEventHandler Validating;
4124 public event EventHandler VisibleChanged;
4125 #endregion // Events