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;
175 size_grip_style = SizeGripStyle.Auto;
176 maximized_bounds = Rectangle.Empty;
177 default_maximized_bounds = Rectangle.Empty;
178 owned_forms = new Form.ControlCollection(this);
179 transparency_key = Color.Empty;
181 // FIXME: this should disappear just as soon as the handle creation is done in the right place (here is too soon()
185 #endregion // Public Constructor & Destructor
187 #region Public Static Properties
189 public static Form ActiveForm {
193 active = FromHandle(XplatUI.GetActive());
195 if (active != null) {
196 if ( !(active is Form)) {
199 parent = active.Parent;
200 while (parent != null) {
201 if (parent is Form) {
204 parent = parent.Parent;
214 #endregion // Public Static Properties
216 #region Public Instance Properties
218 public IButtonControl AcceptButton {
220 return accept_button;
224 accept_button = value;
230 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
231 public bool AllowTransparency {
233 return allow_transparency;
237 if (value == allow_transparency) {
241 allow_transparency = value;
244 if (IsHandleCreated) {
245 if ((XplatUI.SupportsTransparency() & TransparencySupport.Set) != 0) {
246 XplatUI.SetWindowTransparency(Handle, Opacity, TransparencyKey);
249 UpdateStyles(); // Remove the WS_EX_LAYERED style
259 [MWFCategory("Layout")]
260 public bool AutoScale {
272 [EditorBrowsable(EditorBrowsableState.Advanced)]
273 public virtual Size AutoScaleBaseSize {
275 return autoscale_base_size;
279 autoscale_base_size = value;
284 public override bool AutoScroll {
286 return base.AutoScroll;
289 base.AutoScroll = value;
293 public override Color BackColor {
295 /* we don't let parents override our
296 default background color for forms.
297 this fixes the default color for mdi
299 if (background_color.IsEmpty)
300 return DefaultBackColor;
302 return background_color;
305 base.BackColor = value;
310 public IButtonControl CancelButton {
312 return cancel_button;
316 cancel_button = value;
317 if (cancel_button.DialogResult == DialogResult.None)
318 cancel_button.DialogResult = DialogResult.Cancel;
322 // new property so we can change the DesignerSerializationVisibility
323 [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
325 public new Size ClientSize {
326 get { return base.ClientSize; }
327 set { base.ClientSize = value; }
331 [MWFCategory("Window Style")]
332 public bool ControlBox {
338 if (control_box != value) {
346 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
347 public Rectangle DesktopBounds {
349 return new Rectangle(Location, Size);
358 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
359 public Point DesktopLocation {
370 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
371 public DialogResult DialogResult {
373 return dialog_result;
377 if (value < DialogResult.None || value > DialogResult.No)
378 throw new InvalidEnumArgumentException ("value", (int) value,
379 typeof (DialogResult));
381 dialog_result = value;
382 closing = (dialog_result != DialogResult.None && is_modal);
386 [DefaultValue(FormBorderStyle.Sizable)]
388 [MWFCategory("Appearance")]
389 public FormBorderStyle FormBorderStyle {
391 return form_border_style;
394 form_border_style = value;
396 if (window_manager == null) {
397 if (IsHandleCreated) {
398 XplatUI.SetBorderStyle(window.Handle, form_border_style);
401 window_manager.UpdateBorderStyle (value);
408 [DefaultValue(false)]
409 [MWFCategory("Window Style")]
410 public bool HelpButton {
416 if (help_button != value) {
425 [MWFCategory("Window Style")]
435 if (IsHandleCreated) {
436 XplatUI.SetIcon(Handle, icon == null ? default_icon : icon);
443 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
444 public bool IsMdiChild {
446 return mdi_parent != null;
450 [DefaultValue(false)]
451 [MWFCategory("Window Style")]
452 public bool IsMdiContainer {
454 return mdi_container != null;
458 if (value && mdi_container == null) {
459 mdi_container = new MdiClient ();
460 Controls.Add(mdi_container);
461 ControlAdded += new ControlEventHandler (ControlAddedHandler);
462 mdi_container.SendToBack ();
463 mdi_container.SetParentText (true);
464 } else if (!value && mdi_container != null) {
465 Controls.Remove(mdi_container);
466 mdi_container = null;
472 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
473 public Form ActiveMdiChild {
477 return (Form) mdi_container.ActiveMdiChild;
482 [EditorBrowsable(EditorBrowsableState.Advanced)]
483 public bool IsRestrictedWindow {
489 [DefaultValue(false)]
490 public bool KeyPreview {
501 [MWFCategory("Window Style")]
502 public bool MaximizeBox {
507 if (maximize_box != value) {
508 maximize_box = value;
509 if (IsHandleCreated) {
517 [DefaultValue("{Width=0, Height=0}")]
519 [RefreshProperties(RefreshProperties.Repaint)]
520 [MWFCategory("Layout")]
531 if (maximum_size != value) {
532 maximum_size = value;
533 OnMaximumSizeChanged(EventArgs.Empty);
534 if (IsHandleCreated) {
535 XplatUI.SetWindowMinMax(Handle, maximized_bounds, minimum_size, maximum_size);
542 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
543 public Form[] MdiChildren {
545 if (mdi_container != null)
546 return mdi_container.MdiChildren;
553 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
554 public Form MdiParent {
560 if (value != null && !value.IsMdiContainer)
561 throw new ArgumentException ();
563 if (mdi_parent != null) {
564 mdi_parent.MdiContainer.Controls.Remove (this);
569 window_manager = new MdiWindowManager (this,
570 mdi_parent.MdiContainer);
571 mdi_parent.MdiContainer.Controls.Add (this);
572 mdi_parent.MdiContainer.Controls.SetChildIndex (this, 0);
576 } else if (mdi_parent != null) {
579 // Create a new window manager
580 window_manager = null;
581 FormBorderStyle = form_border_style;
588 internal MenuTracker ActiveTracker {
589 get { return active_tracker; }
591 if (value == active_tracker)
594 Capture = value != null;
595 active_tracker = value;
599 internal MdiClient MdiContainer {
600 get { return mdi_container; }
603 internal InternalWindowManager WindowManager {
604 get { return window_manager; }
608 [MWFCategory("Window Style")]
609 public MainMenu Menu {
618 if (menu != null && !IsMdiChild) {
621 if (IsHandleCreated) {
622 XplatUI.SetMenu (window.Handle, menu);
625 if (clientsize_set != Size.Empty) {
626 SetClientSizeCore(clientsize_set.Width, clientsize_set.Height);
628 UpdateBounds (bounds.X, bounds.Y, bounds.Width, bounds.Height, ClientSize.Width, ClientSize.Height -
629 ThemeEngine.Current.CalcMenuBarSize (DeviceContext, menu, ClientSize.Width));
638 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
639 [EditorBrowsable(EditorBrowsableState.Advanced)]
640 public MainMenu MergedMenu {
642 if (!IsMdiChild || window_manager == null)
644 return ((MdiWindowManager) window_manager).MergedMenu;
648 // This is the menu in display and being used because of merging this can
649 // be different then the menu that is actually assosciated with the form
650 internal MainMenu ActiveMenu {
655 if (IsMdiContainer && mdi_container.Controls.Count > 0 &&
656 ((Form) mdi_container.Controls [0]).WindowState == FormWindowState.Maximized) {
657 MdiWindowManager wm = (MdiWindowManager) ((Form) mdi_container.Controls [0]).WindowManager;
658 return wm.MaximizedMenu;
661 Form amc = ActiveMdiChild;
662 if (amc == null || amc.Menu == null)
664 return amc.MergedMenu;
668 internal MdiWindowManager ActiveMaximizedMdiChild {
670 Form child = ActiveMdiChild;
673 if (child.WindowManager == null || child.window_state != FormWindowState.Maximized)
675 return (MdiWindowManager) child.WindowManager;
680 [MWFCategory("Window Style")]
681 public bool MinimizeBox {
686 if (minimize_box != value) {
687 minimize_box = value;
688 if (IsHandleCreated) {
697 [DefaultValue("{Width=0, Height=0}")]
700 [RefreshProperties(RefreshProperties.Repaint)]
701 [MWFCategory("Layout")]
712 if (minimum_size != value) {
713 minimum_size = value;
715 if ((Size.Width < value.Width) || (Size.Height < value.Height)) {
716 Size = new Size(Math.Max(Size.Width, value.Width), Math.Max(Size.Height, value.Height));
720 OnMinimumSizeChanged(EventArgs.Empty);
721 if (IsHandleCreated) {
722 XplatUI.SetWindowMinMax(Handle, maximized_bounds, minimum_size, maximum_size);
729 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
737 [TypeConverter(typeof(OpacityConverter))]
738 [MWFCategory("Window Style")]
739 public double Opacity {
741 if (IsHandleCreated) {
742 if ((XplatUI.SupportsTransparency () & TransparencySupport.Get) != 0)
743 return XplatUI.GetWindowTransparency (Handle);
752 AllowTransparency = true;
754 if (IsHandleCreated) {
756 if ((XplatUI.SupportsTransparency () & TransparencySupport.Set) != 0)
757 XplatUI.SetWindowTransparency(Handle, opacity, TransparencyKey);
764 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
765 public Form[] OwnedForms {
769 form_list = new Form[owned_forms.Count];
771 for (int i=0; i<owned_forms.Count; i++) {
772 form_list[i] = (Form)owned_forms[i];
780 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
787 if (owner != value) {
789 owner.RemoveOwnedForm(this);
793 owner.AddOwnedForm(this);
794 if (IsHandleCreated) {
795 if (owner != null && owner.IsHandleCreated) {
796 XplatUI.SetTopmost(this.window.Handle, owner.window.Handle, true);
798 XplatUI.SetTopmost(this.window.Handle, IntPtr.Zero, false);
806 [MWFCategory("Window Style")]
807 public bool ShowInTaskbar {
809 return show_in_taskbar;
812 if (show_in_taskbar != value) {
813 show_in_taskbar = value;
814 if (IsHandleCreated) {
822 // new property so we can set the DesignerSerializationVisibility
823 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
825 public new Size Size {
826 get { return base.Size; }
827 set { base.Size = value; }
830 [MonoTODO("Trigger something when GripStyle is set")]
831 [DefaultValue(SizeGripStyle.Auto)]
832 [MWFCategory("Window Style")]
833 public SizeGripStyle SizeGripStyle {
835 return size_grip_style;
839 size_grip_style = value;
843 [DefaultValue(FormStartPosition.WindowsDefaultLocation)]
845 [MWFCategory("Layout")]
846 public FormStartPosition StartPosition {
848 return start_position;
852 if (start_position == FormStartPosition.WindowsDefaultLocation) { // Only do this if it's not set yet
853 start_position = value;
854 if (IsHandleCreated) {
855 switch(start_position) {
856 case FormStartPosition.CenterParent: {
861 case FormStartPosition.CenterScreen: {
866 case FormStartPosition.Manual: {
867 Left = CreateParams.X;
868 Top = CreateParams.Y;
881 // new property so we can set EditorBrowsable to never
883 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
884 [EditorBrowsable(EditorBrowsableState.Never)]
885 public new int TabIndex {
886 get { return base.TabIndex; }
887 set { base.TabIndex = value; }
891 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
892 [EditorBrowsable(EditorBrowsableState.Advanced)]
893 public bool TopLevel {
895 return GetTopLevel();
899 if (!value && IsMdiContainer)
900 throw new ArgumentException ("MDI Container forms must be top level.");
905 [DefaultValue(false)]
906 [MWFCategory("Window Style")]
907 public bool TopMost {
913 if (topmost != value) {
916 XplatUI.SetTopmost(window.Handle, owner != null ? owner.window.Handle : IntPtr.Zero, value);
921 [MWFCategory("Window Style")]
922 public Color TransparencyKey {
924 return transparency_key;
928 transparency_key = value;
930 AllowTransparency = true;
932 if ((XplatUI.SupportsTransparency () & TransparencySupport.Set) != 0)
933 XplatUI.SetWindowTransparency(Handle, Opacity, transparency_key);
937 [DefaultValue(FormWindowState.Normal)]
938 [MWFCategory("Layout")]
939 public FormWindowState WindowState {
941 if (IsHandleCreated) {
943 if (window_manager != null)
944 return window_manager.GetWindowState ();
946 FormWindowState new_state = XplatUI.GetWindowState(Handle);
947 if (new_state != (FormWindowState)(-1))
948 window_state = new_state;
955 FormWindowState old_state = window_state;
956 window_state = value;
957 if (IsHandleCreated) {
959 if (window_manager != null) {
960 window_manager.SetWindowState (old_state, value);
964 XplatUI.SetWindowState(Handle, value);
969 #endregion // Public Instance Properties
971 #region Protected Instance Properties
972 protected override CreateParams CreateParams {
974 CreateParams cp = new CreateParams ();
977 cp.ClassName = XplatUI.DefaultClassName;
982 cp.Parent = IntPtr.Zero;
983 cp.menu = ActiveMenu;
985 if (start_position == FormStartPosition.WindowsDefaultLocation && !IsMdiChild) {
986 cp.X = unchecked((int)0x80000000);
987 cp.Y = unchecked((int)0x80000000);
995 cp.Style = (int)(WindowStyles.WS_CLIPCHILDREN | WindowStyles.WS_CLIPSIBLINGS);
998 cp.Style |= (int)(WindowStyles.WS_CHILD | WindowStyles.WS_CAPTION);
999 if (Parent != null) {
1000 cp.Parent = Parent.Handle;
1003 cp.ExStyle |= (int) (WindowExStyles.WS_EX_WINDOWEDGE | WindowExStyles.WS_EX_MDICHILD);
1005 switch (FormBorderStyle) {
1006 case FormBorderStyle.None:
1008 case FormBorderStyle.FixedToolWindow:
1009 case FormBorderStyle.SizableToolWindow:
1010 cp.ExStyle |= (int) WindowExStyles.WS_EX_TOOLWINDOW;
1013 cp.Style |= (int) WindowStyles.WS_OVERLAPPEDWINDOW;
1018 switch (FormBorderStyle) {
1019 case FormBorderStyle.Fixed3D: {
1020 cp.Style |= (int)(WindowStyles.WS_CAPTION | WindowStyles.WS_BORDER);
1021 cp.ExStyle |= (int)WindowExStyles.WS_EX_CLIENTEDGE;
1025 case FormBorderStyle.FixedDialog: {
1026 cp.Style |= (int)(WindowStyles.WS_CAPTION | WindowStyles.WS_BORDER);
1027 cp.ExStyle |= (int)(WindowExStyles.WS_EX_DLGMODALFRAME | WindowExStyles.WS_EX_CONTROLPARENT);
1031 case FormBorderStyle.FixedSingle: {
1032 cp.Style |= (int)(WindowStyles.WS_CAPTION | WindowStyles.WS_BORDER);
1036 case FormBorderStyle.FixedToolWindow: {
1037 cp.Style |= (int)(WindowStyles.WS_CAPTION | WindowStyles.WS_BORDER);
1038 cp.ExStyle |= (int)(WindowExStyles.WS_EX_TOOLWINDOW);
1042 case FormBorderStyle.Sizable: {
1043 cp.Style |= (int)(WindowStyles.WS_BORDER | WindowStyles.WS_THICKFRAME | WindowStyles.WS_CAPTION);
1047 case FormBorderStyle.SizableToolWindow: {
1048 cp.Style |= (int)(WindowStyles.WS_BORDER | WindowStyles.WS_THICKFRAME | WindowStyles.WS_CAPTION);
1049 cp.ExStyle |= (int)(WindowExStyles.WS_EX_TOOLWINDOW);
1053 case FormBorderStyle.None: {
1059 switch(window_state) {
1060 case FormWindowState.Maximized: {
1061 cp.Style |= (int)WindowStyles.WS_MAXIMIZE;
1065 case FormWindowState.Minimized: {
1066 cp.Style |= (int)WindowStyles.WS_MINIMIZE;
1072 cp.ExStyle |= (int) WindowExStyles.WS_EX_TOPMOST;
1075 if (ShowInTaskbar) {
1076 cp.ExStyle |= (int)WindowExStyles.WS_EX_APPWINDOW;
1080 cp.Style |= (int)WindowStyles.WS_MAXIMIZEBOX;
1084 cp.Style |= (int)WindowStyles.WS_MINIMIZEBOX;
1088 cp.Style |= (int)WindowStyles.WS_SYSMENU;
1091 if (HelpButton && !MaximizeBox && !MinimizeBox) {
1092 cp.ExStyle |= (int)WindowExStyles.WS_EX_CONTEXTHELP;
1096 cp.Style |= (int)WindowStyles.WS_VISIBLE;
1098 if (Opacity < 1.0 || TransparencyKey != Color.Empty) {
1099 cp.ExStyle |= (int)WindowExStyles.WS_EX_LAYERED;
1102 if (!is_enabled && context == null) {
1103 cp.Style |= (int)(WindowStyles.WS_DISABLED);
1110 protected override ImeMode DefaultImeMode {
1112 return ImeMode.NoControl;
1116 protected override Size DefaultSize {
1118 return new Size (300, 300);
1122 protected Rectangle MaximizedBounds {
1124 if (maximized_bounds != Rectangle.Empty) {
1125 return maximized_bounds;
1127 return default_maximized_bounds;
1131 maximized_bounds = value;
1132 OnMaximizedBoundsChanged(EventArgs.Empty);
1133 if (IsHandleCreated) {
1134 XplatUI.SetWindowMinMax(Handle, maximized_bounds, minimum_size, maximum_size);
1138 #endregion // Protected Instance Properties
1140 #region Public Static Methods
1141 [EditorBrowsable(EditorBrowsableState.Advanced)]
1142 public static SizeF GetAutoScaleSize (Font font)
1144 return XplatUI.GetAutoScaleSize(font);
1147 #endregion // Public Static Methods
1149 #region Public Instance Methods
1150 internal SizeF GetAutoScaleSize (Graphics g, Font font)
1153 // The following constants come from the dotnet mailing list
1154 // discussion: http://discuss.develop.com/archives/wa.exe?A2=ind0203A&L=DOTNET&P=R3655
1156 // The magic number is "Its almost the length
1157 // of the string with a smattering added in
1158 // for compat with earlier code".
1161 string magic_string = "The quick brown fox jumped over the lazy dog.";
1162 double magic_number = 44.549996948242189;
1163 float width = (float) (g.MeasureString (magic_string, font).Width / magic_number);
1165 return new SizeF (width, font.Height);
1168 public void Activate() {
1171 // The docs say activate only activates if our app is already active
1172 if (IsHandleCreated) {
1174 MdiParent.ActivateMdiChild (this);
1176 active = ActiveForm;
1177 if ((active != null) && (this != active)) {
1178 XplatUI.Activate(window.Handle);
1184 public void AddOwnedForm(Form ownedForm) {
1185 if (!owned_forms.Contains(ownedForm)) {
1186 owned_forms.Add(ownedForm);
1188 ownedForm.Owner = this;
1191 public void Close () {
1199 FormClosingEventArgs ce = new FormClosingEventArgs (CloseReason.FormOwnerClosing, false);
1204 XplatUI.SendMessage(this.Handle, Msg.WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
1207 public void LayoutMdi(MdiLayout value) {
1208 if (mdi_container != null) {
1209 mdi_container.LayoutMdi(value);
1213 public void RemoveOwnedForm(Form ownedForm) {
1214 owned_forms.Remove(ownedForm);
1217 public void SetDesktopBounds(int x, int y, int width, int height) {
1218 DesktopBounds = new Rectangle(x, y, width, height);
1221 public void SetDesktopLocation(int x, int y) {
1222 DesktopLocation = new Point(x, y);
1225 public DialogResult ShowDialog() {
1226 return ShowDialog(this.owner);
1229 public DialogResult ShowDialog(IWin32Window ownerWin32) {
1232 IntPtr capture_window;
1236 if (ownerWin32 != null) {
1237 Control c = Control.FromHandle (ownerWin32.Handle);
1239 owner = c.TopLevelControl as Form;
1242 if (owner == this) {
1243 throw new InvalidOperationException("The 'ownerWin32' cannot be the form being shown.");
1247 throw new InvalidOperationException("The form is already displayed as a modal dialog.");
1251 throw new InvalidOperationException("Already visible forms cannot be displayed as a modal dialog. Set the Visible property to 'false' prior to calling Form.ShowDialog.");
1255 throw new InvalidOperationException("Cannot display a disabled form as modal dialog.");
1258 if (TopLevelControl != this) {
1259 throw new InvalidOperationException("Can only display TopLevel forms as modal dialog.");
1263 // Can't do this, will screw us in the modal loop
1264 form_parent_window.Parent = this.owner;
1267 // Release any captures
1268 XplatUI.GrabInfo(out capture_window, out confined, out area);
1269 if (capture_window != IntPtr.Zero) {
1270 XplatUI.UngrabWindow(capture_window);
1274 // Commented out; we instead let the Visible=true inside the runloop create the control
1275 // otherwise setting DialogResult inside any of the events that are triggered by the
1276 // create will not actually cause the form to not be displayed.
1277 // Leaving this comment here in case there was an actual purpose to creating the control
1279 if (!IsHandleCreated) {
1284 Application.RunLoop(true, new ApplicationContext(this));
1286 if (owner != null) {
1287 // Cannot use Activate(), it has a check for the current active window...
1288 XplatUI.Activate(owner.window.Handle);
1291 if (DialogResult != DialogResult.None) {
1292 return DialogResult;
1294 DialogResult = DialogResult.Cancel;
1295 return DialogResult.Cancel;
1298 public override string ToString() {
1299 return GetType().FullName.ToString() + ", Text: " + Text;
1301 #endregion // Public Instance Methods
1303 #region Protected Instance Methods
1304 protected void ActivateMdiChild(Form form) {
1305 if (!IsMdiContainer)
1307 mdi_container.ActivateChild (form);
1308 OnMdiChildActivate(EventArgs.Empty);
1311 [EditorBrowsable(EditorBrowsableState.Advanced)]
1312 protected override void AdjustFormScrollbars(bool displayScrollbars) {
1313 base.AdjustFormScrollbars (displayScrollbars);
1316 [EditorBrowsable(EditorBrowsableState.Advanced)]
1317 protected void ApplyAutoScaling()
1319 SizeF current_size_f = GetAutoScaleSize (DeviceContext, Font);
1320 Size current_size = new Size ((int) current_size_f.Width, (int) current_size_f.Height);
1324 if (current_size == autoscale_base_size)
1327 if (Environment.GetEnvironmentVariable ("MONO_MWF_SCALING") == "disable"){
1332 // I tried applying the Fudge height factor from:
1333 // http://blogs.msdn.com/mharsh/archive/2004/01/25/62621.aspx
1334 // but it makes things larger without looking better.
1336 if (current_size_f.Width != AutoScaleBaseSize.Width) {
1337 dx = current_size_f.Width / AutoScaleBaseSize.Width + 0.08f;
1342 if (current_size_f.Height != AutoScaleBaseSize.Height) {
1343 dy = current_size_f.Height / AutoScaleBaseSize.Height + 0.08f;
1350 AutoScaleBaseSize = current_size;
1353 protected void CenterToParent() {
1361 w = DefaultSize.Width;
1367 h = DefaultSize.Height;
1371 if (Parent != null) {
1373 } else if (owner != null) {
1377 if (owner != null) {
1378 this.Location = new Point(ctl.Left + ctl.Width / 2 - w /2, ctl.Top + ctl.Height / 2 - h / 2);
1382 protected void CenterToScreen() {
1390 w = DefaultSize.Width;
1396 h = DefaultSize.Height;
1399 XplatUI.GetDisplaySize(out DisplaySize);
1400 this.Location = new Point(DisplaySize.Width / 2 - w / 2, DisplaySize.Height / 2 - h / 2);
1403 [EditorBrowsable(EditorBrowsableState.Advanced)]
1404 protected override Control.ControlCollection CreateControlsInstance() {
1405 return base.CreateControlsInstance ();
1408 [EditorBrowsable(EditorBrowsableState.Advanced)]
1409 protected override void CreateHandle() {
1410 base.CreateHandle ();
1412 Application.AddForm (this);
1416 if ((XplatUI.SupportsTransparency() & TransparencySupport.Set) != 0) {
1417 if (allow_transparency) {
1418 XplatUI.SetWindowTransparency(Handle, Opacity, TransparencyKey);
1422 XplatUI.SetWindowMinMax(window.Handle, maximized_bounds, minimum_size, maximum_size);
1423 if ((FormBorderStyle != FormBorderStyle.FixedDialog) && (icon != null)) {
1424 XplatUI.SetIcon(window.Handle, icon);
1427 if ((owner != null) && (owner.IsHandleCreated)) {
1428 XplatUI.SetTopmost(window.Handle, owner.window.Handle, true);
1431 for (int i = 0; i < owned_forms.Count; i++) {
1432 if (owned_forms[i].IsHandleCreated)
1433 XplatUI.SetTopmost(owned_forms[i].window.Handle, window.Handle, true);
1436 if (window_manager != null && window_state != FormWindowState.Normal) {
1437 window_manager.SetWindowState (FormWindowState.Normal, window_state);
1442 [EditorBrowsable(EditorBrowsableState.Advanced)]
1443 protected override void DefWndProc(ref Message m) {
1444 base.DefWndProc (ref m);
1447 protected override void Dispose(bool disposing)
1449 for (int i = 0; i < owned_forms.Count; i++)
1450 ((Form)owned_forms[i]).Owner = null;
1452 owned_forms.Clear ();
1454 base.Dispose (disposing);
1456 Application.RemoveForm (this);
1459 [EditorBrowsable(EditorBrowsableState.Advanced)]
1460 protected virtual void OnActivated(EventArgs e)
1463 SelectActiveControl ();
1465 EventHandler eh = (EventHandler)(Events [ActivatedEvent]);
1470 [EditorBrowsable(EditorBrowsableState.Advanced)]
1471 protected virtual void OnClosed(EventArgs e) {
1472 EventHandler eh = (EventHandler)(Events [ClosedEvent]);
1477 [EditorBrowsable(EditorBrowsableState.Advanced)]
1478 protected virtual void OnClosing(System.ComponentModel.CancelEventArgs e) {
1479 CancelEventHandler eh = (CancelEventHandler)(Events [ClosingEvent]);
1484 [EditorBrowsable(EditorBrowsableState.Advanced)]
1485 protected override void OnCreateControl() {
1486 base.OnCreateControl ();
1489 XplatUI.SetMenu(window.Handle, menu);
1492 OnLoad(EventArgs.Empty);
1494 SelectActiveControl ();
1496 // Send initial location
1497 OnLocationChanged(EventArgs.Empty);
1499 if (IsMdiContainer) {
1500 mdi_container.LayoutMdi (MdiLayout.Cascade);
1504 [EditorBrowsable(EditorBrowsableState.Advanced)]
1505 protected virtual void OnDeactivate(EventArgs e) {
1506 EventHandler eh = (EventHandler)(Events [DeactivateEvent]);
1511 [EditorBrowsable(EditorBrowsableState.Advanced)]
1512 protected override void OnFontChanged(EventArgs e) {
1513 base.OnFontChanged (e);
1516 [EditorBrowsable(EditorBrowsableState.Advanced)]
1517 protected override void OnHandleCreated(EventArgs e) {
1518 XplatUI.SetBorderStyle(window.Handle, form_border_style);
1519 base.OnHandleCreated (e);
1522 [EditorBrowsable(EditorBrowsableState.Advanced)]
1523 protected override void OnHandleDestroyed(EventArgs e) {
1524 base.OnHandleDestroyed (e);
1527 [EditorBrowsable(EditorBrowsableState.Advanced)]
1528 protected virtual void OnInputLanguageChanged(InputLanguageChangedEventArgs e) {
1529 InputLanguageChangedEventHandler eh = (InputLanguageChangedEventHandler)(Events [InputLanguageChangedEvent]);
1534 [EditorBrowsable(EditorBrowsableState.Advanced)]
1535 protected virtual void OnInputLanguageChanging(InputLanguageChangingEventArgs e) {
1536 InputLanguageChangingEventHandler eh = (InputLanguageChangingEventHandler)(Events [InputLanguageChangingEvent]);
1541 [EditorBrowsable(EditorBrowsableState.Advanced)]
1542 protected virtual void OnLoad(EventArgs e) {
1544 ApplyAutoScaling ();
1548 EventHandler eh = (EventHandler)(Events [LoadEvent]);
1553 switch (StartPosition) {
1554 case FormStartPosition.CenterScreen:
1555 this.CenterToScreen();
1557 case FormStartPosition.CenterParent:
1558 this.CenterToParent ();
1560 case FormStartPosition.Manual:
1561 Left = CreateParams.X;
1562 Top = CreateParams.Y;
1569 [EditorBrowsable(EditorBrowsableState.Advanced)]
1570 protected virtual void OnMaximizedBoundsChanged(EventArgs e) {
1571 EventHandler eh = (EventHandler)(Events [MaximizedBoundsChangedEvent]);
1576 [EditorBrowsable(EditorBrowsableState.Advanced)]
1577 protected virtual void OnMaximumSizeChanged(EventArgs e) {
1578 EventHandler eh = (EventHandler)(Events [MaximumSizeChangedEvent]);
1583 [EditorBrowsable(EditorBrowsableState.Advanced)]
1584 protected virtual void OnMdiChildActivate(EventArgs e) {
1585 EventHandler eh = (EventHandler)(Events [MdiChildActivateEvent]);
1590 [EditorBrowsable(EditorBrowsableState.Advanced)]
1591 protected virtual void OnMenuComplete(EventArgs e) {
1592 EventHandler eh = (EventHandler)(Events [MenuCompleteEvent]);
1597 [EditorBrowsable(EditorBrowsableState.Advanced)]
1598 protected virtual void OnMenuStart(EventArgs e) {
1599 EventHandler eh = (EventHandler)(Events [MenuStartEvent]);
1604 [EditorBrowsable(EditorBrowsableState.Advanced)]
1605 protected virtual void OnMinimumSizeChanged(EventArgs e) {
1606 EventHandler eh = (EventHandler)(Events [MinimumSizeChangedEvent]);
1611 [EditorBrowsable(EditorBrowsableState.Advanced)]
1612 protected override void OnPaint (PaintEventArgs pevent) {
1613 base.OnPaint (pevent);
1616 [EditorBrowsable(EditorBrowsableState.Advanced)]
1617 protected override void OnResize(EventArgs e) {
1620 if (this.IsMdiChild && ParentForm != null) {
1621 ParentForm.PerformLayout();
1622 ParentForm.Size = ParentForm.Size;
1626 [EditorBrowsable(EditorBrowsableState.Advanced)]
1627 protected override void OnStyleChanged(EventArgs e) {
1628 base.OnStyleChanged (e);
1631 [EditorBrowsable(EditorBrowsableState.Advanced)]
1632 protected override void OnTextChanged(EventArgs e) {
1633 base.OnTextChanged (e);
1635 if (mdi_container != null)
1636 mdi_container.SetParentText(true);
1639 [EditorBrowsable(EditorBrowsableState.Advanced)]
1640 protected override void OnVisibleChanged(EventArgs e) {
1641 base.OnVisibleChanged (e);
1644 if (window_manager != null)
1645 window_manager.SetWindowState (WindowState, WindowState);
1649 protected override bool ProcessCmdKey(ref Message msg, Keys keyData) {
1650 if (base.ProcessCmdKey (ref msg, keyData)) {
1654 // Give our menu a shot
1655 if (ActiveMenu != null) {
1656 return ActiveMenu.ProcessCmdKey(ref msg, keyData);
1662 // LAMESPEC - Not documented that Form overrides ProcessDialogChar; class-status showed
1663 [EditorBrowsable (EditorBrowsableState.Advanced)]
1664 protected override bool ProcessDialogChar(char charCode) {
1665 return base.ProcessDialogChar (charCode);
1668 protected override bool ProcessDialogKey(Keys keyData) {
1669 if ((keyData & Keys.Modifiers) == 0) {
1670 if (keyData == Keys.Enter) {
1671 IntPtr window = XplatUI.GetFocus ();
1672 Control c = Control.FromHandle (window);
1673 if (c is Button && c.FindForm () == this) {
1674 ((Button)c).PerformClick ();
1677 else if (accept_button != null) {
1678 accept_button.PerformClick();
1681 } else if (keyData == Keys.Escape && cancel_button != null) {
1682 cancel_button.PerformClick();
1686 return base.ProcessDialogKey(keyData);
1689 protected override bool ProcessKeyPreview(ref Message msg) {
1691 if (ProcessKeyEventArgs(ref msg)) {
1695 return base.ProcessKeyPreview (ref msg);
1698 protected override bool ProcessTabKey(bool forward) {
1699 return SelectNextControl(ActiveControl, forward, true, true, true);
1702 [EditorBrowsable(EditorBrowsableState.Advanced)]
1703 protected override void ScaleCore(float dx, float dy) {
1707 // We can't scale max or min windows
1708 if (WindowState == FormWindowState.Normal) {
1709 // We cannot call base since base also adjusts X/Y, but
1710 // a form is toplevel and doesn't move
1714 if (!GetStyle(ControlStyles.FixedWidth)) {
1715 size.Width = (int)(size.Width * dx);
1718 if (!GetStyle(ControlStyles.FixedHeight)) {
1719 size.Height = (int)(size.Height * dy);
1725 /* Now scale our children */
1726 Control [] controls = Controls.GetAllControls ();
1727 for (int i=0; i < controls.Length; i++) {
1728 controls[i].Scale(dx, dy);
1737 protected override void Select(bool directed, bool forward) {
1741 base.SelectNextControl(null, forward, true, true, true);
1744 parent = this.ParentForm;
1745 if (parent != null) {
1746 parent.ActiveControl = this;
1752 [EditorBrowsable(EditorBrowsableState.Advanced)]
1753 protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
1754 base.SetBoundsCore (x, y, width, height, specified);
1757 [EditorBrowsable(EditorBrowsableState.Advanced)]
1758 protected override void SetClientSizeCore(int x, int y) {
1759 if ((minimum_size.Width != 0) && (x < minimum_size.Width)) {
1760 x = minimum_size.Width;
1761 } else if ((maximum_size.Width != 0) && (x > maximum_size.Width)) {
1762 x = maximum_size.Width;
1765 if ((minimum_size.Height != 0) && (y < minimum_size.Height)) {
1766 y = minimum_size.Height;
1767 } else if ((maximum_size.Height != 0) && (y > maximum_size.Height)) {
1768 y = maximum_size.Height;
1771 Rectangle ClientRect = new Rectangle(0, 0, x, y);
1772 Rectangle WindowRect;
1773 CreateParams cp = this.CreateParams;
1775 clientsize_set = new Size(x, y);
1777 if (XplatUI.CalculateWindowRect(ref ClientRect, cp.Style, cp.ExStyle, cp.menu, out WindowRect)) {
1778 SetBounds(bounds.X, bounds.Y, WindowRect.Width, WindowRect.Height, BoundsSpecified.Size);
1782 [EditorBrowsable(EditorBrowsableState.Advanced)]
1783 protected override void SetVisibleCore(bool value) {
1784 is_changing_visible_state = true;
1785 has_been_visible = value || has_been_visible;
1786 base.SetVisibleCore (value);
1787 is_changing_visible_state = false;
1790 protected override void UpdateDefaultButton() {
1791 base.UpdateDefaultButton ();
1794 [EditorBrowsable(EditorBrowsableState.Advanced)]
1795 protected override void WndProc(ref Message m) {
1797 if (window_manager != null && window_manager.HandleMessage (ref m)) {
1801 switch((Msg)m.Msg) {
1802 case Msg.WM_DESTROY: {
1803 base.WndProc(ref m);
1804 if (!RecreatingHandle) {
1805 this.closing = true;
1810 case Msg.WM_CLOSE_INTERNAL: {
1815 case Msg.WM_CLOSE: {
1816 Form act = Form.ActiveForm;
1817 if (act != null && act != this && act.Modal == true) {
1821 CancelEventArgs args = new CancelEventArgs ();
1823 if (mdi_container != null) {
1824 foreach (Form mdi_child in mdi_container.MdiChildren) {
1825 mdi_child.OnClosing (args);
1832 OnClosed (EventArgs.Empty);
1839 DialogResult = DialogResult.None;
1842 OnClosed (EventArgs.Empty);
1851 case Msg.WM_WINDOWPOSCHANGED: {
1852 if (WindowState != FormWindowState.Minimized) {
1853 base.WndProc(ref m);
1859 case Msg.WM_SYSCOMMAND: {
1860 // Let *Strips know the app's title bar was clicked
1861 if (XplatUI.IsEnabled (Handle))
1862 ToolStripManager.FireAppClicked ();
1864 base.WndProc(ref m);
1869 case Msg.WM_ACTIVATE: {
1870 if (m.WParam != (IntPtr)WindowActiveFlags.WA_INACTIVE) {
1871 OnActivated(EventArgs.Empty);
1873 OnDeactivate(EventArgs.Empty);
1878 case Msg.WM_KILLFOCUS: {
1879 base.WndProc(ref m);
1883 case Msg.WM_SETFOCUS: {
1884 if (ActiveControl != null && ActiveControl != this) {
1885 ActiveControl.Focus();
1886 return; // FIXME - do we need to run base.WndProc, even though we just changed focus?
1888 base.WndProc(ref m);
1893 case Msg.WM_NCLBUTTONDOWN: {
1894 if (XplatUI.IsEnabled (Handle) && ActiveMenu != null) {
1895 ActiveMenu.OnMouseDown(this, new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()), mouse_clicks, Control.MousePosition.X, Control.MousePosition.Y, 0));
1898 if (ActiveMaximizedMdiChild != null) {
1899 if (ActiveMaximizedMdiChild.HandleMenuMouseDown (ActiveMenu,
1900 LowOrder ((int) m.LParam.ToInt32 ()),
1901 HighOrder ((int) m.LParam.ToInt32 ()))) {
1902 // Don't let base process this message, otherwise we won't
1903 // get a WM_NCLBUTTONUP.
1907 base.WndProc(ref m);
1910 case Msg.WM_NCLBUTTONUP: {
1911 if (ActiveMaximizedMdiChild != null) {
1912 ActiveMaximizedMdiChild.HandleMenuMouseUp (ActiveMenu,
1913 LowOrder ((int)m.LParam.ToInt32 ()),
1914 HighOrder ((int)m.LParam.ToInt32 ()));
1916 base.WndProc (ref m);
1920 case Msg.WM_NCMOUSELEAVE: {
1921 if (ActiveMaximizedMdiChild != null) {
1922 ActiveMaximizedMdiChild.HandleMenuMouseLeave(ActiveMenu,
1923 LowOrder((int)m.LParam.ToInt32()),
1924 HighOrder((int)m.LParam.ToInt32()));
1926 base.WndProc(ref m);
1930 case Msg.WM_NCMOUSEMOVE: {
1931 if (XplatUI.IsEnabled (Handle) && ActiveMenu != null) {
1932 ActiveMenu.OnMouseMove(this, new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()), mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()), 0));
1935 if (ActiveMaximizedMdiChild != null) {
1936 ActiveMaximizedMdiChild.HandleMenuMouseMove (ActiveMenu,
1937 LowOrder ((int)m.LParam.ToInt32 ()),
1938 HighOrder ((int)m.LParam.ToInt32 ()));
1940 base.WndProc(ref m);
1944 case Msg.WM_NCPAINT: {
1945 if (ActiveMenu != null) {
1949 pe = XplatUI.PaintEventStart(Handle, false);
1950 pnt = XplatUI.GetMenuOrigin(window.Handle);
1952 // The entire menu has to be in the clip rectangle because the
1953 // control buttons are right-aligned and otherwise they would
1954 // stay painted when the window gets resized.
1955 Rectangle clip = new Rectangle (pnt.X, pnt.Y, ClientSize.Width, 0);
1956 clip = Rectangle.Union(clip, pe.ClipRectangle);
1958 pe.Graphics.SetClip(clip);
1960 ActiveMenu.Draw (pe, new Rectangle (pnt.X, pnt.Y, ClientSize.Width, 0));
1962 if (ActiveMaximizedMdiChild != null) {
1963 ActiveMaximizedMdiChild.DrawMaximizedButtons (ActiveMenu, pe);
1966 XplatUI.PaintEventEnd(Handle, false);
1969 base.WndProc(ref m);
1973 case Msg.WM_NCCALCSIZE: {
1974 XplatUIWin32.NCCALCSIZE_PARAMS ncp;
1976 if ((ActiveMenu != null) && (m.WParam == (IntPtr)1)) {
1977 ncp = (XplatUIWin32.NCCALCSIZE_PARAMS)Marshal.PtrToStructure(m.LParam, typeof(XplatUIWin32.NCCALCSIZE_PARAMS));
1980 ncp.rgrc1.top += ThemeEngine.Current.CalcMenuBarSize (DeviceContext, ActiveMenu, ncp.rgrc1.right - ncp.rgrc1.left);
1981 Marshal.StructureToPtr(ncp, m.LParam, true);
1987 case Msg.WM_MOUSEMOVE: {
1988 if (XplatUI.IsEnabled (Handle) && active_tracker != null) {
1989 MouseEventArgs args;
1991 args = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
1992 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()), 0);
1993 active_tracker.OnMotion(new MouseEventArgs (args.Button, args.Clicks, Control.MousePosition.X, Control.MousePosition.Y, args.Delta));
1996 base.WndProc(ref m);
2000 case Msg.WM_LBUTTONDOWN:
2001 case Msg.WM_MBUTTONDOWN:
2002 case Msg.WM_RBUTTONDOWN: {
2003 if (XplatUI.IsEnabled (Handle) && active_tracker != null) {
2004 MouseEventArgs args;
2006 args = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
2007 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()), 0);
2008 active_tracker.OnMouseDown(new MouseEventArgs (args.Button, args.Clicks, Control.MousePosition.X, Control.MousePosition.Y, args.Delta));
2011 base.WndProc(ref m);
2015 case Msg.WM_LBUTTONUP:
2016 case Msg.WM_MBUTTONUP:
2017 case Msg.WM_RBUTTONUP: {
2018 if (XplatUI.IsEnabled (Handle) && active_tracker != null) {
2019 MouseEventArgs args;
2020 MouseButtons mb = FromParamToMouseButtons ((int) m.WParam.ToInt32());
2022 // We add in the button that was released (not sent in WParam)
2023 switch((Msg)m.Msg) {
2024 case Msg.WM_LBUTTONUP:
2025 mb |= MouseButtons.Left;
2027 case Msg.WM_MBUTTONUP:
2028 mb |= MouseButtons.Middle;
2030 case Msg.WM_RBUTTONUP:
2031 mb |= MouseButtons.Right;
2035 args = new MouseEventArgs (mb, mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()), 0);
2036 active_tracker.OnMouseUp(new MouseEventArgs (args.Button, args.Clicks, Control.MousePosition.X, Control.MousePosition.Y, args.Delta));
2040 base.WndProc(ref m);
2044 case Msg.WM_GETMINMAXINFO: {
2047 if (m.LParam != IntPtr.Zero) {
2048 mmi = (MINMAXINFO)Marshal.PtrToStructure(m.LParam, typeof(MINMAXINFO));
2050 default_maximized_bounds = new Rectangle(mmi.ptMaxPosition.x, mmi.ptMaxPosition.y, mmi.ptMaxSize.x, mmi.ptMaxSize.y);
2051 if (maximized_bounds != Rectangle.Empty) {
2052 mmi.ptMaxPosition.x = maximized_bounds.Left;
2053 mmi.ptMaxPosition.y = maximized_bounds.Top;
2054 mmi.ptMaxSize.x = maximized_bounds.Width;
2055 mmi.ptMaxSize.y = maximized_bounds.Height;
2058 if (minimum_size != Size.Empty) {
2059 mmi.ptMinTrackSize.x = minimum_size.Width;
2060 mmi.ptMinTrackSize.y = minimum_size.Height;
2063 if (maximum_size != Size.Empty) {
2064 mmi.ptMaxTrackSize.x = maximum_size.Width;
2065 mmi.ptMaxTrackSize.y = maximum_size.Height;
2067 Marshal.StructureToPtr(mmi, m.LParam, false);
2073 case Msg.WM_MOUSEACTIVATE: {
2074 // Let *Strips know the form or another control has been clicked
2075 if (XplatUI.IsEnabled (Handle))
2076 ToolStripManager.FireAppClicked ();
2078 base.WndProc (ref m);
2082 case Msg.WM_ACTIVATEAPP: {
2083 // Let *Strips know the app lost focus
2084 if (m.WParam == (IntPtr)0)
2085 if (XplatUI.IsEnabled (Handle))
2086 ToolStripManager.FireAppFocusChanged (this);
2088 base.WndProc (ref m);
2094 base.WndProc (ref m);
2099 #endregion // Protected Instance Methods
2101 internal void RemoveWindowManager ()
2103 window_manager = null;
2106 internal override void CheckAcceptButton()
2108 if (accept_button != null) {
2109 Button a_button = accept_button as Button;
2111 if (ActiveControl == a_button)
2114 if (ActiveControl is Button) {
2115 a_button.paint_as_acceptbutton = false;
2119 a_button.paint_as_acceptbutton = true;
2126 static object ActivatedEvent = new object ();
2127 static object ClosedEvent = new object ();
2128 static object ClosingEvent = new object ();
2129 static object DeactivateEvent = new object ();
2130 static object InputLanguageChangedEvent = new object ();
2131 static object InputLanguageChangingEvent = new object ();
2132 static object LoadEvent = new object ();
2133 static object MaximizedBoundsChangedEvent = new object ();
2134 static object MaximumSizeChangedEvent = new object ();
2135 static object MdiChildActivateEvent = new object ();
2136 static object MenuCompleteEvent = new object ();
2137 static object MenuStartEvent = new object ();
2138 static object MinimumSizeChangedEvent = new object ();
2140 public event EventHandler Activated {
2141 add { Events.AddHandler (ActivatedEvent, value); }
2142 remove { Events.RemoveHandler (ActivatedEvent, value); }
2145 public event EventHandler Closed {
2146 add { Events.AddHandler (ClosedEvent, value); }
2147 remove { Events.RemoveHandler (ClosedEvent, value); }
2150 public event CancelEventHandler Closing {
2151 add { Events.AddHandler (ClosingEvent, value); }
2152 remove { Events.RemoveHandler (ClosingEvent, value); }
2155 public event EventHandler Deactivate {
2156 add { Events.AddHandler (DeactivateEvent, value); }
2157 remove { Events.RemoveHandler (DeactivateEvent, value); }
2160 public event InputLanguageChangedEventHandler InputLanguageChanged {
2161 add { Events.AddHandler (InputLanguageChangedEvent, value); }
2162 remove { Events.RemoveHandler (InputLanguageChangedEvent, value); }
2165 public event InputLanguageChangingEventHandler InputLanguageChanging {
2166 add { Events.AddHandler (InputLanguageChangingEvent, value); }
2167 remove { Events.RemoveHandler (InputLanguageChangingEvent, value); }
2170 public event EventHandler Load {
2171 add { Events.AddHandler (LoadEvent, value); }
2172 remove { Events.RemoveHandler (LoadEvent, value); }
2175 public event EventHandler MaximizedBoundsChanged {
2176 add { Events.AddHandler (MaximizedBoundsChangedEvent, value); }
2177 remove { Events.RemoveHandler (MaximizedBoundsChangedEvent, value); }
2180 public event EventHandler MaximumSizeChanged {
2181 add { Events.AddHandler (MaximumSizeChangedEvent, value); }
2182 remove { Events.RemoveHandler (MaximumSizeChangedEvent, value); }
2185 public event EventHandler MdiChildActivate {
2186 add { Events.AddHandler (MdiChildActivateEvent, value); }
2187 remove { Events.RemoveHandler (MdiChildActivateEvent, value); }
2190 public event EventHandler MenuComplete {
2191 add { Events.AddHandler (MenuCompleteEvent, value); }
2192 remove { Events.RemoveHandler (MenuCompleteEvent, value); }
2195 public event EventHandler MenuStart {
2196 add { Events.AddHandler (MenuStartEvent, value); }
2197 remove { Events.RemoveHandler (MenuStartEvent, value); }
2200 public event EventHandler MinimumSizeChanged {
2201 add { Events.AddHandler (MinimumSizeChangedEvent, value); }
2202 remove { Events.RemoveHandler (MinimumSizeChangedEvent, value); }
2207 [EditorBrowsable(EditorBrowsableState.Never)]
2208 public new event EventHandler TabIndexChanged {
2209 add { base.TabIndexChanged += value; }
2210 remove { base.TabIndexChanged -= value; }
2212 #endregion // Events
2215 public override string Text {
2225 public new Point Location {
2227 return base.Location;
2231 base.Location = value;
2235 static object FormClosingEvent = new object ();
2236 static object FormClosedEvent = new object ();
2238 public event FormClosingEventHandler FormClosing {
2239 add { Events.AddHandler (FormClosingEvent, value); }
2240 remove { Events.RemoveHandler (FormClosingEvent, value); }
2243 public event FormClosedEventHandler FormClosed {
2244 add { Events.AddHandler (FormClosedEvent, value); }
2245 remove { Events.RemoveHandler (FormClosedEvent, value); }
2248 protected virtual void OnFormClosing (FormClosingEventArgs e)
2250 FormClosingEventHandler eh = (FormClosingEventHandler)(Events [FormClosingEvent]);