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) {
104 SendControlFocus (this.mdi_container);
108 if (this.ActiveControl == null) {
111 // This visible hack is to work around CanSelect always being false if one of the parents
112 // is not visible; and we by default create Form invisible...
113 visible = this.is_visible;
114 this.is_visible = true;
116 if (SelectNextControl (this, true, true, true, true) == false) {
120 this.is_visible = visible;
122 Select (ActiveControl);
125 #endregion // Private & Internal Methods
127 #region Public Classes
128 public new class ControlCollection : Control.ControlCollection {
131 public ControlCollection(Form owner) : base(owner) {
132 this.form_owner = owner;
135 public override void Add(Control value) {
136 if (Contains (value))
139 ((Form)value).owner=form_owner;
142 public override void Remove(Control value) {
143 ((Form)value).owner = null;
147 #endregion // Public Classes
149 #region Public Constructor & Destructor
152 SizeF current_scale = GetAutoScaleSize (DeviceContext, Font);
155 autoscale_base_size = new Size ((int)current_scale.Width, (int) current_scale.Height);
156 allow_transparency = false;
159 dialog_result = DialogResult.None;
160 start_position = FormStartPosition.WindowsDefaultLocation;
161 form_border_style = FormBorderStyle.Sizable;
162 window_state = FormWindowState.Normal;
167 minimum_size = Size.Empty;
168 maximum_size = Size.Empty;
169 clientsize_set = Size.Empty;
174 show_in_taskbar = true;
177 size_grip_style = SizeGripStyle.Auto;
178 maximized_bounds = Rectangle.Empty;
179 default_maximized_bounds = Rectangle.Empty;
180 owned_forms = new Form.ControlCollection(this);
181 transparency_key = Color.Empty;
183 // FIXME: this should disappear just as soon as the handle creation is done in the right place (here is too soon()
187 #endregion // Public Constructor & Destructor
189 #region Public Static Properties
191 public static Form ActiveForm {
195 active = FromHandle(XplatUI.GetActive());
197 if (active != null) {
198 if ( !(active is Form)) {
201 parent = active.Parent;
202 while (parent != null) {
203 if (parent is Form) {
206 parent = parent.Parent;
216 #endregion // Public Static Properties
218 #region Public Instance Properties
220 public IButtonControl AcceptButton {
222 return accept_button;
226 accept_button = value;
232 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
233 public bool AllowTransparency {
235 return allow_transparency;
239 if (value == allow_transparency) {
243 allow_transparency = value;
246 if (IsHandleCreated) {
247 if ((XplatUI.SupportsTransparency() & TransparencySupport.Set) != 0) {
248 XplatUI.SetWindowTransparency(Handle, Opacity, TransparencyKey);
251 UpdateStyles(); // Remove the WS_EX_LAYERED style
261 [MWFCategory("Layout")]
262 public bool AutoScale {
274 [EditorBrowsable(EditorBrowsableState.Advanced)]
275 public virtual Size AutoScaleBaseSize {
277 return autoscale_base_size;
281 autoscale_base_size = value;
286 public override bool AutoScroll {
288 return base.AutoScroll;
291 base.AutoScroll = value;
295 public override Color BackColor {
297 /* we don't let parents override our
298 default background color for forms.
299 this fixes the default color for mdi
301 if (background_color.IsEmpty)
302 return DefaultBackColor;
304 return background_color;
307 base.BackColor = value;
312 public IButtonControl CancelButton {
314 return cancel_button;
318 cancel_button = value;
319 if (cancel_button != null && cancel_button.DialogResult == DialogResult.None)
320 cancel_button.DialogResult = DialogResult.Cancel;
324 // new property so we can change the DesignerSerializationVisibility
325 [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
327 public new Size ClientSize {
328 get { return base.ClientSize; }
329 set { base.ClientSize = value; }
333 [MWFCategory("Window Style")]
334 public bool ControlBox {
340 if (control_box != value) {
348 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
349 public Rectangle DesktopBounds {
351 return new Rectangle(Location, Size);
360 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
361 public Point DesktopLocation {
372 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
373 public DialogResult DialogResult {
375 return dialog_result;
379 if (value < DialogResult.None || value > DialogResult.No)
380 throw new InvalidEnumArgumentException ("value", (int) value,
381 typeof (DialogResult));
383 dialog_result = value;
384 closing = (dialog_result != DialogResult.None && is_modal);
388 [DefaultValue(FormBorderStyle.Sizable)]
390 [MWFCategory("Appearance")]
391 public FormBorderStyle FormBorderStyle {
393 return form_border_style;
396 form_border_style = value;
398 if (window_manager == null) {
399 if (IsHandleCreated) {
400 XplatUI.SetBorderStyle(window.Handle, form_border_style);
403 window_manager.UpdateBorderStyle (value);
410 [DefaultValue(false)]
411 [MWFCategory("Window Style")]
412 public bool HelpButton {
418 if (help_button != value) {
427 [MWFCategory("Window Style")]
437 if (IsHandleCreated) {
438 XplatUI.SetIcon(Handle, icon == null ? default_icon : icon);
445 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
446 public bool IsMdiChild {
448 return mdi_parent != null;
452 [DefaultValue(false)]
453 [MWFCategory("Window Style")]
454 public bool IsMdiContainer {
456 return mdi_container != null;
460 if (value && mdi_container == null) {
461 mdi_container = new MdiClient ();
462 Controls.Add(mdi_container);
463 ControlAdded += new ControlEventHandler (ControlAddedHandler);
464 mdi_container.SendToBack ();
465 mdi_container.SetParentText (true);
466 } else if (!value && mdi_container != null) {
467 Controls.Remove(mdi_container);
468 mdi_container = null;
474 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
475 public Form ActiveMdiChild {
479 return (Form) mdi_container.ActiveMdiChild;
484 [EditorBrowsable(EditorBrowsableState.Advanced)]
485 public bool IsRestrictedWindow {
491 [DefaultValue(false)]
492 public bool KeyPreview {
503 [MWFCategory("Window Style")]
504 public bool MaximizeBox {
509 if (maximize_box != value) {
510 maximize_box = value;
511 if (IsHandleCreated) {
519 [DefaultValue("{Width=0, Height=0}")]
521 [RefreshProperties(RefreshProperties.Repaint)]
522 [MWFCategory("Layout")]
533 if (maximum_size != value) {
534 maximum_size = value;
535 OnMaximumSizeChanged(EventArgs.Empty);
536 if (IsHandleCreated) {
537 XplatUI.SetWindowMinMax(Handle, maximized_bounds, minimum_size, maximum_size);
544 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
545 public Form[] MdiChildren {
547 if (mdi_container != null)
548 return mdi_container.MdiChildren;
555 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
556 public Form MdiParent {
562 if (value != null && !value.IsMdiContainer)
563 throw new ArgumentException ();
565 if (mdi_parent != null) {
566 mdi_parent.MdiContainer.Controls.Remove (this);
571 window_manager = new MdiWindowManager (this,
572 mdi_parent.MdiContainer);
573 mdi_parent.MdiContainer.Controls.Add (this);
574 mdi_parent.MdiContainer.Controls.SetChildIndex (this, 0);
578 } else if (mdi_parent != null) {
581 // Create a new window manager
582 window_manager = null;
583 FormBorderStyle = form_border_style;
590 internal MenuTracker ActiveTracker {
591 get { return active_tracker; }
593 if (value == active_tracker)
596 Capture = value != null;
597 active_tracker = value;
601 internal MdiClient MdiContainer {
602 get { return mdi_container; }
605 internal InternalWindowManager WindowManager {
606 get { return window_manager; }
610 [MWFCategory("Window Style")]
611 public MainMenu Menu {
620 if (menu != null && !IsMdiChild) {
623 if (IsHandleCreated) {
624 XplatUI.SetMenu (window.Handle, menu);
627 if (clientsize_set != Size.Empty) {
628 SetClientSizeCore(clientsize_set.Width, clientsize_set.Height);
630 UpdateBounds (bounds.X, bounds.Y, bounds.Width, bounds.Height, ClientSize.Width, ClientSize.Height -
631 ThemeEngine.Current.CalcMenuBarSize (DeviceContext, menu, ClientSize.Width));
640 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
641 [EditorBrowsable(EditorBrowsableState.Advanced)]
642 public MainMenu MergedMenu {
644 if (!IsMdiChild || window_manager == null)
646 return ((MdiWindowManager) window_manager).MergedMenu;
650 // This is the menu in display and being used because of merging this can
651 // be different then the menu that is actually assosciated with the form
652 internal MainMenu ActiveMenu {
657 if (IsMdiContainer && mdi_container.Controls.Count > 0 &&
658 ((Form) mdi_container.Controls [0]).WindowState == FormWindowState.Maximized) {
659 MdiWindowManager wm = (MdiWindowManager) ((Form) mdi_container.Controls [0]).WindowManager;
660 return wm.MaximizedMenu;
663 Form amc = ActiveMdiChild;
664 if (amc == null || amc.Menu == null)
666 return amc.MergedMenu;
670 internal MdiWindowManager ActiveMaximizedMdiChild {
672 Form child = ActiveMdiChild;
675 if (child.WindowManager == null || child.window_state != FormWindowState.Maximized)
677 return (MdiWindowManager) child.WindowManager;
682 [MWFCategory("Window Style")]
683 public bool MinimizeBox {
688 if (minimize_box != value) {
689 minimize_box = value;
690 if (IsHandleCreated) {
699 [DefaultValue("{Width=0, Height=0}")]
702 [RefreshProperties(RefreshProperties.Repaint)]
703 [MWFCategory("Layout")]
714 if (minimum_size != value) {
715 minimum_size = value;
717 if ((Size.Width < value.Width) || (Size.Height < value.Height)) {
718 Size = new Size(Math.Max(Size.Width, value.Width), Math.Max(Size.Height, value.Height));
722 OnMinimumSizeChanged(EventArgs.Empty);
723 if (IsHandleCreated) {
724 XplatUI.SetWindowMinMax(Handle, maximized_bounds, minimum_size, maximum_size);
731 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
739 [TypeConverter(typeof(OpacityConverter))]
740 [MWFCategory("Window Style")]
741 public double Opacity {
743 if (IsHandleCreated) {
744 if ((XplatUI.SupportsTransparency () & TransparencySupport.Get) != 0)
745 return XplatUI.GetWindowTransparency (Handle);
754 AllowTransparency = true;
756 if (IsHandleCreated) {
758 if ((XplatUI.SupportsTransparency () & TransparencySupport.Set) != 0)
759 XplatUI.SetWindowTransparency(Handle, opacity, TransparencyKey);
766 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
767 public Form[] OwnedForms {
771 form_list = new Form[owned_forms.Count];
773 for (int i=0; i<owned_forms.Count; i++) {
774 form_list[i] = (Form)owned_forms[i];
782 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
789 if (owner != value) {
791 owner.RemoveOwnedForm(this);
795 owner.AddOwnedForm(this);
796 if (IsHandleCreated) {
797 if (owner != null && owner.IsHandleCreated) {
798 XplatUI.SetTopmost(this.window.Handle, owner.window.Handle, true);
800 XplatUI.SetTopmost(this.window.Handle, IntPtr.Zero, false);
808 [MWFCategory("Window Style")]
809 public bool ShowInTaskbar {
811 return show_in_taskbar;
814 if (show_in_taskbar != value) {
815 show_in_taskbar = value;
816 if (IsHandleCreated) {
824 // new property so we can set the DesignerSerializationVisibility
825 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
827 public new Size Size {
828 get { return base.Size; }
829 set { base.Size = value; }
832 [MonoTODO("Trigger something when GripStyle is set")]
833 [DefaultValue(SizeGripStyle.Auto)]
834 [MWFCategory("Window Style")]
835 public SizeGripStyle SizeGripStyle {
837 return size_grip_style;
841 size_grip_style = value;
845 [DefaultValue(FormStartPosition.WindowsDefaultLocation)]
847 [MWFCategory("Layout")]
848 public FormStartPosition StartPosition {
850 return start_position;
854 if (start_position == FormStartPosition.WindowsDefaultLocation) { // Only do this if it's not set yet
855 start_position = value;
856 if (IsHandleCreated) {
857 switch(start_position) {
858 case FormStartPosition.CenterParent: {
863 case FormStartPosition.CenterScreen: {
868 case FormStartPosition.Manual: {
869 Left = CreateParams.X;
870 Top = CreateParams.Y;
883 // new property so we can set EditorBrowsable to never
885 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
886 [EditorBrowsable(EditorBrowsableState.Never)]
887 public new int TabIndex {
888 get { return base.TabIndex; }
889 set { base.TabIndex = value; }
893 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
894 [EditorBrowsable(EditorBrowsableState.Advanced)]
895 public bool TopLevel {
897 return GetTopLevel();
901 if (!value && IsMdiContainer)
902 throw new ArgumentException ("MDI Container forms must be top level.");
907 [DefaultValue(false)]
908 [MWFCategory("Window Style")]
909 public bool TopMost {
915 if (topmost != value) {
918 XplatUI.SetTopmost(window.Handle, owner != null ? owner.window.Handle : IntPtr.Zero, value);
923 [MWFCategory("Window Style")]
924 public Color TransparencyKey {
926 return transparency_key;
930 transparency_key = value;
932 AllowTransparency = true;
934 if ((XplatUI.SupportsTransparency () & TransparencySupport.Set) != 0)
935 XplatUI.SetWindowTransparency(Handle, Opacity, transparency_key);
939 [DefaultValue(FormWindowState.Normal)]
940 [MWFCategory("Layout")]
941 public FormWindowState WindowState {
943 if (IsHandleCreated) {
945 if (window_manager != null)
946 return window_manager.GetWindowState ();
948 FormWindowState new_state = XplatUI.GetWindowState(Handle);
949 if (new_state != (FormWindowState)(-1))
950 window_state = new_state;
957 FormWindowState old_state = window_state;
958 window_state = value;
959 if (IsHandleCreated) {
961 if (window_manager != null) {
962 window_manager.SetWindowState (old_state, value);
966 XplatUI.SetWindowState(Handle, value);
971 #endregion // Public Instance Properties
973 #region Protected Instance Properties
974 protected override CreateParams CreateParams {
976 CreateParams cp = new CreateParams ();
979 cp.ClassName = XplatUI.DefaultClassName;
984 cp.Parent = IntPtr.Zero;
985 cp.menu = ActiveMenu;
987 if (start_position == FormStartPosition.WindowsDefaultLocation && !IsMdiChild) {
988 cp.X = unchecked((int)0x80000000);
989 cp.Y = unchecked((int)0x80000000);
997 cp.Style = (int)(WindowStyles.WS_CLIPCHILDREN | WindowStyles.WS_CLIPSIBLINGS);
1000 cp.Style |= (int)(WindowStyles.WS_CHILD | WindowStyles.WS_CAPTION);
1001 if (Parent != null) {
1002 cp.Parent = Parent.Handle;
1005 cp.ExStyle |= (int) (WindowExStyles.WS_EX_WINDOWEDGE | WindowExStyles.WS_EX_MDICHILD);
1007 switch (FormBorderStyle) {
1008 case FormBorderStyle.None:
1010 case FormBorderStyle.FixedToolWindow:
1011 case FormBorderStyle.SizableToolWindow:
1012 cp.ExStyle |= (int) WindowExStyles.WS_EX_TOOLWINDOW;
1015 cp.Style |= (int) WindowStyles.WS_OVERLAPPEDWINDOW;
1020 switch (FormBorderStyle) {
1021 case FormBorderStyle.Fixed3D: {
1022 cp.Style |= (int)(WindowStyles.WS_CAPTION | WindowStyles.WS_BORDER);
1023 cp.ExStyle |= (int)WindowExStyles.WS_EX_CLIENTEDGE;
1027 case FormBorderStyle.FixedDialog: {
1028 cp.Style |= (int)(WindowStyles.WS_CAPTION | WindowStyles.WS_BORDER);
1029 cp.ExStyle |= (int)(WindowExStyles.WS_EX_DLGMODALFRAME | WindowExStyles.WS_EX_CONTROLPARENT);
1033 case FormBorderStyle.FixedSingle: {
1034 cp.Style |= (int)(WindowStyles.WS_CAPTION | WindowStyles.WS_BORDER);
1038 case FormBorderStyle.FixedToolWindow: {
1039 cp.Style |= (int)(WindowStyles.WS_CAPTION | WindowStyles.WS_BORDER);
1040 cp.ExStyle |= (int)(WindowExStyles.WS_EX_TOOLWINDOW);
1044 case FormBorderStyle.Sizable: {
1045 cp.Style |= (int)(WindowStyles.WS_BORDER | WindowStyles.WS_THICKFRAME | WindowStyles.WS_CAPTION);
1049 case FormBorderStyle.SizableToolWindow: {
1050 cp.Style |= (int)(WindowStyles.WS_BORDER | WindowStyles.WS_THICKFRAME | WindowStyles.WS_CAPTION);
1051 cp.ExStyle |= (int)(WindowExStyles.WS_EX_TOOLWINDOW);
1055 case FormBorderStyle.None: {
1061 switch(window_state) {
1062 case FormWindowState.Maximized: {
1063 cp.Style |= (int)WindowStyles.WS_MAXIMIZE;
1067 case FormWindowState.Minimized: {
1068 cp.Style |= (int)WindowStyles.WS_MINIMIZE;
1074 cp.ExStyle |= (int) WindowExStyles.WS_EX_TOPMOST;
1077 if (ShowInTaskbar) {
1078 cp.ExStyle |= (int)WindowExStyles.WS_EX_APPWINDOW;
1082 cp.Style |= (int)WindowStyles.WS_MAXIMIZEBOX;
1086 cp.Style |= (int)WindowStyles.WS_MINIMIZEBOX;
1090 cp.Style |= (int)WindowStyles.WS_SYSMENU;
1093 if (HelpButton && !MaximizeBox && !MinimizeBox) {
1094 cp.ExStyle |= (int)WindowExStyles.WS_EX_CONTEXTHELP;
1098 cp.Style |= (int)WindowStyles.WS_VISIBLE;
1100 if (opacity < 1.0 || TransparencyKey != Color.Empty) {
1101 cp.ExStyle |= (int)WindowExStyles.WS_EX_LAYERED;
1104 if (!is_enabled && context == null) {
1105 cp.Style |= (int)(WindowStyles.WS_DISABLED);
1112 protected override ImeMode DefaultImeMode {
1114 return ImeMode.NoControl;
1118 protected override Size DefaultSize {
1120 return new Size (300, 300);
1124 protected Rectangle MaximizedBounds {
1126 if (maximized_bounds != Rectangle.Empty) {
1127 return maximized_bounds;
1129 return default_maximized_bounds;
1133 maximized_bounds = value;
1134 OnMaximizedBoundsChanged(EventArgs.Empty);
1135 if (IsHandleCreated) {
1136 XplatUI.SetWindowMinMax(Handle, maximized_bounds, minimum_size, maximum_size);
1140 #endregion // Protected Instance Properties
1142 #region Public Static Methods
1143 [EditorBrowsable(EditorBrowsableState.Advanced)]
1144 public static SizeF GetAutoScaleSize (Font font)
1146 return XplatUI.GetAutoScaleSize(font);
1149 #endregion // Public Static Methods
1151 #region Public Instance Methods
1152 internal SizeF GetAutoScaleSize (Graphics g, Font font)
1155 // The following constants come from the dotnet mailing list
1156 // discussion: http://discuss.develop.com/archives/wa.exe?A2=ind0203A&L=DOTNET&P=R3655
1158 // The magic number is "Its almost the length
1159 // of the string with a smattering added in
1160 // for compat with earlier code".
1163 string magic_string = "The quick brown fox jumped over the lazy dog.";
1164 double magic_number = 44.549996948242189;
1165 float width = (float) (g.MeasureString (magic_string, font).Width / magic_number);
1167 return new SizeF (width, font.Height);
1170 public void Activate() {
1173 // The docs say activate only activates if our app is already active
1174 if (IsHandleCreated) {
1176 MdiParent.ActivateMdiChild (this);
1177 } else if (IsMdiContainer) {
1178 SendControlFocus (mdi_container);
1180 active = ActiveForm;
1181 if ((active != null) && (this != active)) {
1182 XplatUI.Activate(window.Handle);
1188 public void AddOwnedForm(Form ownedForm) {
1189 if (!owned_forms.Contains(ownedForm)) {
1190 owned_forms.Add(ownedForm);
1192 ownedForm.Owner = this;
1195 public void Close () {
1203 FormClosingEventArgs ce = new FormClosingEventArgs (CloseReason.FormOwnerClosing, false);
1208 XplatUI.SendMessage(this.Handle, Msg.WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
1211 public void LayoutMdi(MdiLayout value) {
1212 if (mdi_container != null) {
1213 mdi_container.LayoutMdi(value);
1217 public void RemoveOwnedForm(Form ownedForm) {
1218 owned_forms.Remove(ownedForm);
1221 public void SetDesktopBounds(int x, int y, int width, int height) {
1222 DesktopBounds = new Rectangle(x, y, width, height);
1225 public void SetDesktopLocation(int x, int y) {
1226 DesktopLocation = new Point(x, y);
1229 public DialogResult ShowDialog() {
1230 return ShowDialog(this.owner);
1233 public DialogResult ShowDialog(IWin32Window ownerWin32) {
1236 IntPtr capture_window;
1240 if (ownerWin32 != null) {
1241 Control c = Control.FromHandle (ownerWin32.Handle);
1243 owner = c.TopLevelControl as Form;
1246 if (owner == this) {
1247 throw new InvalidOperationException("The 'ownerWin32' cannot be the form being shown.");
1251 throw new InvalidOperationException("The form is already displayed as a modal dialog.");
1255 throw new InvalidOperationException("Already visible forms cannot be displayed as a modal dialog. Set the Visible property to 'false' prior to calling Form.ShowDialog.");
1259 throw new InvalidOperationException("Cannot display a disabled form as modal dialog.");
1262 if (TopLevelControl != this) {
1263 throw new InvalidOperationException("Can only display TopLevel forms as modal dialog.");
1267 // Can't do this, will screw us in the modal loop
1268 form_parent_window.Parent = this.owner;
1271 // Release any captures
1272 XplatUI.GrabInfo(out capture_window, out confined, out area);
1273 if (capture_window != IntPtr.Zero) {
1274 XplatUI.UngrabWindow(capture_window);
1278 // Commented out; we instead let the Visible=true inside the runloop create the control
1279 // otherwise setting DialogResult inside any of the events that are triggered by the
1280 // create will not actually cause the form to not be displayed.
1281 // Leaving this comment here in case there was an actual purpose to creating the control
1283 if (!IsHandleCreated) {
1288 Application.RunLoop(true, new ApplicationContext(this));
1290 if (owner != null) {
1291 // Cannot use Activate(), it has a check for the current active window...
1292 XplatUI.Activate(owner.window.Handle);
1295 if (DialogResult != DialogResult.None) {
1296 return DialogResult;
1298 DialogResult = DialogResult.Cancel;
1299 return DialogResult.Cancel;
1302 public override string ToString() {
1303 return GetType().FullName.ToString() + ", Text: " + Text;
1305 #endregion // Public Instance Methods
1307 #region Protected Instance Methods
1308 protected void ActivateMdiChild(Form form) {
1309 if (!IsMdiContainer)
1311 mdi_container.ActivateChild (form);
1312 OnMdiChildActivate(EventArgs.Empty);
1315 [EditorBrowsable(EditorBrowsableState.Advanced)]
1316 protected override void AdjustFormScrollbars(bool displayScrollbars) {
1317 base.AdjustFormScrollbars (displayScrollbars);
1320 [EditorBrowsable(EditorBrowsableState.Advanced)]
1321 protected void ApplyAutoScaling()
1323 SizeF current_size_f = GetAutoScaleSize (DeviceContext, Font);
1324 Size current_size = new Size ((int) current_size_f.Width, (int) current_size_f.Height);
1328 if (current_size == autoscale_base_size)
1331 if (Environment.GetEnvironmentVariable ("MONO_MWF_SCALING") == "disable"){
1336 // I tried applying the Fudge height factor from:
1337 // http://blogs.msdn.com/mharsh/archive/2004/01/25/62621.aspx
1338 // but it makes things larger without looking better.
1340 if (current_size_f.Width != AutoScaleBaseSize.Width) {
1341 dx = current_size_f.Width / AutoScaleBaseSize.Width + 0.08f;
1346 if (current_size_f.Height != AutoScaleBaseSize.Height) {
1347 dy = current_size_f.Height / AutoScaleBaseSize.Height + 0.08f;
1354 AutoScaleBaseSize = current_size;
1357 protected void CenterToParent() {
1365 w = DefaultSize.Width;
1371 h = DefaultSize.Height;
1375 if (Parent != null) {
1377 } else if (owner != null) {
1381 if (owner != null) {
1382 this.Location = new Point(ctl.Left + ctl.Width / 2 - w /2, ctl.Top + ctl.Height / 2 - h / 2);
1386 protected void CenterToScreen() {
1394 w = DefaultSize.Width;
1400 h = DefaultSize.Height;
1403 XplatUI.GetDisplaySize(out DisplaySize);
1404 this.Location = new Point(DisplaySize.Width / 2 - w / 2, DisplaySize.Height / 2 - h / 2);
1407 [EditorBrowsable(EditorBrowsableState.Advanced)]
1408 protected override Control.ControlCollection CreateControlsInstance() {
1409 return base.CreateControlsInstance ();
1412 [EditorBrowsable(EditorBrowsableState.Advanced)]
1413 protected override void CreateHandle() {
1414 base.CreateHandle ();
1416 Application.AddForm (this);
1420 if ((XplatUI.SupportsTransparency() & TransparencySupport.Set) != 0) {
1421 if (allow_transparency) {
1422 XplatUI.SetWindowTransparency(Handle, Opacity, TransparencyKey);
1426 XplatUI.SetWindowMinMax(window.Handle, maximized_bounds, minimum_size, maximum_size);
1427 if ((FormBorderStyle != FormBorderStyle.FixedDialog) && (icon != null)) {
1428 XplatUI.SetIcon(window.Handle, icon);
1431 if ((owner != null) && (owner.IsHandleCreated)) {
1432 XplatUI.SetTopmost(window.Handle, owner.window.Handle, true);
1435 for (int i = 0; i < owned_forms.Count; i++) {
1436 if (owned_forms[i].IsHandleCreated)
1437 XplatUI.SetTopmost(owned_forms[i].window.Handle, window.Handle, true);
1440 if (window_manager != null && window_state != FormWindowState.Normal) {
1441 window_manager.SetWindowState (FormWindowState.Normal, window_state);
1446 [EditorBrowsable(EditorBrowsableState.Advanced)]
1447 protected override void DefWndProc(ref Message m) {
1448 base.DefWndProc (ref m);
1451 protected override void Dispose(bool disposing)
1453 for (int i = 0; i < owned_forms.Count; i++)
1454 ((Form)owned_forms[i]).Owner = null;
1456 owned_forms.Clear ();
1458 base.Dispose (disposing);
1460 Application.RemoveForm (this);
1463 [EditorBrowsable(EditorBrowsableState.Advanced)]
1464 protected virtual void OnActivated(EventArgs e)
1467 SelectActiveControl ();
1469 EventHandler eh = (EventHandler)(Events [ActivatedEvent]);
1474 [EditorBrowsable(EditorBrowsableState.Advanced)]
1475 protected virtual void OnClosed(EventArgs e) {
1476 EventHandler eh = (EventHandler)(Events [ClosedEvent]);
1481 [EditorBrowsable(EditorBrowsableState.Advanced)]
1482 protected virtual void OnClosing(System.ComponentModel.CancelEventArgs e) {
1483 CancelEventHandler eh = (CancelEventHandler)(Events [ClosingEvent]);
1488 [EditorBrowsable(EditorBrowsableState.Advanced)]
1489 protected override void OnCreateControl() {
1490 base.OnCreateControl ();
1493 XplatUI.SetMenu(window.Handle, menu);
1496 OnLoad(EventArgs.Empty);
1498 SelectActiveControl ();
1500 // Send initial location
1501 OnLocationChanged(EventArgs.Empty);
1503 if (IsMdiContainer) {
1504 mdi_container.LayoutMdi (MdiLayout.Cascade);
1508 [EditorBrowsable(EditorBrowsableState.Advanced)]
1509 protected virtual void OnDeactivate(EventArgs e) {
1510 EventHandler eh = (EventHandler)(Events [DeactivateEvent]);
1515 [EditorBrowsable(EditorBrowsableState.Advanced)]
1516 protected override void OnFontChanged(EventArgs e) {
1517 base.OnFontChanged (e);
1520 [EditorBrowsable(EditorBrowsableState.Advanced)]
1521 protected override void OnHandleCreated(EventArgs e) {
1522 XplatUI.SetBorderStyle(window.Handle, form_border_style);
1523 base.OnHandleCreated (e);
1526 [EditorBrowsable(EditorBrowsableState.Advanced)]
1527 protected override void OnHandleDestroyed(EventArgs e) {
1528 base.OnHandleDestroyed (e);
1531 [EditorBrowsable(EditorBrowsableState.Advanced)]
1532 protected virtual void OnInputLanguageChanged(InputLanguageChangedEventArgs e) {
1533 InputLanguageChangedEventHandler eh = (InputLanguageChangedEventHandler)(Events [InputLanguageChangedEvent]);
1538 [EditorBrowsable(EditorBrowsableState.Advanced)]
1539 protected virtual void OnInputLanguageChanging(InputLanguageChangingEventArgs e) {
1540 InputLanguageChangingEventHandler eh = (InputLanguageChangingEventHandler)(Events [InputLanguageChangingEvent]);
1545 [EditorBrowsable(EditorBrowsableState.Advanced)]
1546 protected virtual void OnLoad(EventArgs e) {
1548 ApplyAutoScaling ();
1552 EventHandler eh = (EventHandler)(Events [LoadEvent]);
1557 switch (StartPosition) {
1558 case FormStartPosition.CenterScreen:
1559 this.CenterToScreen();
1561 case FormStartPosition.CenterParent:
1562 this.CenterToParent ();
1564 case FormStartPosition.Manual:
1565 Left = CreateParams.X;
1566 Top = CreateParams.Y;
1573 [EditorBrowsable(EditorBrowsableState.Advanced)]
1574 protected virtual void OnMaximizedBoundsChanged(EventArgs e) {
1575 EventHandler eh = (EventHandler)(Events [MaximizedBoundsChangedEvent]);
1580 [EditorBrowsable(EditorBrowsableState.Advanced)]
1581 protected virtual void OnMaximumSizeChanged(EventArgs e) {
1582 EventHandler eh = (EventHandler)(Events [MaximumSizeChangedEvent]);
1587 [EditorBrowsable(EditorBrowsableState.Advanced)]
1588 protected virtual void OnMdiChildActivate(EventArgs e) {
1589 EventHandler eh = (EventHandler)(Events [MdiChildActivateEvent]);
1594 [EditorBrowsable(EditorBrowsableState.Advanced)]
1595 protected virtual void OnMenuComplete(EventArgs e) {
1596 EventHandler eh = (EventHandler)(Events [MenuCompleteEvent]);
1601 [EditorBrowsable(EditorBrowsableState.Advanced)]
1602 protected virtual void OnMenuStart(EventArgs e) {
1603 EventHandler eh = (EventHandler)(Events [MenuStartEvent]);
1608 [EditorBrowsable(EditorBrowsableState.Advanced)]
1609 protected virtual void OnMinimumSizeChanged(EventArgs e) {
1610 EventHandler eh = (EventHandler)(Events [MinimumSizeChangedEvent]);
1615 [EditorBrowsable(EditorBrowsableState.Advanced)]
1616 protected override void OnPaint (PaintEventArgs pevent) {
1617 base.OnPaint (pevent);
1620 [EditorBrowsable(EditorBrowsableState.Advanced)]
1621 protected override void OnResize(EventArgs e) {
1624 if (this.IsMdiChild && ParentForm != null) {
1625 ParentForm.PerformLayout();
1626 ParentForm.Size = ParentForm.Size;
1630 [EditorBrowsable(EditorBrowsableState.Advanced)]
1631 protected override void OnStyleChanged(EventArgs e) {
1632 base.OnStyleChanged (e);
1635 [EditorBrowsable(EditorBrowsableState.Advanced)]
1636 protected override void OnTextChanged(EventArgs e) {
1637 base.OnTextChanged (e);
1639 if (mdi_container != null)
1640 mdi_container.SetParentText(true);
1643 [EditorBrowsable(EditorBrowsableState.Advanced)]
1644 protected override void OnVisibleChanged(EventArgs e) {
1645 base.OnVisibleChanged (e);
1648 if (window_manager != null)
1649 window_manager.SetWindowState (WindowState, WindowState);
1653 protected override bool ProcessCmdKey(ref Message msg, Keys keyData) {
1654 if (base.ProcessCmdKey (ref msg, keyData)) {
1658 // Give our menu a shot
1659 if (ActiveMenu != null) {
1660 return ActiveMenu.ProcessCmdKey(ref msg, keyData);
1666 // LAMESPEC - Not documented that Form overrides ProcessDialogChar; class-status showed
1667 [EditorBrowsable (EditorBrowsableState.Advanced)]
1668 protected override bool ProcessDialogChar(char charCode) {
1669 return base.ProcessDialogChar (charCode);
1672 protected override bool ProcessDialogKey(Keys keyData) {
1673 if ((keyData & Keys.Modifiers) == 0) {
1674 if (keyData == Keys.Enter) {
1675 IntPtr window = XplatUI.GetFocus ();
1676 Control c = Control.FromHandle (window);
1677 if (c is Button && c.FindForm () == this) {
1678 ((Button)c).PerformClick ();
1681 else if (accept_button != null) {
1682 accept_button.PerformClick();
1685 } else if (keyData == Keys.Escape && cancel_button != null) {
1686 cancel_button.PerformClick();
1690 return base.ProcessDialogKey(keyData);
1693 protected override bool ProcessKeyPreview(ref Message msg) {
1695 if (ProcessKeyEventArgs(ref msg)) {
1699 return base.ProcessKeyPreview (ref msg);
1702 protected override bool ProcessTabKey(bool forward) {
1703 return SelectNextControl(ActiveControl, forward, true, true, true);
1706 [EditorBrowsable(EditorBrowsableState.Advanced)]
1707 protected override void ScaleCore(float dx, float dy) {
1711 // We can't scale max or min windows
1712 if (WindowState == FormWindowState.Normal) {
1713 // We cannot call base since base also adjusts X/Y, but
1714 // a form is toplevel and doesn't move
1718 if (!GetStyle(ControlStyles.FixedWidth)) {
1719 size.Width = (int)(size.Width * dx);
1722 if (!GetStyle(ControlStyles.FixedHeight)) {
1723 size.Height = (int)(size.Height * dy);
1729 /* Now scale our children */
1730 Control [] controls = Controls.GetAllControls ();
1731 for (int i=0; i < controls.Length; i++) {
1732 controls[i].Scale(dx, dy);
1741 protected override void Select(bool directed, bool forward) {
1745 base.SelectNextControl(null, forward, true, true, true);
1748 parent = this.ParentForm;
1749 if (parent != null) {
1750 parent.ActiveControl = this;
1756 [EditorBrowsable(EditorBrowsableState.Advanced)]
1757 protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
1758 base.SetBoundsCore (x, y, width, height, specified);
1761 [EditorBrowsable(EditorBrowsableState.Advanced)]
1762 protected override void SetClientSizeCore(int x, int y) {
1763 if ((minimum_size.Width != 0) && (x < minimum_size.Width)) {
1764 x = minimum_size.Width;
1765 } else if ((maximum_size.Width != 0) && (x > maximum_size.Width)) {
1766 x = maximum_size.Width;
1769 if ((minimum_size.Height != 0) && (y < minimum_size.Height)) {
1770 y = minimum_size.Height;
1771 } else if ((maximum_size.Height != 0) && (y > maximum_size.Height)) {
1772 y = maximum_size.Height;
1775 Rectangle ClientRect = new Rectangle(0, 0, x, y);
1776 Rectangle WindowRect;
1777 CreateParams cp = this.CreateParams;
1779 clientsize_set = new Size(x, y);
1781 if (XplatUI.CalculateWindowRect(ref ClientRect, cp.Style, cp.ExStyle, cp.menu, out WindowRect)) {
1782 SetBounds(bounds.X, bounds.Y, WindowRect.Width, WindowRect.Height, BoundsSpecified.Size);
1786 [EditorBrowsable(EditorBrowsableState.Advanced)]
1787 protected override void SetVisibleCore(bool value) {
1788 is_changing_visible_state = true;
1789 has_been_visible = value || has_been_visible;
1790 base.SetVisibleCore (value);
1791 is_changing_visible_state = false;
1794 protected override void UpdateDefaultButton() {
1795 base.UpdateDefaultButton ();
1798 [EditorBrowsable(EditorBrowsableState.Advanced)]
1799 protected override void WndProc(ref Message m) {
1801 if (window_manager != null && window_manager.HandleMessage (ref m)) {
1805 switch((Msg)m.Msg) {
1806 case Msg.WM_DESTROY: {
1807 base.WndProc(ref m);
1808 if (!RecreatingHandle) {
1809 this.closing = true;
1814 case Msg.WM_CLOSE_INTERNAL: {
1819 case Msg.WM_CLOSE: {
1820 Form act = Form.ActiveForm;
1821 if (act != null && act != this && act.Modal == true) {
1825 CancelEventArgs args = new CancelEventArgs ();
1827 if (mdi_container != null) {
1828 foreach (Form mdi_child in mdi_container.MdiChildren) {
1829 mdi_child.OnClosing (args);
1836 OnClosed (EventArgs.Empty);
1843 DialogResult = DialogResult.None;
1846 OnClosed (EventArgs.Empty);
1855 case Msg.WM_WINDOWPOSCHANGED: {
1856 if (WindowState != FormWindowState.Minimized) {
1857 base.WndProc(ref m);
1863 case Msg.WM_SYSCOMMAND: {
1864 // Let *Strips know the app's title bar was clicked
1865 if (XplatUI.IsEnabled (Handle))
1866 ToolStripManager.FireAppClicked ();
1868 base.WndProc(ref m);
1873 case Msg.WM_ACTIVATE: {
1874 if (m.WParam != (IntPtr)WindowActiveFlags.WA_INACTIVE) {
1875 OnActivated(EventArgs.Empty);
1877 OnDeactivate(EventArgs.Empty);
1882 case Msg.WM_KILLFOCUS: {
1883 base.WndProc(ref m);
1887 case Msg.WM_SETFOCUS: {
1888 if (ActiveControl != null && ActiveControl != this) {
1889 ActiveControl.Focus();
1890 return; // FIXME - do we need to run base.WndProc, even though we just changed focus?
1892 base.WndProc(ref m);
1897 case Msg.WM_NCLBUTTONDOWN: {
1898 if (XplatUI.IsEnabled (Handle) && ActiveMenu != null) {
1899 ActiveMenu.OnMouseDown(this, new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()), mouse_clicks, Control.MousePosition.X, Control.MousePosition.Y, 0));
1902 if (ActiveMaximizedMdiChild != null) {
1903 if (ActiveMaximizedMdiChild.HandleMenuMouseDown (ActiveMenu,
1904 LowOrder ((int) m.LParam.ToInt32 ()),
1905 HighOrder ((int) m.LParam.ToInt32 ()))) {
1906 // Don't let base process this message, otherwise we won't
1907 // get a WM_NCLBUTTONUP.
1911 base.WndProc(ref m);
1914 case Msg.WM_NCLBUTTONUP: {
1915 if (ActiveMaximizedMdiChild != null) {
1916 ActiveMaximizedMdiChild.HandleMenuMouseUp (ActiveMenu,
1917 LowOrder ((int)m.LParam.ToInt32 ()),
1918 HighOrder ((int)m.LParam.ToInt32 ()));
1920 base.WndProc (ref m);
1924 case Msg.WM_NCMOUSELEAVE: {
1925 if (ActiveMaximizedMdiChild != null) {
1926 ActiveMaximizedMdiChild.HandleMenuMouseLeave(ActiveMenu,
1927 LowOrder((int)m.LParam.ToInt32()),
1928 HighOrder((int)m.LParam.ToInt32()));
1930 base.WndProc(ref m);
1934 case Msg.WM_NCMOUSEMOVE: {
1935 if (XplatUI.IsEnabled (Handle) && ActiveMenu != null) {
1936 ActiveMenu.OnMouseMove(this, new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()), mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()), 0));
1939 if (ActiveMaximizedMdiChild != null) {
1940 ActiveMaximizedMdiChild.HandleMenuMouseMove (ActiveMenu,
1941 LowOrder ((int)m.LParam.ToInt32 ()),
1942 HighOrder ((int)m.LParam.ToInt32 ()));
1944 base.WndProc(ref m);
1948 case Msg.WM_NCPAINT: {
1949 if (ActiveMenu != null) {
1953 pe = XplatUI.PaintEventStart(Handle, false);
1954 pnt = XplatUI.GetMenuOrigin(window.Handle);
1956 // The entire menu has to be in the clip rectangle because the
1957 // control buttons are right-aligned and otherwise they would
1958 // stay painted when the window gets resized.
1959 Rectangle clip = new Rectangle (pnt.X, pnt.Y, ClientSize.Width, 0);
1960 clip = Rectangle.Union(clip, pe.ClipRectangle);
1962 pe.Graphics.SetClip(clip);
1964 ActiveMenu.Draw (pe, new Rectangle (pnt.X, pnt.Y, ClientSize.Width, 0));
1966 if (ActiveMaximizedMdiChild != null) {
1967 ActiveMaximizedMdiChild.DrawMaximizedButtons (ActiveMenu, pe);
1970 XplatUI.PaintEventEnd(Handle, false);
1973 base.WndProc(ref m);
1977 case Msg.WM_NCCALCSIZE: {
1978 XplatUIWin32.NCCALCSIZE_PARAMS ncp;
1980 if ((ActiveMenu != null) && (m.WParam == (IntPtr)1)) {
1981 ncp = (XplatUIWin32.NCCALCSIZE_PARAMS)Marshal.PtrToStructure(m.LParam, typeof(XplatUIWin32.NCCALCSIZE_PARAMS));
1984 ncp.rgrc1.top += ThemeEngine.Current.CalcMenuBarSize (DeviceContext, ActiveMenu, ncp.rgrc1.right - ncp.rgrc1.left);
1985 Marshal.StructureToPtr(ncp, m.LParam, true);
1991 case Msg.WM_MOUSEMOVE: {
1992 if (XplatUI.IsEnabled (Handle) && active_tracker != null) {
1993 MouseEventArgs args;
1995 args = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
1996 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()), 0);
1997 active_tracker.OnMotion(new MouseEventArgs (args.Button, args.Clicks, Control.MousePosition.X, Control.MousePosition.Y, args.Delta));
2000 base.WndProc(ref m);
2004 case Msg.WM_LBUTTONDOWN:
2005 case Msg.WM_MBUTTONDOWN:
2006 case Msg.WM_RBUTTONDOWN: {
2007 if (XplatUI.IsEnabled (Handle) && active_tracker != null) {
2008 MouseEventArgs args;
2010 args = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
2011 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()), 0);
2012 active_tracker.OnMouseDown(new MouseEventArgs (args.Button, args.Clicks, Control.MousePosition.X, Control.MousePosition.Y, args.Delta));
2015 base.WndProc(ref m);
2019 case Msg.WM_LBUTTONUP:
2020 case Msg.WM_MBUTTONUP:
2021 case Msg.WM_RBUTTONUP: {
2022 if (XplatUI.IsEnabled (Handle) && active_tracker != null) {
2023 MouseEventArgs args;
2024 MouseButtons mb = FromParamToMouseButtons ((int) m.WParam.ToInt32());
2026 // We add in the button that was released (not sent in WParam)
2027 switch((Msg)m.Msg) {
2028 case Msg.WM_LBUTTONUP:
2029 mb |= MouseButtons.Left;
2031 case Msg.WM_MBUTTONUP:
2032 mb |= MouseButtons.Middle;
2034 case Msg.WM_RBUTTONUP:
2035 mb |= MouseButtons.Right;
2039 args = new MouseEventArgs (mb, mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()), 0);
2040 active_tracker.OnMouseUp(new MouseEventArgs (args.Button, args.Clicks, Control.MousePosition.X, Control.MousePosition.Y, args.Delta));
2044 base.WndProc(ref m);
2048 case Msg.WM_GETMINMAXINFO: {
2051 if (m.LParam != IntPtr.Zero) {
2052 mmi = (MINMAXINFO)Marshal.PtrToStructure(m.LParam, typeof(MINMAXINFO));
2054 default_maximized_bounds = new Rectangle(mmi.ptMaxPosition.x, mmi.ptMaxPosition.y, mmi.ptMaxSize.x, mmi.ptMaxSize.y);
2055 if (maximized_bounds != Rectangle.Empty) {
2056 mmi.ptMaxPosition.x = maximized_bounds.Left;
2057 mmi.ptMaxPosition.y = maximized_bounds.Top;
2058 mmi.ptMaxSize.x = maximized_bounds.Width;
2059 mmi.ptMaxSize.y = maximized_bounds.Height;
2062 if (minimum_size != Size.Empty) {
2063 mmi.ptMinTrackSize.x = minimum_size.Width;
2064 mmi.ptMinTrackSize.y = minimum_size.Height;
2067 if (maximum_size != Size.Empty) {
2068 mmi.ptMaxTrackSize.x = maximum_size.Width;
2069 mmi.ptMaxTrackSize.y = maximum_size.Height;
2071 Marshal.StructureToPtr(mmi, m.LParam, false);
2077 case Msg.WM_MOUSEACTIVATE: {
2078 // Let *Strips know the form or another control has been clicked
2079 if (XplatUI.IsEnabled (Handle))
2080 ToolStripManager.FireAppClicked ();
2082 base.WndProc (ref m);
2086 case Msg.WM_ACTIVATEAPP: {
2087 // Let *Strips know the app lost focus
2088 if (m.WParam == (IntPtr)0)
2089 if (XplatUI.IsEnabled (Handle))
2090 ToolStripManager.FireAppFocusChanged (this);
2092 base.WndProc (ref m);
2098 base.WndProc (ref m);
2103 #endregion // Protected Instance Methods
2105 internal void RemoveWindowManager ()
2107 window_manager = null;
2110 internal override void CheckAcceptButton()
2112 if (accept_button != null) {
2113 Button a_button = accept_button as Button;
2115 if (ActiveControl == a_button)
2118 if (ActiveControl is Button) {
2119 a_button.paint_as_acceptbutton = false;
2123 a_button.paint_as_acceptbutton = true;
2130 static object ActivatedEvent = new object ();
2131 static object ClosedEvent = new object ();
2132 static object ClosingEvent = new object ();
2133 static object DeactivateEvent = new object ();
2134 static object InputLanguageChangedEvent = new object ();
2135 static object InputLanguageChangingEvent = new object ();
2136 static object LoadEvent = new object ();
2137 static object MaximizedBoundsChangedEvent = new object ();
2138 static object MaximumSizeChangedEvent = new object ();
2139 static object MdiChildActivateEvent = new object ();
2140 static object MenuCompleteEvent = new object ();
2141 static object MenuStartEvent = new object ();
2142 static object MinimumSizeChangedEvent = new object ();
2144 public event EventHandler Activated {
2145 add { Events.AddHandler (ActivatedEvent, value); }
2146 remove { Events.RemoveHandler (ActivatedEvent, value); }
2149 public event EventHandler Closed {
2150 add { Events.AddHandler (ClosedEvent, value); }
2151 remove { Events.RemoveHandler (ClosedEvent, value); }
2154 public event CancelEventHandler Closing {
2155 add { Events.AddHandler (ClosingEvent, value); }
2156 remove { Events.RemoveHandler (ClosingEvent, value); }
2159 public event EventHandler Deactivate {
2160 add { Events.AddHandler (DeactivateEvent, value); }
2161 remove { Events.RemoveHandler (DeactivateEvent, value); }
2164 public event InputLanguageChangedEventHandler InputLanguageChanged {
2165 add { Events.AddHandler (InputLanguageChangedEvent, value); }
2166 remove { Events.RemoveHandler (InputLanguageChangedEvent, value); }
2169 public event InputLanguageChangingEventHandler InputLanguageChanging {
2170 add { Events.AddHandler (InputLanguageChangingEvent, value); }
2171 remove { Events.RemoveHandler (InputLanguageChangingEvent, value); }
2174 public event EventHandler Load {
2175 add { Events.AddHandler (LoadEvent, value); }
2176 remove { Events.RemoveHandler (LoadEvent, value); }
2179 public event EventHandler MaximizedBoundsChanged {
2180 add { Events.AddHandler (MaximizedBoundsChangedEvent, value); }
2181 remove { Events.RemoveHandler (MaximizedBoundsChangedEvent, value); }
2184 public event EventHandler MaximumSizeChanged {
2185 add { Events.AddHandler (MaximumSizeChangedEvent, value); }
2186 remove { Events.RemoveHandler (MaximumSizeChangedEvent, value); }
2189 public event EventHandler MdiChildActivate {
2190 add { Events.AddHandler (MdiChildActivateEvent, value); }
2191 remove { Events.RemoveHandler (MdiChildActivateEvent, value); }
2194 public event EventHandler MenuComplete {
2195 add { Events.AddHandler (MenuCompleteEvent, value); }
2196 remove { Events.RemoveHandler (MenuCompleteEvent, value); }
2199 public event EventHandler MenuStart {
2200 add { Events.AddHandler (MenuStartEvent, value); }
2201 remove { Events.RemoveHandler (MenuStartEvent, value); }
2204 public event EventHandler MinimumSizeChanged {
2205 add { Events.AddHandler (MinimumSizeChangedEvent, value); }
2206 remove { Events.RemoveHandler (MinimumSizeChangedEvent, value); }
2211 [EditorBrowsable(EditorBrowsableState.Never)]
2212 public new event EventHandler TabIndexChanged {
2213 add { base.TabIndexChanged += value; }
2214 remove { base.TabIndexChanged -= value; }
2216 #endregion // Events
2219 public override string Text {
2229 public new Point Location {
2231 return base.Location;
2235 base.Location = value;
2239 static object FormClosingEvent = new object ();
2240 static object FormClosedEvent = new object ();
2242 public event FormClosingEventHandler FormClosing {
2243 add { Events.AddHandler (FormClosingEvent, value); }
2244 remove { Events.RemoveHandler (FormClosingEvent, value); }
2247 public event FormClosedEventHandler FormClosed {
2248 add { Events.AddHandler (FormClosedEvent, value); }
2249 remove { Events.RemoveHandler (FormClosedEvent, value); }
2252 protected virtual void OnFormClosing (FormClosingEventArgs e)
2254 FormClosingEventHandler eh = (FormClosingEventHandler)(Events [FormClosingEvent]);