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-2006 Novell, Inc.
23 // Peter Bartok pbartok@novell.com
30 using System.ComponentModel;
31 using System.ComponentModel.Design;
32 using System.ComponentModel.Design.Serialization;
33 using System.Collections;
34 using System.Runtime.InteropServices;
35 using System.Threading;
37 namespace System.Windows.Forms {
38 [DesignerCategory("Form")]
39 [DesignTimeVisible(false)]
40 [Designer("System.Windows.Forms.Design.FormDocumentDesigner, " + Consts.AssemblySystem_Design, typeof(IRootDesigner))]
41 [DefaultEvent("Load")]
43 public class Form : ContainerControl {
44 #region Local Variables
45 internal bool closing;
46 FormBorderStyle form_border_style;
47 private bool autoscale;
48 private Size clientsize_set;
49 private Size autoscale_base_size;
50 private bool allow_transparency;
51 private static Icon default_icon;
52 internal bool is_modal;
53 internal FormWindowState window_state;
54 private bool control_box;
55 private bool minimize_box;
56 private bool maximize_box;
57 private bool help_button;
58 private bool show_in_taskbar;
60 private IButtonControl accept_button;
61 private IButtonControl cancel_button;
62 private DialogResult dialog_result;
63 private FormStartPosition start_position;
65 private Form.ControlCollection owned_forms;
66 private MdiClient mdi_container;
67 internal InternalWindowManager window_manager;
68 private Form mdi_parent;
69 private bool key_preview;
70 private MainMenu menu;
72 private Size maximum_size;
73 private Size minimum_size;
74 private SizeGripStyle size_grip_style;
75 private Rectangle maximized_bounds;
76 private Rectangle default_maximized_bounds;
77 private double opacity;
78 internal ApplicationContext context;
79 Color transparency_key;
80 internal MenuTracker active_tracker;
81 private bool is_loaded;
82 internal bool is_changing_visible_state;
83 internal bool has_been_visible;
85 #endregion // Local Variables
87 #region Private & Internal Methods
90 default_icon = Locale.GetResource("mono.ico") as Icon;
93 // warning: this is only hooked up when an mdi container is created.
94 private void ControlAddedHandler (object sender, ControlEventArgs e)
96 if (mdi_container != null) {
97 mdi_container.SendToBack ();
101 private void SelectActiveControl ()
103 if (this.IsMdiContainer)
106 if (this.ActiveControl == null) {
109 // This visible hack is to work around CanSelect always being false if one of the parents
110 // is not visible; and we by default create Form invisible...
111 visible = this.is_visible;
112 this.is_visible = true;
114 if (SelectNextControl (this, true, true, true, true) == false) {
118 this.is_visible = visible;
120 Select (ActiveControl);
123 #endregion // Private & Internal Methods
125 #region Public Classes
126 public new class ControlCollection : Control.ControlCollection {
129 public ControlCollection(Form owner) : base(owner) {
130 this.form_owner = owner;
133 public override void Add(Control value) {
134 if (Contains (value))
137 ((Form)value).owner=form_owner;
140 public override void Remove(Control value) {
141 ((Form)value).owner = null;
145 #endregion // Public Classes
147 #region Public Constructor & Destructor
150 SizeF current_scale = GetAutoScaleSize (DeviceContext, Font);
153 autoscale_base_size = new Size ((int)current_scale.Width, (int) current_scale.Height);
154 allow_transparency = false;
157 dialog_result = DialogResult.None;
158 start_position = FormStartPosition.WindowsDefaultLocation;
159 form_border_style = FormBorderStyle.Sizable;
160 window_state = FormWindowState.Normal;
165 minimum_size = Size.Empty;
166 maximum_size = Size.Empty;
167 clientsize_set = Size.Empty;
172 show_in_taskbar = true;
173 ime_mode = ImeMode.NoControl;
176 size_grip_style = SizeGripStyle.Auto;
177 maximized_bounds = Rectangle.Empty;
178 default_maximized_bounds = Rectangle.Empty;
179 owned_forms = new Form.ControlCollection(this);
180 transparency_key = Color.Empty;
182 // FIXME: this should disappear just as soon as the handle creation is done in the right place (here is too soon()
186 #endregion // Public Constructor & Destructor
188 #region Public Static Properties
190 public static Form ActiveForm {
194 active = FromHandle(XplatUI.GetActive());
196 if (active != null) {
197 if ( !(active is Form)) {
200 parent = active.Parent;
201 while (parent != null) {
202 if (parent is Form) {
205 parent = parent.Parent;
215 #endregion // Public Static Properties
217 #region Public Instance Properties
219 public IButtonControl AcceptButton {
221 return accept_button;
225 accept_button = value;
231 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
232 public bool AllowTransparency {
234 return allow_transparency;
238 if (value == allow_transparency) {
242 allow_transparency = value;
245 if (IsHandleCreated) {
246 if ((XplatUI.SupportsTransparency() & TransparencySupport.Set) != 0) {
247 XplatUI.SetWindowTransparency(Handle, Opacity, TransparencyKey);
250 UpdateStyles(); // Remove the WS_EX_LAYERED style
257 [MWFCategory("Layout")]
258 public bool AutoScale {
270 [EditorBrowsable(EditorBrowsableState.Advanced)]
271 public virtual Size AutoScaleBaseSize {
273 return autoscale_base_size;
277 autoscale_base_size = value;
282 public override bool AutoScroll {
284 return base.AutoScroll;
287 base.AutoScroll = value;
291 public override Color BackColor {
293 /* we don't let parents override our
294 default background color for forms.
295 this fixes the default color for mdi
297 if (background_color.IsEmpty)
298 return DefaultBackColor;
300 return background_color;
303 base.BackColor = value;
308 public IButtonControl CancelButton {
310 return cancel_button;
314 cancel_button = value;
318 // new property so we can change the DesignerSerializationVisibility
319 [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
321 public new Size ClientSize {
322 get { return base.ClientSize; }
323 set { base.ClientSize = value; }
327 [MWFCategory("Window Style")]
328 public bool ControlBox {
334 if (control_box != value) {
342 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
343 public Rectangle DesktopBounds {
345 return new Rectangle(Location, Size);
354 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
355 public Point DesktopLocation {
366 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
367 public DialogResult DialogResult {
369 return dialog_result;
373 if (value < DialogResult.None || value > DialogResult.No)
374 throw new InvalidEnumArgumentException ("value", (int) value,
375 typeof (DialogResult));
377 dialog_result = value;
378 closing = (dialog_result != DialogResult.None && is_modal);
382 [DefaultValue(FormBorderStyle.Sizable)]
384 [MWFCategory("Appearance")]
385 public FormBorderStyle FormBorderStyle {
387 return form_border_style;
390 form_border_style = value;
392 if (window_manager == null) {
393 if (IsHandleCreated) {
394 XplatUI.SetBorderStyle(window.Handle, form_border_style);
397 window_manager.UpdateBorderStyle (value);
404 [DefaultValue(false)]
405 [MWFCategory("Window Style")]
406 public bool HelpButton {
412 if (help_button != value) {
421 [MWFCategory("Window Style")]
431 if (IsHandleCreated) {
432 XplatUI.SetIcon(Handle, icon == null ? default_icon : icon);
439 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
440 public bool IsMdiChild {
442 return mdi_parent != null;
446 [DefaultValue(false)]
447 [MWFCategory("Window Style")]
448 public bool IsMdiContainer {
450 return mdi_container != null;
454 if (value && mdi_container == null) {
455 mdi_container = new MdiClient ();
456 Controls.Add(mdi_container);
457 ControlAdded += new ControlEventHandler (ControlAddedHandler);
458 mdi_container.SendToBack ();
459 mdi_container.SetParentText (true);
460 } else if (!value && mdi_container != null) {
461 Controls.Remove(mdi_container);
462 mdi_container = null;
468 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
469 public Form ActiveMdiChild {
473 return (Form) mdi_container.ActiveMdiChild;
478 [EditorBrowsable(EditorBrowsableState.Advanced)]
479 public bool IsRestrictedWindow {
485 [DefaultValue(false)]
486 public bool KeyPreview {
497 [MWFCategory("Window Style")]
498 public bool MaximizeBox {
503 if (maximize_box != value) {
504 maximize_box = value;
505 if (IsHandleCreated) {
513 [DefaultValue("{Width=0, Height=0}")]
515 [RefreshProperties(RefreshProperties.Repaint)]
516 [MWFCategory("Layout")]
517 public Size MaximumSize {
523 if (maximum_size != value) {
524 maximum_size = value;
525 OnMaximumSizeChanged(EventArgs.Empty);
526 if (IsHandleCreated) {
527 XplatUI.SetWindowMinMax(Handle, maximized_bounds, minimum_size, maximum_size);
534 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
535 public Form[] MdiChildren {
537 if (mdi_container != null)
538 return mdi_container.MdiChildren;
545 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
546 public Form MdiParent {
552 if (value != null && !value.IsMdiContainer)
553 throw new ArgumentException ();
555 if (mdi_parent != null) {
556 mdi_parent.MdiContainer.Controls.Remove (this);
561 window_manager = new MdiWindowManager (this,
562 mdi_parent.MdiContainer);
563 mdi_parent.MdiContainer.Controls.Add (this);
564 mdi_parent.MdiContainer.Controls.SetChildIndex (this, 0);
568 } else if (mdi_parent != null) {
571 // Create a new window manager
572 window_manager = null;
573 FormBorderStyle = form_border_style;
580 internal MenuTracker ActiveTracker {
581 get { return active_tracker; }
583 if (value == active_tracker)
586 Capture = value != null;
587 active_tracker = value;
591 internal MdiClient MdiContainer {
592 get { return mdi_container; }
595 internal InternalWindowManager WindowManager {
596 get { return window_manager; }
600 [MWFCategory("Window Style")]
601 public MainMenu Menu {
610 if (menu != null && !IsMdiChild) {
613 if (IsHandleCreated) {
614 XplatUI.SetMenu (window.Handle, menu);
617 if (clientsize_set != Size.Empty) {
618 SetClientSizeCore(clientsize_set.Width, clientsize_set.Height);
620 UpdateBounds (bounds.X, bounds.Y, bounds.Width, bounds.Height, ClientSize.Width, ClientSize.Height -
621 ThemeEngine.Current.CalcMenuBarSize (DeviceContext, menu, ClientSize.Width));
630 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
631 [EditorBrowsable(EditorBrowsableState.Advanced)]
632 public MainMenu MergedMenu {
634 if (!IsMdiChild || window_manager == null)
636 return ((MdiWindowManager) window_manager).MergedMenu;
640 // This is the menu in display and being used because of merging this can
641 // be different then the menu that is actually assosciated with the form
642 internal MainMenu ActiveMenu {
647 if (IsMdiContainer && mdi_container.Controls.Count > 0 &&
648 ((Form) mdi_container.Controls [0]).WindowState == FormWindowState.Maximized) {
649 MdiWindowManager wm = (MdiWindowManager) ((Form) mdi_container.Controls [0]).WindowManager;
650 return wm.MaximizedMenu;
653 Form amc = ActiveMdiChild;
654 if (amc == null || amc.Menu == null)
656 return amc.MergedMenu;
660 internal MdiWindowManager ActiveMaximizedMdiChild {
662 Form child = ActiveMdiChild;
665 if (child.WindowManager == null || child.window_state != FormWindowState.Maximized)
667 return (MdiWindowManager) child.WindowManager;
672 [MWFCategory("Window Style")]
673 public bool MinimizeBox {
678 if (minimize_box != value) {
679 minimize_box = value;
680 if (IsHandleCreated) {
688 [DefaultValue("{Width=0, Height=0}")]
690 [RefreshProperties(RefreshProperties.Repaint)]
691 [MWFCategory("Layout")]
692 public Size MinimumSize {
698 if (minimum_size != value) {
699 minimum_size = value;
701 if ((Size.Width < value.Width) || (Size.Height < value.Height)) {
702 Size = new Size(Math.Max(Size.Width, value.Width), Math.Max(Size.Height, value.Height));
706 OnMinimumSizeChanged(EventArgs.Empty);
707 if (IsHandleCreated) {
708 XplatUI.SetWindowMinMax(Handle, maximized_bounds, minimum_size, maximum_size);
715 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
723 [TypeConverter(typeof(OpacityConverter))]
724 [MWFCategory("Window Style")]
725 public double Opacity {
727 if (IsHandleCreated) {
728 if ((XplatUI.SupportsTransparency () & TransparencySupport.Get) != 0)
729 return XplatUI.GetWindowTransparency (Handle);
738 AllowTransparency = true;
740 if (IsHandleCreated) {
742 if ((XplatUI.SupportsTransparency () & TransparencySupport.Set) != 0)
743 XplatUI.SetWindowTransparency(Handle, opacity, TransparencyKey);
750 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
751 public Form[] OwnedForms {
755 form_list = new Form[owned_forms.Count];
757 for (int i=0; i<owned_forms.Count; i++) {
758 form_list[i] = (Form)owned_forms[i];
766 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
773 if (owner != value) {
775 owner.RemoveOwnedForm(this);
779 owner.AddOwnedForm(this);
780 if (IsHandleCreated) {
781 if (owner != null && owner.IsHandleCreated) {
782 XplatUI.SetTopmost(this.window.Handle, owner.window.Handle, true);
784 XplatUI.SetTopmost(this.window.Handle, IntPtr.Zero, false);
792 [MWFCategory("Window Style")]
793 public bool ShowInTaskbar {
795 return show_in_taskbar;
798 if (show_in_taskbar != value) {
799 show_in_taskbar = value;
800 if (IsHandleCreated) {
808 // new property so we can set the DesignerSerializationVisibility
809 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
811 public new Size Size {
812 get { return base.Size; }
813 set { base.Size = value; }
816 [MonoTODO("Trigger something when GripStyle is set")]
817 [DefaultValue(SizeGripStyle.Auto)]
818 [MWFCategory("Window Style")]
819 public SizeGripStyle SizeGripStyle {
821 return size_grip_style;
825 size_grip_style = value;
829 [DefaultValue(FormStartPosition.WindowsDefaultLocation)]
831 [MWFCategory("Layout")]
832 public FormStartPosition StartPosition {
834 return start_position;
838 if (start_position == FormStartPosition.WindowsDefaultLocation) { // Only do this if it's not set yet
839 start_position = value;
840 if (IsHandleCreated) {
841 switch(start_position) {
842 case FormStartPosition.CenterParent: {
847 case FormStartPosition.CenterScreen: {
852 case FormStartPosition.Manual: {
853 Left = CreateParams.X;
854 Top = CreateParams.Y;
867 // new property so we can set EditorBrowsable to never
869 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
870 [EditorBrowsable(EditorBrowsableState.Never)]
871 public new int TabIndex {
872 get { return base.TabIndex; }
873 set { base.TabIndex = value; }
877 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
878 [EditorBrowsable(EditorBrowsableState.Advanced)]
879 public bool TopLevel {
881 return GetTopLevel();
885 if (!value && IsMdiContainer)
886 throw new ArgumentException ("MDI Container forms must be top level.");
891 [DefaultValue(false)]
892 [MWFCategory("Window Style")]
893 public bool TopMost {
899 if (topmost != value) {
902 XplatUI.SetTopmost(window.Handle, owner != null ? owner.window.Handle : IntPtr.Zero, value);
907 [MWFCategory("Window Style")]
908 public Color TransparencyKey {
910 return transparency_key;
914 transparency_key = value;
916 AllowTransparency = true;
918 if ((XplatUI.SupportsTransparency () & TransparencySupport.Set) != 0)
919 XplatUI.SetWindowTransparency(Handle, Opacity, transparency_key);
923 [DefaultValue(FormWindowState.Normal)]
924 [MWFCategory("Layout")]
925 public FormWindowState WindowState {
927 if (IsHandleCreated) {
929 if (window_manager != null)
930 return window_manager.GetWindowState ();
932 FormWindowState new_state = XplatUI.GetWindowState(Handle);
933 if (new_state != (FormWindowState)(-1))
934 window_state = new_state;
941 FormWindowState old_state = window_state;
942 window_state = value;
943 if (IsHandleCreated) {
945 if (window_manager != null) {
946 window_manager.SetWindowState (old_state, value);
950 XplatUI.SetWindowState(Handle, value);
955 #endregion // Public Instance Properties
957 #region Protected Instance Properties
958 protected override CreateParams CreateParams {
960 CreateParams cp = new CreateParams ();
963 cp.ClassName = XplatUI.DefaultClassName;
968 cp.Parent = IntPtr.Zero;
969 cp.menu = ActiveMenu;
971 if (start_position == FormStartPosition.WindowsDefaultLocation && !IsMdiChild) {
972 cp.X = unchecked((int)0x80000000);
973 cp.Y = unchecked((int)0x80000000);
981 cp.Style = (int)(WindowStyles.WS_CLIPCHILDREN | WindowStyles.WS_CLIPSIBLINGS);
984 cp.Style |= (int)(WindowStyles.WS_CHILD | WindowStyles.WS_CAPTION);
985 if (Parent != null) {
986 cp.Parent = Parent.Handle;
989 cp.ExStyle |= (int) (WindowExStyles.WS_EX_WINDOWEDGE | WindowExStyles.WS_EX_MDICHILD);
991 switch (FormBorderStyle) {
992 case FormBorderStyle.None:
994 case FormBorderStyle.FixedToolWindow:
995 case FormBorderStyle.SizableToolWindow:
996 cp.ExStyle |= (int) WindowExStyles.WS_EX_TOOLWINDOW;
999 cp.Style |= (int) WindowStyles.WS_OVERLAPPEDWINDOW;
1004 switch (FormBorderStyle) {
1005 case FormBorderStyle.Fixed3D: {
1006 cp.Style |= (int)(WindowStyles.WS_CAPTION | WindowStyles.WS_BORDER);
1007 cp.ExStyle |= (int)WindowExStyles.WS_EX_CLIENTEDGE;
1011 case FormBorderStyle.FixedDialog: {
1012 cp.Style |= (int)(WindowStyles.WS_CAPTION | WindowStyles.WS_BORDER);
1013 cp.ExStyle |= (int)(WindowExStyles.WS_EX_DLGMODALFRAME | WindowExStyles.WS_EX_CONTROLPARENT);
1017 case FormBorderStyle.FixedSingle: {
1018 cp.Style |= (int)(WindowStyles.WS_CAPTION | WindowStyles.WS_BORDER);
1022 case FormBorderStyle.FixedToolWindow: {
1023 cp.Style |= (int)(WindowStyles.WS_CAPTION | WindowStyles.WS_BORDER);
1024 cp.ExStyle |= (int)(WindowExStyles.WS_EX_TOOLWINDOW);
1028 case FormBorderStyle.Sizable: {
1029 cp.Style |= (int)(WindowStyles.WS_BORDER | WindowStyles.WS_THICKFRAME | WindowStyles.WS_CAPTION);
1033 case FormBorderStyle.SizableToolWindow: {
1034 cp.Style |= (int)(WindowStyles.WS_BORDER | WindowStyles.WS_THICKFRAME | WindowStyles.WS_CAPTION);
1035 cp.ExStyle |= (int)(WindowExStyles.WS_EX_TOOLWINDOW);
1039 case FormBorderStyle.None: {
1045 switch(window_state) {
1046 case FormWindowState.Maximized: {
1047 cp.Style |= (int)WindowStyles.WS_MAXIMIZE;
1051 case FormWindowState.Minimized: {
1052 cp.Style |= (int)WindowStyles.WS_MINIMIZE;
1058 cp.ExStyle |= (int) WindowExStyles.WS_EX_TOPMOST;
1061 if (ShowInTaskbar) {
1062 cp.ExStyle |= (int)WindowExStyles.WS_EX_APPWINDOW;
1066 cp.Style |= (int)WindowStyles.WS_MAXIMIZEBOX;
1070 cp.Style |= (int)WindowStyles.WS_MINIMIZEBOX;
1074 cp.Style |= (int)WindowStyles.WS_SYSMENU;
1077 if (HelpButton && !MaximizeBox && !MinimizeBox) {
1078 cp.ExStyle |= (int)WindowExStyles.WS_EX_CONTEXTHELP;
1082 cp.Style |= (int)WindowStyles.WS_VISIBLE;
1084 if (Opacity < 1.0 || TransparencyKey != Color.Empty) {
1085 cp.ExStyle |= (int)WindowExStyles.WS_EX_LAYERED;
1088 if (!is_enabled && context == null) {
1089 cp.Style |= (int)(WindowStyles.WS_DISABLED);
1096 protected override ImeMode DefaultImeMode {
1098 return ImeMode.NoControl;
1102 protected override Size DefaultSize {
1104 return new Size (300, 300);
1108 protected Rectangle MaximizedBounds {
1110 if (maximized_bounds != Rectangle.Empty) {
1111 return maximized_bounds;
1113 return default_maximized_bounds;
1117 maximized_bounds = value;
1118 OnMaximizedBoundsChanged(EventArgs.Empty);
1119 if (IsHandleCreated) {
1120 XplatUI.SetWindowMinMax(Handle, maximized_bounds, minimum_size, maximum_size);
1124 #endregion // Protected Instance Properties
1126 #region Public Static Methods
1127 [EditorBrowsable(EditorBrowsableState.Advanced)]
1128 public static SizeF GetAutoScaleSize (Font font)
1130 return XplatUI.GetAutoScaleSize(font);
1133 #endregion // Public Static Methods
1135 #region Public Instance Methods
1136 internal SizeF GetAutoScaleSize (Graphics g, Font font)
1139 // The following constants come from the dotnet mailing list
1140 // discussion: http://discuss.develop.com/archives/wa.exe?A2=ind0203A&L=DOTNET&P=R3655
1142 // The magic number is "Its almost the length
1143 // of the string with a smattering added in
1144 // for compat with earlier code".
1147 string magic_string = "The quick brown fox jumped over the lazy dog.";
1148 double magic_number = 44.549996948242189;
1149 float width = (float) (g.MeasureString (magic_string, font).Width / magic_number);
1151 return new SizeF (width, font.Height);
1154 public void Activate() {
1157 // The docs say activate only activates if our app is already active
1158 if (IsHandleCreated) {
1160 MdiParent.ActivateMdiChild (this);
1162 active = ActiveForm;
1163 if ((active != null) && (this != active)) {
1164 XplatUI.Activate(window.Handle);
1170 public void AddOwnedForm(Form ownedForm) {
1171 if (!owned_forms.Contains(ownedForm)) {
1172 owned_forms.Add(ownedForm);
1174 ownedForm.Owner = this;
1177 public void Close () {
1185 FormClosingEventArgs ce = new FormClosingEventArgs (CloseReason.FormOwnerClosing, false);
1190 XplatUI.SendMessage(this.Handle, Msg.WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
1193 public void LayoutMdi(MdiLayout value) {
1194 if (mdi_container != null) {
1195 mdi_container.LayoutMdi(value);
1199 public void RemoveOwnedForm(Form ownedForm) {
1200 owned_forms.Remove(ownedForm);
1203 public void SetDesktopBounds(int x, int y, int width, int height) {
1204 DesktopBounds = new Rectangle(x, y, width, height);
1207 public void SetDesktopLocation(int x, int y) {
1208 DesktopLocation = new Point(x, y);
1211 public DialogResult ShowDialog() {
1212 return ShowDialog(this.owner);
1215 public DialogResult ShowDialog(IWin32Window ownerWin32) {
1218 IntPtr capture_window;
1222 if (ownerWin32 != null) {
1223 Control c = Control.FromHandle (ownerWin32.Handle);
1225 owner = c.TopLevelControl as Form;
1228 if (owner == this) {
1229 throw new InvalidOperationException("The 'ownerWin32' cannot be the form being shown.");
1233 throw new InvalidOperationException("The form is already displayed as a modal dialog.");
1237 throw new InvalidOperationException("Already visible forms cannot be displayed as a modal dialog. Set the Visible property to 'false' prior to calling Form.ShowDialog.");
1241 throw new InvalidOperationException("Cannot display a disabled form as modal dialog.");
1244 if (TopLevelControl != this) {
1245 throw new InvalidOperationException("Can only display TopLevel forms as modal dialog.");
1249 // Can't do this, will screw us in the modal loop
1250 form_parent_window.Parent = this.owner;
1253 // Release any captures
1254 XplatUI.GrabInfo(out capture_window, out confined, out area);
1255 if (capture_window != IntPtr.Zero) {
1256 XplatUI.UngrabWindow(capture_window);
1260 // Commented out; we instead let the Visible=true inside the runloop create the control
1261 // otherwise setting DialogResult inside any of the events that are triggered by the
1262 // create will not actually cause the form to not be displayed.
1263 // Leaving this comment here in case there was an actual purpose to creating the control
1265 if (!IsHandleCreated) {
1270 Application.RunLoop(true, new ApplicationContext(this));
1272 if (owner != null) {
1273 // Cannot use Activate(), it has a check for the current active window...
1274 XplatUI.Activate(owner.window.Handle);
1277 if (DialogResult != DialogResult.None) {
1278 return DialogResult;
1280 DialogResult = DialogResult.Cancel;
1281 return DialogResult.Cancel;
1284 public override string ToString() {
1285 return GetType().FullName.ToString() + ", Text: " + Text;
1287 #endregion // Public Instance Methods
1289 #region Protected Instance Methods
1290 protected void ActivateMdiChild(Form form) {
1291 if (!IsMdiContainer)
1293 mdi_container.ActivateChild (form);
1294 OnMdiChildActivate(EventArgs.Empty);
1297 [EditorBrowsable(EditorBrowsableState.Advanced)]
1298 protected override void AdjustFormScrollbars(bool displayScrollbars) {
1299 base.AdjustFormScrollbars (displayScrollbars);
1302 [EditorBrowsable(EditorBrowsableState.Advanced)]
1303 protected void ApplyAutoScaling()
1305 SizeF current_size_f = GetAutoScaleSize (DeviceContext, Font);
1306 Size current_size = new Size ((int) current_size_f.Width, (int) current_size_f.Height);
1310 if (current_size == autoscale_base_size)
1313 if (Environment.GetEnvironmentVariable ("MONO_MWF_SCALING") == "disable"){
1318 // I tried applying the Fudge height factor from:
1319 // http://blogs.msdn.com/mharsh/archive/2004/01/25/62621.aspx
1320 // but it makes things larger without looking better.
1322 if (current_size_f.Width != AutoScaleBaseSize.Width) {
1323 dx = current_size_f.Width / AutoScaleBaseSize.Width + 0.08f;
1328 if (current_size_f.Height != AutoScaleBaseSize.Height) {
1329 dy = current_size_f.Height / AutoScaleBaseSize.Height + 0.08f;
1336 AutoScaleBaseSize = current_size;
1339 protected void CenterToParent() {
1347 w = DefaultSize.Width;
1353 h = DefaultSize.Height;
1357 if (parent != null) {
1359 } else if (owner != null) {
1363 if (owner != null) {
1364 this.Location = new Point(ctl.Left + ctl.Width / 2 - w /2, ctl.Top + ctl.Height / 2 - h / 2);
1368 protected void CenterToScreen() {
1376 w = DefaultSize.Width;
1382 h = DefaultSize.Height;
1385 XplatUI.GetDisplaySize(out DisplaySize);
1386 this.Location = new Point(DisplaySize.Width / 2 - w / 2, DisplaySize.Height / 2 - h / 2);
1389 [EditorBrowsable(EditorBrowsableState.Advanced)]
1390 protected override Control.ControlCollection CreateControlsInstance() {
1391 return base.CreateControlsInstance ();
1394 [EditorBrowsable(EditorBrowsableState.Advanced)]
1395 protected override void CreateHandle() {
1396 base.CreateHandle ();
1400 if ((XplatUI.SupportsTransparency() & TransparencySupport.Set) != 0) {
1401 if (allow_transparency) {
1402 XplatUI.SetWindowTransparency(Handle, Opacity, TransparencyKey);
1406 XplatUI.SetWindowMinMax(window.Handle, maximized_bounds, minimum_size, maximum_size);
1407 if ((FormBorderStyle != FormBorderStyle.FixedDialog) && (icon != null)) {
1408 XplatUI.SetIcon(window.Handle, icon);
1411 if ((owner != null) && (owner.IsHandleCreated)) {
1412 XplatUI.SetTopmost(window.Handle, owner.window.Handle, true);
1415 for (int i = 0; i < owned_forms.Count; i++) {
1416 if (owned_forms[i].IsHandleCreated)
1417 XplatUI.SetTopmost(owned_forms[i].window.Handle, window.Handle, true);
1420 if (window_manager != null && window_state != FormWindowState.Normal) {
1421 window_manager.SetWindowState (FormWindowState.Normal, window_state);
1426 [EditorBrowsable(EditorBrowsableState.Advanced)]
1427 protected override void DefWndProc(ref Message m) {
1428 base.DefWndProc (ref m);
1431 protected override void Dispose(bool disposing)
1433 for (int i = 0; i < owned_forms.Count; i++)
1434 ((Form)owned_forms[i]).Owner = null;
1436 owned_forms.Clear ();
1438 base.Dispose (disposing);
1441 [EditorBrowsable(EditorBrowsableState.Advanced)]
1442 protected virtual void OnActivated(EventArgs e)
1445 SelectActiveControl ();
1447 EventHandler eh = (EventHandler)(Events [ActivatedEvent]);
1452 [EditorBrowsable(EditorBrowsableState.Advanced)]
1453 protected virtual void OnClosed(EventArgs e) {
1454 EventHandler eh = (EventHandler)(Events [ClosedEvent]);
1459 [EditorBrowsable(EditorBrowsableState.Advanced)]
1460 protected virtual void OnClosing(System.ComponentModel.CancelEventArgs e) {
1461 CancelEventHandler eh = (CancelEventHandler)(Events [ClosingEvent]);
1466 [EditorBrowsable(EditorBrowsableState.Advanced)]
1467 protected override void OnCreateControl() {
1468 base.OnCreateControl ();
1471 XplatUI.SetMenu(window.Handle, menu);
1474 OnLoad(EventArgs.Empty);
1476 SelectActiveControl ();
1478 // Send initial location
1479 OnLocationChanged(EventArgs.Empty);
1481 if (IsMdiContainer) {
1482 mdi_container.LayoutMdi (MdiLayout.Cascade);
1486 [EditorBrowsable(EditorBrowsableState.Advanced)]
1487 protected virtual void OnDeactivate(EventArgs e) {
1488 EventHandler eh = (EventHandler)(Events [DeactivateEvent]);
1493 [EditorBrowsable(EditorBrowsableState.Advanced)]
1494 protected override void OnFontChanged(EventArgs e) {
1495 base.OnFontChanged (e);
1498 [EditorBrowsable(EditorBrowsableState.Advanced)]
1499 protected override void OnHandleCreated(EventArgs e) {
1500 XplatUI.SetBorderStyle(window.Handle, form_border_style);
1501 base.OnHandleCreated (e);
1504 [EditorBrowsable(EditorBrowsableState.Advanced)]
1505 protected override void OnHandleDestroyed(EventArgs e) {
1506 base.OnHandleDestroyed (e);
1509 [EditorBrowsable(EditorBrowsableState.Advanced)]
1510 protected virtual void OnInputLanguageChanged(InputLanguageChangedEventArgs e) {
1511 InputLanguageChangedEventHandler eh = (InputLanguageChangedEventHandler)(Events [InputLanguageChangedEvent]);
1516 [EditorBrowsable(EditorBrowsableState.Advanced)]
1517 protected virtual void OnInputLanguageChanging(InputLanguageChangingEventArgs e) {
1518 InputLanguageChangingEventHandler eh = (InputLanguageChangingEventHandler)(Events [InputLanguageChangingEvent]);
1523 [EditorBrowsable(EditorBrowsableState.Advanced)]
1524 protected virtual void OnLoad(EventArgs e) {
1526 ApplyAutoScaling ();
1530 EventHandler eh = (EventHandler)(Events [LoadEvent]);
1535 switch (StartPosition) {
1536 case FormStartPosition.CenterScreen:
1537 this.CenterToScreen();
1539 case FormStartPosition.CenterParent:
1540 this.CenterToParent ();
1542 case FormStartPosition.Manual:
1543 Left = CreateParams.X;
1544 Top = CreateParams.Y;
1551 [EditorBrowsable(EditorBrowsableState.Advanced)]
1552 protected virtual void OnMaximizedBoundsChanged(EventArgs e) {
1553 EventHandler eh = (EventHandler)(Events [MaximizedBoundsChangedEvent]);
1558 [EditorBrowsable(EditorBrowsableState.Advanced)]
1559 protected virtual void OnMaximumSizeChanged(EventArgs e) {
1560 EventHandler eh = (EventHandler)(Events [MaximumSizeChangedEvent]);
1565 [EditorBrowsable(EditorBrowsableState.Advanced)]
1566 protected virtual void OnMdiChildActivate(EventArgs e) {
1567 EventHandler eh = (EventHandler)(Events [MdiChildActivateEvent]);
1572 [EditorBrowsable(EditorBrowsableState.Advanced)]
1573 protected virtual void OnMenuComplete(EventArgs e) {
1574 EventHandler eh = (EventHandler)(Events [MenuCompleteEvent]);
1579 [EditorBrowsable(EditorBrowsableState.Advanced)]
1580 protected virtual void OnMenuStart(EventArgs e) {
1581 EventHandler eh = (EventHandler)(Events [MenuStartEvent]);
1586 [EditorBrowsable(EditorBrowsableState.Advanced)]
1587 protected virtual void OnMinimumSizeChanged(EventArgs e) {
1588 EventHandler eh = (EventHandler)(Events [MinimumSizeChangedEvent]);
1593 [EditorBrowsable(EditorBrowsableState.Advanced)]
1594 protected override void OnPaint (PaintEventArgs pevent) {
1595 base.OnPaint (pevent);
1598 [EditorBrowsable(EditorBrowsableState.Advanced)]
1599 protected override void OnResize(EventArgs e) {
1602 if (this.IsMdiChild && ParentForm != null) {
1603 ParentForm.PerformLayout();
1604 ParentForm.Size = ParentForm.Size;
1608 [EditorBrowsable(EditorBrowsableState.Advanced)]
1609 protected override void OnStyleChanged(EventArgs e) {
1610 base.OnStyleChanged (e);
1613 [EditorBrowsable(EditorBrowsableState.Advanced)]
1614 protected override void OnTextChanged(EventArgs e) {
1615 base.OnTextChanged (e);
1617 if (mdi_container != null)
1618 mdi_container.SetParentText(true);
1621 [EditorBrowsable(EditorBrowsableState.Advanced)]
1622 protected override void OnVisibleChanged(EventArgs e) {
1623 base.OnVisibleChanged (e);
1626 if (window_manager != null)
1627 window_manager.SetWindowState (WindowState, WindowState);
1631 protected override bool ProcessCmdKey(ref Message msg, Keys keyData) {
1632 if (base.ProcessCmdKey (ref msg, keyData)) {
1636 // Give our menu a shot
1637 if (ActiveMenu != null) {
1638 return ActiveMenu.ProcessCmdKey(ref msg, keyData);
1644 // LAMESPEC - Not documented that Form overrides ProcessDialogChar; class-status showed
1645 [EditorBrowsable (EditorBrowsableState.Advanced)]
1646 protected override bool ProcessDialogChar(char charCode) {
1647 return base.ProcessDialogChar (charCode);
1650 protected override bool ProcessDialogKey(Keys keyData) {
1651 if ((keyData & Keys.Modifiers) == 0) {
1652 if (keyData == Keys.Enter) {
1653 IntPtr window = XplatUI.GetFocus ();
1654 Control c = Control.FromHandle (window);
1655 if (c is Button && c.FindForm () == this) {
1656 ((Button)c).PerformClick ();
1659 else if (accept_button != null) {
1660 accept_button.PerformClick();
1663 } else if (keyData == Keys.Escape && cancel_button != null) {
1664 cancel_button.PerformClick();
1668 return base.ProcessDialogKey(keyData);
1671 protected override bool ProcessKeyPreview(ref Message msg) {
1673 if (ProcessKeyEventArgs(ref msg)) {
1677 return base.ProcessKeyPreview (ref msg);
1680 protected override bool ProcessTabKey(bool forward) {
1681 return SelectNextControl(ActiveControl, forward, true, true, true);
1684 [EditorBrowsable(EditorBrowsableState.Advanced)]
1685 protected override void ScaleCore(float dx, float dy) {
1689 // We can't scale max or min windows
1690 if (WindowState == FormWindowState.Normal) {
1691 // We cannot call base since base also adjusts X/Y, but
1692 // a form is toplevel and doesn't move
1696 if (!GetStyle(ControlStyles.FixedWidth)) {
1697 size.Width = (int)(size.Width * dx);
1700 if (!GetStyle(ControlStyles.FixedHeight)) {
1701 size.Height = (int)(size.Height * dy);
1707 /* Now scale our children */
1708 Control [] controls = child_controls.GetAllControls ();
1709 for (int i=0; i < controls.Length; i++) {
1710 controls[i].Scale(dx, dy);
1719 protected override void Select(bool directed, bool forward) {
1723 base.SelectNextControl(null, forward, true, true, true);
1726 parent = this.ParentForm;
1727 if (parent != null) {
1728 parent.ActiveControl = this;
1734 [EditorBrowsable(EditorBrowsableState.Advanced)]
1735 protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
1736 base.SetBoundsCore (x, y, width, height, specified);
1739 [EditorBrowsable(EditorBrowsableState.Advanced)]
1740 protected override void SetClientSizeCore(int x, int y) {
1741 if ((minimum_size.Width != 0) && (x < minimum_size.Width)) {
1742 x = minimum_size.Width;
1743 } else if ((maximum_size.Width != 0) && (x > maximum_size.Width)) {
1744 x = maximum_size.Width;
1747 if ((minimum_size.Height != 0) && (y < minimum_size.Height)) {
1748 y = minimum_size.Height;
1749 } else if ((maximum_size.Height != 0) && (y > maximum_size.Height)) {
1750 y = maximum_size.Height;
1753 Rectangle ClientRect = new Rectangle(0, 0, x, y);
1754 Rectangle WindowRect;
1755 CreateParams cp = this.CreateParams;
1757 clientsize_set = new Size(x, y);
1759 if (XplatUI.CalculateWindowRect(ref ClientRect, cp.Style, cp.ExStyle, cp.menu, out WindowRect)) {
1760 SetBounds(bounds.X, bounds.Y, WindowRect.Width, WindowRect.Height, BoundsSpecified.Size);
1764 [EditorBrowsable(EditorBrowsableState.Advanced)]
1765 protected override void SetVisibleCore(bool value) {
1766 is_changing_visible_state = true;
1767 has_been_visible = value || has_been_visible;
1768 base.SetVisibleCore (value);
1769 is_changing_visible_state = false;
1772 protected override void UpdateDefaultButton() {
1773 base.UpdateDefaultButton ();
1776 [EditorBrowsable(EditorBrowsableState.Advanced)]
1777 protected override void WndProc(ref Message m) {
1779 if (window_manager != null && window_manager.HandleMessage (ref m)) {
1783 switch((Msg)m.Msg) {
1784 case Msg.WM_DESTROY: {
1785 base.WndProc(ref m);
1786 if (!is_recreating) {
1787 this.closing = true;
1792 case Msg.WM_CLOSE_INTERNAL: {
1797 case Msg.WM_CLOSE: {
1798 Form act = Form.ActiveForm;
1799 if (act != null && act != this && act.Modal == true) {
1803 CancelEventArgs args = new CancelEventArgs ();
1805 if (mdi_container != null) {
1806 foreach (Form mdi_child in mdi_container.MdiChildren) {
1807 mdi_child.OnClosing (args);
1814 OnClosed (EventArgs.Empty);
1821 DialogResult = DialogResult.None;
1824 OnClosed (EventArgs.Empty);
1833 case Msg.WM_WINDOWPOSCHANGED: {
1834 if (WindowState != FormWindowState.Minimized) {
1835 base.WndProc(ref m);
1841 case Msg.WM_SYSCOMMAND: {
1842 // Let *Strips know the app's title bar was clicked
1843 if (XplatUI.IsEnabled (Handle))
1844 ToolStripManager.FireAppClicked ();
1846 base.WndProc(ref m);
1851 case Msg.WM_ACTIVATE: {
1852 if (m.WParam != (IntPtr)WindowActiveFlags.WA_INACTIVE) {
1853 OnActivated(EventArgs.Empty);
1855 OnDeactivate(EventArgs.Empty);
1860 case Msg.WM_KILLFOCUS: {
1861 base.WndProc(ref m);
1865 case Msg.WM_SETFOCUS: {
1866 if (ActiveControl != null && ActiveControl != this) {
1867 ActiveControl.Focus();
1868 return; // FIXME - do we need to run base.WndProc, even though we just changed focus?
1870 base.WndProc(ref m);
1875 case Msg.WM_NCLBUTTONDOWN: {
1876 if (XplatUI.IsEnabled (Handle) && ActiveMenu != null) {
1877 ActiveMenu.OnMouseDown(this, new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()), mouse_clicks, Control.MousePosition.X, Control.MousePosition.Y, 0));
1880 if (ActiveMaximizedMdiChild != null) {
1881 if (ActiveMaximizedMdiChild.HandleMenuMouseDown (ActiveMenu,
1882 LowOrder ((int) m.LParam.ToInt32 ()),
1883 HighOrder ((int) m.LParam.ToInt32 ()))) {
1884 // Don't let base process this message, otherwise we won't
1885 // get a WM_NCLBUTTONUP.
1889 base.WndProc(ref m);
1892 case Msg.WM_NCLBUTTONUP: {
1893 if (ActiveMaximizedMdiChild != null) {
1894 ActiveMaximizedMdiChild.HandleMenuMouseUp (ActiveMenu,
1895 LowOrder ((int)m.LParam.ToInt32 ()),
1896 HighOrder ((int)m.LParam.ToInt32 ()));
1898 base.WndProc (ref m);
1902 case Msg.WM_NCMOUSELEAVE: {
1903 if (ActiveMaximizedMdiChild != null) {
1904 ActiveMaximizedMdiChild.HandleMenuMouseLeave(ActiveMenu,
1905 LowOrder((int)m.LParam.ToInt32()),
1906 HighOrder((int)m.LParam.ToInt32()));
1908 base.WndProc(ref m);
1912 case Msg.WM_NCMOUSEMOVE: {
1913 if (XplatUI.IsEnabled (Handle) && ActiveMenu != null) {
1914 ActiveMenu.OnMouseMove(this, new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()), mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()), 0));
1917 if (ActiveMaximizedMdiChild != null) {
1918 ActiveMaximizedMdiChild.HandleMenuMouseMove (ActiveMenu,
1919 LowOrder ((int)m.LParam.ToInt32 ()),
1920 HighOrder ((int)m.LParam.ToInt32 ()));
1922 base.WndProc(ref m);
1926 case Msg.WM_NCPAINT: {
1927 if (ActiveMenu != null) {
1931 pe = XplatUI.PaintEventStart(Handle, false);
1932 pnt = XplatUI.GetMenuOrigin(window.Handle);
1934 // The entire menu has to be in the clip rectangle because the
1935 // control buttons are right-aligned and otherwise they would
1936 // stay painted when the window gets resized.
1937 Rectangle clip = new Rectangle (pnt.X, pnt.Y, ClientSize.Width, 0);
1938 clip = Rectangle.Union(clip, pe.ClipRectangle);
1940 pe.Graphics.SetClip(clip);
1942 ActiveMenu.Draw (pe, new Rectangle (pnt.X, pnt.Y, ClientSize.Width, 0));
1944 if (ActiveMaximizedMdiChild != null) {
1945 ActiveMaximizedMdiChild.DrawMaximizedButtons (ActiveMenu, pe);
1948 XplatUI.PaintEventEnd(Handle, false);
1951 base.WndProc(ref m);
1955 case Msg.WM_NCCALCSIZE: {
1956 XplatUIWin32.NCCALCSIZE_PARAMS ncp;
1958 if ((ActiveMenu != null) && (m.WParam == (IntPtr)1)) {
1959 ncp = (XplatUIWin32.NCCALCSIZE_PARAMS)Marshal.PtrToStructure(m.LParam, typeof(XplatUIWin32.NCCALCSIZE_PARAMS));
1962 ncp.rgrc1.top += ThemeEngine.Current.CalcMenuBarSize (DeviceContext, ActiveMenu, ncp.rgrc1.right - ncp.rgrc1.left);
1963 Marshal.StructureToPtr(ncp, m.LParam, true);
1969 case Msg.WM_MOUSEMOVE: {
1970 if (XplatUI.IsEnabled (Handle) && active_tracker != null) {
1971 MouseEventArgs args;
1973 args = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
1974 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()), 0);
1975 active_tracker.OnMotion(new MouseEventArgs (args.Button, args.Clicks, Control.MousePosition.X, Control.MousePosition.Y, args.Delta));
1978 base.WndProc(ref m);
1982 case Msg.WM_LBUTTONDOWN:
1983 case Msg.WM_MBUTTONDOWN:
1984 case Msg.WM_RBUTTONDOWN: {
1985 if (XplatUI.IsEnabled (Handle) && active_tracker != null) {
1986 MouseEventArgs args;
1988 args = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
1989 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()), 0);
1990 active_tracker.OnMouseDown(new MouseEventArgs (args.Button, args.Clicks, Control.MousePosition.X, Control.MousePosition.Y, args.Delta));
1993 base.WndProc(ref m);
1997 case Msg.WM_LBUTTONUP:
1998 case Msg.WM_MBUTTONUP:
1999 case Msg.WM_RBUTTONUP: {
2000 if (XplatUI.IsEnabled (Handle) && active_tracker != null) {
2001 MouseEventArgs args;
2002 MouseButtons mb = FromParamToMouseButtons ((int) m.WParam.ToInt32());
2004 // We add in the button that was released (not sent in WParam)
2005 switch((Msg)m.Msg) {
2006 case Msg.WM_LBUTTONUP:
2007 mb |= MouseButtons.Left;
2009 case Msg.WM_MBUTTONUP:
2010 mb |= MouseButtons.Middle;
2012 case Msg.WM_RBUTTONUP:
2013 mb |= MouseButtons.Right;
2017 args = new MouseEventArgs (mb, mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()), 0);
2018 active_tracker.OnMouseUp(new MouseEventArgs (args.Button, args.Clicks, Control.MousePosition.X, Control.MousePosition.Y, args.Delta));
2022 base.WndProc(ref m);
2026 case Msg.WM_GETMINMAXINFO: {
2029 if (m.LParam != IntPtr.Zero) {
2030 mmi = (MINMAXINFO)Marshal.PtrToStructure(m.LParam, typeof(MINMAXINFO));
2032 default_maximized_bounds = new Rectangle(mmi.ptMaxPosition.x, mmi.ptMaxPosition.y, mmi.ptMaxSize.x, mmi.ptMaxSize.y);
2033 if (maximized_bounds != Rectangle.Empty) {
2034 mmi.ptMaxPosition.x = maximized_bounds.Left;
2035 mmi.ptMaxPosition.y = maximized_bounds.Top;
2036 mmi.ptMaxSize.x = maximized_bounds.Width;
2037 mmi.ptMaxSize.y = maximized_bounds.Height;
2040 if (minimum_size != Size.Empty) {
2041 mmi.ptMinTrackSize.x = minimum_size.Width;
2042 mmi.ptMinTrackSize.y = minimum_size.Height;
2045 if (maximum_size != Size.Empty) {
2046 mmi.ptMaxTrackSize.x = maximum_size.Width;
2047 mmi.ptMaxTrackSize.y = maximum_size.Height;
2049 Marshal.StructureToPtr(mmi, m.LParam, false);
2055 case Msg.WM_MOUSEACTIVATE: {
2056 // Let *Strips know the form or another control has been clicked
2057 if (XplatUI.IsEnabled (Handle))
2058 ToolStripManager.FireAppClicked ();
2060 base.WndProc (ref m);
2064 case Msg.WM_ACTIVATEAPP: {
2065 // Let *Strips know the app lost focus
2066 if (m.WParam == (IntPtr)0)
2067 if (XplatUI.IsEnabled (Handle))
2068 ToolStripManager.FireAppFocusChanged (this);
2070 base.WndProc (ref m);
2076 base.WndProc (ref m);
2081 #endregion // Protected Instance Methods
2083 internal void RemoveWindowManager ()
2085 window_manager = null;
2088 internal override void CheckAcceptButton()
2090 if (accept_button != null) {
2091 Button a_button = accept_button as Button;
2093 if (ActiveControl == a_button)
2096 if (ActiveControl is Button) {
2097 a_button.paint_as_acceptbutton = false;
2101 a_button.paint_as_acceptbutton = true;
2108 static object ActivatedEvent = new object ();
2109 static object ClosedEvent = new object ();
2110 static object ClosingEvent = new object ();
2111 static object DeactivateEvent = new object ();
2112 static object InputLanguageChangedEvent = new object ();
2113 static object InputLanguageChangingEvent = new object ();
2114 static object LoadEvent = new object ();
2115 static object MaximizedBoundsChangedEvent = new object ();
2116 static object MaximumSizeChangedEvent = new object ();
2117 static object MdiChildActivateEvent = new object ();
2118 static object MenuCompleteEvent = new object ();
2119 static object MenuStartEvent = new object ();
2120 static object MinimumSizeChangedEvent = new object ();
2122 public event EventHandler Activated {
2123 add { Events.AddHandler (ActivatedEvent, value); }
2124 remove { Events.RemoveHandler (ActivatedEvent, value); }
2127 public event EventHandler Closed {
2128 add { Events.AddHandler (ClosedEvent, value); }
2129 remove { Events.RemoveHandler (ClosedEvent, value); }
2132 public event CancelEventHandler Closing {
2133 add { Events.AddHandler (ClosingEvent, value); }
2134 remove { Events.RemoveHandler (ClosingEvent, value); }
2137 public event EventHandler Deactivate {
2138 add { Events.AddHandler (DeactivateEvent, value); }
2139 remove { Events.RemoveHandler (DeactivateEvent, value); }
2142 public event InputLanguageChangedEventHandler InputLanguageChanged {
2143 add { Events.AddHandler (InputLanguageChangedEvent, value); }
2144 remove { Events.RemoveHandler (InputLanguageChangedEvent, value); }
2147 public event InputLanguageChangingEventHandler InputLanguageChanging {
2148 add { Events.AddHandler (InputLanguageChangingEvent, value); }
2149 remove { Events.RemoveHandler (InputLanguageChangingEvent, value); }
2152 public event EventHandler Load {
2153 add { Events.AddHandler (LoadEvent, value); }
2154 remove { Events.RemoveHandler (LoadEvent, value); }
2157 public event EventHandler MaximizedBoundsChanged {
2158 add { Events.AddHandler (MaximizedBoundsChangedEvent, value); }
2159 remove { Events.RemoveHandler (MaximizedBoundsChangedEvent, value); }
2162 public event EventHandler MaximumSizeChanged {
2163 add { Events.AddHandler (MaximumSizeChangedEvent, value); }
2164 remove { Events.RemoveHandler (MaximumSizeChangedEvent, value); }
2167 public event EventHandler MdiChildActivate {
2168 add { Events.AddHandler (MdiChildActivateEvent, value); }
2169 remove { Events.RemoveHandler (MdiChildActivateEvent, value); }
2172 public event EventHandler MenuComplete {
2173 add { Events.AddHandler (MenuCompleteEvent, value); }
2174 remove { Events.RemoveHandler (MenuCompleteEvent, value); }
2177 public event EventHandler MenuStart {
2178 add { Events.AddHandler (MenuStartEvent, value); }
2179 remove { Events.RemoveHandler (MenuStartEvent, value); }
2182 public event EventHandler MinimumSizeChanged {
2183 add { Events.AddHandler (MinimumSizeChangedEvent, value); }
2184 remove { Events.RemoveHandler (MinimumSizeChangedEvent, value); }
2189 [EditorBrowsable(EditorBrowsableState.Never)]
2190 public new event EventHandler TabIndexChanged {
2191 add { base.TabIndexChanged += value; }
2192 remove { base.TabIndexChanged -= value; }
2194 #endregion // Events
2197 public override string Text {
2207 public new Point Location {
2209 return base.Location;
2213 base.Location = value;
2217 static object FormClosingEvent = new object ();
2218 static object FormClosedEvent = new object ();
2220 public event FormClosingEventHandler FormClosing {
2221 add { Events.AddHandler (FormClosingEvent, value); }
2222 remove { Events.RemoveHandler (FormClosingEvent, value); }
2225 public event FormClosedEventHandler FormClosed {
2226 add { Events.AddHandler (FormClosedEvent, value); }
2227 remove { Events.RemoveHandler (FormClosedEvent, value); }
2230 protected virtual void OnFormClosing (FormClosingEventArgs e)
2232 FormClosingEventHandler eh = (FormClosingEventHandler)(Events [FormClosingEvent]);