* Control.cs: really remove the call to XplatUI.SetVisible from
[mono-project.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / Control.cs
blobde197cd4f4926d4a4959654f2c3eeb13ba1ac385
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 string name; // for object naming
74 // State
75 bool is_created; // true if OnCreateControl has been sent
76 internal bool has_focus; // true if control has focus
77 internal bool is_visible; // true if control is visible
78 internal bool is_entered; // is the mouse inside the control?
79 internal bool is_enabled; // true if control is enabled (usable/not grayed out)
80 bool is_accessible; // true if the control is visible to accessibility applications
81 bool is_captured; // tracks if the control has captured the mouse
82 internal bool is_toplevel; // tracks if the control is a toplevel window
83 bool is_recreating; // tracks if the handle for the control is being recreated
84 bool causes_validation; // tracks if validation is executed on changes
85 bool is_focusing; // tracks if Focus has been called on the control and has not yet finished
86 int tab_index; // position in tab order of siblings
87 bool tab_stop; // is the control a tab stop?
88 bool is_disposed; // has the window already been disposed?
89 Size client_size; // size of the client area (window excluding decorations)
90 Rectangle client_rect; // rectangle with the client area (window excluding decorations)
91 ControlStyles control_style; // rather win32-specific, style bits for control
92 ImeMode ime_mode;
93 object control_tag; // object that contains data about our control
94 internal int mouse_clicks; // Counter for mouse clicks
95 Cursor cursor; // Cursor for the window
96 internal bool allow_drop; // true if the control accepts droping objects on it
97 Region clip_region; // User-specified clip region for the window
99 // Visuals
100 internal Color foreground_color; // foreground color for control
101 internal Color background_color; // background color for control
102 Image background_image; // background image for control
103 internal Font font; // font for control
104 string text; // window/title text for control
105 internal BorderStyle border_style; // Border style of control
107 // Layout
108 internal enum LayoutType {
109 Anchor,
110 Dock
112 Layout.LayoutEngine layout_engine;
113 int layout_suspended;
114 bool layout_pending; // true if our parent needs to re-layout us
115 internal AnchorStyles anchor_style; // anchoring requirements for our control
116 internal DockStyle dock_style; // docking requirements for our control
117 LayoutType layout_type;
119 // Please leave the next 2 as internal until DefaultLayout (2.0) is rewritten
120 internal int dist_right; // distance to the right border of the parent
121 internal int dist_bottom; // distance to the bottom border of the parent
123 // to be categorized...
124 ControlCollection child_controls; // our children
125 Control parent; // our parent control
126 AccessibleObject accessibility_object; // object that contains accessibility information about our control
127 BindingContext binding_context;
128 RightToLeft right_to_left; // drawing direction for control
129 ContextMenu context_menu; // Context menu associated with the control
130 internal bool use_compatible_text_rendering;
132 // double buffering
133 DoubleBuffer backbuffer;
135 // to implement DeviceContext without depending on double buffering
136 Bitmap bmp;
137 Graphics bmp_g;
139 ControlBindingsCollection data_bindings;
141 #if NET_2_0
142 static bool verify_thread_handle;
143 Padding padding;
144 ImageLayout backgroundimage_layout;
145 Size maximum_size;
146 Size minimum_size;
147 Padding margin;
148 private ContextMenuStrip context_menu_strip;
149 #endif
151 #endregion // Local Variables
153 #region Private Classes
154 // This helper class allows us to dispatch messages to Control.WndProc
155 internal class ControlNativeWindow : NativeWindow {
156 private Control owner;
158 public ControlNativeWindow(Control control) : base() {
159 this.owner=control;
163 public Control Owner {
164 get {
165 return owner;
169 static internal Control ControlFromHandle(IntPtr hWnd) {
170 ControlNativeWindow window;
172 window = (ControlNativeWindow)window_collection[hWnd];
173 if (window != null) {
174 return window.owner;
177 return null;
180 static internal Control ControlFromChildHandle (IntPtr handle) {
181 ControlNativeWindow window;
183 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
184 while (hwnd != null) {
185 window = (ControlNativeWindow)window_collection[hwnd.Handle];
186 if (window != null) {
187 return window.owner;
189 hwnd = hwnd.Parent;
192 return null;
195 protected override void WndProc(ref Message m) {
196 owner.WndProc(ref m);
199 #endregion
201 #region Public Classes
202 [ComVisible(true)]
203 public class ControlAccessibleObject : AccessibleObject {
204 IntPtr handle;
206 #region ControlAccessibleObject Constructors
207 public ControlAccessibleObject(Control ownerControl)
208 : base (ownerControl)
210 if (ownerControl == null)
211 throw new ArgumentNullException ("owner");
213 handle = ownerControl.Handle;
215 #endregion // ControlAccessibleObject Constructors
217 #region ControlAccessibleObject Public Instance Properties
218 public override string DefaultAction {
219 get {
220 return base.DefaultAction;
224 public override string Description {
225 get {
226 return base.Description;
230 public IntPtr Handle {
231 get {
232 return handle;
235 set {
236 // We don't want to let them set it
240 public override string Help {
241 get {
242 return base.Help;
246 public override string KeyboardShortcut {
247 get {
248 return base.KeyboardShortcut;
252 public override string Name {
253 get {
254 return base.Name;
257 set {
258 base.Name = value;
262 public Control Owner {
263 get {
264 return base.owner;
268 public override AccessibleObject Parent {
269 get {
270 return base.Parent;
275 public override AccessibleRole Role {
276 get {
277 return base.Role;
280 #endregion // ControlAccessibleObject Public Instance Properties
282 #region ControlAccessibleObject Public Instance Methods
283 public override int GetHelpTopic(out string FileName) {
284 return base.GetHelpTopic (out FileName);
287 [MonoTODO ("Implement this")]
288 public void NotifyClients(AccessibleEvents accEvent) {
289 throw new NotImplementedException();
292 [MonoTODO ("Implement this")]
293 public void NotifyClients(AccessibleEvents accEvent, int childID) {
296 public override string ToString() {
297 return "ControlAccessibleObject: Owner = " + owner.ToString() + ", Text: " + owner.text;
300 #endregion // ControlAccessibleObject Public Instance Methods
303 private class DoubleBuffer : IDisposable
305 public Region InvalidRegion;
306 private Stack real_graphics;
307 private object back_buffer;
308 private Control parent;
309 private bool pending_disposal;
311 public DoubleBuffer (Control parent) {
312 this.parent = parent;
313 real_graphics = new Stack ();
314 int width = parent.Width;
315 int height = parent.Height;
317 if (width < 1) width = 1;
318 if (height < 1) height = 1;
320 XplatUI.CreateOffscreenDrawable (parent.Handle, width, height, out back_buffer);
321 Invalidate ();
324 public void Blit (PaintEventArgs pe) {
325 Graphics buffered_graphics;
326 buffered_graphics = XplatUI.GetOffscreenGraphics (back_buffer);
327 XplatUI.BlitFromOffscreen (parent.Handle, pe.Graphics, back_buffer, buffered_graphics, pe.ClipRectangle);
328 buffered_graphics.Dispose ();
331 public void Start (PaintEventArgs pe) {
332 // We need to get the graphics for every paint.
333 real_graphics.Push(pe.SetGraphics (XplatUI.GetOffscreenGraphics (back_buffer)));
336 public void End (PaintEventArgs pe) {
337 Graphics buffered_graphics;
338 buffered_graphics = pe.SetGraphics ((Graphics) real_graphics.Pop ());
340 if (pending_disposal)
341 Dispose ();
342 else {
343 XplatUI.BlitFromOffscreen (parent.Handle, pe.Graphics, back_buffer, buffered_graphics, pe.ClipRectangle);
344 InvalidRegion.Exclude (pe.ClipRectangle);
346 buffered_graphics.Dispose ();
349 public void Invalidate () {
350 if (InvalidRegion != null)
351 InvalidRegion.Dispose ();
352 InvalidRegion = new Region (parent.ClientRectangle);
355 public void Dispose () {
356 if (real_graphics.Count > 0) {
357 pending_disposal = true;
358 return;
361 XplatUI.DestroyOffscreenDrawable (back_buffer);
363 if (InvalidRegion != null)
364 InvalidRegion.Dispose ();
365 InvalidRegion = null;
366 back_buffer = null;
367 GC.SuppressFinalize (this);
370 #region IDisposable Members
371 void IDisposable.Dispose () {
372 Dispose ();
374 #endregion
376 ~DoubleBuffer () {
377 Dispose ();
381 [ListBindable (false)]
382 #if NET_2_0
383 [ComVisible (false)]
384 public class ControlCollection : Layout.ArrangedElementCollection, IList, ICollection, ICloneable, IEnumerable {
385 #else
386 [DesignerSerializer("System.Windows.Forms.Design.ControlCollectionCodeDomSerializer, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
387 public class ControlCollection : IList, ICollection, ICloneable, IEnumerable {
388 #endif
389 #region ControlCollection Local Variables
390 #if !NET_2_0
391 ArrayList list;
392 #endif
393 ArrayList impl_list;
394 Control[] all_controls;
395 Control owner;
396 #endregion // ControlCollection Local Variables
398 #region ControlCollection Public Constructor
399 public ControlCollection(Control owner) {
400 this.owner=owner;
401 #if !NET_2_0
402 this.list=new ArrayList();
403 #endif
405 #endregion
407 #region ControlCollection Public Instance Properties
408 int ICollection.Count {
409 get { return Count; }
413 #if !NET_2_0
414 public int Count {
415 get { return list.Count; }
417 #endif
419 #if NET_2_0
420 bool IList.IsReadOnly
421 #else
422 public bool IsReadOnly
423 #endif
425 get {
426 return list.IsReadOnly;
430 #if NET_2_0
431 public Control Owner { get { return this.owner; } }
433 public virtual Control this[string key] {
434 get {
435 int index = IndexOfKey (key);
437 if (index >= 0)
438 return this[index];
440 return null;
445 #endif
446 public virtual Control this[int index] {
447 get {
448 if (index < 0 || index >= list.Count) {
449 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
451 return (Control)list[index];
456 #endregion // ControlCollection Public Instance Properties
458 #region ControlCollection Instance Methods
459 public virtual void Add (Control value) {
460 if (value == null)
461 return;
463 bool owner_permits_toplevels = (owner is MdiClient) || (owner is Form && ((Form)owner).IsMdiContainer);
464 bool child_is_toplevel = ((Control)value).GetTopLevel();
465 bool child_is_mdichild = (value is Form && ((Form)value).IsMdiChild);
467 if (child_is_toplevel && !(owner_permits_toplevels && child_is_mdichild))
468 throw new ArgumentException("Cannot add a top level control to a control.", "value");
470 if (Contains (value)) {
471 owner.PerformLayout();
472 return;
475 if (value.tab_index == -1) {
476 int end;
477 int index;
478 int use;
480 use = 0;
481 end = owner.child_controls.Count;
482 for (int i = 0; i < end; i++) {
483 index = owner.child_controls[i].tab_index;
484 if (index >= use) {
485 use = index + 1;
488 value.tab_index = use;
491 if (value.parent != null) {
492 value.parent.Controls.Remove(value);
495 all_controls = null;
496 list.Add (value);
498 value.ChangeParent(owner);
500 value.InitLayout();
502 if (owner.Visible)
503 owner.UpdateChildrenZOrder();
504 owner.PerformLayout(value, "Parent");
505 owner.OnControlAdded(new ControlEventArgs(value));
508 internal void AddToList (Control c) {
509 all_controls = null;
510 list.Add (c);
513 internal virtual void AddImplicit (Control control) {
514 if (impl_list == null)
515 impl_list = new ArrayList ();
517 if (AllContains (control)) {
518 owner.PerformLayout ();
519 return;
522 if (control.parent != null) {
523 control.parent.Controls.Remove(control);
526 all_controls = null;
527 impl_list.Add (control);
529 control.ChangeParent (owner);
530 control.InitLayout ();
531 if (owner.Visible)
532 owner.UpdateChildrenZOrder ();
533 owner.PerformLayout (control, "Parent");
534 owner.OnControlAdded (new ControlEventArgs (control));
536 #if NET_2_0
537 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
538 #endif
539 public virtual void AddRange (Control[] controls) {
540 if (controls == null)
541 throw new ArgumentNullException ("controls");
543 owner.SuspendLayout ();
545 try {
546 for (int i = 0; i < controls.Length; i++)
547 Add (controls[i]);
548 } finally {
549 owner.ResumeLayout ();
553 internal virtual void AddRangeImplicit (Control [] controls) {
554 if (controls == null)
555 throw new ArgumentNullException ("controls");
557 owner.SuspendLayout ();
559 try {
560 for (int i = 0; i < controls.Length; i++)
561 AddImplicit (controls [i]);
562 } finally {
563 owner.ResumeLayout ();
567 #if NET_2_0
569 #endif
570 public virtual void Clear () {
571 all_controls = null;
573 // MS sends remove events in reverse order
574 while (list.Count > 0) {
575 Remove((Control)list[list.Count - 1]);
579 internal virtual void ClearImplicit () {
580 if (impl_list == null)
581 return;
582 all_controls = null;
583 impl_list.Clear ();
586 public bool Contains (Control value) {
587 for (int i = list.Count; i > 0; ) {
588 i--;
590 if (list [i] == value) {
591 // Do we need to do anything here?
592 return true;
595 return false;
598 internal bool ImplicitContains (Control value) {
599 if (impl_list == null)
600 return false;
602 for (int i = impl_list.Count; i > 0; ) {
603 i--;
605 if (impl_list [i] == value) {
606 // Do we need to do anything here?
607 return true;
610 return false;
613 internal bool AllContains (Control value) {
614 return Contains (value) || ImplicitContains (value);
617 #if NET_2_0
618 public virtual bool ContainsKey (string key)
620 return IndexOfKey (key) >= 0;
622 #endif
624 void ICollection.CopyTo (Array array, int index) {
625 CopyTo (array, index);
628 #if !NET_2_0
629 public void CopyTo (Array array, int index) {
630 list.CopyTo(array, index);
633 public override bool Equals (object other) {
634 if (other is ControlCollection && (((ControlCollection)other).owner==this.owner)) {
635 return(true);
636 } else {
637 return(false);
640 #endif
642 #if NET_2_0
643 // LAMESPEC: MSDN says AE, MS implementation throws ANE
644 public Control[] Find (string key, bool searchAllChildren)
646 if (string.IsNullOrEmpty (key))
647 throw new ArgumentNullException ("key");
649 ArrayList al = new ArrayList ();
651 foreach (Control c in list) {
652 if (c.Name.Equals (key, StringComparison.CurrentCultureIgnoreCase))
653 al.Add (c);
655 if (searchAllChildren)
656 al.AddRange (c.Controls.Find (key, true));
659 return (Control[])al.ToArray (typeof (Control));
661 #endif
663 public int GetChildIndex(Control child) {
664 return GetChildIndex(child, false);
667 #if NET_2_0
668 public virtual int
669 #else
670 public int
671 #endif
672 GetChildIndex(Control child, bool throwException) {
673 int index;
675 index=list.IndexOf(child);
677 if (index==-1 && throwException) {
678 throw new ArgumentException("Not a child control", "child");
680 return index;
683 #if NET_2_0
684 public override IEnumerator
685 #else
686 public IEnumerator
687 #endif
688 GetEnumerator () {
689 return list.GetEnumerator();
692 internal IEnumerator GetAllEnumerator () {
693 Control [] res = GetAllControls ();
694 return res.GetEnumerator ();
697 internal Control [] GetAllControls () {
698 if (all_controls != null)
699 return all_controls;
701 if (impl_list == null) {
702 all_controls = (Control []) list.ToArray (typeof (Control));
703 return all_controls;
706 all_controls = new Control [list.Count + impl_list.Count];
707 impl_list.CopyTo (all_controls);
708 list.CopyTo (all_controls, impl_list.Count);
710 return all_controls;
713 #if !NET_2_0
714 public override int GetHashCode() {
715 return base.GetHashCode();
717 #endif
719 public int IndexOf(Control control) {
720 return list.IndexOf(control);
723 #if NET_2_0
724 public virtual int IndexOfKey (string key)
726 if (string.IsNullOrEmpty (key))
727 return -1;
729 for (int i = 0; i < list.Count; i++)
730 if (((Control)list[i]).Name.Equals (key, StringComparison.CurrentCultureIgnoreCase))
731 return i;
733 return -1;
735 #endif
737 public virtual void Remove(Control value) {
738 if (value == null)
739 return;
741 owner.PerformLayout(value, "Parent");
742 owner.OnControlRemoved(new ControlEventArgs(value));
744 all_controls = null;
745 list.Remove(value);
747 value.ChangeParent(null);
749 owner.UpdateChildrenZOrder();
752 internal virtual void RemoveImplicit (Control control) {
753 if (impl_list != null) {
754 all_controls = null;
755 owner.PerformLayout (control, "Parent");
756 owner.OnControlRemoved (new ControlEventArgs (control));
757 impl_list.Remove (control);
759 control.ChangeParent (null);
760 owner.UpdateChildrenZOrder ();
763 #if NET_2_0
765 #endif
766 public void RemoveAt(int index) {
767 if (index < 0 || index >= list.Count) {
768 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
770 Remove ((Control)list[index]);
773 #if NET_2_0
774 public virtual void RemoveByKey (string key)
776 int index = IndexOfKey (key);
778 if (index >= 0)
779 RemoveAt (index);
781 #endif
783 #if NET_2_0
784 public virtual void
785 #else
786 public void
787 #endif
788 SetChildIndex(Control child, int newIndex) {
789 if (child == null)
790 throw new ArgumentNullException ("child");
792 int old_index;
794 old_index=list.IndexOf(child);
795 if (old_index==-1) {
796 throw new ArgumentException("Not a child control", "child");
799 if (old_index==newIndex) {
800 return;
803 all_controls = null;
804 list.RemoveAt(old_index);
806 if (newIndex>list.Count) {
807 list.Add(child);
808 } else {
809 list.Insert(newIndex, child);
811 child.UpdateZOrder();
812 owner.PerformLayout();
814 #endregion // ControlCollection Private Instance Methods
816 #region ControlCollection Interface Properties
817 object IList.this[int index] {
818 get {
819 if (index<0 || index>=list.Count) {
820 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
822 return this[index];
825 set {
826 if (!(value is Control)) {
827 throw new ArgumentException("Object of type Control required", "value");
830 all_controls = null;
831 Control ctrl = (Control) value;
832 list[index]= ctrl;
834 ctrl.ChangeParent(owner);
836 ctrl.InitLayout();
838 owner.UpdateChildrenZOrder();
839 owner.PerformLayout(ctrl, "Parent");
843 bool IList.IsFixedSize {
844 get {
845 return false;
849 bool ICollection.IsSynchronized {
850 get {
851 return list.IsSynchronized;
855 object ICollection.SyncRoot {
856 get {
857 return list.SyncRoot;
860 #endregion // ControlCollection Interface Properties
862 #region ControlCollection Interface Methods
863 int IList.Add(object value) {
864 if (!(value is Control)) {
865 throw new ArgumentException("Object of type Control required", "value");
868 if (value == null) {
869 throw new ArgumentException("value", "Cannot add null controls");
872 bool owner_permits_toplevels = (owner is MdiClient) || (owner is Form && ((Form)owner).IsMdiContainer);
873 bool child_is_toplevel = ((Control)value).GetTopLevel();
874 bool child_is_mdichild = (value is Form && ((Form)value).IsMdiChild);
876 if (child_is_toplevel && !(owner_permits_toplevels && child_is_mdichild))
877 throw new ArgumentException("Cannot add a top level control to a control.", "value");
879 return list.Add(value);
882 bool IList.Contains(object value) {
883 if (!(value is Control)) {
884 throw new ArgumentException("Object of type Control required", "value");
887 return this.Contains((Control) value);
890 int IList.IndexOf(object value) {
891 if (!(value is Control)) {
892 throw new ArgumentException("Object of type Control required", "value");
895 return this.IndexOf((Control) value);
898 void IList.Insert(int index, object value) {
899 if (!(value is Control)) {
900 throw new ArgumentException("Object of type Control required", "value");
902 all_controls = null;
903 list.Insert(index, value);
906 void IList.Remove(object value) {
907 if (!(value is Control)) {
908 throw new ArgumentException("Object of type Control required", "value");
910 all_controls = null;
911 list.Remove(value);
914 Object ICloneable.Clone() {
915 ControlCollection clone = new ControlCollection(this.owner);
916 clone.list=(ArrayList)list.Clone(); // FIXME: Do we need this?
917 return clone;
919 #endregion // ControlCollection Interface Methods
921 #endregion // ControlCollection Class
923 #region Public Constructors
924 public Control ()
926 layout_type = LayoutType.Anchor;
927 anchor_style = AnchorStyles.Top | AnchorStyles.Left;
929 is_created = false;
930 is_visible = true;
931 is_captured = false;
932 is_disposed = false;
933 is_enabled = true;
934 is_entered = false;
935 layout_pending = false;
936 is_toplevel = false;
937 causes_validation = true;
938 has_focus = false;
939 layout_suspended = 0;
940 mouse_clicks = 1;
941 tab_index = -1;
942 cursor = null;
943 right_to_left = RightToLeft.Inherit;
944 border_style = BorderStyle.None;
945 background_color = Color.Empty;
946 dist_right = 0;
947 dist_bottom = 0;
948 tab_stop = true;
949 ime_mode = ImeMode.Inherit;
950 use_compatible_text_rendering = true;
952 #if NET_2_0
953 backgroundimage_layout = ImageLayout.Tile;
954 use_compatible_text_rendering = Application.use_compatible_text_rendering;
955 padding = new Padding(0);
956 maximum_size = new Size();
957 minimum_size = new Size();
958 margin = this.DefaultMargin;
959 #endif
961 control_style = ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint |
962 ControlStyles.Selectable | ControlStyles.StandardClick |
963 ControlStyles.StandardDoubleClick;
964 #if NET_2_0
965 control_style |= ControlStyles.UseTextForAccessibility;
966 #endif
968 parent = null;
969 background_image = null;
970 text = string.Empty;
971 name = string.Empty;
973 window = new ControlNativeWindow(this);
974 child_controls = CreateControlsInstance();
975 client_size = new Size(DefaultSize.Width, DefaultSize.Height);
976 client_rect = new Rectangle(0, 0, DefaultSize.Width, DefaultSize.Height);
977 bounds.Size = SizeFromClientSize (client_size);
978 explicit_bounds = bounds;
981 public Control (Control parent, string text) : this()
983 Text=text;
984 Parent=parent;
987 public Control (Control parent, string text, int left, int top, int width, int height) : this()
989 Parent=parent;
990 bounds.X=left;
991 bounds.Y=top;
992 bounds.Width=width;
993 bounds.Height=height;
994 SetBounds(left, top, width, height, BoundsSpecified.All);
995 Text=text;
998 public Control (string text) : this()
1000 Text=text;
1003 public Control (string text, int left, int top, int width, int height) : this()
1005 bounds.X=left;
1006 bounds.Y=top;
1007 bounds.Width=width;
1008 bounds.Height=height;
1009 SetBounds(left, top, width, height, BoundsSpecified.All);
1010 Text=text;
1013 private delegate void RemoveDelegate(object c);
1015 protected override void Dispose (bool disposing)
1017 if (!is_disposed && disposing) {
1018 Capture = false;
1020 DisposeBackBuffer ();
1022 if (bmp != null) {
1023 bmp.Dispose ();
1024 bmp = null;
1026 if (bmp_g != null) {
1027 bmp_g.Dispose ();
1028 bmp_g = null;
1031 if (this.InvokeRequired) {
1032 if (Application.MessageLoop) {
1033 this.BeginInvokeInternal(new MethodInvoker(DestroyHandle), null, true);
1035 } else {
1036 DestroyHandle();
1039 if (parent != null) {
1040 parent.Controls.Remove(this);
1043 Control [] children = child_controls.GetAllControls ();
1044 for (int i=0; i<children.Length; i++) {
1045 children[i].parent = null; // Need to set to null or our child will try and remove from ourselves and crash
1046 children[i].Dispose();
1049 is_disposed = true;
1050 is_visible = false;
1051 base.Dispose(disposing);
1053 #endregion // Public Constructors
1055 #region Internal Properties
1056 // Control is currently selected, like Focused, except maintains state
1057 // when Form loses focus
1058 internal bool InternalSelected {
1059 get {
1060 IContainerControl container;
1062 container = GetContainerControl();
1064 if (container != null && container.ActiveControl == this)
1065 return true;
1067 return false;
1071 // Mouse is currently within the control's bounds
1072 internal bool Entered {
1073 get { return this.is_entered; }
1076 internal bool VisibleInternal {
1077 get { return is_visible; }
1080 internal LayoutType ControlLayoutType {
1081 get { return layout_type; }
1084 internal BorderStyle InternalBorderStyle {
1085 get {
1086 return border_style;
1089 set {
1090 if (!Enum.IsDefined (typeof (BorderStyle), value))
1091 throw new InvalidEnumArgumentException (string.Format("Enum argument value '{0}' is not valid for BorderStyle", value));
1093 if (border_style != value) {
1094 border_style = value;
1096 if (IsHandleCreated) {
1097 XplatUI.SetBorderStyle (window.Handle, (FormBorderStyle)border_style);
1098 RecreateHandle ();
1099 Refresh ();
1105 internal Size InternalClientSize { set { this.client_size = value; } }
1106 internal virtual bool ActivateOnShow { get { return true; } }
1107 #endregion // Internal Properties
1109 #region Private & Internal Methods
1111 #if NET_2_0
1112 void IDropTarget.OnDragDrop (DragEventArgs e)
1114 OnDragDrop (e);
1117 void IDropTarget.OnDragEnter (DragEventArgs e)
1119 OnDragEnter (e);
1122 void IDropTarget.OnDragLeave (EventArgs e)
1124 OnDragLeave (e);
1127 void IDropTarget.OnDragOver (DragEventArgs e)
1129 OnDragOver (e);
1131 #endif
1133 internal IAsyncResult BeginInvokeInternal (Delegate method, object [] args, bool disposing) {
1134 AsyncMethodResult result;
1135 AsyncMethodData data;
1137 if (!disposing) {
1138 Control p = this;
1139 do {
1140 if (!p.IsHandleCreated)
1141 throw new InvalidOperationException("Cannot call Invoke or BeginInvoke on a control until the window handle is created");
1142 p = p.parent;
1143 } while (p != null);
1146 result = new AsyncMethodResult ();
1147 data = new AsyncMethodData ();
1149 data.Handle = window.Handle;
1150 data.Method = method;
1151 data.Args = args;
1152 data.Result = result;
1154 #if NET_2_0
1155 if (!ExecutionContext.IsFlowSuppressed ()) {
1156 data.Context = ExecutionContext.Capture ();
1158 #else
1159 #if !MWF_ON_MSRUNTIME
1160 if (SecurityManager.SecurityEnabled) {
1161 data.Stack = CompressedStack.GetCompressedStack ();
1163 #endif
1164 #endif
1166 XplatUI.SendAsyncMethod (data);
1167 return result;
1171 internal void PointToClient (ref int x, ref int y) {
1172 XplatUI.ScreenToClient (Handle, ref x, ref y);
1175 internal void PointToScreen (ref int x, ref int y) {
1176 XplatUI.ClientToScreen (Handle, ref x, ref y);
1179 internal bool IsRecreating {
1180 get {
1181 return is_recreating;
1185 internal Graphics DeviceContext {
1186 get {
1187 if (bmp_g == null) {
1188 bmp = new Bitmap(1, 1, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
1189 bmp_g = Graphics.FromImage (bmp);
1191 return bmp_g;
1195 private void InvalidateBackBuffer () {
1196 if (backbuffer != null)
1197 backbuffer.Invalidate ();
1200 private DoubleBuffer GetBackBuffer () {
1201 if (backbuffer == null)
1202 backbuffer = new DoubleBuffer (this);
1203 return backbuffer;
1206 private void DisposeBackBuffer () {
1207 if (backbuffer != null) {
1208 backbuffer.Dispose ();
1209 backbuffer = null;
1213 internal static void SetChildColor(Control parent) {
1214 Control child;
1216 for (int i=0; i < parent.child_controls.Count; i++) {
1217 child=parent.child_controls[i];
1218 if (child.child_controls.Count>0) {
1219 SetChildColor(child);
1224 internal bool Select(Control control) {
1225 IContainerControl container;
1227 if (control == null) {
1228 return false;
1231 container = GetContainerControl();
1232 if (container != null && (Control)container != control) {
1233 container.ActiveControl = control;
1235 else if (control.IsHandleCreated) {
1236 XplatUI.SetFocus(control.window.Handle);
1238 return true;
1241 internal virtual void DoDefaultAction() {
1242 // Only here to be overriden by our actual controls; this is needed by the accessibility class
1245 internal static IntPtr MakeParam (int low, int high){
1246 return new IntPtr (high << 16 | low & 0xffff);
1249 internal static int LowOrder (int param) {
1250 return ((int)(short)(param & 0xffff));
1253 internal static int HighOrder (int param) {
1254 return ((int)(short)(param >> 16));
1257 // This method exists so controls overriding OnPaintBackground can have default background painting done
1258 internal virtual void PaintControlBackground (PaintEventArgs pevent) {
1259 if (GetStyle(ControlStyles.SupportsTransparentBackColor) && (BackColor.A != 0xff)) {
1260 if (parent != null) {
1261 PaintEventArgs parent_pe;
1262 GraphicsState state;
1264 parent_pe = new PaintEventArgs(pevent.Graphics, new Rectangle(pevent.ClipRectangle.X + Left, pevent.ClipRectangle.Y + Top, pevent.ClipRectangle.Width, pevent.ClipRectangle.Height));
1266 state = parent_pe.Graphics.Save();
1267 parent_pe.Graphics.TranslateTransform(-Left, -Top);
1268 parent.OnPaintBackground(parent_pe);
1269 parent_pe.Graphics.Restore(state);
1271 state = parent_pe.Graphics.Save();
1272 parent_pe.Graphics.TranslateTransform(-Left, -Top);
1273 parent.OnPaint(parent_pe);
1274 parent_pe.Graphics.Restore(state);
1275 parent_pe.SetGraphics(null);
1279 if ((clip_region != null) && (XplatUI.UserClipWontExposeParent)) {
1280 if (parent != null) {
1281 PaintEventArgs parent_pe;
1282 Region region;
1283 GraphicsState state;
1284 Hwnd hwnd;
1286 hwnd = Hwnd.ObjectFromHandle(Handle);
1288 if (hwnd != null) {
1289 parent_pe = new PaintEventArgs(pevent.Graphics, new Rectangle(pevent.ClipRectangle.X + Left, pevent.ClipRectangle.Y + Top, pevent.ClipRectangle.Width, pevent.ClipRectangle.Height));
1291 region = new Region ();
1292 region.MakeEmpty();
1293 region.Union(ClientRectangle);
1295 foreach (Rectangle r in hwnd.ClipRectangles) {
1296 region.Union (r);
1299 state = parent_pe.Graphics.Save();
1300 parent_pe.Graphics.Clip = region;
1302 parent_pe.Graphics.TranslateTransform(-Left, -Top);
1303 parent.OnPaintBackground(parent_pe);
1304 parent_pe.Graphics.Restore(state);
1306 state = parent_pe.Graphics.Save();
1307 parent_pe.Graphics.Clip = region;
1309 parent_pe.Graphics.TranslateTransform(-Left, -Top);
1310 parent.OnPaint(parent_pe);
1311 parent_pe.Graphics.Restore(state);
1312 parent_pe.SetGraphics(null);
1314 region.Intersect(clip_region);
1315 pevent.Graphics.Clip = region;
1320 if (background_image == null) {
1321 pevent.Graphics.FillRectangle(ThemeEngine.Current.ResPool.GetSolidBrush(BackColor), new Rectangle(pevent.ClipRectangle.X - 1, pevent.ClipRectangle.Y - 1, pevent.ClipRectangle.Width + 2, pevent.ClipRectangle.Height + 2));
1322 return;
1325 DrawBackgroundImage (pevent.Graphics);
1328 void DrawBackgroundImage (Graphics g) {
1329 #if NET_2_0
1330 Rectangle drawing_rectangle = new Rectangle ();
1331 g.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (BackColor), ClientRectangle);
1333 switch (backgroundimage_layout)
1335 case ImageLayout.Tile:
1336 using (TextureBrush b = new TextureBrush (background_image, WrapMode.Tile)) {
1337 g.FillRectangle (b, ClientRectangle);
1339 return;
1340 case ImageLayout.Center:
1341 drawing_rectangle.Location = new Point (ClientSize.Width / 2 - background_image.Width / 2, ClientSize.Height / 2 - background_image.Height / 2);
1342 drawing_rectangle.Size = background_image.Size;
1343 break;
1344 case ImageLayout.None:
1345 drawing_rectangle.Location = Point.Empty;
1346 drawing_rectangle.Size = background_image.Size;
1347 break;
1348 case ImageLayout.Stretch:
1349 drawing_rectangle = ClientRectangle;
1350 break;
1351 case ImageLayout.Zoom:
1352 drawing_rectangle = ClientRectangle;
1353 if ((float)background_image.Width / (float)background_image.Height < (float)drawing_rectangle.Width / (float) drawing_rectangle.Height) {
1354 drawing_rectangle.Width = (int) (background_image.Width * ((float)drawing_rectangle.Height / (float)background_image.Height));
1355 drawing_rectangle.X = (ClientRectangle.Width - drawing_rectangle.Width) / 2;
1356 } else {
1357 drawing_rectangle.Height = (int) (background_image.Height * ((float)drawing_rectangle.Width / (float)background_image.Width));
1358 drawing_rectangle.Y = (ClientRectangle.Height - drawing_rectangle.Height) / 2;
1360 break;
1361 default:
1362 return;
1365 g.DrawImage (background_image, drawing_rectangle);
1367 #else
1368 using (TextureBrush b = new TextureBrush (background_image, WrapMode.Tile)) {
1369 g.FillRectangle (b, ClientRectangle);
1371 #endif
1374 internal virtual void DndEnter (DragEventArgs e) {
1375 try {
1376 OnDragEnter (e);
1377 } catch { }
1380 internal virtual void DndOver (DragEventArgs e) {
1381 try {
1382 OnDragOver (e);
1383 } catch { }
1386 internal virtual void DndDrop (DragEventArgs e) {
1387 try {
1388 OnDragDrop (e);
1389 } catch (Exception exc) {
1390 Console.Error.WriteLine ("MWF: Exception while dropping:");
1391 Console.Error.WriteLine (exc);
1395 internal virtual void DndLeave (EventArgs e) {
1396 try {
1397 OnDragLeave (e);
1398 } catch { }
1401 internal virtual void DndFeedback(GiveFeedbackEventArgs e) {
1402 try {
1403 OnGiveFeedback(e);
1404 } catch { }
1407 internal virtual void DndContinueDrag(QueryContinueDragEventArgs e) {
1408 try {
1409 OnQueryContinueDrag(e);
1410 } catch { }
1413 internal static MouseButtons FromParamToMouseButtons (int param) {
1414 MouseButtons buttons = MouseButtons.None;
1416 if ((param & (int) MsgButtons.MK_LBUTTON) != 0)
1417 buttons |= MouseButtons.Left;
1419 if ((param & (int) MsgButtons.MK_MBUTTON) != 0)
1420 buttons |= MouseButtons.Middle;
1422 if ((param & (int) MsgButtons.MK_RBUTTON) != 0)
1423 buttons |= MouseButtons.Right;
1425 return buttons;
1429 internal virtual void FireEnter () {
1430 OnEnter (EventArgs.Empty);
1433 internal virtual void FireLeave () {
1434 OnLeave (EventArgs.Empty);
1437 internal virtual void FireValidating (CancelEventArgs ce) {
1438 OnValidating (ce);
1441 internal virtual void FireValidated () {
1442 OnValidated (EventArgs.Empty);
1445 internal virtual bool ProcessControlMnemonic(char charCode) {
1446 return ProcessMnemonic(charCode);
1449 private static Control FindFlatForward(Control container, Control start) {
1450 Control found;
1451 int index;
1452 int end;
1454 found = null;
1455 end = container.child_controls.Count;
1457 if (start != null) {
1458 index = start.tab_index;
1459 } else {
1460 index = -1;
1463 for (int i = 0, pos = -1; i < end; i++) {
1464 if (start == container.child_controls[i]) {
1465 pos = i;
1466 continue;
1469 if (found == null) {
1470 if (container.child_controls[i].tab_index > index || (pos > -1 && pos < i && container.child_controls[i].tab_index == index)) {
1471 found = container.child_controls[i];
1473 } else if (found.tab_index > container.child_controls[i].tab_index) {
1474 if (container.child_controls[i].tab_index > index) {
1475 found = container.child_controls[i];
1479 return found;
1482 private static Control FindControlForward(Control container, Control start) {
1483 Control found;
1485 found = null;
1487 if (start == null) {
1488 return FindFlatForward(container, start);
1491 if (start.child_controls != null && start.child_controls.Count > 0 &&
1492 (start == container || !((start is IContainerControl) && start.GetStyle(ControlStyles.ContainerControl)))) {
1493 return FindControlForward(start, null);
1495 else {
1496 while (start != container) {
1497 found = FindFlatForward(start.parent, start);
1498 if (found != null) {
1499 return found;
1501 start = start.parent;
1504 return null;
1507 private static Control FindFlatBackward(Control container, Control start) {
1508 Control found;
1509 int index;
1510 int end;
1512 found = null;
1513 end = container.child_controls.Count;
1515 if (start != null) {
1516 index = start.tab_index;
1517 } else {
1518 // FIXME: Possible speed-up: Keep the highest taborder index in the container
1519 index = -1;
1520 for (int i = 0; i < end; i++) {
1521 if (container.child_controls[i].tab_index > index) {
1522 index = container.child_controls[i].tab_index;
1525 index++;
1528 bool hit = false;
1530 for (int i = end - 1; i >= 0; i--) {
1531 if (start == container.child_controls[i]) {
1532 hit = true;
1533 continue;
1536 if (found == null || found.tab_index < container.child_controls[i].tab_index) {
1537 if (container.child_controls[i].tab_index < index || (hit && container.child_controls[i].tab_index == index))
1538 found = container.child_controls[i];
1542 return found;
1545 private static Control FindControlBackward(Control container, Control start) {
1547 Control found = null;
1549 if (start == null) {
1550 found = FindFlatBackward(container, start);
1552 else if (start != container) {
1553 if (start.parent != null) {
1554 found = FindFlatBackward(start.parent, start);
1556 if (found == null) {
1557 if (start.parent != container)
1558 return start.parent;
1559 return null;
1564 if (found == null || start.parent == null)
1565 found = start;
1567 while (found != null && (found == container || (!((found is IContainerControl) && found.GetStyle(ControlStyles.ContainerControl))) &&
1568 found.child_controls != null && found.child_controls.Count > 0)) {
1569 // while (ctl.child_controls != null && ctl.child_controls.Count > 0 &&
1570 // (ctl == this || (!((ctl is IContainerControl) && ctl.GetStyle(ControlStyles.ContainerControl))))) {
1571 found = FindFlatBackward(found, null);
1574 return found;
1577 Control found;
1579 found = null;
1581 if (start != null) {
1582 found = FindFlatBackward(start.parent, start);
1583 if (found == null) {
1584 if (start.parent != container) {
1585 return start.parent;
1589 if (found == null) {
1590 found = FindFlatBackward(container, start);
1593 if (container != start) {
1594 while ((found != null) && (!found.Contains(start)) && found.child_controls != null && found.child_controls.Count > 0 && !(found is IContainerControl)) {// || found.GetStyle(ControlStyles.ContainerControl))) {
1595 found = FindControlBackward(found, null);
1596 if (found != null) {
1597 return found;
1601 return found;
1605 internal virtual void HandleClick(int clicks, MouseEventArgs me) {
1606 if (GetStyle(ControlStyles.StandardClick)) {
1607 if ((clicks > 1) && GetStyle(ControlStyles.StandardDoubleClick)) {
1608 #if !NET_2_0
1609 OnDoubleClick(EventArgs.Empty);
1610 } else {
1611 OnClick(EventArgs.Empty);
1612 #else
1613 OnDoubleClick(me);
1614 OnMouseDoubleClick (me);
1615 } else {
1616 OnClick(me);
1617 OnMouseClick (me);
1618 #endif
1623 internal void CaptureWithConfine (Control ConfineWindow) {
1624 if (this.IsHandleCreated && !is_captured) {
1625 is_captured = true;
1626 XplatUI.GrabWindow (this.window.Handle, ConfineWindow.Handle);
1630 private void CheckDataBindings () {
1631 if (data_bindings == null)
1632 return;
1634 BindingContext binding_context = BindingContext;
1635 foreach (Binding binding in data_bindings) {
1636 binding.Check (binding_context);
1640 private void ChangeParent(Control new_parent) {
1641 bool pre_enabled;
1642 bool pre_visible;
1643 Font pre_font;
1644 Color pre_fore_color;
1645 Color pre_back_color;
1646 RightToLeft pre_rtl;
1648 // These properties are inherited from our parent
1649 // Get them pre parent-change and then send events
1650 // if they are changed after we have our new parent
1651 pre_enabled = Enabled;
1652 pre_visible = Visible;
1653 pre_font = Font;
1654 pre_fore_color = ForeColor;
1655 pre_back_color = BackColor;
1656 pre_rtl = RightToLeft;
1657 // MS doesn't seem to send a CursorChangedEvent
1659 parent = new_parent;
1661 if (IsHandleCreated) {
1662 XplatUI.SetParent(Handle,
1663 (new_parent == null || !new_parent.IsHandleCreated) ? IntPtr.Zero : new_parent.Handle);
1664 if (this is Form ) {
1665 ((Form) this).ChangingParent (new_parent);
1669 OnParentChanged(EventArgs.Empty);
1671 if (pre_enabled != Enabled) {
1672 OnEnabledChanged(EventArgs.Empty);
1675 if (pre_visible != Visible) {
1676 OnVisibleChanged(EventArgs.Empty);
1679 if (pre_font != Font) {
1680 OnFontChanged(EventArgs.Empty);
1683 if (pre_fore_color != ForeColor) {
1684 OnForeColorChanged(EventArgs.Empty);
1687 if (pre_back_color != BackColor) {
1688 OnBackColorChanged(EventArgs.Empty);
1691 if (pre_rtl != RightToLeft) {
1692 // MS sneaks a OnCreateControl and OnHandleCreated in here, I guess
1693 // because when RTL changes they have to recreate the win32 control
1694 // We don't really need that (until someone runs into compatibility issues)
1695 OnRightToLeftChanged(EventArgs.Empty);
1698 if ((new_parent != null) && new_parent.Created && is_visible && !Created) {
1699 CreateControl();
1702 if ((binding_context == null) && Created) {
1703 OnBindingContextChanged(EventArgs.Empty);
1707 private void UpdateDistances() {
1708 if (parent != null) {
1709 if (bounds.Width > 0)
1710 dist_right = parent.ClientSize.Width - bounds.X - bounds.Width;
1711 if (bounds.Height > 0)
1712 dist_bottom = parent.ClientSize.Height - bounds.Y - bounds.Height;
1716 private bool UseDoubleBuffering {
1717 get {
1718 if (!ThemeEngine.Current.DoubleBufferingSupported)
1719 return false;
1721 #if NET_2_0
1722 if (DoubleBuffered)
1723 return true;
1724 #endif
1725 return (control_style & ControlStyles.DoubleBuffer) != 0;
1728 #endregion // Private & Internal Methods
1730 #region Public Static Properties
1731 public static Color DefaultBackColor {
1732 get {
1733 return ThemeEngine.Current.DefaultControlBackColor;
1737 public static Font DefaultFont {
1738 get {
1739 return ThemeEngine.Current.DefaultFont;
1743 public static Color DefaultForeColor {
1744 get {
1745 return ThemeEngine.Current.DefaultControlForeColor;
1749 public static Keys ModifierKeys {
1750 get {
1751 return XplatUI.State.ModifierKeys;
1755 public static MouseButtons MouseButtons {
1756 get {
1757 return XplatUI.State.MouseButtons;
1761 public static Point MousePosition {
1762 get {
1763 return Cursor.Position;
1767 #if NET_2_0
1768 [EditorBrowsable (EditorBrowsableState.Advanced)]
1769 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
1770 [Browsable (false)]
1771 [MonoTODO]
1772 public static bool CheckForIllegalCrossThreadCalls
1774 get {
1775 return verify_thread_handle;
1778 set {
1779 verify_thread_handle = value;
1782 #endif
1783 #endregion // Public Static Properties
1785 #region Public Instance Properties
1786 [EditorBrowsable(EditorBrowsableState.Advanced)]
1787 [Browsable(false)]
1788 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1789 public AccessibleObject AccessibilityObject {
1790 get {
1791 if (accessibility_object==null) {
1792 accessibility_object=CreateAccessibilityInstance();
1794 return accessibility_object;
1798 [EditorBrowsable(EditorBrowsableState.Advanced)]
1799 [Browsable(false)]
1800 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1801 public string AccessibleDefaultActionDescription {
1802 get {
1803 if (accessibility_object != null)
1804 return accessibility_object.default_action;
1805 else
1806 return null;
1809 set {
1810 if (accessibility_object != null)
1811 accessibility_object.default_action = value;
1815 [Localizable(true)]
1816 [DefaultValue(null)]
1817 [MWFCategory("Accessibility")]
1818 public string AccessibleDescription {
1819 get {
1820 if (accessibility_object != null)
1821 return accessibility_object.description;
1822 else
1823 return null;
1826 set {
1827 if (accessibility_object != null)
1828 accessibility_object.description = value;
1832 [Localizable(true)]
1833 [DefaultValue(null)]
1834 [MWFCategory("Accessibility")]
1835 public string AccessibleName {
1836 get {
1837 if (accessibility_object != null)
1838 return accessibility_object.Name;
1839 else
1840 return null;
1843 set {
1844 if (accessibility_object != null)
1845 accessibility_object.Name = value;
1849 [DefaultValue(AccessibleRole.Default)]
1850 [MWFDescription("Role of the control"), MWFCategory("Accessibility")]
1851 public AccessibleRole AccessibleRole {
1852 get {
1853 if (accessibility_object != null)
1854 return accessibility_object.role;
1855 else
1856 return AccessibleRole.Default;
1859 set {
1860 if (accessibility_object != null)
1861 accessibility_object.role = value;
1865 [DefaultValue(false)]
1866 [MWFCategory("Behavior")]
1867 public virtual bool AllowDrop {
1868 get {
1869 return allow_drop;
1872 set {
1873 if (allow_drop == value)
1874 return;
1875 allow_drop = value;
1876 if (IsHandleCreated) {
1877 UpdateStyles();
1878 XplatUI.SetAllowDrop (Handle, value);
1883 [Localizable(true)]
1884 [RefreshProperties(RefreshProperties.Repaint)]
1885 [DefaultValue(AnchorStyles.Top | AnchorStyles.Left)]
1886 [MWFCategory("Layout")]
1887 public virtual AnchorStyles Anchor {
1888 get {
1889 return anchor_style;
1892 set {
1893 layout_type = LayoutType.Anchor;
1895 if (anchor_style == value)
1896 return;
1898 anchor_style=value;
1899 dock_style = DockStyle.None;
1901 UpdateDistances ();
1903 if (parent != null)
1904 parent.PerformLayout(this, "Anchor");
1908 #if NET_2_0
1909 // XXX: Implement me!
1910 bool auto_size;
1912 [RefreshProperties (RefreshProperties.All)]
1913 [Localizable (true)]
1914 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
1915 [Browsable (false)]
1916 [EditorBrowsable (EditorBrowsableState.Never)]
1917 [DefaultValue (false)]
1918 [MonoTODO("This method currently does nothing")]
1919 public virtual bool AutoSize {
1920 get { return auto_size; }
1921 set {
1922 if (this.auto_size != value) {
1923 auto_size = value;
1924 OnAutoSizeChanged (EventArgs.Empty);
1929 #if NET_2_0
1930 [AmbientValue ("{Width=0, Height=0}")]
1931 #else
1932 [AmbientValue (typeof(Size), "0, 0")]
1933 #endif
1934 public virtual Size MaximumSize {
1935 get {
1936 return maximum_size;
1938 set {
1939 if (maximum_size != value) {
1940 maximum_size = value;
1941 Size = PreferredSize;
1946 public virtual Size MinimumSize {
1947 get {
1948 return minimum_size;
1950 set {
1951 if (minimum_size != value) {
1952 minimum_size = value;
1953 Size = PreferredSize;
1957 #endif // NET_2_0
1959 [DispId(-501)]
1960 [MWFCategory("Appearance")]
1961 public virtual Color BackColor {
1962 get {
1963 if (background_color.IsEmpty) {
1964 if (parent!=null) {
1965 Color pcolor = parent.BackColor;
1966 if (pcolor.A == 0xff || GetStyle(ControlStyles.SupportsTransparentBackColor))
1967 return pcolor;
1969 return DefaultBackColor;
1971 return background_color;
1974 set {
1975 if (!value.IsEmpty && (value.A != 0xff) && !GetStyle(ControlStyles.SupportsTransparentBackColor)) {
1976 throw new ArgumentException("Transparent background colors are not supported on this control");
1979 if (background_color != value) {
1980 background_color=value;
1981 SetChildColor(this);
1982 OnBackColorChanged(EventArgs.Empty);
1983 Invalidate();
1988 [Localizable(true)]
1989 [DefaultValue(null)]
1990 [MWFCategory("Appearance")]
1991 public virtual Image BackgroundImage {
1992 get {
1993 return background_image;
1996 set {
1997 if (background_image!=value) {
1998 background_image=value;
1999 OnBackgroundImageChanged(EventArgs.Empty);
2000 Invalidate ();
2005 #if NET_2_0
2006 [DefaultValue (ImageLayout.Tile)]
2007 [Localizable (true)]
2008 public virtual ImageLayout BackgroundImageLayout {
2009 get {
2010 return backgroundimage_layout;
2012 set {
2013 if (Array.IndexOf (Enum.GetValues (typeof (ImageLayout)), value) == -1)
2014 throw new InvalidEnumArgumentException ("value", (int) value, typeof(ImageLayout));
2016 if (value != backgroundimage_layout) {
2017 backgroundimage_layout = value;
2018 Invalidate ();
2019 OnBackgroundImageLayoutChanged (EventArgs.Empty);
2024 #endif
2025 [EditorBrowsable(EditorBrowsableState.Advanced)]
2026 [Browsable(false)]
2027 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2028 public virtual BindingContext BindingContext {
2029 get {
2030 if (binding_context != null)
2031 return binding_context;
2032 if (Parent == null)
2033 return null;
2034 binding_context = Parent.BindingContext;
2035 return binding_context;
2037 set {
2038 if (binding_context != value) {
2039 binding_context = value;
2040 OnBindingContextChanged(EventArgs.Empty);
2045 [EditorBrowsable(EditorBrowsableState.Advanced)]
2046 [Browsable(false)]
2047 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2048 public int Bottom {
2049 get {
2050 return bounds.Y+bounds.Height;
2054 [EditorBrowsable(EditorBrowsableState.Advanced)]
2055 [Browsable(false)]
2056 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2057 public Rectangle Bounds {
2058 get {
2059 return this.bounds;
2062 set {
2063 SetBounds(value.Left, value.Top, value.Width, value.Height, BoundsSpecified.All);
2067 [EditorBrowsable(EditorBrowsableState.Advanced)]
2068 [Browsable(false)]
2069 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2070 public bool CanFocus {
2071 get {
2072 if (IsHandleCreated && Visible && Enabled) {
2073 return true;
2075 return false;
2079 [EditorBrowsable(EditorBrowsableState.Advanced)]
2080 [Browsable(false)]
2081 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2082 public bool CanSelect {
2083 get {
2084 Control parent;
2086 if (!GetStyle(ControlStyles.Selectable)) {
2087 return false;
2090 parent = this;
2091 while (parent != null) {
2092 if (!parent.is_visible || !parent.is_enabled) {
2093 return false;
2096 parent = parent.parent;
2098 return true;
2102 internal virtual bool InternalCapture {
2103 get {
2104 return Capture;
2107 set {
2108 Capture = value;
2112 [EditorBrowsable(EditorBrowsableState.Advanced)]
2113 [Browsable(false)]
2114 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2115 public bool Capture {
2116 get {
2117 return this.is_captured;
2120 set {
2121 // Call OnMouseCaptureChanged when we get WM_CAPTURECHANGED.
2122 if (value != is_captured) {
2123 if (value) {
2124 is_captured = true;
2125 XplatUI.GrabWindow(Handle, IntPtr.Zero);
2126 } else {
2127 if (IsHandleCreated)
2128 XplatUI.UngrabWindow(Handle);
2129 is_captured = false;
2135 [DefaultValue(true)]
2136 [MWFCategory("Focus")]
2137 public bool CausesValidation {
2138 get {
2139 return this.causes_validation;
2142 set {
2143 if (this.causes_validation != value) {
2144 causes_validation = value;
2145 OnCausesValidationChanged(EventArgs.Empty);
2150 [EditorBrowsable(EditorBrowsableState.Advanced)]
2151 [Browsable(false)]
2152 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2153 public Rectangle ClientRectangle {
2154 get {
2155 client_rect.Width = client_size.Width;
2156 client_rect.Height = client_size.Height;
2157 return client_rect;
2161 [EditorBrowsable(EditorBrowsableState.Advanced)]
2162 [Browsable(false)]
2163 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2164 public Size ClientSize {
2165 get {
2166 #if notneeded
2167 if ((this is Form) && (((Form)this).form_parent_window != null)) {
2168 return ((Form)this).form_parent_window.ClientSize;
2170 #endif
2172 return client_size;
2175 set {
2176 this.SetClientSizeCore(value.Width, value.Height);
2177 #if NET_2_0
2178 this.OnClientSizeChanged (EventArgs.Empty);
2179 #endif
2183 [EditorBrowsable(EditorBrowsableState.Advanced)]
2184 [Browsable(false)]
2185 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2186 [DescriptionAttribute("ControlCompanyNameDescr")]
2187 public String CompanyName {
2188 get {
2189 return "Mono Project, Novell, Inc.";
2193 [EditorBrowsable(EditorBrowsableState.Advanced)]
2194 [Browsable(false)]
2195 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2196 public bool ContainsFocus {
2197 get {
2198 IntPtr focused_window;
2200 focused_window = XplatUI.GetFocus();
2201 if (IsHandleCreated) {
2202 if (focused_window == Handle) {
2203 return true;
2206 for (int i=0; i < child_controls.Count; i++) {
2207 if (child_controls[i].ContainsFocus) {
2208 return true;
2212 return false;
2215 #if NET_2_0
2216 [Browsable (false)]
2217 #endif
2218 [DefaultValue(null)]
2219 [MWFCategory("Behavior")]
2220 public virtual ContextMenu ContextMenu {
2221 get {
2222 return GetContextMenuInternal ();
2225 set {
2226 if (context_menu != value) {
2227 context_menu = value;
2228 OnContextMenuChanged(EventArgs.Empty);
2233 internal virtual ContextMenu GetContextMenuInternal () {
2234 return context_menu;
2237 #if NET_2_0
2238 [DefaultValue (null)]
2239 public virtual ContextMenuStrip ContextMenuStrip {
2240 get { return this.context_menu_strip; }
2241 set {
2242 if (this.context_menu_strip != value) {
2243 this.context_menu_strip = value;
2244 OnContextMenuStripChanged (EventArgs.Empty);
2248 #endif
2250 [Browsable(false)]
2251 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
2252 public ControlCollection Controls {
2253 get {
2254 return this.child_controls;
2258 [EditorBrowsable(EditorBrowsableState.Advanced)]
2259 [Browsable(false)]
2260 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2261 public bool Created {
2262 get {
2263 return (!is_disposed && is_created);
2267 [AmbientValue(null)]
2268 [MWFCategory("Appearance")]
2269 public virtual Cursor Cursor {
2270 get {
2271 if (cursor != null) {
2272 return cursor;
2275 if (parent != null) {
2276 return parent.Cursor;
2279 return Cursors.Default;
2282 set {
2283 if (cursor != value) {
2284 Point pt;
2286 cursor = value;
2288 if (IsHandleCreated) {
2289 pt = Cursor.Position;
2291 if (bounds.Contains(pt) || Capture) {
2292 if (GetChildAtPoint(pt) == null) {
2293 if (cursor != null) {
2294 XplatUI.SetCursor(window.Handle, cursor.handle);
2295 } else {
2296 if (parent != null) {
2297 XplatUI.SetCursor(window.Handle, parent.Cursor.handle);
2298 } else {
2299 XplatUI.SetCursor(window.Handle, Cursors.Default.handle);
2306 OnCursorChanged(EventArgs.Empty);
2312 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
2313 [ParenthesizePropertyName(true)]
2314 [RefreshProperties(RefreshProperties.All)]
2315 [MWFCategory("Data")]
2316 public ControlBindingsCollection DataBindings {
2317 get {
2318 if (data_bindings == null)
2319 data_bindings = new ControlBindingsCollection (this);
2320 return data_bindings;
2324 [EditorBrowsable(EditorBrowsableState.Advanced)]
2325 [Browsable(false)]
2326 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2327 public virtual Rectangle DisplayRectangle {
2328 get {
2329 return ClientRectangle;
2333 [EditorBrowsable(EditorBrowsableState.Advanced)]
2334 [Browsable(false)]
2335 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2336 public bool Disposing {
2337 get {
2338 return is_disposed;
2342 [Localizable(true)]
2343 [RefreshProperties(RefreshProperties.Repaint)]
2344 [DefaultValue(DockStyle.None)]
2345 [MWFCategory("Layout")]
2346 public virtual DockStyle Dock {
2347 get {
2348 return dock_style;
2351 set {
2352 layout_type = LayoutType.Dock;
2354 if (dock_style == value) {
2355 return;
2358 if (!Enum.IsDefined (typeof (DockStyle), value)) {
2359 throw new InvalidEnumArgumentException ("value", (int) value,
2360 typeof (DockStyle));
2363 dock_style = value;
2364 anchor_style = AnchorStyles.Top | AnchorStyles.Left;
2366 if (dock_style == DockStyle.None) {
2367 if (explicit_bounds == Rectangle.Empty)
2368 Bounds = new Rectangle (new Point (0, 0), DefaultSize);
2369 else
2370 Bounds = explicit_bounds;
2373 if (parent != null) {
2374 parent.PerformLayout(this, "Dock");
2377 OnDockChanged(EventArgs.Empty);
2381 #if NET_2_0
2382 protected virtual bool DoubleBuffered {
2383 get {
2384 return (control_style & ControlStyles.OptimizedDoubleBuffer) != 0;
2387 set {
2388 if (value == DoubleBuffered)
2389 return;
2390 if (value) {
2391 SetStyle (ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);
2392 } else {
2393 SetStyle (ControlStyles.OptimizedDoubleBuffer, false);
2398 #endif
2400 [DispId(-514)]
2401 [Localizable(true)]
2402 [MWFCategory("Behavior")]
2403 public bool Enabled {
2404 get {
2405 if (!is_enabled) {
2406 return false;
2409 if (parent != null) {
2410 return parent.Enabled;
2413 return true;
2416 set {
2417 if (this.is_enabled != value) {
2418 bool old_value = is_enabled;
2420 is_enabled = value;
2421 if (old_value != value && !value && this.has_focus)
2422 SelectNextControl(this, true, true, true, true);
2424 OnEnabledChanged (EventArgs.Empty);
2429 [EditorBrowsable(EditorBrowsableState.Advanced)]
2430 [Browsable(false)]
2431 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2432 public virtual bool Focused {
2433 get {
2434 return this.has_focus;
2438 [DispId(-512)]
2439 [AmbientValue(null)]
2440 [Localizable(true)]
2441 [MWFCategory("Appearance")]
2442 public virtual Font Font {
2443 get {
2444 if (font != null) {
2445 return font;
2448 if (Parent != null && Parent.Font != null) {
2449 return Parent.Font;
2452 return DefaultFont;
2455 [param:MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Font))]
2456 set {
2457 if (font != null && font.Equals (value)) {
2458 return;
2461 font = value;
2462 Invalidate();
2463 OnFontChanged (EventArgs.Empty);
2464 PerformLayout ();
2468 [DispId(-513)]
2469 [MWFCategory("Appearance")]
2470 public virtual Color ForeColor {
2471 get {
2472 if (foreground_color.IsEmpty) {
2473 if (parent!=null) {
2474 return parent.ForeColor;
2476 return DefaultForeColor;
2478 return foreground_color;
2481 set {
2482 if (foreground_color != value) {
2483 foreground_color=value;
2484 Invalidate();
2485 OnForeColorChanged(EventArgs.Empty);
2490 [DispId(-515)]
2491 [Browsable(false)]
2492 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2493 public IntPtr Handle { // IWin32Window
2494 get {
2495 #if NET_2_0
2496 if (verify_thread_handle) {
2497 if (this.InvokeRequired) {
2498 throw new InvalidOperationException("Cross-thread access of handle detected. Handle access only valid on thread that created the control");
2501 #endif
2502 if (!IsHandleCreated) {
2503 CreateHandle();
2505 return window.Handle;
2509 [EditorBrowsable(EditorBrowsableState.Advanced)]
2510 [Browsable(false)]
2511 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2512 public bool HasChildren {
2513 get {
2514 if (this.child_controls.Count>0) {
2515 return true;
2517 return false;
2521 [EditorBrowsable(EditorBrowsableState.Always)]
2522 [Browsable(false)]
2523 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2524 public int Height {
2525 get {
2526 return this.bounds.Height;
2529 set {
2530 SetBounds(bounds.X, bounds.Y, bounds.Width, value, BoundsSpecified.Height);
2534 [AmbientValue(ImeMode.Inherit)]
2535 [Localizable(true)]
2536 [MWFCategory("Behavior")]
2537 public ImeMode ImeMode {
2538 get {
2539 if (ime_mode == ImeMode.Inherit) {
2540 if (parent != null)
2541 return parent.ImeMode;
2542 else
2543 return ImeMode.NoControl; // default value
2545 return ime_mode;
2548 set {
2549 if (ime_mode != value) {
2550 ime_mode = value;
2552 OnImeModeChanged(EventArgs.Empty);
2557 [EditorBrowsable(EditorBrowsableState.Advanced)]
2558 [Browsable(false)]
2559 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2560 public bool InvokeRequired { // ISynchronizeInvoke
2561 get {
2562 if (creator_thread != null && creator_thread!=Thread.CurrentThread) {
2563 return true;
2565 return false;
2569 [EditorBrowsable(EditorBrowsableState.Advanced)]
2570 [Browsable(false)]
2571 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2572 public bool IsAccessible {
2573 get {
2574 return is_accessible;
2577 set {
2578 is_accessible = value;
2582 [EditorBrowsable(EditorBrowsableState.Advanced)]
2583 [Browsable(false)]
2584 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2585 public bool IsDisposed {
2586 get {
2587 return this.is_disposed;
2591 [EditorBrowsable(EditorBrowsableState.Advanced)]
2592 [Browsable(false)]
2593 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2594 public bool IsHandleCreated {
2595 get {
2596 if (window == null || window.Handle == IntPtr.Zero)
2597 return false;
2599 Hwnd hwnd = Hwnd.ObjectFromHandle (window.Handle);
2600 if (hwnd != null && hwnd.zombie)
2601 return false;
2603 return true;
2607 [Browsable (false)]
2608 [EditorBrowsable (EditorBrowsableState.Advanced)]
2609 #if NET_2_0
2610 public virtual
2611 #endif
2612 Layout.LayoutEngine LayoutEngine {
2613 get {
2614 if (layout_engine == null)
2615 layout_engine = new Layout.DefaultLayout ();
2616 return layout_engine;
2620 [EditorBrowsable(EditorBrowsableState.Always)]
2621 [Browsable(false)]
2622 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2623 public int Left {
2624 get {
2625 return this.bounds.X;
2628 set {
2629 SetBounds(value, bounds.Y, bounds.Width, bounds.Height, BoundsSpecified.X);
2633 [Localizable(true)]
2634 [MWFCategory("Layout")]
2635 public Point Location {
2636 get {
2637 return new Point(bounds.X, bounds.Y);
2640 set {
2641 SetBounds(value.X, value.Y, bounds.Width, bounds.Height, BoundsSpecified.Location);
2645 #if NET_2_0
2646 [Localizable (true)]
2647 public Padding Margin {
2648 get { return this.margin; }
2649 set {
2650 if (this.margin != value) {
2651 this.margin = value;
2652 OnMarginChanged (EventArgs.Empty);
2656 #endif
2658 [Browsable(false)]
2659 public string Name {
2660 get {
2661 return name;
2664 set {
2665 name = value;
2669 #if NET_2_0
2670 [Localizable(true)]
2671 public Padding Padding {
2672 get {
2673 return padding;
2676 set {
2677 if (padding != value) {
2678 padding = value;
2679 OnPaddingChanged (EventArgs.Empty);
2680 PerformLayout ();
2684 #endif
2686 [Browsable(false)]
2687 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2688 public Control Parent {
2689 get {
2690 return this.parent;
2693 set {
2694 if (value == this) {
2695 throw new ArgumentException("A circular control reference has been made. A control cannot be owned or parented to itself.");
2698 if (parent!=value) {
2699 if (value==null) {
2700 parent.Controls.Remove(this);
2701 parent = null;
2702 return;
2705 value.Controls.Add(this);
2710 #if NET_2_0
2711 [Browsable (false)]
2712 public Size PreferredSize {
2713 get { return this.GetPreferredSize (Size.Empty); }
2715 #endif
2717 [EditorBrowsable(EditorBrowsableState.Advanced)]
2718 [Browsable(false)]
2719 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2720 public string ProductName {
2721 get {
2722 Type t = typeof (AssemblyProductAttribute);
2723 Assembly assembly = GetType().Module.Assembly;
2724 object [] attrs = assembly.GetCustomAttributes (t, false);
2725 AssemblyProductAttribute a = null;
2726 // On MS we get a NullRefException if product attribute is not
2727 // set.
2728 if (attrs != null && attrs.Length > 0)
2729 a = (AssemblyProductAttribute) attrs [0];
2730 return a.Product;
2734 [EditorBrowsable(EditorBrowsableState.Advanced)]
2735 [Browsable(false)]
2736 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2737 public string ProductVersion {
2738 get {
2739 Type t = typeof (AssemblyVersionAttribute);
2740 Assembly assembly = GetType().Module.Assembly;
2741 object [] attrs = assembly.GetCustomAttributes (t, false);
2742 if (attrs == null || attrs.Length < 1)
2743 return "1.0.0.0";
2744 return ((AssemblyVersionAttribute)attrs [0]).Version;
2748 [EditorBrowsable(EditorBrowsableState.Advanced)]
2749 [Browsable(false)]
2750 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2751 public bool RecreatingHandle {
2752 get {
2753 return is_recreating;
2757 [EditorBrowsable(EditorBrowsableState.Advanced)]
2758 [Browsable(false)]
2759 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2760 public Region Region {
2761 get {
2762 return clip_region;
2765 set {
2766 if (clip_region != value) {
2767 if (value != null && IsHandleCreated)
2768 XplatUI.SetClipRegion(Handle, value);
2770 clip_region = value;
2771 #if NET_2_0
2772 OnRegionChanged (EventArgs.Empty);
2773 #endif
2778 [EditorBrowsable(EditorBrowsableState.Advanced)]
2779 [Browsable(false)]
2780 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2781 public int Right {
2782 get {
2783 return this.bounds.X+this.bounds.Width;
2787 [AmbientValue(RightToLeft.Inherit)]
2788 [Localizable(true)]
2789 [MWFCategory("Appearance")]
2790 public virtual RightToLeft RightToLeft {
2791 get {
2792 if (right_to_left == RightToLeft.Inherit) {
2793 if (parent != null)
2794 return parent.RightToLeft;
2795 else
2796 return RightToLeft.No; // default value
2798 return right_to_left;
2801 set {
2802 if (value != right_to_left) {
2803 right_to_left = value;
2804 OnRightToLeftChanged(EventArgs.Empty);
2805 PerformLayout ();
2810 [EditorBrowsable(EditorBrowsableState.Advanced)]
2811 public override ISite Site {
2812 get {
2813 return base.Site;
2816 set {
2817 base.Site = value;
2819 if (value != null) {
2820 AmbientProperties ap = (AmbientProperties) value.GetService (typeof (AmbientProperties));
2821 if (ap != null) {
2822 BackColor = ap.BackColor;
2823 ForeColor = ap.ForeColor;
2824 Cursor = ap.Cursor;
2825 Font = ap.Font;
2831 [Localizable(true)]
2832 [MWFCategory("Layout")]
2833 public Size Size {
2834 get {
2835 return new Size(Width, Height);
2838 set {
2839 SetBounds(bounds.X, bounds.Y, value.Width, value.Height, BoundsSpecified.Size);
2843 [Localizable(true)]
2844 [MergableProperty(false)]
2845 [MWFCategory("Behavior")]
2846 public int TabIndex {
2847 get {
2848 if (tab_index != -1) {
2849 return tab_index;
2851 return 0;
2854 set {
2855 if (tab_index != value) {
2856 tab_index = value;
2857 OnTabIndexChanged(EventArgs.Empty);
2862 [DispId(-516)]
2863 [DefaultValue(true)]
2864 [MWFCategory("Behavior")]
2865 public bool TabStop {
2866 get {
2867 return tab_stop;
2870 set {
2871 if (tab_stop != value) {
2872 tab_stop = value;
2873 OnTabStopChanged(EventArgs.Empty);
2878 [Localizable(false)]
2879 [Bindable(true)]
2880 [TypeConverter(typeof(StringConverter))]
2881 [DefaultValue(null)]
2882 [MWFCategory("Data")]
2883 public object Tag {
2884 get {
2885 return control_tag;
2888 set {
2889 control_tag = value;
2893 [DispId(-517)]
2894 [Localizable(true)]
2895 [BindableAttribute(true)]
2896 [MWFCategory("Appearance")]
2897 public virtual string Text {
2898 get {
2899 // Our implementation ignores ControlStyles.CacheText - we always cache
2900 return this.text;
2903 set {
2904 if (value == null) {
2905 value = String.Empty;
2908 if (text!=value) {
2909 text=value;
2910 if (IsHandleCreated) {
2911 /* we need to call .SetWindowStyle here instead of just .Text
2912 because the presence/absence of Text (== "" or not) can cause
2913 other window style things to appear/disappear */
2914 XplatUI.SetWindowStyle(window.Handle, CreateParams);
2915 XplatUI.Text(Handle, text);
2917 OnTextChanged (EventArgs.Empty);
2922 [EditorBrowsable(EditorBrowsableState.Always)]
2923 [Browsable(false)]
2924 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2925 public int Top {
2926 get {
2927 return this.bounds.Y;
2930 set {
2931 SetBounds(bounds.X, value, bounds.Width, bounds.Height, BoundsSpecified.Y);
2935 [EditorBrowsable(EditorBrowsableState.Advanced)]
2936 [Browsable(false)]
2937 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2938 public Control TopLevelControl {
2939 get {
2940 Control p = this;
2942 while (p.parent != null) {
2943 p = p.parent;
2946 return p is Form ? p : null;
2950 [Localizable(true)]
2951 [MWFCategory("Behavior")]
2952 public bool Visible {
2953 get {
2954 if (!is_visible) {
2955 return false;
2956 } else if (parent != null) {
2957 return parent.Visible;
2960 return true;
2963 set {
2964 SetVisibleCore(value);
2968 [EditorBrowsable(EditorBrowsableState.Always)]
2969 [Browsable(false)]
2970 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2971 public int Width {
2972 get {
2973 return this.bounds.Width;
2976 set {
2977 SetBounds(bounds.X, bounds.Y, value, bounds.Height, BoundsSpecified.Width);
2981 [EditorBrowsable(EditorBrowsableState.Never)]
2982 [Browsable(false)]
2983 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2984 public IWindowTarget WindowTarget {
2985 get {
2986 return null;
2989 set {
2990 ; // MS Internal
2993 #endregion // Public Instance Properties
2995 #region Protected Instance Properties
2996 protected virtual CreateParams CreateParams {
2997 get {
2998 CreateParams create_params = new CreateParams();
3000 try {
3001 create_params.Caption = Text;
3003 catch {
3004 create_params.Caption = text;
3007 try {
3008 create_params.X = Left;
3010 catch {
3011 create_params.X = this.bounds.X;
3014 try {
3015 create_params.Y = Top;
3017 catch {
3018 create_params.Y = this.bounds.Y;
3021 try {
3022 create_params.Width = Width;
3024 catch {
3025 create_params.Width = this.bounds.Width;
3028 try {
3029 create_params.Height = Height;
3031 catch {
3032 create_params.Height = this.bounds.Height;
3036 create_params.ClassName = XplatUI.DefaultClassName;
3037 create_params.ClassStyle = (int)(XplatUIWin32.ClassStyle.CS_OWNDC | XplatUIWin32.ClassStyle.CS_DBLCLKS);
3038 create_params.ExStyle = 0;
3039 create_params.Param = 0;
3041 if (allow_drop) {
3042 create_params.ExStyle |= (int)WindowExStyles.WS_EX_ACCEPTFILES;
3045 if ((parent!=null) && (parent.IsHandleCreated)) {
3046 create_params.Parent = parent.Handle;
3049 create_params.Style = (int)WindowStyles.WS_CHILD | (int)WindowStyles.WS_CLIPCHILDREN | (int)WindowStyles.WS_CLIPSIBLINGS;
3051 if (is_visible) {
3052 create_params.Style |= (int)WindowStyles.WS_VISIBLE;
3055 if (!is_enabled) {
3056 create_params.Style |= (int)WindowStyles.WS_DISABLED;
3059 switch (border_style) {
3060 case BorderStyle.FixedSingle:
3061 create_params.Style |= (int) WindowStyles.WS_BORDER;
3062 break;
3063 case BorderStyle.Fixed3D:
3064 create_params.ExStyle |= (int) WindowExStyles.WS_EX_CLIENTEDGE;
3065 break;
3068 return create_params;
3072 #if NET_2_0
3073 protected virtual Cursor DefaultCursor { get { return Cursors.Default; } }
3074 #endif
3076 protected virtual ImeMode DefaultImeMode {
3077 get {
3078 return ImeMode.Inherit;
3082 #if NET_2_0
3083 protected virtual Padding DefaultMargin {
3084 get { return new Padding (3); }
3087 protected virtual Size DefaultMaximumSize { get { return new Size (); } }
3088 protected virtual Size DefaultMinimumSize { get { return new Size (); } }
3089 protected virtual Padding DefaultPadding { get { return new Padding (); } }
3090 #endif
3092 protected virtual Size DefaultSize {
3093 get {
3094 return new Size(0, 0);
3098 protected int FontHeight {
3099 get {
3100 return Font.Height;
3103 set {
3104 ;; // Nothing to do
3107 #if NET_2_0
3108 [Obsolete ()]
3109 #endif
3110 protected bool RenderRightToLeft {
3111 get {
3112 return (this.right_to_left == RightToLeft.Yes);
3116 protected bool ResizeRedraw {
3117 get {
3118 return GetStyle(ControlStyles.ResizeRedraw);
3121 set {
3122 SetStyle(ControlStyles.ResizeRedraw, value);
3126 [EditorBrowsable(EditorBrowsableState.Advanced)]
3127 [Browsable(false)]
3128 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
3129 protected virtual bool ShowFocusCues {
3130 get {
3131 return true;
3135 [EditorBrowsable(EditorBrowsableState.Advanced)]
3136 [Browsable(false)]
3137 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
3138 #if NET_2_0
3139 internal virtual
3140 #endif
3141 protected bool ShowKeyboardCues {
3142 get {
3143 return true;
3146 #endregion // Protected Instance Properties
3148 #region Public Static Methods
3149 [EditorBrowsable(EditorBrowsableState.Advanced)]
3150 public static Control FromChildHandle(IntPtr handle) {
3151 return Control.ControlNativeWindow.ControlFromChildHandle (handle);
3154 [EditorBrowsable(EditorBrowsableState.Advanced)]
3155 public static Control FromHandle(IntPtr handle) {
3156 return Control.ControlNativeWindow.ControlFromHandle(handle);
3159 public static bool IsMnemonic(char charCode, string text) {
3160 int amp;
3162 amp = text.IndexOf('&');
3164 if (amp != -1) {
3165 if (amp + 1 < text.Length) {
3166 if (text[amp + 1] != '&') {
3167 if (Char.ToUpper(charCode) == Char.ToUpper(text.ToCharArray(amp + 1, 1)[0])) {
3168 return true;
3173 return false;
3175 #endregion
3177 #region Protected Static Methods
3178 [EditorBrowsable(EditorBrowsableState.Advanced)]
3179 protected static bool ReflectMessage(IntPtr hWnd, ref Message m) {
3180 Control c;
3182 c = Control.FromHandle(hWnd);
3184 if (c != null) {
3185 c.WndProc(ref m);
3186 return true;
3188 return false;
3190 #endregion
3192 #region Public Instance Methods
3193 [EditorBrowsable(EditorBrowsableState.Advanced)]
3194 public IAsyncResult BeginInvoke(Delegate method) {
3195 object [] prms = null;
3196 if (method is EventHandler)
3197 prms = new object [] { this, EventArgs.Empty };
3198 return BeginInvokeInternal(method, prms, false);
3201 [EditorBrowsable(EditorBrowsableState.Advanced)]
3202 #if NET_2_0
3203 public IAsyncResult BeginInvoke (Delegate method, params object[] args)
3204 #else
3205 public IAsyncResult BeginInvoke (Delegate method, object[] args)
3206 #endif
3208 return BeginInvokeInternal (method, args, false);
3211 public void BringToFront() {
3212 if (parent != null) {
3213 parent.child_controls.SetChildIndex(this, 0);
3215 else if (IsHandleCreated) {
3216 XplatUI.SetZOrder(Handle, IntPtr.Zero, false, false);
3220 public bool Contains(Control ctl) {
3221 while (ctl != null) {
3222 ctl = ctl.parent;
3223 if (ctl == this) {
3224 return true;
3227 return false;
3230 public void CreateControl () {
3231 if (is_disposed) {
3232 throw new ObjectDisposedException(GetType().FullName.ToString());
3234 if (is_created) {
3235 return;
3238 if (!IsHandleCreated) {
3239 CreateHandle();
3242 if (!is_created) {
3243 is_created = true;
3246 if (binding_context == null) { // seem to be sent whenever it's null?
3247 OnBindingContextChanged(EventArgs.Empty);
3250 OnCreateControl();
3253 public Graphics CreateGraphics() {
3254 if (!IsHandleCreated) {
3255 this.CreateHandle();
3257 return Graphics.FromHwnd(this.window.Handle);
3260 public DragDropEffects DoDragDrop(object data, DragDropEffects allowedEffects) {
3261 if (IsHandleCreated)
3262 return XplatUI.StartDrag(Handle, data, allowedEffects);
3263 else
3264 return DragDropEffects.None;
3267 [EditorBrowsable(EditorBrowsableState.Advanced)]
3268 public object EndInvoke (IAsyncResult async_result) {
3269 AsyncMethodResult result = (AsyncMethodResult) async_result;
3270 return result.EndInvoke ();
3273 public Form FindForm() {
3274 Control c;
3276 c = this;
3277 while (c != null) {
3278 if (c is Form) {
3279 return (Form)c;
3281 c = c.Parent;
3283 return null;
3285 #if NET_2_0
3286 [EditorBrowsable (EditorBrowsableState.Advanced)]
3287 #endif
3288 public bool Focus() {
3289 if (CanFocus && IsHandleCreated && !has_focus && !is_focusing) {
3290 is_focusing = true;
3291 Select(this);
3292 is_focusing = false;
3294 return has_focus;
3297 internal void FocusInternal () {
3298 is_focusing = true;
3299 Select(this);
3300 is_focusing = false;
3303 public Control GetChildAtPoint(Point pt) {
3304 // MS's version causes the handle to be created. The stack trace shows that get_Handle is called here, but
3305 // we'll just call CreateHandle instead.
3306 CreateHandle ();
3308 // Microsoft's version of this function doesn't seem to work, so I can't check
3309 // if we only consider children or also grandchildren, etc.
3310 // I'm gonna say 'children only'
3311 for (int i=0; i<child_controls.Count; i++) {
3312 if (child_controls[i].Bounds.Contains(pt)) {
3313 return child_controls[i];
3316 return null;
3319 public IContainerControl GetContainerControl() {
3320 Control current = this;
3322 while (current!=null) {
3323 if ((current is IContainerControl) && ((current.control_style & ControlStyles.ContainerControl)!=0)) {
3324 return (IContainerControl)current;
3326 current = current.parent;
3328 return null;
3331 public Control GetNextControl(Control ctl, bool forward) {
3333 if (!this.Contains(ctl)) {
3334 ctl = this;
3337 if (forward) {
3338 ctl = FindControlForward(this, ctl);
3340 else {
3341 ctl = FindControlBackward(this, ctl);
3344 if (ctl != this) {
3345 return ctl;
3347 return null;
3350 #if NET_2_0
3351 [EditorBrowsable (EditorBrowsableState.Advanced)]
3352 public virtual Size GetPreferredSize (Size proposedSize) {
3353 Size retsize = this.explicit_bounds.Size;
3355 // If we're bigger than the MaximumSize, fix that
3356 if (this.maximum_size.Width != 0 && retsize.Width > this.maximum_size.Width)
3357 retsize.Width = this.maximum_size.Width;
3358 if (this.maximum_size.Height != 0 && retsize.Height > this.maximum_size.Height)
3359 retsize.Height = this.maximum_size.Height;
3361 // If we're smaller than the MinimumSize, fix that
3362 if (this.minimum_size.Width != 0 && retsize.Width < this.minimum_size.Width)
3363 retsize.Width = this.minimum_size.Width;
3364 if (this.minimum_size.Height != 0 && retsize.Height < this.minimum_size.Height)
3365 retsize.Height = this.minimum_size.Height;
3367 return retsize;
3369 #endif
3371 public void Hide() {
3372 this.Visible = false;
3375 public void Invalidate() {
3376 Invalidate(ClientRectangle, false);
3379 public void Invalidate(bool invalidateChildren) {
3380 Invalidate(ClientRectangle, invalidateChildren);
3383 public void Invalidate(System.Drawing.Rectangle rc) {
3384 Invalidate(rc, false);
3387 public void Invalidate(System.Drawing.Rectangle rc, bool invalidateChildren) {
3388 // Win32 invalidates control including when Width and Height is equal 0
3389 // or is not visible, only Paint event must be care about this.
3390 if (!IsHandleCreated)
3391 return;
3393 if (rc.Width > 0 && rc.Height > 0) {
3395 NotifyInvalidate(rc);
3397 XplatUI.Invalidate(Handle, rc, false);
3399 if (invalidateChildren) {
3400 Control [] controls = child_controls.GetAllControls ();
3401 for (int i=0; i<controls.Length; i++)
3402 controls [i].Invalidate ();
3405 OnInvalidated(new InvalidateEventArgs(rc));
3408 public void Invalidate(System.Drawing.Region region) {
3409 Invalidate(region, false);
3412 public void Invalidate(System.Drawing.Region region, bool invalidateChildren) {
3413 RectangleF bounds = region.GetBounds (CreateGraphics ());
3414 Invalidate (new Rectangle ((int) bounds.X, (int) bounds.Y, (int) bounds.Width, (int) bounds.Height),
3415 invalidateChildren);
3418 public object Invoke (Delegate method) {
3419 object [] prms = null;
3420 if (method is EventHandler)
3421 prms = new object [] { this, EventArgs.Empty };
3423 return Invoke(method, prms);
3426 public object Invoke (Delegate method, object[] args) {
3427 Control p = this;
3428 do {
3429 if (!p.IsHandleCreated)
3430 throw new InvalidOperationException("Cannot call Invoke or BeginInvoke on a control until the window handle is created");
3431 p = p.parent;
3432 } while (p != null);
3434 if (!this.InvokeRequired) {
3435 return method.DynamicInvoke(args);
3438 IAsyncResult result = BeginInvoke (method, args);
3439 return EndInvoke(result);
3442 [EditorBrowsable(EditorBrowsableState.Advanced)]
3443 public void PerformLayout() {
3444 PerformLayout(null, null);
3447 internal void SetImplicitBounds (int x, int y, int width, int height) {
3448 Rectangle saved_bounds = explicit_bounds;
3449 SetBounds (x, y, width, height);
3450 explicit_bounds = saved_bounds;
3453 [EditorBrowsable(EditorBrowsableState.Advanced)]
3454 public void PerformLayout(Control affectedControl, string affectedProperty) {
3455 LayoutEventArgs levent = new LayoutEventArgs(affectedControl, affectedProperty);
3457 if (layout_suspended > 0) {
3458 layout_pending = true;
3459 return;
3462 layout_pending = false;
3464 // Prevent us from getting messed up
3465 layout_suspended++;
3467 // Perform all Dock and Anchor calculations
3468 try {
3469 OnLayout(levent);
3472 // Need to make sure we decremend layout_suspended
3473 finally {
3474 layout_suspended--;
3478 public Point PointToClient (Point p) {
3479 int x = p.X;
3480 int y = p.Y;
3482 XplatUI.ScreenToClient (Handle, ref x, ref y);
3484 return new Point (x, y);
3487 public Point PointToScreen(Point p) {
3488 int x = p.X;
3489 int y = p.Y;
3491 XplatUI.ClientToScreen(Handle, ref x, ref y);
3493 return new Point(x, y);
3496 public virtual bool PreProcessMessage(ref Message msg) {
3497 return InternalPreProcessMessage (ref msg);
3500 internal virtual bool InternalPreProcessMessage (ref Message msg) {
3501 Keys key_data;
3503 if ((msg.Msg == (int)Msg.WM_KEYDOWN) || (msg.Msg == (int)Msg.WM_SYSKEYDOWN)) {
3504 key_data = (Keys)msg.WParam.ToInt32() | XplatUI.State.ModifierKeys;
3506 if (!ProcessCmdKey(ref msg, key_data)) {
3507 if (IsInputKey(key_data)) {
3508 return false;
3511 return ProcessDialogKey(key_data);
3514 return true;
3515 } else if (msg.Msg == (int)Msg.WM_CHAR) {
3516 if (IsInputChar((char)msg.WParam)) {
3517 return false;
3519 return ProcessDialogChar((char)msg.WParam);
3520 } else if (msg.Msg == (int)Msg.WM_SYSCHAR) {
3521 return ProcessDialogChar((char)msg.WParam);
3523 return false;
3526 public Rectangle RectangleToClient(Rectangle r) {
3527 return new Rectangle(PointToClient(r.Location), r.Size);
3530 public Rectangle RectangleToScreen(Rectangle r) {
3531 return new Rectangle(PointToScreen(r.Location), r.Size);
3534 public virtual void Refresh() {
3535 if (IsHandleCreated && Visible) {
3536 Invalidate();
3537 XplatUI.UpdateWindow(window.Handle);
3539 Control [] controls = child_controls.GetAllControls ();
3540 for (int i=0; i < controls.Length; i++) {
3541 controls[i].Refresh();
3547 [EditorBrowsable(EditorBrowsableState.Never)]
3548 public virtual void ResetBackColor() {
3549 BackColor = Color.Empty;
3552 [EditorBrowsable(EditorBrowsableState.Never)]
3553 public void ResetBindings() {
3554 if (data_bindings != null)
3555 data_bindings.Clear();
3558 [EditorBrowsable(EditorBrowsableState.Never)]
3559 public virtual void ResetCursor() {
3560 Cursor = null;
3563 [EditorBrowsable(EditorBrowsableState.Never)]
3564 public virtual void ResetFont() {
3565 font = null;
3568 [EditorBrowsable(EditorBrowsableState.Never)]
3569 public virtual void ResetForeColor() {
3570 foreground_color = Color.Empty;
3573 [EditorBrowsable(EditorBrowsableState.Never)]
3574 public void ResetImeMode() {
3575 ime_mode = DefaultImeMode;
3578 [EditorBrowsable(EditorBrowsableState.Never)]
3579 public virtual void ResetRightToLeft() {
3580 right_to_left = RightToLeft.Inherit;
3583 public virtual void ResetText() {
3584 text = String.Empty;
3587 public void ResumeLayout() {
3588 ResumeLayout (true);
3591 public void ResumeLayout(bool performLayout) {
3592 if (layout_suspended > 0) {
3593 layout_suspended--;
3596 if (layout_suspended == 0) {
3597 if (performLayout && layout_pending) {
3598 PerformLayout();
3602 #if NET_2_0
3603 [EditorBrowsable (EditorBrowsableState.Never)]
3604 [Obsolete ()]
3605 #endif
3606 public void Scale(float ratio) {
3607 ScaleCore(ratio, ratio);
3610 #if NET_2_0
3611 [EditorBrowsable (EditorBrowsableState.Never)]
3612 [Obsolete ()]
3613 #endif
3614 public void Scale(float dx, float dy) {
3615 ScaleCore(dx, dy);
3618 #if NET_2_0
3619 [EditorBrowsable (EditorBrowsableState.Advanced)]
3620 public void Scale(SizeF factor) {
3621 ScaleCore(factor.Width, factor.Height);
3623 #endif
3625 public void Select() {
3626 Select(false, false);
3629 #if DebugFocus
3630 private void printTree(Control c, string t) {
3631 foreach(Control i in c.child_controls) {
3632 Console.WriteLine ("{2}{0}.TabIndex={1}", i, i.tab_index, t);
3633 printTree (i, t+"\t");
3636 #endif
3637 public bool SelectNextControl(Control ctl, bool forward, bool tabStopOnly, bool nested, bool wrap) {
3638 Control c;
3640 #if DebugFocus
3641 Console.WriteLine("{0}", this.FindForm());
3642 printTree(this, "\t");
3643 #endif
3645 if (!this.Contains(ctl) || (!nested && (ctl.parent != this))) {
3646 ctl = null;
3648 c = ctl;
3649 do {
3650 c = GetNextControl(c, forward);
3651 if (c == null) {
3652 if (wrap) {
3653 wrap = false;
3654 continue;
3656 break;
3659 if (c.CanSelect && ((c.parent == this) || nested) && (c.tab_stop || !tabStopOnly)) {
3660 c.Select (true, true);
3661 return true;
3663 } while (c != ctl); // If we wrap back to ourselves we stop
3665 return false;
3668 public void SendToBack() {
3669 if (parent != null) {
3670 parent.child_controls.SetChildIndex(this, parent.child_controls.Count);
3674 public void SetBounds(int x, int y, int width, int height) {
3675 SetBounds(x, y, width, height, BoundsSpecified.All);
3678 public void SetBounds(int x, int y, int width, int height, BoundsSpecified specified) {
3679 if ((specified & BoundsSpecified.X) != BoundsSpecified.X) {
3680 x = Left;
3683 if ((specified & BoundsSpecified.Y) != BoundsSpecified.Y) {
3684 y = Top;
3687 if ((specified & BoundsSpecified.Width) != BoundsSpecified.Width) {
3688 width = Width;
3691 if ((specified & BoundsSpecified.Height) != BoundsSpecified.Height) {
3692 height = Height;
3695 SetBoundsCore(x, y, width, height, specified);
3696 if (parent != null)
3697 parent.PerformLayout(this, "Bounds");
3700 public void Show () {
3701 this.Visible = true;
3704 public void SuspendLayout() {
3705 layout_suspended++;
3708 public void Update() {
3709 if (IsHandleCreated) {
3710 XplatUI.UpdateWindow(window.Handle);
3713 #endregion // Public Instance Methods
3715 #region Protected Instance Methods
3716 [EditorBrowsable(EditorBrowsableState.Advanced)]
3717 protected void AccessibilityNotifyClients(AccessibleEvents accEvent, int childID) {
3718 // turns out this method causes handle
3719 // creation in 1.1. at first I thought this
3720 // would be accomplished just by using
3721 // get_AccessibilityObject, which would route
3722 // through CreateAccessibilityInstance, which
3723 // calls CreateControl. This isn't the case,
3724 // though (as overriding
3725 // CreateAccessibilityInstance and adding a
3726 // CWL shows nothing. So we fudge it and put
3727 // a CreateHandle here.
3729 #if ONLY_1_1
3730 CreateHandle ();
3731 #endif
3733 if (accessibility_object != null && accessibility_object is ControlAccessibleObject)
3734 ((ControlAccessibleObject)accessibility_object).NotifyClients (accEvent, childID);
3737 [EditorBrowsable(EditorBrowsableState.Advanced)]
3738 protected virtual AccessibleObject CreateAccessibilityInstance() {
3739 CreateControl ();
3740 return new Control.ControlAccessibleObject(this);
3743 [EditorBrowsable(EditorBrowsableState.Advanced)]
3744 protected virtual ControlCollection CreateControlsInstance() {
3745 return new ControlCollection(this);
3748 [EditorBrowsable(EditorBrowsableState.Advanced)]
3749 protected virtual void CreateHandle() {
3750 if (IsDisposed) {
3751 throw new ObjectDisposedException(GetType().FullName.ToString());
3754 if (IsHandleCreated && !is_recreating) {
3755 return;
3758 window.CreateHandle(CreateParams);
3760 if (window.Handle != IntPtr.Zero) {
3761 creator_thread = Thread.CurrentThread;
3763 XplatUI.EnableWindow(window.Handle, is_enabled);
3765 if (clip_region != null) {
3766 XplatUI.SetClipRegion(window.Handle, clip_region);
3769 // Set our handle with our parent
3770 if ((parent != null) && (parent.IsHandleCreated)) {
3771 XplatUI.SetParent(window.Handle, parent.Handle);
3774 UpdateStyles();
3775 XplatUI.SetAllowDrop (window.Handle, allow_drop);
3777 // Find out where the window manager placed us
3778 if ((CreateParams.Style & (int)WindowStyles.WS_CHILD) != 0) {
3779 XplatUI.SetBorderStyle(window.Handle, (FormBorderStyle)border_style);
3781 UpdateBounds();
3785 [EditorBrowsable(EditorBrowsableState.Advanced)]
3786 protected virtual void DefWndProc(ref Message m) {
3787 window.DefWndProc(ref m);
3790 [EditorBrowsable(EditorBrowsableState.Advanced)]
3791 protected virtual void DestroyHandle() {
3792 if (IsHandleCreated) {
3793 if (window != null) {
3794 window.DestroyHandle();
3799 #if NET_2_0
3800 protected virtual AccessibleObject GetAccessibilityObjectById (int objectId)
3802 // XXX need to implement this.
3803 return null;
3805 #endif
3807 protected internal bool GetStyle(ControlStyles flag) {
3808 return (control_style & flag) != 0;
3811 protected bool GetTopLevel() {
3812 return is_toplevel;
3815 [EditorBrowsable(EditorBrowsableState.Advanced)]
3816 protected virtual void InitLayout() {
3817 UpdateDistances();
3820 [EditorBrowsable(EditorBrowsableState.Advanced)]
3821 protected void InvokeGotFocus(Control toInvoke, EventArgs e) {
3822 toInvoke.OnGotFocus(e);
3825 [EditorBrowsable(EditorBrowsableState.Advanced)]
3826 protected void InvokeLostFocus(Control toInvoke, EventArgs e) {
3827 toInvoke.OnLostFocus(e);
3830 [EditorBrowsable(EditorBrowsableState.Advanced)]
3831 protected void InvokeOnClick(Control toInvoke, EventArgs e) {
3832 toInvoke.OnClick(e);
3835 protected void InvokePaint(Control toInvoke, PaintEventArgs e) {
3836 toInvoke.OnPaint(e);
3839 protected void InvokePaintBackground(Control toInvoke, PaintEventArgs e) {
3840 toInvoke.OnPaintBackground(e);
3843 protected virtual bool IsInputChar (char charCode) {
3844 // XXX on MS.NET this method causes the handle to be created..
3845 CreateHandle ();
3847 return true;
3850 protected virtual bool IsInputKey (Keys keyData) {
3851 // Doc says this one calls IsInputChar; not sure what to do with that
3852 return false;
3855 [EditorBrowsable(EditorBrowsableState.Advanced)]
3856 protected virtual void NotifyInvalidate(Rectangle invalidatedArea) {
3857 // override me?
3860 protected virtual bool ProcessCmdKey(ref Message msg, Keys keyData) {
3861 if ((context_menu != null) && context_menu.ProcessCmdKey(ref msg, keyData)) {
3862 return true;
3865 if (parent != null) {
3866 return parent.ProcessCmdKey(ref msg, keyData);
3869 return false;
3872 protected virtual bool ProcessDialogChar(char charCode) {
3873 if (parent != null) {
3874 return parent.ProcessDialogChar (charCode);
3877 return false;
3880 protected virtual bool ProcessDialogKey (Keys keyData) {
3881 if (parent != null) {
3882 return parent.ProcessDialogKey (keyData);
3885 return false;
3888 protected virtual bool ProcessKeyEventArgs (ref Message msg) {
3889 KeyEventArgs key_event;
3891 switch (msg.Msg) {
3892 case (int)Msg.WM_SYSKEYDOWN:
3893 case (int)Msg.WM_KEYDOWN: {
3894 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
3895 OnKeyDown (key_event);
3896 return key_event.Handled;
3899 case (int)Msg.WM_SYSKEYUP:
3900 case (int)Msg.WM_KEYUP: {
3901 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
3902 OnKeyUp (key_event);
3903 return key_event.Handled;
3906 case (int)Msg.WM_SYSCHAR:
3907 case (int)Msg.WM_CHAR: {
3908 KeyPressEventArgs key_press_event;
3910 key_press_event = new KeyPressEventArgs((char)msg.WParam);
3911 OnKeyPress(key_press_event);
3912 #if NET_2_0
3913 msg.WParam = (IntPtr)key_press_event.KeyChar;
3914 #endif
3915 return key_press_event.Handled;
3918 default: {
3919 break;
3923 return false;
3926 protected internal virtual bool ProcessKeyMessage(ref Message msg) {
3927 if (parent != null) {
3928 if (parent.ProcessKeyPreview(ref msg)) {
3929 return true;
3933 return ProcessKeyEventArgs(ref msg);
3936 protected virtual bool ProcessKeyPreview(ref Message msg) {
3937 if (parent != null) {
3938 return parent.ProcessKeyPreview(ref msg);
3941 return false;
3944 protected virtual bool ProcessMnemonic(char charCode) {
3945 // override me
3946 return false;
3949 [EditorBrowsable(EditorBrowsableState.Advanced)]
3950 protected void RaiseDragEvent(object key, DragEventArgs e) {
3951 // MS Internal
3954 [EditorBrowsable(EditorBrowsableState.Advanced)]
3955 protected void RaiseKeyEvent(object key, KeyEventArgs e) {
3956 // MS Internal
3959 [EditorBrowsable(EditorBrowsableState.Advanced)]
3960 protected void RaiseMouseEvent(object key, MouseEventArgs e) {
3961 // MS Internal
3964 [EditorBrowsable(EditorBrowsableState.Advanced)]
3965 protected void RaisePaintEvent(object key, PaintEventArgs e) {
3966 // MS Internal
3969 private void SetIsRecreating () {
3970 is_recreating=true;
3972 foreach (Control c in Controls.GetAllControls()) {
3973 c.SetIsRecreating ();
3977 [EditorBrowsable(EditorBrowsableState.Advanced)]
3978 protected void RecreateHandle() {
3979 if (!IsHandleCreated)
3980 return;
3982 #if DebugRecreate
3983 Console.WriteLine("Recreating control {0}", XplatUI.Window(window.Handle));
3984 #endif
3986 SetIsRecreating ();
3988 if (IsHandleCreated) {
3989 #if DebugRecreate
3990 Console.WriteLine(" + handle is created, destroying it.");
3991 #endif
3992 DestroyHandle();
3993 // WM_DESTROY will CreateHandle for us
3994 } else {
3995 #if DebugRecreate
3996 Console.WriteLine(" + handle is not created, creating it.");
3997 #endif
3998 if (!is_created) {
3999 CreateControl();
4000 } else {
4001 CreateHandle();
4004 is_recreating = false;
4005 #if DebugRecreate
4006 Console.WriteLine (" + new handle = {0:X}", Handle.ToInt32());
4007 #endif
4012 [EditorBrowsable(EditorBrowsableState.Advanced)]
4013 protected void ResetMouseEventArgs() {
4014 // MS Internal
4017 [EditorBrowsable(EditorBrowsableState.Advanced)]
4018 protected ContentAlignment RtlTranslateAlignment(ContentAlignment align) {
4019 if (right_to_left == RightToLeft.No) {
4020 return align;
4023 switch (align) {
4024 case ContentAlignment.TopLeft: {
4025 return ContentAlignment.TopRight;
4028 case ContentAlignment.TopRight: {
4029 return ContentAlignment.TopLeft;
4032 case ContentAlignment.MiddleLeft: {
4033 return ContentAlignment.MiddleRight;
4036 case ContentAlignment.MiddleRight: {
4037 return ContentAlignment.MiddleLeft;
4040 case ContentAlignment.BottomLeft: {
4041 return ContentAlignment.BottomRight;
4044 case ContentAlignment.BottomRight: {
4045 return ContentAlignment.BottomLeft;
4048 default: {
4049 // if it's center it doesn't change
4050 return align;
4055 [EditorBrowsable(EditorBrowsableState.Advanced)]
4056 protected HorizontalAlignment RtlTranslateAlignment(HorizontalAlignment align) {
4057 if ((right_to_left == RightToLeft.No) || (align == HorizontalAlignment.Center)) {
4058 return align;
4061 if (align == HorizontalAlignment.Left) {
4062 return HorizontalAlignment.Right;
4065 // align must be HorizontalAlignment.Right
4066 return HorizontalAlignment.Left;
4069 [EditorBrowsable(EditorBrowsableState.Advanced)]
4070 protected LeftRightAlignment RtlTranslateAlignment(LeftRightAlignment align) {
4071 if (right_to_left == RightToLeft.No) {
4072 return align;
4075 if (align == LeftRightAlignment.Left) {
4076 return LeftRightAlignment.Right;
4079 // align must be LeftRightAlignment.Right;
4080 return LeftRightAlignment.Left;
4083 [EditorBrowsable(EditorBrowsableState.Advanced)]
4084 protected ContentAlignment RtlTranslateContent(ContentAlignment align) {
4085 return RtlTranslateAlignment(align);
4088 [EditorBrowsable(EditorBrowsableState.Advanced)]
4089 protected HorizontalAlignment RtlTranslateHorizontal(HorizontalAlignment align) {
4090 return RtlTranslateAlignment(align);
4093 [EditorBrowsable(EditorBrowsableState.Advanced)]
4094 protected LeftRightAlignment RtlTranslateLeftRight(LeftRightAlignment align) {
4095 return RtlTranslateAlignment(align);
4098 #if NET_2_0
4099 [EditorBrowsable (EditorBrowsableState.Never)]
4100 #else
4101 [EditorBrowsable(EditorBrowsableState.Advanced)]
4102 #endif
4103 protected virtual void ScaleCore(float dx, float dy) {
4104 Point location;
4105 Size size;
4107 SuspendLayout();
4109 location = new Point((int)(Left * dx), (int)(Top * dy));
4110 size = this.ClientSize;
4112 if (!GetStyle(ControlStyles.FixedWidth)) {
4113 size.Width = (int)(size.Width * dx);
4116 if (!GetStyle(ControlStyles.FixedHeight)) {
4117 size.Height = (int)(size.Height * dy);
4120 SetBounds(location.X, location.Y, size.Width, size.Height, BoundsSpecified.All);
4122 /* Now scale our children */
4123 Control [] controls = child_controls.GetAllControls ();
4124 for (int i=0; i < controls.Length; i++) {
4125 controls[i].Scale(dx, dy);
4128 ResumeLayout();
4131 protected virtual void Select(bool directed, bool forward) {
4132 IContainerControl container;
4134 container = GetContainerControl();
4135 if (container != null && (Control)container != this)
4136 container.ActiveControl = this;
4139 [EditorBrowsable(EditorBrowsableState.Advanced)]
4140 protected virtual void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
4141 // SetBoundsCore updates the Win32 control itself. UpdateBounds updates the controls variables and fires events, I'm guessing - pdb
4142 if (IsHandleCreated) {
4143 XplatUI.SetWindowPos(Handle, x, y, width, height);
4145 // Win32 automatically changes negative width/height to 0.
4146 // The control has already been sent a WM_WINDOWPOSCHANGED message and it has the correct
4147 // data, but it'll be overwritten when we call UpdateBounds unless we get the updated
4148 // size.
4149 if (width < 0 || height < 0) {
4150 int cw, ch, ix, iy;
4151 XplatUI.GetWindowPos(Handle, this is Form, out ix, out iy, out width, out height, out cw, out ch);
4155 UpdateBounds(x, y, width, height);
4157 UpdateDistances();
4160 [EditorBrowsable(EditorBrowsableState.Advanced)]
4161 protected virtual void SetClientSizeCore(int x, int y) {
4162 Size NewSize = SizeFromClientSize (new Size (x, y));
4164 if (NewSize != Size.Empty)
4165 SetBounds (bounds.X, bounds.Y, NewSize.Width, NewSize.Height, BoundsSpecified.Size);
4168 [EditorBrowsable(EditorBrowsableState.Advanced)]
4169 protected internal void SetStyle(ControlStyles flag, bool value) {
4170 if (value) {
4171 control_style |= flag;
4172 } else {
4173 control_style &= ~flag;
4177 protected void SetTopLevel(bool value) {
4178 if ((GetTopLevel() != value) && (parent != null)) {
4179 throw new ArgumentException ("Cannot change toplevel style of a parented control.");
4182 // XXX MS.NET causes handle to be created here
4183 CreateHandle ();
4185 if (this is Form) {
4186 if (value == true) {
4187 if (!Visible) {
4188 Visible = true;
4190 } else {
4191 if (Visible) {
4192 Visible = false;
4196 is_toplevel = value;
4199 protected virtual void SetVisibleCore(bool value) {
4200 if (value != is_visible) {
4201 is_visible = value;
4203 if (is_visible && ((window.Handle == IntPtr.Zero) || !is_created)) {
4204 CreateControl();
4207 if (IsHandleCreated) {
4208 XplatUI.SetVisible(Handle, is_visible, true);
4209 // Explicitly move Toplevel windows to where we want them;
4210 // apparently moving unmapped toplevel windows doesn't work
4211 if (is_visible && (this is Form)) {
4212 XplatUI.SetWindowPos(window.Handle, bounds.X, bounds.Y, bounds.Width, bounds.Height);
4215 else {
4216 OnVisibleChanged(EventArgs.Empty);
4221 [EditorBrowsable (EditorBrowsableState.Advanced)]
4222 #if NET_2_0
4223 protected
4224 #else
4225 internal
4226 #endif
4227 virtual Size SizeFromClientSize (Size clientSize) {
4228 Rectangle ClientRect;
4229 Rectangle WindowRect;
4230 CreateParams cp;
4232 ClientRect = new Rectangle (0, 0, clientSize.Width, clientSize.Height);
4233 cp = this.CreateParams;
4235 if (XplatUI.CalculateWindowRect (ref ClientRect, cp.Style, cp.ExStyle, null, out WindowRect))
4236 return new Size (WindowRect.Width, WindowRect.Height);
4238 return Size.Empty;
4241 [EditorBrowsable(EditorBrowsableState.Advanced)]
4242 protected void UpdateBounds() {
4243 if (!IsHandleCreated)
4244 return;
4246 int x;
4247 int y;
4248 int width;
4249 int height;
4250 int client_width;
4251 int client_height;
4253 XplatUI.GetWindowPos(this.Handle, this is Form, out x, out y, out width, out height, out client_width, out client_height);
4255 UpdateBounds(x, y, width, height, client_width, client_height);
4258 [EditorBrowsable(EditorBrowsableState.Advanced)]
4259 protected void UpdateBounds(int x, int y, int width, int height) {
4260 CreateParams cp;
4261 Rectangle rect;
4263 // Calculate client rectangle
4264 rect = new Rectangle(0, 0, 0, 0);
4265 cp = CreateParams;
4267 XplatUI.CalculateWindowRect(ref rect, cp.Style, cp.ExStyle, cp.menu, out rect);
4268 UpdateBounds(x, y, width, height, width - (rect.Right - rect.Left), height - (rect.Bottom - rect.Top));
4271 [EditorBrowsable(EditorBrowsableState.Advanced)]
4272 protected void UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) {
4273 // UpdateBounds only seems to set our sizes and fire events but not update the GUI window to match
4274 bool moved = false;
4275 bool resized = false;
4277 // Needed to generate required notifications
4278 if ((this.bounds.X!=x) || (this.bounds.Y!=y)) {
4279 moved=true;
4282 if ((this.Bounds.Width!=width) || (this.Bounds.Height!=height)) {
4283 resized=true;
4286 bounds.X=x;
4287 bounds.Y=y;
4288 bounds.Width=width;
4289 bounds.Height=height;
4291 // Assume explicit bounds set. SetImplicitBounds will restore old bounds
4292 explicit_bounds = bounds;
4294 client_size.Width=clientWidth;
4295 client_size.Height=clientHeight;
4297 if (moved) {
4298 OnLocationChanged(EventArgs.Empty);
4300 if (!background_color.IsEmpty && background_color.A < byte.MaxValue)
4301 Invalidate ();
4304 if (resized) {
4305 OnSizeChanged(EventArgs.Empty);
4306 #if NET_2_0
4307 OnClientSizeChanged (EventArgs.Empty);
4308 #endif
4312 [EditorBrowsable(EditorBrowsableState.Advanced)]
4313 protected void UpdateStyles() {
4314 if (!IsHandleCreated) {
4315 return;
4318 XplatUI.SetWindowStyle(window.Handle, CreateParams);
4319 OnStyleChanged(EventArgs.Empty);
4322 private void UpdateZOrderOfChild(Control child) {
4323 if (IsHandleCreated && child.IsHandleCreated && (child.parent == this)) {
4324 int index;
4326 index = child_controls.IndexOf(child);
4328 if (index > 0) {
4329 XplatUI.SetZOrder(child.Handle, child_controls[index - 1].Handle, false, false);
4330 } else {
4331 IntPtr after = AfterTopMostControl ();
4332 if (after != IntPtr.Zero)
4333 XplatUI.SetZOrder (child.Handle, after, false, false);
4334 else
4335 XplatUI.SetZOrder (child.Handle, IntPtr.Zero, true, false);
4340 // Override this if there is a control that shall always remain on
4341 // top of other controls (such as scrollbars). If there are several
4342 // of these controls, the bottom-most should be returned.
4343 internal virtual IntPtr AfterTopMostControl () {
4344 return IntPtr.Zero;
4347 // internal because we need to call it from ScrollableControl.OnVisibleChanged
4348 internal void UpdateChildrenZOrder() {
4349 Control [] controls;
4351 if (!IsHandleCreated) {
4352 return;
4355 // XXX This code is severely broken. It leaks
4356 // the "zero_sized" abstraction out of the X11
4357 // backend and into Control.cs. It'll work on
4358 // windows simply by virtue of windows never
4359 // setting that field to true.
4361 // basically what we need to guard against is
4362 // calling XplatUI.SetZOrder on an hwnd that
4363 // corresponds to an unmapped X window.
4364 controls = child_controls.GetAllControls ();
4366 ArrayList children_to_order = new ArrayList ();
4368 for (int i = 0; i < controls.Length; i ++) {
4369 if (!controls[i].IsHandleCreated || !controls[i].VisibleInternal)
4370 continue;
4372 Hwnd hwnd = Hwnd.ObjectFromHandle (controls[i].Handle);
4373 if (hwnd.zero_sized)
4374 continue;
4376 children_to_order.Add (controls[i]);
4379 for (int i = 1; i < children_to_order.Count; i ++) {
4380 Control upper = (Control)children_to_order[i-1];
4381 Control lower = (Control)children_to_order[i];
4383 XplatUI.SetZOrder(lower.Handle, upper.Handle, false, false);
4387 [EditorBrowsable(EditorBrowsableState.Advanced)]
4388 protected void UpdateZOrder() {
4389 if (parent != null) {
4390 parent.UpdateZOrderOfChild(this);
4394 protected virtual void WndProc(ref Message m) {
4395 #if debug
4396 Console.WriteLine("Control {0} received message {1}", window.Handle == IntPtr.Zero ? this.Text : XplatUI.Window(window.Handle), m.ToString ());
4397 #endif
4398 if ((this.control_style & ControlStyles.EnableNotifyMessage) != 0) {
4399 OnNotifyMessage(m);
4402 switch((Msg)m.Msg) {
4403 case Msg.WM_DESTROY: {
4404 WmDestroy(ref m);
4405 return;
4408 case Msg.WM_WINDOWPOSCHANGED: {
4409 WmWindowPosChanged(ref m);
4410 return;
4413 // Nice description of what should happen when handling WM_PAINT
4414 // can be found here: http://pluralsight.com/wiki/default.aspx/Craig/FlickerFreeControlDrawing.html
4415 // and here http://msdn.microsoft.com/msdnmag/issues/06/03/WindowsFormsPerformance/
4416 case Msg.WM_PAINT: {
4417 WmPaint (ref m);
4418 return;
4421 // The DefWndProc will never have to handle this, we always paint the background in managed code
4422 // In theory this code would look at ControlStyles.AllPaintingInWmPaint and and call OnPaintBackground
4423 // here but it just makes things more complicated...
4424 case Msg.WM_ERASEBKGND: {
4425 WmEraseBackground (ref m);
4426 return;
4429 case Msg.WM_LBUTTONUP: {
4430 WmLButtonUp (ref m);
4431 return;
4434 case Msg.WM_LBUTTONDOWN: {
4435 WmLButtonDown (ref m);
4436 return;
4439 case Msg.WM_LBUTTONDBLCLK: {
4440 WmLButtonDblClick (ref m);
4441 return;
4444 case Msg.WM_MBUTTONUP: {
4445 WmMButtonUp (ref m);
4446 return;
4449 case Msg.WM_MBUTTONDOWN: {
4450 WmMButtonDown (ref m);
4451 return;
4454 case Msg.WM_MBUTTONDBLCLK: {
4455 WmMButtonDblClick (ref m);
4456 return;
4459 case Msg.WM_RBUTTONUP: {
4460 WmRButtonUp (ref m);
4461 return;
4464 case Msg.WM_RBUTTONDOWN: {
4465 WmRButtonDown (ref m);
4466 return;
4469 case Msg.WM_RBUTTONDBLCLK: {
4470 WmRButtonDblClick (ref m);
4471 return;
4474 case Msg.WM_CONTEXTMENU: {
4475 WmContextMenu (ref m);
4476 return;
4479 case Msg.WM_MOUSEWHEEL: {
4480 WmMouseWheel (ref m);
4481 return;
4485 case Msg.WM_MOUSEMOVE: {
4486 WmMouseMove (ref m);
4487 return;
4490 case Msg.WM_SHOWWINDOW: {
4491 WmShowWindow (ref m);
4492 return;
4495 case Msg.WM_CREATE: {
4496 WmCreate (ref m);
4497 return;
4500 case Msg.WM_MOUSE_ENTER: {
4501 WmMouseEnter (ref m);
4502 return;
4505 case Msg.WM_MOUSE_LEAVE: {
4506 WmMouseLeave (ref m);
4507 return;
4510 case Msg.WM_MOUSEHOVER: {
4511 WmMouseHover (ref m);
4512 return;
4515 case Msg.WM_SYSKEYUP: {
4516 WmSysKeyUp (ref m);
4517 return;
4520 case Msg.WM_SYSKEYDOWN:
4521 case Msg.WM_KEYDOWN:
4522 case Msg.WM_KEYUP:
4523 case Msg.WM_SYSCHAR:
4524 case Msg.WM_CHAR: {
4525 WmKeys (ref m);
4526 return;
4529 case Msg.WM_HELP: {
4530 WmHelp (ref m);
4531 return;
4534 case Msg.WM_KILLFOCUS: {
4535 WmKillFocus (ref m);
4536 return;
4539 case Msg.WM_SETFOCUS: {
4540 WmSetFocus (ref m);
4541 return;
4544 case Msg.WM_SYSCOLORCHANGE: {
4545 WmSysColorChange (ref m);
4546 return;
4549 case Msg.WM_SETCURSOR: {
4550 WmSetCursor (ref m);
4551 return;
4554 case Msg.WM_CAPTURECHANGED: {
4555 WmCaptureChanged (ref m);
4556 return;
4559 default:
4560 DefWndProc(ref m);
4561 return;
4564 #endregion // Public Instance Methods
4566 #region WM methods
4568 private void WmDestroy (ref Message m) {
4569 OnHandleDestroyed(EventArgs.Empty);
4570 #if DebugRecreate
4571 IntPtr handle = window.Handle;
4572 #endif
4573 window.InvalidateHandle();
4575 if (is_recreating) {
4576 #if DebugRecreate
4577 Console.WriteLine ("Creating handle for {0:X}", handle.ToInt32());
4578 #endif
4579 CreateHandle();
4580 #if DebugRecreate
4581 Console.WriteLine (" + new handle = {0:X}", Handle.ToInt32());
4582 #endif
4583 is_recreating = false;
4587 private void WmWindowPosChanged (ref Message m) {
4588 if (Visible) {
4589 Rectangle save_bounds = explicit_bounds;
4590 UpdateBounds();
4591 explicit_bounds = save_bounds;
4592 if (GetStyle(ControlStyles.ResizeRedraw)) {
4593 Invalidate();
4599 // Nice description of what should happen when handling WM_PAINT
4600 // can be found here: http://pluralsight.com/wiki/default.aspx/Craig/FlickerFreeControlDrawing.html
4601 // and here http://msdn.microsoft.com/msdnmag/issues/06/03/WindowsFormsPerformance/
4602 private void WmPaint (ref Message m) {
4603 PaintEventArgs paint_event;
4605 paint_event = XplatUI.PaintEventStart(Handle, true);
4607 if (paint_event == null) {
4608 return;
4610 DoubleBuffer current_buffer = null;
4611 if (UseDoubleBuffering) {
4612 current_buffer = GetBackBuffer ();
4613 if (!current_buffer.InvalidRegion.IsVisible (paint_event.ClipRectangle)) {
4614 // Just blit the previous image
4615 current_buffer.Blit (paint_event);
4616 XplatUI.PaintEventEnd (Handle, true);
4617 return;
4619 current_buffer.Start (paint_event);
4622 if (!GetStyle(ControlStyles.Opaque)) {
4623 OnPaintBackground(paint_event);
4626 // Button-derived controls choose to ignore their Opaque style, give them a chance to draw their background anyways
4627 OnPaintBackgroundInternal(paint_event);
4629 OnPaintInternal(paint_event);
4630 if (!paint_event.Handled) {
4631 OnPaint(paint_event);
4634 if (current_buffer != null) {
4635 current_buffer.End (paint_event);
4639 XplatUI.PaintEventEnd(Handle, true);
4643 private void WmEraseBackground (ref Message m) {
4644 // The DefWndProc will never have to handle this, we always paint the background in managed code
4645 // In theory this code would look at ControlStyles.AllPaintingInWmPaint and and call OnPaintBackground
4646 // here but it just makes things more complicated...
4647 m.Result = (IntPtr)1;
4650 private void WmLButtonUp (ref Message m) {
4651 MouseEventArgs me;
4653 me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Left,
4654 mouse_clicks,
4655 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4658 HandleClick(mouse_clicks, me);
4659 OnMouseUp (me);
4661 if (InternalCapture) {
4662 InternalCapture = false;
4665 if (mouse_clicks > 1) {
4666 mouse_clicks = 1;
4670 private void WmLButtonDown (ref Message m) {
4671 if (CanSelect) {
4672 Select (true, true);
4674 InternalCapture = true;
4675 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4676 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4677 0));
4680 private void WmLButtonDblClick (ref Message m) {
4681 InternalCapture = true;
4682 mouse_clicks++;
4683 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4684 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4685 0));
4688 private void WmMButtonUp (ref Message m) {
4689 MouseEventArgs me;
4691 me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Middle,
4692 mouse_clicks,
4693 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4696 HandleClick(mouse_clicks, me);
4697 OnMouseUp (me);
4698 if (InternalCapture) {
4699 InternalCapture = false;
4701 if (mouse_clicks > 1) {
4702 mouse_clicks = 1;
4706 private void WmMButtonDown (ref Message m) {
4707 InternalCapture = true;
4708 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4709 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4710 0));
4713 private void WmMButtonDblClick (ref Message m) {
4714 InternalCapture = true;
4715 mouse_clicks++;
4716 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4717 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4718 0));
4721 private void WmRButtonUp (ref Message m) {
4722 MouseEventArgs me;
4723 Point pt;
4725 pt = new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()));
4726 pt = PointToScreen(pt);
4728 XplatUI.SendMessage(m.HWnd, Msg.WM_CONTEXTMENU, m.HWnd, (IntPtr)(pt.X + (pt.Y << 16)));
4730 me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Right,
4731 mouse_clicks,
4732 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4735 HandleClick(mouse_clicks, me);
4736 OnMouseUp (me);
4738 if (InternalCapture) {
4739 InternalCapture = false;
4742 if (mouse_clicks > 1) {
4743 mouse_clicks = 1;
4747 private void WmRButtonDown (ref Message m) {
4748 InternalCapture = true;
4749 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4750 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4751 0));
4754 private void WmRButtonDblClick (ref Message m) {
4755 InternalCapture = true;
4756 mouse_clicks++;
4757 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4758 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4759 0));
4762 private void WmContextMenu (ref Message m) {
4763 if (context_menu != null) {
4764 Point pt;
4766 pt = new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()));
4768 if (pt.X == -1 || pt.Y == -1) {
4769 pt.X = (this.Width / 2) + this.Left;
4770 pt.Y = (this.Height / 2) + this.Top;
4771 pt = this.PointToScreen (pt);
4774 context_menu.Show (this, PointToClient (pt));
4775 return;
4778 #if NET_2_0
4779 // If there isn't a regular context menu, show the Strip version
4780 if (context_menu == null && context_menu_strip != null) {
4781 Point pt;
4783 pt = new Point (LowOrder ((int)m.LParam.ToInt32 ()), HighOrder ((int)m.LParam.ToInt32 ()));
4785 if (pt.X == -1 || pt.Y == -1) {
4786 pt.X = (this.Width / 2) + this.Left;
4787 pt.Y = (this.Height /2) + this.Top;
4788 pt = this.PointToScreen (pt);
4791 context_menu_strip.Show (this, PointToClient (pt));
4792 return;
4794 #endif
4795 DefWndProc(ref m);
4798 private void WmCreate (ref Message m) {
4799 OnHandleCreated(EventArgs.Empty);
4802 private void WmMouseWheel (ref Message m) {
4803 DefWndProc(ref m);
4804 OnMouseWheel (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4805 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4806 HighOrder(m.WParam.ToInt32())));
4810 private void WmMouseMove (ref Message m) {
4811 OnMouseMove (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4812 mouse_clicks,
4813 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4814 0));
4817 private void WmMouseEnter (ref Message m) {
4818 if (is_entered) {
4819 return;
4821 is_entered = true;
4822 OnMouseEnter(EventArgs.Empty);
4825 private void WmMouseLeave (ref Message m) {
4826 is_entered=false;
4827 OnMouseLeave(EventArgs.Empty);
4830 private void WmMouseHover (ref Message m) {
4831 OnMouseHover(EventArgs.Empty);
4834 private void WmShowWindow (ref Message m) {
4835 if (m.WParam.ToInt32() != 0) {
4836 /* if we're being shown, make sure our child controls all have their handles created */
4837 Control [] controls = child_controls.GetAllControls ();
4838 for (int i=0; i<controls.Length; i++) {
4839 if (controls [i].is_visible) {
4840 controls [i].CreateControl ();
4841 XplatUI.SetParent(controls[i].Handle, window.Handle);
4845 else {
4846 if (parent != null && Focused) {
4847 Control container;
4849 // Need to start at parent, GetContainerControl might return ourselves if we're a container
4850 container = (Control)parent.GetContainerControl();
4851 if (container != null) {
4852 container.SelectNextControl(this, true, true, true, true);
4857 if (is_toplevel) /* XXX make sure this works for mdi forms */
4858 OnVisibleChanged(EventArgs.Empty);
4861 private void WmSysKeyUp (ref Message m) {
4862 if (ProcessKeyMessage(ref m)) {
4863 m.Result = IntPtr.Zero;
4864 return;
4867 if ((m.WParam.ToInt32() & (int)Keys.KeyCode) == (int)Keys.Menu) {
4868 Form form;
4870 form = FindForm();
4871 if (form != null && form.ActiveMenu != null) {
4872 form.ActiveMenu.ProcessCmdKey(ref m, (Keys)m.WParam.ToInt32());
4876 DefWndProc (ref m);
4879 private void WmKeys (ref Message m) {
4880 if (ProcessKeyMessage(ref m)) {
4881 m.Result = IntPtr.Zero;
4882 return;
4884 DefWndProc (ref m);
4887 private void WmHelp (ref Message m) {
4888 Point mouse_pos;
4889 if (m.LParam != IntPtr.Zero) {
4890 HELPINFO hi;
4892 hi = new HELPINFO();
4894 hi = (HELPINFO) Marshal.PtrToStructure (m.LParam, typeof (HELPINFO));
4895 mouse_pos = new Point(hi.MousePos.x, hi.MousePos.y);
4896 } else {
4897 mouse_pos = Control.MousePosition;
4899 OnHelpRequested(new HelpEventArgs(mouse_pos));
4900 m.Result = (IntPtr)1;
4903 private void WmKillFocus (ref Message m) {
4904 this.has_focus = false;
4905 OnLostFocus (EventArgs.Empty);
4908 private void WmSetFocus (ref Message m) {
4909 if (!has_focus) {
4910 this.has_focus = true;
4911 OnGotFocus (EventArgs.Empty);
4915 private void WmSysColorChange (ref Message m) {
4916 ThemeEngine.Current.ResetDefaults();
4917 OnSystemColorsChanged(EventArgs.Empty);
4920 private void WmSetCursor (ref Message m) {
4921 if ((cursor == null) || ((HitTest)(m.LParam.ToInt32() & 0xffff) != HitTest.HTCLIENT)) {
4922 DefWndProc(ref m);
4923 return;
4926 XplatUI.SetCursor(window.Handle, cursor.handle);
4927 m.Result = (IntPtr)1;
4930 private void WmCaptureChanged (ref Message m) {
4931 is_captured = false;
4932 OnMouseCaptureChanged (EventArgs.Empty);
4933 m.Result = (IntPtr) 0;
4937 #endregion
4939 #region OnXXX methods
4940 #if NET_2_0
4941 protected virtual void OnAutoSizeChanged (EventArgs e)
4943 EventHandler eh = (EventHandler)(Events[AutoSizeChangedEvent]);
4944 if (eh != null)
4945 eh (this, e);
4947 #endif
4949 [EditorBrowsable (EditorBrowsableState.Advanced)]
4950 protected virtual void OnBackColorChanged(EventArgs e) {
4951 EventHandler eh = (EventHandler)(Events [BackColorChangedEvent]);
4952 if (eh != null)
4953 eh (this, e);
4954 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackColorChanged(e);
4957 [EditorBrowsable(EditorBrowsableState.Advanced)]
4958 protected virtual void OnBackgroundImageChanged(EventArgs e) {
4959 EventHandler eh = (EventHandler)(Events [BackgroundImageChangedEvent]);
4960 if (eh != null)
4961 eh (this, e);
4962 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackgroundImageChanged(e);
4965 #if NET_2_0
4966 [EditorBrowsable (EditorBrowsableState.Advanced)]
4967 protected virtual void OnBackgroundImageLayoutChanged (EventArgs e)
4969 EventHandler eh = (EventHandler)(Events[BackgroundImageLayoutChangedEvent]);
4970 if (eh != null)
4971 eh (this, e);
4973 #endif
4975 [EditorBrowsable(EditorBrowsableState.Advanced)]
4976 protected virtual void OnBindingContextChanged(EventArgs e) {
4977 CheckDataBindings ();
4978 EventHandler eh = (EventHandler)(Events [BindingContextChangedEvent]);
4979 if (eh != null)
4980 eh (this, e);
4981 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBindingContextChanged(e);
4984 [EditorBrowsable(EditorBrowsableState.Advanced)]
4985 protected virtual void OnCausesValidationChanged(EventArgs e) {
4986 EventHandler eh = (EventHandler)(Events [CausesValidationChangedEvent]);
4987 if (eh != null)
4988 eh (this, e);
4991 [EditorBrowsable(EditorBrowsableState.Advanced)]
4992 protected virtual void OnChangeUICues(UICuesEventArgs e) {
4993 UICuesEventHandler eh = (UICuesEventHandler)(Events [ChangeUICuesEvent]);
4994 if (eh != null)
4995 eh (this, e);
4998 [EditorBrowsable(EditorBrowsableState.Advanced)]
4999 protected virtual void OnClick(EventArgs e) {
5000 EventHandler eh = (EventHandler)(Events [ClickEvent]);
5001 if (eh != null)
5002 eh (this, e);
5005 #if NET_2_0
5006 [EditorBrowsable (EditorBrowsableState.Advanced)]
5007 protected virtual void OnClientSizeChanged (EventArgs e)
5009 EventHandler eh = (EventHandler)(Events[ClientSizeChangedEvent]);
5010 if (eh != null)
5011 eh (this, e);
5013 #endif
5015 [EditorBrowsable(EditorBrowsableState.Advanced)]
5016 protected virtual void OnContextMenuChanged(EventArgs e) {
5017 EventHandler eh = (EventHandler)(Events [ContextMenuChangedEvent]);
5018 if (eh != null)
5019 eh (this, e);
5022 #if NET_2_0
5023 [EditorBrowsable (EditorBrowsableState.Advanced)]
5024 protected virtual void OnContextMenuStripChanged (EventArgs e) {
5025 EventHandler eh = (EventHandler)(Events [ContextMenuStripChangedEvent]);
5026 if (eh != null)
5027 eh (this, e);
5029 #endif
5031 [EditorBrowsable(EditorBrowsableState.Advanced)]
5032 protected virtual void OnControlAdded(ControlEventArgs e) {
5033 ControlEventHandler eh = (ControlEventHandler)(Events [ControlAddedEvent]);
5034 if (eh != null)
5035 eh (this, e);
5038 [EditorBrowsable(EditorBrowsableState.Advanced)]
5039 protected virtual void OnControlRemoved(ControlEventArgs e) {
5040 ControlEventHandler eh = (ControlEventHandler)(Events [ControlRemovedEvent]);
5041 if (eh != null)
5042 eh (this, e);
5045 [EditorBrowsable(EditorBrowsableState.Advanced)]
5046 protected virtual void OnCreateControl() {
5047 // Override me!
5050 [EditorBrowsable(EditorBrowsableState.Advanced)]
5051 protected virtual void OnCursorChanged(EventArgs e) {
5052 EventHandler eh = (EventHandler)(Events [CursorChangedEvent]);
5053 if (eh != null)
5054 eh (this, e);
5057 [EditorBrowsable(EditorBrowsableState.Advanced)]
5058 protected virtual void OnDockChanged(EventArgs e) {
5059 EventHandler eh = (EventHandler)(Events [DockChangedEvent]);
5060 if (eh != null)
5061 eh (this, e);
5064 [EditorBrowsable(EditorBrowsableState.Advanced)]
5065 protected virtual void OnDoubleClick(EventArgs e) {
5066 EventHandler eh = (EventHandler)(Events [DoubleClickEvent]);
5067 if (eh != null)
5068 eh (this, e);
5071 [EditorBrowsable(EditorBrowsableState.Advanced)]
5072 protected virtual void OnDragDrop(DragEventArgs drgevent) {
5073 DragEventHandler eh = (DragEventHandler)(Events [DragDropEvent]);
5074 if (eh != null)
5075 eh (this, drgevent);
5078 [EditorBrowsable(EditorBrowsableState.Advanced)]
5079 protected virtual void OnDragEnter(DragEventArgs drgevent) {
5080 DragEventHandler eh = (DragEventHandler)(Events [DragEnterEvent]);
5081 if (eh != null)
5082 eh (this, drgevent);
5085 [EditorBrowsable(EditorBrowsableState.Advanced)]
5086 protected virtual void OnDragLeave(EventArgs e) {
5087 EventHandler eh = (EventHandler)(Events [DragLeaveEvent]);
5088 if (eh != null)
5089 eh (this, e);
5092 [EditorBrowsable(EditorBrowsableState.Advanced)]
5093 protected virtual void OnDragOver(DragEventArgs drgevent) {
5094 DragEventHandler eh = (DragEventHandler)(Events [DragOverEvent]);
5095 if (eh != null)
5096 eh (this, drgevent);
5099 [EditorBrowsable(EditorBrowsableState.Advanced)]
5100 protected virtual void OnEnabledChanged(EventArgs e) {
5101 if (IsHandleCreated) {
5102 if (this is Form) {
5103 if (((Form)this).context == null) {
5104 XplatUI.EnableWindow(window.Handle, Enabled);
5106 } else {
5107 XplatUI.EnableWindow(window.Handle, Enabled);
5109 Refresh();
5112 EventHandler eh = (EventHandler)(Events [EnabledChangedEvent]);
5113 if (eh != null)
5114 eh (this, e);
5116 for (int i=0; i<child_controls.Count; i++) {
5117 child_controls[i].OnParentEnabledChanged(e);
5121 [EditorBrowsable(EditorBrowsableState.Advanced)]
5122 protected virtual void OnEnter(EventArgs e) {
5123 EventHandler eh = (EventHandler)(Events [EnterEvent]);
5124 if (eh != null)
5125 eh (this, e);
5128 [EditorBrowsable(EditorBrowsableState.Advanced)]
5129 protected virtual void OnFontChanged(EventArgs e) {
5130 EventHandler eh = (EventHandler)(Events [FontChangedEvent]);
5131 if (eh != null)
5132 eh (this, e);
5133 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentFontChanged(e);
5136 [EditorBrowsable(EditorBrowsableState.Advanced)]
5137 protected virtual void OnForeColorChanged(EventArgs e) {
5138 EventHandler eh = (EventHandler)(Events [ForeColorChangedEvent]);
5139 if (eh != null)
5140 eh (this, e);
5141 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentForeColorChanged(e);
5144 [EditorBrowsable(EditorBrowsableState.Advanced)]
5145 protected virtual void OnGiveFeedback(GiveFeedbackEventArgs gfbevent) {
5146 GiveFeedbackEventHandler eh = (GiveFeedbackEventHandler)(Events [GiveFeedbackEvent]);
5147 if (eh != null)
5148 eh (this, gfbevent);
5151 [EditorBrowsable(EditorBrowsableState.Advanced)]
5152 protected virtual void OnGotFocus(EventArgs e) {
5153 EventHandler eh = (EventHandler)(Events [GotFocusEvent]);
5154 if (eh != null)
5155 eh (this, e);
5158 [EditorBrowsable(EditorBrowsableState.Advanced)]
5159 protected virtual void OnHandleCreated(EventArgs e) {
5160 EventHandler eh = (EventHandler)(Events [HandleCreatedEvent]);
5161 if (eh != null)
5162 eh (this, e);
5165 [EditorBrowsable(EditorBrowsableState.Advanced)]
5166 protected virtual void OnHandleDestroyed(EventArgs e) {
5167 EventHandler eh = (EventHandler)(Events [HandleDestroyedEvent]);
5168 if (eh != null)
5169 eh (this, e);
5172 internal void RaiseHelpRequested (HelpEventArgs hevent) {
5173 OnHelpRequested (hevent);
5176 [EditorBrowsable(EditorBrowsableState.Advanced)]
5177 protected virtual void OnHelpRequested(HelpEventArgs hevent) {
5178 HelpEventHandler eh = (HelpEventHandler)(Events [HelpRequestedEvent]);
5179 if (eh != null)
5180 eh (this, hevent);
5183 protected virtual void OnImeModeChanged(EventArgs e) {
5184 EventHandler eh = (EventHandler)(Events [ImeModeChangedEvent]);
5185 if (eh != null)
5186 eh (this, e);
5189 [EditorBrowsable(EditorBrowsableState.Advanced)]
5190 protected virtual void OnInvalidated(InvalidateEventArgs e) {
5191 if (UseDoubleBuffering) {
5192 // should this block be here? seems like it
5193 // would be more at home in
5194 // NotifyInvalidated..
5195 if (e.InvalidRect == ClientRectangle) {
5196 InvalidateBackBuffer ();
5197 } else if (backbuffer != null){
5198 // we need this Inflate call here so
5199 // that the border of the rectangle is
5200 // considered Visible (the
5201 // invalid_region.IsVisible call) in
5202 // the WM_PAINT handling below.
5203 Rectangle r = Rectangle.Inflate(e.InvalidRect, 1,1);
5204 backbuffer.InvalidRegion.Union (r);
5208 InvalidateEventHandler eh = (InvalidateEventHandler)(Events [InvalidatedEvent]);
5209 if (eh != null)
5210 eh (this, e);
5213 [EditorBrowsable(EditorBrowsableState.Advanced)]
5214 protected virtual void OnKeyDown(KeyEventArgs e) {
5215 KeyEventHandler eh = (KeyEventHandler)(Events [KeyDownEvent]);
5216 if (eh != null)
5217 eh (this, e);
5220 [EditorBrowsable(EditorBrowsableState.Advanced)]
5221 protected virtual void OnKeyPress(KeyPressEventArgs e) {
5222 KeyPressEventHandler eh = (KeyPressEventHandler)(Events [KeyPressEvent]);
5223 if (eh != null)
5224 eh (this, e);
5227 [EditorBrowsable(EditorBrowsableState.Advanced)]
5228 protected virtual void OnKeyUp(KeyEventArgs e) {
5229 KeyEventHandler eh = (KeyEventHandler)(Events [KeyUpEvent]);
5230 if (eh != null)
5231 eh (this, e);
5234 [EditorBrowsable(EditorBrowsableState.Advanced)]
5235 protected virtual void OnLayout(LayoutEventArgs levent) {
5236 LayoutEventHandler eh = (LayoutEventHandler)(Events [LayoutEvent]);
5237 if (eh != null)
5238 eh (this, levent);
5240 LayoutEngine.Layout (this, levent);
5243 [EditorBrowsable(EditorBrowsableState.Advanced)]
5244 protected virtual void OnLeave(EventArgs e) {
5245 EventHandler eh = (EventHandler)(Events [LeaveEvent]);
5246 if (eh != null)
5247 eh (this, e);
5250 [EditorBrowsable(EditorBrowsableState.Advanced)]
5251 protected virtual void OnLocationChanged(EventArgs e) {
5252 OnMove(e);
5253 EventHandler eh = (EventHandler)(Events [LocationChangedEvent]);
5254 if (eh != null)
5255 eh (this, e);
5258 [EditorBrowsable(EditorBrowsableState.Advanced)]
5259 protected virtual void OnLostFocus(EventArgs e) {
5260 EventHandler eh = (EventHandler)(Events [LostFocusEvent]);
5261 if (eh != null)
5262 eh (this, e);
5265 #if NET_2_0
5266 protected virtual void OnMarginChanged (EventArgs e)
5268 EventHandler eh = (EventHandler)(Events[MarginChangedEvent]);
5269 if (eh != null)
5270 eh (this, e);
5272 #endif
5273 [EditorBrowsable (EditorBrowsableState.Advanced)]
5274 #if NET_2_0
5275 protected virtual void OnMouseCaptureChanged (EventArgs e)
5276 #else
5277 internal virtual void OnMouseCaptureChanged (EventArgs e)
5278 #endif
5280 EventHandler eh = (EventHandler)(Events [MouseCaptureChangedEvent]);
5281 if (eh != null)
5282 eh (this, e);
5285 #if NET_2_0
5286 [EditorBrowsable (EditorBrowsableState.Advanced)]
5287 protected virtual void OnMouseClick (MouseEventArgs e)
5289 MouseEventHandler eh = (MouseEventHandler)(Events [MouseClickEvent]);
5290 if (eh != null)
5291 eh (this, e);
5294 [EditorBrowsable (EditorBrowsableState.Advanced)]
5295 protected virtual void OnMouseDoubleClick (MouseEventArgs e)
5297 MouseEventHandler eh = (MouseEventHandler)(Events [MouseDoubleClickEvent]);
5298 if (eh != null)
5299 eh (this, e);
5301 #endif
5303 [EditorBrowsable(EditorBrowsableState.Advanced)]
5304 protected virtual void OnMouseDown(MouseEventArgs e) {
5305 MouseEventHandler eh = (MouseEventHandler)(Events [MouseDownEvent]);
5306 if (eh != null)
5307 eh (this, e);
5310 [EditorBrowsable(EditorBrowsableState.Advanced)]
5311 protected virtual void OnMouseEnter(EventArgs e) {
5312 EventHandler eh = (EventHandler)(Events [MouseEnterEvent]);
5313 if (eh != null)
5314 eh (this, e);
5317 [EditorBrowsable(EditorBrowsableState.Advanced)]
5318 protected virtual void OnMouseHover(EventArgs e) {
5319 EventHandler eh = (EventHandler)(Events [MouseHoverEvent]);
5320 if (eh != null)
5321 eh (this, e);
5324 [EditorBrowsable(EditorBrowsableState.Advanced)]
5325 protected virtual void OnMouseLeave(EventArgs e) {
5326 EventHandler eh = (EventHandler)(Events [MouseLeaveEvent]);
5327 if (eh != null)
5328 eh (this, e);
5331 [EditorBrowsable(EditorBrowsableState.Advanced)]
5332 protected virtual void OnMouseMove(MouseEventArgs e) {
5333 MouseEventHandler eh = (MouseEventHandler)(Events [MouseMoveEvent]);
5334 if (eh != null)
5335 eh (this, e);
5338 [EditorBrowsable(EditorBrowsableState.Advanced)]
5339 protected virtual void OnMouseUp(MouseEventArgs e) {
5340 MouseEventHandler eh = (MouseEventHandler)(Events [MouseUpEvent]);
5341 if (eh != null)
5342 eh (this, e);
5345 [EditorBrowsable(EditorBrowsableState.Advanced)]
5346 protected virtual void OnMouseWheel(MouseEventArgs e) {
5347 MouseEventHandler eh = (MouseEventHandler)(Events [MouseWheelEvent]);
5348 if (eh != null)
5349 eh (this, e);
5352 [EditorBrowsable(EditorBrowsableState.Advanced)]
5353 protected virtual void OnMove(EventArgs e) {
5354 EventHandler eh = (EventHandler)(Events [MoveEvent]);
5355 if (eh != null)
5356 eh (this, e);
5359 [EditorBrowsable(EditorBrowsableState.Advanced)]
5360 protected virtual void OnNotifyMessage(Message m) {
5361 // Override me!
5364 #if NET_2_0
5365 protected virtual void OnPaddingChanged (EventArgs e) {
5366 EventHandler eh = (EventHandler) (Events [PaddingChangedEvent]);
5367 if (eh != null)
5368 eh (this, e);
5370 #endif
5372 [EditorBrowsable(EditorBrowsableState.Advanced)]
5373 protected virtual void OnPaint(PaintEventArgs e) {
5374 PaintEventHandler eh = (PaintEventHandler)(Events [PaintEvent]);
5375 if (eh != null)
5376 eh (this, e);
5379 internal virtual void OnPaintBackgroundInternal(PaintEventArgs e) {
5380 // Override me
5383 internal virtual void OnPaintInternal(PaintEventArgs e) {
5384 // Override me
5387 [EditorBrowsable(EditorBrowsableState.Advanced)]
5388 protected virtual void OnPaintBackground(PaintEventArgs pevent) {
5389 PaintControlBackground (pevent);
5392 [EditorBrowsable(EditorBrowsableState.Advanced)]
5393 protected virtual void OnParentBackColorChanged(EventArgs e) {
5394 if (background_color.IsEmpty && background_image==null) {
5395 Invalidate();
5396 OnBackColorChanged(e);
5400 [EditorBrowsable(EditorBrowsableState.Advanced)]
5401 protected virtual void OnParentBackgroundImageChanged(EventArgs e) {
5402 Invalidate();
5403 OnBackgroundImageChanged(e);
5406 [EditorBrowsable(EditorBrowsableState.Advanced)]
5407 protected virtual void OnParentBindingContextChanged(EventArgs e) {
5408 if (binding_context==null) {
5409 binding_context=Parent.binding_context;
5410 OnBindingContextChanged(e);
5414 [EditorBrowsable(EditorBrowsableState.Advanced)]
5415 protected virtual void OnParentChanged(EventArgs e) {
5416 EventHandler eh = (EventHandler)(Events [ParentChangedEvent]);
5417 if (eh != null)
5418 eh (this, e);
5421 [EditorBrowsable(EditorBrowsableState.Advanced)]
5422 protected virtual void OnParentEnabledChanged(EventArgs e) {
5423 if (is_enabled) {
5424 OnEnabledChanged(e);
5428 [EditorBrowsable(EditorBrowsableState.Advanced)]
5429 protected virtual void OnParentFontChanged(EventArgs e) {
5430 if (font==null) {
5431 Invalidate();
5432 OnFontChanged(e);
5436 [EditorBrowsable(EditorBrowsableState.Advanced)]
5437 protected virtual void OnParentForeColorChanged(EventArgs e) {
5438 if (foreground_color.IsEmpty) {
5439 Invalidate();
5440 OnForeColorChanged(e);
5444 [EditorBrowsable(EditorBrowsableState.Advanced)]
5445 protected virtual void OnParentRightToLeftChanged(EventArgs e) {
5446 if (right_to_left==RightToLeft.Inherit) {
5447 Invalidate();
5448 OnRightToLeftChanged(e);
5452 [EditorBrowsable(EditorBrowsableState.Advanced)]
5453 protected virtual void OnParentVisibleChanged(EventArgs e) {
5454 if (is_visible) {
5455 OnVisibleChanged(e);
5459 [EditorBrowsable(EditorBrowsableState.Advanced)]
5460 protected virtual void OnQueryContinueDrag(QueryContinueDragEventArgs e) {
5461 QueryContinueDragEventHandler eh = (QueryContinueDragEventHandler)(Events [QueryContinueDragEvent]);
5462 if (eh != null)
5463 eh (this, e);
5466 #if NET_2_0
5467 [EditorBrowsable (EditorBrowsableState.Advanced)]
5468 protected virtual void OnRegionChanged (EventArgs e)
5470 EventHandler eh = (EventHandler)(Events[RegionChangedEvent]);
5471 if (eh != null)
5472 eh (this, e);
5474 #endif
5476 [EditorBrowsable(EditorBrowsableState.Advanced)]
5477 protected virtual void OnResize(EventArgs e) {
5478 PerformLayout(this, "Bounds");
5480 EventHandler eh = (EventHandler)(Events [ResizeEvent]);
5481 if (eh != null)
5482 eh (this, e);
5485 [EditorBrowsable(EditorBrowsableState.Advanced)]
5486 protected virtual void OnRightToLeftChanged(EventArgs e) {
5487 EventHandler eh = (EventHandler)(Events [RightToLeftChangedEvent]);
5488 if (eh != null)
5489 eh (this, e);
5490 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentRightToLeftChanged(e);
5493 [EditorBrowsable(EditorBrowsableState.Advanced)]
5494 protected virtual void OnSizeChanged(EventArgs e) {
5495 DisposeBackBuffer ();
5496 OnResize(e);
5497 EventHandler eh = (EventHandler)(Events [SizeChangedEvent]);
5498 if (eh != null)
5499 eh (this, e);
5502 [EditorBrowsable(EditorBrowsableState.Advanced)]
5503 protected virtual void OnStyleChanged(EventArgs e) {
5504 EventHandler eh = (EventHandler)(Events [StyleChangedEvent]);
5505 if (eh != null)
5506 eh (this, e);
5509 [EditorBrowsable(EditorBrowsableState.Advanced)]
5510 protected virtual void OnSystemColorsChanged(EventArgs e) {
5511 EventHandler eh = (EventHandler)(Events [SystemColorsChangedEvent]);
5512 if (eh != null)
5513 eh (this, e);
5516 [EditorBrowsable(EditorBrowsableState.Advanced)]
5517 protected virtual void OnTabIndexChanged(EventArgs e) {
5518 EventHandler eh = (EventHandler)(Events [TabIndexChangedEvent]);
5519 if (eh != null)
5520 eh (this, e);
5523 [EditorBrowsable(EditorBrowsableState.Advanced)]
5524 protected virtual void OnTabStopChanged(EventArgs e) {
5525 EventHandler eh = (EventHandler)(Events [TabStopChangedEvent]);
5526 if (eh != null)
5527 eh (this, e);
5530 [EditorBrowsable(EditorBrowsableState.Advanced)]
5531 protected virtual void OnTextChanged(EventArgs e) {
5532 EventHandler eh = (EventHandler)(Events [TextChangedEvent]);
5533 if (eh != null)
5534 eh (this, e);
5537 [EditorBrowsable(EditorBrowsableState.Advanced)]
5538 protected virtual void OnValidated(EventArgs e) {
5539 EventHandler eh = (EventHandler)(Events [ValidatedEvent]);
5540 if (eh != null)
5541 eh (this, e);
5544 [EditorBrowsable(EditorBrowsableState.Advanced)]
5545 protected virtual void OnValidating(System.ComponentModel.CancelEventArgs e) {
5546 CancelEventHandler eh = (CancelEventHandler)(Events [ValidatingEvent]);
5547 if (eh != null)
5548 eh (this, e);
5551 [EditorBrowsable(EditorBrowsableState.Advanced)]
5552 protected virtual void OnVisibleChanged(EventArgs e) {
5553 EventHandler eh = (EventHandler)(Events [VisibleChangedEvent]);
5554 if (eh != null)
5555 eh (this, e);
5557 // We need to tell our kids
5558 for (int i=0; i<child_controls.Count; i++) {
5559 if (child_controls[i].Visible) {
5560 child_controls[i].OnParentVisibleChanged(e);
5564 #endregion // OnXXX methods
5566 #region Events
5567 #if NET_2_0
5568 static object AutoSizeChangedEvent = new object ();
5569 #endif
5570 static object BackColorChangedEvent = new object ();
5571 static object BackgroundImageChangedEvent = new object ();
5572 #if NET_2_0
5573 static object BackgroundImageLayoutChangedEvent = new object ();
5574 #endif
5575 static object BindingContextChangedEvent = new object ();
5576 static object CausesValidationChangedEvent = new object ();
5577 static object ChangeUICuesEvent = new object ();
5578 static object ClickEvent = new object ();
5579 #if NET_2_0
5580 static object ClientSizeChangedEvent = new object ();
5581 #endif
5582 static object ContextMenuChangedEvent = new object ();
5583 #if NET_2_0
5584 static object ContextMenuStripChangedEvent = new object ();
5585 #endif
5586 static object ControlAddedEvent = new object ();
5587 static object ControlRemovedEvent = new object ();
5588 static object CursorChangedEvent = new object ();
5589 static object DockChangedEvent = new object ();
5590 static object DoubleClickEvent = new object ();
5591 static object DragDropEvent = new object ();
5592 static object DragEnterEvent = new object ();
5593 static object DragLeaveEvent = new object ();
5594 static object DragOverEvent = new object ();
5595 static object EnabledChangedEvent = new object ();
5596 static object EnterEvent = new object ();
5597 static object FontChangedEvent = new object ();
5598 static object ForeColorChangedEvent = new object ();
5599 static object GiveFeedbackEvent = new object ();
5600 static object GotFocusEvent = new object ();
5601 static object HandleCreatedEvent = new object ();
5602 static object HandleDestroyedEvent = new object ();
5603 static object HelpRequestedEvent = new object ();
5604 static object ImeModeChangedEvent = new object ();
5605 static object InvalidatedEvent = new object ();
5606 static object KeyDownEvent = new object ();
5607 static object KeyPressEvent = new object ();
5608 static object KeyUpEvent = new object ();
5609 static object LayoutEvent = new object ();
5610 static object LeaveEvent = new object ();
5611 static object LocationChangedEvent = new object ();
5612 static object LostFocusEvent = new object ();
5613 #if NET_2_0
5614 static object MarginChangedEvent = new object ();
5615 #endif
5616 static object MouseCaptureChangedEvent = new object ();
5617 #if NET_2_0
5618 static object MouseClickEvent = new object ();
5619 static object MouseDoubleClickEvent = new object ();
5620 #endif
5621 static object MouseDownEvent = new object ();
5622 static object MouseEnterEvent = new object ();
5623 static object MouseHoverEvent = new object ();
5624 static object MouseLeaveEvent = new object ();
5625 static object MouseMoveEvent = new object ();
5626 static object MouseUpEvent = new object ();
5627 static object MouseWheelEvent = new object ();
5628 static object MoveEvent = new object ();
5629 #if NET_2_0
5630 static object PaddingChangedEvent = new object ();
5631 #endif
5632 static object PaintEvent = new object ();
5633 static object ParentChangedEvent = new object ();
5634 #if NET_2_0
5635 static object PreviewKeyDownEvent = new object ();
5636 #endif
5637 static object QueryAccessibilityHelpEvent = new object ();
5638 static object QueryContinueDragEvent = new object ();
5639 #if NET_2_0
5640 static object RegionChangedEvent = new object ();
5641 #endif
5642 static object ResizeEvent = new object ();
5643 static object RightToLeftChangedEvent = new object ();
5644 static object SizeChangedEvent = new object ();
5645 static object StyleChangedEvent = new object ();
5646 static object SystemColorsChangedEvent = new object ();
5647 static object TabIndexChangedEvent = new object ();
5648 static object TabStopChangedEvent = new object ();
5649 static object TextChangedEvent = new object ();
5650 static object ValidatedEvent = new object ();
5651 static object ValidatingEvent = new object ();
5652 static object VisibleChangedEvent = new object ();
5654 #if NET_2_0
5655 [Browsable (false)]
5656 [EditorBrowsable (EditorBrowsableState.Never)]
5657 public event EventHandler AutoSizeChanged {
5658 add { Events.AddHandler (AutoSizeChangedEvent, value);}
5659 remove {Events.RemoveHandler (AutoSizeChangedEvent, value);}
5661 #endif
5662 public event EventHandler BackColorChanged {
5663 add { Events.AddHandler (BackColorChangedEvent, value); }
5664 remove { Events.RemoveHandler (BackColorChangedEvent, value); }
5667 public event EventHandler BackgroundImageChanged {
5668 add { Events.AddHandler (BackgroundImageChangedEvent, value); }
5669 remove { Events.RemoveHandler (BackgroundImageChangedEvent, value); }
5672 #if NET_2_0
5673 public event EventHandler BackgroundImageLayoutChanged {
5674 add {Events.AddHandler (BackgroundImageLayoutChangedEvent, value);}
5675 remove {Events.RemoveHandler (BackgroundImageLayoutChangedEvent, value);}
5677 #endif
5679 public event EventHandler BindingContextChanged {
5680 add { Events.AddHandler (BindingContextChangedEvent, value); }
5681 remove { Events.RemoveHandler (BindingContextChangedEvent, value); }
5684 public event EventHandler CausesValidationChanged {
5685 add { Events.AddHandler (CausesValidationChangedEvent, value); }
5686 remove { Events.RemoveHandler (CausesValidationChangedEvent, value); }
5689 public event UICuesEventHandler ChangeUICues {
5690 add { Events.AddHandler (ChangeUICuesEvent, value); }
5691 remove { Events.RemoveHandler (ChangeUICuesEvent, value); }
5694 public event EventHandler Click {
5695 add { Events.AddHandler (ClickEvent, value); }
5696 remove { Events.RemoveHandler (ClickEvent, value); }
5699 #if NET_2_0
5700 public event EventHandler ClientSizeChanged {
5701 add {Events.AddHandler (ClientSizeChangedEvent, value);}
5702 remove {Events.RemoveHandler (ClientSizeChangedEvent, value);}
5704 #endif
5706 #if NET_2_0
5707 [Browsable (false)]
5708 #endif
5709 public event EventHandler ContextMenuChanged {
5710 add { Events.AddHandler (ContextMenuChangedEvent, value); }
5711 remove { Events.RemoveHandler (ContextMenuChangedEvent, value); }
5714 #if NET_2_0
5715 public event EventHandler ContextMenuStripChanged {
5716 add { Events.AddHandler (ContextMenuStripChangedEvent, value); }
5717 remove { Events.RemoveHandler (ContextMenuStripChangedEvent, value);}
5719 #endif
5722 [EditorBrowsable(EditorBrowsableState.Advanced)]
5723 #if NET_2_0
5724 [Browsable(true)]
5725 #else
5726 [Browsable(false)]
5727 #endif
5728 public event ControlEventHandler ControlAdded {
5729 add { Events.AddHandler (ControlAddedEvent, value); }
5730 remove { Events.RemoveHandler (ControlAddedEvent, value); }
5733 [EditorBrowsable(EditorBrowsableState.Advanced)]
5734 #if NET_2_0
5735 [Browsable(true)]
5736 #else
5737 [Browsable(false)]
5738 #endif
5739 public event ControlEventHandler ControlRemoved {
5740 add { Events.AddHandler (ControlRemovedEvent, value); }
5741 remove { Events.RemoveHandler (ControlRemovedEvent, value); }
5744 [MWFDescription("Fired when the cursor for the control has been changed"), MWFCategory("PropertyChanged")]
5745 public event EventHandler CursorChanged {
5746 add { Events.AddHandler (CursorChangedEvent, value); }
5747 remove { Events.RemoveHandler (CursorChangedEvent, value); }
5749 public event EventHandler DockChanged {
5750 add { Events.AddHandler (DockChangedEvent, value); }
5751 remove { Events.RemoveHandler (DockChangedEvent, value); }
5754 public event EventHandler DoubleClick {
5755 add { Events.AddHandler (DoubleClickEvent, value); }
5756 remove { Events.RemoveHandler (DoubleClickEvent, value); }
5759 public event DragEventHandler DragDrop {
5760 add { Events.AddHandler (DragDropEvent, value); }
5761 remove { Events.RemoveHandler (DragDropEvent, value); }
5764 public event DragEventHandler DragEnter {
5765 add { Events.AddHandler (DragEnterEvent, value); }
5766 remove { Events.RemoveHandler (DragEnterEvent, value); }
5769 public event EventHandler DragLeave {
5770 add { Events.AddHandler (DragLeaveEvent, value); }
5771 remove { Events.RemoveHandler (DragLeaveEvent, value); }
5774 public event DragEventHandler DragOver {
5775 add { Events.AddHandler (DragOverEvent, value); }
5776 remove { Events.RemoveHandler (DragOverEvent, value); }
5779 public event EventHandler EnabledChanged {
5780 add { Events.AddHandler (EnabledChangedEvent, value); }
5781 remove { Events.RemoveHandler (EnabledChangedEvent, value); }
5784 public event EventHandler Enter {
5785 add { Events.AddHandler (EnterEvent, value); }
5786 remove { Events.RemoveHandler (EnterEvent, value); }
5789 public event EventHandler FontChanged {
5790 add { Events.AddHandler (FontChangedEvent, value); }
5791 remove { Events.RemoveHandler (FontChangedEvent, value); }
5794 public event EventHandler ForeColorChanged {
5795 add { Events.AddHandler (ForeColorChangedEvent, value); }
5796 remove { Events.RemoveHandler (ForeColorChangedEvent, value); }
5799 public event GiveFeedbackEventHandler GiveFeedback {
5800 add { Events.AddHandler (GiveFeedbackEvent, value); }
5801 remove { Events.RemoveHandler (GiveFeedbackEvent, value); }
5804 [EditorBrowsable(EditorBrowsableState.Advanced)]
5805 [Browsable(false)]
5806 public event EventHandler GotFocus {
5807 add { Events.AddHandler (GotFocusEvent, value); }
5808 remove { Events.RemoveHandler (GotFocusEvent, value); }
5812 [EditorBrowsable(EditorBrowsableState.Advanced)]
5813 [Browsable(false)]
5814 public event EventHandler HandleCreated {
5815 add { Events.AddHandler (HandleCreatedEvent, value); }
5816 remove { Events.RemoveHandler (HandleCreatedEvent, value); }
5819 [EditorBrowsable(EditorBrowsableState.Advanced)]
5820 [Browsable(false)]
5821 public event EventHandler HandleDestroyed {
5822 add { Events.AddHandler (HandleDestroyedEvent, value); }
5823 remove { Events.RemoveHandler (HandleDestroyedEvent, value); }
5826 public event HelpEventHandler HelpRequested {
5827 add { Events.AddHandler (HelpRequestedEvent, value); }
5828 remove { Events.RemoveHandler (HelpRequestedEvent, value); }
5831 public event EventHandler ImeModeChanged {
5832 add { Events.AddHandler (ImeModeChangedEvent, value); }
5833 remove { Events.RemoveHandler (ImeModeChangedEvent, value); }
5836 [EditorBrowsable(EditorBrowsableState.Advanced)]
5837 [Browsable(false)]
5838 public event InvalidateEventHandler Invalidated {
5839 add { Events.AddHandler (InvalidatedEvent, value); }
5840 remove { Events.RemoveHandler (InvalidatedEvent, value); }
5843 public event KeyEventHandler KeyDown {
5844 add { Events.AddHandler (KeyDownEvent, value); }
5845 remove { Events.RemoveHandler (KeyDownEvent, value); }
5848 public event KeyPressEventHandler KeyPress {
5849 add { Events.AddHandler (KeyPressEvent, value); }
5850 remove { Events.RemoveHandler (KeyPressEvent, value); }
5853 public event KeyEventHandler KeyUp {
5854 add { Events.AddHandler (KeyUpEvent, value); }
5855 remove { Events.RemoveHandler (KeyUpEvent, value); }
5858 public event LayoutEventHandler Layout {
5859 add { Events.AddHandler (LayoutEvent, value); }
5860 remove { Events.RemoveHandler (LayoutEvent, value); }
5863 public event EventHandler Leave {
5864 add { Events.AddHandler (LeaveEvent, value); }
5865 remove { Events.RemoveHandler (LeaveEvent, value); }
5868 public event EventHandler LocationChanged {
5869 add { Events.AddHandler (LocationChangedEvent, value); }
5870 remove { Events.RemoveHandler (LocationChangedEvent, value); }
5873 [EditorBrowsable(EditorBrowsableState.Advanced)]
5874 [Browsable(false)]
5875 public event EventHandler LostFocus {
5876 add { Events.AddHandler (LostFocusEvent, value); }
5877 remove { Events.RemoveHandler (LostFocusEvent, value); }
5880 #if NET_2_0
5881 public event EventHandler MarginChanged {
5882 add { Events.AddHandler (MarginChangedEvent, value); }
5883 remove {Events.RemoveHandler (MarginChangedEvent, value); }
5885 #endif
5886 #if NET_2_0
5887 public event EventHandler MouseCaptureChanged {
5888 #else
5889 internal event EventHandler MouseCaptureChanged {
5890 #endif
5891 add { Events.AddHandler (MouseCaptureChangedEvent, value); }
5892 remove { Events.RemoveHandler (MouseCaptureChangedEvent, value); }
5894 #if NET_2_0
5895 public event MouseEventHandler MouseClick
5897 add { Events.AddHandler (MouseClickEvent, value); }
5898 remove { Events.RemoveHandler (MouseClickEvent, value); }
5900 public event MouseEventHandler MouseDoubleClick
5902 add { Events.AddHandler (MouseDoubleClickEvent, value); }
5903 remove { Events.RemoveHandler (MouseDoubleClickEvent, value); }
5905 #endif
5906 public event MouseEventHandler MouseDown {
5907 add { Events.AddHandler (MouseDownEvent, value); }
5908 remove { Events.RemoveHandler (MouseDownEvent, value); }
5911 public event EventHandler MouseEnter {
5912 add { Events.AddHandler (MouseEnterEvent, value); }
5913 remove { Events.RemoveHandler (MouseEnterEvent, value); }
5916 public event EventHandler MouseHover {
5917 add { Events.AddHandler (MouseHoverEvent, value); }
5918 remove { Events.RemoveHandler (MouseHoverEvent, value); }
5921 public event EventHandler MouseLeave {
5922 add { Events.AddHandler (MouseLeaveEvent, value); }
5923 remove { Events.RemoveHandler (MouseLeaveEvent, value); }
5926 public event MouseEventHandler MouseMove {
5927 add { Events.AddHandler (MouseMoveEvent, value); }
5928 remove { Events.RemoveHandler (MouseMoveEvent, value); }
5931 public event MouseEventHandler MouseUp {
5932 add { Events.AddHandler (MouseUpEvent, value); }
5933 remove { Events.RemoveHandler (MouseUpEvent, value); }
5936 [EditorBrowsable(EditorBrowsableState.Advanced)]
5937 [Browsable(false)]
5938 public event MouseEventHandler MouseWheel {
5939 add { Events.AddHandler (MouseWheelEvent, value); }
5940 remove { Events.RemoveHandler (MouseWheelEvent, value); }
5943 public event EventHandler Move {
5944 add { Events.AddHandler (MoveEvent, value); }
5945 remove { Events.RemoveHandler (MoveEvent, value); }
5947 #if NET_2_0
5948 public event EventHandler PaddingChanged
5950 add { Events.AddHandler (PaddingChangedEvent, value); }
5951 remove { Events.RemoveHandler (PaddingChangedEvent, value); }
5953 #endif
5954 public event PaintEventHandler Paint {
5955 add { Events.AddHandler (PaintEvent, value); }
5956 remove { Events.RemoveHandler (PaintEvent, value); }
5959 public event EventHandler ParentChanged {
5960 add { Events.AddHandler (ParentChangedEvent, value); }
5961 remove { Events.RemoveHandler (ParentChangedEvent, value); }
5964 #if NET_2_0
5965 public event PreviewKeyDownEventHandler PreviewKeyDown {
5966 add { Events.AddHandler (PreviewKeyDownEvent, value); }
5967 remove { Events.RemoveHandler (PreviewKeyDownEvent, value); }
5969 #endif
5971 public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp {
5972 add { Events.AddHandler (QueryAccessibilityHelpEvent, value); }
5973 remove { Events.RemoveHandler (QueryAccessibilityHelpEvent, value); }
5976 public event QueryContinueDragEventHandler QueryContinueDrag {
5977 add { Events.AddHandler (QueryContinueDragEvent, value); }
5978 remove { Events.RemoveHandler (QueryContinueDragEvent, value); }
5981 #if NET_2_0
5982 public event EventHandler RegionChanged {
5983 add { Events.AddHandler (RegionChangedEvent, value); }
5984 remove { Events.RemoveHandler (RegionChangedEvent, value); }
5986 #endif
5988 #if NET_2_0
5989 [EditorBrowsable (EditorBrowsableState.Advanced)]
5990 #endif
5991 public event EventHandler Resize {
5992 add { Events.AddHandler (ResizeEvent, value); }
5993 remove { Events.RemoveHandler (ResizeEvent, value); }
5996 public event EventHandler RightToLeftChanged {
5997 add { Events.AddHandler (RightToLeftChangedEvent, value); }
5998 remove { Events.RemoveHandler (RightToLeftChangedEvent, value); }
6001 public event EventHandler SizeChanged {
6002 add { Events.AddHandler (SizeChangedEvent, value); }
6003 remove { Events.RemoveHandler (SizeChangedEvent, value); }
6006 public event EventHandler StyleChanged {
6007 add { Events.AddHandler (StyleChangedEvent, value); }
6008 remove { Events.RemoveHandler (StyleChangedEvent, value); }
6011 public event EventHandler SystemColorsChanged {
6012 add { Events.AddHandler (SystemColorsChangedEvent, value); }
6013 remove { Events.RemoveHandler (SystemColorsChangedEvent, value); }
6016 public event EventHandler TabIndexChanged {
6017 add { Events.AddHandler (TabIndexChangedEvent, value); }
6018 remove { Events.RemoveHandler (TabIndexChangedEvent, value); }
6021 public event EventHandler TabStopChanged {
6022 add { Events.AddHandler (TabStopChangedEvent, value); }
6023 remove { Events.RemoveHandler (TabStopChangedEvent, value); }
6026 public event EventHandler TextChanged {
6027 add { Events.AddHandler (TextChangedEvent, value); }
6028 remove { Events.RemoveHandler (TextChangedEvent, value); }
6031 public event EventHandler Validated {
6032 add { Events.AddHandler (ValidatedEvent, value); }
6033 remove { Events.RemoveHandler (ValidatedEvent, value); }
6036 public event CancelEventHandler Validating {
6037 add { Events.AddHandler (ValidatingEvent, value); }
6038 remove { Events.RemoveHandler (ValidatingEvent, value); }
6041 public event EventHandler VisibleChanged {
6042 add { Events.AddHandler (VisibleChangedEvent, value); }
6043 remove { Events.RemoveHandler (VisibleChangedEvent, value); }
6046 #endregion // Events