* ListView.cs: the BackgroundImage override is just to set
[mcs.git] / class / Managed.Windows.Forms / System.Windows.Forms / Control.cs
blob8bd452e88d49c445a9b297fda6bf57157c74d658
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:
8 //
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
11 //
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.
22 // Authors:
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
33 // COMPLETE
35 #undef DebugRecreate
36 #undef DebugFocus
38 using System;
39 using System.ComponentModel;
40 using System.ComponentModel.Design;
41 using System.ComponentModel.Design.Serialization;
42 using System.Collections;
43 using System.Diagnostics;
44 using System.Drawing;
45 using System.Drawing.Drawing2D;
46 using System.Reflection;
47 using System.Runtime.InteropServices;
48 using System.Security;
49 using System.Threading;
51 namespace System.Windows.Forms
53 [Designer("System.Windows.Forms.Design.ControlDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
54 [DefaultProperty("Text")]
55 [DefaultEvent("Click")]
56 [DesignerSerializer("System.Windows.Forms.Design.ControlCodeDomSerializer, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
57 [ToolboxItemFilter("System.Windows.Forms")]
58 public class Control : Component, ISynchronizeInvoke, IWin32Window
60 #region Local Variables
62 // Basic
63 internal Rectangle bounds; // bounding rectangle for control (client area + decorations)
64 Rectangle explicit_bounds; // explicitly set bounds
65 internal object creator_thread; // thread that created the control
66 internal ControlNativeWindow window; // object for native window handle
67 string name; // for object naming
69 // State
70 bool is_created; // true if OnCreateControl has been sent
71 internal bool has_focus; // true if control has focus
72 internal bool is_visible; // true if control is visible
73 internal bool is_entered; // is the mouse inside the control?
74 internal bool is_enabled; // true if control is enabled (usable/not grayed out)
75 bool is_accessible; // true if the control is visible to accessibility applications
76 bool is_captured; // tracks if the control has captured the mouse
77 internal bool is_toplevel; // tracks if the control is a toplevel window
78 bool is_recreating; // tracks if the handle for the control is being recreated
79 bool causes_validation; // tracks if validation is executed on changes
80 bool is_focusing; // tracks if Focus has been called on the control and has not yet finished
81 int tab_index; // position in tab order of siblings
82 bool tab_stop; // is the control a tab stop?
83 bool is_disposed; // has the window already been disposed?
84 Size client_size; // size of the client area (window excluding decorations)
85 Rectangle client_rect; // rectangle with the client area (window excluding decorations)
86 ControlStyles control_style; // rather win32-specific, style bits for control
87 ImeMode ime_mode;
88 bool layout_pending; // true if our parent needs to re-layout us
89 object control_tag; // object that contains data about our control
90 internal int mouse_clicks; // Counter for mouse clicks
91 Cursor cursor; // Cursor for the window
92 internal bool allow_drop; // true if the control accepts droping objects on it
93 Region clip_region; // User-specified clip region for the window
95 // Visuals
96 internal Color foreground_color; // foreground color for control
97 internal Color background_color; // background color for control
98 Image background_image; // background image for control
99 internal Font font; // font for control
100 string text; // window/title text for control
101 internal BorderStyle border_style; // Border style of control
103 // Layout
104 int layout_suspended;
105 internal AnchorStyles anchor_style; // anchoring requirements for our control
106 internal DockStyle dock_style; // docking requirements for our control (supercedes anchoring)
107 // Please leave the next 4 as internal until DefaultLayout (2.0) is rewritten
108 internal int dist_left; // distance to the left border of the parent
109 internal int dist_top; // distance to the top border of the parent
110 internal int dist_right; // distance to the right border of the parent
111 internal int dist_bottom; // distance to the bottom border of the parent
113 // to be categorized...
114 static internal ArrayList controls = new ArrayList(); // All of the application's controls, in a flat list
115 ControlCollection child_controls; // our children
116 Control parent; // our parent control
117 AccessibleObject accessibility_object; // object that contains accessibility information about our control
118 BindingContext binding_context;
119 RightToLeft right_to_left; // drawing direction for control
120 ContextMenu context_menu; // Context menu associated with the control
122 // double buffering
123 Graphics dc_mem; // Graphics context for double buffering
124 Bitmap bmp_mem; // Bitmap for double buffering control
125 Region invalid_region;
127 ControlBindingsCollection data_bindings;
129 #if NET_2_0
130 internal bool use_compatible_text_rendering;
131 static bool verify_thread_handle;
132 Padding padding;
133 Size maximum_size;
134 Size minimum_size;
135 Size preferred_size;
136 Padding margin;
137 Layout.LayoutEngine layout_engine;
138 #endif
140 #endregion // Local Variables
142 #region Private Classes
143 // This helper class allows us to dispatch messages to Control.WndProc
144 internal class ControlNativeWindow : NativeWindow {
145 private Control owner;
147 public ControlNativeWindow(Control control) : base() {
148 this.owner=control;
152 public Control Owner {
153 get {
154 return owner;
158 static internal Control ControlFromHandle(IntPtr hWnd) {
159 ControlNativeWindow window;
161 window = (ControlNativeWindow)window_collection[hWnd];
162 if (window != null) {
163 return window.owner;
166 return null;
169 static internal Control ControlFromChildHandle (IntPtr handle) {
170 ControlNativeWindow window;
172 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
173 while (hwnd != null) {
174 window = (ControlNativeWindow)window_collection[hwnd.Handle];
175 if (window != null) {
176 return window.owner;
178 hwnd = hwnd.Parent;
181 return null;
184 protected override void WndProc(ref Message m) {
185 owner.WndProc(ref m);
188 #endregion
190 #region Public Classes
191 [ComVisible(true)]
192 public class ControlAccessibleObject : AccessibleObject {
193 Control owner;
195 #region ControlAccessibleObject Constructors
196 public ControlAccessibleObject(Control ownerControl)
197 : base (ownerControl)
199 this.owner = ownerControl;
201 #endregion // ControlAccessibleObject Constructors
203 #region ControlAccessibleObject Public Instance Properties
204 public override string DefaultAction {
205 get {
206 return base.DefaultAction;
210 public override string Description {
211 get {
212 return base.Description;
216 public IntPtr Handle {
217 get {
218 return owner.Handle;
221 set {
222 // We don't want to let them set it
226 public override string Help {
227 get {
228 return base.Help;
232 public override string KeyboardShortcut {
233 get {
234 return base.KeyboardShortcut;
238 public override string Name {
239 get {
240 return base.Name;
243 set {
244 base.Name = value;
248 public Control Owner {
249 get {
250 return owner;
254 public override AccessibleObject Parent {
255 get {
256 return base.Parent;
261 public override AccessibleRole Role {
262 get {
263 return base.Role;
266 #endregion // ControlAccessibleObject Public Instance Properties
268 #region ControlAccessibleObject Public Instance Methods
269 public override int GetHelpTopic(out string FileName) {
270 return base.GetHelpTopic (out FileName);
273 [MonoTODO("Implement this and tie it into Control.AccessibilityNotifyClients")]
274 public void NotifyClients(AccessibleEvents accEvent) {
275 throw new NotImplementedException();
278 [MonoTODO("Implement this and tie it into Control.AccessibilityNotifyClients")]
279 public void NotifyClients(AccessibleEvents accEvent, int childID) {
280 throw new NotImplementedException();
283 public override string ToString() {
284 return "ControlAccessibleObject: Owner = " + owner.ToString() + ", Text: " + owner.text;
287 #endregion // ControlAccessibleObject Public Instance Methods
290 [DesignerSerializer("System.Windows.Forms.Design.ControlCollectionCodeDomSerializer, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
291 [ListBindable(false)]
292 public class ControlCollection : IList, ICollection, ICloneable, IEnumerable {
293 #region ControlCollection Local Variables
294 ArrayList list;
295 ArrayList impl_list;
296 Control[] all_controls;
297 Control owner;
298 #endregion // ControlCollection Local Variables
300 #region ControlCollection Public Constructor
301 public ControlCollection(Control owner) {
302 this.owner=owner;
303 this.list=new ArrayList();
305 #endregion
307 #region ControlCollection Public Instance Properties
308 public int Count {
309 get {
310 return list.Count;
314 public bool IsReadOnly {
315 get {
316 return list.IsReadOnly;
320 public virtual Control this[int index] {
321 get {
322 if (index < 0 || index >= list.Count) {
323 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
325 return (Control)list[index];
328 #endregion // ControlCollection Public Instance Properties
330 #region ControlCollection Private Instance Methods
331 public virtual void Add (Control value)
333 if (value == null)
334 return;
336 if (Contains (value)) {
337 owner.PerformLayout();
338 return;
341 if (value.tab_index == -1) {
342 int end;
343 int index;
344 int use;
346 use = 0;
347 end = owner.child_controls.Count;
348 for (int i = 0; i < end; i++) {
349 index = owner.child_controls[i].tab_index;
350 if (index >= use) {
351 use = index + 1;
354 value.tab_index = use;
357 if (value.parent != null) {
358 value.parent.Controls.Remove(value);
361 all_controls = null;
362 list.Add (value);
364 value.ChangeParent(owner);
366 value.InitLayout();
368 owner.UpdateChildrenZOrder();
369 owner.PerformLayout(value, "Parent");
370 owner.OnControlAdded(new ControlEventArgs(value));
373 internal void AddToList (Control c)
375 all_controls = null;
376 list.Add (c);
379 internal virtual void AddImplicit (Control control)
381 if (impl_list == null)
382 impl_list = new ArrayList ();
384 if (AllContains (control))
385 return;
387 all_controls = null;
388 impl_list.Add (control);
390 control.ChangeParent (owner);
391 control.InitLayout ();
392 owner.UpdateChildrenZOrder ();
393 owner.PerformLayout (control, "Parent");
394 owner.OnControlAdded (new ControlEventArgs (control));
397 public virtual void AddRange (Control[] controls)
399 if (controls == null)
400 throw new ArgumentNullException ("controls");
402 owner.SuspendLayout ();
404 try {
405 for (int i = 0; i < controls.Length; i++)
406 Add (controls[i]);
407 } finally {
408 owner.ResumeLayout ();
412 internal virtual void AddRangeImplicit (Control [] controls)
414 if (controls == null)
415 throw new ArgumentNullException ("controls");
417 owner.SuspendLayout ();
419 try {
420 for (int i = 0; i < controls.Length; i++)
421 AddImplicit (controls [i]);
422 } finally {
423 owner.ResumeLayout ();
427 public virtual void Clear ()
429 all_controls = null;
431 // MS sends remove events in reverse order
432 while (list.Count > 0) {
433 Remove((Control)list[list.Count - 1]);
437 internal virtual void ClearImplicit ()
439 if (impl_list == null)
440 return;
441 all_controls = null;
442 impl_list.Clear ();
445 public bool Contains (Control value)
447 for (int i = list.Count; i > 0; ) {
448 i--;
450 if (list [i] == value) {
451 // Do we need to do anything here?
452 return true;
455 return false;
458 internal bool ImplicitContains (Control value)
460 if (impl_list == null)
461 return false;
463 for (int i = impl_list.Count; i > 0; ) {
464 i--;
466 if (impl_list [i] == value) {
467 // Do we need to do anything here?
468 return true;
471 return false;
474 internal bool AllContains (Control value)
476 return Contains (value) || ImplicitContains (value);
479 public void CopyTo (Array array, int index)
481 list.CopyTo(array, index);
484 public override bool Equals(object other) {
485 if (other is ControlCollection && (((ControlCollection)other).owner==this.owner)) {
486 return(true);
487 } else {
488 return(false);
492 public int GetChildIndex(Control child) {
493 return GetChildIndex(child, false);
496 public int GetChildIndex(Control child, bool throwException) {
497 int index;
499 index=list.IndexOf(child);
501 if (index==-1 && throwException) {
502 throw new ArgumentException("Not a child control", "child");
504 return index;
507 public IEnumerator GetEnumerator() {
508 return list.GetEnumerator();
511 internal IEnumerator GetAllEnumerator ()
513 Control [] res = GetAllControls ();
514 return res.GetEnumerator ();
517 internal Control [] GetAllControls ()
519 if (all_controls != null)
520 return all_controls;
522 if (impl_list == null) {
523 all_controls = (Control []) list.ToArray (typeof (Control));
524 return all_controls;
527 all_controls = new Control [list.Count + impl_list.Count];
528 impl_list.CopyTo (all_controls);
529 list.CopyTo (all_controls, impl_list.Count);
531 return all_controls;
534 public override int GetHashCode() {
535 return base.GetHashCode();
538 public int IndexOf(Control control) {
539 return list.IndexOf(control);
542 public virtual void Remove(Control value) {
543 owner.PerformLayout(value, "Parent");
544 owner.OnControlRemoved(new ControlEventArgs(value));
546 all_controls = null;
547 list.Remove(value);
549 value.ChangeParent(null);
551 owner.UpdateChildrenZOrder();
554 internal virtual void RemoveImplicit (Control control)
556 if (impl_list != null) {
557 all_controls = null;
558 owner.PerformLayout (control, "Parent");
559 owner.OnControlRemoved (new ControlEventArgs (control));
560 impl_list.Remove (control);
562 control.ChangeParent (null);
563 owner.UpdateChildrenZOrder ();
566 public void RemoveAt(int index) {
567 if (index < 0 || index >= list.Count) {
568 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
570 Remove ((Control)list[index]);
573 public void SetChildIndex(Control child, int newIndex) {
574 int old_index;
576 old_index=list.IndexOf(child);
577 if (old_index==-1) {
578 throw new ArgumentException("Not a child control", "child");
581 if (old_index==newIndex) {
582 return;
585 all_controls = null;
586 list.RemoveAt(old_index);
588 if (newIndex>list.Count) {
589 list.Add(child);
590 } else {
591 list.Insert(newIndex, child);
593 child.UpdateZOrder();
594 owner.PerformLayout();
596 #endregion // ControlCollection Private Instance Methods
598 #region ControlCollection Interface Properties
599 object IList.this[int index] {
600 get {
601 if (index<0 || index>=list.Count) {
602 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
604 return this[index];
607 set {
608 if (!(value is Control)) {
609 throw new ArgumentException("Object of type Control required", "value");
612 all_controls = null;
613 Control ctrl = (Control) value;
614 list[index]= ctrl;
616 ctrl.ChangeParent(owner);
618 ctrl.InitLayout();
620 owner.UpdateChildrenZOrder();
621 owner.PerformLayout(ctrl, "Parent");
625 bool IList.IsFixedSize {
626 get {
627 return false;
631 bool ICollection.IsSynchronized {
632 get {
633 return list.IsSynchronized;
637 object ICollection.SyncRoot {
638 get {
639 return list.SyncRoot;
642 #endregion // ControlCollection Interface Properties
644 #region ControlCollection Interface Methods
645 int IList.Add(object value) {
646 if (value == null) {
647 throw new ArgumentNullException("value", "Cannot add null controls");
650 if (!(value is Control)) {
651 throw new ArgumentException("Object of type Control required", "value");
654 return list.Add(value);
657 bool IList.Contains(object value) {
658 if (!(value is Control)) {
659 throw new ArgumentException("Object of type Control required", "value");
662 return this.Contains((Control) value);
665 int IList.IndexOf(object value) {
666 if (!(value is Control)) {
667 throw new ArgumentException("Object of type Control required", "value");
670 return this.IndexOf((Control) value);
673 void IList.Insert(int index, object value) {
674 if (!(value is Control)) {
675 throw new ArgumentException("Object of type Control required", "value");
677 all_controls = null;
678 list.Insert(index, value);
681 void IList.Remove(object value) {
682 if (!(value is Control)) {
683 throw new ArgumentException("Object of type Control required", "value");
685 all_controls = null;
686 list.Remove(value);
689 Object ICloneable.Clone() {
690 ControlCollection clone = new ControlCollection(this.owner);
691 clone.list=(ArrayList)list.Clone(); // FIXME: Do we need this?
692 return clone;
694 #endregion // ControlCollection Interface Methods
696 #endregion // ControlCollection Class
698 #region Public Constructors
699 public Control() {
701 anchor_style = AnchorStyles.Top | AnchorStyles.Left;
703 is_created = false;
704 is_visible = true;
705 is_captured = false;
706 is_disposed = false;
707 is_enabled = true;
708 is_entered = false;
709 layout_pending = false;
710 is_toplevel = false;
711 causes_validation = true;
712 has_focus = false;
713 layout_suspended = 0;
714 mouse_clicks = 1;
715 tab_index = -1;
716 cursor = null;
717 right_to_left = RightToLeft.Inherit;
718 border_style = BorderStyle.None;
719 background_color = Color.Empty;
720 dist_left = 0;
721 dist_right = 0;
722 dist_top = 0;
723 dist_bottom = 0;
724 tab_stop = true;
725 ime_mode = ImeMode.Inherit;
727 #if NET_2_0
728 use_compatible_text_rendering = Application.use_compatible_text_rendering;
729 padding = new Padding(0);
730 maximum_size = new Size();
731 minimum_size = new Size();
732 preferred_size = new Size();
733 margin = this.DefaultMargin;
734 layout_engine = this.LayoutEngine;
735 #endif
737 control_style = ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint |
738 ControlStyles.Selectable | ControlStyles.StandardClick |
739 ControlStyles.StandardDoubleClick;
740 #if NET_2_0
741 control_style |= ControlStyles.UseTextForAccessibility;
742 #endif
744 parent = null;
745 background_image = null;
746 text = string.Empty;
747 name = string.Empty;
749 window = new ControlNativeWindow(this);
750 child_controls = CreateControlsInstance();
751 client_size = new Size(DefaultSize.Width, DefaultSize.Height);
752 client_rect = new Rectangle(0, 0, DefaultSize.Width, DefaultSize.Height);
753 XplatUI.CalculateWindowRect(ref client_rect, CreateParams.Style, CreateParams.ExStyle, null, out bounds);
754 if ((CreateParams.Style & (int)WindowStyles.WS_CHILD) == 0) {
755 bounds.X=-1;
756 bounds.Y=-1;
760 public Control(Control parent, string text) : this() {
761 Text=text;
762 Parent=parent;
765 public Control(Control parent, string text, int left, int top, int width, int height) : this() {
766 Parent=parent;
767 bounds.X=left;
768 bounds.Y=top;
769 bounds.Width=width;
770 bounds.Height=height;
771 SetBounds(left, top, width, height, BoundsSpecified.All);
772 Text=text;
775 public Control(string text) : this() {
776 Text=text;
779 public Control(string text, int left, int top, int width, int height) : this() {
780 bounds.X=left;
781 bounds.Y=top;
782 bounds.Width=width;
783 bounds.Height=height;
784 SetBounds(left, top, width, height, BoundsSpecified.All);
785 Text=text;
788 private delegate void RemoveDelegate(object c);
790 protected override void Dispose(bool disposing) {
791 if (!is_disposed && disposing) {
792 Capture = false;
794 if (dc_mem!=null) {
795 dc_mem.Dispose();
796 dc_mem=null;
799 if (bmp_mem!=null) {
800 bmp_mem.Dispose();
801 bmp_mem=null;
804 if (invalid_region!=null) {
805 invalid_region.Dispose();
806 invalid_region=null;
808 if (this.InvokeRequired) {
809 if (Application.MessageLoop) {
810 this.BeginInvokeInternal(new MethodInvoker(DestroyHandle), null, true);
811 this.BeginInvokeInternal(new RemoveDelegate(controls.Remove), new object[] {this}, true);
813 } else {
814 DestroyHandle();
815 lock (Control.controls) {
816 Control.controls.Remove(this);
821 if (parent != null) {
822 parent.Controls.Remove(this);
825 Control [] children = child_controls.GetAllControls ();
826 for (int i=0; i<children.Length; i++) {
827 children[i].parent = null; // Need to set to null or our child will try and remove from ourselves and crash
828 children[i].Dispose();
831 is_disposed = true;
832 is_visible = false;
833 base.Dispose(disposing);
835 #endregion // Public Constructors
837 #region Internal Properties
838 internal BorderStyle InternalBorderStyle {
839 get {
840 return border_style;
843 set {
844 if (!Enum.IsDefined (typeof (BorderStyle), value))
845 throw new InvalidEnumArgumentException (string.Format("Enum argument value '{0}' is not valid for BorderStyle", value));
847 if (border_style != value) {
848 border_style = value;
850 if (IsHandleCreated) {
851 XplatUI.SetBorderStyle(window.Handle, (FormBorderStyle)border_style);
852 Refresh();
857 #endregion // Internal Properties
859 #region Private & Internal Methods
860 internal IAsyncResult BeginInvokeInternal (Delegate method, object [] args, bool disposing) {
861 AsyncMethodResult result;
862 AsyncMethodData data;
864 if (!disposing) {
865 Control p;
867 p = this;
868 do {
869 if (!p.IsHandleCreated) {
870 throw new InvalidOperationException("Cannot call Invoke or InvokeAsync on a control until the window handle is created");
872 p = p.parent;
873 } while (p != null);
876 result = new AsyncMethodResult ();
877 data = new AsyncMethodData ();
879 data.Handle = window.Handle;
880 data.Method = method;
881 data.Args = args;
882 data.Result = result;
884 #if NET_2_0
885 if (!ExecutionContext.IsFlowSuppressed ()) {
886 data.Context = ExecutionContext.Capture ();
888 #else
889 #if !MWF_ON_MSRUNTIME
890 if (SecurityManager.SecurityEnabled) {
891 data.Stack = CompressedStack.GetCompressedStack ();
893 #endif
894 #endif
896 XplatUI.SendAsyncMethod (data);
897 return result;
901 internal void PointToClient (ref int x, ref int y)
903 XplatUI.ScreenToClient (Handle, ref x, ref y);
906 internal void PointToScreen (ref int x, ref int y)
908 XplatUI.ClientToScreen (Handle, ref x, ref y);
911 internal bool IsRecreating {
912 get {
913 return is_recreating;
917 internal Graphics DeviceContext {
918 get {
919 if (dc_mem == null) {
920 CreateBuffers(this.Width, this.Height);
922 return dc_mem;
926 private void ImageBufferNeedsRedraw () {
927 if (invalid_region != null)
928 invalid_region.Dispose();
929 invalid_region = new Region (ClientRectangle);
932 private Bitmap ImageBuffer {
933 get {
934 if (bmp_mem==null) {
935 CreateBuffers(this.Width, this.Height);
937 return bmp_mem;
941 internal void CreateBuffers (int width, int height) {
942 if (width < 1) {
943 width = 1;
946 if (height < 1) {
947 height = 1;
950 bmp_mem = new Bitmap (width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
951 dc_mem = Graphics.FromImage (bmp_mem);
952 ImageBufferNeedsRedraw ();
955 internal void InvalidateBuffers ()
957 if (dc_mem != null) {
958 dc_mem.Dispose ();
961 dc_mem = null;
962 bmp_mem = null;
963 ImageBufferNeedsRedraw ();
966 internal static void SetChildColor(Control parent) {
967 Control child;
969 for (int i=0; i < parent.child_controls.Count; i++) {
970 child=parent.child_controls[i];
971 if (child.child_controls.Count>0) {
972 SetChildColor(child);
978 internal bool Select(Control control) {
979 IContainerControl container;
981 if (control == null) {
982 return false;
985 container = GetContainerControl();
986 if (container != null) {
987 container.ActiveControl = control;
989 if (control.IsHandleCreated) {
990 XplatUI.SetFocus(control.window.Handle);
992 return true;
995 internal void SelectChild (Control control)
997 if (control.IsHandleCreated)
998 XplatUI.SetFocus (control.window.Handle);
1001 internal virtual void DoDefaultAction() {
1002 // Only here to be overriden by our actual controls; this is needed by the accessibility class
1005 internal static int LowOrder (int param) {
1006 return ((int)(short)(param & 0xffff));
1009 internal static int HighOrder (int param) {
1010 return ((int)(short)(param >> 16));
1013 // This method exists so controls overriding OnPaintBackground can have default background painting done
1014 internal virtual void PaintControlBackground (PaintEventArgs pevent)
1016 if (GetStyle(ControlStyles.SupportsTransparentBackColor) && (BackColor.A != 0xff)) {
1017 if (parent != null) {
1018 PaintEventArgs parent_pe;
1019 GraphicsState state;
1021 parent_pe = new PaintEventArgs(pevent.Graphics, new Rectangle(pevent.ClipRectangle.X + Left, pevent.ClipRectangle.Y + Top, pevent.ClipRectangle.Width, pevent.ClipRectangle.Height));
1023 state = parent_pe.Graphics.Save();
1024 parent_pe.Graphics.TranslateTransform(-Left, -Top);
1025 parent.OnPaintBackground(parent_pe);
1026 parent_pe.Graphics.Restore(state);
1028 state = parent_pe.Graphics.Save();
1029 parent_pe.Graphics.TranslateTransform(-Left, -Top);
1030 parent.OnPaint(parent_pe);
1031 parent_pe.Graphics.Restore(state);
1032 parent_pe.SetGraphics(null);
1036 if ((clip_region != null) && (XplatUI.UserClipWontExposeParent)) {
1037 if (parent != null) {
1038 PaintEventArgs parent_pe;
1039 Region region;
1040 GraphicsState state;
1041 Hwnd hwnd;
1043 hwnd = Hwnd.ObjectFromHandle(Handle);
1045 if (hwnd != null) {
1046 parent_pe = new PaintEventArgs(pevent.Graphics, new Rectangle(pevent.ClipRectangle.X + Left, pevent.ClipRectangle.Y + Top, pevent.ClipRectangle.Width, pevent.ClipRectangle.Height));
1048 region = new Region ();
1049 region.MakeEmpty();
1050 region.Union(ClientRectangle);
1052 foreach (Rectangle r in hwnd.ClipRectangles) {
1053 region.Union (r);
1056 state = parent_pe.Graphics.Save();
1057 parent_pe.Graphics.Clip = region;
1059 parent_pe.Graphics.TranslateTransform(-Left, -Top);
1060 parent.OnPaintBackground(parent_pe);
1061 parent_pe.Graphics.Restore(state);
1063 state = parent_pe.Graphics.Save();
1064 parent_pe.Graphics.Clip = region;
1066 parent_pe.Graphics.TranslateTransform(-Left, -Top);
1067 parent.OnPaint(parent_pe);
1068 parent_pe.Graphics.Restore(state);
1069 parent_pe.SetGraphics(null);
1071 region.Intersect(clip_region);
1072 pevent.Graphics.Clip = region;
1077 if (background_image == null) {
1078 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));
1079 return;
1082 DrawBackgroundImage (pevent.Graphics);
1085 void DrawBackgroundImage (Graphics g)
1087 using (TextureBrush b = new TextureBrush (background_image, WrapMode.Tile)) {
1088 g.FillRectangle (b, ClientRectangle);
1092 internal virtual void DndEnter (DragEventArgs e)
1094 try {
1095 OnDragEnter (e);
1096 } catch { }
1099 internal virtual void DndOver (DragEventArgs e)
1101 try {
1102 OnDragOver (e);
1103 } catch { }
1106 internal virtual void DndDrop (DragEventArgs e)
1108 try {
1109 OnDragDrop (e);
1110 } catch (Exception exc) {
1111 Console.Error.WriteLine ("MWF: Exception while dropping:");
1112 Console.Error.WriteLine (exc);
1116 internal virtual void DndLeave (EventArgs e)
1118 try {
1119 OnDragLeave (e);
1120 } catch { }
1123 internal virtual void DndFeedback(GiveFeedbackEventArgs e)
1125 try {
1126 OnGiveFeedback(e);
1127 } catch { }
1130 internal virtual void DndContinueDrag(QueryContinueDragEventArgs e)
1132 try {
1133 OnQueryContinueDrag(e);
1134 } catch { }
1137 internal static MouseButtons FromParamToMouseButtons (int param) {
1138 MouseButtons buttons = MouseButtons.None;
1140 if ((param & (int) MsgButtons.MK_LBUTTON) != 0)
1141 buttons |= MouseButtons.Left;
1143 if ((param & (int) MsgButtons.MK_MBUTTON) != 0)
1144 buttons |= MouseButtons.Middle;
1146 if ((param & (int) MsgButtons.MK_RBUTTON) != 0)
1147 buttons |= MouseButtons.Right;
1149 return buttons;
1153 internal void FireEnter ()
1155 OnEnter (EventArgs.Empty);
1158 internal void FireLeave ()
1160 OnLeave (EventArgs.Empty);
1163 internal void FireValidating (CancelEventArgs ce)
1165 OnValidating (ce);
1168 internal void FireValidated ()
1170 OnValidated (EventArgs.Empty);
1173 internal virtual bool ProcessControlMnemonic(char charCode) {
1174 return ProcessMnemonic(charCode);
1177 private static Control FindFlatForward(Control container, Control start) {
1178 Control found;
1179 int index;
1180 int end;
1182 found = null;
1183 end = container.child_controls.Count;
1185 if (start != null) {
1186 index = start.tab_index;
1187 } else {
1188 index = -1;
1192 for (int i = 0, pos = -1; i < end; i++) {
1193 if (start == container.child_controls[i]) {
1194 pos = i;
1195 continue;
1198 if (found == null) {
1199 if (container.child_controls[i].tab_index > index || (pos > -1 && pos < i && container.child_controls[i].tab_index == index)) {
1200 found = container.child_controls[i];
1202 } else if (found.tab_index > container.child_controls[i].tab_index) {
1203 if (container.child_controls[i].tab_index > index) {
1204 found = container.child_controls[i];
1208 return found;
1211 private static Control FindControlForward(Control container, Control start) {
1212 Control found;
1214 found = null;
1216 if (start == null) {
1217 return FindFlatForward(container, start);
1220 if (start.child_controls != null && start.child_controls.Count > 0 &&
1221 (start == container || !((start is IContainerControl) && start.GetStyle(ControlStyles.ContainerControl)))) {
1222 return FindControlForward(start, null);
1224 else {
1225 while (start != container) {
1226 found = FindFlatForward(start.parent, start);
1227 if (found != null) {
1228 return found;
1230 start = start.parent;
1233 return null;
1236 private static Control FindFlatBackward(Control container, Control start) {
1237 Control found;
1238 int index;
1239 int end;
1241 found = null;
1242 end = container.child_controls.Count;
1244 if (start != null) {
1245 index = start.tab_index;
1246 } else {
1247 // FIXME: Possible speed-up: Keep the highest taborder index in the container
1248 index = -1;
1249 for (int i = 0; i < end; i++) {
1250 if (container.child_controls[i].tab_index > index) {
1251 index = container.child_controls[i].tab_index;
1254 index++;
1257 bool hit = false;
1259 for (int i = end - 1; i >= 0; i--) {
1260 if (start == container.child_controls[i]) {
1261 hit = true;
1262 continue;
1265 if (found == null || found.tab_index < container.child_controls[i].tab_index) {
1266 if (container.child_controls[i].tab_index < index || (hit && container.child_controls[i].tab_index == index))
1267 found = container.child_controls[i];
1271 return found;
1274 private static Control FindControlBackward(Control container, Control start) {
1276 Control found = null;
1278 if (start == null) {
1279 found = FindFlatBackward(container, start);
1281 else if (start != container) {
1282 if (start.parent != null) {
1283 found = FindFlatBackward(start.parent, start);
1285 if (found == null) {
1286 if (start.parent != container)
1287 return start.parent;
1288 return null;
1293 if (found == null || start.parent == null)
1294 found = start;
1296 while (found != null && (found == container || (!((found is IContainerControl) && found.GetStyle(ControlStyles.ContainerControl))) &&
1297 found.child_controls != null && found.child_controls.Count > 0)) {
1298 // while (ctl.child_controls != null && ctl.child_controls.Count > 0 &&
1299 // (ctl == this || (!((ctl is IContainerControl) && ctl.GetStyle(ControlStyles.ContainerControl))))) {
1300 found = FindFlatBackward(found, null);
1303 return found;
1306 Control found;
1308 found = null;
1310 if (start != null) {
1311 found = FindFlatBackward(start.parent, start);
1312 if (found == null) {
1313 if (start.parent != container) {
1314 return start.parent;
1318 if (found == null) {
1319 found = FindFlatBackward(container, start);
1322 if (container != start) {
1323 while ((found != null) && (!found.Contains(start)) && found.child_controls != null && found.child_controls.Count > 0 && !(found is IContainerControl)) {// || found.GetStyle(ControlStyles.ContainerControl))) {
1324 found = FindControlBackward(found, null);
1325 if (found != null) {
1326 return found;
1330 return found;
1334 internal virtual void HandleClick(int clicks, MouseEventArgs me) {
1335 if (GetStyle(ControlStyles.StandardClick)) {
1336 if ((clicks > 1) && GetStyle(ControlStyles.StandardDoubleClick)) {
1337 #if !NET_2_0
1338 OnDoubleClick(EventArgs.Empty);
1339 } else {
1340 OnClick(EventArgs.Empty);
1341 #else
1342 OnDoubleClick(me);
1343 } else {
1344 OnClick(me);
1345 #endif
1350 private void CheckDataBindings ()
1352 if (data_bindings == null)
1353 return;
1355 BindingContext binding_context = BindingContext;
1356 foreach (Binding binding in data_bindings) {
1357 binding.Check (binding_context);
1362 private void ChangeParent(Control new_parent) {
1363 bool pre_enabled;
1364 bool pre_visible;
1365 Font pre_font;
1366 Color pre_fore_color;
1367 Color pre_back_color;
1368 RightToLeft pre_rtl;
1370 // These properties are inherited from our parent
1371 // Get them pre parent-change and then send events
1372 // if they are changed after we have our new parent
1373 pre_enabled = Enabled;
1374 pre_visible = Visible;
1375 pre_font = Font;
1376 pre_fore_color = ForeColor;
1377 pre_back_color = BackColor;
1378 pre_rtl = RightToLeft;
1379 // MS doesn't seem to send a CursorChangedEvent
1381 parent = new_parent;
1383 if (IsHandleCreated)
1384 XplatUI.SetParent(Handle,
1385 (new_parent == null || !new_parent.IsHandleCreated) ? IntPtr.Zero : new_parent.Handle);
1387 OnParentChanged(EventArgs.Empty);
1389 if (pre_enabled != Enabled) {
1390 OnEnabledChanged(EventArgs.Empty);
1393 if (pre_visible != Visible) {
1394 OnVisibleChanged(EventArgs.Empty);
1397 if (pre_font != Font) {
1398 OnFontChanged(EventArgs.Empty);
1401 if (pre_fore_color != ForeColor) {
1402 OnForeColorChanged(EventArgs.Empty);
1405 if (pre_back_color != BackColor) {
1406 OnBackColorChanged(EventArgs.Empty);
1409 if (pre_rtl != RightToLeft) {
1410 // MS sneaks a OnCreateControl and OnHandleCreated in here, I guess
1411 // because when RTL changes they have to recreate the win32 control
1412 // We don't really need that (until someone runs into compatibility issues)
1413 OnRightToLeftChanged(EventArgs.Empty);
1416 if ((new_parent != null) && new_parent.Created && !Created) {
1417 CreateControl();
1420 if ((binding_context == null) && Created) {
1421 OnBindingContextChanged(EventArgs.Empty);
1425 private void UpdateDistances() {
1426 if ((parent != null) && (parent.layout_suspended == 0)) {
1427 dist_left = bounds.X;
1428 dist_top = bounds.Y;
1429 dist_right = parent.ClientSize.Width - bounds.X - bounds.Width;
1430 dist_bottom = parent.ClientSize.Height - bounds.Y - bounds.Height;
1433 #endregion // Private & Internal Methods
1435 #region Public Static Properties
1436 public static Color DefaultBackColor {
1437 get {
1438 return ThemeEngine.Current.DefaultControlBackColor;
1442 public static Font DefaultFont {
1443 get {
1444 return ThemeEngine.Current.DefaultFont;
1448 public static Color DefaultForeColor {
1449 get {
1450 return ThemeEngine.Current.DefaultControlForeColor;
1454 public static Keys ModifierKeys {
1455 get {
1456 return XplatUI.State.ModifierKeys;
1460 public static MouseButtons MouseButtons {
1461 get {
1462 return XplatUI.State.MouseButtons;
1466 public static Point MousePosition {
1467 get {
1468 return Cursor.Position;
1472 #if NET_2_0
1473 [MonoTODO]
1474 public static bool CheckForIllegalCrossThreadCalls
1476 get {
1477 return verify_thread_handle;
1480 set {
1481 verify_thread_handle = value;
1484 #endif
1485 #endregion // Public Static Properties
1487 #region Public Instance Properties
1488 [EditorBrowsable(EditorBrowsableState.Advanced)]
1489 [Browsable(false)]
1490 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1491 public AccessibleObject AccessibilityObject {
1492 get {
1493 if (accessibility_object==null) {
1494 accessibility_object=CreateAccessibilityInstance();
1496 return accessibility_object;
1500 [EditorBrowsable(EditorBrowsableState.Advanced)]
1501 [Browsable(false)]
1502 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1503 public string AccessibleDefaultActionDescription {
1504 get {
1505 return AccessibilityObject.default_action;
1508 set {
1509 AccessibilityObject.default_action=value;
1513 [Localizable(true)]
1514 [DefaultValue(null)]
1515 [MWFCategory("Accessibility")]
1516 public string AccessibleDescription {
1517 get {
1518 return AccessibilityObject.description;
1521 set {
1522 AccessibilityObject.description=value;
1526 [Localizable(true)]
1527 [DefaultValue(null)]
1528 [MWFCategory("Accessibility")]
1529 public string AccessibleName {
1530 get {
1531 return AccessibilityObject.Name;
1534 set {
1535 AccessibilityObject.Name=value;
1539 [DefaultValue(AccessibleRole.Default)]
1540 [MWFDescription("Role of the control"), MWFCategory("Accessibility")]
1541 public AccessibleRole AccessibleRole {
1542 get {
1543 return AccessibilityObject.role;
1546 set {
1547 AccessibilityObject.role=value;
1551 [DefaultValue(false)]
1552 [MWFCategory("Behavior")]
1553 public virtual bool AllowDrop {
1554 get {
1555 return allow_drop;
1558 set {
1559 if (allow_drop == value)
1560 return;
1561 allow_drop = value;
1562 if (IsHandleCreated) {
1563 UpdateStyles();
1564 XplatUI.SetAllowDrop (Handle, value);
1569 [Localizable(true)]
1570 [RefreshProperties(RefreshProperties.Repaint)]
1571 [DefaultValue(AnchorStyles.Top | AnchorStyles.Left)]
1572 [MWFCategory("Layout")]
1573 public virtual AnchorStyles Anchor {
1574 get {
1575 return anchor_style;
1578 set {
1579 anchor_style=value;
1581 if (parent != null) {
1582 parent.PerformLayout(this, "Parent");
1587 #if NET_2_0
1588 // XXX: Implement me!
1589 bool auto_size;
1591 public virtual bool AutoSize {
1592 get {
1593 //Console.Error.WriteLine("Unimplemented: Control::get_AutoSize()");
1594 return auto_size;
1596 set {
1597 Console.Error.WriteLine("Unimplemented: Control::set_AutoSize(bool)");
1598 auto_size = value;
1602 public virtual Size MaximumSize {
1603 get {
1604 return maximum_size;
1606 set {
1607 maximum_size = value;
1611 public virtual Size MinimumSize {
1612 get {
1613 return minimum_size;
1615 set {
1616 minimum_size = value;
1619 #endif // NET_2_0
1621 [DispId(-501)]
1622 [MWFCategory("Appearance")]
1623 public virtual Color BackColor {
1624 get {
1625 if (background_color.IsEmpty) {
1626 if (parent!=null) {
1627 Color pcolor = parent.BackColor;
1628 if (pcolor.A == 0xff || GetStyle(ControlStyles.SupportsTransparentBackColor))
1629 return pcolor;
1631 return DefaultBackColor;
1633 return background_color;
1636 set {
1637 if (!value.IsEmpty && (value.A != 0xff) && !GetStyle(ControlStyles.SupportsTransparentBackColor)) {
1638 throw new ArgumentException("Transparent background colors are not supported on this control");
1641 if (background_color != value) {
1642 background_color=value;
1643 SetChildColor(this);
1644 OnBackColorChanged(EventArgs.Empty);
1645 Invalidate();
1650 [Localizable(true)]
1651 [DefaultValue(null)]
1652 [MWFCategory("Appearance")]
1653 public virtual Image BackgroundImage {
1654 get {
1655 return background_image;
1658 set {
1659 if (background_image!=value) {
1660 background_image=value;
1661 OnBackgroundImageChanged(EventArgs.Empty);
1666 [EditorBrowsable(EditorBrowsableState.Advanced)]
1667 [Browsable(false)]
1668 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1669 public virtual BindingContext BindingContext {
1670 get {
1671 if (binding_context != null)
1672 return binding_context;
1673 if (Parent == null)
1674 return null;
1675 binding_context = Parent.BindingContext;
1676 return binding_context;
1678 set {
1679 if (binding_context != value) {
1680 binding_context = value;
1681 OnBindingContextChanged(EventArgs.Empty);
1686 [EditorBrowsable(EditorBrowsableState.Advanced)]
1687 [Browsable(false)]
1688 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1689 public int Bottom {
1690 get {
1691 return bounds.Y+bounds.Height;
1695 [EditorBrowsable(EditorBrowsableState.Advanced)]
1696 [Browsable(false)]
1697 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1698 public Rectangle Bounds {
1699 get {
1700 return this.bounds;
1703 set {
1704 SetBounds(value.Left, value.Top, value.Width, value.Height, BoundsSpecified.All);
1708 [EditorBrowsable(EditorBrowsableState.Advanced)]
1709 [Browsable(false)]
1710 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1711 public bool CanFocus {
1712 get {
1713 if (IsHandleCreated && Visible && Enabled) {
1714 return true;
1716 return false;
1720 [EditorBrowsable(EditorBrowsableState.Advanced)]
1721 [Browsable(false)]
1722 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1723 public bool CanSelect {
1724 get {
1725 Control parent;
1727 if (!GetStyle(ControlStyles.Selectable)) {
1728 return false;
1731 parent = this;
1732 while (parent != null) {
1733 if (!parent.is_visible || !parent.is_enabled) {
1734 return false;
1737 parent = parent.parent;
1739 return true;
1743 internal virtual bool InternalCapture {
1744 get {
1745 return Capture;
1748 set {
1749 Capture = value;
1753 [EditorBrowsable(EditorBrowsableState.Advanced)]
1754 [Browsable(false)]
1755 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1756 public bool Capture {
1757 get {
1758 return this.is_captured;
1761 set {
1762 if (this.IsHandleCreated && value != is_captured) {
1763 if (value) {
1764 is_captured = true;
1765 XplatUI.GrabWindow(this.window.Handle, IntPtr.Zero);
1766 } else {
1767 XplatUI.UngrabWindow(this.window.Handle);
1768 is_captured = false;
1774 [DefaultValue(true)]
1775 [MWFCategory("Focus")]
1776 public bool CausesValidation {
1777 get {
1778 return this.causes_validation;
1781 set {
1782 if (this.causes_validation != value) {
1783 causes_validation = value;
1784 OnCausesValidationChanged(EventArgs.Empty);
1789 [EditorBrowsable(EditorBrowsableState.Advanced)]
1790 [Browsable(false)]
1791 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1792 public Rectangle ClientRectangle {
1793 get {
1794 client_rect.Width = client_size.Width;
1795 client_rect.Height = client_size.Height;
1796 return client_rect;
1800 [EditorBrowsable(EditorBrowsableState.Advanced)]
1801 [Browsable(false)]
1802 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1803 public Size ClientSize {
1804 get {
1805 #if notneeded
1806 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1807 return ((Form)this).form_parent_window.ClientSize;
1809 #endif
1811 return client_size;
1814 set {
1815 this.SetClientSizeCore(value.Width, value.Height);
1819 [EditorBrowsable(EditorBrowsableState.Advanced)]
1820 [Browsable(false)]
1821 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1822 [DescriptionAttribute("ControlCompanyNameDescr")]
1823 public String CompanyName {
1824 get {
1825 return "Mono Project, Novell, Inc.";
1829 [EditorBrowsable(EditorBrowsableState.Advanced)]
1830 [Browsable(false)]
1831 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1832 public bool ContainsFocus {
1833 get {
1834 IntPtr focused_window;
1836 focused_window = XplatUI.GetFocus();
1837 if (IsHandleCreated) {
1838 if (focused_window == Handle) {
1839 return true;
1842 for (int i=0; i < child_controls.Count; i++) {
1843 if (child_controls[i].ContainsFocus) {
1844 return true;
1848 return false;
1852 [DefaultValue(null)]
1853 [MWFCategory("Behavior")]
1854 public virtual ContextMenu ContextMenu {
1855 get {
1856 return context_menu;
1859 set {
1860 if (context_menu != value) {
1861 context_menu = value;
1862 OnContextMenuChanged(EventArgs.Empty);
1867 [Browsable(false)]
1868 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
1869 public ControlCollection Controls {
1870 get {
1871 return this.child_controls;
1875 [EditorBrowsable(EditorBrowsableState.Advanced)]
1876 [Browsable(false)]
1877 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1878 public bool Created {
1879 get {
1880 return (!is_disposed && is_created);
1884 [AmbientValue(null)]
1885 [MWFCategory("Appearance")]
1886 public virtual Cursor Cursor {
1887 get {
1888 if (cursor != null) {
1889 return cursor;
1892 if (parent != null) {
1893 return parent.Cursor;
1896 return Cursors.Default;
1899 set {
1900 if (cursor != value) {
1901 Point pt;
1903 cursor = value;
1905 if (IsHandleCreated) {
1906 pt = Cursor.Position;
1908 if (bounds.Contains(pt) || Capture) {
1909 if (GetChildAtPoint(pt) == null) {
1910 if (cursor != null) {
1911 XplatUI.SetCursor(window.Handle, cursor.handle);
1912 } else {
1913 if (parent != null) {
1914 XplatUI.SetCursor(window.Handle, parent.Cursor.handle);
1915 } else {
1916 XplatUI.SetCursor(window.Handle, Cursors.Default.handle);
1923 OnCursorChanged(EventArgs.Empty);
1929 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
1930 [ParenthesizePropertyName(true)]
1931 [RefreshProperties(RefreshProperties.All)]
1932 [MWFCategory("Data")]
1933 public ControlBindingsCollection DataBindings {
1934 get {
1935 if (data_bindings == null)
1936 data_bindings = new ControlBindingsCollection (this);
1937 return data_bindings;
1941 [EditorBrowsable(EditorBrowsableState.Advanced)]
1942 [Browsable(false)]
1943 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1944 public virtual Rectangle DisplayRectangle {
1945 get {
1946 return ClientRectangle;
1950 [EditorBrowsable(EditorBrowsableState.Advanced)]
1951 [Browsable(false)]
1952 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1953 public bool Disposing {
1954 get {
1955 return is_disposed;
1959 [Localizable(true)]
1960 [RefreshProperties(RefreshProperties.Repaint)]
1961 [DefaultValue(DockStyle.None)]
1962 [MWFCategory("Layout")]
1963 public virtual DockStyle Dock {
1964 get {
1965 return dock_style;
1968 set {
1969 if (dock_style == value) {
1970 return;
1973 dock_style = value;
1975 if (dock_style == DockStyle.None) {
1976 if (explicit_bounds == Rectangle.Empty)
1977 Bounds = new Rectangle (new Point (0, 0), DefaultSize);
1978 else
1979 Bounds = explicit_bounds;
1982 if (parent != null) {
1983 parent.PerformLayout(this, "Parent");
1986 OnDockChanged(EventArgs.Empty);
1990 [DispId(-514)]
1991 [Localizable(true)]
1992 [MWFCategory("Behavior")]
1993 public bool Enabled {
1994 get {
1995 if (!is_enabled) {
1996 return false;
1999 if (parent != null) {
2000 return parent.Enabled;
2003 return true;
2006 set {
2008 bool old_value = is_enabled;
2010 is_enabled = value;
2011 if (old_value != value && !value && this.has_focus)
2012 SelectNextControl(this, true, true, true, true);
2014 OnEnabledChanged (EventArgs.Empty);
2018 [EditorBrowsable(EditorBrowsableState.Advanced)]
2019 [Browsable(false)]
2020 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2021 public virtual bool Focused {
2022 get {
2023 return this.has_focus;
2027 [DispId(-512)]
2028 [AmbientValue(null)]
2029 [Localizable(true)]
2030 [MWFCategory("Appearance")]
2031 public virtual Font Font {
2032 get {
2033 if (font != null) {
2034 return font;
2037 if (Parent != null && Parent.Font != null) {
2038 return Parent.Font;
2041 return DefaultFont;
2044 [param:MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Font))]
2045 set {
2046 if (font != null && font.Equals (value)) {
2047 return;
2050 font = value;
2051 Invalidate();
2052 OnFontChanged (EventArgs.Empty);
2056 [DispId(-513)]
2057 [MWFCategory("Appearance")]
2058 public virtual Color ForeColor {
2059 get {
2060 if (foreground_color.IsEmpty) {
2061 if (parent!=null) {
2062 return parent.ForeColor;
2064 return DefaultForeColor;
2066 return foreground_color;
2069 set {
2070 if (foreground_color != value) {
2071 foreground_color=value;
2072 Invalidate();
2073 OnForeColorChanged(EventArgs.Empty);
2078 [DispId(-515)]
2079 [Browsable(false)]
2080 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2081 public IntPtr Handle { // IWin32Window
2082 get {
2083 #if NET_2_0
2084 if (verify_thread_handle) {
2085 if (this.InvokeRequired) {
2086 throw new InvalidOperationException("Cross-thread access of handle detected. Handle access only valid on thread that created the control");
2089 #endif
2090 if (!IsHandleCreated) {
2091 CreateHandle();
2093 return window.Handle;
2097 [EditorBrowsable(EditorBrowsableState.Advanced)]
2098 [Browsable(false)]
2099 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2100 public bool HasChildren {
2101 get {
2102 if (this.child_controls.Count>0) {
2103 return true;
2105 return false;
2109 [EditorBrowsable(EditorBrowsableState.Always)]
2110 [Browsable(false)]
2111 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2112 public int Height {
2113 get {
2114 return this.bounds.Height;
2117 set {
2118 SetBounds(bounds.X, bounds.Y, bounds.Width, value, BoundsSpecified.Height);
2122 [AmbientValue(ImeMode.Inherit)]
2123 [Localizable(true)]
2124 [MWFCategory("Behavior")]
2125 public ImeMode ImeMode {
2126 get {
2127 if (ime_mode == ImeMode.Inherit) {
2128 if (parent != null)
2129 return parent.ImeMode;
2130 else
2131 return ImeMode.NoControl; // default value
2133 return ime_mode;
2136 set {
2137 if (ime_mode != value) {
2138 ime_mode = value;
2140 OnImeModeChanged(EventArgs.Empty);
2145 [EditorBrowsable(EditorBrowsableState.Advanced)]
2146 [Browsable(false)]
2147 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2148 public bool InvokeRequired { // ISynchronizeInvoke
2149 get {
2150 if (creator_thread != null && creator_thread!=Thread.CurrentThread) {
2151 return true;
2153 return false;
2157 [EditorBrowsable(EditorBrowsableState.Advanced)]
2158 [Browsable(false)]
2159 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2160 public bool IsAccessible {
2161 get {
2162 return is_accessible;
2165 set {
2166 is_accessible = value;
2170 [EditorBrowsable(EditorBrowsableState.Advanced)]
2171 [Browsable(false)]
2172 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2173 public bool IsDisposed {
2174 get {
2175 return this.is_disposed;
2179 [EditorBrowsable(EditorBrowsableState.Advanced)]
2180 [Browsable(false)]
2181 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2182 public bool IsHandleCreated {
2183 get {
2184 if ((window != null) && (window.Handle != IntPtr.Zero)) {
2185 Hwnd hwnd = Hwnd.ObjectFromHandle (window.Handle);
2186 if (hwnd != null && !hwnd.zombie)
2187 return true;
2190 return false;
2194 #if NET_2_0
2195 public virtual Layout.LayoutEngine LayoutEngine {
2196 get { return new Layout.DefaultLayout (); }
2198 #endif
2200 [EditorBrowsable(EditorBrowsableState.Always)]
2201 [Browsable(false)]
2202 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2203 public int Left {
2204 get {
2205 return this.bounds.X;
2208 set {
2209 SetBounds(value, bounds.Y, bounds.Width, bounds.Height, BoundsSpecified.X);
2213 [Localizable(true)]
2214 [MWFCategory("Layout")]
2215 public Point Location {
2216 get {
2217 return new Point(bounds.X, bounds.Y);
2220 set {
2221 SetBounds(value.X, value.Y, bounds.Width, bounds.Height, BoundsSpecified.Location);
2225 #if NET_2_0
2226 [Localizable (true)]
2227 public Padding Margin {
2228 get { return this.margin; }
2229 set { this.margin = value; }
2231 #endif
2233 [Browsable(false)]
2234 public string Name {
2235 get {
2236 return name;
2239 set {
2240 name = value;
2244 #if NET_2_0
2245 [Localizable(true)]
2246 public Padding Padding {
2247 get {
2248 return padding;
2251 set {
2252 padding = value;
2255 #endif
2257 [Browsable(false)]
2258 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2259 public Control Parent {
2260 get {
2261 return this.parent;
2264 set {
2265 if (value == this) {
2266 throw new ArgumentException("A circular control reference has been made. A control cannot be owned or parented to itself.");
2269 if (parent!=value) {
2270 if (value==null) {
2271 parent.Controls.Remove(this);
2272 parent = null;
2273 return;
2276 value.Controls.Add(this);
2281 [EditorBrowsable(EditorBrowsableState.Advanced)]
2282 [Browsable(false)]
2283 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2284 public string ProductName {
2285 get {
2286 Type t = typeof (AssemblyProductAttribute);
2287 Assembly assembly = GetType().Module.Assembly;
2288 object [] attrs = assembly.GetCustomAttributes (t, false);
2289 AssemblyProductAttribute a = null;
2290 // On MS we get a NullRefException if product attribute is not
2291 // set.
2292 if (attrs != null && attrs.Length > 0)
2293 a = (AssemblyProductAttribute) attrs [0];
2294 return a.Product;
2298 [EditorBrowsable(EditorBrowsableState.Advanced)]
2299 [Browsable(false)]
2300 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2301 public string ProductVersion {
2302 get {
2303 Type t = typeof (AssemblyVersionAttribute);
2304 Assembly assembly = GetType().Module.Assembly;
2305 object [] attrs = assembly.GetCustomAttributes (t, false);
2306 if (attrs == null || attrs.Length < 1)
2307 return "1.0.0.0";
2308 return ((AssemblyVersionAttribute)attrs [0]).Version;
2312 [EditorBrowsable(EditorBrowsableState.Advanced)]
2313 [Browsable(false)]
2314 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2315 public bool RecreatingHandle {
2316 get {
2317 return is_recreating;
2321 [EditorBrowsable(EditorBrowsableState.Advanced)]
2322 [Browsable(false)]
2323 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2324 public Region Region {
2325 get {
2326 return clip_region;
2329 set {
2330 if (IsHandleCreated) {
2331 XplatUI.SetClipRegion(Handle, value);
2333 clip_region = value;
2337 [EditorBrowsable(EditorBrowsableState.Advanced)]
2338 [Browsable(false)]
2339 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2340 public int Right {
2341 get {
2342 return this.bounds.X+this.bounds.Width;
2346 [AmbientValue(RightToLeft.Inherit)]
2347 [Localizable(true)]
2348 [MWFCategory("Appearance")]
2349 public virtual RightToLeft RightToLeft {
2350 get {
2351 if (right_to_left == RightToLeft.Inherit) {
2352 if (parent != null)
2353 return parent.RightToLeft;
2354 else
2355 return RightToLeft.No; // default value
2357 return right_to_left;
2360 set {
2361 if (value != right_to_left) {
2362 right_to_left = value;
2363 OnRightToLeftChanged(EventArgs.Empty);
2368 [EditorBrowsable(EditorBrowsableState.Advanced)]
2369 public override ISite Site {
2370 get {
2371 return base.Site;
2374 set {
2375 base.Site = value;
2377 AmbientProperties ap = (AmbientProperties) value.GetService (typeof (AmbientProperties));
2378 if (ap != null) {
2379 BackColor = ap.BackColor;
2380 ForeColor = ap.ForeColor;
2381 Cursor = ap.Cursor;
2382 Font = ap.Font;
2387 [Localizable(true)]
2388 [MWFCategory("Layout")]
2389 public Size Size {
2390 get {
2391 return new Size(Width, Height);
2394 set {
2395 SetBounds(bounds.X, bounds.Y, value.Width, value.Height, BoundsSpecified.Size);
2399 [Localizable(true)]
2400 [MergableProperty(false)]
2401 [MWFCategory("Behavior")]
2402 public int TabIndex {
2403 get {
2404 if (tab_index != -1) {
2405 return tab_index;
2407 return 0;
2410 set {
2411 if (tab_index != value) {
2412 tab_index = value;
2413 OnTabIndexChanged(EventArgs.Empty);
2418 [DispId(-516)]
2419 [DefaultValue(true)]
2420 [MWFCategory("Behavior")]
2421 public bool TabStop {
2422 get {
2423 return tab_stop;
2426 set {
2427 if (tab_stop != value) {
2428 tab_stop = value;
2429 OnTabStopChanged(EventArgs.Empty);
2434 [Localizable(false)]
2435 [Bindable(true)]
2436 [TypeConverter(typeof(StringConverter))]
2437 [DefaultValue(null)]
2438 [MWFCategory("Data")]
2439 public object Tag {
2440 get {
2441 return control_tag;
2444 set {
2445 control_tag = value;
2449 [DispId(-517)]
2450 [Localizable(true)]
2451 [BindableAttribute(true)]
2452 [MWFCategory("Appearance")]
2453 public virtual string Text {
2454 get {
2455 // Our implementation ignores ControlStyles.CacheText - we always cache
2456 return this.text;
2459 set {
2460 if (value == null) {
2461 value = String.Empty;
2464 if (text!=value) {
2465 text=value;
2466 if (IsHandleCreated) {
2467 /* we need to call .SetWindowStyle here instead of just .Text
2468 because the presence/absence of Text (== "" or not) can cause
2469 other window style things to appear/disappear */
2470 XplatUI.SetWindowStyle(window.Handle, CreateParams);
2471 XplatUI.Text(Handle, text);
2473 OnTextChanged (EventArgs.Empty);
2478 [EditorBrowsable(EditorBrowsableState.Always)]
2479 [Browsable(false)]
2480 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2481 public int Top {
2482 get {
2483 return this.bounds.Y;
2486 set {
2487 SetBounds(bounds.X, value, bounds.Width, bounds.Height, BoundsSpecified.Y);
2491 [EditorBrowsable(EditorBrowsableState.Advanced)]
2492 [Browsable(false)]
2493 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2494 public Control TopLevelControl {
2495 get {
2496 Control p = this;
2498 while (p.parent != null) {
2499 p = p.parent;
2502 return p is Form ? p : null;
2506 [Localizable(true)]
2507 [MWFCategory("Behavior")]
2508 public bool Visible {
2509 get {
2510 if (!is_visible) {
2511 return false;
2512 } else if (parent != null) {
2513 return parent.Visible;
2516 return true;
2519 set {
2520 SetVisibleCore(value);
2524 [EditorBrowsable(EditorBrowsableState.Always)]
2525 [Browsable(false)]
2526 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2527 public int Width {
2528 get {
2529 return this.bounds.Width;
2532 set {
2533 SetBounds(bounds.X, bounds.Y, value, bounds.Height, BoundsSpecified.Width);
2537 [EditorBrowsable(EditorBrowsableState.Never)]
2538 [Browsable(false)]
2539 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2540 public IWindowTarget WindowTarget {
2541 get {
2542 return null;
2545 set {
2546 ; // MS Internal
2549 #endregion // Public Instance Properties
2551 #region Protected Instance Properties
2552 protected virtual CreateParams CreateParams {
2553 get {
2554 CreateParams create_params = new CreateParams();
2556 try {
2557 create_params.Caption = Text;
2559 catch {
2560 create_params.Caption = text;
2563 try {
2564 create_params.X = Left;
2566 catch {
2567 create_params.X = this.bounds.X;
2570 try {
2571 create_params.Y = Top;
2573 catch {
2574 create_params.Y = this.bounds.Y;
2577 try {
2578 create_params.Width = Width;
2580 catch {
2581 create_params.Width = this.bounds.Width;
2584 try {
2585 create_params.Height = Height;
2587 catch {
2588 create_params.Height = this.bounds.Height;
2592 create_params.ClassName = XplatUI.DefaultClassName;
2593 create_params.ClassStyle = 0;
2594 create_params.ExStyle = 0;
2595 create_params.Param = 0;
2597 if (allow_drop) {
2598 create_params.ExStyle |= (int)WindowExStyles.WS_EX_ACCEPTFILES;
2601 if ((parent!=null) && (parent.IsHandleCreated)) {
2602 create_params.Parent = parent.Handle;
2605 create_params.Style = (int)WindowStyles.WS_CHILD | (int)WindowStyles.WS_CLIPCHILDREN | (int)WindowStyles.WS_CLIPSIBLINGS;
2607 if (is_visible) {
2608 create_params.Style |= (int)WindowStyles.WS_VISIBLE;
2611 if (!is_enabled) {
2612 create_params.Style |= (int)WindowStyles.WS_DISABLED;
2615 switch (border_style) {
2616 case BorderStyle.FixedSingle:
2617 create_params.Style |= (int) WindowStyles.WS_BORDER;
2618 break;
2619 case BorderStyle.Fixed3D:
2620 create_params.ExStyle |= (int) WindowExStyles.WS_EX_CLIENTEDGE;
2621 break;
2624 return create_params;
2628 protected virtual ImeMode DefaultImeMode {
2629 get {
2630 return ImeMode.Inherit;
2634 #if NET_2_0
2635 protected virtual Padding DefaultMargin {
2636 get { return new Padding (3); }
2638 #endif
2640 protected virtual Size DefaultSize {
2641 get {
2642 return new Size(0, 0);
2646 protected int FontHeight {
2647 get {
2648 return Font.Height;
2651 set {
2652 ;; // Nothing to do
2656 protected bool RenderRightToLeft {
2657 get {
2658 return (this.right_to_left == RightToLeft.Yes);
2662 protected bool ResizeRedraw {
2663 get {
2664 return GetStyle(ControlStyles.ResizeRedraw);
2667 set {
2668 SetStyle(ControlStyles.ResizeRedraw, value);
2672 [EditorBrowsable(EditorBrowsableState.Advanced)]
2673 [Browsable(false)]
2674 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2675 protected virtual bool ShowFocusCues {
2676 get {
2677 return true;
2681 [EditorBrowsable(EditorBrowsableState.Advanced)]
2682 [Browsable(false)]
2683 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2684 protected bool ShowKeyboardCues {
2685 get {
2686 return true;
2689 #endregion // Protected Instance Properties
2691 #region Public Static Methods
2692 [EditorBrowsable(EditorBrowsableState.Advanced)]
2693 public static Control FromChildHandle(IntPtr handle) {
2694 return Control.ControlNativeWindow.ControlFromChildHandle (handle);
2697 [EditorBrowsable(EditorBrowsableState.Advanced)]
2698 public static Control FromHandle(IntPtr handle) {
2699 return Control.ControlNativeWindow.ControlFromHandle(handle);
2702 public static bool IsMnemonic(char charCode, string text) {
2703 int amp;
2705 amp = text.IndexOf('&');
2707 if (amp != -1) {
2708 if (amp + 1 < text.Length) {
2709 if (text[amp + 1] != '&') {
2710 if (Char.ToUpper(charCode) == Char.ToUpper(text.ToCharArray(amp + 1, 1)[0])) {
2711 return true;
2716 return false;
2718 #endregion
2720 #region Protected Static Methods
2721 [EditorBrowsable(EditorBrowsableState.Advanced)]
2722 protected static bool ReflectMessage(IntPtr hWnd, ref Message m) {
2723 Control c;
2725 c = Control.FromHandle(hWnd);
2727 if (c != null) {
2728 c.WndProc(ref m);
2729 return true;
2731 return false;
2733 #endregion
2735 #region Public Instance Methods
2736 [EditorBrowsable(EditorBrowsableState.Advanced)]
2737 public IAsyncResult BeginInvoke(Delegate method) {
2738 object [] prms = null;
2739 if (method is EventHandler)
2740 prms = new object [] { this, EventArgs.Empty };
2741 return BeginInvokeInternal(method, prms, false);
2744 [EditorBrowsable(EditorBrowsableState.Advanced)]
2745 public IAsyncResult BeginInvoke (Delegate method, object[] args) {
2746 return BeginInvokeInternal (method, args, false);
2749 public void BringToFront() {
2750 if (parent != null) {
2751 parent.child_controls.SetChildIndex(this, 0);
2752 parent.Refresh();
2753 } else {
2754 XplatUI.SetZOrder(Handle, IntPtr.Zero, false, false);
2758 public bool Contains(Control ctl) {
2759 while (ctl != null) {
2760 ctl = ctl.parent;
2761 if (ctl == this) {
2762 return true;
2765 return false;
2768 public void CreateControl() {
2769 if (is_disposed) {
2770 throw new ObjectDisposedException(GetType().FullName.ToString());
2772 if (is_created) {
2773 return;
2776 if (!IsHandleCreated) {
2777 CreateHandle();
2780 if (!is_created) {
2781 is_created = true;
2784 Control [] controls = child_controls.GetAllControls ();
2785 for (int i=0; i<controls.Length; i++) {
2786 controls [i].CreateControl ();
2789 UpdateChildrenZOrder();
2791 if (binding_context == null) { // seem to be sent whenever it's null?
2792 OnBindingContextChanged(EventArgs.Empty);
2795 OnCreateControl();
2798 public Graphics CreateGraphics() {
2799 if (!IsHandleCreated) {
2800 this.CreateHandle();
2802 return Graphics.FromHwnd(this.window.Handle);
2805 public DragDropEffects DoDragDrop(object data, DragDropEffects allowedEffects) {
2806 return XplatUI.StartDrag(this.window.Handle, data, allowedEffects);
2809 [EditorBrowsable(EditorBrowsableState.Advanced)]
2810 public object EndInvoke (IAsyncResult async_result) {
2811 AsyncMethodResult result = (AsyncMethodResult) async_result;
2812 return result.EndInvoke ();
2815 public Form FindForm() {
2816 Control c;
2818 c = this;
2819 while (c != null) {
2820 if (c is Form) {
2821 return (Form)c;
2823 c = c.Parent;
2825 return null;
2828 public bool Focus() {
2829 if (CanFocus && IsHandleCreated && !has_focus && !is_focusing) {
2830 is_focusing = true;
2831 Select(this);
2832 is_focusing = false;
2834 return has_focus;
2837 public Control GetChildAtPoint(Point pt) {
2838 // Microsoft's version of this function doesn't seem to work, so I can't check
2839 // if we only consider children or also grandchildren, etc.
2840 // I'm gonna say 'children only'
2841 for (int i=0; i<child_controls.Count; i++) {
2842 if (child_controls[i].Bounds.Contains(pt)) {
2843 return child_controls[i];
2846 return null;
2849 public IContainerControl GetContainerControl() {
2850 Control current = this;
2852 while (current!=null) {
2853 if ((current is IContainerControl) && ((current.control_style & ControlStyles.ContainerControl)!=0)) {
2854 return (IContainerControl)current;
2856 current = current.parent;
2858 return null;
2861 public Control GetNextControl(Control ctl, bool forward) {
2863 if (!this.Contains(ctl)) {
2864 ctl = this;
2867 if (forward) {
2868 ctl = FindControlForward(this, ctl);
2870 else {
2871 ctl = FindControlBackward(this, ctl);
2874 if (ctl != this) {
2875 return ctl;
2877 return null;
2880 #if NET_2_0
2881 public virtual Size GetPreferredSize (Size proposedSize) {
2882 return preferred_size;
2884 #endif
2886 public void Hide() {
2887 this.Visible = false;
2890 public void Invalidate() {
2891 Invalidate(ClientRectangle, false);
2894 public void Invalidate(bool invalidateChildren) {
2895 Invalidate(ClientRectangle, invalidateChildren);
2898 public void Invalidate(System.Drawing.Rectangle rc) {
2899 Invalidate(rc, false);
2902 public void Invalidate(System.Drawing.Rectangle rc, bool invalidateChildren) {
2903 if (!IsHandleCreated || !Visible || rc.Width == 0 || rc.Height == 0) {
2904 return;
2907 NotifyInvalidate(rc);
2909 XplatUI.Invalidate(Handle, rc, false);
2911 if (invalidateChildren) {
2912 Control [] controls = child_controls.GetAllControls ();
2913 for (int i=0; i<controls.Length; i++)
2914 controls [i].Invalidate ();
2916 OnInvalidated(new InvalidateEventArgs(rc));
2919 public void Invalidate(System.Drawing.Region region) {
2920 Invalidate(region, false);
2923 public void Invalidate(System.Drawing.Region region, bool invalidateChildren) {
2924 RectangleF bounds = region.GetBounds (CreateGraphics ());
2925 Invalidate (new Rectangle ((int) bounds.X, (int) bounds.Y, (int) bounds.Width, (int) bounds.Height),
2926 invalidateChildren);
2929 public object Invoke (Delegate method) {
2930 object [] prms = null;
2931 if (method is EventHandler)
2932 prms = new object [] { this, EventArgs.Empty };
2934 return Invoke(method, prms);
2937 public object Invoke (Delegate method, object[] args) {
2938 if (!this.InvokeRequired) {
2939 return method.DynamicInvoke(args);
2942 IAsyncResult result = BeginInvoke (method, args);
2943 return EndInvoke(result);
2946 internal object InvokeInternal (Delegate method, bool disposing) {
2947 return InvokeInternal(method, null, disposing);
2950 internal object InvokeInternal (Delegate method, object[] args, bool disposing) {
2951 if (!this.InvokeRequired) {
2952 return method.DynamicInvoke(args);
2955 IAsyncResult result = BeginInvokeInternal (method, args, disposing);
2956 return EndInvoke(result);
2959 [EditorBrowsable(EditorBrowsableState.Advanced)]
2960 public void PerformLayout() {
2961 PerformLayout(null, null);
2964 #if !NET_2_0
2965 private void SetImplicitBounds (int x, int y, int width, int height)
2967 Rectangle saved_bounds = explicit_bounds;
2968 SetBounds (x, y, width, height);
2969 explicit_bounds = saved_bounds;
2971 #endif
2973 [EditorBrowsable(EditorBrowsableState.Advanced)]
2974 public void PerformLayout(Control affectedControl, string affectedProperty) {
2975 LayoutEventArgs levent = new LayoutEventArgs(affectedControl, affectedProperty);
2977 if (layout_suspended > 0) {
2978 layout_pending = true;
2979 return;
2982 layout_pending = false;
2984 // Prevent us from getting messed up
2985 layout_suspended++;
2987 // Perform all Dock and Anchor calculations
2988 try {
2990 #if NET_2_0
2991 this.layout_engine.Layout(this, levent);
2992 #else
2993 // This has been moved to Layout/DefaultLayout.cs for 2.0, please duplicate any changes/fixes there.
2994 Control child;
2995 AnchorStyles anchor;
2996 Rectangle space;
2998 space = DisplayRectangle;
3000 // Deal with docking; go through in reverse, MS docs say that lowest Z-order is closest to edge
3001 Control [] controls = child_controls.GetAllControls ();
3002 for (int i = controls.Length - 1; i >= 0; i--) {
3003 child = controls [i];
3005 if (!child.Visible) {
3006 continue;
3009 switch (child.Dock) {
3010 case DockStyle.None: {
3011 // Do nothing
3012 break;
3015 case DockStyle.Left: {
3016 child.SetImplicitBounds(space.Left, space.Y, child.Width, space.Height);
3017 space.X+=child.Width;
3018 space.Width-=child.Width;
3019 break;
3022 case DockStyle.Top: {
3023 child.SetImplicitBounds(space.Left, space.Y, space.Width, child.Height);
3024 space.Y+=child.Height;
3025 space.Height-=child.Height;
3026 break;
3029 case DockStyle.Right: {
3030 child.SetImplicitBounds(space.Right-child.Width, space.Y, child.Width, space.Height);
3031 space.Width-=child.Width;
3032 break;
3035 case DockStyle.Bottom: {
3036 child.SetImplicitBounds(space.Left, space.Bottom-child.Height, space.Width, child.Height);
3037 space.Height-=child.Height;
3038 break;
3043 for (int i = controls.Length - 1; i >= 0; i--) {
3044 child=controls[i];
3046 //if (child.Visible && (child.Dock == DockStyle.Fill)) {
3047 if (child.Dock == DockStyle.Fill) {
3048 child.SetImplicitBounds(space.Left, space.Top, space.Width, space.Height);
3052 space = DisplayRectangle;
3054 for (int i=0; i < controls.Length; i++) {
3055 int left;
3056 int top;
3057 int width;
3058 int height;
3060 child = controls[i];
3062 // If the control is docked we don't need to do anything
3063 if (child.Dock != DockStyle.None) {
3064 continue;
3067 anchor = child.Anchor;
3069 left = child.Left;
3070 top = child.Top;
3071 width = child.Width;
3072 height = child.Height;
3074 if ((anchor & AnchorStyles.Left) !=0 ) {
3075 if ((anchor & AnchorStyles.Right) != 0) {
3076 width = space.Width - child.dist_right - left;
3077 } else {
3078 ; // Left anchored only, nothing to be done
3080 } else if ((anchor & AnchorStyles.Right) != 0) {
3081 left = space.Width - child.dist_right - width;
3082 } else {
3083 // left+=diff_width/2 will introduce rounding errors (diff_width removed from svn after r51780)
3084 // This calculates from scratch every time:
3085 left = child.dist_left + (space.Width - (child.dist_left + width + child.dist_right)) / 2;
3088 if ((anchor & AnchorStyles.Top) !=0 ) {
3089 if ((anchor & AnchorStyles.Bottom) != 0) {
3090 height = space.Height - child.dist_bottom - top;
3091 } else {
3092 ; // Top anchored only, nothing to be done
3094 } else if ((anchor & AnchorStyles.Bottom) != 0) {
3095 top = space.Height - child.dist_bottom - height;
3096 } else {
3097 // top += diff_height/2 will introduce rounding errors (diff_height removed from after r51780)
3098 // This calculates from scratch every time:
3099 top = child.dist_top + (space.Height - (child.dist_top + height + child.dist_bottom)) / 2;
3102 // Sanity
3103 if (width < 0) {
3104 width=0;
3107 if (height < 0) {
3108 height=0;
3111 child.SetImplicitBounds(left, top, width, height);
3113 #endif
3115 // Let everyone know
3116 OnLayout(levent);
3119 // Need to make sure we decremend layout_suspended
3120 finally {
3121 layout_suspended--;
3125 public Point PointToClient (Point p) {
3126 int x = p.X;
3127 int y = p.Y;
3129 XplatUI.ScreenToClient (Handle, ref x, ref y);
3131 return new Point (x, y);
3134 public Point PointToScreen(Point p) {
3135 int x = p.X;
3136 int y = p.Y;
3138 XplatUI.ClientToScreen(Handle, ref x, ref y);
3140 return new Point(x, y);
3143 public virtual bool PreProcessMessage(ref Message msg) {
3144 return InternalPreProcessMessage (ref msg);
3147 internal virtual bool InternalPreProcessMessage (ref Message msg) {
3148 Keys key_data;
3150 if ((msg.Msg == (int)Msg.WM_KEYDOWN) || (msg.Msg == (int)Msg.WM_SYSKEYDOWN)) {
3151 key_data = (Keys)msg.WParam.ToInt32() | XplatUI.State.ModifierKeys;
3153 if (!ProcessCmdKey(ref msg, key_data)) {
3154 if (IsInputKey(key_data)) {
3155 return false;
3158 return ProcessDialogKey(key_data);
3161 return true;
3162 } else if (msg.Msg == (int)Msg.WM_CHAR) {
3163 if (IsInputChar((char)msg.WParam)) {
3164 return false;
3166 return ProcessDialogChar((char)msg.WParam);
3167 } else if (msg.Msg == (int)Msg.WM_SYSCHAR) {
3168 return ProcessDialogChar((char)msg.WParam);
3170 return false;
3173 public Rectangle RectangleToClient(Rectangle r) {
3174 return new Rectangle(PointToClient(r.Location), r.Size);
3177 public Rectangle RectangleToScreen(Rectangle r) {
3178 return new Rectangle(PointToScreen(r.Location), r.Size);
3181 public virtual void Refresh() {
3182 if (IsHandleCreated == true) {
3183 Invalidate();
3184 XplatUI.UpdateWindow(window.Handle);
3186 Control [] controls = child_controls.GetAllControls ();
3187 for (int i=0; i < controls.Length; i++) {
3188 controls[i].Refresh();
3194 [EditorBrowsable(EditorBrowsableState.Never)]
3195 public virtual void ResetBackColor() {
3196 BackColor = Color.Empty;
3199 [EditorBrowsable(EditorBrowsableState.Never)]
3200 public void ResetBindings() {
3201 data_bindings.Clear();
3204 [EditorBrowsable(EditorBrowsableState.Never)]
3205 public virtual void ResetCursor() {
3206 Cursor = null;
3209 [EditorBrowsable(EditorBrowsableState.Never)]
3210 public virtual void ResetFont() {
3211 font = null;
3214 [EditorBrowsable(EditorBrowsableState.Never)]
3215 public virtual void ResetForeColor() {
3216 foreground_color = Color.Empty;
3219 [EditorBrowsable(EditorBrowsableState.Never)]
3220 public void ResetImeMode() {
3221 ime_mode = DefaultImeMode;
3224 [EditorBrowsable(EditorBrowsableState.Never)]
3225 public virtual void ResetRightToLeft() {
3226 right_to_left = RightToLeft.Inherit;
3229 public virtual void ResetText() {
3230 text = String.Empty;
3233 public void ResumeLayout() {
3234 ResumeLayout (true);
3237 public void ResumeLayout(bool performLayout) {
3238 if (layout_suspended > 0) {
3239 layout_suspended--;
3242 if (layout_suspended == 0) {
3243 Control [] controls = child_controls.GetAllControls ();
3244 for (int i=0; i<controls.Length; i++) {
3245 controls [i].UpdateDistances ();
3248 if (performLayout && layout_pending) {
3249 PerformLayout();
3254 public void Scale(float ratio) {
3255 ScaleCore(ratio, ratio);
3258 public void Scale(float dx, float dy) {
3259 ScaleCore(dx, dy);
3262 #if NET_2_0
3263 public void Scale(SizeF factor) {
3264 ScaleCore(factor.Width, factor.Height);
3266 #endif
3268 public void Select() {
3269 Select(false, false);
3272 #if DebugFocus
3273 private void printTree(Control c, string t) {
3274 foreach(Control i in c.child_controls) {
3275 Console.WriteLine("{2}{0}.TabIndex={1}", i, i.tab_index, t);
3276 printTree(i, t+"\t");
3279 #endif
3280 public bool SelectNextControl(Control ctl, bool forward, bool tabStopOnly, bool nested, bool wrap) {
3281 Control c;
3283 #if DebugFocus
3284 Console.WriteLine("{0}", this.FindForm());
3285 printTree(this, "\t");
3286 #endif
3288 if (!this.Contains(ctl) || (!nested && (ctl.parent != this))) {
3289 ctl = null;
3291 c = ctl;
3292 do {
3293 c = GetNextControl(c, forward);
3294 if (c == null) {
3295 if (wrap) {
3296 wrap = false;
3297 continue;
3299 break;
3302 if (c.CanSelect && ((c.parent == this) || nested) && (c.tab_stop || !tabStopOnly)) {
3303 c.Select (true, true);
3304 return true;
3306 } while (c != ctl); // If we wrap back to ourselves we stop
3308 return false;
3311 public void SendToBack() {
3312 if (parent != null) {
3313 parent.child_controls.SetChildIndex(this, parent.child_controls.Count);
3317 public void SetBounds(int x, int y, int width, int height) {
3318 SetBounds(x, y, width, height, BoundsSpecified.All);
3321 public void SetBounds(int x, int y, int width, int height, BoundsSpecified specified) {
3322 if ((specified & BoundsSpecified.X) != BoundsSpecified.X) {
3323 x = Left;
3326 if ((specified & BoundsSpecified.Y) != BoundsSpecified.Y) {
3327 y = Top;
3330 if ((specified & BoundsSpecified.Width) != BoundsSpecified.Width) {
3331 width = Width;
3334 if ((specified & BoundsSpecified.Height) != BoundsSpecified.Height) {
3335 height = Height;
3338 SetBoundsCore(x, y, width, height, specified);
3339 if (parent != null) {
3340 parent.PerformLayout(this, "Bounds");
3344 public void Show() {
3345 if (!is_created) {
3346 this.CreateControl();
3349 this.Visible=true;
3352 public void SuspendLayout() {
3353 layout_suspended++;
3356 public void Update() {
3357 if (IsHandleCreated) {
3358 XplatUI.UpdateWindow(window.Handle);
3361 #endregion // Public Instance Methods
3363 #region Protected Instance Methods
3364 [EditorBrowsable(EditorBrowsableState.Advanced)]
3365 [MonoTODO("Implement this and tie it into Control.ControlAccessibleObject.NotifyClients")]
3366 protected void AccessibilityNotifyClients(AccessibleEvents accEvent, int childID) {
3367 throw new NotImplementedException();
3370 [EditorBrowsable(EditorBrowsableState.Advanced)]
3371 protected virtual AccessibleObject CreateAccessibilityInstance() {
3372 return new Control.ControlAccessibleObject(this);
3375 [EditorBrowsable(EditorBrowsableState.Advanced)]
3376 protected virtual ControlCollection CreateControlsInstance() {
3377 return new ControlCollection(this);
3380 [EditorBrowsable(EditorBrowsableState.Advanced)]
3381 protected virtual void CreateHandle() {
3382 if (IsDisposed) {
3383 throw new ObjectDisposedException(GetType().FullName.ToString());
3386 if (IsHandleCreated && !is_recreating) {
3387 return;
3390 window.CreateHandle(CreateParams);
3392 if (window.Handle != IntPtr.Zero) {
3393 lock (Control.controls) {
3394 if (!Control.controls.Contains(window.Handle)) {
3395 Control.controls.Add(this);
3399 creator_thread = Thread.CurrentThread;
3401 XplatUI.EnableWindow(window.Handle, is_enabled);
3402 XplatUI.SetVisible(window.Handle, is_visible, true);
3404 if (clip_region != null) {
3405 XplatUI.SetClipRegion(Handle, clip_region);
3408 // Set our handle with our parent
3409 if ((parent != null) && (parent.IsHandleCreated)) {
3410 XplatUI.SetParent(window.Handle, parent.Handle);
3413 // Set our handle as parent for our children
3414 Control [] children;
3416 children = child_controls.GetAllControls ();
3417 for (int i = 0; i < children.Length; i++ ) {
3418 if (!children[i].RecreatingHandle)
3419 XplatUI.SetParent(children[i].Handle, window.Handle);
3422 UpdateStyles();
3423 XplatUI.SetAllowDrop (Handle, allow_drop);
3425 // Find out where the window manager placed us
3426 if ((CreateParams.Style & (int)WindowStyles.WS_CHILD) != 0) {
3427 XplatUI.SetBorderStyle(window.Handle, (FormBorderStyle)border_style);
3429 UpdateBounds();
3431 OnHandleCreated(EventArgs.Empty);
3435 [EditorBrowsable(EditorBrowsableState.Advanced)]
3436 protected virtual void DefWndProc(ref Message m) {
3437 window.DefWndProc(ref m);
3440 [EditorBrowsable(EditorBrowsableState.Advanced)]
3441 protected virtual void DestroyHandle() {
3442 if (IsHandleCreated) {
3443 if (window != null) {
3444 window.DestroyHandle();
3449 protected internal bool GetStyle(ControlStyles flag) {
3450 return (control_style & flag) != 0;
3453 protected bool GetTopLevel() {
3454 return is_toplevel;
3457 [EditorBrowsable(EditorBrowsableState.Advanced)]
3458 protected virtual void InitLayout() {
3459 UpdateDistances();
3462 [EditorBrowsable(EditorBrowsableState.Advanced)]
3463 protected void InvokeGotFocus(Control toInvoke, EventArgs e) {
3464 toInvoke.OnGotFocus(e);
3467 [EditorBrowsable(EditorBrowsableState.Advanced)]
3468 protected void InvokeLostFocus(Control toInvoke, EventArgs e) {
3469 toInvoke.OnLostFocus(e);
3472 [EditorBrowsable(EditorBrowsableState.Advanced)]
3473 protected void InvokeOnClick(Control toInvoke, EventArgs e) {
3474 toInvoke.OnClick(e);
3477 protected void InvokePaint(Control toInvoke, PaintEventArgs e) {
3478 toInvoke.OnPaint(e);
3481 protected void InvokePaintBackground(Control toInvoke, PaintEventArgs e) {
3482 toInvoke.OnPaintBackground(e);
3485 protected virtual bool IsInputChar (char charCode) {
3486 return true;
3489 protected virtual bool IsInputKey (Keys keyData) {
3490 // Doc says this one calls IsInputChar; not sure what to do with that
3491 return false;
3494 [EditorBrowsable(EditorBrowsableState.Advanced)]
3495 protected virtual void NotifyInvalidate(Rectangle invalidatedArea) {
3496 // override me?
3499 protected virtual bool ProcessCmdKey(ref Message msg, Keys keyData) {
3500 if ((context_menu != null) && context_menu.ProcessCmdKey(ref msg, keyData)) {
3501 return true;
3504 if (parent != null) {
3505 return parent.ProcessCmdKey(ref msg, keyData);
3508 return false;
3511 protected virtual bool ProcessDialogChar(char charCode) {
3512 if (parent != null) {
3513 return parent.ProcessDialogChar (charCode);
3516 return false;
3519 protected virtual bool ProcessDialogKey (Keys keyData) {
3520 if (parent != null) {
3521 return parent.ProcessDialogKey (keyData);
3524 return false;
3527 protected virtual bool ProcessKeyEventArgs (ref Message msg)
3529 KeyEventArgs key_event;
3531 switch (msg.Msg) {
3532 case (int)Msg.WM_SYSKEYDOWN:
3533 case (int)Msg.WM_KEYDOWN: {
3534 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
3535 OnKeyDown (key_event);
3536 return key_event.Handled;
3539 case (int)Msg.WM_SYSKEYUP:
3540 case (int)Msg.WM_KEYUP: {
3541 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
3542 OnKeyUp (key_event);
3543 return key_event.Handled;
3546 case (int)Msg.WM_SYSCHAR:
3547 case (int)Msg.WM_CHAR: {
3548 KeyPressEventArgs key_press_event;
3550 key_press_event = new KeyPressEventArgs((char)msg.WParam);
3551 OnKeyPress(key_press_event);
3552 #if NET_2_0
3553 msg.WParam = (IntPtr)key_press_event.KeyChar;
3554 #endif
3555 return key_press_event.Handled;
3558 default: {
3559 break;
3563 return false;
3566 protected internal virtual bool ProcessKeyMessage(ref Message msg) {
3567 if (parent != null) {
3568 if (parent.ProcessKeyPreview(ref msg)) {
3569 return true;
3573 return ProcessKeyEventArgs(ref msg);
3576 protected virtual bool ProcessKeyPreview(ref Message msg) {
3577 if (parent != null) {
3578 return parent.ProcessKeyPreview(ref msg);
3581 return false;
3584 protected virtual bool ProcessMnemonic(char charCode) {
3585 // override me
3586 return false;
3589 [EditorBrowsable(EditorBrowsableState.Advanced)]
3590 protected void RaiseDragEvent(object key, DragEventArgs e) {
3591 // MS Internal
3594 [EditorBrowsable(EditorBrowsableState.Advanced)]
3595 protected void RaiseKeyEvent(object key, KeyEventArgs e) {
3596 // MS Internal
3599 [EditorBrowsable(EditorBrowsableState.Advanced)]
3600 protected void RaiseMouseEvent(object key, MouseEventArgs e) {
3601 // MS Internal
3604 [EditorBrowsable(EditorBrowsableState.Advanced)]
3605 protected void RaisePaintEvent(object key, PaintEventArgs e) {
3606 // MS Internal
3609 private void SetIsRecreating ()
3611 is_recreating=true;
3613 foreach (Control c in Controls.GetAllControls()) {
3614 c.SetIsRecreating ();
3618 [EditorBrowsable(EditorBrowsableState.Advanced)]
3619 protected void RecreateHandle() {
3620 #if DebugRecreate
3621 Console.WriteLine("Recreating control {0}", XplatUI.Window(window.Handle));
3622 #endif
3624 SetIsRecreating ();
3626 if (IsHandleCreated) {
3627 #if DebugRecreate
3628 Console.WriteLine(" + handle is created, destroying it.");
3629 #endif
3630 DestroyHandle();
3631 // WM_DESTROY will CreateHandle for us
3632 } else {
3633 #if DebugRecreate
3634 Console.WriteLine(" + handle is not created, creating it.");
3635 #endif
3636 if (!is_created) {
3637 CreateControl();
3638 } else {
3639 CreateHandle();
3642 is_recreating = false;
3643 #if DebugRecreate
3644 Console.WriteLine (" + new handle = {0:X}", Handle.ToInt32());
3645 #endif
3650 [EditorBrowsable(EditorBrowsableState.Advanced)]
3651 protected void ResetMouseEventArgs() {
3652 // MS Internal
3655 [EditorBrowsable(EditorBrowsableState.Advanced)]
3656 protected ContentAlignment RtlTranslateAlignment(ContentAlignment align) {
3657 if (right_to_left == RightToLeft.No) {
3658 return align;
3661 switch (align) {
3662 case ContentAlignment.TopLeft: {
3663 return ContentAlignment.TopRight;
3666 case ContentAlignment.TopRight: {
3667 return ContentAlignment.TopLeft;
3670 case ContentAlignment.MiddleLeft: {
3671 return ContentAlignment.MiddleRight;
3674 case ContentAlignment.MiddleRight: {
3675 return ContentAlignment.MiddleLeft;
3678 case ContentAlignment.BottomLeft: {
3679 return ContentAlignment.BottomRight;
3682 case ContentAlignment.BottomRight: {
3683 return ContentAlignment.BottomLeft;
3686 default: {
3687 // if it's center it doesn't change
3688 return align;
3693 [EditorBrowsable(EditorBrowsableState.Advanced)]
3694 protected HorizontalAlignment RtlTranslateAlignment(HorizontalAlignment align) {
3695 if ((right_to_left == RightToLeft.No) || (align == HorizontalAlignment.Center)) {
3696 return align;
3699 if (align == HorizontalAlignment.Left) {
3700 return HorizontalAlignment.Right;
3703 // align must be HorizontalAlignment.Right
3704 return HorizontalAlignment.Left;
3707 [EditorBrowsable(EditorBrowsableState.Advanced)]
3708 protected LeftRightAlignment RtlTranslateAlignment(LeftRightAlignment align) {
3709 if (right_to_left == RightToLeft.No) {
3710 return align;
3713 if (align == LeftRightAlignment.Left) {
3714 return LeftRightAlignment.Right;
3717 // align must be LeftRightAlignment.Right;
3718 return LeftRightAlignment.Left;
3721 [EditorBrowsable(EditorBrowsableState.Advanced)]
3722 protected ContentAlignment RtlTranslateContent(ContentAlignment align) {
3723 return RtlTranslateAlignment(align);
3726 [EditorBrowsable(EditorBrowsableState.Advanced)]
3727 protected HorizontalAlignment RtlTranslateHorizontal(HorizontalAlignment align) {
3728 return RtlTranslateAlignment(align);
3731 [EditorBrowsable(EditorBrowsableState.Advanced)]
3732 protected LeftRightAlignment RtlTranslateLeftRight(LeftRightAlignment align) {
3733 return RtlTranslateAlignment(align);
3736 [EditorBrowsable(EditorBrowsableState.Advanced)]
3737 protected virtual void ScaleCore(float dx, float dy) {
3738 Point location;
3739 Size size;
3741 SuspendLayout();
3743 location = new Point((int)(Left * dx), (int)(Top * dy));
3744 size = this.ClientSize;
3746 if (!GetStyle(ControlStyles.FixedWidth)) {
3747 size.Width = (int)(size.Width * dx);
3750 if (!GetStyle(ControlStyles.FixedHeight)) {
3751 size.Height = (int)(size.Height * dy);
3754 SetBounds(location.X, location.Y, size.Width, size.Height, BoundsSpecified.All);
3756 /* Now scale our children */
3757 Control [] controls = child_controls.GetAllControls ();
3758 for (int i=0; i < controls.Length; i++) {
3759 controls[i].Scale(dx, dy);
3762 ResumeLayout();
3765 protected virtual void Select(bool directed, bool forward) {
3766 IContainerControl container;
3768 container = GetContainerControl();
3769 if (container != null)
3770 container.ActiveControl = this;
3773 [EditorBrowsable(EditorBrowsableState.Advanced)]
3774 protected virtual void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
3775 // SetBoundsCore updates the Win32 control itself. UpdateBounds updates the controls variables and fires events, I'm guessing - pdb
3776 if (IsHandleCreated) {
3777 XplatUI.SetWindowPos(Handle, x, y, width, height);
3779 // Win32 automatically changes negative width/height to 0.
3780 // The control has already been sent a WM_WINDOWPOSCHANGED message and it has the correct
3781 // data, but it'll be overwritten when we call UpdateBounds unless we get the updated
3782 // size.
3783 if (width < 0 || height < 0) {
3784 int cw, ch, ix, iy;
3785 XplatUI.GetWindowPos(Handle, this is Form, out ix, out iy, out width, out height, out cw, out ch);
3789 UpdateBounds(x, y, width, height);
3791 UpdateDistances();
3794 [EditorBrowsable(EditorBrowsableState.Advanced)]
3795 protected virtual void SetClientSizeCore(int x, int y) {
3796 // Calculate the actual window size from the client size (it usually stays the same or grows)
3797 Rectangle ClientRect;
3798 Rectangle WindowRect;
3799 CreateParams cp;
3801 ClientRect = new Rectangle(0, 0, x, y);
3802 cp = this.CreateParams;
3804 if (XplatUI.CalculateWindowRect(ref ClientRect, cp.Style, cp.ExStyle, null, out WindowRect)==false) {
3805 return;
3808 SetBounds(bounds.X, bounds.Y, WindowRect.Width, WindowRect.Height, BoundsSpecified.Size);
3811 [EditorBrowsable(EditorBrowsableState.Advanced)]
3812 protected internal void SetStyle(ControlStyles flag, bool value) {
3813 if (value) {
3814 control_style |= flag;
3815 } else {
3816 control_style &= ~flag;
3820 protected void SetTopLevel(bool value) {
3821 if ((GetTopLevel() != value) && (parent != null)) {
3822 throw new Exception();
3825 if (this is Form) {
3826 if (value == true) {
3827 if (!Visible) {
3828 Visible = true;
3830 } else {
3831 if (Visible) {
3832 Visible = false;
3836 is_toplevel = value;
3839 protected virtual void SetVisibleCore(bool value) {
3840 if (value!=is_visible) {
3841 if (value && (window.Handle == IntPtr.Zero) || !is_created) {
3842 CreateControl();
3845 is_visible=value;
3847 if (IsHandleCreated) {
3848 XplatUI.SetVisible(Handle, value, true);
3849 // Explicitly move Toplevel windows to where we want them;
3850 // apparently moving unmapped toplevel windows doesn't work
3851 if (is_visible && (this is Form)) {
3852 XplatUI.SetWindowPos(window.Handle, bounds.X, bounds.Y, bounds.Width, bounds.Height);
3856 OnVisibleChanged(EventArgs.Empty);
3858 if (value == false && parent != null && Focused) {
3859 Control container;
3861 // Need to start at parent, GetContainerControl might return ourselves if we're a container
3862 container = (Control)parent.GetContainerControl();
3863 if (container != null) {
3864 container.SelectNextControl(this, true, true, true, true);
3868 if (parent != null) {
3869 parent.PerformLayout(this, "visible");
3870 } else {
3871 PerformLayout(this, "visible");
3876 [EditorBrowsable(EditorBrowsableState.Advanced)]
3877 protected void UpdateBounds() {
3878 int x;
3879 int y;
3880 int width;
3881 int height;
3882 int client_width;
3883 int client_height;
3885 if (!IsHandleCreated) {
3886 CreateHandle();
3889 XplatUI.GetWindowPos(this.Handle, this is Form, out x, out y, out width, out height, out client_width, out client_height);
3891 UpdateBounds(x, y, width, height, client_width, client_height);
3894 [EditorBrowsable(EditorBrowsableState.Advanced)]
3895 protected void UpdateBounds(int x, int y, int width, int height) {
3896 CreateParams cp;
3897 Rectangle rect;
3899 // Calculate client rectangle
3900 rect = new Rectangle(0, 0, 0, 0);
3901 cp = CreateParams;
3903 XplatUI.CalculateWindowRect(ref rect, cp.Style, cp.ExStyle, cp.menu, out rect);
3904 UpdateBounds(x, y, width, height, width - (rect.Right - rect.Left), height - (rect.Bottom - rect.Top));
3907 [EditorBrowsable(EditorBrowsableState.Advanced)]
3908 protected void UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) {
3909 // UpdateBounds only seems to set our sizes and fire events but not update the GUI window to match
3910 bool moved = false;
3911 bool resized = false;
3913 // Needed to generate required notifications
3914 if ((this.bounds.X!=x) || (this.bounds.Y!=y)) {
3915 moved=true;
3918 if ((this.Bounds.Width!=width) || (this.Bounds.Height!=height)) {
3919 resized=true;
3922 bounds.X=x;
3923 bounds.Y=y;
3924 bounds.Width=width;
3925 bounds.Height=height;
3927 // Assume explicit bounds set. SetImplicitBounds will restore old bounds
3928 explicit_bounds = bounds;
3930 client_size.Width=clientWidth;
3931 client_size.Height=clientHeight;
3933 if (moved) {
3934 OnLocationChanged(EventArgs.Empty);
3937 if (resized) {
3938 OnSizeChanged(EventArgs.Empty);
3942 [EditorBrowsable(EditorBrowsableState.Advanced)]
3943 protected void UpdateStyles() {
3944 if (!IsHandleCreated) {
3945 return;
3948 XplatUI.SetWindowStyle(window.Handle, CreateParams);
3949 OnStyleChanged(EventArgs.Empty);
3952 private void UpdateZOrderOfChild(Control child) {
3953 if (IsHandleCreated && child.IsHandleCreated && (child.parent == this)) {
3954 int index;
3956 index = child_controls.IndexOf(child);
3958 if (index > 0) {
3959 XplatUI.SetZOrder(child.Handle, child_controls[index - 1].Handle, false, false);
3960 } else {
3961 XplatUI.SetZOrder(child.Handle, IntPtr.Zero, true, false);
3966 private void UpdateChildrenZOrder() {
3967 Control [] controls;
3969 if (!IsHandleCreated) {
3970 return;
3973 controls = child_controls.GetAllControls ();
3974 for (int i = 1; i < controls.Length; i++ ) {
3975 XplatUI.SetZOrder(controls[i].Handle, controls[i-1].Handle, false, false);
3979 [EditorBrowsable(EditorBrowsableState.Advanced)]
3980 protected void UpdateZOrder() {
3981 if (parent != null) {
3982 parent.UpdateZOrderOfChild(this);
3986 protected virtual void WndProc(ref Message m) {
3987 #if debug
3988 Console.WriteLine("Control {0} received message {1}", window.Handle == IntPtr.Zero ? this.Text : XplatUI.Window(window.Handle), m.ToString ());
3989 #endif
3990 if ((this.control_style & ControlStyles.EnableNotifyMessage) != 0) {
3991 OnNotifyMessage(m);
3994 switch((Msg)m.Msg) {
3995 case Msg.WM_DESTROY: {
3996 OnHandleDestroyed(EventArgs.Empty);
3997 #if DebugRecreate
3998 IntPtr handle = window.Handle;
3999 #endif
4000 window.InvalidateHandle();
4002 if (is_recreating) {
4003 #if DebugRecreate
4004 Console.WriteLine ("Creating handle for {0:X}", handle.ToInt32());
4005 #endif
4006 CreateHandle();
4007 #if DebugRecreate
4008 Console.WriteLine (" + new handle = {0:X}", Handle.ToInt32());
4009 #endif
4010 is_recreating = false;
4012 return;
4015 case Msg.WM_WINDOWPOSCHANGED: {
4016 if (Visible) {
4017 Rectangle save_bounds = explicit_bounds;
4018 UpdateBounds();
4019 explicit_bounds = save_bounds;
4020 if (GetStyle(ControlStyles.ResizeRedraw)) {
4021 Invalidate();
4024 return;
4027 // Nice description of what should happen when handling WM_PAINT
4028 // can be found here: http://pluralsight.com/wiki/default.aspx/Craig/FlickerFreeControlDrawing.html
4029 // and here http://msdn.microsoft.com/msdnmag/issues/06/03/WindowsFormsPerformance/
4030 case Msg.WM_PAINT: {
4031 PaintEventArgs paint_event;
4033 paint_event = XplatUI.PaintEventStart(Handle, true);
4035 if (paint_event == null) {
4036 return;
4039 if (invalid_region != null && !invalid_region.IsVisible (paint_event.ClipRectangle)) {
4040 // Just blit the previous image
4041 paint_event.Graphics.DrawImage (ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle, GraphicsUnit.Pixel);
4042 XplatUI.PaintEventEnd(Handle, true);
4043 return;
4046 Graphics dc = null;
4047 Graphics back_dc = null;
4048 Bitmap backbuffer = null;
4049 if (ThemeEngine.Current.DoubleBufferingSupported) {
4050 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
4051 backbuffer = ImageBuffer;
4052 back_dc = Graphics.FromImage (backbuffer);
4053 dc = paint_event.SetGraphics (back_dc);
4057 if (!GetStyle(ControlStyles.Opaque)) {
4058 OnPaintBackground(paint_event);
4061 // Button-derived controls choose to ignore their Opaque style, give them a chance to draw their background anyways
4062 OnPaintBackgroundInternal(paint_event);
4064 OnPaintInternal(paint_event);
4065 if (!paint_event.Handled) {
4066 OnPaint(paint_event);
4069 if (ThemeEngine.Current.DoubleBufferingSupported)
4070 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
4071 dc.DrawImage (ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle, GraphicsUnit.Pixel);
4072 paint_event.SetGraphics (dc);
4073 invalid_region.Exclude (paint_event.ClipRectangle);
4074 back_dc.Dispose ();
4075 if (backbuffer != bmp_mem)
4076 backbuffer.Dispose();
4079 XplatUI.PaintEventEnd(Handle, true);
4081 return;
4084 case Msg.WM_ERASEBKGND: {
4085 // The DefWndProc will never have to handle this, we always paint the background in managed code
4086 // In theory this code would look at ControlStyles.AllPaintingInWmPaint and and call OnPaintBackground
4087 // here but it just makes things more complicated...
4088 m.Result = (IntPtr)1;
4089 return;
4092 case Msg.WM_LBUTTONUP: {
4093 MouseEventArgs me;
4095 me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Left,
4096 mouse_clicks,
4097 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4100 HandleClick(mouse_clicks, me);
4101 OnMouseUp (me);
4103 if (InternalCapture) {
4104 InternalCapture = false;
4107 if (mouse_clicks > 1) {
4108 mouse_clicks = 1;
4110 return;
4113 case Msg.WM_LBUTTONDOWN: {
4114 if (CanSelect) {
4115 Select (true, true);
4117 InternalCapture = true;
4118 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4119 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4120 0));
4122 return;
4125 case Msg.WM_LBUTTONDBLCLK: {
4126 InternalCapture = true;
4127 mouse_clicks++;
4128 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4129 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4130 0));
4132 return;
4135 case Msg.WM_MBUTTONUP: {
4136 MouseEventArgs me;
4138 me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Middle,
4139 mouse_clicks,
4140 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4143 HandleClick(mouse_clicks, me);
4144 OnMouseUp (me);
4145 if (InternalCapture) {
4146 InternalCapture = false;
4148 if (mouse_clicks > 1) {
4149 mouse_clicks = 1;
4151 return;
4154 case Msg.WM_MBUTTONDOWN: {
4155 InternalCapture = true;
4156 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4157 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4158 0));
4160 return;
4163 case Msg.WM_MBUTTONDBLCLK: {
4164 InternalCapture = true;
4165 mouse_clicks++;
4166 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4167 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4168 0));
4169 return;
4172 case Msg.WM_RBUTTONUP: {
4173 MouseEventArgs me;
4174 Point pt;
4176 pt = new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()));
4177 pt = PointToScreen(pt);
4179 XplatUI.SendMessage(m.HWnd, Msg.WM_CONTEXTMENU, m.HWnd, (IntPtr)(pt.X + (pt.Y << 16)));
4181 me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Right,
4182 mouse_clicks,
4183 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4186 HandleClick(mouse_clicks, me);
4187 OnMouseUp (me);
4189 if (InternalCapture) {
4190 InternalCapture = false;
4193 if (mouse_clicks > 1) {
4194 mouse_clicks = 1;
4196 return;
4199 case Msg.WM_RBUTTONDOWN: {
4200 InternalCapture = true;
4201 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4202 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4203 0));
4204 return;
4207 case Msg.WM_RBUTTONDBLCLK: {
4208 InternalCapture = true;
4209 mouse_clicks++;
4210 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4211 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4212 0));
4213 return;
4216 case Msg.WM_CONTEXTMENU: {
4217 if (context_menu != null) {
4218 Point pt;
4220 pt = new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()));
4221 context_menu.Show(this, PointToClient(pt));
4222 return;
4225 DefWndProc(ref m);
4226 return;
4229 case Msg.WM_MOUSEWHEEL: {
4230 DefWndProc(ref m);
4231 OnMouseWheel (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4232 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4233 HighOrder(m.WParam.ToInt32())));
4234 return;
4238 case Msg.WM_MOUSEMOVE: {
4239 OnMouseMove (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4240 mouse_clicks,
4241 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4242 0));
4243 return;
4246 case Msg.WM_MOUSE_ENTER: {
4247 if (is_entered) {
4248 return;
4250 is_entered = true;
4251 OnMouseEnter(EventArgs.Empty);
4252 return;
4255 case Msg.WM_MOUSE_LEAVE: {
4256 is_entered=false;
4257 OnMouseLeave(EventArgs.Empty);
4258 return;
4261 case Msg.WM_MOUSEHOVER: {
4262 OnMouseHover(EventArgs.Empty);
4263 return;
4266 case Msg.WM_SYSKEYUP: {
4267 if (ProcessKeyMessage(ref m)) {
4268 m.Result = IntPtr.Zero;
4269 return;
4272 if ((m.WParam.ToInt32() & (int)Keys.KeyCode) == (int)Keys.Menu) {
4273 Form form;
4275 form = FindForm();
4276 if (form != null && form.ActiveMenu != null) {
4277 form.ActiveMenu.ProcessCmdKey(ref m, (Keys)m.WParam.ToInt32());
4281 DefWndProc (ref m);
4282 return;
4285 case Msg.WM_SYSKEYDOWN:
4286 case Msg.WM_KEYDOWN:
4287 case Msg.WM_KEYUP:
4288 case Msg.WM_SYSCHAR:
4289 case Msg.WM_CHAR: {
4290 if (ProcessKeyMessage(ref m)) {
4291 m.Result = IntPtr.Zero;
4292 return;
4294 DefWndProc (ref m);
4295 return;
4298 case Msg.WM_HELP: {
4299 Point mouse_pos;
4300 if (m.LParam != IntPtr.Zero) {
4301 HELPINFO hi;
4303 hi = new HELPINFO();
4305 hi = (HELPINFO) Marshal.PtrToStructure (m.LParam, typeof (HELPINFO));
4306 mouse_pos = new Point(hi.MousePos.x, hi.MousePos.y);
4307 } else {
4308 mouse_pos = Control.MousePosition;
4310 OnHelpRequested(new HelpEventArgs(mouse_pos));
4311 m.Result = (IntPtr)1;
4312 return;
4315 case Msg.WM_KILLFOCUS: {
4316 this.has_focus = false;
4317 OnLostFocusInternal (EventArgs.Empty);
4318 return;
4321 case Msg.WM_SETFOCUS: {
4322 if (!has_focus) {
4323 this.has_focus = true;
4324 OnGotFocusInternal (EventArgs.Empty);
4326 return;
4330 case Msg.WM_SYSCOLORCHANGE: {
4331 ThemeEngine.Current.ResetDefaults();
4332 OnSystemColorsChanged(EventArgs.Empty);
4333 return;
4337 case Msg.WM_SETCURSOR: {
4338 if ((cursor == null) || ((HitTest)(m.LParam.ToInt32() & 0xffff) != HitTest.HTCLIENT)) {
4339 DefWndProc(ref m);
4340 return;
4343 XplatUI.SetCursor(window.Handle, cursor.handle);
4344 m.Result = (IntPtr)1;
4346 return;
4349 default: {
4350 DefWndProc(ref m);
4351 return;
4355 #endregion // Public Instance Methods
4357 #region OnXXX methods
4358 [EditorBrowsable(EditorBrowsableState.Advanced)]
4359 protected virtual void OnBackColorChanged(EventArgs e) {
4360 EventHandler eh = (EventHandler)(Events [BackColorChangedEvent]);
4361 if (eh != null)
4362 eh (this, e);
4363 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackColorChanged(e);
4366 [EditorBrowsable(EditorBrowsableState.Advanced)]
4367 protected virtual void OnBackgroundImageChanged(EventArgs e) {
4368 EventHandler eh = (EventHandler)(Events [BackgroundImageChangedEvent]);
4369 if (eh != null)
4370 eh (this, e);
4371 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackgroundImageChanged(e);
4374 [EditorBrowsable(EditorBrowsableState.Advanced)]
4375 protected virtual void OnBindingContextChanged(EventArgs e) {
4376 CheckDataBindings ();
4377 EventHandler eh = (EventHandler)(Events [BindingContextChangedEvent]);
4378 if (eh != null)
4379 eh (this, e);
4380 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBindingContextChanged(e);
4383 [EditorBrowsable(EditorBrowsableState.Advanced)]
4384 protected virtual void OnCausesValidationChanged(EventArgs e) {
4385 EventHandler eh = (EventHandler)(Events [CausesValidationChangedEvent]);
4386 if (eh != null)
4387 eh (this, e);
4390 [EditorBrowsable(EditorBrowsableState.Advanced)]
4391 protected virtual void OnChangeUICues(UICuesEventArgs e) {
4392 UICuesEventHandler eh = (UICuesEventHandler)(Events [ChangeUICuesEvent]);
4393 if (eh != null)
4394 eh (this, e);
4397 [EditorBrowsable(EditorBrowsableState.Advanced)]
4398 protected virtual void OnClick(EventArgs e) {
4399 EventHandler eh = (EventHandler)(Events [ClickEvent]);
4400 if (eh != null)
4401 eh (this, e);
4404 [EditorBrowsable(EditorBrowsableState.Advanced)]
4405 protected virtual void OnContextMenuChanged(EventArgs e) {
4406 EventHandler eh = (EventHandler)(Events [ContextMenuChangedEvent]);
4407 if (eh != null)
4408 eh (this, e);
4411 [EditorBrowsable(EditorBrowsableState.Advanced)]
4412 protected virtual void OnControlAdded(ControlEventArgs e) {
4413 ControlEventHandler eh = (ControlEventHandler)(Events [ControlAddedEvent]);
4414 if (eh != null)
4415 eh (this, e);
4418 [EditorBrowsable(EditorBrowsableState.Advanced)]
4419 protected virtual void OnControlRemoved(ControlEventArgs e) {
4420 ControlEventHandler eh = (ControlEventHandler)(Events [ControlRemovedEvent]);
4421 if (eh != null)
4422 eh (this, e);
4425 [EditorBrowsable(EditorBrowsableState.Advanced)]
4426 protected virtual void OnCreateControl() {
4427 // Override me!
4430 [EditorBrowsable(EditorBrowsableState.Advanced)]
4431 protected virtual void OnCursorChanged(EventArgs e) {
4432 EventHandler eh = (EventHandler)(Events [CursorChangedEvent]);
4433 if (eh != null)
4434 eh (this, e);
4437 [EditorBrowsable(EditorBrowsableState.Advanced)]
4438 protected virtual void OnDockChanged(EventArgs e) {
4439 EventHandler eh = (EventHandler)(Events [DockChangedEvent]);
4440 if (eh != null)
4441 eh (this, e);
4444 [EditorBrowsable(EditorBrowsableState.Advanced)]
4445 protected virtual void OnDoubleClick(EventArgs e) {
4446 EventHandler eh = (EventHandler)(Events [DoubleClickEvent]);
4447 if (eh != null)
4448 eh (this, e);
4451 [EditorBrowsable(EditorBrowsableState.Advanced)]
4452 protected virtual void OnDragDrop(DragEventArgs drgevent) {
4453 DragEventHandler eh = (DragEventHandler)(Events [DragDropEvent]);
4454 if (eh != null)
4455 eh (this, drgevent);
4458 [EditorBrowsable(EditorBrowsableState.Advanced)]
4459 protected virtual void OnDragEnter(DragEventArgs drgevent) {
4460 DragEventHandler eh = (DragEventHandler)(Events [DragEnterEvent]);
4461 if (eh != null)
4462 eh (this, drgevent);
4465 [EditorBrowsable(EditorBrowsableState.Advanced)]
4466 protected virtual void OnDragLeave(EventArgs e) {
4467 EventHandler eh = (EventHandler)(Events [DragLeaveEvent]);
4468 if (eh != null)
4469 eh (this, e);
4472 [EditorBrowsable(EditorBrowsableState.Advanced)]
4473 protected virtual void OnDragOver(DragEventArgs drgevent) {
4474 DragEventHandler eh = (DragEventHandler)(Events [DragOverEvent]);
4475 if (eh != null)
4476 eh (this, drgevent);
4479 [EditorBrowsable(EditorBrowsableState.Advanced)]
4480 protected virtual void OnEnabledChanged(EventArgs e) {
4481 if (IsHandleCreated) {
4482 if (this is Form) {
4483 if (((Form)this).context == null) {
4484 XplatUI.EnableWindow(window.Handle, Enabled);
4486 } else {
4487 XplatUI.EnableWindow(window.Handle, Enabled);
4489 Refresh();
4492 EventHandler eh = (EventHandler)(Events [EnabledChangedEvent]);
4493 if (eh != null)
4494 eh (this, e);
4496 for (int i=0; i<child_controls.Count; i++) {
4497 child_controls[i].OnParentEnabledChanged(e);
4501 [EditorBrowsable(EditorBrowsableState.Advanced)]
4502 protected virtual void OnEnter(EventArgs e) {
4503 EventHandler eh = (EventHandler)(Events [EnterEvent]);
4504 if (eh != null)
4505 eh (this, e);
4508 [EditorBrowsable(EditorBrowsableState.Advanced)]
4509 protected virtual void OnFontChanged(EventArgs e) {
4510 EventHandler eh = (EventHandler)(Events [FontChangedEvent]);
4511 if (eh != null)
4512 eh (this, e);
4513 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentFontChanged(e);
4516 [EditorBrowsable(EditorBrowsableState.Advanced)]
4517 protected virtual void OnForeColorChanged(EventArgs e) {
4518 EventHandler eh = (EventHandler)(Events [ForeColorChangedEvent]);
4519 if (eh != null)
4520 eh (this, e);
4521 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentForeColorChanged(e);
4524 [EditorBrowsable(EditorBrowsableState.Advanced)]
4525 protected virtual void OnGiveFeedback(GiveFeedbackEventArgs gfbevent) {
4526 GiveFeedbackEventHandler eh = (GiveFeedbackEventHandler)(Events [GiveFeedbackEvent]);
4527 if (eh != null)
4528 eh (this, gfbevent);
4531 [EditorBrowsable(EditorBrowsableState.Advanced)]
4532 protected virtual void OnGotFocus(EventArgs e) {
4533 EventHandler eh = (EventHandler)(Events [GotFocusEvent]);
4534 if (eh != null)
4535 eh (this, e);
4538 [EditorBrowsable(EditorBrowsableState.Advanced)]
4539 protected virtual void OnHandleCreated(EventArgs e) {
4540 EventHandler eh = (EventHandler)(Events [HandleCreatedEvent]);
4541 if (eh != null)
4542 eh (this, e);
4545 [EditorBrowsable(EditorBrowsableState.Advanced)]
4546 protected virtual void OnHandleDestroyed(EventArgs e) {
4547 EventHandler eh = (EventHandler)(Events [HandleDestroyedEvent]);
4548 if (eh != null)
4549 eh (this, e);
4552 [EditorBrowsable(EditorBrowsableState.Advanced)]
4553 protected virtual void OnHelpRequested(HelpEventArgs hevent) {
4554 HelpEventHandler eh = (HelpEventHandler)(Events [HelpRequestedEvent]);
4555 if (eh != null)
4556 eh (this, hevent);
4559 protected virtual void OnImeModeChanged(EventArgs e) {
4560 EventHandler eh = (EventHandler)(Events [ImeModeChangedEvent]);
4561 if (eh != null)
4562 eh (this, e);
4565 [EditorBrowsable(EditorBrowsableState.Advanced)]
4566 protected virtual void OnInvalidated(InvalidateEventArgs e) {
4567 if (ThemeEngine.Current.DoubleBufferingSupported)
4568 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
4569 // should this block be here? seems like it
4570 // would be more at home in
4571 // NotifyInvalidated..
4572 if (e.InvalidRect == ClientRectangle) {
4573 ImageBufferNeedsRedraw ();
4575 else {
4576 // we need this Inflate call here so
4577 // that the border of the rectangle is
4578 // considered Visible (the
4579 // invalid_region.IsVisible call) in
4580 // the WM_PAINT handling below.
4581 Rectangle r = Rectangle.Inflate(e.InvalidRect, 1,1);
4582 if (invalid_region == null)
4583 invalid_region = new Region (r);
4584 else
4585 invalid_region.Union (r);
4589 InvalidateEventHandler eh = (InvalidateEventHandler)(Events [InvalidatedEvent]);
4590 if (eh != null)
4591 eh (this, e);
4594 [EditorBrowsable(EditorBrowsableState.Advanced)]
4595 protected virtual void OnKeyDown(KeyEventArgs e) {
4596 KeyEventHandler eh = (KeyEventHandler)(Events [KeyDownEvent]);
4597 if (eh != null)
4598 eh (this, e);
4601 [EditorBrowsable(EditorBrowsableState.Advanced)]
4602 protected virtual void OnKeyPress(KeyPressEventArgs e) {
4603 KeyPressEventHandler eh = (KeyPressEventHandler)(Events [KeyPressEvent]);
4604 if (eh != null)
4605 eh (this, e);
4608 [EditorBrowsable(EditorBrowsableState.Advanced)]
4609 protected virtual void OnKeyUp(KeyEventArgs e) {
4610 KeyEventHandler eh = (KeyEventHandler)(Events [KeyUpEvent]);
4611 if (eh != null)
4612 eh (this, e);
4615 [EditorBrowsable(EditorBrowsableState.Advanced)]
4616 protected virtual void OnLayout(LayoutEventArgs levent) {
4617 LayoutEventHandler eh = (LayoutEventHandler)(Events [LayoutEvent]);
4618 if (eh != null)
4619 eh (this, levent);
4622 [EditorBrowsable(EditorBrowsableState.Advanced)]
4623 protected virtual void OnLeave(EventArgs e) {
4624 EventHandler eh = (EventHandler)(Events [LeaveEvent]);
4625 if (eh != null)
4626 eh (this, e);
4629 [EditorBrowsable(EditorBrowsableState.Advanced)]
4630 protected virtual void OnLocationChanged(EventArgs e) {
4631 OnMove(e);
4632 EventHandler eh = (EventHandler)(Events [LocationChangedEvent]);
4633 if (eh != null)
4634 eh (this, e);
4637 [EditorBrowsable(EditorBrowsableState.Advanced)]
4638 protected virtual void OnLostFocus(EventArgs e) {
4639 EventHandler eh = (EventHandler)(Events [LostFocusEvent]);
4640 if (eh != null)
4641 eh (this, e);
4644 [EditorBrowsable(EditorBrowsableState.Advanced)]
4645 protected virtual void OnMouseDown(MouseEventArgs e) {
4646 MouseEventHandler eh = (MouseEventHandler)(Events [MouseDownEvent]);
4647 if (eh != null)
4648 eh (this, e);
4651 [EditorBrowsable(EditorBrowsableState.Advanced)]
4652 protected virtual void OnMouseEnter(EventArgs e) {
4653 EventHandler eh = (EventHandler)(Events [MouseEnterEvent]);
4654 if (eh != null)
4655 eh (this, e);
4658 [EditorBrowsable(EditorBrowsableState.Advanced)]
4659 protected virtual void OnMouseHover(EventArgs e) {
4660 EventHandler eh = (EventHandler)(Events [MouseHoverEvent]);
4661 if (eh != null)
4662 eh (this, e);
4665 [EditorBrowsable(EditorBrowsableState.Advanced)]
4666 protected virtual void OnMouseLeave(EventArgs e) {
4667 EventHandler eh = (EventHandler)(Events [MouseLeaveEvent]);
4668 if (eh != null)
4669 eh (this, e);
4672 [EditorBrowsable(EditorBrowsableState.Advanced)]
4673 protected virtual void OnMouseMove(MouseEventArgs e) {
4674 MouseEventHandler eh = (MouseEventHandler)(Events [MouseMoveEvent]);
4675 if (eh != null)
4676 eh (this, e);
4679 [EditorBrowsable(EditorBrowsableState.Advanced)]
4680 protected virtual void OnMouseUp(MouseEventArgs e) {
4681 MouseEventHandler eh = (MouseEventHandler)(Events [MouseUpEvent]);
4682 if (eh != null)
4683 eh (this, e);
4686 [EditorBrowsable(EditorBrowsableState.Advanced)]
4687 protected virtual void OnMouseWheel(MouseEventArgs e) {
4688 MouseEventHandler eh = (MouseEventHandler)(Events [MouseWheelEvent]);
4689 if (eh != null)
4690 eh (this, e);
4693 [EditorBrowsable(EditorBrowsableState.Advanced)]
4694 protected virtual void OnMove(EventArgs e) {
4695 EventHandler eh = (EventHandler)(Events [MoveEvent]);
4696 if (eh != null)
4697 eh (this, e);
4700 [EditorBrowsable(EditorBrowsableState.Advanced)]
4701 protected virtual void OnNotifyMessage(Message m) {
4702 // Override me!
4705 [EditorBrowsable(EditorBrowsableState.Advanced)]
4706 protected virtual void OnPaint(PaintEventArgs e) {
4707 PaintEventHandler eh = (PaintEventHandler)(Events [PaintEvent]);
4708 if (eh != null)
4709 eh (this, e);
4712 internal virtual void OnPaintBackgroundInternal(PaintEventArgs e) {
4713 // Override me
4716 internal virtual void OnPaintInternal(PaintEventArgs e) {
4717 // Override me
4720 internal virtual void OnGotFocusInternal (EventArgs e)
4722 OnGotFocus (e);
4725 internal virtual void OnLostFocusInternal (EventArgs e)
4727 OnLostFocus (e);
4730 [EditorBrowsable(EditorBrowsableState.Advanced)]
4731 protected virtual void OnPaintBackground(PaintEventArgs pevent) {
4732 PaintControlBackground (pevent);
4735 [EditorBrowsable(EditorBrowsableState.Advanced)]
4736 protected virtual void OnParentBackColorChanged(EventArgs e) {
4737 if (background_color.IsEmpty && background_image==null) {
4738 Invalidate();
4739 OnBackColorChanged(e);
4743 [EditorBrowsable(EditorBrowsableState.Advanced)]
4744 protected virtual void OnParentBackgroundImageChanged(EventArgs e) {
4745 if (background_color.IsEmpty && background_image==null) {
4746 Invalidate();
4747 OnBackgroundImageChanged(e);
4751 [EditorBrowsable(EditorBrowsableState.Advanced)]
4752 protected virtual void OnParentBindingContextChanged(EventArgs e) {
4753 if (binding_context==null) {
4754 binding_context=Parent.binding_context;
4755 OnBindingContextChanged(e);
4759 [EditorBrowsable(EditorBrowsableState.Advanced)]
4760 protected virtual void OnParentChanged(EventArgs e) {
4761 EventHandler eh = (EventHandler)(Events [ParentChangedEvent]);
4762 if (eh != null)
4763 eh (this, e);
4766 [EditorBrowsable(EditorBrowsableState.Advanced)]
4767 protected virtual void OnParentEnabledChanged(EventArgs e) {
4768 if (is_enabled) {
4769 OnEnabledChanged(e);
4773 [EditorBrowsable(EditorBrowsableState.Advanced)]
4774 protected virtual void OnParentFontChanged(EventArgs e) {
4775 if (font==null) {
4776 Invalidate();
4777 OnFontChanged(e);
4781 [EditorBrowsable(EditorBrowsableState.Advanced)]
4782 protected virtual void OnParentForeColorChanged(EventArgs e) {
4783 if (foreground_color.IsEmpty) {
4784 Invalidate();
4785 OnForeColorChanged(e);
4789 [EditorBrowsable(EditorBrowsableState.Advanced)]
4790 protected virtual void OnParentRightToLeftChanged(EventArgs e) {
4791 if (right_to_left==RightToLeft.Inherit) {
4792 Invalidate();
4793 OnRightToLeftChanged(e);
4797 [EditorBrowsable(EditorBrowsableState.Advanced)]
4798 protected virtual void OnParentVisibleChanged(EventArgs e) {
4799 if (is_visible) {
4800 OnVisibleChanged(e);
4804 [EditorBrowsable(EditorBrowsableState.Advanced)]
4805 protected virtual void OnQueryContinueDrag(QueryContinueDragEventArgs e) {
4806 QueryContinueDragEventHandler eh = (QueryContinueDragEventHandler)(Events [QueryContinueDragEvent]);
4807 if (eh != null)
4808 eh (this, e);
4811 [EditorBrowsable(EditorBrowsableState.Advanced)]
4812 protected virtual void OnResize(EventArgs e) {
4813 EventHandler eh = (EventHandler)(Events [ResizeEvent]);
4814 if (eh != null)
4815 eh (this, e);
4817 PerformLayout(this, "bounds");
4819 if (parent != null) {
4820 parent.PerformLayout();
4824 [EditorBrowsable(EditorBrowsableState.Advanced)]
4825 protected virtual void OnRightToLeftChanged(EventArgs e) {
4826 EventHandler eh = (EventHandler)(Events [RightToLeftChangedEvent]);
4827 if (eh != null)
4828 eh (this, e);
4829 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentRightToLeftChanged(e);
4832 [EditorBrowsable(EditorBrowsableState.Advanced)]
4833 protected virtual void OnSizeChanged(EventArgs e) {
4834 InvalidateBuffers ();
4835 OnResize(e);
4836 EventHandler eh = (EventHandler)(Events [SizeChangedEvent]);
4837 if (eh != null)
4838 eh (this, e);
4841 [EditorBrowsable(EditorBrowsableState.Advanced)]
4842 protected virtual void OnStyleChanged(EventArgs e) {
4843 EventHandler eh = (EventHandler)(Events [StyleChangedEvent]);
4844 if (eh != null)
4845 eh (this, e);
4848 [EditorBrowsable(EditorBrowsableState.Advanced)]
4849 protected virtual void OnSystemColorsChanged(EventArgs e) {
4850 EventHandler eh = (EventHandler)(Events [SystemColorsChangedEvent]);
4851 if (eh != null)
4852 eh (this, e);
4855 [EditorBrowsable(EditorBrowsableState.Advanced)]
4856 protected virtual void OnTabIndexChanged(EventArgs e) {
4857 EventHandler eh = (EventHandler)(Events [TabIndexChangedEvent]);
4858 if (eh != null)
4859 eh (this, e);
4862 [EditorBrowsable(EditorBrowsableState.Advanced)]
4863 protected virtual void OnTabStopChanged(EventArgs e) {
4864 EventHandler eh = (EventHandler)(Events [TabStopChangedEvent]);
4865 if (eh != null)
4866 eh (this, e);
4869 [EditorBrowsable(EditorBrowsableState.Advanced)]
4870 protected virtual void OnTextChanged(EventArgs e) {
4871 EventHandler eh = (EventHandler)(Events [TextChangedEvent]);
4872 if (eh != null)
4873 eh (this, e);
4876 [EditorBrowsable(EditorBrowsableState.Advanced)]
4877 protected virtual void OnValidated(EventArgs e) {
4878 EventHandler eh = (EventHandler)(Events [ValidatedEvent]);
4879 if (eh != null)
4880 eh (this, e);
4883 [EditorBrowsable(EditorBrowsableState.Advanced)]
4884 protected virtual void OnValidating(System.ComponentModel.CancelEventArgs e) {
4885 CancelEventHandler eh = (CancelEventHandler)(Events [ValidatingEvent]);
4886 if (eh != null)
4887 eh (this, e);
4890 [EditorBrowsable(EditorBrowsableState.Advanced)]
4891 protected virtual void OnVisibleChanged(EventArgs e) {
4892 if ((parent != null) && !Created && Visible) {
4893 if (!is_disposed) {
4894 CreateControl();
4895 PerformLayout();
4899 EventHandler eh = (EventHandler)(Events [VisibleChangedEvent]);
4900 if (eh != null)
4901 eh (this, e);
4903 // We need to tell our kids
4904 for (int i=0; i<child_controls.Count; i++) {
4905 if (child_controls[i].Visible) {
4906 child_controls[i].OnParentVisibleChanged(e);
4910 #endregion // OnXXX methods
4912 #region Events
4913 static object BackColorChangedEvent = new object ();
4914 static object BackgroundImageChangedEvent = new object ();
4915 static object BindingContextChangedEvent = new object ();
4916 static object CausesValidationChangedEvent = new object ();
4917 static object ChangeUICuesEvent = new object ();
4918 static object ClickEvent = new object ();
4919 static object ContextMenuChangedEvent = new object ();
4920 static object ControlAddedEvent = new object ();
4921 static object ControlRemovedEvent = new object ();
4922 static object CursorChangedEvent = new object ();
4923 static object DockChangedEvent = new object ();
4924 static object DoubleClickEvent = new object ();
4925 static object DragDropEvent = new object ();
4926 static object DragEnterEvent = new object ();
4927 static object DragLeaveEvent = new object ();
4928 static object DragOverEvent = new object ();
4929 static object EnabledChangedEvent = new object ();
4930 static object EnterEvent = new object ();
4931 static object FontChangedEvent = new object ();
4932 static object ForeColorChangedEvent = new object ();
4933 static object GiveFeedbackEvent = new object ();
4934 static object GotFocusEvent = new object ();
4935 static object HandleCreatedEvent = new object ();
4936 static object HandleDestroyedEvent = new object ();
4937 static object HelpRequestedEvent = new object ();
4938 static object ImeModeChangedEvent = new object ();
4939 static object InvalidatedEvent = new object ();
4940 static object KeyDownEvent = new object ();
4941 static object KeyPressEvent = new object ();
4942 static object KeyUpEvent = new object ();
4943 static object LayoutEvent = new object ();
4944 static object LeaveEvent = new object ();
4945 static object LocationChangedEvent = new object ();
4946 static object LostFocusEvent = new object ();
4947 static object MouseDownEvent = new object ();
4948 static object MouseEnterEvent = new object ();
4949 static object MouseHoverEvent = new object ();
4950 static object MouseLeaveEvent = new object ();
4951 static object MouseMoveEvent = new object ();
4952 static object MouseUpEvent = new object ();
4953 static object MouseWheelEvent = new object ();
4954 static object MoveEvent = new object ();
4955 static object PaintEvent = new object ();
4956 static object ParentChangedEvent = new object ();
4957 static object QueryAccessibilityHelpEvent = new object ();
4958 static object QueryContinueDragEvent = new object ();
4959 static object ResizeEvent = new object ();
4960 static object RightToLeftChangedEvent = new object ();
4961 static object SizeChangedEvent = new object ();
4962 static object StyleChangedEvent = new object ();
4963 static object SystemColorsChangedEvent = new object ();
4964 static object TabIndexChangedEvent = new object ();
4965 static object TabStopChangedEvent = new object ();
4966 static object TextChangedEvent = new object ();
4967 static object ValidatedEvent = new object ();
4968 static object ValidatingEvent = new object ();
4969 static object VisibleChangedEvent = new object ();
4971 public event EventHandler BackColorChanged {
4972 add { Events.AddHandler (BackColorChangedEvent, value); }
4973 remove { Events.RemoveHandler (BackColorChangedEvent, value); }
4976 public event EventHandler BackgroundImageChanged {
4977 add { Events.AddHandler (BackgroundImageChangedEvent, value); }
4978 remove { Events.RemoveHandler (BackgroundImageChangedEvent, value); }
4981 public event EventHandler BindingContextChanged {
4982 add { Events.AddHandler (BindingContextChangedEvent, value); }
4983 remove { Events.RemoveHandler (BindingContextChangedEvent, value); }
4986 public event EventHandler CausesValidationChanged {
4987 add { Events.AddHandler (CausesValidationChangedEvent, value); }
4988 remove { Events.RemoveHandler (CausesValidationChangedEvent, value); }
4991 public event UICuesEventHandler ChangeUICues {
4992 add { Events.AddHandler (ChangeUICuesEvent, value); }
4993 remove { Events.RemoveHandler (ChangeUICuesEvent, value); }
4996 public event EventHandler Click {
4997 add { Events.AddHandler (ClickEvent, value); }
4998 remove { Events.RemoveHandler (ClickEvent, value); }
5001 public event EventHandler ContextMenuChanged {
5002 add { Events.AddHandler (ContextMenuChangedEvent, value); }
5003 remove { Events.RemoveHandler (ContextMenuChangedEvent, value); }
5006 [EditorBrowsable(EditorBrowsableState.Advanced)]
5007 [Browsable(false)]
5008 public event ControlEventHandler ControlAdded {
5009 add { Events.AddHandler (ControlAddedEvent, value); }
5010 remove { Events.RemoveHandler (ControlAddedEvent, value); }
5013 [EditorBrowsable(EditorBrowsableState.Advanced)]
5014 [Browsable(false)]
5015 public event ControlEventHandler ControlRemoved {
5016 add { Events.AddHandler (ControlRemovedEvent, value); }
5017 remove { Events.RemoveHandler (ControlRemovedEvent, value); }
5020 [MWFDescription("Fired when the cursor for the control has been changed"), MWFCategory("PropertyChanged")]
5021 public event EventHandler CursorChanged {
5022 add { Events.AddHandler (CursorChangedEvent, value); }
5023 remove { Events.RemoveHandler (CursorChangedEvent, value); }
5025 public event EventHandler DockChanged {
5026 add { Events.AddHandler (DockChangedEvent, value); }
5027 remove { Events.RemoveHandler (DockChangedEvent, value); }
5030 public event EventHandler DoubleClick {
5031 add { Events.AddHandler (DoubleClickEvent, value); }
5032 remove { Events.RemoveHandler (DoubleClickEvent, value); }
5035 public event DragEventHandler DragDrop {
5036 add { Events.AddHandler (DragDropEvent, value); }
5037 remove { Events.RemoveHandler (DragDropEvent, value); }
5040 public event DragEventHandler DragEnter {
5041 add { Events.AddHandler (DragEnterEvent, value); }
5042 remove { Events.RemoveHandler (DragEnterEvent, value); }
5045 public event EventHandler DragLeave {
5046 add { Events.AddHandler (DragLeaveEvent, value); }
5047 remove { Events.RemoveHandler (DragLeaveEvent, value); }
5050 public event DragEventHandler DragOver {
5051 add { Events.AddHandler (DragOverEvent, value); }
5052 remove { Events.RemoveHandler (DragOverEvent, value); }
5055 public event EventHandler EnabledChanged {
5056 add { Events.AddHandler (EnabledChangedEvent, value); }
5057 remove { Events.RemoveHandler (EnabledChangedEvent, value); }
5060 public event EventHandler Enter {
5061 add { Events.AddHandler (EnterEvent, value); }
5062 remove { Events.RemoveHandler (EnterEvent, value); }
5065 public event EventHandler FontChanged {
5066 add { Events.AddHandler (FontChangedEvent, value); }
5067 remove { Events.RemoveHandler (FontChangedEvent, value); }
5070 public event EventHandler ForeColorChanged {
5071 add { Events.AddHandler (ForeColorChangedEvent, value); }
5072 remove { Events.RemoveHandler (ForeColorChangedEvent, value); }
5075 public event GiveFeedbackEventHandler GiveFeedback {
5076 add { Events.AddHandler (GiveFeedbackEvent, value); }
5077 remove { Events.RemoveHandler (GiveFeedbackEvent, value); }
5080 [EditorBrowsable(EditorBrowsableState.Advanced)]
5081 [Browsable(false)]
5082 public event EventHandler GotFocus {
5083 add { Events.AddHandler (GotFocusEvent, value); }
5084 remove { Events.RemoveHandler (GotFocusEvent, value); }
5088 [EditorBrowsable(EditorBrowsableState.Advanced)]
5089 [Browsable(false)]
5090 public event EventHandler HandleCreated {
5091 add { Events.AddHandler (HandleCreatedEvent, value); }
5092 remove { Events.RemoveHandler (HandleCreatedEvent, value); }
5095 [EditorBrowsable(EditorBrowsableState.Advanced)]
5096 [Browsable(false)]
5097 public event EventHandler HandleDestroyed {
5098 add { Events.AddHandler (HandleDestroyedEvent, value); }
5099 remove { Events.RemoveHandler (HandleDestroyedEvent, value); }
5102 public event HelpEventHandler HelpRequested {
5103 add { Events.AddHandler (HelpRequestedEvent, value); }
5104 remove { Events.RemoveHandler (HelpRequestedEvent, value); }
5107 public event EventHandler ImeModeChanged {
5108 add { Events.AddHandler (ImeModeChangedEvent, value); }
5109 remove { Events.RemoveHandler (ImeModeChangedEvent, value); }
5112 [EditorBrowsable(EditorBrowsableState.Advanced)]
5113 [Browsable(false)]
5114 public event InvalidateEventHandler Invalidated {
5115 add { Events.AddHandler (InvalidatedEvent, value); }
5116 remove { Events.RemoveHandler (InvalidatedEvent, value); }
5119 public event KeyEventHandler KeyDown {
5120 add { Events.AddHandler (KeyDownEvent, value); }
5121 remove { Events.RemoveHandler (KeyDownEvent, value); }
5124 public event KeyPressEventHandler KeyPress {
5125 add { Events.AddHandler (KeyPressEvent, value); }
5126 remove { Events.RemoveHandler (KeyPressEvent, value); }
5129 public event KeyEventHandler KeyUp {
5130 add { Events.AddHandler (KeyUpEvent, value); }
5131 remove { Events.RemoveHandler (KeyUpEvent, value); }
5134 public event LayoutEventHandler Layout {
5135 add { Events.AddHandler (LayoutEvent, value); }
5136 remove { Events.RemoveHandler (LayoutEvent, value); }
5139 public event EventHandler Leave {
5140 add { Events.AddHandler (LeaveEvent, value); }
5141 remove { Events.RemoveHandler (LeaveEvent, value); }
5144 public event EventHandler LocationChanged {
5145 add { Events.AddHandler (LocationChangedEvent, value); }
5146 remove { Events.RemoveHandler (LocationChangedEvent, value); }
5149 [EditorBrowsable(EditorBrowsableState.Advanced)]
5150 [Browsable(false)]
5151 public event EventHandler LostFocus {
5152 add { Events.AddHandler (LostFocusEvent, value); }
5153 remove { Events.RemoveHandler (LostFocusEvent, value); }
5156 public event MouseEventHandler MouseDown {
5157 add { Events.AddHandler (MouseDownEvent, value); }
5158 remove { Events.RemoveHandler (MouseDownEvent, value); }
5161 public event EventHandler MouseEnter {
5162 add { Events.AddHandler (MouseEnterEvent, value); }
5163 remove { Events.RemoveHandler (MouseEnterEvent, value); }
5166 public event EventHandler MouseHover {
5167 add { Events.AddHandler (MouseHoverEvent, value); }
5168 remove { Events.RemoveHandler (MouseHoverEvent, value); }
5171 public event EventHandler MouseLeave {
5172 add { Events.AddHandler (MouseLeaveEvent, value); }
5173 remove { Events.RemoveHandler (MouseLeaveEvent, value); }
5176 public event MouseEventHandler MouseMove {
5177 add { Events.AddHandler (MouseMoveEvent, value); }
5178 remove { Events.RemoveHandler (MouseMoveEvent, value); }
5181 public event MouseEventHandler MouseUp {
5182 add { Events.AddHandler (MouseUpEvent, value); }
5183 remove { Events.RemoveHandler (MouseUpEvent, value); }
5186 [EditorBrowsable(EditorBrowsableState.Advanced)]
5187 [Browsable(false)]
5188 public event MouseEventHandler MouseWheel {
5189 add { Events.AddHandler (MouseWheelEvent, value); }
5190 remove { Events.RemoveHandler (MouseWheelEvent, value); }
5193 public event EventHandler Move {
5194 add { Events.AddHandler (MoveEvent, value); }
5195 remove { Events.RemoveHandler (MoveEvent, value); }
5198 public event PaintEventHandler Paint {
5199 add { Events.AddHandler (PaintEvent, value); }
5200 remove { Events.RemoveHandler (PaintEvent, value); }
5203 public event EventHandler ParentChanged {
5204 add { Events.AddHandler (ParentChangedEvent, value); }
5205 remove { Events.RemoveHandler (ParentChangedEvent, value); }
5208 public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp {
5209 add { Events.AddHandler (QueryAccessibilityHelpEvent, value); }
5210 remove { Events.RemoveHandler (QueryAccessibilityHelpEvent, value); }
5213 public event QueryContinueDragEventHandler QueryContinueDrag {
5214 add { Events.AddHandler (QueryContinueDragEvent, value); }
5215 remove { Events.RemoveHandler (QueryContinueDragEvent, value); }
5218 public event EventHandler Resize {
5219 add { Events.AddHandler (ResizeEvent, value); }
5220 remove { Events.RemoveHandler (ResizeEvent, value); }
5223 public event EventHandler RightToLeftChanged {
5224 add { Events.AddHandler (RightToLeftChangedEvent, value); }
5225 remove { Events.RemoveHandler (RightToLeftChangedEvent, value); }
5228 public event EventHandler SizeChanged {
5229 add { Events.AddHandler (SizeChangedEvent, value); }
5230 remove { Events.RemoveHandler (SizeChangedEvent, value); }
5233 public event EventHandler StyleChanged {
5234 add { Events.AddHandler (StyleChangedEvent, value); }
5235 remove { Events.RemoveHandler (StyleChangedEvent, value); }
5238 public event EventHandler SystemColorsChanged {
5239 add { Events.AddHandler (SystemColorsChangedEvent, value); }
5240 remove { Events.RemoveHandler (SystemColorsChangedEvent, value); }
5243 public event EventHandler TabIndexChanged {
5244 add { Events.AddHandler (TabIndexChangedEvent, value); }
5245 remove { Events.RemoveHandler (TabIndexChangedEvent, value); }
5248 public event EventHandler TabStopChanged {
5249 add { Events.AddHandler (TabStopChangedEvent, value); }
5250 remove { Events.RemoveHandler (TabStopChangedEvent, value); }
5253 public event EventHandler TextChanged {
5254 add { Events.AddHandler (TextChangedEvent, value); }
5255 remove { Events.RemoveHandler (TextChangedEvent, value); }
5258 public event EventHandler Validated {
5259 add { Events.AddHandler (ValidatedEvent, value); }
5260 remove { Events.RemoveHandler (ValidatedEvent, value); }
5263 public event CancelEventHandler Validating {
5264 add { Events.AddHandler (ValidatingEvent, value); }
5265 remove { Events.RemoveHandler (ValidatingEvent, value); }
5268 public event EventHandler VisibleChanged {
5269 add { Events.AddHandler (VisibleChangedEvent, value); }
5270 remove { Events.RemoveHandler (VisibleChangedEvent, value); }
5273 #endregion // Events