1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 // Copyright (c) 2004-2006 Novell, Inc.
23 // Peter Bartok pbartok@novell.com
25 // Partially based on work by:
26 // Aleksey Ryabchuk ryabchuk@yahoo.com
27 // Alexandre Pigolkine pigolkine@gmx.de
28 // Dennis Hayes dennish@raytek.com
29 // Jaak Simm jaaksimm@firm.ee
30 // John Sohn jsohn@columbus.rr.com
37 using System
.ComponentModel
;
38 using System
.ComponentModel
.Design
;
39 using System
.ComponentModel
.Design
.Serialization
;
40 using System
.Collections
;
41 using System
.Diagnostics
;
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
53 [ClassInterface (ClassInterfaceType
.AutoDispatch
)]
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
62 , IBindableComponent
, IDropTarget
65 #region Local Variables
68 internal Rectangle bounds
; // bounding rectangle for control (client area + decorations)
69 Rectangle explicit_bounds
; // explicitly set bounds
70 internal object creator_thread
; // thread that created the control
71 internal ControlNativeWindow window
; // object for native window handle
72 private IWindowTarget window_target
;
73 string name
; // for object naming
76 bool is_created
; // true if OnCreateControl has been sent
77 internal bool has_focus
; // true if control has focus
78 internal bool is_visible
; // true if control is visible
79 internal bool is_entered
; // is the mouse inside the control?
80 internal bool is_enabled
; // true if control is enabled (usable/not grayed out)
81 bool is_accessible
; // true if the control is visible to accessibility applications
82 bool is_captured
; // tracks if the control has captured the mouse
83 internal bool is_toplevel
; // tracks if the control is a toplevel window
84 bool is_recreating
; // tracks if the handle for the control is being recreated
85 bool causes_validation
; // tracks if validation is executed on changes
86 bool is_focusing
; // tracks if Focus has been called on the control and has not yet finished
87 int tab_index
; // position in tab order of siblings
88 bool tab_stop
; // is the control a tab stop?
89 bool is_disposed
; // has the window already been disposed?
90 Size client_size
; // size of the client area (window excluding decorations)
91 Rectangle client_rect
; // rectangle with the client area (window excluding decorations)
92 ControlStyles control_style
; // rather win32-specific, style bits for control
94 object control_tag
; // object that contains data about our control
95 internal int mouse_clicks
; // Counter for mouse clicks
96 Cursor cursor
; // Cursor for the window
97 internal bool allow_drop
; // true if the control accepts droping objects on it
98 Region clip_region
; // User-specified clip region for the window
101 internal Color foreground_color
; // foreground color for control
102 internal Color background_color
; // background color for control
103 Image background_image
; // background image for control
104 internal Font font
; // font for control
105 string text
; // window/title text for control
106 internal BorderStyle border_style
; // Border style of control
109 internal enum LayoutType
{
113 Layout
.LayoutEngine layout_engine
;
114 int layout_suspended
;
115 bool layout_pending
; // true if our parent needs to re-layout us
116 internal AnchorStyles anchor_style
; // anchoring requirements for our control
117 internal DockStyle dock_style
; // docking requirements for our control
118 LayoutType layout_type
;
120 // Please leave the next 2 as internal until DefaultLayout (2.0) is rewritten
121 internal int dist_right
; // distance to the right border of the parent
122 internal int dist_bottom
; // distance to the bottom border of the parent
124 // to be categorized...
125 ControlCollection child_controls
; // our children
126 Control parent
; // our parent control
127 AccessibleObject accessibility_object
; // object that contains accessibility information about our control
128 BindingContext binding_context
;
129 RightToLeft right_to_left
; // drawing direction for control
130 ContextMenu context_menu
; // Context menu associated with the control
131 internal bool use_compatible_text_rendering
;
134 DoubleBuffer backbuffer
;
136 // to implement DeviceContext without depending on double buffering
140 ControlBindingsCollection data_bindings
;
143 static bool verify_thread_handle
;
145 ImageLayout backgroundimage_layout
;
149 private ContextMenuStrip context_menu_strip
;
150 Point auto_scroll_offset
;
153 #endregion // Local Variables
155 #region Private Classes
156 // This helper class allows us to dispatch messages to Control.WndProc
157 internal class ControlNativeWindow
: NativeWindow
{
158 private Control owner
;
160 public ControlNativeWindow(Control control
) : base() {
165 public Control Owner
{
171 protected override void OnHandleChange()
173 this.owner
.WindowTarget
.OnHandleChange(this.owner
.Handle
);
176 static internal Control
ControlFromHandle(IntPtr hWnd
) {
177 ControlNativeWindow window
;
179 window
= (ControlNativeWindow
)window_collection
[hWnd
];
180 if (window
!= null) {
187 static internal Control
ControlFromChildHandle (IntPtr handle
) {
188 ControlNativeWindow window
;
190 Hwnd hwnd
= Hwnd
.ObjectFromHandle (handle
);
191 while (hwnd
!= null) {
192 window
= (ControlNativeWindow
)window_collection
[hwnd
.Handle
];
193 if (window
!= null) {
202 protected override void WndProc(ref Message m
) {
203 owner
.WindowTarget
.OnMessage(ref m
);
207 private class ControlWindowTarget
: IWindowTarget
209 private Control control
;
211 public ControlWindowTarget(Control control
)
213 this.control
= control
;
216 public void OnHandleChange(IntPtr newHandle
)
220 public void OnMessage(ref Message m
)
222 control
.WndProc(ref m
);
227 #region Public Classes
229 public class ControlAccessibleObject
: AccessibleObject
{
232 #region ControlAccessibleObject Constructors
233 public ControlAccessibleObject(Control ownerControl
)
234 : base (ownerControl
)
236 if (ownerControl
== null)
237 throw new ArgumentNullException ("owner");
239 handle
= ownerControl
.Handle
;
241 #endregion // ControlAccessibleObject Constructors
243 #region ControlAccessibleObject Public Instance Properties
244 public override string DefaultAction
{
246 return base.DefaultAction
;
250 public override string Description
{
252 return base.Description
;
256 public IntPtr Handle
{
262 // We don't want to let them set it
266 public override string Help
{
272 public override string KeyboardShortcut
{
274 return base.KeyboardShortcut
;
278 public override string Name
{
288 public Control Owner
{
294 public override AccessibleObject Parent
{
301 public override AccessibleRole Role
{
306 #endregion // ControlAccessibleObject Public Instance Properties
308 #region ControlAccessibleObject Public Instance Methods
309 public override int GetHelpTopic(out string FileName
) {
310 return base.GetHelpTopic (out FileName
);
313 [MonoTODO ("Implement this")]
314 public void NotifyClients(AccessibleEvents accEvent
) {
315 throw new NotImplementedException();
318 [MonoTODO ("Implement this")]
319 public void NotifyClients(AccessibleEvents accEvent
, int childID
) {
322 public override string ToString() {
323 return "ControlAccessibleObject: Owner = " + owner
.ToString() + ", Text: " + owner
.text
;
326 #endregion // ControlAccessibleObject Public Instance Methods
329 private class DoubleBuffer
: IDisposable
331 public Region InvalidRegion
;
332 private Stack real_graphics
;
333 private object back_buffer
;
334 private Control parent
;
335 private bool pending_disposal
;
337 public DoubleBuffer (Control parent
) {
338 this.parent
= parent
;
339 real_graphics
= new Stack ();
340 int width
= parent
.Width
;
341 int height
= parent
.Height
;
343 if (width
< 1) width
= 1;
344 if (height
< 1) height
= 1;
346 XplatUI
.CreateOffscreenDrawable (parent
.Handle
, width
, height
, out back_buffer
);
350 public void Blit (PaintEventArgs pe
) {
351 Graphics buffered_graphics
;
352 buffered_graphics
= XplatUI
.GetOffscreenGraphics (back_buffer
);
353 XplatUI
.BlitFromOffscreen (parent
.Handle
, pe
.Graphics
, back_buffer
, buffered_graphics
, pe
.ClipRectangle
);
354 buffered_graphics
.Dispose ();
357 public void Start (PaintEventArgs pe
) {
358 // We need to get the graphics for every paint.
359 real_graphics
.Push(pe
.SetGraphics (XplatUI
.GetOffscreenGraphics (back_buffer
)));
362 public void End (PaintEventArgs pe
) {
363 Graphics buffered_graphics
;
364 buffered_graphics
= pe
.SetGraphics ((Graphics
) real_graphics
.Pop ());
366 if (pending_disposal
)
369 XplatUI
.BlitFromOffscreen (parent
.Handle
, pe
.Graphics
, back_buffer
, buffered_graphics
, pe
.ClipRectangle
);
370 InvalidRegion
.Exclude (pe
.ClipRectangle
);
372 buffered_graphics
.Dispose ();
375 public void Invalidate () {
376 if (InvalidRegion
!= null)
377 InvalidRegion
.Dispose ();
378 InvalidRegion
= new Region (parent
.ClientRectangle
);
381 public void Dispose () {
382 if (real_graphics
.Count
> 0) {
383 pending_disposal
= true;
387 XplatUI
.DestroyOffscreenDrawable (back_buffer
);
389 if (InvalidRegion
!= null)
390 InvalidRegion
.Dispose ();
391 InvalidRegion
= null;
393 GC
.SuppressFinalize (this);
396 #region IDisposable Members
397 void IDisposable
.Dispose () {
407 [ListBindable (false)]
410 public class ControlCollection
: Layout
.ArrangedElementCollection
, IList
, ICollection
, ICloneable
, IEnumerable
{
412 [DesignerSerializer("System.Windows.Forms.Design.ControlCollectionCodeDomSerializer, " + Consts
.AssemblySystem_Design
, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts
.AssemblySystem_Design
)]
413 public class ControlCollection
: IList
, ICollection
, ICloneable
, IEnumerable
{
415 #region ControlCollection Local Variables
420 Control
[] all_controls
;
422 #endregion // ControlCollection Local Variables
424 #region ControlCollection Public Constructor
425 public ControlCollection(Control owner
) {
428 this.list
=new ArrayList();
433 #region ControlCollection Public Instance Properties
434 int ICollection
.Count
{
435 get { return Count; }
441 get { return list.Count; }
446 bool IList
.IsReadOnly
448 public bool IsReadOnly
452 return list
.IsReadOnly
;
457 public Control Owner { get { return this.owner; }
}
459 public virtual Control
this[string key
] {
461 int index
= IndexOfKey (key
);
472 public virtual Control
this[int index
] {
474 if (index
< 0 || index
>= list
.Count
) {
475 throw new ArgumentOutOfRangeException("index", index
, "ControlCollection does not have that many controls");
477 return (Control
)list
[index
];
482 #endregion // ControlCollection Public Instance Properties
484 #region ControlCollection Instance Methods
485 public virtual void Add (Control
value) {
489 Form form_value
= value as Form
;
490 Form form_owner
= owner
as Form
;
491 bool owner_permits_toplevels
= (owner
is MdiClient
) || (form_owner
!= null && form_owner
.IsMdiContainer
);
492 bool child_is_toplevel
= value.GetTopLevel();
493 bool child_is_mdichild
= form_value
!= null && form_value
.IsMdiChild
;
495 if (child_is_toplevel
&& !(owner_permits_toplevels
&& child_is_mdichild
))
496 throw new ArgumentException("Cannot add a top level control to a control.", "value");
498 if (child_is_mdichild
&& form_value
.MdiParent
!= null && form_value
.MdiParent
!= owner
&& form_value
.MdiParent
!= owner
.Parent
) {
499 throw new ArgumentException ("Form cannot be added to the Controls collection that has a valid MDI parent.", "value");
502 if (Contains (value)) {
503 owner
.PerformLayout();
507 if (value.tab_index
== -1) {
513 end
= owner
.child_controls
.Count
;
514 for (int i
= 0; i
< end
; i
++) {
515 index
= owner
.child_controls
[i
].tab_index
;
520 value.tab_index
= use
;
523 if (value.parent
!= null) {
524 value.parent
.Controls
.Remove(value);
530 value.ChangeParent(owner
);
535 owner
.UpdateChildrenZOrder();
536 owner
.PerformLayout(value, "Parent");
537 owner
.OnControlAdded(new ControlEventArgs(value));
540 internal void AddToList (Control c
) {
545 internal virtual void AddImplicit (Control control
) {
546 if (impl_list
== null)
547 impl_list
= new ArrayList ();
549 if (AllContains (control
)) {
550 owner
.PerformLayout ();
554 if (control
.parent
!= null) {
555 control
.parent
.Controls
.Remove(control
);
559 impl_list
.Add (control
);
561 control
.ChangeParent (owner
);
562 control
.InitLayout ();
564 owner
.UpdateChildrenZOrder ();
566 // If we are adding a new control that isn't
567 // visible, don't trigger a layout
568 if (control
.VisibleInternal
)
569 owner
.PerformLayout (control
, "Parent");
572 [DesignerSerializationVisibility (DesignerSerializationVisibility
.Hidden
)]
574 public virtual void AddRange (Control
[] controls
) {
575 if (controls
== null)
576 throw new ArgumentNullException ("controls");
578 owner
.SuspendLayout ();
581 for (int i
= 0; i
< controls
.Length
; i
++)
584 owner
.ResumeLayout ();
588 internal virtual void AddRangeImplicit (Control
[] controls
) {
589 if (controls
== null)
590 throw new ArgumentNullException ("controls");
592 owner
.SuspendLayout ();
595 for (int i
= 0; i
< controls
.Length
; i
++)
596 AddImplicit (controls
[i
]);
598 owner
.ResumeLayout ();
605 public virtual void Clear () {
608 // MS sends remove events in reverse order
609 while (list
.Count
> 0) {
610 Remove((Control
)list
[list
.Count
- 1]);
614 internal virtual void ClearImplicit () {
615 if (impl_list
== null)
621 public bool Contains (Control
value) {
622 for (int i
= list
.Count
; i
> 0; ) {
625 if (list
[i
] == value) {
626 // Do we need to do anything here?
633 internal bool ImplicitContains (Control
value) {
634 if (impl_list
== null)
637 for (int i
= impl_list
.Count
; i
> 0; ) {
640 if (impl_list
[i
] == value) {
641 // Do we need to do anything here?
648 internal bool AllContains (Control
value) {
649 return Contains (value) || ImplicitContains (value);
653 public virtual bool ContainsKey (string key
)
655 return IndexOfKey (key
) >= 0;
659 void ICollection
.CopyTo (Array array
, int index
) {
660 CopyTo (array
, index
);
664 public void CopyTo (Array array
, int index
) {
665 list
.CopyTo(array
, index
);
668 public override bool Equals (object other
) {
669 if (other
is ControlCollection
&& (((ControlCollection
)other
).owner
==this.owner
)) {
678 // LAMESPEC: MSDN says AE, MS implementation throws ANE
679 public Control
[] Find (string key
, bool searchAllChildren
)
681 if (string.IsNullOrEmpty (key
))
682 throw new ArgumentNullException ("key");
684 ArrayList al
= new ArrayList ();
686 foreach (Control c
in list
) {
687 if (c
.Name
.Equals (key
, StringComparison
.CurrentCultureIgnoreCase
))
690 if (searchAllChildren
)
691 al
.AddRange (c
.Controls
.Find (key
, true));
694 return (Control
[])al
.ToArray (typeof (Control
));
698 public int GetChildIndex(Control child
) {
699 return GetChildIndex(child
, false);
707 GetChildIndex(Control child
, bool throwException
) {
710 index
=list
.IndexOf(child
);
712 if (index
==-1 && throwException
) {
713 throw new ArgumentException("Not a child control", "child");
719 public override IEnumerator
724 return list
.GetEnumerator();
727 internal IEnumerator
GetAllEnumerator () {
728 Control
[] res
= GetAllControls ();
729 return res
.GetEnumerator ();
732 internal Control
[] GetAllControls () {
733 if (all_controls
!= null)
736 if (impl_list
== null) {
737 all_controls
= (Control
[]) list
.ToArray (typeof (Control
));
741 all_controls
= new Control
[list
.Count
+ impl_list
.Count
];
742 impl_list
.CopyTo (all_controls
);
743 list
.CopyTo (all_controls
, impl_list
.Count
);
749 public override int GetHashCode() {
750 return base.GetHashCode();
754 public int IndexOf(Control control
) {
755 return list
.IndexOf(control
);
759 public virtual int IndexOfKey (string key
)
761 if (string.IsNullOrEmpty (key
))
764 for (int i
= 0; i
< list
.Count
; i
++)
765 if (((Control
)list
[i
]).Name
.Equals (key
, StringComparison
.CurrentCultureIgnoreCase
))
772 public virtual void Remove(Control
value) {
776 owner
.PerformLayout(value, "Parent");
777 owner
.OnControlRemoved(new ControlEventArgs(value));
782 ContainerControl container
= owner
as ContainerControl
;
783 if (container
!= null) {
784 // Inform any container controls about the loss of a child control
785 // so that they can update their active control
786 container
.ChildControlRemoved (value);
789 value.ChangeParent(null);
791 owner
.UpdateChildrenZOrder();
794 internal virtual void RemoveImplicit (Control control
) {
795 if (impl_list
!= null) {
797 owner
.PerformLayout (control
, "Parent");
798 owner
.OnControlRemoved (new ControlEventArgs (control
));
799 impl_list
.Remove (control
);
801 control
.ChangeParent (null);
802 owner
.UpdateChildrenZOrder ();
808 public void RemoveAt(int index
) {
809 if (index
< 0 || index
>= list
.Count
) {
810 throw new ArgumentOutOfRangeException("index", index
, "ControlCollection does not have that many controls");
812 Remove ((Control
)list
[index
]);
816 public virtual void RemoveByKey (string key
)
818 int index
= IndexOfKey (key
);
830 SetChildIndex(Control child
, int newIndex
) {
832 throw new ArgumentNullException ("child");
836 old_index
=list
.IndexOf(child
);
838 throw new ArgumentException("Not a child control", "child");
841 if (old_index
==newIndex
) {
846 list
.RemoveAt(old_index
);
848 if (newIndex
>list
.Count
) {
851 list
.Insert(newIndex
, child
);
853 child
.UpdateZOrder();
854 owner
.PerformLayout();
856 #endregion // ControlCollection Private Instance Methods
858 #region ControlCollection Interface Properties
859 object IList
.this[int index
] {
861 if (index
<0 || index
>=list
.Count
) {
862 throw new ArgumentOutOfRangeException("index", index
, "ControlCollection does not have that many controls");
868 if (!(value is Control
)) {
869 throw new ArgumentException("Object of type Control required", "value");
873 Control ctrl
= (Control
) value;
876 ctrl
.ChangeParent(owner
);
880 owner
.UpdateChildrenZOrder();
881 owner
.PerformLayout(ctrl
, "Parent");
885 bool IList
.IsFixedSize
{
891 bool ICollection
.IsSynchronized
{
893 return list
.IsSynchronized
;
897 object ICollection
.SyncRoot
{
899 return list
.SyncRoot
;
902 #endregion // ControlCollection Interface Properties
904 #region ControlCollection Interface Methods
905 int IList
.Add(object value) {
906 if (!(value is Control
)) {
907 throw new ArgumentException("Object of type Control required", "value");
911 throw new ArgumentException("value", "Cannot add null controls");
914 bool owner_permits_toplevels
= (owner
is MdiClient
) || (owner
is Form
&& ((Form
)owner
).IsMdiContainer
);
915 bool child_is_toplevel
= ((Control
)value).GetTopLevel();
916 bool child_is_mdichild
= (value is Form
&& ((Form
)value).IsMdiChild
);
918 if (child_is_toplevel
&& !(owner_permits_toplevels
&& child_is_mdichild
))
919 throw new ArgumentException("Cannot add a top level control to a control.", "value");
921 return list
.Add(value);
924 bool IList
.Contains(object value) {
925 if (!(value is Control
)) {
926 throw new ArgumentException("Object of type Control required", "value");
929 return this.Contains((Control
) value);
932 int IList
.IndexOf(object value) {
933 if (!(value is Control
)) {
934 throw new ArgumentException("Object of type Control required", "value");
937 return this.IndexOf((Control
) value);
940 void IList
.Insert(int index
, object value) {
941 if (!(value is Control
)) {
942 throw new ArgumentException("Object of type Control required", "value");
945 list
.Insert(index
, value);
948 void IList
.Remove(object value) {
949 if (!(value is Control
)) {
950 throw new ArgumentException("Object of type Control required", "value");
956 Object ICloneable
.Clone() {
957 ControlCollection clone
= new ControlCollection(this.owner
);
958 clone
.list
=(ArrayList
)list
.Clone(); // FIXME: Do we need this?
961 #endregion // ControlCollection Interface Methods
963 #endregion // ControlCollection Class
965 #region Public Constructors
968 layout_type
= LayoutType
.Anchor
;
969 anchor_style
= AnchorStyles
.Top
| AnchorStyles
.Left
;
977 layout_pending
= false;
979 causes_validation
= true;
981 layout_suspended
= 0;
985 right_to_left
= RightToLeft
.Inherit
;
986 border_style
= BorderStyle
.None
;
987 background_color
= Color
.Empty
;
991 ime_mode
= ImeMode
.Inherit
;
992 use_compatible_text_rendering
= true;
995 backgroundimage_layout
= ImageLayout
.Tile
;
996 use_compatible_text_rendering
= Application
.use_compatible_text_rendering
;
997 padding
= new Padding(0);
998 maximum_size
= new Size();
999 minimum_size
= new Size();
1000 margin
= this.DefaultMargin
;
1003 control_style
= ControlStyles
.UserPaint
| ControlStyles
.AllPaintingInWmPaint
|
1004 ControlStyles
.Selectable
| ControlStyles
.StandardClick
|
1005 ControlStyles
.StandardDoubleClick
;
1007 control_style
|= ControlStyles
.UseTextForAccessibility
;
1011 background_image
= null;
1012 text
= string.Empty
;
1013 name
= string.Empty
;
1015 window_target
= new ControlWindowTarget(this);
1016 window
= new ControlNativeWindow(this);
1017 child_controls
= CreateControlsInstance();
1018 client_size
= DefaultSize
;
1019 client_rect
= new Rectangle (Point
.Empty
, client_size
);
1020 bounds
.Size
= InternalSizeFromClientSize (client_size
);
1021 explicit_bounds
= bounds
;
1024 public Control (Control parent
, string text
) : this()
1030 public Control (Control parent
, string text
, int left
, int top
, int width
, int height
) : this()
1036 bounds
.Height
=height
;
1037 SetBounds(left
, top
, width
, height
, BoundsSpecified
.All
);
1041 public Control (string text
) : this()
1046 public Control (string text
, int left
, int top
, int width
, int height
) : this()
1051 bounds
.Height
=height
;
1052 SetBounds(left
, top
, width
, height
, BoundsSpecified
.All
);
1056 private delegate void RemoveDelegate(object c
);
1058 protected override void Dispose (bool disposing
)
1060 if (!is_disposed
&& disposing
) {
1063 DisposeBackBuffer ();
1069 if (bmp_g
!= null) {
1074 if (this.InvokeRequired
) {
1075 if (Application
.MessageLoop
&& IsHandleCreated
) {
1076 this.BeginInvokeInternal(new MethodInvoker(DestroyHandle
), null);
1082 if (parent
!= null) {
1083 parent
.Controls
.Remove(this);
1086 Control
[] children
= child_controls
.GetAllControls ();
1087 for (int i
=0; i
<children
.Length
; i
++) {
1088 children
[i
].parent
= null; // Need to set to null or our child will try and remove from ourselves and crash
1089 children
[i
].Dispose();
1094 base.Dispose(disposing
);
1096 #endregion // Public Constructors
1098 #region Internal Properties
1099 // Control is currently selected, like Focused, except maintains state
1100 // when Form loses focus
1101 internal bool InternalSelected
{
1103 IContainerControl container
;
1105 container
= GetContainerControl();
1107 if (container
!= null && container
.ActiveControl
== this)
1114 // Mouse is currently within the control's bounds
1115 internal bool Entered
{
1116 get { return this.is_entered; }
1119 internal bool VisibleInternal
{
1120 get { return is_visible; }
1123 internal LayoutType ControlLayoutType
{
1124 get { return layout_type; }
1127 internal BorderStyle InternalBorderStyle
{
1129 return border_style
;
1133 if (!Enum
.IsDefined (typeof (BorderStyle
), value))
1134 throw new InvalidEnumArgumentException (string.Format("Enum argument value '{0}' is not valid for BorderStyle", value));
1136 if (border_style
!= value) {
1137 border_style
= value;
1139 if (IsHandleCreated
) {
1140 XplatUI
.SetBorderStyle (window
.Handle
, (FormBorderStyle
)border_style
);
1148 internal Size InternalClientSize { set { this.client_size = value; }
}
1149 internal virtual bool ActivateOnShow { get { return true; }
}
1150 #endregion // Internal Properties
1152 #region Private & Internal Methods
1155 void IDropTarget
.OnDragDrop (DragEventArgs e
)
1160 void IDropTarget
.OnDragEnter (DragEventArgs e
)
1165 void IDropTarget
.OnDragLeave (EventArgs e
)
1170 void IDropTarget
.OnDragOver (DragEventArgs e
)
1176 internal IAsyncResult
BeginInvokeInternal (Delegate method
, object [] args
) {
1177 return BeginInvokeInternal (method
, args
, FindControlToInvokeOn ());
1180 internal IAsyncResult
BeginInvokeInternal (Delegate method
, object [] args
, Control control
) {
1181 AsyncMethodResult result
;
1182 AsyncMethodData data
;
1184 result
= new AsyncMethodResult ();
1185 data
= new AsyncMethodData ();
1187 data
.Handle
= control
.Handle
;
1188 data
.Method
= method
;
1190 data
.Result
= result
;
1193 if (!ExecutionContext
.IsFlowSuppressed ()) {
1194 data
.Context
= ExecutionContext
.Capture ();
1197 #if !MWF_ON_MSRUNTIME
1198 if (SecurityManager
.SecurityEnabled
) {
1199 data
.Stack
= CompressedStack
.GetCompressedStack ();
1204 XplatUI
.SendAsyncMethod (data
);
1209 internal void PointToClient (ref int x
, ref int y
) {
1210 XplatUI
.ScreenToClient (Handle
, ref x
, ref y
);
1213 internal void PointToScreen (ref int x
, ref int y
) {
1214 XplatUI
.ClientToScreen (Handle
, ref x
, ref y
);
1217 internal bool IsRecreating
{
1219 return is_recreating
;
1223 internal Graphics DeviceContext
{
1225 if (bmp_g
== null) {
1226 bmp
= new Bitmap(1, 1, System
.Drawing
.Imaging
.PixelFormat
.Format32bppArgb
);
1227 bmp_g
= Graphics
.FromImage (bmp
);
1233 private Control
FindControlToInvokeOn ()
1237 if (p
.IsHandleCreated
)
1240 } while (p
!= null);
1242 if (p
== null || !p
.IsHandleCreated
)
1243 throw new InvalidOperationException ("Cannot call Invoke or BeginInvoke on a control until the window handle is created");
1248 private void InvalidateBackBuffer () {
1249 if (backbuffer
!= null)
1250 backbuffer
.Invalidate ();
1253 private DoubleBuffer
GetBackBuffer () {
1254 if (backbuffer
== null)
1255 backbuffer
= new DoubleBuffer (this);
1259 private void DisposeBackBuffer () {
1260 if (backbuffer
!= null) {
1261 backbuffer
.Dispose ();
1266 internal static void SetChildColor(Control parent
) {
1269 for (int i
=0; i
< parent
.child_controls
.Count
; i
++) {
1270 child
=parent
.child_controls
[i
];
1271 if (child
.child_controls
.Count
>0) {
1272 SetChildColor(child
);
1277 internal bool Select(Control control
) {
1278 IContainerControl container
;
1280 if (control
== null) {
1284 container
= GetContainerControl();
1285 if (container
!= null && (Control
)container
!= control
) {
1286 container
.ActiveControl
= control
;
1288 else if (control
.IsHandleCreated
) {
1289 XplatUI
.SetFocus(control
.window
.Handle
);
1294 internal virtual void DoDefaultAction() {
1295 // Only here to be overriden by our actual controls; this is needed by the accessibility class
1298 internal static IntPtr
MakeParam (int low
, int high
){
1299 return new IntPtr (high
<< 16 | low
& 0xffff);
1302 internal static int LowOrder (int param
) {
1303 return ((int)(short)(param
& 0xffff));
1306 internal static int HighOrder (int param
) {
1307 return ((int)(short)(param
>> 16));
1310 // This method exists so controls overriding OnPaintBackground can have default background painting done
1311 internal virtual void PaintControlBackground (PaintEventArgs pevent
) {
1312 if (GetStyle(ControlStyles
.SupportsTransparentBackColor
) && (BackColor
.A
!= 0xff)) {
1313 if (parent
!= null) {
1314 PaintEventArgs parent_pe
;
1315 GraphicsState state
;
1317 parent_pe
= new PaintEventArgs(pevent
.Graphics
, new Rectangle(pevent
.ClipRectangle
.X
+ Left
, pevent
.ClipRectangle
.Y
+ Top
, pevent
.ClipRectangle
.Width
, pevent
.ClipRectangle
.Height
));
1319 state
= parent_pe
.Graphics
.Save();
1320 parent_pe
.Graphics
.TranslateTransform(-Left
, -Top
);
1321 parent
.OnPaintBackground(parent_pe
);
1322 parent_pe
.Graphics
.Restore(state
);
1324 state
= parent_pe
.Graphics
.Save();
1325 parent_pe
.Graphics
.TranslateTransform(-Left
, -Top
);
1326 parent
.OnPaint(parent_pe
);
1327 parent_pe
.Graphics
.Restore(state
);
1328 parent_pe
.SetGraphics(null);
1332 if ((clip_region
!= null) && (XplatUI
.UserClipWontExposeParent
)) {
1333 if (parent
!= null) {
1334 PaintEventArgs parent_pe
;
1336 GraphicsState state
;
1339 hwnd
= Hwnd
.ObjectFromHandle(Handle
);
1342 parent_pe
= new PaintEventArgs(pevent
.Graphics
, new Rectangle(pevent
.ClipRectangle
.X
+ Left
, pevent
.ClipRectangle
.Y
+ Top
, pevent
.ClipRectangle
.Width
, pevent
.ClipRectangle
.Height
));
1344 region
= new Region ();
1346 region
.Union(ClientRectangle
);
1348 foreach (Rectangle r
in hwnd
.ClipRectangles
) {
1352 state
= parent_pe
.Graphics
.Save();
1353 parent_pe
.Graphics
.Clip
= region
;
1355 parent_pe
.Graphics
.TranslateTransform(-Left
, -Top
);
1356 parent
.OnPaintBackground(parent_pe
);
1357 parent_pe
.Graphics
.Restore(state
);
1359 state
= parent_pe
.Graphics
.Save();
1360 parent_pe
.Graphics
.Clip
= region
;
1362 parent_pe
.Graphics
.TranslateTransform(-Left
, -Top
);
1363 parent
.OnPaint(parent_pe
);
1364 parent_pe
.Graphics
.Restore(state
);
1365 parent_pe
.SetGraphics(null);
1367 region
.Intersect(clip_region
);
1368 pevent
.Graphics
.Clip
= region
;
1373 if (background_image
== null) {
1374 Rectangle paintRect
= new Rectangle(pevent
.ClipRectangle
.X
, pevent
.ClipRectangle
.Y
, pevent
.ClipRectangle
.Width
, pevent
.ClipRectangle
.Height
);
1375 Brush pen
= ThemeEngine
.Current
.ResPool
.GetSolidBrush(BackColor
);
1376 pevent
.Graphics
.FillRectangle(pen
, paintRect
);
1380 DrawBackgroundImage (pevent
.Graphics
);
1383 void DrawBackgroundImage (Graphics g
) {
1385 Rectangle drawing_rectangle
= new Rectangle ();
1386 g
.FillRectangle (ThemeEngine
.Current
.ResPool
.GetSolidBrush (BackColor
), ClientRectangle
);
1388 switch (backgroundimage_layout
)
1390 case ImageLayout
.Tile
:
1391 using (TextureBrush b
= new TextureBrush (background_image
, WrapMode
.Tile
)) {
1392 g
.FillRectangle (b
, ClientRectangle
);
1395 case ImageLayout
.Center
:
1396 drawing_rectangle
.Location
= new Point (ClientSize
.Width
/ 2 - background_image
.Width
/ 2, ClientSize
.Height
/ 2 - background_image
.Height
/ 2);
1397 drawing_rectangle
.Size
= background_image
.Size
;
1399 case ImageLayout
.None
:
1400 drawing_rectangle
.Location
= Point
.Empty
;
1401 drawing_rectangle
.Size
= background_image
.Size
;
1403 case ImageLayout
.Stretch
:
1404 drawing_rectangle
= ClientRectangle
;
1406 case ImageLayout
.Zoom
:
1407 drawing_rectangle
= ClientRectangle
;
1408 if ((float)background_image
.Width
/ (float)background_image
.Height
< (float)drawing_rectangle
.Width
/ (float) drawing_rectangle
.Height
) {
1409 drawing_rectangle
.Width
= (int) (background_image
.Width
* ((float)drawing_rectangle
.Height
/ (float)background_image
.Height
));
1410 drawing_rectangle
.X
= (ClientRectangle
.Width
- drawing_rectangle
.Width
) / 2;
1412 drawing_rectangle
.Height
= (int) (background_image
.Height
* ((float)drawing_rectangle
.Width
/ (float)background_image
.Width
));
1413 drawing_rectangle
.Y
= (ClientRectangle
.Height
- drawing_rectangle
.Height
) / 2;
1420 g
.DrawImage (background_image
, drawing_rectangle
);
1423 using (TextureBrush b
= new TextureBrush (background_image
, WrapMode
.Tile
)) {
1424 g
.FillRectangle (b
, ClientRectangle
);
1429 internal virtual void DndEnter (DragEventArgs e
) {
1435 internal virtual void DndOver (DragEventArgs e
) {
1441 internal virtual void DndDrop (DragEventArgs e
) {
1444 } catch (Exception exc
) {
1445 Console
.Error
.WriteLine ("MWF: Exception while dropping:");
1446 Console
.Error
.WriteLine (exc
);
1450 internal virtual void DndLeave (EventArgs e
) {
1456 internal virtual void DndFeedback(GiveFeedbackEventArgs e
) {
1462 internal virtual void DndContinueDrag(QueryContinueDragEventArgs e
) {
1464 OnQueryContinueDrag(e
);
1468 internal static MouseButtons
FromParamToMouseButtons (int param
) {
1469 MouseButtons buttons
= MouseButtons
.None
;
1471 if ((param
& (int) MsgButtons
.MK_LBUTTON
) != 0)
1472 buttons
|= MouseButtons
.Left
;
1474 if ((param
& (int) MsgButtons
.MK_MBUTTON
) != 0)
1475 buttons
|= MouseButtons
.Middle
;
1477 if ((param
& (int) MsgButtons
.MK_RBUTTON
) != 0)
1478 buttons
|= MouseButtons
.Right
;
1484 internal virtual void FireEnter () {
1485 OnEnter (EventArgs
.Empty
);
1488 internal virtual void FireLeave () {
1489 OnLeave (EventArgs
.Empty
);
1492 internal virtual void FireValidating (CancelEventArgs ce
) {
1496 internal virtual void FireValidated () {
1497 OnValidated (EventArgs
.Empty
);
1500 internal virtual bool ProcessControlMnemonic(char charCode
) {
1501 return ProcessMnemonic(charCode
);
1504 private static Control
FindFlatForward(Control container
, Control start
) {
1510 end
= container
.child_controls
.Count
;
1512 if (start
!= null) {
1513 index
= start
.tab_index
;
1518 for (int i
= 0, pos
= -1; i
< end
; i
++) {
1519 if (start
== container
.child_controls
[i
]) {
1524 if (found
== null) {
1525 if (container
.child_controls
[i
].tab_index
> index
|| (pos
> -1 && pos
< i
&& container
.child_controls
[i
].tab_index
== index
)) {
1526 found
= container
.child_controls
[i
];
1528 } else if (found
.tab_index
> container
.child_controls
[i
].tab_index
) {
1529 if (container
.child_controls
[i
].tab_index
> index
) {
1530 found
= container
.child_controls
[i
];
1537 private static Control
FindControlForward(Control container
, Control start
) {
1542 if (start
== null) {
1543 return FindFlatForward(container
, start
);
1546 if (start
.child_controls
!= null && start
.child_controls
.Count
> 0 &&
1547 (start
== container
|| !((start
is IContainerControl
) && start
.GetStyle(ControlStyles
.ContainerControl
)))) {
1548 return FindControlForward(start
, null);
1551 while (start
!= container
) {
1552 found
= FindFlatForward(start
.parent
, start
);
1553 if (found
!= null) {
1556 start
= start
.parent
;
1562 private static Control
FindFlatBackward(Control container
, Control start
) {
1568 end
= container
.child_controls
.Count
;
1570 if (start
!= null) {
1571 index
= start
.tab_index
;
1573 // FIXME: Possible speed-up: Keep the highest taborder index in the container
1575 for (int i
= 0; i
< end
; i
++) {
1576 if (container
.child_controls
[i
].tab_index
> index
) {
1577 index
= container
.child_controls
[i
].tab_index
;
1585 for (int i
= end
- 1; i
>= 0; i
--) {
1586 if (start
== container
.child_controls
[i
]) {
1591 if (found
== null || found
.tab_index
< container
.child_controls
[i
].tab_index
) {
1592 if (container
.child_controls
[i
].tab_index
< index
|| (hit
&& container
.child_controls
[i
].tab_index
== index
))
1593 found
= container
.child_controls
[i
];
1600 private static Control
FindControlBackward(Control container
, Control start
) {
1602 Control found
= null;
1604 if (start
== null) {
1605 found
= FindFlatBackward(container
, start
);
1607 else if (start
!= container
) {
1608 if (start
.parent
!= null) {
1609 found
= FindFlatBackward(start
.parent
, start
);
1611 if (found
== null) {
1612 if (start
.parent
!= container
)
1613 return start
.parent
;
1619 if (found
== null || start
.parent
== null)
1622 while (found
!= null && (found
== container
|| (!((found
is IContainerControl
) && found
.GetStyle(ControlStyles
.ContainerControl
))) &&
1623 found
.child_controls
!= null && found
.child_controls
.Count
> 0)) {
1624 // while (ctl.child_controls != null && ctl.child_controls.Count > 0 &&
1625 // (ctl == this || (!((ctl is IContainerControl) && ctl.GetStyle(ControlStyles.ContainerControl))))) {
1626 found
= FindFlatBackward(found
, null);
1636 if (start != null) {
1637 found = FindFlatBackward(start.parent, start);
1638 if (found == null) {
1639 if (start.parent != container) {
1640 return start.parent;
1644 if (found == null) {
1645 found = FindFlatBackward(container, start);
1648 if (container != start) {
1649 while ((found != null) && (!found.Contains(start)) && found.child_controls != null && found.child_controls.Count > 0 && !(found is IContainerControl)) {// || found.GetStyle(ControlStyles.ContainerControl))) {
1650 found = FindControlBackward(found, null);
1651 if (found != null) {
1660 internal virtual void HandleClick(int clicks
, MouseEventArgs me
) {
1661 if (GetStyle(ControlStyles
.StandardClick
)) {
1662 if ((clicks
> 1) && GetStyle(ControlStyles
.StandardDoubleClick
)) {
1664 OnDoubleClick(EventArgs
.Empty
);
1666 OnClick(EventArgs
.Empty
);
1669 OnMouseDoubleClick (me
);
1678 internal void CaptureWithConfine (Control ConfineWindow
) {
1679 if (this.IsHandleCreated
&& !is_captured
) {
1681 XplatUI
.GrabWindow (this.window
.Handle
, ConfineWindow
.Handle
);
1685 private void CheckDataBindings () {
1686 if (data_bindings
== null)
1689 BindingContext binding_context
= BindingContext
;
1690 foreach (Binding binding
in data_bindings
) {
1691 binding
.Check (binding_context
);
1695 private void ChangeParent(Control new_parent
) {
1699 Color pre_fore_color
;
1700 Color pre_back_color
;
1701 RightToLeft pre_rtl
;
1703 // These properties are inherited from our parent
1704 // Get them pre parent-change and then send events
1705 // if they are changed after we have our new parent
1706 pre_enabled
= Enabled
;
1707 pre_visible
= Visible
;
1709 pre_fore_color
= ForeColor
;
1710 pre_back_color
= BackColor
;
1711 pre_rtl
= RightToLeft
;
1712 // MS doesn't seem to send a CursorChangedEvent
1714 parent
= new_parent
;
1716 if (IsHandleCreated
) {
1717 XplatUI
.SetParent(Handle
,
1718 (new_parent
== null || !new_parent
.IsHandleCreated
) ? IntPtr
.Zero
: new_parent
.Handle
);
1721 ((Form
)this).ChangingParent (new_parent
);
1724 OnParentChanged(EventArgs
.Empty
);
1726 if (pre_enabled
!= Enabled
) {
1727 OnEnabledChanged(EventArgs
.Empty
);
1730 if (pre_visible
!= Visible
) {
1731 OnVisibleChanged(EventArgs
.Empty
);
1734 if (pre_font
!= Font
) {
1735 OnFontChanged(EventArgs
.Empty
);
1738 if (pre_fore_color
!= ForeColor
) {
1739 OnForeColorChanged(EventArgs
.Empty
);
1742 if (pre_back_color
!= BackColor
) {
1743 OnBackColorChanged(EventArgs
.Empty
);
1746 if (pre_rtl
!= RightToLeft
) {
1747 // MS sneaks a OnCreateControl and OnHandleCreated in here, I guess
1748 // because when RTL changes they have to recreate the win32 control
1749 // We don't really need that (until someone runs into compatibility issues)
1750 OnRightToLeftChanged(EventArgs
.Empty
);
1753 if ((new_parent
!= null) && new_parent
.Created
&& is_visible
&& !Created
) {
1757 if ((binding_context
== null) && Created
) {
1758 OnBindingContextChanged(EventArgs
.Empty
);
1762 // Sometimes we need to do this calculation without it being virtual (constructor)
1763 internal Size
InternalSizeFromClientSize (Size clientSize
)
1765 Rectangle ClientRect
;
1766 Rectangle WindowRect
;
1769 ClientRect
= new Rectangle (0, 0, clientSize
.Width
, clientSize
.Height
);
1770 cp
= this.CreateParams
;
1772 if (XplatUI
.CalculateWindowRect (ref ClientRect
, cp
, null, out WindowRect
))
1773 return new Size (WindowRect
.Width
, WindowRect
.Height
);
1778 internal CreateParams
GetCreateParams ()
1780 return CreateParams
;
1783 private void UpdateDistances() {
1784 if (parent
!= null) {
1785 if (bounds
.Width
>= 0)
1786 dist_right
= parent
.ClientSize
.Width
- bounds
.X
- bounds
.Width
;
1787 if (bounds
.Height
>= 0)
1788 dist_bottom
= parent
.ClientSize
.Height
- bounds
.Y
- bounds
.Height
;
1792 private Cursor
GetAvailableCursor ()
1794 if (Cursor
!= null && Enabled
) {
1798 if (Parent
!= null) {
1799 return Parent
.GetAvailableCursor ();
1802 return Cursors
.Default
;
1805 private void UpdateCursor ()
1807 if (!IsHandleCreated
)
1811 XplatUI
.SetCursor (window
.Handle
, GetAvailableCursor ().handle
);
1815 Point pt
= PointToClient (Cursor
.Position
);
1817 if ((!bounds
.Contains (pt
) && !Capture
) || (GetChildAtPoint (pt
) != null))
1820 if (cursor
!= null) {
1821 XplatUI
.SetCursor (window
.Handle
, cursor
.handle
);
1823 XplatUI
.SetCursor (window
.Handle
, GetAvailableCursor ().handle
);
1827 private bool UseDoubleBuffering
{
1829 if (!ThemeEngine
.Current
.DoubleBufferingSupported
)
1836 return (control_style
& ControlStyles
.DoubleBuffer
) != 0;
1839 #endregion // Private & Internal Methods
1841 #region Public Static Properties
1842 public static Color DefaultBackColor
{
1844 return ThemeEngine
.Current
.DefaultControlBackColor
;
1848 public static Font DefaultFont
{
1850 return ThemeEngine
.Current
.DefaultFont
;
1854 public static Color DefaultForeColor
{
1856 return ThemeEngine
.Current
.DefaultControlForeColor
;
1860 public static Keys ModifierKeys
{
1862 return XplatUI
.State
.ModifierKeys
;
1866 public static MouseButtons MouseButtons
{
1868 return XplatUI
.State
.MouseButtons
;
1872 public static Point MousePosition
{
1874 return Cursor
.Position
;
1879 [EditorBrowsable (EditorBrowsableState
.Advanced
)]
1880 [DesignerSerializationVisibility (DesignerSerializationVisibility
.Hidden
)]
1883 public static bool CheckForIllegalCrossThreadCalls
1886 return verify_thread_handle
;
1890 verify_thread_handle
= value;
1894 #endregion // Public Static Properties
1896 #region Public Instance Properties
1897 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
1899 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
1900 public AccessibleObject AccessibilityObject
{
1902 if (accessibility_object
==null) {
1903 accessibility_object
=CreateAccessibilityInstance();
1905 return accessibility_object
;
1909 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
1911 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
1912 public string AccessibleDefaultActionDescription
{
1914 if (accessibility_object
!= null)
1915 return accessibility_object
.default_action
;
1921 if (accessibility_object
!= null)
1922 accessibility_object
.default_action
= value;
1927 [DefaultValue(null)]
1928 [MWFCategory("Accessibility")]
1929 public string AccessibleDescription
{
1931 if (accessibility_object
!= null)
1932 return accessibility_object
.description
;
1938 if (accessibility_object
!= null)
1939 accessibility_object
.description
= value;
1944 [DefaultValue(null)]
1945 [MWFCategory("Accessibility")]
1946 public string AccessibleName
{
1948 if (accessibility_object
!= null)
1949 return accessibility_object
.Name
;
1955 if (accessibility_object
!= null)
1956 accessibility_object
.Name
= value;
1960 [DefaultValue(AccessibleRole
.Default
)]
1961 [MWFDescription("Role of the control"), MWFCategory("Accessibility")]
1962 public AccessibleRole AccessibleRole
{
1964 if (accessibility_object
!= null)
1965 return accessibility_object
.role
;
1967 return AccessibleRole
.Default
;
1971 if (accessibility_object
!= null)
1972 accessibility_object
.role
= value;
1976 [DefaultValue(false)]
1977 [MWFCategory("Behavior")]
1978 public virtual bool AllowDrop
{
1984 if (allow_drop
== value)
1987 if (IsHandleCreated
) {
1989 XplatUI
.SetAllowDrop (Handle
, value);
1995 [RefreshProperties(RefreshProperties
.Repaint
)]
1996 [DefaultValue(AnchorStyles
.Top
| AnchorStyles
.Left
)]
1997 [MWFCategory("Layout")]
1998 public virtual AnchorStyles Anchor
{
2000 return anchor_style
;
2004 layout_type
= LayoutType
.Anchor
;
2006 if (anchor_style
== value)
2010 dock_style
= DockStyle
.None
;
2015 parent
.PerformLayout(this, "Anchor");
2021 public virtual Point AutoScrollOffset
{
2023 return auto_scroll_offset
;
2027 this.auto_scroll_offset
= value;
2031 // XXX: Implement me!
2034 [RefreshProperties (RefreshProperties
.All
)]
2035 [Localizable (true)]
2036 [DesignerSerializationVisibility (DesignerSerializationVisibility
.Hidden
)]
2038 [EditorBrowsable (EditorBrowsableState
.Never
)]
2039 [DefaultValue (false)]
2040 [MonoTODO("This method currently does nothing")]
2041 public virtual bool AutoSize
{
2042 get { return auto_size; }
2044 if (this.auto_size
!= value) {
2046 OnAutoSizeChanged (EventArgs
.Empty
);
2052 [AmbientValue ("{Width=0, Height=0}")]
2054 [AmbientValue (typeof(Size
), "0, 0")]
2056 public virtual Size MaximumSize
{
2058 return maximum_size
;
2061 if (maximum_size
!= value) {
2062 maximum_size
= value;
2063 Size
= PreferredSize
;
2068 public virtual Size MinimumSize
{
2070 return minimum_size
;
2073 if (minimum_size
!= value) {
2074 minimum_size
= value;
2075 Size
= PreferredSize
;
2082 [MWFCategory("Appearance")]
2083 public virtual Color BackColor
{
2085 if (background_color
.IsEmpty
) {
2087 Color pcolor
= parent
.BackColor
;
2088 if (pcolor
.A
== 0xff || GetStyle(ControlStyles
.SupportsTransparentBackColor
))
2091 return DefaultBackColor
;
2093 return background_color
;
2097 if (!value.IsEmpty
&& (value.A
!= 0xff) && !GetStyle(ControlStyles
.SupportsTransparentBackColor
)) {
2098 throw new ArgumentException("Transparent background colors are not supported on this control");
2101 if (background_color
!= value) {
2102 background_color
=value;
2103 SetChildColor(this);
2104 OnBackColorChanged(EventArgs
.Empty
);
2111 [DefaultValue(null)]
2112 [MWFCategory("Appearance")]
2113 public virtual Image BackgroundImage
{
2115 return background_image
;
2119 if (background_image
!=value) {
2120 background_image
=value;
2121 OnBackgroundImageChanged(EventArgs
.Empty
);
2128 [DefaultValue (ImageLayout
.Tile
)]
2129 [Localizable (true)]
2130 public virtual ImageLayout BackgroundImageLayout
{
2132 return backgroundimage_layout
;
2135 if (Array
.IndexOf (Enum
.GetValues (typeof (ImageLayout
)), value) == -1)
2136 throw new InvalidEnumArgumentException ("value", (int) value, typeof(ImageLayout
));
2138 if (value != backgroundimage_layout
) {
2139 backgroundimage_layout
= value;
2141 OnBackgroundImageLayoutChanged (EventArgs
.Empty
);
2147 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
2149 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
2150 public virtual BindingContext BindingContext
{
2152 if (binding_context
!= null)
2153 return binding_context
;
2156 binding_context
= Parent
.BindingContext
;
2157 return binding_context
;
2160 if (binding_context
!= value) {
2161 binding_context
= value;
2162 OnBindingContextChanged(EventArgs
.Empty
);
2167 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
2169 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
2172 return bounds
.Y
+bounds
.Height
;
2176 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
2178 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
2179 public Rectangle Bounds
{
2185 SetBounds(value.Left
, value.Top
, value.Width
, value.Height
, BoundsSpecified
.All
);
2189 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
2191 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
2192 public bool CanFocus
{
2194 if (IsHandleCreated
&& Visible
&& Enabled
) {
2201 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
2203 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
2204 public bool CanSelect
{
2208 if (!GetStyle(ControlStyles
.Selectable
)) {
2213 while (parent
!= null) {
2214 if (!parent
.is_visible
|| !parent
.is_enabled
) {
2218 parent
= parent
.parent
;
2224 internal virtual bool InternalCapture
{
2234 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
2236 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
2237 public bool Capture
{
2239 return this.is_captured
;
2243 // Call OnMouseCaptureChanged when we get WM_CAPTURECHANGED.
2244 if (value != is_captured
) {
2247 XplatUI
.GrabWindow(Handle
, IntPtr
.Zero
);
2249 if (IsHandleCreated
)
2250 XplatUI
.UngrabWindow(Handle
);
2251 is_captured
= false;
2257 [DefaultValue(true)]
2258 [MWFCategory("Focus")]
2259 public bool CausesValidation
{
2261 return this.causes_validation
;
2265 if (this.causes_validation
!= value) {
2266 causes_validation
= value;
2267 OnCausesValidationChanged(EventArgs
.Empty
);
2272 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
2274 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
2275 public Rectangle ClientRectangle
{
2277 client_rect
.Width
= client_size
.Width
;
2278 client_rect
.Height
= client_size
.Height
;
2283 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
2285 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
2286 public Size ClientSize
{
2289 if ((this is Form
) && (((Form
)this).form_parent_window
!= null)) {
2290 return ((Form
)this).form_parent_window
.ClientSize
;
2298 this.SetClientSizeCore(value.Width
, value.Height
);
2300 this.OnClientSizeChanged (EventArgs
.Empty
);
2305 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
2307 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
2308 [DescriptionAttribute("ControlCompanyNameDescr")]
2309 public String CompanyName
{
2311 return "Mono Project, Novell, Inc.";
2315 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
2317 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
2318 public bool ContainsFocus
{
2320 IntPtr focused_window
;
2322 focused_window
= XplatUI
.GetFocus();
2323 if (IsHandleCreated
) {
2324 if (focused_window
== Handle
) {
2328 for (int i
=0; i
< child_controls
.Count
; i
++) {
2329 if (child_controls
[i
].ContainsFocus
) {
2340 [DefaultValue(null)]
2341 [MWFCategory("Behavior")]
2342 public virtual ContextMenu ContextMenu
{
2344 return GetContextMenuInternal ();
2348 if (context_menu
!= value) {
2349 context_menu
= value;
2350 OnContextMenuChanged(EventArgs
.Empty
);
2355 internal virtual ContextMenu
GetContextMenuInternal () {
2356 return context_menu
;
2360 [DefaultValue (null)]
2361 public virtual ContextMenuStrip ContextMenuStrip
{
2362 get { return this.context_menu_strip; }
2364 if (this.context_menu_strip
!= value) {
2365 this.context_menu_strip
= value;
2366 OnContextMenuStripChanged (EventArgs
.Empty
);
2373 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Content
)]
2374 public ControlCollection Controls
{
2376 return this.child_controls
;
2380 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
2382 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
2383 public bool Created
{
2385 return (!is_disposed
&& is_created
);
2389 [AmbientValue(null)]
2390 [MWFCategory("Appearance")]
2391 public virtual Cursor Cursor
{
2393 if (cursor
!= null) {
2397 if (parent
!= null) {
2398 return parent
.Cursor
;
2401 return Cursors
.Default
;
2405 if (cursor
== value) {
2412 OnCursorChanged (EventArgs
.Empty
);
2417 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Content
)]
2418 [ParenthesizePropertyName(true)]
2419 [RefreshProperties(RefreshProperties
.All
)]
2420 [MWFCategory("Data")]
2421 public ControlBindingsCollection DataBindings
{
2423 if (data_bindings
== null)
2424 data_bindings
= new ControlBindingsCollection (this);
2425 return data_bindings
;
2429 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
2431 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
2432 public virtual Rectangle DisplayRectangle
{
2434 return ClientRectangle
;
2438 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
2440 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
2441 public bool Disposing
{
2448 [RefreshProperties(RefreshProperties
.Repaint
)]
2449 [DefaultValue(DockStyle
.None
)]
2450 [MWFCategory("Layout")]
2451 public virtual DockStyle Dock
{
2457 layout_type
= LayoutType
.Dock
;
2459 if (dock_style
== value) {
2463 if (!Enum
.IsDefined (typeof (DockStyle
), value)) {
2464 throw new InvalidEnumArgumentException ("value", (int) value,
2465 typeof (DockStyle
));
2469 anchor_style
= AnchorStyles
.Top
| AnchorStyles
.Left
;
2471 if (dock_style
== DockStyle
.None
) {
2472 Bounds
= explicit_bounds
;
2475 if (parent
!= null) {
2476 parent
.PerformLayout(this, "Dock");
2479 OnDockChanged(EventArgs
.Empty
);
2484 protected virtual bool DoubleBuffered
{
2486 return (control_style
& ControlStyles
.OptimizedDoubleBuffer
) != 0;
2490 if (value == DoubleBuffered
)
2493 SetStyle (ControlStyles
.OptimizedDoubleBuffer
| ControlStyles
.AllPaintingInWmPaint
, true);
2495 SetStyle (ControlStyles
.OptimizedDoubleBuffer
, false);
2504 [MWFCategory("Behavior")]
2505 public bool Enabled
{
2511 if (parent
!= null) {
2512 return parent
.Enabled
;
2519 if (this.is_enabled
== value)
2522 bool old_value
= is_enabled
;
2529 if (old_value
!= value && !value && this.has_focus
)
2530 SelectNextControl(this, true, true, true, true);
2532 OnEnabledChanged (EventArgs
.Empty
);
2536 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
2538 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
2539 public virtual bool Focused
{
2541 return this.has_focus
;
2546 [AmbientValue(null)]
2548 [MWFCategory("Appearance")]
2549 public virtual Font Font
{
2555 if (Parent
!= null && Parent
.Font
!= null) {
2562 [param
:MarshalAs(UnmanagedType
.CustomMarshaler
, MarshalTypeRef
=typeof(Font
))]
2564 if (font
!= null && font
.Equals (value)) {
2570 OnFontChanged (EventArgs
.Empty
);
2576 [MWFCategory("Appearance")]
2577 public virtual Color ForeColor
{
2579 if (foreground_color
.IsEmpty
) {
2581 return parent
.ForeColor
;
2583 return DefaultForeColor
;
2585 return foreground_color
;
2589 if (foreground_color
!= value) {
2590 foreground_color
=value;
2592 OnForeColorChanged(EventArgs
.Empty
);
2599 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
2600 public IntPtr Handle
{ // IWin32Window
2603 if (verify_thread_handle
) {
2604 if (this.InvokeRequired
) {
2605 throw new InvalidOperationException("Cross-thread access of handle detected. Handle access only valid on thread that created the control");
2609 if (!IsHandleCreated
) {
2612 return window
.Handle
;
2616 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
2618 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
2619 public bool HasChildren
{
2621 if (this.child_controls
.Count
>0) {
2628 [EditorBrowsable(EditorBrowsableState
.Always
)]
2630 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
2633 return this.bounds
.Height
;
2637 SetBounds(bounds
.X
, bounds
.Y
, bounds
.Width
, value, BoundsSpecified
.Height
);
2641 [AmbientValue(ImeMode
.Inherit
)]
2643 [MWFCategory("Behavior")]
2644 public ImeMode ImeMode
{
2646 if (ime_mode
== ImeMode
.Inherit
) {
2648 return parent
.ImeMode
;
2650 return ImeMode
.NoControl
; // default value
2656 if (ime_mode
!= value) {
2659 OnImeModeChanged(EventArgs
.Empty
);
2664 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
2666 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
2667 public bool InvokeRequired
{ // ISynchronizeInvoke
2669 if (creator_thread
!= null && creator_thread
!=Thread
.CurrentThread
) {
2676 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
2678 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
2679 public bool IsAccessible
{
2681 return is_accessible
;
2685 is_accessible
= value;
2689 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
2691 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
2692 public bool IsDisposed
{
2694 return this.is_disposed
;
2698 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
2700 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
2701 public bool IsHandleCreated
{
2703 if (window
== null || window
.Handle
== IntPtr
.Zero
)
2706 Hwnd hwnd
= Hwnd
.ObjectFromHandle (window
.Handle
);
2707 if (hwnd
!= null && hwnd
.zombie
)
2715 [EditorBrowsable (EditorBrowsableState
.Advanced
)]
2719 Layout
.LayoutEngine LayoutEngine
{
2721 if (layout_engine
== null)
2722 layout_engine
= new Layout
.DefaultLayout ();
2723 return layout_engine
;
2727 [EditorBrowsable(EditorBrowsableState
.Always
)]
2729 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
2732 return this.bounds
.X
;
2736 SetBounds(value, bounds
.Y
, bounds
.Width
, bounds
.Height
, BoundsSpecified
.X
);
2741 [MWFCategory("Layout")]
2742 public Point Location
{
2744 return new Point(bounds
.X
, bounds
.Y
);
2748 SetBounds(value.X
, value.Y
, bounds
.Width
, bounds
.Height
, BoundsSpecified
.Location
);
2753 [Localizable (true)]
2754 public Padding Margin
{
2755 get { return this.margin; }
2757 if (this.margin
!= value) {
2758 this.margin
= value;
2759 OnMarginChanged (EventArgs
.Empty
);
2766 public string Name
{
2778 public Padding Padding
{
2784 if (padding
!= value) {
2786 OnPaddingChanged (EventArgs
.Empty
);
2794 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
2795 public Control Parent
{
2801 if (value == this) {
2802 throw new ArgumentException("A circular control reference has been made. A control cannot be owned or parented to itself.");
2805 if (parent
!=value) {
2807 parent
.Controls
.Remove(this);
2812 value.Controls
.Add(this);
2819 public Size PreferredSize
{
2820 get { return this.GetPreferredSize (Size.Empty); }
2824 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
2826 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
2827 public string ProductName
{
2829 Type t
= typeof (AssemblyProductAttribute
);
2830 Assembly assembly
= GetType().Module
.Assembly
;
2831 object [] attrs
= assembly
.GetCustomAttributes (t
, false);
2832 AssemblyProductAttribute a
= null;
2833 // On MS we get a NullRefException if product attribute is not
2835 if (attrs
!= null && attrs
.Length
> 0)
2836 a
= (AssemblyProductAttribute
) attrs
[0];
2838 return GetType ().Namespace
;
2844 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
2846 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
2847 public string ProductVersion
{
2849 Type t
= typeof (AssemblyVersionAttribute
);
2850 Assembly assembly
= GetType().Module
.Assembly
;
2851 object [] attrs
= assembly
.GetCustomAttributes (t
, false);
2852 if (attrs
== null || attrs
.Length
< 1)
2854 return ((AssemblyVersionAttribute
)attrs
[0]).Version
;
2858 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
2860 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
2861 public bool RecreatingHandle
{
2863 return is_recreating
;
2867 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
2869 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
2870 public Region Region
{
2876 if (clip_region
!= value) {
2877 if (value != null && IsHandleCreated
)
2878 XplatUI
.SetClipRegion(Handle
, value);
2880 clip_region
= value;
2883 OnRegionChanged (EventArgs
.Empty
);
2889 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
2891 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
2894 return this.bounds
.X
+this.bounds
.Width
;
2898 [AmbientValue(RightToLeft
.Inherit
)]
2900 [MWFCategory("Appearance")]
2901 public virtual RightToLeft RightToLeft
{
2903 if (right_to_left
== RightToLeft
.Inherit
) {
2905 return parent
.RightToLeft
;
2907 return RightToLeft
.No
; // default value
2909 return right_to_left
;
2913 if (value != right_to_left
) {
2914 right_to_left
= value;
2915 OnRightToLeftChanged(EventArgs
.Empty
);
2921 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
2922 public override ISite Site
{
2930 if (value != null) {
2931 AmbientProperties ap
= (AmbientProperties
) value.GetService (typeof (AmbientProperties
));
2933 BackColor
= ap
.BackColor
;
2934 ForeColor
= ap
.ForeColor
;
2943 [MWFCategory("Layout")]
2946 return new Size(Width
, Height
);
2950 SetBounds(bounds
.X
, bounds
.Y
, value.Width
, value.Height
, BoundsSpecified
.Size
);
2955 [MergableProperty(false)]
2956 [MWFCategory("Behavior")]
2957 public int TabIndex
{
2959 if (tab_index
!= -1) {
2966 if (tab_index
!= value) {
2968 OnTabIndexChanged(EventArgs
.Empty
);
2974 [DefaultValue(true)]
2975 [MWFCategory("Behavior")]
2976 public bool TabStop
{
2982 if (tab_stop
!= value) {
2984 OnTabStopChanged(EventArgs
.Empty
);
2989 [Localizable(false)]
2991 [TypeConverter(typeof(StringConverter
))]
2992 [DefaultValue(null)]
2993 [MWFCategory("Data")]
3000 control_tag
= value;
3006 [BindableAttribute(true)]
3007 [MWFCategory("Appearance")]
3008 public virtual string Text
{
3010 // Our implementation ignores ControlStyles.CacheText - we always cache
3015 if (value == null) {
3016 value = String
.Empty
;
3021 if (IsHandleCreated
) {
3022 /* we need to call .SetWindowStyle here instead of just .Text
3023 because the presence/absence of Text (== "" or not) can cause
3024 other window style things to appear/disappear */
3025 XplatUI
.SetWindowStyle(window
.Handle
, CreateParams
);
3026 XplatUI
.Text(Handle
, text
);
3028 OnTextChanged (EventArgs
.Empty
);
3033 [EditorBrowsable(EditorBrowsableState
.Always
)]
3035 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
3038 return this.bounds
.Y
;
3042 SetBounds(bounds
.X
, value, bounds
.Width
, bounds
.Height
, BoundsSpecified
.Y
);
3046 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
3048 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
3049 public Control TopLevelControl
{
3053 while (p
.parent
!= null) {
3057 return p
is Form
? p
: null;
3062 [MWFCategory("Behavior")]
3063 public bool Visible
{
3067 } else if (parent
!= null) {
3068 return parent
.Visible
;
3075 SetVisibleCore(value);
3079 [EditorBrowsable(EditorBrowsableState
.Always
)]
3081 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
3084 return this.bounds
.Width
;
3088 SetBounds(bounds
.X
, bounds
.Y
, value, bounds
.Height
, BoundsSpecified
.Width
);
3092 [EditorBrowsable(EditorBrowsableState
.Never
)]
3094 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
3095 public IWindowTarget WindowTarget
{
3096 get { return window_target; }
3097 set { window_target = value; }
3099 #endregion // Public Instance Properties
3101 #region Protected Instance Properties
3102 protected virtual CreateParams CreateParams
{
3104 CreateParams create_params
= new CreateParams();
3107 create_params
.Caption
= Text
;
3110 create_params
.Caption
= text
;
3114 create_params
.X
= Left
;
3117 create_params
.X
= this.bounds
.X
;
3121 create_params
.Y
= Top
;
3124 create_params
.Y
= this.bounds
.Y
;
3128 create_params
.Width
= Width
;
3131 create_params
.Width
= this.bounds
.Width
;
3135 create_params
.Height
= Height
;
3138 create_params
.Height
= this.bounds
.Height
;
3142 create_params
.ClassName
= XplatUI
.DefaultClassName
;
3143 create_params
.ClassStyle
= (int)(XplatUIWin32
.ClassStyle
.CS_OWNDC
| XplatUIWin32
.ClassStyle
.CS_DBLCLKS
);
3144 create_params
.ExStyle
= 0;
3145 create_params
.Param
= 0;
3148 create_params
.ExStyle
|= (int)WindowExStyles
.WS_EX_ACCEPTFILES
;
3151 if ((parent
!=null) && (parent
.IsHandleCreated
)) {
3152 create_params
.Parent
= parent
.Handle
;
3155 create_params
.Style
= (int)WindowStyles
.WS_CHILD
| (int)WindowStyles
.WS_CLIPCHILDREN
| (int)WindowStyles
.WS_CLIPSIBLINGS
;
3158 create_params
.Style
|= (int)WindowStyles
.WS_VISIBLE
;
3162 create_params
.Style
|= (int)WindowStyles
.WS_DISABLED
;
3165 switch (border_style
) {
3166 case BorderStyle
.FixedSingle
:
3167 create_params
.Style
|= (int) WindowStyles
.WS_BORDER
;
3169 case BorderStyle
.Fixed3D
:
3170 create_params
.ExStyle
|= (int) WindowExStyles
.WS_EX_CLIENTEDGE
;
3174 create_params
.control
= this;
3176 return create_params
;
3181 protected virtual Cursor DefaultCursor { get { return Cursors.Default; }
}
3184 protected virtual ImeMode DefaultImeMode
{
3186 return ImeMode
.Inherit
;
3191 protected virtual Padding DefaultMargin
{
3192 get { return new Padding (3); }
3195 protected virtual Size DefaultMaximumSize { get { return new Size (); }
}
3196 protected virtual Size DefaultMinimumSize { get { return new Size (); }
}
3197 protected virtual Padding DefaultPadding { get { return new Padding (); }
}
3200 protected virtual Size DefaultSize
{
3202 return new Size(0, 0);
3206 protected int FontHeight
{
3218 protected bool RenderRightToLeft
{
3220 return (this.right_to_left
== RightToLeft
.Yes
);
3224 protected bool ResizeRedraw
{
3226 return GetStyle(ControlStyles
.ResizeRedraw
);
3230 SetStyle(ControlStyles
.ResizeRedraw
, value);
3234 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
3236 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
3237 protected virtual bool ShowFocusCues
{
3243 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
3245 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
3249 protected bool ShowKeyboardCues
{
3254 #endregion // Protected Instance Properties
3256 #region Public Static Methods
3257 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
3258 public static Control
FromChildHandle(IntPtr handle
) {
3259 return Control
.ControlNativeWindow
.ControlFromChildHandle (handle
);
3262 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
3263 public static Control
FromHandle(IntPtr handle
) {
3264 return Control
.ControlNativeWindow
.ControlFromHandle(handle
);
3267 public static bool IsMnemonic(char charCode
, string text
) {
3270 amp
= text
.IndexOf('&');
3273 if (amp
+ 1 < text
.Length
) {
3274 if (text
[amp
+ 1] != '&') {
3275 if (Char
.ToUpper(charCode
) == Char
.ToUpper(text
.ToCharArray(amp
+ 1, 1)[0])) {
3285 #region Protected Static Methods
3286 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
3287 protected static bool ReflectMessage(IntPtr hWnd
, ref Message m
) {
3290 c
= Control
.FromHandle(hWnd
);
3300 #region Public Instance Methods
3301 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
3302 public IAsyncResult
BeginInvoke(Delegate method
) {
3303 object [] prms
= null;
3304 if (method
is EventHandler
)
3305 prms
= new object [] { this, EventArgs.Empty }
;
3306 return BeginInvokeInternal(method
, prms
);
3309 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
3311 public IAsyncResult
BeginInvoke (Delegate method
, params object[] args
)
3313 public IAsyncResult
BeginInvoke (Delegate method
, object[] args
)
3316 return BeginInvokeInternal (method
, args
);
3319 public void BringToFront() {
3320 if (parent
!= null) {
3321 parent
.child_controls
.SetChildIndex(this, 0);
3323 else if (IsHandleCreated
) {
3324 XplatUI
.SetZOrder(Handle
, IntPtr
.Zero
, false, false);
3328 public bool Contains(Control ctl
) {
3329 while (ctl
!= null) {
3338 public void CreateControl () {
3340 throw new ObjectDisposedException(GetType().FullName
.ToString());
3350 if (!IsHandleCreated
) {
3357 // Create all of our children when we are created.
3358 // The child should fire it's OnLoad before the parents, however
3359 // if the child checks Parent.Created in it's OnCreateControl, the
3360 // parent is already created.
3361 foreach (Control c
in Controls
)
3365 if (binding_context
== null && parent
!= null) {
3366 OnBindingContextChanged(EventArgs
.Empty
);
3373 public Graphics
CreateGraphics() {
3374 if (!IsHandleCreated
) {
3375 this.CreateHandle();
3377 return Graphics
.FromHwnd(this.window
.Handle
);
3380 public DragDropEffects
DoDragDrop(object data
, DragDropEffects allowedEffects
) {
3381 if (IsHandleCreated
)
3382 return XplatUI
.StartDrag(Handle
, data
, allowedEffects
);
3384 return DragDropEffects
.None
;
3387 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
3388 public object EndInvoke (IAsyncResult async_result
) {
3389 AsyncMethodResult result
= (AsyncMethodResult
) async_result
;
3390 return result
.EndInvoke ();
3393 public Form
FindForm() {
3406 [EditorBrowsable (EditorBrowsableState
.Advanced
)]
3408 public bool Focus() {
3409 return FocusInternal (false);
3412 internal virtual bool FocusInternal (bool skip_check
) {
3413 if (skip_check
|| (CanFocus
&& IsHandleCreated
&& !has_focus
&& !is_focusing
)) {
3416 is_focusing
= false;
3421 internal Control
GetRealChildAtPoint (Point pt
) {
3422 if (!IsHandleCreated
)
3425 foreach (Control control
in child_controls
.GetAllControls ()) {
3426 if (control
.Bounds
.Contains (PointToClient (pt
))) {
3427 Control child
= control
.GetRealChildAtPoint (pt
);
3438 public Control
GetChildAtPoint(Point pt
) {
3439 // MS's version causes the handle to be created. The stack trace shows that get_Handle is called here, but
3440 // we'll just call CreateHandle instead.
3441 if (!IsHandleCreated
)
3444 // Microsoft's version of this function doesn't seem to work, so I can't check
3445 // if we only consider children or also grandchildren, etc.
3446 // I'm gonna say 'children only'
3447 for (int i
=0; i
<child_controls
.Count
; i
++) {
3448 if (child_controls
[i
].Bounds
.Contains(pt
)) {
3449 return child_controls
[i
];
3455 public IContainerControl
GetContainerControl() {
3456 Control current
= this;
3458 while (current
!=null) {
3459 if ((current
is IContainerControl
) && ((current
.control_style
& ControlStyles
.ContainerControl
)!=0)) {
3460 return (IContainerControl
)current
;
3462 current
= current
.parent
;
3467 public Control
GetNextControl(Control ctl
, bool forward
) {
3469 if (!this.Contains(ctl
)) {
3474 ctl
= FindControlForward(this, ctl
);
3477 ctl
= FindControlBackward(this, ctl
);
3487 [EditorBrowsable (EditorBrowsableState
.Advanced
)]
3488 public virtual Size
GetPreferredSize (Size proposedSize
) {
3489 Size retsize
= this.explicit_bounds
.Size
;
3491 // If we're bigger than the MaximumSize, fix that
3492 if (this.maximum_size
.Width
!= 0 && retsize
.Width
> this.maximum_size
.Width
)
3493 retsize
.Width
= this.maximum_size
.Width
;
3494 if (this.maximum_size
.Height
!= 0 && retsize
.Height
> this.maximum_size
.Height
)
3495 retsize
.Height
= this.maximum_size
.Height
;
3497 // If we're smaller than the MinimumSize, fix that
3498 if (this.minimum_size
.Width
!= 0 && retsize
.Width
< this.minimum_size
.Width
)
3499 retsize
.Width
= this.minimum_size
.Width
;
3500 if (this.minimum_size
.Height
!= 0 && retsize
.Height
< this.minimum_size
.Height
)
3501 retsize
.Height
= this.minimum_size
.Height
;
3507 public void Hide() {
3508 this.Visible
= false;
3511 public void Invalidate() {
3512 Invalidate(ClientRectangle
, false);
3515 public void Invalidate(bool invalidateChildren
) {
3516 Invalidate(ClientRectangle
, invalidateChildren
);
3519 public void Invalidate(System
.Drawing
.Rectangle rc
) {
3520 Invalidate(rc
, false);
3523 public void Invalidate(System
.Drawing
.Rectangle rc
, bool invalidateChildren
) {
3524 // Win32 invalidates control including when Width and Height is equal 0
3525 // or is not visible, only Paint event must be care about this.
3526 if (!IsHandleCreated
)
3529 if (rc
.Width
> 0 && rc
.Height
> 0) {
3531 NotifyInvalidate(rc
);
3533 XplatUI
.Invalidate(Handle
, rc
, false);
3535 if (invalidateChildren
) {
3536 Control
[] controls
= child_controls
.GetAllControls ();
3537 for (int i
=0; i
<controls
.Length
; i
++)
3538 controls
[i
].Invalidate ();
3541 OnInvalidated(new InvalidateEventArgs(rc
));
3544 public void Invalidate(System
.Drawing
.Region region
) {
3545 Invalidate(region
, false);
3548 public void Invalidate(System
.Drawing
.Region region
, bool invalidateChildren
) {
3549 RectangleF bounds
= region
.GetBounds (CreateGraphics ());
3550 Invalidate (new Rectangle ((int) bounds
.X
, (int) bounds
.Y
, (int) bounds
.Width
, (int) bounds
.Height
),
3551 invalidateChildren
);
3554 public object Invoke (Delegate method
) {
3555 object [] prms
= null;
3556 if (method
is EventHandler
)
3557 prms
= new object [] { this, EventArgs.Empty }
;
3559 return Invoke(method
, prms
);
3562 public object Invoke (Delegate method
, params object [] args
) {
3564 public object Invoke (Delegate method
, object[] args
) {
3566 Control control
= FindControlToInvokeOn ();
3568 if (!this.InvokeRequired
) {
3569 return method
.DynamicInvoke(args
);
3572 IAsyncResult result
= BeginInvokeInternal (method
, args
, control
);
3573 return EndInvoke(result
);
3576 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
3577 public void PerformLayout() {
3578 PerformLayout(null, null);
3581 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
3582 public void PerformLayout(Control affectedControl
, string affectedProperty
) {
3583 LayoutEventArgs levent
= new LayoutEventArgs(affectedControl
, affectedProperty
);
3585 if (layout_suspended
> 0) {
3586 layout_pending
= true;
3590 layout_pending
= false;
3592 // Prevent us from getting messed up
3595 // Perform all Dock and Anchor calculations
3600 // Need to make sure we decremend layout_suspended
3606 public Point
PointToClient (Point p
) {
3610 XplatUI
.ScreenToClient (Handle
, ref x
, ref y
);
3612 return new Point (x
, y
);
3615 public Point
PointToScreen(Point p
) {
3619 XplatUI
.ClientToScreen(Handle
, ref x
, ref y
);
3621 return new Point(x
, y
);
3624 public virtual bool PreProcessMessage(ref Message msg
) {
3625 return InternalPreProcessMessage (ref msg
);
3628 internal virtual bool InternalPreProcessMessage (ref Message msg
) {
3631 if ((msg
.Msg
== (int)Msg
.WM_KEYDOWN
) || (msg
.Msg
== (int)Msg
.WM_SYSKEYDOWN
)) {
3632 key_data
= (Keys
)msg
.WParam
.ToInt32() | XplatUI
.State
.ModifierKeys
;
3634 if (!ProcessCmdKey(ref msg
, key_data
)) {
3635 if (IsInputKey(key_data
)) {
3639 return ProcessDialogKey(key_data
);
3643 } else if (msg
.Msg
== (int)Msg
.WM_CHAR
) {
3644 if (IsInputChar((char)msg
.WParam
)) {
3647 return ProcessDialogChar((char)msg
.WParam
);
3648 } else if (msg
.Msg
== (int)Msg
.WM_SYSCHAR
) {
3649 return ProcessDialogChar((char)msg
.WParam
);
3654 public Rectangle
RectangleToClient(Rectangle r
) {
3655 return new Rectangle(PointToClient(r
.Location
), r
.Size
);
3658 public Rectangle
RectangleToScreen(Rectangle r
) {
3659 return new Rectangle(PointToScreen(r
.Location
), r
.Size
);
3662 public virtual void Refresh() {
3663 if (IsHandleCreated
&& Visible
) {
3665 XplatUI
.UpdateWindow(window
.Handle
);
3667 Control
[] controls
= child_controls
.GetAllControls ();
3668 for (int i
=0; i
< controls
.Length
; i
++) {
3669 controls
[i
].Refresh();
3675 [EditorBrowsable(EditorBrowsableState
.Never
)]
3676 public virtual void ResetBackColor() {
3677 BackColor
= Color
.Empty
;
3680 [EditorBrowsable(EditorBrowsableState
.Never
)]
3681 public void ResetBindings() {
3682 if (data_bindings
!= null)
3683 data_bindings
.Clear();
3686 [EditorBrowsable(EditorBrowsableState
.Never
)]
3687 public virtual void ResetCursor() {
3691 [EditorBrowsable(EditorBrowsableState
.Never
)]
3692 public virtual void ResetFont() {
3696 [EditorBrowsable(EditorBrowsableState
.Never
)]
3697 public virtual void ResetForeColor() {
3698 foreground_color
= Color
.Empty
;
3701 [EditorBrowsable(EditorBrowsableState
.Never
)]
3702 public void ResetImeMode() {
3703 ime_mode
= DefaultImeMode
;
3706 [EditorBrowsable(EditorBrowsableState
.Never
)]
3707 public virtual void ResetRightToLeft() {
3708 right_to_left
= RightToLeft
.Inherit
;
3711 public virtual void ResetText() {
3712 text
= String
.Empty
;
3715 public void ResumeLayout() {
3716 ResumeLayout (true);
3719 public void ResumeLayout(bool performLayout
) {
3720 if (layout_suspended
> 0) {
3724 if (layout_suspended
== 0) {
3725 if (performLayout
&& layout_pending
) {
3731 [EditorBrowsable (EditorBrowsableState
.Never
)]
3734 public void Scale(float ratio
) {
3735 ScaleCore(ratio
, ratio
);
3739 [EditorBrowsable (EditorBrowsableState
.Never
)]
3742 public void Scale(float dx
, float dy
) {
3747 [EditorBrowsable (EditorBrowsableState
.Advanced
)]
3748 public void Scale(SizeF factor
) {
3749 ScaleCore(factor
.Width
, factor
.Height
);
3753 public void Select() {
3754 Select(false, false);
3758 private void printTree(Control c
, string t
) {
3759 foreach(Control i
in c
.child_controls
) {
3760 Console
.WriteLine ("{2}{0}.TabIndex={1}", i
, i
.tab_index
, t
);
3761 printTree (i
, t
+"\t");
3765 public bool SelectNextControl(Control ctl
, bool forward
, bool tabStopOnly
, bool nested
, bool wrap
) {
3769 Console
.WriteLine("{0}", this.FindForm());
3770 printTree(this, "\t");
3773 if (!this.Contains(ctl
) || (!nested
&& (ctl
.parent
!= this))) {
3778 c
= GetNextControl(c
, forward
);
3787 if (c
.CanSelect
&& ((c
.parent
== this) || nested
) && (c
.tab_stop
|| !tabStopOnly
)) {
3788 c
.Select (true, true);
3791 } while (c
!= ctl
); // If we wrap back to ourselves we stop
3796 public void SendToBack() {
3797 if (parent
!= null) {
3798 parent
.child_controls
.SetChildIndex(this, parent
.child_controls
.Count
);
3802 public void SetBounds(int x
, int y
, int width
, int height
) {
3803 SetBounds(x
, y
, width
, height
, BoundsSpecified
.All
);
3806 public void SetBounds(int x
, int y
, int width
, int height
, BoundsSpecified specified
) {
3807 // SetBoundsCore is really expensive to call, so we want to avoid it if we can.
3808 // We can avoid it if:
3809 // - The requested dimensions are the same as our current dimensions
3811 // - Any BoundsSpecified is the same as our current explicit_size
3812 if (bounds
.X
!= x
|| (explicit_bounds
.X
!= x
&& (specified
& BoundsSpecified
.X
) == BoundsSpecified
.X
))
3813 SetBoundsCore (x
, y
, width
, height
, specified
);
3814 else if (bounds
.Y
!= y
|| (explicit_bounds
.Y
!= y
&& (specified
& BoundsSpecified
.Y
) == BoundsSpecified
.Y
))
3815 SetBoundsCore (x
, y
, width
, height
, specified
);
3816 else if (bounds
.Width
!= width
|| (explicit_bounds
.Width
!= width
&& (specified
& BoundsSpecified
.Width
) == BoundsSpecified
.Width
))
3817 SetBoundsCore (x
, y
, width
, height
, specified
);
3818 else if (bounds
.Height
!= height
|| (explicit_bounds
.Height
!= height
&& (specified
& BoundsSpecified
.Height
) == BoundsSpecified
.Height
))
3819 SetBoundsCore (x
, y
, width
, height
, specified
);
3824 parent
.PerformLayout(this, "Bounds");
3827 public void Show () {
3828 this.Visible
= true;
3831 public void SuspendLayout() {
3835 public void Update() {
3836 if (IsHandleCreated
) {
3837 XplatUI
.UpdateWindow(window
.Handle
);
3840 #endregion // Public Instance Methods
3842 #region Protected Instance Methods
3843 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
3844 protected void AccessibilityNotifyClients(AccessibleEvents accEvent
, int childID
) {
3845 // turns out this method causes handle
3846 // creation in 1.1. at first I thought this
3847 // would be accomplished just by using
3848 // get_AccessibilityObject, which would route
3849 // through CreateAccessibilityInstance, which
3850 // calls CreateControl. This isn't the case,
3851 // though (as overriding
3852 // CreateAccessibilityInstance and adding a
3853 // CWL shows nothing. So we fudge it and put
3854 // a CreateHandle here.
3860 if (accessibility_object
!= null && accessibility_object
is ControlAccessibleObject
)
3861 ((ControlAccessibleObject
)accessibility_object
).NotifyClients (accEvent
, childID
);
3864 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
3865 protected virtual AccessibleObject
CreateAccessibilityInstance() {
3867 return new Control
.ControlAccessibleObject(this);
3870 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
3871 protected virtual ControlCollection
CreateControlsInstance() {
3872 return new ControlCollection(this);
3875 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
3876 protected virtual void CreateHandle() {
3878 throw new ObjectDisposedException(GetType().FullName
.ToString());
3881 if (IsHandleCreated
&& !is_recreating
) {
3885 CreateParams create_params
= CreateParams
;
3886 window
.CreateHandle(create_params
);
3888 if (window
.Handle
!= IntPtr
.Zero
) {
3889 creator_thread
= Thread
.CurrentThread
;
3891 XplatUI
.EnableWindow(window
.Handle
, is_enabled
);
3893 if (clip_region
!= null) {
3894 XplatUI
.SetClipRegion(window
.Handle
, clip_region
);
3897 // Set our handle with our parent
3898 if ((parent
!= null) && (parent
.IsHandleCreated
)) {
3899 XplatUI
.SetParent(window
.Handle
, parent
.Handle
);
3903 XplatUI
.SetAllowDrop (window
.Handle
, allow_drop
);
3905 // Find out where the window manager placed us
3906 if ((CreateParams
.Style
& (int)WindowStyles
.WS_CHILD
) != 0) {
3907 XplatUI
.SetBorderStyle(window
.Handle
, (FormBorderStyle
)border_style
);
3913 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
3914 protected virtual void DefWndProc(ref Message m
) {
3915 window
.DefWndProc(ref m
);
3918 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
3919 protected virtual void DestroyHandle() {
3920 if (IsHandleCreated
) {
3921 if (window
!= null) {
3922 window
.DestroyHandle();
3928 protected virtual AccessibleObject
GetAccessibilityObjectById (int objectId
)
3930 // XXX need to implement this.
3935 protected internal bool GetStyle(ControlStyles flag
) {
3936 return (control_style
& flag
) != 0;
3939 protected bool GetTopLevel() {
3943 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
3944 protected virtual void InitLayout() {
3948 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
3949 protected void InvokeGotFocus(Control toInvoke
, EventArgs e
) {
3950 toInvoke
.OnGotFocus(e
);
3953 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
3954 protected void InvokeLostFocus(Control toInvoke
, EventArgs e
) {
3955 toInvoke
.OnLostFocus(e
);
3958 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
3959 protected void InvokeOnClick(Control toInvoke
, EventArgs e
) {
3960 toInvoke
.OnClick(e
);
3963 protected void InvokePaint(Control toInvoke
, PaintEventArgs e
) {
3964 toInvoke
.OnPaint(e
);
3967 protected void InvokePaintBackground(Control toInvoke
, PaintEventArgs e
) {
3968 toInvoke
.OnPaintBackground(e
);
3971 protected virtual bool IsInputChar (char charCode
) {
3972 // XXX on MS.NET this method causes the handle to be created..
3973 if (!IsHandleCreated
)
3979 protected virtual bool IsInputKey (Keys keyData
) {
3980 // Doc says this one calls IsInputChar; not sure what to do with that
3984 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
3985 protected virtual void NotifyInvalidate(Rectangle invalidatedArea
) {
3989 protected virtual bool ProcessCmdKey(ref Message msg
, Keys keyData
) {
3990 if ((context_menu
!= null) && context_menu
.ProcessCmdKey(ref msg
, keyData
)) {
3994 if (parent
!= null) {
3995 return parent
.ProcessCmdKey(ref msg
, keyData
);
4001 protected virtual bool ProcessDialogChar(char charCode
) {
4002 if (parent
!= null) {
4003 return parent
.ProcessDialogChar (charCode
);
4009 protected virtual bool ProcessDialogKey (Keys keyData
) {
4010 if (parent
!= null) {
4011 return parent
.ProcessDialogKey (keyData
);
4017 protected virtual bool ProcessKeyEventArgs (ref Message msg
) {
4018 KeyEventArgs key_event
;
4021 case (int)Msg
.WM_SYSKEYDOWN
:
4022 case (int)Msg
.WM_KEYDOWN
: {
4023 key_event
= new KeyEventArgs ((Keys
)msg
.WParam
.ToInt32 ());
4024 OnKeyDown (key_event
);
4025 return key_event
.Handled
;
4028 case (int)Msg
.WM_SYSKEYUP
:
4029 case (int)Msg
.WM_KEYUP
: {
4030 key_event
= new KeyEventArgs ((Keys
)msg
.WParam
.ToInt32 ());
4031 OnKeyUp (key_event
);
4032 return key_event
.Handled
;
4035 case (int)Msg
.WM_SYSCHAR
:
4036 case (int)Msg
.WM_CHAR
: {
4037 KeyPressEventArgs key_press_event
;
4039 key_press_event
= new KeyPressEventArgs((char)msg
.WParam
);
4040 OnKeyPress(key_press_event
);
4042 msg
.WParam
= (IntPtr
)key_press_event
.KeyChar
;
4044 return key_press_event
.Handled
;
4055 protected internal virtual bool ProcessKeyMessage(ref Message msg
) {
4056 if (parent
!= null) {
4057 if (parent
.ProcessKeyPreview(ref msg
)) {
4062 return ProcessKeyEventArgs(ref msg
);
4065 protected virtual bool ProcessKeyPreview(ref Message msg
) {
4066 if (parent
!= null) {
4067 return parent
.ProcessKeyPreview(ref msg
);
4073 protected virtual bool ProcessMnemonic(char charCode
) {
4078 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4079 protected void RaiseDragEvent(object key
, DragEventArgs e
) {
4083 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4084 protected void RaiseKeyEvent(object key
, KeyEventArgs e
) {
4088 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4089 protected void RaiseMouseEvent(object key
, MouseEventArgs e
) {
4093 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4094 protected void RaisePaintEvent(object key
, PaintEventArgs e
) {
4098 private void SetIsRecreating () {
4101 foreach (Control c
in Controls
.GetAllControls()) {
4102 c
.SetIsRecreating ();
4106 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4107 protected void RecreateHandle() {
4108 if (!IsHandleCreated
)
4112 Console
.WriteLine("Recreating control {0}", XplatUI
.Window(window
.Handle
));
4117 if (IsHandleCreated
) {
4119 Console
.WriteLine(" + handle is created, destroying it.");
4122 // WM_DESTROY will CreateHandle for us
4125 Console
.WriteLine(" + handle is not created, creating it.");
4133 is_recreating
= false;
4135 Console
.WriteLine (" + new handle = {0:X}", Handle
.ToInt32());
4141 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4142 protected void ResetMouseEventArgs() {
4146 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4147 protected ContentAlignment
RtlTranslateAlignment(ContentAlignment align
) {
4148 if (right_to_left
== RightToLeft
.No
) {
4153 case ContentAlignment
.TopLeft
: {
4154 return ContentAlignment
.TopRight
;
4157 case ContentAlignment
.TopRight
: {
4158 return ContentAlignment
.TopLeft
;
4161 case ContentAlignment
.MiddleLeft
: {
4162 return ContentAlignment
.MiddleRight
;
4165 case ContentAlignment
.MiddleRight
: {
4166 return ContentAlignment
.MiddleLeft
;
4169 case ContentAlignment
.BottomLeft
: {
4170 return ContentAlignment
.BottomRight
;
4173 case ContentAlignment
.BottomRight
: {
4174 return ContentAlignment
.BottomLeft
;
4178 // if it's center it doesn't change
4184 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4185 protected HorizontalAlignment
RtlTranslateAlignment(HorizontalAlignment align
) {
4186 if ((right_to_left
== RightToLeft
.No
) || (align
== HorizontalAlignment
.Center
)) {
4190 if (align
== HorizontalAlignment
.Left
) {
4191 return HorizontalAlignment
.Right
;
4194 // align must be HorizontalAlignment.Right
4195 return HorizontalAlignment
.Left
;
4198 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4199 protected LeftRightAlignment
RtlTranslateAlignment(LeftRightAlignment align
) {
4200 if (right_to_left
== RightToLeft
.No
) {
4204 if (align
== LeftRightAlignment
.Left
) {
4205 return LeftRightAlignment
.Right
;
4208 // align must be LeftRightAlignment.Right;
4209 return LeftRightAlignment
.Left
;
4212 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4213 protected ContentAlignment
RtlTranslateContent(ContentAlignment align
) {
4214 return RtlTranslateAlignment(align
);
4217 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4218 protected HorizontalAlignment
RtlTranslateHorizontal(HorizontalAlignment align
) {
4219 return RtlTranslateAlignment(align
);
4222 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4223 protected LeftRightAlignment
RtlTranslateLeftRight(LeftRightAlignment align
) {
4224 return RtlTranslateAlignment(align
);
4228 [EditorBrowsable (EditorBrowsableState
.Never
)]
4230 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4232 protected virtual void ScaleCore(float dx
, float dy
) {
4238 location
= new Point((int)(Left
* dx
), (int)(Top
* dy
));
4239 size
= this.ClientSize
;
4241 if (!GetStyle(ControlStyles
.FixedWidth
)) {
4242 size
.Width
= (int)(size
.Width
* dx
);
4245 if (!GetStyle(ControlStyles
.FixedHeight
)) {
4246 size
.Height
= (int)(size
.Height
* dy
);
4249 SetBounds(location
.X
, location
.Y
, size
.Width
, size
.Height
, BoundsSpecified
.All
);
4251 /* Now scale our children */
4252 Control
[] controls
= child_controls
.GetAllControls ();
4253 for (int i
=0; i
< controls
.Length
; i
++) {
4254 controls
[i
].Scale(dx
, dy
);
4260 protected virtual void Select(bool directed
, bool forward
) {
4261 IContainerControl container
;
4263 container
= GetContainerControl();
4264 if (container
!= null && (Control
)container
!= this)
4265 container
.ActiveControl
= this;
4268 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4269 protected virtual void SetBoundsCore(int x
, int y
, int width
, int height
, BoundsSpecified specified
) {
4270 Rectangle old_explicit
= explicit_bounds
;
4271 Rectangle new_bounds
= new Rectangle (x
, y
, width
, height
);
4273 // SetBoundsCore updates the Win32 control itself. UpdateBounds updates the controls variables and fires events, I'm guessing - pdb
4274 if (IsHandleCreated
) {
4275 XplatUI
.SetWindowPos(Handle
, x
, y
, width
, height
);
4277 // Win32 automatically changes negative width/height to 0.
4278 // The control has already been sent a WM_WINDOWPOSCHANGED message and it has the correct
4279 // data, but it'll be overwritten when we call UpdateBounds unless we get the updated
4281 if (width
< 0 || height
< 0) {
4283 XplatUI
.GetWindowPos(Handle
, this is Form
, out ix
, out iy
, out width
, out height
, out cw
, out ch
);
4287 // BoundsSpecified tells us which variables were programatic (user-set).
4288 // We need to store those in the explicit bounds
4289 if ((specified
& BoundsSpecified
.X
) == BoundsSpecified
.X
)
4290 explicit_bounds
.X
= new_bounds
.X
;
4292 explicit_bounds
.X
= old_explicit
.X
;
4294 if ((specified
& BoundsSpecified
.Y
) == BoundsSpecified
.Y
)
4295 explicit_bounds
.Y
= new_bounds
.Y
;
4297 explicit_bounds
.Y
= old_explicit
.Y
;
4299 if ((specified
& BoundsSpecified
.Width
) == BoundsSpecified
.Width
)
4300 explicit_bounds
.Width
= new_bounds
.Width
;
4302 explicit_bounds
.Width
= old_explicit
.Width
;
4304 if ((specified
& BoundsSpecified
.Height
) == BoundsSpecified
.Height
)
4305 explicit_bounds
.Height
= new_bounds
.Height
;
4307 explicit_bounds
.Height
= old_explicit
.Height
;
4309 // We need to store the explicit bounds because UpdateBounds is always going
4310 // to change it, and we have to fix it. However, UpdateBounds also calls
4311 // OnLocationChanged, OnSizeChanged, and OnClientSizeChanged. The user can
4312 // override those or use those events to change the size explicitly, and we
4313 // can't undo those changes. So if the bounds after calling UpdateBounds are
4314 // the same as the ones we sent it, we need to fix the explicit bounds. If
4315 // it's not the same as we sent UpdateBounds, then someone else changed it, and
4316 // we better not mess it up. Fun stuff.
4317 Rectangle stored_explicit_bounds
= explicit_bounds
;
4319 UpdateBounds(x
, y
, width
, height
);
4321 if (explicit_bounds
.X
== x
)
4322 explicit_bounds
.X
= stored_explicit_bounds
.X
;
4324 if (explicit_bounds
.Y
== y
)
4325 explicit_bounds
.Y
= stored_explicit_bounds
.Y
;
4327 if (explicit_bounds
.Width
== width
)
4328 explicit_bounds
.Width
= stored_explicit_bounds
.Width
;
4330 if (explicit_bounds
.Height
== height
)
4331 explicit_bounds
.Height
= stored_explicit_bounds
.Height
;
4336 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4337 protected virtual void SetClientSizeCore(int x
, int y
) {
4338 Size NewSize
= InternalSizeFromClientSize (new Size (x
, y
));
4340 if (NewSize
!= Size
.Empty
)
4341 SetBounds (bounds
.X
, bounds
.Y
, NewSize
.Width
, NewSize
.Height
, BoundsSpecified
.Size
);
4344 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4345 protected internal void SetStyle(ControlStyles flag
, bool value) {
4347 control_style
|= flag
;
4349 control_style
&= ~flag
;
4353 protected void SetTopLevel(bool value) {
4354 if ((GetTopLevel() != value) && (parent
!= null)) {
4355 throw new ArgumentException ("Cannot change toplevel style of a parented control.");
4359 if (IsHandleCreated
&& value != Visible
) {
4363 // XXX MS.NET causes handle to be created here
4364 if (!IsHandleCreated
)
4367 is_toplevel
= value;
4370 protected virtual void SetVisibleCore(bool value) {
4371 if (value != is_visible
) {
4374 if (is_visible
&& ((window
.Handle
== IntPtr
.Zero
) || !is_created
)) {
4378 if (IsHandleCreated
) {
4379 XplatUI
.SetVisible (Handle
, is_visible
, true);
4381 if (is_visible
&& this is Form
) {
4382 // If we are Min or Max, we won't get a WM_SHOWWINDOW from SetWindowState,
4383 // so we need to manually create our children, and set them visible
4384 // (This normally happens in WmShowWindow.)
4385 if ((this as Form
).WindowState
!= FormWindowState
.Normal
)
4386 OnVisibleChanged (EventArgs
.Empty
);
4388 // Explicitly move Toplevel windows to where we want them;
4389 // apparently moving unmapped toplevel windows doesn't work
4390 XplatUI
.SetWindowPos(window
.Handle
, bounds
.X
, bounds
.Y
, bounds
.Width
, bounds
.Height
);
4393 if (!(this is Form
))
4394 OnVisibleChanged (EventArgs
.Empty
);
4397 OnVisibleChanged(EventArgs
.Empty
);
4402 [EditorBrowsable (EditorBrowsableState
.Advanced
)]
4408 virtual Size
SizeFromClientSize (Size clientSize
) {
4409 return InternalSizeFromClientSize (clientSize
);
4412 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4413 protected void UpdateBounds() {
4414 if (!IsHandleCreated
)
4424 XplatUI
.GetWindowPos(this.Handle
, this is Form
, out x
, out y
, out width
, out height
, out client_width
, out client_height
);
4426 UpdateBounds(x
, y
, width
, height
, client_width
, client_height
);
4429 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4430 protected void UpdateBounds(int x
, int y
, int width
, int height
) {
4434 // Calculate client rectangle
4435 rect
= new Rectangle(0, 0, 0, 0);
4438 XplatUI
.CalculateWindowRect(ref rect
, cp
, cp
.menu
, out rect
);
4439 UpdateBounds(x
, y
, width
, height
, width
- (rect
.Right
- rect
.Left
), height
- (rect
.Bottom
- rect
.Top
));
4442 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4443 protected void UpdateBounds(int x
, int y
, int width
, int height
, int clientWidth
, int clientHeight
) {
4444 // UpdateBounds only seems to set our sizes and fire events but not update the GUI window to match
4446 bool resized
= false;
4448 // Needed to generate required notifications
4449 if ((this.bounds
.X
!=x
) || (this.bounds
.Y
!=y
)) {
4453 if ((this.Bounds
.Width
!=width
) || (this.Bounds
.Height
!=height
)) {
4460 bounds
.Height
=height
;
4462 // Assume explicit bounds set. SetBoundsCore will restore old bounds
4464 explicit_bounds
= bounds
;
4466 client_size
.Width
=clientWidth
;
4467 client_size
.Height
=clientHeight
;
4470 OnLocationChanged(EventArgs
.Empty
);
4472 if (!background_color
.IsEmpty
&& background_color
.A
< byte.MaxValue
)
4477 OnSizeChanged(EventArgs
.Empty
);
4479 OnClientSizeChanged (EventArgs
.Empty
);
4484 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4485 protected void UpdateStyles() {
4486 if (!IsHandleCreated
) {
4490 XplatUI
.SetWindowStyle(window
.Handle
, CreateParams
);
4491 OnStyleChanged(EventArgs
.Empty
);
4494 private void UpdateZOrderOfChild(Control child
) {
4495 if (IsHandleCreated
&& child
.IsHandleCreated
&& (child
.parent
== this)) {
4498 index
= child_controls
.IndexOf(child
);
4501 XplatUI
.SetZOrder(child
.Handle
, child_controls
[index
- 1].Handle
, false, false);
4503 IntPtr after
= AfterTopMostControl ();
4504 if (after
!= IntPtr
.Zero
)
4505 XplatUI
.SetZOrder (child
.Handle
, after
, false, false);
4507 XplatUI
.SetZOrder (child
.Handle
, IntPtr
.Zero
, true, false);
4512 // Override this if there is a control that shall always remain on
4513 // top of other controls (such as scrollbars). If there are several
4514 // of these controls, the bottom-most should be returned.
4515 internal virtual IntPtr
AfterTopMostControl () {
4519 // internal because we need to call it from ScrollableControl.OnVisibleChanged
4520 internal void UpdateChildrenZOrder() {
4521 Control
[] controls
;
4523 if (!IsHandleCreated
) {
4527 // XXX This code is severely broken. It leaks
4528 // the "zero_sized" abstraction out of the X11
4529 // backend and into Control.cs. It'll work on
4530 // windows simply by virtue of windows never
4531 // setting that field to true.
4533 // basically what we need to guard against is
4534 // calling XplatUI.SetZOrder on an hwnd that
4535 // corresponds to an unmapped X window.
4536 controls
= child_controls
.GetAllControls ();
4538 ArrayList children_to_order
= new ArrayList ();
4540 for (int i
= 0; i
< controls
.Length
; i
++) {
4541 if (!controls
[i
].IsHandleCreated
|| !controls
[i
].VisibleInternal
)
4544 Hwnd hwnd
= Hwnd
.ObjectFromHandle (controls
[i
].Handle
);
4545 if (hwnd
.zero_sized
)
4548 children_to_order
.Add (controls
[i
]);
4551 for (int i
= 1; i
< children_to_order
.Count
; i
++) {
4552 Control upper
= (Control
)children_to_order
[i
-1];
4553 Control lower
= (Control
)children_to_order
[i
];
4555 XplatUI
.SetZOrder(lower
.Handle
, upper
.Handle
, false, false);
4559 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4560 protected void UpdateZOrder() {
4561 if (parent
!= null) {
4562 parent
.UpdateZOrderOfChild(this);
4566 protected virtual void WndProc(ref Message m
) {
4568 Console
.WriteLine("Control {0} received message {1}", window
.Handle
== IntPtr
.Zero
? this.Text
: XplatUI
.Window(window
.Handle
), m
.ToString ());
4570 if ((this.control_style
& ControlStyles
.EnableNotifyMessage
) != 0) {
4574 switch((Msg
)m
.Msg
) {
4575 case Msg
.WM_DESTROY
: {
4580 case Msg
.WM_WINDOWPOSCHANGED
: {
4581 WmWindowPosChanged(ref m
);
4585 // Nice description of what should happen when handling WM_PAINT
4586 // can be found here: http://pluralsight.com/wiki/default.aspx/Craig/FlickerFreeControlDrawing.html
4587 // and here http://msdn.microsoft.com/msdnmag/issues/06/03/WindowsFormsPerformance/
4588 case Msg
.WM_PAINT
: {
4593 // The DefWndProc will never have to handle this, we always paint the background in managed code
4594 // In theory this code would look at ControlStyles.AllPaintingInWmPaint and and call OnPaintBackground
4595 // here but it just makes things more complicated...
4596 case Msg
.WM_ERASEBKGND
: {
4597 WmEraseBackground (ref m
);
4601 case Msg
.WM_LBUTTONUP
: {
4602 WmLButtonUp (ref m
);
4606 case Msg
.WM_LBUTTONDOWN
: {
4607 WmLButtonDown (ref m
);
4611 case Msg
.WM_LBUTTONDBLCLK
: {
4612 WmLButtonDblClick (ref m
);
4616 case Msg
.WM_MBUTTONUP
: {
4617 WmMButtonUp (ref m
);
4621 case Msg
.WM_MBUTTONDOWN
: {
4622 WmMButtonDown (ref m
);
4626 case Msg
.WM_MBUTTONDBLCLK
: {
4627 WmMButtonDblClick (ref m
);
4631 case Msg
.WM_RBUTTONUP
: {
4632 WmRButtonUp (ref m
);
4636 case Msg
.WM_RBUTTONDOWN
: {
4637 WmRButtonDown (ref m
);
4641 case Msg
.WM_RBUTTONDBLCLK
: {
4642 WmRButtonDblClick (ref m
);
4646 case Msg
.WM_CONTEXTMENU
: {
4647 WmContextMenu (ref m
);
4651 case Msg
.WM_MOUSEWHEEL
: {
4652 WmMouseWheel (ref m
);
4657 case Msg
.WM_MOUSEMOVE
: {
4658 WmMouseMove (ref m
);
4662 case Msg
.WM_SHOWWINDOW
: {
4663 WmShowWindow (ref m
);
4667 case Msg
.WM_CREATE
: {
4672 case Msg
.WM_MOUSE_ENTER
: {
4673 WmMouseEnter (ref m
);
4677 case Msg
.WM_MOUSELEAVE
: {
4678 WmMouseLeave (ref m
);
4682 case Msg
.WM_MOUSEHOVER
: {
4683 WmMouseHover (ref m
);
4687 case Msg
.WM_SYSKEYUP
: {
4692 case Msg
.WM_SYSKEYDOWN
:
4693 case Msg
.WM_KEYDOWN
:
4695 case Msg
.WM_SYSCHAR
:
4706 case Msg
.WM_KILLFOCUS
: {
4707 WmKillFocus (ref m
);
4711 case Msg
.WM_SETFOCUS
: {
4716 case Msg
.WM_SYSCOLORCHANGE
: {
4717 WmSysColorChange (ref m
);
4721 case Msg
.WM_SETCURSOR
: {
4722 WmSetCursor (ref m
);
4726 case Msg
.WM_CAPTURECHANGED
: {
4727 WmCaptureChanged (ref m
);
4736 #endregion // Public Instance Methods
4740 private void WmDestroy (ref Message m
) {
4741 OnHandleDestroyed(EventArgs
.Empty
);
4743 IntPtr handle
= window
.Handle
;
4745 window
.InvalidateHandle();
4747 if (is_recreating
) {
4749 Console
.WriteLine ("Creating handle for {0:X}", handle
.ToInt32());
4753 Console
.WriteLine (" + new handle = {0:X}", Handle
.ToInt32());
4755 is_recreating
= false;
4759 private void WmWindowPosChanged (ref Message m
) {
4761 Rectangle save_bounds
= explicit_bounds
;
4763 explicit_bounds
= save_bounds
;
4764 if (GetStyle(ControlStyles
.ResizeRedraw
)) {
4771 // Nice description of what should happen when handling WM_PAINT
4772 // can be found here: http://pluralsight.com/wiki/default.aspx/Craig/FlickerFreeControlDrawing.html
4773 // and here http://msdn.microsoft.com/msdnmag/issues/06/03/WindowsFormsPerformance/
4774 private void WmPaint (ref Message m
) {
4775 PaintEventArgs paint_event
;
4777 IntPtr handle
= Handle
;
4779 paint_event
= XplatUI
.PaintEventStart (handle
, true);
4781 if (paint_event
== null)
4784 DoubleBuffer current_buffer
= null;
4785 if (UseDoubleBuffering
) {
4786 current_buffer
= GetBackBuffer ();
4787 if (!current_buffer
.InvalidRegion
.IsVisible (paint_event
.ClipRectangle
)) {
4788 // Just blit the previous image
4789 current_buffer
.Blit (paint_event
);
4790 XplatUI
.PaintEventEnd (handle
, true);
4793 current_buffer
.Start (paint_event
);
4796 if (!GetStyle(ControlStyles
.Opaque
)) {
4797 OnPaintBackground (paint_event
);
4800 // Button-derived controls choose to ignore their Opaque style, give them a chance to draw their background anyways
4801 OnPaintBackgroundInternal (paint_event
);
4803 OnPaintInternal(paint_event
);
4804 if (!paint_event
.Handled
) {
4805 OnPaint (paint_event
);
4808 if (current_buffer
!= null) {
4809 current_buffer
.End (paint_event
);
4813 XplatUI
.PaintEventEnd (handle
, true);
4816 private void WmEraseBackground (ref Message m
) {
4817 // The DefWndProc will never have to handle this, we always paint the background in managed code
4818 // In theory this code would look at ControlStyles.AllPaintingInWmPaint and and call OnPaintBackground
4819 // here but it just makes things more complicated...
4820 m
.Result
= (IntPtr
)1;
4823 private void WmLButtonUp (ref Message m
) {
4826 me
= new MouseEventArgs (FromParamToMouseButtons ((int) m
.WParam
.ToInt32()) | MouseButtons
.Left
,
4828 LowOrder ((int) m
.LParam
.ToInt32 ()), HighOrder ((int) m
.LParam
.ToInt32 ()),
4831 HandleClick(mouse_clicks
, me
);
4834 if (InternalCapture
) {
4835 InternalCapture
= false;
4838 if (mouse_clicks
> 1) {
4843 private void WmLButtonDown (ref Message m
) {
4845 Select (true, true);
4847 InternalCapture
= true;
4848 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m
.WParam
.ToInt32()),
4849 mouse_clicks
, LowOrder ((int) m
.LParam
.ToInt32 ()), HighOrder ((int) m
.LParam
.ToInt32 ()),
4853 private void WmLButtonDblClick (ref Message m
) {
4854 InternalCapture
= true;
4856 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m
.WParam
.ToInt32()),
4857 mouse_clicks
, LowOrder ((int) m
.LParam
.ToInt32 ()), HighOrder ((int) m
.LParam
.ToInt32 ()),
4861 private void WmMButtonUp (ref Message m
) {
4864 me
= new MouseEventArgs (FromParamToMouseButtons ((int) m
.WParam
.ToInt32()) | MouseButtons
.Middle
,
4866 LowOrder ((int) m
.LParam
.ToInt32 ()), HighOrder ((int) m
.LParam
.ToInt32 ()),
4869 HandleClick(mouse_clicks
, me
);
4871 if (InternalCapture
) {
4872 InternalCapture
= false;
4874 if (mouse_clicks
> 1) {
4879 private void WmMButtonDown (ref Message m
) {
4880 InternalCapture
= true;
4881 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m
.WParam
.ToInt32()),
4882 mouse_clicks
, LowOrder ((int) m
.LParam
.ToInt32 ()), HighOrder ((int) m
.LParam
.ToInt32 ()),
4886 private void WmMButtonDblClick (ref Message m
) {
4887 InternalCapture
= true;
4889 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m
.WParam
.ToInt32()),
4890 mouse_clicks
, LowOrder ((int) m
.LParam
.ToInt32 ()), HighOrder ((int) m
.LParam
.ToInt32 ()),
4894 private void WmRButtonUp (ref Message m
) {
4898 pt
= new Point(LowOrder ((int) m
.LParam
.ToInt32 ()), HighOrder ((int) m
.LParam
.ToInt32 ()));
4899 pt
= PointToScreen(pt
);
4901 me
= new MouseEventArgs (FromParamToMouseButtons ((int) m
.WParam
.ToInt32()) | MouseButtons
.Right
,
4903 LowOrder ((int) m
.LParam
.ToInt32 ()), HighOrder ((int) m
.LParam
.ToInt32 ()),
4906 HandleClick(mouse_clicks
, me
);
4909 XplatUI
.SendMessage(m
.HWnd
, Msg
.WM_CONTEXTMENU
, m
.HWnd
, (IntPtr
)(pt
.X
+ (pt
.Y
<< 16)));
4911 if (InternalCapture
) {
4912 InternalCapture
= false;
4915 if (mouse_clicks
> 1) {
4920 private void WmRButtonDown (ref Message m
) {
4921 InternalCapture
= true;
4922 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m
.WParam
.ToInt32()),
4923 mouse_clicks
, LowOrder ((int) m
.LParam
.ToInt32 ()), HighOrder ((int) m
.LParam
.ToInt32 ()),
4927 private void WmRButtonDblClick (ref Message m
) {
4928 InternalCapture
= true;
4930 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m
.WParam
.ToInt32()),
4931 mouse_clicks
, LowOrder ((int) m
.LParam
.ToInt32 ()), HighOrder ((int) m
.LParam
.ToInt32 ()),
4935 private void WmContextMenu (ref Message m
) {
4936 if (context_menu
!= null) {
4939 pt
= new Point(LowOrder ((int) m
.LParam
.ToInt32 ()), HighOrder ((int) m
.LParam
.ToInt32 ()));
4941 if (pt
.X
== -1 || pt
.Y
== -1) {
4942 pt
.X
= (this.Width
/ 2) + this.Left
;
4943 pt
.Y
= (this.Height
/ 2) + this.Top
;
4944 pt
= this.PointToScreen (pt
);
4947 context_menu
.Show (this, PointToClient (pt
));
4952 // If there isn't a regular context menu, show the Strip version
4953 if (context_menu
== null && context_menu_strip
!= null) {
4956 pt
= new Point (LowOrder ((int)m
.LParam
.ToInt32 ()), HighOrder ((int)m
.LParam
.ToInt32 ()));
4958 if (pt
.X
== -1 || pt
.Y
== -1) {
4959 pt
.X
= (this.Width
/ 2) + this.Left
;
4960 pt
.Y
= (this.Height
/2) + this.Top
;
4961 pt
= this.PointToScreen (pt
);
4964 context_menu_strip
.Show (this, PointToClient (pt
));
4971 private void WmCreate (ref Message m
) {
4972 OnHandleCreated(EventArgs
.Empty
);
4975 private void WmMouseWheel (ref Message m
) {
4977 OnMouseWheel (new MouseEventArgs (FromParamToMouseButtons ((int) m
.WParam
.ToInt32()),
4978 mouse_clicks
, LowOrder ((int) m
.LParam
.ToInt32 ()), HighOrder ((int) m
.LParam
.ToInt32 ()),
4979 HighOrder(m
.WParam
.ToInt32())));
4983 private void WmMouseMove (ref Message m
) {
4984 OnMouseMove (new MouseEventArgs (FromParamToMouseButtons ((int) m
.WParam
.ToInt32()),
4986 LowOrder ((int) m
.LParam
.ToInt32 ()), HighOrder ((int) m
.LParam
.ToInt32 ()),
4990 private void WmMouseEnter (ref Message m
) {
4995 OnMouseEnter(EventArgs
.Empty
);
4998 private void WmMouseLeave (ref Message m
) {
5000 OnMouseLeave(EventArgs
.Empty
);
5003 private void WmMouseHover (ref Message m
) {
5004 OnMouseHover(EventArgs
.Empty
);
5007 private void WmShowWindow (ref Message m
) {
5008 if (m
.WParam
.ToInt32() != 0) {
5009 if (m
.LParam
.ToInt32 () == 0) {
5012 // Make sure all our children are properly parented to us
5013 Control
[] controls
= child_controls
.GetAllControls ();
5014 for (int i
=0; i
<controls
.Length
; i
++) {
5015 if (controls
[i
].is_visible
&& controls
[i
].IsHandleCreated
)
5016 XplatUI
.SetParent(controls
[i
].Handle
, window
.Handle
);
5021 if (parent
!= null && Focused
) {
5024 // Need to start at parent, GetContainerControl might return ourselves if we're a container
5025 container
= (Control
)parent
.GetContainerControl();
5026 if (container
!= null) {
5027 container
.SelectNextControl(this, true, true, true, true);
5032 // If the form is Max/Min, it got its OnVisibleChanged in SetVisibleCore
5034 Form f
= (Form
)this;
5036 if (f
.IsMdiChild
|| f
.WindowState
== FormWindowState
.Normal
) /* XXX make sure this works for mdi forms */
5037 OnVisibleChanged(EventArgs
.Empty
);
5038 } else if (is_toplevel
)
5039 OnVisibleChanged(EventArgs
.Empty
);
5042 private void WmSysKeyUp (ref Message m
) {
5043 if (ProcessKeyMessage(ref m
)) {
5044 m
.Result
= IntPtr
.Zero
;
5048 if ((m
.WParam
.ToInt32() & (int)Keys
.KeyCode
) == (int)Keys
.Menu
) {
5052 if (form
!= null && form
.ActiveMenu
!= null) {
5053 form
.ActiveMenu
.ProcessCmdKey(ref m
, (Keys
)m
.WParam
.ToInt32());
5060 private void WmKeys (ref Message m
) {
5061 if (ProcessKeyMessage(ref m
)) {
5062 m
.Result
= IntPtr
.Zero
;
5068 private void WmHelp (ref Message m
) {
5070 if (m
.LParam
!= IntPtr
.Zero
) {
5073 hi
= new HELPINFO();
5075 hi
= (HELPINFO
) Marshal
.PtrToStructure (m
.LParam
, typeof (HELPINFO
));
5076 mouse_pos
= new Point(hi
.MousePos
.x
, hi
.MousePos
.y
);
5078 mouse_pos
= Control
.MousePosition
;
5080 OnHelpRequested(new HelpEventArgs(mouse_pos
));
5081 m
.Result
= (IntPtr
)1;
5084 private void WmKillFocus (ref Message m
) {
5085 this.has_focus
= false;
5086 OnLostFocus (EventArgs
.Empty
);
5089 private void WmSetFocus (ref Message m
) {
5091 this.has_focus
= true;
5092 OnGotFocus (EventArgs
.Empty
);
5096 private void WmSysColorChange (ref Message m
) {
5097 ThemeEngine
.Current
.ResetDefaults();
5098 OnSystemColorsChanged(EventArgs
.Empty
);
5101 private void WmSetCursor (ref Message m
) {
5102 if ((cursor
== null) || ((HitTest
)(m
.LParam
.ToInt32() & 0xffff) != HitTest
.HTCLIENT
)) {
5107 XplatUI
.SetCursor(window
.Handle
, cursor
.handle
);
5108 m
.Result
= (IntPtr
)1;
5111 private void WmCaptureChanged (ref Message m
) {
5112 is_captured
= false;
5113 OnMouseCaptureChanged (EventArgs
.Empty
);
5114 m
.Result
= (IntPtr
) 0;
5120 #region OnXXX methods
5122 protected virtual void OnAutoSizeChanged (EventArgs e
)
5124 EventHandler eh
= (EventHandler
)(Events
[AutoSizeChangedEvent
]);
5130 [EditorBrowsable (EditorBrowsableState
.Advanced
)]
5131 protected virtual void OnBackColorChanged(EventArgs e
) {
5132 EventHandler eh
= (EventHandler
)(Events
[BackColorChangedEvent
]);
5135 for (int i
=0; i
<child_controls
.Count
; i
++) child_controls
[i
].OnParentBackColorChanged(e
);
5138 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5139 protected virtual void OnBackgroundImageChanged(EventArgs e
) {
5140 EventHandler eh
= (EventHandler
)(Events
[BackgroundImageChangedEvent
]);
5143 for (int i
=0; i
<child_controls
.Count
; i
++) child_controls
[i
].OnParentBackgroundImageChanged(e
);
5147 [EditorBrowsable (EditorBrowsableState
.Advanced
)]
5148 protected virtual void OnBackgroundImageLayoutChanged (EventArgs e
)
5150 EventHandler eh
= (EventHandler
)(Events
[BackgroundImageLayoutChangedEvent
]);
5156 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5157 protected virtual void OnBindingContextChanged(EventArgs e
) {
5158 CheckDataBindings ();
5159 EventHandler eh
= (EventHandler
)(Events
[BindingContextChangedEvent
]);
5162 for (int i
=0; i
<child_controls
.Count
; i
++) child_controls
[i
].OnParentBindingContextChanged(e
);
5165 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5166 protected virtual void OnCausesValidationChanged(EventArgs e
) {
5167 EventHandler eh
= (EventHandler
)(Events
[CausesValidationChangedEvent
]);
5172 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5173 protected virtual void OnChangeUICues(UICuesEventArgs e
) {
5174 UICuesEventHandler eh
= (UICuesEventHandler
)(Events
[ChangeUICuesEvent
]);
5179 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5180 protected virtual void OnClick(EventArgs e
) {
5181 EventHandler eh
= (EventHandler
)(Events
[ClickEvent
]);
5187 [EditorBrowsable (EditorBrowsableState
.Advanced
)]
5188 protected virtual void OnClientSizeChanged (EventArgs e
)
5190 EventHandler eh
= (EventHandler
)(Events
[ClientSizeChangedEvent
]);
5196 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5197 protected virtual void OnContextMenuChanged(EventArgs e
) {
5198 EventHandler eh
= (EventHandler
)(Events
[ContextMenuChangedEvent
]);
5204 [EditorBrowsable (EditorBrowsableState
.Advanced
)]
5205 protected virtual void OnContextMenuStripChanged (EventArgs e
) {
5206 EventHandler eh
= (EventHandler
)(Events
[ContextMenuStripChangedEvent
]);
5212 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5213 protected virtual void OnControlAdded(ControlEventArgs e
) {
5214 ControlEventHandler eh
= (ControlEventHandler
)(Events
[ControlAddedEvent
]);
5219 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5220 protected virtual void OnControlRemoved(ControlEventArgs e
) {
5221 ControlEventHandler eh
= (ControlEventHandler
)(Events
[ControlRemovedEvent
]);
5226 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5227 protected virtual void OnCreateControl() {
5231 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5232 protected virtual void OnCursorChanged(EventArgs e
) {
5233 EventHandler eh
= (EventHandler
)(Events
[CursorChangedEvent
]);
5238 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5239 protected virtual void OnDockChanged(EventArgs e
) {
5240 EventHandler eh
= (EventHandler
)(Events
[DockChangedEvent
]);
5245 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5246 protected virtual void OnDoubleClick(EventArgs e
) {
5247 EventHandler eh
= (EventHandler
)(Events
[DoubleClickEvent
]);
5252 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5253 protected virtual void OnDragDrop(DragEventArgs drgevent
) {
5254 DragEventHandler eh
= (DragEventHandler
)(Events
[DragDropEvent
]);
5256 eh (this, drgevent
);
5259 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5260 protected virtual void OnDragEnter(DragEventArgs drgevent
) {
5261 DragEventHandler eh
= (DragEventHandler
)(Events
[DragEnterEvent
]);
5263 eh (this, drgevent
);
5266 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5267 protected virtual void OnDragLeave(EventArgs e
) {
5268 EventHandler eh
= (EventHandler
)(Events
[DragLeaveEvent
]);
5273 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5274 protected virtual void OnDragOver(DragEventArgs drgevent
) {
5275 DragEventHandler eh
= (DragEventHandler
)(Events
[DragOverEvent
]);
5277 eh (this, drgevent
);
5280 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5281 protected virtual void OnEnabledChanged(EventArgs e
) {
5282 if (IsHandleCreated
) {
5284 if (((Form
)this).context
== null) {
5285 XplatUI
.EnableWindow(window
.Handle
, Enabled
);
5288 XplatUI
.EnableWindow(window
.Handle
, Enabled
);
5293 EventHandler eh
= (EventHandler
)(Events
[EnabledChangedEvent
]);
5297 for (int i
=0; i
<child_controls
.Count
; i
++) {
5298 child_controls
[i
].OnParentEnabledChanged(e
);
5302 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5303 protected virtual void OnEnter(EventArgs e
) {
5304 EventHandler eh
= (EventHandler
)(Events
[EnterEvent
]);
5309 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5310 protected virtual void OnFontChanged(EventArgs e
) {
5311 EventHandler eh
= (EventHandler
)(Events
[FontChangedEvent
]);
5314 for (int i
=0; i
<child_controls
.Count
; i
++) child_controls
[i
].OnParentFontChanged(e
);
5317 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5318 protected virtual void OnForeColorChanged(EventArgs e
) {
5319 EventHandler eh
= (EventHandler
)(Events
[ForeColorChangedEvent
]);
5322 for (int i
=0; i
<child_controls
.Count
; i
++) child_controls
[i
].OnParentForeColorChanged(e
);
5325 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5326 protected virtual void OnGiveFeedback(GiveFeedbackEventArgs gfbevent
) {
5327 GiveFeedbackEventHandler eh
= (GiveFeedbackEventHandler
)(Events
[GiveFeedbackEvent
]);
5329 eh (this, gfbevent
);
5332 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5333 protected virtual void OnGotFocus(EventArgs e
) {
5334 EventHandler eh
= (EventHandler
)(Events
[GotFocusEvent
]);
5339 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5340 protected virtual void OnHandleCreated(EventArgs e
) {
5341 EventHandler eh
= (EventHandler
)(Events
[HandleCreatedEvent
]);
5346 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5347 protected virtual void OnHandleDestroyed(EventArgs e
) {
5348 EventHandler eh
= (EventHandler
)(Events
[HandleDestroyedEvent
]);
5353 internal void RaiseHelpRequested (HelpEventArgs hevent
) {
5354 OnHelpRequested (hevent
);
5357 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5358 protected virtual void OnHelpRequested(HelpEventArgs hevent
) {
5359 HelpEventHandler eh
= (HelpEventHandler
)(Events
[HelpRequestedEvent
]);
5364 protected virtual void OnImeModeChanged(EventArgs e
) {
5365 EventHandler eh
= (EventHandler
)(Events
[ImeModeChangedEvent
]);
5370 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5371 protected virtual void OnInvalidated(InvalidateEventArgs e
) {
5372 if (UseDoubleBuffering
) {
5373 // should this block be here? seems like it
5374 // would be more at home in
5375 // NotifyInvalidated..
5376 if (e
.InvalidRect
== ClientRectangle
) {
5377 InvalidateBackBuffer ();
5378 } else if (backbuffer
!= null){
5379 // we need this Inflate call here so
5380 // that the border of the rectangle is
5381 // considered Visible (the
5382 // invalid_region.IsVisible call) in
5383 // the WM_PAINT handling below.
5384 Rectangle r
= Rectangle
.Inflate(e
.InvalidRect
, 1,1);
5385 backbuffer
.InvalidRegion
.Union (r
);
5389 InvalidateEventHandler eh
= (InvalidateEventHandler
)(Events
[InvalidatedEvent
]);
5394 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5395 protected virtual void OnKeyDown(KeyEventArgs e
) {
5396 KeyEventHandler eh
= (KeyEventHandler
)(Events
[KeyDownEvent
]);
5401 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5402 protected virtual void OnKeyPress(KeyPressEventArgs e
) {
5403 KeyPressEventHandler eh
= (KeyPressEventHandler
)(Events
[KeyPressEvent
]);
5408 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5409 protected virtual void OnKeyUp(KeyEventArgs e
) {
5410 KeyEventHandler eh
= (KeyEventHandler
)(Events
[KeyUpEvent
]);
5415 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5416 protected virtual void OnLayout(LayoutEventArgs levent
) {
5417 LayoutEventHandler eh
= (LayoutEventHandler
)(Events
[LayoutEvent
]);
5421 LayoutEngine
.Layout (this, levent
);
5424 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5425 protected virtual void OnLeave(EventArgs e
) {
5426 EventHandler eh
= (EventHandler
)(Events
[LeaveEvent
]);
5431 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5432 protected virtual void OnLocationChanged(EventArgs e
) {
5434 EventHandler eh
= (EventHandler
)(Events
[LocationChangedEvent
]);
5439 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5440 protected virtual void OnLostFocus(EventArgs e
) {
5441 EventHandler eh
= (EventHandler
)(Events
[LostFocusEvent
]);
5447 protected virtual void OnMarginChanged (EventArgs e
)
5449 EventHandler eh
= (EventHandler
)(Events
[MarginChangedEvent
]);
5454 [EditorBrowsable (EditorBrowsableState
.Advanced
)]
5456 protected virtual void OnMouseCaptureChanged (EventArgs e
)
5458 internal virtual void OnMouseCaptureChanged (EventArgs e
)
5461 EventHandler eh
= (EventHandler
)(Events
[MouseCaptureChangedEvent
]);
5467 [EditorBrowsable (EditorBrowsableState
.Advanced
)]
5468 protected virtual void OnMouseClick (MouseEventArgs e
)
5470 MouseEventHandler eh
= (MouseEventHandler
)(Events
[MouseClickEvent
]);
5475 [EditorBrowsable (EditorBrowsableState
.Advanced
)]
5476 protected virtual void OnMouseDoubleClick (MouseEventArgs e
)
5478 MouseEventHandler eh
= (MouseEventHandler
)(Events
[MouseDoubleClickEvent
]);
5484 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5485 protected virtual void OnMouseDown(MouseEventArgs e
) {
5486 MouseEventHandler eh
= (MouseEventHandler
)(Events
[MouseDownEvent
]);
5491 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5492 protected virtual void OnMouseEnter(EventArgs e
) {
5493 EventHandler eh
= (EventHandler
)(Events
[MouseEnterEvent
]);
5498 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5499 protected virtual void OnMouseHover(EventArgs e
) {
5500 EventHandler eh
= (EventHandler
)(Events
[MouseHoverEvent
]);
5505 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5506 protected virtual void OnMouseLeave(EventArgs e
) {
5507 EventHandler eh
= (EventHandler
)(Events
[MouseLeaveEvent
]);
5512 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5513 protected virtual void OnMouseMove(MouseEventArgs e
) {
5514 MouseEventHandler eh
= (MouseEventHandler
)(Events
[MouseMoveEvent
]);
5519 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5520 protected virtual void OnMouseUp(MouseEventArgs e
) {
5521 MouseEventHandler eh
= (MouseEventHandler
)(Events
[MouseUpEvent
]);
5526 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5527 protected virtual void OnMouseWheel(MouseEventArgs e
) {
5528 MouseEventHandler eh
= (MouseEventHandler
)(Events
[MouseWheelEvent
]);
5533 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5534 protected virtual void OnMove(EventArgs e
) {
5535 EventHandler eh
= (EventHandler
)(Events
[MoveEvent
]);
5540 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5541 protected virtual void OnNotifyMessage(Message m
) {
5546 protected virtual void OnPaddingChanged (EventArgs e
) {
5547 EventHandler eh
= (EventHandler
) (Events
[PaddingChangedEvent
]);
5553 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5554 protected virtual void OnPaint(PaintEventArgs e
) {
5555 PaintEventHandler eh
= (PaintEventHandler
)(Events
[PaintEvent
]);
5560 internal virtual void OnPaintBackgroundInternal(PaintEventArgs e
) {
5564 internal virtual void OnPaintInternal(PaintEventArgs e
) {
5568 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5569 protected virtual void OnPaintBackground(PaintEventArgs pevent
) {
5570 PaintControlBackground (pevent
);
5573 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5574 protected virtual void OnParentBackColorChanged(EventArgs e
) {
5575 if (background_color
.IsEmpty
&& background_image
==null) {
5577 OnBackColorChanged(e
);
5581 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5582 protected virtual void OnParentBackgroundImageChanged(EventArgs e
) {
5584 OnBackgroundImageChanged(e
);
5587 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5588 protected virtual void OnParentBindingContextChanged(EventArgs e
) {
5589 if (binding_context
==null) {
5590 binding_context
=Parent
.binding_context
;
5591 OnBindingContextChanged(e
);
5595 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5596 protected virtual void OnParentChanged(EventArgs e
) {
5597 EventHandler eh
= (EventHandler
)(Events
[ParentChangedEvent
]);
5602 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5603 protected virtual void OnParentEnabledChanged(EventArgs e
) {
5605 OnEnabledChanged(e
);
5609 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5610 protected virtual void OnParentFontChanged(EventArgs e
) {
5617 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5618 protected virtual void OnParentForeColorChanged(EventArgs e
) {
5619 if (foreground_color
.IsEmpty
) {
5621 OnForeColorChanged(e
);
5625 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5626 protected virtual void OnParentRightToLeftChanged(EventArgs e
) {
5627 if (right_to_left
==RightToLeft
.Inherit
) {
5629 OnRightToLeftChanged(e
);
5633 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5634 protected virtual void OnParentVisibleChanged(EventArgs e
) {
5636 OnVisibleChanged(e
);
5640 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5641 protected virtual void OnQueryContinueDrag(QueryContinueDragEventArgs e
) {
5642 QueryContinueDragEventHandler eh
= (QueryContinueDragEventHandler
)(Events
[QueryContinueDragEvent
]);
5648 [EditorBrowsable (EditorBrowsableState
.Advanced
)]
5649 protected virtual void OnRegionChanged (EventArgs e
)
5651 EventHandler eh
= (EventHandler
)(Events
[RegionChangedEvent
]);
5657 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5658 protected virtual void OnResize(EventArgs e
) {
5659 PerformLayout(this, "Bounds");
5661 EventHandler eh
= (EventHandler
)(Events
[ResizeEvent
]);
5666 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5667 protected virtual void OnRightToLeftChanged(EventArgs e
) {
5668 EventHandler eh
= (EventHandler
)(Events
[RightToLeftChangedEvent
]);
5671 for (int i
=0; i
<child_controls
.Count
; i
++) child_controls
[i
].OnParentRightToLeftChanged(e
);
5674 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5675 protected virtual void OnSizeChanged(EventArgs e
) {
5676 DisposeBackBuffer ();
5678 EventHandler eh
= (EventHandler
)(Events
[SizeChangedEvent
]);
5683 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5684 protected virtual void OnStyleChanged(EventArgs e
) {
5685 EventHandler eh
= (EventHandler
)(Events
[StyleChangedEvent
]);
5690 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5691 protected virtual void OnSystemColorsChanged(EventArgs e
) {
5692 EventHandler eh
= (EventHandler
)(Events
[SystemColorsChangedEvent
]);
5697 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5698 protected virtual void OnTabIndexChanged(EventArgs e
) {
5699 EventHandler eh
= (EventHandler
)(Events
[TabIndexChangedEvent
]);
5704 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5705 protected virtual void OnTabStopChanged(EventArgs e
) {
5706 EventHandler eh
= (EventHandler
)(Events
[TabStopChangedEvent
]);
5711 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5712 protected virtual void OnTextChanged(EventArgs e
) {
5713 EventHandler eh
= (EventHandler
)(Events
[TextChangedEvent
]);
5718 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5719 protected virtual void OnValidated(EventArgs e
) {
5720 EventHandler eh
= (EventHandler
)(Events
[ValidatedEvent
]);
5725 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5726 protected virtual void OnValidating(System
.ComponentModel
.CancelEventArgs e
) {
5727 CancelEventHandler eh
= (CancelEventHandler
)(Events
[ValidatingEvent
]);
5732 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5733 protected virtual void OnVisibleChanged(EventArgs e
) {
5737 EventHandler eh
= (EventHandler
)(Events
[VisibleChangedEvent
]);
5741 // We need to tell our kids (including implicit ones)
5742 foreach (Control c
in Controls
.GetAllControls ())
5744 c
.OnParentVisibleChanged (e
);
5746 #endregion // OnXXX methods
5750 static object AutoSizeChangedEvent
= new object ();
5752 static object BackColorChangedEvent
= new object ();
5753 static object BackgroundImageChangedEvent
= new object ();
5755 static object BackgroundImageLayoutChangedEvent
= new object ();
5757 static object BindingContextChangedEvent
= new object ();
5758 static object CausesValidationChangedEvent
= new object ();
5759 static object ChangeUICuesEvent
= new object ();
5760 static object ClickEvent
= new object ();
5762 static object ClientSizeChangedEvent
= new object ();
5764 static object ContextMenuChangedEvent
= new object ();
5766 static object ContextMenuStripChangedEvent
= new object ();
5768 static object ControlAddedEvent
= new object ();
5769 static object ControlRemovedEvent
= new object ();
5770 static object CursorChangedEvent
= new object ();
5771 static object DockChangedEvent
= new object ();
5772 static object DoubleClickEvent
= new object ();
5773 static object DragDropEvent
= new object ();
5774 static object DragEnterEvent
= new object ();
5775 static object DragLeaveEvent
= new object ();
5776 static object DragOverEvent
= new object ();
5777 static object EnabledChangedEvent
= new object ();
5778 static object EnterEvent
= new object ();
5779 static object FontChangedEvent
= new object ();
5780 static object ForeColorChangedEvent
= new object ();
5781 static object GiveFeedbackEvent
= new object ();
5782 static object GotFocusEvent
= new object ();
5783 static object HandleCreatedEvent
= new object ();
5784 static object HandleDestroyedEvent
= new object ();
5785 static object HelpRequestedEvent
= new object ();
5786 static object ImeModeChangedEvent
= new object ();
5787 static object InvalidatedEvent
= new object ();
5788 static object KeyDownEvent
= new object ();
5789 static object KeyPressEvent
= new object ();
5790 static object KeyUpEvent
= new object ();
5791 static object LayoutEvent
= new object ();
5792 static object LeaveEvent
= new object ();
5793 static object LocationChangedEvent
= new object ();
5794 static object LostFocusEvent
= new object ();
5796 static object MarginChangedEvent
= new object ();
5798 static object MouseCaptureChangedEvent
= new object ();
5800 static object MouseClickEvent
= new object ();
5801 static object MouseDoubleClickEvent
= new object ();
5803 static object MouseDownEvent
= new object ();
5804 static object MouseEnterEvent
= new object ();
5805 static object MouseHoverEvent
= new object ();
5806 static object MouseLeaveEvent
= new object ();
5807 static object MouseMoveEvent
= new object ();
5808 static object MouseUpEvent
= new object ();
5809 static object MouseWheelEvent
= new object ();
5810 static object MoveEvent
= new object ();
5812 static object PaddingChangedEvent
= new object ();
5814 static object PaintEvent
= new object ();
5815 static object ParentChangedEvent
= new object ();
5817 static object PreviewKeyDownEvent
= new object ();
5819 static object QueryAccessibilityHelpEvent
= new object ();
5820 static object QueryContinueDragEvent
= new object ();
5822 static object RegionChangedEvent
= new object ();
5824 static object ResizeEvent
= new object ();
5825 static object RightToLeftChangedEvent
= new object ();
5826 static object SizeChangedEvent
= new object ();
5827 static object StyleChangedEvent
= new object ();
5828 static object SystemColorsChangedEvent
= new object ();
5829 static object TabIndexChangedEvent
= new object ();
5830 static object TabStopChangedEvent
= new object ();
5831 static object TextChangedEvent
= new object ();
5832 static object ValidatedEvent
= new object ();
5833 static object ValidatingEvent
= new object ();
5834 static object VisibleChangedEvent
= new object ();
5838 [EditorBrowsable (EditorBrowsableState
.Never
)]
5839 public event EventHandler AutoSizeChanged
{
5840 add { Events.AddHandler (AutoSizeChangedEvent, value);}
5841 remove {Events.RemoveHandler (AutoSizeChangedEvent, value);}
5844 public event EventHandler BackColorChanged
{
5845 add { Events.AddHandler (BackColorChangedEvent, value); }
5846 remove { Events.RemoveHandler (BackColorChangedEvent, value); }
5849 public event EventHandler BackgroundImageChanged
{
5850 add { Events.AddHandler (BackgroundImageChangedEvent, value); }
5851 remove { Events.RemoveHandler (BackgroundImageChangedEvent, value); }
5855 public event EventHandler BackgroundImageLayoutChanged
{
5856 add {Events.AddHandler (BackgroundImageLayoutChangedEvent, value);}
5857 remove {Events.RemoveHandler (BackgroundImageLayoutChangedEvent, value);}
5861 public event EventHandler BindingContextChanged
{
5862 add { Events.AddHandler (BindingContextChangedEvent, value); }
5863 remove { Events.RemoveHandler (BindingContextChangedEvent, value); }
5866 public event EventHandler CausesValidationChanged
{
5867 add { Events.AddHandler (CausesValidationChangedEvent, value); }
5868 remove { Events.RemoveHandler (CausesValidationChangedEvent, value); }
5871 public event UICuesEventHandler ChangeUICues
{
5872 add { Events.AddHandler (ChangeUICuesEvent, value); }
5873 remove { Events.RemoveHandler (ChangeUICuesEvent, value); }
5876 public event EventHandler Click
{
5877 add { Events.AddHandler (ClickEvent, value); }
5878 remove { Events.RemoveHandler (ClickEvent, value); }
5882 public event EventHandler ClientSizeChanged
{
5883 add {Events.AddHandler (ClientSizeChangedEvent, value);}
5884 remove {Events.RemoveHandler (ClientSizeChangedEvent, value);}
5891 public event EventHandler ContextMenuChanged
{
5892 add { Events.AddHandler (ContextMenuChangedEvent, value); }
5893 remove { Events.RemoveHandler (ContextMenuChangedEvent, value); }
5897 public event EventHandler ContextMenuStripChanged
{
5898 add { Events.AddHandler (ContextMenuStripChangedEvent, value); }
5899 remove { Events.RemoveHandler (ContextMenuStripChangedEvent, value);}
5904 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5910 public event ControlEventHandler ControlAdded
{
5911 add { Events.AddHandler (ControlAddedEvent, value); }
5912 remove { Events.RemoveHandler (ControlAddedEvent, value); }
5915 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5921 public event ControlEventHandler ControlRemoved
{
5922 add { Events.AddHandler (ControlRemovedEvent, value); }
5923 remove { Events.RemoveHandler (ControlRemovedEvent, value); }
5926 [MWFDescription("Fired when the cursor for the control has been changed"), MWFCategory("PropertyChanged")]
5927 public event EventHandler CursorChanged
{
5928 add { Events.AddHandler (CursorChangedEvent, value); }
5929 remove { Events.RemoveHandler (CursorChangedEvent, value); }
5931 public event EventHandler DockChanged
{
5932 add { Events.AddHandler (DockChangedEvent, value); }
5933 remove { Events.RemoveHandler (DockChangedEvent, value); }
5936 public event EventHandler DoubleClick
{
5937 add { Events.AddHandler (DoubleClickEvent, value); }
5938 remove { Events.RemoveHandler (DoubleClickEvent, value); }
5941 public event DragEventHandler DragDrop
{
5942 add { Events.AddHandler (DragDropEvent, value); }
5943 remove { Events.RemoveHandler (DragDropEvent, value); }
5946 public event DragEventHandler DragEnter
{
5947 add { Events.AddHandler (DragEnterEvent, value); }
5948 remove { Events.RemoveHandler (DragEnterEvent, value); }
5951 public event EventHandler DragLeave
{
5952 add { Events.AddHandler (DragLeaveEvent, value); }
5953 remove { Events.RemoveHandler (DragLeaveEvent, value); }
5956 public event DragEventHandler DragOver
{
5957 add { Events.AddHandler (DragOverEvent, value); }
5958 remove { Events.RemoveHandler (DragOverEvent, value); }
5961 public event EventHandler EnabledChanged
{
5962 add { Events.AddHandler (EnabledChangedEvent, value); }
5963 remove { Events.RemoveHandler (EnabledChangedEvent, value); }
5966 public event EventHandler Enter
{
5967 add { Events.AddHandler (EnterEvent, value); }
5968 remove { Events.RemoveHandler (EnterEvent, value); }
5971 public event EventHandler FontChanged
{
5972 add { Events.AddHandler (FontChangedEvent, value); }
5973 remove { Events.RemoveHandler (FontChangedEvent, value); }
5976 public event EventHandler ForeColorChanged
{
5977 add { Events.AddHandler (ForeColorChangedEvent, value); }
5978 remove { Events.RemoveHandler (ForeColorChangedEvent, value); }
5981 public event GiveFeedbackEventHandler GiveFeedback
{
5982 add { Events.AddHandler (GiveFeedbackEvent, value); }
5983 remove { Events.RemoveHandler (GiveFeedbackEvent, value); }
5986 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5988 public event EventHandler GotFocus
{
5989 add { Events.AddHandler (GotFocusEvent, value); }
5990 remove { Events.RemoveHandler (GotFocusEvent, value); }
5994 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5996 public event EventHandler HandleCreated
{
5997 add { Events.AddHandler (HandleCreatedEvent, value); }
5998 remove { Events.RemoveHandler (HandleCreatedEvent, value); }
6001 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
6003 public event EventHandler HandleDestroyed
{
6004 add { Events.AddHandler (HandleDestroyedEvent, value); }
6005 remove { Events.RemoveHandler (HandleDestroyedEvent, value); }
6008 public event HelpEventHandler HelpRequested
{
6009 add { Events.AddHandler (HelpRequestedEvent, value); }
6010 remove { Events.RemoveHandler (HelpRequestedEvent, value); }
6013 public event EventHandler ImeModeChanged
{
6014 add { Events.AddHandler (ImeModeChangedEvent, value); }
6015 remove { Events.RemoveHandler (ImeModeChangedEvent, value); }
6018 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
6020 public event InvalidateEventHandler Invalidated
{
6021 add { Events.AddHandler (InvalidatedEvent, value); }
6022 remove { Events.RemoveHandler (InvalidatedEvent, value); }
6025 public event KeyEventHandler KeyDown
{
6026 add { Events.AddHandler (KeyDownEvent, value); }
6027 remove { Events.RemoveHandler (KeyDownEvent, value); }
6030 public event KeyPressEventHandler KeyPress
{
6031 add { Events.AddHandler (KeyPressEvent, value); }
6032 remove { Events.RemoveHandler (KeyPressEvent, value); }
6035 public event KeyEventHandler KeyUp
{
6036 add { Events.AddHandler (KeyUpEvent, value); }
6037 remove { Events.RemoveHandler (KeyUpEvent, value); }
6040 public event LayoutEventHandler Layout
{
6041 add { Events.AddHandler (LayoutEvent, value); }
6042 remove { Events.RemoveHandler (LayoutEvent, value); }
6045 public event EventHandler Leave
{
6046 add { Events.AddHandler (LeaveEvent, value); }
6047 remove { Events.RemoveHandler (LeaveEvent, value); }
6050 public event EventHandler LocationChanged
{
6051 add { Events.AddHandler (LocationChangedEvent, value); }
6052 remove { Events.RemoveHandler (LocationChangedEvent, value); }
6055 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
6057 public event EventHandler LostFocus
{
6058 add { Events.AddHandler (LostFocusEvent, value); }
6059 remove { Events.RemoveHandler (LostFocusEvent, value); }
6063 public event EventHandler MarginChanged
{
6064 add { Events.AddHandler (MarginChangedEvent, value); }
6065 remove {Events.RemoveHandler (MarginChangedEvent, value); }
6069 public event EventHandler MouseCaptureChanged
{
6071 internal event EventHandler MouseCaptureChanged
{
6073 add { Events.AddHandler (MouseCaptureChangedEvent, value); }
6074 remove { Events.RemoveHandler (MouseCaptureChangedEvent, value); }
6077 public event MouseEventHandler MouseClick
6079 add { Events.AddHandler (MouseClickEvent, value); }
6080 remove { Events.RemoveHandler (MouseClickEvent, value); }
6082 public event MouseEventHandler MouseDoubleClick
6084 add { Events.AddHandler (MouseDoubleClickEvent, value); }
6085 remove { Events.RemoveHandler (MouseDoubleClickEvent, value); }
6088 public event MouseEventHandler MouseDown
{
6089 add { Events.AddHandler (MouseDownEvent, value); }
6090 remove { Events.RemoveHandler (MouseDownEvent, value); }
6093 public event EventHandler MouseEnter
{
6094 add { Events.AddHandler (MouseEnterEvent, value); }
6095 remove { Events.RemoveHandler (MouseEnterEvent, value); }
6098 public event EventHandler MouseHover
{
6099 add { Events.AddHandler (MouseHoverEvent, value); }
6100 remove { Events.RemoveHandler (MouseHoverEvent, value); }
6103 public event EventHandler MouseLeave
{
6104 add { Events.AddHandler (MouseLeaveEvent, value); }
6105 remove { Events.RemoveHandler (MouseLeaveEvent, value); }
6108 public event MouseEventHandler MouseMove
{
6109 add { Events.AddHandler (MouseMoveEvent, value); }
6110 remove { Events.RemoveHandler (MouseMoveEvent, value); }
6113 public event MouseEventHandler MouseUp
{
6114 add { Events.AddHandler (MouseUpEvent, value); }
6115 remove { Events.RemoveHandler (MouseUpEvent, value); }
6118 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
6120 public event MouseEventHandler MouseWheel
{
6121 add { Events.AddHandler (MouseWheelEvent, value); }
6122 remove { Events.RemoveHandler (MouseWheelEvent, value); }
6125 public event EventHandler Move
{
6126 add { Events.AddHandler (MoveEvent, value); }
6127 remove { Events.RemoveHandler (MoveEvent, value); }
6130 public event EventHandler PaddingChanged
6132 add { Events.AddHandler (PaddingChangedEvent, value); }
6133 remove { Events.RemoveHandler (PaddingChangedEvent, value); }
6136 public event PaintEventHandler Paint
{
6137 add { Events.AddHandler (PaintEvent, value); }
6138 remove { Events.RemoveHandler (PaintEvent, value); }
6141 public event EventHandler ParentChanged
{
6142 add { Events.AddHandler (ParentChangedEvent, value); }
6143 remove { Events.RemoveHandler (ParentChangedEvent, value); }
6147 public event PreviewKeyDownEventHandler PreviewKeyDown
{
6148 add { Events.AddHandler (PreviewKeyDownEvent, value); }
6149 remove { Events.RemoveHandler (PreviewKeyDownEvent, value); }
6153 public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp
{
6154 add { Events.AddHandler (QueryAccessibilityHelpEvent, value); }
6155 remove { Events.RemoveHandler (QueryAccessibilityHelpEvent, value); }
6158 public event QueryContinueDragEventHandler QueryContinueDrag
{
6159 add { Events.AddHandler (QueryContinueDragEvent, value); }
6160 remove { Events.RemoveHandler (QueryContinueDragEvent, value); }
6164 public event EventHandler RegionChanged
{
6165 add { Events.AddHandler (RegionChangedEvent, value); }
6166 remove { Events.RemoveHandler (RegionChangedEvent, value); }
6171 [EditorBrowsable (EditorBrowsableState
.Advanced
)]
6173 public event EventHandler Resize
{
6174 add { Events.AddHandler (ResizeEvent, value); }
6175 remove { Events.RemoveHandler (ResizeEvent, value); }
6178 public event EventHandler RightToLeftChanged
{
6179 add { Events.AddHandler (RightToLeftChangedEvent, value); }
6180 remove { Events.RemoveHandler (RightToLeftChangedEvent, value); }
6183 public event EventHandler SizeChanged
{
6184 add { Events.AddHandler (SizeChangedEvent, value); }
6185 remove { Events.RemoveHandler (SizeChangedEvent, value); }
6188 public event EventHandler StyleChanged
{
6189 add { Events.AddHandler (StyleChangedEvent, value); }
6190 remove { Events.RemoveHandler (StyleChangedEvent, value); }
6193 public event EventHandler SystemColorsChanged
{
6194 add { Events.AddHandler (SystemColorsChangedEvent, value); }
6195 remove { Events.RemoveHandler (SystemColorsChangedEvent, value); }
6198 public event EventHandler TabIndexChanged
{
6199 add { Events.AddHandler (TabIndexChangedEvent, value); }
6200 remove { Events.RemoveHandler (TabIndexChangedEvent, value); }
6203 public event EventHandler TabStopChanged
{
6204 add { Events.AddHandler (TabStopChangedEvent, value); }
6205 remove { Events.RemoveHandler (TabStopChangedEvent, value); }
6208 public event EventHandler TextChanged
{
6209 add { Events.AddHandler (TextChangedEvent, value); }
6210 remove { Events.RemoveHandler (TextChangedEvent, value); }
6213 public event EventHandler Validated
{
6214 add { Events.AddHandler (ValidatedEvent, value); }
6215 remove { Events.RemoveHandler (ValidatedEvent, value); }
6218 public event CancelEventHandler Validating
{
6219 add { Events.AddHandler (ValidatingEvent, value); }
6220 remove { Events.RemoveHandler (ValidatingEvent, value); }
6223 public event EventHandler VisibleChanged
{
6224 add { Events.AddHandler (VisibleChangedEvent, value); }
6225 remove { Events.RemoveHandler (VisibleChangedEvent, value); }
6228 #endregion // Events