1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 // Copyright (c) 2004-2006 Novell, Inc.
23 // Peter Bartok pbartok@novell.com
30 using System
.ComponentModel
;
31 using System
.ComponentModel
.Design
;
32 using System
.ComponentModel
.Design
.Serialization
;
33 using System
.Collections
;
34 using System
.Runtime
.InteropServices
;
35 using System
.Threading
;
37 namespace System
.Windows
.Forms
{
38 [DesignerCategory("Form")]
39 [DesignTimeVisible(false)]
40 [Designer("System.Windows.Forms.Design.FormDocumentDesigner, " + Consts
.AssemblySystem_Design
, typeof(IRootDesigner
))]
41 [DefaultEvent("Load")]
43 public class Form
: ContainerControl
{
44 #region Local Variables
45 internal bool closing
;
46 FormBorderStyle form_border_style
;
47 private bool autoscale
;
48 private Size clientsize_set
;
49 private Size autoscale_base_size
;
50 private bool allow_transparency
;
51 private static Icon default_icon
;
52 internal bool is_modal
;
53 internal FormWindowState window_state
;
54 private bool control_box
;
55 private bool minimize_box
;
56 private bool maximize_box
;
57 private bool help_button
;
58 private bool show_in_taskbar
;
60 private IButtonControl accept_button
;
61 private IButtonControl cancel_button
;
62 private DialogResult dialog_result
;
63 private FormStartPosition start_position
;
65 private Form
.ControlCollection owned_forms
;
66 private MdiClient mdi_container
;
67 internal InternalWindowManager window_manager
;
68 private Form mdi_parent
;
69 private bool key_preview
;
70 private MainMenu menu
;
72 private Size maximum_size
;
73 private Size minimum_size
;
74 private SizeGripStyle size_grip_style
;
75 private Rectangle maximized_bounds
;
76 private Rectangle default_maximized_bounds
;
77 private double opacity
;
78 internal ApplicationContext context
;
79 Color transparency_key
;
80 internal MenuTracker active_tracker
;
81 private bool is_loaded
;
82 internal bool is_changing_visible_state
;
83 internal bool has_been_visible
;
85 #endregion // Local Variables
87 #region Private & Internal Methods
90 default_icon
= Locale
.GetResource("mono.ico") as Icon
;
93 // warning: this is only hooked up when an mdi container is created.
94 private void ControlAddedHandler (object sender
, ControlEventArgs e
)
96 if (mdi_container
!= null) {
97 mdi_container
.SendToBack ();
101 private void SelectActiveControl ()
103 if (this.IsMdiContainer
)
106 if (this.ActiveControl
== null) {
109 // This visible hack is to work around CanSelect always being false if one of the parents
110 // is not visible; and we by default create Form invisible...
111 visible
= this.is_visible
;
112 this.is_visible
= true;
114 if (SelectNextControl (this, true, true, true, true) == false) {
118 this.is_visible
= visible
;
120 Select (ActiveControl
);
123 #endregion // Private & Internal Methods
125 #region Public Classes
126 public new class ControlCollection
: Control
.ControlCollection
{
129 public ControlCollection(Form owner
) : base(owner
) {
130 this.form_owner
= owner
;
133 public override void Add(Control
value) {
134 if (Contains (value))
137 ((Form
)value).owner
=form_owner
;
140 public override void Remove(Control
value) {
141 ((Form
)value).owner
= null;
145 #endregion // Public Classes
147 #region Public Constructor & Destructor
150 SizeF current_scale
= GetAutoScaleSize (DeviceContext
, Font
);
153 autoscale_base_size
= new Size ((int)current_scale
.Width
, (int) current_scale
.Height
);
154 allow_transparency
= false;
157 dialog_result
= DialogResult
.None
;
158 start_position
= FormStartPosition
.WindowsDefaultLocation
;
159 form_border_style
= FormBorderStyle
.Sizable
;
160 window_state
= FormWindowState
.Normal
;
165 minimum_size
= Size
.Empty
;
166 maximum_size
= Size
.Empty
;
167 clientsize_set
= Size
.Empty
;
172 show_in_taskbar
= true;
173 ime_mode
= ImeMode
.NoControl
;
176 size_grip_style
= SizeGripStyle
.Auto
;
177 maximized_bounds
= Rectangle
.Empty
;
178 default_maximized_bounds
= Rectangle
.Empty
;
179 owned_forms
= new Form
.ControlCollection(this);
180 transparency_key
= Color
.Empty
;
182 // FIXME: this should disappear just as soon as the handle creation is done in the right place (here is too soon()
186 #endregion // Public Constructor & Destructor
188 #region Public Static Properties
190 public static Form ActiveForm
{
194 active
= FromHandle(XplatUI
.GetActive());
196 if (active
!= null) {
197 if ( !(active
is Form
)) {
200 parent
= active
.Parent
;
201 while (parent
!= null) {
202 if (parent
is Form
) {
205 parent
= parent
.Parent
;
215 #endregion // Public Static Properties
217 #region Public Instance Properties
219 public IButtonControl AcceptButton
{
221 return accept_button
;
225 accept_button
= value;
231 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
232 public bool AllowTransparency
{
234 return allow_transparency
;
238 if (value == allow_transparency
) {
242 allow_transparency
= value;
245 if (IsHandleCreated
) {
246 if ((XplatUI
.SupportsTransparency() & TransparencySupport
.Set
) != 0) {
247 XplatUI
.SetWindowTransparency(Handle
, Opacity
, TransparencyKey
);
250 UpdateStyles(); // Remove the WS_EX_LAYERED style
260 [MWFCategory("Layout")]
261 public bool AutoScale
{
273 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
274 public virtual Size AutoScaleBaseSize
{
276 return autoscale_base_size
;
280 autoscale_base_size
= value;
285 public override bool AutoScroll
{
287 return base.AutoScroll
;
290 base.AutoScroll
= value;
294 public override Color BackColor
{
296 /* we don't let parents override our
297 default background color for forms.
298 this fixes the default color for mdi
300 if (background_color
.IsEmpty
)
301 return DefaultBackColor
;
303 return background_color
;
306 base.BackColor
= value;
311 public IButtonControl CancelButton
{
313 return cancel_button
;
317 cancel_button
= value;
321 // new property so we can change the DesignerSerializationVisibility
322 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Visible
)]
324 public new Size ClientSize
{
325 get { return base.ClientSize; }
326 set { base.ClientSize = value; }
330 [MWFCategory("Window Style")]
331 public bool ControlBox
{
337 if (control_box
!= value) {
345 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
346 public Rectangle DesktopBounds
{
348 return new Rectangle(Location
, Size
);
357 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
358 public Point DesktopLocation
{
369 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
370 public DialogResult DialogResult
{
372 return dialog_result
;
376 if (value < DialogResult
.None
|| value > DialogResult
.No
)
377 throw new InvalidEnumArgumentException ("value", (int) value,
378 typeof (DialogResult
));
380 dialog_result
= value;
381 closing
= (dialog_result
!= DialogResult
.None
&& is_modal
);
385 [DefaultValue(FormBorderStyle
.Sizable
)]
387 [MWFCategory("Appearance")]
388 public FormBorderStyle FormBorderStyle
{
390 return form_border_style
;
393 form_border_style
= value;
395 if (window_manager
== null) {
396 if (IsHandleCreated
) {
397 XplatUI
.SetBorderStyle(window
.Handle
, form_border_style
);
400 window_manager
.UpdateBorderStyle (value);
407 [DefaultValue(false)]
408 [MWFCategory("Window Style")]
409 public bool HelpButton
{
415 if (help_button
!= value) {
424 [MWFCategory("Window Style")]
434 if (IsHandleCreated
) {
435 XplatUI
.SetIcon(Handle
, icon
== null ? default_icon
: icon
);
442 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
443 public bool IsMdiChild
{
445 return mdi_parent
!= null;
449 [DefaultValue(false)]
450 [MWFCategory("Window Style")]
451 public bool IsMdiContainer
{
453 return mdi_container
!= null;
457 if (value && mdi_container
== null) {
458 mdi_container
= new MdiClient ();
459 Controls
.Add(mdi_container
);
460 ControlAdded
+= new ControlEventHandler (ControlAddedHandler
);
461 mdi_container
.SendToBack ();
462 mdi_container
.SetParentText (true);
463 } else if (!value && mdi_container
!= null) {
464 Controls
.Remove(mdi_container
);
465 mdi_container
= null;
471 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
472 public Form ActiveMdiChild
{
476 return (Form
) mdi_container
.ActiveMdiChild
;
481 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
482 public bool IsRestrictedWindow
{
488 [DefaultValue(false)]
489 public bool KeyPreview
{
500 [MWFCategory("Window Style")]
501 public bool MaximizeBox
{
506 if (maximize_box
!= value) {
507 maximize_box
= value;
508 if (IsHandleCreated
) {
516 [DefaultValue("{Width=0, Height=0}")]
518 [RefreshProperties(RefreshProperties
.Repaint
)]
519 [MWFCategory("Layout")]
530 if (maximum_size
!= value) {
531 maximum_size
= value;
532 OnMaximumSizeChanged(EventArgs
.Empty
);
533 if (IsHandleCreated
) {
534 XplatUI
.SetWindowMinMax(Handle
, maximized_bounds
, minimum_size
, maximum_size
);
541 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
542 public Form
[] MdiChildren
{
544 if (mdi_container
!= null)
545 return mdi_container
.MdiChildren
;
552 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
553 public Form MdiParent
{
559 if (value != null && !value.IsMdiContainer
)
560 throw new ArgumentException ();
562 if (mdi_parent
!= null) {
563 mdi_parent
.MdiContainer
.Controls
.Remove (this);
568 window_manager
= new MdiWindowManager (this,
569 mdi_parent
.MdiContainer
);
570 mdi_parent
.MdiContainer
.Controls
.Add (this);
571 mdi_parent
.MdiContainer
.Controls
.SetChildIndex (this, 0);
575 } else if (mdi_parent
!= null) {
578 // Create a new window manager
579 window_manager
= null;
580 FormBorderStyle
= form_border_style
;
587 internal MenuTracker ActiveTracker
{
588 get { return active_tracker; }
590 if (value == active_tracker
)
593 Capture
= value != null;
594 active_tracker
= value;
598 internal MdiClient MdiContainer
{
599 get { return mdi_container; }
602 internal InternalWindowManager WindowManager
{
603 get { return window_manager; }
607 [MWFCategory("Window Style")]
608 public MainMenu Menu
{
617 if (menu
!= null && !IsMdiChild
) {
620 if (IsHandleCreated
) {
621 XplatUI
.SetMenu (window
.Handle
, menu
);
624 if (clientsize_set
!= Size
.Empty
) {
625 SetClientSizeCore(clientsize_set
.Width
, clientsize_set
.Height
);
627 UpdateBounds (bounds
.X
, bounds
.Y
, bounds
.Width
, bounds
.Height
, ClientSize
.Width
, ClientSize
.Height
-
628 ThemeEngine
.Current
.CalcMenuBarSize (DeviceContext
, menu
, ClientSize
.Width
));
637 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
638 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
639 public MainMenu MergedMenu
{
641 if (!IsMdiChild
|| window_manager
== null)
643 return ((MdiWindowManager
) window_manager
).MergedMenu
;
647 // This is the menu in display and being used because of merging this can
648 // be different then the menu that is actually assosciated with the form
649 internal MainMenu ActiveMenu
{
654 if (IsMdiContainer
&& mdi_container
.Controls
.Count
> 0 &&
655 ((Form
) mdi_container
.Controls
[0]).WindowState
== FormWindowState
.Maximized
) {
656 MdiWindowManager wm
= (MdiWindowManager
) ((Form
) mdi_container
.Controls
[0]).WindowManager
;
657 return wm
.MaximizedMenu
;
660 Form amc
= ActiveMdiChild
;
661 if (amc
== null || amc
.Menu
== null)
663 return amc
.MergedMenu
;
667 internal MdiWindowManager ActiveMaximizedMdiChild
{
669 Form child
= ActiveMdiChild
;
672 if (child
.WindowManager
== null || child
.window_state
!= FormWindowState
.Maximized
)
674 return (MdiWindowManager
) child
.WindowManager
;
679 [MWFCategory("Window Style")]
680 public bool MinimizeBox
{
685 if (minimize_box
!= value) {
686 minimize_box
= value;
687 if (IsHandleCreated
) {
696 [DefaultValue("{Width=0, Height=0}")]
699 [RefreshProperties(RefreshProperties
.Repaint
)]
700 [MWFCategory("Layout")]
711 if (minimum_size
!= value) {
712 minimum_size
= value;
714 if ((Size
.Width
< value.Width
) || (Size
.Height
< value.Height
)) {
715 Size
= new Size(Math
.Max(Size
.Width
, value.Width
), Math
.Max(Size
.Height
, value.Height
));
719 OnMinimumSizeChanged(EventArgs
.Empty
);
720 if (IsHandleCreated
) {
721 XplatUI
.SetWindowMinMax(Handle
, maximized_bounds
, minimum_size
, maximum_size
);
728 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
736 [TypeConverter(typeof(OpacityConverter
))]
737 [MWFCategory("Window Style")]
738 public double Opacity
{
740 if (IsHandleCreated
) {
741 if ((XplatUI
.SupportsTransparency () & TransparencySupport
.Get
) != 0)
742 return XplatUI
.GetWindowTransparency (Handle
);
751 AllowTransparency
= true;
753 if (IsHandleCreated
) {
755 if ((XplatUI
.SupportsTransparency () & TransparencySupport
.Set
) != 0)
756 XplatUI
.SetWindowTransparency(Handle
, opacity
, TransparencyKey
);
763 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
764 public Form
[] OwnedForms
{
768 form_list
= new Form
[owned_forms
.Count
];
770 for (int i
=0; i
<owned_forms
.Count
; i
++) {
771 form_list
[i
] = (Form
)owned_forms
[i
];
779 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
786 if (owner
!= value) {
788 owner
.RemoveOwnedForm(this);
792 owner
.AddOwnedForm(this);
793 if (IsHandleCreated
) {
794 if (owner
!= null && owner
.IsHandleCreated
) {
795 XplatUI
.SetTopmost(this.window
.Handle
, owner
.window
.Handle
, true);
797 XplatUI
.SetTopmost(this.window
.Handle
, IntPtr
.Zero
, false);
805 [MWFCategory("Window Style")]
806 public bool ShowInTaskbar
{
808 return show_in_taskbar
;
811 if (show_in_taskbar
!= value) {
812 show_in_taskbar
= value;
813 if (IsHandleCreated
) {
821 // new property so we can set the DesignerSerializationVisibility
822 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
824 public new Size Size
{
825 get { return base.Size; }
826 set { base.Size = value; }
829 [MonoTODO("Trigger something when GripStyle is set")]
830 [DefaultValue(SizeGripStyle
.Auto
)]
831 [MWFCategory("Window Style")]
832 public SizeGripStyle SizeGripStyle
{
834 return size_grip_style
;
838 size_grip_style
= value;
842 [DefaultValue(FormStartPosition
.WindowsDefaultLocation
)]
844 [MWFCategory("Layout")]
845 public FormStartPosition StartPosition
{
847 return start_position
;
851 if (start_position
== FormStartPosition
.WindowsDefaultLocation
) { // Only do this if it's not set yet
852 start_position
= value;
853 if (IsHandleCreated
) {
854 switch(start_position
) {
855 case FormStartPosition
.CenterParent
: {
860 case FormStartPosition
.CenterScreen
: {
865 case FormStartPosition
.Manual
: {
866 Left
= CreateParams
.X
;
867 Top
= CreateParams
.Y
;
880 // new property so we can set EditorBrowsable to never
882 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
883 [EditorBrowsable(EditorBrowsableState
.Never
)]
884 public new int TabIndex
{
885 get { return base.TabIndex; }
886 set { base.TabIndex = value; }
890 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
891 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
892 public bool TopLevel
{
894 return GetTopLevel();
898 if (!value && IsMdiContainer
)
899 throw new ArgumentException ("MDI Container forms must be top level.");
904 [DefaultValue(false)]
905 [MWFCategory("Window Style")]
906 public bool TopMost
{
912 if (topmost
!= value) {
915 XplatUI
.SetTopmost(window
.Handle
, owner
!= null ? owner
.window
.Handle
: IntPtr
.Zero
, value);
920 [MWFCategory("Window Style")]
921 public Color TransparencyKey
{
923 return transparency_key
;
927 transparency_key
= value;
929 AllowTransparency
= true;
931 if ((XplatUI
.SupportsTransparency () & TransparencySupport
.Set
) != 0)
932 XplatUI
.SetWindowTransparency(Handle
, Opacity
, transparency_key
);
936 [DefaultValue(FormWindowState
.Normal
)]
937 [MWFCategory("Layout")]
938 public FormWindowState WindowState
{
940 if (IsHandleCreated
) {
942 if (window_manager
!= null)
943 return window_manager
.GetWindowState ();
945 FormWindowState new_state
= XplatUI
.GetWindowState(Handle
);
946 if (new_state
!= (FormWindowState
)(-1))
947 window_state
= new_state
;
954 FormWindowState old_state
= window_state
;
955 window_state
= value;
956 if (IsHandleCreated
) {
958 if (window_manager
!= null) {
959 window_manager
.SetWindowState (old_state
, value);
963 XplatUI
.SetWindowState(Handle
, value);
968 #endregion // Public Instance Properties
970 #region Protected Instance Properties
971 protected override CreateParams CreateParams
{
973 CreateParams cp
= new CreateParams ();
976 cp
.ClassName
= XplatUI
.DefaultClassName
;
981 cp
.Parent
= IntPtr
.Zero
;
982 cp
.menu
= ActiveMenu
;
984 if (start_position
== FormStartPosition
.WindowsDefaultLocation
&& !IsMdiChild
) {
985 cp
.X
= unchecked((int)0x80000000);
986 cp
.Y
= unchecked((int)0x80000000);
994 cp
.Style
= (int)(WindowStyles
.WS_CLIPCHILDREN
| WindowStyles
.WS_CLIPSIBLINGS
);
997 cp
.Style
|= (int)(WindowStyles
.WS_CHILD
| WindowStyles
.WS_CAPTION
);
998 if (Parent
!= null) {
999 cp
.Parent
= Parent
.Handle
;
1002 cp
.ExStyle
|= (int) (WindowExStyles
.WS_EX_WINDOWEDGE
| WindowExStyles
.WS_EX_MDICHILD
);
1004 switch (FormBorderStyle
) {
1005 case FormBorderStyle
.None
:
1007 case FormBorderStyle
.FixedToolWindow
:
1008 case FormBorderStyle
.SizableToolWindow
:
1009 cp
.ExStyle
|= (int) WindowExStyles
.WS_EX_TOOLWINDOW
;
1012 cp
.Style
|= (int) WindowStyles
.WS_OVERLAPPEDWINDOW
;
1017 switch (FormBorderStyle
) {
1018 case FormBorderStyle
.Fixed3D
: {
1019 cp
.Style
|= (int)(WindowStyles
.WS_CAPTION
| WindowStyles
.WS_BORDER
);
1020 cp
.ExStyle
|= (int)WindowExStyles
.WS_EX_CLIENTEDGE
;
1024 case FormBorderStyle
.FixedDialog
: {
1025 cp
.Style
|= (int)(WindowStyles
.WS_CAPTION
| WindowStyles
.WS_BORDER
);
1026 cp
.ExStyle
|= (int)(WindowExStyles
.WS_EX_DLGMODALFRAME
| WindowExStyles
.WS_EX_CONTROLPARENT
);
1030 case FormBorderStyle
.FixedSingle
: {
1031 cp
.Style
|= (int)(WindowStyles
.WS_CAPTION
| WindowStyles
.WS_BORDER
);
1035 case FormBorderStyle
.FixedToolWindow
: {
1036 cp
.Style
|= (int)(WindowStyles
.WS_CAPTION
| WindowStyles
.WS_BORDER
);
1037 cp
.ExStyle
|= (int)(WindowExStyles
.WS_EX_TOOLWINDOW
);
1041 case FormBorderStyle
.Sizable
: {
1042 cp
.Style
|= (int)(WindowStyles
.WS_BORDER
| WindowStyles
.WS_THICKFRAME
| WindowStyles
.WS_CAPTION
);
1046 case FormBorderStyle
.SizableToolWindow
: {
1047 cp
.Style
|= (int)(WindowStyles
.WS_BORDER
| WindowStyles
.WS_THICKFRAME
| WindowStyles
.WS_CAPTION
);
1048 cp
.ExStyle
|= (int)(WindowExStyles
.WS_EX_TOOLWINDOW
);
1052 case FormBorderStyle
.None
: {
1058 switch(window_state
) {
1059 case FormWindowState
.Maximized
: {
1060 cp
.Style
|= (int)WindowStyles
.WS_MAXIMIZE
;
1064 case FormWindowState
.Minimized
: {
1065 cp
.Style
|= (int)WindowStyles
.WS_MINIMIZE
;
1071 cp
.ExStyle
|= (int) WindowExStyles
.WS_EX_TOPMOST
;
1074 if (ShowInTaskbar
) {
1075 cp
.ExStyle
|= (int)WindowExStyles
.WS_EX_APPWINDOW
;
1079 cp
.Style
|= (int)WindowStyles
.WS_MAXIMIZEBOX
;
1083 cp
.Style
|= (int)WindowStyles
.WS_MINIMIZEBOX
;
1087 cp
.Style
|= (int)WindowStyles
.WS_SYSMENU
;
1090 if (HelpButton
&& !MaximizeBox
&& !MinimizeBox
) {
1091 cp
.ExStyle
|= (int)WindowExStyles
.WS_EX_CONTEXTHELP
;
1095 cp
.Style
|= (int)WindowStyles
.WS_VISIBLE
;
1097 if (Opacity
< 1.0 || TransparencyKey
!= Color
.Empty
) {
1098 cp
.ExStyle
|= (int)WindowExStyles
.WS_EX_LAYERED
;
1101 if (!is_enabled
&& context
== null) {
1102 cp
.Style
|= (int)(WindowStyles
.WS_DISABLED
);
1109 protected override ImeMode DefaultImeMode
{
1111 return ImeMode
.NoControl
;
1115 protected override Size DefaultSize
{
1117 return new Size (300, 300);
1121 protected Rectangle MaximizedBounds
{
1123 if (maximized_bounds
!= Rectangle
.Empty
) {
1124 return maximized_bounds
;
1126 return default_maximized_bounds
;
1130 maximized_bounds
= value;
1131 OnMaximizedBoundsChanged(EventArgs
.Empty
);
1132 if (IsHandleCreated
) {
1133 XplatUI
.SetWindowMinMax(Handle
, maximized_bounds
, minimum_size
, maximum_size
);
1137 #endregion // Protected Instance Properties
1139 #region Public Static Methods
1140 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
1141 public static SizeF
GetAutoScaleSize (Font font
)
1143 return XplatUI
.GetAutoScaleSize(font
);
1146 #endregion // Public Static Methods
1148 #region Public Instance Methods
1149 internal SizeF
GetAutoScaleSize (Graphics g
, Font font
)
1152 // The following constants come from the dotnet mailing list
1153 // discussion: http://discuss.develop.com/archives/wa.exe?A2=ind0203A&L=DOTNET&P=R3655
1155 // The magic number is "Its almost the length
1156 // of the string with a smattering added in
1157 // for compat with earlier code".
1160 string magic_string
= "The quick brown fox jumped over the lazy dog.";
1161 double magic_number
= 44.549996948242189;
1162 float width
= (float) (g
.MeasureString (magic_string
, font
).Width
/ magic_number
);
1164 return new SizeF (width
, font
.Height
);
1167 public void Activate() {
1170 // The docs say activate only activates if our app is already active
1171 if (IsHandleCreated
) {
1173 MdiParent
.ActivateMdiChild (this);
1175 active
= ActiveForm
;
1176 if ((active
!= null) && (this != active
)) {
1177 XplatUI
.Activate(window
.Handle
);
1183 public void AddOwnedForm(Form ownedForm
) {
1184 if (!owned_forms
.Contains(ownedForm
)) {
1185 owned_forms
.Add(ownedForm
);
1187 ownedForm
.Owner
= this;
1190 public void Close () {
1198 FormClosingEventArgs ce
= new FormClosingEventArgs (CloseReason
.FormOwnerClosing
, false);
1203 XplatUI
.SendMessage(this.Handle
, Msg
.WM_CLOSE
, IntPtr
.Zero
, IntPtr
.Zero
);
1206 public void LayoutMdi(MdiLayout
value) {
1207 if (mdi_container
!= null) {
1208 mdi_container
.LayoutMdi(value);
1212 public void RemoveOwnedForm(Form ownedForm
) {
1213 owned_forms
.Remove(ownedForm
);
1216 public void SetDesktopBounds(int x
, int y
, int width
, int height
) {
1217 DesktopBounds
= new Rectangle(x
, y
, width
, height
);
1220 public void SetDesktopLocation(int x
, int y
) {
1221 DesktopLocation
= new Point(x
, y
);
1224 public DialogResult
ShowDialog() {
1225 return ShowDialog(this.owner
);
1228 public DialogResult
ShowDialog(IWin32Window ownerWin32
) {
1231 IntPtr capture_window
;
1235 if (ownerWin32
!= null) {
1236 Control c
= Control
.FromHandle (ownerWin32
.Handle
);
1238 owner
= c
.TopLevelControl
as Form
;
1241 if (owner
== this) {
1242 throw new InvalidOperationException("The 'ownerWin32' cannot be the form being shown.");
1246 throw new InvalidOperationException("The form is already displayed as a modal dialog.");
1250 throw new InvalidOperationException("Already visible forms cannot be displayed as a modal dialog. Set the Visible property to 'false' prior to calling Form.ShowDialog.");
1254 throw new InvalidOperationException("Cannot display a disabled form as modal dialog.");
1257 if (TopLevelControl
!= this) {
1258 throw new InvalidOperationException("Can only display TopLevel forms as modal dialog.");
1262 // Can't do this, will screw us in the modal loop
1263 form_parent_window
.Parent
= this.owner
;
1266 // Release any captures
1267 XplatUI
.GrabInfo(out capture_window
, out confined
, out area
);
1268 if (capture_window
!= IntPtr
.Zero
) {
1269 XplatUI
.UngrabWindow(capture_window
);
1273 // Commented out; we instead let the Visible=true inside the runloop create the control
1274 // otherwise setting DialogResult inside any of the events that are triggered by the
1275 // create will not actually cause the form to not be displayed.
1276 // Leaving this comment here in case there was an actual purpose to creating the control
1278 if (!IsHandleCreated
) {
1283 Application
.RunLoop(true, new ApplicationContext(this));
1285 if (owner
!= null) {
1286 // Cannot use Activate(), it has a check for the current active window...
1287 XplatUI
.Activate(owner
.window
.Handle
);
1290 if (DialogResult
!= DialogResult
.None
) {
1291 return DialogResult
;
1293 DialogResult
= DialogResult
.Cancel
;
1294 return DialogResult
.Cancel
;
1297 public override string ToString() {
1298 return GetType().FullName
.ToString() + ", Text: " + Text
;
1300 #endregion // Public Instance Methods
1302 #region Protected Instance Methods
1303 protected void ActivateMdiChild(Form form
) {
1304 if (!IsMdiContainer
)
1306 mdi_container
.ActivateChild (form
);
1307 OnMdiChildActivate(EventArgs
.Empty
);
1310 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
1311 protected override void AdjustFormScrollbars(bool displayScrollbars
) {
1312 base.AdjustFormScrollbars (displayScrollbars
);
1315 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
1316 protected void ApplyAutoScaling()
1318 SizeF current_size_f
= GetAutoScaleSize (DeviceContext
, Font
);
1319 Size current_size
= new Size ((int) current_size_f
.Width
, (int) current_size_f
.Height
);
1323 if (current_size
== autoscale_base_size
)
1326 if (Environment
.GetEnvironmentVariable ("MONO_MWF_SCALING") == "disable"){
1331 // I tried applying the Fudge height factor from:
1332 // http://blogs.msdn.com/mharsh/archive/2004/01/25/62621.aspx
1333 // but it makes things larger without looking better.
1335 if (current_size_f
.Width
!= AutoScaleBaseSize
.Width
) {
1336 dx
= current_size_f
.Width
/ AutoScaleBaseSize
.Width
+ 0.08f
;
1341 if (current_size_f
.Height
!= AutoScaleBaseSize
.Height
) {
1342 dy
= current_size_f
.Height
/ AutoScaleBaseSize
.Height
+ 0.08f
;
1349 AutoScaleBaseSize
= current_size
;
1352 protected void CenterToParent() {
1360 w
= DefaultSize
.Width
;
1366 h
= DefaultSize
.Height
;
1370 if (Parent
!= null) {
1372 } else if (owner
!= null) {
1376 if (owner
!= null) {
1377 this.Location
= new Point(ctl
.Left
+ ctl
.Width
/ 2 - w
/2, ctl
.Top
+ ctl
.Height
/ 2 - h
/ 2);
1381 protected void CenterToScreen() {
1389 w
= DefaultSize
.Width
;
1395 h
= DefaultSize
.Height
;
1398 XplatUI
.GetDisplaySize(out DisplaySize
);
1399 this.Location
= new Point(DisplaySize
.Width
/ 2 - w
/ 2, DisplaySize
.Height
/ 2 - h
/ 2);
1402 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
1403 protected override Control
.ControlCollection
CreateControlsInstance() {
1404 return base.CreateControlsInstance ();
1407 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
1408 protected override void CreateHandle() {
1409 base.CreateHandle ();
1413 if ((XplatUI
.SupportsTransparency() & TransparencySupport
.Set
) != 0) {
1414 if (allow_transparency
) {
1415 XplatUI
.SetWindowTransparency(Handle
, Opacity
, TransparencyKey
);
1419 XplatUI
.SetWindowMinMax(window
.Handle
, maximized_bounds
, minimum_size
, maximum_size
);
1420 if ((FormBorderStyle
!= FormBorderStyle
.FixedDialog
) && (icon
!= null)) {
1421 XplatUI
.SetIcon(window
.Handle
, icon
);
1424 if ((owner
!= null) && (owner
.IsHandleCreated
)) {
1425 XplatUI
.SetTopmost(window
.Handle
, owner
.window
.Handle
, true);
1428 for (int i
= 0; i
< owned_forms
.Count
; i
++) {
1429 if (owned_forms
[i
].IsHandleCreated
)
1430 XplatUI
.SetTopmost(owned_forms
[i
].window
.Handle
, window
.Handle
, true);
1433 if (window_manager
!= null && window_state
!= FormWindowState
.Normal
) {
1434 window_manager
.SetWindowState (FormWindowState
.Normal
, window_state
);
1439 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
1440 protected override void DefWndProc(ref Message m
) {
1441 base.DefWndProc (ref m
);
1444 protected override void Dispose(bool disposing
)
1446 for (int i
= 0; i
< owned_forms
.Count
; i
++)
1447 ((Form
)owned_forms
[i
]).Owner
= null;
1449 owned_forms
.Clear ();
1451 base.Dispose (disposing
);
1454 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
1455 protected virtual void OnActivated(EventArgs e
)
1458 SelectActiveControl ();
1460 EventHandler eh
= (EventHandler
)(Events
[ActivatedEvent
]);
1465 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
1466 protected virtual void OnClosed(EventArgs e
) {
1467 EventHandler eh
= (EventHandler
)(Events
[ClosedEvent
]);
1472 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
1473 protected virtual void OnClosing(System
.ComponentModel
.CancelEventArgs e
) {
1474 CancelEventHandler eh
= (CancelEventHandler
)(Events
[ClosingEvent
]);
1479 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
1480 protected override void OnCreateControl() {
1481 base.OnCreateControl ();
1484 XplatUI
.SetMenu(window
.Handle
, menu
);
1487 OnLoad(EventArgs
.Empty
);
1489 SelectActiveControl ();
1491 // Send initial location
1492 OnLocationChanged(EventArgs
.Empty
);
1494 if (IsMdiContainer
) {
1495 mdi_container
.LayoutMdi (MdiLayout
.Cascade
);
1499 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
1500 protected virtual void OnDeactivate(EventArgs e
) {
1501 EventHandler eh
= (EventHandler
)(Events
[DeactivateEvent
]);
1506 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
1507 protected override void OnFontChanged(EventArgs e
) {
1508 base.OnFontChanged (e
);
1511 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
1512 protected override void OnHandleCreated(EventArgs e
) {
1513 XplatUI
.SetBorderStyle(window
.Handle
, form_border_style
);
1514 base.OnHandleCreated (e
);
1517 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
1518 protected override void OnHandleDestroyed(EventArgs e
) {
1519 base.OnHandleDestroyed (e
);
1522 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
1523 protected virtual void OnInputLanguageChanged(InputLanguageChangedEventArgs e
) {
1524 InputLanguageChangedEventHandler eh
= (InputLanguageChangedEventHandler
)(Events
[InputLanguageChangedEvent
]);
1529 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
1530 protected virtual void OnInputLanguageChanging(InputLanguageChangingEventArgs e
) {
1531 InputLanguageChangingEventHandler eh
= (InputLanguageChangingEventHandler
)(Events
[InputLanguageChangingEvent
]);
1536 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
1537 protected virtual void OnLoad(EventArgs e
) {
1539 ApplyAutoScaling ();
1543 EventHandler eh
= (EventHandler
)(Events
[LoadEvent
]);
1548 switch (StartPosition
) {
1549 case FormStartPosition
.CenterScreen
:
1550 this.CenterToScreen();
1552 case FormStartPosition
.CenterParent
:
1553 this.CenterToParent ();
1555 case FormStartPosition
.Manual
:
1556 Left
= CreateParams
.X
;
1557 Top
= CreateParams
.Y
;
1564 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
1565 protected virtual void OnMaximizedBoundsChanged(EventArgs e
) {
1566 EventHandler eh
= (EventHandler
)(Events
[MaximizedBoundsChangedEvent
]);
1571 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
1572 protected virtual void OnMaximumSizeChanged(EventArgs e
) {
1573 EventHandler eh
= (EventHandler
)(Events
[MaximumSizeChangedEvent
]);
1578 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
1579 protected virtual void OnMdiChildActivate(EventArgs e
) {
1580 EventHandler eh
= (EventHandler
)(Events
[MdiChildActivateEvent
]);
1585 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
1586 protected virtual void OnMenuComplete(EventArgs e
) {
1587 EventHandler eh
= (EventHandler
)(Events
[MenuCompleteEvent
]);
1592 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
1593 protected virtual void OnMenuStart(EventArgs e
) {
1594 EventHandler eh
= (EventHandler
)(Events
[MenuStartEvent
]);
1599 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
1600 protected virtual void OnMinimumSizeChanged(EventArgs e
) {
1601 EventHandler eh
= (EventHandler
)(Events
[MinimumSizeChangedEvent
]);
1606 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
1607 protected override void OnPaint (PaintEventArgs pevent
) {
1608 base.OnPaint (pevent
);
1611 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
1612 protected override void OnResize(EventArgs e
) {
1615 if (this.IsMdiChild
&& ParentForm
!= null) {
1616 ParentForm
.PerformLayout();
1617 ParentForm
.Size
= ParentForm
.Size
;
1621 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
1622 protected override void OnStyleChanged(EventArgs e
) {
1623 base.OnStyleChanged (e
);
1626 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
1627 protected override void OnTextChanged(EventArgs e
) {
1628 base.OnTextChanged (e
);
1630 if (mdi_container
!= null)
1631 mdi_container
.SetParentText(true);
1634 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
1635 protected override void OnVisibleChanged(EventArgs e
) {
1636 base.OnVisibleChanged (e
);
1639 if (window_manager
!= null)
1640 window_manager
.SetWindowState (WindowState
, WindowState
);
1644 protected override bool ProcessCmdKey(ref Message msg
, Keys keyData
) {
1645 if (base.ProcessCmdKey (ref msg
, keyData
)) {
1649 // Give our menu a shot
1650 if (ActiveMenu
!= null) {
1651 return ActiveMenu
.ProcessCmdKey(ref msg
, keyData
);
1657 // LAMESPEC - Not documented that Form overrides ProcessDialogChar; class-status showed
1658 [EditorBrowsable (EditorBrowsableState
.Advanced
)]
1659 protected override bool ProcessDialogChar(char charCode
) {
1660 return base.ProcessDialogChar (charCode
);
1663 protected override bool ProcessDialogKey(Keys keyData
) {
1664 if ((keyData
& Keys
.Modifiers
) == 0) {
1665 if (keyData
== Keys
.Enter
) {
1666 IntPtr window
= XplatUI
.GetFocus ();
1667 Control c
= Control
.FromHandle (window
);
1668 if (c
is Button
&& c
.FindForm () == this) {
1669 ((Button
)c
).PerformClick ();
1672 else if (accept_button
!= null) {
1673 accept_button
.PerformClick();
1676 } else if (keyData
== Keys
.Escape
&& cancel_button
!= null) {
1677 cancel_button
.PerformClick();
1681 return base.ProcessDialogKey(keyData
);
1684 protected override bool ProcessKeyPreview(ref Message msg
) {
1686 if (ProcessKeyEventArgs(ref msg
)) {
1690 return base.ProcessKeyPreview (ref msg
);
1693 protected override bool ProcessTabKey(bool forward
) {
1694 return SelectNextControl(ActiveControl
, forward
, true, true, true);
1697 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
1698 protected override void ScaleCore(float dx
, float dy
) {
1702 // We can't scale max or min windows
1703 if (WindowState
== FormWindowState
.Normal
) {
1704 // We cannot call base since base also adjusts X/Y, but
1705 // a form is toplevel and doesn't move
1709 if (!GetStyle(ControlStyles
.FixedWidth
)) {
1710 size
.Width
= (int)(size
.Width
* dx
);
1713 if (!GetStyle(ControlStyles
.FixedHeight
)) {
1714 size
.Height
= (int)(size
.Height
* dy
);
1720 /* Now scale our children */
1721 Control
[] controls
= Controls
.GetAllControls ();
1722 for (int i
=0; i
< controls
.Length
; i
++) {
1723 controls
[i
].Scale(dx
, dy
);
1732 protected override void Select(bool directed
, bool forward
) {
1736 base.SelectNextControl(null, forward
, true, true, true);
1739 parent
= this.ParentForm
;
1740 if (parent
!= null) {
1741 parent
.ActiveControl
= this;
1747 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
1748 protected override void SetBoundsCore(int x
, int y
, int width
, int height
, BoundsSpecified specified
) {
1749 base.SetBoundsCore (x
, y
, width
, height
, specified
);
1752 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
1753 protected override void SetClientSizeCore(int x
, int y
) {
1754 if ((minimum_size
.Width
!= 0) && (x
< minimum_size
.Width
)) {
1755 x
= minimum_size
.Width
;
1756 } else if ((maximum_size
.Width
!= 0) && (x
> maximum_size
.Width
)) {
1757 x
= maximum_size
.Width
;
1760 if ((minimum_size
.Height
!= 0) && (y
< minimum_size
.Height
)) {
1761 y
= minimum_size
.Height
;
1762 } else if ((maximum_size
.Height
!= 0) && (y
> maximum_size
.Height
)) {
1763 y
= maximum_size
.Height
;
1766 Rectangle ClientRect
= new Rectangle(0, 0, x
, y
);
1767 Rectangle WindowRect
;
1768 CreateParams cp
= this.CreateParams
;
1770 clientsize_set
= new Size(x
, y
);
1772 if (XplatUI
.CalculateWindowRect(ref ClientRect
, cp
.Style
, cp
.ExStyle
, cp
.menu
, out WindowRect
)) {
1773 SetBounds(bounds
.X
, bounds
.Y
, WindowRect
.Width
, WindowRect
.Height
, BoundsSpecified
.Size
);
1777 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
1778 protected override void SetVisibleCore(bool value) {
1779 is_changing_visible_state
= true;
1780 has_been_visible
= value || has_been_visible
;
1781 base.SetVisibleCore (value);
1782 is_changing_visible_state
= false;
1785 protected override void UpdateDefaultButton() {
1786 base.UpdateDefaultButton ();
1789 [EditorBrowsable(EditorBrowsableState
.Advanced
)]
1790 protected override void WndProc(ref Message m
) {
1792 if (window_manager
!= null && window_manager
.HandleMessage (ref m
)) {
1796 switch((Msg
)m
.Msg
) {
1797 case Msg
.WM_DESTROY
: {
1798 base.WndProc(ref m
);
1799 if (!RecreatingHandle
) {
1800 this.closing
= true;
1805 case Msg
.WM_CLOSE_INTERNAL
: {
1810 case Msg
.WM_CLOSE
: {
1811 Form act
= Form
.ActiveForm
;
1812 if (act
!= null && act
!= this && act
.Modal
== true) {
1816 CancelEventArgs args
= new CancelEventArgs ();
1818 if (mdi_container
!= null) {
1819 foreach (Form mdi_child
in mdi_container
.MdiChildren
) {
1820 mdi_child
.OnClosing (args
);
1827 OnClosed (EventArgs
.Empty
);
1834 DialogResult
= DialogResult
.None
;
1837 OnClosed (EventArgs
.Empty
);
1846 case Msg
.WM_WINDOWPOSCHANGED
: {
1847 if (WindowState
!= FormWindowState
.Minimized
) {
1848 base.WndProc(ref m
);
1854 case Msg
.WM_SYSCOMMAND
: {
1855 // Let *Strips know the app's title bar was clicked
1856 if (XplatUI
.IsEnabled (Handle
))
1857 ToolStripManager
.FireAppClicked ();
1859 base.WndProc(ref m
);
1864 case Msg
.WM_ACTIVATE
: {
1865 if (m
.WParam
!= (IntPtr
)WindowActiveFlags
.WA_INACTIVE
) {
1866 OnActivated(EventArgs
.Empty
);
1868 OnDeactivate(EventArgs
.Empty
);
1873 case Msg
.WM_KILLFOCUS
: {
1874 base.WndProc(ref m
);
1878 case Msg
.WM_SETFOCUS
: {
1879 if (ActiveControl
!= null && ActiveControl
!= this) {
1880 ActiveControl
.Focus();
1881 return; // FIXME - do we need to run base.WndProc, even though we just changed focus?
1883 base.WndProc(ref m
);
1888 case Msg
.WM_NCLBUTTONDOWN
: {
1889 if (XplatUI
.IsEnabled (Handle
) && ActiveMenu
!= null) {
1890 ActiveMenu
.OnMouseDown(this, new MouseEventArgs (FromParamToMouseButtons ((int) m
.WParam
.ToInt32()), mouse_clicks
, Control
.MousePosition
.X
, Control
.MousePosition
.Y
, 0));
1893 if (ActiveMaximizedMdiChild
!= null) {
1894 if (ActiveMaximizedMdiChild
.HandleMenuMouseDown (ActiveMenu
,
1895 LowOrder ((int) m
.LParam
.ToInt32 ()),
1896 HighOrder ((int) m
.LParam
.ToInt32 ()))) {
1897 // Don't let base process this message, otherwise we won't
1898 // get a WM_NCLBUTTONUP.
1902 base.WndProc(ref m
);
1905 case Msg
.WM_NCLBUTTONUP
: {
1906 if (ActiveMaximizedMdiChild
!= null) {
1907 ActiveMaximizedMdiChild
.HandleMenuMouseUp (ActiveMenu
,
1908 LowOrder ((int)m
.LParam
.ToInt32 ()),
1909 HighOrder ((int)m
.LParam
.ToInt32 ()));
1911 base.WndProc (ref m
);
1915 case Msg
.WM_NCMOUSELEAVE
: {
1916 if (ActiveMaximizedMdiChild
!= null) {
1917 ActiveMaximizedMdiChild
.HandleMenuMouseLeave(ActiveMenu
,
1918 LowOrder((int)m
.LParam
.ToInt32()),
1919 HighOrder((int)m
.LParam
.ToInt32()));
1921 base.WndProc(ref m
);
1925 case Msg
.WM_NCMOUSEMOVE
: {
1926 if (XplatUI
.IsEnabled (Handle
) && ActiveMenu
!= null) {
1927 ActiveMenu
.OnMouseMove(this, new MouseEventArgs (FromParamToMouseButtons ((int) m
.WParam
.ToInt32()), mouse_clicks
, LowOrder ((int) m
.LParam
.ToInt32 ()), HighOrder ((int) m
.LParam
.ToInt32 ()), 0));
1930 if (ActiveMaximizedMdiChild
!= null) {
1931 ActiveMaximizedMdiChild
.HandleMenuMouseMove (ActiveMenu
,
1932 LowOrder ((int)m
.LParam
.ToInt32 ()),
1933 HighOrder ((int)m
.LParam
.ToInt32 ()));
1935 base.WndProc(ref m
);
1939 case Msg
.WM_NCPAINT
: {
1940 if (ActiveMenu
!= null) {
1944 pe
= XplatUI
.PaintEventStart(Handle
, false);
1945 pnt
= XplatUI
.GetMenuOrigin(window
.Handle
);
1947 // The entire menu has to be in the clip rectangle because the
1948 // control buttons are right-aligned and otherwise they would
1949 // stay painted when the window gets resized.
1950 Rectangle clip
= new Rectangle (pnt
.X
, pnt
.Y
, ClientSize
.Width
, 0);
1951 clip
= Rectangle
.Union(clip
, pe
.ClipRectangle
);
1953 pe
.Graphics
.SetClip(clip
);
1955 ActiveMenu
.Draw (pe
, new Rectangle (pnt
.X
, pnt
.Y
, ClientSize
.Width
, 0));
1957 if (ActiveMaximizedMdiChild
!= null) {
1958 ActiveMaximizedMdiChild
.DrawMaximizedButtons (ActiveMenu
, pe
);
1961 XplatUI
.PaintEventEnd(Handle
, false);
1964 base.WndProc(ref m
);
1968 case Msg
.WM_NCCALCSIZE
: {
1969 XplatUIWin32
.NCCALCSIZE_PARAMS ncp
;
1971 if ((ActiveMenu
!= null) && (m
.WParam
== (IntPtr
)1)) {
1972 ncp
= (XplatUIWin32
.NCCALCSIZE_PARAMS
)Marshal
.PtrToStructure(m
.LParam
, typeof(XplatUIWin32
.NCCALCSIZE_PARAMS
));
1975 ncp
.rgrc1
.top
+= ThemeEngine
.Current
.CalcMenuBarSize (DeviceContext
, ActiveMenu
, ncp
.rgrc1
.right
- ncp
.rgrc1
.left
);
1976 Marshal
.StructureToPtr(ncp
, m
.LParam
, true);
1982 case Msg
.WM_MOUSEMOVE
: {
1983 if (XplatUI
.IsEnabled (Handle
) && active_tracker
!= null) {
1984 MouseEventArgs args
;
1986 args
= new MouseEventArgs (FromParamToMouseButtons ((int) m
.WParam
.ToInt32()),
1987 mouse_clicks
, LowOrder ((int) m
.LParam
.ToInt32 ()), HighOrder ((int) m
.LParam
.ToInt32 ()), 0);
1988 active_tracker
.OnMotion(new MouseEventArgs (args
.Button
, args
.Clicks
, Control
.MousePosition
.X
, Control
.MousePosition
.Y
, args
.Delta
));
1991 base.WndProc(ref m
);
1995 case Msg
.WM_LBUTTONDOWN
:
1996 case Msg
.WM_MBUTTONDOWN
:
1997 case Msg
.WM_RBUTTONDOWN
: {
1998 if (XplatUI
.IsEnabled (Handle
) && active_tracker
!= null) {
1999 MouseEventArgs args
;
2001 args
= new MouseEventArgs (FromParamToMouseButtons ((int) m
.WParam
.ToInt32()),
2002 mouse_clicks
, LowOrder ((int) m
.LParam
.ToInt32 ()), HighOrder ((int) m
.LParam
.ToInt32 ()), 0);
2003 active_tracker
.OnMouseDown(new MouseEventArgs (args
.Button
, args
.Clicks
, Control
.MousePosition
.X
, Control
.MousePosition
.Y
, args
.Delta
));
2006 base.WndProc(ref m
);
2010 case Msg
.WM_LBUTTONUP
:
2011 case Msg
.WM_MBUTTONUP
:
2012 case Msg
.WM_RBUTTONUP
: {
2013 if (XplatUI
.IsEnabled (Handle
) && active_tracker
!= null) {
2014 MouseEventArgs args
;
2015 MouseButtons mb
= FromParamToMouseButtons ((int) m
.WParam
.ToInt32());
2017 // We add in the button that was released (not sent in WParam)
2018 switch((Msg
)m
.Msg
) {
2019 case Msg
.WM_LBUTTONUP
:
2020 mb
|= MouseButtons
.Left
;
2022 case Msg
.WM_MBUTTONUP
:
2023 mb
|= MouseButtons
.Middle
;
2025 case Msg
.WM_RBUTTONUP
:
2026 mb
|= MouseButtons
.Right
;
2030 args
= new MouseEventArgs (mb
, mouse_clicks
, LowOrder ((int) m
.LParam
.ToInt32 ()), HighOrder ((int) m
.LParam
.ToInt32 ()), 0);
2031 active_tracker
.OnMouseUp(new MouseEventArgs (args
.Button
, args
.Clicks
, Control
.MousePosition
.X
, Control
.MousePosition
.Y
, args
.Delta
));
2035 base.WndProc(ref m
);
2039 case Msg
.WM_GETMINMAXINFO
: {
2042 if (m
.LParam
!= IntPtr
.Zero
) {
2043 mmi
= (MINMAXINFO
)Marshal
.PtrToStructure(m
.LParam
, typeof(MINMAXINFO
));
2045 default_maximized_bounds
= new Rectangle(mmi
.ptMaxPosition
.x
, mmi
.ptMaxPosition
.y
, mmi
.ptMaxSize
.x
, mmi
.ptMaxSize
.y
);
2046 if (maximized_bounds
!= Rectangle
.Empty
) {
2047 mmi
.ptMaxPosition
.x
= maximized_bounds
.Left
;
2048 mmi
.ptMaxPosition
.y
= maximized_bounds
.Top
;
2049 mmi
.ptMaxSize
.x
= maximized_bounds
.Width
;
2050 mmi
.ptMaxSize
.y
= maximized_bounds
.Height
;
2053 if (minimum_size
!= Size
.Empty
) {
2054 mmi
.ptMinTrackSize
.x
= minimum_size
.Width
;
2055 mmi
.ptMinTrackSize
.y
= minimum_size
.Height
;
2058 if (maximum_size
!= Size
.Empty
) {
2059 mmi
.ptMaxTrackSize
.x
= maximum_size
.Width
;
2060 mmi
.ptMaxTrackSize
.y
= maximum_size
.Height
;
2062 Marshal
.StructureToPtr(mmi
, m
.LParam
, false);
2068 case Msg
.WM_MOUSEACTIVATE
: {
2069 // Let *Strips know the form or another control has been clicked
2070 if (XplatUI
.IsEnabled (Handle
))
2071 ToolStripManager
.FireAppClicked ();
2073 base.WndProc (ref m
);
2077 case Msg
.WM_ACTIVATEAPP
: {
2078 // Let *Strips know the app lost focus
2079 if (m
.WParam
== (IntPtr
)0)
2080 if (XplatUI
.IsEnabled (Handle
))
2081 ToolStripManager
.FireAppFocusChanged (this);
2083 base.WndProc (ref m
);
2089 base.WndProc (ref m
);
2094 #endregion // Protected Instance Methods
2096 internal void RemoveWindowManager ()
2098 window_manager
= null;
2101 internal override void CheckAcceptButton()
2103 if (accept_button
!= null) {
2104 Button a_button
= accept_button
as Button
;
2106 if (ActiveControl
== a_button
)
2109 if (ActiveControl
is Button
) {
2110 a_button
.paint_as_acceptbutton
= false;
2114 a_button
.paint_as_acceptbutton
= true;
2121 static object ActivatedEvent
= new object ();
2122 static object ClosedEvent
= new object ();
2123 static object ClosingEvent
= new object ();
2124 static object DeactivateEvent
= new object ();
2125 static object InputLanguageChangedEvent
= new object ();
2126 static object InputLanguageChangingEvent
= new object ();
2127 static object LoadEvent
= new object ();
2128 static object MaximizedBoundsChangedEvent
= new object ();
2129 static object MaximumSizeChangedEvent
= new object ();
2130 static object MdiChildActivateEvent
= new object ();
2131 static object MenuCompleteEvent
= new object ();
2132 static object MenuStartEvent
= new object ();
2133 static object MinimumSizeChangedEvent
= new object ();
2135 public event EventHandler Activated
{
2136 add { Events.AddHandler (ActivatedEvent, value); }
2137 remove { Events.RemoveHandler (ActivatedEvent, value); }
2140 public event EventHandler Closed
{
2141 add { Events.AddHandler (ClosedEvent, value); }
2142 remove { Events.RemoveHandler (ClosedEvent, value); }
2145 public event CancelEventHandler Closing
{
2146 add { Events.AddHandler (ClosingEvent, value); }
2147 remove { Events.RemoveHandler (ClosingEvent, value); }
2150 public event EventHandler Deactivate
{
2151 add { Events.AddHandler (DeactivateEvent, value); }
2152 remove { Events.RemoveHandler (DeactivateEvent, value); }
2155 public event InputLanguageChangedEventHandler InputLanguageChanged
{
2156 add { Events.AddHandler (InputLanguageChangedEvent, value); }
2157 remove { Events.RemoveHandler (InputLanguageChangedEvent, value); }
2160 public event InputLanguageChangingEventHandler InputLanguageChanging
{
2161 add { Events.AddHandler (InputLanguageChangingEvent, value); }
2162 remove { Events.RemoveHandler (InputLanguageChangingEvent, value); }
2165 public event EventHandler Load
{
2166 add { Events.AddHandler (LoadEvent, value); }
2167 remove { Events.RemoveHandler (LoadEvent, value); }
2170 public event EventHandler MaximizedBoundsChanged
{
2171 add { Events.AddHandler (MaximizedBoundsChangedEvent, value); }
2172 remove { Events.RemoveHandler (MaximizedBoundsChangedEvent, value); }
2175 public event EventHandler MaximumSizeChanged
{
2176 add { Events.AddHandler (MaximumSizeChangedEvent, value); }
2177 remove { Events.RemoveHandler (MaximumSizeChangedEvent, value); }
2180 public event EventHandler MdiChildActivate
{
2181 add { Events.AddHandler (MdiChildActivateEvent, value); }
2182 remove { Events.RemoveHandler (MdiChildActivateEvent, value); }
2185 public event EventHandler MenuComplete
{
2186 add { Events.AddHandler (MenuCompleteEvent, value); }
2187 remove { Events.RemoveHandler (MenuCompleteEvent, value); }
2190 public event EventHandler MenuStart
{
2191 add { Events.AddHandler (MenuStartEvent, value); }
2192 remove { Events.RemoveHandler (MenuStartEvent, value); }
2195 public event EventHandler MinimumSizeChanged
{
2196 add { Events.AddHandler (MinimumSizeChangedEvent, value); }
2197 remove { Events.RemoveHandler (MinimumSizeChangedEvent, value); }
2202 [EditorBrowsable(EditorBrowsableState
.Never
)]
2203 public new event EventHandler TabIndexChanged
{
2204 add { base.TabIndexChanged += value; }
2205 remove { base.TabIndexChanged -= value; }
2207 #endregion // Events
2210 public override string Text
{
2220 public new Point Location
{
2222 return base.Location
;
2226 base.Location
= value;
2230 static object FormClosingEvent
= new object ();
2231 static object FormClosedEvent
= new object ();
2233 public event FormClosingEventHandler FormClosing
{
2234 add { Events.AddHandler (FormClosingEvent, value); }
2235 remove { Events.RemoveHandler (FormClosingEvent, value); }
2238 public event FormClosedEventHandler FormClosed
{
2239 add { Events.AddHandler (FormClosedEvent, value); }
2240 remove { Events.RemoveHandler (FormClosedEvent, value); }
2243 protected virtual void OnFormClosing (FormClosingEventArgs e
)
2245 FormClosingEventHandler eh
= (FormClosingEventHandler
)(Events
[FormClosingEvent
]);