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
39 using System
.ComponentModel
;
40 using System
.ComponentModel
.Design
;
41 using System
.ComponentModel
.Design
.Serialization
;
42 using System
.Collections
;
43 using System
.Diagnostics
;
45 using System
.Drawing
.Drawing2D
;
46 using System
.Reflection
;
47 using System
.Runtime
.InteropServices
;
48 using System
.Security
;
49 using System
.Threading
;
51 namespace System
.Windows
.Forms
53 [Designer("System.Windows.Forms.Design.ControlDesigner, " + Consts
.AssemblySystem_Design
, "System.ComponentModel.Design.IDesigner")]
54 [DefaultProperty("Text")]
55 [DefaultEvent("Click")]
56 [DesignerSerializer("System.Windows.Forms.Design.ControlCodeDomSerializer, " + Consts
.AssemblySystem_Design
, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts
.AssemblySystem_Design
)]
57 [ToolboxItemFilter("System.Windows.Forms")]
58 public class Control
: Component
, ISynchronizeInvoke
, IWin32Window
60 #region Local Variables
63 internal Rectangle bounds
; // bounding rectangle for control (client area + decorations)
64 Rectangle explicit_bounds
; // explicitly set bounds
65 internal object creator_thread
; // thread that created the control
66 internal ControlNativeWindow window
; // object for native window handle
67 string name
; // for object naming
70 bool is_created
; // true if OnCreateControl has been sent
71 internal bool has_focus
; // true if control has focus
72 internal bool is_visible
; // true if control is visible
73 internal bool is_entered
; // is the mouse inside the control?
74 internal bool is_enabled
; // true if control is enabled (usable/not grayed out)
75 bool is_accessible
; // true if the control is visible to accessibility applications
76 bool is_captured
; // tracks if the control has captured the mouse
77 internal bool is_toplevel
; // tracks if the control is a toplevel window
78 bool is_recreating
; // tracks if the handle for the control is being recreated
79 bool causes_validation
; // tracks if validation is executed on changes
80 bool is_focusing
; // tracks if Focus has been called on the control and has not yet finished
81 int tab_index
; // position in tab order of siblings
82 bool tab_stop
; // is the control a tab stop?
83 bool is_disposed
; // has the window already been disposed?
84 Size client_size
; // size of the client area (window excluding decorations)
85 Rectangle client_rect
; // rectangle with the client area (window excluding decorations)
86 ControlStyles control_style
; // rather win32-specific, style bits for control
88 bool layout_pending
; // true if our parent needs to re-layout us
89 object control_tag
; // object that contains data about our control
90 internal int mouse_clicks
; // Counter for mouse clicks
91 Cursor cursor
; // Cursor for the window
92 internal bool allow_drop
; // true if the control accepts droping objects on it
93 Region clip_region
; // User-specified clip region for the window
96 internal Color foreground_color
; // foreground color for control
97 internal Color background_color
; // background color for control
98 Image background_image
; // background image for control
99 internal Font font
; // font for control
100 string text
; // window/title text for control
101 internal BorderStyle border_style
; // Border style of control
104 int layout_suspended
;
105 internal AnchorStyles anchor_style
; // anchoring requirements for our control
106 internal DockStyle dock_style
; // docking requirements for our control (supercedes anchoring)
107 // Please leave the next 4 as internal until DefaultLayout (2.0) is rewritten
108 internal int dist_left
; // distance to the left border of the parent
109 internal int dist_top
; // distance to the top border of the parent
110 internal int dist_right
; // distance to the right border of the parent
111 internal int dist_bottom
; // distance to the bottom border of the parent
113 // to be categorized...
114 static internal ArrayList controls
= new ArrayList(); // All of the application's controls, in a flat list
115 ControlCollection child_controls
; // our children
116 Control parent
; // our parent control
117 AccessibleObject accessibility_object
; // object that contains accessibility information about our control
118 BindingContext binding_context
;
119 RightToLeft right_to_left
; // drawing direction for control
120 ContextMenu context_menu
; // Context menu associated with the control
123 Graphics dc_mem
; // Graphics context for double buffering
124 Bitmap bmp_mem
; // Bitmap for double buffering control
125 Region invalid_region
;
127 ControlBindingsCollection data_bindings
;
130 internal bool use_compatible_text_rendering
;
131 static bool verify_thread_handle
;
137 Layout
.LayoutEngine layout_engine
;
140 #endregion // Local Variables
142 #region Private Classes
143 // This helper class allows us to dispatch messages to Control.WndProc
144 internal class ControlNativeWindow
: NativeWindow
{
145 private Control owner
;
147 public ControlNativeWindow(Control control
) : base() {
152 public Control Owner
{
158 static internal Control
ControlFromHandle(IntPtr hWnd
) {
159 ControlNativeWindow window
;
161 window
= (ControlNativeWindow
)window_collection
[hWnd
];
162 if (window
!= null) {
169 static internal Control
ControlFromChildHandle (IntPtr handle
) {
170 ControlNativeWindow window
;
172 Hwnd hwnd
= Hwnd
.ObjectFromHandle (handle
);
173 while (hwnd
!= null) {
174 window
= (ControlNativeWindow
)window_collection
[hwnd
.Handle
];
175 if (window
!= null) {
184 protected override void WndProc(ref Message m
) {
185 owner
.WndProc(ref m
);
190 #region Public Classes
192 public class ControlAccessibleObject
: AccessibleObject
{
195 #region ControlAccessibleObject Constructors
196 public ControlAccessibleObject(Control ownerControl
)
197 : base (ownerControl
)
199 this.owner
= ownerControl
;
201 #endregion // ControlAccessibleObject Constructors
203 #region ControlAccessibleObject Public Instance Properties
204 public override string DefaultAction
{
206 return base.DefaultAction
;
210 public override string Description
{
212 return base.Description
;
216 public IntPtr Handle
{
222 // We don't want to let them set it
226 public override string Help
{
232 public override string KeyboardShortcut
{
234 return base.KeyboardShortcut
;
238 public override string Name
{
248 public Control Owner
{
254 public override AccessibleObject Parent
{
261 public override AccessibleRole Role
{
266 #endregion // ControlAccessibleObject Public Instance Properties
268 #region ControlAccessibleObject Public Instance Methods
269 public override int GetHelpTopic(out string FileName
) {
270 return base.GetHelpTopic (out FileName
);
273 [MonoTODO("Implement this and tie it into Control.AccessibilityNotifyClients")]
274 public void NotifyClients(AccessibleEvents accEvent
) {
275 throw new NotImplementedException();
278 [MonoTODO("Implement this and tie it into Control.AccessibilityNotifyClients")]
279 public void NotifyClients(AccessibleEvents accEvent
, int childID
) {
280 throw new NotImplementedException();
283 public override string ToString() {
284 return "ControlAccessibleObject: Owner = " + owner
.ToString() + ", Text: " + owner
.text
;
287 #endregion // ControlAccessibleObject Public Instance Methods
290 [DesignerSerializer("System.Windows.Forms.Design.ControlCollectionCodeDomSerializer, " + Consts
.AssemblySystem_Design
, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts
.AssemblySystem_Design
)]
291 [ListBindable(false)]
292 public class ControlCollection
: IList
, ICollection
, ICloneable
, IEnumerable
{
293 #region ControlCollection Local Variables
296 Control
[] all_controls
;
298 #endregion // ControlCollection Local Variables
300 #region ControlCollection Public Constructor
301 public ControlCollection(Control owner
) {
303 this.list
=new ArrayList();
307 #region ControlCollection Public Instance Properties
314 public bool IsReadOnly
{
316 return list
.IsReadOnly
;
320 public virtual Control
this[int index
] {
322 if (index
< 0 || index
>= list
.Count
) {
323 throw new ArgumentOutOfRangeException("index", index
, "ControlCollection does not have that many controls");
325 return (Control
)list
[index
];
328 #endregion // ControlCollection Public Instance Properties
330 #region ControlCollection Private Instance Methods
331 public virtual void Add (Control
value)
336 if (Contains (value)) {
337 owner
.PerformLayout();
341 if (value.tab_index
== -1) {
347 end
= owner
.child_controls
.Count
;
348 for (int i
= 0; i
< end
; i
++) {
349 index
= owner
.child_controls
[i
].tab_index
;
354 value.tab_index
= use
;
357 if (value.parent
!= null) {
358 value.parent
.Controls
.Remove(value);
364 value.ChangeParent(owner
);
368 owner
.UpdateChildrenZOrder();
369 owner
.PerformLayout(value, "Parent");
370 owner
.OnControlAdded(new ControlEventArgs(value));
373 internal void AddToList (Control c
)
379 internal virtual void AddImplicit (Control control
)
381 if (impl_list
== null)
382 impl_list
= new ArrayList ();
384 if (AllContains (control
))
388 impl_list
.Add (control
);
390 control
.ChangeParent (owner
);
391 control
.InitLayout ();
392 owner
.UpdateChildrenZOrder ();
393 owner
.PerformLayout (control
, "Parent");
394 owner
.OnControlAdded (new ControlEventArgs (control
));
397 public virtual void AddRange (Control
[] controls
)
399 if (controls
== null)
400 throw new ArgumentNullException ("controls");
402 owner
.SuspendLayout ();
405 for (int i
= 0; i
< controls
.Length
; i
++)
408 owner
.ResumeLayout ();
412 internal virtual void AddRangeImplicit (Control
[] controls
)
414 if (controls
== null)
415 throw new ArgumentNullException ("controls");
417 owner
.SuspendLayout ();
420 for (int i
= 0; i
< controls
.Length
; i
++)
421 AddImplicit (controls
[i
]);
423 owner
.ResumeLayout ();
427 public virtual void Clear ()
431 // MS sends remove events in reverse order
432 while (list
.Count
> 0) {
433 Remove((Control
)list
[list
.Count
- 1]);
437 internal virtual void ClearImplicit ()
439 if (impl_list
== null)
445 public bool Contains (Control
value)
447 for (int i
= list
.Count
; i
> 0; ) {
450 if (list
[i
] == value) {
451 // Do we need to do anything here?
458 internal bool ImplicitContains (Control
value)
460 if (impl_list
== null)
463 for (int i
= impl_list
.Count
; i
> 0; ) {
466 if (impl_list
[i
] == value) {
467 // Do we need to do anything here?
474 internal bool AllContains (Control
value)
476 return Contains (value) || ImplicitContains (value);
479 public void CopyTo (Array array
, int index
)
481 list
.CopyTo(array
, index
);
484 public override bool Equals(object other
) {
485 if (other
is ControlCollection
&& (((ControlCollection
)other
).owner
==this.owner
)) {
492 public int GetChildIndex(Control child
) {
493 return GetChildIndex(child
, false);
496 public int GetChildIndex(Control child
, bool throwException
) {
499 index
=list
.IndexOf(child
);
501 if (index
==-1 && throwException
) {
502 throw new ArgumentException("Not a child control", "child");
507 public IEnumerator
GetEnumerator() {
508 return list
.GetEnumerator();
511 internal IEnumerator
GetAllEnumerator ()
513 Control
[] res
= GetAllControls ();
514 return res
.GetEnumerator ();
517 internal Control
[] GetAllControls ()
519 if (all_controls
!= null)
522 if (impl_list
== null) {
523 all_controls
= (Control
[]) list
.ToArray (typeof (Control
));
527 all_controls
= new Control
[list
.Count
+ impl_list
.Count
];
528 impl_list
.CopyTo (all_controls
);
529 list
.CopyTo (all_controls
, impl_list
.Count
);
534 public override int GetHashCode() {
535 return base.GetHashCode();
538 public int IndexOf(Control control
) {
539 return list
.IndexOf(control
);
542 public virtual void Remove(Control
value) {
543 owner
.PerformLayout(value, "Parent");
544 owner
.OnControlRemoved(new ControlEventArgs(value));
549 value.ChangeParent(null);
551 owner
.UpdateChildrenZOrder();
554 internal virtual void RemoveImplicit (Control control
)
556 if (impl_list
!= null) {
558 owner
.PerformLayout (control
, "Parent");
559 owner
.OnControlRemoved (new ControlEventArgs (control
));
560 impl_list
.Remove (control
);
562 control
.ChangeParent (null);
563 owner
.UpdateChildrenZOrder ();
566 public void RemoveAt(int index
) {
567 if (index
< 0 || index
>= list
.Count
) {
568 throw new ArgumentOutOfRangeException("index", index
, "ControlCollection does not have that many controls");
570 Remove ((Control
)list
[index
]);
573 public void SetChildIndex(Control child
, int newIndex
) {
576 old_index
=list
.IndexOf(child
);
578 throw new ArgumentException("Not a child control", "child");
581 if (old_index
==newIndex
) {
586 list
.RemoveAt(old_index
);
588 if (newIndex
>list
.Count
) {
591 list
.Insert(newIndex
, child
);
593 child
.UpdateZOrder();
594 owner
.PerformLayout();
596 #endregion // ControlCollection Private Instance Methods
598 #region ControlCollection Interface Properties
599 object IList
.this[int index
] {
601 if (index
<0 || index
>=list
.Count
) {
602 throw new ArgumentOutOfRangeException("index", index
, "ControlCollection does not have that many controls");
608 if (!(value is Control
)) {
609 throw new ArgumentException("Object of type Control required", "value");
613 Control ctrl
= (Control
) value;
616 ctrl
.ChangeParent(owner
);
620 owner
.UpdateChildrenZOrder();
621 owner
.PerformLayout(ctrl
, "Parent");
625 bool IList
.IsFixedSize
{
631 bool ICollection
.IsSynchronized
{
633 return list
.IsSynchronized
;
637 object ICollection
.SyncRoot
{
639 return list
.SyncRoot
;
642 #endregion // ControlCollection Interface Properties
644 #region ControlCollection Interface Methods
645 int IList
.Add(object value) {
647 throw new ArgumentNullException("value", "Cannot add null controls");
650 if (!(value is Control
)) {
651 throw new ArgumentException("Object of type Control required", "value");
654 return list
.Add(value);
657 bool IList
.Contains(object value) {
658 if (!(value is Control
)) {
659 throw new ArgumentException("Object of type Control required", "value");
662 return this.Contains((Control
) value);
665 int IList
.IndexOf(object value) {
666 if (!(value is Control
)) {
667 throw new ArgumentException("Object of type Control required", "value");
670 return this.IndexOf((Control
) value);
673 void IList
.Insert(int index
, object value) {
674 if (!(value is Control
)) {
675 throw new ArgumentException("Object of type Control required", "value");
678 list
.Insert(index
, value);
681 void IList
.Remove(object value) {
682 if (!(value is Control
)) {
683 throw new ArgumentException("Object of type Control required", "value");
689 Object ICloneable
.Clone() {
690 ControlCollection clone
= new ControlCollection(this.owner
);
691 clone
.list
=(ArrayList
)list
.Clone(); // FIXME: Do we need this?
694 #endregion // ControlCollection Interface Methods
696 #endregion // ControlCollection Class
698 #region Public Constructors
701 anchor_style
= AnchorStyles
.Top
| AnchorStyles
.Left
;
709 layout_pending
= false;
711 causes_validation
= true;
713 layout_suspended
= 0;
717 right_to_left
= RightToLeft
.Inherit
;
718 border_style
= BorderStyle
.None
;
719 background_color
= Color
.Empty
;
725 ime_mode
= ImeMode
.Inherit
;
728 use_compatible_text_rendering
= Application
.use_compatible_text_rendering
;
729 padding
= new Padding(0);
730 maximum_size
= new Size();
731 minimum_size
= new Size();
732 preferred_size
= new Size();
733 margin
= this.DefaultMargin
;
734 layout_engine
= this.LayoutEngine
;
737 control_style
= ControlStyles
.UserPaint
| ControlStyles
.AllPaintingInWmPaint
|
738 ControlStyles
.Selectable
| ControlStyles
.StandardClick
|
739 ControlStyles
.StandardDoubleClick
;
741 control_style
|= ControlStyles
.UseTextForAccessibility
;
745 background_image
= null;
749 window
= new ControlNativeWindow(this);
750 child_controls
= CreateControlsInstance();
751 client_size
= new Size(DefaultSize
.Width
, DefaultSize
.Height
);
752 client_rect
= new Rectangle(0, 0, DefaultSize
.Width
, DefaultSize
.Height
);
753 XplatUI
.CalculateWindowRect(ref client_rect
, CreateParams
.Style
, CreateParams
.ExStyle
, null, out bounds
);
754 if ((CreateParams
.Style
& (int)WindowStyles
.WS_CHILD
) == 0) {
760 public Control(Control parent
, string text
) : this() {
765 public Control(Control parent
, string text
, int left
, int top
, int width
, int height
) : this() {
770 bounds
.Height
=height
;
771 SetBounds(left
, top
, width
, height
, BoundsSpecified
.All
);
775 public Control(string text
) : this() {
779 public Control(string text
, int left
, int top
, int width
, int height
) : this() {
783 bounds
.Height
=height
;
784 SetBounds(left
, top
, width
, height
, BoundsSpecified
.All
);
788 private delegate void RemoveDelegate(object c
);
790 protected override void Dispose(bool disposing
) {
791 if (!is_disposed
&& disposing
) {
804 if (invalid_region
!=null) {
805 invalid_region
.Dispose();
808 if (this.InvokeRequired
) {
809 if (Application
.MessageLoop
) {
810 this.BeginInvokeInternal(new MethodInvoker(DestroyHandle
), null, true);
811 this.BeginInvokeInternal(new RemoveDelegate(controls
.Remove
), new object[] {this}
, true);
815 lock (Control
.controls
) {
816 Control
.controls
.Remove(this);
821 if (parent
!= null) {
822 parent
.Controls
.Remove(this);
825 Control
[] children
= child_controls
.GetAllControls ();
826 for (int i
=0; i
<children
.Length
; i
++) {
827 children
[i
].parent
= null; // Need to set to null or our child will try and remove from ourselves and crash
828 children
[i
].Dispose();
833 base.Dispose(disposing
);
835 #endregion // Public Constructors
837 #region Internal Properties
838 internal BorderStyle InternalBorderStyle
{
844 if (!Enum
.IsDefined (typeof (BorderStyle
), value))
845 throw new InvalidEnumArgumentException (string.Format("Enum argument value '{0}' is not valid for BorderStyle", value));
847 if (border_style
!= value) {
848 border_style
= value;
850 if (IsHandleCreated
) {
851 XplatUI
.SetBorderStyle(window
.Handle
, (FormBorderStyle
)border_style
);
857 #endregion // Internal Properties
859 #region Private & Internal Methods
860 internal IAsyncResult
BeginInvokeInternal (Delegate method
, object [] args
, bool disposing
) {
861 AsyncMethodResult result
;
862 AsyncMethodData data
;
869 if (!p
.IsHandleCreated
) {
870 throw new InvalidOperationException("Cannot call Invoke or InvokeAsync on a control until the window handle is created");
876 result
= new AsyncMethodResult ();
877 data
= new AsyncMethodData ();
879 data
.Handle
= window
.Handle
;
880 data
.Method
= method
;
882 data
.Result
= result
;
885 if (!ExecutionContext
.IsFlowSuppressed ()) {
886 data
.Context
= ExecutionContext
.Capture ();
889 #if !MWF_ON_MSRUNTIME
890 if (SecurityManager
.SecurityEnabled
) {
891 data
.Stack
= CompressedStack
.GetCompressedStack ();
896 XplatUI
.SendAsyncMethod (data
);
901 internal void PointToClient (ref int x
, ref int y
)
903 XplatUI
.ScreenToClient (Handle
, ref x
, ref y
);
906 internal void PointToScreen (ref int x
, ref int y
)
908 XplatUI
.ClientToScreen (Handle
, ref x
, ref y
);
911 internal bool IsRecreating
{
913 return is_recreating
;
917 internal Graphics DeviceContext
{
919 if (dc_mem
== null) {
920 CreateBuffers(this.Width
, this.Height
);
926 private void ImageBufferNeedsRedraw () {
927 if (invalid_region
!= null)
928 invalid_region
.Dispose();
929 invalid_region
= new Region (ClientRectangle
);
932 private Bitmap ImageBuffer
{
935 CreateBuffers(this.Width
, this.Height
);
941 internal void CreateBuffers (int width
, int height
) {
950 bmp_mem
= new Bitmap (width
, height
, System
.Drawing
.Imaging
.PixelFormat
.Format32bppArgb
);
951 dc_mem
= Graphics
.FromImage (bmp_mem
);
952 ImageBufferNeedsRedraw ();
955 internal void InvalidateBuffers ()
957 if (dc_mem
!= null) {
963 ImageBufferNeedsRedraw ();
966 internal static void SetChildColor(Control parent
) {
969 for (int i
=0; i
< parent
.child_controls
.Count
; i
++) {
970 child
=parent
.child_controls
[i
];
971 if (child
.child_controls
.Count
>0) {
972 SetChildColor(child
);
978 internal bool Select(Control control
) {
979 IContainerControl container
;
981 if (control
== null) {
985 container
= GetContainerControl();
986 if (container
!= null) {
987 container
.ActiveControl
= control
;
989 if (control
.IsHandleCreated
) {
990 XplatUI
.SetFocus(control
.window
.Handle
);
995 internal void SelectChild (Control control
)
997 if (control
.IsHandleCreated
)
998 XplatUI
.SetFocus (control
.window
.Handle
);
1001 internal virtual void DoDefaultAction() {
1002 // Only here to be overriden by our actual controls; this is needed by the accessibility class
1005 internal static int LowOrder (int param
) {
1006 return ((int)(short)(param
& 0xffff));
1009 internal static int HighOrder (int param
) {
1010 return ((int)(short)(param
>> 16));
1013 // This method exists so controls overriding OnPaintBackground can have default background painting done
1014 internal virtual void PaintControlBackground (PaintEventArgs pevent
)
1016 if (GetStyle(ControlStyles
.SupportsTransparentBackColor
) && (BackColor
.A
!= 0xff)) {
1017 if (parent
!= null) {
1018 PaintEventArgs parent_pe
;
1019 GraphicsState state
;
1021 parent_pe
= new PaintEventArgs(pevent
.Graphics
, new Rectangle(pevent
.ClipRectangle
.X
+ Left
, pevent
.ClipRectangle
.Y
+ Top
, pevent
.ClipRectangle
.Width
, pevent
.ClipRectangle
.Height
));
1023 state
= parent_pe
.Graphics
.Save();
1024 parent_pe
.Graphics
.TranslateTransform(-Left
, -Top
);
1025 parent
.OnPaintBackground(parent_pe
);
1026 parent_pe
.Graphics
.Restore(state
);
1028 state
= parent_pe
.Graphics
.Save();
1029 parent_pe
.Graphics
.TranslateTransform(-Left
, -Top
);
1030 parent
.OnPaint(parent_pe
);
1031 parent_pe
.Graphics
.Restore(state
);
1032 parent_pe
.SetGraphics(null);
1036 if ((clip_region
!= null) && (XplatUI
.UserClipWontExposeParent
)) {
1037 if (parent
!= null) {
1038 PaintEventArgs parent_pe
;
1040 GraphicsState state
;
1043 hwnd
= Hwnd
.ObjectFromHandle(Handle
);
1046 parent_pe
= new PaintEventArgs(pevent
.Graphics
, new Rectangle(pevent
.ClipRectangle
.X
+ Left
, pevent
.ClipRectangle
.Y
+ Top
, pevent
.ClipRectangle
.Width
, pevent
.ClipRectangle
.Height
));
1048 region
= new Region ();
1050 region
.Union(ClientRectangle
);
1052 foreach (Rectangle r
in hwnd
.ClipRectangles
) {
1056 state
= parent_pe
.Graphics
.Save();
1057 parent_pe
.Graphics
.Clip
= region
;
1059 parent_pe
.Graphics
.TranslateTransform(-Left
, -Top
);
1060 parent
.OnPaintBackground(parent_pe
);
1061 parent_pe
.Graphics
.Restore(state
);
1063 state
= parent_pe
.Graphics
.Save();
1064 parent_pe
.Graphics
.Clip
= region
;
1066 parent_pe
.Graphics
.TranslateTransform(-Left
, -Top
);
1067 parent
.OnPaint(parent_pe
);
1068 parent_pe
.Graphics
.Restore(state
);
1069 parent_pe
.SetGraphics(null);
1071 region
.Intersect(clip_region
);
1072 pevent
.Graphics
.Clip
= region
;
1077 if (background_image
== null) {
1078 pevent
.Graphics
.FillRectangle(ThemeEngine
.Current
.ResPool
.GetSolidBrush(BackColor
), new Rectangle(pevent
.ClipRectangle
.X
- 1, pevent
.ClipRectangle
.Y
- 1, pevent
.ClipRectangle
.Width
+ 2, pevent
.ClipRectangle
.Height
+ 2));
1082 DrawBackgroundImage (pevent
.Graphics
);
1085 void DrawBackgroundImage (Graphics g
)
1087 using (TextureBrush b
= new TextureBrush (background_image
, WrapMode
.Tile
)) {
1088 g
.FillRectangle (b
, ClientRectangle
);
1092 internal virtual void DndEnter (DragEventArgs e
)
1099 internal virtual void DndOver (DragEventArgs e
)
1106 internal virtual void DndDrop (DragEventArgs e
)
1110 } catch (Exception exc
) {
1111 Console
.Error
.WriteLine ("MWF: Exception while dropping:");
1112 Console
.Error
.WriteLine (exc
);
1116 internal virtual void DndLeave (EventArgs e
)
1123 internal virtual void DndFeedback(GiveFeedbackEventArgs e
)
1130 internal virtual void DndContinueDrag(QueryContinueDragEventArgs e
)
1133 OnQueryContinueDrag(e
);
1137 internal static MouseButtons
FromParamToMouseButtons (int param
) {
1138 MouseButtons buttons
= MouseButtons
.None
;
1140 if ((param
& (int) MsgButtons
.MK_LBUTTON
) != 0)
1141 buttons
|= MouseButtons
.Left
;
1143 if ((param
& (int) MsgButtons
.MK_MBUTTON
) != 0)
1144 buttons
|= MouseButtons
.Middle
;
1146 if ((param
& (int) MsgButtons
.MK_RBUTTON
) != 0)
1147 buttons
|= MouseButtons
.Right
;
1153 internal void FireEnter ()
1155 OnEnter (EventArgs
.Empty
);
1158 internal void FireLeave ()
1160 OnLeave (EventArgs
.Empty
);
1163 internal void FireValidating (CancelEventArgs ce
)
1168 internal void FireValidated ()
1170 OnValidated (EventArgs
.Empty
);
1173 internal virtual bool ProcessControlMnemonic(char charCode
) {
1174 return ProcessMnemonic(charCode
);
1177 private static Control
FindFlatForward(Control container
, Control start
) {
1183 end
= container
.child_controls
.Count
;
1185 if (start
!= null) {
1186 index
= start
.tab_index
;
1192 for (int i
= 0, pos
= -1; i
< end
; i
++) {
1193 if (start
== container
.child_controls
[i
]) {
1198 if (found
== null) {
1199 if (container
.child_controls
[i
].tab_index
> index
|| (pos
> -1 && pos
< i
&& container
.child_controls
[i
].tab_index
== index
)) {
1200 found
= container
.child_controls
[i
];
1202 } else if (found
.tab_index
> container
.child_controls
[i
].tab_index
) {
1203 if (container
.child_controls
[i
].tab_index
> index
) {
1204 found
= container
.child_controls
[i
];
1211 private static Control
FindControlForward(Control container
, Control start
) {
1216 if (start
== null) {
1217 return FindFlatForward(container
, start
);
1220 if (start
.child_controls
!= null && start
.child_controls
.Count
> 0 &&
1221 (start
== container
|| !((start
is IContainerControl
) && start
.GetStyle(ControlStyles
.ContainerControl
)))) {
1222 return FindControlForward(start
, null);
1225 while (start
!= container
) {
1226 found
= FindFlatForward(start
.parent
, start
);
1227 if (found
!= null) {
1230 start
= start
.parent
;
1236 private static Control
FindFlatBackward(Control container
, Control start
) {
1242 end
= container
.child_controls
.Count
;
1244 if (start
!= null) {
1245 index
= start
.tab_index
;
1247 // FIXME: Possible speed-up: Keep the highest taborder index in the container
1249 for (int i
= 0; i
< end
; i
++) {
1250 if (container
.child_controls
[i
].tab_index
> index
) {
1251 index
= container
.child_controls
[i
].tab_index
;
1259 for (int i
= end
- 1; i
>= 0; i
--) {
1260 if (start
== container
.child_controls
[i
]) {
1265 if (found
== null || found
.tab_index
< container
.child_controls
[i
].tab_index
) {
1266 if (container
.child_controls
[i
].tab_index
< index
|| (hit
&& container
.child_controls
[i
].tab_index
== index
))
1267 found
= container
.child_controls
[i
];
1274 private static Control
FindControlBackward(Control container
, Control start
) {
1276 Control found
= null;
1278 if (start
== null) {
1279 found
= FindFlatBackward(container
, start
);
1281 else if (start
!= container
) {
1282 if (start
.parent
!= null) {
1283 found
= FindFlatBackward(start
.parent
, start
);
1285 if (found
== null) {
1286 if (start
.parent
!= container
)
1287 return start
.parent
;
1293 if (found
== null || start
.parent
== null)
1296 while (found
!= null && (found
== container
|| (!((found
is IContainerControl
) && found
.GetStyle(ControlStyles
.ContainerControl
))) &&
1297 found
.child_controls
!= null && found
.child_controls
.Count
> 0)) {
1298 // while (ctl.child_controls != null && ctl.child_controls.Count > 0 &&
1299 // (ctl == this || (!((ctl is IContainerControl) && ctl.GetStyle(ControlStyles.ContainerControl))))) {
1300 found
= FindFlatBackward(found
, null);
1310 if (start != null) {
1311 found = FindFlatBackward(start.parent, start);
1312 if (found == null) {
1313 if (start.parent != container) {
1314 return start.parent;
1318 if (found == null) {
1319 found = FindFlatBackward(container, start);
1322 if (container != start) {
1323 while ((found != null) && (!found.Contains(start)) && found.child_controls != null && found.child_controls.Count > 0 && !(found is IContainerControl)) {// || found.GetStyle(ControlStyles.ContainerControl))) {
1324 found = FindControlBackward(found, null);
1325 if (found != null) {
1334 internal virtual void HandleClick(int clicks
, MouseEventArgs me
) {
1335 if (GetStyle(ControlStyles
.StandardClick
)) {
1336 if ((clicks
> 1) && GetStyle(ControlStyles
.StandardDoubleClick
)) {
1338 OnDoubleClick(EventArgs
.Empty
);
1340 OnClick(EventArgs
.Empty
);
1350 private void CheckDataBindings ()
1352 if (data_bindings
== null)
1355 BindingContext binding_context
= BindingContext
;
1356 foreach (Binding binding
in data_bindings
) {
1357 binding
.Check (binding_context
);
1362 private void ChangeParent(Control new_parent
) {
1366 Color pre_fore_color
;
1367 Color pre_back_color
;
1368 RightToLeft pre_rtl
;
1370 // These properties are inherited from our parent
1371 // Get them pre parent-change and then send events
1372 // if they are changed after we have our new parent
1373 pre_enabled
= Enabled
;
1374 pre_visible
= Visible
;
1376 pre_fore_color
= ForeColor
;
1377 pre_back_color
= BackColor
;
1378 pre_rtl
= RightToLeft
;
1379 // MS doesn't seem to send a CursorChangedEvent
1381 parent
= new_parent
;
1383 if (IsHandleCreated
)
1384 XplatUI
.SetParent(Handle
,
1385 (new_parent
== null || !new_parent
.IsHandleCreated
) ? IntPtr
.Zero
: new_parent
.Handle
);
1387 OnParentChanged(EventArgs
.Empty
);
1389 if (pre_enabled
!= Enabled
) {
1390 OnEnabledChanged(EventArgs
.Empty
);
1393 if (pre_visible
!= Visible
) {
1394 OnVisibleChanged(EventArgs
.Empty
);
1397 if (pre_font
!= Font
) {
1398 OnFontChanged(EventArgs
.Empty
);
1401 if (pre_fore_color
!= ForeColor
) {
1402 OnForeColorChanged(EventArgs
.Empty
);
1405 if (pre_back_color
!= BackColor
) {
1406 OnBackColorChanged(EventArgs
.Empty
);
1409 if (pre_rtl
!= RightToLeft
) {
1410 // MS sneaks a OnCreateControl and OnHandleCreated in here, I guess
1411 // because when RTL changes they have to recreate the win32 control
1412 // We don't really need that (until someone runs into compatibility issues)
1413 OnRightToLeftChanged(EventArgs
.Empty
);
1416 if ((new_parent
!= null) && new_parent
.Created
&& !Created
) {
1420 if ((binding_context
== null) && Created
) {
1421 OnBindingContextChanged(EventArgs
.Empty
);
1425 private void UpdateDistances() {
1426 if ((parent
!= null) && (parent
.layout_suspended
== 0)) {
1427 dist_left
= bounds
.X
;
1428 dist_top
= bounds
.Y
;
1429 dist_right
= parent
.ClientSize
.Width
- bounds
.X
- bounds
.Width
;
1430 dist_bottom
= parent
.ClientSize
.Height
- bounds
.Y
- bounds
.Height
;
1433 #endregion // Private & Internal Methods
1435 #region Public Static Properties
1436 public static Color DefaultBackColor
{
1438 return ThemeEngine
.Current
.DefaultControlBackColor
;
1442 public static Font DefaultFont
{
1444 return ThemeEngine
.Current
.DefaultFont
;
1448 public static Color DefaultForeColor
{
1450 return ThemeEngine
.Current
.DefaultControlForeColor
;
1454 public static Keys ModifierKeys
{
1456 return XplatUI
.State
.ModifierKeys
;
1460 public static MouseButtons MouseButtons
{
1462 return XplatUI
.State
.MouseButtons
;
1466 public static Point MousePosition
{
1468 return Cursor
.Position
;
1474 public static bool CheckForIllegalCrossThreadCalls
1477 return verify_thread_handle
;
1481 verify_thread_handle
= value;
1485 #endregion // Public Static Properties
1487 #region Public Instance Properties
1488 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
1490 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
1491 public AccessibleObject AccessibilityObject
{
1493 if (accessibility_object
==null) {
1494 accessibility_object
=CreateAccessibilityInstance();
1496 return accessibility_object
;
1500 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
1502 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
1503 public string AccessibleDefaultActionDescription
{
1505 return AccessibilityObject
.default_action
;
1509 AccessibilityObject
.default_action
=value;
1514 [DefaultValue(null)]
1515 [MWFCategory("Accessibility")]
1516 public string AccessibleDescription
{
1518 return AccessibilityObject
.description
;
1522 AccessibilityObject
.description
=value;
1527 [DefaultValue(null)]
1528 [MWFCategory("Accessibility")]
1529 public string AccessibleName
{
1531 return AccessibilityObject
.Name
;
1535 AccessibilityObject
.Name
=value;
1539 [DefaultValue(AccessibleRole
.Default
)]
1540 [MWFDescription("Role of the control"), MWFCategory("Accessibility")]
1541 public AccessibleRole AccessibleRole
{
1543 return AccessibilityObject
.role
;
1547 AccessibilityObject
.role
=value;
1551 [DefaultValue(false)]
1552 [MWFCategory("Behavior")]
1553 public virtual bool AllowDrop
{
1559 if (allow_drop
== value)
1562 if (IsHandleCreated
) {
1564 XplatUI
.SetAllowDrop (Handle
, value);
1570 [RefreshProperties(RefreshProperties
.Repaint
)]
1571 [DefaultValue(AnchorStyles
.Top
| AnchorStyles
.Left
)]
1572 [MWFCategory("Layout")]
1573 public virtual AnchorStyles Anchor
{
1575 return anchor_style
;
1581 if (parent
!= null) {
1582 parent
.PerformLayout(this, "Parent");
1588 // XXX: Implement me!
1591 public virtual bool AutoSize
{
1593 //Console.Error.WriteLine("Unimplemented: Control::get_AutoSize()");
1597 Console
.Error
.WriteLine("Unimplemented: Control::set_AutoSize(bool)");
1602 public virtual Size MaximumSize
{
1604 return maximum_size
;
1607 maximum_size
= value;
1611 public virtual Size MinimumSize
{
1613 return minimum_size
;
1616 minimum_size
= value;
1622 [MWFCategory("Appearance")]
1623 public virtual Color BackColor
{
1625 if (background_color
.IsEmpty
) {
1627 Color pcolor
= parent
.BackColor
;
1628 if (pcolor
.A
== 0xff || GetStyle(ControlStyles
.SupportsTransparentBackColor
))
1631 return DefaultBackColor
;
1633 return background_color
;
1637 if (!value.IsEmpty
&& (value.A
!= 0xff) && !GetStyle(ControlStyles
.SupportsTransparentBackColor
)) {
1638 throw new ArgumentException("Transparent background colors are not supported on this control");
1641 if (background_color
!= value) {
1642 background_color
=value;
1643 SetChildColor(this);
1644 OnBackColorChanged(EventArgs
.Empty
);
1651 [DefaultValue(null)]
1652 [MWFCategory("Appearance")]
1653 public virtual Image BackgroundImage
{
1655 return background_image
;
1659 if (background_image
!=value) {
1660 background_image
=value;
1661 OnBackgroundImageChanged(EventArgs
.Empty
);
1666 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
1668 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
1669 public virtual BindingContext BindingContext
{
1671 if (binding_context
!= null)
1672 return binding_context
;
1675 binding_context
= Parent
.BindingContext
;
1676 return binding_context
;
1679 if (binding_context
!= value) {
1680 binding_context
= value;
1681 OnBindingContextChanged(EventArgs
.Empty
);
1686 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
1688 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
1691 return bounds
.Y
+bounds
.Height
;
1695 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
1697 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
1698 public Rectangle Bounds
{
1704 SetBounds(value.Left
, value.Top
, value.Width
, value.Height
, BoundsSpecified
.All
);
1708 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
1710 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
1711 public bool CanFocus
{
1713 if (IsHandleCreated
&& Visible
&& Enabled
) {
1720 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
1722 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
1723 public bool CanSelect
{
1727 if (!GetStyle(ControlStyles
.Selectable
)) {
1732 while (parent
!= null) {
1733 if (!parent
.is_visible
|| !parent
.is_enabled
) {
1737 parent
= parent
.parent
;
1743 internal virtual bool InternalCapture
{
1753 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
1755 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
1756 public bool Capture
{
1758 return this.is_captured
;
1762 if (this.IsHandleCreated
&& value != is_captured
) {
1765 XplatUI
.GrabWindow(this.window
.Handle
, IntPtr
.Zero
);
1767 XplatUI
.UngrabWindow(this.window
.Handle
);
1768 is_captured
= false;
1774 [DefaultValue(true)]
1775 [MWFCategory("Focus")]
1776 public bool CausesValidation
{
1778 return this.causes_validation
;
1782 if (this.causes_validation
!= value) {
1783 causes_validation
= value;
1784 OnCausesValidationChanged(EventArgs
.Empty
);
1789 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
1791 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
1792 public Rectangle ClientRectangle
{
1794 client_rect
.Width
= client_size
.Width
;
1795 client_rect
.Height
= client_size
.Height
;
1800 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
1802 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
1803 public Size ClientSize
{
1806 if ((this is Form
) && (((Form
)this).form_parent_window
!= null)) {
1807 return ((Form
)this).form_parent_window
.ClientSize
;
1815 this.SetClientSizeCore(value.Width
, value.Height
);
1819 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
1821 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
1822 [DescriptionAttribute("ControlCompanyNameDescr")]
1823 public String CompanyName
{
1825 return "Mono Project, Novell, Inc.";
1829 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
1831 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
1832 public bool ContainsFocus
{
1834 IntPtr focused_window
;
1836 focused_window
= XplatUI
.GetFocus();
1837 if (IsHandleCreated
) {
1838 if (focused_window
== Handle
) {
1842 for (int i
=0; i
< child_controls
.Count
; i
++) {
1843 if (child_controls
[i
].ContainsFocus
) {
1852 [DefaultValue(null)]
1853 [MWFCategory("Behavior")]
1854 public virtual ContextMenu ContextMenu
{
1856 return context_menu
;
1860 if (context_menu
!= value) {
1861 context_menu
= value;
1862 OnContextMenuChanged(EventArgs
.Empty
);
1868 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Content
)]
1869 public ControlCollection Controls
{
1871 return this.child_controls
;
1875 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
1877 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
1878 public bool Created
{
1880 return (!is_disposed
&& is_created
);
1884 [AmbientValue(null)]
1885 [MWFCategory("Appearance")]
1886 public virtual Cursor Cursor
{
1888 if (cursor
!= null) {
1892 if (parent
!= null) {
1893 return parent
.Cursor
;
1896 return Cursors
.Default
;
1900 if (cursor
!= value) {
1905 if (IsHandleCreated
) {
1906 pt
= Cursor
.Position
;
1908 if (bounds
.Contains(pt
) || Capture
) {
1909 if (GetChildAtPoint(pt
) == null) {
1910 if (cursor
!= null) {
1911 XplatUI
.SetCursor(window
.Handle
, cursor
.handle
);
1913 if (parent
!= null) {
1914 XplatUI
.SetCursor(window
.Handle
, parent
.Cursor
.handle
);
1916 XplatUI
.SetCursor(window
.Handle
, Cursors
.Default
.handle
);
1923 OnCursorChanged(EventArgs
.Empty
);
1929 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Content
)]
1930 [ParenthesizePropertyName(true)]
1931 [RefreshProperties(RefreshProperties
.All
)]
1932 [MWFCategory("Data")]
1933 public ControlBindingsCollection DataBindings
{
1935 if (data_bindings
== null)
1936 data_bindings
= new ControlBindingsCollection (this);
1937 return data_bindings
;
1941 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
1943 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
1944 public virtual Rectangle DisplayRectangle
{
1946 return ClientRectangle
;
1950 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
1952 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
1953 public bool Disposing
{
1960 [RefreshProperties(RefreshProperties
.Repaint
)]
1961 [DefaultValue(DockStyle
.None
)]
1962 [MWFCategory("Layout")]
1963 public virtual DockStyle Dock
{
1969 if (dock_style
== value) {
1975 if (dock_style
== DockStyle
.None
) {
1976 if (explicit_bounds
== Rectangle
.Empty
)
1977 Bounds
= new Rectangle (new Point (0, 0), DefaultSize
);
1979 Bounds
= explicit_bounds
;
1982 if (parent
!= null) {
1983 parent
.PerformLayout(this, "Parent");
1986 OnDockChanged(EventArgs
.Empty
);
1992 [MWFCategory("Behavior")]
1993 public bool Enabled
{
1999 if (parent
!= null) {
2000 return parent
.Enabled
;
2008 bool old_value
= is_enabled
;
2011 if (old_value
!= value && !value && this.has_focus
)
2012 SelectNextControl(this, true, true, true, true);
2014 OnEnabledChanged (EventArgs
.Empty
);
2018 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
2020 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
2021 public virtual bool Focused
{
2023 return this.has_focus
;
2028 [AmbientValue(null)]
2030 [MWFCategory("Appearance")]
2031 public virtual Font Font
{
2037 if (Parent
!= null && Parent
.Font
!= null) {
2044 [param
:MarshalAs(UnmanagedType
.CustomMarshaler
, MarshalTypeRef
=typeof(Font
))]
2046 if (font
!= null && font
.Equals (value)) {
2052 OnFontChanged (EventArgs
.Empty
);
2057 [MWFCategory("Appearance")]
2058 public virtual Color ForeColor
{
2060 if (foreground_color
.IsEmpty
) {
2062 return parent
.ForeColor
;
2064 return DefaultForeColor
;
2066 return foreground_color
;
2070 if (foreground_color
!= value) {
2071 foreground_color
=value;
2073 OnForeColorChanged(EventArgs
.Empty
);
2080 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
2081 public IntPtr Handle
{ // IWin32Window
2084 if (verify_thread_handle
) {
2085 if (this.InvokeRequired
) {
2086 throw new InvalidOperationException("Cross-thread access of handle detected. Handle access only valid on thread that created the control");
2090 if (!IsHandleCreated
) {
2093 return window
.Handle
;
2097 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
2099 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
2100 public bool HasChildren
{
2102 if (this.child_controls
.Count
>0) {
2109 [EditorBrowsable(EditorBrowsableState
.Always
)]
2111 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
2114 return this.bounds
.Height
;
2118 SetBounds(bounds
.X
, bounds
.Y
, bounds
.Width
, value, BoundsSpecified
.Height
);
2122 [AmbientValue(ImeMode
.Inherit
)]
2124 [MWFCategory("Behavior")]
2125 public ImeMode ImeMode
{
2127 if (ime_mode
== ImeMode
.Inherit
) {
2129 return parent
.ImeMode
;
2131 return ImeMode
.NoControl
; // default value
2137 if (ime_mode
!= value) {
2140 OnImeModeChanged(EventArgs
.Empty
);
2145 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
2147 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
2148 public bool InvokeRequired
{ // ISynchronizeInvoke
2150 if (creator_thread
!= null && creator_thread
!=Thread
.CurrentThread
) {
2157 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
2159 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
2160 public bool IsAccessible
{
2162 return is_accessible
;
2166 is_accessible
= value;
2170 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
2172 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
2173 public bool IsDisposed
{
2175 return this.is_disposed
;
2179 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
2181 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
2182 public bool IsHandleCreated
{
2184 if ((window
!= null) && (window
.Handle
!= IntPtr
.Zero
)) {
2185 Hwnd hwnd
= Hwnd
.ObjectFromHandle (window
.Handle
);
2186 if (hwnd
!= null && !hwnd
.zombie
)
2195 public virtual Layout
.LayoutEngine LayoutEngine
{
2196 get { return new Layout.DefaultLayout (); }
2200 [EditorBrowsable(EditorBrowsableState
.Always
)]
2202 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
2205 return this.bounds
.X
;
2209 SetBounds(value, bounds
.Y
, bounds
.Width
, bounds
.Height
, BoundsSpecified
.X
);
2214 [MWFCategory("Layout")]
2215 public Point Location
{
2217 return new Point(bounds
.X
, bounds
.Y
);
2221 SetBounds(value.X
, value.Y
, bounds
.Width
, bounds
.Height
, BoundsSpecified
.Location
);
2226 [Localizable (true)]
2227 public Padding Margin
{
2228 get { return this.margin; }
2229 set { this.margin = value; }
2234 public string Name
{
2246 public Padding Padding
{
2258 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
2259 public Control Parent
{
2265 if (value == this) {
2266 throw new ArgumentException("A circular control reference has been made. A control cannot be owned or parented to itself.");
2269 if (parent
!=value) {
2271 parent
.Controls
.Remove(this);
2276 value.Controls
.Add(this);
2281 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
2283 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
2284 public string ProductName
{
2286 Type t
= typeof (AssemblyProductAttribute
);
2287 Assembly assembly
= GetType().Module
.Assembly
;
2288 object [] attrs
= assembly
.GetCustomAttributes (t
, false);
2289 AssemblyProductAttribute a
= null;
2290 // On MS we get a NullRefException if product attribute is not
2292 if (attrs
!= null && attrs
.Length
> 0)
2293 a
= (AssemblyProductAttribute
) attrs
[0];
2298 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
2300 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
2301 public string ProductVersion
{
2303 Type t
= typeof (AssemblyVersionAttribute
);
2304 Assembly assembly
= GetType().Module
.Assembly
;
2305 object [] attrs
= assembly
.GetCustomAttributes (t
, false);
2306 if (attrs
== null || attrs
.Length
< 1)
2308 return ((AssemblyVersionAttribute
)attrs
[0]).Version
;
2312 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
2314 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
2315 public bool RecreatingHandle
{
2317 return is_recreating
;
2321 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
2323 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
2324 public Region Region
{
2330 if (IsHandleCreated
) {
2331 XplatUI
.SetClipRegion(Handle
, value);
2333 clip_region
= value;
2337 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
2339 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
2342 return this.bounds
.X
+this.bounds
.Width
;
2346 [AmbientValue(RightToLeft
.Inherit
)]
2348 [MWFCategory("Appearance")]
2349 public virtual RightToLeft RightToLeft
{
2351 if (right_to_left
== RightToLeft
.Inherit
) {
2353 return parent
.RightToLeft
;
2355 return RightToLeft
.No
; // default value
2357 return right_to_left
;
2361 if (value != right_to_left
) {
2362 right_to_left
= value;
2363 OnRightToLeftChanged(EventArgs
.Empty
);
2368 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
2369 public override ISite Site
{
2377 AmbientProperties ap
= (AmbientProperties
) value.GetService (typeof (AmbientProperties
));
2379 BackColor
= ap
.BackColor
;
2380 ForeColor
= ap
.ForeColor
;
2388 [MWFCategory("Layout")]
2391 return new Size(Width
, Height
);
2395 SetBounds(bounds
.X
, bounds
.Y
, value.Width
, value.Height
, BoundsSpecified
.Size
);
2400 [MergableProperty(false)]
2401 [MWFCategory("Behavior")]
2402 public int TabIndex
{
2404 if (tab_index
!= -1) {
2411 if (tab_index
!= value) {
2413 OnTabIndexChanged(EventArgs
.Empty
);
2419 [DefaultValue(true)]
2420 [MWFCategory("Behavior")]
2421 public bool TabStop
{
2427 if (tab_stop
!= value) {
2429 OnTabStopChanged(EventArgs
.Empty
);
2434 [Localizable(false)]
2436 [TypeConverter(typeof(StringConverter
))]
2437 [DefaultValue(null)]
2438 [MWFCategory("Data")]
2445 control_tag
= value;
2451 [BindableAttribute(true)]
2452 [MWFCategory("Appearance")]
2453 public virtual string Text
{
2455 // Our implementation ignores ControlStyles.CacheText - we always cache
2460 if (value == null) {
2461 value = String
.Empty
;
2466 if (IsHandleCreated
) {
2467 /* we need to call .SetWindowStyle here instead of just .Text
2468 because the presence/absence of Text (== "" or not) can cause
2469 other window style things to appear/disappear */
2470 XplatUI
.SetWindowStyle(window
.Handle
, CreateParams
);
2471 XplatUI
.Text(Handle
, text
);
2473 OnTextChanged (EventArgs
.Empty
);
2478 [EditorBrowsable(EditorBrowsableState
.Always
)]
2480 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
2483 return this.bounds
.Y
;
2487 SetBounds(bounds
.X
, value, bounds
.Width
, bounds
.Height
, BoundsSpecified
.Y
);
2491 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
2493 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
2494 public Control TopLevelControl
{
2498 while (p
.parent
!= null) {
2502 return p
is Form
? p
: null;
2507 [MWFCategory("Behavior")]
2508 public bool Visible
{
2512 } else if (parent
!= null) {
2513 return parent
.Visible
;
2520 SetVisibleCore(value);
2524 [EditorBrowsable(EditorBrowsableState
.Always
)]
2526 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
2529 return this.bounds
.Width
;
2533 SetBounds(bounds
.X
, bounds
.Y
, value, bounds
.Height
, BoundsSpecified
.Width
);
2537 [EditorBrowsable(EditorBrowsableState
.Never
)]
2539 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
2540 public IWindowTarget WindowTarget
{
2549 #endregion // Public Instance Properties
2551 #region Protected Instance Properties
2552 protected virtual CreateParams CreateParams
{
2554 CreateParams create_params
= new CreateParams();
2557 create_params
.Caption
= Text
;
2560 create_params
.Caption
= text
;
2564 create_params
.X
= Left
;
2567 create_params
.X
= this.bounds
.X
;
2571 create_params
.Y
= Top
;
2574 create_params
.Y
= this.bounds
.Y
;
2578 create_params
.Width
= Width
;
2581 create_params
.Width
= this.bounds
.Width
;
2585 create_params
.Height
= Height
;
2588 create_params
.Height
= this.bounds
.Height
;
2592 create_params
.ClassName
= XplatUI
.DefaultClassName
;
2593 create_params
.ClassStyle
= 0;
2594 create_params
.ExStyle
= 0;
2595 create_params
.Param
= 0;
2598 create_params
.ExStyle
|= (int)WindowExStyles
.WS_EX_ACCEPTFILES
;
2601 if ((parent
!=null) && (parent
.IsHandleCreated
)) {
2602 create_params
.Parent
= parent
.Handle
;
2605 create_params
.Style
= (int)WindowStyles
.WS_CHILD
| (int)WindowStyles
.WS_CLIPCHILDREN
| (int)WindowStyles
.WS_CLIPSIBLINGS
;
2608 create_params
.Style
|= (int)WindowStyles
.WS_VISIBLE
;
2612 create_params
.Style
|= (int)WindowStyles
.WS_DISABLED
;
2615 switch (border_style
) {
2616 case BorderStyle
.FixedSingle
:
2617 create_params
.Style
|= (int) WindowStyles
.WS_BORDER
;
2619 case BorderStyle
.Fixed3D
:
2620 create_params
.ExStyle
|= (int) WindowExStyles
.WS_EX_CLIENTEDGE
;
2624 return create_params
;
2628 protected virtual ImeMode DefaultImeMode
{
2630 return ImeMode
.Inherit
;
2635 protected virtual Padding DefaultMargin
{
2636 get { return new Padding (3); }
2640 protected virtual Size DefaultSize
{
2642 return new Size(0, 0);
2646 protected int FontHeight
{
2656 protected bool RenderRightToLeft
{
2658 return (this.right_to_left
== RightToLeft
.Yes
);
2662 protected bool ResizeRedraw
{
2664 return GetStyle(ControlStyles
.ResizeRedraw
);
2668 SetStyle(ControlStyles
.ResizeRedraw
, value);
2672 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
2674 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
2675 protected virtual bool ShowFocusCues
{
2681 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
2683 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
2684 protected bool ShowKeyboardCues
{
2689 #endregion // Protected Instance Properties
2691 #region Public Static Methods
2692 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
2693 public static Control
FromChildHandle(IntPtr handle
) {
2694 return Control
.ControlNativeWindow
.ControlFromChildHandle (handle
);
2697 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
2698 public static Control
FromHandle(IntPtr handle
) {
2699 return Control
.ControlNativeWindow
.ControlFromHandle(handle
);
2702 public static bool IsMnemonic(char charCode
, string text
) {
2705 amp
= text
.IndexOf('&');
2708 if (amp
+ 1 < text
.Length
) {
2709 if (text
[amp
+ 1] != '&') {
2710 if (Char
.ToUpper(charCode
) == Char
.ToUpper(text
.ToCharArray(amp
+ 1, 1)[0])) {
2720 #region Protected Static Methods
2721 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
2722 protected static bool ReflectMessage(IntPtr hWnd
, ref Message m
) {
2725 c
= Control
.FromHandle(hWnd
);
2735 #region Public Instance Methods
2736 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
2737 public IAsyncResult
BeginInvoke(Delegate method
) {
2738 object [] prms
= null;
2739 if (method
is EventHandler
)
2740 prms
= new object [] { this, EventArgs.Empty }
;
2741 return BeginInvokeInternal(method
, prms
, false);
2744 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
2745 public IAsyncResult
BeginInvoke (Delegate method
, object[] args
) {
2746 return BeginInvokeInternal (method
, args
, false);
2749 public void BringToFront() {
2750 if (parent
!= null) {
2751 parent
.child_controls
.SetChildIndex(this, 0);
2754 XplatUI
.SetZOrder(Handle
, IntPtr
.Zero
, false, false);
2758 public bool Contains(Control ctl
) {
2759 while (ctl
!= null) {
2768 public void CreateControl() {
2770 throw new ObjectDisposedException(GetType().FullName
.ToString());
2776 if (!IsHandleCreated
) {
2784 Control
[] controls
= child_controls
.GetAllControls ();
2785 for (int i
=0; i
<controls
.Length
; i
++) {
2786 controls
[i
].CreateControl ();
2789 UpdateChildrenZOrder();
2791 if (binding_context
== null) { // seem to be sent whenever it's null?
2792 OnBindingContextChanged(EventArgs
.Empty
);
2798 public Graphics
CreateGraphics() {
2799 if (!IsHandleCreated
) {
2800 this.CreateHandle();
2802 return Graphics
.FromHwnd(this.window
.Handle
);
2805 public DragDropEffects
DoDragDrop(object data
, DragDropEffects allowedEffects
) {
2806 return XplatUI
.StartDrag(this.window
.Handle
, data
, allowedEffects
);
2809 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
2810 public object EndInvoke (IAsyncResult async_result
) {
2811 AsyncMethodResult result
= (AsyncMethodResult
) async_result
;
2812 return result
.EndInvoke ();
2815 public Form
FindForm() {
2828 public bool Focus() {
2829 if (CanFocus
&& IsHandleCreated
&& !has_focus
&& !is_focusing
) {
2832 is_focusing
= false;
2837 public Control
GetChildAtPoint(Point pt
) {
2838 // Microsoft's version of this function doesn't seem to work, so I can't check
2839 // if we only consider children or also grandchildren, etc.
2840 // I'm gonna say 'children only'
2841 for (int i
=0; i
<child_controls
.Count
; i
++) {
2842 if (child_controls
[i
].Bounds
.Contains(pt
)) {
2843 return child_controls
[i
];
2849 public IContainerControl
GetContainerControl() {
2850 Control current
= this;
2852 while (current
!=null) {
2853 if ((current
is IContainerControl
) && ((current
.control_style
& ControlStyles
.ContainerControl
)!=0)) {
2854 return (IContainerControl
)current
;
2856 current
= current
.parent
;
2861 public Control
GetNextControl(Control ctl
, bool forward
) {
2863 if (!this.Contains(ctl
)) {
2868 ctl
= FindControlForward(this, ctl
);
2871 ctl
= FindControlBackward(this, ctl
);
2881 public virtual Size
GetPreferredSize (Size proposedSize
) {
2882 return preferred_size
;
2886 public void Hide() {
2887 this.Visible
= false;
2890 public void Invalidate() {
2891 Invalidate(ClientRectangle
, false);
2894 public void Invalidate(bool invalidateChildren
) {
2895 Invalidate(ClientRectangle
, invalidateChildren
);
2898 public void Invalidate(System
.Drawing
.Rectangle rc
) {
2899 Invalidate(rc
, false);
2902 public void Invalidate(System
.Drawing
.Rectangle rc
, bool invalidateChildren
) {
2903 if (!IsHandleCreated
|| !Visible
|| rc
.Width
== 0 || rc
.Height
== 0) {
2907 NotifyInvalidate(rc
);
2909 XplatUI
.Invalidate(Handle
, rc
, false);
2911 if (invalidateChildren
) {
2912 Control
[] controls
= child_controls
.GetAllControls ();
2913 for (int i
=0; i
<controls
.Length
; i
++)
2914 controls
[i
].Invalidate ();
2916 OnInvalidated(new InvalidateEventArgs(rc
));
2919 public void Invalidate(System
.Drawing
.Region region
) {
2920 Invalidate(region
, false);
2923 public void Invalidate(System
.Drawing
.Region region
, bool invalidateChildren
) {
2924 RectangleF bounds
= region
.GetBounds (CreateGraphics ());
2925 Invalidate (new Rectangle ((int) bounds
.X
, (int) bounds
.Y
, (int) bounds
.Width
, (int) bounds
.Height
),
2926 invalidateChildren
);
2929 public object Invoke (Delegate method
) {
2930 object [] prms
= null;
2931 if (method
is EventHandler
)
2932 prms
= new object [] { this, EventArgs.Empty }
;
2934 return Invoke(method
, prms
);
2937 public object Invoke (Delegate method
, object[] args
) {
2938 if (!this.InvokeRequired
) {
2939 return method
.DynamicInvoke(args
);
2942 IAsyncResult result
= BeginInvoke (method
, args
);
2943 return EndInvoke(result
);
2946 internal object InvokeInternal (Delegate method
, bool disposing
) {
2947 return InvokeInternal(method
, null, disposing
);
2950 internal object InvokeInternal (Delegate method
, object[] args
, bool disposing
) {
2951 if (!this.InvokeRequired
) {
2952 return method
.DynamicInvoke(args
);
2955 IAsyncResult result
= BeginInvokeInternal (method
, args
, disposing
);
2956 return EndInvoke(result
);
2959 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
2960 public void PerformLayout() {
2961 PerformLayout(null, null);
2965 private void SetImplicitBounds (int x
, int y
, int width
, int height
)
2967 Rectangle saved_bounds
= explicit_bounds
;
2968 SetBounds (x
, y
, width
, height
);
2969 explicit_bounds
= saved_bounds
;
2973 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
2974 public void PerformLayout(Control affectedControl
, string affectedProperty
) {
2975 LayoutEventArgs levent
= new LayoutEventArgs(affectedControl
, affectedProperty
);
2977 if (layout_suspended
> 0) {
2978 layout_pending
= true;
2982 layout_pending
= false;
2984 // Prevent us from getting messed up
2987 // Perform all Dock and Anchor calculations
2991 this.layout_engine
.Layout(this, levent
);
2993 // This has been moved to Layout/DefaultLayout.cs for 2.0, please duplicate any changes/fixes there.
2995 AnchorStyles anchor
;
2998 space
= DisplayRectangle
;
3000 // Deal with docking; go through in reverse, MS docs say that lowest Z-order is closest to edge
3001 Control
[] controls
= child_controls
.GetAllControls ();
3002 for (int i
= controls
.Length
- 1; i
>= 0; i
--) {
3003 child
= controls
[i
];
3005 if (!child
.Visible
) {
3009 switch (child
.Dock
) {
3010 case DockStyle
.None
: {
3015 case DockStyle
.Left
: {
3016 child
.SetImplicitBounds(space
.Left
, space
.Y
, child
.Width
, space
.Height
);
3017 space
.X
+=child
.Width
;
3018 space
.Width
-=child
.Width
;
3022 case DockStyle
.Top
: {
3023 child
.SetImplicitBounds(space
.Left
, space
.Y
, space
.Width
, child
.Height
);
3024 space
.Y
+=child
.Height
;
3025 space
.Height
-=child
.Height
;
3029 case DockStyle
.Right
: {
3030 child
.SetImplicitBounds(space
.Right
-child
.Width
, space
.Y
, child
.Width
, space
.Height
);
3031 space
.Width
-=child
.Width
;
3035 case DockStyle
.Bottom
: {
3036 child
.SetImplicitBounds(space
.Left
, space
.Bottom
-child
.Height
, space
.Width
, child
.Height
);
3037 space
.Height
-=child
.Height
;
3043 for (int i
= controls
.Length
- 1; i
>= 0; i
--) {
3046 //if (child.Visible && (child.Dock == DockStyle.Fill)) {
3047 if (child
.Dock
== DockStyle
.Fill
) {
3048 child
.SetImplicitBounds(space
.Left
, space
.Top
, space
.Width
, space
.Height
);
3052 space
= DisplayRectangle
;
3054 for (int i
=0; i
< controls
.Length
; i
++) {
3060 child
= controls
[i
];
3062 // If the control is docked we don't need to do anything
3063 if (child
.Dock
!= DockStyle
.None
) {
3067 anchor
= child
.Anchor
;
3071 width
= child
.Width
;
3072 height
= child
.Height
;
3074 if ((anchor
& AnchorStyles
.Left
) !=0 ) {
3075 if ((anchor
& AnchorStyles
.Right
) != 0) {
3076 width
= space
.Width
- child
.dist_right
- left
;
3078 ; // Left anchored only, nothing to be done
3080 } else if ((anchor
& AnchorStyles
.Right
) != 0) {
3081 left
= space
.Width
- child
.dist_right
- width
;
3083 // left+=diff_width/2 will introduce rounding errors (diff_width removed from svn after r51780)
3084 // This calculates from scratch every time:
3085 left
= child
.dist_left
+ (space
.Width
- (child
.dist_left
+ width
+ child
.dist_right
)) / 2;
3088 if ((anchor
& AnchorStyles
.Top
) !=0 ) {
3089 if ((anchor
& AnchorStyles
.Bottom
) != 0) {
3090 height
= space
.Height
- child
.dist_bottom
- top
;
3092 ; // Top anchored only, nothing to be done
3094 } else if ((anchor
& AnchorStyles
.Bottom
) != 0) {
3095 top
= space
.Height
- child
.dist_bottom
- height
;
3097 // top += diff_height/2 will introduce rounding errors (diff_height removed from after r51780)
3098 // This calculates from scratch every time:
3099 top
= child
.dist_top
+ (space
.Height
- (child
.dist_top
+ height
+ child
.dist_bottom
)) / 2;
3111 child
.SetImplicitBounds(left
, top
, width
, height
);
3115 // Let everyone know
3119 // Need to make sure we decremend layout_suspended
3125 public Point
PointToClient (Point p
) {
3129 XplatUI
.ScreenToClient (Handle
, ref x
, ref y
);
3131 return new Point (x
, y
);
3134 public Point
PointToScreen(Point p
) {
3138 XplatUI
.ClientToScreen(Handle
, ref x
, ref y
);
3140 return new Point(x
, y
);
3143 public virtual bool PreProcessMessage(ref Message msg
) {
3144 return InternalPreProcessMessage (ref msg
);
3147 internal virtual bool InternalPreProcessMessage (ref Message msg
) {
3150 if ((msg
.Msg
== (int)Msg
.WM_KEYDOWN
) || (msg
.Msg
== (int)Msg
.WM_SYSKEYDOWN
)) {
3151 key_data
= (Keys
)msg
.WParam
.ToInt32() | XplatUI
.State
.ModifierKeys
;
3153 if (!ProcessCmdKey(ref msg
, key_data
)) {
3154 if (IsInputKey(key_data
)) {
3158 return ProcessDialogKey(key_data
);
3162 } else if (msg
.Msg
== (int)Msg
.WM_CHAR
) {
3163 if (IsInputChar((char)msg
.WParam
)) {
3166 return ProcessDialogChar((char)msg
.WParam
);
3167 } else if (msg
.Msg
== (int)Msg
.WM_SYSCHAR
) {
3168 return ProcessDialogChar((char)msg
.WParam
);
3173 public Rectangle
RectangleToClient(Rectangle r
) {
3174 return new Rectangle(PointToClient(r
.Location
), r
.Size
);
3177 public Rectangle
RectangleToScreen(Rectangle r
) {
3178 return new Rectangle(PointToScreen(r
.Location
), r
.Size
);
3181 public virtual void Refresh() {
3182 if (IsHandleCreated
== true) {
3184 XplatUI
.UpdateWindow(window
.Handle
);
3186 Control
[] controls
= child_controls
.GetAllControls ();
3187 for (int i
=0; i
< controls
.Length
; i
++) {
3188 controls
[i
].Refresh();
3194 [EditorBrowsable(EditorBrowsableState
.Never
)]
3195 public virtual void ResetBackColor() {
3196 BackColor
= Color
.Empty
;
3199 [EditorBrowsable(EditorBrowsableState
.Never
)]
3200 public void ResetBindings() {
3201 data_bindings
.Clear();
3204 [EditorBrowsable(EditorBrowsableState
.Never
)]
3205 public virtual void ResetCursor() {
3209 [EditorBrowsable(EditorBrowsableState
.Never
)]
3210 public virtual void ResetFont() {
3214 [EditorBrowsable(EditorBrowsableState
.Never
)]
3215 public virtual void ResetForeColor() {
3216 foreground_color
= Color
.Empty
;
3219 [EditorBrowsable(EditorBrowsableState
.Never
)]
3220 public void ResetImeMode() {
3221 ime_mode
= DefaultImeMode
;
3224 [EditorBrowsable(EditorBrowsableState
.Never
)]
3225 public virtual void ResetRightToLeft() {
3226 right_to_left
= RightToLeft
.Inherit
;
3229 public virtual void ResetText() {
3230 text
= String
.Empty
;
3233 public void ResumeLayout() {
3234 ResumeLayout (true);
3237 public void ResumeLayout(bool performLayout
) {
3238 if (layout_suspended
> 0) {
3242 if (layout_suspended
== 0) {
3243 Control
[] controls
= child_controls
.GetAllControls ();
3244 for (int i
=0; i
<controls
.Length
; i
++) {
3245 controls
[i
].UpdateDistances ();
3248 if (performLayout
&& layout_pending
) {
3254 public void Scale(float ratio
) {
3255 ScaleCore(ratio
, ratio
);
3258 public void Scale(float dx
, float dy
) {
3263 public void Scale(SizeF factor
) {
3264 ScaleCore(factor
.Width
, factor
.Height
);
3268 public void Select() {
3269 Select(false, false);
3273 private void printTree(Control c
, string t
) {
3274 foreach(Control i
in c
.child_controls
) {
3275 Console
.WriteLine("{2}{0}.TabIndex={1}", i
, i
.tab_index
, t
);
3276 printTree(i
, t
+"\t");
3280 public bool SelectNextControl(Control ctl
, bool forward
, bool tabStopOnly
, bool nested
, bool wrap
) {
3284 Console
.WriteLine("{0}", this.FindForm());
3285 printTree(this, "\t");
3288 if (!this.Contains(ctl
) || (!nested
&& (ctl
.parent
!= this))) {
3293 c
= GetNextControl(c
, forward
);
3302 if (c
.CanSelect
&& ((c
.parent
== this) || nested
) && (c
.tab_stop
|| !tabStopOnly
)) {
3303 c
.Select (true, true);
3306 } while (c
!= ctl
); // If we wrap back to ourselves we stop
3311 public void SendToBack() {
3312 if (parent
!= null) {
3313 parent
.child_controls
.SetChildIndex(this, parent
.child_controls
.Count
);
3317 public void SetBounds(int x
, int y
, int width
, int height
) {
3318 SetBounds(x
, y
, width
, height
, BoundsSpecified
.All
);
3321 public void SetBounds(int x
, int y
, int width
, int height
, BoundsSpecified specified
) {
3322 if ((specified
& BoundsSpecified
.X
) != BoundsSpecified
.X
) {
3326 if ((specified
& BoundsSpecified
.Y
) != BoundsSpecified
.Y
) {
3330 if ((specified
& BoundsSpecified
.Width
) != BoundsSpecified
.Width
) {
3334 if ((specified
& BoundsSpecified
.Height
) != BoundsSpecified
.Height
) {
3338 SetBoundsCore(x
, y
, width
, height
, specified
);
3339 if (parent
!= null) {
3340 parent
.PerformLayout(this, "Bounds");
3344 public void Show() {
3346 this.CreateControl();
3352 public void SuspendLayout() {
3356 public void Update() {
3357 if (IsHandleCreated
) {
3358 XplatUI
.UpdateWindow(window
.Handle
);
3361 #endregion // Public Instance Methods
3363 #region Protected Instance Methods
3364 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
3365 [MonoTODO("Implement this and tie it into Control.ControlAccessibleObject.NotifyClients")]
3366 protected void AccessibilityNotifyClients(AccessibleEvents accEvent
, int childID
) {
3367 throw new NotImplementedException();
3370 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
3371 protected virtual AccessibleObject
CreateAccessibilityInstance() {
3372 return new Control
.ControlAccessibleObject(this);
3375 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
3376 protected virtual ControlCollection
CreateControlsInstance() {
3377 return new ControlCollection(this);
3380 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
3381 protected virtual void CreateHandle() {
3383 throw new ObjectDisposedException(GetType().FullName
.ToString());
3386 if (IsHandleCreated
&& !is_recreating
) {
3390 window
.CreateHandle(CreateParams
);
3392 if (window
.Handle
!= IntPtr
.Zero
) {
3393 lock (Control
.controls
) {
3394 if (!Control
.controls
.Contains(window
.Handle
)) {
3395 Control
.controls
.Add(this);
3399 creator_thread
= Thread
.CurrentThread
;
3401 XplatUI
.EnableWindow(window
.Handle
, is_enabled
);
3402 XplatUI
.SetVisible(window
.Handle
, is_visible
, true);
3404 if (clip_region
!= null) {
3405 XplatUI
.SetClipRegion(Handle
, clip_region
);
3408 // Set our handle with our parent
3409 if ((parent
!= null) && (parent
.IsHandleCreated
)) {
3410 XplatUI
.SetParent(window
.Handle
, parent
.Handle
);
3413 // Set our handle as parent for our children
3414 Control
[] children
;
3416 children
= child_controls
.GetAllControls ();
3417 for (int i
= 0; i
< children
.Length
; i
++ ) {
3418 if (!children
[i
].RecreatingHandle
)
3419 XplatUI
.SetParent(children
[i
].Handle
, window
.Handle
);
3423 XplatUI
.SetAllowDrop (Handle
, allow_drop
);
3425 // Find out where the window manager placed us
3426 if ((CreateParams
.Style
& (int)WindowStyles
.WS_CHILD
) != 0) {
3427 XplatUI
.SetBorderStyle(window
.Handle
, (FormBorderStyle
)border_style
);
3431 OnHandleCreated(EventArgs
.Empty
);
3435 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
3436 protected virtual void DefWndProc(ref Message m
) {
3437 window
.DefWndProc(ref m
);
3440 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
3441 protected virtual void DestroyHandle() {
3442 if (IsHandleCreated
) {
3443 if (window
!= null) {
3444 window
.DestroyHandle();
3449 protected internal bool GetStyle(ControlStyles flag
) {
3450 return (control_style
& flag
) != 0;
3453 protected bool GetTopLevel() {
3457 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
3458 protected virtual void InitLayout() {
3462 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
3463 protected void InvokeGotFocus(Control toInvoke
, EventArgs e
) {
3464 toInvoke
.OnGotFocus(e
);
3467 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
3468 protected void InvokeLostFocus(Control toInvoke
, EventArgs e
) {
3469 toInvoke
.OnLostFocus(e
);
3472 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
3473 protected void InvokeOnClick(Control toInvoke
, EventArgs e
) {
3474 toInvoke
.OnClick(e
);
3477 protected void InvokePaint(Control toInvoke
, PaintEventArgs e
) {
3478 toInvoke
.OnPaint(e
);
3481 protected void InvokePaintBackground(Control toInvoke
, PaintEventArgs e
) {
3482 toInvoke
.OnPaintBackground(e
);
3485 protected virtual bool IsInputChar (char charCode
) {
3489 protected virtual bool IsInputKey (Keys keyData
) {
3490 // Doc says this one calls IsInputChar; not sure what to do with that
3494 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
3495 protected virtual void NotifyInvalidate(Rectangle invalidatedArea
) {
3499 protected virtual bool ProcessCmdKey(ref Message msg
, Keys keyData
) {
3500 if ((context_menu
!= null) && context_menu
.ProcessCmdKey(ref msg
, keyData
)) {
3504 if (parent
!= null) {
3505 return parent
.ProcessCmdKey(ref msg
, keyData
);
3511 protected virtual bool ProcessDialogChar(char charCode
) {
3512 if (parent
!= null) {
3513 return parent
.ProcessDialogChar (charCode
);
3519 protected virtual bool ProcessDialogKey (Keys keyData
) {
3520 if (parent
!= null) {
3521 return parent
.ProcessDialogKey (keyData
);
3527 protected virtual bool ProcessKeyEventArgs (ref Message msg
)
3529 KeyEventArgs key_event
;
3532 case (int)Msg
.WM_SYSKEYDOWN
:
3533 case (int)Msg
.WM_KEYDOWN
: {
3534 key_event
= new KeyEventArgs ((Keys
)msg
.WParam
.ToInt32 ());
3535 OnKeyDown (key_event
);
3536 return key_event
.Handled
;
3539 case (int)Msg
.WM_SYSKEYUP
:
3540 case (int)Msg
.WM_KEYUP
: {
3541 key_event
= new KeyEventArgs ((Keys
)msg
.WParam
.ToInt32 ());
3542 OnKeyUp (key_event
);
3543 return key_event
.Handled
;
3546 case (int)Msg
.WM_SYSCHAR
:
3547 case (int)Msg
.WM_CHAR
: {
3548 KeyPressEventArgs key_press_event
;
3550 key_press_event
= new KeyPressEventArgs((char)msg
.WParam
);
3551 OnKeyPress(key_press_event
);
3553 msg
.WParam
= (IntPtr
)key_press_event
.KeyChar
;
3555 return key_press_event
.Handled
;
3566 protected internal virtual bool ProcessKeyMessage(ref Message msg
) {
3567 if (parent
!= null) {
3568 if (parent
.ProcessKeyPreview(ref msg
)) {
3573 return ProcessKeyEventArgs(ref msg
);
3576 protected virtual bool ProcessKeyPreview(ref Message msg
) {
3577 if (parent
!= null) {
3578 return parent
.ProcessKeyPreview(ref msg
);
3584 protected virtual bool ProcessMnemonic(char charCode
) {
3589 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
3590 protected void RaiseDragEvent(object key
, DragEventArgs e
) {
3594 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
3595 protected void RaiseKeyEvent(object key
, KeyEventArgs e
) {
3599 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
3600 protected void RaiseMouseEvent(object key
, MouseEventArgs e
) {
3604 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
3605 protected void RaisePaintEvent(object key
, PaintEventArgs e
) {
3609 private void SetIsRecreating ()
3613 foreach (Control c
in Controls
.GetAllControls()) {
3614 c
.SetIsRecreating ();
3618 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
3619 protected void RecreateHandle() {
3621 Console
.WriteLine("Recreating control {0}", XplatUI
.Window(window
.Handle
));
3626 if (IsHandleCreated
) {
3628 Console
.WriteLine(" + handle is created, destroying it.");
3631 // WM_DESTROY will CreateHandle for us
3634 Console
.WriteLine(" + handle is not created, creating it.");
3642 is_recreating
= false;
3644 Console
.WriteLine (" + new handle = {0:X}", Handle
.ToInt32());
3650 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
3651 protected void ResetMouseEventArgs() {
3655 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
3656 protected ContentAlignment
RtlTranslateAlignment(ContentAlignment align
) {
3657 if (right_to_left
== RightToLeft
.No
) {
3662 case ContentAlignment
.TopLeft
: {
3663 return ContentAlignment
.TopRight
;
3666 case ContentAlignment
.TopRight
: {
3667 return ContentAlignment
.TopLeft
;
3670 case ContentAlignment
.MiddleLeft
: {
3671 return ContentAlignment
.MiddleRight
;
3674 case ContentAlignment
.MiddleRight
: {
3675 return ContentAlignment
.MiddleLeft
;
3678 case ContentAlignment
.BottomLeft
: {
3679 return ContentAlignment
.BottomRight
;
3682 case ContentAlignment
.BottomRight
: {
3683 return ContentAlignment
.BottomLeft
;
3687 // if it's center it doesn't change
3693 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
3694 protected HorizontalAlignment
RtlTranslateAlignment(HorizontalAlignment align
) {
3695 if ((right_to_left
== RightToLeft
.No
) || (align
== HorizontalAlignment
.Center
)) {
3699 if (align
== HorizontalAlignment
.Left
) {
3700 return HorizontalAlignment
.Right
;
3703 // align must be HorizontalAlignment.Right
3704 return HorizontalAlignment
.Left
;
3707 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
3708 protected LeftRightAlignment
RtlTranslateAlignment(LeftRightAlignment align
) {
3709 if (right_to_left
== RightToLeft
.No
) {
3713 if (align
== LeftRightAlignment
.Left
) {
3714 return LeftRightAlignment
.Right
;
3717 // align must be LeftRightAlignment.Right;
3718 return LeftRightAlignment
.Left
;
3721 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
3722 protected ContentAlignment
RtlTranslateContent(ContentAlignment align
) {
3723 return RtlTranslateAlignment(align
);
3726 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
3727 protected HorizontalAlignment
RtlTranslateHorizontal(HorizontalAlignment align
) {
3728 return RtlTranslateAlignment(align
);
3731 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
3732 protected LeftRightAlignment
RtlTranslateLeftRight(LeftRightAlignment align
) {
3733 return RtlTranslateAlignment(align
);
3736 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
3737 protected virtual void ScaleCore(float dx
, float dy
) {
3743 location
= new Point((int)(Left
* dx
), (int)(Top
* dy
));
3744 size
= this.ClientSize
;
3746 if (!GetStyle(ControlStyles
.FixedWidth
)) {
3747 size
.Width
= (int)(size
.Width
* dx
);
3750 if (!GetStyle(ControlStyles
.FixedHeight
)) {
3751 size
.Height
= (int)(size
.Height
* dy
);
3754 SetBounds(location
.X
, location
.Y
, size
.Width
, size
.Height
, BoundsSpecified
.All
);
3756 /* Now scale our children */
3757 Control
[] controls
= child_controls
.GetAllControls ();
3758 for (int i
=0; i
< controls
.Length
; i
++) {
3759 controls
[i
].Scale(dx
, dy
);
3765 protected virtual void Select(bool directed
, bool forward
) {
3766 IContainerControl container
;
3768 container
= GetContainerControl();
3769 if (container
!= null)
3770 container
.ActiveControl
= this;
3773 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
3774 protected virtual void SetBoundsCore(int x
, int y
, int width
, int height
, BoundsSpecified specified
) {
3775 // SetBoundsCore updates the Win32 control itself. UpdateBounds updates the controls variables and fires events, I'm guessing - pdb
3776 if (IsHandleCreated
) {
3777 XplatUI
.SetWindowPos(Handle
, x
, y
, width
, height
);
3779 // Win32 automatically changes negative width/height to 0.
3780 // The control has already been sent a WM_WINDOWPOSCHANGED message and it has the correct
3781 // data, but it'll be overwritten when we call UpdateBounds unless we get the updated
3783 if (width
< 0 || height
< 0) {
3785 XplatUI
.GetWindowPos(Handle
, this is Form
, out ix
, out iy
, out width
, out height
, out cw
, out ch
);
3789 UpdateBounds(x
, y
, width
, height
);
3794 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
3795 protected virtual void SetClientSizeCore(int x
, int y
) {
3796 // Calculate the actual window size from the client size (it usually stays the same or grows)
3797 Rectangle ClientRect
;
3798 Rectangle WindowRect
;
3801 ClientRect
= new Rectangle(0, 0, x
, y
);
3802 cp
= this.CreateParams
;
3804 if (XplatUI
.CalculateWindowRect(ref ClientRect
, cp
.Style
, cp
.ExStyle
, null, out WindowRect
)==false) {
3808 SetBounds(bounds
.X
, bounds
.Y
, WindowRect
.Width
, WindowRect
.Height
, BoundsSpecified
.Size
);
3811 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
3812 protected internal void SetStyle(ControlStyles flag
, bool value) {
3814 control_style
|= flag
;
3816 control_style
&= ~flag
;
3820 protected void SetTopLevel(bool value) {
3821 if ((GetTopLevel() != value) && (parent
!= null)) {
3822 throw new Exception();
3826 if (value == true) {
3836 is_toplevel
= value;
3839 protected virtual void SetVisibleCore(bool value) {
3840 if (value!=is_visible
) {
3841 if (value && (window
.Handle
== IntPtr
.Zero
) || !is_created
) {
3847 if (IsHandleCreated
) {
3848 XplatUI
.SetVisible(Handle
, value, true);
3849 // Explicitly move Toplevel windows to where we want them;
3850 // apparently moving unmapped toplevel windows doesn't work
3851 if (is_visible
&& (this is Form
)) {
3852 XplatUI
.SetWindowPos(window
.Handle
, bounds
.X
, bounds
.Y
, bounds
.Width
, bounds
.Height
);
3856 OnVisibleChanged(EventArgs
.Empty
);
3858 if (value == false && parent
!= null && Focused
) {
3861 // Need to start at parent, GetContainerControl might return ourselves if we're a container
3862 container
= (Control
)parent
.GetContainerControl();
3863 if (container
!= null) {
3864 container
.SelectNextControl(this, true, true, true, true);
3868 if (parent
!= null) {
3869 parent
.PerformLayout(this, "visible");
3871 PerformLayout(this, "visible");
3876 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
3877 protected void UpdateBounds() {
3885 if (!IsHandleCreated
) {
3889 XplatUI
.GetWindowPos(this.Handle
, this is Form
, out x
, out y
, out width
, out height
, out client_width
, out client_height
);
3891 UpdateBounds(x
, y
, width
, height
, client_width
, client_height
);
3894 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
3895 protected void UpdateBounds(int x
, int y
, int width
, int height
) {
3899 // Calculate client rectangle
3900 rect
= new Rectangle(0, 0, 0, 0);
3903 XplatUI
.CalculateWindowRect(ref rect
, cp
.Style
, cp
.ExStyle
, cp
.menu
, out rect
);
3904 UpdateBounds(x
, y
, width
, height
, width
- (rect
.Right
- rect
.Left
), height
- (rect
.Bottom
- rect
.Top
));
3907 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
3908 protected void UpdateBounds(int x
, int y
, int width
, int height
, int clientWidth
, int clientHeight
) {
3909 // UpdateBounds only seems to set our sizes and fire events but not update the GUI window to match
3911 bool resized
= false;
3913 // Needed to generate required notifications
3914 if ((this.bounds
.X
!=x
) || (this.bounds
.Y
!=y
)) {
3918 if ((this.Bounds
.Width
!=width
) || (this.Bounds
.Height
!=height
)) {
3925 bounds
.Height
=height
;
3927 // Assume explicit bounds set. SetImplicitBounds will restore old bounds
3928 explicit_bounds
= bounds
;
3930 client_size
.Width
=clientWidth
;
3931 client_size
.Height
=clientHeight
;
3934 OnLocationChanged(EventArgs
.Empty
);
3938 OnSizeChanged(EventArgs
.Empty
);
3942 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
3943 protected void UpdateStyles() {
3944 if (!IsHandleCreated
) {
3948 XplatUI
.SetWindowStyle(window
.Handle
, CreateParams
);
3949 OnStyleChanged(EventArgs
.Empty
);
3952 private void UpdateZOrderOfChild(Control child
) {
3953 if (IsHandleCreated
&& child
.IsHandleCreated
&& (child
.parent
== this)) {
3956 index
= child_controls
.IndexOf(child
);
3959 XplatUI
.SetZOrder(child
.Handle
, child_controls
[index
- 1].Handle
, false, false);
3961 XplatUI
.SetZOrder(child
.Handle
, IntPtr
.Zero
, true, false);
3966 private void UpdateChildrenZOrder() {
3967 Control
[] controls
;
3969 if (!IsHandleCreated
) {
3973 controls
= child_controls
.GetAllControls ();
3974 for (int i
= 1; i
< controls
.Length
; i
++ ) {
3975 XplatUI
.SetZOrder(controls
[i
].Handle
, controls
[i
-1].Handle
, false, false);
3979 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
3980 protected void UpdateZOrder() {
3981 if (parent
!= null) {
3982 parent
.UpdateZOrderOfChild(this);
3986 protected virtual void WndProc(ref Message m
) {
3988 Console
.WriteLine("Control {0} received message {1}", window
.Handle
== IntPtr
.Zero
? this.Text
: XplatUI
.Window(window
.Handle
), m
.ToString ());
3990 if ((this.control_style
& ControlStyles
.EnableNotifyMessage
) != 0) {
3994 switch((Msg
)m
.Msg
) {
3995 case Msg
.WM_DESTROY
: {
3996 OnHandleDestroyed(EventArgs
.Empty
);
3998 IntPtr handle
= window
.Handle
;
4000 window
.InvalidateHandle();
4002 if (is_recreating
) {
4004 Console
.WriteLine ("Creating handle for {0:X}", handle
.ToInt32());
4008 Console
.WriteLine (" + new handle = {0:X}", Handle
.ToInt32());
4010 is_recreating
= false;
4015 case Msg
.WM_WINDOWPOSCHANGED
: {
4017 Rectangle save_bounds
= explicit_bounds
;
4019 explicit_bounds
= save_bounds
;
4020 if (GetStyle(ControlStyles
.ResizeRedraw
)) {
4027 // Nice description of what should happen when handling WM_PAINT
4028 // can be found here: http://pluralsight.com/wiki/default.aspx/Craig/FlickerFreeControlDrawing.html
4029 // and here http://msdn.microsoft.com/msdnmag/issues/06/03/WindowsFormsPerformance/
4030 case Msg
.WM_PAINT
: {
4031 PaintEventArgs paint_event
;
4033 paint_event
= XplatUI
.PaintEventStart(Handle
, true);
4035 if (paint_event
== null) {
4039 if (invalid_region
!= null && !invalid_region
.IsVisible (paint_event
.ClipRectangle
)) {
4040 // Just blit the previous image
4041 paint_event
.Graphics
.DrawImage (ImageBuffer
, paint_event
.ClipRectangle
, paint_event
.ClipRectangle
, GraphicsUnit
.Pixel
);
4042 XplatUI
.PaintEventEnd(Handle
, true);
4047 Graphics back_dc
= null;
4048 Bitmap backbuffer
= null;
4049 if (ThemeEngine
.Current
.DoubleBufferingSupported
) {
4050 if ((control_style
& ControlStyles
.DoubleBuffer
) != 0) {
4051 backbuffer
= ImageBuffer
;
4052 back_dc
= Graphics
.FromImage (backbuffer
);
4053 dc
= paint_event
.SetGraphics (back_dc
);
4057 if (!GetStyle(ControlStyles
.Opaque
)) {
4058 OnPaintBackground(paint_event
);
4061 // Button-derived controls choose to ignore their Opaque style, give them a chance to draw their background anyways
4062 OnPaintBackgroundInternal(paint_event
);
4064 OnPaintInternal(paint_event
);
4065 if (!paint_event
.Handled
) {
4066 OnPaint(paint_event
);
4069 if (ThemeEngine
.Current
.DoubleBufferingSupported
)
4070 if ((control_style
& ControlStyles
.DoubleBuffer
) != 0) {
4071 dc
.DrawImage (ImageBuffer
, paint_event
.ClipRectangle
, paint_event
.ClipRectangle
, GraphicsUnit
.Pixel
);
4072 paint_event
.SetGraphics (dc
);
4073 invalid_region
.Exclude (paint_event
.ClipRectangle
);
4075 if (backbuffer
!= bmp_mem
)
4076 backbuffer
.Dispose();
4079 XplatUI
.PaintEventEnd(Handle
, true);
4084 case Msg
.WM_ERASEBKGND
: {
4085 // The DefWndProc will never have to handle this, we always paint the background in managed code
4086 // In theory this code would look at ControlStyles.AllPaintingInWmPaint and and call OnPaintBackground
4087 // here but it just makes things more complicated...
4088 m
.Result
= (IntPtr
)1;
4092 case Msg
.WM_LBUTTONUP
: {
4095 me
= new MouseEventArgs (FromParamToMouseButtons ((int) m
.WParam
.ToInt32()) | MouseButtons
.Left
,
4097 LowOrder ((int) m
.LParam
.ToInt32 ()), HighOrder ((int) m
.LParam
.ToInt32 ()),
4100 HandleClick(mouse_clicks
, me
);
4103 if (InternalCapture
) {
4104 InternalCapture
= false;
4107 if (mouse_clicks
> 1) {
4113 case Msg
.WM_LBUTTONDOWN
: {
4115 Select (true, true);
4117 InternalCapture
= true;
4118 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m
.WParam
.ToInt32()),
4119 mouse_clicks
, LowOrder ((int) m
.LParam
.ToInt32 ()), HighOrder ((int) m
.LParam
.ToInt32 ()),
4125 case Msg
.WM_LBUTTONDBLCLK
: {
4126 InternalCapture
= true;
4128 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m
.WParam
.ToInt32()),
4129 mouse_clicks
, LowOrder ((int) m
.LParam
.ToInt32 ()), HighOrder ((int) m
.LParam
.ToInt32 ()),
4135 case Msg
.WM_MBUTTONUP
: {
4138 me
= new MouseEventArgs (FromParamToMouseButtons ((int) m
.WParam
.ToInt32()) | MouseButtons
.Middle
,
4140 LowOrder ((int) m
.LParam
.ToInt32 ()), HighOrder ((int) m
.LParam
.ToInt32 ()),
4143 HandleClick(mouse_clicks
, me
);
4145 if (InternalCapture
) {
4146 InternalCapture
= false;
4148 if (mouse_clicks
> 1) {
4154 case Msg
.WM_MBUTTONDOWN
: {
4155 InternalCapture
= true;
4156 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m
.WParam
.ToInt32()),
4157 mouse_clicks
, LowOrder ((int) m
.LParam
.ToInt32 ()), HighOrder ((int) m
.LParam
.ToInt32 ()),
4163 case Msg
.WM_MBUTTONDBLCLK
: {
4164 InternalCapture
= true;
4166 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m
.WParam
.ToInt32()),
4167 mouse_clicks
, LowOrder ((int) m
.LParam
.ToInt32 ()), HighOrder ((int) m
.LParam
.ToInt32 ()),
4172 case Msg
.WM_RBUTTONUP
: {
4176 pt
= new Point(LowOrder ((int) m
.LParam
.ToInt32 ()), HighOrder ((int) m
.LParam
.ToInt32 ()));
4177 pt
= PointToScreen(pt
);
4179 XplatUI
.SendMessage(m
.HWnd
, Msg
.WM_CONTEXTMENU
, m
.HWnd
, (IntPtr
)(pt
.X
+ (pt
.Y
<< 16)));
4181 me
= new MouseEventArgs (FromParamToMouseButtons ((int) m
.WParam
.ToInt32()) | MouseButtons
.Right
,
4183 LowOrder ((int) m
.LParam
.ToInt32 ()), HighOrder ((int) m
.LParam
.ToInt32 ()),
4186 HandleClick(mouse_clicks
, me
);
4189 if (InternalCapture
) {
4190 InternalCapture
= false;
4193 if (mouse_clicks
> 1) {
4199 case Msg
.WM_RBUTTONDOWN
: {
4200 InternalCapture
= true;
4201 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m
.WParam
.ToInt32()),
4202 mouse_clicks
, LowOrder ((int) m
.LParam
.ToInt32 ()), HighOrder ((int) m
.LParam
.ToInt32 ()),
4207 case Msg
.WM_RBUTTONDBLCLK
: {
4208 InternalCapture
= true;
4210 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m
.WParam
.ToInt32()),
4211 mouse_clicks
, LowOrder ((int) m
.LParam
.ToInt32 ()), HighOrder ((int) m
.LParam
.ToInt32 ()),
4216 case Msg
.WM_CONTEXTMENU
: {
4217 if (context_menu
!= null) {
4220 pt
= new Point(LowOrder ((int) m
.LParam
.ToInt32 ()), HighOrder ((int) m
.LParam
.ToInt32 ()));
4221 context_menu
.Show(this, PointToClient(pt
));
4229 case Msg
.WM_MOUSEWHEEL
: {
4231 OnMouseWheel (new MouseEventArgs (FromParamToMouseButtons ((int) m
.WParam
.ToInt32()),
4232 mouse_clicks
, LowOrder ((int) m
.LParam
.ToInt32 ()), HighOrder ((int) m
.LParam
.ToInt32 ()),
4233 HighOrder(m
.WParam
.ToInt32())));
4238 case Msg
.WM_MOUSEMOVE
: {
4239 OnMouseMove (new MouseEventArgs (FromParamToMouseButtons ((int) m
.WParam
.ToInt32()),
4241 LowOrder ((int) m
.LParam
.ToInt32 ()), HighOrder ((int) m
.LParam
.ToInt32 ()),
4246 case Msg
.WM_MOUSE_ENTER
: {
4251 OnMouseEnter(EventArgs
.Empty
);
4255 case Msg
.WM_MOUSE_LEAVE
: {
4257 OnMouseLeave(EventArgs
.Empty
);
4261 case Msg
.WM_MOUSEHOVER
: {
4262 OnMouseHover(EventArgs
.Empty
);
4266 case Msg
.WM_SYSKEYUP
: {
4267 if (ProcessKeyMessage(ref m
)) {
4268 m
.Result
= IntPtr
.Zero
;
4272 if ((m
.WParam
.ToInt32() & (int)Keys
.KeyCode
) == (int)Keys
.Menu
) {
4276 if (form
!= null && form
.ActiveMenu
!= null) {
4277 form
.ActiveMenu
.ProcessCmdKey(ref m
, (Keys
)m
.WParam
.ToInt32());
4285 case Msg
.WM_SYSKEYDOWN
:
4286 case Msg
.WM_KEYDOWN
:
4288 case Msg
.WM_SYSCHAR
:
4290 if (ProcessKeyMessage(ref m
)) {
4291 m
.Result
= IntPtr
.Zero
;
4300 if (m
.LParam
!= IntPtr
.Zero
) {
4303 hi
= new HELPINFO();
4305 hi
= (HELPINFO
) Marshal
.PtrToStructure (m
.LParam
, typeof (HELPINFO
));
4306 mouse_pos
= new Point(hi
.MousePos
.x
, hi
.MousePos
.y
);
4308 mouse_pos
= Control
.MousePosition
;
4310 OnHelpRequested(new HelpEventArgs(mouse_pos
));
4311 m
.Result
= (IntPtr
)1;
4315 case Msg
.WM_KILLFOCUS
: {
4316 this.has_focus
= false;
4317 OnLostFocusInternal (EventArgs
.Empty
);
4321 case Msg
.WM_SETFOCUS
: {
4323 this.has_focus
= true;
4324 OnGotFocusInternal (EventArgs
.Empty
);
4330 case Msg
.WM_SYSCOLORCHANGE
: {
4331 ThemeEngine
.Current
.ResetDefaults();
4332 OnSystemColorsChanged(EventArgs
.Empty
);
4337 case Msg
.WM_SETCURSOR
: {
4338 if ((cursor
== null) || ((HitTest
)(m
.LParam
.ToInt32() & 0xffff) != HitTest
.HTCLIENT
)) {
4343 XplatUI
.SetCursor(window
.Handle
, cursor
.handle
);
4344 m
.Result
= (IntPtr
)1;
4355 #endregion // Public Instance Methods
4357 #region OnXXX methods
4358 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4359 protected virtual void OnBackColorChanged(EventArgs e
) {
4360 EventHandler eh
= (EventHandler
)(Events
[BackColorChangedEvent
]);
4363 for (int i
=0; i
<child_controls
.Count
; i
++) child_controls
[i
].OnParentBackColorChanged(e
);
4366 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4367 protected virtual void OnBackgroundImageChanged(EventArgs e
) {
4368 EventHandler eh
= (EventHandler
)(Events
[BackgroundImageChangedEvent
]);
4371 for (int i
=0; i
<child_controls
.Count
; i
++) child_controls
[i
].OnParentBackgroundImageChanged(e
);
4374 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4375 protected virtual void OnBindingContextChanged(EventArgs e
) {
4376 CheckDataBindings ();
4377 EventHandler eh
= (EventHandler
)(Events
[BindingContextChangedEvent
]);
4380 for (int i
=0; i
<child_controls
.Count
; i
++) child_controls
[i
].OnParentBindingContextChanged(e
);
4383 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4384 protected virtual void OnCausesValidationChanged(EventArgs e
) {
4385 EventHandler eh
= (EventHandler
)(Events
[CausesValidationChangedEvent
]);
4390 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4391 protected virtual void OnChangeUICues(UICuesEventArgs e
) {
4392 UICuesEventHandler eh
= (UICuesEventHandler
)(Events
[ChangeUICuesEvent
]);
4397 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4398 protected virtual void OnClick(EventArgs e
) {
4399 EventHandler eh
= (EventHandler
)(Events
[ClickEvent
]);
4404 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4405 protected virtual void OnContextMenuChanged(EventArgs e
) {
4406 EventHandler eh
= (EventHandler
)(Events
[ContextMenuChangedEvent
]);
4411 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4412 protected virtual void OnControlAdded(ControlEventArgs e
) {
4413 ControlEventHandler eh
= (ControlEventHandler
)(Events
[ControlAddedEvent
]);
4418 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4419 protected virtual void OnControlRemoved(ControlEventArgs e
) {
4420 ControlEventHandler eh
= (ControlEventHandler
)(Events
[ControlRemovedEvent
]);
4425 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4426 protected virtual void OnCreateControl() {
4430 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4431 protected virtual void OnCursorChanged(EventArgs e
) {
4432 EventHandler eh
= (EventHandler
)(Events
[CursorChangedEvent
]);
4437 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4438 protected virtual void OnDockChanged(EventArgs e
) {
4439 EventHandler eh
= (EventHandler
)(Events
[DockChangedEvent
]);
4444 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4445 protected virtual void OnDoubleClick(EventArgs e
) {
4446 EventHandler eh
= (EventHandler
)(Events
[DoubleClickEvent
]);
4451 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4452 protected virtual void OnDragDrop(DragEventArgs drgevent
) {
4453 DragEventHandler eh
= (DragEventHandler
)(Events
[DragDropEvent
]);
4455 eh (this, drgevent
);
4458 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4459 protected virtual void OnDragEnter(DragEventArgs drgevent
) {
4460 DragEventHandler eh
= (DragEventHandler
)(Events
[DragEnterEvent
]);
4462 eh (this, drgevent
);
4465 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4466 protected virtual void OnDragLeave(EventArgs e
) {
4467 EventHandler eh
= (EventHandler
)(Events
[DragLeaveEvent
]);
4472 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4473 protected virtual void OnDragOver(DragEventArgs drgevent
) {
4474 DragEventHandler eh
= (DragEventHandler
)(Events
[DragOverEvent
]);
4476 eh (this, drgevent
);
4479 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4480 protected virtual void OnEnabledChanged(EventArgs e
) {
4481 if (IsHandleCreated
) {
4483 if (((Form
)this).context
== null) {
4484 XplatUI
.EnableWindow(window
.Handle
, Enabled
);
4487 XplatUI
.EnableWindow(window
.Handle
, Enabled
);
4492 EventHandler eh
= (EventHandler
)(Events
[EnabledChangedEvent
]);
4496 for (int i
=0; i
<child_controls
.Count
; i
++) {
4497 child_controls
[i
].OnParentEnabledChanged(e
);
4501 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4502 protected virtual void OnEnter(EventArgs e
) {
4503 EventHandler eh
= (EventHandler
)(Events
[EnterEvent
]);
4508 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4509 protected virtual void OnFontChanged(EventArgs e
) {
4510 EventHandler eh
= (EventHandler
)(Events
[FontChangedEvent
]);
4513 for (int i
=0; i
<child_controls
.Count
; i
++) child_controls
[i
].OnParentFontChanged(e
);
4516 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4517 protected virtual void OnForeColorChanged(EventArgs e
) {
4518 EventHandler eh
= (EventHandler
)(Events
[ForeColorChangedEvent
]);
4521 for (int i
=0; i
<child_controls
.Count
; i
++) child_controls
[i
].OnParentForeColorChanged(e
);
4524 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4525 protected virtual void OnGiveFeedback(GiveFeedbackEventArgs gfbevent
) {
4526 GiveFeedbackEventHandler eh
= (GiveFeedbackEventHandler
)(Events
[GiveFeedbackEvent
]);
4528 eh (this, gfbevent
);
4531 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4532 protected virtual void OnGotFocus(EventArgs e
) {
4533 EventHandler eh
= (EventHandler
)(Events
[GotFocusEvent
]);
4538 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4539 protected virtual void OnHandleCreated(EventArgs e
) {
4540 EventHandler eh
= (EventHandler
)(Events
[HandleCreatedEvent
]);
4545 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4546 protected virtual void OnHandleDestroyed(EventArgs e
) {
4547 EventHandler eh
= (EventHandler
)(Events
[HandleDestroyedEvent
]);
4552 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4553 protected virtual void OnHelpRequested(HelpEventArgs hevent
) {
4554 HelpEventHandler eh
= (HelpEventHandler
)(Events
[HelpRequestedEvent
]);
4559 protected virtual void OnImeModeChanged(EventArgs e
) {
4560 EventHandler eh
= (EventHandler
)(Events
[ImeModeChangedEvent
]);
4565 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4566 protected virtual void OnInvalidated(InvalidateEventArgs e
) {
4567 if (ThemeEngine
.Current
.DoubleBufferingSupported
)
4568 if ((control_style
& ControlStyles
.DoubleBuffer
) != 0) {
4569 // should this block be here? seems like it
4570 // would be more at home in
4571 // NotifyInvalidated..
4572 if (e
.InvalidRect
== ClientRectangle
) {
4573 ImageBufferNeedsRedraw ();
4576 // we need this Inflate call here so
4577 // that the border of the rectangle is
4578 // considered Visible (the
4579 // invalid_region.IsVisible call) in
4580 // the WM_PAINT handling below.
4581 Rectangle r
= Rectangle
.Inflate(e
.InvalidRect
, 1,1);
4582 if (invalid_region
== null)
4583 invalid_region
= new Region (r
);
4585 invalid_region
.Union (r
);
4589 InvalidateEventHandler eh
= (InvalidateEventHandler
)(Events
[InvalidatedEvent
]);
4594 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4595 protected virtual void OnKeyDown(KeyEventArgs e
) {
4596 KeyEventHandler eh
= (KeyEventHandler
)(Events
[KeyDownEvent
]);
4601 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4602 protected virtual void OnKeyPress(KeyPressEventArgs e
) {
4603 KeyPressEventHandler eh
= (KeyPressEventHandler
)(Events
[KeyPressEvent
]);
4608 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4609 protected virtual void OnKeyUp(KeyEventArgs e
) {
4610 KeyEventHandler eh
= (KeyEventHandler
)(Events
[KeyUpEvent
]);
4615 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4616 protected virtual void OnLayout(LayoutEventArgs levent
) {
4617 LayoutEventHandler eh
= (LayoutEventHandler
)(Events
[LayoutEvent
]);
4622 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4623 protected virtual void OnLeave(EventArgs e
) {
4624 EventHandler eh
= (EventHandler
)(Events
[LeaveEvent
]);
4629 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4630 protected virtual void OnLocationChanged(EventArgs e
) {
4632 EventHandler eh
= (EventHandler
)(Events
[LocationChangedEvent
]);
4637 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4638 protected virtual void OnLostFocus(EventArgs e
) {
4639 EventHandler eh
= (EventHandler
)(Events
[LostFocusEvent
]);
4644 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4645 protected virtual void OnMouseDown(MouseEventArgs e
) {
4646 MouseEventHandler eh
= (MouseEventHandler
)(Events
[MouseDownEvent
]);
4651 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4652 protected virtual void OnMouseEnter(EventArgs e
) {
4653 EventHandler eh
= (EventHandler
)(Events
[MouseEnterEvent
]);
4658 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4659 protected virtual void OnMouseHover(EventArgs e
) {
4660 EventHandler eh
= (EventHandler
)(Events
[MouseHoverEvent
]);
4665 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4666 protected virtual void OnMouseLeave(EventArgs e
) {
4667 EventHandler eh
= (EventHandler
)(Events
[MouseLeaveEvent
]);
4672 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4673 protected virtual void OnMouseMove(MouseEventArgs e
) {
4674 MouseEventHandler eh
= (MouseEventHandler
)(Events
[MouseMoveEvent
]);
4679 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4680 protected virtual void OnMouseUp(MouseEventArgs e
) {
4681 MouseEventHandler eh
= (MouseEventHandler
)(Events
[MouseUpEvent
]);
4686 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4687 protected virtual void OnMouseWheel(MouseEventArgs e
) {
4688 MouseEventHandler eh
= (MouseEventHandler
)(Events
[MouseWheelEvent
]);
4693 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4694 protected virtual void OnMove(EventArgs e
) {
4695 EventHandler eh
= (EventHandler
)(Events
[MoveEvent
]);
4700 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4701 protected virtual void OnNotifyMessage(Message m
) {
4705 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4706 protected virtual void OnPaint(PaintEventArgs e
) {
4707 PaintEventHandler eh
= (PaintEventHandler
)(Events
[PaintEvent
]);
4712 internal virtual void OnPaintBackgroundInternal(PaintEventArgs e
) {
4716 internal virtual void OnPaintInternal(PaintEventArgs e
) {
4720 internal virtual void OnGotFocusInternal (EventArgs e
)
4725 internal virtual void OnLostFocusInternal (EventArgs e
)
4730 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4731 protected virtual void OnPaintBackground(PaintEventArgs pevent
) {
4732 PaintControlBackground (pevent
);
4735 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4736 protected virtual void OnParentBackColorChanged(EventArgs e
) {
4737 if (background_color
.IsEmpty
&& background_image
==null) {
4739 OnBackColorChanged(e
);
4743 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4744 protected virtual void OnParentBackgroundImageChanged(EventArgs e
) {
4745 if (background_color
.IsEmpty
&& background_image
==null) {
4747 OnBackgroundImageChanged(e
);
4751 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4752 protected virtual void OnParentBindingContextChanged(EventArgs e
) {
4753 if (binding_context
==null) {
4754 binding_context
=Parent
.binding_context
;
4755 OnBindingContextChanged(e
);
4759 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4760 protected virtual void OnParentChanged(EventArgs e
) {
4761 EventHandler eh
= (EventHandler
)(Events
[ParentChangedEvent
]);
4766 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4767 protected virtual void OnParentEnabledChanged(EventArgs e
) {
4769 OnEnabledChanged(e
);
4773 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4774 protected virtual void OnParentFontChanged(EventArgs e
) {
4781 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4782 protected virtual void OnParentForeColorChanged(EventArgs e
) {
4783 if (foreground_color
.IsEmpty
) {
4785 OnForeColorChanged(e
);
4789 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4790 protected virtual void OnParentRightToLeftChanged(EventArgs e
) {
4791 if (right_to_left
==RightToLeft
.Inherit
) {
4793 OnRightToLeftChanged(e
);
4797 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4798 protected virtual void OnParentVisibleChanged(EventArgs e
) {
4800 OnVisibleChanged(e
);
4804 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4805 protected virtual void OnQueryContinueDrag(QueryContinueDragEventArgs e
) {
4806 QueryContinueDragEventHandler eh
= (QueryContinueDragEventHandler
)(Events
[QueryContinueDragEvent
]);
4811 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4812 protected virtual void OnResize(EventArgs e
) {
4813 EventHandler eh
= (EventHandler
)(Events
[ResizeEvent
]);
4817 PerformLayout(this, "bounds");
4819 if (parent
!= null) {
4820 parent
.PerformLayout();
4824 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4825 protected virtual void OnRightToLeftChanged(EventArgs e
) {
4826 EventHandler eh
= (EventHandler
)(Events
[RightToLeftChangedEvent
]);
4829 for (int i
=0; i
<child_controls
.Count
; i
++) child_controls
[i
].OnParentRightToLeftChanged(e
);
4832 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4833 protected virtual void OnSizeChanged(EventArgs e
) {
4834 InvalidateBuffers ();
4836 EventHandler eh
= (EventHandler
)(Events
[SizeChangedEvent
]);
4841 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4842 protected virtual void OnStyleChanged(EventArgs e
) {
4843 EventHandler eh
= (EventHandler
)(Events
[StyleChangedEvent
]);
4848 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4849 protected virtual void OnSystemColorsChanged(EventArgs e
) {
4850 EventHandler eh
= (EventHandler
)(Events
[SystemColorsChangedEvent
]);
4855 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4856 protected virtual void OnTabIndexChanged(EventArgs e
) {
4857 EventHandler eh
= (EventHandler
)(Events
[TabIndexChangedEvent
]);
4862 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4863 protected virtual void OnTabStopChanged(EventArgs e
) {
4864 EventHandler eh
= (EventHandler
)(Events
[TabStopChangedEvent
]);
4869 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4870 protected virtual void OnTextChanged(EventArgs e
) {
4871 EventHandler eh
= (EventHandler
)(Events
[TextChangedEvent
]);
4876 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4877 protected virtual void OnValidated(EventArgs e
) {
4878 EventHandler eh
= (EventHandler
)(Events
[ValidatedEvent
]);
4883 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4884 protected virtual void OnValidating(System
.ComponentModel
.CancelEventArgs e
) {
4885 CancelEventHandler eh
= (CancelEventHandler
)(Events
[ValidatingEvent
]);
4890 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
4891 protected virtual void OnVisibleChanged(EventArgs e
) {
4892 if ((parent
!= null) && !Created
&& Visible
) {
4899 EventHandler eh
= (EventHandler
)(Events
[VisibleChangedEvent
]);
4903 // We need to tell our kids
4904 for (int i
=0; i
<child_controls
.Count
; i
++) {
4905 if (child_controls
[i
].Visible
) {
4906 child_controls
[i
].OnParentVisibleChanged(e
);
4910 #endregion // OnXXX methods
4913 static object BackColorChangedEvent
= new object ();
4914 static object BackgroundImageChangedEvent
= new object ();
4915 static object BindingContextChangedEvent
= new object ();
4916 static object CausesValidationChangedEvent
= new object ();
4917 static object ChangeUICuesEvent
= new object ();
4918 static object ClickEvent
= new object ();
4919 static object ContextMenuChangedEvent
= new object ();
4920 static object ControlAddedEvent
= new object ();
4921 static object ControlRemovedEvent
= new object ();
4922 static object CursorChangedEvent
= new object ();
4923 static object DockChangedEvent
= new object ();
4924 static object DoubleClickEvent
= new object ();
4925 static object DragDropEvent
= new object ();
4926 static object DragEnterEvent
= new object ();
4927 static object DragLeaveEvent
= new object ();
4928 static object DragOverEvent
= new object ();
4929 static object EnabledChangedEvent
= new object ();
4930 static object EnterEvent
= new object ();
4931 static object FontChangedEvent
= new object ();
4932 static object ForeColorChangedEvent
= new object ();
4933 static object GiveFeedbackEvent
= new object ();
4934 static object GotFocusEvent
= new object ();
4935 static object HandleCreatedEvent
= new object ();
4936 static object HandleDestroyedEvent
= new object ();
4937 static object HelpRequestedEvent
= new object ();
4938 static object ImeModeChangedEvent
= new object ();
4939 static object InvalidatedEvent
= new object ();
4940 static object KeyDownEvent
= new object ();
4941 static object KeyPressEvent
= new object ();
4942 static object KeyUpEvent
= new object ();
4943 static object LayoutEvent
= new object ();
4944 static object LeaveEvent
= new object ();
4945 static object LocationChangedEvent
= new object ();
4946 static object LostFocusEvent
= new object ();
4947 static object MouseDownEvent
= new object ();
4948 static object MouseEnterEvent
= new object ();
4949 static object MouseHoverEvent
= new object ();
4950 static object MouseLeaveEvent
= new object ();
4951 static object MouseMoveEvent
= new object ();
4952 static object MouseUpEvent
= new object ();
4953 static object MouseWheelEvent
= new object ();
4954 static object MoveEvent
= new object ();
4955 static object PaintEvent
= new object ();
4956 static object ParentChangedEvent
= new object ();
4957 static object QueryAccessibilityHelpEvent
= new object ();
4958 static object QueryContinueDragEvent
= new object ();
4959 static object ResizeEvent
= new object ();
4960 static object RightToLeftChangedEvent
= new object ();
4961 static object SizeChangedEvent
= new object ();
4962 static object StyleChangedEvent
= new object ();
4963 static object SystemColorsChangedEvent
= new object ();
4964 static object TabIndexChangedEvent
= new object ();
4965 static object TabStopChangedEvent
= new object ();
4966 static object TextChangedEvent
= new object ();
4967 static object ValidatedEvent
= new object ();
4968 static object ValidatingEvent
= new object ();
4969 static object VisibleChangedEvent
= new object ();
4971 public event EventHandler BackColorChanged
{
4972 add { Events.AddHandler (BackColorChangedEvent, value); }
4973 remove { Events.RemoveHandler (BackColorChangedEvent, value); }
4976 public event EventHandler BackgroundImageChanged
{
4977 add { Events.AddHandler (BackgroundImageChangedEvent, value); }
4978 remove { Events.RemoveHandler (BackgroundImageChangedEvent, value); }
4981 public event EventHandler BindingContextChanged
{
4982 add { Events.AddHandler (BindingContextChangedEvent, value); }
4983 remove { Events.RemoveHandler (BindingContextChangedEvent, value); }
4986 public event EventHandler CausesValidationChanged
{
4987 add { Events.AddHandler (CausesValidationChangedEvent, value); }
4988 remove { Events.RemoveHandler (CausesValidationChangedEvent, value); }
4991 public event UICuesEventHandler ChangeUICues
{
4992 add { Events.AddHandler (ChangeUICuesEvent, value); }
4993 remove { Events.RemoveHandler (ChangeUICuesEvent, value); }
4996 public event EventHandler Click
{
4997 add { Events.AddHandler (ClickEvent, value); }
4998 remove { Events.RemoveHandler (ClickEvent, value); }
5001 public event EventHandler ContextMenuChanged
{
5002 add { Events.AddHandler (ContextMenuChangedEvent, value); }
5003 remove { Events.RemoveHandler (ContextMenuChangedEvent, value); }
5006 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5008 public event ControlEventHandler ControlAdded
{
5009 add { Events.AddHandler (ControlAddedEvent, value); }
5010 remove { Events.RemoveHandler (ControlAddedEvent, value); }
5013 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5015 public event ControlEventHandler ControlRemoved
{
5016 add { Events.AddHandler (ControlRemovedEvent, value); }
5017 remove { Events.RemoveHandler (ControlRemovedEvent, value); }
5020 [MWFDescription("Fired when the cursor for the control has been changed"), MWFCategory("PropertyChanged")]
5021 public event EventHandler CursorChanged
{
5022 add { Events.AddHandler (CursorChangedEvent, value); }
5023 remove { Events.RemoveHandler (CursorChangedEvent, value); }
5025 public event EventHandler DockChanged
{
5026 add { Events.AddHandler (DockChangedEvent, value); }
5027 remove { Events.RemoveHandler (DockChangedEvent, value); }
5030 public event EventHandler DoubleClick
{
5031 add { Events.AddHandler (DoubleClickEvent, value); }
5032 remove { Events.RemoveHandler (DoubleClickEvent, value); }
5035 public event DragEventHandler DragDrop
{
5036 add { Events.AddHandler (DragDropEvent, value); }
5037 remove { Events.RemoveHandler (DragDropEvent, value); }
5040 public event DragEventHandler DragEnter
{
5041 add { Events.AddHandler (DragEnterEvent, value); }
5042 remove { Events.RemoveHandler (DragEnterEvent, value); }
5045 public event EventHandler DragLeave
{
5046 add { Events.AddHandler (DragLeaveEvent, value); }
5047 remove { Events.RemoveHandler (DragLeaveEvent, value); }
5050 public event DragEventHandler DragOver
{
5051 add { Events.AddHandler (DragOverEvent, value); }
5052 remove { Events.RemoveHandler (DragOverEvent, value); }
5055 public event EventHandler EnabledChanged
{
5056 add { Events.AddHandler (EnabledChangedEvent, value); }
5057 remove { Events.RemoveHandler (EnabledChangedEvent, value); }
5060 public event EventHandler Enter
{
5061 add { Events.AddHandler (EnterEvent, value); }
5062 remove { Events.RemoveHandler (EnterEvent, value); }
5065 public event EventHandler FontChanged
{
5066 add { Events.AddHandler (FontChangedEvent, value); }
5067 remove { Events.RemoveHandler (FontChangedEvent, value); }
5070 public event EventHandler ForeColorChanged
{
5071 add { Events.AddHandler (ForeColorChangedEvent, value); }
5072 remove { Events.RemoveHandler (ForeColorChangedEvent, value); }
5075 public event GiveFeedbackEventHandler GiveFeedback
{
5076 add { Events.AddHandler (GiveFeedbackEvent, value); }
5077 remove { Events.RemoveHandler (GiveFeedbackEvent, value); }
5080 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5082 public event EventHandler GotFocus
{
5083 add { Events.AddHandler (GotFocusEvent, value); }
5084 remove { Events.RemoveHandler (GotFocusEvent, value); }
5088 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5090 public event EventHandler HandleCreated
{
5091 add { Events.AddHandler (HandleCreatedEvent, value); }
5092 remove { Events.RemoveHandler (HandleCreatedEvent, value); }
5095 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5097 public event EventHandler HandleDestroyed
{
5098 add { Events.AddHandler (HandleDestroyedEvent, value); }
5099 remove { Events.RemoveHandler (HandleDestroyedEvent, value); }
5102 public event HelpEventHandler HelpRequested
{
5103 add { Events.AddHandler (HelpRequestedEvent, value); }
5104 remove { Events.RemoveHandler (HelpRequestedEvent, value); }
5107 public event EventHandler ImeModeChanged
{
5108 add { Events.AddHandler (ImeModeChangedEvent, value); }
5109 remove { Events.RemoveHandler (ImeModeChangedEvent, value); }
5112 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5114 public event InvalidateEventHandler Invalidated
{
5115 add { Events.AddHandler (InvalidatedEvent, value); }
5116 remove { Events.RemoveHandler (InvalidatedEvent, value); }
5119 public event KeyEventHandler KeyDown
{
5120 add { Events.AddHandler (KeyDownEvent, value); }
5121 remove { Events.RemoveHandler (KeyDownEvent, value); }
5124 public event KeyPressEventHandler KeyPress
{
5125 add { Events.AddHandler (KeyPressEvent, value); }
5126 remove { Events.RemoveHandler (KeyPressEvent, value); }
5129 public event KeyEventHandler KeyUp
{
5130 add { Events.AddHandler (KeyUpEvent, value); }
5131 remove { Events.RemoveHandler (KeyUpEvent, value); }
5134 public event LayoutEventHandler Layout
{
5135 add { Events.AddHandler (LayoutEvent, value); }
5136 remove { Events.RemoveHandler (LayoutEvent, value); }
5139 public event EventHandler Leave
{
5140 add { Events.AddHandler (LeaveEvent, value); }
5141 remove { Events.RemoveHandler (LeaveEvent, value); }
5144 public event EventHandler LocationChanged
{
5145 add { Events.AddHandler (LocationChangedEvent, value); }
5146 remove { Events.RemoveHandler (LocationChangedEvent, value); }
5149 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5151 public event EventHandler LostFocus
{
5152 add { Events.AddHandler (LostFocusEvent, value); }
5153 remove { Events.RemoveHandler (LostFocusEvent, value); }
5156 public event MouseEventHandler MouseDown
{
5157 add { Events.AddHandler (MouseDownEvent, value); }
5158 remove { Events.RemoveHandler (MouseDownEvent, value); }
5161 public event EventHandler MouseEnter
{
5162 add { Events.AddHandler (MouseEnterEvent, value); }
5163 remove { Events.RemoveHandler (MouseEnterEvent, value); }
5166 public event EventHandler MouseHover
{
5167 add { Events.AddHandler (MouseHoverEvent, value); }
5168 remove { Events.RemoveHandler (MouseHoverEvent, value); }
5171 public event EventHandler MouseLeave
{
5172 add { Events.AddHandler (MouseLeaveEvent, value); }
5173 remove { Events.RemoveHandler (MouseLeaveEvent, value); }
5176 public event MouseEventHandler MouseMove
{
5177 add { Events.AddHandler (MouseMoveEvent, value); }
5178 remove { Events.RemoveHandler (MouseMoveEvent, value); }
5181 public event MouseEventHandler MouseUp
{
5182 add { Events.AddHandler (MouseUpEvent, value); }
5183 remove { Events.RemoveHandler (MouseUpEvent, value); }
5186 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
5188 public event MouseEventHandler MouseWheel
{
5189 add { Events.AddHandler (MouseWheelEvent, value); }
5190 remove { Events.RemoveHandler (MouseWheelEvent, value); }
5193 public event EventHandler Move
{
5194 add { Events.AddHandler (MoveEvent, value); }
5195 remove { Events.RemoveHandler (MoveEvent, value); }
5198 public event PaintEventHandler Paint
{
5199 add { Events.AddHandler (PaintEvent, value); }
5200 remove { Events.RemoveHandler (PaintEvent, value); }
5203 public event EventHandler ParentChanged
{
5204 add { Events.AddHandler (ParentChangedEvent, value); }
5205 remove { Events.RemoveHandler (ParentChangedEvent, value); }
5208 public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp
{
5209 add { Events.AddHandler (QueryAccessibilityHelpEvent, value); }
5210 remove { Events.RemoveHandler (QueryAccessibilityHelpEvent, value); }
5213 public event QueryContinueDragEventHandler QueryContinueDrag
{
5214 add { Events.AddHandler (QueryContinueDragEvent, value); }
5215 remove { Events.RemoveHandler (QueryContinueDragEvent, value); }
5218 public event EventHandler Resize
{
5219 add { Events.AddHandler (ResizeEvent, value); }
5220 remove { Events.RemoveHandler (ResizeEvent, value); }
5223 public event EventHandler RightToLeftChanged
{
5224 add { Events.AddHandler (RightToLeftChangedEvent, value); }
5225 remove { Events.RemoveHandler (RightToLeftChangedEvent, value); }
5228 public event EventHandler SizeChanged
{
5229 add { Events.AddHandler (SizeChangedEvent, value); }
5230 remove { Events.RemoveHandler (SizeChangedEvent, value); }
5233 public event EventHandler StyleChanged
{
5234 add { Events.AddHandler (StyleChangedEvent, value); }
5235 remove { Events.RemoveHandler (StyleChangedEvent, value); }
5238 public event EventHandler SystemColorsChanged
{
5239 add { Events.AddHandler (SystemColorsChangedEvent, value); }
5240 remove { Events.RemoveHandler (SystemColorsChangedEvent, value); }
5243 public event EventHandler TabIndexChanged
{
5244 add { Events.AddHandler (TabIndexChangedEvent, value); }
5245 remove { Events.RemoveHandler (TabIndexChangedEvent, value); }
5248 public event EventHandler TabStopChanged
{
5249 add { Events.AddHandler (TabStopChangedEvent, value); }
5250 remove { Events.RemoveHandler (TabStopChangedEvent, value); }
5253 public event EventHandler TextChanged
{
5254 add { Events.AddHandler (TextChangedEvent, value); }
5255 remove { Events.RemoveHandler (TextChangedEvent, value); }
5258 public event EventHandler Validated
{
5259 add { Events.AddHandler (ValidatedEvent, value); }
5260 remove { Events.RemoveHandler (ValidatedEvent, value); }
5263 public event CancelEventHandler Validating
{
5264 add { Events.AddHandler (ValidatingEvent, value); }
5265 remove { Events.RemoveHandler (ValidatingEvent, value); }
5268 public event EventHandler VisibleChanged
{
5269 add { Events.AddHandler (VisibleChangedEvent, value); }
5270 remove { Events.RemoveHandler (VisibleChangedEvent, value); }
5273 #endregion // Events