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
76 internal Cursor cursor; // Cursor for the window
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;
503 control_style = ControlStyles.Selectable | ControlStyles.StandardClick | ControlStyles.StandardDoubleClick;
506 background_image = null;
510 child_controls = CreateControlsInstance();
511 client_size = new Size(DefaultSize.Width, DefaultSize.Height);
512 client_rect = new Rectangle(0, 0, DefaultSize.Width, DefaultSize.Height);
513 XplatUI.CalculateWindowRect(IntPtr.Zero, ref client_rect, CreateParams.Style, false, out bounds);
514 if ((CreateParams.Style & (int)WindowStyles.WS_CHILD) == 0) {
520 public Control(Control parent, string text) : this() {
525 public Control(Control parent, string text, int left, int top, int width, int height) : this() {
530 bounds.Height=height;
531 SetBoundsCore(left, top, width, height, BoundsSpecified.All);
535 public Control(string text) : this() {
539 public Control(string text, int left, int top, int width, int height) : this() {
543 bounds.Height=height;
544 SetBoundsCore(left, top, width, height, BoundsSpecified.All);
548 protected override void Dispose(bool disposing) {
561 controls.Remove(this);
563 #endregion // Public Constructors
565 #region Internal Properties
566 #endregion // Internal Properties
568 #region Private & Internal Methods
569 internal static IAsyncResult BeginInvokeInternal (Delegate method, object [] args) {
570 AsyncMethodResult result = new AsyncMethodResult ();
571 AsyncMethodData data = new AsyncMethodData ();
573 data.Method = method;
575 data.Result = new WeakReference (result);
577 XplatUI.SendAsyncMethod (data);
581 internal Graphics DeviceContext {
584 CreateBuffers(this.Width, this.Height);
590 internal Bitmap ImageBuffer {
593 CreateBuffers(this.Width, this.Height);
599 internal void CreateBuffers (int width, int height) {
600 if (double_buffering == false)
616 bmp_mem = new Bitmap (width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
617 dc_mem = Graphics.FromImage (bmp_mem);
620 internal void InvalidateBuffers ()
622 if (double_buffering == false)
634 internal static void SetChildColor(Control parent) {
637 for (int i=0; i < parent.child_controls.Count; i++) {
638 child=parent.child_controls[i];
639 if (child.IsHandleCreated) {
640 XplatUI.SetWindowBackground(child.window.Handle, child.BackColor);
642 if (child.child_controls.Count>0) {
643 SetChildColor(child);
649 private bool Select(Control control) {
651 IContainerControl container;
653 if (control == null) {
657 parent = control.parent;
659 if (((control.control_style & ControlStyles.Selectable) !=0) && (parent != null)) {
660 while (parent != null) {
661 if (!parent.is_visible || !parent.is_enabled) {
664 parent = parent.parent;
668 control.is_selected = true;
670 XplatUI.SetFocus(control.window.Handle);
671 container = GetContainerControl();
672 if (container != null) {
673 container.ActiveControl = control;
679 private Control FindTabStop(Control control, bool forward) {
680 if (control == null) {
688 internal virtual void DoDefaultAction() {
689 // Only here to be overriden by our actual controls; this is needed by the accessibility class
692 internal static int LowOrder (int param) {
693 return (param & 0xffff);
696 internal static int HighOrder (int param) {
697 return (param >> 16);
700 internal static MouseButtons FromParamToMouseButtons (int param) {
701 MouseButtons buttons = MouseButtons.None;
703 if ((param & (int) MsgButtons.MK_LBUTTON) != 0)
704 buttons |= MouseButtons.Left;
706 if ((param & (int) MsgButtons.MK_MBUTTON) != 0)
707 buttons |= MouseButtons.Middle;
709 if ((param & (int) MsgButtons.MK_RBUTTON) != 0)
710 buttons |= MouseButtons.Right;
716 private static Control FindFlatForward(Control container, Control start) {
722 end = container.child_controls.Count;
725 index = start.tab_index;
730 for (int i = 0; i < end; i++) {
732 if (container.child_controls[i].tab_index > index) {
733 found = container.child_controls[i];
735 } else if (found.tab_index > container.child_controls[i].tab_index) {
736 if (container.child_controls[i].tab_index > index) {
737 found = container.child_controls[i];
744 private static Control FindControlForward(Control container, Control start) {
754 if ((start is IContainerControl) || start.GetStyle(ControlStyles.ContainerControl)) {
755 found = FindControlForward(start, null);
762 while (p != container) {
763 found = FindFlatForward(p, start);
771 return FindFlatForward(container, start);
774 private static Control FindFlatBackward(Control container, Control start) {
780 end = container.child_controls.Count;
783 index = start.tab_index;
785 // FIXME: Possible speed-up: Keep the highest taborder index in the container
787 for (int i = 0; i < end; i++) {
788 if (container.child_controls[i].tab_index > index) {
789 index = container.child_controls[i].tab_index;
795 for (int i = 0; i < end; i++) {
797 if (container.child_controls[i].tab_index < index) {
798 found = container.child_controls[i];
800 } else if (found.tab_index < container.child_controls[i].tab_index) {
801 if (container.child_controls[i].tab_index < index) {
802 found = container.child_controls[i];
809 private static Control FindControlBackward(Control container, Control start) {
819 found = FindFlatBackward(start.parent, start);
820 if (found == null && start.parent != container) {
825 found = FindFlatBackward(container, start);
828 while ((found != null) && ((found is IContainerControl) || found.GetStyle(ControlStyles.ContainerControl))) {
829 found = FindControlBackward(found, null);
837 #endregion // Private & Internal Methods
839 #region Public Static Properties
840 public static Color DefaultBackColor {
842 return ThemeEngine.Current.DefaultControlBackColor;
846 public static Font DefaultFont {
848 return ThemeEngine.Current.DefaultFont;
852 public static Color DefaultForeColor {
854 return ThemeEngine.Current.DefaultControlForeColor;
858 public static Keys ModifierKeys {
860 return XplatUI.State.ModifierKeys;
864 public static MouseButtons MouseButtons {
866 return XplatUI.State.MouseButtons;
870 public static Point MousePosition {
872 return Cursor.Position;
875 #endregion // Public Static Properties
877 #region Public Instance Properties
878 public AccessibleObject AccessibilityObject {
880 if (accessibility_object==null) {
881 accessibility_object=CreateAccessibilityInstance();
883 return accessibility_object;
887 public string AccessibleDefaultActionDescription {
889 return AccessibilityObject.default_action;
893 AccessibilityObject.default_action=value;
897 public string AccessibleDescription {
899 return AccessibilityObject.description;
903 AccessibilityObject.description=value;
907 public string AccessibleName {
909 return AccessibilityObject.Name;
913 AccessibilityObject.Name=value;
917 public AccessibleRole AccessibleRole {
919 return AccessibilityObject.role;
923 AccessibilityObject.role=value;
927 public virtual bool AllowDrop {
929 return XplatUI.State.DropTarget;
933 XplatUI.State.DropTarget=value;
937 public virtual AnchorStyles Anchor {
945 if (parent != null) {
946 parent.PerformLayout(this, "Parent");
951 public virtual Color BackColor {
953 if (background_color.IsEmpty) {
955 return parent.BackColor;
957 return DefaultBackColor;
959 return background_color;
963 background_color=value;
964 if (this.IsHandleCreated) {
965 XplatUI.SetWindowBackground(this.window.Handle, value);
968 OnBackColorChanged(EventArgs.Empty);
973 public virtual Image BackgroundImage {
975 return background_image;
979 if (background_image!=value) {
980 background_image=value;
981 OnBackgroundImageChanged(EventArgs.Empty);
986 public virtual BindingContext BindingContext {
988 throw new NotImplementedException();
992 throw new NotImplementedException();
998 if ((this is Form) && (((Form)this).form_parent_window != null)) {
999 return ((Form)this).form_parent_window.Bottom;
1002 return bounds.Y+bounds.Height;
1006 public Rectangle Bounds {
1012 SetBoundsCore(value.Left, value.Top, value.Width, value.Height, BoundsSpecified.All);
1016 public bool CanFocus {
1018 if (is_visible && is_enabled && GetStyle(ControlStyles.Selectable)) {
1025 public bool CanSelect {
1029 if (!GetStyle(ControlStyles.Selectable) || this.parent == null) {
1033 parent = this.parent;
1034 while (parent != null) {
1035 if (!parent.is_visible || !parent.is_enabled) {
1039 parent = parent.parent;
1045 public bool Capture {
1047 return this.is_captured;
1051 if (this.IsHandleCreated) {
1052 if (value && !is_captured) {
1054 XplatUI.GrabWindow(this.window.Handle, IntPtr.Zero);
1055 } else if (!value && is_captured) {
1056 XplatUI.ReleaseWindow(this.window.Handle);
1057 is_captured = false;
1063 public bool CausesValidation {
1065 return this.causes_validation;
1069 if (this.causes_validation != value) {
1070 causes_validation = value;
1071 OnCausesValidationChanged(EventArgs.Empty);
1076 public Rectangle ClientRectangle {
1078 client_rect.Width = client_size.Width;
1079 client_rect.Height = client_size.Height;
1084 public Size ClientSize {
1087 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1088 return ((Form)this).form_parent_window.ClientSize;
1096 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1097 ((Form)this).form_parent_window.ClientSize = value;
1101 this.SetClientSizeCore(value.Width, value.Height);
1105 public String CompanyName {
1107 return "Mono Project, Novell, Inc.";
1111 public bool ContainsFocus {
1117 for (int i=0; i < child_controls.Count; i++) {
1118 if (child_controls[i].ContainsFocus) {
1125 public virtual ContextMenu ContextMenu {
1127 return context_menu;
1131 if (context_menu != value) {
1132 context_menu = value;
1133 OnContextMenuChanged(EventArgs.Empty);
1138 public ControlCollection Controls {
1140 return this.child_controls;
1144 public bool Created {
1146 if (!this.is_disposed && (this.window.Handle != IntPtr.Zero)) {
1153 public virtual Cursor Cursor {
1155 if (cursor != null) {
1159 if (parent != null) {
1160 return parent.Cursor;
1163 return Cursors.Default;
1167 if (cursor != value) {
1172 pt = Cursor.Position;
1173 if (bounds.Contains(pt)) {
1174 if (GetChildAtPoint(pt) == null) {
1175 if (cursor != null) {
1176 XplatUI.SetCursor(window.Handle, cursor.handle);
1178 if (parent != null) {
1179 XplatUI.SetCursor(window.Handle, parent.Cursor.handle);
1181 XplatUI.SetCursor(window.Handle, Cursors.def.handle);
1187 OnCursorChanged(EventArgs.Empty);
1193 public ControlBindingsCollection DataBindings {
1195 throw new NotImplementedException();
1200 public virtual Rectangle DisplayRectangle {
1202 return ClientRectangle;
1206 public bool Disposing {
1212 public virtual DockStyle Dock {
1218 if (dock_style == value) {
1224 if (parent != null) {
1225 parent.PerformLayout(this, "Parent");
1228 OnDockChanged(EventArgs.Empty);
1232 public bool Enabled {
1238 if (is_enabled == value) {
1244 OnEnabledChanged (EventArgs.Empty);
1248 public virtual bool Focused {
1250 return this.has_focus;
1254 public virtual Font Font {
1260 if (Parent != null && Parent.Font != null) {
1268 if (font == value) {
1274 OnFontChanged (EventArgs.Empty);
1278 public virtual Color ForeColor {
1280 if (foreground_color.IsEmpty) {
1282 return parent.ForeColor;
1284 return DefaultForeColor;
1286 return foreground_color;
1290 if (foreground_color != value) {
1291 foreground_color=value;
1293 OnForeColorChanged(EventArgs.Empty);
1298 public IntPtr Handle { // IWin32Window
1300 if (!IsHandleCreated) {
1303 return window.Handle;
1307 public bool HasChildren {
1309 if (this.child_controls.Count>0) {
1318 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1319 return ((Form)this).form_parent_window.Height;
1321 return this.bounds.Height;
1325 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1326 ((Form)this).form_parent_window.Height = value;
1330 SetBoundsCore(bounds.X, bounds.Y, bounds.Width, value, BoundsSpecified.Height);
1334 public ImeMode ImeMode {
1344 public bool InvokeRequired { // ISynchronizeInvoke
1346 if (creator_thread!=Thread.CurrentThread) {
1353 public bool IsAccessible {
1355 return is_accessible;
1359 is_accessible = value;
1363 public bool IsDisposed {
1365 return this.is_disposed;
1369 public bool IsHandleCreated {
1371 if ((window!=null) && (window.Handle!=IntPtr.Zero)) {
1381 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1382 return ((Form)this).form_parent_window.Left;
1385 return this.bounds.X;
1389 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1390 ((Form)this).form_parent_window.Left = value;
1394 SetBoundsCore(value, bounds.Y, bounds.Width, bounds.Height, BoundsSpecified.X);
1398 public Point Location {
1400 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1401 return ((Form)this).form_parent_window.Location;
1403 return new Point(bounds.X, bounds.Y);
1407 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1408 ((Form)this).form_parent_window.Location = value;
1412 SetBoundsCore(value.X, value.Y, bounds.Width, bounds.Height, BoundsSpecified.Location);
1416 public string Name {
1426 public Control Parent {
1432 if (value == this) {
1433 throw new ArgumentException("A circular control reference has been made. A control cannot be owned or parented to itself.");
1436 if (parent!=value) {
1438 parent.Controls.Remove(this);
1443 if (!parent.Controls.Contains(this)) {
1444 parent.Controls.Add(this);
1447 XplatUI.SetParent(Handle, value.Handle);
1454 public string ProductName {
1456 return "Novell Mono .NET Framework";
1460 public string ProductVersion {
1462 return "1.1.4322.573";
1466 public bool RecreatingHandle {
1468 return is_recreating;
1472 public Region Region {
1474 return new Region(this.bounds);
1481 g = this.CreateGraphics();
1482 r = value.GetBounds(g);
1484 SetBounds((int)r.X, (int)r.Y, (int)r.Width, (int)r.Height);
1492 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1493 return ((Form)this).form_parent_window.Right;
1496 return this.bounds.X+this.bounds.Width;
1500 public virtual RightToLeft RightToLeft {
1502 return right_to_left;
1506 if (value != right_to_left) {
1507 right_to_left = value;
1508 OnRightToLeftChanged(EventArgs.Empty);
1513 public override ISite Site {
1525 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1526 return ((Form)this).form_parent_window.Size;
1528 return new Size(Width, Height);
1532 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1533 ((Form)this).form_parent_window.Size = value;
1536 SetBoundsCore(bounds.X, bounds.Y, value.Width, value.Height, BoundsSpecified.Size);
1540 public int TabIndex {
1542 if (tab_index != -1) {
1549 if (tab_index != value) {
1551 OnTabIndexChanged(EventArgs.Empty);
1556 public bool TabStop {
1572 control_tag = value;
1576 public virtual string Text {
1582 if (value == null) {
1583 value = String.Empty;
1588 XplatUI.Text(Handle, text);
1589 // FIXME: Do we need a Refresh() here?
1590 OnTextChanged (EventArgs.Empty);
1597 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1598 return ((Form)this).form_parent_window.Top;
1600 return this.bounds.Y;
1604 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1605 ((Form)this).form_parent_window.Top = value;
1609 SetBoundsCore(bounds.X, value, bounds.Width, bounds.Height, BoundsSpecified.Y);
1613 public Control TopLevelControl {
1617 while (p.parent != null) {
1625 public bool Visible {
1627 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1628 return ((Form)this).form_parent_window.Visible;
1638 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1639 ((Form)this).form_parent_window.Visible = value;
1643 SetVisibleCore(value);
1649 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1650 return ((Form)this).form_parent_window.Width;
1652 return this.bounds.Width;
1656 if ((this is Form) && (((Form)this).form_parent_window != null)) {
1657 ((Form)this).form_parent_window.Width = value;
1661 SetBoundsCore(bounds.X, bounds.Y, value, bounds.Height, BoundsSpecified.Width);
1665 public IWindowTarget WindowTarget {
1674 #endregion // Public Instance Properties
1676 #region Protected Instance Properties
1677 protected virtual CreateParams CreateParams {
1679 CreateParams create_params = new CreateParams();
1681 create_params.Caption = Text;
1682 create_params.X = Left;
1683 create_params.Y = Top;
1684 create_params.Width = Width;
1685 create_params.Height = Height;
1687 create_params.ClassName = XplatUI.DefaultClassName;
1688 create_params.ClassStyle = 0;
1689 create_params.ExStyle = 0;
1690 create_params.Param = 0;
1693 create_params.Parent = parent.Handle;
1696 create_params.Style = (int)WindowStyles.WS_CHILD | (int)WindowStyles.WS_CLIPCHILDREN | (int)WindowStyles.WS_CLIPSIBLINGS;
1699 create_params.Style |= (int)WindowStyles.WS_VISIBLE;
1702 return create_params;
1706 protected virtual ImeMode DefaultImeMode {
1708 return ImeMode.Inherit;
1712 protected virtual Size DefaultSize {
1714 return new Size(100, 23);
1718 protected int FontHeight {
1728 protected bool RenderRightToLeft {
1730 return (this.right_to_left == RightToLeft.Yes);
1734 ;; // Nothing to do?
1738 protected bool ResizeRedraw {
1740 return GetStyle(ControlStyles.ResizeRedraw);
1744 SetStyle(ControlStyles.ResizeRedraw, value);
1748 protected virtual bool ShowFocusCues {
1754 protected bool ShowKeyboardCues {
1759 #endregion // Protected Instance Properties
1761 #region Public Static Methods
1762 public static Control FromChildHandle(IntPtr handle) {
1763 IEnumerator control = Control.controls.GetEnumerator();
1765 while (control.MoveNext()) {
1766 if (((Control)control.Current).window.Handle == handle) {
1768 if (((Control)control.Current).Parent != null) {
1769 return ((Control)control.Current).Parent;
1776 public static Control FromHandle(IntPtr handle) {
1777 IEnumerator control = Control.controls.GetEnumerator();
1779 while (control.MoveNext()) {
1780 if (((Control)control.Current).window.Handle == handle) {
1782 return ((Control)control.Current);
1788 public static bool IsMnemonic(char charCode, string text) {
1791 amp = text.IndexOf('&');
1794 if (amp + 1 < text.Length) {
1795 if (text[amp + 1] != '&') {
1796 if (Char.ToUpper(charCode) == Char.ToUpper(text.ToCharArray(amp + 1, 1)[0])) {
1806 #region Protected Static Methods
1807 protected static bool ReflectMessage(IntPtr hWnd, ref Message m) {
1810 c = Control.FromHandle(hWnd);
1820 #region Public Instance Methods
1821 public IAsyncResult BeginInvoke(Delegate method) {
1822 return BeginInvokeInternal(method, null);
1825 public IAsyncResult BeginInvoke (Delegate method, object[] args) {
1826 return BeginInvokeInternal (method, args);
1829 public void BringToFront() {
1830 if ((parent != null) && (parent.child_controls[0]!=this)) {
1831 if (parent.child_controls.Contains(this)) {
1832 parent.child_controls.SetChildIndex(this, 0);
1836 XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, true, false);
1838 if (parent != null) {
1843 public bool Contains(Control ctl) {
1844 while (ctl != null) {
1853 public void CreateControl() {
1855 if (!IsHandleCreated)
1858 for (int i=0; i<child_controls.Count; i++) {
1859 child_controls[i].CreateControl();
1864 public Graphics CreateGraphics() {
1865 if (!IsHandleCreated) {
1866 this.CreateHandle();
1868 return Graphics.FromHwnd(this.window.Handle);
1871 [MonoTODO("Come up with cross platform drag-drop driver interface")]
1872 public DragDropEffects DoDragDrop(object data, DragDropEffects allowedEffects) {
1873 return DragDropEffects.None;
1876 public object EndInvoke (IAsyncResult async_result) {
1877 AsyncMethodResult result = (AsyncMethodResult) async_result;
1878 return result.EndInvoke ();
1881 public bool Focus() {
1882 if (IsHandleCreated) {
1883 XplatUI.SetFocus(window.Handle);
1888 public Control GetChildAtPoint(Point pt) {
1889 // Microsoft's version of this function doesn't seem to work, so I can't check
1890 // if we only consider children or also grandchildren, etc.
1891 // I'm gonna say 'children only'
1892 for (int i=0; i<child_controls.Count; i++) {
1893 if (child_controls[i].Bounds.Contains(pt)) {
1894 return child_controls[i];
1900 public IContainerControl GetContainerControl() {
1901 Control current = this;
1903 while (current!=null) {
1904 if ((current is IContainerControl) && ((current.control_style & ControlStyles.ContainerControl)!=0)) {
1905 return (IContainerControl)current;
1907 current = current.parent;
1912 public Control GetNextControl(Control ctl, bool forward) {
1913 // If we're not a container we don't play
1914 if (!(this is IContainerControl) && !this.GetStyle(ControlStyles.ContainerControl)) {
1918 // If ctl is not contained by this, we start at the first child of this
1919 if (!this.Contains(ctl)) {
1923 // Search through our controls, starting at ctl, stepping into children as we encounter them
1924 // try to find the control with the tabindex closest to our own, or, if we're looking into
1925 // child controls, the one with the smallest tabindex
1927 return FindControlForward(this, ctl);
1929 return FindControlBackward(this, ctl);
1932 public void Hide() {
1933 this.Visible = false;
1936 public void Invalidate() {
1937 Invalidate(ClientRectangle, false);
1940 public void Invalidate(bool invalidateChildren) {
1941 Invalidate(ClientRectangle, invalidateChildren);
1944 public void Invalidate(System.Drawing.Rectangle rc) {
1945 Invalidate(rc, false);
1948 public void Invalidate(System.Drawing.Rectangle rc, bool invalidateChildren) {
1949 if (!IsHandleCreated || !Visible) {
1953 XplatUI.Invalidate(Handle, rc, !GetStyle (ControlStyles.AllPaintingInWmPaint));
1955 if (invalidateChildren) {
1956 for (int i=0; i<child_controls.Count; i++) child_controls[i].Invalidate();
1960 public void Invalidate(System.Drawing.Region region) {
1961 Invalidate(region, false);
1964 [MonoTODO("Figure out if GetRegionScans is usable")]
1965 public void Invalidate(System.Drawing.Region region, bool invalidateChildren) {
1966 throw new NotImplementedException();
1968 // FIXME - should use the GetRegionScans function of the region to invalidate each area
1969 //if (invalidateChildren) {
1970 // for (int i=0; i<child_controls.Count; i++) child_controls[i].Invalidate();
1974 public object Invoke (Delegate method) {
1975 return Invoke(method, null);
1978 public object Invoke (Delegate method, object[] args) {
1979 IAsyncResult result = BeginInvoke (method, args);
1980 return EndInvoke(result);
1983 public void PerformLayout() {
1984 PerformLayout(null, null);
1987 public void PerformLayout(Control affectedControl, string affectedProperty) {
1988 LayoutEventArgs levent = new LayoutEventArgs(affectedControl, affectedProperty);
1990 if (layout_suspended>0) {
1991 layout_pending = true;
1995 layout_pending = false;
1997 // Prevent us from getting messed up
2000 // Perform all Dock and Anchor calculations
2003 AnchorStyles anchor;
2008 space=this.DisplayRectangle;
2009 if (prev_size != Size.Empty) {
2010 diff_width = space.Width - prev_size.Width;
2011 diff_height = space.Height - prev_size.Height;
2017 // Deal with docking; go through in reverse, MS docs say that lowest Z-order is closest to edge
2018 for (int i = child_controls.Count - 1; i >= 0; i--) {
2019 child=child_controls[i];
2020 switch (child.Dock) {
2021 case DockStyle.None: {
2026 case DockStyle.Left: {
2027 child.SetBounds(space.Left, space.Y, child.Width, space.Height);
2028 space.X+=child.Width;
2029 space.Width-=child.Width;
2033 case DockStyle.Top: {
2034 child.SetBounds(space.Left, space.Y, space.Width, child.Height);
2035 space.Y+=child.Height;
2036 space.Height-=child.Height;
2040 case DockStyle.Right: {
2041 child.SetBounds(space.Right-child.Width, space.Y, child.Width, space.Height);
2042 space.Width-=child.Width;
2046 case DockStyle.Bottom: {
2047 child.SetBounds(space.Left, space.Bottom-child.Height, space.Width, child.Height);
2048 space.Height-=child.Height;
2052 case DockStyle.Fill: {
2053 child.SetBounds(space.Left, space.Top, space.Width, space.Height);
2061 space=this.DisplayRectangle;
2063 // Deal with anchoring
2064 for (int i=0; i < child_controls.Count; i++) {
2070 child=child_controls[i];
2071 anchor=child.Anchor;
2076 height=child.Height;
2078 // If the control is docked we don't need to do anything
2079 if (child.Dock != DockStyle.None) {
2083 if ((anchor & AnchorStyles.Left) !=0 ) {
2084 if ((anchor & AnchorStyles.Right) != 0) {
2085 // Anchoring to left and right
2086 width=width+diff_width;
2090 } else if ((anchor & AnchorStyles.Right) != 0) {
2096 if ((anchor & AnchorStyles.Top) !=0 ) {
2097 if ((anchor & AnchorStyles.Bottom) != 0) {
2098 height+=diff_height;
2102 } else if ((anchor & AnchorStyles.Bottom) != 0) {
2117 child.SetBounds(left, top, width, height);
2120 // Let everyone know
2124 // Need to make sure we decremend layout_suspended
2130 public Point PointToClient (Point p) {
2134 XplatUI.ScreenToClient (Handle, ref x, ref y);
2136 return new Point (x, y);
2139 public Point PointToScreen(Point p) {
2143 XplatUI.ClientToScreen(Handle, ref x, ref y);
2145 return new Point(x, y);
2148 public virtual bool PreProcessMessage(ref Message msg) {
2151 if (msg.Msg == (int)Msg.WM_KEYDOWN) {
2152 key_data = (Keys)msg.WParam.ToInt32();
2153 if (!ProcessCmdKey(ref msg, key_data)) {
2154 if (IsInputKey(key_data)) {
2158 return ProcessDialogKey(key_data);
2162 } else if (msg.Msg == (int)Msg.WM_CHAR) {
2163 if (IsInputChar((char)msg.WParam)) {
2167 return ProcessDialogChar((char)msg.WParam);
2173 public virtual void Refresh() {
2174 if (IsHandleCreated == true) {
2175 XplatUI.RefreshWindow(window.Handle);
2179 public void ResumeLayout() {
2180 ResumeLayout (true);
2183 public void ResumeLayout(bool performLayout) {
2186 if (layout_suspended > 0) {
2190 if (performLayout || layout_pending) {
2195 public void Select() {
2196 Select(false, false);
2199 public bool SelectNextControl(Control ctl, bool forward, bool tabStopOnly, bool nested, bool wrap) {
2204 c = GetNextControl(c, forward);
2213 if (c.CanSelect && ((c.parent == this) || nested) && (c.tab_stop || !tabStopOnly)) {
2217 } while (c != ctl); // If we wrap back to ourselves we stop
2222 public void SendToBack() {
2223 if ((parent != null) && (parent.child_controls[parent.child_controls.Count-1]!=this)) {
2224 if (parent.child_controls.Contains(this)) {
2225 parent.child_controls.SetChildIndex(this, parent.child_controls.Count);
2229 XplatUI.SetZOrder(this.window.Handle, IntPtr.Zero, false, true);
2230 if (parent != null) {
2235 public void SetBounds(int x, int y, int width, int height) {
2236 SetBoundsCore(x, y, width, height, BoundsSpecified.All);
2239 public void SetBounds(int x, int y, int width, int height, BoundsSpecified specified) {
2240 SetBoundsCore(x, y, width, height, specified);
2243 public void Show() {
2244 if (!IsHandleCreated) {
2245 this.CreateHandle();
2251 public void SuspendLayout() {
2255 #endregion // Public Instance Methods
2257 #region Protected Instance Methods
2258 protected virtual AccessibleObject CreateAccessibilityInstance() {
2259 return new AccessibleObject(this);
2262 protected virtual ControlCollection CreateControlsInstance() {
2263 return new ControlCollection(this);
2266 protected virtual void CreateHandle() {
2268 throw new ObjectDisposedException(Name);
2271 if (IsHandleCreated) {
2276 window = new ControlNativeWindow(this);
2277 window.CreateHandle(CreateParams);
2280 if (window.Handle!=IntPtr.Zero) {
2281 if (!controls.Contains(window.Handle)) {
2285 creator_thread = Thread.CurrentThread;
2287 XplatUI.SetWindowBackground(window.Handle, this.BackColor);
2289 OnHandleCreated(EventArgs.Empty);
2293 protected virtual void DefWndProc(ref Message m) {
2294 window.DefWndProc(ref m);
2297 protected virtual void DestroyHandle() {
2298 if (IsHandleCreated) {
2299 if (Handle != IntPtr.Zero) {
2300 controls.Remove(Handle);
2303 if (window != null) {
2304 window.DestroyHandle();
2309 protected bool GetStyle(ControlStyles flag) {
2310 return (control_style & flag) != 0;
2313 protected bool GetTopLevel() {
2317 protected virtual void InitLayout() {
2318 if (parent != null) {
2319 parent.PerformLayout(this, "parent");
2323 protected virtual bool IsInputChar (char charCode) {
2324 if (parent != null) {
2325 return parent.IsInputChar(charCode);
2331 protected virtual bool IsInputKey (Keys keyData) {
2332 // Doc says this one calls IsInputChar; not sure what to do with that
2336 protected virtual bool ProcessCmdKey(ref Message msg, Keys keyData) {
2337 if ((context_menu != null) && context_menu.ProcessCmdKey(ref msg, keyData)) {
2341 if (parent != null) {
2342 return parent.ProcessCmdKey(ref msg, keyData);
2348 protected virtual bool ProcessDialogChar(char charCode) {
2349 if (parent != null) {
2350 return parent.ProcessDialogChar (charCode);
2356 protected virtual bool ProcessDialogKey (Keys keyData) {
2357 if (parent != null) {
2358 return parent.ProcessDialogKey (keyData);
2364 protected virtual bool ProcessKeyEventArgs (ref Message msg)
2366 KeyEventArgs key_event;
2368 PreProcessMessage(ref msg);
2371 case (int)Msg.WM_KEYDOWN: {
2372 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
2373 OnKeyDown (key_event);
2374 return key_event.Handled;
2376 case (int)Msg.WM_KEYUP: {
2377 key_event = new KeyEventArgs ((Keys)msg.WParam.ToInt32 ());
2378 OnKeyUp (key_event);
2379 return key_event.Handled;
2382 case (int)Msg.WM_CHAR: {
2383 KeyPressEventArgs key_press_event;
2385 key_press_event = new KeyPressEventArgs((char)msg.WParam);
2386 OnKeyPress(key_press_event);
2387 return key_press_event.Handled;
2398 protected internal virtual bool ProcessKeyMessage(ref Message msg) {
2399 if (parent != null) {
2400 if (parent.ProcessKeyPreview(ref msg)) {
2405 return ProcessKeyEventArgs(ref msg);
2408 protected virtual bool ProcessKeyPreview(ref Message msg) {
2409 if (parent != null) {
2410 return parent.ProcessKeyPreview(ref msg);
2416 protected virtual bool ProcessMnemonic(char charCode) {
2421 protected void RaiseDragEvent(object key, DragEventArgs e) {
2425 protected void RaiseKeyEvent(object key, KeyEventArgs e) {
2429 protected void RaiseMouseEvent(object key, MouseEventArgs e) {
2433 protected void RaisePaintEvent(object key, PaintEventArgs e) {
2437 protected void RecreateHandle() {
2438 IEnumerator child = child_controls.GetEnumerator();
2442 if (IsHandleCreated) {
2448 while (child.MoveNext()) {
2449 ((Control)child.Current).RecreateHandle();
2455 is_recreating = false;
2458 protected void ResetMouseEventArgs() {
2462 protected ContentAlignment RtlTranslateAlignment(ContentAlignment align) {
2463 if (right_to_left == RightToLeft.No) {
2468 case ContentAlignment.TopLeft: {
2469 return ContentAlignment.TopRight;
2472 case ContentAlignment.TopRight: {
2473 return ContentAlignment.TopLeft;
2476 case ContentAlignment.MiddleLeft: {
2477 return ContentAlignment.MiddleRight;
2480 case ContentAlignment.MiddleRight: {
2481 return ContentAlignment.MiddleLeft;
2484 case ContentAlignment.BottomLeft: {
2485 return ContentAlignment.BottomRight;
2488 case ContentAlignment.BottomRight: {
2489 return ContentAlignment.BottomLeft;
2493 // if it's center it doesn't change
2499 protected HorizontalAlignment RtlTranslateAlignment(HorizontalAlignment align) {
2500 if ((right_to_left == RightToLeft.No) || (align == HorizontalAlignment.Center)) {
2504 if (align == HorizontalAlignment.Left) {
2505 return HorizontalAlignment.Right;
2508 // align must be HorizontalAlignment.Right
2509 return HorizontalAlignment.Left;
2512 protected LeftRightAlignment RtlTranslateAlignment(LeftRightAlignment align) {
2513 if (right_to_left == RightToLeft.No) {
2517 if (align == LeftRightAlignment.Left) {
2518 return LeftRightAlignment.Right;
2521 // align must be LeftRightAlignment.Right;
2522 return LeftRightAlignment.Left;
2525 protected ContentAlignment RtlTranslateContent(ContentAlignment align) {
2526 return RtlTranslateAlignment(align);
2529 protected HorizontalAlignment RtlTranslateHorizontal(HorizontalAlignment align) {
2530 return RtlTranslateAlignment(align);
2533 protected LeftRightAlignment RtlTranslateLeftRight(LeftRightAlignment align) {
2534 return RtlTranslateAlignment(align);
2537 protected virtual void ScaleCore(float dx, float dy) {
2538 throw new NotImplementedException();
2541 protected virtual void Select(bool directed, bool forward) {
2546 // Select this control
2551 if (parent == null) {
2555 index = parent.child_controls.IndexOf(this);
2560 if ((index+1) < parent.child_controls.Count) {
2569 index = parent.child_controls.Count-1;
2572 result = Select(parent.child_controls[index]);
2573 } while (!result && parent.child_controls[index] != this);
2576 protected virtual void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
2577 // SetBoundsCore updates the Win32 control itself. UpdateBounds updates the controls variables and fires events, I'm guessing - pdb
2578 if ((specified & BoundsSpecified.X) != BoundsSpecified.X) {
2582 if ((specified & BoundsSpecified.Y) != BoundsSpecified.Y) {
2586 if ((specified & BoundsSpecified.Width)!= BoundsSpecified.Width) {
2590 if ((specified & BoundsSpecified.Height) != BoundsSpecified.Height) {
2594 if (IsHandleCreated) {
2595 XplatUI.SetWindowPos(Handle, x, y, width, height);
2597 UpdateBounds(x, y, width, height);
2600 protected virtual void SetClientSizeCore(int x, int y) {
2601 // Calculate the actual window size from the client size (it usually stays the same or grows)
2602 Rectangle ClientRect;
2603 Rectangle WindowRect;
2606 ClientRect = new Rectangle(0, 0, x, y);
2607 cp = this.CreateParams;
2609 if (XplatUI.CalculateWindowRect(Handle, ref ClientRect, cp.Style, false, out WindowRect)==false) {
2613 this.client_size = new Size(x, y);
2614 SetBoundsCore(bounds.X, bounds.Y, WindowRect.Width, WindowRect.Height, BoundsSpecified.Size);
2617 protected void SetStyle(ControlStyles flag, bool value) {
2619 control_style |= flag;
2621 control_style &= ~flag;
2625 protected void SetTopLevel(bool value) {
2626 if ((GetTopLevel() != value) && (parent != null)) {
2627 throw new Exception();
2631 if (value == true) {
2641 is_toplevel = value;
2644 protected virtual void SetVisibleCore(bool value) {
2645 if (value!=is_visible) {
2647 XplatUI.SetVisible(Handle, value);
2648 OnVisibleChanged(EventArgs.Empty);
2650 if (dc_mem != null) {
2655 if (bmp_mem != null) {
2660 this.CreateBuffers(bounds.Width, bounds.Height);
2663 // FIXME - deal with focus
2665 if (parent != null) {
2666 parent.PerformLayout(this, "visible");
2668 PerformLayout(this, "visible");
2673 protected void UpdateBounds() {
2681 if (!IsHandleCreated) {
2685 XplatUI.GetWindowPos(this.Handle, out x, out y, out width, out height, out client_width, out client_height);
2686 UpdateBounds(x, y, width, height, client_width, client_height);
2689 protected void UpdateBounds(int x, int y, int width, int height) {
2690 // UpdateBounds only seems to set our sizes and fire events but not update the GUI window to match
2692 bool resized = false;
2694 int client_x_diff = this.bounds.Width-this.client_size.Width;
2695 int client_y_diff = this.bounds.Height-this.client_size.Height;
2697 // Needed to generate required notifications
2698 if ((this.bounds.X!=x) || (this.bounds.Y!=y)) {
2702 if ((this.Bounds.Width!=width) || (this.Bounds.Height!=height)) {
2709 bounds.Height=height;
2711 // Update client rectangle as well
2712 if (this.layout_suspended==0) {
2713 prev_size.Width=client_size.Width;
2714 prev_size.Height=client_size.Height;
2717 client_size.Width=width-client_x_diff;
2718 client_size.Height=height-client_y_diff;
2721 OnLocationChanged(EventArgs.Empty);
2725 OnSizeChanged(EventArgs.Empty);
2729 protected void UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) {
2730 UpdateBounds(x, y, width, height);
2732 this.client_size.Width=clientWidth;
2733 this.client_size.Height=clientHeight;
2736 protected void UpdateStyles() {
2737 if (!IsHandleCreated) {
2741 XplatUI.SetWindowStyle(window.Handle, CreateParams);
2744 protected void UpdateZOrder() {
2749 if (parent == null) {
2755 children = ctl.child_controls.Count;
2756 for (int i = 1; i < children; i++ ) {
2757 XplatUI.SetZOrder(ctl.child_controls[i].window.Handle, ctl.child_controls[i-1].window.Handle, false, false);
2760 children = child_controls.Count;
2761 for (int i = 1; i < children; i++ ) {
2762 XplatUI.SetZOrder(child_controls[i].window.Handle, child_controls[i-1].window.Handle, false, false);
2768 protected virtual void WndProc(ref Message m) {
2770 Console.WriteLine("Received message {0}", m);
2772 if ((this.control_style & ControlStyles.EnableNotifyMessage) != 0) {
2776 switch((Msg)m.Msg) {
2777 case Msg.WM_WINDOWPOSCHANGED: {
2780 if (GetStyle(ControlStyles.ResizeRedraw)) {
2787 case Msg.WM_PAINT: {
2788 PaintEventArgs paint_event;
2790 paint_event = XplatUI.PaintEventStart(Handle);
2791 OnPaint(paint_event);
2792 XplatUI.PaintEventEnd(Handle);
2797 case Msg.WM_ERASEBKGND: {
2798 if (GetStyle (ControlStyles.UserPaint)) {
2799 if (!GetStyle(ControlStyles.AllPaintingInWmPaint)) {
2800 PaintEventArgs eraseEventArgs = new PaintEventArgs (m.WParam == IntPtr.Zero ? Graphics.FromHwnd (m.HWnd) :
2801 Graphics.FromHdc (m.WParam), new Rectangle (new Point (0,0),Size));
2802 OnPaintBackground (eraseEventArgs);
2804 m.Result = (IntPtr)1;
2806 m.Result = IntPtr.Zero;
2813 case Msg.WM_LBUTTONUP: {
2814 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Left,
2816 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
2818 if (mouse_clicks > 1) {
2824 case Msg.WM_LBUTTONDOWN: {
2825 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
2826 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
2832 case Msg.WM_LBUTTONDBLCLK: {
2834 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
2835 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
2841 case Msg.WM_MBUTTONUP: {
2842 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Middle,
2844 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
2846 if (mouse_clicks > 1) {
2852 case Msg.WM_MBUTTONDOWN: {
2853 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
2854 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
2860 case Msg.WM_MBUTTONDBLCLK: {
2862 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
2863 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
2868 case Msg.WM_RBUTTONUP: {
2869 OnMouseUp (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Right,
2871 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
2873 if (mouse_clicks > 1) {
2879 case Msg.WM_RBUTTONDOWN: {
2880 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
2881 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
2886 case Msg.WM_RBUTTONDBLCLK: {
2888 OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
2889 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
2894 case Msg.WM_MOUSEWHEEL: {
2896 OnMouseWheel (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
2897 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
2898 HighOrder(m.WParam.ToInt32())));
2903 case Msg.WM_MOUSEMOVE: {
2904 OnMouseMove (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
2906 LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
2911 case Msg.WM_MOUSE_ENTER: {
2916 OnMouseEnter(EventArgs.Empty);
2920 case Msg.WM_MOUSE_LEAVE: {
2922 OnMouseLeave(EventArgs.Empty);
2926 case Msg.WM_MOUSEHOVER: {
2927 OnMouseHover(EventArgs.Empty);
2931 case Msg.WM_KEYDOWN: {
2932 if (!ProcessKeyMessage(ref m)) {
2938 case Msg.WM_KEYUP: {
2939 if (!ProcessKeyMessage(ref m)) {
2946 if (!ProcessKeyMessage(ref m)) {
2954 if (m.LParam != IntPtr.Zero) {
2957 hi = new HELPINFO();
2959 hi = (HELPINFO) Marshal.PtrToStructure (m.LParam, typeof (HELPINFO));
2960 mouse_pos = new Point(hi.MousePos.x, hi.MousePos.y);
2962 mouse_pos = Control.MousePosition;
2964 OnHelpRequested(new HelpEventArgs(mouse_pos));
2965 m.Result = (IntPtr)1;
2969 case Msg.WM_KILLFOCUS: {
2970 Console.WriteLine("Window {0} lost focus", this.Text);
2971 OnLeave(EventArgs.Empty);
2972 if (CausesValidation) {
2974 e = new CancelEventArgs(false);
2983 OnValidated(EventArgs.Empty);
2986 this.has_focus = false;
2987 OnLostFocus(EventArgs.Empty);
2991 case Msg.WM_SETFOCUS: {
2992 Console.WriteLine("Window {0} got focus", this.Text);
2993 OnEnter(EventArgs.Empty);
2994 this.has_focus = true;
2995 OnGotFocus(EventArgs.Empty);
3001 case Msg.WM_SYSCOLORCHANGE: throw new NotImplementedException(); break;
3005 case Msg.WM_SETCURSOR: {
3006 Console.WriteLine("Got WM_SETCURSOR, cursor is {0}", cursor);
3007 if (cursor == null) {
3012 XplatUI.SetCursor(window.Handle, cursor.handle);
3013 m.Result = (IntPtr)1;
3022 #endregion // Public Instance Methods
3024 #region OnXXX methods
3025 protected virtual void OnBackColorChanged(EventArgs e) {
3026 if (BackColorChanged!=null) BackColorChanged(this, e);
3027 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackColorChanged(e);
3030 protected virtual void OnBackgroundImageChanged(EventArgs e) {
3031 if (BackgroundImageChanged!=null) BackgroundImageChanged(this, e);
3032 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackgroundImageChanged(e);
3035 protected virtual void OnBindingContextChanged(EventArgs e) {
3036 if (BindingContextChanged!=null) BindingContextChanged(this, e);
3037 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBindingContextChanged(e);
3040 protected virtual void OnCausesValidationChanged(EventArgs e) {
3041 if (CausesValidationChanged!=null) CausesValidationChanged(this, e);
3044 protected virtual void OnChangeUICues(UICuesEventArgs e) {
3045 if (CausesValidationChanged!=null) CausesValidationChanged(this, e);
3048 protected virtual void OnClick(EventArgs e) {
3049 if (Click!=null) Click(this, e);
3052 protected virtual void OnContextMenuChanged(EventArgs e) {
3053 if (ContextMenuChanged!=null) ContextMenuChanged(this, e);
3056 protected virtual void OnControlAdded(ControlEventArgs e) {
3057 if (ControlAdded!=null) ControlAdded(this, e);
3060 protected virtual void OnControlRemoved(ControlEventArgs e) {
3061 if (ControlRemoved!=null) ControlRemoved(this, e);
3064 protected virtual void OnCreateControl() {
3068 protected virtual void OnCursorChanged(EventArgs e) {
3069 if (CursorChanged!=null) CursorChanged(this, e);
3072 protected virtual void OnDockChanged(EventArgs e) {
3073 if (DockChanged!=null) DockChanged(this, e);
3076 protected virtual void OnDoubleClick(EventArgs e) {
3077 if (DoubleClick!=null) DoubleClick(this, e);
3080 protected virtual void OnDragDrop(DragEventArgs drgevent) {
3081 if (DragDrop!=null) DragDrop(this, drgevent);
3084 protected virtual void OnDragEnter(DragEventArgs drgevent) {
3085 if (DragEnter!=null) DragEnter(this, drgevent);
3088 protected virtual void OnDragLeave(EventArgs e) {
3089 if (DragLeave!=null) DragLeave(this, e);
3092 protected virtual void OnDragOver(DragEventArgs drgevent) {
3093 if (DragOver!=null) DragOver(this, drgevent);
3096 protected virtual void OnEnabledChanged(EventArgs e) {
3097 if (EnabledChanged!=null) EnabledChanged(this, e);
3098 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentEnabledChanged(e);
3101 protected virtual void OnEnter(EventArgs e) {
3102 if (Enter!=null) Enter(this, e);
3105 protected virtual void OnFontChanged(EventArgs e) {
3106 if (FontChanged!=null) FontChanged(this, e);
3109 protected virtual void OnForeColorChanged(EventArgs e) {
3110 if (ForeColorChanged!=null) ForeColorChanged(this, e);
3111 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentForeColorChanged(e);
3114 protected virtual void OnGiveFeedback(GiveFeedbackEventArgs gfbevent) {
3115 if (GiveFeedback!=null) GiveFeedback(this, gfbevent);
3118 protected virtual void OnGotFocus(EventArgs e) {
3119 if (GotFocus!=null) GotFocus(this, e);
3122 protected virtual void OnHandleCreated(EventArgs e) {
3123 if (HandleCreated!=null) HandleCreated(this, e);
3126 protected virtual void OnHandleDestroyed(EventArgs e) {
3127 if (HandleDestroyed!=null) HandleDestroyed(this, e);
3130 protected virtual void OnHelpRequested(HelpEventArgs hevent) {
3131 if (HelpRequested!=null) HelpRequested(this, hevent);
3134 protected virtual void OnImeModeChanged(EventArgs e) {
3135 if (ImeModeChanged!=null) ImeModeChanged(this, e);
3138 protected virtual void OnInvalidated(InvalidateEventArgs e) {
3139 if (Invalidated!=null) Invalidated(this, e);
3142 protected virtual void OnKeyDown(KeyEventArgs e) {
3143 if (KeyDown!=null) KeyDown(this, e);
3146 protected virtual void OnKeyPress(KeyPressEventArgs e) {
3147 if (KeyPress!=null) KeyPress(this, e);
3150 protected virtual void OnKeyUp(KeyEventArgs e) {
3151 if (KeyUp!=null) KeyUp(this, e);
3154 protected virtual void OnLayout(LayoutEventArgs levent) {
3155 if (Layout!=null) Layout(this, levent);
3158 protected virtual void OnLeave(EventArgs e) {
3159 if (Leave!=null) Leave(this, e);
3162 protected virtual void OnLocationChanged(EventArgs e) {
3163 if (LocationChanged!=null) LocationChanged(this, e);
3166 protected virtual void OnLostFocus(EventArgs e) {
3167 if (LostFocus!=null) LostFocus(this, e);
3170 protected virtual void OnMouseDown(MouseEventArgs e) {
3171 if (MouseDown!=null) MouseDown(this, e);
3174 protected virtual void OnMouseEnter(EventArgs e) {
3175 if (MouseEnter!=null) MouseEnter(this, e);
3178 protected virtual void OnMouseHover(EventArgs e) {
3179 if (MouseHover!=null) MouseHover(this, e);
3182 protected virtual void OnMouseLeave(EventArgs e) {
3183 if (MouseLeave!=null) MouseLeave(this, e);
3186 protected virtual void OnMouseMove(MouseEventArgs e) {
3187 if (MouseMove!=null) MouseMove(this, e);
3190 protected virtual void OnMouseUp(MouseEventArgs e) {
3191 if (MouseUp!=null) MouseUp(this, e);
3194 protected virtual void OnMouseWheel(MouseEventArgs e) {
3195 if (MouseWheel!=null) MouseWheel(this, e);
3198 protected virtual void OnMove(EventArgs e) {
3199 if (Move!=null) Move(this, e);
3202 protected virtual void OnNotifyMessage(Message m) {
3206 protected virtual void OnPaint(PaintEventArgs e) {
3207 if (Paint!=null) Paint(this, e);
3210 protected virtual void OnPaintBackground(PaintEventArgs pevent) {
3214 protected virtual void OnParentBackColorChanged(EventArgs e) {
3215 if (background_color.IsEmpty && background_image==null) {
3217 OnBackColorChanged(e);
3221 protected virtual void OnParentBackgroundImageChanged(EventArgs e) {
3222 if (background_color.IsEmpty && background_image==null) {
3224 OnBackgroundImageChanged(e);
3228 protected virtual void OnParentBindingContextChanged(EventArgs e) {
3229 if (binding_context==null) {
3230 binding_context=Parent.binding_context;
3231 OnBindingContextChanged(e);
3235 protected virtual void OnParentChanged(EventArgs e) {
3236 if (ParentChanged!=null) ParentChanged(this, e);
3239 protected virtual void OnParentEnabledChanged(EventArgs e) {
3240 if (is_enabled != Parent.is_enabled) {
3241 is_enabled=Parent.is_enabled;
3243 if (EnabledChanged != null) {
3244 EnabledChanged(this, e);
3249 protected virtual void OnParentFontChanged(EventArgs e) {
3256 protected virtual void OnParentForeColorChanged(EventArgs e) {
3257 if (foreground_color.IsEmpty) {
3259 OnForeColorChanged(e);
3263 protected virtual void OnParentRightToLeftChanged(EventArgs e) {
3264 if (right_to_left==RightToLeft.Inherit) {
3266 OnRightToLeftChanged(e);
3270 protected virtual void OnParentVisibleChanged(EventArgs e) {
3271 if (is_visible!=Parent.is_visible) {
3274 OnVisibleChanged(e);
3278 protected virtual void OnQueryContinueDrag(QueryContinueDragEventArgs e) {
3279 if (QueryContinueDrag!=null) QueryContinueDrag(this, e);
3282 protected virtual void OnResize(EventArgs e) {
3283 if (Resize!=null) Resize(this, e);
3285 PerformLayout(this, "bounds");
3287 if (parent != null) {
3288 parent.PerformLayout();
3292 protected virtual void OnRightToLeftChanged(EventArgs e) {
3293 if (RightToLeftChanged!=null) RightToLeftChanged(this, e);
3294 for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentRightToLeftChanged(e);
3297 protected virtual void OnSizeChanged(EventArgs e) {
3298 InvalidateBuffers ();
3300 if (SizeChanged!=null) SizeChanged(this, e);
3303 protected virtual void OnStyleChanged(EventArgs e) {
3304 if (StyleChanged!=null) StyleChanged(this, e);
3307 protected virtual void OnSystemColorsChanged(EventArgs e) {
3308 if (SystemColorsChanged!=null) SystemColorsChanged(this, e);
3311 protected virtual void OnTabIndexChanged(EventArgs e) {
3312 if (TabIndexChanged!=null) TabIndexChanged(this, e);
3315 protected virtual void OnTabStopChanged(EventArgs e) {
3316 if (TabStopChanged!=null) TabStopChanged(this, e);
3319 protected virtual void OnTextChanged(EventArgs e) {
3320 if (TextChanged!=null) TextChanged(this, e);
3323 protected virtual void OnValidated(EventArgs e) {
3324 if (Validated!=null) Validated(this, e);
3327 protected virtual void OnValidating(System.ComponentModel.CancelEventArgs e) {
3328 if (Validating!=null) Validating(this, e);
3331 protected virtual void OnVisibleChanged(EventArgs e) {
3338 if (bmp_mem!=null) {
3344 if (!this.IsHandleCreated) {
3345 this.CreateHandle();
3351 if (VisibleChanged!=null) VisibleChanged(this, e);
3353 // We need to tell our kids
3354 for (int i=0; i<child_controls.Count; i++) {
3355 child_controls[i].OnParentVisibleChanged(e);
3358 #endregion // OnXXX methods
3361 public event EventHandler BackColorChanged;
3362 public event EventHandler BackgroundImageChanged;
3363 public event EventHandler BindingContextChanged;
3364 public event EventHandler CausesValidationChanged;
3365 public event UICuesEventHandler ChangeUICues;
3366 public event EventHandler Click;
3367 public event EventHandler ContextMenuChanged;
3368 public event ControlEventHandler ControlAdded;
3369 public event ControlEventHandler ControlRemoved;
3370 public event EventHandler CursorChanged;
3371 public event EventHandler DockChanged;
3372 public event EventHandler DoubleClick;
3373 public event DragEventHandler DragDrop;
3374 public event DragEventHandler DragEnter;
3375 public event EventHandler DragLeave;
3376 public event DragEventHandler DragOver;
3377 public event EventHandler EnabledChanged;
3378 public event EventHandler Enter;
3379 public event EventHandler FontChanged;
3380 public event EventHandler ForeColorChanged;
3381 public event GiveFeedbackEventHandler GiveFeedback;
3382 public event EventHandler GotFocus;
3383 public event EventHandler HandleCreated;
3384 public event EventHandler HandleDestroyed;
3385 public event HelpEventHandler HelpRequested;
3386 public event EventHandler ImeModeChanged;
3387 public event InvalidateEventHandler Invalidated;
3388 public event KeyEventHandler KeyDown;
3389 public event KeyPressEventHandler KeyPress;
3390 public event KeyEventHandler KeyUp;
3391 public event LayoutEventHandler Layout;
3392 public event EventHandler Leave;
3393 public event EventHandler LocationChanged;
3394 public event EventHandler LostFocus;
3395 public event MouseEventHandler MouseDown;
3396 public event EventHandler MouseEnter;
3397 public event EventHandler MouseHover;
3398 public event EventHandler MouseLeave;
3399 public event MouseEventHandler MouseMove;
3400 public event MouseEventHandler MouseUp;
3401 public event MouseEventHandler MouseWheel;
3402 public event EventHandler Move;
3403 public event PaintEventHandler Paint;
3404 public event EventHandler ParentChanged;
3405 public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp;
3406 public event QueryContinueDragEventHandler QueryContinueDrag;
3407 public event EventHandler Resize;
3408 public event EventHandler RightToLeftChanged;
3409 public event EventHandler SizeChanged;
3410 public event EventHandler StyleChanged;
3411 public event EventHandler SystemColorsChanged;
3412 public event EventHandler TabIndexChanged;
3413 public event EventHandler TabStopChanged;
3414 public event EventHandler TextChanged;
3415 public event EventHandler Validated;
3416 public event CancelEventHandler Validating;
3417 public event EventHandler VisibleChanged;
3418 #endregion // Events