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 XplatUI.SetFocus(control.window.Handle);
765 internal virtual void DoDefaultAction() {
766 // Only here to be overriden by our actual controls; this is needed by the accessibility class
769 internal static int LowOrder (int param) {
770 return ((int)(short)(param & 0xffff));
773 internal static int HighOrder (int param) {
774 return ((int)(short)(param >> 16));
777 // This method exists so controls overriding OnPaintBackground can have default background painting done
778 internal void PaintControlBackground (PaintEventArgs pevent)
780 if (background_image == null)
783 DrawBackgroundImage (pevent.Graphics);
786 void DrawBackgroundImage (Graphics g)
788 using (TextureBrush b = new TextureBrush (background_image)) {
789 g.FillRectangle (b, ClientRectangle);
793 internal void DndEnter (DragEventArgs e)
798 internal void DndOver (DragEventArgs e)
803 internal void DndDrop (DragEventArgs e)
808 internal void DndLeave (EventArgs e)
813 internal void DnDFeedback(GiveFeedbackEventArgs e)
818 internal void DnDContinueDrag(QueryContinueDragEventArgs e) {
819 OnQueryContinueDrag(e);
822 internal static MouseButtons FromParamToMouseButtons (int param) {
823 MouseButtons buttons = MouseButtons.None;
825 if ((param & (int) MsgButtons.MK_LBUTTON) != 0)
826 buttons |= MouseButtons.Left;
828 if ((param & (int) MsgButtons.MK_MBUTTON) != 0)
829 buttons |= MouseButtons.Middle;
831 if ((param & (int) MsgButtons.MK_RBUTTON) != 0)
832 buttons |= MouseButtons.Right;
838 internal virtual bool ProcessControlMnemonic(char charCode) {
839 return ProcessMnemonic(charCode);
842 private static Control FindFlatForward(Control container, Control start) {
848 end = container.child_controls.Count;
851 index = start.tab_index;
856 for (int i = 0; i < end; i++) {
858 if (container.child_controls[i].tab_index > index) {
859 found = container.child_controls[i];
861 } else if (found.tab_index > container.child_controls[i].tab_index) {
862 if (container.child_controls[i].tab_index > index) {
863 found = container.child_controls[i];
870 private static Control FindControlForward(Control container, Control start) {
877 if ((start is IContainerControl) || start.GetStyle(ControlStyles.ContainerControl)) {
878 found = FindControlForward(start, null);
885 while (p != container) {
886 found = FindFlatForward(p, start);
894 return FindFlatForward(container, start);
897 private static Control FindFlatBackward(Control container, Control start) {
903 end = container.child_controls.Count;
906 index = start.tab_index;
908 // FIXME: Possible speed-up: Keep the highest taborder index in the container
910 for (int i = 0; i < end; i++) {
911 if (container.child_controls[i].tab_index > index) {
912 index = container.child_controls[i].tab_index;
918 for (int i = 0; i < end; i++) {
920 if (container.child_controls[i].tab_index < index) {
921 found = container.child_controls[i];
923 } else if (found.tab_index < container.child_controls[i].tab_index) {
924 if (container.child_controls[i].tab_index < index) {
925 found = container.child_controls[i];
932 private static Control FindControlBackward(Control container, Control start) {
938 found = FindFlatBackward(start.parent, start);
939 if (found == null && start.parent != container) {
944 found = FindFlatBackward(container, start);
947 while ((found != null) && ((found is IContainerControl) || found.GetStyle(ControlStyles.ContainerControl))) {
948 found = FindControlBackward(found, null);
957 private void HandleClick(int clicks) {
958 if (GetStyle(ControlStyles.StandardClick)) {
960 if (GetStyle(ControlStyles.StandardDoubleClick)) {
961 OnDoubleClick(EventArgs.Empty);
963 OnClick(EventArgs.Empty);
966 OnClick(EventArgs.Empty);
971 private void CheckDataBindings ()
973 if (data_bindings == null)
976 BindingContext binding_context = BindingContext;
977 foreach (Binding binding in data_bindings) {
978 binding.Check (binding_context);
982 #endregion // Private & Internal Methods
984 #region Public Static Properties
985 public static Color DefaultBackColor {
987 return ThemeEngine.Current.DefaultControlBackColor;
991 public static Font DefaultFont {
993 return ThemeEngine.Current.DefaultFont;
997 public static Color DefaultForeColor {
999 return ThemeEngine.Current.DefaultControlForeColor;
1003 public static Keys ModifierKeys {
1005 return XplatUI.State.ModifierKeys;
1009 public static MouseButtons MouseButtons {
1011 return XplatUI.State.MouseButtons;
1015 public static Point MousePosition {
1017 return Cursor.Position;
1023 public static bool CheckForIllegalCrossThreadCalls
1032 #endregion // Public Static Properties
1034 #region Public Instance Properties
1035 [EditorBrowsable(EditorBrowsableState.Advanced)]
1037 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1038 public AccessibleObject AccessibilityObject {
1040 if (accessibility_object==null) {
1041 accessibility_object=CreateAccessibilityInstance();
1043 return accessibility_object;
1047 [EditorBrowsable(EditorBrowsableState.Advanced)]
1049 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1050 public string AccessibleDefaultActionDescription {
1052 return AccessibilityObject.default_action;
1056 AccessibilityObject.default_action=value;
1061 [DefaultValue(null)]
1062 public string AccessibleDescription {
1064 return AccessibilityObject.description;
1068 AccessibilityObject.description=value;
1073 [DefaultValue(null)]
1074 public string AccessibleName {
1076 return AccessibilityObject.Name;
1080 AccessibilityObject.Name=value;
1084 [DefaultValue(AccessibleRole.Default)]
1085 [MWFDescription("Role of the control"), MWFCategory("Accessibility")]
1086 public AccessibleRole AccessibleRole {
1088 return AccessibilityObject.role;
1092 AccessibilityObject.role=value;
1096 [DefaultValue(false)]
1097 public virtual bool AllowDrop {
1103 if (allow_drop == value)
1107 XplatUI.SetAllowDrop (Handle, value);
1112 [RefreshProperties(RefreshProperties.Repaint)]
1113 [DefaultValue(AnchorStyles.Top | AnchorStyles.Left)]
1114 public virtual AnchorStyles Anchor {
1116 return anchor_style;
1122 if (parent != null) {
1123 parent.PerformLayout(this, "Parent");
1129 public virtual Color BackColor {
1131 if (background_color.IsEmpty) {
1133 return parent.BackColor;
1135 return DefaultBackColor;
1137 return background_color;
1141 background_color=value;
1142 if (this.IsHandleCreated) {
1143 XplatUI.SetWindowBackground(this.window.Handle, value);
1145 SetChildColor(this);
1146 OnBackColorChanged(EventArgs.Empty);
1152 [DefaultValue(null)]
1153 public virtual Image BackgroundImage {
1155 return background_image;
1159 if (background_image!=value) {
1160 background_image=value;
1161 OnBackgroundImageChanged(EventArgs.Empty);
1166 [EditorBrowsable(EditorBrowsableState.Advanced)]
1168 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1169 public virtual BindingContext BindingContext {
1171 if (binding_context != null)
1172 return binding_context;
1175 binding_context = Parent.BindingContext;
1176 return binding_context;
1179 if (binding_context != value) {
1180 binding_context = value;
1181 OnBindingContextChanged(EventArgs.Empty);
1186 [EditorBrowsable(EditorBrowsableState.Advanced)]
1188 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1191 return bounds.Y+bounds.Height;
1195 [EditorBrowsable(EditorBrowsableState.Advanced)]
1197 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1198 public Rectangle Bounds {
1204 SetBoundsCore(value.Left, value.Top, value.Width, value.Height, BoundsSpecified.All);
1208 [EditorBrowsable(EditorBrowsableState.Advanced)]
1210 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1211 public bool CanFocus {
1213 if (Visible && is_enabled && GetStyle(ControlStyles.Selectable)) {
1220 [EditorBrowsable(EditorBrowsableState.Advanced)]
1222 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1223 public bool CanSelect {
1227 if (!GetStyle(ControlStyles.Selectable) || this.parent == null) {
1231 parent = this.parent;
1232 while (parent != null) {
1233 if (!parent.is_visible || !parent.is_enabled) {
1237 parent = parent.parent;
1243 [EditorBrowsable(EditorBrowsableState.Advanced)]
1245 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1246 public bool Capture {
1248 return this.is_captured;
1252 if (this.IsHandleCreated) {
1253 if (value && !is_captured) {
1255 XplatUI.GrabWindow(this.window.Handle, IntPtr.Zero);
1256 } else if (!value && is_captured) {
1257 XplatUI.UngrabWindow(this.window.Handle);
1258 is_captured = false;
1264 [DefaultValue(true)]
1265 public bool CausesValidation {
1267 return this.causes_validation;
1271 if (this.causes_validation != value) {
1272 causes_validation = value;
1273 OnCausesValidationChanged(EventArgs.Empty);
1278 [EditorBrowsable(EditorBrowsableState.Advanced)]
1280 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1281 public Rectangle ClientRectangle {
1283 client_rect.Width = client_size.Width;
1284 client_rect.Height = client_size.Height;
1289 [EditorBrowsable(EditorBrowsableState.Advanced)]
1291 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1292 public Size ClientSize {
1295 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1296 return ((Form)this).form_parent_window.ClientSize;
1304 this.SetClientSizeCore(value.Width, value.Height);
1308 [EditorBrowsable(EditorBrowsableState.Advanced)]
1310 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1311 [DescriptionAttribute("ControlCompanyNameDescr")]
1312 public String CompanyName {
1314 return "Mono Project, Novell, Inc.";
1318 [EditorBrowsable(EditorBrowsableState.Advanced)]
1320 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1321 public bool ContainsFocus {
1327 for (int i=0; i < child_controls.Count; i++) {
1328 if (child_controls[i].ContainsFocus) {
1336 [DefaultValue(null)]
1337 public virtual ContextMenu ContextMenu {
1339 return context_menu;
1343 if (context_menu != value) {
1344 context_menu = value;
1345 OnContextMenuChanged(EventArgs.Empty);
1351 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
1352 public ControlCollection Controls {
1354 return this.child_controls;
1358 [EditorBrowsable(EditorBrowsableState.Advanced)]
1360 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1361 public bool Created {
1363 if (!this.is_disposed && (this.window.Handle != IntPtr.Zero)) {
1370 [AmbientValue(null)]
1371 public virtual Cursor Cursor {
1373 if (cursor != null) {
1377 if (parent != null) {
1378 return parent.Cursor;
1381 return Cursors.Default;
1385 if (cursor != value) {
1390 pt = Cursor.Position;
1391 if (bounds.Contains(pt)) {
1392 if (GetChildAtPoint(pt) == null) {
1393 if (cursor != null) {
1394 XplatUI.SetCursor(window.Handle, cursor.handle);
1396 if (parent != null) {
1397 XplatUI.SetCursor(window.Handle, parent.Cursor.handle);
1399 XplatUI.SetCursor(window.Handle, Cursors.def.handle);
1405 OnCursorChanged(EventArgs.Empty);
1411 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
1412 [ParenthesizePropertyName(true)]
1413 [RefreshProperties(RefreshProperties.All)]
1414 public ControlBindingsCollection DataBindings {
1416 if (data_bindings == null)
1417 data_bindings = new ControlBindingsCollection (this);
1418 return data_bindings;
1422 [EditorBrowsable(EditorBrowsableState.Advanced)]
1424 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1425 public virtual Rectangle DisplayRectangle {
1427 return ClientRectangle;
1431 [EditorBrowsable(EditorBrowsableState.Advanced)]
1433 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1434 public bool Disposing {
1441 [RefreshProperties(RefreshProperties.Repaint)]
1442 [DefaultValue(DockStyle.None)]
1443 public virtual DockStyle Dock {
1449 if (dock_style == value) {
1455 if (parent != null) {
1456 parent.PerformLayout(this, "Parent");
1459 OnDockChanged(EventArgs.Empty);
1465 public bool Enabled {
1471 if (is_enabled == value) {
1477 OnEnabledChanged (EventArgs.Empty);
1481 [EditorBrowsable(EditorBrowsableState.Advanced)]
1483 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1484 public virtual bool Focused {
1486 return this.has_focus;
1491 [AmbientValue(null)]
1493 public virtual Font Font {
1499 if (Parent != null && Parent.Font != null) {
1507 if (font != null && font.Equals (value)) {
1513 OnFontChanged (EventArgs.Empty);
1518 public virtual Color ForeColor {
1520 if (foreground_color.IsEmpty) {
1522 return parent.ForeColor;
1524 return DefaultForeColor;
1526 return foreground_color;
1530 if (foreground_color != value) {
1531 foreground_color=value;
1533 OnForeColorChanged(EventArgs.Empty);
1540 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1541 public IntPtr Handle { // IWin32Window
1543 if (!IsHandleCreated) {
1546 return window.Handle;
1550 [EditorBrowsable(EditorBrowsableState.Advanced)]
1552 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1553 public bool HasChildren {
1555 if (this.child_controls.Count>0) {
1562 [EditorBrowsable(EditorBrowsableState.Always)]
1564 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1567 return this.bounds.Height;
1571 SetBoundsCore(bounds.X, bounds.Y, bounds.Width, value, BoundsSpecified.Height);
1575 [AmbientValue(ImeMode.Inherit)]
1577 public ImeMode ImeMode {
1579 if (ime_mode == DefaultImeMode) {
1581 return parent.ImeMode;
1583 return ImeMode.NoControl; // default value
1589 if (ime_mode != value) {
1592 OnImeModeChanged(EventArgs.Empty);
1597 [EditorBrowsable(EditorBrowsableState.Advanced)]
1599 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1600 public bool InvokeRequired { // ISynchronizeInvoke
1602 if (creator_thread!=Thread.CurrentThread) {
1609 [EditorBrowsable(EditorBrowsableState.Advanced)]
1611 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1612 public bool IsAccessible {
1614 return is_accessible;
1618 is_accessible = value;
1622 [EditorBrowsable(EditorBrowsableState.Advanced)]
1624 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1625 public bool IsDisposed {
1627 return this.is_disposed;
1631 [EditorBrowsable(EditorBrowsableState.Advanced)]
1633 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1634 public bool IsHandleCreated {
1636 if ((window!=null) && (window.Handle!=IntPtr.Zero)) {
1644 [EditorBrowsable(EditorBrowsableState.Always)]
1646 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1649 return this.bounds.X;
1653 SetBoundsCore(value, bounds.Y, bounds.Width, bounds.Height, BoundsSpecified.X);
1658 public Point Location {
1660 return new Point(bounds.X, bounds.Y);
1664 SetBoundsCore(value.X, value.Y, bounds.Width, bounds.Height, BoundsSpecified.Location);
1669 public string Name {
1680 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1681 public Control Parent {
1687 if (value == this) {
1688 throw new ArgumentException("A circular control reference has been made. A control cannot be owned or parented to itself.");
1691 if (parent!=value) {
1693 parent.Controls.Remove(this);
1699 if (!parent.Controls.Contains(this)) {
1700 parent.Controls.Add(this);
1703 if (IsHandleCreated) {
1704 XplatUI.SetParent(Handle, value.Handle);
1707 OnParentChanged(EventArgs.Empty);
1713 [EditorBrowsable(EditorBrowsableState.Advanced)]
1715 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1716 public string ProductName {
1718 Type t = typeof (AssemblyProductAttribute);
1719 Assembly assembly = GetType().Module.Assembly;
1720 object [] attrs = assembly.GetCustomAttributes (t, false);
1721 AssemblyProductAttribute a = null;
1722 // On MS we get a NullRefException if product attribute is not
1724 if (attrs != null && attrs.Length > 0)
1725 a = (AssemblyProductAttribute) attrs [0];
1730 [EditorBrowsable(EditorBrowsableState.Advanced)]
1732 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1733 public string ProductVersion {
1735 Type t = typeof (AssemblyVersionAttribute);
1736 Assembly assembly = GetType().Module.Assembly;
1737 object [] attrs = assembly.GetCustomAttributes (t, false);
1738 if (attrs == null || attrs.Length < 1)
1740 return ((AssemblyVersionAttribute)attrs [0]).Version;
1744 [EditorBrowsable(EditorBrowsableState.Advanced)]
1746 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1747 public bool RecreatingHandle {
1749 return is_recreating;
1753 [EditorBrowsable(EditorBrowsableState.Advanced)]
1755 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1756 public Region Region {
1758 return new Region(this.bounds);
1765 g = this.CreateGraphics();
1766 r = value.GetBounds(g);
1768 SetBounds((int)r.X, (int)r.Y, (int)r.Width, (int)r.Height);
1774 [EditorBrowsable(EditorBrowsableState.Advanced)]
1776 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1779 return this.bounds.X+this.bounds.Width;
1783 [AmbientValue(RightToLeft.Inherit)]
1785 public virtual RightToLeft RightToLeft {
1787 if (right_to_left == RightToLeft.Inherit) {
1789 return parent.RightToLeft;
1791 return RightToLeft.No; // default value
1793 return right_to_left;
1797 if (value != right_to_left) {
1798 right_to_left = value;
1799 OnRightToLeftChanged(EventArgs.Empty);
1804 [EditorBrowsable(EditorBrowsableState.Advanced)]
1805 public override ISite Site {
1818 return new Size(Width, Height);
1822 SetBoundsCore(bounds.X, bounds.Y, value.Width, value.Height, BoundsSpecified.Size);
1827 [MergableProperty(false)]
1828 public int TabIndex {
1830 if (tab_index != -1) {
1837 if (tab_index != value) {
1839 OnTabIndexChanged(EventArgs.Empty);
1845 [DefaultValue(true)]
1846 public bool TabStop {
1852 if (tab_stop != value) {
1854 OnTabStopChanged(EventArgs.Empty);
1859 [Localizable(false)]
1861 [TypeConverter(typeof(StringConverter))]
1862 [DefaultValue(null)]
1869 control_tag = value;
1875 [BindableAttribute(true)]
1876 public virtual string Text {
1882 if (value == null) {
1883 value = String.Empty;
1888 XplatUI.Text(Handle, text);
1889 // FIXME: Do we need a Refresh() here?
1890 OnTextChanged (EventArgs.Empty);
1895 [EditorBrowsable(EditorBrowsableState.Always)]
1897 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1900 return this.bounds.Y;
1904 SetBoundsCore(bounds.X, value, bounds.Width, bounds.Height, BoundsSpecified.Y);
1908 [EditorBrowsable(EditorBrowsableState.Advanced)]
1910 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1911 public Control TopLevelControl {
1915 while (p.parent != null) {
1924 public bool Visible {
1928 } else if (parent != null) {
1929 return parent.Visible;
1936 SetVisibleCore(value);
1940 [EditorBrowsable(EditorBrowsableState.Always)]
1942 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1945 return this.bounds.Width;
1949 SetBoundsCore(bounds.X, bounds.Y, value, bounds.Height, BoundsSpecified.Width);
1953 [EditorBrowsable(EditorBrowsableState.Never)]
1955 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1956 public IWindowTarget WindowTarget {
1965 #endregion // Public Instance Properties
1967 #region Protected Instance Properties
1968 protected virtual CreateParams CreateParams {
1970 CreateParams create_params = new CreateParams();
1973 create_params.Caption = Text;
1976 create_params.Caption = text;
1980 create_params.X = Left;
1983 create_params.X = this.bounds.X;
1987 create_params.Y = Top;
1990 create_params.Y = this.bounds.Y;
1994 create_params.Width = Width;
1997 create_params.Width = this.bounds.Width;
2001 create_params.Height = Height;
2004 create_params.Height = this.bounds.Height;
2008 create_params.ClassName = XplatUI.DefaultClassName;
2009 create_params.ClassStyle = 0;
2010 create_params.ExStyle = 0;
2011 create_params.Param = 0;
2014 create_params.ExStyle |= (int)WindowStyles.WS_EX_ACCEPTFILES;
2018 create_params.Parent = parent.Handle;
2021 create_params.Style = (int)WindowStyles.WS_CHILD | (int)WindowStyles.WS_CLIPCHILDREN | (int)WindowStyles.WS_CLIPSIBLINGS;
2024 create_params.Style |= (int)WindowStyles.WS_VISIBLE;
2027 return create_params;
2031 protected virtual ImeMode DefaultImeMode {
2033 return ImeMode.Inherit;
2037 protected virtual Size DefaultSize {
2039 return new Size(100, 23);
2043 protected int FontHeight {
2053 protected bool RenderRightToLeft {
2055 return (this.right_to_left == RightToLeft.Yes);
2059 protected bool ResizeRedraw {
2061 return GetStyle(ControlStyles.ResizeRedraw);
2065 SetStyle(ControlStyles.ResizeRedraw, value);
2069 [EditorBrowsable(EditorBrowsableState.Advanced)]
2071 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2072 protected virtual bool ShowFocusCues {
2078 [EditorBrowsable(EditorBrowsableState.Advanced)]
2080 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2081 protected bool ShowKeyboardCues {
2086 #endregion // Protected Instance Properties
2088 #region Public Static Methods
2089 [EditorBrowsable(EditorBrowsableState.Advanced)]
2090 public static Control FromChildHandle(IntPtr handle) {
2091 IEnumerator control = Control.controls.GetEnumerator();
2093 while (control.MoveNext()) {
2094 if (((Control)control.Current).window.Handle == handle) {
2096 if (((Control)control.Current).Parent != null) {
2097 return ((Control)control.Current).Parent;
2104 [EditorBrowsable(EditorBrowsableState.Advanced)]
2105 public static Control FromHandle(IntPtr handle) {
2106 IEnumerator control = Control.controls.GetEnumerator();
2108 while (control.MoveNext()) {
2109 if (((Control)control.Current).window.Handle == handle) {
2111 return ((Control)control.Current);
2117 public static bool IsMnemonic(char charCode, string text) {
2120 amp = text.IndexOf('&');
2123 if (amp + 1 < text.Length) {
2124 if (text[amp + 1] != '&') {
2125 if (Char.ToUpper(charCode) == Char.ToUpper(text.ToCharArray(amp + 1, 1)[0])) {
2135 #region Protected Static Methods
2136 [EditorBrowsable(EditorBrowsableState.Advanced)]
2137 protected static bool ReflectMessage(IntPtr hWnd, ref Message m) {
2140 c = Control.FromHandle(hWnd);
2150 #region Public Instance Methods
2151 [EditorBrowsable(EditorBrowsableState.Advanced)]
2152 public IAsyncResult BeginInvoke(Delegate method) {
2153 return BeginInvokeInternal(method, null);
2156 [EditorBrowsable(EditorBrowsableState.Advanced)]
2157 public IAsyncResult BeginInvoke (Delegate method, object[] args) {
2158 return BeginInvokeInternal (method, args);
2161 public void BringToFront() {
2162 if ((parent != null) && (parent.child_controls[0]!=this)) {
2163 if (parent.child_controls.Contains(this)) {
2164 parent.child_controls.SetChildIndex(this, 0);
2168 XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, true, false);
2170 if (parent != null) {
2175 public bool Contains(Control ctl) {
2176 while (ctl != null) {
2185 public void CreateControl() {
2187 if (!IsHandleCreated) {
2191 if (!create_handled) {
2192 create_handled = true;
2196 for (int i=0; i<child_controls.Count; i++) {
2197 child_controls[i].CreateControl();
2201 public Graphics CreateGraphics() {
2202 if (!IsHandleCreated) {
2203 this.CreateControl();
2205 return Graphics.FromHwnd(this.window.Handle);
2208 public DragDropEffects DoDragDrop(object data, DragDropEffects allowedEffects) {
2209 return XplatUI.StartDrag(this.window.Handle, data, allowedEffects);
2212 [EditorBrowsable(EditorBrowsableState.Advanced)]
2213 public object EndInvoke (IAsyncResult async_result) {
2214 AsyncMethodResult result = (AsyncMethodResult) async_result;
2215 return result.EndInvoke ();
2218 public Form FindForm() {
2231 public bool Focus() {
2232 if (IsHandleCreated && !has_focus) {
2234 XplatUI.SetFocus(window.Handle);
2239 public Control GetChildAtPoint(Point pt) {
2240 // Microsoft's version of this function doesn't seem to work, so I can't check
2241 // if we only consider children or also grandchildren, etc.
2242 // I'm gonna say 'children only'
2243 for (int i=0; i<child_controls.Count; i++) {
2244 if (child_controls[i].Bounds.Contains(pt)) {
2245 return child_controls[i];
2251 public IContainerControl GetContainerControl() {
2252 Control current = this;
2254 while (current!=null) {
2255 if ((current is IContainerControl) && ((current.control_style & ControlStyles.ContainerControl)!=0)) {
2256 return (IContainerControl)current;
2258 current = current.parent;
2263 public Control GetNextControl(Control ctl, bool forward) {
2264 // If we're not a container we don't play
2265 if (!(this is IContainerControl) && !this.GetStyle(ControlStyles.ContainerControl)) {
2269 // If ctl is not contained by this, we start at the first child of this
2270 if (!this.Contains(ctl)) {
2274 // Search through our controls, starting at ctl, stepping into children as we encounter them
2275 // try to find the control with the tabindex closest to our own, or, if we're looking into
2276 // child controls, the one with the smallest tabindex
2278 return FindControlForward(this, ctl);
2280 return FindControlBackward(this, ctl);
2283 public void Hide() {
2284 this.Visible = false;
2287 public void Invalidate() {
2288 Invalidate(ClientRectangle, false);
2291 public void Invalidate(bool invalidateChildren) {
2292 Invalidate(ClientRectangle, invalidateChildren);
2295 public void Invalidate(System.Drawing.Rectangle rc) {
2296 Invalidate(rc, false);
2299 public void Invalidate(System.Drawing.Rectangle rc, bool invalidateChildren) {
2300 if (!IsHandleCreated || !Visible) {
2304 NotifyInvalidate(rc);
2306 XplatUI.Invalidate(Handle, rc, false);
2308 if (invalidateChildren) {
2309 for (int i=0; i<child_controls.Count; i++) child_controls[i].Invalidate();
2311 OnInvalidated(new InvalidateEventArgs(rc));
2314 public void Invalidate(System.Drawing.Region region) {
2315 Invalidate(region, false);
2318 [MonoTODO("Figure out if GetRegionScans is usable")]
2319 public void Invalidate(System.Drawing.Region region, bool invalidateChildren) {
2320 throw new NotImplementedException();
2322 // FIXME - should use the GetRegionScans function of the region to invalidate each area
2323 //if (invalidateChildren) {
2324 // for (int i=0; i<child_controls.Count; i++) child_controls[i].Invalidate();
2328 public object Invoke (Delegate method) {
2329 return Invoke(method, null);
2332 public object Invoke (Delegate method, object[] args) {
2333 if (!this.InvokeRequired) {
2334 return method.DynamicInvoke(args);
2337 IAsyncResult result = BeginInvoke (method, args);
2338 return EndInvoke(result);
2341 [EditorBrowsable(EditorBrowsableState.Advanced)]
2342 public void PerformLayout() {
2343 PerformLayout(null, null);
2346 [EditorBrowsable(EditorBrowsableState.Advanced)]
2347 public void PerformLayout(Control affectedControl, string affectedProperty) {
2348 LayoutEventArgs levent = new LayoutEventArgs(affectedControl, affectedProperty);
2350 if (layout_suspended>0) {
2351 layout_pending = true;
2355 layout_pending = false;
2357 // Prevent us from getting messed up
2360 // Perform all Dock and Anchor calculations
2363 AnchorStyles anchor;
2368 space=this.DisplayRectangle;
2369 if (prev_size != Size.Empty) {
2370 diff_width = space.Width - prev_size.Width;
2371 diff_height = space.Height - prev_size.Height;
2377 // Deal with docking; go through in reverse, MS docs say that lowest Z-order is closest to edge
2378 for (int i = child_controls.Count - 1; i >= 0; i--) {
2379 child=child_controls[i];
2380 switch (child.Dock) {
2381 case DockStyle.None: {
2386 case DockStyle.Left: {
2387 child.SetBounds(space.Left, space.Y, child.Width, space.Height);
2388 space.X+=child.Width;
2389 space.Width-=child.Width;
2393 case DockStyle.Top: {
2394 child.SetBounds(space.Left, space.Y, space.Width, child.Height);
2395 space.Y+=child.Height;
2396 space.Height-=child.Height;
2400 case DockStyle.Right: {
2401 child.SetBounds(space.Right-child.Width, space.Y, child.Width, space.Height);
2402 space.Width-=child.Width;
2406 case DockStyle.Bottom: {
2407 child.SetBounds(space.Left, space.Bottom-child.Height, space.Width, child.Height);
2408 space.Height-=child.Height;
2414 for (int i = child_controls.Count - 1; i >= 0; i--) {
2415 child=child_controls[i];
2417 if (child.Dock == DockStyle.Fill) {
2418 child.SetBounds(space.Left, space.Top, space.Width, space.Height);
2424 space=this.DisplayRectangle;
2426 // Deal with anchoring
2427 for (int i=0; i < child_controls.Count; i++) {
2433 child=child_controls[i];
2434 anchor=child.Anchor;
2439 height=child.Height;
2441 // If the control is docked we don't need to do anything
2442 if (child.Dock != DockStyle.None) {
2446 if ((anchor & AnchorStyles.Left) !=0 ) {
2447 if ((anchor & AnchorStyles.Right) != 0) {
2448 // Anchoring to left and right
2449 width=width+diff_width;
2453 } else if ((anchor & AnchorStyles.Right) != 0) {
2459 if ((anchor & AnchorStyles.Top) !=0 ) {
2460 if ((anchor & AnchorStyles.Bottom) != 0) {
2461 height+=diff_height;
2465 } else if ((anchor & AnchorStyles.Bottom) != 0) {
2480 child.SetBounds(left, top, width, height);
2483 // Let everyone know
2487 // Need to make sure we decremend layout_suspended
2493 public Point PointToClient (Point p) {
2497 XplatUI.ScreenToClient (Handle, ref x, ref y);
2499 return new Point (x, y);
2502 public Point PointToScreen(Point p) {
2506 XplatUI.ClientToScreen(Handle, ref x, ref y);
2508 return new Point(x, y);
2511 public virtual bool PreProcessMessage(ref Message msg) {
2514 if ((msg.Msg == (int)Msg.WM_KEYDOWN) || (msg.Msg == (int)Msg.WM_SYSKEYDOWN)) {
2515 key_data = (Keys)msg.WParam.ToInt32();
2516 if (!ProcessCmdKey(ref msg, key_data)) {
2517 if (IsInputKey(key_data)) {
2521 return ProcessDialogKey(key_data);
2525 } else if (msg.Msg == (int)Msg.WM_CHAR) {
2526 if (IsInputChar((char)msg.WParam)) {
2529 } else if (msg.Msg == (int)Msg.WM_SYSCHAR) {
2530 if (IsInputChar((char)msg.WParam)) {
2533 return ProcessDialogChar((char)msg.WParam);
2538 public Rectangle RectangleToClient(Rectangle r) {
2539 return new Rectangle(PointToClient(r.Location), r.Size);
2542 public Rectangle RectangleToScreen(Rectangle r) {
2543 return new Rectangle(PointToScreen(r.Location), r.Size);
2546 public virtual void Refresh() {
2547 if (IsHandleCreated == true) {
2551 XplatUI.UpdateWindow(window.Handle);
2553 end = child_controls.Count;
2554 for (int i=0; i < end; i++) {
2555 child_controls[i].Refresh();
2561 [EditorBrowsable(EditorBrowsableState.Never)]
2562 public virtual void ResetBackColor() {
2563 background_color = Color.Empty;
2566 [EditorBrowsable(EditorBrowsableState.Never)]
2568 public void ResetBindings() {
2572 [EditorBrowsable(EditorBrowsableState.Never)]
2573 public virtual void ResetCursor() {
2577 [EditorBrowsable(EditorBrowsableState.Never)]
2578 public virtual void ResetFont() {
2582 [EditorBrowsable(EditorBrowsableState.Never)]
2583 public virtual void ResetForeColor() {
2584 foreground_color = Color.Empty;
2587 [EditorBrowsable(EditorBrowsableState.Never)]
2588 public void ResetImeMode() {
2589 ime_mode = DefaultImeMode;
2592 [EditorBrowsable(EditorBrowsableState.Never)]
2593 public virtual void ResetRightToLeft() {
2594 right_to_left = RightToLeft.Inherit;
2597 public virtual void ResetText() {
2598 text = String.Empty;
2601 public void ResumeLayout() {
2602 ResumeLayout (true);
2605 public void ResumeLayout(bool performLayout) {
2608 if (layout_suspended > 0) {
2612 if (performLayout || layout_pending) {
2617 public void Scale(float ratio) {
2618 ScaleCore(ratio, ratio);
2621 public void Scale(float dx, float dy) {
2625 public void Select() {
2626 Select(false, false);
2629 public bool SelectNextControl(Control ctl, bool forward, bool tabStopOnly, bool nested, bool wrap) {
2634 c = GetNextControl(c, forward);
2643 if (c.CanSelect && ((c.parent == ctl.parent) || nested) && (c.tab_stop || !tabStopOnly)) {
2647 } while (c != ctl); // If we wrap back to ourselves we stop
2652 public void SendToBack() {
2653 if ((parent != null) && (parent.child_controls[parent.child_controls.Count-1]!=this)) {
2654 if (parent.child_controls.Contains(this)) {
2655 parent.child_controls.SetChildIndex(this, parent.child_controls.Count);
2659 XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, false, true);
2660 if (parent != null) {
2665 public void SetBounds(int x, int y, int width, int height) {
2666 SetBoundsCore(x, y, width, height, BoundsSpecified.All);
2669 public void SetBounds(int x, int y, int width, int height, BoundsSpecified specified) {
2670 SetBoundsCore(x, y, width, height, specified);
2673 public void Show() {
2674 if (!IsHandleCreated) {
2675 this.CreateControl();
2681 public void SuspendLayout() {
2685 public void Update() {
2686 needs_redraw = true;
2687 XplatUI.UpdateWindow(window.Handle);
2689 #endregion // Public Instance Methods
2691 #region Protected Instance Methods
2692 [EditorBrowsable(EditorBrowsableState.Advanced)]
2693 [MonoTODO("Implement this and tie it into Control.ControlAccessibleObject.NotifyClients")]
2694 protected void AccessibilityNotifyClients(AccessibleEvents accEvent, int childID) {
2695 throw new NotImplementedException();
2698 [EditorBrowsable(EditorBrowsableState.Advanced)]
2699 protected virtual AccessibleObject CreateAccessibilityInstance() {
2700 return new Control.ControlAccessibleObject(this);
2703 [EditorBrowsable(EditorBrowsableState.Advanced)]
2704 protected virtual ControlCollection CreateControlsInstance() {
2705 return new ControlCollection(this);
2708 [EditorBrowsable(EditorBrowsableState.Advanced)]
2709 protected virtual void CreateHandle() {
2711 throw new ObjectDisposedException(Name);
2714 if (IsHandleCreated) {
2718 window.CreateHandle(CreateParams);
2720 // Find out where the window manager placed us
2724 if (window.Handle!=IntPtr.Zero) {
2725 if (!controls.Contains(window.Handle)) {
2729 creator_thread = Thread.CurrentThread;
2731 XplatUI.SetWindowBackground(window.Handle, this.BackColor);
2733 OnHandleCreated(EventArgs.Empty);
2737 [EditorBrowsable(EditorBrowsableState.Advanced)]
2738 protected virtual void DefWndProc(ref Message m) {
2739 window.DefWndProc(ref m);
2742 [EditorBrowsable(EditorBrowsableState.Advanced)]
2743 protected virtual void DestroyHandle() {
2744 if (IsHandleCreated) {
2745 // Destroy our children before we destroy ourselves, to prevent them from
2746 // being implictly (without us knowing) destroyed
2747 for (int i=0; i < child_controls.Count; i++) {
2748 child_controls[i].DestroyHandle();
2752 if (window != null) {
2753 window.DestroyHandle();
2755 OnHandleDestroyed(EventArgs.Empty);
2759 protected bool GetStyle(ControlStyles flag) {
2760 return (control_style & flag) != 0;
2763 protected bool GetTopLevel() {
2767 [EditorBrowsable(EditorBrowsableState.Advanced)]
2768 protected virtual void InitLayout() {
2769 if (parent != null) {
2770 parent.PerformLayout(this, "parent");
2774 [EditorBrowsable(EditorBrowsableState.Advanced)]
2775 protected void InvokeGotFocus(Control toInvoke, EventArgs e) {
2776 toInvoke.OnGotFocus(e);
2779 [EditorBrowsable(EditorBrowsableState.Advanced)]
2780 protected void InvokeLostFocus(Control toInvoke, EventArgs e) {
2781 toInvoke.OnLostFocus(e);
2784 [EditorBrowsable(EditorBrowsableState.Advanced)]
2785 protected void InvokeOnClick(Control toInvoke, EventArgs e) {
2786 toInvoke.OnClick(e);
2789 protected void InvokePaint(Control toInvoke, PaintEventArgs e) {
2790 toInvoke.OnPaint(e);
2793 protected void InvokePaintBackground(Control toInvoke, PaintEventArgs e) {
2794 toInvoke.OnPaintBackground(e);
2797 protected virtual bool IsInputChar (char charCode) {
2798 if (parent != null) {
2799 return parent.IsInputChar(charCode);
2805 protected virtual bool IsInputKey (Keys keyData) {
2806 // Doc says this one calls IsInputChar; not sure what to do with that
2810 [EditorBrowsable(EditorBrowsableState.Advanced)]
2811 protected virtual void NotifyInvalidate(Rectangle invalidatedArea) {
2815 protected virtual bool ProcessCmdKey(ref Message msg, Keys keyData) {
2816 if ((context_menu != null) && context_menu.ProcessCmdKey(ref msg, keyData)) {
2820 if (parent != null) {
2821 return parent.ProcessCmdKey(ref msg, keyData);
2827 protected virtual bool ProcessDialogChar(char charCode) {
2828 if (parent != null) {
2829 return parent.ProcessDialogChar (charCode);
2835 protected virtual bool ProcessDialogKey (Keys keyData) {
2836 if (parent != null) {
2837 return parent.ProcessDialogKey (keyData);
2843 protected virtual bool ProcessKeyEventArgs (ref Message msg)
2845 KeyEventArgs key_event;
2848 case (int)Msg.WM_KEYDOWN: {
2849 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
2850 OnKeyDown (key_event);
2851 return key_event.Handled;
2853 case (int)Msg.WM_KEYUP: {
2854 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
2855 OnKeyUp (key_event);
2856 return key_event.Handled;
2859 case (int)Msg.WM_CHAR: {
2860 KeyPressEventArgs key_press_event;
2862 key_press_event = new KeyPressEventArgs((char)msg.WParam);
2863 OnKeyPress(key_press_event);
2864 return key_press_event.Handled;
2875 protected internal virtual bool ProcessKeyMessage(ref Message msg) {
2876 if (parent != null) {
2877 if (parent.ProcessKeyPreview(ref msg)) {
2885 protected virtual bool ProcessKeyPreview(ref Message msg) {
2886 if (parent != null) {
2887 return parent.ProcessKeyPreview(ref msg);
2893 protected virtual bool ProcessMnemonic(char charCode) {
2898 [EditorBrowsable(EditorBrowsableState.Advanced)]
2899 protected void RaiseDragEvent(object key, DragEventArgs e) {
2903 [EditorBrowsable(EditorBrowsableState.Advanced)]
2904 protected void RaiseKeyEvent(object key, KeyEventArgs e) {
2908 [EditorBrowsable(EditorBrowsableState.Advanced)]
2909 protected void RaiseMouseEvent(object key, MouseEventArgs e) {
2913 [EditorBrowsable(EditorBrowsableState.Advanced)]
2914 protected void RaisePaintEvent(object key, PaintEventArgs e) {
2918 [EditorBrowsable(EditorBrowsableState.Advanced)]
2919 protected void RecreateHandle() {
2920 IEnumerator child = child_controls.GetEnumerator();
2924 if (IsHandleCreated) {
2930 while (child.MoveNext()) {
2931 ((Control)child.Current).RecreateHandle();
2937 is_recreating = false;
2940 [EditorBrowsable(EditorBrowsableState.Advanced)]
2941 protected void ResetMouseEventArgs() {
2945 [EditorBrowsable(EditorBrowsableState.Advanced)]
2946 protected ContentAlignment RtlTranslateAlignment(ContentAlignment align) {
2947 if (right_to_left == RightToLeft.No) {
2952 case ContentAlignment.TopLeft: {
2953 return ContentAlignment.TopRight;
2956 case ContentAlignment.TopRight: {
2957 return ContentAlignment.TopLeft;
2960 case ContentAlignment.MiddleLeft: {
2961 return ContentAlignment.MiddleRight;
2964 case ContentAlignment.MiddleRight: {
2965 return ContentAlignment.MiddleLeft;
2968 case ContentAlignment.BottomLeft: {
2969 return ContentAlignment.BottomRight;
2972 case ContentAlignment.BottomRight: {
2973 return ContentAlignment.BottomLeft;
2977 // if it's center it doesn't change
2983 [EditorBrowsable(EditorBrowsableState.Advanced)]
2984 protected HorizontalAlignment RtlTranslateAlignment(HorizontalAlignment align) {
2985 if ((right_to_left == RightToLeft.No) || (align == HorizontalAlignment.Center)) {
2989 if (align == HorizontalAlignment.Left) {
2990 return HorizontalAlignment.Right;
2993 // align must be HorizontalAlignment.Right
2994 return HorizontalAlignment.Left;
2997 [EditorBrowsable(EditorBrowsableState.Advanced)]
2998 protected LeftRightAlignment RtlTranslateAlignment(LeftRightAlignment align) {
2999 if (right_to_left == RightToLeft.No) {
3003 if (align == LeftRightAlignment.Left) {
3004 return LeftRightAlignment.Right;
3007 // align must be LeftRightAlignment.Right;
3008 return LeftRightAlignment.Left;
3011 [EditorBrowsable(EditorBrowsableState.Advanced)]
3012 protected ContentAlignment RtlTranslateContent(ContentAlignment align) {
3013 return RtlTranslateAlignment(align);
3016 [EditorBrowsable(EditorBrowsableState.Advanced)]
3017 protected HorizontalAlignment RtlTranslateHorizontal(HorizontalAlignment align) {
3018 return RtlTranslateAlignment(align);
3021 [EditorBrowsable(EditorBrowsableState.Advanced)]
3022 protected LeftRightAlignment RtlTranslateLeftRight(LeftRightAlignment align) {
3023 return RtlTranslateAlignment(align);
3026 [EditorBrowsable(EditorBrowsableState.Advanced)]
3027 protected virtual void ScaleCore(float dx, float dy) {
3033 location = new Point((int)(Left * dx), (int)(Top * dy));
3034 size = this.ClientSize;
3037 if (!GetStyle(ControlStyles.FixedWidth)) {
3038 size.Width = (int)(size.Width * dx);
3041 if (!GetStyle(ControlStyles.FixedHeight)) {
3042 size.Height = (int)(size.Height * dy);
3045 Location = location;
3048 /* Now scale our children */
3049 for (int i=0; i < child_controls.Count; i++) {
3050 child_controls[i].Scale(dx, dy);
3056 protected virtual void Select(bool directed, bool forward) {
3061 // Select this control
3066 if (parent == null) {
3070 // FIXME - this thing is doing the wrong stuff, needs to be similar to SelectNextControl
3072 index = parent.child_controls.IndexOf(this);
3077 if ((index+1) < parent.child_controls.Count) {
3086 index = parent.child_controls.Count-1;
3089 result = Select(parent.child_controls[index]);
3090 } while (!result && parent.child_controls[index] != this);
3093 [EditorBrowsable(EditorBrowsableState.Advanced)]
3094 protected virtual void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
3095 // SetBoundsCore updates the Win32 control itself. UpdateBounds updates the controls variables and fires events, I'm guessing - pdb
3096 if ((specified & BoundsSpecified.X) != BoundsSpecified.X) {
3100 if ((specified & BoundsSpecified.Y) != BoundsSpecified.Y) {
3104 if ((specified & BoundsSpecified.Width) != BoundsSpecified.Width) {
3108 if ((specified & BoundsSpecified.Height) != BoundsSpecified.Height) {
3112 if (IsHandleCreated) {
3113 XplatUI.SetWindowPos(Handle, x, y, width, height);
3115 UpdateBounds(x, y, width, height);
3118 [EditorBrowsable(EditorBrowsableState.Advanced)]
3119 protected virtual void SetClientSizeCore(int x, int y) {
3120 // Calculate the actual window size from the client size (it usually stays the same or grows)
3121 Rectangle ClientRect;
3122 Rectangle WindowRect;
3125 ClientRect = new Rectangle(0, 0, x, y);
3126 cp = this.CreateParams;
3128 if (XplatUI.CalculateWindowRect(Handle, ref ClientRect, cp.Style, cp.ExStyle, IntPtr.Zero, out WindowRect)==false) {
3132 SetBoundsCore(bounds.X, bounds.Y, WindowRect.Width, WindowRect.Height, BoundsSpecified.Size);
3135 [EditorBrowsable(EditorBrowsableState.Advanced)]
3136 protected void SetStyle(ControlStyles flag, bool value) {
3138 control_style |= flag;
3140 control_style &= ~flag;
3142 OnStyleChanged(EventArgs.Empty);
3145 protected void SetTopLevel(bool value) {
3146 if ((GetTopLevel() != value) && (parent != null)) {
3147 throw new Exception();
3151 if (value == true) {
3161 is_toplevel = value;
3164 protected virtual void SetVisibleCore(bool value) {
3165 if (value!=is_visible) {
3167 XplatUI.SetVisible(Handle, value);
3168 // Explicitly move Toplevel windows to where we want them;
3169 // apparently moving unmapped toplevel windows doesn't work
3170 if (is_visible && (this is Form)) {
3171 XplatUI.SetWindowPos(window.Handle, bounds.X, bounds.Y, bounds.Width, bounds.Height);
3173 OnVisibleChanged(EventArgs.Empty);
3176 if (dc_mem != null) {
3181 if (bmp_mem != null) {
3186 this.CreateBuffers(bounds.Width, bounds.Height);
3191 if (value == false && parent != null) {
3194 // Need to start at parent, GetContainerControl might return ourselves if we're a container
3195 container = (Control)parent.GetContainerControl();
3196 if (container != null) {
3197 container.SelectNextControl(this, true, true, true, true);
3201 if (parent != null) {
3202 parent.PerformLayout(this, "visible");
3204 PerformLayout(this, "visible");
3209 [EditorBrowsable(EditorBrowsableState.Advanced)]
3210 protected void UpdateBounds() {
3218 if (!IsHandleCreated) {
3222 XplatUI.GetWindowPos(this.Handle, this is Form, out x, out y, out width, out height, out client_width, out client_height);
3224 UpdateBounds(x, y, width, height, client_width, client_height);
3227 [EditorBrowsable(EditorBrowsableState.Advanced)]
3228 protected void UpdateBounds(int x, int y, int width, int height) {
3229 // UpdateBounds only seems to set our sizes and fire events but not update the GUI window to match
3231 bool resized = false;
3233 int client_x_diff = this.bounds.Width-this.client_size.Width;
3234 int client_y_diff = this.bounds.Height-this.client_size.Height;
3236 // Needed to generate required notifications
3237 if ((this.bounds.X!=x) || (this.bounds.Y!=y)) {
3241 if ((this.Bounds.Width!=width) || (this.Bounds.Height!=height)) {
3248 bounds.Height=height;
3250 // Update client rectangle as well
3251 if (this.layout_suspended==0) {
3252 prev_size.Width=client_size.Width;
3253 prev_size.Height=client_size.Height;
3256 client_size.Width=width-client_x_diff;
3257 client_size.Height=height-client_y_diff;
3260 OnLocationChanged(EventArgs.Empty);
3264 OnSizeChanged(EventArgs.Empty);
3268 [EditorBrowsable(EditorBrowsableState.Advanced)]
3269 protected void UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) {
3270 UpdateBounds(x, y, width, height);
3272 this.client_size.Width=clientWidth;
3273 this.client_size.Height=clientHeight;
3276 [EditorBrowsable(EditorBrowsableState.Advanced)]
3277 protected void UpdateStyles() {
3278 if (!IsHandleCreated) {
3282 XplatUI.SetWindowStyle(window.Handle, CreateParams);
3285 [EditorBrowsable(EditorBrowsableState.Advanced)]
3286 protected void UpdateZOrder() {
3291 if (parent == null) {
3297 children = ctl.child_controls.Count;
3298 for (int i = 1; i < children; i++ ) {
3299 XplatUI.SetZOrder(ctl.child_controls[i].window.Handle, ctl.child_controls[i-1].window.Handle, false, false);
3302 children = child_controls.Count;
3303 for (int i = 1; i < children; i++ ) {
3304 XplatUI.SetZOrder(child_controls[i].Handle, child_controls[i-1].Handle, false, false);
3309 protected virtual void WndProc(ref Message m) {
3311 Console.WriteLine("Control received message {0}", (Msg)m.Msg);
3313 if ((this.control_style & ControlStyles.EnableNotifyMessage) != 0) {
3317 switch((Msg)m.Msg) {
3318 case Msg.WM_WINDOWPOSCHANGED: {
3321 if (GetStyle(ControlStyles.ResizeRedraw)) {
3328 case Msg.WM_PAINT: {
3329 PaintEventArgs paint_event;
3331 paint_event = XplatUI.PaintEventStart(Handle, true);
3333 if (!needs_redraw) {
3334 // Just blit the previous image
3335 paint_event.Graphics.DrawImage (ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle, GraphicsUnit.Pixel);
3336 XplatUI.PaintEventEnd(Handle, true);
3341 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
3342 dc = paint_event.SetGraphics (DeviceContext);
3345 if ((control_style & (ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint)) != (ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint)) {
3346 OnPaintBackground(paint_event);
3349 OnPaint(paint_event);
3351 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
3352 dc.DrawImage (ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle, GraphicsUnit.Pixel);
3353 paint_event.SetGraphics (dc);
3354 needs_redraw = false;
3357 XplatUI.PaintEventEnd(Handle, true);
3359 if (!GetStyle(ControlStyles.UserPaint)) {
3366 case Msg.WM_ERASEBKGND: {
3367 if (GetStyle (ControlStyles.UserPaint)) {
3368 if (!GetStyle(ControlStyles.AllPaintingInWmPaint)) {
3369 PaintEventArgs eraseEventArgs = new PaintEventArgs (m.WParam == IntPtr.Zero ? Graphics.FromHwnd (m.HWnd) :
3370 Graphics.FromHdc (m.WParam), new Rectangle (new Point (0,0),Size));
3371 OnPaintBackground (eraseEventArgs);
3374 XplatUI.EraseWindowBackground(m.HWnd, m.WParam);
3376 // The DefWndProc will never have to handle this, we don't ever set hbr on the window
3377 m.Result = (IntPtr)1;
3381 case Msg.WM_LBUTTONUP: {
3382 HandleClick(mouse_clicks);
3383 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Left,
3385 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3387 if (mouse_clicks > 1) {
3393 case Msg.WM_LBUTTONDOWN: {
3394 if (CanSelect && !is_selected) {
3397 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3398 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3404 case Msg.WM_LBUTTONDBLCLK: {
3406 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3407 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3413 case Msg.WM_MBUTTONUP: {
3414 HandleClick(mouse_clicks);
3415 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Middle,
3417 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3419 if (mouse_clicks > 1) {
3425 case Msg.WM_MBUTTONDOWN: {
3426 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3427 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3433 case Msg.WM_MBUTTONDBLCLK: {
3435 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3436 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3441 case Msg.WM_RBUTTONUP: {
3442 if (context_menu != null) {
3443 context_menu.Show(this, new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ())));
3446 HandleClick(mouse_clicks);
3447 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Right,
3449 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3451 if (mouse_clicks > 1) {
3457 case Msg.WM_RBUTTONDOWN: {
3458 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3459 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3464 case Msg.WM_RBUTTONDBLCLK: {
3466 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3467 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3472 case Msg.WM_MOUSEWHEEL: {
3474 OnMouseWheel (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3475 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3476 HighOrder(m.WParam.ToInt32())));
3481 case Msg.WM_MOUSEMOVE: {
3482 OnMouseMove (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3484 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3489 case Msg.WM_MOUSE_ENTER: {
3494 OnMouseEnter(EventArgs.Empty);
3498 case Msg.WM_MOUSE_LEAVE: {
3500 OnMouseLeave(EventArgs.Empty);
3504 case Msg.WM_MOUSEHOVER: {
3505 OnMouseHover(EventArgs.Empty);
3509 case Msg.WM_SYSKEYDOWN:
3510 case Msg.WM_KEYDOWN:
3511 case Msg.WM_SYSKEYUP:
3513 case Msg.WM_SYSCHAR:
3515 if (ProcessKeyEventArgs(ref m)) {
3519 if (PreProcessMessage(ref m)) {
3523 if (ProcessKeyMessage(ref m)) {
3532 if (m.LParam != IntPtr.Zero) {
3535 hi = new HELPINFO();
3537 hi = (HELPINFO) Marshal.PtrToStructure (m.LParam, typeof (HELPINFO));
3538 mouse_pos = new Point(hi.MousePos.x, hi.MousePos.y);
3540 mouse_pos = Control.MousePosition;
3542 OnHelpRequested(new HelpEventArgs(mouse_pos));
3543 m.Result = (IntPtr)1;
3547 case Msg.WM_KILLFOCUS: {
3548 OnLeave(EventArgs.Empty);
3549 if (CausesValidation) {
3551 e = new CancelEventArgs(false);
3560 OnValidated(EventArgs.Empty);
3563 this.has_focus = false;
3564 this.is_selected = false;
3565 OnLostFocus(EventArgs.Empty);
3569 case Msg.WM_SETFOCUS: {
3570 OnEnter(EventArgs.Empty);
3571 this.has_focus = true;
3572 OnGotFocus(EventArgs.Empty);
3577 case Msg.WM_SYSCOLORCHANGE: {
3578 ThemeEngine.Current.ResetDefaults();
3579 OnSystemColorsChanged(EventArgs.Empty);
3584 case Msg.WM_SETCURSOR: {
3585 if (cursor == null) {
3590 XplatUI.SetCursor(window.Handle, cursor.handle);
3591 m.Result = (IntPtr)1;
3602 #endregion // Public Instance Methods
3604 #region OnXXX methods
3605 [EditorBrowsable(EditorBrowsableState.Advanced)]
3606 protected virtual void OnBackColorChanged(EventArgs e) {
3607 if (BackColorChanged!=null) BackColorChanged(this, e);
3608 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackColorChanged(e);
3611 [EditorBrowsable(EditorBrowsableState.Advanced)]
3612 protected virtual void OnBackgroundImageChanged(EventArgs e) {
3613 if (BackgroundImageChanged!=null) BackgroundImageChanged(this, e);
3614 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackgroundImageChanged(e);
3617 [EditorBrowsable(EditorBrowsableState.Advanced)]
3618 protected virtual void OnBindingContextChanged(EventArgs e) {
3619 CheckDataBindings ();
3620 if (BindingContextChanged!=null) {
3621 BindingContextChanged(this, e);
3623 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBindingContextChanged(e);
3626 [EditorBrowsable(EditorBrowsableState.Advanced)]
3627 protected virtual void OnCausesValidationChanged(EventArgs e) {
3628 if (CausesValidationChanged!=null) CausesValidationChanged(this, e);
3631 [EditorBrowsable(EditorBrowsableState.Advanced)]
3632 protected virtual void OnChangeUICues(UICuesEventArgs e) {
3633 if (ChangeUICues!=null) ChangeUICues(this, e);
3636 [EditorBrowsable(EditorBrowsableState.Advanced)]
3637 protected virtual void OnClick(EventArgs e) {
3638 if (Click!=null) Click(this, e);
3641 [EditorBrowsable(EditorBrowsableState.Advanced)]
3642 protected virtual void OnContextMenuChanged(EventArgs e) {
3643 if (ContextMenuChanged!=null) ContextMenuChanged(this, e);
3646 [EditorBrowsable(EditorBrowsableState.Advanced)]
3647 protected virtual void OnControlAdded(ControlEventArgs e) {
3648 if (ControlAdded!=null) ControlAdded(this, e);
3651 [EditorBrowsable(EditorBrowsableState.Advanced)]
3652 protected virtual void OnControlRemoved(ControlEventArgs e) {
3653 if (ControlRemoved!=null) ControlRemoved(this, e);
3656 [EditorBrowsable(EditorBrowsableState.Advanced)]
3657 protected virtual void OnCreateControl() {
3661 [EditorBrowsable(EditorBrowsableState.Advanced)]
3662 protected virtual void OnCursorChanged(EventArgs e) {
3663 if (CursorChanged!=null) CursorChanged(this, e);
3666 [EditorBrowsable(EditorBrowsableState.Advanced)]
3667 protected virtual void OnDockChanged(EventArgs e) {
3668 if (DockChanged!=null) DockChanged(this, e);
3671 [EditorBrowsable(EditorBrowsableState.Advanced)]
3672 protected virtual void OnDoubleClick(EventArgs e) {
3673 if (DoubleClick!=null) DoubleClick(this, e);
3676 [EditorBrowsable(EditorBrowsableState.Advanced)]
3677 protected virtual void OnDragDrop(DragEventArgs drgevent) {
3678 if (DragDrop!=null) DragDrop(this, drgevent);
3681 [EditorBrowsable(EditorBrowsableState.Advanced)]
3682 protected virtual void OnDragEnter(DragEventArgs drgevent) {
3683 if (DragEnter!=null) DragEnter(this, drgevent);
3686 [EditorBrowsable(EditorBrowsableState.Advanced)]
3687 protected virtual void OnDragLeave(EventArgs e) {
3688 if (DragLeave!=null) DragLeave(this, e);
3691 [EditorBrowsable(EditorBrowsableState.Advanced)]
3692 protected virtual void OnDragOver(DragEventArgs drgevent) {
3693 if (DragOver!=null) DragOver(this, drgevent);
3696 [EditorBrowsable(EditorBrowsableState.Advanced)]
3697 protected virtual void OnEnabledChanged(EventArgs e) {
3698 if (EnabledChanged!=null) EnabledChanged(this, e);
3699 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentEnabledChanged(e);
3702 [EditorBrowsable(EditorBrowsableState.Advanced)]
3703 protected virtual void OnEnter(EventArgs e) {
3704 if (Enter!=null) Enter(this, e);
3707 [EditorBrowsable(EditorBrowsableState.Advanced)]
3708 protected virtual void OnFontChanged(EventArgs e) {
3709 if (FontChanged!=null) FontChanged(this, e);
3710 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentFontChanged(e);
3713 [EditorBrowsable(EditorBrowsableState.Advanced)]
3714 protected virtual void OnForeColorChanged(EventArgs e) {
3715 if (ForeColorChanged!=null) ForeColorChanged(this, e);
3716 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentForeColorChanged(e);
3719 [EditorBrowsable(EditorBrowsableState.Advanced)]
3720 protected virtual void OnGiveFeedback(GiveFeedbackEventArgs gfbevent) {
3721 if (GiveFeedback!=null) GiveFeedback(this, gfbevent);
3724 [EditorBrowsable(EditorBrowsableState.Advanced)]
3725 protected virtual void OnGotFocus(EventArgs e) {
3726 if (GotFocus!=null) GotFocus(this, e);
3729 [EditorBrowsable(EditorBrowsableState.Advanced)]
3730 protected virtual void OnHandleCreated(EventArgs e) {
3731 if (HandleCreated!=null) HandleCreated(this, e);
3734 [EditorBrowsable(EditorBrowsableState.Advanced)]
3735 protected virtual void OnHandleDestroyed(EventArgs e) {
3736 if (HandleDestroyed!=null) HandleDestroyed(this, e);
3739 [EditorBrowsable(EditorBrowsableState.Advanced)]
3740 protected virtual void OnHelpRequested(HelpEventArgs hevent) {
3741 if (HelpRequested!=null) HelpRequested(this, hevent);
3744 protected virtual void OnImeModeChanged(EventArgs e) {
3745 if (ImeModeChanged!=null) ImeModeChanged(this, e);
3748 [EditorBrowsable(EditorBrowsableState.Advanced)]
3749 protected virtual void OnInvalidated(InvalidateEventArgs e) {
3750 needs_redraw = true;
3751 if (Invalidated!=null) Invalidated(this, e);
3754 [EditorBrowsable(EditorBrowsableState.Advanced)]
3755 protected virtual void OnKeyDown(KeyEventArgs e) {
3756 if (KeyDown!=null) KeyDown(this, e);
3759 [EditorBrowsable(EditorBrowsableState.Advanced)]
3760 protected virtual void OnKeyPress(KeyPressEventArgs e) {
3761 if (KeyPress!=null) KeyPress(this, e);
3764 [EditorBrowsable(EditorBrowsableState.Advanced)]
3765 protected virtual void OnKeyUp(KeyEventArgs e) {
3766 if (KeyUp!=null) KeyUp(this, e);
3769 [EditorBrowsable(EditorBrowsableState.Advanced)]
3770 protected virtual void OnLayout(LayoutEventArgs levent) {
3771 if (Layout!=null) Layout(this, levent);
3774 [EditorBrowsable(EditorBrowsableState.Advanced)]
3775 protected virtual void OnLeave(EventArgs e) {
3776 if (Leave!=null) Leave(this, e);
3779 [EditorBrowsable(EditorBrowsableState.Advanced)]
3780 protected virtual void OnLocationChanged(EventArgs e) {
3782 if (LocationChanged!=null) LocationChanged(this, e);
3785 [EditorBrowsable(EditorBrowsableState.Advanced)]
3786 protected virtual void OnLostFocus(EventArgs e) {
3787 if (LostFocus!=null) LostFocus(this, e);
3790 [EditorBrowsable(EditorBrowsableState.Advanced)]
3791 protected virtual void OnMouseDown(MouseEventArgs e) {
3792 if (MouseDown!=null) MouseDown(this, e);
3795 [EditorBrowsable(EditorBrowsableState.Advanced)]
3796 protected virtual void OnMouseEnter(EventArgs e) {
3797 if (MouseEnter!=null) MouseEnter(this, e);
3800 [EditorBrowsable(EditorBrowsableState.Advanced)]
3801 protected virtual void OnMouseHover(EventArgs e) {
3802 if (MouseHover!=null) MouseHover(this, e);
3805 [EditorBrowsable(EditorBrowsableState.Advanced)]
3806 protected virtual void OnMouseLeave(EventArgs e) {
3807 if (MouseLeave!=null) MouseLeave(this, e);
3810 [EditorBrowsable(EditorBrowsableState.Advanced)]
3811 protected virtual void OnMouseMove(MouseEventArgs e) {
3812 if (MouseMove!=null) MouseMove(this, e);
3815 [EditorBrowsable(EditorBrowsableState.Advanced)]
3816 protected virtual void OnMouseUp(MouseEventArgs e) {
3817 if (MouseUp!=null) MouseUp(this, e);
3820 [EditorBrowsable(EditorBrowsableState.Advanced)]
3821 protected virtual void OnMouseWheel(MouseEventArgs e) {
3822 if (MouseWheel!=null) MouseWheel(this, e);
3825 [EditorBrowsable(EditorBrowsableState.Advanced)]
3826 protected virtual void OnMove(EventArgs e) {
3827 if (Move!=null) Move(this, e);
3830 [EditorBrowsable(EditorBrowsableState.Advanced)]
3831 protected virtual void OnNotifyMessage(Message m) {
3835 [EditorBrowsable(EditorBrowsableState.Advanced)]
3836 protected virtual void OnPaint(PaintEventArgs e) {
3837 if (Paint!=null) Paint(this, e);
3840 [EditorBrowsable(EditorBrowsableState.Advanced)]
3841 protected virtual void OnPaintBackground(PaintEventArgs pevent) {
3842 PaintControlBackground (pevent);
3845 [EditorBrowsable(EditorBrowsableState.Advanced)]
3846 protected virtual void OnParentBackColorChanged(EventArgs e) {
3847 if (background_color.IsEmpty && background_image==null) {
3849 OnBackColorChanged(e);
3853 [EditorBrowsable(EditorBrowsableState.Advanced)]
3854 protected virtual void OnParentBackgroundImageChanged(EventArgs e) {
3855 if (background_color.IsEmpty && background_image==null) {
3857 OnBackgroundImageChanged(e);
3861 [EditorBrowsable(EditorBrowsableState.Advanced)]
3862 protected virtual void OnParentBindingContextChanged(EventArgs e) {
3863 if (binding_context==null) {
3864 binding_context=Parent.binding_context;
3865 OnBindingContextChanged(e);
3869 [EditorBrowsable(EditorBrowsableState.Advanced)]
3870 protected virtual void OnParentChanged(EventArgs e) {
3871 if (ParentChanged!=null) ParentChanged(this, e);
3874 [EditorBrowsable(EditorBrowsableState.Advanced)]
3875 protected virtual void OnParentEnabledChanged(EventArgs e) {
3876 if (is_enabled != Parent.is_enabled) {
3877 is_enabled=Parent.is_enabled;
3879 if (EnabledChanged != null) {
3880 EnabledChanged(this, e);
3885 [EditorBrowsable(EditorBrowsableState.Advanced)]
3886 protected virtual void OnParentFontChanged(EventArgs e) {
3893 [EditorBrowsable(EditorBrowsableState.Advanced)]
3894 protected virtual void OnParentForeColorChanged(EventArgs e) {
3895 if (foreground_color.IsEmpty) {
3897 OnForeColorChanged(e);
3901 [EditorBrowsable(EditorBrowsableState.Advanced)]
3902 protected virtual void OnParentRightToLeftChanged(EventArgs e) {
3903 if (right_to_left==RightToLeft.Inherit) {
3905 OnRightToLeftChanged(e);
3909 [EditorBrowsable(EditorBrowsableState.Advanced)]
3910 protected virtual void OnParentVisibleChanged(EventArgs e) {
3912 OnVisibleChanged(e);
3916 [EditorBrowsable(EditorBrowsableState.Advanced)]
3917 protected virtual void OnQueryContinueDrag(QueryContinueDragEventArgs e) {
3918 if (QueryContinueDrag!=null) QueryContinueDrag(this, e);
3921 [EditorBrowsable(EditorBrowsableState.Advanced)]
3922 protected virtual void OnResize(EventArgs e) {
3923 if (Resize!=null) Resize(this, e);
3925 PerformLayout(this, "bounds");
3927 if (parent != null) {
3928 parent.PerformLayout();
3932 [EditorBrowsable(EditorBrowsableState.Advanced)]
3933 protected virtual void OnRightToLeftChanged(EventArgs e) {
3934 if (RightToLeftChanged!=null) RightToLeftChanged(this, e);
3935 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentRightToLeftChanged(e);
3938 [EditorBrowsable(EditorBrowsableState.Advanced)]
3939 protected virtual void OnSizeChanged(EventArgs e) {
3940 InvalidateBuffers ();
3942 if (SizeChanged!=null) SizeChanged(this, e);
3945 [EditorBrowsable(EditorBrowsableState.Advanced)]
3946 protected virtual void OnStyleChanged(EventArgs e) {
3947 if (StyleChanged!=null) StyleChanged(this, e);
3950 [EditorBrowsable(EditorBrowsableState.Advanced)]
3951 protected virtual void OnSystemColorsChanged(EventArgs e) {
3952 if (SystemColorsChanged!=null) SystemColorsChanged(this, e);
3955 [EditorBrowsable(EditorBrowsableState.Advanced)]
3956 protected virtual void OnTabIndexChanged(EventArgs e) {
3957 if (TabIndexChanged!=null) TabIndexChanged(this, e);
3960 [EditorBrowsable(EditorBrowsableState.Advanced)]
3961 protected virtual void OnTabStopChanged(EventArgs e) {
3962 if (TabStopChanged!=null) TabStopChanged(this, e);
3965 [EditorBrowsable(EditorBrowsableState.Advanced)]
3966 protected virtual void OnTextChanged(EventArgs e) {
3967 if (TextChanged!=null) TextChanged(this, e);
3970 [EditorBrowsable(EditorBrowsableState.Advanced)]
3971 protected virtual void OnValidated(EventArgs e) {
3972 if (Validated!=null) Validated(this, e);
3975 [EditorBrowsable(EditorBrowsableState.Advanced)]
3976 protected virtual void OnValidating(System.ComponentModel.CancelEventArgs e) {
3977 if (Validating!=null) Validating(this, e);
3980 [EditorBrowsable(EditorBrowsableState.Advanced)]
3981 protected virtual void OnVisibleChanged(EventArgs e) {
3988 if (bmp_mem!=null) {
3994 if (!this.IsHandleCreated) {
3995 this.CreateControl();
4001 if (VisibleChanged!=null) VisibleChanged(this, e);
4003 // We need to tell our kids
4004 for (int i=0; i<child_controls.Count; i++) {
4005 child_controls[i].OnParentVisibleChanged(e);
4008 #endregion // OnXXX methods
4011 public event EventHandler BackColorChanged;
4012 public event EventHandler BackgroundImageChanged;
4013 public event EventHandler BindingContextChanged;
4014 public event EventHandler CausesValidationChanged;
4015 public event UICuesEventHandler ChangeUICues;
4016 public event EventHandler Click;
4017 public event EventHandler ContextMenuChanged;
4019 [EditorBrowsable(EditorBrowsableState.Advanced)]
4021 public event ControlEventHandler ControlAdded;
4023 [EditorBrowsable(EditorBrowsableState.Advanced)]
4025 public event ControlEventHandler ControlRemoved;
4027 [MWFDescription("Fired when the cursor for the control has been changed"), MWFCategory("PropertyChanged")]
4028 public event EventHandler CursorChanged;
4029 public event EventHandler DockChanged;
4030 public event EventHandler DoubleClick;
4031 public event DragEventHandler DragDrop;
4032 public event DragEventHandler DragEnter;
4033 public event EventHandler DragLeave;
4034 public event DragEventHandler DragOver;
4035 public event EventHandler EnabledChanged;
4036 public event EventHandler Enter;
4037 public event EventHandler FontChanged;
4038 public event EventHandler ForeColorChanged;
4039 public event GiveFeedbackEventHandler GiveFeedback;
4041 [EditorBrowsable(EditorBrowsableState.Advanced)]
4043 public event EventHandler GotFocus;
4045 [EditorBrowsable(EditorBrowsableState.Advanced)]
4047 public event EventHandler HandleCreated;
4049 [EditorBrowsable(EditorBrowsableState.Advanced)]
4051 public event EventHandler HandleDestroyed;
4053 public event HelpEventHandler HelpRequested;
4054 public event EventHandler ImeModeChanged;
4056 [EditorBrowsable(EditorBrowsableState.Advanced)]
4058 public event InvalidateEventHandler Invalidated;
4060 public event KeyEventHandler KeyDown;
4061 public event KeyPressEventHandler KeyPress;
4062 public event KeyEventHandler KeyUp;
4063 public event LayoutEventHandler Layout;
4064 public event EventHandler Leave;
4065 public event EventHandler LocationChanged;
4067 [EditorBrowsable(EditorBrowsableState.Advanced)]
4069 public event EventHandler LostFocus;
4071 public event MouseEventHandler MouseDown;
4072 public event EventHandler MouseEnter;
4073 public event EventHandler MouseHover;
4074 public event EventHandler MouseLeave;
4075 public event MouseEventHandler MouseMove;
4076 public event MouseEventHandler MouseUp;
4078 [EditorBrowsable(EditorBrowsableState.Advanced)]
4080 public event MouseEventHandler MouseWheel;
4082 public event EventHandler Move;
4083 public event PaintEventHandler Paint;
4084 public event EventHandler ParentChanged;
4085 public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp;
4086 public event QueryContinueDragEventHandler QueryContinueDrag;
4087 public event EventHandler Resize;
4088 public event EventHandler RightToLeftChanged;
4089 public event EventHandler SizeChanged;
4090 public event EventHandler StyleChanged;
4091 public event EventHandler SystemColorsChanged;
4092 public event EventHandler TabIndexChanged;
4093 public event EventHandler TabStopChanged;
4094 public event EventHandler TextChanged;
4095 public event EventHandler Validated;
4096 public event CancelEventHandler Validating;
4097 public event EventHandler VisibleChanged;
4098 #endregion // Events