1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 // Copyright (c) 2004-2005 Novell, Inc.
23 // Peter Bartok pbartok@novell.com
25 // Partially based on work by:
26 // Aleksey Ryabchuk ryabchuk@yahoo.com
27 // Alexandre Pigolkine pigolkine@gmx.de
28 // Dennis Hayes dennish@raytek.com
29 // Jaak Simm jaaksimm@firm.ee
30 // John Sohn jsohn@columbus.rr.com
36 using System.ComponentModel;
37 using System.ComponentModel.Design;
38 using System.ComponentModel.Design.Serialization;
39 using System.Collections;
40 using System.Diagnostics;
42 using System.Reflection;
43 using System.Runtime.InteropServices;
44 using System.Security;
45 using System.Threading;
48 namespace System.Windows.Forms
50 [Designer("System.Windows.Forms.Design.ControlDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
51 [DefaultProperty("Text")]
52 [DefaultEvent("Click")]
53 [DesignerSerializer("System.Windows.Forms.Design.ControlCodeDomSerializer, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
54 [ToolboxItemFilter("System.Windows.Forms")]
55 public class Control : Component, ISynchronizeInvoke, IWin32Window
57 #region Local Variables
60 internal Rectangle bounds; // bounding rectangle for control (client area + decorations)
61 internal object creator_thread; // thread that created the control
62 internal ControlNativeWindow window; // object for native window handle
63 internal string name; // for object naming
66 internal bool is_created; // true if OnCreateControl has been sent
67 internal bool has_focus; // true if control has focus
68 internal bool is_visible; // true if control is visible
69 internal bool is_entered; // is the mouse inside the control?
70 internal bool is_enabled; // true if control is enabled (usable/not grayed out)
71 internal bool is_selected; // true if control is selected
72 internal bool is_accessible; // true if the control is visible to accessibility applications
73 internal bool is_captured; // tracks if the control has captured the mouse
74 internal bool is_toplevel; // tracks if the control is a toplevel window
75 internal bool is_recreating; // tracks if the handle for the control is being recreated
76 internal bool causes_validation; // tracks if validation is executed on changes
77 internal int tab_index; // position in tab order of siblings
78 internal bool tab_stop = true; // is the control a tab stop?
79 internal bool is_disposed; // has the window already been disposed?
80 internal Size client_size; // size of the client area (window excluding decorations)
81 internal Rectangle client_rect; // rectangle with the client area (window excluding decorations)
82 internal ControlStyles control_style; // rather win32-specific, style bits for control
83 internal ImeMode ime_mode = ImeMode.Inherit;
84 internal bool layout_pending; // true if our parent needs to re-layout us
85 internal object control_tag; // object that contains data about our control
86 internal int mouse_clicks; // Counter for mouse clicks
87 internal Cursor cursor; // Cursor for the window
88 internal bool allow_drop; // true if the control accepts droping objects on it
91 internal Color foreground_color; // foreground color for control
92 internal Color background_color; // background color for control
93 internal Image background_image; // background image for control
94 internal Font font; // font for control
95 internal string text; // window/title text for control
96 internal BorderStyle border_style; // Border style of control
99 internal AnchorStyles anchor_style; // anchoring requirements for our control
100 internal DockStyle dock_style; // docking requirements for our control (supercedes anchoring)
101 internal int dist_left; // distance to the left border of the parent
102 internal int dist_top; // distance to the top border of the parent
103 internal int dist_right; // distance to the right border of the parent
104 internal int dist_bottom; // distance to the bottom border of the parent
106 // to be categorized...
107 static internal ArrayList controls = new ArrayList(); // All of the application's controls, in a flat list
108 internal ControlCollection child_controls; // our children
109 internal Control parent; // our parent control
110 internal AccessibleObject accessibility_object; // object that contains accessibility information about our control
111 internal BindingContext binding_context; // TODO
112 internal RightToLeft right_to_left; // drawing direction for control
113 internal int layout_suspended;
114 internal ContextMenu context_menu; // Context menu associated with the control
116 private Graphics dc_mem; // Graphics context for double buffering
117 private Bitmap bmp_mem; // Bitmap for double buffering control
118 private bool needs_redraw = true;
120 private ControlBindingsCollection data_bindings;
122 #endregion // Local Variables
124 #region Private Classes
125 // This helper class allows us to dispatch messages to Control.WndProc
126 internal class ControlNativeWindow : NativeWindow {
127 private Control owner;
129 public ControlNativeWindow(Control control) : base() {
134 public Control Owner {
140 static internal Control ControlFromHandle(IntPtr hWnd) {
141 ControlNativeWindow window;
143 window = (ControlNativeWindow)window_collection[hWnd];
144 if (window != null) {
151 protected override void WndProc(ref Message m) {
152 owner.WndProc(ref m);
157 #region Public Classes
159 public class ControlAccessibleObject : AccessibleObject {
160 #region ControlAccessibleObject Local Variables
161 private Control owner;
162 #endregion // ControlAccessibleObject Local Variables
164 #region ControlAccessibleObject Constructors
165 public ControlAccessibleObject(Control ownerControl) {
166 this.owner = ownerControl;
168 #endregion // ControlAccessibleObject Constructors
170 #region ControlAccessibleObject Public Instance Properties
171 public override string DefaultAction {
173 return base.DefaultAction;
177 public override string Description {
179 return base.Description;
183 public IntPtr Handle {
189 // We don't want to let them set it
193 public override string Help {
199 public override string KeyboardShortcut {
201 return base.KeyboardShortcut;
205 public override string Name {
215 public Control Owner {
221 public override AccessibleObject Parent {
228 public override AccessibleRole Role {
233 #endregion // ControlAccessibleObject Public Instance Properties
235 #region ControlAccessibleObject Public Instance Methods
236 public override int GetHelpTopic(out string FileName) {
237 return base.GetHelpTopic (out FileName);
240 [MonoTODO("Implement this and tie it into Control.AccessibilityNotifyClients")]
241 public void NotifyClients(AccessibleEvents accEvent) {
242 throw new NotImplementedException();
245 [MonoTODO("Implement this and tie it into Control.AccessibilityNotifyClients")]
246 public void NotifyClients(AccessibleEvents accEvent, int childID) {
247 throw new NotImplementedException();
250 public override string ToString() {
251 return "ControlAccessibleObject: Owner = " + owner.ToString() + ", Text: " + owner.text;
254 #endregion // ControlAccessibleObject Public Instance Methods
257 [DesignerSerializer("System.Windows.Forms.Design.ControlCollectionCodeDomSerializer, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
258 [ListBindable(false)]
259 public class ControlCollection : IList, ICollection, ICloneable, IEnumerable {
260 #region ControlCollection Local Variables
261 private ArrayList list;
262 private ArrayList impl_list;
263 private Control [] all_controls;
264 internal Control owner;
265 #endregion // ControlCollection Local Variables
267 #region ControlCollection Public Constructor
268 public ControlCollection(Control owner) {
270 this.list=new ArrayList();
274 #region ControlCollection Public Instance Properties
281 public virtual bool IsReadOnly {
283 return list.IsReadOnly;
287 public virtual Control this[int index] {
289 if (index < 0 || index >= list.Count) {
290 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
292 return (Control)list[index];
295 #endregion // ControlCollection Public Instance Properties
297 #region ControlCollection Private Instance Methods
298 public virtual void Add (Control value)
303 if (Contains (value)) {
304 owner.PerformLayout();
308 if (value.tab_index == -1) {
314 end = owner.child_controls.Count;
315 for (int i = 0; i < end; i++) {
316 index = owner.child_controls[i].tab_index;
321 value.tab_index = use;
324 if (value.parent != null) {
325 value.parent.Controls.Remove(value);
331 value.ChangeParent(owner);
335 owner.UpdateZOrder();
336 owner.PerformLayout(value, "Parent");
337 owner.OnControlAdded(new ControlEventArgs(value));
340 internal void AddToList (Control c)
346 internal virtual void AddImplicit (Control control)
348 if (impl_list == null)
349 impl_list = new ArrayList ();
351 impl_list.Add (control);
352 control.ChangeParent (owner);
353 owner.UpdateZOrder ();
354 owner.PerformLayout (control, "Parent");
355 owner.OnControlAdded (new ControlEventArgs (control));
358 public virtual void AddRange (Control[] controls)
360 if (controls == null)
361 throw new ArgumentNullException ("controls");
363 owner.SuspendLayout ();
366 for (int i = 0; i < controls.Length; i++)
369 owner.ResumeLayout ();
373 internal virtual void AddRangeImplicit (Control [] controls)
375 if (controls == null)
376 throw new ArgumentNullException ("controls");
378 owner.SuspendLayout ();
381 for (int i = 0; i < controls.Length; i++)
382 AddImplicit (controls [i]);
384 owner.ResumeLayout ();
388 public virtual void Clear ()
392 // MS sends remove events in reverse order
393 while (list.Count > 0) {
394 RemoveAt(list.Count - 1);
398 internal virtual void ClearImplicit ()
400 if (impl_list == null)
406 public bool Contains (Control value)
408 for (int i = list.Count; i > 0; ) {
411 if (list [i] == value) {
412 // Do we need to do anything here?
419 internal bool ImplicitContains (Control value)
421 if (impl_list == null)
424 for (int i = impl_list.Count; i > 0; ) {
427 if (impl_list [i] == value) {
428 // Do we need to do anything here?
435 internal bool AllContains (Control value)
437 return Contains (value) || ImplicitContains (value);
440 public virtual void CopyTo (Array array, int index)
442 list.CopyTo(array, index);
445 public override bool Equals(object other) {
446 if (other is ControlCollection && (((ControlCollection)other).owner==this.owner)) {
453 public int GetChildIndex(Control child) {
454 return GetChildIndex(child, false);
457 public int GetChildIndex(Control child, bool throwException) {
460 index=list.IndexOf(child);
462 if (index==-1 && throwException) {
463 throw new ArgumentException("Not a child control", "child");
468 public IEnumerator GetEnumerator() {
469 return list.GetEnumerator();
472 internal IEnumerator GetAllEnumerator ()
474 Control [] res = GetAllControls ();
475 return res.GetEnumerator ();
478 internal Control [] GetAllControls ()
480 if (all_controls != null)
483 if (impl_list == null)
484 return (Control []) list.ToArray (typeof (Control));
485 Control [] res = new Control [list.Count + impl_list.Count];
487 impl_list.CopyTo (res, list.Count);
491 public override int GetHashCode() {
492 return base.GetHashCode();
495 public int IndexOf(Control control) {
496 return list.IndexOf(control);
499 public virtual void Remove(Control value) {
502 owner.PerformLayout(value, "Parent");
503 owner.OnControlRemoved(new ControlEventArgs(value));
506 value.ChangeParent(null);
508 owner.UpdateZOrder();
511 internal virtual void RemoveImplicit (Control control)
513 if (impl_list != null) {
515 owner.PerformLayout (control, "Parent");
516 owner.OnControlRemoved (new ControlEventArgs (control));
517 impl_list.Remove (control);
519 control.ChangeParent (null);
520 owner.UpdateZOrder ();
523 public void RemoveAt(int index) {
524 if (index < 0 || index >= list.Count) {
525 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
527 Remove ((Control)list[index]);
530 public void SetChildIndex(Control child, int newIndex) {
533 old_index=list.IndexOf(child);
535 throw new ArgumentException("Not a child control", "child");
538 if (old_index==newIndex) {
544 if (newIndex>list.Count) {
547 list.Insert(newIndex, child);
549 child.parent = owner;
550 owner.UpdateZOrder();
552 #endregion // ControlCollection Private Instance Methods
554 #region ControlCollection Interface Properties
555 object IList.this[int index] {
557 if (index<0 || index>=list.Count) {
558 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
564 if (!(value is Control)) {
565 throw new ArgumentException("Object of type Control required", "value");
568 list[index]=(Control)value;
572 bool IList.IsFixedSize {
578 bool IList.IsReadOnly {
580 return list.IsReadOnly;
584 bool ICollection.IsSynchronized {
586 return list.IsSynchronized;
590 object ICollection.SyncRoot {
592 return list.SyncRoot;
595 #endregion // ControlCollection Interface Properties
597 #region ControlCollection Interface Methods
598 int IList.Add(object value) {
600 throw new ArgumentNullException("value", "Cannot add null controls");
603 if (!(value is Control)) {
604 throw new ArgumentException("Object of type Control required", "value");
607 return list.Add(value);
610 bool IList.Contains(object value) {
611 if (!(value is Control)) {
612 throw new ArgumentException("Object of type Control required", "value");
615 return this.Contains((Control) value);
618 int IList.IndexOf(object value) {
619 if (!(value is Control)) {
620 throw new ArgumentException("Object of type Control required", "value");
623 return this.IndexOf((Control) value);
626 void IList.Insert(int index, object value) {
627 if (!(value is Control)) {
628 throw new ArgumentException("Object of type Control required", "value");
631 list.Insert(index, value);
634 void IList.Remove(object value) {
635 if (!(value is Control)) {
636 throw new ArgumentException("Object of type Control required", "value");
642 void ICollection.CopyTo(Array array, int index) {
644 list.CopyTo(array, index);
648 Object ICloneable.Clone() {
649 ControlCollection clone = new ControlCollection(this.owner);
650 clone.list=(ArrayList)list.Clone(); // FIXME: Do we need this?
653 #endregion // ControlCollection Interface Methods
655 #endregion // ControlCollection Class
657 #region Public Constructors
659 creator_thread = Thread.CurrentThread;
661 anchor_style = AnchorStyles.Top | AnchorStyles.Left;
669 layout_pending = false;
671 causes_validation = true;
673 layout_suspended = 0;
677 right_to_left = RightToLeft.Inherit;
678 border_style = BorderStyle.None;
679 background_color = Color.Empty;
685 control_style = ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint |
686 ControlStyles.Selectable | ControlStyles.StandardClick |
687 ControlStyles.StandardDoubleClick;
690 background_image = null;
694 window = new ControlNativeWindow(this);
695 child_controls = CreateControlsInstance();
696 client_size = new Size(DefaultSize.Width, DefaultSize.Height);
697 client_rect = new Rectangle(0, 0, DefaultSize.Width, DefaultSize.Height);
698 XplatUI.CalculateWindowRect(IntPtr.Zero, ref client_rect, CreateParams.Style, CreateParams.ExStyle, null, out bounds);
699 if ((CreateParams.Style & (int)WindowStyles.WS_CHILD) == 0) {
705 public Control(Control parent, string text) : this() {
710 public Control(Control parent, string text, int left, int top, int width, int height) : this() {
715 bounds.Height=height;
716 SetBoundsCore(left, top, width, height, BoundsSpecified.All);
720 public Control(string text) : this() {
724 public Control(string text, int left, int top, int width, int height) : this() {
728 bounds.Height=height;
729 SetBoundsCore(left, top, width, height, BoundsSpecified.All);
733 private delegate void RemoveDelegate(object c);
735 protected override void Dispose(bool disposing) {
747 if (this.InvokeRequired) {
748 this.InvokeInternal(new MethodInvoker(DestroyHandle), true);
749 this.InvokeInternal(new RemoveDelegate(controls.Remove), new object[] {this}, true);
752 controls.Remove(this);
755 #endregion // Public Constructors
757 #region Internal Properties
758 internal BorderStyle InternalBorderStyle {
764 if (!Enum.IsDefined (typeof (BorderStyle), value))
765 throw new InvalidEnumArgumentException (string.Format("Enum argument value '{0}' is not valid for BorderStyle", value));
767 if (border_style != value) {
768 border_style = value;
770 if (IsHandleCreated) {
771 XplatUI.SetBorderStyle(window.Handle, (FormBorderStyle)border_style);
777 #endregion // Internal Properties
779 #region Private & Internal Methods
780 internal IAsyncResult BeginInvokeInternal (Delegate method, object [] args, bool disposing) {
781 AsyncMethodResult result;
782 AsyncMethodData data;
789 if (!p.IsHandleCreated) {
790 throw new InvalidOperationException("Cannot call Invoke or InvokeAsync on a control until the window handle is created");
796 result = new AsyncMethodResult ();
797 data = new AsyncMethodData ();
799 data.Method = method;
801 data.Result = new WeakReference (result);
804 if (!ExecutionContext.IsFlowSuppressed ()) {
805 data.Context = ExecutionContext.Capture ();
808 #if !MWF_ON_MSRUNTIME
809 if (SecurityManager.SecurityEnabled) {
810 data.Stack = CompressedStack.GetCompressedStack ();
815 XplatUI.SendAsyncMethod (data);
820 internal void PointToClient (ref int x, ref int y)
822 XplatUI.ScreenToClient (Handle, ref x, ref y);
825 internal void PointToScreen (ref int x, ref int y)
827 XplatUI.ClientToScreen (Handle, ref x, ref y);
830 internal Graphics DeviceContext {
833 CreateBuffers(this.Width, this.Height);
839 private Bitmap ImageBuffer {
842 CreateBuffers(this.Width, this.Height);
848 internal void CreateBuffers (int width, int height) {
849 if (dc_mem != null) {
863 bmp_mem = new Bitmap (width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
864 dc_mem = Graphics.FromImage (bmp_mem);
868 internal void InvalidateBuffers ()
870 if (dc_mem != null) {
881 internal static void SetChildColor(Control parent) {
884 for (int i=0; i < parent.child_controls.Count; i++) {
885 child=parent.child_controls[i];
886 if (child.child_controls.Count>0) {
887 SetChildColor(child);
893 internal bool Select(Control control) {
895 IContainerControl container;
897 if (control == null) {
901 parent = control.parent;
903 if (((control.control_style & ControlStyles.Selectable) !=0) && (parent != null)) {
904 while (parent != null) {
905 if (!parent.Visible || !parent.is_enabled) {
908 parent = parent.parent;
912 control.is_selected = true;
914 container = GetContainerControl();
915 if (container != null) {
916 container.ActiveControl = control;
918 if (control.IsHandleCreated) {
919 XplatUI.SetFocus(control.window.Handle);
924 internal virtual void DoDefaultAction() {
925 // Only here to be overriden by our actual controls; this is needed by the accessibility class
928 internal static int LowOrder (int param) {
929 return ((int)(short)(param & 0xffff));
932 internal static int HighOrder (int param) {
933 return ((int)(short)(param >> 16));
936 // This method exists so controls overriding OnPaintBackground can have default background painting done
937 internal virtual void PaintControlBackground (PaintEventArgs pevent)
939 if (background_image == null) {
940 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));
944 DrawBackgroundImage (pevent.Graphics);
947 void DrawBackgroundImage (Graphics g)
949 using (TextureBrush b = new TextureBrush (background_image)) {
950 g.FillRectangle (b, ClientRectangle);
954 internal virtual void DndEnter (DragEventArgs e)
961 internal virtual void DndOver (DragEventArgs e)
968 internal virtual void DndDrop (DragEventArgs e)
972 } catch (Exception exc) {
973 Console.Error.WriteLine ("MWF: Exception while dropping:");
974 Console.Error.WriteLine (exc);
978 internal virtual void DndLeave (EventArgs e)
985 internal virtual void DndFeedback(GiveFeedbackEventArgs e)
992 internal virtual void DndContinueDrag(QueryContinueDragEventArgs e)
995 OnQueryContinueDrag(e);
999 internal static MouseButtons FromParamToMouseButtons (int param) {
1000 MouseButtons buttons = MouseButtons.None;
1002 if ((param & (int) MsgButtons.MK_LBUTTON) != 0)
1003 buttons |= MouseButtons.Left;
1005 if ((param & (int) MsgButtons.MK_MBUTTON) != 0)
1006 buttons |= MouseButtons.Middle;
1008 if ((param & (int) MsgButtons.MK_RBUTTON) != 0)
1009 buttons |= MouseButtons.Right;
1015 internal virtual bool ProcessControlMnemonic(char charCode) {
1016 return ProcessMnemonic(charCode);
1019 private static Control FindFlatForward(Control container, Control start) {
1025 end = container.child_controls.Count;
1027 if (start != null) {
1028 index = start.tab_index;
1033 for (int i = 0; i < end; i++) {
1034 if (found == null) {
1035 if (container.child_controls[i].tab_index > index) {
1036 found = container.child_controls[i];
1038 } else if (found.tab_index > container.child_controls[i].tab_index) {
1039 if (container.child_controls[i].tab_index > index) {
1040 found = container.child_controls[i];
1047 private static Control FindControlForward(Control container, Control start) {
1053 if (start != null) {
1054 if ((start is IContainerControl) || start.GetStyle(ControlStyles.ContainerControl)) {
1055 found = FindControlForward(start, null);
1056 if (found != null) {
1062 while (p != container) {
1063 found = FindFlatForward(p, start);
1064 if (found != null) {
1071 return FindFlatForward(container, start);
1074 private static Control FindFlatBackward(Control container, Control start) {
1080 end = container.child_controls.Count;
1082 if (start != null) {
1083 index = start.tab_index;
1085 // FIXME: Possible speed-up: Keep the highest taborder index in the container
1087 for (int i = 0; i < end; i++) {
1088 if (container.child_controls[i].tab_index > index) {
1089 index = container.child_controls[i].tab_index;
1095 for (int i = 0; i < end; i++) {
1096 if (found == null) {
1097 if (container.child_controls[i].tab_index < index) {
1098 found = container.child_controls[i];
1100 } else if (found.tab_index < container.child_controls[i].tab_index) {
1101 if (container.child_controls[i].tab_index < index) {
1102 found = container.child_controls[i];
1109 private static Control FindControlBackward(Control container, Control start) {
1114 if (start != null) {
1115 found = FindFlatBackward(start.parent, start);
1116 if (found == null && start.parent != container) {
1117 return start.parent;
1120 if (found == null) {
1121 found = FindFlatBackward(container, start);
1124 while ((found != null) && ((found is IContainerControl) || found.GetStyle(ControlStyles.ContainerControl))) {
1125 found = FindControlBackward(found, null);
1126 if (found != null) {
1134 private void HandleClick(int clicks) {
1135 if (GetStyle(ControlStyles.StandardClick)) {
1137 if (GetStyle(ControlStyles.StandardDoubleClick)) {
1138 OnDoubleClick(EventArgs.Empty);
1140 OnClick(EventArgs.Empty);
1143 OnClick(EventArgs.Empty);
1148 private void CheckDataBindings ()
1150 if (data_bindings == null)
1153 BindingContext binding_context = BindingContext;
1154 foreach (Binding binding in data_bindings) {
1155 binding.Check (binding_context);
1160 private void ChangeParent(Control new_parent) {
1164 Color pre_fore_color;
1165 Color pre_back_color;
1166 RightToLeft pre_rtl;
1168 // These properties are inherited from our parent
1169 // Get them pre parent-change and then send events
1170 // if they are changed after we have our new parent
1171 pre_enabled = Enabled;
1172 pre_visible = Visible;
1174 pre_fore_color = ForeColor;
1175 pre_back_color = BackColor;
1176 pre_rtl = RightToLeft;
1177 // MS doesn't seem to send a CursorChangedEvent
1179 parent = new_parent;
1181 if (IsHandleCreated && (new_parent != null) && new_parent.IsHandleCreated) {
1182 XplatUI.SetParent(Handle, new_parent.Handle);
1185 OnParentChanged(EventArgs.Empty);
1187 if (pre_enabled != Enabled) {
1188 OnEnabledChanged(EventArgs.Empty);
1191 if (pre_visible != Visible) {
1192 OnVisibleChanged(EventArgs.Empty);
1195 if (pre_font != Font) {
1196 OnFontChanged(EventArgs.Empty);
1199 if (pre_fore_color != ForeColor) {
1200 OnForeColorChanged(EventArgs.Empty);
1203 if (pre_back_color != BackColor) {
1204 OnBackColorChanged(EventArgs.Empty);
1207 if (pre_rtl != RightToLeft) {
1208 // MS sneaks a OnCreateControl and OnHandleCreated in here, I guess
1209 // because when RTL changes they have to recreate the win32 control
1210 // We don't really need that (until someone runs into compatibility issues)
1211 OnRightToLeftChanged(EventArgs.Empty);
1214 if ((new_parent != null) && new_parent.Created && !Created) {
1218 if ((binding_context == null) && Created) {
1219 OnBindingContextChanged(EventArgs.Empty);
1223 private void UpdateDistances() {
1224 dist_left = bounds.X;
1225 dist_top = bounds.Y;
1226 if ((parent != null) && (parent.layout_suspended == 0)) {
1227 dist_right = parent.ClientSize.Width - bounds.X - bounds.Width;
1228 dist_bottom = parent.ClientSize.Height - bounds.Y - bounds.Height;
1231 #endregion // Private & Internal Methods
1233 #region Public Static Properties
1234 public static Color DefaultBackColor {
1236 return ThemeEngine.Current.DefaultControlBackColor;
1240 public static Font DefaultFont {
1242 return ThemeEngine.Current.DefaultFont;
1246 public static Color DefaultForeColor {
1248 return ThemeEngine.Current.DefaultControlForeColor;
1252 public static Keys ModifierKeys {
1254 return XplatUI.State.ModifierKeys;
1258 public static MouseButtons MouseButtons {
1260 return XplatUI.State.MouseButtons;
1264 public static Point MousePosition {
1266 return Cursor.Position;
1272 public static bool CheckForIllegalCrossThreadCalls
1281 #endregion // Public Static Properties
1283 #region Public Instance Properties
1284 [EditorBrowsable(EditorBrowsableState.Advanced)]
1286 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1287 public AccessibleObject AccessibilityObject {
1289 if (accessibility_object==null) {
1290 accessibility_object=CreateAccessibilityInstance();
1292 return accessibility_object;
1296 [EditorBrowsable(EditorBrowsableState.Advanced)]
1298 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1299 public string AccessibleDefaultActionDescription {
1301 return AccessibilityObject.default_action;
1305 AccessibilityObject.default_action=value;
1310 [DefaultValue(null)]
1311 public string AccessibleDescription {
1313 return AccessibilityObject.description;
1317 AccessibilityObject.description=value;
1322 [DefaultValue(null)]
1323 public string AccessibleName {
1325 return AccessibilityObject.Name;
1329 AccessibilityObject.Name=value;
1333 [DefaultValue(AccessibleRole.Default)]
1334 [MWFDescription("Role of the control"), MWFCategory("Accessibility")]
1335 public AccessibleRole AccessibleRole {
1337 return AccessibilityObject.role;
1341 AccessibilityObject.role=value;
1345 [DefaultValue(false)]
1346 public virtual bool AllowDrop {
1352 if (allow_drop == value)
1356 XplatUI.SetAllowDrop (Handle, value);
1361 [RefreshProperties(RefreshProperties.Repaint)]
1362 [DefaultValue(AnchorStyles.Top | AnchorStyles.Left)]
1363 public virtual AnchorStyles Anchor {
1365 return anchor_style;
1371 if (parent != null) {
1372 parent.PerformLayout(this, "Parent");
1378 public virtual Color BackColor {
1380 if (background_color.IsEmpty) {
1382 return parent.BackColor;
1384 return DefaultBackColor;
1386 return background_color;
1390 background_color=value;
1391 SetChildColor(this);
1392 OnBackColorChanged(EventArgs.Empty);
1398 [DefaultValue(null)]
1399 public virtual Image BackgroundImage {
1401 return background_image;
1405 if (background_image!=value) {
1406 background_image=value;
1407 OnBackgroundImageChanged(EventArgs.Empty);
1412 [EditorBrowsable(EditorBrowsableState.Advanced)]
1414 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1415 public virtual BindingContext BindingContext {
1417 if (binding_context != null)
1418 return binding_context;
1421 binding_context = Parent.BindingContext;
1422 return binding_context;
1425 if (binding_context != value) {
1426 binding_context = value;
1427 OnBindingContextChanged(EventArgs.Empty);
1432 [EditorBrowsable(EditorBrowsableState.Advanced)]
1434 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1437 return bounds.Y+bounds.Height;
1441 [EditorBrowsable(EditorBrowsableState.Advanced)]
1443 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1444 public Rectangle Bounds {
1450 SetBoundsCore(value.Left, value.Top, value.Width, value.Height, BoundsSpecified.All);
1454 [EditorBrowsable(EditorBrowsableState.Advanced)]
1456 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1457 public bool CanFocus {
1459 if (Visible && is_enabled && GetStyle(ControlStyles.Selectable)) {
1466 [EditorBrowsable(EditorBrowsableState.Advanced)]
1468 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1469 public bool CanSelect {
1473 if (!GetStyle(ControlStyles.Selectable) || this.parent == null) {
1477 parent = this.parent;
1478 while (parent != null) {
1479 if (!parent.is_visible || !parent.is_enabled) {
1483 parent = parent.parent;
1489 [EditorBrowsable(EditorBrowsableState.Advanced)]
1491 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1492 public bool Capture {
1494 return this.is_captured;
1498 if (this.IsHandleCreated) {
1499 if (value && !is_captured) {
1501 XplatUI.GrabWindow(this.window.Handle, IntPtr.Zero);
1502 } else if (!value && is_captured) {
1503 XplatUI.UngrabWindow(this.window.Handle);
1504 is_captured = false;
1510 [DefaultValue(true)]
1511 public bool CausesValidation {
1513 return this.causes_validation;
1517 if (this.causes_validation != value) {
1518 causes_validation = value;
1519 OnCausesValidationChanged(EventArgs.Empty);
1524 [EditorBrowsable(EditorBrowsableState.Advanced)]
1526 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1527 public Rectangle ClientRectangle {
1529 client_rect.Width = client_size.Width;
1530 client_rect.Height = client_size.Height;
1535 [EditorBrowsable(EditorBrowsableState.Advanced)]
1537 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1538 public Size ClientSize {
1541 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1542 return ((Form)this).form_parent_window.ClientSize;
1550 this.SetClientSizeCore(value.Width, value.Height);
1554 [EditorBrowsable(EditorBrowsableState.Advanced)]
1556 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1557 [DescriptionAttribute("ControlCompanyNameDescr")]
1558 public String CompanyName {
1560 return "Mono Project, Novell, Inc.";
1564 [EditorBrowsable(EditorBrowsableState.Advanced)]
1566 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1567 public bool ContainsFocus {
1573 for (int i=0; i < child_controls.Count; i++) {
1574 if (child_controls[i].ContainsFocus) {
1582 [DefaultValue(null)]
1583 public virtual ContextMenu ContextMenu {
1585 return context_menu;
1589 if (context_menu != value) {
1590 context_menu = value;
1591 OnContextMenuChanged(EventArgs.Empty);
1597 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
1598 public ControlCollection Controls {
1600 return this.child_controls;
1604 [EditorBrowsable(EditorBrowsableState.Advanced)]
1606 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1607 public bool Created {
1609 if (!this.is_disposed && (this.window.Handle != IntPtr.Zero)) {
1616 [AmbientValue(null)]
1617 public virtual Cursor Cursor {
1619 if (cursor != null) {
1623 if (parent != null) {
1624 return parent.Cursor;
1627 return Cursors.Default;
1631 if (cursor != value) {
1636 pt = Cursor.Position;
1637 //Console.WriteLine ("{0} {1} {2}", bounds, pt, bounds.Contains (pt));
1638 if (bounds.Contains(pt)) {
1639 if (GetChildAtPoint(pt) == null) {
1640 if (cursor != null) {
1641 XplatUI.SetCursor(window.Handle, cursor.handle);
1643 if (parent != null) {
1644 XplatUI.SetCursor(window.Handle, parent.Cursor.handle);
1646 XplatUI.SetCursor(window.Handle, Cursors.def.handle);
1652 OnCursorChanged(EventArgs.Empty);
1658 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
1659 [ParenthesizePropertyName(true)]
1660 [RefreshProperties(RefreshProperties.All)]
1661 public ControlBindingsCollection DataBindings {
1663 if (data_bindings == null)
1664 data_bindings = new ControlBindingsCollection (this);
1665 return data_bindings;
1669 [EditorBrowsable(EditorBrowsableState.Advanced)]
1671 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1672 public virtual Rectangle DisplayRectangle {
1674 return ClientRectangle;
1678 [EditorBrowsable(EditorBrowsableState.Advanced)]
1680 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1681 public bool Disposing {
1688 [RefreshProperties(RefreshProperties.Repaint)]
1689 [DefaultValue(DockStyle.None)]
1690 public virtual DockStyle Dock {
1696 if (dock_style == value) {
1702 if (parent != null) {
1703 parent.PerformLayout(this, "Parent");
1706 OnDockChanged(EventArgs.Empty);
1712 public bool Enabled {
1718 if (parent != null) {
1719 return parent.Enabled;
1726 if (is_enabled == value) {
1732 OnEnabledChanged (EventArgs.Empty);
1736 [EditorBrowsable(EditorBrowsableState.Advanced)]
1738 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1739 public virtual bool Focused {
1741 return this.has_focus;
1746 [AmbientValue(null)]
1748 public virtual Font Font {
1754 if (Parent != null && Parent.Font != null) {
1762 if (font != null && font.Equals (value)) {
1768 OnFontChanged (EventArgs.Empty);
1773 public virtual Color ForeColor {
1775 if (foreground_color.IsEmpty) {
1777 return parent.ForeColor;
1779 return DefaultForeColor;
1781 return foreground_color;
1785 if (foreground_color != value) {
1786 foreground_color=value;
1788 OnForeColorChanged(EventArgs.Empty);
1795 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1796 public IntPtr Handle { // IWin32Window
1798 if (!IsHandleCreated) {
1801 return window.Handle;
1805 [EditorBrowsable(EditorBrowsableState.Advanced)]
1807 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1808 public bool HasChildren {
1810 if (this.child_controls.Count>0) {
1817 [EditorBrowsable(EditorBrowsableState.Always)]
1819 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1822 return this.bounds.Height;
1826 SetBoundsCore(bounds.X, bounds.Y, bounds.Width, value, BoundsSpecified.Height);
1830 [AmbientValue(ImeMode.Inherit)]
1832 public ImeMode ImeMode {
1834 if (ime_mode == DefaultImeMode) {
1836 return parent.ImeMode;
1838 return ImeMode.NoControl; // default value
1844 if (ime_mode != value) {
1847 OnImeModeChanged(EventArgs.Empty);
1852 [EditorBrowsable(EditorBrowsableState.Advanced)]
1854 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1855 public bool InvokeRequired { // ISynchronizeInvoke
1857 if (creator_thread!=Thread.CurrentThread) {
1864 [EditorBrowsable(EditorBrowsableState.Advanced)]
1866 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1867 public bool IsAccessible {
1869 return is_accessible;
1873 is_accessible = value;
1877 [EditorBrowsable(EditorBrowsableState.Advanced)]
1879 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1880 public bool IsDisposed {
1882 return this.is_disposed;
1886 [EditorBrowsable(EditorBrowsableState.Advanced)]
1888 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1889 public bool IsHandleCreated {
1891 if ((window!=null) && (window.Handle!=IntPtr.Zero)) {
1899 [EditorBrowsable(EditorBrowsableState.Always)]
1901 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1904 return this.bounds.X;
1908 SetBoundsCore(value, bounds.Y, bounds.Width, bounds.Height, BoundsSpecified.X);
1913 public Point Location {
1915 return new Point(bounds.X, bounds.Y);
1919 SetBoundsCore(value.X, value.Y, bounds.Width, bounds.Height, BoundsSpecified.Location);
1924 public string Name {
1935 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1936 public Control Parent {
1942 if (value == this) {
1943 throw new ArgumentException("A circular control reference has been made. A control cannot be owned or parented to itself.");
1946 if (parent!=value) {
1948 parent.Controls.Remove(this);
1952 value.Controls.Add(this);
1957 [EditorBrowsable(EditorBrowsableState.Advanced)]
1959 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1960 public string ProductName {
1962 Type t = typeof (AssemblyProductAttribute);
1963 Assembly assembly = GetType().Module.Assembly;
1964 object [] attrs = assembly.GetCustomAttributes (t, false);
1965 AssemblyProductAttribute a = null;
1966 // On MS we get a NullRefException if product attribute is not
1968 if (attrs != null && attrs.Length > 0)
1969 a = (AssemblyProductAttribute) attrs [0];
1974 [EditorBrowsable(EditorBrowsableState.Advanced)]
1976 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1977 public string ProductVersion {
1979 Type t = typeof (AssemblyVersionAttribute);
1980 Assembly assembly = GetType().Module.Assembly;
1981 object [] attrs = assembly.GetCustomAttributes (t, false);
1982 if (attrs == null || attrs.Length < 1)
1984 return ((AssemblyVersionAttribute)attrs [0]).Version;
1988 [EditorBrowsable(EditorBrowsableState.Advanced)]
1990 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1991 public bool RecreatingHandle {
1993 return is_recreating;
1997 [EditorBrowsable(EditorBrowsableState.Advanced)]
1999 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2000 public Region Region {
2002 return new Region(this.bounds);
2009 g = this.CreateGraphics();
2010 r = value.GetBounds(g);
2012 SetBounds((int)r.X, (int)r.Y, (int)r.Width, (int)r.Height);
2018 [EditorBrowsable(EditorBrowsableState.Advanced)]
2020 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2023 return this.bounds.X+this.bounds.Width;
2027 [AmbientValue(RightToLeft.Inherit)]
2029 public virtual RightToLeft RightToLeft {
2031 if (right_to_left == RightToLeft.Inherit) {
2033 return parent.RightToLeft;
2035 return RightToLeft.No; // default value
2037 return right_to_left;
2041 if (value != right_to_left) {
2042 right_to_left = value;
2043 OnRightToLeftChanged(EventArgs.Empty);
2048 [EditorBrowsable(EditorBrowsableState.Advanced)]
2049 public override ISite Site {
2062 return new Size(Width, Height);
2066 SetBoundsCore(bounds.X, bounds.Y, value.Width, value.Height, BoundsSpecified.Size);
2071 [MergableProperty(false)]
2072 public int TabIndex {
2074 if (tab_index != -1) {
2081 if (tab_index != value) {
2083 OnTabIndexChanged(EventArgs.Empty);
2089 [DefaultValue(true)]
2090 public bool TabStop {
2096 if (tab_stop != value) {
2098 OnTabStopChanged(EventArgs.Empty);
2103 [Localizable(false)]
2105 [TypeConverter(typeof(StringConverter))]
2106 [DefaultValue(null)]
2113 control_tag = value;
2119 [BindableAttribute(true)]
2120 public virtual string Text {
2122 // Our implementation ignores ControlStyles.CacheText - we always cache
2127 if (value == null) {
2128 value = String.Empty;
2133 if (IsHandleCreated) {
2134 XplatUI.Text(Handle, text);
2136 OnTextChanged (EventArgs.Empty);
2141 [EditorBrowsable(EditorBrowsableState.Always)]
2143 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2146 return this.bounds.Y;
2150 SetBoundsCore(bounds.X, value, bounds.Width, bounds.Height, BoundsSpecified.Y);
2154 [EditorBrowsable(EditorBrowsableState.Advanced)]
2156 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2157 public Control TopLevelControl {
2161 while (p.parent != null) {
2170 public bool Visible {
2174 } else if (parent != null) {
2175 return parent.Visible;
2182 SetVisibleCore(value);
2186 [EditorBrowsable(EditorBrowsableState.Always)]
2188 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2191 return this.bounds.Width;
2195 SetBoundsCore(bounds.X, bounds.Y, value, bounds.Height, BoundsSpecified.Width);
2199 [EditorBrowsable(EditorBrowsableState.Never)]
2201 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2202 public IWindowTarget WindowTarget {
2211 #endregion // Public Instance Properties
2213 #region Protected Instance Properties
2214 protected virtual CreateParams CreateParams {
2216 CreateParams create_params = new CreateParams();
2219 create_params.Caption = Text;
2222 create_params.Caption = text;
2226 create_params.X = Left;
2229 create_params.X = this.bounds.X;
2233 create_params.Y = Top;
2236 create_params.Y = this.bounds.Y;
2240 create_params.Width = Width;
2243 create_params.Width = this.bounds.Width;
2247 create_params.Height = Height;
2250 create_params.Height = this.bounds.Height;
2254 create_params.ClassName = XplatUI.DefaultClassName;
2255 create_params.ClassStyle = 0;
2256 create_params.ExStyle = 0;
2257 create_params.Param = 0;
2260 create_params.ExStyle |= (int)WindowStyles.WS_EX_ACCEPTFILES;
2264 create_params.Parent = parent.Handle;
2267 create_params.Style = (int)WindowStyles.WS_CHILD | (int)WindowStyles.WS_CLIPCHILDREN | (int)WindowStyles.WS_CLIPSIBLINGS;
2270 create_params.Style |= (int)WindowStyles.WS_VISIBLE;
2273 switch (border_style) {
2274 case BorderStyle.FixedSingle:
2275 create_params.Style |= (int) WindowStyles.WS_BORDER;
2277 case BorderStyle.Fixed3D:
2278 create_params.ExStyle |= (int) WindowStyles.WS_EX_CLIENTEDGE;
2282 return create_params;
2286 protected virtual ImeMode DefaultImeMode {
2288 return ImeMode.Inherit;
2292 protected virtual Size DefaultSize {
2294 return new Size(100, 23);
2298 protected int FontHeight {
2308 protected bool RenderRightToLeft {
2310 return (this.right_to_left == RightToLeft.Yes);
2314 protected bool ResizeRedraw {
2316 return GetStyle(ControlStyles.ResizeRedraw);
2320 SetStyle(ControlStyles.ResizeRedraw, value);
2324 [EditorBrowsable(EditorBrowsableState.Advanced)]
2326 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2327 protected virtual bool ShowFocusCues {
2333 [EditorBrowsable(EditorBrowsableState.Advanced)]
2335 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2336 protected bool ShowKeyboardCues {
2341 #endregion // Protected Instance Properties
2343 #region Public Static Methods
2344 [EditorBrowsable(EditorBrowsableState.Advanced)]
2345 public static Control FromChildHandle(IntPtr handle) {
2346 IEnumerator control = Control.controls.GetEnumerator();
2348 while (control.MoveNext()) {
2349 if (((Control)control.Current).window.Handle == handle) {
2351 if (((Control)control.Current).Parent != null) {
2352 return ((Control)control.Current).Parent;
2359 [EditorBrowsable(EditorBrowsableState.Advanced)]
2360 public static Control FromHandle(IntPtr handle) {
2362 IEnumerator control = Control.controls.GetEnumerator();
2364 while (control.MoveNext()) {
2365 if (((Control)control.Current).window.Handle == handle) {
2367 return ((Control)control.Current);
2373 return Control.ControlNativeWindow.ControlFromHandle(handle);
2377 public static bool IsMnemonic(char charCode, string text) {
2380 amp = text.IndexOf('&');
2383 if (amp + 1 < text.Length) {
2384 if (text[amp + 1] != '&') {
2385 if (Char.ToUpper(charCode) == Char.ToUpper(text.ToCharArray(amp + 1, 1)[0])) {
2395 #region Protected Static Methods
2396 [EditorBrowsable(EditorBrowsableState.Advanced)]
2397 protected static bool ReflectMessage(IntPtr hWnd, ref Message m) {
2400 c = Control.FromHandle(hWnd);
2410 #region Public Instance Methods
2411 [EditorBrowsable(EditorBrowsableState.Advanced)]
2412 public IAsyncResult BeginInvoke(Delegate method) {
2413 return BeginInvokeInternal(method, null, false);
2416 [EditorBrowsable(EditorBrowsableState.Advanced)]
2417 public IAsyncResult BeginInvoke (Delegate method, object[] args) {
2418 return BeginInvokeInternal (method, args, false);
2421 public void BringToFront() {
2422 if ((parent != null) && (parent.child_controls[0]!=this)) {
2423 if (parent.child_controls.Contains(this)) {
2424 parent.child_controls.SetChildIndex(this, 0);
2428 XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, true, false);
2430 if (parent != null) {
2435 public bool Contains(Control ctl) {
2436 while (ctl != null) {
2445 public void CreateControl() {
2450 if (!IsHandleCreated) {
2458 Control [] controls = child_controls.GetAllControls ();
2459 for (int i=0; i<controls.Length; i++) {
2460 controls [i].CreateControl ();
2465 if (binding_context == null) { // seem to be sent whenever it's null?
2466 OnBindingContextChanged(EventArgs.Empty);
2472 public Graphics CreateGraphics() {
2473 if (!IsHandleCreated) {
2474 this.CreateHandle();
2476 return Graphics.FromHwnd(this.window.Handle);
2479 public DragDropEffects DoDragDrop(object data, DragDropEffects allowedEffects) {
2480 return XplatUI.StartDrag(this.window.Handle, data, allowedEffects);
2483 [EditorBrowsable(EditorBrowsableState.Advanced)]
2484 public object EndInvoke (IAsyncResult async_result) {
2485 AsyncMethodResult result = (AsyncMethodResult) async_result;
2486 return result.EndInvoke ();
2489 public Form FindForm() {
2502 public bool Focus() {
2503 if (IsHandleCreated && !has_focus) {
2505 XplatUI.SetFocus(window.Handle);
2510 public Control GetChildAtPoint(Point pt) {
2511 // Microsoft's version of this function doesn't seem to work, so I can't check
2512 // if we only consider children or also grandchildren, etc.
2513 // I'm gonna say 'children only'
2514 for (int i=0; i<child_controls.Count; i++) {
2515 if (child_controls[i].Bounds.Contains(pt)) {
2516 return child_controls[i];
2522 public IContainerControl GetContainerControl() {
2523 Control current = this;
2525 while (current!=null) {
2526 if ((current is IContainerControl) && ((current.control_style & ControlStyles.ContainerControl)!=0)) {
2527 return (IContainerControl)current;
2529 current = current.parent;
2534 public Control GetNextControl(Control ctl, bool forward) {
2535 // If we're not a container we don't play
2536 if (!(this is IContainerControl) && !this.GetStyle(ControlStyles.ContainerControl)) {
2540 // If ctl is not contained by this, we start at the first child of this
2541 if (!this.Contains(ctl)) {
2545 // Search through our controls, starting at ctl, stepping into children as we encounter them
2546 // try to find the control with the tabindex closest to our own, or, if we're looking into
2547 // child controls, the one with the smallest tabindex
2549 return FindControlForward(this, ctl);
2551 return FindControlBackward(this, ctl);
2554 public void Hide() {
2555 this.Visible = false;
2558 public void Invalidate() {
2559 Invalidate(ClientRectangle, false);
2562 public void Invalidate(bool invalidateChildren) {
2563 Invalidate(ClientRectangle, invalidateChildren);
2566 public void Invalidate(System.Drawing.Rectangle rc) {
2567 Invalidate(rc, false);
2570 public void Invalidate(System.Drawing.Rectangle rc, bool invalidateChildren) {
2571 if (!IsHandleCreated || !Visible || rc.Width == 0 || rc.Height == 0) {
2575 NotifyInvalidate(rc);
2577 XplatUI.Invalidate(Handle, rc, false);
2579 if (invalidateChildren) {
2580 Control [] controls = child_controls.GetAllControls ();
2581 for (int i=0; i<controls.Length; i++)
2582 controls [i].Invalidate ();
2584 OnInvalidated(new InvalidateEventArgs(rc));
2587 public void Invalidate(System.Drawing.Region region) {
2588 Invalidate(region, false);
2591 public void Invalidate(System.Drawing.Region region, bool invalidateChildren) {
2592 RectangleF bounds = region.GetBounds (CreateGraphics ());
2593 Invalidate (new Rectangle ((int) bounds.X, (int) bounds.Y, (int) bounds.Width, (int) bounds.Height),
2594 invalidateChildren);
2597 public object Invoke (Delegate method) {
2598 return Invoke(method, null);
2601 public object Invoke (Delegate method, object[] args) {
2602 if (!this.InvokeRequired) {
2603 return method.DynamicInvoke(args);
2606 IAsyncResult result = BeginInvoke (method, args);
2607 return EndInvoke(result);
2610 internal object InvokeInternal (Delegate method, bool disposing) {
2611 return InvokeInternal(method, null, disposing);
2614 internal object InvokeInternal (Delegate method, object[] args, bool disposing) {
2615 if (!this.InvokeRequired) {
2616 return method.DynamicInvoke(args);
2619 IAsyncResult result = BeginInvokeInternal (method, args, disposing);
2620 return EndInvoke(result);
2623 [EditorBrowsable(EditorBrowsableState.Advanced)]
2624 public void PerformLayout() {
2625 PerformLayout(null, null);
2628 [EditorBrowsable(EditorBrowsableState.Advanced)]
2629 public void PerformLayout(Control affectedControl, string affectedProperty) {
2630 LayoutEventArgs levent = new LayoutEventArgs(affectedControl, affectedProperty);
2632 if (layout_suspended > 0) {
2633 layout_pending = true;
2637 layout_pending = false;
2639 // Prevent us from getting messed up
2642 // Perform all Dock and Anchor calculations
2645 AnchorStyles anchor;
2648 space=this.DisplayRectangle;
2650 // Deal with docking; go through in reverse, MS docs say that lowest Z-order is closest to edge
2651 Control [] controls = child_controls.GetAllControls ();
2652 for (int i = controls.Length - 1; i >= 0; i--) {
2653 child = controls [i];
2654 switch (child.Dock) {
2655 case DockStyle.None: {
2660 case DockStyle.Left: {
2661 child.SetBounds(space.Left, space.Y, child.Width, space.Height);
2662 space.X+=child.Width;
2663 space.Width-=child.Width;
2667 case DockStyle.Top: {
2668 child.SetBounds(space.Left, space.Y, space.Width, child.Height);
2669 space.Y+=child.Height;
2670 space.Height-=child.Height;
2674 case DockStyle.Right: {
2675 child.SetBounds(space.Right-child.Width, space.Y, child.Width, space.Height);
2676 space.Width-=child.Width;
2680 case DockStyle.Bottom: {
2681 child.SetBounds(space.Left, space.Bottom-child.Height, space.Width, child.Height);
2682 space.Height-=child.Height;
2688 for (int i = controls.Length - 1; i >= 0; i--) {
2691 if (child.Dock == DockStyle.Fill) {
2692 child.SetBounds(space.Left, space.Top, space.Width, space.Height);
2698 space=this.DisplayRectangle;
2700 for (int i=0; i < controls.Length; i++) {
2706 child = controls[i];
2707 anchor = child.Anchor;
2711 width = child.Width;
2712 height = child.Height;
2714 // If the control is docked we don't need to do anything
2715 if (child.Dock != DockStyle.None) {
2719 if ((anchor & AnchorStyles.Left) !=0 ) {
2720 if ((anchor & AnchorStyles.Right) != 0) {
2721 width = client_size.Width - child.dist_right - left;
2723 ; // Left anchored only, nothing to be done
2725 } else if ((anchor & AnchorStyles.Right) != 0) {
2726 left = client_size.Width - child.dist_right - width;
2728 // left+=diff_width/2 will introduce rounding errors (diff_width removed from svn after r51780)
2729 // This calculates from scratch every time:
2730 left = child.dist_left + (client_size.Width - (child.dist_left + width + child.dist_right)) / 2;
2733 if ((anchor & AnchorStyles.Top) !=0 ) {
2734 if ((anchor & AnchorStyles.Bottom) != 0) {
2735 height = client_size.Height - child.dist_bottom - top;
2737 ; // Top anchored only, nothing to be done
2739 } else if ((anchor & AnchorStyles.Bottom) != 0) {
2740 top = client_size.Height - child.dist_bottom - height;
2742 // top += diff_height/2 will introduce rounding errors (diff_height removed from after r51780)
2743 // This calculates from scratch every time:
2744 top = child.dist_top + (client_size.Height - (child.dist_top + height + child.dist_bottom)) / 2;
2756 child.SetBounds(left, top, width, height);
2759 // Let everyone know
2763 // Need to make sure we decremend layout_suspended
2769 public Point PointToClient (Point p) {
2773 XplatUI.ScreenToClient (Handle, ref x, ref y);
2775 return new Point (x, y);
2778 public Point PointToScreen(Point p) {
2782 XplatUI.ClientToScreen(Handle, ref x, ref y);
2784 return new Point(x, y);
2787 public virtual bool PreProcessMessage(ref Message msg) {
2790 if ((msg.Msg == (int)Msg.WM_KEYDOWN) || (msg.Msg == (int)Msg.WM_SYSKEYDOWN)) {
2791 key_data = (Keys)msg.WParam.ToInt32() | XplatUI.State.ModifierKeys;
2793 if (!ProcessCmdKey(ref msg, key_data)) {
2794 if (IsInputKey(key_data)) {
2798 return ProcessDialogKey(key_data);
2802 } else if (msg.Msg == (int)Msg.WM_CHAR) {
2803 if (IsInputChar((char)msg.WParam)) {
2806 } else if (msg.Msg == (int)Msg.WM_SYSCHAR) {
2807 if (IsInputChar((char)msg.WParam)) {
2810 return ProcessDialogChar((char)msg.WParam);
2815 public Rectangle RectangleToClient(Rectangle r) {
2816 return new Rectangle(PointToClient(r.Location), r.Size);
2819 public Rectangle RectangleToScreen(Rectangle r) {
2820 return new Rectangle(PointToScreen(r.Location), r.Size);
2823 public virtual void Refresh() {
2824 if (IsHandleCreated == true) {
2827 XplatUI.UpdateWindow(window.Handle);
2829 Control [] controls = child_controls.GetAllControls ();
2830 for (int i=0; i < controls.Length; i++) {
2831 controls[i].Refresh();
2837 [EditorBrowsable(EditorBrowsableState.Never)]
2838 public virtual void ResetBackColor() {
2839 background_color = Color.Empty;
2842 [EditorBrowsable(EditorBrowsableState.Never)]
2844 public void ResetBindings() {
2848 [EditorBrowsable(EditorBrowsableState.Never)]
2849 public virtual void ResetCursor() {
2853 [EditorBrowsable(EditorBrowsableState.Never)]
2854 public virtual void ResetFont() {
2858 [EditorBrowsable(EditorBrowsableState.Never)]
2859 public virtual void ResetForeColor() {
2860 foreground_color = Color.Empty;
2863 [EditorBrowsable(EditorBrowsableState.Never)]
2864 public void ResetImeMode() {
2865 ime_mode = DefaultImeMode;
2868 [EditorBrowsable(EditorBrowsableState.Never)]
2869 public virtual void ResetRightToLeft() {
2870 right_to_left = RightToLeft.Inherit;
2873 public virtual void ResetText() {
2874 text = String.Empty;
2877 public void ResumeLayout() {
2878 ResumeLayout (true);
2881 public void ResumeLayout(bool performLayout) {
2884 if (layout_suspended > 0) {
2888 Control [] controls = child_controls.GetAllControls ();
2889 for (int i=0; i<controls.Length; i++) {
2890 controls [i].UpdateDistances ();
2893 if (performLayout || layout_pending) {
2898 public void Scale(float ratio) {
2899 ScaleCore(ratio, ratio);
2902 public void Scale(float dx, float dy) {
2906 public void Select() {
2907 Select(false, false);
2910 public bool SelectNextControl(Control ctl, bool forward, bool tabStopOnly, bool nested, bool wrap) {
2915 c = GetNextControl(c, forward);
2924 if (c.CanSelect && ((c.parent == ctl.parent) || nested) && (c.tab_stop || !tabStopOnly)) {
2928 } while (c != ctl); // If we wrap back to ourselves we stop
2933 public void SendToBack() {
2934 if ((parent != null) && (parent.child_controls[parent.child_controls.Count-1]!=this)) {
2935 if (parent.child_controls.Contains(this)) {
2936 parent.child_controls.SetChildIndex(this, parent.child_controls.Count);
2940 XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, false, true);
2941 if (parent != null) {
2946 public void SetBounds(int x, int y, int width, int height) {
2947 SetBoundsCore(x, y, width, height, BoundsSpecified.All);
2950 public void SetBounds(int x, int y, int width, int height, BoundsSpecified specified) {
2951 SetBoundsCore(x, y, width, height, specified);
2954 public void Show() {
2955 if (!IsHandleCreated) {
2956 this.CreateControl();
2962 public void SuspendLayout() {
2966 public void Update() {
2967 needs_redraw = true;
2968 if (IsHandleCreated) {
2969 XplatUI.UpdateWindow(window.Handle);
2972 #endregion // Public Instance Methods
2974 #region Protected Instance Methods
2975 [EditorBrowsable(EditorBrowsableState.Advanced)]
2976 [MonoTODO("Implement this and tie it into Control.ControlAccessibleObject.NotifyClients")]
2977 protected void AccessibilityNotifyClients(AccessibleEvents accEvent, int childID) {
2978 throw new NotImplementedException();
2981 [EditorBrowsable(EditorBrowsableState.Advanced)]
2982 protected virtual AccessibleObject CreateAccessibilityInstance() {
2983 return new Control.ControlAccessibleObject(this);
2986 [EditorBrowsable(EditorBrowsableState.Advanced)]
2987 protected virtual ControlCollection CreateControlsInstance() {
2988 return new ControlCollection(this);
2991 [EditorBrowsable(EditorBrowsableState.Advanced)]
2992 protected virtual void CreateHandle() {
2994 throw new ObjectDisposedException(Name);
2997 if (IsHandleCreated) {
3001 window.CreateHandle(CreateParams);
3003 if (window.Handle!=IntPtr.Zero) {
3004 if (!controls.Contains(window.Handle)) {
3008 creator_thread = Thread.CurrentThread;
3010 OnHandleCreated(EventArgs.Empty);
3012 // Set our handle with our parent
3013 if ((parent != null) && (parent.IsHandleCreated)) {
3014 XplatUI.SetParent(window.Handle, parent.Handle);
3017 // Set our handle as parent for our children
3018 Control [] children;
3020 children = child_controls.GetAllControls ();
3021 for (int i = 0; i < children.Length; i++ ) {
3022 if (children[i].IsHandleCreated) {
3023 XplatUI.SetParent(children[i].Handle, window.Handle);
3028 // Find out where the window manager placed us
3030 if ((CreateParams.Style & (int)WindowStyles.WS_CHILD) != 0) {
3031 XplatUI.SetBorderStyle(window.Handle, (FormBorderStyle)border_style);
3036 [EditorBrowsable(EditorBrowsableState.Advanced)]
3037 protected virtual void DefWndProc(ref Message m) {
3038 window.DefWndProc(ref m);
3041 [EditorBrowsable(EditorBrowsableState.Advanced)]
3042 protected virtual void DestroyHandle() {
3043 if (IsHandleCreated) {
3044 if (window != null) {
3045 window.DestroyHandle();
3050 protected bool GetStyle(ControlStyles flag) {
3051 return (control_style & flag) != 0;
3054 protected bool GetTopLevel() {
3058 [EditorBrowsable(EditorBrowsableState.Advanced)]
3059 protected virtual void InitLayout() {
3063 [EditorBrowsable(EditorBrowsableState.Advanced)]
3064 protected void InvokeGotFocus(Control toInvoke, EventArgs e) {
3065 toInvoke.OnGotFocus(e);
3068 [EditorBrowsable(EditorBrowsableState.Advanced)]
3069 protected void InvokeLostFocus(Control toInvoke, EventArgs e) {
3070 toInvoke.OnLostFocus(e);
3073 [EditorBrowsable(EditorBrowsableState.Advanced)]
3074 protected void InvokeOnClick(Control toInvoke, EventArgs e) {
3075 toInvoke.OnClick(e);
3078 protected void InvokePaint(Control toInvoke, PaintEventArgs e) {
3079 toInvoke.OnPaint(e);
3082 protected void InvokePaintBackground(Control toInvoke, PaintEventArgs e) {
3083 toInvoke.OnPaintBackground(e);
3086 protected virtual bool IsInputChar (char charCode) {
3087 if (parent != null) {
3088 return parent.IsInputChar(charCode);
3094 protected virtual bool IsInputKey (Keys keyData) {
3095 // Doc says this one calls IsInputChar; not sure what to do with that
3099 [EditorBrowsable(EditorBrowsableState.Advanced)]
3100 protected virtual void NotifyInvalidate(Rectangle invalidatedArea) {
3104 protected virtual bool ProcessCmdKey(ref Message msg, Keys keyData) {
3105 if ((context_menu != null) && context_menu.ProcessCmdKey(ref msg, keyData)) {
3109 if (parent != null) {
3110 return parent.ProcessCmdKey(ref msg, keyData);
3116 protected virtual bool ProcessDialogChar(char charCode) {
3117 if (parent != null) {
3118 return parent.ProcessDialogChar (charCode);
3124 protected virtual bool ProcessDialogKey (Keys keyData) {
3125 if (parent != null) {
3126 return parent.ProcessDialogKey (keyData);
3132 protected virtual bool ProcessKeyEventArgs (ref Message msg)
3134 KeyEventArgs key_event;
3137 case (int)Msg.WM_SYSKEYDOWN:
3138 case (int)Msg.WM_KEYDOWN: {
3139 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
3140 OnKeyDown (key_event);
3141 return key_event.Handled;
3144 case (int)Msg.WM_SYSKEYUP:
3145 case (int)Msg.WM_KEYUP: {
3146 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
3147 OnKeyUp (key_event);
3148 return key_event.Handled;
3151 case (int)Msg.WM_SYSCHAR:
3152 case (int)Msg.WM_CHAR: {
3153 KeyPressEventArgs key_press_event;
3155 key_press_event = new KeyPressEventArgs((char)msg.WParam);
3156 OnKeyPress(key_press_event);
3157 return key_press_event.Handled;
3168 protected internal virtual bool ProcessKeyMessage(ref Message msg) {
3169 if (parent != null) {
3170 if (parent.ProcessKeyPreview(ref msg)) {
3178 protected virtual bool ProcessKeyPreview(ref Message msg) {
3179 if (parent != null) {
3180 return parent.ProcessKeyPreview(ref msg);
3186 protected virtual bool ProcessMnemonic(char charCode) {
3191 [EditorBrowsable(EditorBrowsableState.Advanced)]
3192 protected void RaiseDragEvent(object key, DragEventArgs e) {
3196 [EditorBrowsable(EditorBrowsableState.Advanced)]
3197 protected void RaiseKeyEvent(object key, KeyEventArgs e) {
3201 [EditorBrowsable(EditorBrowsableState.Advanced)]
3202 protected void RaiseMouseEvent(object key, MouseEventArgs e) {
3206 [EditorBrowsable(EditorBrowsableState.Advanced)]
3207 protected void RaisePaintEvent(object key, PaintEventArgs e) {
3211 [EditorBrowsable(EditorBrowsableState.Advanced)]
3212 protected void RecreateHandle() {
3213 IEnumerator child = child_controls.GetAllEnumerator();
3217 if (IsHandleCreated) {
3223 while (child.MoveNext()) {
3224 ((Control)child.Current).RecreateHandle();
3230 is_recreating = false;
3233 [EditorBrowsable(EditorBrowsableState.Advanced)]
3234 protected void ResetMouseEventArgs() {
3238 [EditorBrowsable(EditorBrowsableState.Advanced)]
3239 protected ContentAlignment RtlTranslateAlignment(ContentAlignment align) {
3240 if (right_to_left == RightToLeft.No) {
3245 case ContentAlignment.TopLeft: {
3246 return ContentAlignment.TopRight;
3249 case ContentAlignment.TopRight: {
3250 return ContentAlignment.TopLeft;
3253 case ContentAlignment.MiddleLeft: {
3254 return ContentAlignment.MiddleRight;
3257 case ContentAlignment.MiddleRight: {
3258 return ContentAlignment.MiddleLeft;
3261 case ContentAlignment.BottomLeft: {
3262 return ContentAlignment.BottomRight;
3265 case ContentAlignment.BottomRight: {
3266 return ContentAlignment.BottomLeft;
3270 // if it's center it doesn't change
3276 [EditorBrowsable(EditorBrowsableState.Advanced)]
3277 protected HorizontalAlignment RtlTranslateAlignment(HorizontalAlignment align) {
3278 if ((right_to_left == RightToLeft.No) || (align == HorizontalAlignment.Center)) {
3282 if (align == HorizontalAlignment.Left) {
3283 return HorizontalAlignment.Right;
3286 // align must be HorizontalAlignment.Right
3287 return HorizontalAlignment.Left;
3290 [EditorBrowsable(EditorBrowsableState.Advanced)]
3291 protected LeftRightAlignment RtlTranslateAlignment(LeftRightAlignment align) {
3292 if (right_to_left == RightToLeft.No) {
3296 if (align == LeftRightAlignment.Left) {
3297 return LeftRightAlignment.Right;
3300 // align must be LeftRightAlignment.Right;
3301 return LeftRightAlignment.Left;
3304 [EditorBrowsable(EditorBrowsableState.Advanced)]
3305 protected ContentAlignment RtlTranslateContent(ContentAlignment align) {
3306 return RtlTranslateAlignment(align);
3309 [EditorBrowsable(EditorBrowsableState.Advanced)]
3310 protected HorizontalAlignment RtlTranslateHorizontal(HorizontalAlignment align) {
3311 return RtlTranslateAlignment(align);
3314 [EditorBrowsable(EditorBrowsableState.Advanced)]
3315 protected LeftRightAlignment RtlTranslateLeftRight(LeftRightAlignment align) {
3316 return RtlTranslateAlignment(align);
3319 [EditorBrowsable(EditorBrowsableState.Advanced)]
3320 protected virtual void ScaleCore(float dx, float dy) {
3326 location = new Point((int)(Left * dx), (int)(Top * dy));
3327 size = this.ClientSize;
3330 if (!GetStyle(ControlStyles.FixedWidth)) {
3331 size.Width = (int)(size.Width * dx);
3334 if (!GetStyle(ControlStyles.FixedHeight)) {
3335 size.Height = (int)(size.Height * dy);
3338 Location = location;
3341 /* Now scale our children */
3342 Control [] controls = child_controls.GetAllControls ();
3343 for (int i=0; i < controls.Length; i++) {
3344 controls[i].Scale(dx, dy);
3350 protected virtual void Select(bool directed, bool forward) {
3355 // Select this control
3360 if (parent == null) {
3364 // FIXME - this thing is doing the wrong stuff, needs to be similar to SelectNextControl
3366 index = parent.child_controls.IndexOf(this);
3371 if ((index+1) < parent.child_controls.Count) {
3380 index = parent.child_controls.Count-1;
3383 result = Select(parent.child_controls[index]);
3384 } while (!result && parent.child_controls[index] != this);
3387 [EditorBrowsable(EditorBrowsableState.Advanced)]
3388 protected virtual void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
3389 // SetBoundsCore updates the Win32 control itself. UpdateBounds updates the controls variables and fires events, I'm guessing - pdb
3390 if ((specified & BoundsSpecified.X) != BoundsSpecified.X) {
3394 if ((specified & BoundsSpecified.Y) != BoundsSpecified.Y) {
3398 if ((specified & BoundsSpecified.Width) != BoundsSpecified.Width) {
3402 if ((specified & BoundsSpecified.Height) != BoundsSpecified.Height) {
3406 if (IsHandleCreated) {
3407 XplatUI.SetWindowPos(Handle, x, y, width, height);
3410 UpdateBounds(x, y, width, height);
3413 [EditorBrowsable(EditorBrowsableState.Advanced)]
3414 protected virtual void SetClientSizeCore(int x, int y) {
3415 // Calculate the actual window size from the client size (it usually stays the same or grows)
3416 Rectangle ClientRect;
3417 Rectangle WindowRect;
3420 ClientRect = new Rectangle(0, 0, x, y);
3421 cp = this.CreateParams;
3423 if (XplatUI.CalculateWindowRect(Handle, ref ClientRect, cp.Style, cp.ExStyle, null, out WindowRect)==false) {
3427 SetBoundsCore(bounds.X, bounds.Y, WindowRect.Width, WindowRect.Height, BoundsSpecified.Size);
3430 [EditorBrowsable(EditorBrowsableState.Advanced)]
3431 protected void SetStyle(ControlStyles flag, bool value) {
3433 control_style |= flag;
3435 control_style &= ~flag;
3437 OnStyleChanged(EventArgs.Empty);
3440 protected void SetTopLevel(bool value) {
3441 if ((GetTopLevel() != value) && (parent != null)) {
3442 throw new Exception();
3446 if (value == true) {
3456 is_toplevel = value;
3459 protected virtual void SetVisibleCore(bool value) {
3460 if (value!=is_visible) {
3463 if (IsHandleCreated) {
3464 XplatUI.SetVisible(Handle, value);
3465 // Explicitly move Toplevel windows to where we want them;
3466 // apparently moving unmapped toplevel windows doesn't work
3467 if (is_visible && (this is Form)) {
3468 XplatUI.SetWindowPos(window.Handle, bounds.X, bounds.Y, bounds.Width, bounds.Height);
3472 OnVisibleChanged(EventArgs.Empty);
3475 if (dc_mem != null) {
3480 if (bmp_mem != null) {
3485 this.CreateBuffers(bounds.Width, bounds.Height);
3489 if (value == false && parent != null) {
3492 // Need to start at parent, GetContainerControl might return ourselves if we're a container
3493 container = (Control)parent.GetContainerControl();
3494 if (container != null) {
3495 container.SelectNextControl(this, true, true, true, true);
3499 if (parent != null) {
3500 parent.PerformLayout(this, "visible");
3502 PerformLayout(this, "visible");
3507 [EditorBrowsable(EditorBrowsableState.Advanced)]
3508 protected void UpdateBounds() {
3516 if (!IsHandleCreated) {
3520 XplatUI.GetWindowPos(this.Handle, this is Form, out x, out y, out width, out height, out client_width, out client_height);
3522 UpdateBounds(x, y, width, height, client_width, client_height);
3525 [EditorBrowsable(EditorBrowsableState.Advanced)]
3526 protected void UpdateBounds(int x, int y, int width, int height) {
3527 // UpdateBounds only seems to set our sizes and fire events but not update the GUI window to match
3529 bool resized = false;
3531 int client_x_diff = this.bounds.Width-this.client_size.Width;
3532 int client_y_diff = this.bounds.Height-this.client_size.Height;
3534 // Needed to generate required notifications
3535 if ((this.bounds.X!=x) || (this.bounds.Y!=y)) {
3539 if ((this.Bounds.Width!=width) || (this.Bounds.Height!=height)) {
3546 bounds.Height=height;
3548 // Update client rectangle as well
3549 client_size.Width=width-client_x_diff;
3550 client_size.Height=height-client_y_diff;
3555 OnLocationChanged(EventArgs.Empty);
3559 OnSizeChanged(EventArgs.Empty);
3563 [EditorBrowsable(EditorBrowsableState.Advanced)]
3564 protected void UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) {
3565 UpdateBounds(x, y, width, height);
3567 this.client_size.Width=clientWidth;
3568 this.client_size.Height=clientHeight;
3571 [EditorBrowsable(EditorBrowsableState.Advanced)]
3572 protected void UpdateStyles() {
3573 if (!IsHandleCreated) {
3577 XplatUI.SetWindowStyle(window.Handle, CreateParams);
3580 [EditorBrowsable(EditorBrowsableState.Advanced)]
3581 protected void UpdateZOrder() {
3582 Control [] controls;
3583 if (!IsHandleCreated) {
3587 controls = child_controls.GetAllControls ();
3588 for (int i = 1; i < controls.Length; i++ ) {
3589 XplatUI.SetZOrder(controls[i].Handle, controls[i-1].Handle, false, false);
3593 protected virtual void WndProc(ref Message m) {
3595 Console.WriteLine("Control received message {0}", (Msg)m.Msg);
3597 if ((this.control_style & ControlStyles.EnableNotifyMessage) != 0) {
3601 switch((Msg)m.Msg) {
3602 case Msg.WM_DESTROY: {
3603 OnHandleDestroyed(EventArgs.Empty);
3604 window.InvalidateHandle();
3608 case Msg.WM_WINDOWPOSCHANGED: {
3611 if (GetStyle(ControlStyles.ResizeRedraw)) {
3618 case Msg.WM_PAINT: {
3619 PaintEventArgs paint_event;
3621 paint_event = XplatUI.PaintEventStart(Handle, true);
3623 if (!needs_redraw) {
3624 // Just blit the previous image
3625 paint_event.Graphics.DrawImage (ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle, GraphicsUnit.Pixel);
3626 XplatUI.PaintEventEnd(Handle, true);
3631 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
3632 dc = paint_event.SetGraphics (DeviceContext);
3635 OnPaintBackground(paint_event);
3636 // Leave out for now, our controls can do Paint += ... as well
3637 //OnPaintInternal(paint_event);
3638 OnPaint(paint_event);
3640 if ((control_style & ControlStyles.DoubleBuffer) != 0) {
3641 dc.DrawImage (ImageBuffer, paint_event.ClipRectangle, paint_event.ClipRectangle, GraphicsUnit.Pixel);
3642 paint_event.SetGraphics (dc);
3643 needs_redraw = false;
3646 XplatUI.PaintEventEnd(Handle, true);
3651 case Msg.WM_ERASEBKGND: {
3652 // The DefWndProc will never have to handle this, we always paint the background in managed code
3653 m.Result = (IntPtr)1;
3657 case Msg.WM_LBUTTONUP: {
3658 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Left,
3660 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3662 HandleClick(mouse_clicks);
3663 if (mouse_clicks > 1) {
3669 case Msg.WM_LBUTTONDOWN: {
3670 if (CanSelect && !is_selected) {
3673 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3674 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3680 case Msg.WM_LBUTTONDBLCLK: {
3682 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3683 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3689 case Msg.WM_MBUTTONUP: {
3690 HandleClick(mouse_clicks);
3691 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Middle,
3693 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3695 if (mouse_clicks > 1) {
3701 case Msg.WM_MBUTTONDOWN: {
3702 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3703 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3709 case Msg.WM_MBUTTONDBLCLK: {
3711 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3712 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3717 case Msg.WM_RBUTTONUP: {
3718 if (context_menu != null) {
3719 context_menu.Show(this, new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ())));
3722 HandleClick(mouse_clicks);
3723 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Right,
3725 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3727 if (mouse_clicks > 1) {
3733 case Msg.WM_RBUTTONDOWN: {
3734 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3735 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3740 case Msg.WM_RBUTTONDBLCLK: {
3742 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3743 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3748 case Msg.WM_MOUSEWHEEL: {
3750 OnMouseWheel (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3751 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3752 HighOrder(m.WParam.ToInt32())));
3757 case Msg.WM_MOUSEMOVE: {
3758 OnMouseMove (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3760 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3765 case Msg.WM_MOUSE_ENTER: {
3770 OnMouseEnter(EventArgs.Empty);
3774 case Msg.WM_MOUSE_LEAVE: {
3776 OnMouseLeave(EventArgs.Empty);
3780 case Msg.WM_MOUSEHOVER: {
3781 OnMouseHover(EventArgs.Empty);
3785 case Msg.WM_SYSKEYDOWN:
3786 case Msg.WM_KEYDOWN:
3787 case Msg.WM_SYSKEYUP:
3789 case Msg.WM_SYSCHAR:
3791 if (PreProcessMessage(ref m)) {
3795 if (ProcessKeyMessage(ref m)) {
3799 if (ProcessKeyEventArgs(ref m)) {
3803 if ((m.Msg == (int)Msg.WM_SYSKEYUP) && ((m.WParam.ToInt32() & (int)Keys.KeyCode) == (int)Keys.Menu)) {
3807 if (form != null && form.ActiveMenu != null) {
3808 form.ActiveMenu.ProcessCmdKey(ref m, (Keys)m.WParam.ToInt32());
3818 if (m.LParam != IntPtr.Zero) {
3821 hi = new HELPINFO();
3823 hi = (HELPINFO) Marshal.PtrToStructure (m.LParam, typeof (HELPINFO));
3824 mouse_pos = new Point(hi.MousePos.x, hi.MousePos.y);
3826 mouse_pos = Control.MousePosition;
3828 OnHelpRequested(new HelpEventArgs(mouse_pos));
3829 m.Result = (IntPtr)1;
3833 case Msg.WM_KILLFOCUS: {
3834 OnLeave(EventArgs.Empty);
3835 if (CausesValidation) {
3837 e = new CancelEventArgs(false);
3846 OnValidated(EventArgs.Empty);
3849 this.has_focus = false;
3850 this.is_selected = false;
3851 OnLostFocus(EventArgs.Empty);
3855 case Msg.WM_SETFOCUS: {
3856 OnEnter(EventArgs.Empty);
3857 this.has_focus = true;
3858 OnGotFocus(EventArgs.Empty);
3863 case Msg.WM_SYSCOLORCHANGE: {
3864 ThemeEngine.Current.ResetDefaults();
3865 OnSystemColorsChanged(EventArgs.Empty);
3870 case Msg.WM_SETCURSOR: {
3871 if (cursor == null) {
3876 XplatUI.SetCursor(window.Handle, cursor.handle);
3877 m.Result = (IntPtr)1;
3888 #endregion // Public Instance Methods
3890 #region OnXXX methods
3891 [EditorBrowsable(EditorBrowsableState.Advanced)]
3892 protected virtual void OnBackColorChanged(EventArgs e) {
3893 if (BackColorChanged!=null) BackColorChanged(this, e);
3894 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackColorChanged(e);
3897 [EditorBrowsable(EditorBrowsableState.Advanced)]
3898 protected virtual void OnBackgroundImageChanged(EventArgs e) {
3899 if (BackgroundImageChanged!=null) BackgroundImageChanged(this, e);
3900 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackgroundImageChanged(e);
3903 [EditorBrowsable(EditorBrowsableState.Advanced)]
3904 protected virtual void OnBindingContextChanged(EventArgs e) {
3905 CheckDataBindings ();
3906 if (BindingContextChanged!=null) {
3907 BindingContextChanged(this, e);
3909 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBindingContextChanged(e);
3912 [EditorBrowsable(EditorBrowsableState.Advanced)]
3913 protected virtual void OnCausesValidationChanged(EventArgs e) {
3914 if (CausesValidationChanged!=null) CausesValidationChanged(this, e);
3917 [EditorBrowsable(EditorBrowsableState.Advanced)]
3918 protected virtual void OnChangeUICues(UICuesEventArgs e) {
3919 if (ChangeUICues!=null) ChangeUICues(this, e);
3922 [EditorBrowsable(EditorBrowsableState.Advanced)]
3923 protected virtual void OnClick(EventArgs e) {
3924 if (Click!=null) Click(this, e);
3927 [EditorBrowsable(EditorBrowsableState.Advanced)]
3928 protected virtual void OnContextMenuChanged(EventArgs e) {
3929 if (ContextMenuChanged!=null) ContextMenuChanged(this, e);
3932 [EditorBrowsable(EditorBrowsableState.Advanced)]
3933 protected virtual void OnControlAdded(ControlEventArgs e) {
3934 if (ControlAdded!=null) ControlAdded(this, e);
3937 [EditorBrowsable(EditorBrowsableState.Advanced)]
3938 protected virtual void OnControlRemoved(ControlEventArgs e) {
3939 if (ControlRemoved!=null) ControlRemoved(this, e);
3942 [EditorBrowsable(EditorBrowsableState.Advanced)]
3943 protected virtual void OnCreateControl() {
3947 [EditorBrowsable(EditorBrowsableState.Advanced)]
3948 protected virtual void OnCursorChanged(EventArgs e) {
3949 if (CursorChanged!=null) CursorChanged(this, e);
3952 [EditorBrowsable(EditorBrowsableState.Advanced)]
3953 protected virtual void OnDockChanged(EventArgs e) {
3954 if (DockChanged!=null) DockChanged(this, e);
3957 [EditorBrowsable(EditorBrowsableState.Advanced)]
3958 protected virtual void OnDoubleClick(EventArgs e) {
3959 if (DoubleClick!=null) DoubleClick(this, e);
3962 [EditorBrowsable(EditorBrowsableState.Advanced)]
3963 protected virtual void OnDragDrop(DragEventArgs drgevent) {
3964 if (DragDrop!=null) DragDrop(this, drgevent);
3967 [EditorBrowsable(EditorBrowsableState.Advanced)]
3968 protected virtual void OnDragEnter(DragEventArgs drgevent) {
3969 if (DragEnter!=null) DragEnter(this, drgevent);
3972 [EditorBrowsable(EditorBrowsableState.Advanced)]
3973 protected virtual void OnDragLeave(EventArgs e) {
3974 if (DragLeave!=null) DragLeave(this, e);
3977 [EditorBrowsable(EditorBrowsableState.Advanced)]
3978 protected virtual void OnDragOver(DragEventArgs drgevent) {
3979 if (DragOver!=null) DragOver(this, drgevent);
3982 [EditorBrowsable(EditorBrowsableState.Advanced)]
3983 protected virtual void OnEnabledChanged(EventArgs e) {
3984 if (EnabledChanged!=null) EnabledChanged(this, e);
3985 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentEnabledChanged(e);
3988 [EditorBrowsable(EditorBrowsableState.Advanced)]
3989 protected virtual void OnEnter(EventArgs e) {
3990 if (Enter!=null) Enter(this, e);
3993 [EditorBrowsable(EditorBrowsableState.Advanced)]
3994 protected virtual void OnFontChanged(EventArgs e) {
3995 if (FontChanged!=null) FontChanged(this, e);
3996 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentFontChanged(e);
3999 [EditorBrowsable(EditorBrowsableState.Advanced)]
4000 protected virtual void OnForeColorChanged(EventArgs e) {
4001 if (ForeColorChanged!=null) ForeColorChanged(this, e);
4002 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentForeColorChanged(e);
4005 [EditorBrowsable(EditorBrowsableState.Advanced)]
4006 protected virtual void OnGiveFeedback(GiveFeedbackEventArgs gfbevent) {
4007 if (GiveFeedback!=null) GiveFeedback(this, gfbevent);
4010 [EditorBrowsable(EditorBrowsableState.Advanced)]
4011 protected virtual void OnGotFocus(EventArgs e) {
4012 if (GotFocus!=null) GotFocus(this, e);
4015 [EditorBrowsable(EditorBrowsableState.Advanced)]
4016 protected virtual void OnHandleCreated(EventArgs e) {
4017 if (HandleCreated!=null) HandleCreated(this, e);
4020 [EditorBrowsable(EditorBrowsableState.Advanced)]
4021 protected virtual void OnHandleDestroyed(EventArgs e) {
4022 if (HandleDestroyed!=null) HandleDestroyed(this, e);
4025 [EditorBrowsable(EditorBrowsableState.Advanced)]
4026 protected virtual void OnHelpRequested(HelpEventArgs hevent) {
4027 if (HelpRequested!=null) HelpRequested(this, hevent);
4030 protected virtual void OnImeModeChanged(EventArgs e) {
4031 if (ImeModeChanged!=null) ImeModeChanged(this, e);
4034 [EditorBrowsable(EditorBrowsableState.Advanced)]
4035 protected virtual void OnInvalidated(InvalidateEventArgs e) {
4036 needs_redraw = true;
4037 if (Invalidated!=null) Invalidated(this, e);
4040 [EditorBrowsable(EditorBrowsableState.Advanced)]
4041 protected virtual void OnKeyDown(KeyEventArgs e) {
4042 if (KeyDown!=null) KeyDown(this, e);
4045 [EditorBrowsable(EditorBrowsableState.Advanced)]
4046 protected virtual void OnKeyPress(KeyPressEventArgs e) {
4047 if (KeyPress!=null) KeyPress(this, e);
4050 [EditorBrowsable(EditorBrowsableState.Advanced)]
4051 protected virtual void OnKeyUp(KeyEventArgs e) {
4052 if (KeyUp!=null) KeyUp(this, e);
4055 [EditorBrowsable(EditorBrowsableState.Advanced)]
4056 protected virtual void OnLayout(LayoutEventArgs levent) {
4057 if (Layout!=null) Layout(this, levent);
4060 [EditorBrowsable(EditorBrowsableState.Advanced)]
4061 protected virtual void OnLeave(EventArgs e) {
4062 if (Leave!=null) Leave(this, e);
4065 [EditorBrowsable(EditorBrowsableState.Advanced)]
4066 protected virtual void OnLocationChanged(EventArgs e) {
4068 if (LocationChanged!=null) LocationChanged(this, e);
4071 [EditorBrowsable(EditorBrowsableState.Advanced)]
4072 protected virtual void OnLostFocus(EventArgs e) {
4073 if (LostFocus!=null) LostFocus(this, e);
4076 [EditorBrowsable(EditorBrowsableState.Advanced)]
4077 protected virtual void OnMouseDown(MouseEventArgs e) {
4078 if (MouseDown!=null) MouseDown(this, e);
4081 [EditorBrowsable(EditorBrowsableState.Advanced)]
4082 protected virtual void OnMouseEnter(EventArgs e) {
4083 if (MouseEnter!=null) MouseEnter(this, e);
4086 [EditorBrowsable(EditorBrowsableState.Advanced)]
4087 protected virtual void OnMouseHover(EventArgs e) {
4088 if (MouseHover!=null) MouseHover(this, e);
4091 [EditorBrowsable(EditorBrowsableState.Advanced)]
4092 protected virtual void OnMouseLeave(EventArgs e) {
4093 if (MouseLeave!=null) MouseLeave(this, e);
4096 [EditorBrowsable(EditorBrowsableState.Advanced)]
4097 protected virtual void OnMouseMove(MouseEventArgs e) {
4098 if (MouseMove!=null) MouseMove(this, e);
4101 [EditorBrowsable(EditorBrowsableState.Advanced)]
4102 protected virtual void OnMouseUp(MouseEventArgs e) {
4103 if (MouseUp!=null) MouseUp(this, e);
4106 [EditorBrowsable(EditorBrowsableState.Advanced)]
4107 protected virtual void OnMouseWheel(MouseEventArgs e) {
4108 if (MouseWheel!=null) MouseWheel(this, e);
4111 [EditorBrowsable(EditorBrowsableState.Advanced)]
4112 protected virtual void OnMove(EventArgs e) {
4113 if (Move!=null) Move(this, e);
4116 [EditorBrowsable(EditorBrowsableState.Advanced)]
4117 protected virtual void OnNotifyMessage(Message m) {
4121 [EditorBrowsable(EditorBrowsableState.Advanced)]
4122 protected virtual void OnPaint(PaintEventArgs e) {
4123 if (Paint!=null) Paint(this, e);
4126 internal virtual void OnPaintInternal(PaintEventArgs e) {
4130 [EditorBrowsable(EditorBrowsableState.Advanced)]
4131 protected virtual void OnPaintBackground(PaintEventArgs pevent) {
4132 PaintControlBackground (pevent);
4135 [EditorBrowsable(EditorBrowsableState.Advanced)]
4136 protected virtual void OnParentBackColorChanged(EventArgs e) {
4137 if (background_color.IsEmpty && background_image==null) {
4139 OnBackColorChanged(e);
4143 [EditorBrowsable(EditorBrowsableState.Advanced)]
4144 protected virtual void OnParentBackgroundImageChanged(EventArgs e) {
4145 if (background_color.IsEmpty && background_image==null) {
4147 OnBackgroundImageChanged(e);
4151 [EditorBrowsable(EditorBrowsableState.Advanced)]
4152 protected virtual void OnParentBindingContextChanged(EventArgs e) {
4153 if (binding_context==null) {
4154 binding_context=Parent.binding_context;
4155 OnBindingContextChanged(e);
4159 [EditorBrowsable(EditorBrowsableState.Advanced)]
4160 protected virtual void OnParentChanged(EventArgs e) {
4161 if (ParentChanged!=null) ParentChanged(this, e);
4164 [EditorBrowsable(EditorBrowsableState.Advanced)]
4165 protected virtual void OnParentEnabledChanged(EventArgs e) {
4166 if (is_enabled != Parent.is_enabled) {
4167 is_enabled=Parent.is_enabled;
4169 if (EnabledChanged != null) {
4170 EnabledChanged(this, e);
4175 [EditorBrowsable(EditorBrowsableState.Advanced)]
4176 protected virtual void OnParentFontChanged(EventArgs e) {
4183 [EditorBrowsable(EditorBrowsableState.Advanced)]
4184 protected virtual void OnParentForeColorChanged(EventArgs e) {
4185 if (foreground_color.IsEmpty) {
4187 OnForeColorChanged(e);
4191 [EditorBrowsable(EditorBrowsableState.Advanced)]
4192 protected virtual void OnParentRightToLeftChanged(EventArgs e) {
4193 if (right_to_left==RightToLeft.Inherit) {
4195 OnRightToLeftChanged(e);
4199 [EditorBrowsable(EditorBrowsableState.Advanced)]
4200 protected virtual void OnParentVisibleChanged(EventArgs e) {
4202 OnVisibleChanged(e);
4206 [EditorBrowsable(EditorBrowsableState.Advanced)]
4207 protected virtual void OnQueryContinueDrag(QueryContinueDragEventArgs e) {
4208 if (QueryContinueDrag!=null) QueryContinueDrag(this, e);
4211 [EditorBrowsable(EditorBrowsableState.Advanced)]
4212 protected virtual void OnResize(EventArgs e) {
4213 if (Resize!=null) Resize(this, e);
4215 PerformLayout(this, "bounds");
4217 if (parent != null) {
4218 parent.PerformLayout();
4222 [EditorBrowsable(EditorBrowsableState.Advanced)]
4223 protected virtual void OnRightToLeftChanged(EventArgs e) {
4224 if (RightToLeftChanged!=null) RightToLeftChanged(this, e);
4225 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentRightToLeftChanged(e);
4228 [EditorBrowsable(EditorBrowsableState.Advanced)]
4229 protected virtual void OnSizeChanged(EventArgs e) {
4230 InvalidateBuffers ();
4232 if (SizeChanged!=null) SizeChanged(this, e);
4235 [EditorBrowsable(EditorBrowsableState.Advanced)]
4236 protected virtual void OnStyleChanged(EventArgs e) {
4237 if (StyleChanged!=null) StyleChanged(this, e);
4240 [EditorBrowsable(EditorBrowsableState.Advanced)]
4241 protected virtual void OnSystemColorsChanged(EventArgs e) {
4242 if (SystemColorsChanged!=null) SystemColorsChanged(this, e);
4245 [EditorBrowsable(EditorBrowsableState.Advanced)]
4246 protected virtual void OnTabIndexChanged(EventArgs e) {
4247 if (TabIndexChanged!=null) TabIndexChanged(this, e);
4250 [EditorBrowsable(EditorBrowsableState.Advanced)]
4251 protected virtual void OnTabStopChanged(EventArgs e) {
4252 if (TabStopChanged!=null) TabStopChanged(this, e);
4255 [EditorBrowsable(EditorBrowsableState.Advanced)]
4256 protected virtual void OnTextChanged(EventArgs e) {
4257 if (TextChanged!=null) TextChanged(this, e);
4260 [EditorBrowsable(EditorBrowsableState.Advanced)]
4261 protected virtual void OnValidated(EventArgs e) {
4262 if (Validated!=null) Validated(this, e);
4265 [EditorBrowsable(EditorBrowsableState.Advanced)]
4266 protected virtual void OnValidating(System.ComponentModel.CancelEventArgs e) {
4267 if (Validating!=null) Validating(this, e);
4270 [EditorBrowsable(EditorBrowsableState.Advanced)]
4271 protected virtual void OnVisibleChanged(EventArgs e) {
4278 if (bmp_mem!=null) {
4284 if (!this.IsHandleCreated) {
4285 this.CreateControl();
4291 if (VisibleChanged!=null) VisibleChanged(this, e);
4293 // We need to tell our kids
4294 for (int i=0; i<child_controls.Count; i++) {
4295 child_controls[i].OnParentVisibleChanged(e);
4298 #endregion // OnXXX methods
4301 public event EventHandler BackColorChanged;
4302 public event EventHandler BackgroundImageChanged;
4303 public event EventHandler BindingContextChanged;
4304 public event EventHandler CausesValidationChanged;
4305 public event UICuesEventHandler ChangeUICues;
4306 public event EventHandler Click;
4307 public event EventHandler ContextMenuChanged;
4309 [EditorBrowsable(EditorBrowsableState.Advanced)]
4311 public event ControlEventHandler ControlAdded;
4313 [EditorBrowsable(EditorBrowsableState.Advanced)]
4315 public event ControlEventHandler ControlRemoved;
4317 [MWFDescription("Fired when the cursor for the control has been changed"), MWFCategory("PropertyChanged")]
4318 public event EventHandler CursorChanged;
4319 public event EventHandler DockChanged;
4320 public event EventHandler DoubleClick;
4321 public event DragEventHandler DragDrop;
4322 public event DragEventHandler DragEnter;
4323 public event EventHandler DragLeave;
4324 public event DragEventHandler DragOver;
4325 public event EventHandler EnabledChanged;
4326 public event EventHandler Enter;
4327 public event EventHandler FontChanged;
4328 public event EventHandler ForeColorChanged;
4329 public event GiveFeedbackEventHandler GiveFeedback;
4331 [EditorBrowsable(EditorBrowsableState.Advanced)]
4333 public event EventHandler GotFocus;
4335 [EditorBrowsable(EditorBrowsableState.Advanced)]
4337 public event EventHandler HandleCreated;
4339 [EditorBrowsable(EditorBrowsableState.Advanced)]
4341 public event EventHandler HandleDestroyed;
4343 public event HelpEventHandler HelpRequested;
4344 public event EventHandler ImeModeChanged;
4346 [EditorBrowsable(EditorBrowsableState.Advanced)]
4348 public event InvalidateEventHandler Invalidated;
4350 public event KeyEventHandler KeyDown;
4351 public event KeyPressEventHandler KeyPress;
4352 public event KeyEventHandler KeyUp;
4353 public event LayoutEventHandler Layout;
4354 public event EventHandler Leave;
4355 public event EventHandler LocationChanged;
4357 [EditorBrowsable(EditorBrowsableState.Advanced)]
4359 public event EventHandler LostFocus;
4361 public event MouseEventHandler MouseDown;
4362 public event EventHandler MouseEnter;
4363 public event EventHandler MouseHover;
4364 public event EventHandler MouseLeave;
4365 public event MouseEventHandler MouseMove;
4366 public event MouseEventHandler MouseUp;
4368 [EditorBrowsable(EditorBrowsableState.Advanced)]
4370 public event MouseEventHandler MouseWheel;
4372 public event EventHandler Move;
4373 public event PaintEventHandler Paint;
4374 public event EventHandler ParentChanged;
4375 public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp;
4376 public event QueryContinueDragEventHandler QueryContinueDrag;
4377 public event EventHandler Resize;
4378 public event EventHandler RightToLeftChanged;
4379 public event EventHandler SizeChanged;
4380 public event EventHandler StyleChanged;
4381 public event EventHandler SystemColorsChanged;
4382 public event EventHandler TabIndexChanged;
4383 public event EventHandler TabStopChanged;
4384 public event EventHandler TextChanged;
4385 public event EventHandler Validated;
4386 public event CancelEventHandler Validating;
4387 public event EventHandler VisibleChanged;
4388 #endregion // Events