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;
83 #endregion // Local Variables
85 #region Private & Internal Methods
88 default_icon = Locale.GetResource("mono.ico") as Icon;
91 // warning: this is only hooked up when an mdi container is created.
92 private void ControlAddedHandler (object sender, ControlEventArgs e)
94 if (mdi_container != null) {
95 mdi_container.SendToBack ();
99 private void SelectActiveControl ()
101 if (this.IsMdiContainer)
104 if (this.ActiveControl == null) {
107 // This visible hack is to work around CanSelect always being false if one of the parents
108 // is not visible; and we by default create Form invisible...
109 visible = this.is_visible;
110 this.is_visible = true;
112 if (SelectNextControl (this, true, true, true, true) == false) {
116 this.is_visible = visible;
118 Select (ActiveControl);
121 #endregion // Private & Internal Methods
123 #region Public Classes
124 public new class ControlCollection : Control.ControlCollection {
127 public ControlCollection(Form owner) : base(owner) {
128 this.form_owner = owner;
131 public override void Add(Control value) {
132 if (Contains (value))
135 ((Form)value).owner=(Form)owner;
138 public override void Remove(Control value) {
139 ((Form)value).owner = null;
143 #endregion // Public Classes
145 #region Public Constructor & Destructor
148 SizeF current_scale = GetAutoScaleSize (DeviceContext, Font);
151 autoscale_base_size = new Size ((int)current_scale.Width, (int) current_scale.Height);
152 allow_transparency = false;
155 dialog_result = DialogResult.None;
156 start_position = FormStartPosition.WindowsDefaultLocation;
157 form_border_style = FormBorderStyle.Sizable;
158 window_state = FormWindowState.Normal;
163 minimum_size = Size.Empty;
164 maximum_size = Size.Empty;
165 clientsize_set = Size.Empty;
170 show_in_taskbar = true;
171 ime_mode = ImeMode.NoControl;
174 size_grip_style = SizeGripStyle.Auto;
175 maximized_bounds = Rectangle.Empty;
176 default_maximized_bounds = Rectangle.Empty;
177 owned_forms = new Form.ControlCollection(this);
178 transparency_key = Color.Empty;
180 // FIXME: this should disappear just as soon as the handle creation is done in the right place (here is too soon()
184 #endregion // Public Constructor & Destructor
186 #region Public Static Properties
188 public static Form ActiveForm {
192 active = FromHandle(XplatUI.GetActive());
194 if (active != null) {
195 if ( !(active is Form)) {
198 parent = active.Parent;
199 while (parent != null) {
200 if (parent is Form) {
203 parent = parent.Parent;
213 #endregion // Public Static Properties
215 #region Public Instance Properties
217 public IButtonControl AcceptButton {
219 return accept_button;
223 accept_button = value;
229 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
230 public bool AllowTransparency {
232 return allow_transparency;
236 if (value == allow_transparency) {
240 allow_transparency = value;
243 if (IsHandleCreated) {
244 if ((XplatUI.SupportsTransparency() & TransparencySupport.Set) != 0) {
245 XplatUI.SetWindowTransparency(Handle, Opacity, TransparencyKey);
248 UpdateStyles(); // Remove the WS_EX_LAYERED style
255 [MWFCategory("Layout")]
256 public bool AutoScale {
268 [EditorBrowsable(EditorBrowsableState.Advanced)]
269 public virtual Size AutoScaleBaseSize {
271 return autoscale_base_size;
275 autoscale_base_size = value;
280 public override bool AutoScroll {
282 return base.AutoScroll;
285 base.AutoScroll = value;
289 public override Color BackColor {
291 /* we don't let parents override our
292 default background color for forms.
293 this fixes the default color for mdi
295 if (background_color.IsEmpty)
296 return DefaultBackColor;
298 return background_color;
301 base.BackColor = value;
306 public IButtonControl CancelButton {
308 return cancel_button;
312 cancel_button = value;
316 [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
318 public Size ClientSize {
320 return base.ClientSize;
324 base.ClientSize = value;
329 [MWFCategory("Window Style")]
330 public bool ControlBox {
336 if (control_box != value) {
344 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
345 public Rectangle DesktopBounds {
347 return new Rectangle(Location, Size);
356 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
357 public Point DesktopLocation {
368 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
369 public DialogResult DialogResult {
371 return dialog_result;
375 if (value < DialogResult.None || value > DialogResult.No)
376 throw new InvalidEnumArgumentException ("value", (int) value,
377 typeof (DialogResult));
379 dialog_result = value;
380 closing = (dialog_result != DialogResult.None && is_modal);
384 [DefaultValue(FormBorderStyle.Sizable)]
386 [MWFCategory("Appearance")]
387 public FormBorderStyle FormBorderStyle {
389 return form_border_style;
392 form_border_style = value;
394 if (window_manager == null) {
395 if (IsHandleCreated) {
396 XplatUI.SetBorderStyle(window.Handle, form_border_style);
399 window_manager.UpdateBorderStyle (value);
406 [DefaultValue(false)]
407 [MWFCategory("Window Style")]
408 public bool HelpButton {
414 if (help_button != value) {
423 [MWFCategory("Window Style")]
433 if (IsHandleCreated) {
434 XplatUI.SetIcon(Handle, icon == null ? default_icon : icon);
441 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
442 public bool IsMdiChild {
444 return mdi_parent != null;
448 [DefaultValue(false)]
449 [MWFCategory("Window Style")]
450 public bool IsMdiContainer {
452 return mdi_container != null;
456 if (value && mdi_container == null) {
457 mdi_container = new MdiClient ();
458 Controls.Add(mdi_container);
459 ControlAdded += new ControlEventHandler (ControlAddedHandler);
460 mdi_container.SendToBack ();
461 } else if (!value && mdi_container != null) {
462 Controls.Remove(mdi_container);
463 mdi_container = null;
469 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
470 public Form ActiveMdiChild {
474 return (Form) mdi_container.ActiveMdiChild;
479 [EditorBrowsable(EditorBrowsableState.Advanced)]
480 public bool IsRestrictedWindow {
486 [DefaultValue(false)]
487 public bool KeyPreview {
498 [MWFCategory("Window Style")]
499 public bool MaximizeBox {
504 if (maximize_box != value) {
505 maximize_box = value;
506 if (IsHandleCreated) {
514 [DefaultValue("{Width=0, Height=0}")]
516 [RefreshProperties(RefreshProperties.Repaint)]
517 [MWFCategory("Layout")]
518 public Size MaximumSize {
524 if (maximum_size != value) {
525 maximum_size = value;
526 OnMaximumSizeChanged(EventArgs.Empty);
527 if (IsHandleCreated) {
528 XplatUI.SetWindowMinMax(Handle, maximized_bounds, minimum_size, maximum_size);
535 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
536 public Form[] MdiChildren {
538 if (mdi_container != null)
539 return mdi_container.MdiChildren;
546 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
547 public Form MdiParent {
553 if (value != null && !value.IsMdiContainer)
554 throw new ArgumentException ();
556 if (mdi_parent != null) {
557 mdi_parent.MdiContainer.original_order.Remove (this);
558 mdi_parent.MdiContainer.Controls.Remove (this);
563 window_manager = new MdiWindowManager (this,
564 mdi_parent.MdiContainer);
565 mdi_parent.MdiContainer.original_order.Add (this);
566 mdi_parent.MdiContainer.Controls.Add (this);
570 } else if (mdi_parent != null) {
573 // Create a new window manager
574 window_manager = null;
575 FormBorderStyle = form_border_style;
582 internal MenuTracker ActiveTracker {
583 get { return active_tracker; }
585 if (value == active_tracker)
588 Capture = value != null;
589 active_tracker = value;
593 internal MdiClient MdiContainer {
594 get { return mdi_container; }
597 internal InternalWindowManager WindowManager {
598 get { return window_manager; }
602 [MWFCategory("Window Style")]
603 public MainMenu Menu {
612 if (menu != null && !IsMdiChild) {
615 if (IsHandleCreated) {
616 XplatUI.SetMenu (window.Handle, menu);
619 if (clientsize_set != Size.Empty) {
620 SetClientSizeCore(clientsize_set.Width, clientsize_set.Height);
622 UpdateBounds (bounds.X, bounds.Y, bounds.Width, bounds.Height, ClientSize.Width, ClientSize.Height -
623 ThemeEngine.Current.CalcMenuBarSize (DeviceContext, menu, ClientSize.Width));
632 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
633 [EditorBrowsable(EditorBrowsableState.Advanced)]
634 public MainMenu MergedMenu {
636 if (!IsMdiChild || window_manager == null)
638 return ((MdiWindowManager) window_manager).MergedMenu;
642 // This is the menu in display and being used because of merging this can
643 // be different then the menu that is actually assosciated with the form
644 internal MainMenu ActiveMenu {
649 if (IsMdiContainer && mdi_container.Controls.Count > 0 &&
650 ((Form) mdi_container.Controls [0]).WindowState == FormWindowState.Maximized) {
651 MdiWindowManager wm = (MdiWindowManager) ((Form) mdi_container.Controls [0]).WindowManager;
652 return wm.MaximizedMenu;
655 Form amc = ActiveMdiChild;
656 if (amc == null || amc.Menu == null)
658 return amc.MergedMenu;
662 internal MdiWindowManager ActiveMaximizedMdiChild {
664 Form child = ActiveMdiChild;
667 if (child.WindowManager == null || child.window_state != FormWindowState.Maximized)
669 return (MdiWindowManager) child.WindowManager;
674 [MWFCategory("Window Style")]
675 public bool MinimizeBox {
680 if (minimize_box != value) {
681 minimize_box = value;
682 if (IsHandleCreated) {
690 [DefaultValue("{Width=0, Height=0}")]
692 [RefreshProperties(RefreshProperties.Repaint)]
693 [MWFCategory("Layout")]
694 public Size MinimumSize {
700 if (minimum_size != value) {
701 minimum_size = value;
703 if ((Size.Width < value.Width) || (Size.Height < value.Height)) {
704 Size = new Size(Math.Max(Size.Width, value.Width), Math.Max(Size.Height, value.Height));
708 OnMinimumSizeChanged(EventArgs.Empty);
709 if (IsHandleCreated) {
710 XplatUI.SetWindowMinMax(Handle, maximized_bounds, minimum_size, maximum_size);
717 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
725 [TypeConverter(typeof(OpacityConverter))]
726 [MWFCategory("Window Style")]
727 public double Opacity {
729 if (IsHandleCreated) {
730 if ((XplatUI.SupportsTransparency () & TransparencySupport.Get) != 0)
731 return XplatUI.GetWindowTransparency (Handle);
740 AllowTransparency = true;
742 if (IsHandleCreated) {
744 if ((XplatUI.SupportsTransparency () & TransparencySupport.Set) != 0)
745 XplatUI.SetWindowTransparency(Handle, opacity, TransparencyKey);
752 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
753 public Form[] OwnedForms {
757 form_list = new Form[owned_forms.Count];
759 for (int i=0; i<owned_forms.Count; i++) {
760 form_list[i] = (Form)owned_forms[i];
768 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
775 if (owner != value) {
777 owner.RemoveOwnedForm(this);
781 owner.AddOwnedForm(this);
782 if (IsHandleCreated) {
783 if (owner != null && owner.IsHandleCreated) {
784 XplatUI.SetTopmost(this.window.Handle, owner.window.Handle, true);
786 XplatUI.SetTopmost(this.window.Handle, IntPtr.Zero, false);
794 [MWFCategory("Window Style")]
795 public bool ShowInTaskbar {
797 return show_in_taskbar;
800 if (show_in_taskbar != value) {
801 show_in_taskbar = value;
802 if (IsHandleCreated) {
810 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
822 [MonoTODO("Trigger something when GripStyle is set")]
823 [DefaultValue(SizeGripStyle.Auto)]
824 [MWFCategory("Window Style")]
825 public SizeGripStyle SizeGripStyle {
827 return size_grip_style;
831 size_grip_style = value;
835 [DefaultValue(FormStartPosition.WindowsDefaultLocation)]
837 [MWFCategory("Layout")]
838 public FormStartPosition StartPosition {
840 return start_position;
844 if (start_position == FormStartPosition.WindowsDefaultLocation) { // Only do this if it's not set yet
845 start_position = value;
846 if (IsHandleCreated) {
847 switch(start_position) {
848 case FormStartPosition.CenterParent: {
853 case FormStartPosition.CenterScreen: {
858 case FormStartPosition.Manual: {
859 Left = CreateParams.X;
860 Top = CreateParams.Y;
874 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
875 [EditorBrowsable(EditorBrowsableState.Never)]
876 public int TabIndex {
878 return base.TabIndex;
882 base.TabIndex = value;
887 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
888 [EditorBrowsable(EditorBrowsableState.Advanced)]
889 public bool TopLevel {
891 return GetTopLevel();
895 if (!value && IsMdiContainer)
896 throw new ArgumentException ("MDI Container forms must be top level.");
901 [DefaultValue(false)]
902 [MWFCategory("Window Style")]
903 public bool TopMost {
909 if (topmost != value) {
912 XplatUI.SetTopmost(window.Handle, owner != null ? owner.window.Handle : IntPtr.Zero, value);
917 [MWFCategory("Window Style")]
918 public Color TransparencyKey {
920 return transparency_key;
924 transparency_key = value;
926 AllowTransparency = true;
928 if ((XplatUI.SupportsTransparency () & TransparencySupport.Set) != 0)
929 XplatUI.SetWindowTransparency(Handle, Opacity, transparency_key);
933 [DefaultValue(FormWindowState.Normal)]
934 [MWFCategory("Layout")]
935 public FormWindowState WindowState {
937 if (IsHandleCreated) {
939 if (window_manager != null)
940 return window_manager.GetWindowState ();
942 FormWindowState new_state = XplatUI.GetWindowState(Handle);
943 if (new_state != (FormWindowState)(-1))
944 window_state = new_state;
951 FormWindowState old_state = window_state;
952 window_state = value;
953 if (IsHandleCreated) {
955 if (window_manager != null) {
956 window_manager.SetWindowState (old_state, value);
960 XplatUI.SetWindowState(Handle, value);
965 #endregion // Public Instance Properties
967 #region Protected Instance Properties
968 protected override CreateParams CreateParams {
970 CreateParams cp = new CreateParams ();
973 cp.ClassName = XplatUI.DefaultClassName;
978 cp.Parent = IntPtr.Zero;
979 cp.menu = ActiveMenu;
981 if (start_position == FormStartPosition.WindowsDefaultLocation && !IsMdiChild) {
982 cp.X = unchecked((int)0x80000000);
983 cp.Y = unchecked((int)0x80000000);
991 cp.Style = (int)(WindowStyles.WS_CLIPCHILDREN | WindowStyles.WS_CLIPSIBLINGS);
994 cp.Style |= (int)(WindowStyles.WS_CHILD | WindowStyles.WS_CAPTION);
995 if (Parent != null) {
996 cp.Parent = Parent.Handle;
999 cp.ExStyle |= (int) (WindowExStyles.WS_EX_WINDOWEDGE | WindowExStyles.WS_EX_MDICHILD);
1001 switch (FormBorderStyle) {
1002 case FormBorderStyle.None:
1004 case FormBorderStyle.FixedToolWindow:
1005 case FormBorderStyle.SizableToolWindow:
1006 cp.ExStyle |= (int) WindowExStyles.WS_EX_TOOLWINDOW;
1009 cp.Style |= (int) WindowStyles.WS_OVERLAPPEDWINDOW;
1014 switch (FormBorderStyle) {
1015 case FormBorderStyle.Fixed3D: {
1016 cp.Style |= (int)(WindowStyles.WS_CAPTION | WindowStyles.WS_BORDER);
1017 cp.ExStyle |= (int)WindowExStyles.WS_EX_CLIENTEDGE;
1021 case FormBorderStyle.FixedDialog: {
1022 cp.Style |= (int)(WindowStyles.WS_CAPTION | WindowStyles.WS_BORDER);
1023 cp.ExStyle |= (int)(WindowExStyles.WS_EX_DLGMODALFRAME | WindowExStyles.WS_EX_CONTROLPARENT);
1027 case FormBorderStyle.FixedSingle: {
1028 cp.Style |= (int)(WindowStyles.WS_CAPTION | WindowStyles.WS_BORDER);
1032 case FormBorderStyle.FixedToolWindow: {
1033 cp.Style |= (int)(WindowStyles.WS_CAPTION | WindowStyles.WS_BORDER);
1034 cp.ExStyle |= (int)(WindowExStyles.WS_EX_TOOLWINDOW);
1038 case FormBorderStyle.Sizable: {
1039 cp.Style |= (int)(WindowStyles.WS_BORDER | WindowStyles.WS_THICKFRAME | WindowStyles.WS_CAPTION);
1043 case FormBorderStyle.SizableToolWindow: {
1044 cp.Style |= (int)(WindowStyles.WS_BORDER | WindowStyles.WS_THICKFRAME | WindowStyles.WS_CAPTION);
1045 cp.ExStyle |= (int)(WindowExStyles.WS_EX_TOOLWINDOW);
1049 case FormBorderStyle.None: {
1055 switch(window_state) {
1056 case FormWindowState.Maximized: {
1057 cp.Style |= (int)WindowStyles.WS_MAXIMIZE;
1061 case FormWindowState.Minimized: {
1062 cp.Style |= (int)WindowStyles.WS_MINIMIZE;
1068 cp.ExStyle |= (int) WindowExStyles.WS_EX_TOPMOST;
1071 if (ShowInTaskbar) {
1072 cp.ExStyle |= (int)WindowExStyles.WS_EX_APPWINDOW;
1076 cp.Style |= (int)WindowStyles.WS_MAXIMIZEBOX;
1080 cp.Style |= (int)WindowStyles.WS_MINIMIZEBOX;
1084 cp.Style |= (int)WindowStyles.WS_SYSMENU;
1087 if (HelpButton && !MaximizeBox && !MinimizeBox) {
1088 cp.ExStyle |= (int)WindowExStyles.WS_EX_CONTEXTHELP;
1092 cp.Style |= (int)WindowStyles.WS_VISIBLE;
1094 if (Opacity < 1.0 || TransparencyKey != Color.Empty) {
1095 cp.ExStyle |= (int)WindowExStyles.WS_EX_LAYERED;
1098 if (!is_enabled && context == null) {
1099 cp.Style |= (int)(WindowStyles.WS_DISABLED);
1106 protected override ImeMode DefaultImeMode {
1108 return ImeMode.NoControl;
1112 protected override Size DefaultSize {
1114 return new Size (300, 300);
1118 protected Rectangle MaximizedBounds {
1120 if (maximized_bounds != Rectangle.Empty) {
1121 return maximized_bounds;
1123 return default_maximized_bounds;
1127 maximized_bounds = value;
1128 OnMaximizedBoundsChanged(EventArgs.Empty);
1129 if (IsHandleCreated) {
1130 XplatUI.SetWindowMinMax(Handle, maximized_bounds, minimum_size, maximum_size);
1134 #endregion // Protected Instance Properties
1136 #region Public Static Methods
1137 [EditorBrowsable(EditorBrowsableState.Advanced)]
1138 public static SizeF GetAutoScaleSize (Font font)
1140 return XplatUI.GetAutoScaleSize(font);
1143 #endregion // Public Static Methods
1145 #region Public Instance Methods
1146 internal SizeF GetAutoScaleSize (Graphics g, Font font)
1149 // The following constants come from the dotnet mailing list
1150 // discussion: http://discuss.develop.com/archives/wa.exe?A2=ind0203A&L=DOTNET&P=R3655
1152 // The magic number is "Its almost the length
1153 // of the string with a smattering added in
1154 // for compat with earlier code".
1157 string magic_string = "The quick brown fox jumped over the lazy dog.";
1158 double magic_number = 44.549996948242189;
1159 float width = (float) (g.MeasureString (magic_string, font).Width / magic_number);
1161 return new SizeF (width, font.Height);
1164 public void Activate() {
1167 // The docs say activate only activates if our app is already active
1168 if (IsHandleCreated) {
1170 MdiParent.ActivateMdiChild (this);
1172 active = ActiveForm;
1173 if ((active != null) && (this != active)) {
1174 XplatUI.Activate(window.Handle);
1180 public void AddOwnedForm(Form ownedForm) {
1181 if (!owned_forms.Contains(ownedForm)) {
1182 owned_forms.Add(ownedForm);
1184 ownedForm.Owner = this;
1187 public void Close () {
1195 FormClosingEventArgs ce = new FormClosingEventArgs (CloseReason.FormOwnerClosing, false);
1200 XplatUI.SendMessage(this.Handle, Msg.WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
1203 public void LayoutMdi(MdiLayout value) {
1204 if (mdi_container != null) {
1205 mdi_container.LayoutMdi(value);
1209 public void RemoveOwnedForm(Form ownedForm) {
1210 owned_forms.Remove(ownedForm);
1213 public void SetDesktopBounds(int x, int y, int width, int height) {
1214 DesktopBounds = new Rectangle(x, y, width, height);
1217 public void SetDesktopLocation(int x, int y) {
1218 DesktopLocation = new Point(x, y);
1221 public DialogResult ShowDialog() {
1222 return ShowDialog(this.owner);
1225 public DialogResult ShowDialog(IWin32Window ownerWin32) {
1228 IntPtr capture_window;
1232 if (ownerWin32 != null) {
1233 Control c = Control.FromHandle (ownerWin32.Handle);
1235 owner = c.TopLevelControl as Form;
1238 if (owner == this) {
1239 throw new InvalidOperationException("The 'ownerWin32' cannot be the form being shown.");
1243 throw new InvalidOperationException("The form is already displayed as a modal dialog.");
1247 throw new InvalidOperationException("Already visible forms cannot be displayed as a modal dialog. Set the Visible property to 'false' prior to calling Form.ShowDialog.");
1251 throw new InvalidOperationException("Cannot display a disabled form as modal dialog.");
1254 if (TopLevelControl != this) {
1255 throw new InvalidOperationException("Can only display TopLevel forms as modal dialog.");
1259 // Can't do this, will screw us in the modal loop
1260 form_parent_window.Parent = this.owner;
1263 // Release any captures
1264 XplatUI.GrabInfo(out capture_window, out confined, out area);
1265 if (capture_window != IntPtr.Zero) {
1266 XplatUI.UngrabWindow(capture_window);
1270 // Commented out; we instead let the Visible=true inside the runloop create the control
1271 // otherwise setting DialogResult inside any of the events that are triggered by the
1272 // create will not actually cause the form to not be displayed.
1273 // Leaving this comment here in case there was an actual purpose to creating the control
1275 if (!IsHandleCreated) {
1280 Application.RunLoop(true, new ApplicationContext(this));
1282 if (owner != null) {
1283 // Cannot use Activate(), it has a check for the current active window...
1284 XplatUI.Activate(owner.window.Handle);
1287 if (DialogResult != DialogResult.None) {
1288 return DialogResult;
1290 DialogResult = DialogResult.Cancel;
1291 return DialogResult.Cancel;
1294 public override string ToString() {
1295 return GetType().FullName.ToString() + ", Text: " + Text;
1297 #endregion // Public Instance Methods
1299 #region Protected Instance Methods
1300 protected void ActivateMdiChild(Form form) {
1301 if (!IsMdiContainer)
1303 mdi_container.ActivateChild (form);
1304 OnMdiChildActivate(EventArgs.Empty);
1307 [EditorBrowsable(EditorBrowsableState.Advanced)]
1308 protected override void AdjustFormScrollbars(bool displayScrollbars) {
1309 base.AdjustFormScrollbars (displayScrollbars);
1312 [EditorBrowsable(EditorBrowsableState.Advanced)]
1313 protected void ApplyAutoScaling()
1315 SizeF current_size_f = GetAutoScaleSize (DeviceContext, Font);
1316 Size current_size = new Size ((int) current_size_f.Width, (int) current_size_f.Height);
1320 if (current_size == autoscale_base_size)
1323 if (Environment.GetEnvironmentVariable ("MONO_MWF_SCALING") == "disable"){
1328 // I tried applying the Fudge height factor from:
1329 // http://blogs.msdn.com/mharsh/archive/2004/01/25/62621.aspx
1330 // but it makes things larger without looking better.
1332 if (current_size_f.Width != AutoScaleBaseSize.Width) {
1333 dx = current_size_f.Width / AutoScaleBaseSize.Width + 0.08f;
1338 if (current_size_f.Height != AutoScaleBaseSize.Height) {
1339 dy = current_size_f.Height / AutoScaleBaseSize.Height + 0.08f;
1346 AutoScaleBaseSize = current_size;
1349 protected void CenterToParent() {
1357 w = DefaultSize.Width;
1363 h = DefaultSize.Height;
1367 if (parent != null) {
1369 } else if (owner != null) {
1373 if (owner != null) {
1374 this.Location = new Point(ctl.Left + ctl.Width / 2 - w /2, ctl.Top + ctl.Height / 2 - h / 2);
1378 protected void CenterToScreen() {
1386 w = DefaultSize.Width;
1392 h = DefaultSize.Height;
1395 XplatUI.GetDisplaySize(out DisplaySize);
1396 this.Location = new Point(DisplaySize.Width / 2 - w / 2, DisplaySize.Height / 2 - h / 2);
1399 [EditorBrowsable(EditorBrowsableState.Advanced)]
1400 protected override Control.ControlCollection CreateControlsInstance() {
1401 return base.CreateControlsInstance ();
1404 [EditorBrowsable(EditorBrowsableState.Advanced)]
1405 protected override void CreateHandle() {
1406 base.CreateHandle ();
1410 if ((XplatUI.SupportsTransparency() & TransparencySupport.Set) != 0) {
1411 if (allow_transparency) {
1412 XplatUI.SetWindowTransparency(Handle, Opacity, TransparencyKey);
1416 XplatUI.SetWindowMinMax(window.Handle, maximized_bounds, minimum_size, maximum_size);
1417 if ((FormBorderStyle != FormBorderStyle.FixedDialog) && (icon != null)) {
1418 XplatUI.SetIcon(window.Handle, icon);
1421 if ((owner != null) && (owner.IsHandleCreated)) {
1422 XplatUI.SetTopmost(window.Handle, owner.window.Handle, true);
1425 for (int i = 0; i < owned_forms.Count; i++) {
1426 if (owned_forms[i].IsHandleCreated)
1427 XplatUI.SetTopmost(owned_forms[i].window.Handle, window.Handle, true);
1430 if (window_manager != null && window_state != FormWindowState.Normal) {
1431 window_manager.SetWindowState (FormWindowState.Normal, window_state);
1436 [EditorBrowsable(EditorBrowsableState.Advanced)]
1437 protected override void DefWndProc(ref Message m) {
1438 base.DefWndProc (ref m);
1441 protected override void Dispose(bool disposing)
1443 for (int i = 0; i < owned_forms.Count; i++)
1444 ((Form)owned_forms[i]).Owner = null;
1446 owned_forms.Clear ();
1448 base.Dispose (disposing);
1451 [EditorBrowsable(EditorBrowsableState.Advanced)]
1452 protected virtual void OnActivated(EventArgs e)
1455 SelectActiveControl ();
1457 if (Activated != null) {
1462 [EditorBrowsable(EditorBrowsableState.Advanced)]
1463 protected virtual void OnClosed(EventArgs e) {
1464 if (Closed != null) {
1469 [EditorBrowsable(EditorBrowsableState.Advanced)]
1470 protected virtual void OnClosing(System.ComponentModel.CancelEventArgs e) {
1471 if (Closing != null) {
1476 [EditorBrowsable(EditorBrowsableState.Advanced)]
1477 protected override void OnCreateControl() {
1478 base.OnCreateControl ();
1481 XplatUI.SetMenu(window.Handle, menu);
1484 OnLoad(EventArgs.Empty);
1486 SelectActiveControl ();
1488 // Send initial location
1489 OnLocationChanged(EventArgs.Empty);
1491 if (IsMdiContainer) {
1492 mdi_container.LayoutMdi (MdiLayout.Cascade);
1496 [EditorBrowsable(EditorBrowsableState.Advanced)]
1497 protected virtual void OnDeactivate(EventArgs e) {
1498 if (Deactivate != null) {
1499 Deactivate(this, e);
1503 [EditorBrowsable(EditorBrowsableState.Advanced)]
1504 protected override void OnFontChanged(EventArgs e) {
1505 base.OnFontChanged (e);
1508 [EditorBrowsable(EditorBrowsableState.Advanced)]
1509 protected override void OnHandleCreated(EventArgs e) {
1510 XplatUI.SetBorderStyle(window.Handle, form_border_style);
1511 base.OnHandleCreated (e);
1514 [EditorBrowsable(EditorBrowsableState.Advanced)]
1515 protected override void OnHandleDestroyed(EventArgs e) {
1516 base.OnHandleDestroyed (e);
1519 [EditorBrowsable(EditorBrowsableState.Advanced)]
1520 protected virtual void OnInputLanguageChanged(InputLanguageChangedEventArgs e) {
1521 if (InputLanguageChanged!=null) {
1522 InputLanguageChanged(this, e);
1526 [EditorBrowsable(EditorBrowsableState.Advanced)]
1527 protected virtual void OnInputLanguageChanging(InputLanguageChangingEventArgs e) {
1528 if (InputLanguageChanging!=null) {
1529 InputLanguageChanging(this, e);
1533 [EditorBrowsable(EditorBrowsableState.Advanced)]
1534 protected virtual void OnLoad(EventArgs e) {
1536 ApplyAutoScaling ();
1545 switch (StartPosition) {
1546 case FormStartPosition.CenterScreen:
1547 this.CenterToScreen();
1549 case FormStartPosition.CenterParent:
1550 this.CenterToParent ();
1552 case FormStartPosition.Manual:
1553 Left = CreateParams.X;
1554 Top = CreateParams.Y;
1561 [EditorBrowsable(EditorBrowsableState.Advanced)]
1562 protected virtual void OnMaximizedBoundsChanged(EventArgs e) {
1563 if (MaximizedBoundsChanged != null) {
1564 MaximizedBoundsChanged(this, e);
1568 [EditorBrowsable(EditorBrowsableState.Advanced)]
1569 protected virtual void OnMaximumSizeChanged(EventArgs e) {
1570 if (MaximumSizeChanged != null) {
1571 MaximumSizeChanged(this, e);
1575 [EditorBrowsable(EditorBrowsableState.Advanced)]
1576 protected virtual void OnMdiChildActivate(EventArgs e) {
1577 if (MdiChildActivate != null) {
1578 MdiChildActivate(this, e);
1582 [EditorBrowsable(EditorBrowsableState.Advanced)]
1583 protected virtual void OnMenuComplete(EventArgs e) {
1584 if (MenuComplete != null) {
1585 MenuComplete(this, e);
1589 [EditorBrowsable(EditorBrowsableState.Advanced)]
1590 protected virtual void OnMenuStart(EventArgs e) {
1591 if (MenuStart != null) {
1596 [EditorBrowsable(EditorBrowsableState.Advanced)]
1597 protected virtual void OnMinimumSizeChanged(EventArgs e) {
1598 if (MinimumSizeChanged != null) {
1599 MinimumSizeChanged(this, e);
1603 [EditorBrowsable(EditorBrowsableState.Advanced)]
1604 protected override void OnPaint (PaintEventArgs pevent) {
1605 base.OnPaint (pevent);
1608 [EditorBrowsable(EditorBrowsableState.Advanced)]
1609 protected override void OnResize(EventArgs e) {
1612 if (this.IsMdiChild && ParentForm != null) {
1613 ParentForm.PerformLayout();
1614 ParentForm.Size = ParentForm.Size;
1618 [EditorBrowsable(EditorBrowsableState.Advanced)]
1619 protected override void OnStyleChanged(EventArgs e) {
1620 base.OnStyleChanged (e);
1623 [EditorBrowsable(EditorBrowsableState.Advanced)]
1624 protected override void OnTextChanged(EventArgs e) {
1625 base.OnTextChanged (e);
1627 if (mdi_container != null)
1628 mdi_container.SetParentText(true);
1631 [EditorBrowsable(EditorBrowsableState.Advanced)]
1632 protected override void OnVisibleChanged(EventArgs e) {
1633 base.OnVisibleChanged (e);
1636 if (window_manager != null)
1637 window_manager.SetWindowState (WindowState, WindowState);
1641 protected override bool ProcessCmdKey(ref Message msg, Keys keyData) {
1642 if (base.ProcessCmdKey (ref msg, keyData)) {
1646 // Give our menu a shot
1647 if (ActiveMenu != null) {
1648 return ActiveMenu.ProcessCmdKey(ref msg, keyData);
1654 // LAMESPEC - Not documented that Form overrides ProcessDialogChar; class-status showed
1655 [EditorBrowsable (EditorBrowsableState.Advanced)]
1656 protected override bool ProcessDialogChar(char charCode) {
1657 return base.ProcessDialogChar (charCode);
1660 protected override bool ProcessDialogKey(Keys keyData) {
1661 if ((keyData & Keys.Modifiers) == 0) {
1662 if (keyData == Keys.Enter) {
1663 IntPtr window = XplatUI.GetFocus ();
1664 Control c = Control.FromHandle (window);
1665 if (c is Button && c.FindForm () == this) {
1666 ((Button)c).PerformClick ();
1669 else if (accept_button != null) {
1670 accept_button.PerformClick();
1673 } else if (keyData == Keys.Escape && cancel_button != null) {
1674 cancel_button.PerformClick();
1678 return base.ProcessDialogKey(keyData);
1681 protected override bool ProcessKeyPreview(ref Message msg) {
1683 if (ProcessKeyEventArgs(ref msg)) {
1687 return base.ProcessKeyPreview (ref msg);
1690 protected override bool ProcessTabKey(bool forward) {
1691 return SelectNextControl(ActiveControl, forward, true, true, true);
1694 [EditorBrowsable(EditorBrowsableState.Advanced)]
1695 protected override void ScaleCore(float dx, float dy) {
1699 // We can't scale max or min windows
1700 if (WindowState == FormWindowState.Normal) {
1701 // We cannot call base since base also adjusts X/Y, but
1702 // a form is toplevel and doesn't move
1706 if (!GetStyle(ControlStyles.FixedWidth)) {
1707 size.Width = (int)(size.Width * dx);
1710 if (!GetStyle(ControlStyles.FixedHeight)) {
1711 size.Height = (int)(size.Height * dy);
1717 /* Now scale our children */
1718 Control [] controls = child_controls.GetAllControls ();
1719 for (int i=0; i < controls.Length; i++) {
1720 controls[i].Scale(dx, dy);
1729 protected override void Select(bool directed, bool forward) {
1733 base.SelectNextControl(null, forward, true, true, true);
1736 parent = this.ParentForm;
1737 if (parent != null) {
1738 parent.ActiveControl = this;
1744 [EditorBrowsable(EditorBrowsableState.Advanced)]
1745 protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
1746 base.SetBoundsCore (x, y, width, height, specified);
1749 [EditorBrowsable(EditorBrowsableState.Advanced)]
1750 protected override void SetClientSizeCore(int x, int y) {
1751 if ((minimum_size.Width != 0) && (x < minimum_size.Width)) {
1752 x = minimum_size.Width;
1753 } else if ((maximum_size.Width != 0) && (x > maximum_size.Width)) {
1754 x = maximum_size.Width;
1757 if ((minimum_size.Height != 0) && (y < minimum_size.Height)) {
1758 y = minimum_size.Height;
1759 } else if ((maximum_size.Height != 0) && (y > maximum_size.Height)) {
1760 y = maximum_size.Height;
1763 Rectangle ClientRect = new Rectangle(0, 0, x, y);
1764 Rectangle WindowRect;
1765 CreateParams cp = this.CreateParams;
1767 clientsize_set = new Size(x, y);
1769 if (XplatUI.CalculateWindowRect(ref ClientRect, cp.Style, cp.ExStyle, cp.menu, out WindowRect)) {
1770 SetBounds(bounds.X, bounds.Y, WindowRect.Width, WindowRect.Height, BoundsSpecified.Size);
1774 [EditorBrowsable(EditorBrowsableState.Advanced)]
1775 protected override void SetVisibleCore(bool value) {
1776 base.SetVisibleCore (value);
1779 protected override void UpdateDefaultButton() {
1780 base.UpdateDefaultButton ();
1783 [EditorBrowsable(EditorBrowsableState.Advanced)]
1784 protected override void WndProc(ref Message m) {
1786 if (window_manager != null && window_manager.HandleMessage (ref m)) {
1790 switch((Msg)m.Msg) {
1791 case Msg.WM_DESTROY: {
1792 base.WndProc(ref m);
1793 if (!is_recreating) {
1794 this.closing = true;
1799 case Msg.WM_CLOSE_INTERNAL: {
1804 case Msg.WM_CLOSE: {
1805 Form act = Form.ActiveForm;
1806 if (act != null && act != this && act.Modal == true) {
1810 CancelEventArgs args = new CancelEventArgs ();
1812 if (mdi_container != null) {
1813 foreach (Form mdi_child in mdi_container.MdiChildren) {
1814 mdi_child.OnClosing (args);
1821 OnClosed (EventArgs.Empty);
1828 DialogResult = DialogResult.None;
1831 OnClosed (EventArgs.Empty);
1840 case Msg.WM_WINDOWPOSCHANGED: {
1841 if (WindowState != FormWindowState.Minimized) {
1842 base.WndProc(ref m);
1848 case Msg.WM_SYSCOMMAND: {
1849 // Let *Strips know the app's title bar was clicked
1850 if (XplatUI.IsEnabled (Handle))
1851 ToolStripMenuTracker.FireAppClicked ();
1853 base.WndProc(ref m);
1858 case Msg.WM_ACTIVATE: {
1859 if (m.WParam != (IntPtr)WindowActiveFlags.WA_INACTIVE) {
1860 OnActivated(EventArgs.Empty);
1862 OnDeactivate(EventArgs.Empty);
1864 // Let *Strips know the app lost focus
1865 if (XplatUI.IsEnabled (Handle))
1866 ToolStripMenuTracker.FireAppFocusChanged ();
1872 case Msg.WM_KILLFOCUS: {
1873 base.WndProc(ref m);
1877 case Msg.WM_SETFOCUS: {
1878 if (ActiveControl != null && ActiveControl != this) {
1879 ActiveControl.Focus();
1880 return; // FIXME - do we need to run base.WndProc, even though we just changed focus?
1882 base.WndProc(ref m);
1887 case Msg.WM_NCLBUTTONDOWN: {
1888 if (XplatUI.IsEnabled (Handle) && ActiveMenu != null) {
1889 ActiveMenu.OnMouseDown(this, new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()), mouse_clicks, Control.MousePosition.X, Control.MousePosition.Y, 0));
1892 if (ActiveMaximizedMdiChild != null) {
1893 if (ActiveMaximizedMdiChild.HandleMenuMouseDown (ActiveMenu,
1894 LowOrder ((int) m.LParam.ToInt32 ()),
1895 HighOrder ((int) m.LParam.ToInt32 ()))) {
1896 // Don't let base process this message, otherwise we won't
1897 // get a WM_NCLBUTTONUP.
1901 base.WndProc(ref m);
1904 case Msg.WM_NCLBUTTONUP: {
1905 if (ActiveMaximizedMdiChild != null) {
1906 ActiveMaximizedMdiChild.HandleMenuMouseUp (ActiveMenu,
1907 LowOrder ((int)m.LParam.ToInt32 ()),
1908 HighOrder ((int)m.LParam.ToInt32 ()));
1910 base.WndProc (ref m);
1914 case Msg.WM_NCMOUSELEAVE: {
1915 if (ActiveMaximizedMdiChild != null) {
1916 ActiveMaximizedMdiChild.HandleMenuMouseLeave(ActiveMenu,
1917 LowOrder((int)m.LParam.ToInt32()),
1918 HighOrder((int)m.LParam.ToInt32()));
1920 base.WndProc(ref m);
1924 case Msg.WM_NCMOUSEMOVE: {
1925 if (XplatUI.IsEnabled (Handle) && ActiveMenu != null) {
1926 ActiveMenu.OnMouseMove(this, new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()), mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()), 0));
1929 if (ActiveMaximizedMdiChild != null) {
1930 ActiveMaximizedMdiChild.HandleMenuMouseMove (ActiveMenu,
1931 LowOrder ((int)m.LParam.ToInt32 ()),
1932 HighOrder ((int)m.LParam.ToInt32 ()));
1934 base.WndProc(ref m);
1938 case Msg.WM_NCPAINT: {
1939 if (ActiveMenu != null) {
1943 pe = XplatUI.PaintEventStart(Handle, false);
1944 pnt = XplatUI.GetMenuOrigin(window.Handle);
1946 // The entire menu has to be in the clip rectangle because the
1947 // control buttons are right-aligned and otherwise they would
1948 // stay painted when the window gets resized.
1949 Rectangle clip = new Rectangle (pnt.X, pnt.Y, ClientSize.Width, 0);
1950 clip = Rectangle.Union(clip, pe.ClipRectangle);
1952 pe.Graphics.SetClip(clip);
1954 ActiveMenu.Draw (pe, new Rectangle (pnt.X, pnt.Y, ClientSize.Width, 0));
1956 if (ActiveMaximizedMdiChild != null) {
1957 ActiveMaximizedMdiChild.DrawMaximizedButtons (ActiveMenu, pe);
1960 XplatUI.PaintEventEnd(Handle, false);
1963 base.WndProc(ref m);
1967 case Msg.WM_NCCALCSIZE: {
1968 XplatUIWin32.NCCALCSIZE_PARAMS ncp;
1970 if ((ActiveMenu != null) && (m.WParam == (IntPtr)1)) {
1971 ncp = (XplatUIWin32.NCCALCSIZE_PARAMS)Marshal.PtrToStructure(m.LParam, typeof(XplatUIWin32.NCCALCSIZE_PARAMS));
1974 ncp.rgrc1.top += ThemeEngine.Current.CalcMenuBarSize (DeviceContext, ActiveMenu, ncp.rgrc1.right - ncp.rgrc1.left);
1975 Marshal.StructureToPtr(ncp, m.LParam, true);
1981 case Msg.WM_MOUSEMOVE: {
1982 if (XplatUI.IsEnabled (Handle) && active_tracker != null) {
1983 MouseEventArgs args;
1985 args = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
1986 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()), 0);
1987 active_tracker.OnMotion(new MouseEventArgs (args.Button, args.Clicks, Control.MousePosition.X, Control.MousePosition.Y, args.Delta));
1990 base.WndProc(ref m);
1994 case Msg.WM_LBUTTONDOWN:
1995 case Msg.WM_MBUTTONDOWN:
1996 case Msg.WM_RBUTTONDOWN: {
1997 if (XplatUI.IsEnabled (Handle) && active_tracker != null) {
1998 MouseEventArgs args;
2000 args = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
2001 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()), 0);
2002 active_tracker.OnMouseDown(new MouseEventArgs (args.Button, args.Clicks, Control.MousePosition.X, Control.MousePosition.Y, args.Delta));
2005 base.WndProc(ref m);
2009 case Msg.WM_LBUTTONUP:
2010 case Msg.WM_MBUTTONUP:
2011 case Msg.WM_RBUTTONUP: {
2012 if (XplatUI.IsEnabled (Handle) && active_tracker != null) {
2013 MouseEventArgs args;
2014 MouseButtons mb = FromParamToMouseButtons ((int) m.WParam.ToInt32());
2016 // We add in the button that was released (not sent in WParam)
2017 switch((Msg)m.Msg) {
2018 case Msg.WM_LBUTTONUP:
2019 mb |= MouseButtons.Left;
2021 case Msg.WM_MBUTTONUP:
2022 mb |= MouseButtons.Middle;
2024 case Msg.WM_RBUTTONUP:
2025 mb |= MouseButtons.Right;
2029 args = new MouseEventArgs (mb, mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()), 0);
2030 active_tracker.OnMouseUp(new MouseEventArgs (args.Button, args.Clicks, Control.MousePosition.X, Control.MousePosition.Y, args.Delta));
2034 base.WndProc(ref m);
2038 case Msg.WM_GETMINMAXINFO: {
2041 if (m.LParam != IntPtr.Zero) {
2042 mmi = (MINMAXINFO)Marshal.PtrToStructure(m.LParam, typeof(MINMAXINFO));
2044 default_maximized_bounds = new Rectangle(mmi.ptMaxPosition.x, mmi.ptMaxPosition.y, mmi.ptMaxSize.x, mmi.ptMaxSize.y);
2045 if (maximized_bounds != Rectangle.Empty) {
2046 mmi.ptMaxPosition.x = maximized_bounds.Left;
2047 mmi.ptMaxPosition.y = maximized_bounds.Top;
2048 mmi.ptMaxSize.x = maximized_bounds.Width;
2049 mmi.ptMaxSize.y = maximized_bounds.Height;
2052 if (minimum_size != Size.Empty) {
2053 mmi.ptMinTrackSize.x = minimum_size.Width;
2054 mmi.ptMinTrackSize.y = minimum_size.Height;
2057 if (maximum_size != Size.Empty) {
2058 mmi.ptMaxTrackSize.x = maximum_size.Width;
2059 mmi.ptMaxTrackSize.y = maximum_size.Height;
2061 Marshal.StructureToPtr(mmi, m.LParam, false);
2067 case Msg.WM_MOUSEACTIVATE: {
2068 // Let *Strips know the form or another control has been clicked
2069 if (XplatUI.IsEnabled (Handle))
2070 ToolStripMenuTracker.FireAppClicked ();
2072 base.WndProc (ref m);
2078 base.WndProc (ref m);
2083 #endregion // Protected Instance Methods
2085 internal void RemoveWindowManager ()
2087 window_manager = null;
2090 internal override void CheckAcceptButton()
2092 if (accept_button != null) {
2093 Button a_button = accept_button as Button;
2095 if (ActiveControl == a_button)
2098 if (ActiveControl is Button) {
2099 a_button.paint_as_acceptbutton = false;
2103 a_button.paint_as_acceptbutton = true;
2110 public event EventHandler Activated;
2111 public event EventHandler Closed;
2112 public event CancelEventHandler Closing;
2113 public event EventHandler Deactivate;
2114 public event InputLanguageChangedEventHandler InputLanguageChanged;
2115 public event InputLanguageChangingEventHandler InputLanguageChanging;
2116 public event EventHandler Load;
2117 public event EventHandler MaximizedBoundsChanged;
2118 public event EventHandler MaximumSizeChanged;
2119 public event EventHandler MdiChildActivate;
2120 public event EventHandler MenuComplete;
2121 public event EventHandler MenuStart;
2122 public event EventHandler MinimumSizeChanged;
2125 [EditorBrowsable(EditorBrowsableState.Never)]
2126 public new event EventHandler TabIndexChanged {
2127 add { base.TabIndexChanged += value; }
2128 remove { base.TabIndexChanged -= value; }
2130 #endregion // Events
2133 public override string Text {
2143 public new Point Location {
2145 return base.Location;
2149 base.Location = value;
2153 public event FormClosingEventHandler FormClosing;
2154 public event FormClosedEventHandler FormClosed;
2156 protected virtual void OnFormClosing (FormClosingEventArgs e)
2158 if (FormClosing != null)
2159 FormClosing (this, e);