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 [ClassInterface (ClassInterfaceType.AutoDispatch)]
44 [InitializationEvent ("Load")]
48 public class Form : ContainerControl {
49 #region Local Variables
50 internal bool closing;
51 FormBorderStyle form_border_style;
52 private bool autoscale;
53 private Size clientsize_set;
54 private Size autoscale_base_size;
55 private bool allow_transparency;
56 private static Icon default_icon;
57 internal bool is_modal;
58 internal FormWindowState window_state;
59 private bool control_box;
60 private bool minimize_box;
61 private bool maximize_box;
62 private bool help_button;
63 private bool show_in_taskbar;
65 private IButtonControl accept_button;
66 private IButtonControl cancel_button;
67 private DialogResult dialog_result;
68 private FormStartPosition start_position;
70 private Form.ControlCollection owned_forms;
71 private MdiClient mdi_container;
72 internal InternalWindowManager window_manager;
73 private Form mdi_parent;
74 private bool key_preview;
75 private MainMenu menu;
77 private Size maximum_size;
78 private Size minimum_size;
79 private SizeGripStyle size_grip_style;
80 private Rectangle maximized_bounds;
81 private Rectangle default_maximized_bounds;
82 private double opacity;
83 internal ApplicationContext context;
84 Color transparency_key;
85 internal MenuTracker active_tracker;
86 private bool is_loaded;
87 internal bool is_changing_visible_state;
88 internal bool has_been_visible;
91 private MenuStrip main_menu_strip;
93 #endregion // Local Variables
95 #region Private & Internal Methods
98 default_icon = Locale.GetResource("mono.ico") as Icon;
101 // warning: this is only hooked up when an mdi container is created.
102 private void ControlAddedHandler (object sender, ControlEventArgs e)
104 if (mdi_container != null) {
105 mdi_container.SendToBack ();
109 private void SelectActiveControl ()
111 if (this.IsMdiContainer) {
112 SendControlFocus (this.mdi_container);
116 if (this.ActiveControl == null) {
119 // This visible hack is to work around CanSelect always being false if one of the parents
120 // is not visible; and we by default create Form invisible...
121 visible = this.is_visible;
122 this.is_visible = true;
124 if (SelectNextControl (this, true, true, true, true) == false) {
128 this.is_visible = visible;
130 Select (ActiveControl);
133 #endregion // Private & Internal Methods
135 #region Public Classes
136 public new class ControlCollection : Control.ControlCollection {
139 public ControlCollection(Form owner) : base(owner) {
140 this.form_owner = owner;
143 public override void Add(Control value) {
144 if (Contains (value))
147 ((Form)value).owner=form_owner;
150 public override void Remove(Control value) {
151 ((Form)value).owner = null;
155 #endregion // Public Classes
157 #region Public Constructor & Destructor
160 SizeF current_scale = GetAutoScaleSize (DeviceContext, Font);
163 autoscale_base_size = new Size ((int)current_scale.Width, (int) current_scale.Height);
164 allow_transparency = false;
167 dialog_result = DialogResult.None;
168 start_position = FormStartPosition.WindowsDefaultLocation;
169 form_border_style = FormBorderStyle.Sizable;
170 window_state = FormWindowState.Normal;
175 minimum_size = Size.Empty;
176 maximum_size = Size.Empty;
177 clientsize_set = Size.Empty;
182 show_in_taskbar = true;
185 size_grip_style = SizeGripStyle.Auto;
186 maximized_bounds = Rectangle.Empty;
187 default_maximized_bounds = Rectangle.Empty;
188 owned_forms = new Form.ControlCollection(this);
189 transparency_key = Color.Empty;
191 // FIXME: this should disappear just as soon as the handle creation is done in the right place (here is too soon()
195 #endregion // Public Constructor & Destructor
197 #region Public Static Properties
199 public static Form ActiveForm {
203 active = FromHandle(XplatUI.GetActive());
205 if (active != null) {
206 if ( !(active is Form)) {
209 parent = active.Parent;
210 while (parent != null) {
211 if (parent is Form) {
214 parent = parent.Parent;
224 #endregion // Public Static Properties
226 #region Public Instance Properties
228 public IButtonControl AcceptButton {
230 return accept_button;
234 accept_button = value;
240 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
241 public bool AllowTransparency {
243 return allow_transparency;
247 if (value == allow_transparency) {
251 allow_transparency = value;
254 if (IsHandleCreated) {
255 if ((XplatUI.SupportsTransparency() & TransparencySupport.Set) != 0) {
256 XplatUI.SetWindowTransparency(Handle, Opacity, TransparencyKey);
259 UpdateStyles(); // Remove the WS_EX_LAYERED style
267 [EditorBrowsable (EditorBrowsableState.Never)]
268 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
269 [Obsolete ("This property has been deprecated in favor of AutoScaleMode.")]
273 [MWFCategory("Layout")]
274 public bool AutoScale {
285 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
286 [EditorBrowsable(EditorBrowsableState.Never)]
288 [EditorBrowsable(EditorBrowsableState.Advanced)]
292 public virtual Size AutoScaleBaseSize {
294 return autoscale_base_size;
298 autoscale_base_size = value;
303 public override bool AutoScroll {
305 return base.AutoScroll;
308 base.AutoScroll = value;
312 public override Color BackColor {
314 /* we don't let parents override our
315 default background color for forms.
316 this fixes the default color for mdi
318 if (background_color.IsEmpty)
319 return DefaultBackColor;
321 return background_color;
324 base.BackColor = value;
329 public IButtonControl CancelButton {
331 return cancel_button;
335 cancel_button = value;
336 if (cancel_button != null && cancel_button.DialogResult == DialogResult.None)
337 cancel_button.DialogResult = DialogResult.Cancel;
341 // new property so we can change the DesignerSerializationVisibility
342 [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
344 public new Size ClientSize {
345 get { return base.ClientSize; }
346 set { base.ClientSize = value; }
350 [MWFCategory("Window Style")]
351 public bool ControlBox {
357 if (control_box != value) {
365 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
366 public Rectangle DesktopBounds {
368 return new Rectangle(Location, Size);
377 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
378 public Point DesktopLocation {
389 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
390 public DialogResult DialogResult {
392 return dialog_result;
396 if (value < DialogResult.None || value > DialogResult.No)
397 throw new InvalidEnumArgumentException ("value", (int) value,
398 typeof (DialogResult));
400 dialog_result = value;
401 closing = (dialog_result != DialogResult.None && is_modal);
405 [DefaultValue(FormBorderStyle.Sizable)]
407 [MWFCategory("Appearance")]
408 public FormBorderStyle FormBorderStyle {
410 return form_border_style;
413 form_border_style = value;
415 if (window_manager == null) {
416 if (IsHandleCreated) {
417 XplatUI.SetBorderStyle(window.Handle, form_border_style);
420 window_manager.UpdateBorderStyle (value);
427 [DefaultValue(false)]
428 [MWFCategory("Window Style")]
429 public bool HelpButton {
435 if (help_button != value) {
444 [MWFCategory("Window Style")]
454 if (IsHandleCreated) {
455 XplatUI.SetIcon(Handle, icon == null ? default_icon : icon);
462 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
463 public bool IsMdiChild {
465 return mdi_parent != null;
469 [DefaultValue(false)]
470 [MWFCategory("Window Style")]
471 public bool IsMdiContainer {
473 return mdi_container != null;
477 if (value && mdi_container == null) {
478 mdi_container = new MdiClient ();
479 Controls.Add(mdi_container);
480 ControlAdded += new ControlEventHandler (ControlAddedHandler);
481 mdi_container.SendToBack ();
482 mdi_container.SetParentText (true);
483 } else if (!value && mdi_container != null) {
484 Controls.Remove(mdi_container);
485 mdi_container = null;
491 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
492 public Form ActiveMdiChild {
496 return (Form) mdi_container.ActiveMdiChild;
501 [EditorBrowsable(EditorBrowsableState.Advanced)]
502 public bool IsRestrictedWindow {
508 [DefaultValue(false)]
509 public bool KeyPreview {
520 [DefaultValue (null)]
521 [TypeConverter (typeof (ReferenceConverter))]
522 public MenuStrip MainMenuStrip {
523 get { return this.main_menu_strip; }
525 if (this.main_menu_strip != value) {
526 this.main_menu_strip = value;
527 this.main_menu_strip.RefreshMdiItems ();
534 [MWFCategory("Window Style")]
535 public bool MaximizeBox {
540 if (maximize_box != value) {
541 maximize_box = value;
542 if (IsHandleCreated) {
550 [DefaultValue("{Width=0, Height=0}")]
552 [RefreshProperties(RefreshProperties.Repaint)]
553 [MWFCategory("Layout")]
564 if (maximum_size != value) {
565 maximum_size = value;
566 OnMaximumSizeChanged(EventArgs.Empty);
567 if (IsHandleCreated) {
568 XplatUI.SetWindowMinMax(Handle, maximized_bounds, minimum_size, maximum_size);
575 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
576 public Form[] MdiChildren {
578 if (mdi_container != null)
579 return mdi_container.MdiChildren;
586 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
587 public Form MdiParent {
593 if (value != null && !value.IsMdiContainer)
594 throw new ArgumentException ();
596 if (mdi_parent != null) {
597 mdi_parent.MdiContainer.Controls.Remove (this);
602 window_manager = new MdiWindowManager (this,
603 mdi_parent.MdiContainer);
604 mdi_parent.MdiContainer.Controls.Add (this);
605 mdi_parent.MdiContainer.Controls.SetChildIndex (this, 0);
609 } else if (mdi_parent != null) {
612 // Create a new window manager
613 window_manager = null;
614 FormBorderStyle = form_border_style;
621 internal MenuTracker ActiveTracker {
622 get { return active_tracker; }
624 if (value == active_tracker)
627 Capture = value != null;
628 active_tracker = value;
632 internal MdiClient MdiContainer {
633 get { return mdi_container; }
636 internal InternalWindowManager WindowManager {
637 get { return window_manager; }
642 [TypeConverter (typeof (ReferenceConverter))]
645 [MWFCategory("Window Style")]
646 public MainMenu Menu {
655 if (menu != null && !IsMdiChild) {
658 if (IsHandleCreated) {
659 XplatUI.SetMenu (window.Handle, menu);
662 if (clientsize_set != Size.Empty) {
663 SetClientSizeCore(clientsize_set.Width, clientsize_set.Height);
665 UpdateBounds (bounds.X, bounds.Y, bounds.Width, bounds.Height, ClientSize.Width, ClientSize.Height -
666 ThemeEngine.Current.CalcMenuBarSize (DeviceContext, menu, ClientSize.Width));
675 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
676 [EditorBrowsable(EditorBrowsableState.Advanced)]
677 public MainMenu MergedMenu {
679 if (!IsMdiChild || window_manager == null)
681 return ((MdiWindowManager) window_manager).MergedMenu;
685 // This is the menu in display and being used because of merging this can
686 // be different then the menu that is actually assosciated with the form
687 internal MainMenu ActiveMenu {
692 if (IsMdiContainer && mdi_container.Controls.Count > 0 &&
693 ((Form) mdi_container.Controls [0]).WindowState == FormWindowState.Maximized) {
694 MdiWindowManager wm = (MdiWindowManager) ((Form) mdi_container.Controls [0]).WindowManager;
695 return wm.MaximizedMenu;
698 Form amc = ActiveMdiChild;
699 if (amc == null || amc.Menu == null)
701 return amc.MergedMenu;
705 internal MdiWindowManager ActiveMaximizedMdiChild {
707 Form child = ActiveMdiChild;
710 if (child.WindowManager == null || child.window_state != FormWindowState.Maximized)
712 return (MdiWindowManager) child.WindowManager;
717 [MWFCategory("Window Style")]
718 public bool MinimizeBox {
723 if (minimize_box != value) {
724 minimize_box = value;
725 if (IsHandleCreated) {
734 [DefaultValue("{Width=0, Height=0}")]
737 [RefreshProperties(RefreshProperties.Repaint)]
738 [MWFCategory("Layout")]
749 if (minimum_size != value) {
750 minimum_size = value;
752 if ((Size.Width < value.Width) || (Size.Height < value.Height)) {
753 Size = new Size(Math.Max(Size.Width, value.Width), Math.Max(Size.Height, value.Height));
757 OnMinimumSizeChanged(EventArgs.Empty);
758 if (IsHandleCreated) {
759 XplatUI.SetWindowMinMax(Handle, maximized_bounds, minimum_size, maximum_size);
766 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
774 [TypeConverter(typeof(OpacityConverter))]
775 [MWFCategory("Window Style")]
776 public double Opacity {
778 if (IsHandleCreated) {
779 if ((XplatUI.SupportsTransparency () & TransparencySupport.Get) != 0)
780 return XplatUI.GetWindowTransparency (Handle);
789 AllowTransparency = true;
791 if (IsHandleCreated) {
793 if ((XplatUI.SupportsTransparency () & TransparencySupport.Set) != 0)
794 XplatUI.SetWindowTransparency(Handle, opacity, TransparencyKey);
801 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
802 public Form[] OwnedForms {
806 form_list = new Form[owned_forms.Count];
808 for (int i=0; i<owned_forms.Count; i++) {
809 form_list[i] = (Form)owned_forms[i];
817 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
824 if (owner != value) {
826 owner.RemoveOwnedForm(this);
830 owner.AddOwnedForm(this);
831 if (IsHandleCreated) {
832 if (owner != null && owner.IsHandleCreated) {
833 XplatUI.SetTopmost(this.window.Handle, owner.window.Handle, true);
835 XplatUI.SetTopmost(this.window.Handle, IntPtr.Zero, false);
843 [MWFCategory("Window Style")]
844 public bool ShowInTaskbar {
846 return show_in_taskbar;
849 if (show_in_taskbar != value) {
850 show_in_taskbar = value;
851 if (IsHandleCreated) {
859 // new property so we can set the DesignerSerializationVisibility
860 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
862 public new Size Size {
863 get { return base.Size; }
864 set { base.Size = value; }
867 [MonoTODO("Trigger something when GripStyle is set")]
868 [DefaultValue(SizeGripStyle.Auto)]
869 [MWFCategory("Window Style")]
870 public SizeGripStyle SizeGripStyle {
872 return size_grip_style;
876 size_grip_style = value;
880 [DefaultValue(FormStartPosition.WindowsDefaultLocation)]
882 [MWFCategory("Layout")]
883 public FormStartPosition StartPosition {
885 return start_position;
889 if (start_position == FormStartPosition.WindowsDefaultLocation) { // Only do this if it's not set yet
890 start_position = value;
891 if (IsHandleCreated) {
892 switch(start_position) {
893 case FormStartPosition.CenterParent: {
898 case FormStartPosition.CenterScreen: {
903 case FormStartPosition.Manual: {
904 Left = CreateParams.X;
905 Top = CreateParams.Y;
918 // new property so we can set EditorBrowsable to never
920 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
921 [EditorBrowsable(EditorBrowsableState.Never)]
922 public new int TabIndex {
923 get { return base.TabIndex; }
924 set { base.TabIndex = value; }
928 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
929 [EditorBrowsable(EditorBrowsableState.Advanced)]
930 public bool TopLevel {
932 return GetTopLevel();
936 if (!value && IsMdiContainer)
937 throw new ArgumentException ("MDI Container forms must be top level.");
942 [DefaultValue(false)]
943 [MWFCategory("Window Style")]
944 public bool TopMost {
950 if (topmost != value) {
953 XplatUI.SetTopmost(window.Handle, owner != null ? owner.window.Handle : IntPtr.Zero, value);
958 [MWFCategory("Window Style")]
959 public Color TransparencyKey {
961 return transparency_key;
965 transparency_key = value;
967 AllowTransparency = true;
969 if ((XplatUI.SupportsTransparency () & TransparencySupport.Set) != 0)
970 XplatUI.SetWindowTransparency(Handle, Opacity, transparency_key);
974 [DefaultValue(FormWindowState.Normal)]
975 [MWFCategory("Layout")]
976 public FormWindowState WindowState {
978 if (IsHandleCreated) {
980 if (window_manager != null)
981 return window_manager.GetWindowState ();
983 FormWindowState new_state = XplatUI.GetWindowState(Handle);
984 if (new_state != (FormWindowState)(-1))
985 window_state = new_state;
992 FormWindowState old_state = window_state;
993 window_state = value;
994 if (IsHandleCreated) {
996 if (window_manager != null) {
997 window_manager.SetWindowState (old_state, value);
1001 XplatUI.SetWindowState(Handle, value);
1006 #endregion // Public Instance Properties
1008 #region Protected Instance Properties
1009 protected override CreateParams CreateParams {
1011 CreateParams cp = new CreateParams ();
1014 cp.ClassName = XplatUI.DefaultClassName;
1019 cp.Parent = IntPtr.Zero;
1020 cp.menu = ActiveMenu;
1022 if (start_position == FormStartPosition.WindowsDefaultLocation && !IsMdiChild) {
1023 cp.X = unchecked((int)0x80000000);
1024 cp.Y = unchecked((int)0x80000000);
1032 cp.Style = (int)(WindowStyles.WS_CLIPCHILDREN | WindowStyles.WS_CLIPSIBLINGS);
1035 cp.Style |= (int)(WindowStyles.WS_CHILD | WindowStyles.WS_CAPTION);
1036 if (Parent != null) {
1037 cp.Parent = Parent.Handle;
1040 cp.ExStyle |= (int) (WindowExStyles.WS_EX_WINDOWEDGE | WindowExStyles.WS_EX_MDICHILD);
1042 switch (FormBorderStyle) {
1043 case FormBorderStyle.None:
1045 case FormBorderStyle.FixedToolWindow:
1046 case FormBorderStyle.SizableToolWindow:
1047 cp.ExStyle |= (int) WindowExStyles.WS_EX_TOOLWINDOW;
1050 cp.Style |= (int) WindowStyles.WS_OVERLAPPEDWINDOW;
1055 switch (FormBorderStyle) {
1056 case FormBorderStyle.Fixed3D: {
1057 cp.Style |= (int)(WindowStyles.WS_CAPTION | WindowStyles.WS_BORDER);
1058 cp.ExStyle |= (int)WindowExStyles.WS_EX_CLIENTEDGE;
1062 case FormBorderStyle.FixedDialog: {
1063 cp.Style |= (int)(WindowStyles.WS_CAPTION | WindowStyles.WS_BORDER);
1064 cp.ExStyle |= (int)(WindowExStyles.WS_EX_DLGMODALFRAME | WindowExStyles.WS_EX_CONTROLPARENT);
1068 case FormBorderStyle.FixedSingle: {
1069 cp.Style |= (int)(WindowStyles.WS_CAPTION | WindowStyles.WS_BORDER);
1073 case FormBorderStyle.FixedToolWindow: {
1074 cp.Style |= (int)(WindowStyles.WS_CAPTION | WindowStyles.WS_BORDER);
1075 cp.ExStyle |= (int)(WindowExStyles.WS_EX_TOOLWINDOW);
1079 case FormBorderStyle.Sizable: {
1080 cp.Style |= (int)(WindowStyles.WS_BORDER | WindowStyles.WS_THICKFRAME | WindowStyles.WS_CAPTION);
1084 case FormBorderStyle.SizableToolWindow: {
1085 cp.Style |= (int)(WindowStyles.WS_BORDER | WindowStyles.WS_THICKFRAME | WindowStyles.WS_CAPTION);
1086 cp.ExStyle |= (int)(WindowExStyles.WS_EX_TOOLWINDOW);
1090 case FormBorderStyle.None: {
1096 switch(window_state) {
1097 case FormWindowState.Maximized: {
1098 cp.Style |= (int)WindowStyles.WS_MAXIMIZE;
1102 case FormWindowState.Minimized: {
1103 cp.Style |= (int)WindowStyles.WS_MINIMIZE;
1109 cp.ExStyle |= (int) WindowExStyles.WS_EX_TOPMOST;
1112 if (ShowInTaskbar) {
1113 cp.ExStyle |= (int)WindowExStyles.WS_EX_APPWINDOW;
1117 cp.Style |= (int)WindowStyles.WS_MAXIMIZEBOX;
1121 cp.Style |= (int)WindowStyles.WS_MINIMIZEBOX;
1125 cp.Style |= (int)WindowStyles.WS_SYSMENU;
1128 if (HelpButton && !MaximizeBox && !MinimizeBox) {
1129 cp.ExStyle |= (int)WindowExStyles.WS_EX_CONTEXTHELP;
1133 cp.Style |= (int)WindowStyles.WS_VISIBLE;
1135 if (opacity < 1.0 || TransparencyKey != Color.Empty) {
1136 cp.ExStyle |= (int)WindowExStyles.WS_EX_LAYERED;
1139 if (!is_enabled && context == null) {
1140 cp.Style |= (int)(WindowStyles.WS_DISABLED);
1147 protected override ImeMode DefaultImeMode {
1149 return ImeMode.NoControl;
1153 protected override Size DefaultSize {
1155 return new Size (300, 300);
1159 protected Rectangle MaximizedBounds {
1161 if (maximized_bounds != Rectangle.Empty) {
1162 return maximized_bounds;
1164 return default_maximized_bounds;
1168 maximized_bounds = value;
1169 OnMaximizedBoundsChanged(EventArgs.Empty);
1170 if (IsHandleCreated) {
1171 XplatUI.SetWindowMinMax(Handle, maximized_bounds, minimum_size, maximum_size);
1175 #endregion // Protected Instance Properties
1177 #region Public Static Methods
1179 [EditorBrowsable(EditorBrowsableState.Never)]
1180 [Obsolete ("This method has been deprecated. Use AutoScaleDimensions instead")]
1182 [EditorBrowsable(EditorBrowsableState.Advanced)]
1184 public static SizeF GetAutoScaleSize (Font font)
1186 return XplatUI.GetAutoScaleSize(font);
1189 #endregion // Public Static Methods
1191 #region Public Instance Methods
1192 internal SizeF GetAutoScaleSize (Graphics g, Font font)
1195 // The following constants come from the dotnet mailing list
1196 // discussion: http://discuss.develop.com/archives/wa.exe?A2=ind0203A&L=DOTNET&P=R3655
1198 // The magic number is "Its almost the length
1199 // of the string with a smattering added in
1200 // for compat with earlier code".
1203 string magic_string = "The quick brown fox jumped over the lazy dog.";
1204 double magic_number = 44.549996948242189;
1205 float width = (float) (g.MeasureString (magic_string, font).Width / magic_number);
1207 return new SizeF (width, font.Height);
1210 public void Activate ()
1214 // The docs say activate only activates if our app is already active
1215 if (IsHandleCreated) {
1217 MdiParent.ActivateMdiChild (this);
1218 } else if (IsMdiContainer) {
1219 SendControlFocus (mdi_container);
1221 active = ActiveForm;
1222 if ((active != null) && (this != active)) {
1223 XplatUI.Activate(window.Handle);
1229 public void AddOwnedForm(Form ownedForm) {
1230 if (!owned_forms.Contains(ownedForm)) {
1231 owned_forms.Add(ownedForm);
1233 ownedForm.Owner = this;
1236 public void Close () {
1244 FormClosingEventArgs ce = new FormClosingEventArgs (CloseReason.FormOwnerClosing, false);
1249 XplatUI.SendMessage(this.Handle, Msg.WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
1252 public void LayoutMdi(MdiLayout value) {
1253 if (mdi_container != null) {
1254 mdi_container.LayoutMdi(value);
1258 public void RemoveOwnedForm(Form ownedForm) {
1259 owned_forms.Remove(ownedForm);
1262 public void SetDesktopBounds(int x, int y, int width, int height) {
1263 DesktopBounds = new Rectangle(x, y, width, height);
1266 public void SetDesktopLocation(int x, int y) {
1267 DesktopLocation = new Point(x, y);
1270 public DialogResult ShowDialog() {
1271 return ShowDialog(this.owner);
1274 public DialogResult ShowDialog(IWin32Window ownerWin32) {
1277 IntPtr capture_window;
1281 if (ownerWin32 != null) {
1282 Control c = Control.FromHandle (ownerWin32.Handle);
1284 owner = c.TopLevelControl as Form;
1287 if (owner == this) {
1288 throw new InvalidOperationException("The 'ownerWin32' cannot be the form being shown.");
1292 throw new InvalidOperationException("The form is already displayed as a modal dialog.");
1296 throw new InvalidOperationException("Already visible forms cannot be displayed as a modal dialog. Set the Visible property to 'false' prior to calling Form.ShowDialog.");
1300 throw new InvalidOperationException("Cannot display a disabled form as modal dialog.");
1303 if (TopLevelControl != this) {
1304 throw new InvalidOperationException("Can only display TopLevel forms as modal dialog.");
1308 // Can't do this, will screw us in the modal loop
1309 form_parent_window.Parent = this.owner;
1312 // Release any captures
1313 XplatUI.GrabInfo(out capture_window, out confined, out area);
1314 if (capture_window != IntPtr.Zero) {
1315 XplatUI.UngrabWindow(capture_window);
1319 // Commented out; we instead let the Visible=true inside the runloop create the control
1320 // otherwise setting DialogResult inside any of the events that are triggered by the
1321 // create will not actually cause the form to not be displayed.
1322 // Leaving this comment here in case there was an actual purpose to creating the control
1324 if (!IsHandleCreated) {
1329 Application.RunLoop(true, new ApplicationContext(this));
1331 if (owner != null) {
1332 // Cannot use Activate(), it has a check for the current active window...
1333 XplatUI.Activate(owner.window.Handle);
1336 if (DialogResult != DialogResult.None) {
1337 return DialogResult;
1339 DialogResult = DialogResult.Cancel;
1340 return DialogResult.Cancel;
1343 public override string ToString() {
1344 return GetType().FullName.ToString() + ", Text: " + Text;
1346 #endregion // Public Instance Methods
1348 #region Protected Instance Methods
1349 protected void ActivateMdiChild(Form form) {
1350 if (!IsMdiContainer)
1352 mdi_container.ActivateChild (form);
1353 OnMdiChildActivate(EventArgs.Empty);
1356 [EditorBrowsable(EditorBrowsableState.Advanced)]
1357 protected override void AdjustFormScrollbars(bool displayScrollbars) {
1358 base.AdjustFormScrollbars (displayScrollbars);
1362 [EditorBrowsable(EditorBrowsableState.Never)]
1363 [Obsolete ("This method has been deprecated")] // XXX what to use instead?
1365 [EditorBrowsable(EditorBrowsableState.Advanced)]
1367 protected void ApplyAutoScaling()
1369 SizeF current_size_f = GetAutoScaleSize (DeviceContext, Font);
1370 Size current_size = new Size ((int) current_size_f.Width, (int) current_size_f.Height);
1374 if (current_size == autoscale_base_size)
1377 if (Environment.GetEnvironmentVariable ("MONO_MWF_SCALING") == "disable"){
1382 // I tried applying the Fudge height factor from:
1383 // http://blogs.msdn.com/mharsh/archive/2004/01/25/62621.aspx
1384 // but it makes things larger without looking better.
1386 if (current_size_f.Width != AutoScaleBaseSize.Width) {
1387 dx = current_size_f.Width / AutoScaleBaseSize.Width + 0.08f;
1392 if (current_size_f.Height != AutoScaleBaseSize.Height) {
1393 dy = current_size_f.Height / AutoScaleBaseSize.Height + 0.08f;
1400 AutoScaleBaseSize = current_size;
1403 protected void CenterToParent() {
1411 w = DefaultSize.Width;
1417 h = DefaultSize.Height;
1421 if (Parent != null) {
1423 } else if (owner != null) {
1427 if (owner != null) {
1428 this.Location = new Point(ctl.Left + ctl.Width / 2 - w /2, ctl.Top + ctl.Height / 2 - h / 2);
1432 protected void CenterToScreen() {
1440 w = DefaultSize.Width;
1446 h = DefaultSize.Height;
1449 XplatUI.GetDisplaySize(out DisplaySize);
1450 this.Location = new Point(DisplaySize.Width / 2 - w / 2, DisplaySize.Height / 2 - h / 2);
1453 [EditorBrowsable(EditorBrowsableState.Advanced)]
1454 protected override Control.ControlCollection CreateControlsInstance() {
1455 return base.CreateControlsInstance ();
1458 [EditorBrowsable(EditorBrowsableState.Advanced)]
1459 protected override void CreateHandle() {
1460 base.CreateHandle ();
1462 Application.AddForm (this);
1466 if ((XplatUI.SupportsTransparency() & TransparencySupport.Set) != 0) {
1467 if (allow_transparency) {
1468 XplatUI.SetWindowTransparency(Handle, Opacity, TransparencyKey);
1472 XplatUI.SetWindowMinMax(window.Handle, maximized_bounds, minimum_size, maximum_size);
1473 if ((FormBorderStyle != FormBorderStyle.FixedDialog) && (icon != null)) {
1474 XplatUI.SetIcon(window.Handle, icon);
1477 if ((owner != null) && (owner.IsHandleCreated)) {
1478 XplatUI.SetTopmost(window.Handle, owner.window.Handle, true);
1481 for (int i = 0; i < owned_forms.Count; i++) {
1482 if (owned_forms[i].IsHandleCreated)
1483 XplatUI.SetTopmost(owned_forms[i].window.Handle, window.Handle, true);
1486 if (window_manager != null && window_state != FormWindowState.Normal) {
1487 window_manager.SetWindowState (FormWindowState.Normal, window_state);
1492 [EditorBrowsable(EditorBrowsableState.Advanced)]
1493 protected override void DefWndProc(ref Message m) {
1494 base.DefWndProc (ref m);
1497 protected override void Dispose(bool disposing)
1499 for (int i = 0; i < owned_forms.Count; i++)
1500 ((Form)owned_forms[i]).Owner = null;
1502 owned_forms.Clear ();
1504 base.Dispose (disposing);
1506 Application.RemoveForm (this);
1509 [EditorBrowsable(EditorBrowsableState.Advanced)]
1510 protected virtual void OnActivated(EventArgs e)
1513 SelectActiveControl ();
1515 EventHandler eh = (EventHandler)(Events [ActivatedEvent]);
1520 [EditorBrowsable(EditorBrowsableState.Advanced)]
1521 protected virtual void OnClosed(EventArgs e) {
1522 EventHandler eh = (EventHandler)(Events [ClosedEvent]);
1527 [EditorBrowsable(EditorBrowsableState.Advanced)]
1528 protected virtual void OnClosing(System.ComponentModel.CancelEventArgs e) {
1529 CancelEventHandler eh = (CancelEventHandler)(Events [ClosingEvent]);
1534 [EditorBrowsable(EditorBrowsableState.Advanced)]
1535 protected override void OnCreateControl() {
1536 base.OnCreateControl ();
1539 XplatUI.SetMenu(window.Handle, menu);
1542 OnLoad(EventArgs.Empty);
1544 SelectActiveControl ();
1546 // Send initial location
1547 OnLocationChanged(EventArgs.Empty);
1549 if (IsMdiContainer) {
1550 mdi_container.LayoutMdi (MdiLayout.Cascade);
1554 [EditorBrowsable(EditorBrowsableState.Advanced)]
1555 protected virtual void OnDeactivate(EventArgs e) {
1556 EventHandler eh = (EventHandler)(Events [DeactivateEvent]);
1561 [EditorBrowsable(EditorBrowsableState.Advanced)]
1562 protected override void OnFontChanged(EventArgs e) {
1563 base.OnFontChanged (e);
1566 [EditorBrowsable(EditorBrowsableState.Advanced)]
1567 protected override void OnHandleCreated(EventArgs e) {
1568 XplatUI.SetBorderStyle(window.Handle, form_border_style);
1569 base.OnHandleCreated (e);
1572 [EditorBrowsable(EditorBrowsableState.Advanced)]
1573 protected override void OnHandleDestroyed(EventArgs e) {
1574 base.OnHandleDestroyed (e);
1577 [EditorBrowsable(EditorBrowsableState.Advanced)]
1578 protected virtual void OnInputLanguageChanged(InputLanguageChangedEventArgs e) {
1579 InputLanguageChangedEventHandler eh = (InputLanguageChangedEventHandler)(Events [InputLanguageChangedEvent]);
1584 [EditorBrowsable(EditorBrowsableState.Advanced)]
1585 protected virtual void OnInputLanguageChanging(InputLanguageChangingEventArgs e) {
1586 InputLanguageChangingEventHandler eh = (InputLanguageChangingEventHandler)(Events [InputLanguageChangingEvent]);
1591 [EditorBrowsable(EditorBrowsableState.Advanced)]
1592 protected virtual void OnLoad(EventArgs e) {
1594 ApplyAutoScaling ();
1598 EventHandler eh = (EventHandler)(Events [LoadEvent]);
1603 switch (StartPosition) {
1604 case FormStartPosition.CenterScreen:
1605 this.CenterToScreen();
1607 case FormStartPosition.CenterParent:
1608 this.CenterToParent ();
1610 case FormStartPosition.Manual:
1611 Left = CreateParams.X;
1612 Top = CreateParams.Y;
1619 [EditorBrowsable(EditorBrowsableState.Advanced)]
1620 protected virtual void OnMaximizedBoundsChanged(EventArgs e) {
1621 EventHandler eh = (EventHandler)(Events [MaximizedBoundsChangedEvent]);
1626 [EditorBrowsable(EditorBrowsableState.Advanced)]
1627 protected virtual void OnMaximumSizeChanged(EventArgs e) {
1628 EventHandler eh = (EventHandler)(Events [MaximumSizeChangedEvent]);
1633 [EditorBrowsable(EditorBrowsableState.Advanced)]
1634 protected virtual void OnMdiChildActivate(EventArgs e) {
1635 EventHandler eh = (EventHandler)(Events [MdiChildActivateEvent]);
1640 [EditorBrowsable(EditorBrowsableState.Advanced)]
1641 protected virtual void OnMenuComplete(EventArgs e) {
1642 EventHandler eh = (EventHandler)(Events [MenuCompleteEvent]);
1647 [EditorBrowsable(EditorBrowsableState.Advanced)]
1648 protected virtual void OnMenuStart(EventArgs e) {
1649 EventHandler eh = (EventHandler)(Events [MenuStartEvent]);
1654 [EditorBrowsable(EditorBrowsableState.Advanced)]
1655 protected virtual void OnMinimumSizeChanged(EventArgs e) {
1656 EventHandler eh = (EventHandler)(Events [MinimumSizeChangedEvent]);
1661 [EditorBrowsable(EditorBrowsableState.Advanced)]
1662 protected override void OnPaint (PaintEventArgs pevent) {
1663 base.OnPaint (pevent);
1666 [EditorBrowsable(EditorBrowsableState.Advanced)]
1667 protected override void OnResize(EventArgs e) {
1670 if (this.IsMdiChild && ParentForm != null) {
1671 ParentForm.PerformLayout();
1672 ParentForm.Size = ParentForm.Size;
1676 [EditorBrowsable(EditorBrowsableState.Advanced)]
1677 protected override void OnStyleChanged(EventArgs e) {
1678 base.OnStyleChanged (e);
1681 [EditorBrowsable(EditorBrowsableState.Advanced)]
1682 protected override void OnTextChanged(EventArgs e) {
1683 base.OnTextChanged (e);
1685 if (mdi_container != null)
1686 mdi_container.SetParentText(true);
1689 [EditorBrowsable(EditorBrowsableState.Advanced)]
1690 protected override void OnVisibleChanged(EventArgs e) {
1691 base.OnVisibleChanged (e);
1694 if (window_manager != null)
1695 window_manager.SetWindowState (WindowState, WindowState);
1699 protected override bool ProcessCmdKey(ref Message msg, Keys keyData) {
1700 if (base.ProcessCmdKey (ref msg, keyData)) {
1704 // Give our menu a shot
1705 if (ActiveMenu != null) {
1706 return ActiveMenu.ProcessCmdKey(ref msg, keyData);
1712 // LAMESPEC - Not documented that Form overrides ProcessDialogChar; class-status showed
1713 [EditorBrowsable (EditorBrowsableState.Advanced)]
1714 protected override bool ProcessDialogChar(char charCode) {
1715 return base.ProcessDialogChar (charCode);
1718 protected override bool ProcessDialogKey(Keys keyData) {
1719 if ((keyData & Keys.Modifiers) == 0) {
1720 if (keyData == Keys.Enter) {
1721 IntPtr window = XplatUI.GetFocus ();
1722 Control c = Control.FromHandle (window);
1723 if (c is Button && c.FindForm () == this) {
1724 ((Button)c).PerformClick ();
1727 else if (accept_button != null) {
1728 accept_button.PerformClick();
1731 } else if (keyData == Keys.Escape && cancel_button != null) {
1732 cancel_button.PerformClick();
1736 return base.ProcessDialogKey(keyData);
1739 protected override bool ProcessKeyPreview(ref Message msg) {
1741 if (ProcessKeyEventArgs(ref msg)) {
1745 return base.ProcessKeyPreview (ref msg);
1748 protected override bool ProcessTabKey(bool forward) {
1749 return SelectNextControl(ActiveControl, forward, true, true, true);
1753 [EditorBrowsable(EditorBrowsableState.Never)]
1755 [EditorBrowsable(EditorBrowsableState.Advanced)]
1757 protected override void ScaleCore(float dx, float dy) {
1761 // We can't scale max or min windows
1762 if (WindowState == FormWindowState.Normal) {
1763 // We cannot call base since base also adjusts X/Y, but
1764 // a form is toplevel and doesn't move
1768 if (!GetStyle(ControlStyles.FixedWidth)) {
1769 size.Width = (int)(size.Width * dx);
1772 if (!GetStyle(ControlStyles.FixedHeight)) {
1773 size.Height = (int)(size.Height * dy);
1779 /* Now scale our children */
1780 Control [] controls = Controls.GetAllControls ();
1781 for (int i=0; i < controls.Length; i++) {
1782 controls[i].Scale(dx, dy);
1791 protected override void Select(bool directed, bool forward) {
1795 base.SelectNextControl(null, forward, true, true, true);
1798 parent = this.ParentForm;
1799 if (parent != null) {
1800 parent.ActiveControl = this;
1806 [EditorBrowsable(EditorBrowsableState.Advanced)]
1807 protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
1808 base.SetBoundsCore (x, y, width, height, specified);
1811 [EditorBrowsable(EditorBrowsableState.Advanced)]
1812 protected override void SetClientSizeCore(int x, int y) {
1813 if ((minimum_size.Width != 0) && (x < minimum_size.Width)) {
1814 x = minimum_size.Width;
1815 } else if ((maximum_size.Width != 0) && (x > maximum_size.Width)) {
1816 x = maximum_size.Width;
1819 if ((minimum_size.Height != 0) && (y < minimum_size.Height)) {
1820 y = minimum_size.Height;
1821 } else if ((maximum_size.Height != 0) && (y > maximum_size.Height)) {
1822 y = maximum_size.Height;
1825 Rectangle ClientRect = new Rectangle(0, 0, x, y);
1826 Rectangle WindowRect;
1827 CreateParams cp = this.CreateParams;
1829 clientsize_set = new Size(x, y);
1831 if (XplatUI.CalculateWindowRect(ref ClientRect, cp.Style, cp.ExStyle, cp.menu, out WindowRect)) {
1832 SetBounds(bounds.X, bounds.Y, WindowRect.Width, WindowRect.Height, BoundsSpecified.Size);
1836 [EditorBrowsable(EditorBrowsableState.Advanced)]
1837 protected override void SetVisibleCore(bool value) {
1838 is_changing_visible_state = true;
1839 has_been_visible = value || has_been_visible;
1840 base.SetVisibleCore (value);
1841 is_changing_visible_state = false;
1844 protected override void UpdateDefaultButton() {
1845 base.UpdateDefaultButton ();
1848 [EditorBrowsable(EditorBrowsableState.Advanced)]
1849 protected override void WndProc(ref Message m) {
1851 if (window_manager != null && window_manager.HandleMessage (ref m)) {
1855 switch((Msg)m.Msg) {
1856 case Msg.WM_DESTROY: {
1857 base.WndProc(ref m);
1858 if (!RecreatingHandle) {
1859 this.closing = true;
1864 case Msg.WM_CLOSE_INTERNAL: {
1869 case Msg.WM_CLOSE: {
1870 Form act = Form.ActiveForm;
1871 if (act != null && act != this && act.Modal == true) {
1875 CancelEventArgs args = new CancelEventArgs ();
1877 if (mdi_container != null) {
1878 foreach (Form mdi_child in mdi_container.MdiChildren) {
1879 mdi_child.OnClosing (args);
1886 OnClosed (EventArgs.Empty);
1896 DialogResult = DialogResult.None;
1900 OnClosed (EventArgs.Empty);
1909 case Msg.WM_WINDOWPOSCHANGED: {
1910 if (WindowState != FormWindowState.Minimized) {
1911 base.WndProc(ref m);
1917 case Msg.WM_SYSCOMMAND: {
1918 // Let *Strips know the app's title bar was clicked
1919 if (XplatUI.IsEnabled (Handle))
1920 ToolStripManager.FireAppClicked ();
1922 base.WndProc(ref m);
1927 case Msg.WM_ACTIVATE: {
1928 if (m.WParam != (IntPtr)WindowActiveFlags.WA_INACTIVE) {
1929 OnActivated(EventArgs.Empty);
1931 OnDeactivate(EventArgs.Empty);
1936 case Msg.WM_KILLFOCUS: {
1937 base.WndProc(ref m);
1941 case Msg.WM_SETFOCUS: {
1942 if (ActiveControl != null && ActiveControl != this) {
1943 ActiveControl.Focus();
1944 return; // FIXME - do we need to run base.WndProc, even though we just changed focus?
1946 base.WndProc(ref m);
1951 case Msg.WM_NCLBUTTONDOWN: {
1952 if (XplatUI.IsEnabled (Handle) && ActiveMenu != null) {
1953 ActiveMenu.OnMouseDown(this, new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()), mouse_clicks, Control.MousePosition.X, Control.MousePosition.Y, 0));
1956 if (ActiveMaximizedMdiChild != null) {
1957 if (ActiveMaximizedMdiChild.HandleMenuMouseDown (ActiveMenu,
1958 LowOrder ((int) m.LParam.ToInt32 ()),
1959 HighOrder ((int) m.LParam.ToInt32 ()))) {
1960 // Don't let base process this message, otherwise we won't
1961 // get a WM_NCLBUTTONUP.
1965 base.WndProc(ref m);
1968 case Msg.WM_NCLBUTTONUP: {
1969 if (ActiveMaximizedMdiChild != null) {
1970 ActiveMaximizedMdiChild.HandleMenuMouseUp (ActiveMenu,
1971 LowOrder ((int)m.LParam.ToInt32 ()),
1972 HighOrder ((int)m.LParam.ToInt32 ()));
1974 base.WndProc (ref m);
1978 case Msg.WM_NCMOUSELEAVE: {
1979 if (ActiveMaximizedMdiChild != null) {
1980 ActiveMaximizedMdiChild.HandleMenuMouseLeave(ActiveMenu,
1981 LowOrder((int)m.LParam.ToInt32()),
1982 HighOrder((int)m.LParam.ToInt32()));
1984 base.WndProc(ref m);
1988 case Msg.WM_NCMOUSEMOVE: {
1989 if (XplatUI.IsEnabled (Handle) && ActiveMenu != null) {
1990 ActiveMenu.OnMouseMove(this, new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()), mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()), 0));
1993 if (ActiveMaximizedMdiChild != null) {
1994 XplatUI.RequestAdditionalWM_NCMessages (Handle, false, true);
1995 ActiveMaximizedMdiChild.HandleMenuMouseMove (ActiveMenu,
1996 LowOrder ((int)m.LParam.ToInt32 ()),
1997 HighOrder ((int)m.LParam.ToInt32 ()));
1999 base.WndProc(ref m);
2003 case Msg.WM_NCPAINT: {
2004 if (ActiveMenu != null) {
2008 pe = XplatUI.PaintEventStart(Handle, false);
2009 pnt = XplatUI.GetMenuOrigin(window.Handle);
2011 // The entire menu has to be in the clip rectangle because the
2012 // control buttons are right-aligned and otherwise they would
2013 // stay painted when the window gets resized.
2014 Rectangle clip = new Rectangle (pnt.X, pnt.Y, ClientSize.Width, 0);
2015 clip = Rectangle.Union(clip, pe.ClipRectangle);
2017 pe.Graphics.SetClip(clip);
2019 ActiveMenu.Draw (pe, new Rectangle (pnt.X, pnt.Y, ClientSize.Width, 0));
2021 if (ActiveMaximizedMdiChild != null) {
2022 ActiveMaximizedMdiChild.DrawMaximizedButtons (ActiveMenu, pe);
2025 XplatUI.PaintEventEnd(Handle, false);
2028 base.WndProc(ref m);
2032 case Msg.WM_NCCALCSIZE: {
2033 XplatUIWin32.NCCALCSIZE_PARAMS ncp;
2035 if ((ActiveMenu != null) && (m.WParam == (IntPtr)1)) {
2036 ncp = (XplatUIWin32.NCCALCSIZE_PARAMS)Marshal.PtrToStructure(m.LParam, typeof(XplatUIWin32.NCCALCSIZE_PARAMS));
2039 ncp.rgrc1.top += ThemeEngine.Current.CalcMenuBarSize (DeviceContext, ActiveMenu, ncp.rgrc1.right - ncp.rgrc1.left);
2040 Marshal.StructureToPtr(ncp, m.LParam, true);
2046 case Msg.WM_MOUSEMOVE: {
2047 if (XplatUI.IsEnabled (Handle) && active_tracker != null) {
2048 MouseEventArgs args;
2050 args = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
2051 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()), 0);
2052 active_tracker.OnMotion(new MouseEventArgs (args.Button, args.Clicks, Control.MousePosition.X, Control.MousePosition.Y, args.Delta));
2055 base.WndProc(ref m);
2059 case Msg.WM_LBUTTONDOWN:
2060 case Msg.WM_MBUTTONDOWN:
2061 case Msg.WM_RBUTTONDOWN: {
2062 if (XplatUI.IsEnabled (Handle) && active_tracker != null) {
2063 MouseEventArgs args;
2065 args = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
2066 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()), 0);
2067 active_tracker.OnMouseDown(new MouseEventArgs (args.Button, args.Clicks, Control.MousePosition.X, Control.MousePosition.Y, args.Delta));
2070 base.WndProc(ref m);
2074 case Msg.WM_LBUTTONUP:
2075 case Msg.WM_MBUTTONUP:
2076 case Msg.WM_RBUTTONUP: {
2077 if (XplatUI.IsEnabled (Handle) && active_tracker != null) {
2078 MouseEventArgs args;
2079 MouseButtons mb = FromParamToMouseButtons ((int) m.WParam.ToInt32());
2081 // We add in the button that was released (not sent in WParam)
2082 switch((Msg)m.Msg) {
2083 case Msg.WM_LBUTTONUP:
2084 mb |= MouseButtons.Left;
2086 case Msg.WM_MBUTTONUP:
2087 mb |= MouseButtons.Middle;
2089 case Msg.WM_RBUTTONUP:
2090 mb |= MouseButtons.Right;
2094 args = new MouseEventArgs (mb, mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()), 0);
2095 active_tracker.OnMouseUp(new MouseEventArgs (args.Button, args.Clicks, Control.MousePosition.X, Control.MousePosition.Y, args.Delta));
2099 base.WndProc(ref m);
2103 case Msg.WM_GETMINMAXINFO: {
2106 if (m.LParam != IntPtr.Zero) {
2107 mmi = (MINMAXINFO)Marshal.PtrToStructure(m.LParam, typeof(MINMAXINFO));
2109 default_maximized_bounds = new Rectangle(mmi.ptMaxPosition.x, mmi.ptMaxPosition.y, mmi.ptMaxSize.x, mmi.ptMaxSize.y);
2110 if (maximized_bounds != Rectangle.Empty) {
2111 mmi.ptMaxPosition.x = maximized_bounds.Left;
2112 mmi.ptMaxPosition.y = maximized_bounds.Top;
2113 mmi.ptMaxSize.x = maximized_bounds.Width;
2114 mmi.ptMaxSize.y = maximized_bounds.Height;
2117 if (minimum_size != Size.Empty) {
2118 mmi.ptMinTrackSize.x = minimum_size.Width;
2119 mmi.ptMinTrackSize.y = minimum_size.Height;
2122 if (maximum_size != Size.Empty) {
2123 mmi.ptMaxTrackSize.x = maximum_size.Width;
2124 mmi.ptMaxTrackSize.y = maximum_size.Height;
2126 Marshal.StructureToPtr(mmi, m.LParam, false);
2132 case Msg.WM_MOUSEACTIVATE: {
2133 // Let *Strips know the form or another control has been clicked
2134 if (XplatUI.IsEnabled (Handle))
2135 ToolStripManager.FireAppClicked ();
2137 base.WndProc (ref m);
2141 case Msg.WM_ACTIVATEAPP: {
2142 // Let *Strips know the app lost focus
2143 if (m.WParam == (IntPtr)0)
2144 if (XplatUI.IsEnabled (Handle))
2145 ToolStripManager.FireAppFocusChanged (this);
2147 base.WndProc (ref m);
2153 base.WndProc (ref m);
2158 #endregion // Protected Instance Methods
2160 internal void RemoveWindowManager ()
2162 window_manager = null;
2165 internal override void CheckAcceptButton()
2167 if (accept_button != null) {
2168 Button a_button = accept_button as Button;
2170 if (ActiveControl == a_button)
2173 if (ActiveControl is Button) {
2174 a_button.paint_as_acceptbutton = false;
2178 a_button.paint_as_acceptbutton = true;
2185 static object ActivatedEvent = new object ();
2186 static object ClosedEvent = new object ();
2187 static object ClosingEvent = new object ();
2188 static object DeactivateEvent = new object ();
2189 static object InputLanguageChangedEvent = new object ();
2190 static object InputLanguageChangingEvent = new object ();
2191 static object LoadEvent = new object ();
2192 static object MaximizedBoundsChangedEvent = new object ();
2193 static object MaximumSizeChangedEvent = new object ();
2194 static object MdiChildActivateEvent = new object ();
2195 static object MenuCompleteEvent = new object ();
2196 static object MenuStartEvent = new object ();
2197 static object MinimumSizeChangedEvent = new object ();
2199 public event EventHandler Activated {
2200 add { Events.AddHandler (ActivatedEvent, value); }
2201 remove { Events.RemoveHandler (ActivatedEvent, value); }
2206 [EditorBrowsable (EditorBrowsableState.Never)]
2208 public event EventHandler Closed {
2209 add { Events.AddHandler (ClosedEvent, value); }
2210 remove { Events.RemoveHandler (ClosedEvent, value); }
2215 [EditorBrowsable (EditorBrowsableState.Never)]
2217 public event CancelEventHandler Closing {
2218 add { Events.AddHandler (ClosingEvent, value); }
2219 remove { Events.RemoveHandler (ClosingEvent, value); }
2222 public event EventHandler Deactivate {
2223 add { Events.AddHandler (DeactivateEvent, value); }
2224 remove { Events.RemoveHandler (DeactivateEvent, value); }
2227 public event InputLanguageChangedEventHandler InputLanguageChanged {
2228 add { Events.AddHandler (InputLanguageChangedEvent, value); }
2229 remove { Events.RemoveHandler (InputLanguageChangedEvent, value); }
2232 public event InputLanguageChangingEventHandler InputLanguageChanging {
2233 add { Events.AddHandler (InputLanguageChangingEvent, value); }
2234 remove { Events.RemoveHandler (InputLanguageChangingEvent, value); }
2237 public event EventHandler Load {
2238 add { Events.AddHandler (LoadEvent, value); }
2239 remove { Events.RemoveHandler (LoadEvent, value); }
2242 public event EventHandler MaximizedBoundsChanged {
2243 add { Events.AddHandler (MaximizedBoundsChangedEvent, value); }
2244 remove { Events.RemoveHandler (MaximizedBoundsChangedEvent, value); }
2247 public event EventHandler MaximumSizeChanged {
2248 add { Events.AddHandler (MaximumSizeChangedEvent, value); }
2249 remove { Events.RemoveHandler (MaximumSizeChangedEvent, value); }
2252 public event EventHandler MdiChildActivate {
2253 add { Events.AddHandler (MdiChildActivateEvent, value); }
2254 remove { Events.RemoveHandler (MdiChildActivateEvent, value); }
2260 public event EventHandler MenuComplete {
2261 add { Events.AddHandler (MenuCompleteEvent, value); }
2262 remove { Events.RemoveHandler (MenuCompleteEvent, value); }
2268 public event EventHandler MenuStart {
2269 add { Events.AddHandler (MenuStartEvent, value); }
2270 remove { Events.RemoveHandler (MenuStartEvent, value); }
2273 public event EventHandler MinimumSizeChanged {
2274 add { Events.AddHandler (MinimumSizeChangedEvent, value); }
2275 remove { Events.RemoveHandler (MinimumSizeChangedEvent, value); }
2280 [EditorBrowsable(EditorBrowsableState.Never)]
2281 public new event EventHandler TabIndexChanged {
2282 add { base.TabIndexChanged += value; }
2283 remove { base.TabIndexChanged -= value; }
2285 #endregion // Events
2288 [SettingsBindable (true)]
2289 public override string Text {
2299 [SettingsBindable (true)]
2300 public new Point Location {
2302 return base.Location;
2306 base.Location = value;
2310 static object AutoValidateChangedEvent = new object ();
2311 static object FormClosingEvent = new object ();
2312 static object FormClosedEvent = new object ();
2313 static object HelpButtonClickedEvent = new object ();
2314 static object ResizeEndEvent = new object ();
2315 static object ResizeBeginEvent = new object ();
2316 static object RightToLeftLayoutChangedEvent = new object ();
2317 static object ShownEvent = new object ();
2320 [EditorBrowsable (EditorBrowsableState.Always)]
2321 public new event EventHandler AutoSizeChanged {
2322 add { base.AutoSizeChanged += value; }
2323 remove { base.AutoSizeChanged -= value; }
2327 [EditorBrowsable (EditorBrowsableState.Always)]
2328 public event EventHandler AutoValidateChanged {
2329 add { Events.AddHandler (AutoValidateChangedEvent, value); }
2330 remove { Events.RemoveHandler (AutoValidateChangedEvent, value); }
2333 public event FormClosingEventHandler FormClosing {
2334 add { Events.AddHandler (FormClosingEvent, value); }
2335 remove { Events.RemoveHandler (FormClosingEvent, value); }
2338 public event FormClosedEventHandler FormClosed {
2339 add { Events.AddHandler (FormClosedEvent, value); }
2340 remove { Events.RemoveHandler (FormClosedEvent, value); }
2344 [EditorBrowsable (EditorBrowsableState.Always)]
2345 public event CancelEventHandler HelpButtonClicked {
2346 add { Events.AddHandler (HelpButtonClickedEvent, value); }
2347 remove { Events.RemoveHandler (HelpButtonClickedEvent, value); }
2351 [EditorBrowsable (EditorBrowsableState.Never)]
2352 public new event EventHandler MarginChanged {
2353 add { base.MarginChanged += value; }
2354 remove { base.MarginChanged -= value; }
2357 public event EventHandler RightToLeftLayoutChanged {
2358 add { Events.AddHandler (RightToLeftLayoutChangedEvent, value); }
2359 remove { Events.RemoveHandler (RightToLeftLayoutChangedEvent, value); }
2362 public event EventHandler ResizeBegin {
2363 add { Events.AddHandler (ResizeBeginEvent, value); }
2364 remove { Events.RemoveHandler (ResizeBeginEvent, value); }
2367 public event EventHandler ResizeEnd {
2368 add { Events.AddHandler (ResizeEndEvent, value); }
2369 remove { Events.RemoveHandler (ResizeEndEvent, value); }
2372 public event EventHandler Shown {
2373 add { Events.AddHandler (ShownEvent, value); }
2374 remove { Events.RemoveHandler (ShownEvent, value); }
2378 [EditorBrowsable (EditorBrowsableState.Never)]
2379 public new event EventHandler TabStopChanged {
2380 add { base.TabStopChanged += value; }
2381 remove { base.TabStopChanged -= value; }
2384 [EditorBrowsable (EditorBrowsableState.Advanced)]
2385 protected virtual void OnFormClosing (FormClosingEventArgs e)
2387 FormClosingEventHandler eh = (FormClosingEventHandler)(Events [FormClosingEvent]);
2392 [EditorBrowsable (EditorBrowsableState.Advanced)]
2393 protected virtual void OnResizeBegin (EventArgs e)
2395 EventHandler eh = (EventHandler) (Events [ResizeBeginEvent]);
2400 [EditorBrowsable (EditorBrowsableState.Advanced)]
2401 protected virtual void OnResizeEnd (EventArgs e)
2403 EventHandler eh = (EventHandler) (Events [ResizeEndEvent]);