2007-04-17 Chris Toshok <toshok@ximian.com>
[mono-project.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / Control.cs
blob9f301f1d1ae3096030774abc22a8496e97b8b4d2
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 #undef DebugRecreate
34 #undef DebugFocus
36 using System;
37 using System.ComponentModel;
38 using System.ComponentModel.Design;
39 using System.ComponentModel.Design.Serialization;
40 using System.Collections;
41 using System.Diagnostics;
42 using System.Drawing;
43 using System.Drawing.Drawing2D;
44 using System.Reflection;
45 using System.Runtime.InteropServices;
46 using System.Security;
47 using System.Threading;
49 namespace System.Windows.Forms
51 #if NET_2_0
52 [ComVisible(true)]
53 [ClassInterface (ClassInterfaceType.AutoDispatch)]
54 #endif
55 [Designer("System.Windows.Forms.Design.ControlDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
56 [DefaultProperty("Text")]
57 [DefaultEvent("Click")]
58 [DesignerSerializer("System.Windows.Forms.Design.ControlCodeDomSerializer, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
59 [ToolboxItemFilter("System.Windows.Forms")]
60 public class Control : Component, ISynchronizeInvoke, IWin32Window
61 #if NET_2_0
62 , IBindableComponent, IDropTarget
63 #endif
65 #region Local Variables
67 // Basic
68 internal Rectangle bounds; // bounding rectangle for control (client area + decorations)
69 Rectangle explicit_bounds; // explicitly set bounds
70 internal object creator_thread; // thread that created the control
71 internal ControlNativeWindow window; // object for native window handle
72 private IWindowTarget window_target;
73 string name; // for object naming
75 // State
76 bool is_created; // true if OnCreateControl has been sent
77 internal bool has_focus; // true if control has focus
78 internal bool is_visible; // true if control is visible
79 internal bool is_entered; // is the mouse inside the control?
80 internal bool is_enabled; // true if control is enabled (usable/not grayed out)
81 bool is_accessible; // true if the control is visible to accessibility applications
82 bool is_captured; // tracks if the control has captured the mouse
83 internal bool is_toplevel; // tracks if the control is a toplevel window
84 bool is_recreating; // tracks if the handle for the control is being recreated
85 bool causes_validation; // tracks if validation is executed on changes
86 bool is_focusing; // tracks if Focus has been called on the control and has not yet finished
87 int tab_index; // position in tab order of siblings
88 bool tab_stop; // is the control a tab stop?
89 bool is_disposed; // has the window already been disposed?
90 Size client_size; // size of the client area (window excluding decorations)
91 Rectangle client_rect; // rectangle with the client area (window excluding decorations)
92 ControlStyles control_style; // rather win32-specific, style bits for control
93 ImeMode ime_mode;
94 object control_tag; // object that contains data about our control
95 internal int mouse_clicks; // Counter for mouse clicks
96 Cursor cursor; // Cursor for the window
97 internal bool allow_drop; // true if the control accepts droping objects on it
98 Region clip_region; // User-specified clip region for the window
100 // Visuals
101 internal Color foreground_color; // foreground color for control
102 internal Color background_color; // background color for control
103 Image background_image; // background image for control
104 internal Font font; // font for control
105 string text; // window/title text for control
106 internal BorderStyle border_style; // Border style of control
108 // Layout
109 internal enum LayoutType {
110 Anchor,
111 Dock
113 Layout.LayoutEngine layout_engine;
114 int layout_suspended;
115 bool layout_pending; // true if our parent needs to re-layout us
116 internal AnchorStyles anchor_style; // anchoring requirements for our control
117 internal DockStyle dock_style; // docking requirements for our control
118 LayoutType layout_type;
120 // Please leave the next 2 as internal until DefaultLayout (2.0) is rewritten
121 internal int dist_right; // distance to the right border of the parent
122 internal int dist_bottom; // distance to the bottom border of the parent
124 // to be categorized...
125 ControlCollection child_controls; // our children
126 Control parent; // our parent control
127 AccessibleObject accessibility_object; // object that contains accessibility information about our control
128 BindingContext binding_context;
129 RightToLeft right_to_left; // drawing direction for control
130 ContextMenu context_menu; // Context menu associated with the control
131 internal bool use_compatible_text_rendering;
133 // double buffering
134 DoubleBuffer backbuffer;
136 // to implement DeviceContext without depending on double buffering
137 Bitmap bmp;
138 Graphics bmp_g;
140 ControlBindingsCollection data_bindings;
142 #if NET_2_0
143 static bool verify_thread_handle;
144 Padding padding;
145 ImageLayout backgroundimage_layout;
146 Size maximum_size;
147 Size minimum_size;
148 Padding margin;
149 private ContextMenuStrip context_menu_strip;
150 Point auto_scroll_offset;
151 #endif
153 #endregion // Local Variables
155 #region Private Classes
156 // This helper class allows us to dispatch messages to Control.WndProc
157 internal class ControlNativeWindow : NativeWindow {
158 private Control owner;
160 public ControlNativeWindow(Control control) : base() {
161 this.owner=control;
165 public Control Owner {
166 get {
167 return owner;
171 protected override void OnHandleChange()
173 this.owner.WindowTarget.OnHandleChange(this.owner.Handle);
176 static internal Control ControlFromHandle(IntPtr hWnd) {
177 ControlNativeWindow window;
179 window = (ControlNativeWindow)window_collection[hWnd];
180 if (window != null) {
181 return window.owner;
184 return null;
187 static internal Control ControlFromChildHandle (IntPtr handle) {
188 ControlNativeWindow window;
190 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
191 while (hwnd != null) {
192 window = (ControlNativeWindow)window_collection[hwnd.Handle];
193 if (window != null) {
194 return window.owner;
196 hwnd = hwnd.Parent;
199 return null;
202 protected override void WndProc(ref Message m) {
203 owner.WindowTarget.OnMessage(ref m);
207 private class ControlWindowTarget : IWindowTarget
209 private Control control;
211 public ControlWindowTarget(Control control)
213 this.control = control;
216 public void OnHandleChange(IntPtr newHandle)
220 public void OnMessage(ref Message m)
222 control.WndProc(ref m);
225 #endregion
227 #region Public Classes
228 [ComVisible(true)]
229 public class ControlAccessibleObject : AccessibleObject {
230 IntPtr handle;
232 #region ControlAccessibleObject Constructors
233 public ControlAccessibleObject(Control ownerControl)
234 : base (ownerControl)
236 if (ownerControl == null)
237 throw new ArgumentNullException ("owner");
239 handle = ownerControl.Handle;
241 #endregion // ControlAccessibleObject Constructors
243 #region ControlAccessibleObject Public Instance Properties
244 public override string DefaultAction {
245 get {
246 return base.DefaultAction;
250 public override string Description {
251 get {
252 return base.Description;
256 public IntPtr Handle {
257 get {
258 return handle;
261 set {
262 // We don't want to let them set it
266 public override string Help {
267 get {
268 return base.Help;
272 public override string KeyboardShortcut {
273 get {
274 return base.KeyboardShortcut;
278 public override string Name {
279 get {
280 return base.Name;
283 set {
284 base.Name = value;
288 public Control Owner {
289 get {
290 return base.owner;
294 public override AccessibleObject Parent {
295 get {
296 return base.Parent;
301 public override AccessibleRole Role {
302 get {
303 return base.Role;
306 #endregion // ControlAccessibleObject Public Instance Properties
308 #region ControlAccessibleObject Public Instance Methods
309 public override int GetHelpTopic(out string FileName) {
310 return base.GetHelpTopic (out FileName);
313 [MonoTODO ("Implement this")]
314 public void NotifyClients(AccessibleEvents accEvent) {
315 throw new NotImplementedException();
318 [MonoTODO ("Implement this")]
319 public void NotifyClients(AccessibleEvents accEvent, int childID) {
322 public override string ToString() {
323 return "ControlAccessibleObject: Owner = " + owner.ToString() + ", Text: " + owner.text;
326 #endregion // ControlAccessibleObject Public Instance Methods
329 private class DoubleBuffer : IDisposable
331 public Region InvalidRegion;
332 private Stack real_graphics;
333 private object back_buffer;
334 private Control parent;
335 private bool pending_disposal;
337 public DoubleBuffer (Control parent) {
338 this.parent = parent;
339 real_graphics = new Stack ();
340 int width = parent.Width;
341 int height = parent.Height;
343 if (width < 1) width = 1;
344 if (height < 1) height = 1;
346 XplatUI.CreateOffscreenDrawable (parent.Handle, width, height, out back_buffer);
347 Invalidate ();
350 public void Blit (PaintEventArgs pe) {
351 Graphics buffered_graphics;
352 buffered_graphics = XplatUI.GetOffscreenGraphics (back_buffer);
353 XplatUI.BlitFromOffscreen (parent.Handle, pe.Graphics, back_buffer, buffered_graphics, pe.ClipRectangle);
354 buffered_graphics.Dispose ();
357 public void Start (PaintEventArgs pe) {
358 // We need to get the graphics for every paint.
359 real_graphics.Push(pe.SetGraphics (XplatUI.GetOffscreenGraphics (back_buffer)));
362 public void End (PaintEventArgs pe) {
363 Graphics buffered_graphics;
364 buffered_graphics = pe.SetGraphics ((Graphics) real_graphics.Pop ());
366 if (pending_disposal)
367 Dispose ();
368 else {
369 XplatUI.BlitFromOffscreen (parent.Handle, pe.Graphics, back_buffer, buffered_graphics, pe.ClipRectangle);
370 InvalidRegion.Exclude (pe.ClipRectangle);
372 buffered_graphics.Dispose ();
375 public void Invalidate () {
376 if (InvalidRegion != null)
377 InvalidRegion.Dispose ();
378 InvalidRegion = new Region (parent.ClientRectangle);
381 public void Dispose () {
382 if (real_graphics.Count > 0) {
383 pending_disposal = true;
384 return;
387 XplatUI.DestroyOffscreenDrawable (back_buffer);
389 if (InvalidRegion != null)
390 InvalidRegion.Dispose ();
391 InvalidRegion = null;
392 back_buffer = null;
393 GC.SuppressFinalize (this);
396 #region IDisposable Members
397 void IDisposable.Dispose () {
398 Dispose ();
400 #endregion
402 ~DoubleBuffer () {
403 Dispose ();
407 [ListBindable (false)]
408 #if NET_2_0
409 [ComVisible (false)]
410 public class ControlCollection : Layout.ArrangedElementCollection, IList, ICollection, ICloneable, IEnumerable {
411 #else
412 [DesignerSerializer("System.Windows.Forms.Design.ControlCollectionCodeDomSerializer, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
413 public class ControlCollection : IList, ICollection, ICloneable, IEnumerable {
414 #endif
415 #region ControlCollection Local Variables
416 #if !NET_2_0
417 ArrayList list;
418 #endif
419 ArrayList impl_list;
420 Control[] all_controls;
421 Control owner;
422 #endregion // ControlCollection Local Variables
424 #region ControlCollection Public Constructor
425 public ControlCollection(Control owner) {
426 this.owner=owner;
427 #if !NET_2_0
428 this.list=new ArrayList();
429 #endif
431 #endregion
433 #region ControlCollection Public Instance Properties
434 int ICollection.Count {
435 get { return Count; }
439 #if !NET_2_0
440 public int Count {
441 get { return list.Count; }
443 #endif
445 #if NET_2_0
446 bool IList.IsReadOnly
447 #else
448 public bool IsReadOnly
449 #endif
451 get {
452 return list.IsReadOnly;
456 #if NET_2_0
457 public Control Owner { get { return this.owner; } }
459 public virtual Control this[string key] {
460 get {
461 int index = IndexOfKey (key);
463 if (index >= 0)
464 return this[index];
466 return null;
471 #endif
472 public virtual Control this[int index] {
473 get {
474 if (index < 0 || index >= list.Count) {
475 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
477 return (Control)list[index];
482 #endregion // ControlCollection Public Instance Properties
484 #region ControlCollection Instance Methods
485 public virtual void Add (Control value) {
486 if (value == null)
487 return;
489 Form form_value = value as Form;
490 Form form_owner = owner as Form;
491 bool owner_permits_toplevels = (owner is MdiClient) || (form_owner != null && form_owner.IsMdiContainer);
492 bool child_is_toplevel = value.GetTopLevel();
493 bool child_is_mdichild = form_value != null && form_value.IsMdiChild;
495 if (child_is_toplevel && !(owner_permits_toplevels && child_is_mdichild))
496 throw new ArgumentException("Cannot add a top level control to a control.", "value");
498 if (child_is_mdichild && form_value.MdiParent != null && form_value.MdiParent != owner && form_value.MdiParent != owner.Parent) {
499 throw new ArgumentException ("Form cannot be added to the Controls collection that has a valid MDI parent.", "value");
502 if (Contains (value)) {
503 owner.PerformLayout();
504 return;
507 if (value.tab_index == -1) {
508 int end;
509 int index;
510 int use;
512 use = 0;
513 end = owner.child_controls.Count;
514 for (int i = 0; i < end; i++) {
515 index = owner.child_controls[i].tab_index;
516 if (index >= use) {
517 use = index + 1;
520 value.tab_index = use;
523 if (value.parent != null) {
524 value.parent.Controls.Remove(value);
527 all_controls = null;
528 list.Add (value);
530 value.ChangeParent(owner);
532 value.InitLayout();
534 if (owner.Visible)
535 owner.UpdateChildrenZOrder();
536 owner.PerformLayout(value, "Parent");
537 owner.OnControlAdded(new ControlEventArgs(value));
540 internal void AddToList (Control c) {
541 all_controls = null;
542 list.Add (c);
545 internal virtual void AddImplicit (Control control) {
546 if (impl_list == null)
547 impl_list = new ArrayList ();
549 if (AllContains (control)) {
550 owner.PerformLayout ();
551 return;
554 if (control.parent != null) {
555 control.parent.Controls.Remove(control);
558 all_controls = null;
559 impl_list.Add (control);
561 control.ChangeParent (owner);
562 control.InitLayout ();
563 if (owner.Visible)
564 owner.UpdateChildrenZOrder ();
566 // If we are adding a new control that isn't
567 // visible, don't trigger a layout
568 if (control.VisibleInternal)
569 owner.PerformLayout (control, "Parent");
571 #if NET_2_0
572 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
573 #endif
574 public virtual void AddRange (Control[] controls) {
575 if (controls == null)
576 throw new ArgumentNullException ("controls");
578 owner.SuspendLayout ();
580 try {
581 for (int i = 0; i < controls.Length; i++)
582 Add (controls[i]);
583 } finally {
584 owner.ResumeLayout ();
588 internal virtual void AddRangeImplicit (Control [] controls) {
589 if (controls == null)
590 throw new ArgumentNullException ("controls");
592 owner.SuspendLayout ();
594 try {
595 for (int i = 0; i < controls.Length; i++)
596 AddImplicit (controls [i]);
597 } finally {
598 owner.ResumeLayout ();
602 #if NET_2_0
604 #endif
605 public virtual void Clear () {
606 all_controls = null;
608 // MS sends remove events in reverse order
609 while (list.Count > 0) {
610 Remove((Control)list[list.Count - 1]);
614 internal virtual void ClearImplicit () {
615 if (impl_list == null)
616 return;
617 all_controls = null;
618 impl_list.Clear ();
621 public bool Contains (Control value) {
622 for (int i = list.Count; i > 0; ) {
623 i--;
625 if (list [i] == value) {
626 // Do we need to do anything here?
627 return true;
630 return false;
633 internal bool ImplicitContains (Control value) {
634 if (impl_list == null)
635 return false;
637 for (int i = impl_list.Count; i > 0; ) {
638 i--;
640 if (impl_list [i] == value) {
641 // Do we need to do anything here?
642 return true;
645 return false;
648 internal bool AllContains (Control value) {
649 return Contains (value) || ImplicitContains (value);
652 #if NET_2_0
653 public virtual bool ContainsKey (string key)
655 return IndexOfKey (key) >= 0;
657 #endif
659 void ICollection.CopyTo (Array array, int index) {
660 CopyTo (array, index);
663 #if !NET_2_0
664 public void CopyTo (Array array, int index) {
665 list.CopyTo(array, index);
668 public override bool Equals (object other) {
669 if (other is ControlCollection && (((ControlCollection)other).owner==this.owner)) {
670 return(true);
671 } else {
672 return(false);
675 #endif
677 #if NET_2_0
678 // LAMESPEC: MSDN says AE, MS implementation throws ANE
679 public Control[] Find (string key, bool searchAllChildren)
681 if (string.IsNullOrEmpty (key))
682 throw new ArgumentNullException ("key");
684 ArrayList al = new ArrayList ();
686 foreach (Control c in list) {
687 if (c.Name.Equals (key, StringComparison.CurrentCultureIgnoreCase))
688 al.Add (c);
690 if (searchAllChildren)
691 al.AddRange (c.Controls.Find (key, true));
694 return (Control[])al.ToArray (typeof (Control));
696 #endif
698 public int GetChildIndex(Control child) {
699 return GetChildIndex(child, false);
702 #if NET_2_0
703 public virtual int
704 #else
705 public int
706 #endif
707 GetChildIndex(Control child, bool throwException) {
708 int index;
710 index=list.IndexOf(child);
712 if (index==-1 && throwException) {
713 throw new ArgumentException("Not a child control", "child");
715 return index;
718 #if NET_2_0
719 public override IEnumerator
720 #else
721 public IEnumerator
722 #endif
723 GetEnumerator () {
724 return list.GetEnumerator();
727 internal IEnumerator GetAllEnumerator () {
728 Control [] res = GetAllControls ();
729 return res.GetEnumerator ();
732 internal Control [] GetAllControls () {
733 if (all_controls != null)
734 return all_controls;
736 if (impl_list == null) {
737 all_controls = (Control []) list.ToArray (typeof (Control));
738 return all_controls;
741 all_controls = new Control [list.Count + impl_list.Count];
742 impl_list.CopyTo (all_controls);
743 list.CopyTo (all_controls, impl_list.Count);
745 return all_controls;
748 #if !NET_2_0
749 public override int GetHashCode() {
750 return base.GetHashCode();
752 #endif
754 public int IndexOf(Control control) {
755 return list.IndexOf(control);
758 #if NET_2_0
759 public virtual int IndexOfKey (string key)
761 if (string.IsNullOrEmpty (key))
762 return -1;
764 for (int i = 0; i < list.Count; i++)
765 if (((Control)list[i]).Name.Equals (key, StringComparison.CurrentCultureIgnoreCase))
766 return i;
768 return -1;
770 #endif
772 public virtual void Remove(Control value) {
773 if (value == null)
774 return;
776 owner.PerformLayout(value, "Parent");
777 owner.OnControlRemoved(new ControlEventArgs(value));
779 all_controls = null;
780 list.Remove(value);
782 ContainerControl container = owner as ContainerControl;
783 if (container != null) {
784 // Inform any container controls about the loss of a child control
785 // so that they can update their active control
786 container.ChildControlRemoved (value);
789 value.ChangeParent(null);
791 owner.UpdateChildrenZOrder();
794 internal virtual void RemoveImplicit (Control control) {
795 if (impl_list != null) {
796 all_controls = null;
797 owner.PerformLayout (control, "Parent");
798 owner.OnControlRemoved (new ControlEventArgs (control));
799 impl_list.Remove (control);
801 control.ChangeParent (null);
802 owner.UpdateChildrenZOrder ();
805 #if NET_2_0
807 #endif
808 public void RemoveAt(int index) {
809 if (index < 0 || index >= list.Count) {
810 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
812 Remove ((Control)list[index]);
815 #if NET_2_0
816 public virtual void RemoveByKey (string key)
818 int index = IndexOfKey (key);
820 if (index >= 0)
821 RemoveAt (index);
823 #endif
825 #if NET_2_0
826 public virtual void
827 #else
828 public void
829 #endif
830 SetChildIndex(Control child, int newIndex) {
831 if (child == null)
832 throw new ArgumentNullException ("child");
834 int old_index;
836 old_index=list.IndexOf(child);
837 if (old_index==-1) {
838 throw new ArgumentException("Not a child control", "child");
841 if (old_index==newIndex) {
842 return;
845 all_controls = null;
846 list.RemoveAt(old_index);
848 if (newIndex>list.Count) {
849 list.Add(child);
850 } else {
851 list.Insert(newIndex, child);
853 child.UpdateZOrder();
854 owner.PerformLayout();
856 #endregion // ControlCollection Private Instance Methods
858 #region ControlCollection Interface Properties
859 object IList.this[int index] {
860 get {
861 if (index<0 || index>=list.Count) {
862 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
864 return this[index];
867 set {
868 if (!(value is Control)) {
869 throw new ArgumentException("Object of type Control required", "value");
872 all_controls = null;
873 Control ctrl = (Control) value;
874 list[index]= ctrl;
876 ctrl.ChangeParent(owner);
878 ctrl.InitLayout();
880 owner.UpdateChildrenZOrder();
881 owner.PerformLayout(ctrl, "Parent");
885 bool IList.IsFixedSize {
886 get {
887 return false;
891 bool ICollection.IsSynchronized {
892 get {
893 return list.IsSynchronized;
897 object ICollection.SyncRoot {
898 get {
899 return list.SyncRoot;
902 #endregion // ControlCollection Interface Properties
904 #region ControlCollection Interface Methods
905 int IList.Add(object value) {
906 if (!(value is Control)) {
907 throw new ArgumentException("Object of type Control required", "value");
910 if (value == null) {
911 throw new ArgumentException("value", "Cannot add null controls");
914 bool owner_permits_toplevels = (owner is MdiClient) || (owner is Form && ((Form)owner).IsMdiContainer);
915 bool child_is_toplevel = ((Control)value).GetTopLevel();
916 bool child_is_mdichild = (value is Form && ((Form)value).IsMdiChild);
918 if (child_is_toplevel && !(owner_permits_toplevels && child_is_mdichild))
919 throw new ArgumentException("Cannot add a top level control to a control.", "value");
921 return list.Add(value);
924 bool IList.Contains(object value) {
925 if (!(value is Control)) {
926 throw new ArgumentException("Object of type Control required", "value");
929 return this.Contains((Control) value);
932 int IList.IndexOf(object value) {
933 if (!(value is Control)) {
934 throw new ArgumentException("Object of type Control required", "value");
937 return this.IndexOf((Control) value);
940 void IList.Insert(int index, object value) {
941 if (!(value is Control)) {
942 throw new ArgumentException("Object of type Control required", "value");
944 all_controls = null;
945 list.Insert(index, value);
948 void IList.Remove(object value) {
949 if (!(value is Control)) {
950 throw new ArgumentException("Object of type Control required", "value");
952 all_controls = null;
953 list.Remove(value);
956 Object ICloneable.Clone() {
957 ControlCollection clone = new ControlCollection(this.owner);
958 clone.list=(ArrayList)list.Clone(); // FIXME: Do we need this?
959 return clone;
961 #endregion // ControlCollection Interface Methods
963 #endregion // ControlCollection Class
965 #region Public Constructors
966 public Control ()
968 layout_type = LayoutType.Anchor;
969 anchor_style = AnchorStyles.Top | AnchorStyles.Left;
971 is_created = false;
972 is_visible = true;
973 is_captured = false;
974 is_disposed = false;
975 is_enabled = true;
976 is_entered = false;
977 layout_pending = false;
978 is_toplevel = false;
979 causes_validation = true;
980 has_focus = false;
981 layout_suspended = 0;
982 mouse_clicks = 1;
983 tab_index = -1;
984 cursor = null;
985 right_to_left = RightToLeft.Inherit;
986 border_style = BorderStyle.None;
987 background_color = Color.Empty;
988 dist_right = 0;
989 dist_bottom = 0;
990 tab_stop = true;
991 ime_mode = ImeMode.Inherit;
992 use_compatible_text_rendering = true;
994 #if NET_2_0
995 backgroundimage_layout = ImageLayout.Tile;
996 use_compatible_text_rendering = Application.use_compatible_text_rendering;
997 padding = new Padding(0);
998 maximum_size = new Size();
999 minimum_size = new Size();
1000 margin = this.DefaultMargin;
1001 #endif
1003 control_style = ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint |
1004 ControlStyles.Selectable | ControlStyles.StandardClick |
1005 ControlStyles.StandardDoubleClick;
1006 #if NET_2_0
1007 control_style |= ControlStyles.UseTextForAccessibility;
1008 #endif
1010 parent = null;
1011 background_image = null;
1012 text = string.Empty;
1013 name = string.Empty;
1015 window_target = new ControlWindowTarget(this);
1016 window = new ControlNativeWindow(this);
1017 child_controls = CreateControlsInstance();
1018 client_size = DefaultSize;
1019 client_rect = new Rectangle (Point.Empty, client_size);
1020 bounds.Size = InternalSizeFromClientSize (client_size);
1021 explicit_bounds = bounds;
1024 public Control (Control parent, string text) : this()
1026 Text=text;
1027 Parent=parent;
1030 public Control (Control parent, string text, int left, int top, int width, int height) : this()
1032 Parent=parent;
1033 bounds.X=left;
1034 bounds.Y=top;
1035 bounds.Width=width;
1036 bounds.Height=height;
1037 SetBounds(left, top, width, height, BoundsSpecified.All);
1038 Text=text;
1041 public Control (string text) : this()
1043 Text=text;
1046 public Control (string text, int left, int top, int width, int height) : this()
1048 bounds.X=left;
1049 bounds.Y=top;
1050 bounds.Width=width;
1051 bounds.Height=height;
1052 SetBounds(left, top, width, height, BoundsSpecified.All);
1053 Text=text;
1056 private delegate void RemoveDelegate(object c);
1058 protected override void Dispose (bool disposing)
1060 if (!is_disposed && disposing) {
1061 Capture = false;
1063 DisposeBackBuffer ();
1065 if (bmp != null) {
1066 bmp.Dispose ();
1067 bmp = null;
1069 if (bmp_g != null) {
1070 bmp_g.Dispose ();
1071 bmp_g = null;
1074 if (this.InvokeRequired) {
1075 if (Application.MessageLoop && IsHandleCreated) {
1076 this.BeginInvokeInternal(new MethodInvoker(DestroyHandle), null);
1078 } else {
1079 DestroyHandle();
1082 if (parent != null) {
1083 parent.Controls.Remove(this);
1086 Control [] children = child_controls.GetAllControls ();
1087 for (int i=0; i<children.Length; i++) {
1088 children[i].parent = null; // Need to set to null or our child will try and remove from ourselves and crash
1089 children[i].Dispose();
1092 is_disposed = true;
1093 is_visible = false;
1094 base.Dispose(disposing);
1096 #endregion // Public Constructors
1098 #region Internal Properties
1099 // Control is currently selected, like Focused, except maintains state
1100 // when Form loses focus
1101 internal bool InternalSelected {
1102 get {
1103 IContainerControl container;
1105 container = GetContainerControl();
1107 if (container != null && container.ActiveControl == this)
1108 return true;
1110 return false;
1114 // Mouse is currently within the control's bounds
1115 internal bool Entered {
1116 get { return this.is_entered; }
1119 internal bool VisibleInternal {
1120 get { return is_visible; }
1123 internal LayoutType ControlLayoutType {
1124 get { return layout_type; }
1127 internal BorderStyle InternalBorderStyle {
1128 get {
1129 return border_style;
1132 set {
1133 if (!Enum.IsDefined (typeof (BorderStyle), value))
1134 throw new InvalidEnumArgumentException (string.Format("Enum argument value '{0}' is not valid for BorderStyle", value));
1136 if (border_style != value) {
1137 border_style = value;
1139 if (IsHandleCreated) {
1140 XplatUI.SetBorderStyle (window.Handle, (FormBorderStyle)border_style);
1141 RecreateHandle ();
1142 Refresh ();
1148 internal Size InternalClientSize { set { this.client_size = value; } }
1149 internal virtual bool ActivateOnShow { get { return true; } }
1150 #endregion // Internal Properties
1152 #region Private & Internal Methods
1154 #if NET_2_0
1155 void IDropTarget.OnDragDrop (DragEventArgs e)
1157 OnDragDrop (e);
1160 void IDropTarget.OnDragEnter (DragEventArgs e)
1162 OnDragEnter (e);
1165 void IDropTarget.OnDragLeave (EventArgs e)
1167 OnDragLeave (e);
1170 void IDropTarget.OnDragOver (DragEventArgs e)
1172 OnDragOver (e);
1174 #endif
1176 internal IAsyncResult BeginInvokeInternal (Delegate method, object [] args) {
1177 return BeginInvokeInternal (method, args, FindControlToInvokeOn ());
1180 internal IAsyncResult BeginInvokeInternal (Delegate method, object [] args, Control control) {
1181 AsyncMethodResult result;
1182 AsyncMethodData data;
1184 result = new AsyncMethodResult ();
1185 data = new AsyncMethodData ();
1187 data.Handle = control.Handle;
1188 data.Method = method;
1189 data.Args = args;
1190 data.Result = result;
1192 #if NET_2_0
1193 if (!ExecutionContext.IsFlowSuppressed ()) {
1194 data.Context = ExecutionContext.Capture ();
1196 #else
1197 #if !MWF_ON_MSRUNTIME
1198 if (SecurityManager.SecurityEnabled) {
1199 data.Stack = CompressedStack.GetCompressedStack ();
1201 #endif
1202 #endif
1204 XplatUI.SendAsyncMethod (data);
1205 return result;
1209 internal void PointToClient (ref int x, ref int y) {
1210 XplatUI.ScreenToClient (Handle, ref x, ref y);
1213 internal void PointToScreen (ref int x, ref int y) {
1214 XplatUI.ClientToScreen (Handle, ref x, ref y);
1217 internal bool IsRecreating {
1218 get {
1219 return is_recreating;
1223 internal Graphics DeviceContext {
1224 get {
1225 if (bmp_g == null) {
1226 bmp = new Bitmap(1, 1, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
1227 bmp_g = Graphics.FromImage (bmp);
1229 return bmp_g;
1233 private Control FindControlToInvokeOn ()
1235 Control p = this;
1236 do {
1237 if (p.IsHandleCreated)
1238 break;
1239 p = p.parent;
1240 } while (p != null);
1242 if (p == null || !p.IsHandleCreated)
1243 throw new InvalidOperationException ("Cannot call Invoke or BeginInvoke on a control until the window handle is created");
1245 return p;
1248 private void InvalidateBackBuffer () {
1249 if (backbuffer != null)
1250 backbuffer.Invalidate ();
1253 private DoubleBuffer GetBackBuffer () {
1254 if (backbuffer == null)
1255 backbuffer = new DoubleBuffer (this);
1256 return backbuffer;
1259 private void DisposeBackBuffer () {
1260 if (backbuffer != null) {
1261 backbuffer.Dispose ();
1262 backbuffer = null;
1266 internal static void SetChildColor(Control parent) {
1267 Control child;
1269 for (int i=0; i < parent.child_controls.Count; i++) {
1270 child=parent.child_controls[i];
1271 if (child.child_controls.Count>0) {
1272 SetChildColor(child);
1277 internal bool Select(Control control) {
1278 IContainerControl container;
1280 if (control == null) {
1281 return false;
1284 container = GetContainerControl();
1285 if (container != null && (Control)container != control) {
1286 container.ActiveControl = control;
1288 else if (control.IsHandleCreated) {
1289 XplatUI.SetFocus(control.window.Handle);
1291 return true;
1294 internal virtual void DoDefaultAction() {
1295 // Only here to be overriden by our actual controls; this is needed by the accessibility class
1298 internal static IntPtr MakeParam (int low, int high){
1299 return new IntPtr (high << 16 | low & 0xffff);
1302 internal static int LowOrder (int param) {
1303 return ((int)(short)(param & 0xffff));
1306 internal static int HighOrder (int param) {
1307 return ((int)(short)(param >> 16));
1310 // This method exists so controls overriding OnPaintBackground can have default background painting done
1311 internal virtual void PaintControlBackground (PaintEventArgs pevent) {
1312 if (GetStyle(ControlStyles.SupportsTransparentBackColor) && (BackColor.A != 0xff)) {
1313 if (parent != null) {
1314 PaintEventArgs parent_pe;
1315 GraphicsState state;
1317 parent_pe = new PaintEventArgs(pevent.Graphics, new Rectangle(pevent.ClipRectangle.X + Left, pevent.ClipRectangle.Y + Top, pevent.ClipRectangle.Width, pevent.ClipRectangle.Height));
1319 state = parent_pe.Graphics.Save();
1320 parent_pe.Graphics.TranslateTransform(-Left, -Top);
1321 parent.OnPaintBackground(parent_pe);
1322 parent_pe.Graphics.Restore(state);
1324 state = parent_pe.Graphics.Save();
1325 parent_pe.Graphics.TranslateTransform(-Left, -Top);
1326 parent.OnPaint(parent_pe);
1327 parent_pe.Graphics.Restore(state);
1328 parent_pe.SetGraphics(null);
1332 if ((clip_region != null) && (XplatUI.UserClipWontExposeParent)) {
1333 if (parent != null) {
1334 PaintEventArgs parent_pe;
1335 Region region;
1336 GraphicsState state;
1337 Hwnd hwnd;
1339 hwnd = Hwnd.ObjectFromHandle(Handle);
1341 if (hwnd != null) {
1342 parent_pe = new PaintEventArgs(pevent.Graphics, new Rectangle(pevent.ClipRectangle.X + Left, pevent.ClipRectangle.Y + Top, pevent.ClipRectangle.Width, pevent.ClipRectangle.Height));
1344 region = new Region ();
1345 region.MakeEmpty();
1346 region.Union(ClientRectangle);
1348 foreach (Rectangle r in hwnd.ClipRectangles) {
1349 region.Union (r);
1352 state = parent_pe.Graphics.Save();
1353 parent_pe.Graphics.Clip = region;
1355 parent_pe.Graphics.TranslateTransform(-Left, -Top);
1356 parent.OnPaintBackground(parent_pe);
1357 parent_pe.Graphics.Restore(state);
1359 state = parent_pe.Graphics.Save();
1360 parent_pe.Graphics.Clip = region;
1362 parent_pe.Graphics.TranslateTransform(-Left, -Top);
1363 parent.OnPaint(parent_pe);
1364 parent_pe.Graphics.Restore(state);
1365 parent_pe.SetGraphics(null);
1367 region.Intersect(clip_region);
1368 pevent.Graphics.Clip = region;
1373 if (background_image == null) {
1374 Rectangle paintRect = new Rectangle(pevent.ClipRectangle.X, pevent.ClipRectangle.Y, pevent.ClipRectangle.Width, pevent.ClipRectangle.Height);
1375 Brush pen = ThemeEngine.Current.ResPool.GetSolidBrush(BackColor);
1376 pevent.Graphics.FillRectangle(pen, paintRect);
1377 return;
1380 DrawBackgroundImage (pevent.Graphics);
1383 void DrawBackgroundImage (Graphics g) {
1384 #if NET_2_0
1385 Rectangle drawing_rectangle = new Rectangle ();
1386 g.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (BackColor), ClientRectangle);
1388 switch (backgroundimage_layout)
1390 case ImageLayout.Tile:
1391 using (TextureBrush b = new TextureBrush (background_image, WrapMode.Tile)) {
1392 g.FillRectangle (b, ClientRectangle);
1394 return;
1395 case ImageLayout.Center:
1396 drawing_rectangle.Location = new Point (ClientSize.Width / 2 - background_image.Width / 2, ClientSize.Height / 2 - background_image.Height / 2);
1397 drawing_rectangle.Size = background_image.Size;
1398 break;
1399 case ImageLayout.None:
1400 drawing_rectangle.Location = Point.Empty;
1401 drawing_rectangle.Size = background_image.Size;
1402 break;
1403 case ImageLayout.Stretch:
1404 drawing_rectangle = ClientRectangle;
1405 break;
1406 case ImageLayout.Zoom:
1407 drawing_rectangle = ClientRectangle;
1408 if ((float)background_image.Width / (float)background_image.Height < (float)drawing_rectangle.Width / (float) drawing_rectangle.Height) {
1409 drawing_rectangle.Width = (int) (background_image.Width * ((float)drawing_rectangle.Height / (float)background_image.Height));
1410 drawing_rectangle.X = (ClientRectangle.Width - drawing_rectangle.Width) / 2;
1411 } else {
1412 drawing_rectangle.Height = (int) (background_image.Height * ((float)drawing_rectangle.Width / (float)background_image.Width));
1413 drawing_rectangle.Y = (ClientRectangle.Height - drawing_rectangle.Height) / 2;
1415 break;
1416 default:
1417 return;
1420 g.DrawImage (background_image, drawing_rectangle);
1422 #else
1423 using (TextureBrush b = new TextureBrush (background_image, WrapMode.Tile)) {
1424 g.FillRectangle (b, ClientRectangle);
1426 #endif
1429 internal virtual void DndEnter (DragEventArgs e) {
1430 try {
1431 OnDragEnter (e);
1432 } catch { }
1435 internal virtual void DndOver (DragEventArgs e) {
1436 try {
1437 OnDragOver (e);
1438 } catch { }
1441 internal virtual void DndDrop (DragEventArgs e) {
1442 try {
1443 OnDragDrop (e);
1444 } catch (Exception exc) {
1445 Console.Error.WriteLine ("MWF: Exception while dropping:");
1446 Console.Error.WriteLine (exc);
1450 internal virtual void DndLeave (EventArgs e) {
1451 try {
1452 OnDragLeave (e);
1453 } catch { }
1456 internal virtual void DndFeedback(GiveFeedbackEventArgs e) {
1457 try {
1458 OnGiveFeedback(e);
1459 } catch { }
1462 internal virtual void DndContinueDrag(QueryContinueDragEventArgs e) {
1463 try {
1464 OnQueryContinueDrag(e);
1465 } catch { }
1468 internal static MouseButtons FromParamToMouseButtons (int param) {
1469 MouseButtons buttons = MouseButtons.None;
1471 if ((param & (int) MsgButtons.MK_LBUTTON) != 0)
1472 buttons |= MouseButtons.Left;
1474 if ((param & (int) MsgButtons.MK_MBUTTON) != 0)
1475 buttons |= MouseButtons.Middle;
1477 if ((param & (int) MsgButtons.MK_RBUTTON) != 0)
1478 buttons |= MouseButtons.Right;
1480 return buttons;
1484 internal virtual void FireEnter () {
1485 OnEnter (EventArgs.Empty);
1488 internal virtual void FireLeave () {
1489 OnLeave (EventArgs.Empty);
1492 internal virtual void FireValidating (CancelEventArgs ce) {
1493 OnValidating (ce);
1496 internal virtual void FireValidated () {
1497 OnValidated (EventArgs.Empty);
1500 internal virtual bool ProcessControlMnemonic(char charCode) {
1501 return ProcessMnemonic(charCode);
1504 private static Control FindFlatForward(Control container, Control start) {
1505 Control found;
1506 int index;
1507 int end;
1509 found = null;
1510 end = container.child_controls.Count;
1512 if (start != null) {
1513 index = start.tab_index;
1514 } else {
1515 index = -1;
1518 for (int i = 0, pos = -1; i < end; i++) {
1519 if (start == container.child_controls[i]) {
1520 pos = i;
1521 continue;
1524 if (found == null) {
1525 if (container.child_controls[i].tab_index > index || (pos > -1 && pos < i && container.child_controls[i].tab_index == index)) {
1526 found = container.child_controls[i];
1528 } else if (found.tab_index > container.child_controls[i].tab_index) {
1529 if (container.child_controls[i].tab_index > index) {
1530 found = container.child_controls[i];
1534 return found;
1537 private static Control FindControlForward(Control container, Control start) {
1538 Control found;
1540 found = null;
1542 if (start == null) {
1543 return FindFlatForward(container, start);
1546 if (start.child_controls != null && start.child_controls.Count > 0 &&
1547 (start == container || !((start is IContainerControl) && start.GetStyle(ControlStyles.ContainerControl)))) {
1548 return FindControlForward(start, null);
1550 else {
1551 while (start != container) {
1552 found = FindFlatForward(start.parent, start);
1553 if (found != null) {
1554 return found;
1556 start = start.parent;
1559 return null;
1562 private static Control FindFlatBackward(Control container, Control start) {
1563 Control found;
1564 int index;
1565 int end;
1567 found = null;
1568 end = container.child_controls.Count;
1570 if (start != null) {
1571 index = start.tab_index;
1572 } else {
1573 // FIXME: Possible speed-up: Keep the highest taborder index in the container
1574 index = -1;
1575 for (int i = 0; i < end; i++) {
1576 if (container.child_controls[i].tab_index > index) {
1577 index = container.child_controls[i].tab_index;
1580 index++;
1583 bool hit = false;
1585 for (int i = end - 1; i >= 0; i--) {
1586 if (start == container.child_controls[i]) {
1587 hit = true;
1588 continue;
1591 if (found == null || found.tab_index < container.child_controls[i].tab_index) {
1592 if (container.child_controls[i].tab_index < index || (hit && container.child_controls[i].tab_index == index))
1593 found = container.child_controls[i];
1597 return found;
1600 private static Control FindControlBackward(Control container, Control start) {
1602 Control found = null;
1604 if (start == null) {
1605 found = FindFlatBackward(container, start);
1607 else if (start != container) {
1608 if (start.parent != null) {
1609 found = FindFlatBackward(start.parent, start);
1611 if (found == null) {
1612 if (start.parent != container)
1613 return start.parent;
1614 return null;
1619 if (found == null || start.parent == null)
1620 found = start;
1622 while (found != null && (found == container || (!((found is IContainerControl) && found.GetStyle(ControlStyles.ContainerControl))) &&
1623 found.child_controls != null && found.child_controls.Count > 0)) {
1624 // while (ctl.child_controls != null && ctl.child_controls.Count > 0 &&
1625 // (ctl == this || (!((ctl is IContainerControl) && ctl.GetStyle(ControlStyles.ContainerControl))))) {
1626 found = FindFlatBackward(found, null);
1629 return found;
1632 Control found;
1634 found = null;
1636 if (start != null) {
1637 found = FindFlatBackward(start.parent, start);
1638 if (found == null) {
1639 if (start.parent != container) {
1640 return start.parent;
1644 if (found == null) {
1645 found = FindFlatBackward(container, start);
1648 if (container != start) {
1649 while ((found != null) && (!found.Contains(start)) && found.child_controls != null && found.child_controls.Count > 0 && !(found is IContainerControl)) {// || found.GetStyle(ControlStyles.ContainerControl))) {
1650 found = FindControlBackward(found, null);
1651 if (found != null) {
1652 return found;
1656 return found;
1660 internal virtual void HandleClick(int clicks, MouseEventArgs me) {
1661 if (GetStyle(ControlStyles.StandardClick)) {
1662 if ((clicks > 1) && GetStyle(ControlStyles.StandardDoubleClick)) {
1663 #if !NET_2_0
1664 OnDoubleClick(EventArgs.Empty);
1665 } else {
1666 OnClick(EventArgs.Empty);
1667 #else
1668 OnDoubleClick(me);
1669 OnMouseDoubleClick (me);
1670 } else {
1671 OnClick(me);
1672 OnMouseClick (me);
1673 #endif
1678 internal void CaptureWithConfine (Control ConfineWindow) {
1679 if (this.IsHandleCreated && !is_captured) {
1680 is_captured = true;
1681 XplatUI.GrabWindow (this.window.Handle, ConfineWindow.Handle);
1685 private void CheckDataBindings () {
1686 if (data_bindings == null)
1687 return;
1689 BindingContext binding_context = BindingContext;
1690 foreach (Binding binding in data_bindings) {
1691 binding.Check (binding_context);
1695 private void ChangeParent(Control new_parent) {
1696 bool pre_enabled;
1697 bool pre_visible;
1698 Font pre_font;
1699 Color pre_fore_color;
1700 Color pre_back_color;
1701 RightToLeft pre_rtl;
1703 // These properties are inherited from our parent
1704 // Get them pre parent-change and then send events
1705 // if they are changed after we have our new parent
1706 pre_enabled = Enabled;
1707 pre_visible = Visible;
1708 pre_font = Font;
1709 pre_fore_color = ForeColor;
1710 pre_back_color = BackColor;
1711 pre_rtl = RightToLeft;
1712 // MS doesn't seem to send a CursorChangedEvent
1714 parent = new_parent;
1716 if (IsHandleCreated) {
1717 XplatUI.SetParent(Handle,
1718 (new_parent == null || !new_parent.IsHandleCreated) ? IntPtr.Zero : new_parent.Handle);
1720 if (this is Form) {
1721 ((Form)this).ChangingParent (new_parent);
1724 OnParentChanged(EventArgs.Empty);
1726 if (pre_enabled != Enabled) {
1727 OnEnabledChanged(EventArgs.Empty);
1730 if (pre_visible != Visible) {
1731 OnVisibleChanged(EventArgs.Empty);
1734 if (pre_font != Font) {
1735 OnFontChanged(EventArgs.Empty);
1738 if (pre_fore_color != ForeColor) {
1739 OnForeColorChanged(EventArgs.Empty);
1742 if (pre_back_color != BackColor) {
1743 OnBackColorChanged(EventArgs.Empty);
1746 if (pre_rtl != RightToLeft) {
1747 // MS sneaks a OnCreateControl and OnHandleCreated in here, I guess
1748 // because when RTL changes they have to recreate the win32 control
1749 // We don't really need that (until someone runs into compatibility issues)
1750 OnRightToLeftChanged(EventArgs.Empty);
1753 if ((new_parent != null) && new_parent.Created && is_visible && !Created) {
1754 CreateControl();
1757 if ((binding_context == null) && Created) {
1758 OnBindingContextChanged(EventArgs.Empty);
1762 // Sometimes we need to do this calculation without it being virtual (constructor)
1763 internal Size InternalSizeFromClientSize (Size clientSize)
1765 Rectangle ClientRect;
1766 Rectangle WindowRect;
1767 CreateParams cp;
1769 ClientRect = new Rectangle (0, 0, clientSize.Width, clientSize.Height);
1770 cp = this.CreateParams;
1772 if (XplatUI.CalculateWindowRect (ref ClientRect, cp, null, out WindowRect))
1773 return new Size (WindowRect.Width, WindowRect.Height);
1775 return Size.Empty;
1778 internal CreateParams GetCreateParams ()
1780 return CreateParams;
1783 private void UpdateDistances() {
1784 if (parent != null) {
1785 if (bounds.Width >= 0)
1786 dist_right = parent.ClientSize.Width - bounds.X - bounds.Width;
1787 if (bounds.Height >= 0)
1788 dist_bottom = parent.ClientSize.Height - bounds.Y - bounds.Height;
1792 private Cursor GetAvailableCursor ()
1794 if (Cursor != null && Enabled) {
1795 return Cursor;
1798 if (Parent != null) {
1799 return Parent.GetAvailableCursor ();
1802 return Cursors.Default;
1805 private void UpdateCursor ()
1807 if (!IsHandleCreated)
1808 return;
1810 if (!Enabled) {
1811 XplatUI.SetCursor (window.Handle, GetAvailableCursor ().handle);
1812 return;
1815 Point pt = PointToClient (Cursor.Position);
1817 if ((!bounds.Contains (pt) && !Capture) || (GetChildAtPoint (pt) != null))
1818 return;
1820 if (cursor != null) {
1821 XplatUI.SetCursor (window.Handle, cursor.handle);
1822 } else {
1823 XplatUI.SetCursor (window.Handle, GetAvailableCursor ().handle);
1827 private bool UseDoubleBuffering {
1828 get {
1829 if (!ThemeEngine.Current.DoubleBufferingSupported)
1830 return false;
1832 #if NET_2_0
1833 if (DoubleBuffered)
1834 return true;
1835 #endif
1836 return (control_style & ControlStyles.DoubleBuffer) != 0;
1839 #endregion // Private & Internal Methods
1841 #region Public Static Properties
1842 public static Color DefaultBackColor {
1843 get {
1844 return ThemeEngine.Current.DefaultControlBackColor;
1848 public static Font DefaultFont {
1849 get {
1850 return ThemeEngine.Current.DefaultFont;
1854 public static Color DefaultForeColor {
1855 get {
1856 return ThemeEngine.Current.DefaultControlForeColor;
1860 public static Keys ModifierKeys {
1861 get {
1862 return XplatUI.State.ModifierKeys;
1866 public static MouseButtons MouseButtons {
1867 get {
1868 return XplatUI.State.MouseButtons;
1872 public static Point MousePosition {
1873 get {
1874 return Cursor.Position;
1878 #if NET_2_0
1879 [EditorBrowsable (EditorBrowsableState.Advanced)]
1880 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
1881 [Browsable (false)]
1882 [MonoTODO]
1883 public static bool CheckForIllegalCrossThreadCalls
1885 get {
1886 return verify_thread_handle;
1889 set {
1890 verify_thread_handle = value;
1893 #endif
1894 #endregion // Public Static Properties
1896 #region Public Instance Properties
1897 [EditorBrowsable(EditorBrowsableState.Advanced)]
1898 [Browsable(false)]
1899 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1900 public AccessibleObject AccessibilityObject {
1901 get {
1902 if (accessibility_object==null) {
1903 accessibility_object=CreateAccessibilityInstance();
1905 return accessibility_object;
1909 [EditorBrowsable(EditorBrowsableState.Advanced)]
1910 [Browsable(false)]
1911 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1912 public string AccessibleDefaultActionDescription {
1913 get {
1914 if (accessibility_object != null)
1915 return accessibility_object.default_action;
1916 else
1917 return null;
1920 set {
1921 if (accessibility_object != null)
1922 accessibility_object.default_action = value;
1926 [Localizable(true)]
1927 [DefaultValue(null)]
1928 [MWFCategory("Accessibility")]
1929 public string AccessibleDescription {
1930 get {
1931 if (accessibility_object != null)
1932 return accessibility_object.description;
1933 else
1934 return null;
1937 set {
1938 if (accessibility_object != null)
1939 accessibility_object.description = value;
1943 [Localizable(true)]
1944 [DefaultValue(null)]
1945 [MWFCategory("Accessibility")]
1946 public string AccessibleName {
1947 get {
1948 if (accessibility_object != null)
1949 return accessibility_object.Name;
1950 else
1951 return null;
1954 set {
1955 if (accessibility_object != null)
1956 accessibility_object.Name = value;
1960 [DefaultValue(AccessibleRole.Default)]
1961 [MWFDescription("Role of the control"), MWFCategory("Accessibility")]
1962 public AccessibleRole AccessibleRole {
1963 get {
1964 if (accessibility_object != null)
1965 return accessibility_object.role;
1966 else
1967 return AccessibleRole.Default;
1970 set {
1971 if (accessibility_object != null)
1972 accessibility_object.role = value;
1976 [DefaultValue(false)]
1977 [MWFCategory("Behavior")]
1978 public virtual bool AllowDrop {
1979 get {
1980 return allow_drop;
1983 set {
1984 if (allow_drop == value)
1985 return;
1986 allow_drop = value;
1987 if (IsHandleCreated) {
1988 UpdateStyles();
1989 XplatUI.SetAllowDrop (Handle, value);
1994 [Localizable(true)]
1995 [RefreshProperties(RefreshProperties.Repaint)]
1996 [DefaultValue(AnchorStyles.Top | AnchorStyles.Left)]
1997 [MWFCategory("Layout")]
1998 public virtual AnchorStyles Anchor {
1999 get {
2000 return anchor_style;
2003 set {
2004 layout_type = LayoutType.Anchor;
2006 if (anchor_style == value)
2007 return;
2009 anchor_style=value;
2010 dock_style = DockStyle.None;
2012 UpdateDistances ();
2014 if (parent != null)
2015 parent.PerformLayout(this, "Anchor");
2019 #if NET_2_0
2021 public virtual Point AutoScrollOffset {
2022 get {
2023 return auto_scroll_offset;
2026 set {
2027 this.auto_scroll_offset = value;
2031 // XXX: Implement me!
2032 bool auto_size;
2034 [RefreshProperties (RefreshProperties.All)]
2035 [Localizable (true)]
2036 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
2037 [Browsable (false)]
2038 [EditorBrowsable (EditorBrowsableState.Never)]
2039 [DefaultValue (false)]
2040 [MonoTODO("This method currently does nothing")]
2041 public virtual bool AutoSize {
2042 get { return auto_size; }
2043 set {
2044 if (this.auto_size != value) {
2045 auto_size = value;
2046 OnAutoSizeChanged (EventArgs.Empty);
2051 #if NET_2_0
2052 [AmbientValue ("{Width=0, Height=0}")]
2053 #else
2054 [AmbientValue (typeof(Size), "0, 0")]
2055 #endif
2056 public virtual Size MaximumSize {
2057 get {
2058 return maximum_size;
2060 set {
2061 if (maximum_size != value) {
2062 maximum_size = value;
2063 Size = PreferredSize;
2068 public virtual Size MinimumSize {
2069 get {
2070 return minimum_size;
2072 set {
2073 if (minimum_size != value) {
2074 minimum_size = value;
2075 Size = PreferredSize;
2079 #endif // NET_2_0
2081 [DispId(-501)]
2082 [MWFCategory("Appearance")]
2083 public virtual Color BackColor {
2084 get {
2085 if (background_color.IsEmpty) {
2086 if (parent!=null) {
2087 Color pcolor = parent.BackColor;
2088 if (pcolor.A == 0xff || GetStyle(ControlStyles.SupportsTransparentBackColor))
2089 return pcolor;
2091 return DefaultBackColor;
2093 return background_color;
2096 set {
2097 if (!value.IsEmpty && (value.A != 0xff) && !GetStyle(ControlStyles.SupportsTransparentBackColor)) {
2098 throw new ArgumentException("Transparent background colors are not supported on this control");
2101 if (background_color != value) {
2102 background_color=value;
2103 SetChildColor(this);
2104 OnBackColorChanged(EventArgs.Empty);
2105 Invalidate();
2110 [Localizable(true)]
2111 [DefaultValue(null)]
2112 [MWFCategory("Appearance")]
2113 public virtual Image BackgroundImage {
2114 get {
2115 return background_image;
2118 set {
2119 if (background_image!=value) {
2120 background_image=value;
2121 OnBackgroundImageChanged(EventArgs.Empty);
2122 Invalidate ();
2127 #if NET_2_0
2128 [DefaultValue (ImageLayout.Tile)]
2129 [Localizable (true)]
2130 public virtual ImageLayout BackgroundImageLayout {
2131 get {
2132 return backgroundimage_layout;
2134 set {
2135 if (Array.IndexOf (Enum.GetValues (typeof (ImageLayout)), value) == -1)
2136 throw new InvalidEnumArgumentException ("value", (int) value, typeof(ImageLayout));
2138 if (value != backgroundimage_layout) {
2139 backgroundimage_layout = value;
2140 Invalidate ();
2141 OnBackgroundImageLayoutChanged (EventArgs.Empty);
2146 #endif
2147 [EditorBrowsable(EditorBrowsableState.Advanced)]
2148 [Browsable(false)]
2149 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2150 public virtual BindingContext BindingContext {
2151 get {
2152 if (binding_context != null)
2153 return binding_context;
2154 if (Parent == null)
2155 return null;
2156 binding_context = Parent.BindingContext;
2157 return binding_context;
2159 set {
2160 if (binding_context != value) {
2161 binding_context = value;
2162 OnBindingContextChanged(EventArgs.Empty);
2167 [EditorBrowsable(EditorBrowsableState.Advanced)]
2168 [Browsable(false)]
2169 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2170 public int Bottom {
2171 get {
2172 return bounds.Y+bounds.Height;
2176 [EditorBrowsable(EditorBrowsableState.Advanced)]
2177 [Browsable(false)]
2178 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2179 public Rectangle Bounds {
2180 get {
2181 return this.bounds;
2184 set {
2185 SetBounds(value.Left, value.Top, value.Width, value.Height, BoundsSpecified.All);
2189 [EditorBrowsable(EditorBrowsableState.Advanced)]
2190 [Browsable(false)]
2191 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2192 public bool CanFocus {
2193 get {
2194 if (IsHandleCreated && Visible && Enabled) {
2195 return true;
2197 return false;
2201 [EditorBrowsable(EditorBrowsableState.Advanced)]
2202 [Browsable(false)]
2203 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2204 public bool CanSelect {
2205 get {
2206 Control parent;
2208 if (!GetStyle(ControlStyles.Selectable)) {
2209 return false;
2212 parent = this;
2213 while (parent != null) {
2214 if (!parent.is_visible || !parent.is_enabled) {
2215 return false;
2218 parent = parent.parent;
2220 return true;
2224 internal virtual bool InternalCapture {
2225 get {
2226 return Capture;
2229 set {
2230 Capture = value;
2234 [EditorBrowsable(EditorBrowsableState.Advanced)]
2235 [Browsable(false)]
2236 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2237 public bool Capture {
2238 get {
2239 return this.is_captured;
2242 set {
2243 // Call OnMouseCaptureChanged when we get WM_CAPTURECHANGED.
2244 if (value != is_captured) {
2245 if (value) {
2246 is_captured = true;
2247 XplatUI.GrabWindow(Handle, IntPtr.Zero);
2248 } else {
2249 if (IsHandleCreated)
2250 XplatUI.UngrabWindow(Handle);
2251 is_captured = false;
2257 [DefaultValue(true)]
2258 [MWFCategory("Focus")]
2259 public bool CausesValidation {
2260 get {
2261 return this.causes_validation;
2264 set {
2265 if (this.causes_validation != value) {
2266 causes_validation = value;
2267 OnCausesValidationChanged(EventArgs.Empty);
2272 [EditorBrowsable(EditorBrowsableState.Advanced)]
2273 [Browsable(false)]
2274 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2275 public Rectangle ClientRectangle {
2276 get {
2277 client_rect.Width = client_size.Width;
2278 client_rect.Height = client_size.Height;
2279 return client_rect;
2283 [EditorBrowsable(EditorBrowsableState.Advanced)]
2284 [Browsable(false)]
2285 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2286 public Size ClientSize {
2287 get {
2288 #if notneeded
2289 if ((this is Form) && (((Form)this).form_parent_window != null)) {
2290 return ((Form)this).form_parent_window.ClientSize;
2292 #endif
2294 return client_size;
2297 set {
2298 this.SetClientSizeCore(value.Width, value.Height);
2299 #if NET_2_0
2300 this.OnClientSizeChanged (EventArgs.Empty);
2301 #endif
2305 [EditorBrowsable(EditorBrowsableState.Advanced)]
2306 [Browsable(false)]
2307 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2308 [DescriptionAttribute("ControlCompanyNameDescr")]
2309 public String CompanyName {
2310 get {
2311 return "Mono Project, Novell, Inc.";
2315 [EditorBrowsable(EditorBrowsableState.Advanced)]
2316 [Browsable(false)]
2317 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2318 public bool ContainsFocus {
2319 get {
2320 IntPtr focused_window;
2322 focused_window = XplatUI.GetFocus();
2323 if (IsHandleCreated) {
2324 if (focused_window == Handle) {
2325 return true;
2328 for (int i=0; i < child_controls.Count; i++) {
2329 if (child_controls[i].ContainsFocus) {
2330 return true;
2334 return false;
2337 #if NET_2_0
2338 [Browsable (false)]
2339 #endif
2340 [DefaultValue(null)]
2341 [MWFCategory("Behavior")]
2342 public virtual ContextMenu ContextMenu {
2343 get {
2344 return GetContextMenuInternal ();
2347 set {
2348 if (context_menu != value) {
2349 context_menu = value;
2350 OnContextMenuChanged(EventArgs.Empty);
2355 internal virtual ContextMenu GetContextMenuInternal () {
2356 return context_menu;
2359 #if NET_2_0
2360 [DefaultValue (null)]
2361 public virtual ContextMenuStrip ContextMenuStrip {
2362 get { return this.context_menu_strip; }
2363 set {
2364 if (this.context_menu_strip != value) {
2365 this.context_menu_strip = value;
2366 OnContextMenuStripChanged (EventArgs.Empty);
2370 #endif
2372 [Browsable(false)]
2373 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
2374 public ControlCollection Controls {
2375 get {
2376 return this.child_controls;
2380 [EditorBrowsable(EditorBrowsableState.Advanced)]
2381 [Browsable(false)]
2382 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2383 public bool Created {
2384 get {
2385 return (!is_disposed && is_created);
2389 [AmbientValue(null)]
2390 [MWFCategory("Appearance")]
2391 public virtual Cursor Cursor {
2392 get {
2393 if (cursor != null) {
2394 return cursor;
2397 if (parent != null) {
2398 return parent.Cursor;
2401 return Cursors.Default;
2404 set {
2405 if (cursor == value) {
2406 return;
2409 cursor = value;
2410 UpdateCursor ();
2412 OnCursorChanged (EventArgs.Empty);
2417 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
2418 [ParenthesizePropertyName(true)]
2419 [RefreshProperties(RefreshProperties.All)]
2420 [MWFCategory("Data")]
2421 public ControlBindingsCollection DataBindings {
2422 get {
2423 if (data_bindings == null)
2424 data_bindings = new ControlBindingsCollection (this);
2425 return data_bindings;
2429 [EditorBrowsable(EditorBrowsableState.Advanced)]
2430 [Browsable(false)]
2431 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2432 public virtual Rectangle DisplayRectangle {
2433 get {
2434 return ClientRectangle;
2438 [EditorBrowsable(EditorBrowsableState.Advanced)]
2439 [Browsable(false)]
2440 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2441 public bool Disposing {
2442 get {
2443 return is_disposed;
2447 [Localizable(true)]
2448 [RefreshProperties(RefreshProperties.Repaint)]
2449 [DefaultValue(DockStyle.None)]
2450 [MWFCategory("Layout")]
2451 public virtual DockStyle Dock {
2452 get {
2453 return dock_style;
2456 set {
2457 layout_type = LayoutType.Dock;
2459 if (dock_style == value) {
2460 return;
2463 if (!Enum.IsDefined (typeof (DockStyle), value)) {
2464 throw new InvalidEnumArgumentException ("value", (int) value,
2465 typeof (DockStyle));
2468 dock_style = value;
2469 anchor_style = AnchorStyles.Top | AnchorStyles.Left;
2471 if (dock_style == DockStyle.None) {
2472 Bounds = explicit_bounds;
2475 if (parent != null) {
2476 parent.PerformLayout(this, "Dock");
2479 OnDockChanged(EventArgs.Empty);
2483 #if NET_2_0
2484 protected virtual bool DoubleBuffered {
2485 get {
2486 return (control_style & ControlStyles.OptimizedDoubleBuffer) != 0;
2489 set {
2490 if (value == DoubleBuffered)
2491 return;
2492 if (value) {
2493 SetStyle (ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);
2494 } else {
2495 SetStyle (ControlStyles.OptimizedDoubleBuffer, false);
2500 #endif
2502 [DispId(-514)]
2503 [Localizable(true)]
2504 [MWFCategory("Behavior")]
2505 public bool Enabled {
2506 get {
2507 if (!is_enabled) {
2508 return false;
2511 if (parent != null) {
2512 return parent.Enabled;
2515 return true;
2518 set {
2519 if (this.is_enabled == value)
2520 return;
2522 bool old_value = is_enabled;
2524 is_enabled = value;
2526 if (!value)
2527 UpdateCursor ();
2529 if (old_value != value && !value && this.has_focus)
2530 SelectNextControl(this, true, true, true, true);
2532 OnEnabledChanged (EventArgs.Empty);
2536 [EditorBrowsable(EditorBrowsableState.Advanced)]
2537 [Browsable(false)]
2538 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2539 public virtual bool Focused {
2540 get {
2541 return this.has_focus;
2545 [DispId(-512)]
2546 [AmbientValue(null)]
2547 [Localizable(true)]
2548 [MWFCategory("Appearance")]
2549 public virtual Font Font {
2550 get {
2551 if (font != null) {
2552 return font;
2555 if (Parent != null && Parent.Font != null) {
2556 return Parent.Font;
2559 return DefaultFont;
2562 [param:MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Font))]
2563 set {
2564 if (font != null && font.Equals (value)) {
2565 return;
2568 font = value;
2569 Invalidate();
2570 OnFontChanged (EventArgs.Empty);
2571 PerformLayout ();
2575 [DispId(-513)]
2576 [MWFCategory("Appearance")]
2577 public virtual Color ForeColor {
2578 get {
2579 if (foreground_color.IsEmpty) {
2580 if (parent!=null) {
2581 return parent.ForeColor;
2583 return DefaultForeColor;
2585 return foreground_color;
2588 set {
2589 if (foreground_color != value) {
2590 foreground_color=value;
2591 Invalidate();
2592 OnForeColorChanged(EventArgs.Empty);
2597 [DispId(-515)]
2598 [Browsable(false)]
2599 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2600 public IntPtr Handle { // IWin32Window
2601 get {
2602 #if NET_2_0
2603 if (verify_thread_handle) {
2604 if (this.InvokeRequired) {
2605 throw new InvalidOperationException("Cross-thread access of handle detected. Handle access only valid on thread that created the control");
2608 #endif
2609 if (!IsHandleCreated) {
2610 CreateHandle();
2612 return window.Handle;
2616 [EditorBrowsable(EditorBrowsableState.Advanced)]
2617 [Browsable(false)]
2618 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2619 public bool HasChildren {
2620 get {
2621 if (this.child_controls.Count>0) {
2622 return true;
2624 return false;
2628 [EditorBrowsable(EditorBrowsableState.Always)]
2629 [Browsable(false)]
2630 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2631 public int Height {
2632 get {
2633 return this.bounds.Height;
2636 set {
2637 SetBounds(bounds.X, bounds.Y, bounds.Width, value, BoundsSpecified.Height);
2641 [AmbientValue(ImeMode.Inherit)]
2642 [Localizable(true)]
2643 [MWFCategory("Behavior")]
2644 public ImeMode ImeMode {
2645 get {
2646 if (ime_mode == ImeMode.Inherit) {
2647 if (parent != null)
2648 return parent.ImeMode;
2649 else
2650 return ImeMode.NoControl; // default value
2652 return ime_mode;
2655 set {
2656 if (ime_mode != value) {
2657 ime_mode = value;
2659 OnImeModeChanged(EventArgs.Empty);
2664 [EditorBrowsable(EditorBrowsableState.Advanced)]
2665 [Browsable(false)]
2666 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2667 public bool InvokeRequired { // ISynchronizeInvoke
2668 get {
2669 if (creator_thread != null && creator_thread!=Thread.CurrentThread) {
2670 return true;
2672 return false;
2676 [EditorBrowsable(EditorBrowsableState.Advanced)]
2677 [Browsable(false)]
2678 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2679 public bool IsAccessible {
2680 get {
2681 return is_accessible;
2684 set {
2685 is_accessible = value;
2689 [EditorBrowsable(EditorBrowsableState.Advanced)]
2690 [Browsable(false)]
2691 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2692 public bool IsDisposed {
2693 get {
2694 return this.is_disposed;
2698 [EditorBrowsable(EditorBrowsableState.Advanced)]
2699 [Browsable(false)]
2700 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2701 public bool IsHandleCreated {
2702 get {
2703 if (window == null || window.Handle == IntPtr.Zero)
2704 return false;
2706 Hwnd hwnd = Hwnd.ObjectFromHandle (window.Handle);
2707 if (hwnd != null && hwnd.zombie)
2708 return false;
2710 return true;
2714 [Browsable (false)]
2715 [EditorBrowsable (EditorBrowsableState.Advanced)]
2716 #if NET_2_0
2717 public virtual
2718 #endif
2719 Layout.LayoutEngine LayoutEngine {
2720 get {
2721 if (layout_engine == null)
2722 layout_engine = new Layout.DefaultLayout ();
2723 return layout_engine;
2727 [EditorBrowsable(EditorBrowsableState.Always)]
2728 [Browsable(false)]
2729 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2730 public int Left {
2731 get {
2732 return this.bounds.X;
2735 set {
2736 SetBounds(value, bounds.Y, bounds.Width, bounds.Height, BoundsSpecified.X);
2740 [Localizable(true)]
2741 [MWFCategory("Layout")]
2742 public Point Location {
2743 get {
2744 return new Point(bounds.X, bounds.Y);
2747 set {
2748 SetBounds(value.X, value.Y, bounds.Width, bounds.Height, BoundsSpecified.Location);
2752 #if NET_2_0
2753 [Localizable (true)]
2754 public Padding Margin {
2755 get { return this.margin; }
2756 set {
2757 if (this.margin != value) {
2758 this.margin = value;
2759 OnMarginChanged (EventArgs.Empty);
2763 #endif
2765 [Browsable(false)]
2766 public string Name {
2767 get {
2768 return name;
2771 set {
2772 name = value;
2776 #if NET_2_0
2777 [Localizable(true)]
2778 public Padding Padding {
2779 get {
2780 return padding;
2783 set {
2784 if (padding != value) {
2785 padding = value;
2786 OnPaddingChanged (EventArgs.Empty);
2787 PerformLayout ();
2791 #endif
2793 [Browsable(false)]
2794 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2795 public Control Parent {
2796 get {
2797 return this.parent;
2800 set {
2801 if (value == this) {
2802 throw new ArgumentException("A circular control reference has been made. A control cannot be owned or parented to itself.");
2805 if (parent!=value) {
2806 if (value==null) {
2807 parent.Controls.Remove(this);
2808 parent = null;
2809 return;
2812 value.Controls.Add(this);
2817 #if NET_2_0
2818 [Browsable (false)]
2819 public Size PreferredSize {
2820 get { return this.GetPreferredSize (Size.Empty); }
2822 #endif
2824 [EditorBrowsable(EditorBrowsableState.Advanced)]
2825 [Browsable(false)]
2826 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2827 public string ProductName {
2828 get {
2829 Type t = typeof (AssemblyProductAttribute);
2830 Assembly assembly = GetType().Module.Assembly;
2831 object [] attrs = assembly.GetCustomAttributes (t, false);
2832 AssemblyProductAttribute a = null;
2833 // On MS we get a NullRefException if product attribute is not
2834 // set.
2835 if (attrs != null && attrs.Length > 0)
2836 a = (AssemblyProductAttribute) attrs [0];
2837 if (a == null) {
2838 return GetType ().Namespace;
2840 return a.Product;
2844 [EditorBrowsable(EditorBrowsableState.Advanced)]
2845 [Browsable(false)]
2846 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2847 public string ProductVersion {
2848 get {
2849 Type t = typeof (AssemblyVersionAttribute);
2850 Assembly assembly = GetType().Module.Assembly;
2851 object [] attrs = assembly.GetCustomAttributes (t, false);
2852 if (attrs == null || attrs.Length < 1)
2853 return "1.0.0.0";
2854 return ((AssemblyVersionAttribute)attrs [0]).Version;
2858 [EditorBrowsable(EditorBrowsableState.Advanced)]
2859 [Browsable(false)]
2860 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2861 public bool RecreatingHandle {
2862 get {
2863 return is_recreating;
2867 [EditorBrowsable(EditorBrowsableState.Advanced)]
2868 [Browsable(false)]
2869 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2870 public Region Region {
2871 get {
2872 return clip_region;
2875 set {
2876 if (clip_region != value) {
2877 if (value != null && IsHandleCreated)
2878 XplatUI.SetClipRegion(Handle, value);
2880 clip_region = value;
2881 Invalidate ();
2882 #if NET_2_0
2883 OnRegionChanged (EventArgs.Empty);
2884 #endif
2889 [EditorBrowsable(EditorBrowsableState.Advanced)]
2890 [Browsable(false)]
2891 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2892 public int Right {
2893 get {
2894 return this.bounds.X+this.bounds.Width;
2898 [AmbientValue(RightToLeft.Inherit)]
2899 [Localizable(true)]
2900 [MWFCategory("Appearance")]
2901 public virtual RightToLeft RightToLeft {
2902 get {
2903 if (right_to_left == RightToLeft.Inherit) {
2904 if (parent != null)
2905 return parent.RightToLeft;
2906 else
2907 return RightToLeft.No; // default value
2909 return right_to_left;
2912 set {
2913 if (value != right_to_left) {
2914 right_to_left = value;
2915 OnRightToLeftChanged(EventArgs.Empty);
2916 PerformLayout ();
2921 [EditorBrowsable(EditorBrowsableState.Advanced)]
2922 public override ISite Site {
2923 get {
2924 return base.Site;
2927 set {
2928 base.Site = value;
2930 if (value != null) {
2931 AmbientProperties ap = (AmbientProperties) value.GetService (typeof (AmbientProperties));
2932 if (ap != null) {
2933 BackColor = ap.BackColor;
2934 ForeColor = ap.ForeColor;
2935 Cursor = ap.Cursor;
2936 Font = ap.Font;
2942 [Localizable(true)]
2943 [MWFCategory("Layout")]
2944 public Size Size {
2945 get {
2946 return new Size(Width, Height);
2949 set {
2950 SetBounds(bounds.X, bounds.Y, value.Width, value.Height, BoundsSpecified.Size);
2954 [Localizable(true)]
2955 [MergableProperty(false)]
2956 [MWFCategory("Behavior")]
2957 public int TabIndex {
2958 get {
2959 if (tab_index != -1) {
2960 return tab_index;
2962 return 0;
2965 set {
2966 if (tab_index != value) {
2967 tab_index = value;
2968 OnTabIndexChanged(EventArgs.Empty);
2973 [DispId(-516)]
2974 [DefaultValue(true)]
2975 [MWFCategory("Behavior")]
2976 public bool TabStop {
2977 get {
2978 return tab_stop;
2981 set {
2982 if (tab_stop != value) {
2983 tab_stop = value;
2984 OnTabStopChanged(EventArgs.Empty);
2989 [Localizable(false)]
2990 [Bindable(true)]
2991 [TypeConverter(typeof(StringConverter))]
2992 [DefaultValue(null)]
2993 [MWFCategory("Data")]
2994 public object Tag {
2995 get {
2996 return control_tag;
2999 set {
3000 control_tag = value;
3004 [DispId(-517)]
3005 [Localizable(true)]
3006 [BindableAttribute(true)]
3007 [MWFCategory("Appearance")]
3008 public virtual string Text {
3009 get {
3010 // Our implementation ignores ControlStyles.CacheText - we always cache
3011 return this.text;
3014 set {
3015 if (value == null) {
3016 value = String.Empty;
3019 if (text!=value) {
3020 text=value;
3021 if (IsHandleCreated) {
3022 /* we need to call .SetWindowStyle here instead of just .Text
3023 because the presence/absence of Text (== "" or not) can cause
3024 other window style things to appear/disappear */
3025 XplatUI.SetWindowStyle(window.Handle, CreateParams);
3026 XplatUI.Text(Handle, text);
3028 OnTextChanged (EventArgs.Empty);
3033 [EditorBrowsable(EditorBrowsableState.Always)]
3034 [Browsable(false)]
3035 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
3036 public int Top {
3037 get {
3038 return this.bounds.Y;
3041 set {
3042 SetBounds(bounds.X, value, bounds.Width, bounds.Height, BoundsSpecified.Y);
3046 [EditorBrowsable(EditorBrowsableState.Advanced)]
3047 [Browsable(false)]
3048 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
3049 public Control TopLevelControl {
3050 get {
3051 Control p = this;
3053 while (p.parent != null) {
3054 p = p.parent;
3057 return p is Form ? p : null;
3061 [Localizable(true)]
3062 [MWFCategory("Behavior")]
3063 public bool Visible {
3064 get {
3065 if (!is_visible) {
3066 return false;
3067 } else if (parent != null) {
3068 return parent.Visible;
3071 return true;
3074 set {
3075 SetVisibleCore(value);
3079 [EditorBrowsable(EditorBrowsableState.Always)]
3080 [Browsable(false)]
3081 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
3082 public int Width {
3083 get {
3084 return this.bounds.Width;
3087 set {
3088 SetBounds(bounds.X, bounds.Y, value, bounds.Height, BoundsSpecified.Width);
3092 [EditorBrowsable(EditorBrowsableState.Never)]
3093 [Browsable(false)]
3094 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
3095 public IWindowTarget WindowTarget {
3096 get { return window_target; }
3097 set { window_target = value; }
3099 #endregion // Public Instance Properties
3101 #region Protected Instance Properties
3102 protected virtual CreateParams CreateParams {
3103 get {
3104 CreateParams create_params = new CreateParams();
3106 try {
3107 create_params.Caption = Text;
3109 catch {
3110 create_params.Caption = text;
3113 try {
3114 create_params.X = Left;
3116 catch {
3117 create_params.X = this.bounds.X;
3120 try {
3121 create_params.Y = Top;
3123 catch {
3124 create_params.Y = this.bounds.Y;
3127 try {
3128 create_params.Width = Width;
3130 catch {
3131 create_params.Width = this.bounds.Width;
3134 try {
3135 create_params.Height = Height;
3137 catch {
3138 create_params.Height = this.bounds.Height;
3142 create_params.ClassName = XplatUI.DefaultClassName;
3143 create_params.ClassStyle = (int)(XplatUIWin32.ClassStyle.CS_OWNDC | XplatUIWin32.ClassStyle.CS_DBLCLKS);
3144 create_params.ExStyle = 0;
3145 create_params.Param = 0;
3147 if (allow_drop) {
3148 create_params.ExStyle |= (int)WindowExStyles.WS_EX_ACCEPTFILES;
3151 if ((parent!=null) && (parent.IsHandleCreated)) {
3152 create_params.Parent = parent.Handle;
3155 create_params.Style = (int)WindowStyles.WS_CHILD | (int)WindowStyles.WS_CLIPCHILDREN | (int)WindowStyles.WS_CLIPSIBLINGS;
3157 if (is_visible) {
3158 create_params.Style |= (int)WindowStyles.WS_VISIBLE;
3161 if (!is_enabled) {
3162 create_params.Style |= (int)WindowStyles.WS_DISABLED;
3165 switch (border_style) {
3166 case BorderStyle.FixedSingle:
3167 create_params.Style |= (int) WindowStyles.WS_BORDER;
3168 break;
3169 case BorderStyle.Fixed3D:
3170 create_params.ExStyle |= (int) WindowExStyles.WS_EX_CLIENTEDGE;
3171 break;
3174 create_params.control = this;
3176 return create_params;
3180 #if NET_2_0
3181 protected virtual Cursor DefaultCursor { get { return Cursors.Default; } }
3182 #endif
3184 protected virtual ImeMode DefaultImeMode {
3185 get {
3186 return ImeMode.Inherit;
3190 #if NET_2_0
3191 protected virtual Padding DefaultMargin {
3192 get { return new Padding (3); }
3195 protected virtual Size DefaultMaximumSize { get { return new Size (); } }
3196 protected virtual Size DefaultMinimumSize { get { return new Size (); } }
3197 protected virtual Padding DefaultPadding { get { return new Padding (); } }
3198 #endif
3200 protected virtual Size DefaultSize {
3201 get {
3202 return new Size(0, 0);
3206 protected int FontHeight {
3207 get {
3208 return Font.Height;
3211 set {
3212 ;; // Nothing to do
3215 #if NET_2_0
3216 [Obsolete ()]
3217 #endif
3218 protected bool RenderRightToLeft {
3219 get {
3220 return (this.right_to_left == RightToLeft.Yes);
3224 protected bool ResizeRedraw {
3225 get {
3226 return GetStyle(ControlStyles.ResizeRedraw);
3229 set {
3230 SetStyle(ControlStyles.ResizeRedraw, value);
3234 [EditorBrowsable(EditorBrowsableState.Advanced)]
3235 [Browsable(false)]
3236 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
3237 protected virtual bool ShowFocusCues {
3238 get {
3239 return true;
3243 [EditorBrowsable(EditorBrowsableState.Advanced)]
3244 [Browsable(false)]
3245 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
3246 #if NET_2_0
3247 internal virtual
3248 #endif
3249 protected bool ShowKeyboardCues {
3250 get {
3251 return true;
3254 #endregion // Protected Instance Properties
3256 #region Public Static Methods
3257 [EditorBrowsable(EditorBrowsableState.Advanced)]
3258 public static Control FromChildHandle(IntPtr handle) {
3259 return Control.ControlNativeWindow.ControlFromChildHandle (handle);
3262 [EditorBrowsable(EditorBrowsableState.Advanced)]
3263 public static Control FromHandle(IntPtr handle) {
3264 return Control.ControlNativeWindow.ControlFromHandle(handle);
3267 public static bool IsMnemonic(char charCode, string text) {
3268 int amp;
3270 amp = text.IndexOf('&');
3272 if (amp != -1) {
3273 if (amp + 1 < text.Length) {
3274 if (text[amp + 1] != '&') {
3275 if (Char.ToUpper(charCode) == Char.ToUpper(text.ToCharArray(amp + 1, 1)[0])) {
3276 return true;
3281 return false;
3283 #endregion
3285 #region Protected Static Methods
3286 [EditorBrowsable(EditorBrowsableState.Advanced)]
3287 protected static bool ReflectMessage(IntPtr hWnd, ref Message m) {
3288 Control c;
3290 c = Control.FromHandle(hWnd);
3292 if (c != null) {
3293 c.WndProc(ref m);
3294 return true;
3296 return false;
3298 #endregion
3300 #region Public Instance Methods
3301 [EditorBrowsable(EditorBrowsableState.Advanced)]
3302 public IAsyncResult BeginInvoke(Delegate method) {
3303 object [] prms = null;
3304 if (method is EventHandler)
3305 prms = new object [] { this, EventArgs.Empty };
3306 return BeginInvokeInternal(method, prms);
3309 [EditorBrowsable(EditorBrowsableState.Advanced)]
3310 #if NET_2_0
3311 public IAsyncResult BeginInvoke (Delegate method, params object[] args)
3312 #else
3313 public IAsyncResult BeginInvoke (Delegate method, object[] args)
3314 #endif
3316 return BeginInvokeInternal (method, args);
3319 public void BringToFront() {
3320 if (parent != null) {
3321 parent.child_controls.SetChildIndex(this, 0);
3323 else if (IsHandleCreated) {
3324 XplatUI.SetZOrder(Handle, IntPtr.Zero, false, false);
3328 public bool Contains(Control ctl) {
3329 while (ctl != null) {
3330 ctl = ctl.parent;
3331 if (ctl == this) {
3332 return true;
3335 return false;
3338 public void CreateControl () {
3339 if (is_disposed) {
3340 throw new ObjectDisposedException(GetType().FullName.ToString());
3342 if (is_created) {
3343 return;
3346 if (!is_visible) {
3347 return;
3350 if (!IsHandleCreated) {
3351 CreateHandle();
3354 if (!is_created) {
3355 is_created = true;
3357 // Create all of our children when we are created.
3358 // The child should fire it's OnLoad before the parents, however
3359 // if the child checks Parent.Created in it's OnCreateControl, the
3360 // parent is already created.
3361 foreach (Control c in Controls)
3362 if (!c.Created)
3363 c.CreateControl ();
3365 if (binding_context == null && parent != null) {
3366 OnBindingContextChanged(EventArgs.Empty);
3369 OnCreateControl();
3373 public Graphics CreateGraphics() {
3374 if (!IsHandleCreated) {
3375 this.CreateHandle();
3377 return Graphics.FromHwnd(this.window.Handle);
3380 public DragDropEffects DoDragDrop(object data, DragDropEffects allowedEffects) {
3381 if (IsHandleCreated)
3382 return XplatUI.StartDrag(Handle, data, allowedEffects);
3383 else
3384 return DragDropEffects.None;
3387 [EditorBrowsable(EditorBrowsableState.Advanced)]
3388 public object EndInvoke (IAsyncResult async_result) {
3389 AsyncMethodResult result = (AsyncMethodResult) async_result;
3390 return result.EndInvoke ();
3393 public Form FindForm() {
3394 Control c;
3396 c = this;
3397 while (c != null) {
3398 if (c is Form) {
3399 return (Form)c;
3401 c = c.Parent;
3403 return null;
3405 #if NET_2_0
3406 [EditorBrowsable (EditorBrowsableState.Advanced)]
3407 #endif
3408 public bool Focus() {
3409 return FocusInternal (false);
3412 internal virtual bool FocusInternal (bool skip_check) {
3413 if (skip_check || (CanFocus && IsHandleCreated && !has_focus && !is_focusing)) {
3414 is_focusing = true;
3415 Select(this);
3416 is_focusing = false;
3418 return has_focus;
3421 internal Control GetRealChildAtPoint (Point pt) {
3422 if (!IsHandleCreated)
3423 CreateHandle ();
3425 foreach (Control control in child_controls.GetAllControls ()) {
3426 if (control.Bounds.Contains (PointToClient (pt))) {
3427 Control child = control.GetRealChildAtPoint (pt);
3428 if (child == null)
3429 return control;
3430 else
3431 return child;
3435 return null;
3438 public Control GetChildAtPoint(Point pt) {
3439 // MS's version causes the handle to be created. The stack trace shows that get_Handle is called here, but
3440 // we'll just call CreateHandle instead.
3441 if (!IsHandleCreated)
3442 CreateHandle ();
3444 // Microsoft's version of this function doesn't seem to work, so I can't check
3445 // if we only consider children or also grandchildren, etc.
3446 // I'm gonna say 'children only'
3447 for (int i=0; i<child_controls.Count; i++) {
3448 if (child_controls[i].Bounds.Contains(pt)) {
3449 return child_controls[i];
3452 return null;
3455 public IContainerControl GetContainerControl() {
3456 Control current = this;
3458 while (current!=null) {
3459 if ((current is IContainerControl) && ((current.control_style & ControlStyles.ContainerControl)!=0)) {
3460 return (IContainerControl)current;
3462 current = current.parent;
3464 return null;
3467 public Control GetNextControl(Control ctl, bool forward) {
3469 if (!this.Contains(ctl)) {
3470 ctl = this;
3473 if (forward) {
3474 ctl = FindControlForward(this, ctl);
3476 else {
3477 ctl = FindControlBackward(this, ctl);
3480 if (ctl != this) {
3481 return ctl;
3483 return null;
3486 #if NET_2_0
3487 [EditorBrowsable (EditorBrowsableState.Advanced)]
3488 public virtual Size GetPreferredSize (Size proposedSize) {
3489 Size retsize = this.explicit_bounds.Size;
3491 // If we're bigger than the MaximumSize, fix that
3492 if (this.maximum_size.Width != 0 && retsize.Width > this.maximum_size.Width)
3493 retsize.Width = this.maximum_size.Width;
3494 if (this.maximum_size.Height != 0 && retsize.Height > this.maximum_size.Height)
3495 retsize.Height = this.maximum_size.Height;
3497 // If we're smaller than the MinimumSize, fix that
3498 if (this.minimum_size.Width != 0 && retsize.Width < this.minimum_size.Width)
3499 retsize.Width = this.minimum_size.Width;
3500 if (this.minimum_size.Height != 0 && retsize.Height < this.minimum_size.Height)
3501 retsize.Height = this.minimum_size.Height;
3503 return retsize;
3505 #endif
3507 public void Hide() {
3508 this.Visible = false;
3511 public void Invalidate() {
3512 Invalidate(ClientRectangle, false);
3515 public void Invalidate(bool invalidateChildren) {
3516 Invalidate(ClientRectangle, invalidateChildren);
3519 public void Invalidate(System.Drawing.Rectangle rc) {
3520 Invalidate(rc, false);
3523 public void Invalidate(System.Drawing.Rectangle rc, bool invalidateChildren) {
3524 // Win32 invalidates control including when Width and Height is equal 0
3525 // or is not visible, only Paint event must be care about this.
3526 if (!IsHandleCreated)
3527 return;
3529 if (rc.Width > 0 && rc.Height > 0) {
3531 NotifyInvalidate(rc);
3533 XplatUI.Invalidate(Handle, rc, false);
3535 if (invalidateChildren) {
3536 Control [] controls = child_controls.GetAllControls ();
3537 for (int i=0; i<controls.Length; i++)
3538 controls [i].Invalidate ();
3541 OnInvalidated(new InvalidateEventArgs(rc));
3544 public void Invalidate(System.Drawing.Region region) {
3545 Invalidate(region, false);
3548 public void Invalidate(System.Drawing.Region region, bool invalidateChildren) {
3549 RectangleF bounds = region.GetBounds (CreateGraphics ());
3550 Invalidate (new Rectangle ((int) bounds.X, (int) bounds.Y, (int) bounds.Width, (int) bounds.Height),
3551 invalidateChildren);
3554 public object Invoke (Delegate method) {
3555 object [] prms = null;
3556 if (method is EventHandler)
3557 prms = new object [] { this, EventArgs.Empty };
3559 return Invoke(method, prms);
3561 #if NET_2_0
3562 public object Invoke (Delegate method, params object [] args) {
3563 #else
3564 public object Invoke (Delegate method, object[] args) {
3565 #endif
3566 Control control = FindControlToInvokeOn ();
3568 if (!this.InvokeRequired) {
3569 return method.DynamicInvoke(args);
3572 IAsyncResult result = BeginInvokeInternal (method, args, control);
3573 return EndInvoke(result);
3576 [EditorBrowsable(EditorBrowsableState.Advanced)]
3577 public void PerformLayout() {
3578 PerformLayout(null, null);
3581 [EditorBrowsable(EditorBrowsableState.Advanced)]
3582 public void PerformLayout(Control affectedControl, string affectedProperty) {
3583 LayoutEventArgs levent = new LayoutEventArgs(affectedControl, affectedProperty);
3585 if (layout_suspended > 0) {
3586 layout_pending = true;
3587 return;
3590 layout_pending = false;
3592 // Prevent us from getting messed up
3593 layout_suspended++;
3595 // Perform all Dock and Anchor calculations
3596 try {
3597 OnLayout(levent);
3600 // Need to make sure we decremend layout_suspended
3601 finally {
3602 layout_suspended--;
3606 public Point PointToClient (Point p) {
3607 int x = p.X;
3608 int y = p.Y;
3610 XplatUI.ScreenToClient (Handle, ref x, ref y);
3612 return new Point (x, y);
3615 public Point PointToScreen(Point p) {
3616 int x = p.X;
3617 int y = p.Y;
3619 XplatUI.ClientToScreen(Handle, ref x, ref y);
3621 return new Point(x, y);
3624 public virtual bool PreProcessMessage(ref Message msg) {
3625 return InternalPreProcessMessage (ref msg);
3628 internal virtual bool InternalPreProcessMessage (ref Message msg) {
3629 Keys key_data;
3631 if ((msg.Msg == (int)Msg.WM_KEYDOWN) || (msg.Msg == (int)Msg.WM_SYSKEYDOWN)) {
3632 key_data = (Keys)msg.WParam.ToInt32() | XplatUI.State.ModifierKeys;
3634 if (!ProcessCmdKey(ref msg, key_data)) {
3635 if (IsInputKey(key_data)) {
3636 return false;
3639 return ProcessDialogKey(key_data);
3642 return true;
3643 } else if (msg.Msg == (int)Msg.WM_CHAR) {
3644 if (IsInputChar((char)msg.WParam)) {
3645 return false;
3647 return ProcessDialogChar((char)msg.WParam);
3648 } else if (msg.Msg == (int)Msg.WM_SYSCHAR) {
3649 return ProcessDialogChar((char)msg.WParam);
3651 return false;
3654 public Rectangle RectangleToClient(Rectangle r) {
3655 return new Rectangle(PointToClient(r.Location), r.Size);
3658 public Rectangle RectangleToScreen(Rectangle r) {
3659 return new Rectangle(PointToScreen(r.Location), r.Size);
3662 public virtual void Refresh() {
3663 if (IsHandleCreated && Visible) {
3664 Invalidate();
3665 XplatUI.UpdateWindow(window.Handle);
3667 Control [] controls = child_controls.GetAllControls ();
3668 for (int i=0; i < controls.Length; i++) {
3669 controls[i].Refresh();
3675 [EditorBrowsable(EditorBrowsableState.Never)]
3676 public virtual void ResetBackColor() {
3677 BackColor = Color.Empty;
3680 [EditorBrowsable(EditorBrowsableState.Never)]
3681 public void ResetBindings() {
3682 if (data_bindings != null)
3683 data_bindings.Clear();
3686 [EditorBrowsable(EditorBrowsableState.Never)]
3687 public virtual void ResetCursor() {
3688 Cursor = null;
3691 [EditorBrowsable(EditorBrowsableState.Never)]
3692 public virtual void ResetFont() {
3693 font = null;
3696 [EditorBrowsable(EditorBrowsableState.Never)]
3697 public virtual void ResetForeColor() {
3698 foreground_color = Color.Empty;
3701 [EditorBrowsable(EditorBrowsableState.Never)]
3702 public void ResetImeMode() {
3703 ime_mode = DefaultImeMode;
3706 [EditorBrowsable(EditorBrowsableState.Never)]
3707 public virtual void ResetRightToLeft() {
3708 right_to_left = RightToLeft.Inherit;
3711 public virtual void ResetText() {
3712 text = String.Empty;
3715 public void ResumeLayout() {
3716 ResumeLayout (true);
3719 public void ResumeLayout(bool performLayout) {
3720 if (layout_suspended > 0) {
3721 layout_suspended--;
3724 if (layout_suspended == 0) {
3725 if (performLayout && layout_pending) {
3726 PerformLayout();
3730 #if NET_2_0
3731 [EditorBrowsable (EditorBrowsableState.Never)]
3732 [Obsolete ()]
3733 #endif
3734 public void Scale(float ratio) {
3735 ScaleCore(ratio, ratio);
3738 #if NET_2_0
3739 [EditorBrowsable (EditorBrowsableState.Never)]
3740 [Obsolete ()]
3741 #endif
3742 public void Scale(float dx, float dy) {
3743 ScaleCore(dx, dy);
3746 #if NET_2_0
3747 [EditorBrowsable (EditorBrowsableState.Advanced)]
3748 public void Scale(SizeF factor) {
3749 ScaleCore(factor.Width, factor.Height);
3751 #endif
3753 public void Select() {
3754 Select(false, false);
3757 #if DebugFocus
3758 private void printTree(Control c, string t) {
3759 foreach(Control i in c.child_controls) {
3760 Console.WriteLine ("{2}{0}.TabIndex={1}", i, i.tab_index, t);
3761 printTree (i, t+"\t");
3764 #endif
3765 public bool SelectNextControl(Control ctl, bool forward, bool tabStopOnly, bool nested, bool wrap) {
3766 Control c;
3768 #if DebugFocus
3769 Console.WriteLine("{0}", this.FindForm());
3770 printTree(this, "\t");
3771 #endif
3773 if (!this.Contains(ctl) || (!nested && (ctl.parent != this))) {
3774 ctl = null;
3776 c = ctl;
3777 do {
3778 c = GetNextControl(c, forward);
3779 if (c == null) {
3780 if (wrap) {
3781 wrap = false;
3782 continue;
3784 break;
3787 if (c.CanSelect && ((c.parent == this) || nested) && (c.tab_stop || !tabStopOnly)) {
3788 c.Select (true, true);
3789 return true;
3791 } while (c != ctl); // If we wrap back to ourselves we stop
3793 return false;
3796 public void SendToBack() {
3797 if (parent != null) {
3798 parent.child_controls.SetChildIndex(this, parent.child_controls.Count);
3802 public void SetBounds(int x, int y, int width, int height) {
3803 SetBounds(x, y, width, height, BoundsSpecified.All);
3806 public void SetBounds(int x, int y, int width, int height, BoundsSpecified specified) {
3807 // SetBoundsCore is really expensive to call, so we want to avoid it if we can.
3808 // We can avoid it if:
3809 // - The requested dimensions are the same as our current dimensions
3810 // AND
3811 // - Any BoundsSpecified is the same as our current explicit_size
3812 if (bounds.X != x || (explicit_bounds.X != x && (specified & BoundsSpecified.X) == BoundsSpecified.X))
3813 SetBoundsCore (x, y, width, height, specified);
3814 else if (bounds.Y != y || (explicit_bounds.Y != y && (specified & BoundsSpecified.Y) == BoundsSpecified.Y))
3815 SetBoundsCore (x, y, width, height, specified);
3816 else if (bounds.Width != width || (explicit_bounds.Width != width && (specified & BoundsSpecified.Width) == BoundsSpecified.Width))
3817 SetBoundsCore (x, y, width, height, specified);
3818 else if (bounds.Height != height || (explicit_bounds.Height != height && (specified & BoundsSpecified.Height) == BoundsSpecified.Height))
3819 SetBoundsCore (x, y, width, height, specified);
3820 else
3821 return;
3823 if (parent != null)
3824 parent.PerformLayout(this, "Bounds");
3827 public void Show () {
3828 this.Visible = true;
3831 public void SuspendLayout() {
3832 layout_suspended++;
3835 public void Update() {
3836 if (IsHandleCreated) {
3837 XplatUI.UpdateWindow(window.Handle);
3840 #endregion // Public Instance Methods
3842 #region Protected Instance Methods
3843 [EditorBrowsable(EditorBrowsableState.Advanced)]
3844 protected void AccessibilityNotifyClients(AccessibleEvents accEvent, int childID) {
3845 // turns out this method causes handle
3846 // creation in 1.1. at first I thought this
3847 // would be accomplished just by using
3848 // get_AccessibilityObject, which would route
3849 // through CreateAccessibilityInstance, which
3850 // calls CreateControl. This isn't the case,
3851 // though (as overriding
3852 // CreateAccessibilityInstance and adding a
3853 // CWL shows nothing. So we fudge it and put
3854 // a CreateHandle here.
3856 #if ONLY_1_1
3857 CreateHandle ();
3858 #endif
3860 if (accessibility_object != null && accessibility_object is ControlAccessibleObject)
3861 ((ControlAccessibleObject)accessibility_object).NotifyClients (accEvent, childID);
3864 [EditorBrowsable(EditorBrowsableState.Advanced)]
3865 protected virtual AccessibleObject CreateAccessibilityInstance() {
3866 CreateControl ();
3867 return new Control.ControlAccessibleObject(this);
3870 [EditorBrowsable(EditorBrowsableState.Advanced)]
3871 protected virtual ControlCollection CreateControlsInstance() {
3872 return new ControlCollection(this);
3875 [EditorBrowsable(EditorBrowsableState.Advanced)]
3876 protected virtual void CreateHandle() {
3877 if (IsDisposed) {
3878 throw new ObjectDisposedException(GetType().FullName.ToString());
3881 if (IsHandleCreated && !is_recreating) {
3882 return;
3885 CreateParams create_params = CreateParams;
3886 window.CreateHandle(create_params);
3888 if (window.Handle != IntPtr.Zero) {
3889 creator_thread = Thread.CurrentThread;
3891 XplatUI.EnableWindow(window.Handle, is_enabled);
3893 if (clip_region != null) {
3894 XplatUI.SetClipRegion(window.Handle, clip_region);
3897 // Set our handle with our parent
3898 if ((parent != null) && (parent.IsHandleCreated)) {
3899 XplatUI.SetParent(window.Handle, parent.Handle);
3902 UpdateStyles();
3903 XplatUI.SetAllowDrop (window.Handle, allow_drop);
3905 // Find out where the window manager placed us
3906 if ((CreateParams.Style & (int)WindowStyles.WS_CHILD) != 0) {
3907 XplatUI.SetBorderStyle(window.Handle, (FormBorderStyle)border_style);
3909 UpdateBounds();
3913 [EditorBrowsable(EditorBrowsableState.Advanced)]
3914 protected virtual void DefWndProc(ref Message m) {
3915 window.DefWndProc(ref m);
3918 [EditorBrowsable(EditorBrowsableState.Advanced)]
3919 protected virtual void DestroyHandle() {
3920 if (IsHandleCreated) {
3921 if (window != null) {
3922 window.DestroyHandle();
3927 #if NET_2_0
3928 protected virtual AccessibleObject GetAccessibilityObjectById (int objectId)
3930 // XXX need to implement this.
3931 return null;
3933 #endif
3935 protected internal bool GetStyle(ControlStyles flag) {
3936 return (control_style & flag) != 0;
3939 protected bool GetTopLevel() {
3940 return is_toplevel;
3943 [EditorBrowsable(EditorBrowsableState.Advanced)]
3944 protected virtual void InitLayout() {
3945 UpdateDistances();
3948 [EditorBrowsable(EditorBrowsableState.Advanced)]
3949 protected void InvokeGotFocus(Control toInvoke, EventArgs e) {
3950 toInvoke.OnGotFocus(e);
3953 [EditorBrowsable(EditorBrowsableState.Advanced)]
3954 protected void InvokeLostFocus(Control toInvoke, EventArgs e) {
3955 toInvoke.OnLostFocus(e);
3958 [EditorBrowsable(EditorBrowsableState.Advanced)]
3959 protected void InvokeOnClick(Control toInvoke, EventArgs e) {
3960 toInvoke.OnClick(e);
3963 protected void InvokePaint(Control toInvoke, PaintEventArgs e) {
3964 toInvoke.OnPaint(e);
3967 protected void InvokePaintBackground(Control toInvoke, PaintEventArgs e) {
3968 toInvoke.OnPaintBackground(e);
3971 protected virtual bool IsInputChar (char charCode) {
3972 // XXX on MS.NET this method causes the handle to be created..
3973 if (!IsHandleCreated)
3974 CreateHandle ();
3976 return true;
3979 protected virtual bool IsInputKey (Keys keyData) {
3980 // Doc says this one calls IsInputChar; not sure what to do with that
3981 return false;
3984 [EditorBrowsable(EditorBrowsableState.Advanced)]
3985 protected virtual void NotifyInvalidate(Rectangle invalidatedArea) {
3986 // override me?
3989 protected virtual bool ProcessCmdKey(ref Message msg, Keys keyData) {
3990 if ((context_menu != null) && context_menu.ProcessCmdKey(ref msg, keyData)) {
3991 return true;
3994 if (parent != null) {
3995 return parent.ProcessCmdKey(ref msg, keyData);
3998 return false;
4001 protected virtual bool ProcessDialogChar(char charCode) {
4002 if (parent != null) {
4003 return parent.ProcessDialogChar (charCode);
4006 return false;
4009 protected virtual bool ProcessDialogKey (Keys keyData) {
4010 if (parent != null) {
4011 return parent.ProcessDialogKey (keyData);
4014 return false;
4017 protected virtual bool ProcessKeyEventArgs (ref Message msg) {
4018 KeyEventArgs key_event;
4020 switch (msg.Msg) {
4021 case (int)Msg.WM_SYSKEYDOWN:
4022 case (int)Msg.WM_KEYDOWN: {
4023 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
4024 OnKeyDown (key_event);
4025 return key_event.Handled;
4028 case (int)Msg.WM_SYSKEYUP:
4029 case (int)Msg.WM_KEYUP: {
4030 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
4031 OnKeyUp (key_event);
4032 return key_event.Handled;
4035 case (int)Msg.WM_SYSCHAR:
4036 case (int)Msg.WM_CHAR: {
4037 KeyPressEventArgs key_press_event;
4039 key_press_event = new KeyPressEventArgs((char)msg.WParam);
4040 OnKeyPress(key_press_event);
4041 #if NET_2_0
4042 msg.WParam = (IntPtr)key_press_event.KeyChar;
4043 #endif
4044 return key_press_event.Handled;
4047 default: {
4048 break;
4052 return false;
4055 protected internal virtual bool ProcessKeyMessage(ref Message msg) {
4056 if (parent != null) {
4057 if (parent.ProcessKeyPreview(ref msg)) {
4058 return true;
4062 return ProcessKeyEventArgs(ref msg);
4065 protected virtual bool ProcessKeyPreview(ref Message msg) {
4066 if (parent != null) {
4067 return parent.ProcessKeyPreview(ref msg);
4070 return false;
4073 protected virtual bool ProcessMnemonic(char charCode) {
4074 // override me
4075 return false;
4078 [EditorBrowsable(EditorBrowsableState.Advanced)]
4079 protected void RaiseDragEvent(object key, DragEventArgs e) {
4080 // MS Internal
4083 [EditorBrowsable(EditorBrowsableState.Advanced)]
4084 protected void RaiseKeyEvent(object key, KeyEventArgs e) {
4085 // MS Internal
4088 [EditorBrowsable(EditorBrowsableState.Advanced)]
4089 protected void RaiseMouseEvent(object key, MouseEventArgs e) {
4090 // MS Internal
4093 [EditorBrowsable(EditorBrowsableState.Advanced)]
4094 protected void RaisePaintEvent(object key, PaintEventArgs e) {
4095 // MS Internal
4098 private void SetIsRecreating () {
4099 is_recreating=true;
4101 foreach (Control c in Controls.GetAllControls()) {
4102 c.SetIsRecreating ();
4106 [EditorBrowsable(EditorBrowsableState.Advanced)]
4107 protected void RecreateHandle() {
4108 if (!IsHandleCreated)
4109 return;
4111 #if DebugRecreate
4112 Console.WriteLine("Recreating control {0}", XplatUI.Window(window.Handle));
4113 #endif
4115 SetIsRecreating ();
4117 if (IsHandleCreated) {
4118 #if DebugRecreate
4119 Console.WriteLine(" + handle is created, destroying it.");
4120 #endif
4121 DestroyHandle();
4122 // WM_DESTROY will CreateHandle for us
4123 } else {
4124 #if DebugRecreate
4125 Console.WriteLine(" + handle is not created, creating it.");
4126 #endif
4127 if (!is_created) {
4128 CreateControl();
4129 } else {
4130 CreateHandle();
4133 is_recreating = false;
4134 #if DebugRecreate
4135 Console.WriteLine (" + new handle = {0:X}", Handle.ToInt32());
4136 #endif
4141 [EditorBrowsable(EditorBrowsableState.Advanced)]
4142 protected void ResetMouseEventArgs() {
4143 // MS Internal
4146 [EditorBrowsable(EditorBrowsableState.Advanced)]
4147 protected ContentAlignment RtlTranslateAlignment(ContentAlignment align) {
4148 if (right_to_left == RightToLeft.No) {
4149 return align;
4152 switch (align) {
4153 case ContentAlignment.TopLeft: {
4154 return ContentAlignment.TopRight;
4157 case ContentAlignment.TopRight: {
4158 return ContentAlignment.TopLeft;
4161 case ContentAlignment.MiddleLeft: {
4162 return ContentAlignment.MiddleRight;
4165 case ContentAlignment.MiddleRight: {
4166 return ContentAlignment.MiddleLeft;
4169 case ContentAlignment.BottomLeft: {
4170 return ContentAlignment.BottomRight;
4173 case ContentAlignment.BottomRight: {
4174 return ContentAlignment.BottomLeft;
4177 default: {
4178 // if it's center it doesn't change
4179 return align;
4184 [EditorBrowsable(EditorBrowsableState.Advanced)]
4185 protected HorizontalAlignment RtlTranslateAlignment(HorizontalAlignment align) {
4186 if ((right_to_left == RightToLeft.No) || (align == HorizontalAlignment.Center)) {
4187 return align;
4190 if (align == HorizontalAlignment.Left) {
4191 return HorizontalAlignment.Right;
4194 // align must be HorizontalAlignment.Right
4195 return HorizontalAlignment.Left;
4198 [EditorBrowsable(EditorBrowsableState.Advanced)]
4199 protected LeftRightAlignment RtlTranslateAlignment(LeftRightAlignment align) {
4200 if (right_to_left == RightToLeft.No) {
4201 return align;
4204 if (align == LeftRightAlignment.Left) {
4205 return LeftRightAlignment.Right;
4208 // align must be LeftRightAlignment.Right;
4209 return LeftRightAlignment.Left;
4212 [EditorBrowsable(EditorBrowsableState.Advanced)]
4213 protected ContentAlignment RtlTranslateContent(ContentAlignment align) {
4214 return RtlTranslateAlignment(align);
4217 [EditorBrowsable(EditorBrowsableState.Advanced)]
4218 protected HorizontalAlignment RtlTranslateHorizontal(HorizontalAlignment align) {
4219 return RtlTranslateAlignment(align);
4222 [EditorBrowsable(EditorBrowsableState.Advanced)]
4223 protected LeftRightAlignment RtlTranslateLeftRight(LeftRightAlignment align) {
4224 return RtlTranslateAlignment(align);
4227 #if NET_2_0
4228 [EditorBrowsable (EditorBrowsableState.Never)]
4229 #else
4230 [EditorBrowsable(EditorBrowsableState.Advanced)]
4231 #endif
4232 protected virtual void ScaleCore(float dx, float dy) {
4233 Point location;
4234 Size size;
4236 SuspendLayout();
4238 location = new Point((int)(Left * dx), (int)(Top * dy));
4239 size = this.ClientSize;
4241 if (!GetStyle(ControlStyles.FixedWidth)) {
4242 size.Width = (int)(size.Width * dx);
4245 if (!GetStyle(ControlStyles.FixedHeight)) {
4246 size.Height = (int)(size.Height * dy);
4249 SetBounds(location.X, location.Y, size.Width, size.Height, BoundsSpecified.All);
4251 /* Now scale our children */
4252 Control [] controls = child_controls.GetAllControls ();
4253 for (int i=0; i < controls.Length; i++) {
4254 controls[i].Scale(dx, dy);
4257 ResumeLayout();
4260 protected virtual void Select(bool directed, bool forward) {
4261 IContainerControl container;
4263 container = GetContainerControl();
4264 if (container != null && (Control)container != this)
4265 container.ActiveControl = this;
4268 [EditorBrowsable(EditorBrowsableState.Advanced)]
4269 protected virtual void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
4270 Rectangle old_explicit = explicit_bounds;
4271 Rectangle new_bounds = new Rectangle (x, y, width, height);
4273 // SetBoundsCore updates the Win32 control itself. UpdateBounds updates the controls variables and fires events, I'm guessing - pdb
4274 if (IsHandleCreated) {
4275 XplatUI.SetWindowPos(Handle, x, y, width, height);
4277 // Win32 automatically changes negative width/height to 0.
4278 // The control has already been sent a WM_WINDOWPOSCHANGED message and it has the correct
4279 // data, but it'll be overwritten when we call UpdateBounds unless we get the updated
4280 // size.
4281 if (width < 0 || height < 0) {
4282 int cw, ch, ix, iy;
4283 XplatUI.GetWindowPos(Handle, this is Form, out ix, out iy, out width, out height, out cw, out ch);
4287 // BoundsSpecified tells us which variables were programatic (user-set).
4288 // We need to store those in the explicit bounds
4289 if ((specified & BoundsSpecified.X) == BoundsSpecified.X)
4290 explicit_bounds.X = new_bounds.X;
4291 else
4292 explicit_bounds.X = old_explicit.X;
4294 if ((specified & BoundsSpecified.Y) == BoundsSpecified.Y)
4295 explicit_bounds.Y = new_bounds.Y;
4296 else
4297 explicit_bounds.Y = old_explicit.Y;
4299 if ((specified & BoundsSpecified.Width) == BoundsSpecified.Width)
4300 explicit_bounds.Width = new_bounds.Width;
4301 else
4302 explicit_bounds.Width = old_explicit.Width;
4304 if ((specified & BoundsSpecified.Height) == BoundsSpecified.Height)
4305 explicit_bounds.Height = new_bounds.Height;
4306 else
4307 explicit_bounds.Height = old_explicit.Height;
4309 // We need to store the explicit bounds because UpdateBounds is always going
4310 // to change it, and we have to fix it. However, UpdateBounds also calls
4311 // OnLocationChanged, OnSizeChanged, and OnClientSizeChanged. The user can
4312 // override those or use those events to change the size explicitly, and we
4313 // can't undo those changes. So if the bounds after calling UpdateBounds are
4314 // the same as the ones we sent it, we need to fix the explicit bounds. If
4315 // it's not the same as we sent UpdateBounds, then someone else changed it, and
4316 // we better not mess it up. Fun stuff.
4317 Rectangle stored_explicit_bounds = explicit_bounds;
4319 UpdateBounds(x, y, width, height);
4321 if (explicit_bounds.X == x)
4322 explicit_bounds.X = stored_explicit_bounds.X;
4324 if (explicit_bounds.Y == y)
4325 explicit_bounds.Y = stored_explicit_bounds.Y;
4327 if (explicit_bounds.Width == width)
4328 explicit_bounds.Width = stored_explicit_bounds.Width;
4330 if (explicit_bounds.Height == height)
4331 explicit_bounds.Height = stored_explicit_bounds.Height;
4333 UpdateDistances();
4336 [EditorBrowsable(EditorBrowsableState.Advanced)]
4337 protected virtual void SetClientSizeCore(int x, int y) {
4338 Size NewSize = InternalSizeFromClientSize (new Size (x, y));
4340 if (NewSize != Size.Empty)
4341 SetBounds (bounds.X, bounds.Y, NewSize.Width, NewSize.Height, BoundsSpecified.Size);
4344 [EditorBrowsable(EditorBrowsableState.Advanced)]
4345 protected internal void SetStyle(ControlStyles flag, bool value) {
4346 if (value) {
4347 control_style |= flag;
4348 } else {
4349 control_style &= ~flag;
4353 protected void SetTopLevel(bool value) {
4354 if ((GetTopLevel() != value) && (parent != null)) {
4355 throw new ArgumentException ("Cannot change toplevel style of a parented control.");
4358 if (this is Form) {
4359 if (IsHandleCreated && value != Visible) {
4360 Visible = value;
4362 } else {
4363 // XXX MS.NET causes handle to be created here
4364 if (!IsHandleCreated)
4365 CreateHandle ();
4367 is_toplevel = value;
4370 protected virtual void SetVisibleCore(bool value) {
4371 if (value != is_visible) {
4372 is_visible = value;
4374 if (is_visible && ((window.Handle == IntPtr.Zero) || !is_created)) {
4375 CreateControl();
4378 if (IsHandleCreated) {
4379 XplatUI.SetVisible (Handle, is_visible, true);
4381 if (is_visible && this is Form) {
4382 // If we are Min or Max, we won't get a WM_SHOWWINDOW from SetWindowState,
4383 // so we need to manually create our children, and set them visible
4384 // (This normally happens in WmShowWindow.)
4385 if ((this as Form).WindowState != FormWindowState.Normal)
4386 OnVisibleChanged (EventArgs.Empty);
4387 else
4388 // Explicitly move Toplevel windows to where we want them;
4389 // apparently moving unmapped toplevel windows doesn't work
4390 XplatUI.SetWindowPos(window.Handle, bounds.X, bounds.Y, bounds.Width, bounds.Height);
4393 if (!(this is Form))
4394 OnVisibleChanged (EventArgs.Empty);
4396 else {
4397 OnVisibleChanged(EventArgs.Empty);
4402 [EditorBrowsable (EditorBrowsableState.Advanced)]
4403 #if NET_2_0
4404 protected
4405 #else
4406 internal
4407 #endif
4408 virtual Size SizeFromClientSize (Size clientSize) {
4409 return InternalSizeFromClientSize (clientSize);
4412 [EditorBrowsable(EditorBrowsableState.Advanced)]
4413 protected void UpdateBounds() {
4414 if (!IsHandleCreated)
4415 return;
4417 int x;
4418 int y;
4419 int width;
4420 int height;
4421 int client_width;
4422 int client_height;
4424 XplatUI.GetWindowPos(this.Handle, this is Form, out x, out y, out width, out height, out client_width, out client_height);
4426 UpdateBounds(x, y, width, height, client_width, client_height);
4429 [EditorBrowsable(EditorBrowsableState.Advanced)]
4430 protected void UpdateBounds(int x, int y, int width, int height) {
4431 CreateParams cp;
4432 Rectangle rect;
4434 // Calculate client rectangle
4435 rect = new Rectangle(0, 0, 0, 0);
4436 cp = CreateParams;
4438 XplatUI.CalculateWindowRect(ref rect, cp, cp.menu, out rect);
4439 UpdateBounds(x, y, width, height, width - (rect.Right - rect.Left), height - (rect.Bottom - rect.Top));
4442 [EditorBrowsable(EditorBrowsableState.Advanced)]
4443 protected void UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) {
4444 // UpdateBounds only seems to set our sizes and fire events but not update the GUI window to match
4445 bool moved = false;
4446 bool resized = false;
4448 // Needed to generate required notifications
4449 if ((this.bounds.X!=x) || (this.bounds.Y!=y)) {
4450 moved=true;
4453 if ((this.Bounds.Width!=width) || (this.Bounds.Height!=height)) {
4454 resized=true;
4457 bounds.X=x;
4458 bounds.Y=y;
4459 bounds.Width=width;
4460 bounds.Height=height;
4462 // Assume explicit bounds set. SetBoundsCore will restore old bounds
4463 // if needed.
4464 explicit_bounds = bounds;
4466 client_size.Width=clientWidth;
4467 client_size.Height=clientHeight;
4469 if (moved) {
4470 OnLocationChanged(EventArgs.Empty);
4472 if (!background_color.IsEmpty && background_color.A < byte.MaxValue)
4473 Invalidate ();
4476 if (resized) {
4477 OnSizeChanged(EventArgs.Empty);
4478 #if NET_2_0
4479 OnClientSizeChanged (EventArgs.Empty);
4480 #endif
4484 [EditorBrowsable(EditorBrowsableState.Advanced)]
4485 protected void UpdateStyles() {
4486 if (!IsHandleCreated) {
4487 return;
4490 XplatUI.SetWindowStyle(window.Handle, CreateParams);
4491 OnStyleChanged(EventArgs.Empty);
4494 private void UpdateZOrderOfChild(Control child) {
4495 if (IsHandleCreated && child.IsHandleCreated && (child.parent == this)) {
4496 int index;
4498 index = child_controls.IndexOf(child);
4500 if (index > 0) {
4501 XplatUI.SetZOrder(child.Handle, child_controls[index - 1].Handle, false, false);
4502 } else {
4503 IntPtr after = AfterTopMostControl ();
4504 if (after != IntPtr.Zero)
4505 XplatUI.SetZOrder (child.Handle, after, false, false);
4506 else
4507 XplatUI.SetZOrder (child.Handle, IntPtr.Zero, true, false);
4512 // Override this if there is a control that shall always remain on
4513 // top of other controls (such as scrollbars). If there are several
4514 // of these controls, the bottom-most should be returned.
4515 internal virtual IntPtr AfterTopMostControl () {
4516 return IntPtr.Zero;
4519 // internal because we need to call it from ScrollableControl.OnVisibleChanged
4520 internal void UpdateChildrenZOrder() {
4521 Control [] controls;
4523 if (!IsHandleCreated) {
4524 return;
4527 // XXX This code is severely broken. It leaks
4528 // the "zero_sized" abstraction out of the X11
4529 // backend and into Control.cs. It'll work on
4530 // windows simply by virtue of windows never
4531 // setting that field to true.
4533 // basically what we need to guard against is
4534 // calling XplatUI.SetZOrder on an hwnd that
4535 // corresponds to an unmapped X window.
4536 controls = child_controls.GetAllControls ();
4538 ArrayList children_to_order = new ArrayList ();
4540 for (int i = 0; i < controls.Length; i ++) {
4541 if (!controls[i].IsHandleCreated || !controls[i].VisibleInternal)
4542 continue;
4544 Hwnd hwnd = Hwnd.ObjectFromHandle (controls[i].Handle);
4545 if (hwnd.zero_sized)
4546 continue;
4548 children_to_order.Add (controls[i]);
4551 for (int i = 1; i < children_to_order.Count; i ++) {
4552 Control upper = (Control)children_to_order[i-1];
4553 Control lower = (Control)children_to_order[i];
4555 XplatUI.SetZOrder(lower.Handle, upper.Handle, false, false);
4559 [EditorBrowsable(EditorBrowsableState.Advanced)]
4560 protected void UpdateZOrder() {
4561 if (parent != null) {
4562 parent.UpdateZOrderOfChild(this);
4566 protected virtual void WndProc(ref Message m) {
4567 #if debug
4568 Console.WriteLine("Control {0} received message {1}", window.Handle == IntPtr.Zero ? this.Text : XplatUI.Window(window.Handle), m.ToString ());
4569 #endif
4570 if ((this.control_style & ControlStyles.EnableNotifyMessage) != 0) {
4571 OnNotifyMessage(m);
4574 switch((Msg)m.Msg) {
4575 case Msg.WM_DESTROY: {
4576 WmDestroy(ref m);
4577 return;
4580 case Msg.WM_WINDOWPOSCHANGED: {
4581 WmWindowPosChanged(ref m);
4582 return;
4585 // Nice description of what should happen when handling WM_PAINT
4586 // can be found here: http://pluralsight.com/wiki/default.aspx/Craig/FlickerFreeControlDrawing.html
4587 // and here http://msdn.microsoft.com/msdnmag/issues/06/03/WindowsFormsPerformance/
4588 case Msg.WM_PAINT: {
4589 WmPaint (ref m);
4590 return;
4593 // The DefWndProc will never have to handle this, we always paint the background in managed code
4594 // In theory this code would look at ControlStyles.AllPaintingInWmPaint and and call OnPaintBackground
4595 // here but it just makes things more complicated...
4596 case Msg.WM_ERASEBKGND: {
4597 WmEraseBackground (ref m);
4598 return;
4601 case Msg.WM_LBUTTONUP: {
4602 WmLButtonUp (ref m);
4603 return;
4606 case Msg.WM_LBUTTONDOWN: {
4607 WmLButtonDown (ref m);
4608 return;
4611 case Msg.WM_LBUTTONDBLCLK: {
4612 WmLButtonDblClick (ref m);
4613 return;
4616 case Msg.WM_MBUTTONUP: {
4617 WmMButtonUp (ref m);
4618 return;
4621 case Msg.WM_MBUTTONDOWN: {
4622 WmMButtonDown (ref m);
4623 return;
4626 case Msg.WM_MBUTTONDBLCLK: {
4627 WmMButtonDblClick (ref m);
4628 return;
4631 case Msg.WM_RBUTTONUP: {
4632 WmRButtonUp (ref m);
4633 return;
4636 case Msg.WM_RBUTTONDOWN: {
4637 WmRButtonDown (ref m);
4638 return;
4641 case Msg.WM_RBUTTONDBLCLK: {
4642 WmRButtonDblClick (ref m);
4643 return;
4646 case Msg.WM_CONTEXTMENU: {
4647 WmContextMenu (ref m);
4648 return;
4651 case Msg.WM_MOUSEWHEEL: {
4652 WmMouseWheel (ref m);
4653 return;
4657 case Msg.WM_MOUSEMOVE: {
4658 WmMouseMove (ref m);
4659 return;
4662 case Msg.WM_SHOWWINDOW: {
4663 WmShowWindow (ref m);
4664 return;
4667 case Msg.WM_CREATE: {
4668 WmCreate (ref m);
4669 return;
4672 case Msg.WM_MOUSE_ENTER: {
4673 WmMouseEnter (ref m);
4674 return;
4677 case Msg.WM_MOUSELEAVE: {
4678 WmMouseLeave (ref m);
4679 return;
4682 case Msg.WM_MOUSEHOVER: {
4683 WmMouseHover (ref m);
4684 return;
4687 case Msg.WM_SYSKEYUP: {
4688 WmSysKeyUp (ref m);
4689 return;
4692 case Msg.WM_SYSKEYDOWN:
4693 case Msg.WM_KEYDOWN:
4694 case Msg.WM_KEYUP:
4695 case Msg.WM_SYSCHAR:
4696 case Msg.WM_CHAR: {
4697 WmKeys (ref m);
4698 return;
4701 case Msg.WM_HELP: {
4702 WmHelp (ref m);
4703 return;
4706 case Msg.WM_KILLFOCUS: {
4707 WmKillFocus (ref m);
4708 return;
4711 case Msg.WM_SETFOCUS: {
4712 WmSetFocus (ref m);
4713 return;
4716 case Msg.WM_SYSCOLORCHANGE: {
4717 WmSysColorChange (ref m);
4718 return;
4721 case Msg.WM_SETCURSOR: {
4722 WmSetCursor (ref m);
4723 return;
4726 case Msg.WM_CAPTURECHANGED: {
4727 WmCaptureChanged (ref m);
4728 return;
4731 default:
4732 DefWndProc(ref m);
4733 return;
4736 #endregion // Public Instance Methods
4738 #region WM methods
4740 private void WmDestroy (ref Message m) {
4741 OnHandleDestroyed(EventArgs.Empty);
4742 #if DebugRecreate
4743 IntPtr handle = window.Handle;
4744 #endif
4745 window.InvalidateHandle();
4747 if (is_recreating) {
4748 #if DebugRecreate
4749 Console.WriteLine ("Creating handle for {0:X}", handle.ToInt32());
4750 #endif
4751 CreateHandle();
4752 #if DebugRecreate
4753 Console.WriteLine (" + new handle = {0:X}", Handle.ToInt32());
4754 #endif
4755 is_recreating = false;
4759 private void WmWindowPosChanged (ref Message m) {
4760 if (Visible) {
4761 Rectangle save_bounds = explicit_bounds;
4762 UpdateBounds();
4763 explicit_bounds = save_bounds;
4764 if (GetStyle(ControlStyles.ResizeRedraw)) {
4765 Invalidate();
4771 // Nice description of what should happen when handling WM_PAINT
4772 // can be found here: http://pluralsight.com/wiki/default.aspx/Craig/FlickerFreeControlDrawing.html
4773 // and here http://msdn.microsoft.com/msdnmag/issues/06/03/WindowsFormsPerformance/
4774 private void WmPaint (ref Message m) {
4775 PaintEventArgs paint_event;
4777 IntPtr handle = Handle;
4779 paint_event = XplatUI.PaintEventStart (handle, true);
4781 if (paint_event == null)
4782 return;
4784 DoubleBuffer current_buffer = null;
4785 if (UseDoubleBuffering) {
4786 current_buffer = GetBackBuffer ();
4787 if (!current_buffer.InvalidRegion.IsVisible (paint_event.ClipRectangle)) {
4788 // Just blit the previous image
4789 current_buffer.Blit (paint_event);
4790 XplatUI.PaintEventEnd (handle, true);
4791 return;
4793 current_buffer.Start (paint_event);
4796 if (!GetStyle(ControlStyles.Opaque)) {
4797 OnPaintBackground (paint_event);
4800 // Button-derived controls choose to ignore their Opaque style, give them a chance to draw their background anyways
4801 OnPaintBackgroundInternal (paint_event);
4803 OnPaintInternal(paint_event);
4804 if (!paint_event.Handled) {
4805 OnPaint (paint_event);
4808 if (current_buffer != null) {
4809 current_buffer.End (paint_event);
4813 XplatUI.PaintEventEnd (handle, true);
4816 private void WmEraseBackground (ref Message m) {
4817 // The DefWndProc will never have to handle this, we always paint the background in managed code
4818 // In theory this code would look at ControlStyles.AllPaintingInWmPaint and and call OnPaintBackground
4819 // here but it just makes things more complicated...
4820 m.Result = (IntPtr)1;
4823 private void WmLButtonUp (ref Message m) {
4824 MouseEventArgs me;
4826 me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Left,
4827 mouse_clicks,
4828 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4831 HandleClick(mouse_clicks, me);
4832 OnMouseUp (me);
4834 if (InternalCapture) {
4835 InternalCapture = false;
4838 if (mouse_clicks > 1) {
4839 mouse_clicks = 1;
4843 private void WmLButtonDown (ref Message m) {
4844 if (CanSelect) {
4845 Select (true, true);
4847 InternalCapture = true;
4848 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4849 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4850 0));
4853 private void WmLButtonDblClick (ref Message m) {
4854 InternalCapture = true;
4855 mouse_clicks++;
4856 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4857 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4858 0));
4861 private void WmMButtonUp (ref Message m) {
4862 MouseEventArgs me;
4864 me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Middle,
4865 mouse_clicks,
4866 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4869 HandleClick(mouse_clicks, me);
4870 OnMouseUp (me);
4871 if (InternalCapture) {
4872 InternalCapture = false;
4874 if (mouse_clicks > 1) {
4875 mouse_clicks = 1;
4879 private void WmMButtonDown (ref Message m) {
4880 InternalCapture = true;
4881 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4882 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4883 0));
4886 private void WmMButtonDblClick (ref Message m) {
4887 InternalCapture = true;
4888 mouse_clicks++;
4889 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4890 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4891 0));
4894 private void WmRButtonUp (ref Message m) {
4895 MouseEventArgs me;
4896 Point pt;
4898 pt = new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()));
4899 pt = PointToScreen(pt);
4901 me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Right,
4902 mouse_clicks,
4903 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4906 HandleClick(mouse_clicks, me);
4907 OnMouseUp (me);
4909 XplatUI.SendMessage(m.HWnd, Msg.WM_CONTEXTMENU, m.HWnd, (IntPtr)(pt.X + (pt.Y << 16)));
4911 if (InternalCapture) {
4912 InternalCapture = false;
4915 if (mouse_clicks > 1) {
4916 mouse_clicks = 1;
4920 private void WmRButtonDown (ref Message m) {
4921 InternalCapture = true;
4922 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4923 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4924 0));
4927 private void WmRButtonDblClick (ref Message m) {
4928 InternalCapture = true;
4929 mouse_clicks++;
4930 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4931 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4932 0));
4935 private void WmContextMenu (ref Message m) {
4936 if (context_menu != null) {
4937 Point pt;
4939 pt = new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()));
4941 if (pt.X == -1 || pt.Y == -1) {
4942 pt.X = (this.Width / 2) + this.Left;
4943 pt.Y = (this.Height / 2) + this.Top;
4944 pt = this.PointToScreen (pt);
4947 context_menu.Show (this, PointToClient (pt));
4948 return;
4951 #if NET_2_0
4952 // If there isn't a regular context menu, show the Strip version
4953 if (context_menu == null && context_menu_strip != null) {
4954 Point pt;
4956 pt = new Point (LowOrder ((int)m.LParam.ToInt32 ()), HighOrder ((int)m.LParam.ToInt32 ()));
4958 if (pt.X == -1 || pt.Y == -1) {
4959 pt.X = (this.Width / 2) + this.Left;
4960 pt.Y = (this.Height /2) + this.Top;
4961 pt = this.PointToScreen (pt);
4964 context_menu_strip.Show (this, PointToClient (pt));
4965 return;
4967 #endif
4968 DefWndProc(ref m);
4971 private void WmCreate (ref Message m) {
4972 OnHandleCreated(EventArgs.Empty);
4975 private void WmMouseWheel (ref Message m) {
4976 DefWndProc(ref m);
4977 OnMouseWheel (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4978 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4979 HighOrder(m.WParam.ToInt32())));
4983 private void WmMouseMove (ref Message m) {
4984 OnMouseMove (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4985 mouse_clicks,
4986 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4987 0));
4990 private void WmMouseEnter (ref Message m) {
4991 if (is_entered) {
4992 return;
4994 is_entered = true;
4995 OnMouseEnter(EventArgs.Empty);
4998 private void WmMouseLeave (ref Message m) {
4999 is_entered=false;
5000 OnMouseLeave(EventArgs.Empty);
5003 private void WmMouseHover (ref Message m) {
5004 OnMouseHover(EventArgs.Empty);
5007 private void WmShowWindow (ref Message m) {
5008 if (m.WParam.ToInt32() != 0) {
5009 if (m.LParam.ToInt32 () == 0) {
5010 CreateControl ();
5012 // Make sure all our children are properly parented to us
5013 Control [] controls = child_controls.GetAllControls ();
5014 for (int i=0; i<controls.Length; i++) {
5015 if (controls [i].is_visible && controls[i].IsHandleCreated)
5016 XplatUI.SetParent(controls[i].Handle, window.Handle);
5020 else {
5021 if (parent != null && Focused) {
5022 Control container;
5024 // Need to start at parent, GetContainerControl might return ourselves if we're a container
5025 container = (Control)parent.GetContainerControl();
5026 if (container != null) {
5027 container.SelectNextControl(this, true, true, true, true);
5032 // If the form is Max/Min, it got its OnVisibleChanged in SetVisibleCore
5033 if (this is Form) {
5034 Form f = (Form)this;
5036 if (f.IsMdiChild || f.WindowState == FormWindowState.Normal) /* XXX make sure this works for mdi forms */
5037 OnVisibleChanged(EventArgs.Empty);
5038 } else if (is_toplevel)
5039 OnVisibleChanged(EventArgs.Empty);
5042 private void WmSysKeyUp (ref Message m) {
5043 if (ProcessKeyMessage(ref m)) {
5044 m.Result = IntPtr.Zero;
5045 return;
5048 if ((m.WParam.ToInt32() & (int)Keys.KeyCode) == (int)Keys.Menu) {
5049 Form form;
5051 form = FindForm();
5052 if (form != null && form.ActiveMenu != null) {
5053 form.ActiveMenu.ProcessCmdKey(ref m, (Keys)m.WParam.ToInt32());
5057 DefWndProc (ref m);
5060 private void WmKeys (ref Message m) {
5061 if (ProcessKeyMessage(ref m)) {
5062 m.Result = IntPtr.Zero;
5063 return;
5065 DefWndProc (ref m);
5068 private void WmHelp (ref Message m) {
5069 Point mouse_pos;
5070 if (m.LParam != IntPtr.Zero) {
5071 HELPINFO hi;
5073 hi = new HELPINFO();
5075 hi = (HELPINFO) Marshal.PtrToStructure (m.LParam, typeof (HELPINFO));
5076 mouse_pos = new Point(hi.MousePos.x, hi.MousePos.y);
5077 } else {
5078 mouse_pos = Control.MousePosition;
5080 OnHelpRequested(new HelpEventArgs(mouse_pos));
5081 m.Result = (IntPtr)1;
5084 private void WmKillFocus (ref Message m) {
5085 this.has_focus = false;
5086 OnLostFocus (EventArgs.Empty);
5089 private void WmSetFocus (ref Message m) {
5090 if (!has_focus) {
5091 this.has_focus = true;
5092 OnGotFocus (EventArgs.Empty);
5096 private void WmSysColorChange (ref Message m) {
5097 ThemeEngine.Current.ResetDefaults();
5098 OnSystemColorsChanged(EventArgs.Empty);
5101 private void WmSetCursor (ref Message m) {
5102 if ((cursor == null) || ((HitTest)(m.LParam.ToInt32() & 0xffff) != HitTest.HTCLIENT)) {
5103 DefWndProc(ref m);
5104 return;
5107 XplatUI.SetCursor(window.Handle, cursor.handle);
5108 m.Result = (IntPtr)1;
5111 private void WmCaptureChanged (ref Message m) {
5112 is_captured = false;
5113 OnMouseCaptureChanged (EventArgs.Empty);
5114 m.Result = (IntPtr) 0;
5118 #endregion
5120 #region OnXXX methods
5121 #if NET_2_0
5122 protected virtual void OnAutoSizeChanged (EventArgs e)
5124 EventHandler eh = (EventHandler)(Events[AutoSizeChangedEvent]);
5125 if (eh != null)
5126 eh (this, e);
5128 #endif
5130 [EditorBrowsable (EditorBrowsableState.Advanced)]
5131 protected virtual void OnBackColorChanged(EventArgs e) {
5132 EventHandler eh = (EventHandler)(Events [BackColorChangedEvent]);
5133 if (eh != null)
5134 eh (this, e);
5135 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackColorChanged(e);
5138 [EditorBrowsable(EditorBrowsableState.Advanced)]
5139 protected virtual void OnBackgroundImageChanged(EventArgs e) {
5140 EventHandler eh = (EventHandler)(Events [BackgroundImageChangedEvent]);
5141 if (eh != null)
5142 eh (this, e);
5143 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackgroundImageChanged(e);
5146 #if NET_2_0
5147 [EditorBrowsable (EditorBrowsableState.Advanced)]
5148 protected virtual void OnBackgroundImageLayoutChanged (EventArgs e)
5150 EventHandler eh = (EventHandler)(Events[BackgroundImageLayoutChangedEvent]);
5151 if (eh != null)
5152 eh (this, e);
5154 #endif
5156 [EditorBrowsable(EditorBrowsableState.Advanced)]
5157 protected virtual void OnBindingContextChanged(EventArgs e) {
5158 CheckDataBindings ();
5159 EventHandler eh = (EventHandler)(Events [BindingContextChangedEvent]);
5160 if (eh != null)
5161 eh (this, e);
5162 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBindingContextChanged(e);
5165 [EditorBrowsable(EditorBrowsableState.Advanced)]
5166 protected virtual void OnCausesValidationChanged(EventArgs e) {
5167 EventHandler eh = (EventHandler)(Events [CausesValidationChangedEvent]);
5168 if (eh != null)
5169 eh (this, e);
5172 [EditorBrowsable(EditorBrowsableState.Advanced)]
5173 protected virtual void OnChangeUICues(UICuesEventArgs e) {
5174 UICuesEventHandler eh = (UICuesEventHandler)(Events [ChangeUICuesEvent]);
5175 if (eh != null)
5176 eh (this, e);
5179 [EditorBrowsable(EditorBrowsableState.Advanced)]
5180 protected virtual void OnClick(EventArgs e) {
5181 EventHandler eh = (EventHandler)(Events [ClickEvent]);
5182 if (eh != null)
5183 eh (this, e);
5186 #if NET_2_0
5187 [EditorBrowsable (EditorBrowsableState.Advanced)]
5188 protected virtual void OnClientSizeChanged (EventArgs e)
5190 EventHandler eh = (EventHandler)(Events[ClientSizeChangedEvent]);
5191 if (eh != null)
5192 eh (this, e);
5194 #endif
5196 [EditorBrowsable(EditorBrowsableState.Advanced)]
5197 protected virtual void OnContextMenuChanged(EventArgs e) {
5198 EventHandler eh = (EventHandler)(Events [ContextMenuChangedEvent]);
5199 if (eh != null)
5200 eh (this, e);
5203 #if NET_2_0
5204 [EditorBrowsable (EditorBrowsableState.Advanced)]
5205 protected virtual void OnContextMenuStripChanged (EventArgs e) {
5206 EventHandler eh = (EventHandler)(Events [ContextMenuStripChangedEvent]);
5207 if (eh != null)
5208 eh (this, e);
5210 #endif
5212 [EditorBrowsable(EditorBrowsableState.Advanced)]
5213 protected virtual void OnControlAdded(ControlEventArgs e) {
5214 ControlEventHandler eh = (ControlEventHandler)(Events [ControlAddedEvent]);
5215 if (eh != null)
5216 eh (this, e);
5219 [EditorBrowsable(EditorBrowsableState.Advanced)]
5220 protected virtual void OnControlRemoved(ControlEventArgs e) {
5221 ControlEventHandler eh = (ControlEventHandler)(Events [ControlRemovedEvent]);
5222 if (eh != null)
5223 eh (this, e);
5226 [EditorBrowsable(EditorBrowsableState.Advanced)]
5227 protected virtual void OnCreateControl() {
5228 // Override me!
5231 [EditorBrowsable(EditorBrowsableState.Advanced)]
5232 protected virtual void OnCursorChanged(EventArgs e) {
5233 EventHandler eh = (EventHandler)(Events [CursorChangedEvent]);
5234 if (eh != null)
5235 eh (this, e);
5238 [EditorBrowsable(EditorBrowsableState.Advanced)]
5239 protected virtual void OnDockChanged(EventArgs e) {
5240 EventHandler eh = (EventHandler)(Events [DockChangedEvent]);
5241 if (eh != null)
5242 eh (this, e);
5245 [EditorBrowsable(EditorBrowsableState.Advanced)]
5246 protected virtual void OnDoubleClick(EventArgs e) {
5247 EventHandler eh = (EventHandler)(Events [DoubleClickEvent]);
5248 if (eh != null)
5249 eh (this, e);
5252 [EditorBrowsable(EditorBrowsableState.Advanced)]
5253 protected virtual void OnDragDrop(DragEventArgs drgevent) {
5254 DragEventHandler eh = (DragEventHandler)(Events [DragDropEvent]);
5255 if (eh != null)
5256 eh (this, drgevent);
5259 [EditorBrowsable(EditorBrowsableState.Advanced)]
5260 protected virtual void OnDragEnter(DragEventArgs drgevent) {
5261 DragEventHandler eh = (DragEventHandler)(Events [DragEnterEvent]);
5262 if (eh != null)
5263 eh (this, drgevent);
5266 [EditorBrowsable(EditorBrowsableState.Advanced)]
5267 protected virtual void OnDragLeave(EventArgs e) {
5268 EventHandler eh = (EventHandler)(Events [DragLeaveEvent]);
5269 if (eh != null)
5270 eh (this, e);
5273 [EditorBrowsable(EditorBrowsableState.Advanced)]
5274 protected virtual void OnDragOver(DragEventArgs drgevent) {
5275 DragEventHandler eh = (DragEventHandler)(Events [DragOverEvent]);
5276 if (eh != null)
5277 eh (this, drgevent);
5280 [EditorBrowsable(EditorBrowsableState.Advanced)]
5281 protected virtual void OnEnabledChanged(EventArgs e) {
5282 if (IsHandleCreated) {
5283 if (this is Form) {
5284 if (((Form)this).context == null) {
5285 XplatUI.EnableWindow(window.Handle, Enabled);
5287 } else {
5288 XplatUI.EnableWindow(window.Handle, Enabled);
5290 Refresh();
5293 EventHandler eh = (EventHandler)(Events [EnabledChangedEvent]);
5294 if (eh != null)
5295 eh (this, e);
5297 for (int i=0; i<child_controls.Count; i++) {
5298 child_controls[i].OnParentEnabledChanged(e);
5302 [EditorBrowsable(EditorBrowsableState.Advanced)]
5303 protected virtual void OnEnter(EventArgs e) {
5304 EventHandler eh = (EventHandler)(Events [EnterEvent]);
5305 if (eh != null)
5306 eh (this, e);
5309 [EditorBrowsable(EditorBrowsableState.Advanced)]
5310 protected virtual void OnFontChanged(EventArgs e) {
5311 EventHandler eh = (EventHandler)(Events [FontChangedEvent]);
5312 if (eh != null)
5313 eh (this, e);
5314 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentFontChanged(e);
5317 [EditorBrowsable(EditorBrowsableState.Advanced)]
5318 protected virtual void OnForeColorChanged(EventArgs e) {
5319 EventHandler eh = (EventHandler)(Events [ForeColorChangedEvent]);
5320 if (eh != null)
5321 eh (this, e);
5322 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentForeColorChanged(e);
5325 [EditorBrowsable(EditorBrowsableState.Advanced)]
5326 protected virtual void OnGiveFeedback(GiveFeedbackEventArgs gfbevent) {
5327 GiveFeedbackEventHandler eh = (GiveFeedbackEventHandler)(Events [GiveFeedbackEvent]);
5328 if (eh != null)
5329 eh (this, gfbevent);
5332 [EditorBrowsable(EditorBrowsableState.Advanced)]
5333 protected virtual void OnGotFocus(EventArgs e) {
5334 EventHandler eh = (EventHandler)(Events [GotFocusEvent]);
5335 if (eh != null)
5336 eh (this, e);
5339 [EditorBrowsable(EditorBrowsableState.Advanced)]
5340 protected virtual void OnHandleCreated(EventArgs e) {
5341 EventHandler eh = (EventHandler)(Events [HandleCreatedEvent]);
5342 if (eh != null)
5343 eh (this, e);
5346 [EditorBrowsable(EditorBrowsableState.Advanced)]
5347 protected virtual void OnHandleDestroyed(EventArgs e) {
5348 EventHandler eh = (EventHandler)(Events [HandleDestroyedEvent]);
5349 if (eh != null)
5350 eh (this, e);
5353 internal void RaiseHelpRequested (HelpEventArgs hevent) {
5354 OnHelpRequested (hevent);
5357 [EditorBrowsable(EditorBrowsableState.Advanced)]
5358 protected virtual void OnHelpRequested(HelpEventArgs hevent) {
5359 HelpEventHandler eh = (HelpEventHandler)(Events [HelpRequestedEvent]);
5360 if (eh != null)
5361 eh (this, hevent);
5364 protected virtual void OnImeModeChanged(EventArgs e) {
5365 EventHandler eh = (EventHandler)(Events [ImeModeChangedEvent]);
5366 if (eh != null)
5367 eh (this, e);
5370 [EditorBrowsable(EditorBrowsableState.Advanced)]
5371 protected virtual void OnInvalidated(InvalidateEventArgs e) {
5372 if (UseDoubleBuffering) {
5373 // should this block be here? seems like it
5374 // would be more at home in
5375 // NotifyInvalidated..
5376 if (e.InvalidRect == ClientRectangle) {
5377 InvalidateBackBuffer ();
5378 } else if (backbuffer != null){
5379 // we need this Inflate call here so
5380 // that the border of the rectangle is
5381 // considered Visible (the
5382 // invalid_region.IsVisible call) in
5383 // the WM_PAINT handling below.
5384 Rectangle r = Rectangle.Inflate(e.InvalidRect, 1,1);
5385 backbuffer.InvalidRegion.Union (r);
5389 InvalidateEventHandler eh = (InvalidateEventHandler)(Events [InvalidatedEvent]);
5390 if (eh != null)
5391 eh (this, e);
5394 [EditorBrowsable(EditorBrowsableState.Advanced)]
5395 protected virtual void OnKeyDown(KeyEventArgs e) {
5396 KeyEventHandler eh = (KeyEventHandler)(Events [KeyDownEvent]);
5397 if (eh != null)
5398 eh (this, e);
5401 [EditorBrowsable(EditorBrowsableState.Advanced)]
5402 protected virtual void OnKeyPress(KeyPressEventArgs e) {
5403 KeyPressEventHandler eh = (KeyPressEventHandler)(Events [KeyPressEvent]);
5404 if (eh != null)
5405 eh (this, e);
5408 [EditorBrowsable(EditorBrowsableState.Advanced)]
5409 protected virtual void OnKeyUp(KeyEventArgs e) {
5410 KeyEventHandler eh = (KeyEventHandler)(Events [KeyUpEvent]);
5411 if (eh != null)
5412 eh (this, e);
5415 [EditorBrowsable(EditorBrowsableState.Advanced)]
5416 protected virtual void OnLayout(LayoutEventArgs levent) {
5417 LayoutEventHandler eh = (LayoutEventHandler)(Events [LayoutEvent]);
5418 if (eh != null)
5419 eh (this, levent);
5421 LayoutEngine.Layout (this, levent);
5424 [EditorBrowsable(EditorBrowsableState.Advanced)]
5425 protected virtual void OnLeave(EventArgs e) {
5426 EventHandler eh = (EventHandler)(Events [LeaveEvent]);
5427 if (eh != null)
5428 eh (this, e);
5431 [EditorBrowsable(EditorBrowsableState.Advanced)]
5432 protected virtual void OnLocationChanged(EventArgs e) {
5433 OnMove(e);
5434 EventHandler eh = (EventHandler)(Events [LocationChangedEvent]);
5435 if (eh != null)
5436 eh (this, e);
5439 [EditorBrowsable(EditorBrowsableState.Advanced)]
5440 protected virtual void OnLostFocus(EventArgs e) {
5441 EventHandler eh = (EventHandler)(Events [LostFocusEvent]);
5442 if (eh != null)
5443 eh (this, e);
5446 #if NET_2_0
5447 protected virtual void OnMarginChanged (EventArgs e)
5449 EventHandler eh = (EventHandler)(Events[MarginChangedEvent]);
5450 if (eh != null)
5451 eh (this, e);
5453 #endif
5454 [EditorBrowsable (EditorBrowsableState.Advanced)]
5455 #if NET_2_0
5456 protected virtual void OnMouseCaptureChanged (EventArgs e)
5457 #else
5458 internal virtual void OnMouseCaptureChanged (EventArgs e)
5459 #endif
5461 EventHandler eh = (EventHandler)(Events [MouseCaptureChangedEvent]);
5462 if (eh != null)
5463 eh (this, e);
5466 #if NET_2_0
5467 [EditorBrowsable (EditorBrowsableState.Advanced)]
5468 protected virtual void OnMouseClick (MouseEventArgs e)
5470 MouseEventHandler eh = (MouseEventHandler)(Events [MouseClickEvent]);
5471 if (eh != null)
5472 eh (this, e);
5475 [EditorBrowsable (EditorBrowsableState.Advanced)]
5476 protected virtual void OnMouseDoubleClick (MouseEventArgs e)
5478 MouseEventHandler eh = (MouseEventHandler)(Events [MouseDoubleClickEvent]);
5479 if (eh != null)
5480 eh (this, e);
5482 #endif
5484 [EditorBrowsable(EditorBrowsableState.Advanced)]
5485 protected virtual void OnMouseDown(MouseEventArgs e) {
5486 MouseEventHandler eh = (MouseEventHandler)(Events [MouseDownEvent]);
5487 if (eh != null)
5488 eh (this, e);
5491 [EditorBrowsable(EditorBrowsableState.Advanced)]
5492 protected virtual void OnMouseEnter(EventArgs e) {
5493 EventHandler eh = (EventHandler)(Events [MouseEnterEvent]);
5494 if (eh != null)
5495 eh (this, e);
5498 [EditorBrowsable(EditorBrowsableState.Advanced)]
5499 protected virtual void OnMouseHover(EventArgs e) {
5500 EventHandler eh = (EventHandler)(Events [MouseHoverEvent]);
5501 if (eh != null)
5502 eh (this, e);
5505 [EditorBrowsable(EditorBrowsableState.Advanced)]
5506 protected virtual void OnMouseLeave(EventArgs e) {
5507 EventHandler eh = (EventHandler)(Events [MouseLeaveEvent]);
5508 if (eh != null)
5509 eh (this, e);
5512 [EditorBrowsable(EditorBrowsableState.Advanced)]
5513 protected virtual void OnMouseMove(MouseEventArgs e) {
5514 MouseEventHandler eh = (MouseEventHandler)(Events [MouseMoveEvent]);
5515 if (eh != null)
5516 eh (this, e);
5519 [EditorBrowsable(EditorBrowsableState.Advanced)]
5520 protected virtual void OnMouseUp(MouseEventArgs e) {
5521 MouseEventHandler eh = (MouseEventHandler)(Events [MouseUpEvent]);
5522 if (eh != null)
5523 eh (this, e);
5526 [EditorBrowsable(EditorBrowsableState.Advanced)]
5527 protected virtual void OnMouseWheel(MouseEventArgs e) {
5528 MouseEventHandler eh = (MouseEventHandler)(Events [MouseWheelEvent]);
5529 if (eh != null)
5530 eh (this, e);
5533 [EditorBrowsable(EditorBrowsableState.Advanced)]
5534 protected virtual void OnMove(EventArgs e) {
5535 EventHandler eh = (EventHandler)(Events [MoveEvent]);
5536 if (eh != null)
5537 eh (this, e);
5540 [EditorBrowsable(EditorBrowsableState.Advanced)]
5541 protected virtual void OnNotifyMessage(Message m) {
5542 // Override me!
5545 #if NET_2_0
5546 protected virtual void OnPaddingChanged (EventArgs e) {
5547 EventHandler eh = (EventHandler) (Events [PaddingChangedEvent]);
5548 if (eh != null)
5549 eh (this, e);
5551 #endif
5553 [EditorBrowsable(EditorBrowsableState.Advanced)]
5554 protected virtual void OnPaint(PaintEventArgs e) {
5555 PaintEventHandler eh = (PaintEventHandler)(Events [PaintEvent]);
5556 if (eh != null)
5557 eh (this, e);
5560 internal virtual void OnPaintBackgroundInternal(PaintEventArgs e) {
5561 // Override me
5564 internal virtual void OnPaintInternal(PaintEventArgs e) {
5565 // Override me
5568 [EditorBrowsable(EditorBrowsableState.Advanced)]
5569 protected virtual void OnPaintBackground(PaintEventArgs pevent) {
5570 PaintControlBackground (pevent);
5573 [EditorBrowsable(EditorBrowsableState.Advanced)]
5574 protected virtual void OnParentBackColorChanged(EventArgs e) {
5575 if (background_color.IsEmpty && background_image==null) {
5576 Invalidate();
5577 OnBackColorChanged(e);
5581 [EditorBrowsable(EditorBrowsableState.Advanced)]
5582 protected virtual void OnParentBackgroundImageChanged(EventArgs e) {
5583 Invalidate();
5584 OnBackgroundImageChanged(e);
5587 [EditorBrowsable(EditorBrowsableState.Advanced)]
5588 protected virtual void OnParentBindingContextChanged(EventArgs e) {
5589 if (binding_context==null) {
5590 binding_context=Parent.binding_context;
5591 OnBindingContextChanged(e);
5595 [EditorBrowsable(EditorBrowsableState.Advanced)]
5596 protected virtual void OnParentChanged(EventArgs e) {
5597 EventHandler eh = (EventHandler)(Events [ParentChangedEvent]);
5598 if (eh != null)
5599 eh (this, e);
5602 [EditorBrowsable(EditorBrowsableState.Advanced)]
5603 protected virtual void OnParentEnabledChanged(EventArgs e) {
5604 if (is_enabled) {
5605 OnEnabledChanged(e);
5609 [EditorBrowsable(EditorBrowsableState.Advanced)]
5610 protected virtual void OnParentFontChanged(EventArgs e) {
5611 if (font==null) {
5612 Invalidate();
5613 OnFontChanged(e);
5617 [EditorBrowsable(EditorBrowsableState.Advanced)]
5618 protected virtual void OnParentForeColorChanged(EventArgs e) {
5619 if (foreground_color.IsEmpty) {
5620 Invalidate();
5621 OnForeColorChanged(e);
5625 [EditorBrowsable(EditorBrowsableState.Advanced)]
5626 protected virtual void OnParentRightToLeftChanged(EventArgs e) {
5627 if (right_to_left==RightToLeft.Inherit) {
5628 Invalidate();
5629 OnRightToLeftChanged(e);
5633 [EditorBrowsable(EditorBrowsableState.Advanced)]
5634 protected virtual void OnParentVisibleChanged(EventArgs e) {
5635 if (is_visible) {
5636 OnVisibleChanged(e);
5640 [EditorBrowsable(EditorBrowsableState.Advanced)]
5641 protected virtual void OnQueryContinueDrag(QueryContinueDragEventArgs e) {
5642 QueryContinueDragEventHandler eh = (QueryContinueDragEventHandler)(Events [QueryContinueDragEvent]);
5643 if (eh != null)
5644 eh (this, e);
5647 #if NET_2_0
5648 [EditorBrowsable (EditorBrowsableState.Advanced)]
5649 protected virtual void OnRegionChanged (EventArgs e)
5651 EventHandler eh = (EventHandler)(Events[RegionChangedEvent]);
5652 if (eh != null)
5653 eh (this, e);
5655 #endif
5657 [EditorBrowsable(EditorBrowsableState.Advanced)]
5658 protected virtual void OnResize(EventArgs e) {
5659 PerformLayout(this, "Bounds");
5661 EventHandler eh = (EventHandler)(Events [ResizeEvent]);
5662 if (eh != null)
5663 eh (this, e);
5666 [EditorBrowsable(EditorBrowsableState.Advanced)]
5667 protected virtual void OnRightToLeftChanged(EventArgs e) {
5668 EventHandler eh = (EventHandler)(Events [RightToLeftChangedEvent]);
5669 if (eh != null)
5670 eh (this, e);
5671 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentRightToLeftChanged(e);
5674 [EditorBrowsable(EditorBrowsableState.Advanced)]
5675 protected virtual void OnSizeChanged(EventArgs e) {
5676 DisposeBackBuffer ();
5677 OnResize(e);
5678 EventHandler eh = (EventHandler)(Events [SizeChangedEvent]);
5679 if (eh != null)
5680 eh (this, e);
5683 [EditorBrowsable(EditorBrowsableState.Advanced)]
5684 protected virtual void OnStyleChanged(EventArgs e) {
5685 EventHandler eh = (EventHandler)(Events [StyleChangedEvent]);
5686 if (eh != null)
5687 eh (this, e);
5690 [EditorBrowsable(EditorBrowsableState.Advanced)]
5691 protected virtual void OnSystemColorsChanged(EventArgs e) {
5692 EventHandler eh = (EventHandler)(Events [SystemColorsChangedEvent]);
5693 if (eh != null)
5694 eh (this, e);
5697 [EditorBrowsable(EditorBrowsableState.Advanced)]
5698 protected virtual void OnTabIndexChanged(EventArgs e) {
5699 EventHandler eh = (EventHandler)(Events [TabIndexChangedEvent]);
5700 if (eh != null)
5701 eh (this, e);
5704 [EditorBrowsable(EditorBrowsableState.Advanced)]
5705 protected virtual void OnTabStopChanged(EventArgs e) {
5706 EventHandler eh = (EventHandler)(Events [TabStopChangedEvent]);
5707 if (eh != null)
5708 eh (this, e);
5711 [EditorBrowsable(EditorBrowsableState.Advanced)]
5712 protected virtual void OnTextChanged(EventArgs e) {
5713 EventHandler eh = (EventHandler)(Events [TextChangedEvent]);
5714 if (eh != null)
5715 eh (this, e);
5718 [EditorBrowsable(EditorBrowsableState.Advanced)]
5719 protected virtual void OnValidated(EventArgs e) {
5720 EventHandler eh = (EventHandler)(Events [ValidatedEvent]);
5721 if (eh != null)
5722 eh (this, e);
5725 [EditorBrowsable(EditorBrowsableState.Advanced)]
5726 protected virtual void OnValidating(System.ComponentModel.CancelEventArgs e) {
5727 CancelEventHandler eh = (CancelEventHandler)(Events [ValidatingEvent]);
5728 if (eh != null)
5729 eh (this, e);
5732 [EditorBrowsable(EditorBrowsableState.Advanced)]
5733 protected virtual void OnVisibleChanged(EventArgs e) {
5734 if (Visible)
5735 CreateControl ();
5737 EventHandler eh = (EventHandler)(Events [VisibleChangedEvent]);
5738 if (eh != null)
5739 eh (this, e);
5741 // We need to tell our kids (including implicit ones)
5742 foreach (Control c in Controls.GetAllControls ())
5743 if (c.Visible)
5744 c.OnParentVisibleChanged (e);
5746 #endregion // OnXXX methods
5748 #region Events
5749 #if NET_2_0
5750 static object AutoSizeChangedEvent = new object ();
5751 #endif
5752 static object BackColorChangedEvent = new object ();
5753 static object BackgroundImageChangedEvent = new object ();
5754 #if NET_2_0
5755 static object BackgroundImageLayoutChangedEvent = new object ();
5756 #endif
5757 static object BindingContextChangedEvent = new object ();
5758 static object CausesValidationChangedEvent = new object ();
5759 static object ChangeUICuesEvent = new object ();
5760 static object ClickEvent = new object ();
5761 #if NET_2_0
5762 static object ClientSizeChangedEvent = new object ();
5763 #endif
5764 static object ContextMenuChangedEvent = new object ();
5765 #if NET_2_0
5766 static object ContextMenuStripChangedEvent = new object ();
5767 #endif
5768 static object ControlAddedEvent = new object ();
5769 static object ControlRemovedEvent = new object ();
5770 static object CursorChangedEvent = new object ();
5771 static object DockChangedEvent = new object ();
5772 static object DoubleClickEvent = new object ();
5773 static object DragDropEvent = new object ();
5774 static object DragEnterEvent = new object ();
5775 static object DragLeaveEvent = new object ();
5776 static object DragOverEvent = new object ();
5777 static object EnabledChangedEvent = new object ();
5778 static object EnterEvent = new object ();
5779 static object FontChangedEvent = new object ();
5780 static object ForeColorChangedEvent = new object ();
5781 static object GiveFeedbackEvent = new object ();
5782 static object GotFocusEvent = new object ();
5783 static object HandleCreatedEvent = new object ();
5784 static object HandleDestroyedEvent = new object ();
5785 static object HelpRequestedEvent = new object ();
5786 static object ImeModeChangedEvent = new object ();
5787 static object InvalidatedEvent = new object ();
5788 static object KeyDownEvent = new object ();
5789 static object KeyPressEvent = new object ();
5790 static object KeyUpEvent = new object ();
5791 static object LayoutEvent = new object ();
5792 static object LeaveEvent = new object ();
5793 static object LocationChangedEvent = new object ();
5794 static object LostFocusEvent = new object ();
5795 #if NET_2_0
5796 static object MarginChangedEvent = new object ();
5797 #endif
5798 static object MouseCaptureChangedEvent = new object ();
5799 #if NET_2_0
5800 static object MouseClickEvent = new object ();
5801 static object MouseDoubleClickEvent = new object ();
5802 #endif
5803 static object MouseDownEvent = new object ();
5804 static object MouseEnterEvent = new object ();
5805 static object MouseHoverEvent = new object ();
5806 static object MouseLeaveEvent = new object ();
5807 static object MouseMoveEvent = new object ();
5808 static object MouseUpEvent = new object ();
5809 static object MouseWheelEvent = new object ();
5810 static object MoveEvent = new object ();
5811 #if NET_2_0
5812 static object PaddingChangedEvent = new object ();
5813 #endif
5814 static object PaintEvent = new object ();
5815 static object ParentChangedEvent = new object ();
5816 #if NET_2_0
5817 static object PreviewKeyDownEvent = new object ();
5818 #endif
5819 static object QueryAccessibilityHelpEvent = new object ();
5820 static object QueryContinueDragEvent = new object ();
5821 #if NET_2_0
5822 static object RegionChangedEvent = new object ();
5823 #endif
5824 static object ResizeEvent = new object ();
5825 static object RightToLeftChangedEvent = new object ();
5826 static object SizeChangedEvent = new object ();
5827 static object StyleChangedEvent = new object ();
5828 static object SystemColorsChangedEvent = new object ();
5829 static object TabIndexChangedEvent = new object ();
5830 static object TabStopChangedEvent = new object ();
5831 static object TextChangedEvent = new object ();
5832 static object ValidatedEvent = new object ();
5833 static object ValidatingEvent = new object ();
5834 static object VisibleChangedEvent = new object ();
5836 #if NET_2_0
5837 [Browsable (false)]
5838 [EditorBrowsable (EditorBrowsableState.Never)]
5839 public event EventHandler AutoSizeChanged {
5840 add { Events.AddHandler (AutoSizeChangedEvent, value);}
5841 remove {Events.RemoveHandler (AutoSizeChangedEvent, value);}
5843 #endif
5844 public event EventHandler BackColorChanged {
5845 add { Events.AddHandler (BackColorChangedEvent, value); }
5846 remove { Events.RemoveHandler (BackColorChangedEvent, value); }
5849 public event EventHandler BackgroundImageChanged {
5850 add { Events.AddHandler (BackgroundImageChangedEvent, value); }
5851 remove { Events.RemoveHandler (BackgroundImageChangedEvent, value); }
5854 #if NET_2_0
5855 public event EventHandler BackgroundImageLayoutChanged {
5856 add {Events.AddHandler (BackgroundImageLayoutChangedEvent, value);}
5857 remove {Events.RemoveHandler (BackgroundImageLayoutChangedEvent, value);}
5859 #endif
5861 public event EventHandler BindingContextChanged {
5862 add { Events.AddHandler (BindingContextChangedEvent, value); }
5863 remove { Events.RemoveHandler (BindingContextChangedEvent, value); }
5866 public event EventHandler CausesValidationChanged {
5867 add { Events.AddHandler (CausesValidationChangedEvent, value); }
5868 remove { Events.RemoveHandler (CausesValidationChangedEvent, value); }
5871 public event UICuesEventHandler ChangeUICues {
5872 add { Events.AddHandler (ChangeUICuesEvent, value); }
5873 remove { Events.RemoveHandler (ChangeUICuesEvent, value); }
5876 public event EventHandler Click {
5877 add { Events.AddHandler (ClickEvent, value); }
5878 remove { Events.RemoveHandler (ClickEvent, value); }
5881 #if NET_2_0
5882 public event EventHandler ClientSizeChanged {
5883 add {Events.AddHandler (ClientSizeChangedEvent, value);}
5884 remove {Events.RemoveHandler (ClientSizeChangedEvent, value);}
5886 #endif
5888 #if NET_2_0
5889 [Browsable (false)]
5890 #endif
5891 public event EventHandler ContextMenuChanged {
5892 add { Events.AddHandler (ContextMenuChangedEvent, value); }
5893 remove { Events.RemoveHandler (ContextMenuChangedEvent, value); }
5896 #if NET_2_0
5897 public event EventHandler ContextMenuStripChanged {
5898 add { Events.AddHandler (ContextMenuStripChangedEvent, value); }
5899 remove { Events.RemoveHandler (ContextMenuStripChangedEvent, value);}
5901 #endif
5904 [EditorBrowsable(EditorBrowsableState.Advanced)]
5905 #if NET_2_0
5906 [Browsable(true)]
5907 #else
5908 [Browsable(false)]
5909 #endif
5910 public event ControlEventHandler ControlAdded {
5911 add { Events.AddHandler (ControlAddedEvent, value); }
5912 remove { Events.RemoveHandler (ControlAddedEvent, value); }
5915 [EditorBrowsable(EditorBrowsableState.Advanced)]
5916 #if NET_2_0
5917 [Browsable(true)]
5918 #else
5919 [Browsable(false)]
5920 #endif
5921 public event ControlEventHandler ControlRemoved {
5922 add { Events.AddHandler (ControlRemovedEvent, value); }
5923 remove { Events.RemoveHandler (ControlRemovedEvent, value); }
5926 [MWFDescription("Fired when the cursor for the control has been changed"), MWFCategory("PropertyChanged")]
5927 public event EventHandler CursorChanged {
5928 add { Events.AddHandler (CursorChangedEvent, value); }
5929 remove { Events.RemoveHandler (CursorChangedEvent, value); }
5931 public event EventHandler DockChanged {
5932 add { Events.AddHandler (DockChangedEvent, value); }
5933 remove { Events.RemoveHandler (DockChangedEvent, value); }
5936 public event EventHandler DoubleClick {
5937 add { Events.AddHandler (DoubleClickEvent, value); }
5938 remove { Events.RemoveHandler (DoubleClickEvent, value); }
5941 public event DragEventHandler DragDrop {
5942 add { Events.AddHandler (DragDropEvent, value); }
5943 remove { Events.RemoveHandler (DragDropEvent, value); }
5946 public event DragEventHandler DragEnter {
5947 add { Events.AddHandler (DragEnterEvent, value); }
5948 remove { Events.RemoveHandler (DragEnterEvent, value); }
5951 public event EventHandler DragLeave {
5952 add { Events.AddHandler (DragLeaveEvent, value); }
5953 remove { Events.RemoveHandler (DragLeaveEvent, value); }
5956 public event DragEventHandler DragOver {
5957 add { Events.AddHandler (DragOverEvent, value); }
5958 remove { Events.RemoveHandler (DragOverEvent, value); }
5961 public event EventHandler EnabledChanged {
5962 add { Events.AddHandler (EnabledChangedEvent, value); }
5963 remove { Events.RemoveHandler (EnabledChangedEvent, value); }
5966 public event EventHandler Enter {
5967 add { Events.AddHandler (EnterEvent, value); }
5968 remove { Events.RemoveHandler (EnterEvent, value); }
5971 public event EventHandler FontChanged {
5972 add { Events.AddHandler (FontChangedEvent, value); }
5973 remove { Events.RemoveHandler (FontChangedEvent, value); }
5976 public event EventHandler ForeColorChanged {
5977 add { Events.AddHandler (ForeColorChangedEvent, value); }
5978 remove { Events.RemoveHandler (ForeColorChangedEvent, value); }
5981 public event GiveFeedbackEventHandler GiveFeedback {
5982 add { Events.AddHandler (GiveFeedbackEvent, value); }
5983 remove { Events.RemoveHandler (GiveFeedbackEvent, value); }
5986 [EditorBrowsable(EditorBrowsableState.Advanced)]
5987 [Browsable(false)]
5988 public event EventHandler GotFocus {
5989 add { Events.AddHandler (GotFocusEvent, value); }
5990 remove { Events.RemoveHandler (GotFocusEvent, value); }
5994 [EditorBrowsable(EditorBrowsableState.Advanced)]
5995 [Browsable(false)]
5996 public event EventHandler HandleCreated {
5997 add { Events.AddHandler (HandleCreatedEvent, value); }
5998 remove { Events.RemoveHandler (HandleCreatedEvent, value); }
6001 [EditorBrowsable(EditorBrowsableState.Advanced)]
6002 [Browsable(false)]
6003 public event EventHandler HandleDestroyed {
6004 add { Events.AddHandler (HandleDestroyedEvent, value); }
6005 remove { Events.RemoveHandler (HandleDestroyedEvent, value); }
6008 public event HelpEventHandler HelpRequested {
6009 add { Events.AddHandler (HelpRequestedEvent, value); }
6010 remove { Events.RemoveHandler (HelpRequestedEvent, value); }
6013 public event EventHandler ImeModeChanged {
6014 add { Events.AddHandler (ImeModeChangedEvent, value); }
6015 remove { Events.RemoveHandler (ImeModeChangedEvent, value); }
6018 [EditorBrowsable(EditorBrowsableState.Advanced)]
6019 [Browsable(false)]
6020 public event InvalidateEventHandler Invalidated {
6021 add { Events.AddHandler (InvalidatedEvent, value); }
6022 remove { Events.RemoveHandler (InvalidatedEvent, value); }
6025 public event KeyEventHandler KeyDown {
6026 add { Events.AddHandler (KeyDownEvent, value); }
6027 remove { Events.RemoveHandler (KeyDownEvent, value); }
6030 public event KeyPressEventHandler KeyPress {
6031 add { Events.AddHandler (KeyPressEvent, value); }
6032 remove { Events.RemoveHandler (KeyPressEvent, value); }
6035 public event KeyEventHandler KeyUp {
6036 add { Events.AddHandler (KeyUpEvent, value); }
6037 remove { Events.RemoveHandler (KeyUpEvent, value); }
6040 public event LayoutEventHandler Layout {
6041 add { Events.AddHandler (LayoutEvent, value); }
6042 remove { Events.RemoveHandler (LayoutEvent, value); }
6045 public event EventHandler Leave {
6046 add { Events.AddHandler (LeaveEvent, value); }
6047 remove { Events.RemoveHandler (LeaveEvent, value); }
6050 public event EventHandler LocationChanged {
6051 add { Events.AddHandler (LocationChangedEvent, value); }
6052 remove { Events.RemoveHandler (LocationChangedEvent, value); }
6055 [EditorBrowsable(EditorBrowsableState.Advanced)]
6056 [Browsable(false)]
6057 public event EventHandler LostFocus {
6058 add { Events.AddHandler (LostFocusEvent, value); }
6059 remove { Events.RemoveHandler (LostFocusEvent, value); }
6062 #if NET_2_0
6063 public event EventHandler MarginChanged {
6064 add { Events.AddHandler (MarginChangedEvent, value); }
6065 remove {Events.RemoveHandler (MarginChangedEvent, value); }
6067 #endif
6068 #if NET_2_0
6069 public event EventHandler MouseCaptureChanged {
6070 #else
6071 internal event EventHandler MouseCaptureChanged {
6072 #endif
6073 add { Events.AddHandler (MouseCaptureChangedEvent, value); }
6074 remove { Events.RemoveHandler (MouseCaptureChangedEvent, value); }
6076 #if NET_2_0
6077 public event MouseEventHandler MouseClick
6079 add { Events.AddHandler (MouseClickEvent, value); }
6080 remove { Events.RemoveHandler (MouseClickEvent, value); }
6082 public event MouseEventHandler MouseDoubleClick
6084 add { Events.AddHandler (MouseDoubleClickEvent, value); }
6085 remove { Events.RemoveHandler (MouseDoubleClickEvent, value); }
6087 #endif
6088 public event MouseEventHandler MouseDown {
6089 add { Events.AddHandler (MouseDownEvent, value); }
6090 remove { Events.RemoveHandler (MouseDownEvent, value); }
6093 public event EventHandler MouseEnter {
6094 add { Events.AddHandler (MouseEnterEvent, value); }
6095 remove { Events.RemoveHandler (MouseEnterEvent, value); }
6098 public event EventHandler MouseHover {
6099 add { Events.AddHandler (MouseHoverEvent, value); }
6100 remove { Events.RemoveHandler (MouseHoverEvent, value); }
6103 public event EventHandler MouseLeave {
6104 add { Events.AddHandler (MouseLeaveEvent, value); }
6105 remove { Events.RemoveHandler (MouseLeaveEvent, value); }
6108 public event MouseEventHandler MouseMove {
6109 add { Events.AddHandler (MouseMoveEvent, value); }
6110 remove { Events.RemoveHandler (MouseMoveEvent, value); }
6113 public event MouseEventHandler MouseUp {
6114 add { Events.AddHandler (MouseUpEvent, value); }
6115 remove { Events.RemoveHandler (MouseUpEvent, value); }
6118 [EditorBrowsable(EditorBrowsableState.Advanced)]
6119 [Browsable(false)]
6120 public event MouseEventHandler MouseWheel {
6121 add { Events.AddHandler (MouseWheelEvent, value); }
6122 remove { Events.RemoveHandler (MouseWheelEvent, value); }
6125 public event EventHandler Move {
6126 add { Events.AddHandler (MoveEvent, value); }
6127 remove { Events.RemoveHandler (MoveEvent, value); }
6129 #if NET_2_0
6130 public event EventHandler PaddingChanged
6132 add { Events.AddHandler (PaddingChangedEvent, value); }
6133 remove { Events.RemoveHandler (PaddingChangedEvent, value); }
6135 #endif
6136 public event PaintEventHandler Paint {
6137 add { Events.AddHandler (PaintEvent, value); }
6138 remove { Events.RemoveHandler (PaintEvent, value); }
6141 public event EventHandler ParentChanged {
6142 add { Events.AddHandler (ParentChangedEvent, value); }
6143 remove { Events.RemoveHandler (ParentChangedEvent, value); }
6146 #if NET_2_0
6147 public event PreviewKeyDownEventHandler PreviewKeyDown {
6148 add { Events.AddHandler (PreviewKeyDownEvent, value); }
6149 remove { Events.RemoveHandler (PreviewKeyDownEvent, value); }
6151 #endif
6153 public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp {
6154 add { Events.AddHandler (QueryAccessibilityHelpEvent, value); }
6155 remove { Events.RemoveHandler (QueryAccessibilityHelpEvent, value); }
6158 public event QueryContinueDragEventHandler QueryContinueDrag {
6159 add { Events.AddHandler (QueryContinueDragEvent, value); }
6160 remove { Events.RemoveHandler (QueryContinueDragEvent, value); }
6163 #if NET_2_0
6164 public event EventHandler RegionChanged {
6165 add { Events.AddHandler (RegionChangedEvent, value); }
6166 remove { Events.RemoveHandler (RegionChangedEvent, value); }
6168 #endif
6170 #if NET_2_0
6171 [EditorBrowsable (EditorBrowsableState.Advanced)]
6172 #endif
6173 public event EventHandler Resize {
6174 add { Events.AddHandler (ResizeEvent, value); }
6175 remove { Events.RemoveHandler (ResizeEvent, value); }
6178 public event EventHandler RightToLeftChanged {
6179 add { Events.AddHandler (RightToLeftChangedEvent, value); }
6180 remove { Events.RemoveHandler (RightToLeftChangedEvent, value); }
6183 public event EventHandler SizeChanged {
6184 add { Events.AddHandler (SizeChangedEvent, value); }
6185 remove { Events.RemoveHandler (SizeChangedEvent, value); }
6188 public event EventHandler StyleChanged {
6189 add { Events.AddHandler (StyleChangedEvent, value); }
6190 remove { Events.RemoveHandler (StyleChangedEvent, value); }
6193 public event EventHandler SystemColorsChanged {
6194 add { Events.AddHandler (SystemColorsChangedEvent, value); }
6195 remove { Events.RemoveHandler (SystemColorsChangedEvent, value); }
6198 public event EventHandler TabIndexChanged {
6199 add { Events.AddHandler (TabIndexChangedEvent, value); }
6200 remove { Events.RemoveHandler (TabIndexChangedEvent, value); }
6203 public event EventHandler TabStopChanged {
6204 add { Events.AddHandler (TabStopChangedEvent, value); }
6205 remove { Events.RemoveHandler (TabStopChangedEvent, value); }
6208 public event EventHandler TextChanged {
6209 add { Events.AddHandler (TextChangedEvent, value); }
6210 remove { Events.RemoveHandler (TextChangedEvent, value); }
6213 public event EventHandler Validated {
6214 add { Events.AddHandler (ValidatedEvent, value); }
6215 remove { Events.RemoveHandler (ValidatedEvent, value); }
6218 public event CancelEventHandler Validating {
6219 add { Events.AddHandler (ValidatingEvent, value); }
6220 remove { Events.RemoveHandler (ValidatingEvent, value); }
6223 public event EventHandler VisibleChanged {
6224 add { Events.AddHandler (VisibleChangedEvent, value); }
6225 remove { Events.RemoveHandler (VisibleChangedEvent, value); }
6228 #endregion // Events