In System.Windows.Forms:
[mono-project.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / Control.cs
blob39fc3e1e9088f3ca50c2e4eeaa4122be6ff2ba3a
1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
8 //
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
11 //
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 // Copyright (c) 2004-2006 Novell, Inc.
22 // Authors:
23 // Peter Bartok pbartok@novell.com
25 // Partially based on work by:
26 // Aleksey Ryabchuk ryabchuk@yahoo.com
27 // Alexandre Pigolkine pigolkine@gmx.de
28 // Dennis Hayes dennish@raytek.com
29 // Jaak Simm jaaksimm@firm.ee
30 // John Sohn jsohn@columbus.rr.com
33 // COMPLETE
35 #undef DebugRecreate
36 #undef DebugFocus
38 using System;
39 using System.ComponentModel;
40 using System.ComponentModel.Design;
41 using System.ComponentModel.Design.Serialization;
42 using System.Collections;
43 using System.Diagnostics;
44 using System.Drawing;
45 using System.Drawing.Drawing2D;
46 using System.Reflection;
47 using System.Runtime.InteropServices;
48 using System.Security;
49 using System.Threading;
51 namespace System.Windows.Forms
53 [Designer("System.Windows.Forms.Design.ControlDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
54 [DefaultProperty("Text")]
55 [DefaultEvent("Click")]
56 [DesignerSerializer("System.Windows.Forms.Design.ControlCodeDomSerializer, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
57 [ToolboxItemFilter("System.Windows.Forms")]
58 public class Control : Component, ISynchronizeInvoke, IWin32Window
60 #region Local Variables
62 // Basic
63 internal Rectangle bounds; // bounding rectangle for control (client area + decorations)
64 Rectangle explicit_bounds; // explicitly set bounds
65 internal object creator_thread; // thread that created the control
66 internal ControlNativeWindow window; // object for native window handle
67 string name; // for object naming
69 // State
70 bool is_created; // true if OnCreateControl has been sent
71 internal bool has_focus; // true if control has focus
72 internal bool is_visible; // true if control is visible
73 internal bool is_entered; // is the mouse inside the control?
74 internal bool is_enabled; // true if control is enabled (usable/not grayed out)
75 bool is_accessible; // true if the control is visible to accessibility applications
76 bool is_captured; // tracks if the control has captured the mouse
77 internal bool is_toplevel; // tracks if the control is a toplevel window
78 bool is_recreating; // tracks if the handle for the control is being recreated
79 bool causes_validation; // tracks if validation is executed on changes
80 bool is_focusing; // tracks if Focus has been called on the control and has not yet finished
81 int tab_index; // position in tab order of siblings
82 bool tab_stop; // is the control a tab stop?
83 bool is_disposed; // has the window already been disposed?
84 Size client_size; // size of the client area (window excluding decorations)
85 Rectangle client_rect; // rectangle with the client area (window excluding decorations)
86 ControlStyles control_style; // rather win32-specific, style bits for control
87 ImeMode ime_mode;
88 bool layout_pending; // true if our parent needs to re-layout us
89 object control_tag; // object that contains data about our control
90 internal int mouse_clicks; // Counter for mouse clicks
91 Cursor cursor; // Cursor for the window
92 internal bool allow_drop; // true if the control accepts droping objects on it
93 Region clip_region; // User-specified clip region for the window
95 // Visuals
96 internal Color foreground_color; // foreground color for control
97 internal Color background_color; // background color for control
98 Image background_image; // background image for control
99 internal Font font; // font for control
100 string text; // window/title text for control
101 internal BorderStyle border_style; // Border style of control
103 // Layout
104 int layout_suspended;
105 internal AnchorStyles anchor_style; // anchoring requirements for our control
106 internal DockStyle dock_style; // docking requirements for our control (supercedes anchoring)
107 // Please leave the next 4 as internal until DefaultLayout (2.0) is rewritten
108 internal int dist_left; // distance to the left border of the parent
109 internal int dist_top; // distance to the top border of the parent
110 internal int dist_right; // distance to the right border of the parent
111 internal int dist_bottom; // distance to the bottom border of the parent
113 // to be categorized...
114 ControlCollection child_controls; // our children
115 Control parent; // our parent control
116 AccessibleObject accessibility_object; // object that contains accessibility information about our control
117 BindingContext binding_context;
118 RightToLeft right_to_left; // drawing direction for control
119 ContextMenu context_menu; // Context menu associated with the control
121 // double buffering
122 Graphics backbuffer_dc;
123 object backbuffer;
124 Region invalid_region;
126 ControlBindingsCollection data_bindings;
128 #if NET_2_0
129 internal bool use_compatible_text_rendering;
130 static bool verify_thread_handle;
131 Padding padding;
132 Size maximum_size;
133 Size minimum_size;
134 Size preferred_size;
135 Padding margin;
136 Layout.LayoutEngine layout_engine;
137 #endif
139 #endregion // Local Variables
141 #region Private Classes
142 // This helper class allows us to dispatch messages to Control.WndProc
143 internal class ControlNativeWindow : NativeWindow {
144 private Control owner;
146 public ControlNativeWindow(Control control) : base() {
147 this.owner=control;
151 public Control Owner {
152 get {
153 return owner;
157 static internal Control ControlFromHandle(IntPtr hWnd) {
158 ControlNativeWindow window;
160 window = (ControlNativeWindow)window_collection[hWnd];
161 if (window != null) {
162 return window.owner;
165 return null;
168 static internal Control ControlFromChildHandle (IntPtr handle) {
169 ControlNativeWindow window;
171 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
172 while (hwnd != null) {
173 window = (ControlNativeWindow)window_collection[hwnd.Handle];
174 if (window != null) {
175 return window.owner;
177 hwnd = hwnd.Parent;
180 return null;
183 protected override void WndProc(ref Message m) {
184 owner.WndProc(ref m);
187 #endregion
189 #region Public Classes
190 [ComVisible(true)]
191 public class ControlAccessibleObject : AccessibleObject {
192 Control owner;
194 #region ControlAccessibleObject Constructors
195 public ControlAccessibleObject(Control ownerControl)
196 : base (ownerControl)
198 this.owner = ownerControl;
200 #endregion // ControlAccessibleObject Constructors
202 #region ControlAccessibleObject Public Instance Properties
203 public override string DefaultAction {
204 get {
205 return base.DefaultAction;
209 public override string Description {
210 get {
211 return base.Description;
215 public IntPtr Handle {
216 get {
217 return owner.Handle;
220 set {
221 // We don't want to let them set it
225 public override string Help {
226 get {
227 return base.Help;
231 public override string KeyboardShortcut {
232 get {
233 return base.KeyboardShortcut;
237 public override string Name {
238 get {
239 return base.Name;
242 set {
243 base.Name = value;
247 public Control Owner {
248 get {
249 return owner;
253 public override AccessibleObject Parent {
254 get {
255 return base.Parent;
260 public override AccessibleRole Role {
261 get {
262 return base.Role;
265 #endregion // ControlAccessibleObject Public Instance Properties
267 #region ControlAccessibleObject Public Instance Methods
268 public override int GetHelpTopic(out string FileName) {
269 return base.GetHelpTopic (out FileName);
272 [MonoTODO("Implement this and tie it into Control.AccessibilityNotifyClients")]
273 public void NotifyClients(AccessibleEvents accEvent) {
274 throw new NotImplementedException();
277 [MonoTODO("Implement this and tie it into Control.AccessibilityNotifyClients")]
278 public void NotifyClients(AccessibleEvents accEvent, int childID) {
279 throw new NotImplementedException();
282 public override string ToString() {
283 return "ControlAccessibleObject: Owner = " + owner.ToString() + ", Text: " + owner.text;
286 #endregion // ControlAccessibleObject Public Instance Methods
289 [DesignerSerializer("System.Windows.Forms.Design.ControlCollectionCodeDomSerializer, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
290 [ListBindable(false)]
291 public class ControlCollection : IList, ICollection, ICloneable, IEnumerable {
292 #region ControlCollection Local Variables
293 ArrayList list;
294 ArrayList impl_list;
295 Control[] all_controls;
296 Control owner;
297 #endregion // ControlCollection Local Variables
299 #region ControlCollection Public Constructor
300 public ControlCollection(Control owner) {
301 this.owner=owner;
302 this.list=new ArrayList();
304 #endregion
306 #region ControlCollection Public Instance Properties
307 public int Count {
308 get {
309 return list.Count;
313 public bool IsReadOnly {
314 get {
315 return list.IsReadOnly;
319 public virtual Control this[int index] {
320 get {
321 if (index < 0 || index >= list.Count) {
322 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
324 return (Control)list[index];
327 #endregion // ControlCollection Public Instance Properties
329 #region ControlCollection Private Instance Methods
330 public virtual void Add (Control value)
332 if (value == null)
333 return;
335 if (Contains (value)) {
336 owner.PerformLayout();
337 return;
340 if (value.tab_index == -1) {
341 int end;
342 int index;
343 int use;
345 use = 0;
346 end = owner.child_controls.Count;
347 for (int i = 0; i < end; i++) {
348 index = owner.child_controls[i].tab_index;
349 if (index >= use) {
350 use = index + 1;
353 value.tab_index = use;
356 if (value.parent != null) {
357 value.parent.Controls.Remove(value);
360 all_controls = null;
361 list.Add (value);
363 value.ChangeParent(owner);
365 value.InitLayout();
367 owner.UpdateChildrenZOrder();
368 owner.PerformLayout(value, "Parent");
369 owner.OnControlAdded(new ControlEventArgs(value));
372 internal void AddToList (Control c)
374 all_controls = null;
375 list.Add (c);
378 internal virtual void AddImplicit (Control control)
380 if (impl_list == null)
381 impl_list = new ArrayList ();
383 if (AllContains (control))
384 return;
386 all_controls = null;
387 impl_list.Add (control);
389 control.ChangeParent (owner);
390 control.InitLayout ();
391 owner.UpdateChildrenZOrder ();
392 owner.PerformLayout (control, "Parent");
393 owner.OnControlAdded (new ControlEventArgs (control));
396 public virtual void AddRange (Control[] controls)
398 if (controls == null)
399 throw new ArgumentNullException ("controls");
401 owner.SuspendLayout ();
403 try {
404 for (int i = 0; i < controls.Length; i++)
405 Add (controls[i]);
406 } finally {
407 owner.ResumeLayout ();
411 internal virtual void AddRangeImplicit (Control [] controls)
413 if (controls == null)
414 throw new ArgumentNullException ("controls");
416 owner.SuspendLayout ();
418 try {
419 for (int i = 0; i < controls.Length; i++)
420 AddImplicit (controls [i]);
421 } finally {
422 owner.ResumeLayout ();
426 public virtual void Clear ()
428 all_controls = null;
430 // MS sends remove events in reverse order
431 while (list.Count > 0) {
432 Remove((Control)list[list.Count - 1]);
436 internal virtual void ClearImplicit ()
438 if (impl_list == null)
439 return;
440 all_controls = null;
441 impl_list.Clear ();
444 public bool Contains (Control value)
446 for (int i = list.Count; i > 0; ) {
447 i--;
449 if (list [i] == value) {
450 // Do we need to do anything here?
451 return true;
454 return false;
457 internal bool ImplicitContains (Control value)
459 if (impl_list == null)
460 return false;
462 for (int i = impl_list.Count; i > 0; ) {
463 i--;
465 if (impl_list [i] == value) {
466 // Do we need to do anything here?
467 return true;
470 return false;
473 internal bool AllContains (Control value)
475 return Contains (value) || ImplicitContains (value);
478 public void CopyTo (Array array, int index)
480 list.CopyTo(array, index);
483 public override bool Equals(object other) {
484 if (other is ControlCollection && (((ControlCollection)other).owner==this.owner)) {
485 return(true);
486 } else {
487 return(false);
491 public int GetChildIndex(Control child) {
492 return GetChildIndex(child, false);
495 public int GetChildIndex(Control child, bool throwException) {
496 int index;
498 index=list.IndexOf(child);
500 if (index==-1 && throwException) {
501 throw new ArgumentException("Not a child control", "child");
503 return index;
506 public IEnumerator GetEnumerator() {
507 return list.GetEnumerator();
510 internal IEnumerator GetAllEnumerator ()
512 Control [] res = GetAllControls ();
513 return res.GetEnumerator ();
516 internal Control [] GetAllControls ()
518 if (all_controls != null)
519 return all_controls;
521 if (impl_list == null) {
522 all_controls = (Control []) list.ToArray (typeof (Control));
523 return all_controls;
526 all_controls = new Control [list.Count + impl_list.Count];
527 impl_list.CopyTo (all_controls);
528 list.CopyTo (all_controls, impl_list.Count);
530 return all_controls;
533 public override int GetHashCode() {
534 return base.GetHashCode();
537 public int IndexOf(Control control) {
538 return list.IndexOf(control);
541 public virtual void Remove(Control value) {
542 if (value == null)
543 return;
545 owner.PerformLayout(value, "Parent");
546 owner.OnControlRemoved(new ControlEventArgs(value));
548 all_controls = null;
549 list.Remove(value);
551 value.ChangeParent(null);
553 owner.UpdateChildrenZOrder();
556 internal virtual void RemoveImplicit (Control control)
558 if (impl_list != null) {
559 all_controls = null;
560 owner.PerformLayout (control, "Parent");
561 owner.OnControlRemoved (new ControlEventArgs (control));
562 impl_list.Remove (control);
564 control.ChangeParent (null);
565 owner.UpdateChildrenZOrder ();
568 public void RemoveAt(int index) {
569 if (index < 0 || index >= list.Count) {
570 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
572 Remove ((Control)list[index]);
575 public void SetChildIndex(Control child, int newIndex) {
576 if (child == null)
577 throw new ArgumentNullException ("child");
579 int old_index;
581 old_index=list.IndexOf(child);
582 if (old_index==-1) {
583 throw new ArgumentException("Not a child control", "child");
586 if (old_index==newIndex) {
587 return;
590 all_controls = null;
591 list.RemoveAt(old_index);
593 if (newIndex>list.Count) {
594 list.Add(child);
595 } else {
596 list.Insert(newIndex, child);
598 child.UpdateZOrder();
599 owner.PerformLayout();
601 #endregion // ControlCollection Private Instance Methods
603 #region ControlCollection Interface Properties
604 object IList.this[int index] {
605 get {
606 if (index<0 || index>=list.Count) {
607 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
609 return this[index];
612 set {
613 if (!(value is Control)) {
614 throw new ArgumentException("Object of type Control required", "value");
617 all_controls = null;
618 Control ctrl = (Control) value;
619 list[index]= ctrl;
621 ctrl.ChangeParent(owner);
623 ctrl.InitLayout();
625 owner.UpdateChildrenZOrder();
626 owner.PerformLayout(ctrl, "Parent");
630 bool IList.IsFixedSize {
631 get {
632 return false;
636 bool ICollection.IsSynchronized {
637 get {
638 return list.IsSynchronized;
642 object ICollection.SyncRoot {
643 get {
644 return list.SyncRoot;
647 #endregion // ControlCollection Interface Properties
649 #region ControlCollection Interface Methods
650 int IList.Add(object value) {
651 if (value == null) {
652 throw new ArgumentNullException("value", "Cannot add null controls");
655 if (!(value is Control)) {
656 throw new ArgumentException("Object of type Control required", "value");
659 return list.Add(value);
662 bool IList.Contains(object value) {
663 if (!(value is Control)) {
664 throw new ArgumentException("Object of type Control required", "value");
667 return this.Contains((Control) value);
670 int IList.IndexOf(object value) {
671 if (!(value is Control)) {
672 throw new ArgumentException("Object of type Control required", "value");
675 return this.IndexOf((Control) value);
678 void IList.Insert(int index, object value) {
679 if (!(value is Control)) {
680 throw new ArgumentException("Object of type Control required", "value");
682 all_controls = null;
683 list.Insert(index, value);
686 void IList.Remove(object value) {
687 if (!(value is Control)) {
688 throw new ArgumentException("Object of type Control required", "value");
690 all_controls = null;
691 list.Remove(value);
694 Object ICloneable.Clone() {
695 ControlCollection clone = new ControlCollection(this.owner);
696 clone.list=(ArrayList)list.Clone(); // FIXME: Do we need this?
697 return clone;
699 #endregion // ControlCollection Interface Methods
701 #endregion // ControlCollection Class
703 #region Public Constructors
704 public Control()
706 anchor_style = AnchorStyles.Top | AnchorStyles.Left;
708 is_created = false;
709 is_visible = true;
710 is_captured = false;
711 is_disposed = false;
712 is_enabled = true;
713 is_entered = false;
714 layout_pending = false;
715 is_toplevel = false;
716 causes_validation = true;
717 has_focus = false;
718 layout_suspended = 0;
719 mouse_clicks = 1;
720 tab_index = -1;
721 cursor = null;
722 right_to_left = RightToLeft.Inherit;
723 border_style = BorderStyle.None;
724 background_color = Color.Empty;
725 dist_left = 0;
726 dist_right = 0;
727 dist_top = 0;
728 dist_bottom = 0;
729 tab_stop = true;
730 ime_mode = ImeMode.Inherit;
732 #if NET_2_0
733 use_compatible_text_rendering = Application.use_compatible_text_rendering;
734 padding = new Padding(0);
735 maximum_size = new Size();
736 minimum_size = new Size();
737 preferred_size = new Size();
738 margin = this.DefaultMargin;
739 layout_engine = this.LayoutEngine;
740 #endif
742 control_style = ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint |
743 ControlStyles.Selectable | ControlStyles.StandardClick |
744 ControlStyles.StandardDoubleClick;
745 #if NET_2_0
746 control_style |= ControlStyles.UseTextForAccessibility;
747 #endif
749 parent = null;
750 background_image = null;
751 text = string.Empty;
752 name = string.Empty;
754 window = new ControlNativeWindow(this);
755 child_controls = CreateControlsInstance();
756 client_size = new Size(DefaultSize.Width, DefaultSize.Height);
757 client_rect = new Rectangle(0, 0, DefaultSize.Width, DefaultSize.Height);
758 XplatUI.CalculateWindowRect(ref client_rect, CreateParams.Style, CreateParams.ExStyle, null, out bounds);
759 if ((CreateParams.Style & (int)WindowStyles.WS_CHILD) == 0) {
760 bounds.X=-1;
761 bounds.Y=-1;
765 public Control(Control parent, string text) : this() {
766 Text=text;
767 Parent=parent;
770 public Control(Control parent, string text, int left, int top, int width, int height) : this() {
771 Parent=parent;
772 bounds.X=left;
773 bounds.Y=top;
774 bounds.Width=width;
775 bounds.Height=height;
776 SetBounds(left, top, width, height, BoundsSpecified.All);
777 Text=text;
780 public Control(string text) : this() {
781 Text=text;
784 public Control(string text, int left, int top, int width, int height) : this() {
785 bounds.X=left;
786 bounds.Y=top;
787 bounds.Width=width;
788 bounds.Height=height;
789 SetBounds(left, top, width, height, BoundsSpecified.All);
790 Text=text;
793 private delegate void RemoveDelegate(object c);
795 protected override void Dispose(bool disposing) {
796 if (!is_disposed && disposing) {
797 Capture = false;
799 DisposeBackBuffer ();
801 if (invalid_region!=null) {
802 invalid_region.Dispose();
803 invalid_region=null;
805 if (this.InvokeRequired) {
806 if (Application.MessageLoop) {
807 this.BeginInvokeInternal(new MethodInvoker(DestroyHandle), null, true);
809 } else {
810 DestroyHandle();
813 if (parent != null) {
814 parent.Controls.Remove(this);
817 Control [] children = child_controls.GetAllControls ();
818 for (int i=0; i<children.Length; i++) {
819 children[i].parent = null; // Need to set to null or our child will try and remove from ourselves and crash
820 children[i].Dispose();
823 is_disposed = true;
824 is_visible = false;
825 base.Dispose(disposing);
827 #endregion // Public Constructors
829 #region Internal Properties
830 internal BorderStyle InternalBorderStyle {
831 get {
832 return border_style;
835 set {
836 if (!Enum.IsDefined (typeof (BorderStyle), value))
837 throw new InvalidEnumArgumentException (string.Format("Enum argument value '{0}' is not valid for BorderStyle", value));
839 if (border_style != value) {
840 border_style = value;
842 if (IsHandleCreated) {
843 XplatUI.SetBorderStyle(window.Handle, (FormBorderStyle)border_style);
844 Refresh();
849 #endregion // Internal Properties
851 #region Private & Internal Methods
852 internal IAsyncResult BeginInvokeInternal (Delegate method, object [] args, bool disposing) {
853 AsyncMethodResult result;
854 AsyncMethodData data;
856 if (!disposing) {
857 Control p = this;
858 do {
859 if (!p.IsHandleCreated) {
860 throw new InvalidOperationException("Cannot call Invoke or InvokeAsync on a control until the window handle is created");
862 p = p.parent;
863 } while (p != null);
866 result = new AsyncMethodResult ();
867 data = new AsyncMethodData ();
869 data.Handle = window.Handle;
870 data.Method = method;
871 data.Args = args;
872 data.Result = result;
874 #if NET_2_0
875 if (!ExecutionContext.IsFlowSuppressed ()) {
876 data.Context = ExecutionContext.Capture ();
878 #else
879 #if !MWF_ON_MSRUNTIME
880 if (SecurityManager.SecurityEnabled) {
881 data.Stack = CompressedStack.GetCompressedStack ();
883 #endif
884 #endif
886 XplatUI.SendAsyncMethod (data);
887 return result;
891 internal void PointToClient (ref int x, ref int y)
893 XplatUI.ScreenToClient (Handle, ref x, ref y);
896 internal void PointToScreen (ref int x, ref int y)
898 XplatUI.ClientToScreen (Handle, ref x, ref y);
901 internal bool IsRecreating {
902 get {
903 return is_recreating;
907 internal Graphics DeviceContext {
908 get { return Hwnd.bmp_g; }
911 private void InvalidateBackBuffer ()
913 if (invalid_region != null)
914 invalid_region.Dispose();
915 invalid_region = new Region (ClientRectangle);
918 private void CreateBackBuffer ()
920 if (backbuffer != null)
921 return;
923 int width = Width;
924 int height = Height;
926 if (width < 1) width = 1;
927 if (height < 1) height = 1;
929 XplatUI.CreateOffscreenDrawable (Handle, width, height, out backbuffer, out backbuffer_dc);
930 InvalidateBackBuffer ();
933 private void DisposeBackBuffer ()
935 if (backbuffer == null)
936 return;
938 XplatUI.DestroyOffscreenDrawable (backbuffer, backbuffer_dc);
939 backbuffer = null;
940 backbuffer_dc = null;
943 if (invalid_region != null)
944 invalid_region.Dispose ();
945 invalid_region = null;
948 internal static void SetChildColor(Control parent) {
949 Control child;
951 for (int i=0; i < parent.child_controls.Count; i++) {
952 child=parent.child_controls[i];
953 if (child.child_controls.Count>0) {
954 SetChildColor(child);
959 internal bool Select(Control control) {
960 IContainerControl container;
962 if (control == null) {
963 return false;
966 container = GetContainerControl();
967 if (container != null) {
968 container.ActiveControl = control;
970 if (control.IsHandleCreated) {
971 XplatUI.SetFocus(control.window.Handle);
973 return true;
976 internal void SelectChild (Control control)
978 if (control.IsHandleCreated)
979 XplatUI.SetFocus (control.window.Handle);
982 internal virtual void DoDefaultAction() {
983 // Only here to be overriden by our actual controls; this is needed by the accessibility class
986 internal static int LowOrder (int param) {
987 return ((int)(short)(param & 0xffff));
990 internal static int HighOrder (int param) {
991 return ((int)(short)(param >> 16));
994 // This method exists so controls overriding OnPaintBackground can have default background painting done
995 internal virtual void PaintControlBackground (PaintEventArgs pevent)
997 if (GetStyle(ControlStyles.SupportsTransparentBackColor) && (BackColor.A != 0xff)) {
998 if (parent != null) {
999 PaintEventArgs parent_pe;
1000 GraphicsState state;
1002 parent_pe = new PaintEventArgs(pevent.Graphics, new Rectangle(pevent.ClipRectangle.X + Left, pevent.ClipRectangle.Y + Top, pevent.ClipRectangle.Width, pevent.ClipRectangle.Height));
1004 state = parent_pe.Graphics.Save();
1005 parent_pe.Graphics.TranslateTransform(-Left, -Top);
1006 parent.OnPaintBackground(parent_pe);
1007 parent_pe.Graphics.Restore(state);
1009 state = parent_pe.Graphics.Save();
1010 parent_pe.Graphics.TranslateTransform(-Left, -Top);
1011 parent.OnPaint(parent_pe);
1012 parent_pe.Graphics.Restore(state);
1013 parent_pe.SetGraphics(null);
1017 if ((clip_region != null) && (XplatUI.UserClipWontExposeParent)) {
1018 if (parent != null) {
1019 PaintEventArgs parent_pe;
1020 Region region;
1021 GraphicsState state;
1022 Hwnd hwnd;
1024 hwnd = Hwnd.ObjectFromHandle(Handle);
1026 if (hwnd != null) {
1027 parent_pe = new PaintEventArgs(pevent.Graphics, new Rectangle(pevent.ClipRectangle.X + Left, pevent.ClipRectangle.Y + Top, pevent.ClipRectangle.Width, pevent.ClipRectangle.Height));
1029 region = new Region ();
1030 region.MakeEmpty();
1031 region.Union(ClientRectangle);
1033 foreach (Rectangle r in hwnd.ClipRectangles) {
1034 region.Union (r);
1037 state = parent_pe.Graphics.Save();
1038 parent_pe.Graphics.Clip = region;
1040 parent_pe.Graphics.TranslateTransform(-Left, -Top);
1041 parent.OnPaintBackground(parent_pe);
1042 parent_pe.Graphics.Restore(state);
1044 state = parent_pe.Graphics.Save();
1045 parent_pe.Graphics.Clip = region;
1047 parent_pe.Graphics.TranslateTransform(-Left, -Top);
1048 parent.OnPaint(parent_pe);
1049 parent_pe.Graphics.Restore(state);
1050 parent_pe.SetGraphics(null);
1052 region.Intersect(clip_region);
1053 pevent.Graphics.Clip = region;
1058 if (background_image == null) {
1059 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));
1060 return;
1063 DrawBackgroundImage (pevent.Graphics);
1066 void DrawBackgroundImage (Graphics g)
1068 using (TextureBrush b = new TextureBrush (background_image, WrapMode.Tile)) {
1069 g.FillRectangle (b, ClientRectangle);
1073 internal virtual void DndEnter (DragEventArgs e)
1075 try {
1076 OnDragEnter (e);
1077 } catch { }
1080 internal virtual void DndOver (DragEventArgs e)
1082 try {
1083 OnDragOver (e);
1084 } catch { }
1087 internal virtual void DndDrop (DragEventArgs e)
1089 try {
1090 OnDragDrop (e);
1091 } catch (Exception exc) {
1092 Console.Error.WriteLine ("MWF: Exception while dropping:");
1093 Console.Error.WriteLine (exc);
1097 internal virtual void DndLeave (EventArgs e)
1099 try {
1100 OnDragLeave (e);
1101 } catch { }
1104 internal virtual void DndFeedback(GiveFeedbackEventArgs e)
1106 try {
1107 OnGiveFeedback(e);
1108 } catch { }
1111 internal virtual void DndContinueDrag(QueryContinueDragEventArgs e)
1113 try {
1114 OnQueryContinueDrag(e);
1115 } catch { }
1118 internal static MouseButtons FromParamToMouseButtons (int param) {
1119 MouseButtons buttons = MouseButtons.None;
1121 if ((param & (int) MsgButtons.MK_LBUTTON) != 0)
1122 buttons |= MouseButtons.Left;
1124 if ((param & (int) MsgButtons.MK_MBUTTON) != 0)
1125 buttons |= MouseButtons.Middle;
1127 if ((param & (int) MsgButtons.MK_RBUTTON) != 0)
1128 buttons |= MouseButtons.Right;
1130 return buttons;
1134 internal void FireEnter ()
1136 OnEnter (EventArgs.Empty);
1139 internal void FireLeave ()
1141 OnLeave (EventArgs.Empty);
1144 internal void FireValidating (CancelEventArgs ce)
1146 OnValidating (ce);
1149 internal void FireValidated ()
1151 OnValidated (EventArgs.Empty);
1154 internal virtual bool ProcessControlMnemonic(char charCode) {
1155 return ProcessMnemonic(charCode);
1158 private static Control FindFlatForward(Control container, Control start) {
1159 Control found;
1160 int index;
1161 int end;
1163 found = null;
1164 end = container.child_controls.Count;
1166 if (start != null) {
1167 index = start.tab_index;
1168 } else {
1169 index = -1;
1172 for (int i = 0, pos = -1; i < end; i++) {
1173 if (start == container.child_controls[i]) {
1174 pos = i;
1175 continue;
1178 if (found == null) {
1179 if (container.child_controls[i].tab_index > index || (pos > -1 && pos < i && container.child_controls[i].tab_index == index)) {
1180 found = container.child_controls[i];
1182 } else if (found.tab_index > container.child_controls[i].tab_index) {
1183 if (container.child_controls[i].tab_index > index) {
1184 found = container.child_controls[i];
1188 return found;
1191 private static Control FindControlForward(Control container, Control start) {
1192 Control found;
1194 found = null;
1196 if (start == null) {
1197 return FindFlatForward(container, start);
1200 if (start.child_controls != null && start.child_controls.Count > 0 &&
1201 (start == container || !((start is IContainerControl) && start.GetStyle(ControlStyles.ContainerControl)))) {
1202 return FindControlForward(start, null);
1204 else {
1205 while (start != container) {
1206 found = FindFlatForward(start.parent, start);
1207 if (found != null) {
1208 return found;
1210 start = start.parent;
1213 return null;
1216 private static Control FindFlatBackward(Control container, Control start) {
1217 Control found;
1218 int index;
1219 int end;
1221 found = null;
1222 end = container.child_controls.Count;
1224 if (start != null) {
1225 index = start.tab_index;
1226 } else {
1227 // FIXME: Possible speed-up: Keep the highest taborder index in the container
1228 index = -1;
1229 for (int i = 0; i < end; i++) {
1230 if (container.child_controls[i].tab_index > index) {
1231 index = container.child_controls[i].tab_index;
1234 index++;
1237 bool hit = false;
1239 for (int i = end - 1; i >= 0; i--) {
1240 if (start == container.child_controls[i]) {
1241 hit = true;
1242 continue;
1245 if (found == null || found.tab_index < container.child_controls[i].tab_index) {
1246 if (container.child_controls[i].tab_index < index || (hit && container.child_controls[i].tab_index == index))
1247 found = container.child_controls[i];
1251 return found;
1254 private static Control FindControlBackward(Control container, Control start) {
1256 Control found = null;
1258 if (start == null) {
1259 found = FindFlatBackward(container, start);
1261 else if (start != container) {
1262 if (start.parent != null) {
1263 found = FindFlatBackward(start.parent, start);
1265 if (found == null) {
1266 if (start.parent != container)
1267 return start.parent;
1268 return null;
1273 if (found == null || start.parent == null)
1274 found = start;
1276 while (found != null && (found == container || (!((found is IContainerControl) && found.GetStyle(ControlStyles.ContainerControl))) &&
1277 found.child_controls != null && found.child_controls.Count > 0)) {
1278 // while (ctl.child_controls != null && ctl.child_controls.Count > 0 &&
1279 // (ctl == this || (!((ctl is IContainerControl) && ctl.GetStyle(ControlStyles.ContainerControl))))) {
1280 found = FindFlatBackward(found, null);
1283 return found;
1286 Control found;
1288 found = null;
1290 if (start != null) {
1291 found = FindFlatBackward(start.parent, start);
1292 if (found == null) {
1293 if (start.parent != container) {
1294 return start.parent;
1298 if (found == null) {
1299 found = FindFlatBackward(container, start);
1302 if (container != start) {
1303 while ((found != null) && (!found.Contains(start)) && found.child_controls != null && found.child_controls.Count > 0 && !(found is IContainerControl)) {// || found.GetStyle(ControlStyles.ContainerControl))) {
1304 found = FindControlBackward(found, null);
1305 if (found != null) {
1306 return found;
1310 return found;
1314 internal virtual void HandleClick(int clicks, MouseEventArgs me) {
1315 if (GetStyle(ControlStyles.StandardClick)) {
1316 if ((clicks > 1) && GetStyle(ControlStyles.StandardDoubleClick)) {
1317 #if !NET_2_0
1318 OnDoubleClick(EventArgs.Empty);
1319 } else {
1320 OnClick(EventArgs.Empty);
1321 #else
1322 OnDoubleClick(me);
1323 } else {
1324 OnClick(me);
1325 #endif
1330 private void CheckDataBindings ()
1332 if (data_bindings == null)
1333 return;
1335 BindingContext binding_context = BindingContext;
1336 foreach (Binding binding in data_bindings) {
1337 binding.Check (binding_context);
1341 private void ChangeParent(Control new_parent) {
1342 bool pre_enabled;
1343 bool pre_visible;
1344 Font pre_font;
1345 Color pre_fore_color;
1346 Color pre_back_color;
1347 RightToLeft pre_rtl;
1349 // These properties are inherited from our parent
1350 // Get them pre parent-change and then send events
1351 // if they are changed after we have our new parent
1352 pre_enabled = Enabled;
1353 pre_visible = Visible;
1354 pre_font = Font;
1355 pre_fore_color = ForeColor;
1356 pre_back_color = BackColor;
1357 pre_rtl = RightToLeft;
1358 // MS doesn't seem to send a CursorChangedEvent
1360 parent = new_parent;
1362 if (IsHandleCreated)
1363 XplatUI.SetParent(Handle,
1364 (new_parent == null || !new_parent.IsHandleCreated) ? IntPtr.Zero : new_parent.Handle);
1366 OnParentChanged(EventArgs.Empty);
1368 if (pre_enabled != Enabled) {
1369 OnEnabledChanged(EventArgs.Empty);
1372 if (pre_visible != Visible) {
1373 OnVisibleChanged(EventArgs.Empty);
1376 if (pre_font != Font) {
1377 OnFontChanged(EventArgs.Empty);
1380 if (pre_fore_color != ForeColor) {
1381 OnForeColorChanged(EventArgs.Empty);
1384 if (pre_back_color != BackColor) {
1385 OnBackColorChanged(EventArgs.Empty);
1388 if (pre_rtl != RightToLeft) {
1389 // MS sneaks a OnCreateControl and OnHandleCreated in here, I guess
1390 // because when RTL changes they have to recreate the win32 control
1391 // We don't really need that (until someone runs into compatibility issues)
1392 OnRightToLeftChanged(EventArgs.Empty);
1395 if ((new_parent != null) && new_parent.Created && !Created) {
1396 CreateControl();
1399 if ((binding_context == null) && Created) {
1400 OnBindingContextChanged(EventArgs.Empty);
1404 private void UpdateDistances() {
1405 if ((parent != null) && (parent.layout_suspended == 0)) {
1406 dist_left = bounds.X;
1407 dist_top = bounds.Y;
1408 dist_right = parent.ClientSize.Width - bounds.X - bounds.Width;
1409 dist_bottom = parent.ClientSize.Height - bounds.Y - bounds.Height;
1412 #endregion // Private & Internal Methods
1414 #region Public Static Properties
1415 public static Color DefaultBackColor {
1416 get {
1417 return ThemeEngine.Current.DefaultControlBackColor;
1421 public static Font DefaultFont {
1422 get {
1423 return ThemeEngine.Current.DefaultFont;
1427 public static Color DefaultForeColor {
1428 get {
1429 return ThemeEngine.Current.DefaultControlForeColor;
1433 public static Keys ModifierKeys {
1434 get {
1435 return XplatUI.State.ModifierKeys;
1439 public static MouseButtons MouseButtons {
1440 get {
1441 return XplatUI.State.MouseButtons;
1445 public static Point MousePosition {
1446 get {
1447 return Cursor.Position;
1451 #if NET_2_0
1452 [MonoTODO]
1453 public static bool CheckForIllegalCrossThreadCalls
1455 get {
1456 return verify_thread_handle;
1459 set {
1460 verify_thread_handle = value;
1463 #endif
1464 #endregion // Public Static Properties
1466 #region Public Instance Properties
1467 [EditorBrowsable(EditorBrowsableState.Advanced)]
1468 [Browsable(false)]
1469 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1470 public AccessibleObject AccessibilityObject {
1471 get {
1472 if (accessibility_object==null) {
1473 accessibility_object=CreateAccessibilityInstance();
1475 return accessibility_object;
1479 [EditorBrowsable(EditorBrowsableState.Advanced)]
1480 [Browsable(false)]
1481 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1482 public string AccessibleDefaultActionDescription {
1483 get {
1484 return AccessibilityObject.default_action;
1487 set {
1488 AccessibilityObject.default_action=value;
1492 [Localizable(true)]
1493 [DefaultValue(null)]
1494 [MWFCategory("Accessibility")]
1495 public string AccessibleDescription {
1496 get {
1497 return AccessibilityObject.description;
1500 set {
1501 AccessibilityObject.description=value;
1505 [Localizable(true)]
1506 [DefaultValue(null)]
1507 [MWFCategory("Accessibility")]
1508 public string AccessibleName {
1509 get {
1510 return AccessibilityObject.Name;
1513 set {
1514 AccessibilityObject.Name=value;
1518 [DefaultValue(AccessibleRole.Default)]
1519 [MWFDescription("Role of the control"), MWFCategory("Accessibility")]
1520 public AccessibleRole AccessibleRole {
1521 get {
1522 return AccessibilityObject.role;
1525 set {
1526 AccessibilityObject.role=value;
1530 [DefaultValue(false)]
1531 [MWFCategory("Behavior")]
1532 public virtual bool AllowDrop {
1533 get {
1534 return allow_drop;
1537 set {
1538 if (allow_drop == value)
1539 return;
1540 allow_drop = value;
1541 if (IsHandleCreated) {
1542 UpdateStyles();
1543 XplatUI.SetAllowDrop (Handle, value);
1548 [Localizable(true)]
1549 [RefreshProperties(RefreshProperties.Repaint)]
1550 [DefaultValue(AnchorStyles.Top | AnchorStyles.Left)]
1551 [MWFCategory("Layout")]
1552 public virtual AnchorStyles Anchor {
1553 get {
1554 return anchor_style;
1557 set {
1558 anchor_style=value;
1560 if (parent != null) {
1561 parent.PerformLayout(this, "Parent");
1566 #if NET_2_0
1567 // XXX: Implement me!
1568 bool auto_size;
1570 public virtual bool AutoSize {
1571 get {
1572 //Console.Error.WriteLine("Unimplemented: Control::get_AutoSize()");
1573 return auto_size;
1575 set {
1576 Console.Error.WriteLine("Unimplemented: Control::set_AutoSize(bool)");
1577 auto_size = value;
1581 public virtual Size MaximumSize {
1582 get {
1583 return maximum_size;
1585 set {
1586 maximum_size = value;
1590 public virtual Size MinimumSize {
1591 get {
1592 return minimum_size;
1594 set {
1595 minimum_size = value;
1598 #endif // NET_2_0
1600 [DispId(-501)]
1601 [MWFCategory("Appearance")]
1602 public virtual Color BackColor {
1603 get {
1604 if (background_color.IsEmpty) {
1605 if (parent!=null) {
1606 Color pcolor = parent.BackColor;
1607 if (pcolor.A == 0xff || GetStyle(ControlStyles.SupportsTransparentBackColor))
1608 return pcolor;
1610 return DefaultBackColor;
1612 return background_color;
1615 set {
1616 if (!value.IsEmpty && (value.A != 0xff) && !GetStyle(ControlStyles.SupportsTransparentBackColor)) {
1617 throw new ArgumentException("Transparent background colors are not supported on this control");
1620 if (background_color != value) {
1621 background_color=value;
1622 SetChildColor(this);
1623 OnBackColorChanged(EventArgs.Empty);
1624 Invalidate();
1629 [Localizable(true)]
1630 [DefaultValue(null)]
1631 [MWFCategory("Appearance")]
1632 public virtual Image BackgroundImage {
1633 get {
1634 return background_image;
1637 set {
1638 if (background_image!=value) {
1639 background_image=value;
1640 OnBackgroundImageChanged(EventArgs.Empty);
1641 Invalidate ();
1646 [EditorBrowsable(EditorBrowsableState.Advanced)]
1647 [Browsable(false)]
1648 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1649 public virtual BindingContext BindingContext {
1650 get {
1651 if (binding_context != null)
1652 return binding_context;
1653 if (Parent == null)
1654 return null;
1655 binding_context = Parent.BindingContext;
1656 return binding_context;
1658 set {
1659 if (binding_context != value) {
1660 binding_context = value;
1661 OnBindingContextChanged(EventArgs.Empty);
1666 [EditorBrowsable(EditorBrowsableState.Advanced)]
1667 [Browsable(false)]
1668 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1669 public int Bottom {
1670 get {
1671 return bounds.Y+bounds.Height;
1675 [EditorBrowsable(EditorBrowsableState.Advanced)]
1676 [Browsable(false)]
1677 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1678 public Rectangle Bounds {
1679 get {
1680 return this.bounds;
1683 set {
1684 SetBounds(value.Left, value.Top, value.Width, value.Height, BoundsSpecified.All);
1688 [EditorBrowsable(EditorBrowsableState.Advanced)]
1689 [Browsable(false)]
1690 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1691 public bool CanFocus {
1692 get {
1693 if (IsHandleCreated && Visible && Enabled) {
1694 return true;
1696 return false;
1700 [EditorBrowsable(EditorBrowsableState.Advanced)]
1701 [Browsable(false)]
1702 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1703 public bool CanSelect {
1704 get {
1705 Control parent;
1707 if (!GetStyle(ControlStyles.Selectable)) {
1708 return false;
1711 parent = this;
1712 while (parent != null) {
1713 if (!parent.is_visible || !parent.is_enabled) {
1714 return false;
1717 parent = parent.parent;
1719 return true;
1723 internal virtual bool InternalCapture {
1724 get {
1725 return Capture;
1728 set {
1729 Capture = value;
1733 [EditorBrowsable(EditorBrowsableState.Advanced)]
1734 [Browsable(false)]
1735 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1736 public bool Capture {
1737 get {
1738 return this.is_captured;
1741 set {
1742 if (this.IsHandleCreated && value != is_captured) {
1743 if (value) {
1744 is_captured = true;
1745 XplatUI.GrabWindow(this.window.Handle, IntPtr.Zero);
1746 } else {
1747 XplatUI.UngrabWindow(this.window.Handle);
1748 is_captured = false;
1754 [DefaultValue(true)]
1755 [MWFCategory("Focus")]
1756 public bool CausesValidation {
1757 get {
1758 return this.causes_validation;
1761 set {
1762 if (this.causes_validation != value) {
1763 causes_validation = value;
1764 OnCausesValidationChanged(EventArgs.Empty);
1769 [EditorBrowsable(EditorBrowsableState.Advanced)]
1770 [Browsable(false)]
1771 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1772 public Rectangle ClientRectangle {
1773 get {
1774 client_rect.Width = client_size.Width;
1775 client_rect.Height = client_size.Height;
1776 return client_rect;
1780 [EditorBrowsable(EditorBrowsableState.Advanced)]
1781 [Browsable(false)]
1782 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1783 public Size ClientSize {
1784 get {
1785 #if notneeded
1786 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1787 return ((Form)this).form_parent_window.ClientSize;
1789 #endif
1791 return client_size;
1794 set {
1795 this.SetClientSizeCore(value.Width, value.Height);
1799 [EditorBrowsable(EditorBrowsableState.Advanced)]
1800 [Browsable(false)]
1801 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1802 [DescriptionAttribute("ControlCompanyNameDescr")]
1803 public String CompanyName {
1804 get {
1805 return "Mono Project, Novell, Inc.";
1809 [EditorBrowsable(EditorBrowsableState.Advanced)]
1810 [Browsable(false)]
1811 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1812 public bool ContainsFocus {
1813 get {
1814 IntPtr focused_window;
1816 focused_window = XplatUI.GetFocus();
1817 if (IsHandleCreated) {
1818 if (focused_window == Handle) {
1819 return true;
1822 for (int i=0; i < child_controls.Count; i++) {
1823 if (child_controls[i].ContainsFocus) {
1824 return true;
1828 return false;
1832 [DefaultValue(null)]
1833 [MWFCategory("Behavior")]
1834 public virtual ContextMenu ContextMenu {
1835 get {
1836 return context_menu;
1839 set {
1840 if (context_menu != value) {
1841 context_menu = value;
1842 OnContextMenuChanged(EventArgs.Empty);
1847 [Browsable(false)]
1848 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
1849 public ControlCollection Controls {
1850 get {
1851 return this.child_controls;
1855 [EditorBrowsable(EditorBrowsableState.Advanced)]
1856 [Browsable(false)]
1857 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1858 public bool Created {
1859 get {
1860 return (!is_disposed && is_created);
1864 [AmbientValue(null)]
1865 [MWFCategory("Appearance")]
1866 public virtual Cursor Cursor {
1867 get {
1868 if (cursor != null) {
1869 return cursor;
1872 if (parent != null) {
1873 return parent.Cursor;
1876 return Cursors.Default;
1879 set {
1880 if (cursor != value) {
1881 Point pt;
1883 cursor = value;
1885 if (IsHandleCreated) {
1886 pt = Cursor.Position;
1888 if (bounds.Contains(pt) || Capture) {
1889 if (GetChildAtPoint(pt) == null) {
1890 if (cursor != null) {
1891 XplatUI.SetCursor(window.Handle, cursor.handle);
1892 } else {
1893 if (parent != null) {
1894 XplatUI.SetCursor(window.Handle, parent.Cursor.handle);
1895 } else {
1896 XplatUI.SetCursor(window.Handle, Cursors.Default.handle);
1903 OnCursorChanged(EventArgs.Empty);
1909 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
1910 [ParenthesizePropertyName(true)]
1911 [RefreshProperties(RefreshProperties.All)]
1912 [MWFCategory("Data")]
1913 public ControlBindingsCollection DataBindings {
1914 get {
1915 if (data_bindings == null)
1916 data_bindings = new ControlBindingsCollection (this);
1917 return data_bindings;
1921 [EditorBrowsable(EditorBrowsableState.Advanced)]
1922 [Browsable(false)]
1923 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1924 public virtual Rectangle DisplayRectangle {
1925 get {
1926 return ClientRectangle;
1930 [EditorBrowsable(EditorBrowsableState.Advanced)]
1931 [Browsable(false)]
1932 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1933 public bool Disposing {
1934 get {
1935 return is_disposed;
1939 [Localizable(true)]
1940 [RefreshProperties(RefreshProperties.Repaint)]
1941 [DefaultValue(DockStyle.None)]
1942 [MWFCategory("Layout")]
1943 public virtual DockStyle Dock {
1944 get {
1945 return dock_style;
1948 set {
1949 if (dock_style == value) {
1950 return;
1953 if (!Enum.IsDefined (typeof (DockStyle), value)) {
1954 throw new InvalidEnumArgumentException ("value", (int) value,
1955 typeof (DockStyle));
1958 dock_style = value;
1960 if (dock_style == DockStyle.None) {
1961 if (explicit_bounds == Rectangle.Empty)
1962 Bounds = new Rectangle (new Point (0, 0), DefaultSize);
1963 else
1964 Bounds = explicit_bounds;
1967 if (parent != null) {
1968 parent.PerformLayout(this, "Parent");
1971 OnDockChanged(EventArgs.Empty);
1975 [DispId(-514)]
1976 [Localizable(true)]
1977 [MWFCategory("Behavior")]
1978 public bool Enabled {
1979 get {
1980 if (!is_enabled) {
1981 return false;
1984 if (parent != null) {
1985 return parent.Enabled;
1988 return true;
1991 set {
1993 bool old_value = is_enabled;
1995 is_enabled = value;
1996 if (old_value != value && !value && this.has_focus)
1997 SelectNextControl(this, true, true, true, true);
1999 OnEnabledChanged (EventArgs.Empty);
2003 [EditorBrowsable(EditorBrowsableState.Advanced)]
2004 [Browsable(false)]
2005 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2006 public virtual bool Focused {
2007 get {
2008 return this.has_focus;
2012 [DispId(-512)]
2013 [AmbientValue(null)]
2014 [Localizable(true)]
2015 [MWFCategory("Appearance")]
2016 public virtual Font Font {
2017 get {
2018 if (font != null) {
2019 return font;
2022 if (Parent != null && Parent.Font != null) {
2023 return Parent.Font;
2026 return DefaultFont;
2029 [param:MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Font))]
2030 set {
2031 if (font != null && font.Equals (value)) {
2032 return;
2035 font = value;
2036 Invalidate();
2037 OnFontChanged (EventArgs.Empty);
2041 [DispId(-513)]
2042 [MWFCategory("Appearance")]
2043 public virtual Color ForeColor {
2044 get {
2045 if (foreground_color.IsEmpty) {
2046 if (parent!=null) {
2047 return parent.ForeColor;
2049 return DefaultForeColor;
2051 return foreground_color;
2054 set {
2055 if (foreground_color != value) {
2056 foreground_color=value;
2057 Invalidate();
2058 OnForeColorChanged(EventArgs.Empty);
2063 [DispId(-515)]
2064 [Browsable(false)]
2065 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2066 public IntPtr Handle { // IWin32Window
2067 get {
2068 #if NET_2_0
2069 if (verify_thread_handle) {
2070 if (this.InvokeRequired) {
2071 throw new InvalidOperationException("Cross-thread access of handle detected. Handle access only valid on thread that created the control");
2074 #endif
2075 if (!IsHandleCreated) {
2076 CreateHandle();
2078 return window.Handle;
2082 [EditorBrowsable(EditorBrowsableState.Advanced)]
2083 [Browsable(false)]
2084 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2085 public bool HasChildren {
2086 get {
2087 if (this.child_controls.Count>0) {
2088 return true;
2090 return false;
2094 [EditorBrowsable(EditorBrowsableState.Always)]
2095 [Browsable(false)]
2096 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2097 public int Height {
2098 get {
2099 return this.bounds.Height;
2102 set {
2103 SetBounds(bounds.X, bounds.Y, bounds.Width, value, BoundsSpecified.Height);
2107 [AmbientValue(ImeMode.Inherit)]
2108 [Localizable(true)]
2109 [MWFCategory("Behavior")]
2110 public ImeMode ImeMode {
2111 get {
2112 if (ime_mode == ImeMode.Inherit) {
2113 if (parent != null)
2114 return parent.ImeMode;
2115 else
2116 return ImeMode.NoControl; // default value
2118 return ime_mode;
2121 set {
2122 if (ime_mode != value) {
2123 ime_mode = value;
2125 OnImeModeChanged(EventArgs.Empty);
2130 [EditorBrowsable(EditorBrowsableState.Advanced)]
2131 [Browsable(false)]
2132 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2133 public bool InvokeRequired { // ISynchronizeInvoke
2134 get {
2135 if (creator_thread != null && creator_thread!=Thread.CurrentThread) {
2136 return true;
2138 return false;
2142 [EditorBrowsable(EditorBrowsableState.Advanced)]
2143 [Browsable(false)]
2144 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2145 public bool IsAccessible {
2146 get {
2147 return is_accessible;
2150 set {
2151 is_accessible = value;
2155 [EditorBrowsable(EditorBrowsableState.Advanced)]
2156 [Browsable(false)]
2157 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2158 public bool IsDisposed {
2159 get {
2160 return this.is_disposed;
2164 [EditorBrowsable(EditorBrowsableState.Advanced)]
2165 [Browsable(false)]
2166 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2167 public bool IsHandleCreated {
2168 get {
2169 if ((window != null) && (window.Handle != IntPtr.Zero)) {
2170 Hwnd hwnd = Hwnd.ObjectFromHandle (window.Handle);
2171 if (hwnd != null && !hwnd.zombie)
2172 return true;
2175 return false;
2179 #if NET_2_0
2180 public virtual Layout.LayoutEngine LayoutEngine {
2181 get { return new Layout.DefaultLayout (); }
2183 #endif
2185 [EditorBrowsable(EditorBrowsableState.Always)]
2186 [Browsable(false)]
2187 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2188 public int Left {
2189 get {
2190 return this.bounds.X;
2193 set {
2194 SetBounds(value, bounds.Y, bounds.Width, bounds.Height, BoundsSpecified.X);
2198 [Localizable(true)]
2199 [MWFCategory("Layout")]
2200 public Point Location {
2201 get {
2202 return new Point(bounds.X, bounds.Y);
2205 set {
2206 SetBounds(value.X, value.Y, bounds.Width, bounds.Height, BoundsSpecified.Location);
2210 #if NET_2_0
2211 [Localizable (true)]
2212 public Padding Margin {
2213 get { return this.margin; }
2214 set { this.margin = value; }
2216 #endif
2218 [Browsable(false)]
2219 public string Name {
2220 get {
2221 return name;
2224 set {
2225 name = value;
2229 #if NET_2_0
2230 [Localizable(true)]
2231 public Padding Padding {
2232 get {
2233 return padding;
2236 set {
2237 padding = value;
2240 #endif
2242 [Browsable(false)]
2243 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2244 public Control Parent {
2245 get {
2246 return this.parent;
2249 set {
2250 if (value == this) {
2251 throw new ArgumentException("A circular control reference has been made. A control cannot be owned or parented to itself.");
2254 if (parent!=value) {
2255 if (value==null) {
2256 parent.Controls.Remove(this);
2257 parent = null;
2258 return;
2261 value.Controls.Add(this);
2266 [EditorBrowsable(EditorBrowsableState.Advanced)]
2267 [Browsable(false)]
2268 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2269 public string ProductName {
2270 get {
2271 Type t = typeof (AssemblyProductAttribute);
2272 Assembly assembly = GetType().Module.Assembly;
2273 object [] attrs = assembly.GetCustomAttributes (t, false);
2274 AssemblyProductAttribute a = null;
2275 // On MS we get a NullRefException if product attribute is not
2276 // set.
2277 if (attrs != null && attrs.Length > 0)
2278 a = (AssemblyProductAttribute) attrs [0];
2279 return a.Product;
2283 [EditorBrowsable(EditorBrowsableState.Advanced)]
2284 [Browsable(false)]
2285 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2286 public string ProductVersion {
2287 get {
2288 Type t = typeof (AssemblyVersionAttribute);
2289 Assembly assembly = GetType().Module.Assembly;
2290 object [] attrs = assembly.GetCustomAttributes (t, false);
2291 if (attrs == null || attrs.Length < 1)
2292 return "1.0.0.0";
2293 return ((AssemblyVersionAttribute)attrs [0]).Version;
2297 [EditorBrowsable(EditorBrowsableState.Advanced)]
2298 [Browsable(false)]
2299 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2300 public bool RecreatingHandle {
2301 get {
2302 return is_recreating;
2306 [EditorBrowsable(EditorBrowsableState.Advanced)]
2307 [Browsable(false)]
2308 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2309 public Region Region {
2310 get {
2311 return clip_region;
2314 set {
2315 if (IsHandleCreated) {
2316 XplatUI.SetClipRegion(Handle, value);
2318 clip_region = value;
2322 [EditorBrowsable(EditorBrowsableState.Advanced)]
2323 [Browsable(false)]
2324 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2325 public int Right {
2326 get {
2327 return this.bounds.X+this.bounds.Width;
2331 [AmbientValue(RightToLeft.Inherit)]
2332 [Localizable(true)]
2333 [MWFCategory("Appearance")]
2334 public virtual RightToLeft RightToLeft {
2335 get {
2336 if (right_to_left == RightToLeft.Inherit) {
2337 if (parent != null)
2338 return parent.RightToLeft;
2339 else
2340 return RightToLeft.No; // default value
2342 return right_to_left;
2345 set {
2346 if (value != right_to_left) {
2347 right_to_left = value;
2348 OnRightToLeftChanged(EventArgs.Empty);
2353 [EditorBrowsable(EditorBrowsableState.Advanced)]
2354 public override ISite Site {
2355 get {
2356 return base.Site;
2359 set {
2360 base.Site = value;
2362 AmbientProperties ap = (AmbientProperties) value.GetService (typeof (AmbientProperties));
2363 if (ap != null) {
2364 BackColor = ap.BackColor;
2365 ForeColor = ap.ForeColor;
2366 Cursor = ap.Cursor;
2367 Font = ap.Font;
2372 [Localizable(true)]
2373 [MWFCategory("Layout")]
2374 public Size Size {
2375 get {
2376 return new Size(Width, Height);
2379 set {
2380 SetBounds(bounds.X, bounds.Y, value.Width, value.Height, BoundsSpecified.Size);
2384 [Localizable(true)]
2385 [MergableProperty(false)]
2386 [MWFCategory("Behavior")]
2387 public int TabIndex {
2388 get {
2389 if (tab_index != -1) {
2390 return tab_index;
2392 return 0;
2395 set {
2396 if (tab_index != value) {
2397 tab_index = value;
2398 OnTabIndexChanged(EventArgs.Empty);
2403 [DispId(-516)]
2404 [DefaultValue(true)]
2405 [MWFCategory("Behavior")]
2406 public bool TabStop {
2407 get {
2408 return tab_stop;
2411 set {
2412 if (tab_stop != value) {
2413 tab_stop = value;
2414 OnTabStopChanged(EventArgs.Empty);
2419 [Localizable(false)]
2420 [Bindable(true)]
2421 [TypeConverter(typeof(StringConverter))]
2422 [DefaultValue(null)]
2423 [MWFCategory("Data")]
2424 public object Tag {
2425 get {
2426 return control_tag;
2429 set {
2430 control_tag = value;
2434 [DispId(-517)]
2435 [Localizable(true)]
2436 [BindableAttribute(true)]
2437 [MWFCategory("Appearance")]
2438 public virtual string Text {
2439 get {
2440 // Our implementation ignores ControlStyles.CacheText - we always cache
2441 return this.text;
2444 set {
2445 if (value == null) {
2446 value = String.Empty;
2449 if (text!=value) {
2450 text=value;
2451 if (IsHandleCreated) {
2452 /* we need to call .SetWindowStyle here instead of just .Text
2453 because the presence/absence of Text (== "" or not) can cause
2454 other window style things to appear/disappear */
2455 XplatUI.SetWindowStyle(window.Handle, CreateParams);
2456 XplatUI.Text(Handle, text);
2458 OnTextChanged (EventArgs.Empty);
2463 [EditorBrowsable(EditorBrowsableState.Always)]
2464 [Browsable(false)]
2465 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2466 public int Top {
2467 get {
2468 return this.bounds.Y;
2471 set {
2472 SetBounds(bounds.X, value, bounds.Width, bounds.Height, BoundsSpecified.Y);
2476 [EditorBrowsable(EditorBrowsableState.Advanced)]
2477 [Browsable(false)]
2478 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2479 public Control TopLevelControl {
2480 get {
2481 Control p = this;
2483 while (p.parent != null) {
2484 p = p.parent;
2487 return p is Form ? p : null;
2491 [Localizable(true)]
2492 [MWFCategory("Behavior")]
2493 public bool Visible {
2494 get {
2495 if (!is_visible) {
2496 return false;
2497 } else if (parent != null) {
2498 return parent.Visible;
2501 return true;
2504 set {
2505 SetVisibleCore(value);
2509 [EditorBrowsable(EditorBrowsableState.Always)]
2510 [Browsable(false)]
2511 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2512 public int Width {
2513 get {
2514 return this.bounds.Width;
2517 set {
2518 SetBounds(bounds.X, bounds.Y, value, bounds.Height, BoundsSpecified.Width);
2522 [EditorBrowsable(EditorBrowsableState.Never)]
2523 [Browsable(false)]
2524 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2525 public IWindowTarget WindowTarget {
2526 get {
2527 return null;
2530 set {
2531 ; // MS Internal
2534 #endregion // Public Instance Properties
2536 #region Protected Instance Properties
2537 protected virtual CreateParams CreateParams {
2538 get {
2539 CreateParams create_params = new CreateParams();
2541 try {
2542 create_params.Caption = Text;
2544 catch {
2545 create_params.Caption = text;
2548 try {
2549 create_params.X = Left;
2551 catch {
2552 create_params.X = this.bounds.X;
2555 try {
2556 create_params.Y = Top;
2558 catch {
2559 create_params.Y = this.bounds.Y;
2562 try {
2563 create_params.Width = Width;
2565 catch {
2566 create_params.Width = this.bounds.Width;
2569 try {
2570 create_params.Height = Height;
2572 catch {
2573 create_params.Height = this.bounds.Height;
2577 create_params.ClassName = XplatUI.DefaultClassName;
2578 create_params.ClassStyle = 0;
2579 create_params.ExStyle = 0;
2580 create_params.Param = 0;
2582 if (allow_drop) {
2583 create_params.ExStyle |= (int)WindowExStyles.WS_EX_ACCEPTFILES;
2586 if ((parent!=null) && (parent.IsHandleCreated)) {
2587 create_params.Parent = parent.Handle;
2590 create_params.Style = (int)WindowStyles.WS_CHILD | (int)WindowStyles.WS_CLIPCHILDREN | (int)WindowStyles.WS_CLIPSIBLINGS;
2592 if (is_visible) {
2593 create_params.Style |= (int)WindowStyles.WS_VISIBLE;
2596 if (!is_enabled) {
2597 create_params.Style |= (int)WindowStyles.WS_DISABLED;
2600 switch (border_style) {
2601 case BorderStyle.FixedSingle:
2602 create_params.Style |= (int) WindowStyles.WS_BORDER;
2603 break;
2604 case BorderStyle.Fixed3D:
2605 create_params.ExStyle |= (int) WindowExStyles.WS_EX_CLIENTEDGE;
2606 break;
2609 return create_params;
2613 protected virtual ImeMode DefaultImeMode {
2614 get {
2615 return ImeMode.Inherit;
2619 #if NET_2_0
2620 protected virtual Padding DefaultMargin {
2621 get { return new Padding (3); }
2623 #endif
2625 protected virtual Size DefaultSize {
2626 get {
2627 return new Size(0, 0);
2631 protected int FontHeight {
2632 get {
2633 return Font.Height;
2636 set {
2637 ;; // Nothing to do
2641 protected bool RenderRightToLeft {
2642 get {
2643 return (this.right_to_left == RightToLeft.Yes);
2647 protected bool ResizeRedraw {
2648 get {
2649 return GetStyle(ControlStyles.ResizeRedraw);
2652 set {
2653 SetStyle(ControlStyles.ResizeRedraw, value);
2657 [EditorBrowsable(EditorBrowsableState.Advanced)]
2658 [Browsable(false)]
2659 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2660 protected virtual bool ShowFocusCues {
2661 get {
2662 return true;
2666 [EditorBrowsable(EditorBrowsableState.Advanced)]
2667 [Browsable(false)]
2668 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2669 protected bool ShowKeyboardCues {
2670 get {
2671 return true;
2674 #endregion // Protected Instance Properties
2676 #region Public Static Methods
2677 [EditorBrowsable(EditorBrowsableState.Advanced)]
2678 public static Control FromChildHandle(IntPtr handle) {
2679 return Control.ControlNativeWindow.ControlFromChildHandle (handle);
2682 [EditorBrowsable(EditorBrowsableState.Advanced)]
2683 public static Control FromHandle(IntPtr handle) {
2684 return Control.ControlNativeWindow.ControlFromHandle(handle);
2687 public static bool IsMnemonic(char charCode, string text) {
2688 int amp;
2690 amp = text.IndexOf('&');
2692 if (amp != -1) {
2693 if (amp + 1 < text.Length) {
2694 if (text[amp + 1] != '&') {
2695 if (Char.ToUpper(charCode) == Char.ToUpper(text.ToCharArray(amp + 1, 1)[0])) {
2696 return true;
2701 return false;
2703 #endregion
2705 #region Protected Static Methods
2706 [EditorBrowsable(EditorBrowsableState.Advanced)]
2707 protected static bool ReflectMessage(IntPtr hWnd, ref Message m) {
2708 Control c;
2710 c = Control.FromHandle(hWnd);
2712 if (c != null) {
2713 c.WndProc(ref m);
2714 return true;
2716 return false;
2718 #endregion
2720 #region Public Instance Methods
2721 [EditorBrowsable(EditorBrowsableState.Advanced)]
2722 public IAsyncResult BeginInvoke(Delegate method) {
2723 object [] prms = null;
2724 if (method is EventHandler)
2725 prms = new object [] { this, EventArgs.Empty };
2726 return BeginInvokeInternal(method, prms, false);
2729 [EditorBrowsable(EditorBrowsableState.Advanced)]
2730 public IAsyncResult BeginInvoke (Delegate method, object[] args) {
2731 return BeginInvokeInternal (method, args, false);
2734 public void BringToFront() {
2735 if (parent != null) {
2736 parent.child_controls.SetChildIndex(this, 0);
2737 parent.Refresh();
2738 } else {
2739 XplatUI.SetZOrder(Handle, IntPtr.Zero, false, false);
2743 public bool Contains(Control ctl) {
2744 while (ctl != null) {
2745 ctl = ctl.parent;
2746 if (ctl == this) {
2747 return true;
2750 return false;
2753 public void CreateControl() {
2754 if (is_disposed) {
2755 throw new ObjectDisposedException(GetType().FullName.ToString());
2757 if (is_created) {
2758 return;
2761 if (!IsHandleCreated) {
2762 CreateHandle();
2765 if (!is_created) {
2766 is_created = true;
2769 Control [] controls = child_controls.GetAllControls ();
2770 for (int i=0; i<controls.Length; i++) {
2771 controls [i].CreateControl ();
2774 UpdateChildrenZOrder();
2776 if (binding_context == null) { // seem to be sent whenever it's null?
2777 OnBindingContextChanged(EventArgs.Empty);
2780 OnCreateControl();
2783 public Graphics CreateGraphics() {
2784 if (!IsHandleCreated) {
2785 this.CreateHandle();
2787 return Graphics.FromHwnd(this.window.Handle);
2790 public DragDropEffects DoDragDrop(object data, DragDropEffects allowedEffects) {
2791 return XplatUI.StartDrag(this.window.Handle, data, allowedEffects);
2794 [EditorBrowsable(EditorBrowsableState.Advanced)]
2795 public object EndInvoke (IAsyncResult async_result) {
2796 AsyncMethodResult result = (AsyncMethodResult) async_result;
2797 return result.EndInvoke ();
2800 public Form FindForm() {
2801 Control c;
2803 c = this;
2804 while (c != null) {
2805 if (c is Form) {
2806 return (Form)c;
2808 c = c.Parent;
2810 return null;
2813 public bool Focus() {
2814 if (CanFocus && IsHandleCreated && !has_focus && !is_focusing) {
2815 is_focusing = true;
2816 Select(this);
2817 is_focusing = false;
2819 return has_focus;
2822 public Control GetChildAtPoint(Point pt) {
2823 // Microsoft's version of this function doesn't seem to work, so I can't check
2824 // if we only consider children or also grandchildren, etc.
2825 // I'm gonna say 'children only'
2826 for (int i=0; i<child_controls.Count; i++) {
2827 if (child_controls[i].Bounds.Contains(pt)) {
2828 return child_controls[i];
2831 return null;
2834 public IContainerControl GetContainerControl() {
2835 Control current = this;
2837 while (current!=null) {
2838 if ((current is IContainerControl) && ((current.control_style & ControlStyles.ContainerControl)!=0)) {
2839 return (IContainerControl)current;
2841 current = current.parent;
2843 return null;
2846 public Control GetNextControl(Control ctl, bool forward) {
2848 if (!this.Contains(ctl)) {
2849 ctl = this;
2852 if (forward) {
2853 ctl = FindControlForward(this, ctl);
2855 else {
2856 ctl = FindControlBackward(this, ctl);
2859 if (ctl != this) {
2860 return ctl;
2862 return null;
2865 #if NET_2_0
2866 public virtual Size GetPreferredSize (Size proposedSize) {
2867 return preferred_size;
2869 #endif
2871 public void Hide() {
2872 this.Visible = false;
2875 public void Invalidate() {
2876 Invalidate(ClientRectangle, false);
2879 public void Invalidate(bool invalidateChildren) {
2880 Invalidate(ClientRectangle, invalidateChildren);
2883 public void Invalidate(System.Drawing.Rectangle rc) {
2884 Invalidate(rc, false);
2887 public void Invalidate(System.Drawing.Rectangle rc, bool invalidateChildren) {
2888 if (!IsHandleCreated || !Visible || rc.Width == 0 || rc.Height == 0) {
2889 return;
2892 NotifyInvalidate(rc);
2894 XplatUI.Invalidate(Handle, rc, false);
2896 if (invalidateChildren) {
2897 Control [] controls = child_controls.GetAllControls ();
2898 for (int i=0; i<controls.Length; i++)
2899 controls [i].Invalidate ();
2901 OnInvalidated(new InvalidateEventArgs(rc));
2904 public void Invalidate(System.Drawing.Region region) {
2905 Invalidate(region, false);
2908 public void Invalidate(System.Drawing.Region region, bool invalidateChildren) {
2909 RectangleF bounds = region.GetBounds (CreateGraphics ());
2910 Invalidate (new Rectangle ((int) bounds.X, (int) bounds.Y, (int) bounds.Width, (int) bounds.Height),
2911 invalidateChildren);
2914 public object Invoke (Delegate method) {
2915 object [] prms = null;
2916 if (method is EventHandler)
2917 prms = new object [] { this, EventArgs.Empty };
2919 return Invoke(method, prms);
2922 public object Invoke (Delegate method, object[] args) {
2923 if (!this.InvokeRequired) {
2924 return method.DynamicInvoke(args);
2927 IAsyncResult result = BeginInvoke (method, args);
2928 return EndInvoke(result);
2931 internal object InvokeInternal (Delegate method, bool disposing) {
2932 return InvokeInternal(method, null, disposing);
2935 internal object InvokeInternal (Delegate method, object[] args, bool disposing) {
2936 if (!this.InvokeRequired) {
2937 return method.DynamicInvoke(args);
2940 IAsyncResult result = BeginInvokeInternal (method, args, disposing);
2941 return EndInvoke(result);
2944 [EditorBrowsable(EditorBrowsableState.Advanced)]
2945 public void PerformLayout() {
2946 PerformLayout(null, null);
2949 #if !NET_2_0
2950 private void SetImplicitBounds (int x, int y, int width, int height)
2952 Rectangle saved_bounds = explicit_bounds;
2953 SetBounds (x, y, width, height);
2954 explicit_bounds = saved_bounds;
2956 #endif
2958 [EditorBrowsable(EditorBrowsableState.Advanced)]
2959 public void PerformLayout(Control affectedControl, string affectedProperty) {
2960 LayoutEventArgs levent = new LayoutEventArgs(affectedControl, affectedProperty);
2962 if (layout_suspended > 0) {
2963 layout_pending = true;
2964 return;
2967 layout_pending = false;
2969 // Prevent us from getting messed up
2970 layout_suspended++;
2972 // Perform all Dock and Anchor calculations
2973 try {
2975 #if NET_2_0
2976 this.layout_engine.Layout(this, levent);
2977 #else
2978 // This has been moved to Layout/DefaultLayout.cs for 2.0, please duplicate any changes/fixes there.
2979 Control child;
2980 AnchorStyles anchor;
2981 Rectangle space;
2983 space = DisplayRectangle;
2985 // Deal with docking; go through in reverse, MS docs say that lowest Z-order is closest to edge
2986 Control [] controls = child_controls.GetAllControls ();
2987 for (int i = controls.Length - 1; i >= 0; i--) {
2988 child = controls [i];
2990 if (!child.Visible) {
2991 continue;
2994 switch (child.Dock) {
2995 case DockStyle.None: {
2996 // Do nothing
2997 break;
3000 case DockStyle.Left: {
3001 child.SetImplicitBounds(space.Left, space.Y, child.Width, space.Height);
3002 space.X+=child.Width;
3003 space.Width-=child.Width;
3004 break;
3007 case DockStyle.Top: {
3008 child.SetImplicitBounds(space.Left, space.Y, space.Width, child.Height);
3009 space.Y+=child.Height;
3010 space.Height-=child.Height;
3011 break;
3014 case DockStyle.Right: {
3015 child.SetImplicitBounds(space.Right-child.Width, space.Y, child.Width, space.Height);
3016 space.Width-=child.Width;
3017 break;
3020 case DockStyle.Bottom: {
3021 child.SetImplicitBounds(space.Left, space.Bottom-child.Height, space.Width, child.Height);
3022 space.Height-=child.Height;
3023 break;
3028 for (int i = controls.Length - 1; i >= 0; i--) {
3029 child=controls[i];
3031 //if (child.Visible && (child.Dock == DockStyle.Fill)) {
3032 if (child.Dock == DockStyle.Fill) {
3033 child.SetImplicitBounds(space.Left, space.Top, space.Width, space.Height);
3037 space = DisplayRectangle;
3039 for (int i=0; i < controls.Length; i++) {
3040 int left;
3041 int top;
3042 int width;
3043 int height;
3045 child = controls[i];
3047 // If the control is docked we don't need to do anything
3048 if (child.Dock != DockStyle.None) {
3049 continue;
3052 anchor = child.Anchor;
3054 left = child.Left;
3055 top = child.Top;
3056 width = child.Width;
3057 height = child.Height;
3059 if ((anchor & AnchorStyles.Left) !=0 ) {
3060 if ((anchor & AnchorStyles.Right) != 0) {
3061 width = space.Width - child.dist_right - left;
3062 } else {
3063 ; // Left anchored only, nothing to be done
3065 } else if ((anchor & AnchorStyles.Right) != 0) {
3066 left = space.Width - child.dist_right - width;
3067 } else {
3068 // left+=diff_width/2 will introduce rounding errors (diff_width removed from svn after r51780)
3069 // This calculates from scratch every time:
3070 left = child.dist_left + (space.Width - (child.dist_left + width + child.dist_right)) / 2;
3073 if ((anchor & AnchorStyles.Top) !=0 ) {
3074 if ((anchor & AnchorStyles.Bottom) != 0) {
3075 height = space.Height - child.dist_bottom - top;
3076 } else {
3077 ; // Top anchored only, nothing to be done
3079 } else if ((anchor & AnchorStyles.Bottom) != 0) {
3080 top = space.Height - child.dist_bottom - height;
3081 } else {
3082 // top += diff_height/2 will introduce rounding errors (diff_height removed from after r51780)
3083 // This calculates from scratch every time:
3084 top = child.dist_top + (space.Height - (child.dist_top + height + child.dist_bottom)) / 2;
3087 // Sanity
3088 if (width < 0) {
3089 width=0;
3092 if (height < 0) {
3093 height=0;
3096 child.SetImplicitBounds(left, top, width, height);
3098 #endif
3100 // Let everyone know
3101 OnLayout(levent);
3104 // Need to make sure we decremend layout_suspended
3105 finally {
3106 layout_suspended--;
3110 public Point PointToClient (Point p) {
3111 int x = p.X;
3112 int y = p.Y;
3114 XplatUI.ScreenToClient (Handle, ref x, ref y);
3116 return new Point (x, y);
3119 public Point PointToScreen(Point p) {
3120 int x = p.X;
3121 int y = p.Y;
3123 XplatUI.ClientToScreen(Handle, ref x, ref y);
3125 return new Point(x, y);
3128 public virtual bool PreProcessMessage(ref Message msg) {
3129 return InternalPreProcessMessage (ref msg);
3132 internal virtual bool InternalPreProcessMessage (ref Message msg) {
3133 Keys key_data;
3135 if ((msg.Msg == (int)Msg.WM_KEYDOWN) || (msg.Msg == (int)Msg.WM_SYSKEYDOWN)) {
3136 key_data = (Keys)msg.WParam.ToInt32() | XplatUI.State.ModifierKeys;
3138 if (!ProcessCmdKey(ref msg, key_data)) {
3139 if (IsInputKey(key_data)) {
3140 return false;
3143 return ProcessDialogKey(key_data);
3146 return true;
3147 } else if (msg.Msg == (int)Msg.WM_CHAR) {
3148 if (IsInputChar((char)msg.WParam)) {
3149 return false;
3151 return ProcessDialogChar((char)msg.WParam);
3152 } else if (msg.Msg == (int)Msg.WM_SYSCHAR) {
3153 return ProcessDialogChar((char)msg.WParam);
3155 return false;
3158 public Rectangle RectangleToClient(Rectangle r) {
3159 return new Rectangle(PointToClient(r.Location), r.Size);
3162 public Rectangle RectangleToScreen(Rectangle r) {
3163 return new Rectangle(PointToScreen(r.Location), r.Size);
3166 public virtual void Refresh() {
3167 if (IsHandleCreated == true) {
3168 Invalidate();
3169 XplatUI.UpdateWindow(window.Handle);
3171 Control [] controls = child_controls.GetAllControls ();
3172 for (int i=0; i < controls.Length; i++) {
3173 controls[i].Refresh();
3179 [EditorBrowsable(EditorBrowsableState.Never)]
3180 public virtual void ResetBackColor() {
3181 BackColor = Color.Empty;
3184 [EditorBrowsable(EditorBrowsableState.Never)]
3185 public void ResetBindings() {
3186 data_bindings.Clear();
3189 [EditorBrowsable(EditorBrowsableState.Never)]
3190 public virtual void ResetCursor() {
3191 Cursor = null;
3194 [EditorBrowsable(EditorBrowsableState.Never)]
3195 public virtual void ResetFont() {
3196 font = null;
3199 [EditorBrowsable(EditorBrowsableState.Never)]
3200 public virtual void ResetForeColor() {
3201 foreground_color = Color.Empty;
3204 [EditorBrowsable(EditorBrowsableState.Never)]
3205 public void ResetImeMode() {
3206 ime_mode = DefaultImeMode;
3209 [EditorBrowsable(EditorBrowsableState.Never)]
3210 public virtual void ResetRightToLeft() {
3211 right_to_left = RightToLeft.Inherit;
3214 public virtual void ResetText() {
3215 text = String.Empty;
3218 public void ResumeLayout() {
3219 ResumeLayout (true);
3222 public void ResumeLayout(bool performLayout) {
3223 if (layout_suspended > 0) {
3224 layout_suspended--;
3227 if (layout_suspended == 0) {
3228 Control [] controls = child_controls.GetAllControls ();
3229 for (int i=0; i<controls.Length; i++) {
3230 controls [i].UpdateDistances ();
3233 if (performLayout && layout_pending) {
3234 PerformLayout();
3239 public void Scale(float ratio) {
3240 ScaleCore(ratio, ratio);
3243 public void Scale(float dx, float dy) {
3244 ScaleCore(dx, dy);
3247 #if NET_2_0
3248 public void Scale(SizeF factor) {
3249 ScaleCore(factor.Width, factor.Height);
3251 #endif
3253 public void Select() {
3254 Select(false, false);
3257 #if DebugFocus
3258 private void printTree(Control c, string t) {
3259 foreach(Control i in c.child_controls) {
3260 Console.WriteLine("{2}{0}.TabIndex={1}", i, i.tab_index, t);
3261 printTree(i, t+"\t");
3264 #endif
3265 public bool SelectNextControl(Control ctl, bool forward, bool tabStopOnly, bool nested, bool wrap) {
3266 Control c;
3268 #if DebugFocus
3269 Console.WriteLine("{0}", this.FindForm());
3270 printTree(this, "\t");
3271 #endif
3273 if (!this.Contains(ctl) || (!nested && (ctl.parent != this))) {
3274 ctl = null;
3276 c = ctl;
3277 do {
3278 c = GetNextControl(c, forward);
3279 if (c == null) {
3280 if (wrap) {
3281 wrap = false;
3282 continue;
3284 break;
3287 if (c.CanSelect && ((c.parent == this) || nested) && (c.tab_stop || !tabStopOnly)) {
3288 c.Select (true, true);
3289 return true;
3291 } while (c != ctl); // If we wrap back to ourselves we stop
3293 return false;
3296 public void SendToBack() {
3297 if (parent != null) {
3298 parent.child_controls.SetChildIndex(this, parent.child_controls.Count);
3302 public void SetBounds(int x, int y, int width, int height) {
3303 SetBounds(x, y, width, height, BoundsSpecified.All);
3306 public void SetBounds(int x, int y, int width, int height, BoundsSpecified specified) {
3307 if ((specified & BoundsSpecified.X) != BoundsSpecified.X) {
3308 x = Left;
3311 if ((specified & BoundsSpecified.Y) != BoundsSpecified.Y) {
3312 y = Top;
3315 if ((specified & BoundsSpecified.Width) != BoundsSpecified.Width) {
3316 width = Width;
3319 if ((specified & BoundsSpecified.Height) != BoundsSpecified.Height) {
3320 height = Height;
3323 SetBoundsCore(x, y, width, height, specified);
3324 if (parent != null) {
3325 parent.PerformLayout(this, "Bounds");
3329 public void Show() {
3330 if (!is_created) {
3331 this.CreateControl();
3334 this.Visible=true;
3337 public void SuspendLayout() {
3338 layout_suspended++;
3341 public void Update() {
3342 if (IsHandleCreated) {
3343 XplatUI.UpdateWindow(window.Handle);
3346 #endregion // Public Instance Methods
3348 #region Protected Instance Methods
3349 [EditorBrowsable(EditorBrowsableState.Advanced)]
3350 [MonoTODO("Implement this and tie it into Control.ControlAccessibleObject.NotifyClients")]
3351 protected void AccessibilityNotifyClients(AccessibleEvents accEvent, int childID) {
3352 throw new NotImplementedException();
3355 [EditorBrowsable(EditorBrowsableState.Advanced)]
3356 protected virtual AccessibleObject CreateAccessibilityInstance() {
3357 return new Control.ControlAccessibleObject(this);
3360 [EditorBrowsable(EditorBrowsableState.Advanced)]
3361 protected virtual ControlCollection CreateControlsInstance() {
3362 return new ControlCollection(this);
3365 [EditorBrowsable(EditorBrowsableState.Advanced)]
3366 protected virtual void CreateHandle() {
3367 if (IsDisposed) {
3368 throw new ObjectDisposedException(GetType().FullName.ToString());
3371 if (IsHandleCreated && !is_recreating) {
3372 return;
3375 window.CreateHandle(CreateParams);
3377 if (window.Handle != IntPtr.Zero) {
3378 creator_thread = Thread.CurrentThread;
3380 XplatUI.EnableWindow(window.Handle, is_enabled);
3381 XplatUI.SetVisible(window.Handle, is_visible, true);
3383 if (clip_region != null) {
3384 XplatUI.SetClipRegion(Handle, clip_region);
3387 // Set our handle with our parent
3388 if ((parent != null) && (parent.IsHandleCreated)) {
3389 XplatUI.SetParent(window.Handle, parent.Handle);
3392 // Set our handle as parent for our children
3393 Control [] children;
3395 children = child_controls.GetAllControls ();
3396 for (int i = 0; i < children.Length; i++ ) {
3397 if (!children[i].RecreatingHandle)
3398 XplatUI.SetParent(children[i].Handle, window.Handle);
3401 UpdateStyles();
3402 XplatUI.SetAllowDrop (Handle, allow_drop);
3404 // Find out where the window manager placed us
3405 if ((CreateParams.Style & (int)WindowStyles.WS_CHILD) != 0) {
3406 XplatUI.SetBorderStyle(window.Handle, (FormBorderStyle)border_style);
3408 UpdateBounds();
3410 OnHandleCreated(EventArgs.Empty);
3414 [EditorBrowsable(EditorBrowsableState.Advanced)]
3415 protected virtual void DefWndProc(ref Message m) {
3416 window.DefWndProc(ref m);
3419 [EditorBrowsable(EditorBrowsableState.Advanced)]
3420 protected virtual void DestroyHandle() {
3421 if (IsHandleCreated) {
3422 if (window != null) {
3423 window.DestroyHandle();
3428 protected internal bool GetStyle(ControlStyles flag) {
3429 return (control_style & flag) != 0;
3432 protected bool GetTopLevel() {
3433 return is_toplevel;
3436 [EditorBrowsable(EditorBrowsableState.Advanced)]
3437 protected virtual void InitLayout() {
3438 UpdateDistances();
3441 [EditorBrowsable(EditorBrowsableState.Advanced)]
3442 protected void InvokeGotFocus(Control toInvoke, EventArgs e) {
3443 toInvoke.OnGotFocus(e);
3446 [EditorBrowsable(EditorBrowsableState.Advanced)]
3447 protected void InvokeLostFocus(Control toInvoke, EventArgs e) {
3448 toInvoke.OnLostFocus(e);
3451 [EditorBrowsable(EditorBrowsableState.Advanced)]
3452 protected void InvokeOnClick(Control toInvoke, EventArgs e) {
3453 toInvoke.OnClick(e);
3456 protected void InvokePaint(Control toInvoke, PaintEventArgs e) {
3457 toInvoke.OnPaint(e);
3460 protected void InvokePaintBackground(Control toInvoke, PaintEventArgs e) {
3461 toInvoke.OnPaintBackground(e);
3464 protected virtual bool IsInputChar (char charCode) {
3465 return true;
3468 protected virtual bool IsInputKey (Keys keyData) {
3469 // Doc says this one calls IsInputChar; not sure what to do with that
3470 return false;
3473 [EditorBrowsable(EditorBrowsableState.Advanced)]
3474 protected virtual void NotifyInvalidate(Rectangle invalidatedArea) {
3475 // override me?
3478 protected virtual bool ProcessCmdKey(ref Message msg, Keys keyData) {
3479 if ((context_menu != null) && context_menu.ProcessCmdKey(ref msg, keyData)) {
3480 return true;
3483 if (parent != null) {
3484 return parent.ProcessCmdKey(ref msg, keyData);
3487 return false;
3490 protected virtual bool ProcessDialogChar(char charCode) {
3491 if (parent != null) {
3492 return parent.ProcessDialogChar (charCode);
3495 return false;
3498 protected virtual bool ProcessDialogKey (Keys keyData) {
3499 if (parent != null) {
3500 return parent.ProcessDialogKey (keyData);
3503 return false;
3506 protected virtual bool ProcessKeyEventArgs (ref Message msg)
3508 KeyEventArgs key_event;
3510 switch (msg.Msg) {
3511 case (int)Msg.WM_SYSKEYDOWN:
3512 case (int)Msg.WM_KEYDOWN: {
3513 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
3514 OnKeyDown (key_event);
3515 return key_event.Handled;
3518 case (int)Msg.WM_SYSKEYUP:
3519 case (int)Msg.WM_KEYUP: {
3520 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
3521 OnKeyUp (key_event);
3522 return key_event.Handled;
3525 case (int)Msg.WM_SYSCHAR:
3526 case (int)Msg.WM_CHAR: {
3527 KeyPressEventArgs key_press_event;
3529 key_press_event = new KeyPressEventArgs((char)msg.WParam);
3530 OnKeyPress(key_press_event);
3531 #if NET_2_0
3532 msg.WParam = (IntPtr)key_press_event.KeyChar;
3533 #endif
3534 return key_press_event.Handled;
3537 default: {
3538 break;
3542 return false;
3545 protected internal virtual bool ProcessKeyMessage(ref Message msg) {
3546 if (parent != null) {
3547 if (parent.ProcessKeyPreview(ref msg)) {
3548 return true;
3552 return ProcessKeyEventArgs(ref msg);
3555 protected virtual bool ProcessKeyPreview(ref Message msg) {
3556 if (parent != null) {
3557 return parent.ProcessKeyPreview(ref msg);
3560 return false;
3563 protected virtual bool ProcessMnemonic(char charCode) {
3564 // override me
3565 return false;
3568 [EditorBrowsable(EditorBrowsableState.Advanced)]
3569 protected void RaiseDragEvent(object key, DragEventArgs e) {
3570 // MS Internal
3573 [EditorBrowsable(EditorBrowsableState.Advanced)]
3574 protected void RaiseKeyEvent(object key, KeyEventArgs e) {
3575 // MS Internal
3578 [EditorBrowsable(EditorBrowsableState.Advanced)]
3579 protected void RaiseMouseEvent(object key, MouseEventArgs e) {
3580 // MS Internal
3583 [EditorBrowsable(EditorBrowsableState.Advanced)]
3584 protected void RaisePaintEvent(object key, PaintEventArgs e) {
3585 // MS Internal
3588 private void SetIsRecreating ()
3590 is_recreating=true;
3592 foreach (Control c in Controls.GetAllControls()) {
3593 c.SetIsRecreating ();
3597 [EditorBrowsable(EditorBrowsableState.Advanced)]
3598 protected void RecreateHandle() {
3599 #if DebugRecreate
3600 Console.WriteLine("Recreating control {0}", XplatUI.Window(window.Handle));
3601 #endif
3603 SetIsRecreating ();
3605 if (IsHandleCreated) {
3606 #if DebugRecreate
3607 Console.WriteLine(" + handle is created, destroying it.");
3608 #endif
3609 DestroyHandle();
3610 // WM_DESTROY will CreateHandle for us
3611 } else {
3612 #if DebugRecreate
3613 Console.WriteLine(" + handle is not created, creating it.");
3614 #endif
3615 if (!is_created) {
3616 CreateControl();
3617 } else {
3618 CreateHandle();
3621 is_recreating = false;
3622 #if DebugRecreate
3623 Console.WriteLine (" + new handle = {0:X}", Handle.ToInt32());
3624 #endif
3629 [EditorBrowsable(EditorBrowsableState.Advanced)]
3630 protected void ResetMouseEventArgs() {
3631 // MS Internal
3634 [EditorBrowsable(EditorBrowsableState.Advanced)]
3635 protected ContentAlignment RtlTranslateAlignment(ContentAlignment align) {
3636 if (right_to_left == RightToLeft.No) {
3637 return align;
3640 switch (align) {
3641 case ContentAlignment.TopLeft: {
3642 return ContentAlignment.TopRight;
3645 case ContentAlignment.TopRight: {
3646 return ContentAlignment.TopLeft;
3649 case ContentAlignment.MiddleLeft: {
3650 return ContentAlignment.MiddleRight;
3653 case ContentAlignment.MiddleRight: {
3654 return ContentAlignment.MiddleLeft;
3657 case ContentAlignment.BottomLeft: {
3658 return ContentAlignment.BottomRight;
3661 case ContentAlignment.BottomRight: {
3662 return ContentAlignment.BottomLeft;
3665 default: {
3666 // if it's center it doesn't change
3667 return align;
3672 [EditorBrowsable(EditorBrowsableState.Advanced)]
3673 protected HorizontalAlignment RtlTranslateAlignment(HorizontalAlignment align) {
3674 if ((right_to_left == RightToLeft.No) || (align == HorizontalAlignment.Center)) {
3675 return align;
3678 if (align == HorizontalAlignment.Left) {
3679 return HorizontalAlignment.Right;
3682 // align must be HorizontalAlignment.Right
3683 return HorizontalAlignment.Left;
3686 [EditorBrowsable(EditorBrowsableState.Advanced)]
3687 protected LeftRightAlignment RtlTranslateAlignment(LeftRightAlignment align) {
3688 if (right_to_left == RightToLeft.No) {
3689 return align;
3692 if (align == LeftRightAlignment.Left) {
3693 return LeftRightAlignment.Right;
3696 // align must be LeftRightAlignment.Right;
3697 return LeftRightAlignment.Left;
3700 [EditorBrowsable(EditorBrowsableState.Advanced)]
3701 protected ContentAlignment RtlTranslateContent(ContentAlignment align) {
3702 return RtlTranslateAlignment(align);
3705 [EditorBrowsable(EditorBrowsableState.Advanced)]
3706 protected HorizontalAlignment RtlTranslateHorizontal(HorizontalAlignment align) {
3707 return RtlTranslateAlignment(align);
3710 [EditorBrowsable(EditorBrowsableState.Advanced)]
3711 protected LeftRightAlignment RtlTranslateLeftRight(LeftRightAlignment align) {
3712 return RtlTranslateAlignment(align);
3715 [EditorBrowsable(EditorBrowsableState.Advanced)]
3716 protected virtual void ScaleCore(float dx, float dy) {
3717 Point location;
3718 Size size;
3720 SuspendLayout();
3722 location = new Point((int)(Left * dx), (int)(Top * dy));
3723 size = this.ClientSize;
3725 if (!GetStyle(ControlStyles.FixedWidth)) {
3726 size.Width = (int)(size.Width * dx);
3729 if (!GetStyle(ControlStyles.FixedHeight)) {
3730 size.Height = (int)(size.Height * dy);
3733 SetBounds(location.X, location.Y, size.Width, size.Height, BoundsSpecified.All);
3735 /* Now scale our children */
3736 Control [] controls = child_controls.GetAllControls ();
3737 for (int i=0; i < controls.Length; i++) {
3738 controls[i].Scale(dx, dy);
3741 ResumeLayout();
3744 protected virtual void Select(bool directed, bool forward) {
3745 IContainerControl container;
3747 container = GetContainerControl();
3748 if (container != null)
3749 container.ActiveControl = this;
3752 [EditorBrowsable(EditorBrowsableState.Advanced)]
3753 protected virtual void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
3754 // SetBoundsCore updates the Win32 control itself. UpdateBounds updates the controls variables and fires events, I'm guessing - pdb
3755 if (IsHandleCreated) {
3756 XplatUI.SetWindowPos(Handle, x, y, width, height);
3758 // Win32 automatically changes negative width/height to 0.
3759 // The control has already been sent a WM_WINDOWPOSCHANGED message and it has the correct
3760 // data, but it'll be overwritten when we call UpdateBounds unless we get the updated
3761 // size.
3762 if (width < 0 || height < 0) {
3763 int cw, ch, ix, iy;
3764 XplatUI.GetWindowPos(Handle, this is Form, out ix, out iy, out width, out height, out cw, out ch);
3768 UpdateBounds(x, y, width, height);
3770 UpdateDistances();
3773 [EditorBrowsable(EditorBrowsableState.Advanced)]
3774 protected virtual void SetClientSizeCore(int x, int y) {
3775 // Calculate the actual window size from the client size (it usually stays the same or grows)
3776 Rectangle ClientRect;
3777 Rectangle WindowRect;
3778 CreateParams cp;
3780 ClientRect = new Rectangle(0, 0, x, y);
3781 cp = this.CreateParams;
3783 if (XplatUI.CalculateWindowRect(ref ClientRect, cp.Style, cp.ExStyle, null, out WindowRect)==false) {
3784 return;
3787 SetBounds(bounds.X, bounds.Y, WindowRect.Width, WindowRect.Height, BoundsSpecified.Size);
3790 [EditorBrowsable(EditorBrowsableState.Advanced)]
3791 protected internal void SetStyle(ControlStyles flag, bool value) {
3792 if (value) {
3793 control_style |= flag;
3794 } else {
3795 control_style &= ~flag;
3799 protected void SetTopLevel(bool value) {
3800 if ((GetTopLevel() != value) && (parent != null)) {
3801 throw new Exception();
3804 if (this is Form) {
3805 if (value == true) {
3806 if (!Visible) {
3807 Visible = true;
3809 } else {
3810 if (Visible) {
3811 Visible = false;
3815 is_toplevel = value;
3818 protected virtual void SetVisibleCore(bool value) {
3819 if (value!=is_visible) {
3820 if (value && (window.Handle == IntPtr.Zero) || !is_created) {
3821 CreateControl();
3824 is_visible=value;
3826 if (IsHandleCreated) {
3827 XplatUI.SetVisible(Handle, value, true);
3828 // Explicitly move Toplevel windows to where we want them;
3829 // apparently moving unmapped toplevel windows doesn't work
3830 if (is_visible && (this is Form)) {
3831 XplatUI.SetWindowPos(window.Handle, bounds.X, bounds.Y, bounds.Width, bounds.Height);
3835 OnVisibleChanged(EventArgs.Empty);
3837 if (value == false && parent != null && Focused) {
3838 Control container;
3840 // Need to start at parent, GetContainerControl might return ourselves if we're a container
3841 container = (Control)parent.GetContainerControl();
3842 if (container != null) {
3843 container.SelectNextControl(this, true, true, true, true);
3847 if (parent != null) {
3848 parent.PerformLayout(this, "visible");
3849 } else {
3850 PerformLayout(this, "visible");
3855 [EditorBrowsable(EditorBrowsableState.Advanced)]
3856 protected void UpdateBounds() {
3857 int x;
3858 int y;
3859 int width;
3860 int height;
3861 int client_width;
3862 int client_height;
3864 if (!IsHandleCreated) {
3865 CreateHandle();
3868 XplatUI.GetWindowPos(this.Handle, this is Form, out x, out y, out width, out height, out client_width, out client_height);
3870 UpdateBounds(x, y, width, height, client_width, client_height);
3873 [EditorBrowsable(EditorBrowsableState.Advanced)]
3874 protected void UpdateBounds(int x, int y, int width, int height) {
3875 CreateParams cp;
3876 Rectangle rect;
3878 // Calculate client rectangle
3879 rect = new Rectangle(0, 0, 0, 0);
3880 cp = CreateParams;
3882 XplatUI.CalculateWindowRect(ref rect, cp.Style, cp.ExStyle, cp.menu, out rect);
3883 UpdateBounds(x, y, width, height, width - (rect.Right - rect.Left), height - (rect.Bottom - rect.Top));
3886 [EditorBrowsable(EditorBrowsableState.Advanced)]
3887 protected void UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) {
3888 // UpdateBounds only seems to set our sizes and fire events but not update the GUI window to match
3889 bool moved = false;
3890 bool resized = false;
3892 // Needed to generate required notifications
3893 if ((this.bounds.X!=x) || (this.bounds.Y!=y)) {
3894 moved=true;
3897 if ((this.Bounds.Width!=width) || (this.Bounds.Height!=height)) {
3898 resized=true;
3901 bounds.X=x;
3902 bounds.Y=y;
3903 bounds.Width=width;
3904 bounds.Height=height;
3906 // Assume explicit bounds set. SetImplicitBounds will restore old bounds
3907 explicit_bounds = bounds;
3909 client_size.Width=clientWidth;
3910 client_size.Height=clientHeight;
3912 if (moved) {
3913 OnLocationChanged(EventArgs.Empty);
3916 if (resized) {
3917 OnSizeChanged(EventArgs.Empty);
3921 [EditorBrowsable(EditorBrowsableState.Advanced)]
3922 protected void UpdateStyles() {
3923 if (!IsHandleCreated) {
3924 return;
3927 XplatUI.SetWindowStyle(window.Handle, CreateParams);
3928 OnStyleChanged(EventArgs.Empty);
3931 private void UpdateZOrderOfChild(Control child) {
3932 if (IsHandleCreated && child.IsHandleCreated && (child.parent == this)) {
3933 int index;
3935 index = child_controls.IndexOf(child);
3937 if (index > 0) {
3938 XplatUI.SetZOrder(child.Handle, child_controls[index - 1].Handle, false, false);
3939 } else {
3940 XplatUI.SetZOrder(child.Handle, IntPtr.Zero, true, false);
3945 private void UpdateChildrenZOrder() {
3946 Control [] controls;
3948 if (!IsHandleCreated) {
3949 return;
3952 controls = child_controls.GetAllControls ();
3953 for (int i = 1; i < controls.Length; i++ ) {
3954 XplatUI.SetZOrder(controls[i].Handle, controls[i-1].Handle, false, false);
3958 [EditorBrowsable(EditorBrowsableState.Advanced)]
3959 protected void UpdateZOrder() {
3960 if (parent != null) {
3961 parent.UpdateZOrderOfChild(this);
3965 protected virtual void WndProc(ref Message m) {
3966 #if debug
3967 Console.WriteLine("Control {0} received message {1}", window.Handle == IntPtr.Zero ? this.Text : XplatUI.Window(window.Handle), m.ToString ());
3968 #endif
3969 if ((this.control_style & ControlStyles.EnableNotifyMessage) != 0) {
3970 OnNotifyMessage(m);
3973 switch((Msg)m.Msg) {
3974 case Msg.WM_DESTROY: {
3975 OnHandleDestroyed(EventArgs.Empty);
3976 #if DebugRecreate
3977 IntPtr handle = window.Handle;
3978 #endif
3979 window.InvalidateHandle();
3981 if (is_recreating) {
3982 #if DebugRecreate
3983 Console.WriteLine ("Creating handle for {0:X}", handle.ToInt32());
3984 #endif
3985 CreateHandle();
3986 #if DebugRecreate
3987 Console.WriteLine (" + new handle = {0:X}", Handle.ToInt32());
3988 #endif
3989 is_recreating = false;
3991 return;
3994 case Msg.WM_WINDOWPOSCHANGED: {
3995 if (Visible) {
3996 Rectangle save_bounds = explicit_bounds;
3997 UpdateBounds();
3998 explicit_bounds = save_bounds;
3999 if (GetStyle(ControlStyles.ResizeRedraw)) {
4000 Invalidate();
4003 return;
4006 // Nice description of what should happen when handling WM_PAINT
4007 // can be found here: http://pluralsight.com/wiki/default.aspx/Craig/FlickerFreeControlDrawing.html
4008 // and here http://msdn.microsoft.com/msdnmag/issues/06/03/WindowsFormsPerformance/
4009 case Msg.WM_PAINT: {
4010 PaintEventArgs paint_event;
4012 paint_event = XplatUI.PaintEventStart(Handle, true);
4014 if (paint_event == null) {
4015 return;
4018 if (invalid_region != null && !invalid_region.IsVisible (paint_event.ClipRectangle)) {
4020 // Just blit the previous image
4021 XplatUI.BlitFromOffscreen (Handle, paint_event.Graphics, backbuffer, backbuffer_dc, paint_event.ClipRectangle);
4022 XplatUI.PaintEventEnd (Handle, true);
4023 return;
4026 Graphics dc = null;
4027 Graphics back_dc = null;
4028 object back = null;
4029 if (ThemeEngine.Current.DoubleBufferingSupported) {
4030 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
4031 CreateBackBuffer ();
4032 back = backbuffer;
4033 back_dc = backbuffer_dc;
4034 dc = paint_event.SetGraphics (back_dc);
4038 if (!GetStyle(ControlStyles.Opaque)) {
4039 OnPaintBackground(paint_event);
4042 // Button-derived controls choose to ignore their Opaque style, give them a chance to draw their background anyways
4043 OnPaintBackgroundInternal(paint_event);
4045 OnPaintInternal(paint_event);
4046 if (!paint_event.Handled) {
4047 OnPaint(paint_event);
4050 if (ThemeEngine.Current.DoubleBufferingSupported)
4051 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
4052 XplatUI.BlitFromOffscreen (Handle, dc, back, back_dc, paint_event.ClipRectangle);
4053 paint_event.SetGraphics (dc);
4054 invalid_region.Exclude (paint_event.ClipRectangle);
4056 if (back != backbuffer)
4057 XplatUI.DestroyOffscreenDrawable (back, back_dc);
4060 XplatUI.PaintEventEnd(Handle, true);
4062 return;
4065 case Msg.WM_ERASEBKGND: {
4066 // The DefWndProc will never have to handle this, we always paint the background in managed code
4067 // In theory this code would look at ControlStyles.AllPaintingInWmPaint and and call OnPaintBackground
4068 // here but it just makes things more complicated...
4069 m.Result = (IntPtr)1;
4070 return;
4073 case Msg.WM_LBUTTONUP: {
4074 MouseEventArgs me;
4076 me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Left,
4077 mouse_clicks,
4078 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4081 HandleClick(mouse_clicks, me);
4082 OnMouseUp (me);
4084 if (InternalCapture) {
4085 InternalCapture = false;
4088 if (mouse_clicks > 1) {
4089 mouse_clicks = 1;
4091 return;
4094 case Msg.WM_LBUTTONDOWN: {
4095 if (CanSelect) {
4096 Select (true, true);
4098 InternalCapture = true;
4099 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4100 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4101 0));
4103 return;
4106 case Msg.WM_LBUTTONDBLCLK: {
4107 InternalCapture = true;
4108 mouse_clicks++;
4109 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4110 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4111 0));
4112 return;
4115 case Msg.WM_MBUTTONUP: {
4116 MouseEventArgs me;
4118 me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Middle,
4119 mouse_clicks,
4120 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4123 HandleClick(mouse_clicks, me);
4124 OnMouseUp (me);
4125 if (InternalCapture) {
4126 InternalCapture = false;
4128 if (mouse_clicks > 1) {
4129 mouse_clicks = 1;
4131 return;
4134 case Msg.WM_MBUTTONDOWN: {
4135 InternalCapture = true;
4136 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4137 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4138 0));
4139 return;
4142 case Msg.WM_MBUTTONDBLCLK: {
4143 InternalCapture = true;
4144 mouse_clicks++;
4145 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4146 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4147 0));
4148 return;
4151 case Msg.WM_RBUTTONUP: {
4152 MouseEventArgs me;
4153 Point pt;
4155 pt = new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()));
4156 pt = PointToScreen(pt);
4158 XplatUI.SendMessage(m.HWnd, Msg.WM_CONTEXTMENU, m.HWnd, (IntPtr)(pt.X + (pt.Y << 16)));
4160 me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Right,
4161 mouse_clicks,
4162 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4165 HandleClick(mouse_clicks, me);
4166 OnMouseUp (me);
4168 if (InternalCapture) {
4169 InternalCapture = false;
4172 if (mouse_clicks > 1) {
4173 mouse_clicks = 1;
4175 return;
4178 case Msg.WM_RBUTTONDOWN: {
4179 InternalCapture = true;
4180 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4181 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4182 0));
4183 return;
4186 case Msg.WM_RBUTTONDBLCLK: {
4187 InternalCapture = true;
4188 mouse_clicks++;
4189 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4190 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4191 0));
4192 return;
4195 case Msg.WM_CONTEXTMENU: {
4196 if (context_menu != null) {
4197 Point pt;
4199 pt = new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()));
4200 context_menu.Show(this, PointToClient(pt));
4201 return;
4204 DefWndProc(ref m);
4205 return;
4208 case Msg.WM_MOUSEWHEEL: {
4209 DefWndProc(ref m);
4210 OnMouseWheel (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4211 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4212 HighOrder(m.WParam.ToInt32())));
4213 return;
4217 case Msg.WM_MOUSEMOVE: {
4218 OnMouseMove (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
4219 mouse_clicks,
4220 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
4221 0));
4222 return;
4225 case Msg.WM_MOUSE_ENTER: {
4226 if (is_entered) {
4227 return;
4229 is_entered = true;
4230 OnMouseEnter(EventArgs.Empty);
4231 return;
4234 case Msg.WM_MOUSE_LEAVE: {
4235 is_entered=false;
4236 OnMouseLeave(EventArgs.Empty);
4237 return;
4240 case Msg.WM_MOUSEHOVER: {
4241 OnMouseHover(EventArgs.Empty);
4242 return;
4245 case Msg.WM_SYSKEYUP: {
4246 if (ProcessKeyMessage(ref m)) {
4247 m.Result = IntPtr.Zero;
4248 return;
4251 if ((m.WParam.ToInt32() & (int)Keys.KeyCode) == (int)Keys.Menu) {
4252 Form form;
4254 form = FindForm();
4255 if (form != null && form.ActiveMenu != null) {
4256 form.ActiveMenu.ProcessCmdKey(ref m, (Keys)m.WParam.ToInt32());
4260 DefWndProc (ref m);
4261 return;
4264 case Msg.WM_SYSKEYDOWN:
4265 case Msg.WM_KEYDOWN:
4266 case Msg.WM_KEYUP:
4267 case Msg.WM_SYSCHAR:
4268 case Msg.WM_CHAR: {
4269 if (ProcessKeyMessage(ref m)) {
4270 m.Result = IntPtr.Zero;
4271 return;
4273 DefWndProc (ref m);
4274 return;
4277 case Msg.WM_HELP: {
4278 Point mouse_pos;
4279 if (m.LParam != IntPtr.Zero) {
4280 HELPINFO hi;
4282 hi = new HELPINFO();
4284 hi = (HELPINFO) Marshal.PtrToStructure (m.LParam, typeof (HELPINFO));
4285 mouse_pos = new Point(hi.MousePos.x, hi.MousePos.y);
4286 } else {
4287 mouse_pos = Control.MousePosition;
4289 OnHelpRequested(new HelpEventArgs(mouse_pos));
4290 m.Result = (IntPtr)1;
4291 return;
4294 case Msg.WM_KILLFOCUS: {
4295 this.has_focus = false;
4296 OnLostFocusInternal (EventArgs.Empty);
4297 return;
4300 case Msg.WM_SETFOCUS: {
4301 if (!has_focus) {
4302 this.has_focus = true;
4303 OnGotFocusInternal (EventArgs.Empty);
4305 return;
4308 case Msg.WM_SYSCOLORCHANGE: {
4309 ThemeEngine.Current.ResetDefaults();
4310 OnSystemColorsChanged(EventArgs.Empty);
4311 return;
4314 case Msg.WM_SETCURSOR: {
4315 if ((cursor == null) || ((HitTest)(m.LParam.ToInt32() & 0xffff) != HitTest.HTCLIENT)) {
4316 DefWndProc(ref m);
4317 return;
4320 XplatUI.SetCursor(window.Handle, cursor.handle);
4321 m.Result = (IntPtr)1;
4323 return;
4326 default:
4327 DefWndProc(ref m);
4328 return;
4331 #endregion // Public Instance Methods
4333 #region OnXXX methods
4334 [EditorBrowsable(EditorBrowsableState.Advanced)]
4335 protected virtual void OnBackColorChanged(EventArgs e) {
4336 EventHandler eh = (EventHandler)(Events [BackColorChangedEvent]);
4337 if (eh != null)
4338 eh (this, e);
4339 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackColorChanged(e);
4342 [EditorBrowsable(EditorBrowsableState.Advanced)]
4343 protected virtual void OnBackgroundImageChanged(EventArgs e) {
4344 EventHandler eh = (EventHandler)(Events [BackgroundImageChangedEvent]);
4345 if (eh != null)
4346 eh (this, e);
4347 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackgroundImageChanged(e);
4350 [EditorBrowsable(EditorBrowsableState.Advanced)]
4351 protected virtual void OnBindingContextChanged(EventArgs e) {
4352 CheckDataBindings ();
4353 EventHandler eh = (EventHandler)(Events [BindingContextChangedEvent]);
4354 if (eh != null)
4355 eh (this, e);
4356 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBindingContextChanged(e);
4359 [EditorBrowsable(EditorBrowsableState.Advanced)]
4360 protected virtual void OnCausesValidationChanged(EventArgs e) {
4361 EventHandler eh = (EventHandler)(Events [CausesValidationChangedEvent]);
4362 if (eh != null)
4363 eh (this, e);
4366 [EditorBrowsable(EditorBrowsableState.Advanced)]
4367 protected virtual void OnChangeUICues(UICuesEventArgs e) {
4368 UICuesEventHandler eh = (UICuesEventHandler)(Events [ChangeUICuesEvent]);
4369 if (eh != null)
4370 eh (this, e);
4373 [EditorBrowsable(EditorBrowsableState.Advanced)]
4374 protected virtual void OnClick(EventArgs e) {
4375 EventHandler eh = (EventHandler)(Events [ClickEvent]);
4376 if (eh != null)
4377 eh (this, e);
4380 [EditorBrowsable(EditorBrowsableState.Advanced)]
4381 protected virtual void OnContextMenuChanged(EventArgs e) {
4382 EventHandler eh = (EventHandler)(Events [ContextMenuChangedEvent]);
4383 if (eh != null)
4384 eh (this, e);
4387 [EditorBrowsable(EditorBrowsableState.Advanced)]
4388 protected virtual void OnControlAdded(ControlEventArgs e) {
4389 ControlEventHandler eh = (ControlEventHandler)(Events [ControlAddedEvent]);
4390 if (eh != null)
4391 eh (this, e);
4394 [EditorBrowsable(EditorBrowsableState.Advanced)]
4395 protected virtual void OnControlRemoved(ControlEventArgs e) {
4396 ControlEventHandler eh = (ControlEventHandler)(Events [ControlRemovedEvent]);
4397 if (eh != null)
4398 eh (this, e);
4401 [EditorBrowsable(EditorBrowsableState.Advanced)]
4402 protected virtual void OnCreateControl() {
4403 // Override me!
4406 [EditorBrowsable(EditorBrowsableState.Advanced)]
4407 protected virtual void OnCursorChanged(EventArgs e) {
4408 EventHandler eh = (EventHandler)(Events [CursorChangedEvent]);
4409 if (eh != null)
4410 eh (this, e);
4413 [EditorBrowsable(EditorBrowsableState.Advanced)]
4414 protected virtual void OnDockChanged(EventArgs e) {
4415 EventHandler eh = (EventHandler)(Events [DockChangedEvent]);
4416 if (eh != null)
4417 eh (this, e);
4420 [EditorBrowsable(EditorBrowsableState.Advanced)]
4421 protected virtual void OnDoubleClick(EventArgs e) {
4422 EventHandler eh = (EventHandler)(Events [DoubleClickEvent]);
4423 if (eh != null)
4424 eh (this, e);
4427 [EditorBrowsable(EditorBrowsableState.Advanced)]
4428 protected virtual void OnDragDrop(DragEventArgs drgevent) {
4429 DragEventHandler eh = (DragEventHandler)(Events [DragDropEvent]);
4430 if (eh != null)
4431 eh (this, drgevent);
4434 [EditorBrowsable(EditorBrowsableState.Advanced)]
4435 protected virtual void OnDragEnter(DragEventArgs drgevent) {
4436 DragEventHandler eh = (DragEventHandler)(Events [DragEnterEvent]);
4437 if (eh != null)
4438 eh (this, drgevent);
4441 [EditorBrowsable(EditorBrowsableState.Advanced)]
4442 protected virtual void OnDragLeave(EventArgs e) {
4443 EventHandler eh = (EventHandler)(Events [DragLeaveEvent]);
4444 if (eh != null)
4445 eh (this, e);
4448 [EditorBrowsable(EditorBrowsableState.Advanced)]
4449 protected virtual void OnDragOver(DragEventArgs drgevent) {
4450 DragEventHandler eh = (DragEventHandler)(Events [DragOverEvent]);
4451 if (eh != null)
4452 eh (this, drgevent);
4455 [EditorBrowsable(EditorBrowsableState.Advanced)]
4456 protected virtual void OnEnabledChanged(EventArgs e) {
4457 if (IsHandleCreated) {
4458 if (this is Form) {
4459 if (((Form)this).context == null) {
4460 XplatUI.EnableWindow(window.Handle, Enabled);
4462 } else {
4463 XplatUI.EnableWindow(window.Handle, Enabled);
4465 Refresh();
4468 EventHandler eh = (EventHandler)(Events [EnabledChangedEvent]);
4469 if (eh != null)
4470 eh (this, e);
4472 for (int i=0; i<child_controls.Count; i++) {
4473 child_controls[i].OnParentEnabledChanged(e);
4477 [EditorBrowsable(EditorBrowsableState.Advanced)]
4478 protected virtual void OnEnter(EventArgs e) {
4479 EventHandler eh = (EventHandler)(Events [EnterEvent]);
4480 if (eh != null)
4481 eh (this, e);
4484 [EditorBrowsable(EditorBrowsableState.Advanced)]
4485 protected virtual void OnFontChanged(EventArgs e) {
4486 EventHandler eh = (EventHandler)(Events [FontChangedEvent]);
4487 if (eh != null)
4488 eh (this, e);
4489 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentFontChanged(e);
4492 [EditorBrowsable(EditorBrowsableState.Advanced)]
4493 protected virtual void OnForeColorChanged(EventArgs e) {
4494 EventHandler eh = (EventHandler)(Events [ForeColorChangedEvent]);
4495 if (eh != null)
4496 eh (this, e);
4497 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentForeColorChanged(e);
4500 [EditorBrowsable(EditorBrowsableState.Advanced)]
4501 protected virtual void OnGiveFeedback(GiveFeedbackEventArgs gfbevent) {
4502 GiveFeedbackEventHandler eh = (GiveFeedbackEventHandler)(Events [GiveFeedbackEvent]);
4503 if (eh != null)
4504 eh (this, gfbevent);
4507 [EditorBrowsable(EditorBrowsableState.Advanced)]
4508 protected virtual void OnGotFocus(EventArgs e) {
4509 EventHandler eh = (EventHandler)(Events [GotFocusEvent]);
4510 if (eh != null)
4511 eh (this, e);
4514 [EditorBrowsable(EditorBrowsableState.Advanced)]
4515 protected virtual void OnHandleCreated(EventArgs e) {
4516 EventHandler eh = (EventHandler)(Events [HandleCreatedEvent]);
4517 if (eh != null)
4518 eh (this, e);
4521 [EditorBrowsable(EditorBrowsableState.Advanced)]
4522 protected virtual void OnHandleDestroyed(EventArgs e) {
4523 EventHandler eh = (EventHandler)(Events [HandleDestroyedEvent]);
4524 if (eh != null)
4525 eh (this, e);
4528 [EditorBrowsable(EditorBrowsableState.Advanced)]
4529 protected virtual void OnHelpRequested(HelpEventArgs hevent) {
4530 HelpEventHandler eh = (HelpEventHandler)(Events [HelpRequestedEvent]);
4531 if (eh != null)
4532 eh (this, hevent);
4535 protected virtual void OnImeModeChanged(EventArgs e) {
4536 EventHandler eh = (EventHandler)(Events [ImeModeChangedEvent]);
4537 if (eh != null)
4538 eh (this, e);
4541 [EditorBrowsable(EditorBrowsableState.Advanced)]
4542 protected virtual void OnInvalidated(InvalidateEventArgs e) {
4543 if (ThemeEngine.Current.DoubleBufferingSupported)
4544 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
4545 // should this block be here? seems like it
4546 // would be more at home in
4547 // NotifyInvalidated..
4548 if (e.InvalidRect == ClientRectangle) {
4549 InvalidateBackBuffer ();
4551 else {
4552 // we need this Inflate call here so
4553 // that the border of the rectangle is
4554 // considered Visible (the
4555 // invalid_region.IsVisible call) in
4556 // the WM_PAINT handling below.
4557 Rectangle r = Rectangle.Inflate(e.InvalidRect, 1,1);
4558 if (invalid_region == null)
4559 invalid_region = new Region (r);
4560 else
4561 invalid_region.Union (r);
4565 InvalidateEventHandler eh = (InvalidateEventHandler)(Events [InvalidatedEvent]);
4566 if (eh != null)
4567 eh (this, e);
4570 [EditorBrowsable(EditorBrowsableState.Advanced)]
4571 protected virtual void OnKeyDown(KeyEventArgs e) {
4572 KeyEventHandler eh = (KeyEventHandler)(Events [KeyDownEvent]);
4573 if (eh != null)
4574 eh (this, e);
4577 [EditorBrowsable(EditorBrowsableState.Advanced)]
4578 protected virtual void OnKeyPress(KeyPressEventArgs e) {
4579 KeyPressEventHandler eh = (KeyPressEventHandler)(Events [KeyPressEvent]);
4580 if (eh != null)
4581 eh (this, e);
4584 [EditorBrowsable(EditorBrowsableState.Advanced)]
4585 protected virtual void OnKeyUp(KeyEventArgs e) {
4586 KeyEventHandler eh = (KeyEventHandler)(Events [KeyUpEvent]);
4587 if (eh != null)
4588 eh (this, e);
4591 [EditorBrowsable(EditorBrowsableState.Advanced)]
4592 protected virtual void OnLayout(LayoutEventArgs levent) {
4593 LayoutEventHandler eh = (LayoutEventHandler)(Events [LayoutEvent]);
4594 if (eh != null)
4595 eh (this, levent);
4598 [EditorBrowsable(EditorBrowsableState.Advanced)]
4599 protected virtual void OnLeave(EventArgs e) {
4600 EventHandler eh = (EventHandler)(Events [LeaveEvent]);
4601 if (eh != null)
4602 eh (this, e);
4605 [EditorBrowsable(EditorBrowsableState.Advanced)]
4606 protected virtual void OnLocationChanged(EventArgs e) {
4607 OnMove(e);
4608 EventHandler eh = (EventHandler)(Events [LocationChangedEvent]);
4609 if (eh != null)
4610 eh (this, e);
4613 [EditorBrowsable(EditorBrowsableState.Advanced)]
4614 protected virtual void OnLostFocus(EventArgs e) {
4615 EventHandler eh = (EventHandler)(Events [LostFocusEvent]);
4616 if (eh != null)
4617 eh (this, e);
4620 [EditorBrowsable(EditorBrowsableState.Advanced)]
4621 protected virtual void OnMouseDown(MouseEventArgs e) {
4622 MouseEventHandler eh = (MouseEventHandler)(Events [MouseDownEvent]);
4623 if (eh != null)
4624 eh (this, e);
4627 [EditorBrowsable(EditorBrowsableState.Advanced)]
4628 protected virtual void OnMouseEnter(EventArgs e) {
4629 EventHandler eh = (EventHandler)(Events [MouseEnterEvent]);
4630 if (eh != null)
4631 eh (this, e);
4634 [EditorBrowsable(EditorBrowsableState.Advanced)]
4635 protected virtual void OnMouseHover(EventArgs e) {
4636 EventHandler eh = (EventHandler)(Events [MouseHoverEvent]);
4637 if (eh != null)
4638 eh (this, e);
4641 [EditorBrowsable(EditorBrowsableState.Advanced)]
4642 protected virtual void OnMouseLeave(EventArgs e) {
4643 EventHandler eh = (EventHandler)(Events [MouseLeaveEvent]);
4644 if (eh != null)
4645 eh (this, e);
4648 [EditorBrowsable(EditorBrowsableState.Advanced)]
4649 protected virtual void OnMouseMove(MouseEventArgs e) {
4650 MouseEventHandler eh = (MouseEventHandler)(Events [MouseMoveEvent]);
4651 if (eh != null)
4652 eh (this, e);
4655 [EditorBrowsable(EditorBrowsableState.Advanced)]
4656 protected virtual void OnMouseUp(MouseEventArgs e) {
4657 MouseEventHandler eh = (MouseEventHandler)(Events [MouseUpEvent]);
4658 if (eh != null)
4659 eh (this, e);
4662 [EditorBrowsable(EditorBrowsableState.Advanced)]
4663 protected virtual void OnMouseWheel(MouseEventArgs e) {
4664 MouseEventHandler eh = (MouseEventHandler)(Events [MouseWheelEvent]);
4665 if (eh != null)
4666 eh (this, e);
4669 [EditorBrowsable(EditorBrowsableState.Advanced)]
4670 protected virtual void OnMove(EventArgs e) {
4671 EventHandler eh = (EventHandler)(Events [MoveEvent]);
4672 if (eh != null)
4673 eh (this, e);
4676 [EditorBrowsable(EditorBrowsableState.Advanced)]
4677 protected virtual void OnNotifyMessage(Message m) {
4678 // Override me!
4681 [EditorBrowsable(EditorBrowsableState.Advanced)]
4682 protected virtual void OnPaint(PaintEventArgs e) {
4683 PaintEventHandler eh = (PaintEventHandler)(Events [PaintEvent]);
4684 if (eh != null)
4685 eh (this, e);
4688 internal virtual void OnPaintBackgroundInternal(PaintEventArgs e) {
4689 // Override me
4692 internal virtual void OnPaintInternal(PaintEventArgs e) {
4693 // Override me
4696 internal virtual void OnGotFocusInternal (EventArgs e)
4698 OnGotFocus (e);
4701 internal virtual void OnLostFocusInternal (EventArgs e)
4703 OnLostFocus (e);
4706 [EditorBrowsable(EditorBrowsableState.Advanced)]
4707 protected virtual void OnPaintBackground(PaintEventArgs pevent) {
4708 PaintControlBackground (pevent);
4711 [EditorBrowsable(EditorBrowsableState.Advanced)]
4712 protected virtual void OnParentBackColorChanged(EventArgs e) {
4713 if (background_color.IsEmpty && background_image==null) {
4714 Invalidate();
4715 OnBackColorChanged(e);
4719 [EditorBrowsable(EditorBrowsableState.Advanced)]
4720 protected virtual void OnParentBackgroundImageChanged(EventArgs e) {
4721 if (background_color.IsEmpty && background_image==null) {
4722 Invalidate();
4723 OnBackgroundImageChanged(e);
4727 [EditorBrowsable(EditorBrowsableState.Advanced)]
4728 protected virtual void OnParentBindingContextChanged(EventArgs e) {
4729 if (binding_context==null) {
4730 binding_context=Parent.binding_context;
4731 OnBindingContextChanged(e);
4735 [EditorBrowsable(EditorBrowsableState.Advanced)]
4736 protected virtual void OnParentChanged(EventArgs e) {
4737 EventHandler eh = (EventHandler)(Events [ParentChangedEvent]);
4738 if (eh != null)
4739 eh (this, e);
4742 [EditorBrowsable(EditorBrowsableState.Advanced)]
4743 protected virtual void OnParentEnabledChanged(EventArgs e) {
4744 if (is_enabled) {
4745 OnEnabledChanged(e);
4749 [EditorBrowsable(EditorBrowsableState.Advanced)]
4750 protected virtual void OnParentFontChanged(EventArgs e) {
4751 if (font==null) {
4752 Invalidate();
4753 OnFontChanged(e);
4757 [EditorBrowsable(EditorBrowsableState.Advanced)]
4758 protected virtual void OnParentForeColorChanged(EventArgs e) {
4759 if (foreground_color.IsEmpty) {
4760 Invalidate();
4761 OnForeColorChanged(e);
4765 [EditorBrowsable(EditorBrowsableState.Advanced)]
4766 protected virtual void OnParentRightToLeftChanged(EventArgs e) {
4767 if (right_to_left==RightToLeft.Inherit) {
4768 Invalidate();
4769 OnRightToLeftChanged(e);
4773 [EditorBrowsable(EditorBrowsableState.Advanced)]
4774 protected virtual void OnParentVisibleChanged(EventArgs e) {
4775 if (is_visible) {
4776 OnVisibleChanged(e);
4780 [EditorBrowsable(EditorBrowsableState.Advanced)]
4781 protected virtual void OnQueryContinueDrag(QueryContinueDragEventArgs e) {
4782 QueryContinueDragEventHandler eh = (QueryContinueDragEventHandler)(Events [QueryContinueDragEvent]);
4783 if (eh != null)
4784 eh (this, e);
4787 [EditorBrowsable(EditorBrowsableState.Advanced)]
4788 protected virtual void OnResize(EventArgs e) {
4789 EventHandler eh = (EventHandler)(Events [ResizeEvent]);
4790 if (eh != null)
4791 eh (this, e);
4793 PerformLayout(this, "bounds");
4795 if (parent != null) {
4796 parent.PerformLayout();
4800 [EditorBrowsable(EditorBrowsableState.Advanced)]
4801 protected virtual void OnRightToLeftChanged(EventArgs e) {
4802 EventHandler eh = (EventHandler)(Events [RightToLeftChangedEvent]);
4803 if (eh != null)
4804 eh (this, e);
4805 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentRightToLeftChanged(e);
4808 [EditorBrowsable(EditorBrowsableState.Advanced)]
4809 protected virtual void OnSizeChanged(EventArgs e) {
4810 DisposeBackBuffer ();
4811 OnResize(e);
4812 EventHandler eh = (EventHandler)(Events [SizeChangedEvent]);
4813 if (eh != null)
4814 eh (this, e);
4817 [EditorBrowsable(EditorBrowsableState.Advanced)]
4818 protected virtual void OnStyleChanged(EventArgs e) {
4819 EventHandler eh = (EventHandler)(Events [StyleChangedEvent]);
4820 if (eh != null)
4821 eh (this, e);
4824 [EditorBrowsable(EditorBrowsableState.Advanced)]
4825 protected virtual void OnSystemColorsChanged(EventArgs e) {
4826 EventHandler eh = (EventHandler)(Events [SystemColorsChangedEvent]);
4827 if (eh != null)
4828 eh (this, e);
4831 [EditorBrowsable(EditorBrowsableState.Advanced)]
4832 protected virtual void OnTabIndexChanged(EventArgs e) {
4833 EventHandler eh = (EventHandler)(Events [TabIndexChangedEvent]);
4834 if (eh != null)
4835 eh (this, e);
4838 [EditorBrowsable(EditorBrowsableState.Advanced)]
4839 protected virtual void OnTabStopChanged(EventArgs e) {
4840 EventHandler eh = (EventHandler)(Events [TabStopChangedEvent]);
4841 if (eh != null)
4842 eh (this, e);
4845 [EditorBrowsable(EditorBrowsableState.Advanced)]
4846 protected virtual void OnTextChanged(EventArgs e) {
4847 EventHandler eh = (EventHandler)(Events [TextChangedEvent]);
4848 if (eh != null)
4849 eh (this, e);
4852 [EditorBrowsable(EditorBrowsableState.Advanced)]
4853 protected virtual void OnValidated(EventArgs e) {
4854 EventHandler eh = (EventHandler)(Events [ValidatedEvent]);
4855 if (eh != null)
4856 eh (this, e);
4859 [EditorBrowsable(EditorBrowsableState.Advanced)]
4860 protected virtual void OnValidating(System.ComponentModel.CancelEventArgs e) {
4861 CancelEventHandler eh = (CancelEventHandler)(Events [ValidatingEvent]);
4862 if (eh != null)
4863 eh (this, e);
4866 [EditorBrowsable(EditorBrowsableState.Advanced)]
4867 protected virtual void OnVisibleChanged(EventArgs e) {
4868 if ((parent != null) && !Created && Visible) {
4869 if (!is_disposed) {
4870 CreateControl();
4871 PerformLayout();
4875 EventHandler eh = (EventHandler)(Events [VisibleChangedEvent]);
4876 if (eh != null)
4877 eh (this, e);
4879 // We need to tell our kids
4880 for (int i=0; i<child_controls.Count; i++) {
4881 if (child_controls[i].Visible) {
4882 child_controls[i].OnParentVisibleChanged(e);
4886 #endregion // OnXXX methods
4888 #region Events
4889 static object BackColorChangedEvent = new object ();
4890 static object BackgroundImageChangedEvent = new object ();
4891 static object BindingContextChangedEvent = new object ();
4892 static object CausesValidationChangedEvent = new object ();
4893 static object ChangeUICuesEvent = new object ();
4894 static object ClickEvent = new object ();
4895 static object ContextMenuChangedEvent = new object ();
4896 static object ControlAddedEvent = new object ();
4897 static object ControlRemovedEvent = new object ();
4898 static object CursorChangedEvent = new object ();
4899 static object DockChangedEvent = new object ();
4900 static object DoubleClickEvent = new object ();
4901 static object DragDropEvent = new object ();
4902 static object DragEnterEvent = new object ();
4903 static object DragLeaveEvent = new object ();
4904 static object DragOverEvent = new object ();
4905 static object EnabledChangedEvent = new object ();
4906 static object EnterEvent = new object ();
4907 static object FontChangedEvent = new object ();
4908 static object ForeColorChangedEvent = new object ();
4909 static object GiveFeedbackEvent = new object ();
4910 static object GotFocusEvent = new object ();
4911 static object HandleCreatedEvent = new object ();
4912 static object HandleDestroyedEvent = new object ();
4913 static object HelpRequestedEvent = new object ();
4914 static object ImeModeChangedEvent = new object ();
4915 static object InvalidatedEvent = new object ();
4916 static object KeyDownEvent = new object ();
4917 static object KeyPressEvent = new object ();
4918 static object KeyUpEvent = new object ();
4919 static object LayoutEvent = new object ();
4920 static object LeaveEvent = new object ();
4921 static object LocationChangedEvent = new object ();
4922 static object LostFocusEvent = new object ();
4923 static object MouseDownEvent = new object ();
4924 static object MouseEnterEvent = new object ();
4925 static object MouseHoverEvent = new object ();
4926 static object MouseLeaveEvent = new object ();
4927 static object MouseMoveEvent = new object ();
4928 static object MouseUpEvent = new object ();
4929 static object MouseWheelEvent = new object ();
4930 static object MoveEvent = new object ();
4931 static object PaintEvent = new object ();
4932 static object ParentChangedEvent = new object ();
4933 static object QueryAccessibilityHelpEvent = new object ();
4934 static object QueryContinueDragEvent = new object ();
4935 static object ResizeEvent = new object ();
4936 static object RightToLeftChangedEvent = new object ();
4937 static object SizeChangedEvent = new object ();
4938 static object StyleChangedEvent = new object ();
4939 static object SystemColorsChangedEvent = new object ();
4940 static object TabIndexChangedEvent = new object ();
4941 static object TabStopChangedEvent = new object ();
4942 static object TextChangedEvent = new object ();
4943 static object ValidatedEvent = new object ();
4944 static object ValidatingEvent = new object ();
4945 static object VisibleChangedEvent = new object ();
4947 public event EventHandler BackColorChanged {
4948 add { Events.AddHandler (BackColorChangedEvent, value); }
4949 remove { Events.RemoveHandler (BackColorChangedEvent, value); }
4952 public event EventHandler BackgroundImageChanged {
4953 add { Events.AddHandler (BackgroundImageChangedEvent, value); }
4954 remove { Events.RemoveHandler (BackgroundImageChangedEvent, value); }
4957 public event EventHandler BindingContextChanged {
4958 add { Events.AddHandler (BindingContextChangedEvent, value); }
4959 remove { Events.RemoveHandler (BindingContextChangedEvent, value); }
4962 public event EventHandler CausesValidationChanged {
4963 add { Events.AddHandler (CausesValidationChangedEvent, value); }
4964 remove { Events.RemoveHandler (CausesValidationChangedEvent, value); }
4967 public event UICuesEventHandler ChangeUICues {
4968 add { Events.AddHandler (ChangeUICuesEvent, value); }
4969 remove { Events.RemoveHandler (ChangeUICuesEvent, value); }
4972 public event EventHandler Click {
4973 add { Events.AddHandler (ClickEvent, value); }
4974 remove { Events.RemoveHandler (ClickEvent, value); }
4977 public event EventHandler ContextMenuChanged {
4978 add { Events.AddHandler (ContextMenuChangedEvent, value); }
4979 remove { Events.RemoveHandler (ContextMenuChangedEvent, value); }
4982 [EditorBrowsable(EditorBrowsableState.Advanced)]
4983 [Browsable(false)]
4984 public event ControlEventHandler ControlAdded {
4985 add { Events.AddHandler (ControlAddedEvent, value); }
4986 remove { Events.RemoveHandler (ControlAddedEvent, value); }
4989 [EditorBrowsable(EditorBrowsableState.Advanced)]
4990 [Browsable(false)]
4991 public event ControlEventHandler ControlRemoved {
4992 add { Events.AddHandler (ControlRemovedEvent, value); }
4993 remove { Events.RemoveHandler (ControlRemovedEvent, value); }
4996 [MWFDescription("Fired when the cursor for the control has been changed"), MWFCategory("PropertyChanged")]
4997 public event EventHandler CursorChanged {
4998 add { Events.AddHandler (CursorChangedEvent, value); }
4999 remove { Events.RemoveHandler (CursorChangedEvent, value); }
5001 public event EventHandler DockChanged {
5002 add { Events.AddHandler (DockChangedEvent, value); }
5003 remove { Events.RemoveHandler (DockChangedEvent, value); }
5006 public event EventHandler DoubleClick {
5007 add { Events.AddHandler (DoubleClickEvent, value); }
5008 remove { Events.RemoveHandler (DoubleClickEvent, value); }
5011 public event DragEventHandler DragDrop {
5012 add { Events.AddHandler (DragDropEvent, value); }
5013 remove { Events.RemoveHandler (DragDropEvent, value); }
5016 public event DragEventHandler DragEnter {
5017 add { Events.AddHandler (DragEnterEvent, value); }
5018 remove { Events.RemoveHandler (DragEnterEvent, value); }
5021 public event EventHandler DragLeave {
5022 add { Events.AddHandler (DragLeaveEvent, value); }
5023 remove { Events.RemoveHandler (DragLeaveEvent, value); }
5026 public event DragEventHandler DragOver {
5027 add { Events.AddHandler (DragOverEvent, value); }
5028 remove { Events.RemoveHandler (DragOverEvent, value); }
5031 public event EventHandler EnabledChanged {
5032 add { Events.AddHandler (EnabledChangedEvent, value); }
5033 remove { Events.RemoveHandler (EnabledChangedEvent, value); }
5036 public event EventHandler Enter {
5037 add { Events.AddHandler (EnterEvent, value); }
5038 remove { Events.RemoveHandler (EnterEvent, value); }
5041 public event EventHandler FontChanged {
5042 add { Events.AddHandler (FontChangedEvent, value); }
5043 remove { Events.RemoveHandler (FontChangedEvent, value); }
5046 public event EventHandler ForeColorChanged {
5047 add { Events.AddHandler (ForeColorChangedEvent, value); }
5048 remove { Events.RemoveHandler (ForeColorChangedEvent, value); }
5051 public event GiveFeedbackEventHandler GiveFeedback {
5052 add { Events.AddHandler (GiveFeedbackEvent, value); }
5053 remove { Events.RemoveHandler (GiveFeedbackEvent, value); }
5056 [EditorBrowsable(EditorBrowsableState.Advanced)]
5057 [Browsable(false)]
5058 public event EventHandler GotFocus {
5059 add { Events.AddHandler (GotFocusEvent, value); }
5060 remove { Events.RemoveHandler (GotFocusEvent, value); }
5064 [EditorBrowsable(EditorBrowsableState.Advanced)]
5065 [Browsable(false)]
5066 public event EventHandler HandleCreated {
5067 add { Events.AddHandler (HandleCreatedEvent, value); }
5068 remove { Events.RemoveHandler (HandleCreatedEvent, value); }
5071 [EditorBrowsable(EditorBrowsableState.Advanced)]
5072 [Browsable(false)]
5073 public event EventHandler HandleDestroyed {
5074 add { Events.AddHandler (HandleDestroyedEvent, value); }
5075 remove { Events.RemoveHandler (HandleDestroyedEvent, value); }
5078 public event HelpEventHandler HelpRequested {
5079 add { Events.AddHandler (HelpRequestedEvent, value); }
5080 remove { Events.RemoveHandler (HelpRequestedEvent, value); }
5083 public event EventHandler ImeModeChanged {
5084 add { Events.AddHandler (ImeModeChangedEvent, value); }
5085 remove { Events.RemoveHandler (ImeModeChangedEvent, value); }
5088 [EditorBrowsable(EditorBrowsableState.Advanced)]
5089 [Browsable(false)]
5090 public event InvalidateEventHandler Invalidated {
5091 add { Events.AddHandler (InvalidatedEvent, value); }
5092 remove { Events.RemoveHandler (InvalidatedEvent, value); }
5095 public event KeyEventHandler KeyDown {
5096 add { Events.AddHandler (KeyDownEvent, value); }
5097 remove { Events.RemoveHandler (KeyDownEvent, value); }
5100 public event KeyPressEventHandler KeyPress {
5101 add { Events.AddHandler (KeyPressEvent, value); }
5102 remove { Events.RemoveHandler (KeyPressEvent, value); }
5105 public event KeyEventHandler KeyUp {
5106 add { Events.AddHandler (KeyUpEvent, value); }
5107 remove { Events.RemoveHandler (KeyUpEvent, value); }
5110 public event LayoutEventHandler Layout {
5111 add { Events.AddHandler (LayoutEvent, value); }
5112 remove { Events.RemoveHandler (LayoutEvent, value); }
5115 public event EventHandler Leave {
5116 add { Events.AddHandler (LeaveEvent, value); }
5117 remove { Events.RemoveHandler (LeaveEvent, value); }
5120 public event EventHandler LocationChanged {
5121 add { Events.AddHandler (LocationChangedEvent, value); }
5122 remove { Events.RemoveHandler (LocationChangedEvent, value); }
5125 [EditorBrowsable(EditorBrowsableState.Advanced)]
5126 [Browsable(false)]
5127 public event EventHandler LostFocus {
5128 add { Events.AddHandler (LostFocusEvent, value); }
5129 remove { Events.RemoveHandler (LostFocusEvent, value); }
5132 public event MouseEventHandler MouseDown {
5133 add { Events.AddHandler (MouseDownEvent, value); }
5134 remove { Events.RemoveHandler (MouseDownEvent, value); }
5137 public event EventHandler MouseEnter {
5138 add { Events.AddHandler (MouseEnterEvent, value); }
5139 remove { Events.RemoveHandler (MouseEnterEvent, value); }
5142 public event EventHandler MouseHover {
5143 add { Events.AddHandler (MouseHoverEvent, value); }
5144 remove { Events.RemoveHandler (MouseHoverEvent, value); }
5147 public event EventHandler MouseLeave {
5148 add { Events.AddHandler (MouseLeaveEvent, value); }
5149 remove { Events.RemoveHandler (MouseLeaveEvent, value); }
5152 public event MouseEventHandler MouseMove {
5153 add { Events.AddHandler (MouseMoveEvent, value); }
5154 remove { Events.RemoveHandler (MouseMoveEvent, value); }
5157 public event MouseEventHandler MouseUp {
5158 add { Events.AddHandler (MouseUpEvent, value); }
5159 remove { Events.RemoveHandler (MouseUpEvent, value); }
5162 [EditorBrowsable(EditorBrowsableState.Advanced)]
5163 [Browsable(false)]
5164 public event MouseEventHandler MouseWheel {
5165 add { Events.AddHandler (MouseWheelEvent, value); }
5166 remove { Events.RemoveHandler (MouseWheelEvent, value); }
5169 public event EventHandler Move {
5170 add { Events.AddHandler (MoveEvent, value); }
5171 remove { Events.RemoveHandler (MoveEvent, value); }
5174 public event PaintEventHandler Paint {
5175 add { Events.AddHandler (PaintEvent, value); }
5176 remove { Events.RemoveHandler (PaintEvent, value); }
5179 public event EventHandler ParentChanged {
5180 add { Events.AddHandler (ParentChangedEvent, value); }
5181 remove { Events.RemoveHandler (ParentChangedEvent, value); }
5184 public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp {
5185 add { Events.AddHandler (QueryAccessibilityHelpEvent, value); }
5186 remove { Events.RemoveHandler (QueryAccessibilityHelpEvent, value); }
5189 public event QueryContinueDragEventHandler QueryContinueDrag {
5190 add { Events.AddHandler (QueryContinueDragEvent, value); }
5191 remove { Events.RemoveHandler (QueryContinueDragEvent, value); }
5194 public event EventHandler Resize {
5195 add { Events.AddHandler (ResizeEvent, value); }
5196 remove { Events.RemoveHandler (ResizeEvent, value); }
5199 public event EventHandler RightToLeftChanged {
5200 add { Events.AddHandler (RightToLeftChangedEvent, value); }
5201 remove { Events.RemoveHandler (RightToLeftChangedEvent, value); }
5204 public event EventHandler SizeChanged {
5205 add { Events.AddHandler (SizeChangedEvent, value); }
5206 remove { Events.RemoveHandler (SizeChangedEvent, value); }
5209 public event EventHandler StyleChanged {
5210 add { Events.AddHandler (StyleChangedEvent, value); }
5211 remove { Events.RemoveHandler (StyleChangedEvent, value); }
5214 public event EventHandler SystemColorsChanged {
5215 add { Events.AddHandler (SystemColorsChangedEvent, value); }
5216 remove { Events.RemoveHandler (SystemColorsChangedEvent, value); }
5219 public event EventHandler TabIndexChanged {
5220 add { Events.AddHandler (TabIndexChangedEvent, value); }
5221 remove { Events.RemoveHandler (TabIndexChangedEvent, value); }
5224 public event EventHandler TabStopChanged {
5225 add { Events.AddHandler (TabStopChangedEvent, value); }
5226 remove { Events.RemoveHandler (TabStopChangedEvent, value); }
5229 public event EventHandler TextChanged {
5230 add { Events.AddHandler (TextChangedEvent, value); }
5231 remove { Events.RemoveHandler (TextChangedEvent, value); }
5234 public event EventHandler Validated {
5235 add { Events.AddHandler (ValidatedEvent, value); }
5236 remove { Events.RemoveHandler (ValidatedEvent, value); }
5239 public event CancelEventHandler Validating {
5240 add { Events.AddHandler (ValidatingEvent, value); }
5241 remove { Events.RemoveHandler (ValidatingEvent, value); }
5244 public event EventHandler VisibleChanged {
5245 add { Events.AddHandler (VisibleChangedEvent, value); }
5246 remove { Events.RemoveHandler (VisibleChangedEvent, value); }
5249 #endregion // Events