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 Novell, Inc.
23 // Peter Bartok pbartok@novell.com
26 // Aleksey Ryabchuk ryabchuk@yahoo.com
27 // Alexandre Pigolkine pigolkine@gmx.de
28 // Dennis Hayes dennish@raytek.com
29 // Jaak Simm jaaksimm@firm.ee
30 // John Sohn jsohn@columbus.rr.com
37 using System.ComponentModel;
38 using System.ComponentModel.Design;
39 using System.Collections;
40 using System.Diagnostics;
41 using System.Threading;
42 using System.Runtime.InteropServices;
43 using System.ComponentModel.Design.Serialization;
46 namespace System.Windows.Forms
48 [Designer("System.Windows.Forms.Design.ContolDesigner, System.Design")]
49 [DefaultProperty("Text")]
50 [DefaultEvent("Click")]
51 [DesignerSerializer("System.Windows.Forms.Design.ControlCodeDomSerializer, System.Design", "System.ComponentModel.Design.Serialization.CodeDomSerializer, System.Design")]
52 [ToolboxItemFilter("System.Windows.Forms")]
53 public class Control : Component, ISynchronizeInvoke, IWin32Window
55 #region Local Variables
58 internal Rectangle bounds; // bounding rectangle for control (client area + decorations)
59 internal object creator_thread; // thread that created the control
60 internal ControlNativeWindow window; // object for native window handle
61 internal string name; // for object naming
64 internal bool has_focus; // true if control has focus
65 internal bool is_visible; // true if control is visible
66 internal bool is_entered; // is the mouse inside the control?
67 internal bool is_enabled; // true if control is enabled (usable/not grayed out)
68 internal bool is_selected; // true if control is selected
69 internal bool is_accessible; // true if the control is visible to accessibility applications
70 internal bool is_captured; // tracks if the control has captured the mouse
71 internal bool is_toplevel; // tracks if the control is a toplevel window
72 internal bool is_recreating; // tracks if the handle for the control is being recreated
73 internal bool causes_validation; // tracks if validation is executed on changes
74 internal int tab_index; // position in tab order of siblings
75 internal bool tab_stop = true; // is the control a tab stop?
76 internal bool is_disposed; // has the window already been disposed?
77 internal Size client_size; // size of the client area (window excluding decorations)
78 internal Rectangle client_rect; // rectangle with the client area (window excluding decorations)
79 internal ControlStyles control_style; // rather win32-specific, style bits for control
80 internal ImeMode ime_mode = ImeMode.Inherit;
81 internal bool layout_pending; // true if our parent needs to re-layout us
82 internal object control_tag; // object that contains data about our control
83 internal int mouse_clicks; // Counter for mouse clicks
84 internal Cursor cursor; // Cursor for the window
87 internal Color foreground_color; // foreground color for control
88 internal Color background_color; // background color for control
89 internal Image background_image; // background image for control
90 internal Font font; // font for control
91 internal string text; // window/title text for control
94 internal AnchorStyles anchor_style; // anchoring requirements for our control
95 internal DockStyle dock_style; // docking requirements for our control (supercedes anchoring)
96 internal SizeF size_ratio; // size ratio of our control to it's parent; required for anchoring
97 internal Size prev_size; // previous size of the control; required for anchoring
99 // to be categorized...
100 static internal ArrayList controls = new ArrayList(); // All of the applications controls, in a flat list
101 internal ControlCollection child_controls; // our children
102 internal Control parent; // our parent control
103 internal AccessibleObject accessibility_object; // object that contains accessibility information about our control
104 internal BindingContext binding_context; // TODO
105 internal RightToLeft right_to_left; // drawing direction for control
106 internal int layout_suspended;
107 internal bool double_buffering;
108 internal ContextMenu context_menu; // Context menu associated with the control
110 private Graphics dc_mem; // Graphics context for double buffering
111 private Bitmap bmp_mem; // Bitmap for double buffering control
113 #endregion // Local Variables
115 #region Private Classes
116 // This helper class allows us to dispatch messages to Control.WndProc
117 internal class ControlNativeWindow : NativeWindow {
118 private Control owner;
120 public ControlNativeWindow(Control control) : base() {
125 public Control Owner {
131 static internal Control ControlFromHandle(IntPtr hWnd) {
132 ControlNativeWindow window;
134 window = (ControlNativeWindow)window_collection[hWnd];
139 protected override void WndProc(ref Message m) {
140 owner.WndProc(ref m);
145 #region Public Classes
146 public class ControlAccessibleObject : AccessibleObject {
147 #region ControlAccessibleObject Local Variables
148 private Control owner;
149 #endregion // ControlAccessibleObject Local Variables
151 #region ControlAccessibleObject Constructors
152 public ControlAccessibleObject(Control ownerControl) {
153 this.owner = ownerControl;
155 #endregion // ControlAccessibleObject Constructors
157 #region ControlAccessibleObject Public Instance Properties
158 public override string DefaultAction {
160 return base.DefaultAction;
164 public override string Description {
166 return base.Description;
170 public IntPtr Handle {
176 // We don't want to let them set it
180 public override string Help {
186 public override string KeyboardShortcut {
188 return base.KeyboardShortcut;
192 public override string Name {
202 public Control Owner {
208 public override AccessibleRole Role {
213 #endregion // ControlAccessibleObject Public Instance Properties
215 #region ControlAccessibleObject Public Instance Methods
216 public override int GetHelpTopic(out string FileName) {
217 return base.GetHelpTopic (out FileName);
220 [MonoTODO("Implement this and tie it into Control.AccessibilityNotifyClients")]
221 public void NotifyClients(AccessibleEvents accEvent) {
222 throw new NotImplementedException();
225 [MonoTODO("Implement this and tie it into Control.AccessibilityNotifyClients")]
226 public void NotifyClients(AccessibleEvents accEvent, int childID) {
227 throw new NotImplementedException();
230 public override string ToString() {
231 return "ControlAccessibleObject: Owner = " + owner.ToString() + ", Text: " + owner.text;
234 #endregion // ControlAccessibleObject Public Instance Methods
237 public class ControlCollection : IList, ICollection, ICloneable, IEnumerable {
238 #region ControlCollection Local Variables
239 internal ArrayList list;
240 internal Control owner;
241 #endregion // ControlCollection Local Variables
243 #region ControlCollection Public Constructor
244 public ControlCollection(Control owner) {
246 this.list=new ArrayList();
250 #region ControlCollection Public Instance Properties
257 public bool IsReadOnly {
259 return list.IsReadOnly;
263 public virtual Control this[int index] {
265 if (index < 0 || index >= list.Count) {
266 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
268 return (Control)list[index];
271 #endregion // ControlCollection Public Instance Properties
273 #region ControlCollection Private Instance Methods
274 public virtual void Add (Control value)
277 for (int i = 0; i < list.Count; i++) {
278 if (list [i] == value) {
279 // Do we need to do anything here?
284 if (value.tab_index == -1) {
290 end = owner.child_controls.Count;
291 for (int i = 0; i < end; i++) {
292 index = owner.child_controls[i].tab_index;
297 value.tab_index = use;
301 value.Parent = owner;
302 owner.UpdateZOrder();
303 owner.OnControlAdded(new ControlEventArgs(value));
306 public virtual void AddRange (Control[] controls)
308 if (controls == null)
309 throw new ArgumentNullException ("controls");
311 owner.SuspendLayout ();
314 for (int i = 0; i < controls.Length; i++)
317 owner.ResumeLayout ();
321 public virtual void Clear ()
323 owner.SuspendLayout();
324 for (int i = 0; i < list.Count; i++) {
325 owner.OnControlRemoved(new ControlEventArgs((Control)list[i]));
328 owner.ResumeLayout();
331 public virtual bool Contains (Control value)
333 return list.Contains (value);
336 public void CopyTo (Array array, int index)
338 list.CopyTo(array, index);
341 public override bool Equals(object other) {
342 if (other is ControlCollection && (((ControlCollection)other).owner==this.owner)) {
349 public int GetChildIndex(Control child) {
350 return GetChildIndex(child, false);
353 public int GetChildIndex(Control child, bool throwException) {
356 index=list.IndexOf(child);
358 if (index==-1 && throwException) {
359 throw new ArgumentException("Not a child control", "child");
364 public IEnumerator GetEnumerator() {
365 return list.GetEnumerator();
368 public override int GetHashCode() {
369 return base.GetHashCode();
372 public int IndexOf(Control control) {
373 return list.IndexOf(control);
376 public virtual void Remove(Control value) {
377 owner.OnControlRemoved(new ControlEventArgs(value));
379 owner.UpdateZOrder();
382 public void RemoveAt(int index) {
383 if (index<0 || index>=list.Count) {
384 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
387 owner.OnControlRemoved(new ControlEventArgs((Control)list[index]));
388 list.RemoveAt(index);
389 owner.UpdateZOrder();
392 public void SetChildIndex(Control child, int newIndex) {
395 old_index=list.IndexOf(child);
397 throw new ArgumentException("Not a child control", "child");
400 if (old_index==newIndex) {
406 if (newIndex>list.Count) {
409 list.Insert(newIndex, child);
411 owner.UpdateZOrder();
413 #endregion // ControlCollection Private Instance Methods
415 #region ControlCollection Interface Properties
416 object IList.this[int index] {
418 if (index<0 || index>=list.Count) {
419 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
425 if (!(value is Control)) {
426 throw new ArgumentException("Object of type Control required", "value");
429 list[index]=(Control)value;
433 bool IList.IsFixedSize {
439 bool IList.IsReadOnly {
441 return list.IsReadOnly;
445 bool ICollection.IsSynchronized {
447 return list.IsSynchronized;
451 object ICollection.SyncRoot {
453 return list.SyncRoot;
456 #endregion // ControlCollection Interface Properties
458 #region ControlCollection Interface Methods
459 int IList.Add(object value) {
461 throw new ArgumentNullException("value", "Cannot add null controls");
464 if (!(value is Control)) {
465 throw new ArgumentException("Object of type Control required", "value");
468 return list.Add(value);
471 bool IList.Contains(object value) {
472 if (!(value is Control)) {
473 throw new ArgumentException("Object of type Control required", "value");
476 return this.Contains((Control) value);
479 int IList.IndexOf(object value) {
480 if (!(value is Control)) {
481 throw new ArgumentException("Object of type Control required", "value");
484 return this.IndexOf((Control) value);
487 void IList.Insert(int index, object value) {
488 if (!(value is Control)) {
489 throw new ArgumentException("Object of type Control required", "value");
491 list.Insert(index, value);
494 void IList.Remove(object value) {
495 if (!(value is Control)) {
496 throw new ArgumentException("Object of type Control required", "value");
501 void ICollection.CopyTo(Array array, int index) {
503 list.CopyTo(array, index);
507 Object ICloneable.Clone() {
508 ControlCollection clone = new ControlCollection(this.owner);
509 clone.list=(ArrayList)list.Clone(); // FIXME: Do we need this?
512 #endregion // ControlCollection Interface Methods
514 #endregion // ControlCollection Class
516 #region Public Constructors
518 creator_thread = Thread.CurrentThread;
520 prev_size = Size.Empty;
521 anchor_style = AnchorStyles.Top | AnchorStyles.Left;
528 layout_pending = false;
530 causes_validation = true;
532 layout_suspended = 0;
533 double_buffering = true;
537 right_to_left = RightToLeft.Inherit;
539 control_style = ControlStyles.Selectable | ControlStyles.StandardClick | ControlStyles.StandardDoubleClick;
542 background_image = null;
546 child_controls = CreateControlsInstance();
547 client_size = new Size(DefaultSize.Width, DefaultSize.Height);
548 client_rect = new Rectangle(0, 0, DefaultSize.Width, DefaultSize.Height);
549 XplatUI.CalculateWindowRect(IntPtr.Zero, ref client_rect, CreateParams.Style, false, out bounds);
550 if ((CreateParams.Style & (int)WindowStyles.WS_CHILD) == 0) {
556 public Control(Control parent, string text) : this() {
561 public Control(Control parent, string text, int left, int top, int width, int height) : this() {
566 bounds.Height=height;
567 SetBoundsCore(left, top, width, height, BoundsSpecified.All);
571 public Control(string text) : this() {
575 public Control(string text, int left, int top, int width, int height) : this() {
579 bounds.Height=height;
580 SetBoundsCore(left, top, width, height, BoundsSpecified.All);
584 protected override void Dispose(bool disposing) {
597 OnHandleDestroyed(EventArgs.Empty);
598 controls.Remove(this);
600 #endregion // Public Constructors
602 #region Internal Properties
603 #endregion // Internal Properties
605 #region Private & Internal Methods
606 internal static IAsyncResult BeginInvokeInternal (Delegate method, object [] args) {
607 AsyncMethodResult result = new AsyncMethodResult ();
608 AsyncMethodData data = new AsyncMethodData ();
610 data.Method = method;
612 data.Result = new WeakReference (result);
614 XplatUI.SendAsyncMethod (data);
618 internal Graphics DeviceContext {
621 CreateBuffers(this.Width, this.Height);
627 internal Bitmap ImageBuffer {
630 CreateBuffers(this.Width, this.Height);
636 internal void CreateBuffers (int width, int height) {
637 if (double_buffering == false)
653 bmp_mem = new Bitmap (width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
654 dc_mem = Graphics.FromImage (bmp_mem);
657 internal void InvalidateBuffers ()
659 if (double_buffering == false)
671 internal static void SetChildColor(Control parent) {
674 for (int i=0; i < parent.child_controls.Count; i++) {
675 child=parent.child_controls[i];
676 if (child.IsHandleCreated) {
677 XplatUI.SetWindowBackground(child.window.Handle, child.BackColor);
679 if (child.child_controls.Count>0) {
680 SetChildColor(child);
686 internal bool Select(Control control) {
688 IContainerControl container;
690 if (control == null) {
694 parent = control.parent;
696 if (((control.control_style & ControlStyles.Selectable) !=0) && (parent != null)) {
697 while (parent != null) {
698 if (!parent.is_visible || !parent.is_enabled) {
701 parent = parent.parent;
705 control.is_selected = true;
707 XplatUI.SetFocus(control.window.Handle);
708 container = GetContainerControl();
709 if (container != null) {
710 container.ActiveControl = control;
716 private Control FindTabStop(Control control, bool forward) {
717 if (control == null) {
725 internal virtual void DoDefaultAction() {
726 // Only here to be overriden by our actual controls; this is needed by the accessibility class
729 internal static int LowOrder (int param) {
730 return (param & 0xffff);
733 internal static int HighOrder (int param) {
734 return (param >> 16);
737 internal static MouseButtons FromParamToMouseButtons (int param) {
738 MouseButtons buttons = MouseButtons.None;
740 if ((param & (int) MsgButtons.MK_LBUTTON) != 0)
741 buttons |= MouseButtons.Left;
743 if ((param & (int) MsgButtons.MK_MBUTTON) != 0)
744 buttons |= MouseButtons.Middle;
746 if ((param & (int) MsgButtons.MK_RBUTTON) != 0)
747 buttons |= MouseButtons.Right;
753 private static Control FindFlatForward(Control container, Control start) {
759 end = container.child_controls.Count;
762 index = start.tab_index;
767 for (int i = 0; i < end; i++) {
769 if (container.child_controls[i].tab_index > index) {
770 found = container.child_controls[i];
772 } else if (found.tab_index > container.child_controls[i].tab_index) {
773 if (container.child_controls[i].tab_index > index) {
774 found = container.child_controls[i];
781 private static Control FindControlForward(Control container, Control start) {
788 if ((start is IContainerControl) || start.GetStyle(ControlStyles.ContainerControl)) {
789 found = FindControlForward(start, null);
796 while (p != container) {
797 found = FindFlatForward(p, start);
805 return FindFlatForward(container, start);
808 private static Control FindFlatBackward(Control container, Control start) {
814 end = container.child_controls.Count;
817 index = start.tab_index;
819 // FIXME: Possible speed-up: Keep the highest taborder index in the container
821 for (int i = 0; i < end; i++) {
822 if (container.child_controls[i].tab_index > index) {
823 index = container.child_controls[i].tab_index;
829 for (int i = 0; i < end; i++) {
831 if (container.child_controls[i].tab_index < index) {
832 found = container.child_controls[i];
834 } else if (found.tab_index < container.child_controls[i].tab_index) {
835 if (container.child_controls[i].tab_index < index) {
836 found = container.child_controls[i];
843 private static Control FindControlBackward(Control container, Control start) {
849 found = FindFlatBackward(start.parent, start);
850 if (found == null && start.parent != container) {
855 found = FindFlatBackward(container, start);
858 while ((found != null) && ((found is IContainerControl) || found.GetStyle(ControlStyles.ContainerControl))) {
859 found = FindControlBackward(found, null);
868 private void HandleClick(int clicks) {
869 if (GetStyle(ControlStyles.StandardClick)) {
871 if (GetStyle(ControlStyles.StandardDoubleClick)) {
872 OnDoubleClick(EventArgs.Empty);
874 OnClick(EventArgs.Empty);
877 OnClick(EventArgs.Empty);
881 #endregion // Private & Internal Methods
883 #region Public Static Properties
884 public static Color DefaultBackColor {
886 return ThemeEngine.Current.DefaultControlBackColor;
890 public static Font DefaultFont {
892 return ThemeEngine.Current.DefaultFont;
896 public static Color DefaultForeColor {
898 return ThemeEngine.Current.DefaultControlForeColor;
902 public static Keys ModifierKeys {
904 return XplatUI.State.ModifierKeys;
908 public static MouseButtons MouseButtons {
910 return XplatUI.State.MouseButtons;
914 public static Point MousePosition {
916 return Cursor.Position;
919 #endregion // Public Static Properties
921 #region Public Instance Properties
922 [EditorBrowsable(EditorBrowsableState.Advanced)]
924 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
925 public AccessibleObject AccessibilityObject {
927 if (accessibility_object==null) {
928 accessibility_object=CreateAccessibilityInstance();
930 return accessibility_object;
934 [EditorBrowsable(EditorBrowsableState.Advanced)]
936 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
937 public string AccessibleDefaultActionDescription {
939 return AccessibilityObject.default_action;
943 AccessibilityObject.default_action=value;
949 public string AccessibleDescription {
951 return AccessibilityObject.description;
955 AccessibilityObject.description=value;
961 public string AccessibleName {
963 return AccessibilityObject.Name;
967 AccessibilityObject.Name=value;
972 public AccessibleRole AccessibleRole {
974 return AccessibilityObject.role;
978 AccessibilityObject.role=value;
982 [DefaultValue(false)]
983 public virtual bool AllowDrop {
985 return XplatUI.State.DropTarget;
989 XplatUI.State.DropTarget=value;
994 [RefreshProperties(RefreshProperties.Repaint)]
995 [DefaultValue(AnchorStyles.Top | AnchorStyles.Left)]
996 public virtual AnchorStyles Anchor {
1004 if (parent != null) {
1005 parent.PerformLayout(this, "Parent");
1011 public virtual Color BackColor {
1013 if (background_color.IsEmpty) {
1015 return parent.BackColor;
1017 return DefaultBackColor;
1019 return background_color;
1023 background_color=value;
1024 if (this.IsHandleCreated) {
1025 XplatUI.SetWindowBackground(this.window.Handle, value);
1027 SetChildColor(this);
1028 OnBackColorChanged(EventArgs.Empty);
1034 [DefaultValue(null)]
1035 public virtual Image BackgroundImage {
1037 return background_image;
1041 if (background_image!=value) {
1042 background_image=value;
1043 OnBackgroundImageChanged(EventArgs.Empty);
1048 [EditorBrowsable(EditorBrowsableState.Advanced)]
1050 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1051 public virtual BindingContext BindingContext {
1053 return binding_context;
1057 if (binding_context != value) {
1058 binding_context = value;
1059 OnBindingContextChanged(EventArgs.Empty);
1064 [EditorBrowsable(EditorBrowsableState.Advanced)]
1066 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1069 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1070 return ((Form)this).form_parent_window.Bottom;
1073 return bounds.Y+bounds.Height;
1077 [EditorBrowsable(EditorBrowsableState.Advanced)]
1079 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1080 public Rectangle Bounds {
1086 SetBoundsCore(value.Left, value.Top, value.Width, value.Height, BoundsSpecified.All);
1090 [EditorBrowsable(EditorBrowsableState.Advanced)]
1092 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1093 public bool CanFocus {
1095 if (is_visible && is_enabled && GetStyle(ControlStyles.Selectable)) {
1102 [EditorBrowsable(EditorBrowsableState.Advanced)]
1104 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1105 public bool CanSelect {
1109 if (!GetStyle(ControlStyles.Selectable) || this.parent == null) {
1113 parent = this.parent;
1114 while (parent != null) {
1115 if (!parent.is_visible || !parent.is_enabled) {
1119 parent = parent.parent;
1125 [EditorBrowsable(EditorBrowsableState.Advanced)]
1127 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1128 public bool Capture {
1130 return this.is_captured;
1134 if (this.IsHandleCreated) {
1135 if (value && !is_captured) {
1137 XplatUI.GrabWindow(this.window.Handle, IntPtr.Zero);
1138 } else if (!value && is_captured) {
1139 XplatUI.ReleaseWindow(this.window.Handle);
1140 is_captured = false;
1146 [DefaultValue(true)]
1147 public bool CausesValidation {
1149 return this.causes_validation;
1153 if (this.causes_validation != value) {
1154 causes_validation = value;
1155 OnCausesValidationChanged(EventArgs.Empty);
1160 [EditorBrowsable(EditorBrowsableState.Advanced)]
1162 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1163 public Rectangle ClientRectangle {
1165 client_rect.Width = client_size.Width;
1166 client_rect.Height = client_size.Height;
1171 [EditorBrowsable(EditorBrowsableState.Advanced)]
1173 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1174 public Size ClientSize {
1177 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1178 return ((Form)this).form_parent_window.ClientSize;
1186 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1187 ((Form)this).form_parent_window.ClientSize = value;
1191 this.SetClientSizeCore(value.Width, value.Height);
1195 [EditorBrowsable(EditorBrowsableState.Advanced)]
1197 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1198 [DescriptionAttribute("ControlCompanyNameDescr")]
1199 public String CompanyName {
1201 return "Mono Project, Novell, Inc.";
1205 [EditorBrowsable(EditorBrowsableState.Advanced)]
1207 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1208 public bool ContainsFocus {
1214 for (int i=0; i < child_controls.Count; i++) {
1215 if (child_controls[i].ContainsFocus) {
1223 [DefaultValue(null)]
1224 public virtual ContextMenu ContextMenu {
1226 return context_menu;
1230 if (context_menu != value) {
1231 context_menu = value;
1232 OnContextMenuChanged(EventArgs.Empty);
1238 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
1239 public ControlCollection Controls {
1241 return this.child_controls;
1245 [EditorBrowsable(EditorBrowsableState.Advanced)]
1247 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1248 public bool Created {
1250 if (!this.is_disposed && (this.window.Handle != IntPtr.Zero)) {
1257 [AmbientValue(null)]
1258 public virtual Cursor Cursor {
1260 if (cursor != null) {
1264 if (parent != null) {
1265 return parent.Cursor;
1268 return Cursors.Default;
1272 if (cursor != value) {
1277 pt = Cursor.Position;
1278 if (bounds.Contains(pt)) {
1279 if (GetChildAtPoint(pt) == null) {
1280 if (cursor != null) {
1281 XplatUI.SetCursor(window.Handle, cursor.handle);
1283 if (parent != null) {
1284 XplatUI.SetCursor(window.Handle, parent.Cursor.handle);
1286 XplatUI.SetCursor(window.Handle, Cursors.def.handle);
1292 OnCursorChanged(EventArgs.Empty);
1297 #if haveDataBindings
1298 [EditorBrowsable(EditorBrowsableState.Advanced)]
1300 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1301 public ControlBindingsCollection DataBindings {
1303 throw new NotImplementedException();
1308 [EditorBrowsable(EditorBrowsableState.Advanced)]
1310 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1311 public virtual Rectangle DisplayRectangle {
1313 return ClientRectangle;
1317 [EditorBrowsable(EditorBrowsableState.Advanced)]
1319 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1320 public bool Disposing {
1327 [RefreshProperties(RefreshProperties.Repaint)]
1328 [DefaultValue(DockStyle.None)]
1329 public virtual DockStyle Dock {
1335 if (dock_style == value) {
1341 if (parent != null) {
1342 parent.PerformLayout(this, "Parent");
1345 OnDockChanged(EventArgs.Empty);
1351 public bool Enabled {
1357 if (is_enabled == value) {
1363 OnEnabledChanged (EventArgs.Empty);
1367 [EditorBrowsable(EditorBrowsableState.Advanced)]
1369 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1370 public virtual bool Focused {
1372 return this.has_focus;
1377 [AmbientValue(null)]
1379 public virtual Font Font {
1385 if (Parent != null && Parent.Font != null) {
1393 if (font == value) {
1399 OnFontChanged (EventArgs.Empty);
1404 public virtual Color ForeColor {
1406 if (foreground_color.IsEmpty) {
1408 return parent.ForeColor;
1410 return DefaultForeColor;
1412 return foreground_color;
1416 if (foreground_color != value) {
1417 foreground_color=value;
1419 OnForeColorChanged(EventArgs.Empty);
1426 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1427 public IntPtr Handle { // IWin32Window
1429 if (!IsHandleCreated) {
1432 return window.Handle;
1436 [EditorBrowsable(EditorBrowsableState.Advanced)]
1438 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1439 public bool HasChildren {
1441 if (this.child_controls.Count>0) {
1448 [EditorBrowsable(EditorBrowsableState.Always)]
1450 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1453 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1454 return ((Form)this).form_parent_window.Height;
1456 return this.bounds.Height;
1460 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1461 ((Form)this).form_parent_window.Height = value;
1465 SetBoundsCore(bounds.X, bounds.Y, bounds.Width, value, BoundsSpecified.Height);
1469 [AmbientValue(ImeMode.Inherit)]
1471 public ImeMode ImeMode {
1477 if (ime_mode != value) {
1480 OnImeModeChanged(EventArgs.Empty);
1485 [EditorBrowsable(EditorBrowsableState.Advanced)]
1487 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1488 public bool InvokeRequired { // ISynchronizeInvoke
1490 if (creator_thread!=Thread.CurrentThread) {
1497 [EditorBrowsable(EditorBrowsableState.Advanced)]
1499 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1500 public bool IsAccessible {
1502 return is_accessible;
1506 is_accessible = value;
1510 [EditorBrowsable(EditorBrowsableState.Advanced)]
1512 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1513 public bool IsDisposed {
1515 return this.is_disposed;
1519 [EditorBrowsable(EditorBrowsableState.Advanced)]
1521 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1522 public bool IsHandleCreated {
1524 if ((window!=null) && (window.Handle!=IntPtr.Zero)) {
1532 [EditorBrowsable(EditorBrowsableState.Always)]
1534 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1537 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1538 return ((Form)this).form_parent_window.Left;
1541 return this.bounds.X;
1545 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1546 ((Form)this).form_parent_window.Left = value;
1550 SetBoundsCore(value, bounds.Y, bounds.Width, bounds.Height, BoundsSpecified.X);
1555 public Point Location {
1557 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1558 return ((Form)this).form_parent_window.Location;
1560 return new Point(bounds.X, bounds.Y);
1564 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1565 ((Form)this).form_parent_window.Location = value;
1569 SetBoundsCore(value.X, value.Y, bounds.Width, bounds.Height, BoundsSpecified.Location);
1574 public string Name {
1585 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1586 public Control Parent {
1592 if (value == this) {
1593 throw new ArgumentException("A circular control reference has been made. A control cannot be owned or parented to itself.");
1596 if (parent!=value) {
1598 parent.Controls.Remove(this);
1603 if (!parent.Controls.Contains(this)) {
1604 parent.Controls.Add(this);
1607 XplatUI.SetParent(Handle, value.Handle);
1611 OnParentChanged(EventArgs.Empty);
1616 [EditorBrowsable(EditorBrowsableState.Advanced)]
1618 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1619 public string ProductName {
1621 return "Novell Mono MWF";
1625 [EditorBrowsable(EditorBrowsableState.Advanced)]
1627 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1628 public string ProductVersion {
1630 return "1.1.4322.573";
1634 [EditorBrowsable(EditorBrowsableState.Advanced)]
1636 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1637 public bool RecreatingHandle {
1639 return is_recreating;
1643 [EditorBrowsable(EditorBrowsableState.Advanced)]
1645 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1646 public Region Region {
1648 return new Region(this.bounds);
1655 g = this.CreateGraphics();
1656 r = value.GetBounds(g);
1658 SetBounds((int)r.X, (int)r.Y, (int)r.Width, (int)r.Height);
1664 [EditorBrowsable(EditorBrowsableState.Advanced)]
1666 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1669 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1670 return ((Form)this).form_parent_window.Right;
1673 return this.bounds.X+this.bounds.Width;
1677 [AmbientValue(RightToLeft.Inherit)]
1679 public virtual RightToLeft RightToLeft {
1681 return right_to_left;
1685 if (value != right_to_left) {
1686 right_to_left = value;
1687 OnRightToLeftChanged(EventArgs.Empty);
1692 [EditorBrowsable(EditorBrowsableState.Advanced)]
1693 public override ISite Site {
1706 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1707 return ((Form)this).form_parent_window.Size;
1709 return new Size(Width, Height);
1713 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1714 ((Form)this).form_parent_window.Size = value;
1717 SetBoundsCore(bounds.X, bounds.Y, value.Width, value.Height, BoundsSpecified.Size);
1722 [MergableProperty(false)]
1723 public int TabIndex {
1725 if (tab_index != -1) {
1732 if (tab_index != value) {
1734 OnTabIndexChanged(EventArgs.Empty);
1740 [DefaultValue(true)]
1741 public bool TabStop {
1747 if (tab_stop != value) {
1749 OnTabStopChanged(EventArgs.Empty);
1754 [Localizable(false)]
1756 [TypeConverter(typeof(StringConverter))]
1757 [DefaultValue(null)]
1764 control_tag = value;
1770 [BindableAttribute(true)]
1771 public virtual string Text {
1777 if (value == null) {
1778 value = String.Empty;
1783 XplatUI.Text(Handle, text);
1784 // FIXME: Do we need a Refresh() here?
1785 OnTextChanged (EventArgs.Empty);
1790 [EditorBrowsable(EditorBrowsableState.Advanced)]
1792 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1795 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1796 return ((Form)this).form_parent_window.Top;
1798 return this.bounds.Y;
1802 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1803 ((Form)this).form_parent_window.Top = value;
1807 SetBoundsCore(bounds.X, value, bounds.Width, bounds.Height, BoundsSpecified.Y);
1811 [EditorBrowsable(EditorBrowsableState.Advanced)]
1813 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1814 public Control TopLevelControl {
1818 while (p.parent != null) {
1827 public bool Visible {
1829 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1830 return ((Form)this).form_parent_window.Visible;
1840 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1841 ((Form)this).form_parent_window.Visible = value;
1845 SetVisibleCore(value);
1849 [EditorBrowsable(EditorBrowsableState.Always)]
1851 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1854 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1855 return ((Form)this).form_parent_window.Width;
1857 return this.bounds.Width;
1861 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1862 ((Form)this).form_parent_window.Width = value;
1866 SetBoundsCore(bounds.X, bounds.Y, value, bounds.Height, BoundsSpecified.Width);
1870 [EditorBrowsable(EditorBrowsableState.Never)]
1872 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1873 public IWindowTarget WindowTarget {
1882 #endregion // Public Instance Properties
1884 #region Protected Instance Properties
1885 protected virtual CreateParams CreateParams {
1887 CreateParams create_params = new CreateParams();
1889 create_params.Caption = Text;
1890 create_params.X = Left;
1891 create_params.Y = Top;
1892 create_params.Width = Width;
1893 create_params.Height = Height;
1895 create_params.ClassName = XplatUI.DefaultClassName;
1896 create_params.ClassStyle = 0;
1897 create_params.ExStyle = 0;
1898 create_params.Param = 0;
1901 create_params.Parent = parent.Handle;
1904 create_params.Style = (int)WindowStyles.WS_CHILD | (int)WindowStyles.WS_CLIPCHILDREN | (int)WindowStyles.WS_CLIPSIBLINGS;
1907 create_params.Style |= (int)WindowStyles.WS_VISIBLE;
1910 return create_params;
1914 protected virtual ImeMode DefaultImeMode {
1916 return ImeMode.Inherit;
1920 protected virtual Size DefaultSize {
1922 return new Size(100, 23);
1926 protected int FontHeight {
1936 protected bool RenderRightToLeft {
1938 return (this.right_to_left == RightToLeft.Yes);
1942 protected bool ResizeRedraw {
1944 return GetStyle(ControlStyles.ResizeRedraw);
1948 SetStyle(ControlStyles.ResizeRedraw, value);
1952 [EditorBrowsable(EditorBrowsableState.Advanced)]
1954 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1955 protected virtual bool ShowFocusCues {
1961 [EditorBrowsable(EditorBrowsableState.Advanced)]
1963 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1964 protected bool ShowKeyboardCues {
1969 #endregion // Protected Instance Properties
1971 #region Public Static Methods
1972 [EditorBrowsable(EditorBrowsableState.Advanced)]
1973 public static Control FromChildHandle(IntPtr handle) {
1974 IEnumerator control = Control.controls.GetEnumerator();
1976 while (control.MoveNext()) {
1977 if (((Control)control.Current).window.Handle == handle) {
1979 if (((Control)control.Current).Parent != null) {
1980 return ((Control)control.Current).Parent;
1987 [EditorBrowsable(EditorBrowsableState.Advanced)]
1988 public static Control FromHandle(IntPtr handle) {
1989 IEnumerator control = Control.controls.GetEnumerator();
1991 while (control.MoveNext()) {
1992 if (((Control)control.Current).window.Handle == handle) {
1994 return ((Control)control.Current);
2000 public static bool IsMnemonic(char charCode, string text) {
2003 amp = text.IndexOf('&');
2006 if (amp + 1 < text.Length) {
2007 if (text[amp + 1] != '&') {
2008 if (Char.ToUpper(charCode) == Char.ToUpper(text.ToCharArray(amp + 1, 1)[0])) {
2018 #region Protected Static Methods
2019 [EditorBrowsable(EditorBrowsableState.Advanced)]
2020 protected static bool ReflectMessage(IntPtr hWnd, ref Message m) {
2023 c = Control.FromHandle(hWnd);
2033 #region Public Instance Methods
2034 [EditorBrowsable(EditorBrowsableState.Advanced)]
2035 public IAsyncResult BeginInvoke(Delegate method) {
2036 return BeginInvokeInternal(method, null);
2039 [EditorBrowsable(EditorBrowsableState.Advanced)]
2040 public IAsyncResult BeginInvoke (Delegate method, object[] args) {
2041 return BeginInvokeInternal (method, args);
2044 public void BringToFront() {
2045 if ((parent != null) && (parent.child_controls[0]!=this)) {
2046 if (parent.child_controls.Contains(this)) {
2047 parent.child_controls.SetChildIndex(this, 0);
2051 XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, true, false);
2053 if (parent != null) {
2058 public bool Contains(Control ctl) {
2059 while (ctl != null) {
2068 public void CreateControl() {
2070 if (!IsHandleCreated)
2073 for (int i=0; i<child_controls.Count; i++) {
2074 child_controls[i].CreateControl();
2079 public Graphics CreateGraphics() {
2080 if (!IsHandleCreated) {
2081 this.CreateHandle();
2083 return Graphics.FromHwnd(this.window.Handle);
2086 [MonoTODO("Come up with cross platform drag-drop driver interface")]
2087 public DragDropEffects DoDragDrop(object data, DragDropEffects allowedEffects) {
2088 return DragDropEffects.None;
2091 [EditorBrowsable(EditorBrowsableState.Advanced)]
2092 public object EndInvoke (IAsyncResult async_result) {
2093 AsyncMethodResult result = (AsyncMethodResult) async_result;
2094 return result.EndInvoke ();
2097 public Form FindForm() {
2110 public bool Focus() {
2111 if (IsHandleCreated && !has_focus) {
2112 XplatUI.SetFocus(window.Handle);
2118 public Control GetChildAtPoint(Point pt) {
2119 // Microsoft's version of this function doesn't seem to work, so I can't check
2120 // if we only consider children or also grandchildren, etc.
2121 // I'm gonna say 'children only'
2122 for (int i=0; i<child_controls.Count; i++) {
2123 if (child_controls[i].Bounds.Contains(pt)) {
2124 return child_controls[i];
2130 public IContainerControl GetContainerControl() {
2131 Control current = this;
2133 while (current!=null) {
2134 if ((current is IContainerControl) && ((current.control_style & ControlStyles.ContainerControl)!=0)) {
2135 return (IContainerControl)current;
2137 current = current.parent;
2142 public Control GetNextControl(Control ctl, bool forward) {
2143 // If we're not a container we don't play
2144 if (!(this is IContainerControl) && !this.GetStyle(ControlStyles.ContainerControl)) {
2148 // If ctl is not contained by this, we start at the first child of this
2149 if (!this.Contains(ctl)) {
2153 // Search through our controls, starting at ctl, stepping into children as we encounter them
2154 // try to find the control with the tabindex closest to our own, or, if we're looking into
2155 // child controls, the one with the smallest tabindex
2157 return FindControlForward(this, ctl);
2159 return FindControlBackward(this, ctl);
2162 public void Hide() {
2163 this.Visible = false;
2166 public void Invalidate() {
2167 Invalidate(ClientRectangle, false);
2170 public void Invalidate(bool invalidateChildren) {
2171 Invalidate(ClientRectangle, invalidateChildren);
2174 public void Invalidate(System.Drawing.Rectangle rc) {
2175 Invalidate(rc, false);
2178 public void Invalidate(System.Drawing.Rectangle rc, bool invalidateChildren) {
2179 if (!IsHandleCreated || !Visible) {
2183 NotifyInvalidate(rc);
2185 XplatUI.Invalidate(Handle, rc, !GetStyle (ControlStyles.AllPaintingInWmPaint));
2187 if (invalidateChildren) {
2188 for (int i=0; i<child_controls.Count; i++) child_controls[i].Invalidate();
2190 OnInvalidated(new InvalidateEventArgs(rc));
2193 public void Invalidate(System.Drawing.Region region) {
2194 Invalidate(region, false);
2197 [MonoTODO("Figure out if GetRegionScans is usable")]
2198 public void Invalidate(System.Drawing.Region region, bool invalidateChildren) {
2199 throw new NotImplementedException();
2201 // FIXME - should use the GetRegionScans function of the region to invalidate each area
2202 //if (invalidateChildren) {
2203 // for (int i=0; i<child_controls.Count; i++) child_controls[i].Invalidate();
2207 public object Invoke (Delegate method) {
2208 return Invoke(method, null);
2211 public object Invoke (Delegate method, object[] args) {
2212 IAsyncResult result = BeginInvoke (method, args);
2213 return EndInvoke(result);
2216 [EditorBrowsable(EditorBrowsableState.Advanced)]
2217 public void PerformLayout() {
2218 PerformLayout(null, null);
2221 [EditorBrowsable(EditorBrowsableState.Advanced)]
2222 public void PerformLayout(Control affectedControl, string affectedProperty) {
2223 LayoutEventArgs levent = new LayoutEventArgs(affectedControl, affectedProperty);
2225 if (layout_suspended>0) {
2226 layout_pending = true;
2230 layout_pending = false;
2232 // Prevent us from getting messed up
2235 // Perform all Dock and Anchor calculations
2238 AnchorStyles anchor;
2243 space=this.DisplayRectangle;
2244 if (prev_size != Size.Empty) {
2245 diff_width = space.Width - prev_size.Width;
2246 diff_height = space.Height - prev_size.Height;
2252 // Deal with docking; go through in reverse, MS docs say that lowest Z-order is closest to edge
2253 for (int i = child_controls.Count - 1; i >= 0; i--) {
2254 child=child_controls[i];
2255 switch (child.Dock) {
2256 case DockStyle.None: {
2261 case DockStyle.Left: {
2262 child.SetBounds(space.Left, space.Y, child.Width, space.Height);
2263 space.X+=child.Width;
2264 space.Width-=child.Width;
2268 case DockStyle.Top: {
2269 child.SetBounds(space.Left, space.Y, space.Width, child.Height);
2270 space.Y+=child.Height;
2271 space.Height-=child.Height;
2275 case DockStyle.Right: {
2276 child.SetBounds(space.Right-child.Width, space.Y, child.Width, space.Height);
2277 space.Width-=child.Width;
2281 case DockStyle.Bottom: {
2282 child.SetBounds(space.Left, space.Bottom-child.Height, space.Width, child.Height);
2283 space.Height-=child.Height;
2287 case DockStyle.Fill: {
2288 child.SetBounds(space.Left, space.Top, space.Width, space.Height);
2296 space=this.DisplayRectangle;
2298 // Deal with anchoring
2299 for (int i=0; i < child_controls.Count; i++) {
2305 child=child_controls[i];
2306 anchor=child.Anchor;
2311 height=child.Height;
2313 // If the control is docked we don't need to do anything
2314 if (child.Dock != DockStyle.None) {
2318 if ((anchor & AnchorStyles.Left) !=0 ) {
2319 if ((anchor & AnchorStyles.Right) != 0) {
2320 // Anchoring to left and right
2321 width=width+diff_width;
2325 } else if ((anchor & AnchorStyles.Right) != 0) {
2331 if ((anchor & AnchorStyles.Top) !=0 ) {
2332 if ((anchor & AnchorStyles.Bottom) != 0) {
2333 height+=diff_height;
2337 } else if ((anchor & AnchorStyles.Bottom) != 0) {
2352 child.SetBounds(left, top, width, height);
2355 // Let everyone know
2359 // Need to make sure we decremend layout_suspended
2365 public Point PointToClient (Point p) {
2369 XplatUI.ScreenToClient (Handle, ref x, ref y);
2371 return new Point (x, y);
2374 public Point PointToScreen(Point p) {
2378 XplatUI.ClientToScreen(Handle, ref x, ref y);
2380 return new Point(x, y);
2383 public virtual bool PreProcessMessage(ref Message msg) {
2386 if (msg.Msg == (int)Msg.WM_KEYDOWN) {
2387 key_data = (Keys)msg.WParam.ToInt32();
2388 if (!ProcessCmdKey(ref msg, key_data)) {
2389 if (IsInputKey(key_data)) {
2393 return ProcessDialogKey(key_data);
2397 } else if (msg.Msg == (int)Msg.WM_CHAR) {
2398 if (IsInputChar((char)msg.WParam)) {
2402 return ProcessDialogChar((char)msg.WParam);
2408 public Rectangle RectangleToClient(Rectangle r) {
2409 return new Rectangle(PointToClient(r.Location), r.Size);
2412 public Rectangle RectangleToScreen(Rectangle r) {
2413 return new Rectangle(PointToScreen(r.Location), r.Size);
2416 public virtual void Refresh() {
2417 if (IsHandleCreated == true) {
2419 XplatUI.UpdateWindow(window.Handle);
2423 [EditorBrowsable(EditorBrowsableState.Never)]
2424 public virtual void ResetBackColor() {
2425 background_color = Color.Empty;
2428 #if haveDataBindings
2429 [EditorBrowsable(EditorBrowsableState.Never)]
2431 public void ResetBindings() {
2436 [EditorBrowsable(EditorBrowsableState.Never)]
2437 public virtual void ResetCursor() {
2441 [EditorBrowsable(EditorBrowsableState.Never)]
2442 public virtual void ResetFont() {
2446 [EditorBrowsable(EditorBrowsableState.Never)]
2447 public virtual void ResetForeColor() {
2448 foreground_color = Color.Empty;
2451 [EditorBrowsable(EditorBrowsableState.Never)]
2452 public void ResetImeMode() {
2453 ime_mode = DefaultImeMode;
2456 [EditorBrowsable(EditorBrowsableState.Never)]
2457 public virtual void ResetRightToLeft() {
2458 right_to_left = RightToLeft.Inherit;
2461 public virtual void ResetText() {
2465 public void ResumeLayout() {
2466 ResumeLayout (true);
2469 public void ResumeLayout(bool performLayout) {
2472 if (layout_suspended > 0) {
2476 if (performLayout || layout_pending) {
2481 public void Scale(float ratio) {
2482 ScaleCore(ratio, ratio);
2485 public void Scale(float dx, float dy) {
2489 public void Select() {
2490 Select(false, false);
2493 public bool SelectNextControl(Control ctl, bool forward, bool tabStopOnly, bool nested, bool wrap) {
2498 c = GetNextControl(c, forward);
2507 if (c.CanSelect && ((c.parent == this) || nested) && (c.tab_stop || !tabStopOnly)) {
2511 } while (c != ctl); // If we wrap back to ourselves we stop
2516 public void SendToBack() {
2517 if ((parent != null) && (parent.child_controls[parent.child_controls.Count-1]!=this)) {
2518 if (parent.child_controls.Contains(this)) {
2519 parent.child_controls.SetChildIndex(this, parent.child_controls.Count);
2523 XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, false, true);
2524 if (parent != null) {
2529 public void SetBounds(int x, int y, int width, int height) {
2530 SetBoundsCore(x, y, width, height, BoundsSpecified.All);
2533 public void SetBounds(int x, int y, int width, int height, BoundsSpecified specified) {
2534 SetBoundsCore(x, y, width, height, specified);
2537 public void Show() {
2538 if (!IsHandleCreated) {
2539 this.CreateHandle();
2545 public void SuspendLayout() {
2549 public void Update() {
2550 XplatUI.UpdateWindow(window.Handle);
2552 #endregion // Public Instance Methods
2554 #region Protected Instance Methods
2555 [EditorBrowsable(EditorBrowsableState.Advanced)]
2556 [MonoTODO("Implement this and tie it into Control.ControlAccessibleObject.NotifyClients")]
2557 protected void AccessibilityNotifyClients(AccessibleEvents accEvent, int childID) {
2558 throw new NotImplementedException();
2561 [EditorBrowsable(EditorBrowsableState.Advanced)]
2562 protected virtual AccessibleObject CreateAccessibilityInstance() {
2563 return new Control.ControlAccessibleObject(this);
2566 [EditorBrowsable(EditorBrowsableState.Advanced)]
2567 protected virtual ControlCollection CreateControlsInstance() {
2568 return new ControlCollection(this);
2571 [EditorBrowsable(EditorBrowsableState.Advanced)]
2572 protected virtual void CreateHandle() {
2574 throw new ObjectDisposedException(Name);
2577 if (IsHandleCreated) {
2582 window = new ControlNativeWindow(this);
2583 window.CreateHandle(CreateParams);
2585 // Find out where the window manager placed us
2590 if (window.Handle!=IntPtr.Zero) {
2591 if (!controls.Contains(window.Handle)) {
2595 creator_thread = Thread.CurrentThread;
2597 XplatUI.SetWindowBackground(window.Handle, this.BackColor);
2599 OnHandleCreated(EventArgs.Empty);
2603 [EditorBrowsable(EditorBrowsableState.Advanced)]
2604 protected virtual void DefWndProc(ref Message m) {
2605 window.DefWndProc(ref m);
2608 [EditorBrowsable(EditorBrowsableState.Advanced)]
2609 protected virtual void DestroyHandle() {
2610 if (IsHandleCreated) {
2611 if (Handle != IntPtr.Zero) {
2612 controls.Remove(Handle);
2615 if (window != null) {
2616 window.DestroyHandle();
2621 protected bool GetStyle(ControlStyles flag) {
2622 return (control_style & flag) != 0;
2625 protected bool GetTopLevel() {
2629 [EditorBrowsable(EditorBrowsableState.Advanced)]
2630 protected virtual void InitLayout() {
2631 if (parent != null) {
2632 parent.PerformLayout(this, "parent");
2636 [EditorBrowsable(EditorBrowsableState.Advanced)]
2637 protected void InvokeGotFocus(Control toInvoke, EventArgs e) {
2638 toInvoke.OnGotFocus(e);
2641 [EditorBrowsable(EditorBrowsableState.Advanced)]
2642 protected void InvokeLostFocus(Control toInvoke, EventArgs e) {
2643 toInvoke.OnLostFocus(e);
2646 [EditorBrowsable(EditorBrowsableState.Advanced)]
2647 protected void InvokeOnClick(Control toInvoke, EventArgs e) {
2648 toInvoke.OnClick(e);
2651 protected void InvokePaint(Control toInvoke, PaintEventArgs e) {
2652 toInvoke.OnPaint(e);
2655 protected void InvokePaintBackground(Control toInvoke, PaintEventArgs e) {
2656 toInvoke.OnPaintBackground(e);
2659 protected virtual bool IsInputChar (char charCode) {
2660 if (parent != null) {
2661 return parent.IsInputChar(charCode);
2667 protected virtual bool IsInputKey (Keys keyData) {
2668 // Doc says this one calls IsInputChar; not sure what to do with that
2672 [EditorBrowsable(EditorBrowsableState.Advanced)]
2673 protected virtual void NotifyInvalidate(Rectangle invalidatedArea) {
2677 protected virtual bool ProcessCmdKey(ref Message msg, Keys keyData) {
2678 if ((context_menu != null) && context_menu.ProcessCmdKey(ref msg, keyData)) {
2682 if (parent != null) {
2683 return parent.ProcessCmdKey(ref msg, keyData);
2689 protected virtual bool ProcessDialogChar(char charCode) {
2690 if (parent != null) {
2691 return parent.ProcessDialogChar (charCode);
2697 protected virtual bool ProcessDialogKey (Keys keyData) {
2698 if (parent != null) {
2699 return parent.ProcessDialogKey (keyData);
2705 protected virtual bool ProcessKeyEventArgs (ref Message msg)
2707 KeyEventArgs key_event;
2709 PreProcessMessage(ref msg);
2712 case (int)Msg.WM_KEYDOWN: {
2713 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
2714 OnKeyDown (key_event);
2715 return key_event.Handled;
2717 case (int)Msg.WM_KEYUP: {
2718 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
2719 OnKeyUp (key_event);
2720 return key_event.Handled;
2723 case (int)Msg.WM_CHAR: {
2724 KeyPressEventArgs key_press_event;
2726 key_press_event = new KeyPressEventArgs((char)msg.WParam);
2727 OnKeyPress(key_press_event);
2728 return key_press_event.Handled;
2739 protected internal virtual bool ProcessKeyMessage(ref Message msg) {
2740 if (parent != null) {
2741 if (parent.ProcessKeyPreview(ref msg)) {
2746 return ProcessKeyEventArgs(ref msg);
2749 protected virtual bool ProcessKeyPreview(ref Message msg) {
2750 if (parent != null) {
2751 return parent.ProcessKeyPreview(ref msg);
2757 protected virtual bool ProcessMnemonic(char charCode) {
2762 [EditorBrowsable(EditorBrowsableState.Advanced)]
2763 protected void RaiseDragEvent(object key, DragEventArgs e) {
2767 [EditorBrowsable(EditorBrowsableState.Advanced)]
2768 protected void RaiseKeyEvent(object key, KeyEventArgs e) {
2772 [EditorBrowsable(EditorBrowsableState.Advanced)]
2773 protected void RaiseMouseEvent(object key, MouseEventArgs e) {
2777 [EditorBrowsable(EditorBrowsableState.Advanced)]
2778 protected void RaisePaintEvent(object key, PaintEventArgs e) {
2782 [EditorBrowsable(EditorBrowsableState.Advanced)]
2783 protected void RecreateHandle() {
2784 IEnumerator child = child_controls.GetEnumerator();
2788 if (IsHandleCreated) {
2794 while (child.MoveNext()) {
2795 ((Control)child.Current).RecreateHandle();
2801 is_recreating = false;
2804 [EditorBrowsable(EditorBrowsableState.Advanced)]
2805 protected void ResetMouseEventArgs() {
2809 [EditorBrowsable(EditorBrowsableState.Advanced)]
2810 protected ContentAlignment RtlTranslateAlignment(ContentAlignment align) {
2811 if (right_to_left == RightToLeft.No) {
2816 case ContentAlignment.TopLeft: {
2817 return ContentAlignment.TopRight;
2820 case ContentAlignment.TopRight: {
2821 return ContentAlignment.TopLeft;
2824 case ContentAlignment.MiddleLeft: {
2825 return ContentAlignment.MiddleRight;
2828 case ContentAlignment.MiddleRight: {
2829 return ContentAlignment.MiddleLeft;
2832 case ContentAlignment.BottomLeft: {
2833 return ContentAlignment.BottomRight;
2836 case ContentAlignment.BottomRight: {
2837 return ContentAlignment.BottomLeft;
2841 // if it's center it doesn't change
2847 [EditorBrowsable(EditorBrowsableState.Advanced)]
2848 protected HorizontalAlignment RtlTranslateAlignment(HorizontalAlignment align) {
2849 if ((right_to_left == RightToLeft.No) || (align == HorizontalAlignment.Center)) {
2853 if (align == HorizontalAlignment.Left) {
2854 return HorizontalAlignment.Right;
2857 // align must be HorizontalAlignment.Right
2858 return HorizontalAlignment.Left;
2861 [EditorBrowsable(EditorBrowsableState.Advanced)]
2862 protected LeftRightAlignment RtlTranslateAlignment(LeftRightAlignment align) {
2863 if (right_to_left == RightToLeft.No) {
2867 if (align == LeftRightAlignment.Left) {
2868 return LeftRightAlignment.Right;
2871 // align must be LeftRightAlignment.Right;
2872 return LeftRightAlignment.Left;
2875 [EditorBrowsable(EditorBrowsableState.Advanced)]
2876 protected ContentAlignment RtlTranslateContent(ContentAlignment align) {
2877 return RtlTranslateAlignment(align);
2880 [EditorBrowsable(EditorBrowsableState.Advanced)]
2881 protected HorizontalAlignment RtlTranslateHorizontal(HorizontalAlignment align) {
2882 return RtlTranslateAlignment(align);
2885 [EditorBrowsable(EditorBrowsableState.Advanced)]
2886 protected LeftRightAlignment RtlTranslateLeftRight(LeftRightAlignment align) {
2887 return RtlTranslateAlignment(align);
2890 [EditorBrowsable(EditorBrowsableState.Advanced)]
2891 protected virtual void ScaleCore(float dx, float dy) {
2897 location = new Point((int)(Left * dx), (int)(Top * dy));
2898 size = this.ClientSize;
2901 if (!GetStyle(ControlStyles.FixedWidth)) {
2902 size.Width = (int)(size.Width * dx);
2905 if (!GetStyle(ControlStyles.FixedHeight)) {
2906 size.Height = (int)(size.Height * dy);
2909 Location = location;
2912 /* Now scale our children */
2913 for (int i=0; i < child_controls.Count; i++) {
2914 child_controls[i].Scale(dx, dy);
2920 protected virtual void Select(bool directed, bool forward) {
2925 // Select this control
2930 if (parent == null) {
2934 index = parent.child_controls.IndexOf(this);
2939 if ((index+1) < parent.child_controls.Count) {
2948 index = parent.child_controls.Count-1;
2951 result = Select(parent.child_controls[index]);
2952 } while (!result && parent.child_controls[index] != this);
2955 [EditorBrowsable(EditorBrowsableState.Advanced)]
2956 protected virtual void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
2957 // SetBoundsCore updates the Win32 control itself. UpdateBounds updates the controls variables and fires events, I'm guessing - pdb
2958 if ((specified & BoundsSpecified.X) != BoundsSpecified.X) {
2962 if ((specified & BoundsSpecified.Y) != BoundsSpecified.Y) {
2966 if ((specified & BoundsSpecified.Width)!= BoundsSpecified.Width) {
2970 if ((specified & BoundsSpecified.Height) != BoundsSpecified.Height) {
2974 if (IsHandleCreated) {
2975 XplatUI.SetWindowPos(Handle, x, y, width, height);
2977 UpdateBounds(x, y, width, height);
2980 [EditorBrowsable(EditorBrowsableState.Advanced)]
2981 protected virtual void SetClientSizeCore(int x, int y) {
2982 // Calculate the actual window size from the client size (it usually stays the same or grows)
2983 Rectangle ClientRect;
2984 Rectangle WindowRect;
2987 ClientRect = new Rectangle(0, 0, x, y);
2988 cp = this.CreateParams;
2990 if (XplatUI.CalculateWindowRect(Handle, ref ClientRect, cp.Style, false, out WindowRect)==false) {
2994 SetBoundsCore(bounds.X, bounds.Y, WindowRect.Width, WindowRect.Height, BoundsSpecified.Size);
2997 [EditorBrowsable(EditorBrowsableState.Advanced)]
2998 protected void SetStyle(ControlStyles flag, bool value) {
3000 control_style |= flag;
3002 control_style &= ~flag;
3006 protected void SetTopLevel(bool value) {
3007 if ((GetTopLevel() != value) && (parent != null)) {
3008 throw new Exception();
3012 if (value == true) {
3022 is_toplevel = value;
3025 protected virtual void SetVisibleCore(bool value) {
3026 if (value!=is_visible) {
3028 XplatUI.SetVisible(Handle, value);
3029 // Explicitly move Toplevel windows to where we want them;
3030 // apparently moving unmapped toplevel windows doesn't work
3031 if (is_visible && (this is Form.FormParentWindow)) {
3032 XplatUI.SetWindowPos(window.Handle, bounds.X, bounds.Y, bounds.Width, bounds.Height);
3034 OnVisibleChanged(EventArgs.Empty);
3036 if (dc_mem != null) {
3041 if (bmp_mem != null) {
3046 this.CreateBuffers(bounds.Width, bounds.Height);
3049 // FIXME - deal with focus
3051 if (parent != null) {
3052 parent.PerformLayout(this, "visible");
3054 PerformLayout(this, "visible");
3059 [EditorBrowsable(EditorBrowsableState.Advanced)]
3060 protected void UpdateBounds() {
3068 if (!IsHandleCreated) {
3072 XplatUI.GetWindowPos(this.Handle, this is Form.FormParentWindow, out x, out y, out width, out height, out client_width, out client_height);
3073 UpdateBounds(x, y, width, height, client_width, client_height);
3076 [EditorBrowsable(EditorBrowsableState.Advanced)]
3077 protected void UpdateBounds(int x, int y, int width, int height) {
3078 // UpdateBounds only seems to set our sizes and fire events but not update the GUI window to match
3080 bool resized = false;
3082 int client_x_diff = this.bounds.Width-this.client_size.Width;
3083 int client_y_diff = this.bounds.Height-this.client_size.Height;
3085 // Needed to generate required notifications
3086 if ((this.bounds.X!=x) || (this.bounds.Y!=y)) {
3090 if ((this.Bounds.Width!=width) || (this.Bounds.Height!=height)) {
3097 bounds.Height=height;
3099 // Update client rectangle as well
3100 if (this.layout_suspended==0) {
3101 prev_size.Width=client_size.Width;
3102 prev_size.Height=client_size.Height;
3105 client_size.Width=width-client_x_diff;
3106 client_size.Height=height-client_y_diff;
3109 OnLocationChanged(EventArgs.Empty);
3113 OnSizeChanged(EventArgs.Empty);
3117 [EditorBrowsable(EditorBrowsableState.Advanced)]
3118 protected void UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) {
3119 UpdateBounds(x, y, width, height);
3121 this.client_size.Width=clientWidth;
3122 this.client_size.Height=clientHeight;
3125 [EditorBrowsable(EditorBrowsableState.Advanced)]
3126 protected void UpdateStyles() {
3127 if (!IsHandleCreated) {
3131 if ( !(this is Form) && !(this is Form.FormParentWindow)) {
3132 XplatUI.SetWindowStyle(window.Handle, CreateParams);
3135 XplatUI.SetWindowStyle(((Form)this).form_parent_window.window.Handle, ((Form)this).CreateFormParams);
3137 XplatUI.SetWindowStyle(((Form.FormParentWindow)this).window.Handle, ((Form.FormParentWindow)this).owner.CreateFormParams);
3142 protected void UpdateZOrder() {
3147 if (parent == null) {
3153 children = ctl.child_controls.Count;
3154 for (int i = 1; i < children; i++ ) {
3155 XplatUI.SetZOrder(ctl.child_controls[i].window.Handle, ctl.child_controls[i-1].window.Handle, false, false);
3158 children = child_controls.Count;
3159 for (int i = 1; i < children; i++ ) {
3160 XplatUI.SetZOrder(child_controls[i].window.Handle, child_controls[i-1].window.Handle, false, false);
3165 protected virtual void WndProc(ref Message m) {
3167 Console.WriteLine("Received message {0}", m);
3169 if ((this.control_style & ControlStyles.EnableNotifyMessage) != 0) {
3173 switch((Msg)m.Msg) {
3174 case Msg.WM_WINDOWPOSCHANGED: {
3177 if (GetStyle(ControlStyles.ResizeRedraw)) {
3184 case Msg.WM_PAINT: {
3185 PaintEventArgs paint_event;
3187 paint_event = XplatUI.PaintEventStart(Handle);
3188 OnPaint(paint_event);
3189 XplatUI.PaintEventEnd(Handle);
3194 case Msg.WM_ERASEBKGND: {
3195 if (GetStyle (ControlStyles.UserPaint)) {
3196 if (!GetStyle(ControlStyles.AllPaintingInWmPaint)) {
3197 PaintEventArgs eraseEventArgs = new PaintEventArgs (m.WParam == IntPtr.Zero ? Graphics.FromHwnd (m.HWnd) :
3198 Graphics.FromHdc (m.WParam), new Rectangle (new Point (0,0),Size));
3199 OnPaintBackground (eraseEventArgs);
3201 m.Result = (IntPtr)1;
3203 m.Result = IntPtr.Zero;
3210 case Msg.WM_LBUTTONUP: {
3211 HandleClick(mouse_clicks);
3212 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Left,
3214 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3216 if (mouse_clicks > 1) {
3222 case Msg.WM_LBUTTONDOWN: {
3223 if (CanSelect && !is_selected) {
3226 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3227 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3233 case Msg.WM_LBUTTONDBLCLK: {
3235 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3236 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3242 case Msg.WM_MBUTTONUP: {
3243 HandleClick(mouse_clicks);
3244 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Middle,
3246 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3248 if (mouse_clicks > 1) {
3254 case Msg.WM_MBUTTONDOWN: {
3255 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3256 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3262 case Msg.WM_MBUTTONDBLCLK: {
3264 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3265 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3270 case Msg.WM_RBUTTONUP: {
3271 HandleClick(mouse_clicks);
3272 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Right,
3274 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3276 if (mouse_clicks > 1) {
3282 case Msg.WM_RBUTTONDOWN: {
3283 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3284 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3289 case Msg.WM_RBUTTONDBLCLK: {
3291 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3292 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3297 case Msg.WM_MOUSEWHEEL: {
3299 OnMouseWheel (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3300 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3301 HighOrder(m.WParam.ToInt32())));
3306 case Msg.WM_MOUSEMOVE: {
3307 OnMouseMove (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
3309 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
3314 case Msg.WM_MOUSE_ENTER: {
3319 OnMouseEnter(EventArgs.Empty);
3323 case Msg.WM_MOUSE_LEAVE: {
3325 OnMouseLeave(EventArgs.Empty);
3329 case Msg.WM_MOUSEHOVER: {
3330 OnMouseHover(EventArgs.Empty);
3334 case Msg.WM_KEYDOWN: {
3335 if (!ProcessKeyMessage(ref m)) {
3341 case Msg.WM_KEYUP: {
3342 if (!ProcessKeyMessage(ref m)) {
3349 if (!ProcessKeyMessage(ref m)) {
3357 if (m.LParam != IntPtr.Zero) {
3360 hi = new HELPINFO();
3362 hi = (HELPINFO) Marshal.PtrToStructure (m.LParam, typeof (HELPINFO));
3363 mouse_pos = new Point(hi.MousePos.x, hi.MousePos.y);
3365 mouse_pos = Control.MousePosition;
3367 OnHelpRequested(new HelpEventArgs(mouse_pos));
3368 m.Result = (IntPtr)1;
3372 case Msg.WM_KILLFOCUS: {
3373 OnLeave(EventArgs.Empty);
3374 if (CausesValidation) {
3376 e = new CancelEventArgs(false);
3385 OnValidated(EventArgs.Empty);
3388 this.has_focus = false;
3389 this.is_selected = false;
3390 OnLostFocus(EventArgs.Empty);
3394 case Msg.WM_SETFOCUS: {
3395 OnEnter(EventArgs.Empty);
3396 this.has_focus = true;
3397 OnGotFocus(EventArgs.Empty);
3402 case Msg.WM_SYSCOLORCHANGE: {
3403 ThemeEngine.Current.ResetDefaults();
3404 OnSystemColorsChanged(EventArgs.Empty);
3409 case Msg.WM_SETCURSOR: {
3410 if (cursor == null) {
3415 XplatUI.SetCursor(window.Handle, cursor.handle);
3416 m.Result = (IntPtr)1;
3425 #endregion // Public Instance Methods
3427 #region OnXXX methods
3428 [EditorBrowsable(EditorBrowsableState.Advanced)]
3429 protected virtual void OnBackColorChanged(EventArgs e) {
3430 if (BackColorChanged!=null) BackColorChanged(this, e);
3431 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackColorChanged(e);
3434 [EditorBrowsable(EditorBrowsableState.Advanced)]
3435 protected virtual void OnBackgroundImageChanged(EventArgs e) {
3436 if (BackgroundImageChanged!=null) BackgroundImageChanged(this, e);
3437 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackgroundImageChanged(e);
3440 [EditorBrowsable(EditorBrowsableState.Advanced)]
3441 protected virtual void OnBindingContextChanged(EventArgs e) {
3442 if (BindingContextChanged!=null) BindingContextChanged(this, e);
3443 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBindingContextChanged(e);
3446 [EditorBrowsable(EditorBrowsableState.Advanced)]
3447 protected virtual void OnCausesValidationChanged(EventArgs e) {
3448 if (CausesValidationChanged!=null) CausesValidationChanged(this, e);
3451 [EditorBrowsable(EditorBrowsableState.Advanced)]
3452 protected virtual void OnChangeUICues(UICuesEventArgs e) {
3453 if (ChangeUICues!=null) ChangeUICues(this, e);
3456 [EditorBrowsable(EditorBrowsableState.Advanced)]
3457 protected virtual void OnClick(EventArgs e) {
3458 if (Click!=null) Click(this, e);
3461 [EditorBrowsable(EditorBrowsableState.Advanced)]
3462 protected virtual void OnContextMenuChanged(EventArgs e) {
3463 if (ContextMenuChanged!=null) ContextMenuChanged(this, e);
3466 [EditorBrowsable(EditorBrowsableState.Advanced)]
3467 protected virtual void OnControlAdded(ControlEventArgs e) {
3468 if (ControlAdded!=null) ControlAdded(this, e);
3471 [EditorBrowsable(EditorBrowsableState.Advanced)]
3472 protected virtual void OnControlRemoved(ControlEventArgs e) {
3473 if (ControlRemoved!=null) ControlRemoved(this, e);
3476 [EditorBrowsable(EditorBrowsableState.Advanced)]
3477 protected virtual void OnCreateControl() {
3481 [EditorBrowsable(EditorBrowsableState.Advanced)]
3482 protected virtual void OnCursorChanged(EventArgs e) {
3483 if (CursorChanged!=null) CursorChanged(this, e);
3486 [EditorBrowsable(EditorBrowsableState.Advanced)]
3487 protected virtual void OnDockChanged(EventArgs e) {
3488 if (DockChanged!=null) DockChanged(this, e);
3491 [EditorBrowsable(EditorBrowsableState.Advanced)]
3492 protected virtual void OnDoubleClick(EventArgs e) {
3493 if (DoubleClick!=null) DoubleClick(this, e);
3496 [EditorBrowsable(EditorBrowsableState.Advanced)]
3497 protected virtual void OnDragDrop(DragEventArgs drgevent) {
3498 if (DragDrop!=null) DragDrop(this, drgevent);
3501 [EditorBrowsable(EditorBrowsableState.Advanced)]
3502 protected virtual void OnDragEnter(DragEventArgs drgevent) {
3503 if (DragEnter!=null) DragEnter(this, drgevent);
3506 [EditorBrowsable(EditorBrowsableState.Advanced)]
3507 protected virtual void OnDragLeave(EventArgs e) {
3508 if (DragLeave!=null) DragLeave(this, e);
3511 [EditorBrowsable(EditorBrowsableState.Advanced)]
3512 protected virtual void OnDragOver(DragEventArgs drgevent) {
3513 if (DragOver!=null) DragOver(this, drgevent);
3516 [EditorBrowsable(EditorBrowsableState.Advanced)]
3517 protected virtual void OnEnabledChanged(EventArgs e) {
3518 if (EnabledChanged!=null) EnabledChanged(this, e);
3519 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentEnabledChanged(e);
3522 [EditorBrowsable(EditorBrowsableState.Advanced)]
3523 protected virtual void OnEnter(EventArgs e) {
3524 if (Enter!=null) Enter(this, e);
3527 [EditorBrowsable(EditorBrowsableState.Advanced)]
3528 protected virtual void OnFontChanged(EventArgs e) {
3529 if (FontChanged!=null) FontChanged(this, e);
3530 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentFontChanged(e);
3533 [EditorBrowsable(EditorBrowsableState.Advanced)]
3534 protected virtual void OnForeColorChanged(EventArgs e) {
3535 if (ForeColorChanged!=null) ForeColorChanged(this, e);
3536 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentForeColorChanged(e);
3539 [EditorBrowsable(EditorBrowsableState.Advanced)]
3540 protected virtual void OnGiveFeedback(GiveFeedbackEventArgs gfbevent) {
3541 if (GiveFeedback!=null) GiveFeedback(this, gfbevent);
3544 [EditorBrowsable(EditorBrowsableState.Advanced)]
3545 protected virtual void OnGotFocus(EventArgs e) {
3546 if (GotFocus!=null) GotFocus(this, e);
3549 [EditorBrowsable(EditorBrowsableState.Advanced)]
3550 protected virtual void OnHandleCreated(EventArgs e) {
3551 if (HandleCreated!=null) HandleCreated(this, e);
3554 [EditorBrowsable(EditorBrowsableState.Advanced)]
3555 protected virtual void OnHandleDestroyed(EventArgs e) {
3556 if (HandleDestroyed!=null) HandleDestroyed(this, e);
3559 [EditorBrowsable(EditorBrowsableState.Advanced)]
3560 protected virtual void OnHelpRequested(HelpEventArgs hevent) {
3561 if (HelpRequested!=null) HelpRequested(this, hevent);
3564 protected virtual void OnImeModeChanged(EventArgs e) {
3565 if (ImeModeChanged!=null) ImeModeChanged(this, e);
3568 [EditorBrowsable(EditorBrowsableState.Advanced)]
3569 protected virtual void OnInvalidated(InvalidateEventArgs e) {
3570 if (Invalidated!=null) Invalidated(this, e);
3573 [EditorBrowsable(EditorBrowsableState.Advanced)]
3574 protected virtual void OnKeyDown(KeyEventArgs e) {
3575 if (KeyDown!=null) KeyDown(this, e);
3578 [EditorBrowsable(EditorBrowsableState.Advanced)]
3579 protected virtual void OnKeyPress(KeyPressEventArgs e) {
3580 if (KeyPress!=null) KeyPress(this, e);
3583 [EditorBrowsable(EditorBrowsableState.Advanced)]
3584 protected virtual void OnKeyUp(KeyEventArgs e) {
3585 if (KeyUp!=null) KeyUp(this, e);
3588 [EditorBrowsable(EditorBrowsableState.Advanced)]
3589 protected virtual void OnLayout(LayoutEventArgs levent) {
3590 if (Layout!=null) Layout(this, levent);
3593 [EditorBrowsable(EditorBrowsableState.Advanced)]
3594 protected virtual void OnLeave(EventArgs e) {
3595 if (Leave!=null) Leave(this, e);
3598 [EditorBrowsable(EditorBrowsableState.Advanced)]
3599 protected virtual void OnLocationChanged(EventArgs e) {
3601 if (LocationChanged!=null) LocationChanged(this, e);
3602 if (this is Form.FormParentWindow) {
3605 form = ((Form.FormParentWindow)this).owner;
3607 if (form.LocationChanged != null) {
3608 form.LocationChanged(form, e);
3613 [EditorBrowsable(EditorBrowsableState.Advanced)]
3614 protected virtual void OnLostFocus(EventArgs e) {
3615 if (LostFocus!=null) LostFocus(this, e);
3618 [EditorBrowsable(EditorBrowsableState.Advanced)]
3619 protected virtual void OnMouseDown(MouseEventArgs e) {
3620 if (MouseDown!=null) MouseDown(this, e);
3623 [EditorBrowsable(EditorBrowsableState.Advanced)]
3624 protected virtual void OnMouseEnter(EventArgs e) {
3625 if (MouseEnter!=null) MouseEnter(this, e);
3628 [EditorBrowsable(EditorBrowsableState.Advanced)]
3629 protected virtual void OnMouseHover(EventArgs e) {
3630 if (MouseHover!=null) MouseHover(this, e);
3633 [EditorBrowsable(EditorBrowsableState.Advanced)]
3634 protected virtual void OnMouseLeave(EventArgs e) {
3635 if (MouseLeave!=null) MouseLeave(this, e);
3638 [EditorBrowsable(EditorBrowsableState.Advanced)]
3639 protected virtual void OnMouseMove(MouseEventArgs e) {
3640 if (MouseMove!=null) MouseMove(this, e);
3643 [EditorBrowsable(EditorBrowsableState.Advanced)]
3644 protected virtual void OnMouseUp(MouseEventArgs e) {
3645 if (MouseUp!=null) MouseUp(this, e);
3648 [EditorBrowsable(EditorBrowsableState.Advanced)]
3649 protected virtual void OnMouseWheel(MouseEventArgs e) {
3650 if (MouseWheel!=null) MouseWheel(this, e);
3653 [EditorBrowsable(EditorBrowsableState.Advanced)]
3654 protected virtual void OnMove(EventArgs e) {
3655 if (Move!=null) Move(this, e);
3658 [EditorBrowsable(EditorBrowsableState.Advanced)]
3659 protected virtual void OnNotifyMessage(Message m) {
3663 [EditorBrowsable(EditorBrowsableState.Advanced)]
3664 protected virtual void OnPaint(PaintEventArgs e) {
3665 if (Paint!=null) Paint(this, e);
3668 [EditorBrowsable(EditorBrowsableState.Advanced)]
3669 protected virtual void OnPaintBackground(PaintEventArgs pevent) {
3673 [EditorBrowsable(EditorBrowsableState.Advanced)]
3674 protected virtual void OnParentBackColorChanged(EventArgs e) {
3675 if (background_color.IsEmpty && background_image==null) {
3677 OnBackColorChanged(e);
3681 [EditorBrowsable(EditorBrowsableState.Advanced)]
3682 protected virtual void OnParentBackgroundImageChanged(EventArgs e) {
3683 if (background_color.IsEmpty && background_image==null) {
3685 OnBackgroundImageChanged(e);
3689 [EditorBrowsable(EditorBrowsableState.Advanced)]
3690 protected virtual void OnParentBindingContextChanged(EventArgs e) {
3691 if (binding_context==null) {
3692 binding_context=Parent.binding_context;
3693 OnBindingContextChanged(e);
3697 [EditorBrowsable(EditorBrowsableState.Advanced)]
3698 protected virtual void OnParentChanged(EventArgs e) {
3699 if (ParentChanged!=null) ParentChanged(this, e);
3702 [EditorBrowsable(EditorBrowsableState.Advanced)]
3703 protected virtual void OnParentEnabledChanged(EventArgs e) {
3704 if (is_enabled != Parent.is_enabled) {
3705 is_enabled=Parent.is_enabled;
3707 if (EnabledChanged != null) {
3708 EnabledChanged(this, e);
3713 [EditorBrowsable(EditorBrowsableState.Advanced)]
3714 protected virtual void OnParentFontChanged(EventArgs e) {
3721 [EditorBrowsable(EditorBrowsableState.Advanced)]
3722 protected virtual void OnParentForeColorChanged(EventArgs e) {
3723 if (foreground_color.IsEmpty) {
3725 OnForeColorChanged(e);
3729 [EditorBrowsable(EditorBrowsableState.Advanced)]
3730 protected virtual void OnParentRightToLeftChanged(EventArgs e) {
3731 if (right_to_left==RightToLeft.Inherit) {
3733 OnRightToLeftChanged(e);
3737 [EditorBrowsable(EditorBrowsableState.Advanced)]
3738 protected virtual void OnParentVisibleChanged(EventArgs e) {
3739 if (is_visible!=Parent.is_visible) {
3742 OnVisibleChanged(e);
3746 [EditorBrowsable(EditorBrowsableState.Advanced)]
3747 protected virtual void OnQueryContinueDrag(QueryContinueDragEventArgs e) {
3748 if (QueryContinueDrag!=null) QueryContinueDrag(this, e);
3751 [EditorBrowsable(EditorBrowsableState.Advanced)]
3752 protected virtual void OnResize(EventArgs e) {
3753 if (Resize!=null) Resize(this, e);
3755 PerformLayout(this, "bounds");
3757 if (parent != null) {
3758 parent.PerformLayout();
3762 [EditorBrowsable(EditorBrowsableState.Advanced)]
3763 protected virtual void OnRightToLeftChanged(EventArgs e) {
3764 if (RightToLeftChanged!=null) RightToLeftChanged(this, e);
3765 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentRightToLeftChanged(e);
3768 [EditorBrowsable(EditorBrowsableState.Advanced)]
3769 protected virtual void OnSizeChanged(EventArgs e) {
3770 InvalidateBuffers ();
3772 if (SizeChanged!=null) SizeChanged(this, e);
3775 [EditorBrowsable(EditorBrowsableState.Advanced)]
3776 protected virtual void OnStyleChanged(EventArgs e) {
3777 if (StyleChanged!=null) StyleChanged(this, e);
3780 [EditorBrowsable(EditorBrowsableState.Advanced)]
3781 protected virtual void OnSystemColorsChanged(EventArgs e) {
3782 if (SystemColorsChanged!=null) SystemColorsChanged(this, e);
3785 [EditorBrowsable(EditorBrowsableState.Advanced)]
3786 protected virtual void OnTabIndexChanged(EventArgs e) {
3787 if (TabIndexChanged!=null) TabIndexChanged(this, e);
3790 [EditorBrowsable(EditorBrowsableState.Advanced)]
3791 protected virtual void OnTabStopChanged(EventArgs e) {
3792 if (TabStopChanged!=null) TabStopChanged(this, e);
3795 [EditorBrowsable(EditorBrowsableState.Advanced)]
3796 protected virtual void OnTextChanged(EventArgs e) {
3797 if (TextChanged!=null) TextChanged(this, e);
3800 [EditorBrowsable(EditorBrowsableState.Advanced)]
3801 protected virtual void OnValidated(EventArgs e) {
3802 if (Validated!=null) Validated(this, e);
3805 [EditorBrowsable(EditorBrowsableState.Advanced)]
3806 protected virtual void OnValidating(System.ComponentModel.CancelEventArgs e) {
3807 if (Validating!=null) Validating(this, e);
3810 [EditorBrowsable(EditorBrowsableState.Advanced)]
3811 protected virtual void OnVisibleChanged(EventArgs e) {
3818 if (bmp_mem!=null) {
3824 if (!this.IsHandleCreated) {
3825 this.CreateHandle();
3831 if (VisibleChanged!=null) VisibleChanged(this, e);
3833 if (this is Form.FormParentWindow) {
3836 form = ((Form.FormParentWindow)this).owner;
3838 form.OnVisibleChanged(e);
3841 // We need to tell our kids
3842 for (int i=0; i<child_controls.Count; i++) {
3843 child_controls[i].OnParentVisibleChanged(e);
3846 #endregion // OnXXX methods
3849 public event EventHandler BackColorChanged;
3850 public event EventHandler BackgroundImageChanged;
3851 public event EventHandler BindingContextChanged;
3852 public event EventHandler CausesValidationChanged;
3853 public event UICuesEventHandler ChangeUICues;
3854 public event EventHandler Click;
3855 public event EventHandler ContextMenuChanged;
3857 [EditorBrowsable(EditorBrowsableState.Advanced)]
3859 public event ControlEventHandler ControlAdded;
3861 [EditorBrowsable(EditorBrowsableState.Advanced)]
3863 public event ControlEventHandler ControlRemoved;
3865 public event EventHandler CursorChanged;
3866 public event EventHandler DockChanged;
3867 public event EventHandler DoubleClick;
3868 public event DragEventHandler DragDrop;
3869 public event DragEventHandler DragEnter;
3870 public event EventHandler DragLeave;
3871 public event DragEventHandler DragOver;
3872 public event EventHandler EnabledChanged;
3873 public event EventHandler Enter;
3874 public event EventHandler FontChanged;
3875 public event EventHandler ForeColorChanged;
3876 public event GiveFeedbackEventHandler GiveFeedback;
3878 [EditorBrowsable(EditorBrowsableState.Advanced)]
3880 public event EventHandler GotFocus;
3882 [EditorBrowsable(EditorBrowsableState.Advanced)]
3884 public event EventHandler HandleCreated;
3886 [EditorBrowsable(EditorBrowsableState.Advanced)]
3888 public event EventHandler HandleDestroyed;
3890 public event HelpEventHandler HelpRequested;
3891 public event EventHandler ImeModeChanged;
3893 [EditorBrowsable(EditorBrowsableState.Advanced)]
3895 public event InvalidateEventHandler Invalidated;
3897 public event KeyEventHandler KeyDown;
3898 public event KeyPressEventHandler KeyPress;
3899 public event KeyEventHandler KeyUp;
3900 public event LayoutEventHandler Layout;
3901 public event EventHandler Leave;
3902 public event EventHandler LocationChanged;
3904 [EditorBrowsable(EditorBrowsableState.Advanced)]
3906 public event EventHandler LostFocus;
3908 public event MouseEventHandler MouseDown;
3909 public event EventHandler MouseEnter;
3910 public event EventHandler MouseHover;
3911 public event EventHandler MouseLeave;
3912 public event MouseEventHandler MouseMove;
3913 public event MouseEventHandler MouseUp;
3915 [EditorBrowsable(EditorBrowsableState.Advanced)]
3917 public event MouseEventHandler MouseWheel;
3919 public event EventHandler Move;
3920 public event PaintEventHandler Paint;
3921 public event EventHandler ParentChanged;
3922 public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp;
3923 public event QueryContinueDragEventHandler QueryContinueDrag;
3924 public event EventHandler Resize;
3925 public event EventHandler RightToLeftChanged;
3926 public event EventHandler SizeChanged;
3927 public event EventHandler StyleChanged;
3928 public event EventHandler SystemColorsChanged;
3929 public event EventHandler TabIndexChanged;
3930 public event EventHandler TabStopChanged;
3931 public event EventHandler TextChanged;
3932 public event EventHandler Validated;
3933 public event CancelEventHandler Validating;
3934 public event EventHandler VisibleChanged;
3935 #endregion // Events