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-2006 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.Drawing.Drawing2D;
43 using System.Reflection;
44 using System.Runtime.InteropServices;
45 using System.Security;
46 using System.Threading;
49 namespace System.Windows.Forms
51 [Designer("System.Windows.Forms.Design.ControlDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
52 [DefaultProperty("Text")]
53 [DefaultEvent("Click")]
54 [DesignerSerializer("System.Windows.Forms.Design.ControlCodeDomSerializer, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
55 [ToolboxItemFilter("System.Windows.Forms")]
56 public class Control : Component, ISynchronizeInvoke, IWin32Window
58 #region Local Variables
61 internal Rectangle bounds; // bounding rectangle for control (client area + decorations)
62 internal object creator_thread; // thread that created the control
63 internal ControlNativeWindow window; // object for native window handle
64 internal string name; // for object naming
67 internal bool is_created; // true if OnCreateControl has been sent
68 internal bool has_focus; // true if control has focus
69 internal bool is_visible; // true if control is visible
70 internal bool is_entered; // is the mouse inside the control?
71 internal bool is_enabled; // true if control is enabled (usable/not grayed out)
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 internal bool allow_drop; // true if the control accepts droping objects on it
89 internal Region clip_region; // User-specified clip region for the window
92 internal Color foreground_color; // foreground color for control
93 internal Color background_color; // background color for control
94 internal Image background_image; // background image for control
95 internal Font font; // font for control
96 internal string text; // window/title text for control
97 internal BorderStyle border_style; // Border style of control
100 internal AnchorStyles anchor_style; // anchoring requirements for our control
101 internal DockStyle dock_style; // docking requirements for our control (supercedes anchoring)
102 internal int dist_left; // distance to the left border of the parent
103 internal int dist_top; // distance to the top border of the parent
104 internal int dist_right; // distance to the right border of the parent
105 internal int dist_bottom; // distance to the bottom border of the parent
107 // to be categorized...
108 static internal ArrayList controls = new ArrayList(); // All of the application's controls, in a flat list
109 internal ControlCollection child_controls; // our children
110 internal Control parent; // our parent control
111 internal AccessibleObject accessibility_object; // object that contains accessibility information about our control
112 internal BindingContext binding_context; // TODO
113 internal RightToLeft right_to_left; // drawing direction for control
114 internal int layout_suspended;
115 internal ContextMenu context_menu; // Context menu associated with the control
117 private Graphics dc_mem; // Graphics context for double buffering
118 private GraphicsState dc_state; // Pristine graphics context to reset after paint code alters dc_mem
119 private Bitmap bmp_mem; // Bitmap for double buffering control
120 private bool needs_redraw = true;
122 private ControlBindingsCollection data_bindings;
125 internal bool use_compatible_text_rendering;
126 static internal bool verify_thread_handle;
127 private Padding padding;
128 private Size maximum_size;
129 private Size minimum_size;
132 #endregion // Local Variables
134 #region Private Classes
135 // This helper class allows us to dispatch messages to Control.WndProc
136 internal class ControlNativeWindow : NativeWindow {
137 private Control owner;
139 public ControlNativeWindow(Control control) : base() {
144 public Control Owner {
150 static internal Control ControlFromHandle(IntPtr hWnd) {
151 ControlNativeWindow window;
153 window = (ControlNativeWindow)window_collection[hWnd];
154 if (window != null) {
161 protected override void WndProc(ref Message m) {
162 owner.WndProc(ref m);
167 #region Public Classes
169 public class ControlAccessibleObject : AccessibleObject {
170 #region ControlAccessibleObject Constructors
171 public ControlAccessibleObject(Control ownerControl) {
172 this.owner = ownerControl;
174 #endregion // ControlAccessibleObject Constructors
176 #region ControlAccessibleObject Public Instance Properties
177 public override string DefaultAction {
179 return base.DefaultAction;
183 public override string Description {
185 return base.Description;
189 public IntPtr Handle {
195 // We don't want to let them set it
199 public override string Help {
205 public override string KeyboardShortcut {
207 return base.KeyboardShortcut;
211 public override string Name {
221 public Control Owner {
227 public override AccessibleObject Parent {
234 public override AccessibleRole Role {
239 #endregion // ControlAccessibleObject Public Instance Properties
241 #region ControlAccessibleObject Public Instance Methods
242 public override int GetHelpTopic(out string FileName) {
243 return base.GetHelpTopic (out FileName);
246 [MonoTODO("Implement this and tie it into Control.AccessibilityNotifyClients")]
247 public void NotifyClients(AccessibleEvents accEvent) {
248 throw new NotImplementedException();
251 [MonoTODO("Implement this and tie it into Control.AccessibilityNotifyClients")]
252 public void NotifyClients(AccessibleEvents accEvent, int childID) {
253 throw new NotImplementedException();
256 public override string ToString() {
257 return "ControlAccessibleObject: Owner = " + owner.ToString() + ", Text: " + owner.text;
260 #endregion // ControlAccessibleObject Public Instance Methods
263 [DesignerSerializer("System.Windows.Forms.Design.ControlCollectionCodeDomSerializer, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
264 [ListBindable(false)]
265 public class ControlCollection : IList, ICollection, ICloneable, IEnumerable {
266 #region ControlCollection Local Variables
267 private ArrayList list;
268 internal ArrayList impl_list;
269 private Control [] all_controls;
270 internal Control owner;
271 #endregion // ControlCollection Local Variables
273 #region ControlCollection Public Constructor
274 public ControlCollection(Control owner) {
276 this.list=new ArrayList();
280 #region ControlCollection Public Instance Properties
287 public bool IsReadOnly {
289 return list.IsReadOnly;
293 public virtual Control this[int index] {
295 if (index < 0 || index >= list.Count) {
296 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
298 return (Control)list[index];
301 #endregion // ControlCollection Public Instance Properties
303 #region ControlCollection Private Instance Methods
304 public virtual void Add (Control value)
309 if (Contains (value)) {
310 owner.PerformLayout();
314 if (value.tab_index == -1) {
320 end = owner.child_controls.Count;
321 for (int i = 0; i < end; i++) {
322 index = owner.child_controls[i].tab_index;
327 value.tab_index = use;
330 if (value.parent != null) {
331 value.parent.Controls.Remove(value);
337 value.ChangeParent(owner);
341 owner.UpdateChildrenZOrder();
342 owner.PerformLayout(value, "Parent");
343 owner.OnControlAdded(new ControlEventArgs(value));
346 internal void AddToList (Control c)
352 internal virtual void AddImplicit (Control control)
354 if (impl_list == null)
355 impl_list = new ArrayList ();
357 impl_list.Add (control);
359 control.ChangeParent (owner);
360 control.InitLayout ();
361 owner.UpdateChildrenZOrder ();
362 owner.PerformLayout (control, "Parent");
363 owner.OnControlAdded (new ControlEventArgs (control));
366 public virtual void AddRange (Control[] controls)
368 if (controls == null)
369 throw new ArgumentNullException ("controls");
371 owner.SuspendLayout ();
374 for (int i = 0; i < controls.Length; i++)
377 owner.ResumeLayout ();
381 internal virtual void AddRangeImplicit (Control [] controls)
383 if (controls == null)
384 throw new ArgumentNullException ("controls");
386 owner.SuspendLayout ();
389 for (int i = 0; i < controls.Length; i++)
390 AddImplicit (controls [i]);
392 owner.ResumeLayout ();
396 public virtual void Clear ()
400 // MS sends remove events in reverse order
401 while (list.Count > 0) {
402 RemoveAt(list.Count - 1);
406 internal virtual void ClearImplicit ()
408 if (impl_list == null)
414 public bool Contains (Control value)
416 for (int i = list.Count; i > 0; ) {
419 if (list [i] == value) {
420 // Do we need to do anything here?
427 internal bool ImplicitContains (Control value)
429 if (impl_list == null)
432 for (int i = impl_list.Count; i > 0; ) {
435 if (impl_list [i] == value) {
436 // Do we need to do anything here?
443 internal bool AllContains (Control value)
445 return Contains (value) || ImplicitContains (value);
448 public void CopyTo (Array array, int index)
450 list.CopyTo(array, index);
453 public override bool Equals(object other) {
454 if (other is ControlCollection && (((ControlCollection)other).owner==this.owner)) {
461 public int GetChildIndex(Control child) {
462 return GetChildIndex(child, false);
465 public int GetChildIndex(Control child, bool throwException) {
468 index=list.IndexOf(child);
470 if (index==-1 && throwException) {
471 throw new ArgumentException("Not a child control", "child");
476 public IEnumerator GetEnumerator() {
477 return list.GetEnumerator();
480 internal IEnumerator GetAllEnumerator ()
482 Control [] res = GetAllControls ();
483 return res.GetEnumerator ();
486 internal Control [] GetAllControls ()
488 if (all_controls != null)
491 if (impl_list == null) {
492 all_controls = (Control []) list.ToArray (typeof (Control));
496 all_controls = new Control [list.Count + impl_list.Count];
497 impl_list.CopyTo (all_controls);
498 list.CopyTo (all_controls, impl_list.Count);
503 public override int GetHashCode() {
504 return base.GetHashCode();
507 public int IndexOf(Control control) {
508 return list.IndexOf(control);
511 public virtual void Remove(Control value) {
514 owner.PerformLayout(value, "Parent");
515 owner.OnControlRemoved(new ControlEventArgs(value));
518 value.ChangeParent(null);
520 owner.UpdateChildrenZOrder();
523 internal virtual void RemoveImplicit (Control control)
525 if (impl_list != null) {
527 owner.PerformLayout (control, "Parent");
528 owner.OnControlRemoved (new ControlEventArgs (control));
529 impl_list.Remove (control);
531 control.ChangeParent (null);
532 owner.UpdateChildrenZOrder ();
535 public void RemoveAt(int index) {
536 if (index < 0 || index >= list.Count) {
537 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
539 Remove ((Control)list[index]);
542 public void SetChildIndex(Control child, int newIndex) {
545 old_index=list.IndexOf(child);
547 throw new ArgumentException("Not a child control", "child");
550 if (old_index==newIndex) {
554 list.RemoveAt(old_index);
556 if (newIndex>list.Count) {
559 list.Insert(newIndex, child);
561 child.UpdateZOrder();
562 owner.PerformLayout();
564 #endregion // ControlCollection Private Instance Methods
566 #region ControlCollection Interface Properties
567 object IList.this[int index] {
569 if (index<0 || index>=list.Count) {
570 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
576 if (!(value is Control)) {
577 throw new ArgumentException("Object of type Control required", "value");
580 list[index]=(Control)value;
584 bool IList.IsFixedSize {
590 bool ICollection.IsSynchronized {
592 return list.IsSynchronized;
596 object ICollection.SyncRoot {
598 return list.SyncRoot;
601 #endregion // ControlCollection Interface Properties
603 #region ControlCollection Interface Methods
604 int IList.Add(object value) {
606 throw new ArgumentNullException("value", "Cannot add null controls");
609 if (!(value is Control)) {
610 throw new ArgumentException("Object of type Control required", "value");
613 return list.Add(value);
616 bool IList.Contains(object value) {
617 if (!(value is Control)) {
618 throw new ArgumentException("Object of type Control required", "value");
621 return this.Contains((Control) value);
624 int IList.IndexOf(object value) {
625 if (!(value is Control)) {
626 throw new ArgumentException("Object of type Control required", "value");
629 return this.IndexOf((Control) value);
632 void IList.Insert(int index, object value) {
633 if (!(value is Control)) {
634 throw new ArgumentException("Object of type Control required", "value");
637 list.Insert(index, value);
640 void IList.Remove(object value) {
641 if (!(value is Control)) {
642 throw new ArgumentException("Object of type Control required", "value");
648 Object ICloneable.Clone() {
649 ControlCollection clone = new ControlCollection(this.owner);
650 clone.list=(ArrayList)list.Clone(); // FIXME: Do we need this?
653 #endregion // ControlCollection Interface Methods
655 #endregion // ControlCollection Class
657 #region Public Constructors
660 anchor_style = AnchorStyles.Top | AnchorStyles.Left;
668 layout_pending = false;
670 causes_validation = true;
672 layout_suspended = 0;
676 right_to_left = RightToLeft.Inherit;
677 border_style = BorderStyle.None;
678 background_color = Color.Empty;
685 use_compatible_text_rendering = Application.use_compatible_text_rendering;
686 padding = new Padding(0);
687 maximum_size = new Size();
688 minimum_size = new Size();
691 control_style = ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint |
692 ControlStyles.Selectable | ControlStyles.StandardClick |
693 ControlStyles.StandardDoubleClick;
696 background_image = null;
700 window = new ControlNativeWindow(this);
701 child_controls = CreateControlsInstance();
702 client_size = new Size(DefaultSize.Width, DefaultSize.Height);
703 client_rect = new Rectangle(0, 0, DefaultSize.Width, DefaultSize.Height);
704 XplatUI.CalculateWindowRect(ref client_rect, CreateParams.Style, CreateParams.ExStyle, null, out bounds);
705 if ((CreateParams.Style & (int)WindowStyles.WS_CHILD) == 0) {
711 public Control(Control parent, string text) : this() {
716 public Control(Control parent, string text, int left, int top, int width, int height) : this() {
721 bounds.Height=height;
722 SetBoundsCore(left, top, width, height, BoundsSpecified.All);
726 public Control(string text) : this() {
730 public Control(string text, int left, int top, int width, int height) : this() {
734 bounds.Height=height;
735 SetBoundsCore(left, top, width, height, BoundsSpecified.All);
739 private delegate void RemoveDelegate(object c);
741 protected override void Dispose(bool disposing) {
755 if (this.InvokeRequired) {
756 if (Application.MessageLoop) {
757 this.BeginInvokeInternal(new MethodInvoker(DestroyHandle), null, true);
758 this.BeginInvokeInternal(new RemoveDelegate(controls.Remove), new object[] {this}, true);
762 controls.Remove(this);
766 if (parent != null) {
767 parent.Controls.Remove(this);
770 Control [] children = child_controls.GetAllControls ();
771 for (int i=0; i<children.Length; i++) {
772 children[i].parent = null; // Need to set to null or our child will try and remove from ourselves and crash
773 children[i].Dispose();
777 base.Dispose(disposing);
779 #endregion // Public Constructors
781 #region Internal Properties
782 internal BorderStyle InternalBorderStyle {
788 if (!Enum.IsDefined (typeof (BorderStyle), value))
789 throw new InvalidEnumArgumentException (string.Format("Enum argument value '{0}' is not valid for BorderStyle", value));
791 if (border_style != value) {
792 border_style = value;
794 if (IsHandleCreated) {
795 XplatUI.SetBorderStyle(window.Handle, (FormBorderStyle)border_style);
801 #endregion // Internal Properties
803 #region Private & Internal Methods
804 internal IAsyncResult BeginInvokeInternal (Delegate method, object [] args, bool disposing) {
805 AsyncMethodResult result;
806 AsyncMethodData data;
813 if (!p.IsHandleCreated) {
814 throw new InvalidOperationException("Cannot call Invoke or InvokeAsync on a control until the window handle is created");
820 result = new AsyncMethodResult ();
821 data = new AsyncMethodData ();
823 data.Method = method;
825 data.Result = result;
828 if (!ExecutionContext.IsFlowSuppressed ()) {
829 data.Context = ExecutionContext.Capture ();
832 #if !MWF_ON_MSRUNTIME
833 if (SecurityManager.SecurityEnabled) {
834 data.Stack = CompressedStack.GetCompressedStack ();
839 XplatUI.SendAsyncMethod (data);
844 internal void PointToClient (ref int x, ref int y)
846 XplatUI.ScreenToClient (Handle, ref x, ref y);
849 internal void PointToScreen (ref int x, ref int y)
851 XplatUI.ClientToScreen (Handle, ref x, ref y);
854 private bool IsRecreating {
860 if (parent != null) {
861 return parent.IsRecreating;
868 private bool ParentIsRecreating {
870 if (parent != null) {
871 return parent.IsRecreating;
877 internal Graphics DeviceContext {
879 if (dc_mem == null) {
880 CreateBuffers(this.Width, this.Height);
881 dc_state = dc_mem.Save();
887 internal void ResetDeviceContext() {
888 dc_mem.Restore(dc_state);
889 dc_state = dc_mem.Save();
892 private Bitmap ImageBuffer {
895 CreateBuffers(this.Width, this.Height);
901 internal void CreateBuffers (int width, int height) {
902 if (dc_mem != null) {
916 bmp_mem = new Bitmap (width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
917 dc_mem = Graphics.FromImage (bmp_mem);
921 internal void InvalidateBuffers ()
923 if (dc_mem != null) {
934 internal static void SetChildColor(Control parent) {
937 for (int i=0; i < parent.child_controls.Count; i++) {
938 child=parent.child_controls[i];
939 if (child.child_controls.Count>0) {
940 SetChildColor(child);
946 internal bool Select(Control control) {
947 IContainerControl container;
949 if (control == null) {
953 container = GetContainerControl();
954 if (container != null) {
955 container.ActiveControl = control;
957 if (control.IsHandleCreated) {
958 XplatUI.SetFocus(control.window.Handle);
963 internal void SelectChild (Control control)
965 if (control.IsHandleCreated)
966 XplatUI.SetFocus (control.window.Handle);
969 internal virtual void DoDefaultAction() {
970 // Only here to be overriden by our actual controls; this is needed by the accessibility class
973 internal static int LowOrder (int param) {
974 return ((int)(short)(param & 0xffff));
977 internal static int HighOrder (int param) {
978 return ((int)(short)(param >> 16));
981 // This method exists so controls overriding OnPaintBackground can have default background painting done
982 internal virtual void PaintControlBackground (PaintEventArgs pevent)
984 if (GetStyle(ControlStyles.SupportsTransparentBackColor) && (BackColor.A != 0xff)) {
985 if (parent != null) {
986 PaintEventArgs parent_pe;
989 parent_pe = new PaintEventArgs(pevent.Graphics, new Rectangle(pevent.ClipRectangle.X + Left, pevent.ClipRectangle.Y + Top, pevent.ClipRectangle.Width, pevent.ClipRectangle.Height));
991 state = parent_pe.Graphics.Save();
992 parent_pe.Graphics.TranslateTransform(-Left, -Top);
993 parent.OnPaintBackground(parent_pe);
994 parent_pe.Graphics.Restore(state);
996 state = parent_pe.Graphics.Save();
997 parent_pe.Graphics.TranslateTransform(-Left, -Top);
998 parent.OnPaint(parent_pe);
999 parent_pe.Graphics.Restore(state);
1000 parent_pe.SetGraphics(null);
1004 if ((clip_region != null) && (XplatUI.UserClipWontExposeParent)) {
1005 if (parent != null) {
1006 PaintEventArgs parent_pe;
1008 GraphicsState state;
1011 hwnd = Hwnd.ObjectFromHandle(Handle);
1014 parent_pe = new PaintEventArgs(pevent.Graphics, new Rectangle(pevent.ClipRectangle.X + Left, pevent.ClipRectangle.Y + Top, pevent.ClipRectangle.Width, pevent.ClipRectangle.Height));
1016 region = new Region ();
1018 region.Union(ClientRectangle);
1020 foreach (Rectangle r in hwnd.ClipRectangles) {
1024 state = parent_pe.Graphics.Save();
1025 parent_pe.Graphics.Clip = region;
1027 parent_pe.Graphics.TranslateTransform(-Left, -Top);
1028 parent.OnPaintBackground(parent_pe);
1029 parent_pe.Graphics.Restore(state);
1031 state = parent_pe.Graphics.Save();
1032 parent_pe.Graphics.Clip = region;
1034 parent_pe.Graphics.TranslateTransform(-Left, -Top);
1035 parent.OnPaint(parent_pe);
1036 parent_pe.Graphics.Restore(state);
1037 parent_pe.SetGraphics(null);
1039 region.Intersect(clip_region);
1040 pevent.Graphics.Clip = region;
1045 if (background_image == null) {
1046 pevent.Graphics.FillRectangle(ThemeEngine.Current.ResPool.GetSolidBrush(BackColor), new Rectangle(pevent.ClipRectangle.X - 1, pevent.ClipRectangle.Y - 1, pevent.ClipRectangle.Width + 2, pevent.ClipRectangle.Height + 2));
1050 DrawBackgroundImage (pevent.Graphics);
1053 void DrawBackgroundImage (Graphics g)
1055 using (TextureBrush b = new TextureBrush (background_image, WrapMode.Tile)) {
1056 g.FillRectangle (b, ClientRectangle);
1060 internal virtual void DndEnter (DragEventArgs e)
1067 internal virtual void DndOver (DragEventArgs e)
1074 internal virtual void DndDrop (DragEventArgs e)
1078 } catch (Exception exc) {
1079 Console.Error.WriteLine ("MWF: Exception while dropping:");
1080 Console.Error.WriteLine (exc);
1084 internal virtual void DndLeave (EventArgs e)
1091 internal virtual void DndFeedback(GiveFeedbackEventArgs e)
1098 internal virtual void DndContinueDrag(QueryContinueDragEventArgs e)
1101 OnQueryContinueDrag(e);
1105 internal static MouseButtons FromParamToMouseButtons (int param) {
1106 MouseButtons buttons = MouseButtons.None;
1108 if ((param & (int) MsgButtons.MK_LBUTTON) != 0)
1109 buttons |= MouseButtons.Left;
1111 if ((param & (int) MsgButtons.MK_MBUTTON) != 0)
1112 buttons |= MouseButtons.Middle;
1114 if ((param & (int) MsgButtons.MK_RBUTTON) != 0)
1115 buttons |= MouseButtons.Right;
1121 internal void FireEnter ()
1123 OnEnter (EventArgs.Empty);
1126 internal void FireLeave ()
1128 OnLeave (EventArgs.Empty);
1131 internal virtual bool ProcessControlMnemonic(char charCode) {
1132 return ProcessMnemonic(charCode);
1135 private static Control FindFlatForward(Control container, Control start) {
1141 end = container.child_controls.Count;
1143 if (start != null) {
1144 index = start.tab_index;
1149 for (int i = 0; i < end; i++) {
1150 if (found == null) {
1151 if (container.child_controls[i].tab_index > index) {
1152 found = container.child_controls[i];
1154 } else if (found.tab_index > container.child_controls[i].tab_index) {
1155 if (container.child_controls[i].tab_index > index) {
1156 found = container.child_controls[i];
1163 private static Control FindControlForward(Control container, Control start) {
1169 if (start != null) {
1170 if ((start is IContainerControl) || start.GetStyle(ControlStyles.ContainerControl)) {
1171 found = FindControlForward(start, null);
1172 if (found != null) {
1178 while (p != container) {
1179 found = FindFlatForward(p, start);
1180 if (found != null) {
1187 return FindFlatForward(container, start);
1190 private static Control FindFlatBackward(Control container, Control start) {
1196 end = container.child_controls.Count;
1198 if (start != null) {
1199 index = start.tab_index;
1201 // FIXME: Possible speed-up: Keep the highest taborder index in the container
1203 for (int i = 0; i < end; i++) {
1204 if (container.child_controls[i].tab_index > index) {
1205 index = container.child_controls[i].tab_index;
1211 for (int i = 0; i < end; i++) {
1212 if (found == null) {
1213 if (container.child_controls[i].tab_index < index) {
1214 found = container.child_controls[i];
1216 } else if (found.tab_index < container.child_controls[i].tab_index) {
1217 if (container.child_controls[i].tab_index < index) {
1218 found = container.child_controls[i];
1225 private static Control FindControlBackward(Control container, Control start) {
1230 if (start != null) {
1231 found = FindFlatBackward(start.parent, start);
1232 if (found == null) {
1233 if (start.parent != container) {
1234 return start.parent;
1240 if (found == null) {
1241 found = FindFlatBackward(container, start);
1244 if (container != start) {
1245 while ((found != null) && (!found.Contains(start)) && ((found is IContainerControl) || found.GetStyle(ControlStyles.ContainerControl))) {
1246 found = FindControlBackward(found, null);
1247 if (found != null) {
1256 private void HandleClick(int clicks, MouseEventArgs me) {
1257 if (GetStyle(ControlStyles.StandardClick)) {
1258 if ((clicks > 1) && GetStyle(ControlStyles.StandardDoubleClick)) {
1260 OnDoubleClick(EventArgs.Empty);
1262 OnClick(EventArgs.Empty);
1272 private void CheckDataBindings ()
1274 if (data_bindings == null)
1277 BindingContext binding_context = BindingContext;
1278 foreach (Binding binding in data_bindings) {
1279 binding.Check (binding_context);
1284 private void ChangeParent(Control new_parent) {
1288 Color pre_fore_color;
1289 Color pre_back_color;
1290 RightToLeft pre_rtl;
1292 // These properties are inherited from our parent
1293 // Get them pre parent-change and then send events
1294 // if they are changed after we have our new parent
1295 pre_enabled = Enabled;
1296 pre_visible = Visible;
1298 pre_fore_color = ForeColor;
1299 pre_back_color = BackColor;
1300 pre_rtl = RightToLeft;
1301 // MS doesn't seem to send a CursorChangedEvent
1303 parent = new_parent;
1305 if (IsHandleCreated && (new_parent != null) && new_parent.IsHandleCreated) {
1306 XplatUI.SetParent(Handle, new_parent.Handle);
1309 OnParentChanged(EventArgs.Empty);
1311 if (pre_enabled != Enabled) {
1312 OnEnabledChanged(EventArgs.Empty);
1315 if (pre_visible != Visible) {
1316 OnVisibleChanged(EventArgs.Empty);
1319 if (pre_font != Font) {
1320 OnFontChanged(EventArgs.Empty);
1323 if (pre_fore_color != ForeColor) {
1324 OnForeColorChanged(EventArgs.Empty);
1327 if (pre_back_color != BackColor) {
1328 OnBackColorChanged(EventArgs.Empty);
1331 if (pre_rtl != RightToLeft) {
1332 // MS sneaks a OnCreateControl and OnHandleCreated in here, I guess
1333 // because when RTL changes they have to recreate the win32 control
1334 // We don't really need that (until someone runs into compatibility issues)
1335 OnRightToLeftChanged(EventArgs.Empty);
1338 if ((new_parent != null) && new_parent.Created && !Created) {
1342 if ((binding_context == null) && Created) {
1343 OnBindingContextChanged(EventArgs.Empty);
1347 private void UpdateDistances() {
1348 if ((parent != null) && (parent.layout_suspended == 0)) {
1349 dist_left = bounds.X;
1350 dist_top = bounds.Y;
1351 dist_right = parent.ClientSize.Width - bounds.X - bounds.Width;
1352 dist_bottom = parent.ClientSize.Height - bounds.Y - bounds.Height;
1355 #endregion // Private & Internal Methods
1357 #region Public Static Properties
1358 public static Color DefaultBackColor {
1360 return ThemeEngine.Current.DefaultControlBackColor;
1364 public static Font DefaultFont {
1366 return ThemeEngine.Current.DefaultFont;
1370 public static Color DefaultForeColor {
1372 return ThemeEngine.Current.DefaultControlForeColor;
1376 public static Keys ModifierKeys {
1378 return XplatUI.State.ModifierKeys;
1382 public static MouseButtons MouseButtons {
1384 return XplatUI.State.MouseButtons;
1388 public static Point MousePosition {
1390 return Cursor.Position;
1396 public static bool CheckForIllegalCrossThreadCalls
1399 return verify_thread_handle;
1403 verify_thread_handle = value;
1407 #endregion // Public Static Properties
1409 #region Public Instance Properties
1410 [EditorBrowsable(EditorBrowsableState.Advanced)]
1412 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1413 public AccessibleObject AccessibilityObject {
1415 if (accessibility_object==null) {
1416 accessibility_object=CreateAccessibilityInstance();
1418 return accessibility_object;
1422 [EditorBrowsable(EditorBrowsableState.Advanced)]
1424 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1425 public string AccessibleDefaultActionDescription {
1427 return AccessibilityObject.default_action;
1431 AccessibilityObject.default_action=value;
1436 [DefaultValue(null)]
1437 [MWFCategory("Accessibility")]
1438 public string AccessibleDescription {
1440 return AccessibilityObject.description;
1444 AccessibilityObject.description=value;
1449 [DefaultValue(null)]
1450 [MWFCategory("Accessibility")]
1451 public string AccessibleName {
1453 return AccessibilityObject.Name;
1457 AccessibilityObject.Name=value;
1461 [DefaultValue(AccessibleRole.Default)]
1462 [MWFDescription("Role of the control"), MWFCategory("Accessibility")]
1463 public AccessibleRole AccessibleRole {
1465 return AccessibilityObject.role;
1469 AccessibilityObject.role=value;
1473 [DefaultValue(false)]
1474 [MWFCategory("Behavior")]
1475 public virtual bool AllowDrop {
1481 if (allow_drop == value)
1484 if (IsHandleCreated) {
1486 XplatUI.SetAllowDrop (Handle, value);
1492 [RefreshProperties(RefreshProperties.Repaint)]
1493 [DefaultValue(AnchorStyles.Top | AnchorStyles.Left)]
1494 [MWFCategory("Layout")]
1495 public virtual AnchorStyles Anchor {
1497 return anchor_style;
1503 if (parent != null) {
1504 parent.PerformLayout(this, "Parent");
1510 // XXX: Implement me!
1513 public virtual bool AutoSize {
1515 Console.Error.WriteLine("Unimplemented: Control::get_AutoSize()");
1519 Console.Error.WriteLine("Unimplemented: Control::set_AutoSize(bool)");
1524 public virtual Size MaximumSize {
1526 return maximum_size;
1529 maximum_size = value;
1533 public virtual Size MinimumSize {
1535 return minimum_size;
1538 minimum_size = value;
1544 [MWFCategory("Appearance")]
1545 public virtual Color BackColor {
1547 if (background_color.IsEmpty) {
1549 Color pcolor = parent.BackColor;
1550 if (pcolor.A == 0xff || GetStyle(ControlStyles.SupportsTransparentBackColor))
1553 return DefaultBackColor;
1555 return background_color;
1559 if (!value.IsEmpty && (value.A != 0xff) && !GetStyle(ControlStyles.SupportsTransparentBackColor)) {
1560 throw new ArgumentException("Transparent background colors are not supported on this control");
1563 background_color=value;
1564 SetChildColor(this);
1565 OnBackColorChanged(EventArgs.Empty);
1571 [DefaultValue(null)]
1572 [MWFCategory("Appearance")]
1573 public virtual Image BackgroundImage {
1575 return background_image;
1579 if (background_image!=value) {
1580 background_image=value;
1581 OnBackgroundImageChanged(EventArgs.Empty);
1586 [EditorBrowsable(EditorBrowsableState.Advanced)]
1588 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1589 public virtual BindingContext BindingContext {
1591 if (binding_context != null)
1592 return binding_context;
1595 binding_context = Parent.BindingContext;
1596 return binding_context;
1599 if (binding_context != value) {
1600 binding_context = value;
1601 OnBindingContextChanged(EventArgs.Empty);
1606 [EditorBrowsable(EditorBrowsableState.Advanced)]
1608 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1611 return bounds.Y+bounds.Height;
1615 [EditorBrowsable(EditorBrowsableState.Advanced)]
1617 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1618 public Rectangle Bounds {
1624 SetBoundsCore(value.Left, value.Top, value.Width, value.Height, BoundsSpecified.All);
1628 [EditorBrowsable(EditorBrowsableState.Advanced)]
1630 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1631 public bool CanFocus {
1633 if (IsHandleCreated && Visible && Enabled) {
1640 [EditorBrowsable(EditorBrowsableState.Advanced)]
1642 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1643 public bool CanSelect {
1647 if (!GetStyle(ControlStyles.Selectable)) {
1652 while (parent != null) {
1653 if (!parent.is_visible || !parent.is_enabled) {
1657 parent = parent.parent;
1663 internal virtual bool InternalCapture {
1673 [EditorBrowsable(EditorBrowsableState.Advanced)]
1675 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1676 public bool Capture {
1678 return this.is_captured;
1682 if (this.IsHandleCreated) {
1683 if (value && !is_captured) {
1685 XplatUI.GrabWindow(this.window.Handle, IntPtr.Zero);
1686 } else if (!value && is_captured) {
1687 XplatUI.UngrabWindow(this.window.Handle);
1688 is_captured = false;
1694 [DefaultValue(true)]
1695 [MWFCategory("Focus")]
1696 public bool CausesValidation {
1698 return this.causes_validation;
1702 if (this.causes_validation != value) {
1703 causes_validation = value;
1704 OnCausesValidationChanged(EventArgs.Empty);
1709 [EditorBrowsable(EditorBrowsableState.Advanced)]
1711 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1712 public Rectangle ClientRectangle {
1714 client_rect.Width = client_size.Width;
1715 client_rect.Height = client_size.Height;
1720 [EditorBrowsable(EditorBrowsableState.Advanced)]
1722 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1723 public Size ClientSize {
1726 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1727 return ((Form)this).form_parent_window.ClientSize;
1735 this.SetClientSizeCore(value.Width, value.Height);
1739 [EditorBrowsable(EditorBrowsableState.Advanced)]
1741 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1742 [DescriptionAttribute("ControlCompanyNameDescr")]
1743 public String CompanyName {
1745 return "Mono Project, Novell, Inc.";
1749 [EditorBrowsable(EditorBrowsableState.Advanced)]
1751 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1752 public bool ContainsFocus {
1754 IntPtr focused_window;
1756 focused_window = XplatUI.GetFocus();
1757 if (IsHandleCreated) {
1758 if (focused_window == Handle) {
1762 for (int i=0; i < child_controls.Count; i++) {
1763 if (child_controls[i].ContainsFocus) {
1772 [DefaultValue(null)]
1773 [MWFCategory("Behavior")]
1774 public virtual ContextMenu ContextMenu {
1776 return context_menu;
1780 if (context_menu != value) {
1781 context_menu = value;
1782 OnContextMenuChanged(EventArgs.Empty);
1788 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
1789 public ControlCollection Controls {
1791 return this.child_controls;
1795 [EditorBrowsable(EditorBrowsableState.Advanced)]
1797 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1798 public bool Created {
1800 return (!is_disposed && is_created);
1804 [AmbientValue(null)]
1805 [MWFCategory("Appearance")]
1806 public virtual Cursor Cursor {
1808 if (cursor != null) {
1812 if (parent != null) {
1813 return parent.Cursor;
1816 return Cursors.Default;
1820 if (cursor != value) {
1825 if (IsHandleCreated) {
1826 pt = Cursor.Position;
1828 if (bounds.Contains(pt) || Capture) {
1829 if (GetChildAtPoint(pt) == null) {
1830 if (cursor != null) {
1831 XplatUI.SetCursor(window.Handle, cursor.handle);
1833 if (parent != null) {
1834 XplatUI.SetCursor(window.Handle, parent.Cursor.handle);
1836 XplatUI.SetCursor(window.Handle, Cursors.Default.handle);
1843 OnCursorChanged(EventArgs.Empty);
1849 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
1850 [ParenthesizePropertyName(true)]
1851 [RefreshProperties(RefreshProperties.All)]
1852 [MWFCategory("Data")]
1853 public ControlBindingsCollection DataBindings {
1855 if (data_bindings == null)
1856 data_bindings = new ControlBindingsCollection (this);
1857 return data_bindings;
1861 [EditorBrowsable(EditorBrowsableState.Advanced)]
1863 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1864 public virtual Rectangle DisplayRectangle {
1866 return ClientRectangle;
1870 [EditorBrowsable(EditorBrowsableState.Advanced)]
1872 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1873 public bool Disposing {
1880 [RefreshProperties(RefreshProperties.Repaint)]
1881 [DefaultValue(DockStyle.None)]
1882 [MWFCategory("Layout")]
1883 public virtual DockStyle Dock {
1889 if (dock_style == value) {
1895 if (parent != null) {
1896 parent.PerformLayout(this, "Parent");
1899 OnDockChanged(EventArgs.Empty);
1905 [MWFCategory("Behavior")]
1906 public bool Enabled {
1912 if (parent != null) {
1913 return parent.Enabled;
1920 if (Enabled == value) {
1927 // FIXME - we need to switch focus to next control if we're disabling the focused control
1929 OnEnabledChanged (EventArgs.Empty);
1933 [EditorBrowsable(EditorBrowsableState.Advanced)]
1935 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1936 public virtual bool Focused {
1938 return this.has_focus;
1943 [AmbientValue(null)]
1945 [MWFCategory("Appearance")]
1946 public virtual Font Font {
1952 if (Parent != null && Parent.Font != null) {
1959 [param:MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Font))]
1961 if (font != null && font.Equals (value)) {
1967 OnFontChanged (EventArgs.Empty);
1972 [MWFCategory("Appearance")]
1973 public virtual Color ForeColor {
1975 if (foreground_color.IsEmpty) {
1977 return parent.ForeColor;
1979 return DefaultForeColor;
1981 return foreground_color;
1985 if (foreground_color != value) {
1986 foreground_color=value;
1988 OnForeColorChanged(EventArgs.Empty);
1995 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1996 public IntPtr Handle { // IWin32Window
1999 if (verify_thread_handle) {
2000 if (this.InvokeRequired) {
2001 throw new InvalidOperationException("Cross-thread access of handle detected. Handle access only valid on thread that created the control");
2005 if (!IsHandleCreated) {
2008 return window.Handle;
2012 [EditorBrowsable(EditorBrowsableState.Advanced)]
2014 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2015 public bool HasChildren {
2017 if (this.child_controls.Count>0) {
2024 [EditorBrowsable(EditorBrowsableState.Always)]
2026 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2029 return this.bounds.Height;
2033 SetBoundsCore(bounds.X, bounds.Y, bounds.Width, value, BoundsSpecified.Height);
2037 [AmbientValue(ImeMode.Inherit)]
2039 [MWFCategory("Behavior")]
2040 public ImeMode ImeMode {
2042 if (ime_mode == DefaultImeMode) {
2044 return parent.ImeMode;
2046 return ImeMode.NoControl; // default value
2052 if (ime_mode != value) {
2055 OnImeModeChanged(EventArgs.Empty);
2060 [EditorBrowsable(EditorBrowsableState.Advanced)]
2062 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2063 public bool InvokeRequired { // ISynchronizeInvoke
2065 if (creator_thread != null && creator_thread!=Thread.CurrentThread) {
2072 [EditorBrowsable(EditorBrowsableState.Advanced)]
2074 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2075 public bool IsAccessible {
2077 return is_accessible;
2081 is_accessible = value;
2085 [EditorBrowsable(EditorBrowsableState.Advanced)]
2087 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2088 public bool IsDisposed {
2090 return this.is_disposed;
2094 [EditorBrowsable(EditorBrowsableState.Advanced)]
2096 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2097 public bool IsHandleCreated {
2099 if ((window != null) && (window.Handle != IntPtr.Zero)) {
2107 [EditorBrowsable(EditorBrowsableState.Always)]
2109 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2112 return this.bounds.X;
2116 SetBoundsCore(value, bounds.Y, bounds.Width, bounds.Height, BoundsSpecified.X);
2121 [MWFCategory("Layout")]
2122 public Point Location {
2124 return new Point(bounds.X, bounds.Y);
2128 SetBoundsCore(value.X, value.Y, bounds.Width, bounds.Height, BoundsSpecified.Location);
2133 public string Name {
2145 public Padding Padding {
2157 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2158 public Control Parent {
2164 if (value == this) {
2165 throw new ArgumentException("A circular control reference has been made. A control cannot be owned or parented to itself.");
2168 if (parent!=value) {
2170 parent.Controls.Remove(this);
2174 value.Controls.Add(this);
2179 [EditorBrowsable(EditorBrowsableState.Advanced)]
2181 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2182 public string ProductName {
2184 Type t = typeof (AssemblyProductAttribute);
2185 Assembly assembly = GetType().Module.Assembly;
2186 object [] attrs = assembly.GetCustomAttributes (t, false);
2187 AssemblyProductAttribute a = null;
2188 // On MS we get a NullRefException if product attribute is not
2190 if (attrs != null && attrs.Length > 0)
2191 a = (AssemblyProductAttribute) attrs [0];
2196 [EditorBrowsable(EditorBrowsableState.Advanced)]
2198 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2199 public string ProductVersion {
2201 Type t = typeof (AssemblyVersionAttribute);
2202 Assembly assembly = GetType().Module.Assembly;
2203 object [] attrs = assembly.GetCustomAttributes (t, false);
2204 if (attrs == null || attrs.Length < 1)
2206 return ((AssemblyVersionAttribute)attrs [0]).Version;
2210 [EditorBrowsable(EditorBrowsableState.Advanced)]
2212 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2213 public bool RecreatingHandle {
2215 return is_recreating;
2219 [EditorBrowsable(EditorBrowsableState.Advanced)]
2221 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2222 public Region Region {
2228 if (IsHandleCreated) {
2229 XplatUI.SetClipRegion(Handle, value);
2231 clip_region = value;
2235 [EditorBrowsable(EditorBrowsableState.Advanced)]
2237 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2240 return this.bounds.X+this.bounds.Width;
2244 [AmbientValue(RightToLeft.Inherit)]
2246 [MWFCategory("Appearance")]
2247 public virtual RightToLeft RightToLeft {
2249 if (right_to_left == RightToLeft.Inherit) {
2251 return parent.RightToLeft;
2253 return RightToLeft.No; // default value
2255 return right_to_left;
2259 if (value != right_to_left) {
2260 right_to_left = value;
2261 OnRightToLeftChanged(EventArgs.Empty);
2266 [EditorBrowsable(EditorBrowsableState.Advanced)]
2267 public override ISite Site {
2275 AmbientProperties ap = (AmbientProperties) value.GetService (typeof (AmbientProperties));
2277 BackColor = ap.BackColor;
2278 ForeColor = ap.ForeColor;
2286 [MWFCategory("Layout")]
2289 return new Size(Width, Height);
2293 SetBoundsCore(bounds.X, bounds.Y, value.Width, value.Height, BoundsSpecified.Size);
2298 [MergableProperty(false)]
2299 [MWFCategory("Behavior")]
2300 public int TabIndex {
2302 if (tab_index != -1) {
2309 if (tab_index != value) {
2311 OnTabIndexChanged(EventArgs.Empty);
2317 [DefaultValue(true)]
2318 [MWFCategory("Behavior")]
2319 public bool TabStop {
2325 if (tab_stop != value) {
2327 OnTabStopChanged(EventArgs.Empty);
2332 [Localizable(false)]
2334 [TypeConverter(typeof(StringConverter))]
2335 [DefaultValue(null)]
2336 [MWFCategory("Data")]
2343 control_tag = value;
2349 [BindableAttribute(true)]
2350 [MWFCategory("Appearance")]
2351 public virtual string Text {
2353 // Our implementation ignores ControlStyles.CacheText - we always cache
2358 if (value == null) {
2359 value = String.Empty;
2364 if (IsHandleCreated) {
2365 XplatUI.Text(Handle, text);
2367 OnTextChanged (EventArgs.Empty);
2372 [EditorBrowsable(EditorBrowsableState.Always)]
2374 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2377 return this.bounds.Y;
2381 SetBoundsCore(bounds.X, value, bounds.Width, bounds.Height, BoundsSpecified.Y);
2385 [EditorBrowsable(EditorBrowsableState.Advanced)]
2387 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2388 public Control TopLevelControl {
2392 while (p.parent != null) {
2401 [MWFCategory("Behavior")]
2402 public bool Visible {
2406 } else if (parent != null) {
2407 return parent.Visible;
2414 SetVisibleCore(value);
2418 [EditorBrowsable(EditorBrowsableState.Always)]
2420 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2423 return this.bounds.Width;
2427 SetBoundsCore(bounds.X, bounds.Y, value, bounds.Height, BoundsSpecified.Width);
2431 [EditorBrowsable(EditorBrowsableState.Never)]
2433 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2434 public IWindowTarget WindowTarget {
2443 #endregion // Public Instance Properties
2445 #region Protected Instance Properties
2446 protected virtual CreateParams CreateParams {
2448 CreateParams create_params = new CreateParams();
2451 create_params.Caption = Text;
2454 create_params.Caption = text;
2458 create_params.X = Left;
2461 create_params.X = this.bounds.X;
2465 create_params.Y = Top;
2468 create_params.Y = this.bounds.Y;
2472 create_params.Width = Width;
2475 create_params.Width = this.bounds.Width;
2479 create_params.Height = Height;
2482 create_params.Height = this.bounds.Height;
2486 create_params.ClassName = XplatUI.DefaultClassName;
2487 create_params.ClassStyle = 0;
2488 create_params.ExStyle = 0;
2489 create_params.Param = 0;
2492 create_params.ExStyle |= (int)WindowExStyles.WS_EX_ACCEPTFILES;
2495 if ((parent!=null) && (parent.IsHandleCreated)) {
2496 create_params.Parent = parent.Handle;
2499 create_params.Style = (int)WindowStyles.WS_CHILD | (int)WindowStyles.WS_CLIPCHILDREN | (int)WindowStyles.WS_CLIPSIBLINGS;
2502 create_params.Style |= (int)WindowStyles.WS_VISIBLE;
2506 create_params.Style |= (int)WindowStyles.WS_DISABLED;
2509 switch (border_style) {
2510 case BorderStyle.FixedSingle:
2511 create_params.Style |= (int) WindowStyles.WS_BORDER;
2513 case BorderStyle.Fixed3D:
2514 create_params.ExStyle |= (int) WindowExStyles.WS_EX_CLIENTEDGE;
2518 return create_params;
2522 protected virtual ImeMode DefaultImeMode {
2524 return ImeMode.Inherit;
2528 protected virtual Size DefaultSize {
2530 return new Size(0, 0);
2534 protected int FontHeight {
2544 protected bool RenderRightToLeft {
2546 return (this.right_to_left == RightToLeft.Yes);
2550 protected bool ResizeRedraw {
2552 return GetStyle(ControlStyles.ResizeRedraw);
2556 SetStyle(ControlStyles.ResizeRedraw, value);
2560 [EditorBrowsable(EditorBrowsableState.Advanced)]
2562 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2563 protected virtual bool ShowFocusCues {
2569 [EditorBrowsable(EditorBrowsableState.Advanced)]
2571 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2572 protected bool ShowKeyboardCues {
2577 #endregion // Protected Instance Properties
2579 #region Public Static Methods
2580 [EditorBrowsable(EditorBrowsableState.Advanced)]
2581 public static Control FromChildHandle(IntPtr handle) {
2582 IEnumerator control = Control.controls.GetEnumerator();
2584 while (control.MoveNext()) {
2585 if (((Control)control.Current).window.Handle == handle) {
2587 if (((Control)control.Current).Parent != null) {
2588 return ((Control)control.Current).Parent;
2595 [EditorBrowsable(EditorBrowsableState.Advanced)]
2596 public static Control FromHandle(IntPtr handle) {
2598 IEnumerator control = Control.controls.GetEnumerator();
2600 while (control.MoveNext()) {
2601 if (((Control)control.Current).window.Handle == handle) {
2603 return ((Control)control.Current);
2609 return Control.ControlNativeWindow.ControlFromHandle(handle);
2613 public static bool IsMnemonic(char charCode, string text) {
2616 amp = text.IndexOf('&');
2619 if (amp + 1 < text.Length) {
2620 if (text[amp + 1] != '&') {
2621 if (Char.ToUpper(charCode) == Char.ToUpper(text.ToCharArray(amp + 1, 1)[0])) {
2631 #region Protected Static Methods
2632 [EditorBrowsable(EditorBrowsableState.Advanced)]
2633 protected static bool ReflectMessage(IntPtr hWnd, ref Message m) {
2636 c = Control.FromHandle(hWnd);
2646 #region Public Instance Methods
2647 [EditorBrowsable(EditorBrowsableState.Advanced)]
2648 public IAsyncResult BeginInvoke(Delegate method) {
2649 object [] prms = null;
2650 if (method is EventHandler)
2651 prms = new object [] { this, EventArgs.Empty };
2652 return BeginInvokeInternal(method, prms, false);
2655 [EditorBrowsable(EditorBrowsableState.Advanced)]
2656 public IAsyncResult BeginInvoke (Delegate method, object[] args) {
2657 return BeginInvokeInternal (method, args, false);
2660 public void BringToFront() {
2661 if (parent != null) {
2662 parent.child_controls.SetChildIndex(this, 0);
2667 public bool Contains(Control ctl) {
2668 while (ctl != null) {
2677 public void CreateControl() {
2682 if (!IsHandleCreated) {
2690 Control [] controls = child_controls.GetAllControls ();
2691 for (int i=0; i<controls.Length; i++) {
2692 controls [i].CreateControl ();
2695 UpdateChildrenZOrder();
2697 if (binding_context == null) { // seem to be sent whenever it's null?
2698 OnBindingContextChanged(EventArgs.Empty);
2704 public Graphics CreateGraphics() {
2705 if (!IsHandleCreated) {
2706 this.CreateHandle();
2708 return Graphics.FromHwnd(this.window.Handle);
2711 public DragDropEffects DoDragDrop(object data, DragDropEffects allowedEffects) {
2712 return XplatUI.StartDrag(this.window.Handle, data, allowedEffects);
2715 [EditorBrowsable(EditorBrowsableState.Advanced)]
2716 public object EndInvoke (IAsyncResult async_result) {
2717 AsyncMethodResult result = (AsyncMethodResult) async_result;
2718 return result.EndInvoke ();
2721 public Form FindForm() {
2734 public bool Focus() {
2735 if (CanFocus && IsHandleCreated && !has_focus) {
2736 XplatUI.SetFocus(window.Handle);
2741 public Control GetChildAtPoint(Point pt) {
2742 // Microsoft's version of this function doesn't seem to work, so I can't check
2743 // if we only consider children or also grandchildren, etc.
2744 // I'm gonna say 'children only'
2745 for (int i=0; i<child_controls.Count; i++) {
2746 if (child_controls[i].Bounds.Contains(pt)) {
2747 return child_controls[i];
2753 public IContainerControl GetContainerControl() {
2754 Control current = this;
2756 while (current!=null) {
2757 if ((current is IContainerControl) && ((current.control_style & ControlStyles.ContainerControl)!=0)) {
2758 return (IContainerControl)current;
2760 current = current.parent;
2765 public Control GetNextControl(Control ctl, bool forward) {
2766 // If we're not a container we don't play
2767 if (!(this is IContainerControl) && !this.GetStyle(ControlStyles.ContainerControl)) {
2774 return FindFlatBackward(ctl, null);
2777 if ((parent == null) && (ctl is IContainerControl) && ctl.GetStyle(ControlStyles.ContainerControl)) {
2779 return FindFlatForward(this, ctl);
2781 return FindFlatBackward(this, ctl);
2786 // If ctl is not contained by this, we start at the first child of this
2787 if (!this.Contains(ctl)) {
2791 // Search through our controls, starting at ctl, stepping into children as we encounter them
2792 // try to find the control with the tabindex closest to our own, or, if we're looking into
2793 // child controls, the one with the smallest tabindex
2795 return FindControlForward(this, ctl);
2797 return FindControlBackward(this, ctl);
2800 public void Hide() {
2801 this.Visible = false;
2804 public void Invalidate() {
2805 Invalidate(ClientRectangle, false);
2808 public void Invalidate(bool invalidateChildren) {
2809 Invalidate(ClientRectangle, invalidateChildren);
2812 public void Invalidate(System.Drawing.Rectangle rc) {
2813 Invalidate(rc, false);
2816 public void Invalidate(System.Drawing.Rectangle rc, bool invalidateChildren) {
2817 if (!IsHandleCreated || !Visible || rc.Width == 0 || rc.Height == 0) {
2821 NotifyInvalidate(rc);
2823 XplatUI.Invalidate(Handle, rc, false);
2825 if (invalidateChildren) {
2826 Control [] controls = child_controls.GetAllControls ();
2827 for (int i=0; i<controls.Length; i++)
2828 controls [i].Invalidate ();
2830 OnInvalidated(new InvalidateEventArgs(rc));
2833 public void Invalidate(System.Drawing.Region region) {
2834 Invalidate(region, false);
2837 public void Invalidate(System.Drawing.Region region, bool invalidateChildren) {
2838 RectangleF bounds = region.GetBounds (CreateGraphics ());
2839 Invalidate (new Rectangle ((int) bounds.X, (int) bounds.Y, (int) bounds.Width, (int) bounds.Height),
2840 invalidateChildren);
2843 public object Invoke (Delegate method) {
2844 object [] prms = null;
2845 if (method is EventHandler)
2846 prms = new object [] { this, EventArgs.Empty };
2848 return Invoke(method, prms);
2851 public object Invoke (Delegate method, object[] args) {
2852 if (!this.InvokeRequired) {
2853 return method.DynamicInvoke(args);
2856 IAsyncResult result = BeginInvoke (method, args);
2857 return EndInvoke(result);
2860 internal object InvokeInternal (Delegate method, bool disposing) {
2861 return InvokeInternal(method, null, disposing);
2864 internal object InvokeInternal (Delegate method, object[] args, bool disposing) {
2865 if (!this.InvokeRequired) {
2866 return method.DynamicInvoke(args);
2869 IAsyncResult result = BeginInvokeInternal (method, args, disposing);
2870 return EndInvoke(result);
2873 [EditorBrowsable(EditorBrowsableState.Advanced)]
2874 public void PerformLayout() {
2875 PerformLayout(null, null);
2878 [EditorBrowsable(EditorBrowsableState.Advanced)]
2879 public void PerformLayout(Control affectedControl, string affectedProperty) {
2880 LayoutEventArgs levent = new LayoutEventArgs(affectedControl, affectedProperty);
2882 if (layout_suspended > 0) {
2883 layout_pending = true;
2887 layout_pending = false;
2889 // Prevent us from getting messed up
2892 // Perform all Dock and Anchor calculations
2895 AnchorStyles anchor;
2898 space= DisplayRectangle;
2900 // Deal with docking; go through in reverse, MS docs say that lowest Z-order is closest to edge
2901 Control [] controls = child_controls.GetAllControls ();
2902 for (int i = controls.Length - 1; i >= 0; i--) {
2903 child = controls [i];
2905 if (!child.Visible) {
2909 switch (child.Dock) {
2910 case DockStyle.None: {
2915 case DockStyle.Left: {
2916 child.SetBounds(space.Left, space.Y, child.Width, space.Height);
2917 space.X+=child.Width;
2918 space.Width-=child.Width;
2922 case DockStyle.Top: {
2923 child.SetBounds(space.Left, space.Y, space.Width, child.Height);
2924 space.Y+=child.Height;
2925 space.Height-=child.Height;
2929 case DockStyle.Right: {
2930 child.SetBounds(space.Right-child.Width, space.Y, child.Width, space.Height);
2931 space.Width-=child.Width;
2935 case DockStyle.Bottom: {
2936 child.SetBounds(space.Left, space.Bottom-child.Height, space.Width, child.Height);
2937 space.Height-=child.Height;
2943 for (int i = controls.Length - 1; i >= 0; i--) {
2946 if (child.Visible && (child.Dock == DockStyle.Fill)) {
2947 child.SetBounds(space.Left, space.Top, space.Width, space.Height);
2951 space=DisplayRectangle;
2953 for (int i=0; i < controls.Length; i++) {
2959 child = controls[i];
2961 // If the control is docked we don't need to do anything
2962 if (child.Dock != DockStyle.None) {
2966 anchor = child.Anchor;
2970 width = child.Width;
2971 height = child.Height;
2973 if ((anchor & AnchorStyles.Left) !=0 ) {
2974 if ((anchor & AnchorStyles.Right) != 0) {
2975 width = space.Width - child.dist_right - left;
2977 ; // Left anchored only, nothing to be done
2979 } else if ((anchor & AnchorStyles.Right) != 0) {
2980 left = space.Width - child.dist_right - width;
2982 // left+=diff_width/2 will introduce rounding errors (diff_width removed from svn after r51780)
2983 // This calculates from scratch every time:
2984 left = child.dist_left + (space.Width - (child.dist_left + width + child.dist_right)) / 2;
2987 if ((anchor & AnchorStyles.Top) !=0 ) {
2988 if ((anchor & AnchorStyles.Bottom) != 0) {
2989 height = space.Height - child.dist_bottom - top;
2991 ; // Top anchored only, nothing to be done
2993 } else if ((anchor & AnchorStyles.Bottom) != 0) {
2994 top = space.Height - child.dist_bottom - height;
2996 // top += diff_height/2 will introduce rounding errors (diff_height removed from after r51780)
2997 // This calculates from scratch every time:
2998 top = child.dist_top + (space.Height - (child.dist_top + height + child.dist_bottom)) / 2;
3010 child.SetBounds(left, top, width, height);
3013 // Let everyone know
3017 // Need to make sure we decremend layout_suspended
3023 public Point PointToClient (Point p) {
3027 XplatUI.ScreenToClient (Handle, ref x, ref y);
3029 return new Point (x, y);
3032 public Point PointToScreen(Point p) {
3036 XplatUI.ClientToScreen(Handle, ref x, ref y);
3038 return new Point(x, y);
3041 public virtual bool PreProcessMessage(ref Message msg) {
3042 return InternalPreProcessMessage (ref msg);
3045 internal virtual bool InternalPreProcessMessage (ref Message msg) {
3048 if ((msg.Msg == (int)Msg.WM_KEYDOWN) || (msg.Msg == (int)Msg.WM_SYSKEYDOWN)) {
3049 key_data = (Keys)msg.WParam.ToInt32() | XplatUI.State.ModifierKeys;
3051 if (!ProcessCmdKey(ref msg, key_data)) {
3052 if (IsInputKey(key_data)) {
3056 return ProcessDialogKey(key_data);
3060 } else if (msg.Msg == (int)Msg.WM_CHAR) {
3061 if (IsInputChar((char)msg.WParam)) {
3064 } else if (msg.Msg == (int)Msg.WM_SYSCHAR) {
3065 if (IsInputChar((char)msg.WParam)) {
3068 return ProcessDialogChar((char)msg.WParam);
3073 public Rectangle RectangleToClient(Rectangle r) {
3074 return new Rectangle(PointToClient(r.Location), r.Size);
3077 public Rectangle RectangleToScreen(Rectangle r) {
3078 return new Rectangle(PointToScreen(r.Location), r.Size);
3081 public virtual void Refresh() {
3082 if (IsHandleCreated == true) {
3084 XplatUI.UpdateWindow(window.Handle);
3086 Control [] controls = child_controls.GetAllControls ();
3087 for (int i=0; i < controls.Length; i++) {
3088 controls[i].Refresh();
3094 [EditorBrowsable(EditorBrowsableState.Never)]
3095 public virtual void ResetBackColor() {
3096 background_color = Color.Empty;
3099 [EditorBrowsable(EditorBrowsableState.Never)]
3100 public void ResetBindings() {
3101 data_bindings.Clear();
3104 [EditorBrowsable(EditorBrowsableState.Never)]
3105 public virtual void ResetCursor() {
3109 [EditorBrowsable(EditorBrowsableState.Never)]
3110 public virtual void ResetFont() {
3114 [EditorBrowsable(EditorBrowsableState.Never)]
3115 public virtual void ResetForeColor() {
3116 foreground_color = Color.Empty;
3119 [EditorBrowsable(EditorBrowsableState.Never)]
3120 public void ResetImeMode() {
3121 ime_mode = DefaultImeMode;
3124 [EditorBrowsable(EditorBrowsableState.Never)]
3125 public virtual void ResetRightToLeft() {
3126 right_to_left = RightToLeft.Inherit;
3129 public virtual void ResetText() {
3130 text = String.Empty;
3133 public void ResumeLayout() {
3134 ResumeLayout (true);
3137 public void ResumeLayout(bool performLayout) {
3138 if (layout_suspended > 0) {
3142 if (layout_suspended == 0) {
3143 Control [] controls = child_controls.GetAllControls ();
3144 for (int i=0; i<controls.Length; i++) {
3145 controls [i].UpdateDistances ();
3148 if (performLayout && layout_pending) {
3154 public void Scale(float ratio) {
3155 ScaleCore(ratio, ratio);
3158 public void Scale(float dx, float dy) {
3163 public void Scale(SizeF factor) {
3164 ScaleCore(factor.Width, factor.Height);
3168 public void Select() {
3169 Select(false, false);
3172 public bool SelectNextControl(Control ctl, bool forward, bool tabStopOnly, bool nested, bool wrap) {
3177 c = GetNextControl(c, forward);
3186 if (c.CanSelect && ((c.parent == this) || nested) && (c.tab_stop || !tabStopOnly)) {
3187 c.Select (true, true);
3190 } while (c != ctl); // If we wrap back to ourselves we stop
3195 public void SendToBack() {
3196 if (parent != null) {
3197 parent.child_controls.SetChildIndex(this, parent.child_controls.Count);
3201 public void SetBounds(int x, int y, int width, int height) {
3202 SetBoundsCore(x, y, width, height, BoundsSpecified.All);
3205 public void SetBounds(int x, int y, int width, int height, BoundsSpecified specified) {
3206 SetBoundsCore(x, y, width, height, specified);
3209 public void Show() {
3211 this.CreateControl();
3217 public void SuspendLayout() {
3221 public void Update() {
3222 needs_redraw = true;
3223 if (IsHandleCreated) {
3224 XplatUI.UpdateWindow(window.Handle);
3227 #endregion // Public Instance Methods
3229 #region Protected Instance Methods
3230 [EditorBrowsable(EditorBrowsableState.Advanced)]
3231 [MonoTODO("Implement this and tie it into Control.ControlAccessibleObject.NotifyClients")]
3232 protected void AccessibilityNotifyClients(AccessibleEvents accEvent, int childID) {
3233 throw new NotImplementedException();
3236 [EditorBrowsable(EditorBrowsableState.Advanced)]
3237 protected virtual AccessibleObject CreateAccessibilityInstance() {
3238 return new Control.ControlAccessibleObject(this);
3241 [EditorBrowsable(EditorBrowsableState.Advanced)]
3242 protected virtual ControlCollection CreateControlsInstance() {
3243 return new ControlCollection(this);
3246 [EditorBrowsable(EditorBrowsableState.Advanced)]
3247 protected virtual void CreateHandle() {
3249 throw new ObjectDisposedException(Name);
3252 if (IsHandleCreated && !is_recreating) {
3256 window.CreateHandle(CreateParams);
3258 if (window.Handle != IntPtr.Zero) {
3259 if (!controls.Contains(window.Handle)) {
3263 creator_thread = Thread.CurrentThread;
3265 XplatUI.EnableWindow(window.Handle, is_enabled);
3267 if (clip_region != null) {
3268 XplatUI.SetClipRegion(Handle, clip_region);
3271 // Set our handle with our parent
3272 if ((parent != null) && (parent.IsHandleCreated)) {
3273 XplatUI.SetParent(window.Handle, parent.Handle);
3276 // Set our handle as parent for our children
3277 Control [] children;
3279 children = child_controls.GetAllControls ();
3280 for (int i = 0; i < children.Length; i++ ) {
3281 if (children[i].IsHandleCreated) {
3282 XplatUI.SetParent(children[i].Handle, window.Handle);
3287 XplatUI.SetAllowDrop (Handle, allow_drop);
3289 // Find out where the window manager placed us
3290 if ((CreateParams.Style & (int)WindowStyles.WS_CHILD) != 0) {
3291 XplatUI.SetBorderStyle(window.Handle, (FormBorderStyle)border_style);
3295 OnHandleCreated(EventArgs.Empty);
3300 [EditorBrowsable(EditorBrowsableState.Advanced)]
3301 protected virtual void DefWndProc(ref Message m) {
3302 window.DefWndProc(ref m);
3305 [EditorBrowsable(EditorBrowsableState.Advanced)]
3306 protected virtual void DestroyHandle() {
3307 if (IsHandleCreated) {
3308 if (window != null) {
3309 window.DestroyHandle();
3314 protected bool GetStyle(ControlStyles flag) {
3315 return (control_style & flag) != 0;
3318 protected bool GetTopLevel() {
3322 [EditorBrowsable(EditorBrowsableState.Advanced)]
3323 protected virtual void InitLayout() {
3327 [EditorBrowsable(EditorBrowsableState.Advanced)]
3328 protected void InvokeGotFocus(Control toInvoke, EventArgs e) {
3329 toInvoke.OnGotFocus(e);
3332 [EditorBrowsable(EditorBrowsableState.Advanced)]
3333 protected void InvokeLostFocus(Control toInvoke, EventArgs e) {
3334 toInvoke.OnLostFocus(e);
3337 [EditorBrowsable(EditorBrowsableState.Advanced)]
3338 protected void InvokeOnClick(Control toInvoke, EventArgs e) {
3339 toInvoke.OnClick(e);
3342 protected void InvokePaint(Control toInvoke, PaintEventArgs e) {
3343 toInvoke.OnPaint(e);
3346 protected void InvokePaintBackground(Control toInvoke, PaintEventArgs e) {
3347 toInvoke.OnPaintBackground(e);
3350 protected virtual bool IsInputChar (char charCode) {
3354 protected virtual bool IsInputKey (Keys keyData) {
3355 // Doc says this one calls IsInputChar; not sure what to do with that
3359 [EditorBrowsable(EditorBrowsableState.Advanced)]
3360 protected virtual void NotifyInvalidate(Rectangle invalidatedArea) {
3364 protected virtual bool ProcessCmdKey(ref Message msg, Keys keyData) {
3365 if ((context_menu != null) && context_menu.ProcessCmdKey(ref msg, keyData)) {
3369 if (parent != null) {
3370 return parent.ProcessCmdKey(ref msg, keyData);
3376 protected virtual bool ProcessDialogChar(char charCode) {
3377 if (parent != null) {
3378 return parent.ProcessDialogChar (charCode);
3384 protected virtual bool ProcessDialogKey (Keys keyData) {
3385 if (parent != null) {
3386 return parent.ProcessDialogKey (keyData);
3392 protected virtual bool ProcessKeyEventArgs (ref Message msg)
3394 KeyEventArgs key_event;
3397 case (int)Msg.WM_SYSKEYDOWN:
3398 case (int)Msg.WM_KEYDOWN: {
3399 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
3400 OnKeyDown (key_event);
3401 return key_event.Handled;
3404 case (int)Msg.WM_SYSKEYUP:
3405 case (int)Msg.WM_KEYUP: {
3406 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
3407 OnKeyUp (key_event);
3408 return key_event.Handled;
3411 case (int)Msg.WM_SYSCHAR:
3412 case (int)Msg.WM_CHAR: {
3413 KeyPressEventArgs key_press_event;
3415 key_press_event = new KeyPressEventArgs((char)msg.WParam);
3416 OnKeyPress(key_press_event);
3417 return key_press_event.Handled;
3428 protected internal virtual bool ProcessKeyMessage(ref Message msg) {
3429 if (parent != null) {
3430 if (parent.ProcessKeyPreview(ref msg)) {
3435 return ProcessKeyEventArgs(ref msg);
3438 protected virtual bool ProcessKeyPreview(ref Message msg) {
3439 if (parent != null) {
3440 return parent.ProcessKeyPreview(ref msg);
3446 protected virtual bool ProcessMnemonic(char charCode) {
3451 [EditorBrowsable(EditorBrowsableState.Advanced)]
3452 protected void RaiseDragEvent(object key, DragEventArgs e) {
3456 [EditorBrowsable(EditorBrowsableState.Advanced)]
3457 protected void RaiseKeyEvent(object key, KeyEventArgs e) {
3461 [EditorBrowsable(EditorBrowsableState.Advanced)]
3462 protected void RaiseMouseEvent(object key, MouseEventArgs e) {
3466 [EditorBrowsable(EditorBrowsableState.Advanced)]
3467 protected void RaisePaintEvent(object key, PaintEventArgs e) {
3471 [EditorBrowsable(EditorBrowsableState.Advanced)]
3472 protected void RecreateHandle() {
3475 if (IsHandleCreated) {
3477 // WM_DESTROY will CreateHandle for us
3486 is_recreating = false;
3489 [EditorBrowsable(EditorBrowsableState.Advanced)]
3490 protected void ResetMouseEventArgs() {
3494 [EditorBrowsable(EditorBrowsableState.Advanced)]
3495 protected ContentAlignment RtlTranslateAlignment(ContentAlignment align) {
3496 if (right_to_left == RightToLeft.No) {
3501 case ContentAlignment.TopLeft: {
3502 return ContentAlignment.TopRight;
3505 case ContentAlignment.TopRight: {
3506 return ContentAlignment.TopLeft;
3509 case ContentAlignment.MiddleLeft: {
3510 return ContentAlignment.MiddleRight;
3513 case ContentAlignment.MiddleRight: {
3514 return ContentAlignment.MiddleLeft;
3517 case ContentAlignment.BottomLeft: {
3518 return ContentAlignment.BottomRight;
3521 case ContentAlignment.BottomRight: {
3522 return ContentAlignment.BottomLeft;
3526 // if it's center it doesn't change
3532 [EditorBrowsable(EditorBrowsableState.Advanced)]
3533 protected HorizontalAlignment RtlTranslateAlignment(HorizontalAlignment align) {
3534 if ((right_to_left == RightToLeft.No) || (align == HorizontalAlignment.Center)) {
3538 if (align == HorizontalAlignment.Left) {
3539 return HorizontalAlignment.Right;
3542 // align must be HorizontalAlignment.Right
3543 return HorizontalAlignment.Left;
3546 [EditorBrowsable(EditorBrowsableState.Advanced)]
3547 protected LeftRightAlignment RtlTranslateAlignment(LeftRightAlignment align) {
3548 if (right_to_left == RightToLeft.No) {
3552 if (align == LeftRightAlignment.Left) {
3553 return LeftRightAlignment.Right;
3556 // align must be LeftRightAlignment.Right;
3557 return LeftRightAlignment.Left;
3560 [EditorBrowsable(EditorBrowsableState.Advanced)]
3561 protected ContentAlignment RtlTranslateContent(ContentAlignment align) {
3562 return RtlTranslateAlignment(align);
3565 [EditorBrowsable(EditorBrowsableState.Advanced)]
3566 protected HorizontalAlignment RtlTranslateHorizontal(HorizontalAlignment align) {
3567 return RtlTranslateAlignment(align);
3570 [EditorBrowsable(EditorBrowsableState.Advanced)]
3571 protected LeftRightAlignment RtlTranslateLeftRight(LeftRightAlignment align) {
3572 return RtlTranslateAlignment(align);
3575 [EditorBrowsable(EditorBrowsableState.Advanced)]
3576 protected virtual void ScaleCore(float dx, float dy) {
3582 location = new Point((int)(Left * dx), (int)(Top * dy));
3583 size = this.ClientSize;
3585 if (!GetStyle(ControlStyles.FixedWidth)) {
3586 size.Width = (int)(size.Width * dx);
3589 if (!GetStyle(ControlStyles.FixedHeight)) {
3590 size.Height = (int)(size.Height * dy);
3593 SetBoundsCore(location.X, location.Y, size.Width, size.Height, BoundsSpecified.All);
3595 /* Now scale our children */
3596 Control [] controls = child_controls.GetAllControls ();
3597 for (int i=0; i < controls.Length; i++) {
3598 controls[i].Scale(dx, dy);
3604 protected virtual void Select(bool directed, bool forward) {
3605 IContainerControl container;
3607 container = GetContainerControl();
3608 if (container != null) {
3609 container.ActiveControl = this;
3612 if (IsHandleCreated) {
3613 XplatUI.SetFocus(window.Handle);
3617 [EditorBrowsable(EditorBrowsableState.Advanced)]
3618 protected virtual void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
3619 // SetBoundsCore updates the Win32 control itself. UpdateBounds updates the controls variables and fires events, I'm guessing - pdb
3620 if ((specified & BoundsSpecified.X) != BoundsSpecified.X) {
3624 if ((specified & BoundsSpecified.Y) != BoundsSpecified.Y) {
3628 if ((specified & BoundsSpecified.Width) != BoundsSpecified.Width) {
3632 if ((specified & BoundsSpecified.Height) != BoundsSpecified.Height) {
3636 if (IsHandleCreated) {
3637 XplatUI.SetWindowPos(Handle, x, y, width, height);
3640 UpdateBounds(x, y, width, height);
3645 [EditorBrowsable(EditorBrowsableState.Advanced)]
3646 protected virtual void SetClientSizeCore(int x, int y) {
3647 // Calculate the actual window size from the client size (it usually stays the same or grows)
3648 Rectangle ClientRect;
3649 Rectangle WindowRect;
3652 ClientRect = new Rectangle(0, 0, x, y);
3653 cp = this.CreateParams;
3655 if (XplatUI.CalculateWindowRect(ref ClientRect, cp.Style, cp.ExStyle, null, out WindowRect)==false) {
3659 SetBoundsCore(bounds.X, bounds.Y, WindowRect.Width, WindowRect.Height, BoundsSpecified.Size);
3662 [EditorBrowsable(EditorBrowsableState.Advanced)]
3663 protected void SetStyle(ControlStyles flag, bool value) {
3665 control_style |= flag;
3667 control_style &= ~flag;
3671 protected void SetTopLevel(bool value) {
3672 if ((GetTopLevel() != value) && (parent != null)) {
3673 throw new Exception();
3677 if (value == true) {
3687 is_toplevel = value;
3690 protected virtual void SetVisibleCore(bool value) {
3691 if (value!=is_visible) {
3692 if (value && !is_created) {
3698 if (IsHandleCreated) {
3699 XplatUI.SetVisible(Handle, value);
3700 // Explicitly move Toplevel windows to where we want them;
3701 // apparently moving unmapped toplevel windows doesn't work
3702 if (is_visible && (this is Form)) {
3703 XplatUI.SetWindowPos(window.Handle, bounds.X, bounds.Y, bounds.Width, bounds.Height);
3707 OnVisibleChanged(EventArgs.Empty);
3709 if (value == false && parent != null && Focused) {
3712 // Need to start at parent, GetContainerControl might return ourselves if we're a container
3713 container = (Control)parent.GetContainerControl();
3714 if (container != null) {
3715 container.SelectNextControl(this, true, true, true, true);
3719 if (parent != null) {
3720 parent.PerformLayout(this, "visible");
3722 PerformLayout(this, "visible");
3727 [EditorBrowsable(EditorBrowsableState.Advanced)]
3728 protected void UpdateBounds() {
3736 if (!IsHandleCreated) {
3740 XplatUI.GetWindowPos(this.Handle, this is Form, out x, out y, out width, out height, out client_width, out client_height);
3742 UpdateBounds(x, y, width, height, client_width, client_height);
3745 [EditorBrowsable(EditorBrowsableState.Advanced)]
3746 protected void UpdateBounds(int x, int y, int width, int height) {
3750 // Calculate client rectangle
3751 rect = new Rectangle(0, 0, 0, 0);
3754 XplatUI.CalculateWindowRect(ref rect, cp.Style, cp.ExStyle, cp.menu, out rect);
3755 UpdateBounds(x, y, width, height, width - (rect.Right - rect.Left), height - (rect.Bottom - rect.Top));
3758 [EditorBrowsable(EditorBrowsableState.Advanced)]
3759 protected void UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) {
3760 // UpdateBounds only seems to set our sizes and fire events but not update the GUI window to match
3762 bool resized = false;
3764 // Needed to generate required notifications
3765 if ((this.bounds.X!=x) || (this.bounds.Y!=y)) {
3769 if ((this.Bounds.Width!=width) || (this.Bounds.Height!=height)) {
3776 bounds.Height=height;
3778 client_size.Width=clientWidth;
3779 client_size.Height=clientHeight;
3782 OnLocationChanged(EventArgs.Empty);
3786 OnSizeChanged(EventArgs.Empty);
3790 [EditorBrowsable(EditorBrowsableState.Advanced)]
3791 protected void UpdateStyles() {
3792 if (!IsHandleCreated) {
3796 XplatUI.SetWindowStyle(window.Handle, CreateParams);
3797 OnStyleChanged(EventArgs.Empty);
3800 private void UpdateZOrderOfChild(Control child) {
3801 if (IsHandleCreated && child.IsHandleCreated && (child.parent == this)) {
3804 index = child_controls.IndexOf(child);
3807 XplatUI.SetZOrder(child.Handle, child_controls[index - 1].Handle, false, false);
3809 XplatUI.SetZOrder(child.Handle, IntPtr.Zero, true, false);
3814 private void UpdateChildrenZOrder() {
3815 Control [] controls;
3817 if (!IsHandleCreated) {
3821 controls = child_controls.GetAllControls ();
3822 for (int i = 1; i < controls.Length; i++ ) {
3823 XplatUI.SetZOrder(controls[i].Handle, controls[i-1].Handle, false, false);
3827 [EditorBrowsable(EditorBrowsableState.Advanced)]
3828 protected void UpdateZOrder() {
3829 if (parent != null) {
3830 parent.UpdateZOrderOfChild(this);
3834 protected virtual void WndProc(ref Message m) {
3836 Console.WriteLine("Control {0} received message {1}", window.Handle == IntPtr.Zero ? this.Text : XplatUI.Window(window.Handle), (Msg)m.Msg);
3838 if ((this.control_style & ControlStyles.EnableNotifyMessage) != 0) {
3842 switch((Msg)m.Msg) {
3843 case Msg.WM_DESTROY: {
3844 OnHandleDestroyed(EventArgs.Empty);
3845 window.InvalidateHandle();
3847 if (ParentIsRecreating) {
3849 } else if (is_recreating) {
3855 case Msg.WM_WINDOWPOSCHANGED: {
3858 if (GetStyle(ControlStyles.ResizeRedraw)) {
3865 // Nice description of what should happen when handling WM_PAINT
3866 // can be found here: http://pluralsight.com/wiki/default.aspx/Craig/FlickerFreeControlDrawing.html
3867 // and here http://msdn.microsoft.com/msdnmag/issues/06/03/WindowsFormsPerformance/
3868 case Msg.WM_PAINT: {
3869 PaintEventArgs paint_event;
3872 paint_event = XplatUI.PaintEventStart(Handle, true);
3873 reset_context = false;
3875 if (paint_event == null) {
3879 if (!needs_redraw) {
3880 // Just blit the previous image
3881 paint_event.Graphics.DrawImage (ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle, GraphicsUnit.Pixel);
3882 XplatUI.PaintEventEnd(Handle, true);
3887 if (ThemeEngine.Current.DoubleBufferingSupported) {
3888 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
3889 dc = paint_event.SetGraphics (DeviceContext);
3890 reset_context = true;
3894 if (!GetStyle(ControlStyles.Opaque)) {
3895 OnPaintBackground(paint_event);
3898 // Button-derived controls choose to ignore their Opaque style, give them a chance to draw their background anyways
3899 OnPaintBackgroundInternal(paint_event);
3901 OnPaintInternal(paint_event);
3902 if (!paint_event.Handled) {
3903 OnPaint(paint_event);
3906 if (ThemeEngine.Current.DoubleBufferingSupported)
3907 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
3908 dc.DrawImage (ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle, GraphicsUnit.Pixel);
3909 paint_event.SetGraphics (dc);
3910 needs_redraw = false;
3913 XplatUI.PaintEventEnd(Handle, true);
3915 if (reset_context) {
3916 ResetDeviceContext();
3922 case Msg.WM_ERASEBKGND: {
3923 // The DefWndProc will never have to handle this, we always paint the background in managed code
3924 // In theory this code would look at ControlStyles.AllPaintingInWmPaint and and call OnPaintBackground
3925 // here but it just makes things more complicated...
3926 m.Result = (IntPtr)1;
3930 case Msg.WM_LBUTTONUP: {
3933 me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Left,
3935 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3938 HandleClick(mouse_clicks, me);
3941 if (InternalCapture) {
3942 InternalCapture = false;
3945 if (mouse_clicks > 1) {
3951 case Msg.WM_LBUTTONDOWN: {
3953 Select (true, true);
3955 InternalCapture = true;
3956 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3957 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3963 case Msg.WM_LBUTTONDBLCLK: {
3964 InternalCapture = true;
3966 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3967 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3973 case Msg.WM_MBUTTONUP: {
3976 me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Middle,
3978 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3981 HandleClick(mouse_clicks, me);
3983 if (InternalCapture) {
3984 InternalCapture = false;
3986 if (mouse_clicks > 1) {
3992 case Msg.WM_MBUTTONDOWN: {
3993 InternalCapture = true;
3994 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3995 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4001 case Msg.WM_MBUTTONDBLCLK: {
4002 InternalCapture = true;
4004 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4005 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4010 case Msg.WM_RBUTTONUP: {
4014 pt = new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()));
4015 pt = PointToScreen(pt);
4017 XplatUI.SendMessage(m.HWnd, Msg.WM_CONTEXTMENU, m.HWnd, (IntPtr)(pt.X + (pt.Y << 16)));
4019 me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Right,
4021 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4024 HandleClick(mouse_clicks, me);
4027 if (InternalCapture) {
4028 InternalCapture = false;
4031 if (mouse_clicks > 1) {
4037 case Msg.WM_RBUTTONDOWN: {
4038 InternalCapture = true;
4039 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4040 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4045 case Msg.WM_RBUTTONDBLCLK: {
4046 InternalCapture = true;
4048 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4049 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4054 case Msg.WM_CONTEXTMENU: {
4055 if (context_menu != null) {
4058 pt = new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()));
4059 context_menu.Show(this, PointToClient(pt));
4067 case Msg.WM_MOUSEWHEEL: {
4069 OnMouseWheel (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4070 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4071 HighOrder(m.WParam.ToInt32())));
4076 case Msg.WM_MOUSEMOVE: {
4077 OnMouseMove (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4079 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4084 case Msg.WM_MOUSE_ENTER: {
4089 OnMouseEnter(EventArgs.Empty);
4093 case Msg.WM_MOUSE_LEAVE: {
4095 OnMouseLeave(EventArgs.Empty);
4099 case Msg.WM_MOUSEHOVER: {
4100 OnMouseHover(EventArgs.Empty);
4104 case Msg.WM_SYSKEYUP: {
4105 if (ProcessKeyMessage(ref m)) {
4106 m.Result = IntPtr.Zero;
4110 if ((m.WParam.ToInt32() & (int)Keys.KeyCode) == (int)Keys.Menu) {
4114 if (form != null && form.ActiveMenu != null) {
4115 form.ActiveMenu.ProcessCmdKey(ref m, (Keys)m.WParam.ToInt32());
4123 case Msg.WM_SYSKEYDOWN:
4124 case Msg.WM_KEYDOWN:
4126 case Msg.WM_SYSCHAR:
4128 if (ProcessKeyMessage(ref m)) {
4129 m.Result = IntPtr.Zero;
4138 if (m.LParam != IntPtr.Zero) {
4141 hi = new HELPINFO();
4143 hi = (HELPINFO) Marshal.PtrToStructure (m.LParam, typeof (HELPINFO));
4144 mouse_pos = new Point(hi.MousePos.x, hi.MousePos.y);
4146 mouse_pos = Control.MousePosition;
4148 OnHelpRequested(new HelpEventArgs(mouse_pos));
4149 m.Result = (IntPtr)1;
4153 case Msg.WM_KILLFOCUS: {
4154 if (CausesValidation) {
4156 e = new CancelEventArgs(false);
4165 OnValidated(EventArgs.Empty);
4168 this.has_focus = false;
4169 OnLostFocusInternal (EventArgs.Empty);
4173 case Msg.WM_SETFOCUS: {
4175 this.has_focus = true;
4176 OnGotFocusInternal (EventArgs.Empty);
4182 case Msg.WM_SYSCOLORCHANGE: {
4183 ThemeEngine.Current.ResetDefaults();
4184 OnSystemColorsChanged(EventArgs.Empty);
4189 case Msg.WM_SETCURSOR: {
4190 if ((cursor == null) || ((HitTest)(m.LParam.ToInt32() & 0xffff) != HitTest.HTCLIENT)) {
4195 XplatUI.SetCursor(window.Handle, cursor.handle);
4196 m.Result = (IntPtr)1;
4207 #endregion // Public Instance Methods
4209 #region OnXXX methods
4210 [EditorBrowsable(EditorBrowsableState.Advanced)]
4211 protected virtual void OnBackColorChanged(EventArgs e) {
4212 if (BackColorChanged!=null) BackColorChanged(this, e);
4213 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackColorChanged(e);
4216 [EditorBrowsable(EditorBrowsableState.Advanced)]
4217 protected virtual void OnBackgroundImageChanged(EventArgs e) {
4218 if (BackgroundImageChanged!=null) BackgroundImageChanged(this, e);
4219 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackgroundImageChanged(e);
4222 [EditorBrowsable(EditorBrowsableState.Advanced)]
4223 protected virtual void OnBindingContextChanged(EventArgs e) {
4224 CheckDataBindings ();
4225 if (BindingContextChanged!=null) {
4226 BindingContextChanged(this, e);
4228 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBindingContextChanged(e);
4231 [EditorBrowsable(EditorBrowsableState.Advanced)]
4232 protected virtual void OnCausesValidationChanged(EventArgs e) {
4233 if (CausesValidationChanged!=null) CausesValidationChanged(this, e);
4236 [EditorBrowsable(EditorBrowsableState.Advanced)]
4237 protected virtual void OnChangeUICues(UICuesEventArgs e) {
4238 if (ChangeUICues!=null) ChangeUICues(this, e);
4241 [EditorBrowsable(EditorBrowsableState.Advanced)]
4242 protected virtual void OnClick(EventArgs e) {
4243 if (Click!=null) Click(this, e);
4246 [EditorBrowsable(EditorBrowsableState.Advanced)]
4247 protected virtual void OnContextMenuChanged(EventArgs e) {
4248 if (ContextMenuChanged!=null) ContextMenuChanged(this, e);
4251 [EditorBrowsable(EditorBrowsableState.Advanced)]
4252 protected virtual void OnControlAdded(ControlEventArgs e) {
4253 if (ControlAdded!=null) ControlAdded(this, e);
4256 [EditorBrowsable(EditorBrowsableState.Advanced)]
4257 protected virtual void OnControlRemoved(ControlEventArgs e) {
4258 if (ControlRemoved!=null) ControlRemoved(this, e);
4261 [EditorBrowsable(EditorBrowsableState.Advanced)]
4262 protected virtual void OnCreateControl() {
4266 [EditorBrowsable(EditorBrowsableState.Advanced)]
4267 protected virtual void OnCursorChanged(EventArgs e) {
4268 if (CursorChanged!=null) CursorChanged(this, e);
4271 [EditorBrowsable(EditorBrowsableState.Advanced)]
4272 protected virtual void OnDockChanged(EventArgs e) {
4273 if (DockChanged!=null) DockChanged(this, e);
4276 [EditorBrowsable(EditorBrowsableState.Advanced)]
4277 protected virtual void OnDoubleClick(EventArgs e) {
4278 if (DoubleClick!=null) DoubleClick(this, e);
4281 [EditorBrowsable(EditorBrowsableState.Advanced)]
4282 protected virtual void OnDragDrop(DragEventArgs drgevent) {
4283 if (DragDrop!=null) DragDrop(this, drgevent);
4286 [EditorBrowsable(EditorBrowsableState.Advanced)]
4287 protected virtual void OnDragEnter(DragEventArgs drgevent) {
4288 if (DragEnter!=null) DragEnter(this, drgevent);
4291 [EditorBrowsable(EditorBrowsableState.Advanced)]
4292 protected virtual void OnDragLeave(EventArgs e) {
4293 if (DragLeave!=null) DragLeave(this, e);
4296 [EditorBrowsable(EditorBrowsableState.Advanced)]
4297 protected virtual void OnDragOver(DragEventArgs drgevent) {
4298 if (DragOver!=null) DragOver(this, drgevent);
4301 [EditorBrowsable(EditorBrowsableState.Advanced)]
4302 protected virtual void OnEnabledChanged(EventArgs e) {
4303 if (IsHandleCreated) {
4305 if (((Form)this).context == null) {
4306 XplatUI.EnableWindow(window.Handle, Enabled);
4309 XplatUI.EnableWindow(window.Handle, Enabled);
4314 if (EnabledChanged != null) {
4315 EnabledChanged(this, e);
4318 for (int i=0; i<child_controls.Count; i++) {
4319 child_controls[i].OnParentEnabledChanged(e);
4323 [EditorBrowsable(EditorBrowsableState.Advanced)]
4324 protected virtual void OnEnter(EventArgs e) {
4325 if (Enter!=null) Enter(this, e);
4328 [EditorBrowsable(EditorBrowsableState.Advanced)]
4329 protected virtual void OnFontChanged(EventArgs e) {
4330 if (FontChanged!=null) FontChanged(this, e);
4331 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentFontChanged(e);
4334 [EditorBrowsable(EditorBrowsableState.Advanced)]
4335 protected virtual void OnForeColorChanged(EventArgs e) {
4336 if (ForeColorChanged!=null) ForeColorChanged(this, e);
4337 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentForeColorChanged(e);
4340 [EditorBrowsable(EditorBrowsableState.Advanced)]
4341 protected virtual void OnGiveFeedback(GiveFeedbackEventArgs gfbevent) {
4342 if (GiveFeedback!=null) GiveFeedback(this, gfbevent);
4345 [EditorBrowsable(EditorBrowsableState.Advanced)]
4346 protected virtual void OnGotFocus(EventArgs e) {
4347 if (GotFocus!=null) GotFocus(this, e);
4350 [EditorBrowsable(EditorBrowsableState.Advanced)]
4351 protected virtual void OnHandleCreated(EventArgs e) {
4352 if (HandleCreated!=null) HandleCreated(this, e);
4355 [EditorBrowsable(EditorBrowsableState.Advanced)]
4356 protected virtual void OnHandleDestroyed(EventArgs e) {
4357 if (HandleDestroyed!=null) HandleDestroyed(this, e);
4360 [EditorBrowsable(EditorBrowsableState.Advanced)]
4361 protected virtual void OnHelpRequested(HelpEventArgs hevent) {
4362 if (HelpRequested!=null) HelpRequested(this, hevent);
4365 protected virtual void OnImeModeChanged(EventArgs e) {
4366 if (ImeModeChanged!=null) ImeModeChanged(this, e);
4369 [EditorBrowsable(EditorBrowsableState.Advanced)]
4370 protected virtual void OnInvalidated(InvalidateEventArgs e) {
4371 needs_redraw = true;
4372 if (Invalidated!=null) Invalidated(this, e);
4375 [EditorBrowsable(EditorBrowsableState.Advanced)]
4376 protected virtual void OnKeyDown(KeyEventArgs e) {
4377 if (KeyDown!=null) KeyDown(this, e);
4380 [EditorBrowsable(EditorBrowsableState.Advanced)]
4381 protected virtual void OnKeyPress(KeyPressEventArgs e) {
4382 if (KeyPress!=null) KeyPress(this, e);
4385 [EditorBrowsable(EditorBrowsableState.Advanced)]
4386 protected virtual void OnKeyUp(KeyEventArgs e) {
4387 if (KeyUp!=null) KeyUp(this, e);
4390 [EditorBrowsable(EditorBrowsableState.Advanced)]
4391 protected virtual void OnLayout(LayoutEventArgs levent) {
4392 if (Layout!=null) Layout(this, levent);
4395 [EditorBrowsable(EditorBrowsableState.Advanced)]
4396 protected virtual void OnLeave(EventArgs e) {
4397 if (Leave!=null) Leave(this, e);
4400 [EditorBrowsable(EditorBrowsableState.Advanced)]
4401 protected virtual void OnLocationChanged(EventArgs e) {
4403 if (LocationChanged!=null) LocationChanged(this, e);
4406 [EditorBrowsable(EditorBrowsableState.Advanced)]
4407 protected virtual void OnLostFocus(EventArgs e) {
4408 if (LostFocus!=null) LostFocus(this, e);
4411 [EditorBrowsable(EditorBrowsableState.Advanced)]
4412 protected virtual void OnMouseDown(MouseEventArgs e) {
4413 if (MouseDown!=null) MouseDown(this, e);
4416 [EditorBrowsable(EditorBrowsableState.Advanced)]
4417 protected virtual void OnMouseEnter(EventArgs e) {
4418 if (MouseEnter!=null) MouseEnter(this, e);
4421 [EditorBrowsable(EditorBrowsableState.Advanced)]
4422 protected virtual void OnMouseHover(EventArgs e) {
4423 if (MouseHover!=null) MouseHover(this, e);
4426 [EditorBrowsable(EditorBrowsableState.Advanced)]
4427 protected virtual void OnMouseLeave(EventArgs e) {
4428 if (MouseLeave!=null) MouseLeave(this, e);
4431 [EditorBrowsable(EditorBrowsableState.Advanced)]
4432 protected virtual void OnMouseMove(MouseEventArgs e) {
4433 if (MouseMove!=null) MouseMove(this, e);
4436 [EditorBrowsable(EditorBrowsableState.Advanced)]
4437 protected virtual void OnMouseUp(MouseEventArgs e) {
4438 if (MouseUp!=null) MouseUp(this, e);
4441 [EditorBrowsable(EditorBrowsableState.Advanced)]
4442 protected virtual void OnMouseWheel(MouseEventArgs e) {
4443 if (MouseWheel!=null) MouseWheel(this, e);
4446 [EditorBrowsable(EditorBrowsableState.Advanced)]
4447 protected virtual void OnMove(EventArgs e) {
4448 if (Move!=null) Move(this, e);
4451 [EditorBrowsable(EditorBrowsableState.Advanced)]
4452 protected virtual void OnNotifyMessage(Message m) {
4456 [EditorBrowsable(EditorBrowsableState.Advanced)]
4457 protected virtual void OnPaint(PaintEventArgs e) {
4458 if (Paint!=null) Paint(this, e);
4461 internal virtual void OnPaintBackgroundInternal(PaintEventArgs e) {
4465 internal virtual void OnPaintInternal(PaintEventArgs e) {
4469 internal virtual void OnGotFocusInternal (EventArgs e)
4474 internal virtual void OnLostFocusInternal (EventArgs e)
4479 [EditorBrowsable(EditorBrowsableState.Advanced)]
4480 protected virtual void OnPaintBackground(PaintEventArgs pevent) {
4481 PaintControlBackground (pevent);
4484 [EditorBrowsable(EditorBrowsableState.Advanced)]
4485 protected virtual void OnParentBackColorChanged(EventArgs e) {
4486 if (background_color.IsEmpty && background_image==null) {
4488 OnBackColorChanged(e);
4492 [EditorBrowsable(EditorBrowsableState.Advanced)]
4493 protected virtual void OnParentBackgroundImageChanged(EventArgs e) {
4494 if (background_color.IsEmpty && background_image==null) {
4496 OnBackgroundImageChanged(e);
4500 [EditorBrowsable(EditorBrowsableState.Advanced)]
4501 protected virtual void OnParentBindingContextChanged(EventArgs e) {
4502 if (binding_context==null) {
4503 binding_context=Parent.binding_context;
4504 OnBindingContextChanged(e);
4508 [EditorBrowsable(EditorBrowsableState.Advanced)]
4509 protected virtual void OnParentChanged(EventArgs e) {
4510 if (ParentChanged!=null) ParentChanged(this, e);
4513 [EditorBrowsable(EditorBrowsableState.Advanced)]
4514 protected virtual void OnParentEnabledChanged(EventArgs e) {
4516 OnEnabledChanged(e);
4520 [EditorBrowsable(EditorBrowsableState.Advanced)]
4521 protected virtual void OnParentFontChanged(EventArgs e) {
4528 [EditorBrowsable(EditorBrowsableState.Advanced)]
4529 protected virtual void OnParentForeColorChanged(EventArgs e) {
4530 if (foreground_color.IsEmpty) {
4532 OnForeColorChanged(e);
4536 [EditorBrowsable(EditorBrowsableState.Advanced)]
4537 protected virtual void OnParentRightToLeftChanged(EventArgs e) {
4538 if (right_to_left==RightToLeft.Inherit) {
4540 OnRightToLeftChanged(e);
4544 [EditorBrowsable(EditorBrowsableState.Advanced)]
4545 protected virtual void OnParentVisibleChanged(EventArgs e) {
4547 OnVisibleChanged(e);
4551 [EditorBrowsable(EditorBrowsableState.Advanced)]
4552 protected virtual void OnQueryContinueDrag(QueryContinueDragEventArgs e) {
4553 if (QueryContinueDrag!=null) QueryContinueDrag(this, e);
4556 [EditorBrowsable(EditorBrowsableState.Advanced)]
4557 protected virtual void OnResize(EventArgs e) {
4558 if (Resize!=null) Resize(this, e);
4560 PerformLayout(this, "bounds");
4562 if (parent != null) {
4563 parent.PerformLayout();
4567 [EditorBrowsable(EditorBrowsableState.Advanced)]
4568 protected virtual void OnRightToLeftChanged(EventArgs e) {
4569 if (RightToLeftChanged!=null) RightToLeftChanged(this, e);
4570 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentRightToLeftChanged(e);
4573 [EditorBrowsable(EditorBrowsableState.Advanced)]
4574 protected virtual void OnSizeChanged(EventArgs e) {
4575 InvalidateBuffers ();
4577 if (SizeChanged!=null) SizeChanged(this, e);
4580 [EditorBrowsable(EditorBrowsableState.Advanced)]
4581 protected virtual void OnStyleChanged(EventArgs e) {
4582 if (StyleChanged!=null) StyleChanged(this, e);
4585 [EditorBrowsable(EditorBrowsableState.Advanced)]
4586 protected virtual void OnSystemColorsChanged(EventArgs e) {
4587 if (SystemColorsChanged!=null) SystemColorsChanged(this, e);
4590 [EditorBrowsable(EditorBrowsableState.Advanced)]
4591 protected virtual void OnTabIndexChanged(EventArgs e) {
4592 if (TabIndexChanged!=null) TabIndexChanged(this, e);
4595 [EditorBrowsable(EditorBrowsableState.Advanced)]
4596 protected virtual void OnTabStopChanged(EventArgs e) {
4597 if (TabStopChanged!=null) TabStopChanged(this, e);
4600 [EditorBrowsable(EditorBrowsableState.Advanced)]
4601 protected virtual void OnTextChanged(EventArgs e) {
4602 if (TextChanged!=null) TextChanged(this, e);
4605 [EditorBrowsable(EditorBrowsableState.Advanced)]
4606 protected virtual void OnValidated(EventArgs e) {
4607 if (Validated!=null) Validated(this, e);
4610 [EditorBrowsable(EditorBrowsableState.Advanced)]
4611 protected virtual void OnValidating(System.ComponentModel.CancelEventArgs e) {
4612 if (Validating!=null) Validating(this, e);
4615 [EditorBrowsable(EditorBrowsableState.Advanced)]
4616 protected virtual void OnVisibleChanged(EventArgs e) {
4617 if ((parent != null) && !Created && Visible) {
4624 needs_redraw = true;
4626 if (VisibleChanged!=null) VisibleChanged(this, e);
4628 // We need to tell our kids
4629 for (int i=0; i<child_controls.Count; i++) {
4630 if (child_controls[i].Visible) {
4631 child_controls[i].OnParentVisibleChanged(e);
4635 #endregion // OnXXX methods
4638 public event EventHandler BackColorChanged;
4639 public event EventHandler BackgroundImageChanged;
4640 public event EventHandler BindingContextChanged;
4641 public event EventHandler CausesValidationChanged;
4642 public event UICuesEventHandler ChangeUICues;
4643 public event EventHandler Click;
4644 public event EventHandler ContextMenuChanged;
4646 [EditorBrowsable(EditorBrowsableState.Advanced)]
4648 public event ControlEventHandler ControlAdded;
4650 [EditorBrowsable(EditorBrowsableState.Advanced)]
4652 public event ControlEventHandler ControlRemoved;
4654 [MWFDescription("Fired when the cursor for the control has been changed"), MWFCategory("PropertyChanged")]
4655 public event EventHandler CursorChanged;
4656 public event EventHandler DockChanged;
4657 public event EventHandler DoubleClick;
4658 public event DragEventHandler DragDrop;
4659 public event DragEventHandler DragEnter;
4660 public event EventHandler DragLeave;
4661 public event DragEventHandler DragOver;
4662 public event EventHandler EnabledChanged;
4663 public event EventHandler Enter;
4664 public event EventHandler FontChanged;
4665 public event EventHandler ForeColorChanged;
4666 public event GiveFeedbackEventHandler GiveFeedback;
4668 [EditorBrowsable(EditorBrowsableState.Advanced)]
4670 public event EventHandler GotFocus;
4672 [EditorBrowsable(EditorBrowsableState.Advanced)]
4674 public event EventHandler HandleCreated;
4676 [EditorBrowsable(EditorBrowsableState.Advanced)]
4678 public event EventHandler HandleDestroyed;
4680 public event HelpEventHandler HelpRequested;
4681 public event EventHandler ImeModeChanged;
4683 [EditorBrowsable(EditorBrowsableState.Advanced)]
4685 public event InvalidateEventHandler Invalidated;
4687 public event KeyEventHandler KeyDown;
4688 public event KeyPressEventHandler KeyPress;
4689 public event KeyEventHandler KeyUp;
4690 public event LayoutEventHandler Layout;
4691 public event EventHandler Leave;
4692 public event EventHandler LocationChanged;
4694 [EditorBrowsable(EditorBrowsableState.Advanced)]
4696 public event EventHandler LostFocus;
4698 public event MouseEventHandler MouseDown;
4699 public event EventHandler MouseEnter;
4700 public event EventHandler MouseHover;
4701 public event EventHandler MouseLeave;
4702 public event MouseEventHandler MouseMove;
4703 public event MouseEventHandler MouseUp;
4705 [EditorBrowsable(EditorBrowsableState.Advanced)]
4707 public event MouseEventHandler MouseWheel;
4709 public event EventHandler Move;
4710 public event PaintEventHandler Paint;
4711 public event EventHandler ParentChanged;
4712 public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp;
4713 public event QueryContinueDragEventHandler QueryContinueDrag;
4714 public event EventHandler Resize;
4715 public event EventHandler RightToLeftChanged;
4716 public event EventHandler SizeChanged;
4717 public event EventHandler StyleChanged;
4718 public event EventHandler SystemColorsChanged;
4719 public event EventHandler TabIndexChanged;
4720 public event EventHandler TabStopChanged;
4721 public event EventHandler TextChanged;
4722 public event EventHandler Validated;
4723 public event CancelEventHandler Validating;
4724 public event EventHandler VisibleChanged;
4725 #endregion // Events