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.Collections;
39 using System.Diagnostics;
40 using System.Threading;
41 using System.Runtime.InteropServices;
43 namespace System.Windows.Forms
45 public class Control : Component, ISynchronizeInvoke, IWin32Window
47 #region Local Variables
50 internal Rectangle bounds; // bounding rectangle for control (client area + decorations)
51 internal object creator_thread; // thread that created the control
52 internal ControlNativeWindow window; // object for native window handle
53 internal string name; // for object naming
56 internal bool has_focus; // true if control has focus
57 internal bool is_visible; // true if control is visible
58 internal bool is_entered; // is the mouse inside the control?
59 internal bool is_enabled; // true if control is enabled (usable/not grayed out)
60 internal bool is_selected; // true if control is selected
61 internal bool is_accessible; // true if the control is visible to accessibility applications
62 internal bool is_captured; // tracks if the control has captured the mouse
63 internal bool is_toplevel; // tracks if the control is a toplevel window
64 internal bool is_recreating; // tracks if the handle for the control is being recreated
65 internal bool causes_validation; // tracks if validation is executed on changes
66 internal int tab_index; // position in tab order of siblings
67 internal bool tab_stop = true; // is the control a tab stop?
68 internal bool is_disposed; // has the window already been disposed?
69 internal Size client_size; // size of the client area (window excluding decorations)
70 internal Rectangle client_rect; // rectangle with the client area (window excluding decorations)
71 internal ControlStyles control_style; // rather win32-specific, style bits for control
72 internal ImeMode ime_mode = ImeMode.Inherit;
73 internal bool layout_pending; // true if our parent needs to re-layout us
74 internal object control_tag; // object that contains data about our control
75 internal int mouse_clicks; // Counter for mouse clicks
79 internal Color foreground_color; // foreground color for control
80 internal Color background_color; // background color for control
81 internal Image background_image; // background image for control
82 internal Font font; // font for control
83 internal string text; // window/title text for control
86 internal AnchorStyles anchor_style; // anchoring requirements for our control
87 internal DockStyle dock_style; // docking requirements for our control (supercedes anchoring)
88 internal SizeF size_ratio; // size ratio of our control to it's parent; required for anchoring
89 internal Size prev_size; // previous size of the control; required for anchoring
91 // to be categorized...
92 static internal ArrayList controls = new ArrayList(); // All of the applications controls, in a flat list
93 internal ControlCollection child_controls; // our children
94 internal Control parent; // our parent control
95 internal AccessibleObject accessibility_object; // object that contains accessibility information about our control
96 internal BindingContext binding_context; // TODO
97 internal RightToLeft right_to_left; // drawing direction for control
98 internal int layout_suspended;
99 internal bool double_buffering;
100 internal ContextMenu context_menu; // Context menu associated with the control
102 private Graphics dc_mem; // Graphics context for double buffering
103 private Bitmap bmp_mem; // Bitmap for double buffering control
105 #endregion // Local Variables
107 #region Private Classes
108 // This helper class allows us to dispatch messages to Control.WndProc
109 internal class ControlNativeWindow : NativeWindow {
110 private Control control;
112 public ControlNativeWindow(Control control) : base() {
113 this.control=control;
116 static internal Control ControlFromHandle(IntPtr hWnd) {
117 ControlNativeWindow window;
119 window = (ControlNativeWindow)window_collection[hWnd];
121 return window.control;
124 protected override void WndProc(ref Message m) {
125 control.WndProc(ref m);
130 #region Public Classes
131 public class ControlAccessibleObject : AccessibleObject {
132 #region ControlAccessibleObject Local Variables
133 private Control owner;
134 #endregion // ControlAccessibleObject Local Variables
136 #region ControlAccessibleObject Constructors
137 public ControlAccessibleObject(Control ownerControl) {
138 this.owner = ownerControl;
140 #endregion // ControlAccessibleObject Constructors
142 #region ControlAccessibleObject Public Instance Properties
143 public override string DefaultAction {
145 return base.DefaultAction;
149 public override string Description {
151 return base.Description;
155 public IntPtr Handle {
161 // We don't want to let them set it
165 public override string Help {
171 public override string KeyboardShortcut {
173 return base.KeyboardShortcut;
177 public override string Name {
187 public Control Owner {
193 public override AccessibleRole Role {
198 #endregion // ControlAccessibleObject Public Instance Properties
200 #region ControlAccessibleObject Public Instance Methods
201 public override int GetHelpTopic(out string FileName) {
202 return base.GetHelpTopic (out FileName);
205 #endregion // ControlAccessibleObject Public Instance Methods
208 public class ControlCollection : IList, ICollection, ICloneable, IEnumerable {
209 #region ControlCollection Local Variables
210 internal ArrayList list;
211 internal Control owner;
212 #endregion // ControlCollection Local Variables
214 #region ControlCollection Public Constructor
215 public ControlCollection(Control owner) {
217 this.list=new ArrayList();
221 #region ControlCollection Public Instance Properties
228 public bool IsReadOnly {
230 return list.IsReadOnly;
234 public virtual Control this[int index] {
236 if (index < 0 || index >= list.Count) {
237 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
239 return (Control)list[index];
242 #endregion // ControlCollection Public Instance Properties
244 #region ControlCollection Private Instance Methods
245 public virtual void Add (Control value)
248 for (int i = 0; i < list.Count; i++) {
249 if (list [i] == value) {
250 // Do we need to do anything here?
255 if (value.tab_index == -1) {
261 end = owner.child_controls.Count;
262 for (int i = 0; i < end; i++) {
263 index = owner.child_controls[i].tab_index;
268 value.tab_index = use;
272 value.Parent = owner;
273 owner.UpdateZOrder();
276 public virtual void AddRange (Control[] controls)
278 if (controls == null)
279 throw new ArgumentNullException ("controls");
281 owner.SuspendLayout ();
284 for (int i = 0; i < controls.Length; i++)
287 owner.ResumeLayout ();
291 public virtual void Clear ()
293 owner.SuspendLayout();
295 owner.ResumeLayout();
298 public virtual bool Contains (Control value)
300 return list.Contains (value);
303 public void CopyTo (Array array, int index)
305 list.CopyTo(array, index);
308 public override bool Equals(object other) {
309 if (other is ControlCollection && (((ControlCollection)other).owner==this.owner)) {
316 public int GetChildIndex(Control child) {
317 return GetChildIndex(child, false);
320 public int GetChildIndex(Control child, bool throwException) {
323 index=list.IndexOf(child);
325 if (index==-1 && throwException) {
326 throw new ArgumentException("Not a child control", "child");
331 public IEnumerator GetEnumerator() {
332 return list.GetEnumerator();
335 public override int GetHashCode() {
336 return base.GetHashCode();
339 public int IndexOf(Control control) {
340 return list.IndexOf(control);
343 public virtual void Remove(Control value) {
345 owner.UpdateZOrder();
348 public void RemoveAt(int index) {
349 if (index<0 || index>=list.Count) {
350 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
353 list.RemoveAt(index);
354 owner.UpdateZOrder();
357 public void SetChildIndex(Control child, int newIndex) {
360 old_index=list.IndexOf(child);
362 throw new ArgumentException("Not a child control", "child");
365 if (old_index==newIndex) {
371 if (newIndex>list.Count) {
374 list.Insert(newIndex, child);
376 owner.UpdateZOrder();
378 #endregion // ControlCollection Private Instance Methods
380 #region ControlCollection Interface Properties
381 object IList.this[int index] {
383 if (index<0 || index>=list.Count) {
384 throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
390 if (!(value is Control)) {
391 throw new ArgumentException("Object of type Control required", "value");
394 list[index]=(Control)value;
398 bool IList.IsFixedSize {
404 bool IList.IsReadOnly {
406 return list.IsReadOnly;
410 bool ICollection.IsSynchronized {
412 return list.IsSynchronized;
416 object ICollection.SyncRoot {
418 return list.SyncRoot;
421 #endregion // ControlCollection Interface Properties
423 #region ControlCollection Interface Methods
424 int IList.Add(object value) {
426 throw new ArgumentNullException("value", "Cannot add null controls");
429 if (!(value is Control)) {
430 throw new ArgumentException("Object of type Control required", "value");
433 return list.Add(value);
436 bool IList.Contains(object value) {
437 if (!(value is Control)) {
438 throw new ArgumentException("Object of type Control required", "value");
441 return this.Contains((Control) value);
444 int IList.IndexOf(object value) {
445 if (!(value is Control)) {
446 throw new ArgumentException("Object of type Control required", "value");
449 return this.IndexOf((Control) value);
452 void IList.Insert(int index, object value) {
453 if (!(value is Control)) {
454 throw new ArgumentException("Object of type Control required", "value");
456 list.Insert(index, value);
459 void IList.Remove(object value) {
460 if (!(value is Control)) {
461 throw new ArgumentException("Object of type Control required", "value");
466 void ICollection.CopyTo(Array array, int index) {
468 list.CopyTo(array, index);
472 Object ICloneable.Clone() {
473 ControlCollection clone = new ControlCollection(this.owner);
474 clone.list=(ArrayList)list.Clone(); // FIXME: Do we need this?
477 #endregion // ControlCollection Interface Methods
479 #endregion // ControlCollection Class
481 #region Public Constructors
483 creator_thread = Thread.CurrentThread;
485 prev_size = Size.Empty;
486 anchor_style = AnchorStyles.Top | AnchorStyles.Left;
493 layout_pending = false;
495 causes_validation = true;
497 layout_suspended = 0;
498 double_buffering = true;
502 control_style = ControlStyles.Selectable | ControlStyles.StandardClick | ControlStyles.StandardDoubleClick;
505 background_image = null;
509 child_controls = CreateControlsInstance();
510 client_size = new Size(DefaultSize.Width, DefaultSize.Height);
511 client_rect = new Rectangle(0, 0, DefaultSize.Width, DefaultSize.Height);
512 XplatUI.CalculateWindowRect(IntPtr.Zero, ref client_rect, CreateParams.Style, false, out bounds);
513 if ((CreateParams.Style & (int)WindowStyles.WS_CHILD) == 0) {
519 public Control(Control parent, string text) : this() {
524 public Control(Control parent, string text, int left, int top, int width, int height) : this() {
529 bounds.Height=height;
530 SetBoundsCore(left, top, width, height, BoundsSpecified.All);
534 public Control(string text) : this() {
538 public Control(string text, int left, int top, int width, int height) : this() {
542 bounds.Height=height;
543 SetBoundsCore(left, top, width, height, BoundsSpecified.All);
547 protected override void Dispose(bool disposing) {
560 controls.Remove(this);
562 #endregion // Public Constructors
564 #region Internal Properties
565 #endregion // Internal Properties
567 #region Private & Internal Methods
568 internal static IAsyncResult BeginInvokeInternal (Delegate method, object [] args) {
569 AsyncMethodResult result = new AsyncMethodResult ();
570 AsyncMethodData data = new AsyncMethodData ();
572 data.Method = method;
574 data.Result = new WeakReference (result);
576 XplatUI.SendAsyncMethod (data);
580 internal Graphics DeviceContext {
583 CreateBuffers(this.Width, this.Height);
589 internal Bitmap ImageBuffer {
592 CreateBuffers(this.Width, this.Height);
598 internal void CreateBuffers (int width, int height) {
599 if (double_buffering == false)
615 bmp_mem = new Bitmap (width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
616 dc_mem = Graphics.FromImage (bmp_mem);
619 internal void InvalidateBuffers ()
621 if (double_buffering == false)
633 internal static void SetChildColor(Control parent) {
636 for (int i=0; i < parent.child_controls.Count; i++) {
637 child=parent.child_controls[i];
638 if (child.IsHandleCreated) {
639 XplatUI.SetWindowBackground(child.window.Handle, child.BackColor);
641 if (child.child_controls.Count>0) {
642 SetChildColor(child);
648 private bool Select(Control control) {
650 IContainerControl container;
652 if (control == null) {
656 parent = control.parent;
658 if (((control.control_style & ControlStyles.Selectable) !=0) && (parent != null)) {
659 while (parent != null) {
660 if (!parent.is_visible || !parent.is_enabled) {
663 parent = parent.parent;
667 control.is_selected = true;
669 XplatUI.SetFocus(control.window.Handle);
670 container = GetContainerControl();
671 if (container != null) {
672 container.ActiveControl = control;
678 private Control FindTabStop(Control control, bool forward) {
679 if (control == null) {
687 internal virtual void DoDefaultAction() {
688 // Only here to be overriden by our actual controls; this is needed by the accessibility class
691 internal static int LowOrder (int param) {
692 return (param & 0xffff);
695 internal static int HighOrder (int param) {
696 return (param >> 16);
699 internal static MouseButtons FromParamToMouseButtons (int param) {
700 MouseButtons buttons = MouseButtons.None;
702 if ((param & (int) MsgButtons.MK_LBUTTON) != 0)
703 buttons |= MouseButtons.Left;
705 if ((param & (int) MsgButtons.MK_MBUTTON) != 0)
706 buttons |= MouseButtons.Middle;
708 if ((param & (int) MsgButtons.MK_RBUTTON) != 0)
709 buttons |= MouseButtons.Right;
715 private static Control FindFlatForward(Control container, Control start) {
721 end = container.child_controls.Count;
724 index = start.tab_index;
729 for (int i = 0; i < end; i++) {
731 if (container.child_controls[i].tab_index > index) {
732 found = container.child_controls[i];
734 } else if (found.tab_index > container.child_controls[i].tab_index) {
735 if (container.child_controls[i].tab_index > index) {
736 found = container.child_controls[i];
743 private static Control FindControlForward(Control container, Control start) {
753 if ((start is IContainerControl) || start.GetStyle(ControlStyles.ContainerControl)) {
754 found = FindControlForward(start, null);
761 while (p != container) {
762 found = FindFlatForward(p, start);
770 return FindFlatForward(container, start);
773 private static Control FindFlatBackward(Control container, Control start) {
779 end = container.child_controls.Count;
782 index = start.tab_index;
784 // FIXME: Possible speed-up: Keep the highest taborder index in the container
786 for (int i = 0; i < end; i++) {
787 if (container.child_controls[i].tab_index > index) {
788 index = container.child_controls[i].tab_index;
794 for (int i = 0; i < end; i++) {
796 if (container.child_controls[i].tab_index < index) {
797 found = container.child_controls[i];
799 } else if (found.tab_index < container.child_controls[i].tab_index) {
800 if (container.child_controls[i].tab_index < index) {
801 found = container.child_controls[i];
808 private static Control FindControlBackward(Control container, Control start) {
818 found = FindFlatBackward(start.parent, start);
819 if (found == null && start.parent != container) {
824 found = FindFlatBackward(container, start);
827 while ((found != null) && ((found is IContainerControl) || found.GetStyle(ControlStyles.ContainerControl))) {
828 found = FindControlBackward(found, null);
836 #endregion // Private & Internal Methods
838 #region Public Static Properties
839 public static Color DefaultBackColor {
841 return ThemeEngine.Current.DefaultControlBackColor;
845 public static Font DefaultFont {
847 return ThemeEngine.Current.DefaultFont;
851 public static Color DefaultForeColor {
853 return ThemeEngine.Current.DefaultControlForeColor;
857 public static Keys ModifierKeys {
859 return XplatUI.State.ModifierKeys;
863 public static MouseButtons MouseButtons {
865 return XplatUI.State.MouseButtons;
869 public static Point MousePosition {
871 return Cursor.Position;
874 #endregion // Public Static Properties
876 #region Public Instance Properties
877 public AccessibleObject AccessibilityObject {
879 if (accessibility_object==null) {
880 accessibility_object=CreateAccessibilityInstance();
882 return accessibility_object;
886 public string AccessibleDefaultActionDescription {
888 return AccessibilityObject.default_action;
892 AccessibilityObject.default_action=value;
896 public string AccessibleDescription {
898 return AccessibilityObject.description;
902 AccessibilityObject.description=value;
906 public string AccessibleName {
908 return AccessibilityObject.Name;
912 AccessibilityObject.Name=value;
916 public AccessibleRole AccessibleRole {
918 return AccessibilityObject.role;
922 AccessibilityObject.role=value;
926 public virtual bool AllowDrop {
928 return XplatUI.State.DropTarget;
932 XplatUI.State.DropTarget=value;
936 public virtual AnchorStyles Anchor {
944 if (parent != null) {
945 parent.PerformLayout(this, "Parent");
950 public virtual Color BackColor {
952 if (background_color.IsEmpty) {
954 return parent.BackColor;
956 return DefaultBackColor;
958 return background_color;
962 background_color=value;
963 if (this.IsHandleCreated) {
964 XplatUI.SetWindowBackground(this.window.Handle, value);
967 OnBackColorChanged(EventArgs.Empty);
972 public virtual Image BackgroundImage {
974 return background_image;
978 if (background_image!=value) {
979 background_image=value;
980 OnBackgroundImageChanged(EventArgs.Empty);
985 public virtual BindingContext BindingContext {
987 throw new NotImplementedException();
991 throw new NotImplementedException();
997 if ((this is Form) && (((Form)this).form_parent_window != null)) {
998 return ((Form)this).form_parent_window.Bottom;
1001 return bounds.Y+bounds.Height;
1005 public Rectangle Bounds {
1011 SetBoundsCore(value.Left, value.Top, value.Width, value.Height, BoundsSpecified.All);
1015 public bool CanFocus {
1017 if (is_visible && is_enabled && GetStyle(ControlStyles.Selectable)) {
1024 public bool CanSelect {
1028 if (!GetStyle(ControlStyles.Selectable) || this.parent == null) {
1032 parent = this.parent;
1033 while (parent != null) {
1034 if (!parent.is_visible || !parent.is_enabled) {
1038 parent = parent.parent;
1044 public bool Capture {
1046 return this.is_captured;
1050 if (this.IsHandleCreated) {
1051 if (value && !is_captured) {
1053 XplatUI.GrabWindow(this.window.Handle, IntPtr.Zero);
1054 } else if (!value && is_captured) {
1055 XplatUI.ReleaseWindow(this.window.Handle);
1056 is_captured = false;
1062 public bool CausesValidation {
1064 return this.causes_validation;
1068 if (this.causes_validation != value) {
1069 causes_validation = value;
1070 OnCausesValidationChanged(EventArgs.Empty);
1075 public Rectangle ClientRectangle {
1077 client_rect.Width = client_size.Width;
1078 client_rect.Height = client_size.Height;
1083 public Size ClientSize {
1086 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1087 return ((Form)this).form_parent_window.ClientSize;
1095 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1096 ((Form)this).form_parent_window.ClientSize = value;
1100 this.SetClientSizeCore(value.Width, value.Height);
1104 public String CompanyName {
1106 return "Mono Project, Novell, Inc.";
1110 public bool ContainsFocus {
1116 for (int i=0; i < child_controls.Count; i++) {
1117 if (child_controls[i].ContainsFocus) {
1124 public virtual ContextMenu ContextMenu {
1126 return context_menu;
1130 if (context_menu != value) {
1131 context_menu = value;
1132 OnContextMenuChanged(EventArgs.Empty);
1137 public ControlCollection Controls {
1139 return this.child_controls;
1143 public bool Created {
1145 if (!this.is_disposed && (this.window.Handle != IntPtr.Zero)) {
1153 public virtual Cursor Cursor {
1155 throw new NotImplementedException();
1159 throw new NotImplementedException();
1163 public ControlBidingsCollection DataBindings {
1165 throw new NotImplementedException();
1169 public virtual Rectangle DisplayRectangle {
1171 return ClientRectangle;
1175 public bool Disposing {
1181 public virtual DockStyle Dock {
1187 if (dock_style == value) {
1193 if (parent != null) {
1194 parent.PerformLayout(this, "Parent");
1197 OnDockChanged(EventArgs.Empty);
1201 public bool Enabled {
1207 if (is_enabled == value) {
1213 OnEnabledChanged (EventArgs.Empty);
1217 public virtual bool Focused {
1219 return this.has_focus;
1223 public virtual Font Font {
1229 if (Parent != null && Parent.Font != null) {
1237 if (font == value) {
1243 OnFontChanged (EventArgs.Empty);
1247 public virtual Color ForeColor {
1249 if (foreground_color.IsEmpty) {
1251 return parent.ForeColor;
1253 return DefaultForeColor;
1255 return foreground_color;
1259 if (foreground_color != value) {
1260 foreground_color=value;
1262 OnForeColorChanged(EventArgs.Empty);
1267 public IntPtr Handle { // IWin32Window
1269 if (!IsHandleCreated) {
1272 return window.Handle;
1276 public bool HasChildren {
1278 if (this.child_controls.Count>0) {
1287 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1288 return ((Form)this).form_parent_window.Height;
1290 return this.bounds.Height;
1294 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1295 ((Form)this).form_parent_window.Height = value;
1299 SetBoundsCore(bounds.X, bounds.Y, bounds.Width, value, BoundsSpecified.Height);
1303 public ImeMode ImeMode {
1313 public bool InvokeRequired { // ISynchronizeInvoke
1315 if (creator_thread!=Thread.CurrentThread) {
1322 public bool IsAccessible {
1324 return is_accessible;
1328 is_accessible = value;
1332 public bool IsDisposed {
1334 return this.is_disposed;
1338 public bool IsHandleCreated {
1340 if ((window!=null) && (window.Handle!=IntPtr.Zero)) {
1350 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1351 return ((Form)this).form_parent_window.Left;
1354 return this.bounds.X;
1358 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1359 ((Form)this).form_parent_window.Left = value;
1363 SetBoundsCore(value, bounds.Y, bounds.Width, bounds.Height, BoundsSpecified.X);
1367 public Point Location {
1369 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1370 return ((Form)this).form_parent_window.Location;
1372 return new Point(bounds.X, bounds.Y);
1376 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1377 ((Form)this).form_parent_window.Location = value;
1381 SetBoundsCore(value.X, value.Y, bounds.Width, bounds.Height, BoundsSpecified.Location);
1385 public string Name {
1395 public Control Parent {
1401 if (value == this) {
1402 throw new ArgumentException("A circular control reference has been made. A control cannot be owned or parented to itself.");
1405 if (parent!=value) {
1407 parent.Controls.Remove(this);
1412 if (!parent.Controls.Contains(this)) {
1413 parent.Controls.Add(this);
1416 XplatUI.SetParent(Handle, value.Handle);
1423 public string ProductName {
1425 return "Novell Mono .NET Framework";
1429 public string ProductVersion {
1431 return "1.1.4322.573";
1435 public bool RecreatingHandle {
1437 return is_recreating;
1441 public Region Region {
1443 return new Region(this.bounds);
1450 g = this.CreateGraphics();
1451 r = value.GetBounds(g);
1453 SetBounds((int)r.X, (int)r.Y, (int)r.Width, (int)r.Height);
1461 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1462 return ((Form)this).form_parent_window.Right;
1465 return this.bounds.X+this.bounds.Width;
1469 public virtual RightToLeft RightToLeft {
1471 return right_to_left;
1475 if (value != right_to_left) {
1476 right_to_left = value;
1477 OnRightToLeftChanged(EventArgs.Empty);
1482 public override ISite Site {
1494 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1495 return ((Form)this).form_parent_window.Size;
1497 return new Size(Width, Height);
1501 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1502 ((Form)this).form_parent_window.Size = value;
1505 SetBoundsCore(bounds.X, bounds.Y, value.Width, value.Height, BoundsSpecified.Size);
1509 public int TabIndex {
1511 if (tab_index != -1) {
1518 if (tab_index != value) {
1520 OnTabIndexChanged(EventArgs.Empty);
1525 public bool TabStop {
1541 control_tag = value;
1545 public virtual string Text {
1551 if (value == null) {
1552 value = String.Empty;
1557 XplatUI.Text(Handle, text);
1558 // FIXME: Do we need a Refresh() here?
1559 OnTextChanged (EventArgs.Empty);
1566 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1567 return ((Form)this).form_parent_window.Top;
1569 return this.bounds.Y;
1573 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1574 ((Form)this).form_parent_window.Top = value;
1578 SetBoundsCore(bounds.X, value, bounds.Width, bounds.Height, BoundsSpecified.Y);
1582 public Control TopLevelControl {
1586 while (p.parent != null) {
1594 public bool Visible {
1596 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1597 return ((Form)this).form_parent_window.Visible;
1607 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1608 ((Form)this).form_parent_window.Visible = value;
1612 SetVisibleCore(value);
1618 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1619 return ((Form)this).form_parent_window.Width;
1621 return this.bounds.Width;
1625 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1626 ((Form)this).form_parent_window.Width = value;
1630 SetBoundsCore(bounds.X, bounds.Y, value, bounds.Height, BoundsSpecified.Width);
1634 public IWindowTarget WindowTarget {
1643 #endregion // Public Instance Properties
1645 #region Protected Instance Properties
1646 protected virtual CreateParams CreateParams {
1648 CreateParams create_params = new CreateParams();
1650 create_params.Caption = Text;
1651 create_params.X = Left;
1652 create_params.Y = Top;
1653 create_params.Width = Width;
1654 create_params.Height = Height;
1656 create_params.ClassName = XplatUI.DefaultClassName;
1657 create_params.ClassStyle = 0;
1658 create_params.ExStyle = 0;
1659 create_params.Param = 0;
1662 create_params.Parent = parent.Handle;
1665 create_params.Style = (int)WindowStyles.WS_CHILD | (int)WindowStyles.WS_CLIPCHILDREN | (int)WindowStyles.WS_CLIPSIBLINGS;
1668 create_params.Style |= (int)WindowStyles.WS_VISIBLE;
1671 return create_params;
1675 protected virtual ImeMode DefaultImeMode {
1677 return ImeMode.Inherit;
1681 protected virtual Size DefaultSize {
1683 return new Size(100, 23);
1687 protected int FontHeight {
1697 protected bool RenderRightToLeft {
1699 return (this.right_to_left == RightToLeft.Yes);
1703 ;; // Nothing to do?
1707 protected bool ResizeRedraw {
1709 return GetStyle(ControlStyles.ResizeRedraw);
1713 SetStyle(ControlStyles.ResizeRedraw, value);
1717 protected virtual bool ShowFocusCues {
1723 protected bool ShowKeyboardCues {
1728 #endregion // Protected Instance Properties
1730 #region Public Static Methods
1731 public static Control FromChildHandle(IntPtr handle) {
1732 IEnumerator control = Control.controls.GetEnumerator();
1734 while (control.MoveNext()) {
1735 if (((Control)control.Current).window.Handle == handle) {
1737 if (((Control)control.Current).Parent != null) {
1738 return ((Control)control.Current).Parent;
1745 public static Control FromHandle(IntPtr handle) {
1746 IEnumerator control = Control.controls.GetEnumerator();
1748 while (control.MoveNext()) {
1749 if (((Control)control.Current).window.Handle == handle) {
1751 return ((Control)control.Current);
1757 public static bool IsMnemonic(char charCode, string text) {
1760 amp = text.IndexOf('&');
1763 if (amp + 1 < text.Length) {
1764 if (text[amp + 1] != '&') {
1765 if (Char.ToUpper(charCode) == Char.ToUpper(text.ToCharArray(amp + 1, 1)[0])) {
1775 #region Protected Static Methods
1776 protected static bool ReflectMessage(IntPtr hWnd, ref Message m) {
1779 c = Control.FromHandle(hWnd);
1789 #region Public Instance Methods
1790 public IAsyncResult BeginInvoke(Delegate method) {
1791 return BeginInvokeInternal(method, null);
1794 public IAsyncResult BeginInvoke (Delegate method, object[] args) {
1795 return BeginInvokeInternal (method, args);
1798 public void BringToFront() {
1799 if ((parent != null) && (parent.child_controls[0]!=this)) {
1800 if (parent.child_controls.Contains(this)) {
1801 parent.child_controls.SetChildIndex(this, 0);
1805 XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, true, false);
1807 if (parent != null) {
1812 public bool Contains(Control ctl) {
1813 while (ctl != null) {
1822 public void CreateControl() {
1824 if (!IsHandleCreated)
1827 for (int i=0; i<child_controls.Count; i++) {
1828 child_controls[i].CreateControl();
1833 public Graphics CreateGraphics() {
1834 if (!IsHandleCreated) {
1835 this.CreateHandle();
1837 return Graphics.FromHwnd(this.window.Handle);
1840 [MonoTODO("Come up with cross platform drag-drop driver interface")]
1841 public DragDropEffects DoDragDrop(object data, DragDropEffects allowedEffects) {
1842 return DragDropEffects.None;
1845 public object EndInvoke (IAsyncResult async_result) {
1846 AsyncMethodResult result = (AsyncMethodResult) async_result;
1847 return result.EndInvoke ();
1850 public bool Focus() {
1851 if (IsHandleCreated) {
1852 XplatUI.SetFocus(window.Handle);
1857 public Control GetChildAtPoint(Point pt) {
1858 // Microsoft's version of this function doesn't seem to work, so I can't check
1859 // if we only consider children or also grandchildren, etc.
1860 // I'm gonna say 'children only'
1861 for (int i=0; i<child_controls.Count; i++) {
1862 if (child_controls[i].Bounds.Contains(pt)) {
1863 return child_controls[i];
1869 public IContainerControl GetContainerControl() {
1870 Control current = this;
1872 while (current!=null) {
1873 if ((current is IContainerControl) && ((current.control_style & ControlStyles.ContainerControl)!=0)) {
1874 return (IContainerControl)current;
1876 current = current.parent;
1881 public Control GetNextControl(Control ctl, bool forward) {
1882 // If we're not a container we don't play
1883 if (!(this is IContainerControl) && !this.GetStyle(ControlStyles.ContainerControl)) {
1887 // If ctl is not contained by this, we start at the first child of this
1888 if (!this.Contains(ctl)) {
1892 // Search through our controls, starting at ctl, stepping into children as we encounter them
1893 // try to find the control with the tabindex closest to our own, or, if we're looking into
1894 // child controls, the one with the smallest tabindex
1896 return FindControlForward(this, ctl);
1898 return FindControlBackward(this, ctl);
1901 public void Hide() {
1902 this.Visible = false;
1905 public void Invalidate() {
1906 Invalidate(ClientRectangle, false);
1909 public void Invalidate(bool invalidateChildren) {
1910 Invalidate(ClientRectangle, invalidateChildren);
1913 public void Invalidate(System.Drawing.Rectangle rc) {
1914 Invalidate(rc, false);
1917 public void Invalidate(System.Drawing.Rectangle rc, bool invalidateChildren) {
1918 if (!IsHandleCreated || !Visible) {
1922 XplatUI.Invalidate(Handle, rc, !GetStyle (ControlStyles.AllPaintingInWmPaint));
1924 if (invalidateChildren) {
1925 for (int i=0; i<child_controls.Count; i++) child_controls[i].Invalidate();
1929 public void Invalidate(System.Drawing.Region region) {
1930 Invalidate(region, false);
1933 [MonoTODO("Figure out if GetRegionScans is usable")]
1934 public void Invalidate(System.Drawing.Region region, bool invalidateChildren) {
1935 throw new NotImplementedException();
1937 // FIXME - should use the GetRegionScans function of the region to invalidate each area
1938 //if (invalidateChildren) {
1939 // for (int i=0; i<child_controls.Count; i++) child_controls[i].Invalidate();
1943 public object Invoke (Delegate method) {
1944 return Invoke(method, null);
1947 public object Invoke (Delegate method, object[] args) {
1948 IAsyncResult result = BeginInvoke (method, args);
1949 return EndInvoke(result);
1952 public void PerformLayout() {
1953 PerformLayout(null, null);
1956 public void PerformLayout(Control affectedControl, string affectedProperty) {
1957 LayoutEventArgs levent = new LayoutEventArgs(affectedControl, affectedProperty);
1959 if (layout_suspended>0) {
1960 layout_pending = true;
1964 layout_pending = false;
1966 // Prevent us from getting messed up
1969 // Perform all Dock and Anchor calculations
1972 AnchorStyles anchor;
1977 space=this.DisplayRectangle;
1978 if (prev_size != Size.Empty) {
1979 diff_width = space.Width - prev_size.Width;
1980 diff_height = space.Height - prev_size.Height;
1986 // Deal with docking; go through in reverse, MS docs say that lowest Z-order is closest to edge
1987 for (int i = child_controls.Count - 1; i >= 0; i--) {
1988 child=child_controls[i];
1989 switch (child.Dock) {
1990 case DockStyle.None: {
1995 case DockStyle.Left: {
1996 child.SetBounds(space.Left, space.Y, child.Width, space.Height);
1997 space.X+=child.Width;
1998 space.Width-=child.Width;
2002 case DockStyle.Top: {
2003 child.SetBounds(space.Left, space.Y, space.Width, child.Height);
2004 space.Y+=child.Height;
2005 space.Height-=child.Height;
2009 case DockStyle.Right: {
2010 child.SetBounds(space.Right-child.Width, space.Y, child.Width, space.Height);
2011 space.Width-=child.Width;
2015 case DockStyle.Bottom: {
2016 child.SetBounds(space.Left, space.Bottom-child.Height, space.Width, child.Height);
2017 space.Height-=child.Height;
2021 case DockStyle.Fill: {
2022 child.SetBounds(space.Left, space.Top, space.Width, space.Height);
2030 space=this.DisplayRectangle;
2032 // Deal with anchoring
2033 for (int i=0; i < child_controls.Count; i++) {
2039 child=child_controls[i];
2040 anchor=child.Anchor;
2045 height=child.Height;
2047 // If the control is docked we don't need to do anything
2048 if (child.Dock != DockStyle.None) {
2052 if ((anchor & AnchorStyles.Left) !=0 ) {
2053 if ((anchor & AnchorStyles.Right) != 0) {
2054 // Anchoring to left and right
2055 width=width+diff_width;
2059 } else if ((anchor & AnchorStyles.Right) != 0) {
2065 if ((anchor & AnchorStyles.Top) !=0 ) {
2066 if ((anchor & AnchorStyles.Bottom) != 0) {
2067 height+=diff_height;
2071 } else if ((anchor & AnchorStyles.Bottom) != 0) {
2086 child.SetBounds(left, top, width, height);
2089 // Let everyone know
2093 // Need to make sure we decremend layout_suspended
2099 public Point PointToClient (Point p) {
2103 XplatUI.ScreenToClient (Handle, ref x, ref y);
2105 return new Point (x, y);
2108 public Point PointToScreen(Point p) {
2112 XplatUI.ClientToScreen(Handle, ref x, ref y);
2114 return new Point(x, y);
2117 public virtual bool PreProcessMessage(ref Message msg) {
2120 if (msg.Msg == (int)Msg.WM_KEYDOWN) {
2121 key_data = (Keys)msg.WParam.ToInt32();
2122 if (!ProcessCmdKey(ref msg, key_data)) {
2123 if (IsInputKey(key_data)) {
2127 return ProcessDialogKey(key_data);
2131 } else if (msg.Msg == (int)Msg.WM_CHAR) {
2132 if (IsInputChar((char)msg.WParam)) {
2136 return ProcessDialogChar((char)msg.WParam);
2142 public virtual void Refresh() {
2143 if (IsHandleCreated == true) {
2144 XplatUI.RefreshWindow(window.Handle);
2148 public void ResumeLayout() {
2149 ResumeLayout (true);
2152 public void ResumeLayout(bool performLayout) {
2155 if (layout_suspended > 0) {
2159 if (performLayout || layout_pending) {
2164 public void Select() {
2165 Select(false, false);
2168 public bool SelectNextControl(Control ctl, bool forward, bool tabStopOnly, bool nested, bool wrap) {
2173 c = GetNextControl(c, forward);
2182 if (c.CanSelect && ((c.parent == this) || nested) && (c.tab_stop || !tabStopOnly)) {
2186 } while (c != ctl); // If we wrap back to ourselves we stop
2191 public void SendToBack() {
2192 if ((parent != null) && (parent.child_controls[parent.child_controls.Count-1]!=this)) {
2193 if (parent.child_controls.Contains(this)) {
2194 parent.child_controls.SetChildIndex(this, parent.child_controls.Count);
2198 XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, false, true);
2199 if (parent != null) {
2204 public void SetBounds(int x, int y, int width, int height) {
2205 SetBoundsCore(x, y, width, height, BoundsSpecified.All);
2208 public void SetBounds(int x, int y, int width, int height, BoundsSpecified specified) {
2209 SetBoundsCore(x, y, width, height, specified);
2212 public void Show() {
2213 if (!IsHandleCreated) {
2214 this.CreateHandle();
2220 public void SuspendLayout() {
2224 #endregion // Public Instance Methods
2226 #region Protected Instance Methods
2227 protected virtual AccessibleObject CreateAccessibilityInstance() {
2228 return new AccessibleObject(this);
2231 protected virtual ControlCollection CreateControlsInstance() {
2232 return new ControlCollection(this);
2235 protected virtual void CreateHandle() {
2237 throw new ObjectDisposedException(Name);
2240 if (IsHandleCreated) {
2245 window = new ControlNativeWindow(this);
2246 window.CreateHandle(CreateParams);
2249 if (window.Handle!=IntPtr.Zero) {
2250 if (!controls.Contains(window.Handle)) {
2254 creator_thread = Thread.CurrentThread;
2256 XplatUI.SetWindowBackground(window.Handle, this.BackColor);
2258 OnHandleCreated(EventArgs.Empty);
2262 protected virtual void DefWndProc(ref Message m) {
2263 window.DefWndProc(ref m);
2266 protected virtual void DestroyHandle() {
2267 if (IsHandleCreated) {
2268 if (Handle != IntPtr.Zero) {
2269 controls.Remove(Handle);
2272 if (window != null) {
2273 window.DestroyHandle();
2278 protected bool GetStyle(ControlStyles flag) {
2279 return (control_style & flag) != 0;
2282 protected bool GetTopLevel() {
2286 protected virtual void InitLayout() {
2287 if (parent != null) {
2288 parent.PerformLayout(this, "parent");
2292 protected virtual bool IsInputChar (char charCode) {
2293 if (parent != null) {
2294 return parent.IsInputChar(charCode);
2300 protected virtual bool IsInputKey (Keys keyData) {
2301 // Doc says this one calls IsInputChar; not sure what to do with that
2305 protected virtual bool ProcessCmdKey(ref Message msg, Keys keyData) {
2306 if ((context_menu != null) && context_menu.ProcessCmdKey(ref msg, keyData)) {
2310 if (parent != null) {
2311 return parent.ProcessCmdKey(ref msg, keyData);
2317 protected virtual bool ProcessDialogChar(char charCode) {
2318 if (parent != null) {
2319 return parent.ProcessDialogChar (charCode);
2325 protected virtual bool ProcessDialogKey (Keys keyData) {
2326 if (parent != null) {
2327 return parent.ProcessDialogKey (keyData);
2333 protected virtual bool ProcessKeyEventArgs (ref Message msg)
2335 KeyEventArgs key_event;
2337 PreProcessMessage(ref msg);
2340 case (int)Msg.WM_KEYDOWN: {
2341 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
2342 OnKeyDown (key_event);
2343 return key_event.Handled;
2345 case (int)Msg.WM_KEYUP: {
2346 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
2347 OnKeyUp (key_event);
2348 return key_event.Handled;
2351 case (int)Msg.WM_CHAR: {
2352 KeyPressEventArgs key_press_event;
2354 key_press_event = new KeyPressEventArgs((char)msg.WParam);
2355 OnKeyPress(key_press_event);
2356 return key_press_event.Handled;
2367 protected internal virtual bool ProcessKeyMessage(ref Message msg) {
2368 if (parent != null) {
2369 if (parent.ProcessKeyPreview(ref msg)) {
2374 return ProcessKeyEventArgs(ref msg);
2377 protected virtual bool ProcessKeyPreview(ref Message msg) {
2378 if (parent != null) {
2379 return parent.ProcessKeyPreview(ref msg);
2385 protected virtual bool ProcessMnemonic(char charCode) {
2390 protected void RaiseDragEvent(object key, DragEventArgs e) {
2394 protected void RaiseKeyEvent(object key, KeyEventArgs e) {
2398 protected void RaiseMouseEvent(object key, MouseEventArgs e) {
2402 protected void RaisePaintEvent(object key, PaintEventArgs e) {
2406 protected void RecreateHandle() {
2407 IEnumerator child = child_controls.GetEnumerator();
2411 if (IsHandleCreated) {
2417 while (child.MoveNext()) {
2418 ((Control)child.Current).RecreateHandle();
2424 is_recreating = false;
2427 protected void ResetMouseEventArgs() {
2431 protected ContentAlignment RtlTranslateAlignment(ContentAlignment align) {
2432 if (right_to_left == RightToLeft.No) {
2437 case ContentAlignment.TopLeft: {
2438 return ContentAlignment.TopRight;
2441 case ContentAlignment.TopRight: {
2442 return ContentAlignment.TopLeft;
2445 case ContentAlignment.MiddleLeft: {
2446 return ContentAlignment.MiddleRight;
2449 case ContentAlignment.MiddleRight: {
2450 return ContentAlignment.MiddleLeft;
2453 case ContentAlignment.BottomLeft: {
2454 return ContentAlignment.BottomRight;
2457 case ContentAlignment.BottomRight: {
2458 return ContentAlignment.BottomLeft;
2462 // if it's center it doesn't change
2468 protected HorizontalAlignment RtlTranslateAlignment(HorizontalAlignment align) {
2469 if ((right_to_left == RightToLeft.No) || (align == HorizontalAlignment.Center)) {
2473 if (align == HorizontalAlignment.Left) {
2474 return HorizontalAlignment.Right;
2477 // align must be HorizontalAlignment.Right
2478 return HorizontalAlignment.Left;
2481 protected LeftRightAlignment RtlTranslateAlignment(LeftRightAlignment align) {
2482 if (right_to_left == RightToLeft.No) {
2486 if (align == LeftRightAlignment.Left) {
2487 return LeftRightAlignment.Right;
2490 // align must be LeftRightAlignment.Right;
2491 return LeftRightAlignment.Left;
2494 protected ContentAlignment RtlTranslateContent(ContentAlignment align) {
2495 return RtlTranslateAlignment(align);
2498 protected HorizontalAlignment RtlTranslateHorizontal(HorizontalAlignment align) {
2499 return RtlTranslateAlignment(align);
2502 protected LeftRightAlignment RtlTranslateLeftRight(LeftRightAlignment align) {
2503 return RtlTranslateAlignment(align);
2506 protected virtual void ScaleCore(float dx, float dy) {
2507 throw new NotImplementedException();
2510 protected virtual void Select(bool directed, bool forward) {
2515 // Select this control
2520 if (parent == null) {
2524 index = parent.child_controls.IndexOf(this);
2529 if ((index+1) < parent.child_controls.Count) {
2538 index = parent.child_controls.Count-1;
2541 result = Select(parent.child_controls[index]);
2542 } while (!result && parent.child_controls[index] != this);
2545 protected virtual void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
2546 // SetBoundsCore updates the Win32 control itself. UpdateBounds updates the controls variables and fires events, I'm guessing - pdb
2547 if ((specified & BoundsSpecified.X) != BoundsSpecified.X) {
2551 if ((specified & BoundsSpecified.Y) != BoundsSpecified.Y) {
2555 if ((specified & BoundsSpecified.Width)!= BoundsSpecified.Width) {
2559 if ((specified & BoundsSpecified.Height) != BoundsSpecified.Height) {
2563 if (IsHandleCreated) {
2564 XplatUI.SetWindowPos(Handle, x, y, width, height);
2566 UpdateBounds(x, y, width, height);
2569 protected virtual void SetClientSizeCore(int x, int y) {
2570 // Calculate the actual window size from the client size (it usually stays the same or grows)
2571 Rectangle ClientRect;
2572 Rectangle WindowRect;
2575 ClientRect = new Rectangle(0, 0, x, y);
2576 cp = this.CreateParams;
2578 if (XplatUI.CalculateWindowRect(Handle, ref ClientRect, cp.Style, false, out WindowRect)==false) {
2582 this.client_size = new Size(x, y);
2583 SetBoundsCore(bounds.X, bounds.Y, WindowRect.Width, WindowRect.Height, BoundsSpecified.Size);
2586 protected void SetStyle(ControlStyles flag, bool value) {
2588 control_style |= flag;
2590 control_style &= ~flag;
2594 protected void SetTopLevel(bool value) {
2595 if ((GetTopLevel() != value) && (parent != null)) {
2596 throw new Exception();
2600 if (value == true) {
2610 is_toplevel = value;
2613 protected virtual void SetVisibleCore(bool value) {
2614 if (value!=is_visible) {
2616 XplatUI.SetVisible(Handle, value);
2617 OnVisibleChanged(EventArgs.Empty);
2619 if (dc_mem != null) {
2624 if (bmp_mem != null) {
2629 this.CreateBuffers(bounds.Width, bounds.Height);
2632 // FIXME - deal with focus
2634 if (parent != null) {
2635 parent.PerformLayout(this, "visible");
2637 PerformLayout(this, "visible");
2642 protected void UpdateBounds() {
2650 if (!IsHandleCreated) {
2654 XplatUI.GetWindowPos(this.Handle, out x, out y, out width, out height, out client_width, out client_height);
2655 UpdateBounds(x, y, width, height, client_width, client_height);
2658 protected void UpdateBounds(int x, int y, int width, int height) {
2659 // UpdateBounds only seems to set our sizes and fire events but not update the GUI window to match
2661 bool resized = false;
2663 int client_x_diff = this.bounds.Width-this.client_size.Width;
2664 int client_y_diff = this.bounds.Height-this.client_size.Height;
2666 // Needed to generate required notifications
2667 if ((this.bounds.X!=x) || (this.bounds.Y!=y)) {
2671 if ((this.Bounds.Width!=width) || (this.Bounds.Height!=height)) {
2678 bounds.Height=height;
2680 // Update client rectangle as well
2681 if (this.layout_suspended==0) {
2682 prev_size.Width=client_size.Width;
2683 prev_size.Height=client_size.Height;
2686 client_size.Width=width-client_x_diff;
2687 client_size.Height=height-client_y_diff;
2690 OnLocationChanged(EventArgs.Empty);
2694 OnSizeChanged(EventArgs.Empty);
2698 protected void UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) {
2699 UpdateBounds(x, y, width, height);
2701 this.client_size.Width=clientWidth;
2702 this.client_size.Height=clientHeight;
2705 protected void UpdateStyles() {
2706 if (!IsHandleCreated) {
2710 XplatUI.SetWindowStyle(window.Handle, CreateParams);
2713 protected void UpdateZOrder() {
2718 if (parent == null) {
2724 children = ctl.child_controls.Count;
2725 for (int i = 1; i < children; i++ ) {
2726 XplatUI.SetZOrder(ctl.child_controls[i].window.Handle, ctl.child_controls[i-1].window.Handle, false, false);
2729 children = child_controls.Count;
2730 for (int i = 1; i < children; i++ ) {
2731 XplatUI.SetZOrder(child_controls[i].window.Handle, child_controls[i-1].window.Handle, false, false);
2737 protected virtual void WndProc(ref Message m) {
2739 Console.WriteLine("Received message {0}", m);
2741 if ((this.control_style & ControlStyles.EnableNotifyMessage) != 0) {
2745 switch((Msg)m.Msg) {
2746 case Msg.WM_WINDOWPOSCHANGED: {
2749 if (GetStyle(ControlStyles.ResizeRedraw)) {
2756 case Msg.WM_PAINT: {
2757 PaintEventArgs paint_event;
2759 paint_event = XplatUI.PaintEventStart(Handle);
2760 OnPaint(paint_event);
2761 XplatUI.PaintEventEnd(Handle);
2766 case Msg.WM_ERASEBKGND: {
2767 if (GetStyle (ControlStyles.UserPaint)) {
2768 if (!GetStyle(ControlStyles.AllPaintingInWmPaint)) {
2769 PaintEventArgs eraseEventArgs = new PaintEventArgs (m.WParam == IntPtr.Zero ? Graphics.FromHwnd (m.HWnd) :
2770 Graphics.FromHdc (m.WParam), new Rectangle (new Point (0,0),Size));
2771 OnPaintBackground (eraseEventArgs);
2773 m.Result = (IntPtr)1;
2775 m.Result = IntPtr.Zero;
2782 case Msg.WM_LBUTTONUP: {
2783 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Left,
2785 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
2787 if (mouse_clicks > 1) {
2793 case Msg.WM_LBUTTONDOWN: {
2794 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
2795 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
2801 case Msg.WM_LBUTTONDBLCLK: {
2803 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
2804 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
2810 case Msg.WM_MBUTTONUP: {
2811 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Middle,
2813 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
2815 if (mouse_clicks > 1) {
2821 case Msg.WM_MBUTTONDOWN: {
2822 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
2823 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
2829 case Msg.WM_MBUTTONDBLCLK: {
2831 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
2832 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
2837 case Msg.WM_RBUTTONUP: {
2838 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Right,
2840 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
2842 if (mouse_clicks > 1) {
2848 case Msg.WM_RBUTTONDOWN: {
2849 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
2850 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
2856 case Msg.WM_RBUTTONDBLCLK: {
2858 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
2859 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
2864 case Msg.WM_MOUSEWHEEL: {
2866 OnMouseWheel (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
2867 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
2868 HighOrder(m.WParam.ToInt32())));
2873 case Msg.WM_MOUSEMOVE: {
2874 OnMouseMove (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
2876 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
2881 case Msg.WM_MOUSE_ENTER: {
2886 OnMouseEnter(EventArgs.Empty);
2890 case Msg.WM_MOUSE_LEAVE: {
2892 OnMouseLeave(EventArgs.Empty);
2896 case Msg.WM_MOUSEHOVER: {
2897 OnMouseHover(EventArgs.Empty);
2901 case Msg.WM_KEYDOWN: {
2902 if (!ProcessKeyMessage(ref m)) {
2909 case Msg.WM_KEYUP: {
2910 if (!ProcessKeyMessage(ref m)) {
2918 if (!ProcessKeyMessage(ref m)) {
2927 if (m.LParam != IntPtr.Zero) {
2930 hi = new HELPINFO();
2932 hi = (HELPINFO) Marshal.PtrToStructure (m.LParam, typeof (HELPINFO));
2933 mouse_pos = new Point(hi.MousePos.x, hi.MousePos.y);
2935 mouse_pos = Control.MousePosition;
2937 OnHelpRequested(new HelpEventArgs(mouse_pos));
2942 case Msg.WM_KILLFOCUS: {
2943 Console.WriteLine("Window {0} lost focus", this.Text);
2944 OnLeave(EventArgs.Empty);
2945 if (CausesValidation) {
2947 e = new CancelEventArgs(false);
2956 OnValidated(EventArgs.Empty);
2959 this.has_focus = false;
2960 OnLostFocus(EventArgs.Empty);
2964 case Msg.WM_SETFOCUS: {
2965 Console.WriteLine("Window {0} got focus", this.Text);
2966 OnEnter(EventArgs.Empty);
2967 this.has_focus = true;
2968 OnGotFocus(EventArgs.Empty);
2974 case Msg.WM_SYSCOLORCHANGE: throw new NotImplementedException(); break;
2986 #endregion // Public Instance Methods
2988 #region OnXXX methods
2989 protected virtual void OnBackColorChanged(EventArgs e) {
2990 if (BackColorChanged!=null) BackColorChanged(this, e);
2991 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackColorChanged(e);
2994 protected virtual void OnBackgroundImageChanged(EventArgs e) {
2995 if (BackgroundImageChanged!=null) BackgroundImageChanged(this, e);
2996 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackgroundImageChanged(e);
2999 protected virtual void OnBindingContextChanged(EventArgs e) {
3000 if (BindingContextChanged!=null) BindingContextChanged(this, e);
3001 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBindingContextChanged(e);
3004 protected virtual void OnCausesValidationChanged(EventArgs e) {
3005 if (CausesValidationChanged!=null) CausesValidationChanged(this, e);
3008 protected virtual void OnChangeUICues(UICuesEventArgs e) {
3009 if (CausesValidationChanged!=null) CausesValidationChanged(this, e);
3012 protected virtual void OnClick(EventArgs e) {
3013 if (Click!=null) Click(this, e);
3016 protected virtual void OnContextMenuChanged(EventArgs e) {
3017 if (ContextMenuChanged!=null) ContextMenuChanged(this, e);
3020 protected virtual void OnControlAdded(ControlEventArgs e) {
3021 if (ControlAdded!=null) ControlAdded(this, e);
3024 protected virtual void OnControlRemoved(ControlEventArgs e) {
3025 if (ControlRemoved!=null) ControlRemoved(this, e);
3028 protected virtual void OnCreateControl() {
3032 protected virtual void OnCursorChanged(EventArgs e) {
3033 if (CursorChanged!=null) CursorChanged(this, e);
3036 protected virtual void OnDockChanged(EventArgs e) {
3037 if (DockChanged!=null) DockChanged(this, e);
3040 protected virtual void OnDoubleClick(EventArgs e) {
3041 if (DoubleClick!=null) DoubleClick(this, e);
3044 protected virtual void OnDragDrop(DragEventArgs drgevent) {
3045 if (DragDrop!=null) DragDrop(this, drgevent);
3048 protected virtual void OnDragEnter(DragEventArgs drgevent) {
3049 if (DragEnter!=null) DragEnter(this, drgevent);
3052 protected virtual void OnDragLeave(EventArgs e) {
3053 if (DragLeave!=null) DragLeave(this, e);
3056 protected virtual void OnDragOver(DragEventArgs drgevent) {
3057 if (DragOver!=null) DragOver(this, drgevent);
3060 protected virtual void OnEnabledChanged(EventArgs e) {
3061 if (EnabledChanged!=null) EnabledChanged(this, e);
3062 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentEnabledChanged(e);
3065 protected virtual void OnEnter(EventArgs e) {
3066 if (Enter!=null) Enter(this, e);
3069 protected virtual void OnFontChanged(EventArgs e) {
3070 if (FontChanged!=null) FontChanged(this, e);
3073 protected virtual void OnForeColorChanged(EventArgs e) {
3074 if (ForeColorChanged!=null) ForeColorChanged(this, e);
3075 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentForeColorChanged(e);
3078 protected virtual void OnGiveFeedback(GiveFeedbackEventArgs gfbevent) {
3079 if (GiveFeedback!=null) GiveFeedback(this, gfbevent);
3082 protected virtual void OnGotFocus(EventArgs e) {
3083 if (GotFocus!=null) GotFocus(this, e);
3086 protected virtual void OnHandleCreated(EventArgs e) {
3087 if (HandleCreated!=null) HandleCreated(this, e);
3090 protected virtual void OnHandleDestroyed(EventArgs e) {
3091 if (HandleDestroyed!=null) HandleDestroyed(this, e);
3094 protected virtual void OnHelpRequested(HelpEventArgs hevent) {
3095 if (HelpRequested!=null) HelpRequested(this, hevent);
3098 protected virtual void OnImeModeChanged(EventArgs e) {
3099 if (ImeModeChanged!=null) ImeModeChanged(this, e);
3102 protected virtual void OnInvalidated(InvalidateEventArgs e) {
3103 if (Invalidated!=null) Invalidated(this, e);
3106 protected virtual void OnKeyDown(KeyEventArgs e) {
3107 if (KeyDown!=null) KeyDown(this, e);
3110 protected virtual void OnKeyPress(KeyPressEventArgs e) {
3111 if (KeyPress!=null) KeyPress(this, e);
3114 protected virtual void OnKeyUp(KeyEventArgs e) {
3115 if (KeyUp!=null) KeyUp(this, e);
3118 protected virtual void OnLayout(LayoutEventArgs levent) {
3119 if (Layout!=null) Layout(this, levent);
3122 protected virtual void OnLeave(EventArgs e) {
3123 if (Leave!=null) Leave(this, e);
3126 protected virtual void OnLocationChanged(EventArgs e) {
3127 if (LocationChanged!=null) LocationChanged(this, e);
3130 protected virtual void OnLostFocus(EventArgs e) {
3131 if (LostFocus!=null) LostFocus(this, e);
3134 protected virtual void OnMouseDown(MouseEventArgs e) {
3135 if (MouseDown!=null) MouseDown(this, e);
3138 protected virtual void OnMouseEnter(EventArgs e) {
3139 if (MouseEnter!=null) MouseEnter(this, e);
3142 protected virtual void OnMouseHover(EventArgs e) {
3143 if (MouseHover!=null) MouseHover(this, e);
3146 protected virtual void OnMouseLeave(EventArgs e) {
3147 if (MouseLeave!=null) MouseLeave(this, e);
3150 protected virtual void OnMouseMove(MouseEventArgs e) {
3151 if (MouseMove!=null) MouseMove(this, e);
3154 protected virtual void OnMouseUp(MouseEventArgs e) {
3155 if (MouseUp!=null) MouseUp(this, e);
3158 protected virtual void OnMouseWheel(MouseEventArgs e) {
3159 if (MouseWheel!=null) MouseWheel(this, e);
3162 protected virtual void OnMove(EventArgs e) {
3163 if (Move!=null) Move(this, e);
3166 protected virtual void OnNotifyMessage(Message m) {
3170 protected virtual void OnPaint(PaintEventArgs e) {
3171 if (Paint!=null) Paint(this, e);
3174 protected virtual void OnPaintBackground(PaintEventArgs pevent) {
3178 protected virtual void OnParentBackColorChanged(EventArgs e) {
3179 if (background_color.IsEmpty && background_image==null) {
3181 OnBackColorChanged(e);
3185 protected virtual void OnParentBackgroundImageChanged(EventArgs e) {
3186 if (background_color.IsEmpty && background_image==null) {
3188 OnBackgroundImageChanged(e);
3192 protected virtual void OnParentBindingContextChanged(EventArgs e) {
3193 if (binding_context==null) {
3194 binding_context=Parent.binding_context;
3195 OnBindingContextChanged(e);
3199 protected virtual void OnParentChanged(EventArgs e) {
3200 if (ParentChanged!=null) ParentChanged(this, e);
3203 protected virtual void OnParentEnabledChanged(EventArgs e) {
3204 if (is_enabled != Parent.is_enabled) {
3205 is_enabled=Parent.is_enabled;
3207 if (EnabledChanged != null) {
3208 EnabledChanged(this, e);
3213 protected virtual void OnParentFontChanged(EventArgs e) {
3220 protected virtual void OnParentForeColorChanged(EventArgs e) {
3221 if (foreground_color.IsEmpty) {
3223 OnForeColorChanged(e);
3227 protected virtual void OnParentRightToLeftChanged(EventArgs e) {
3228 if (right_to_left==RightToLeft.Inherit) {
3230 OnRightToLeftChanged(e);
3234 protected virtual void OnParentVisibleChanged(EventArgs e) {
3235 if (is_visible!=Parent.is_visible) {
3238 OnVisibleChanged(e);
3242 protected virtual void OnQueryContinueDrag(QueryContinueDragEventArgs e) {
3243 if (QueryContinueDrag!=null) QueryContinueDrag(this, e);
3246 protected virtual void OnResize(EventArgs e) {
3247 if (Resize!=null) Resize(this, e);
3249 PerformLayout(this, "bounds");
3251 if (parent != null) {
3252 parent.PerformLayout();
3256 protected virtual void OnRightToLeftChanged(EventArgs e) {
3257 if (RightToLeftChanged!=null) RightToLeftChanged(this, e);
3258 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentRightToLeftChanged(e);
3261 protected virtual void OnSizeChanged(EventArgs e) {
3262 InvalidateBuffers ();
3264 if (SizeChanged!=null) SizeChanged(this, e);
3267 protected virtual void OnStyleChanged(EventArgs e) {
3268 if (StyleChanged!=null) StyleChanged(this, e);
3271 protected virtual void OnSystemColorsChanged(EventArgs e) {
3272 if (SystemColorsChanged!=null) SystemColorsChanged(this, e);
3275 protected virtual void OnTabIndexChanged(EventArgs e) {
3276 if (TabIndexChanged!=null) TabIndexChanged(this, e);
3279 protected virtual void OnTabStopChanged(EventArgs e) {
3280 if (TabStopChanged!=null) TabStopChanged(this, e);
3283 protected virtual void OnTextChanged(EventArgs e) {
3284 if (TextChanged!=null) TextChanged(this, e);
3287 protected virtual void OnValidated(EventArgs e) {
3288 if (Validated!=null) Validated(this, e);
3291 protected virtual void OnValidating(System.ComponentModel.CancelEventArgs e) {
3292 if (Validating!=null) Validating(this, e);
3295 protected virtual void OnVisibleChanged(EventArgs e) {
3302 if (bmp_mem!=null) {
3308 if (!this.IsHandleCreated) {
3309 this.CreateHandle();
3315 if (VisibleChanged!=null) VisibleChanged(this, e);
3317 // We need to tell our kids
3318 for (int i=0; i<child_controls.Count; i++) {
3319 child_controls[i].OnParentVisibleChanged(e);
3322 #endregion // OnXXX methods
3325 public event EventHandler BackColorChanged;
3326 public event EventHandler BackgroundImageChanged;
3327 public event EventHandler BindingContextChanged;
3328 public event EventHandler CausesValidationChanged;
3329 public event UICuesEventHandler ChangeUICues;
3330 public event EventHandler Click;
3331 public event EventHandler ContextMenuChanged;
3332 public event ControlEventHandler ControlAdded;
3333 public event ControlEventHandler ControlRemoved;
3334 public event EventHandler CursorChanged;
3335 public event EventHandler DockChanged;
3336 public event EventHandler DoubleClick;
3337 public event DragEventHandler DragDrop;
3338 public event DragEventHandler DragEnter;
3339 public event EventHandler DragLeave;
3340 public event DragEventHandler DragOver;
3341 public event EventHandler EnabledChanged;
3342 public event EventHandler Enter;
3343 public event EventHandler FontChanged;
3344 public event EventHandler ForeColorChanged;
3345 public event GiveFeedbackEventHandler GiveFeedback;
3346 public event EventHandler GotFocus;
3347 public event EventHandler HandleCreated;
3348 public event EventHandler HandleDestroyed;
3349 public event HelpEventHandler HelpRequested;
3350 public event EventHandler ImeModeChanged;
3351 public event InvalidateEventHandler Invalidated;
3352 public event KeyEventHandler KeyDown;
3353 public event KeyPressEventHandler KeyPress;
3354 public event KeyEventHandler KeyUp;
3355 public event LayoutEventHandler Layout;
3356 public event EventHandler Leave;
3357 public event EventHandler LocationChanged;
3358 public event EventHandler LostFocus;
3359 public event MouseEventHandler MouseDown;
3360 public event EventHandler MouseEnter;
3361 public event EventHandler MouseHover;
3362 public event EventHandler MouseLeave;
3363 public event MouseEventHandler MouseMove;
3364 public event MouseEventHandler MouseUp;
3365 public event MouseEventHandler MouseWheel;
3366 public event EventHandler Move;
3367 public event PaintEventHandler Paint;
3368 public event EventHandler ParentChanged;
3369 public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp;
3370 public event QueryContinueDragEventHandler QueryContinueDrag;
3371 public event EventHandler Resize;
3372 public event EventHandler RightToLeftChanged;
3373 public event EventHandler SizeChanged;
3374 public event EventHandler StyleChanged;
3375 public event EventHandler SystemColorsChanged;
3376 public event EventHandler TabIndexChanged;
3377 public event EventHandler TabStopChanged;
3378 public event EventHandler TextChanged;
3379 public event EventHandler Validated;
3380 public event CancelEventHandler Validating;
3381 public event EventHandler VisibleChanged;
3382 #endregion // Events