* Control.cs: Make IsRecreating internal so that the driver can
[mono-project.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / Form.cs
blob778e6c427c0331f0029152435f870b166c4246a9
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:
8 //
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
11 //
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.
22 // Authors:
23 // Peter Bartok pbartok@novell.com
26 // NOT COMPLETE
28 using System;
29 using System.Drawing;
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")]
42 [ToolboxItem(false)]
43 public class Form : ContainerControl {
44 #region Local Variables
45 internal static Form active_form;
46 internal bool closing;
47 FormBorderStyle form_border_style;
48 private bool autoscale;
49 private Size clientsize_set;
50 private Size autoscale_base_size;
51 private bool allow_transparency;
52 private static Icon default_icon;
53 internal bool is_modal;
54 internal FormWindowState window_state;
55 private bool control_box;
56 private bool minimize_box;
57 private bool maximize_box;
58 private bool help_button;
59 private bool show_in_taskbar;
60 private bool topmost;
61 private IButtonControl accept_button;
62 private IButtonControl cancel_button;
63 private DialogResult dialog_result;
64 private FormStartPosition start_position;
65 private Form owner;
66 private Form.ControlCollection owned_forms;
67 private MdiClient mdi_container;
68 internal InternalWindowManager window_manager;
69 private Form mdi_parent;
70 private bool key_preview;
71 private MainMenu menu;
72 private Icon icon;
73 private Size maximum_size;
74 private Size minimum_size;
75 private SizeGripStyle size_grip_style;
76 private Rectangle maximized_bounds;
77 private Rectangle default_maximized_bounds;
78 private double opacity;
79 internal ApplicationContext context;
80 Color transparency_key;
81 internal MenuTracker active_tracker;
83 #endregion // Local Variables
85 #region Private & Internal Methods
86 static Form ()
88 default_icon = (Icon)Locale.GetResource("mono.ico");
91 // warning: this is only hooked up when an mdi container is created.
92 private void ControlAddedHandler (object sender, ControlEventArgs e)
94 if (mdi_container != null) {
95 Console.WriteLine ("SENDING TO BACK");
96 mdi_container.SendToBack ();
99 #endregion // Private & Internal Methods
101 #region Public Classes
102 public new class ControlCollection : Control.ControlCollection {
103 Form form_owner;
105 public ControlCollection(Form owner) : base(owner) {
106 this.form_owner = owner;
109 public override void Add(Control value) {
110 if (Contains (value))
111 return;
112 AddToList (value);
113 ((Form)value).owner=(Form)owner;
116 public override void Remove(Control value) {
117 ((Form)value).owner = null;
118 base.Remove (value);
121 #endregion // Public Classes
123 #region Public Constructor & Destructor
124 public Form ()
126 SizeF current_scale = GetAutoScaleSize (DeviceContext, Font);
128 autoscale = true;
129 autoscale_base_size = new Size ((int)current_scale.Width, (int) current_scale.Height);
130 allow_transparency = false;
131 closing = false;
132 is_modal = false;
133 dialog_result = DialogResult.None;
134 start_position = FormStartPosition.WindowsDefaultLocation;
135 form_border_style = FormBorderStyle.Sizable;
136 window_state = FormWindowState.Normal;
137 key_preview = false;
138 opacity = 1D;
139 menu = null;
140 icon = default_icon;
141 minimum_size = Size.Empty;
142 maximum_size = Size.Empty;
143 clientsize_set = Size.Empty;
144 control_box = true;
145 minimize_box = true;
146 maximize_box = true;
147 help_button = false;
148 show_in_taskbar = true;
149 ime_mode = ImeMode.NoControl;
150 is_visible = false;
151 is_toplevel = true;
152 size_grip_style = SizeGripStyle.Auto;
153 maximized_bounds = Rectangle.Empty;
154 default_maximized_bounds = Rectangle.Empty;
155 owned_forms = new Form.ControlCollection(this);
156 transparency_key = Color.Empty;
158 #endregion // Public Constructor & Destructor
160 #region Public Static Properties
162 public static Form ActiveForm {
163 get {
164 Control active;
166 active = FromHandle(XplatUI.GetActive());
168 if (active != null) {
169 if ( !(active is Form)) {
170 Control parent;
172 parent = active.Parent;
173 while (parent != null) {
174 if (parent is Form) {
175 return (Form)parent;
177 parent = parent.Parent;
179 } else {
180 return (Form)active;
183 return null;
187 #endregion // Public Static Properties
189 #region Public Instance Properties
190 [DefaultValue(null)]
191 public IButtonControl AcceptButton {
192 get {
193 return accept_button;
196 set {
197 accept_button = value;
198 CheckAcceptButton();
202 [Browsable(false)]
203 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
204 public bool AllowTransparency {
205 get {
206 return allow_transparency;
209 set {
210 if (value == allow_transparency) {
211 return;
214 if (XplatUI.SupportsTransparency()) {
215 allow_transparency = value;
217 if (value) {
218 if (IsHandleCreated) {
219 XplatUI.SetWindowTransparency(Handle, Opacity, TransparencyKey);
221 } else {
222 UpdateStyles(); // Remove the WS_EX_LAYERED style
228 [DefaultValue(true)]
229 [MWFCategory("Layout")]
230 public bool AutoScale {
231 get {
232 return autoscale;
235 set {
236 autoscale = value;
240 [Localizable(true)]
241 [Browsable(false)]
242 [EditorBrowsable(EditorBrowsableState.Advanced)]
243 public virtual Size AutoScaleBaseSize {
244 get {
245 return autoscale_base_size;
248 set {
249 autoscale_base_size = value;
253 [Localizable(true)]
254 public override bool AutoScroll {
255 get {
256 return base.AutoScroll;
258 set {
259 base.AutoScroll = value;
263 public override Color BackColor {
264 get {
265 return base.BackColor;
267 set {
268 base.BackColor = value;
272 [DefaultValue(null)]
273 public IButtonControl CancelButton {
274 get {
275 return cancel_button;
278 set {
279 cancel_button = value;
283 [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
284 [Localizable(true)]
285 public Size ClientSize {
286 get {
287 return base.ClientSize;
290 set {
291 base.ClientSize = value;
295 [DefaultValue(true)]
296 [MWFCategory("Window Style")]
297 public bool ControlBox {
298 get {
299 return control_box;
302 set {
303 if (control_box != value) {
304 control_box = value;
305 UpdateStyles();
310 [Browsable(false)]
311 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
312 public Rectangle DesktopBounds {
313 get {
314 return new Rectangle(Location, Size);
317 set {
318 Bounds = value;
322 [Browsable(false)]
323 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
324 public Point DesktopLocation {
325 get {
326 return Location;
329 set {
330 Location = value;
334 [Browsable(false)]
335 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
336 public DialogResult DialogResult {
337 get {
338 return dialog_result;
341 set {
342 if (value < DialogResult.None || value > DialogResult.No)
343 throw new InvalidEnumArgumentException ("value", (int) value,
344 typeof (DialogResult));
346 dialog_result = value;
347 if (is_modal) {
348 closing = true;
353 [DefaultValue(FormBorderStyle.Sizable)]
354 [DispId(-504)]
355 [MWFCategory("Appearance")]
356 public FormBorderStyle FormBorderStyle {
357 get {
358 return form_border_style;
360 set {
361 form_border_style = value;
363 if (window_manager == null) {
364 if (IsHandleCreated) {
365 XplatUI.SetBorderStyle(window.Handle, form_border_style);
367 } else {
368 window_manager.UpdateBorderStyle (value);
371 UpdateStyles();
375 [DefaultValue(false)]
376 [MWFCategory("Window Style")]
377 public bool HelpButton {
378 get {
379 return help_button;
382 set {
383 if (help_button != value) {
384 help_button = value;
385 UpdateStyles();
390 [Localizable(true)]
391 [AmbientValue(null)]
392 [MWFCategory("Window Style")]
393 public Icon Icon {
394 get {
395 return icon;
398 set {
399 if (icon != value) {
400 icon = value;
402 if (IsHandleCreated) {
403 XplatUI.SetIcon(Handle, icon == null ? default_icon : icon);
409 [Browsable(false)]
410 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
411 public bool IsMdiChild {
412 get {
413 return mdi_parent != null;
417 [DefaultValue(false)]
418 [MWFCategory("Window Style")]
419 public bool IsMdiContainer {
420 get {
421 return mdi_container != null;
424 set {
425 if (value && mdi_container == null) {
426 mdi_container = new MdiClient ();
427 Controls.Add(mdi_container);
428 ControlAdded += new ControlEventHandler (ControlAddedHandler);
429 mdi_container.SendToBack ();
430 } else if (!value && mdi_container != null) {
431 Controls.Remove(mdi_container);
432 mdi_container = null;
437 [Browsable(false)]
438 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
439 public Form ActiveMdiChild {
440 get {
441 if (!IsMdiContainer)
442 return null;
443 return (Form) mdi_container.ActiveMdiChild;
447 [Browsable(false)]
448 [EditorBrowsable(EditorBrowsableState.Advanced)]
449 public bool IsRestrictedWindow {
450 get {
451 return false;
455 [DefaultValue(false)]
456 public bool KeyPreview {
457 get {
458 return key_preview;
461 set {
462 key_preview = value;
466 [DefaultValue(true)]
467 [MWFCategory("Window Style")]
468 public bool MaximizeBox {
469 get {
470 return maximize_box;
472 set {
473 if (maximize_box != value) {
474 maximize_box = value;
475 if (IsHandleCreated) {
476 RecreateHandle();
478 UpdateStyles();
483 [DefaultValue("{Width=0, Height=0}")]
484 [Localizable(true)]
485 [RefreshProperties(RefreshProperties.Repaint)]
486 [MWFCategory("Layout")]
487 public Size MaximumSize {
488 get {
489 return maximum_size;
492 set {
493 if (maximum_size != value) {
494 maximum_size = value;
495 OnMaximumSizeChanged(EventArgs.Empty);
496 if (IsHandleCreated) {
497 XplatUI.SetWindowMinMax(Handle, maximized_bounds, minimum_size, maximum_size);
503 [Browsable(false)]
504 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
505 public Form[] MdiChildren {
506 get {
507 if (mdi_container != null)
508 return mdi_container.MdiChildren;
509 else
510 return new Form[0];
514 [Browsable(false)]
515 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
516 public Form MdiParent {
517 get {
518 return mdi_parent;
521 set {
522 if (value != null && !value.IsMdiContainer)
523 throw new ArgumentException ();
525 if (mdi_parent != null) {
526 mdi_parent.MdiContainer.Controls.Remove (this);
529 if (value != null) {
530 mdi_parent = value;
531 window_manager = new MdiWindowManager (this,
532 mdi_parent.MdiContainer);
533 mdi_parent.MdiContainer.Controls.Add (this);
535 RecreateHandle ();
537 } else if (mdi_parent != null) {
538 mdi_parent = null;
540 // Create a new window manager
541 window_manager = null;
542 FormBorderStyle = form_border_style;
544 RecreateHandle ();
549 internal MenuTracker ActiveTracker {
550 get { return active_tracker; }
551 set {
552 if (value == active_tracker)
553 return;
555 Capture = value != null;
556 active_tracker = value;
560 internal MdiClient MdiContainer {
561 get { return mdi_container; }
564 internal InternalWindowManager WindowManager {
565 get { return window_manager; }
568 [DefaultValue(null)]
569 [MWFCategory("Window Style")]
570 public MainMenu Menu {
571 get {
572 return menu;
575 set {
576 if (menu != value) {
577 menu = value;
579 if (menu != null && !IsMdiChild) {
580 menu.SetForm (this);
582 if (IsHandleCreated) {
583 XplatUI.SetMenu (window.Handle, menu);
586 if (clientsize_set != Size.Empty) {
587 SetClientSizeCore(clientsize_set.Width, clientsize_set.Height);
588 } else {
589 UpdateBounds (bounds.X, bounds.Y, bounds.Width, bounds.Height, ClientSize.Width, ClientSize.Height -
590 ThemeEngine.Current.CalcMenuBarSize (DeviceContext, menu, ClientSize.Width));
592 } else
593 UpdateBounds ();
598 [Browsable(false)]
599 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
600 [EditorBrowsable(EditorBrowsableState.Advanced)]
601 public MainMenu MergedMenu {
602 get {
603 if (!IsMdiChild || window_manager == null)
604 return null;
605 return ((MdiWindowManager) window_manager).MergedMenu;
609 // This is the menu in display and being used because of merging this can
610 // be different then the menu that is actually assosciated with the form
611 internal MainMenu ActiveMenu {
612 get {
613 if (IsMdiChild)
614 return null;
616 if (IsMdiContainer && mdi_container.Controls.Count > 0 &&
617 ((Form) mdi_container.Controls [0]).WindowState == FormWindowState.Maximized) {
618 MdiWindowManager wm = (MdiWindowManager) ((Form) mdi_container.Controls [0]).WindowManager;
619 return wm.MaximizedMenu;
622 Form amc = ActiveMdiChild;
623 if (amc == null || amc.Menu == null)
624 return menu;
625 return amc.MergedMenu;
629 internal MdiWindowManager ActiveMaximizedMdiChild {
630 get {
631 Form child = ActiveMdiChild;
632 if (child == null)
633 return null;
634 if (child.WindowManager == null || child.window_state != FormWindowState.Maximized)
635 return null;
636 return (MdiWindowManager) child.WindowManager;
640 [DefaultValue(true)]
641 [MWFCategory("Window Style")]
642 public bool MinimizeBox {
643 get {
644 return minimize_box;
646 set {
647 if (minimize_box != value) {
648 minimize_box = value;
649 if (IsHandleCreated) {
650 RecreateHandle();
652 UpdateStyles();
657 [DefaultValue("{Width=0, Height=0}")]
658 [Localizable(true)]
659 [RefreshProperties(RefreshProperties.Repaint)]
660 [MWFCategory("Layout")]
661 public Size MinimumSize {
662 get {
663 return minimum_size;
666 set {
667 if (minimum_size != value) {
668 minimum_size = value;
670 if ((Size.Width < value.Width) || (Size.Height < value.Height)) {
671 Size = new Size(Math.Max(Size.Width, value.Width), Math.Max(Size.Height, value.Height));
675 OnMinimumSizeChanged(EventArgs.Empty);
676 if (IsHandleCreated) {
677 XplatUI.SetWindowMinMax(Handle, maximized_bounds, minimum_size, maximum_size);
683 [Browsable(false)]
684 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
685 public bool Modal {
686 get {
687 return is_modal;
691 [DefaultValue(1D)]
692 [TypeConverter(typeof(OpacityConverter))]
693 [MWFCategory("Window Style")]
694 public double Opacity {
695 get {
696 return opacity;
699 set {
700 opacity = value;
702 AllowTransparency = true;
704 if (IsHandleCreated) {
705 UpdateStyles();
706 XplatUI.SetWindowTransparency(Handle, opacity, TransparencyKey);
712 [Browsable(false)]
713 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
714 public Form[] OwnedForms {
715 get {
716 Form[] form_list;
718 form_list = new Form[owned_forms.Count];
720 for (int i=0; i<owned_forms.Count; i++) {
721 form_list[i] = (Form)owned_forms[i];
724 return form_list;
728 [Browsable(false)]
729 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
730 public Form Owner {
731 get {
732 return owner;
735 set {
736 if (owner != value) {
737 if (owner != null) {
738 owner.RemoveOwnedForm(this);
740 owner = value;
741 owner.AddOwnedForm(this);
742 if (IsHandleCreated) {
743 if (owner != null && owner.IsHandleCreated) {
744 XplatUI.SetTopmost(this.window.Handle, owner.window.Handle, true);
745 } else {
746 XplatUI.SetTopmost(this.window.Handle, IntPtr.Zero, false);
753 [DefaultValue(true)]
754 [MWFCategory("Window Style")]
755 public bool ShowInTaskbar {
756 get {
757 return show_in_taskbar;
759 set {
760 if (show_in_taskbar != value) {
761 show_in_taskbar = value;
762 if (IsHandleCreated) {
763 RecreateHandle();
765 UpdateStyles();
770 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
771 [Localizable(false)]
772 public Size Size {
773 get {
774 return base.Size;
777 set {
778 base.Size = value;
782 [MonoTODO("Trigger something when GripStyle is set")]
783 [DefaultValue(SizeGripStyle.Auto)]
784 [MWFCategory("Window Style")]
785 public SizeGripStyle SizeGripStyle {
786 get {
787 return size_grip_style;
790 set {
791 size_grip_style = value;
795 [DefaultValue(FormStartPosition.WindowsDefaultLocation)]
796 [Localizable(true)]
797 [MWFCategory("Layout")]
798 public FormStartPosition StartPosition {
799 get {
800 return start_position;
803 set {
804 if (start_position == FormStartPosition.WindowsDefaultLocation) { // Only do this if it's not set yet
805 start_position = value;
806 if (IsHandleCreated) {
807 switch(start_position) {
808 case FormStartPosition.CenterParent: {
809 CenterToParent();
810 break;
813 case FormStartPosition.CenterScreen: {
814 CenterToScreen();
815 break;
818 case FormStartPosition.Manual: {
819 Left = CreateParams.X;
820 Top = CreateParams.Y;
821 break;
824 default: {
825 break;
833 [Browsable(false)]
834 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
835 [EditorBrowsable(EditorBrowsableState.Never)]
836 public int TabIndex {
837 get {
838 return base.TabIndex;
841 set {
842 base.TabIndex = value;
846 [Browsable(false)]
847 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
848 [EditorBrowsable(EditorBrowsableState.Advanced)]
849 public bool TopLevel {
850 get {
851 return GetTopLevel();
854 set {
855 if (!value && IsMdiContainer)
856 throw new ArgumentException ("MDI Container forms must be top level.");
857 SetTopLevel(value);
861 [DefaultValue(false)]
862 [MWFCategory("Window Style")]
863 public bool TopMost {
864 get {
865 return topmost;
868 set {
869 if (topmost != value) {
870 topmost = value;
871 if (IsHandleCreated)
872 XplatUI.SetTopmost(window.Handle, owner != null ? owner.window.Handle : IntPtr.Zero, value);
877 [MWFCategory("Window Style")]
878 public Color TransparencyKey {
879 get {
880 return transparency_key;
883 set {
884 transparency_key = value;
886 AllowTransparency = true;
887 UpdateStyles();
888 XplatUI.SetWindowTransparency(Handle, Opacity, transparency_key);
892 [DefaultValue(FormWindowState.Normal)]
893 [MWFCategory("Layout")]
894 public FormWindowState WindowState {
895 get {
896 if (IsHandleCreated) {
898 if (window_manager != null)
899 return window_manager.GetWindowState ();
901 try {
902 window_state = XplatUI.GetWindowState(Handle);
905 catch(NotSupportedException) {
909 return window_state;
912 set {
913 FormWindowState old_state = window_state;
914 window_state = value;
915 if (IsHandleCreated) {
917 if (window_manager != null) {
918 window_manager.SetWindowState (old_state, value);
919 return;
922 try {
923 XplatUI.SetWindowState(Handle, value);
926 catch(NotSupportedException) {
932 #endregion // Public Instance Properties
934 #region Protected Instance Properties
935 protected override CreateParams CreateParams {
936 get {
937 CreateParams cp = new CreateParams ();
939 cp.Caption = Text;
940 cp.ClassName = XplatUI.DefaultClassName;
941 cp.ClassStyle = 0;
942 cp.Style = 0;
943 cp.ExStyle = 0;
944 cp.Param = 0;
945 cp.Parent = IntPtr.Zero;
946 cp.menu = ActiveMenu;
948 if (start_position == FormStartPosition.WindowsDefaultLocation && !IsMdiChild) {
949 cp.X = unchecked((int)0x80000000);
950 cp.Y = unchecked((int)0x80000000);
951 } else {
952 cp.X = Left;
953 cp.Y = Top;
955 cp.Width = Width;
956 cp.Height = Height;
958 cp.Style = (int)(WindowStyles.WS_CLIPCHILDREN | WindowStyles.WS_CLIPSIBLINGS);
960 if (IsMdiChild) {
961 cp.Style |= (int)(WindowStyles.WS_CHILD | WindowStyles.WS_CAPTION);
962 if (Parent != null) {
963 cp.Parent = Parent.Handle;
966 cp.ExStyle |= (int) (WindowExStyles.WS_EX_WINDOWEDGE | WindowExStyles.WS_EX_MDICHILD);
968 switch (FormBorderStyle) {
969 case FormBorderStyle.None:
970 break;
971 case FormBorderStyle.FixedToolWindow:
972 case FormBorderStyle.SizableToolWindow:
973 cp.ExStyle |= (int) WindowExStyles.WS_EX_TOOLWINDOW;
974 goto default;
975 default:
976 cp.Style |= (int) WindowStyles.WS_OVERLAPPEDWINDOW;
977 break;
980 } else {
981 switch (FormBorderStyle) {
982 case FormBorderStyle.Fixed3D: {
983 cp.Style |= (int)(WindowStyles.WS_CAPTION | WindowStyles.WS_BORDER);
984 cp.ExStyle |= (int)WindowExStyles.WS_EX_CLIENTEDGE;
985 break;
988 case FormBorderStyle.FixedDialog: {
989 cp.Style |= (int)(WindowStyles.WS_CAPTION | WindowStyles.WS_BORDER);
990 cp.ExStyle |= (int)(WindowExStyles.WS_EX_DLGMODALFRAME);
991 break;
994 case FormBorderStyle.FixedSingle: {
995 cp.Style |= (int)(WindowStyles.WS_CAPTION | WindowStyles.WS_BORDER);
996 break;
999 case FormBorderStyle.FixedToolWindow: {
1000 cp.Style |= (int)(WindowStyles.WS_CAPTION | WindowStyles.WS_BORDER);
1001 cp.ExStyle |= (int)(WindowExStyles.WS_EX_TOOLWINDOW);
1002 break;
1005 case FormBorderStyle.Sizable: {
1006 cp.Style |= (int)(WindowStyles.WS_BORDER | WindowStyles.WS_THICKFRAME | WindowStyles.WS_CAPTION);
1007 break;
1010 case FormBorderStyle.SizableToolWindow: {
1011 cp.Style |= (int)(WindowStyles.WS_BORDER | WindowStyles.WS_THICKFRAME | WindowStyles.WS_CAPTION);
1012 cp.ExStyle |= (int)(WindowExStyles.WS_EX_TOOLWINDOW);
1013 break;
1016 case FormBorderStyle.None: {
1017 break;
1022 switch(window_state) {
1023 case FormWindowState.Maximized: {
1024 cp.Style |= (int)WindowStyles.WS_MAXIMIZE;
1025 break;
1028 case FormWindowState.Minimized: {
1029 cp.Style |= (int)WindowStyles.WS_MINIMIZE;
1030 break;
1034 if (TopMost) {
1035 cp.ExStyle |= (int) WindowExStyles.WS_EX_TOPMOST;
1038 if (ShowInTaskbar) {
1039 cp.ExStyle |= (int)WindowExStyles.WS_EX_APPWINDOW;
1042 if (MaximizeBox) {
1043 cp.Style |= (int)WindowStyles.WS_MAXIMIZEBOX;
1046 if (MinimizeBox) {
1047 cp.Style |= (int)WindowStyles.WS_MINIMIZEBOX;
1050 if (ControlBox) {
1051 cp.Style |= (int)WindowStyles.WS_SYSMENU;
1054 if (HelpButton && !MaximizeBox && !MinimizeBox) {
1055 cp.ExStyle |= (int)WindowExStyles.WS_EX_CONTEXTHELP;
1058 if (Visible)
1059 cp.Style |= (int)WindowStyles.WS_VISIBLE;
1061 if (Opacity < 1.0 || TransparencyKey != Color.Empty) {
1062 cp.ExStyle |= (int)WindowExStyles.WS_EX_LAYERED;
1065 if (!is_enabled && context == null) {
1066 cp.Style |= (int)(WindowStyles.WS_DISABLED);
1069 return cp;
1073 protected override ImeMode DefaultImeMode {
1074 get {
1075 return ImeMode.NoControl;
1079 protected override Size DefaultSize {
1080 get {
1081 return new Size (300, 300);
1085 protected Rectangle MaximizedBounds {
1086 get {
1087 if (maximized_bounds != Rectangle.Empty) {
1088 return maximized_bounds;
1090 return default_maximized_bounds;
1093 set {
1094 maximized_bounds = value;
1095 OnMaximizedBoundsChanged(EventArgs.Empty);
1096 if (IsHandleCreated) {
1097 XplatUI.SetWindowMinMax(Handle, maximized_bounds, minimum_size, maximum_size);
1101 #endregion // Protected Instance Properties
1103 #region Public Static Methods
1104 [EditorBrowsable(EditorBrowsableState.Advanced)]
1105 public static SizeF GetAutoScaleSize (Font font)
1107 return XplatUI.GetAutoScaleSize(font);
1110 #endregion // Public Static Methods
1112 #region Public Instance Methods
1113 internal SizeF GetAutoScaleSize (Graphics g, Font font)
1116 // The following constants come from the dotnet mailing list
1117 // discussion: http://discuss.develop.com/archives/wa.exe?A2=ind0203A&L=DOTNET&P=R3655
1119 // The magic number is "Its almost the length
1120 // of the string with a smattering added in
1121 // for compat with earlier code".
1124 string magic_string = "The quick brown fox jumped over the lazy dog.";
1125 double magic_number = 44.549996948242189;
1126 float width = (float) (g.MeasureString (magic_string, font).Width / magic_number);
1128 return new SizeF (width, font.Height);
1131 public void Activate() {
1132 Form active;
1134 // The docs say activate only activates if our app is already active
1135 active = ActiveForm;
1136 if ((active != null) && (this != active)) {
1137 XplatUI.Activate(window.Handle);
1141 public void AddOwnedForm(Form ownedForm) {
1142 if (!owned_forms.Contains(ownedForm)) {
1143 owned_forms.Add(ownedForm);
1145 ownedForm.Owner = this;
1148 public void Close () {
1149 if (!IsDisposed) {
1150 XplatUI.SendMessage(this.Handle, Msg.WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
1154 public void LayoutMdi(MdiLayout value) {
1155 if (mdi_container != null) {
1156 mdi_container.LayoutMdi(value);
1160 public void RemoveOwnedForm(Form ownedForm) {
1161 owned_forms.Remove(ownedForm);
1164 public void SetDesktopBounds(int x, int y, int width, int height) {
1165 DesktopBounds = new Rectangle(x, y, width, height);
1168 public void SetDesktopLocation(int x, int y) {
1169 DesktopLocation = new Point(x, y);
1172 public DialogResult ShowDialog() {
1173 return ShowDialog(null);
1176 public DialogResult ShowDialog(IWin32Window ownerWin32) {
1177 Form previous;
1178 Rectangle area;
1179 bool confined;
1180 IntPtr capture_window;
1182 owner = null;
1184 if (ownerWin32 != null) {
1185 Control c = Control.FromHandle (ownerWin32.Handle);
1186 if (c != null)
1187 owner = c.TopLevelControl as Form;
1190 if (owner == this) {
1191 throw new InvalidOperationException("The 'ownerWin32' cannot be the form being shown.");
1194 if (is_modal) {
1195 throw new InvalidOperationException("The form is already displayed as a modal dialog.");
1198 if (Visible) {
1199 throw new InvalidOperationException("Already visible forms cannot be displayed as a modal dialog. Set the Visible property to 'false' prior to calling Form.ShowDialog.");
1202 if (!Enabled) {
1203 throw new InvalidOperationException("Cannot display a disabled form as modal dialog.");
1206 if (TopLevelControl != this) {
1207 throw new InvalidOperationException("Can only display TopLevel forms as modal dialog.");
1210 #if broken
1211 // Can't do this, will screw us in the modal loop
1212 form_parent_window.Parent = this.owner;
1213 #endif
1215 // Release any captures
1216 XplatUI.GrabInfo(out capture_window, out confined, out area);
1217 if (capture_window != IntPtr.Zero) {
1218 XplatUI.UngrabWindow(capture_window);
1221 previous = Form.ActiveForm;
1223 #if not
1224 // Commented out; we instead let the Visible=true inside the runloop create the control
1225 // otherwise setting DialogResult inside any of the events that are triggered by the
1226 // create will not actually cause the form to not be displayed.
1227 // Leaving this comment here in case there was an actual purpose to creating the control
1228 // in here.
1229 if (!IsHandleCreated) {
1230 CreateControl();
1232 #endif
1234 Application.RunLoop(true, new ApplicationContext(this));
1236 if (previous != null) {
1237 // Cannot use Activate(), it has a check for the current active window...
1238 XplatUI.Activate(previous.window.Handle);
1241 if (DialogResult != DialogResult.None) {
1242 return DialogResult;
1244 DialogResult = DialogResult.Cancel;
1245 return DialogResult.Cancel;
1248 public override string ToString() {
1249 return GetType().FullName.ToString() + ", Text: " + Text;
1251 #endregion // Public Instance Methods
1253 #region Protected Instance Methods
1254 protected void ActivateMdiChild(Form form) {
1255 if (!IsMdiContainer)
1256 return;
1257 mdi_container.ActivateChild (form);
1258 OnMdiChildActivate(EventArgs.Empty);
1261 [EditorBrowsable(EditorBrowsableState.Advanced)]
1262 protected override void AdjustFormScrollbars(bool displayScrollbars) {
1263 base.AdjustFormScrollbars (displayScrollbars);
1266 [EditorBrowsable(EditorBrowsableState.Advanced)]
1267 protected void ApplyAutoScaling()
1269 SizeF current_size_f = GetAutoScaleSize (DeviceContext, Font);
1270 Size current_size = new Size ((int) current_size_f.Width, (int) current_size_f.Height);
1271 float dx;
1272 float dy;
1274 if (current_size == autoscale_base_size)
1275 return;
1277 if (Environment.GetEnvironmentVariable ("MONO_MWF_SCALING") == "disable"){
1278 Console.WriteLine ("Not scaling");
1279 return;
1283 // I tried applying the Fudge height factor from:
1284 // http://blogs.msdn.com/mharsh/archive/2004/01/25/62621.aspx
1285 // but it makes things larger without looking better.
1287 if (current_size_f.Width != AutoScaleBaseSize.Width) {
1288 dx = current_size_f.Width / AutoScaleBaseSize.Width + 0.08f;
1289 } else {
1290 dx = 1;
1293 if (current_size_f.Height != AutoScaleBaseSize.Height) {
1294 dy = current_size_f.Height / AutoScaleBaseSize.Height + 0.08f;
1295 } else {
1296 dy = 1;
1299 Scale (dx, dy);
1301 AutoScaleBaseSize = current_size;
1304 protected void CenterToParent() {
1305 Control ctl;
1306 int w;
1307 int h;
1309 if (Width > 0) {
1310 w = Width;
1311 } else {
1312 w = DefaultSize.Width;
1315 if (Height > 0) {
1316 h = Height;
1317 } else {
1318 h = DefaultSize.Height;
1321 ctl = null;
1322 if (parent != null) {
1323 ctl = parent;
1324 } else if (owner != null) {
1325 ctl = owner;
1328 if (owner != null) {
1329 this.Location = new Point(ctl.Left + ctl.Width / 2 - w /2, ctl.Top + ctl.Height / 2 - h / 2);
1333 protected void CenterToScreen() {
1334 Size DisplaySize;
1335 int w;
1336 int h;
1338 if (Width > 0) {
1339 w = Width;
1340 } else {
1341 w = DefaultSize.Width;
1344 if (Height > 0) {
1345 h = Height;
1346 } else {
1347 h = DefaultSize.Height;
1350 XplatUI.GetDisplaySize(out DisplaySize);
1351 this.Location = new Point(DisplaySize.Width / 2 - w / 2, DisplaySize.Height / 2 - h / 2);
1354 [EditorBrowsable(EditorBrowsableState.Advanced)]
1355 protected override Control.ControlCollection CreateControlsInstance() {
1356 return base.CreateControlsInstance ();
1359 [EditorBrowsable(EditorBrowsableState.Advanced)]
1360 protected override void CreateHandle() {
1361 base.CreateHandle ();
1363 if (XplatUI.SupportsTransparency()) {
1364 if (allow_transparency) {
1365 XplatUI.SetWindowTransparency(Handle, Opacity, TransparencyKey);
1369 XplatUI.SetWindowMinMax(window.Handle, maximized_bounds, minimum_size, maximum_size);
1370 if (icon != null) {
1371 XplatUI.SetIcon(window.Handle, icon);
1374 if ((owner != null) && (owner.IsHandleCreated)) {
1375 XplatUI.SetTopmost(window.Handle, owner.window.Handle, true);
1378 if (owned_forms.Count > 0) {
1379 for (int i = 0; i < owned_forms.Count; i++) {
1380 if (owned_forms[i].IsHandleCreated) {
1381 XplatUI.SetTopmost(owned_forms[i].window.Handle, window.Handle, true);
1388 [EditorBrowsable(EditorBrowsableState.Advanced)]
1389 protected override void DefWndProc(ref Message m) {
1390 base.DefWndProc (ref m);
1393 protected override void Dispose(bool disposing) {
1394 base.Dispose (disposing);
1397 [EditorBrowsable(EditorBrowsableState.Advanced)]
1398 protected virtual void OnActivated(EventArgs e) {
1399 if (Activated != null) {
1400 Activated(this, e);
1404 [EditorBrowsable(EditorBrowsableState.Advanced)]
1405 protected virtual void OnClosed(EventArgs e) {
1406 if (Closed != null) {
1407 Closed(this, e);
1411 [EditorBrowsable(EditorBrowsableState.Advanced)]
1412 protected virtual void OnClosing(System.ComponentModel.CancelEventArgs e) {
1413 if (Closing != null) {
1414 Closing(this, e);
1418 [EditorBrowsable(EditorBrowsableState.Advanced)]
1419 protected override void OnCreateControl() {
1420 base.OnCreateControl ();
1421 if (this.ActiveControl == null) {
1422 bool visible;
1424 // This visible hack is to work around CanSelect always being false if one of the parents
1425 // is not visible; and we by default create Form invisible...
1426 visible = this.is_visible;
1427 this.is_visible = true;
1429 if (SelectNextControl(this, true, true, true, true) == false) {
1430 Select(this);
1433 this.is_visible = visible;
1434 } else {
1435 Select(ActiveControl);
1438 if (menu != null) {
1439 XplatUI.SetMenu(window.Handle, menu);
1442 OnLoad(EventArgs.Empty);
1444 // Send initial location
1445 OnLocationChanged(EventArgs.Empty);
1447 if (IsMdiContainer) {
1448 mdi_container.LayoutMdi (MdiLayout.Cascade);
1452 [EditorBrowsable(EditorBrowsableState.Advanced)]
1453 protected virtual void OnDeactivate(EventArgs e) {
1454 if (Deactivate != null) {
1455 Deactivate(this, e);
1459 [EditorBrowsable(EditorBrowsableState.Advanced)]
1460 protected override void OnFontChanged(EventArgs e) {
1461 base.OnFontChanged (e);
1464 [EditorBrowsable(EditorBrowsableState.Advanced)]
1465 protected override void OnHandleCreated(EventArgs e) {
1466 XplatUI.SetBorderStyle(window.Handle, form_border_style);
1467 base.OnHandleCreated (e);
1470 [EditorBrowsable(EditorBrowsableState.Advanced)]
1471 protected override void OnHandleDestroyed(EventArgs e) {
1472 base.OnHandleDestroyed (e);
1475 [EditorBrowsable(EditorBrowsableState.Advanced)]
1476 protected virtual void OnInputLanguageChanged(InputLanguageChangedEventArgs e) {
1477 if (InputLanguageChanged!=null) {
1478 InputLanguageChanged(this, e);
1482 [EditorBrowsable(EditorBrowsableState.Advanced)]
1483 protected virtual void OnInputLanguageChanging(InputLanguageChangingEventArgs e) {
1484 if (InputLanguageChanging!=null) {
1485 InputLanguageChanging(this, e);
1489 [EditorBrowsable(EditorBrowsableState.Advanced)]
1490 protected virtual void OnLoad(EventArgs e) {
1491 if (AutoScale){
1492 ApplyAutoScaling ();
1493 AutoScale = false;
1496 if (Load != null) {
1497 Load(this, e);
1500 if (!IsMdiChild) {
1501 switch (StartPosition) {
1502 case FormStartPosition.CenterScreen:
1503 this.CenterToScreen();
1504 break;
1505 case FormStartPosition.CenterParent:
1506 this.CenterToParent ();
1507 break;
1508 case FormStartPosition.Manual:
1509 Left = CreateParams.X;
1510 Top = CreateParams.Y;
1511 break;
1516 [EditorBrowsable(EditorBrowsableState.Advanced)]
1517 protected virtual void OnMaximizedBoundsChanged(EventArgs e) {
1518 if (MaximizedBoundsChanged != null) {
1519 MaximizedBoundsChanged(this, e);
1523 [EditorBrowsable(EditorBrowsableState.Advanced)]
1524 protected virtual void OnMaximumSizeChanged(EventArgs e) {
1525 if (MaximumSizeChanged != null) {
1526 MaximumSizeChanged(this, e);
1530 [EditorBrowsable(EditorBrowsableState.Advanced)]
1531 protected virtual void OnMdiChildActivate(EventArgs e) {
1532 if (MdiChildActivate != null) {
1533 MdiChildActivate(this, e);
1537 [EditorBrowsable(EditorBrowsableState.Advanced)]
1538 protected virtual void OnMenuComplete(EventArgs e) {
1539 if (MenuComplete != null) {
1540 MenuComplete(this, e);
1544 [EditorBrowsable(EditorBrowsableState.Advanced)]
1545 protected virtual void OnMenuStart(EventArgs e) {
1546 if (MenuStart != null) {
1547 MenuStart(this, e);
1551 [EditorBrowsable(EditorBrowsableState.Advanced)]
1552 protected virtual void OnMinimumSizeChanged(EventArgs e) {
1553 if (MinimumSizeChanged != null) {
1554 MinimumSizeChanged(this, e);
1558 [EditorBrowsable(EditorBrowsableState.Advanced)]
1559 protected override void OnPaint (PaintEventArgs pevent) {
1560 base.OnPaint (pevent);
1563 [EditorBrowsable(EditorBrowsableState.Advanced)]
1564 protected override void OnResize(EventArgs e) {
1565 base.OnResize(e);
1568 [EditorBrowsable(EditorBrowsableState.Advanced)]
1569 protected override void OnStyleChanged(EventArgs e) {
1570 base.OnStyleChanged (e);
1573 [EditorBrowsable(EditorBrowsableState.Advanced)]
1574 protected override void OnTextChanged(EventArgs e) {
1575 base.OnTextChanged (e);
1578 [EditorBrowsable(EditorBrowsableState.Advanced)]
1579 protected override void OnVisibleChanged(EventArgs e) {
1580 base.OnVisibleChanged (e);
1583 protected override bool ProcessCmdKey(ref Message msg, Keys keyData) {
1584 if (base.ProcessCmdKey (ref msg, keyData)) {
1585 return true;
1588 // Give our menu a shot
1589 if (ActiveMenu != null) {
1590 return ActiveMenu.ProcessCmdKey(ref msg, keyData);
1593 return false;
1596 // LAMESPEC - Not documented that Form overrides ProcessDialogChar; class-status showed
1597 [EditorBrowsable (EditorBrowsableState.Advanced)]
1598 protected override bool ProcessDialogChar(char charCode) {
1599 return base.ProcessDialogChar (charCode);
1602 protected override bool ProcessDialogKey(Keys keyData) {
1603 if ((keyData & Keys.Modifiers) == 0) {
1604 if (keyData == Keys.Enter && accept_button != null) {
1605 accept_button.PerformClick();
1606 return true;
1607 } else if (keyData == Keys.Escape && cancel_button != null) {
1608 cancel_button.PerformClick();
1609 return true;
1612 return base.ProcessDialogKey(keyData);
1615 protected override bool ProcessKeyPreview(ref Message msg) {
1616 if (key_preview) {
1617 if (ProcessKeyEventArgs(ref msg)) {
1618 return true;
1621 return base.ProcessKeyPreview (ref msg);
1624 protected override bool ProcessTabKey(bool forward) {
1625 return SelectNextControl(ActiveControl, forward, true, true, true);
1628 [EditorBrowsable(EditorBrowsableState.Advanced)]
1629 protected override void ScaleCore(float dx, float dy) {
1630 try {
1631 SuspendLayout();
1633 // We can't scale max or min windows
1634 if (WindowState == FormWindowState.Normal) {
1635 // We cannot call base since base also adjusts X/Y, but
1636 // a form is toplevel and doesn't move
1637 Size size;
1639 size = ClientSize;
1640 if (!GetStyle(ControlStyles.FixedWidth)) {
1641 size.Width = (int)(size.Width * dx);
1644 if (!GetStyle(ControlStyles.FixedHeight)) {
1645 size.Height = (int)(size.Height * dy);
1648 ClientSize = size;
1651 /* Now scale our children */
1652 Control [] controls = child_controls.GetAllControls ();
1653 for (int i=0; i < controls.Length; i++) {
1654 controls[i].Scale(dx, dy);
1658 finally {
1659 ResumeLayout();
1663 protected override void Select(bool directed, bool forward) {
1664 Form parent;
1666 if (directed) {
1667 base.SelectNextControl(null, forward, true, true, true);
1670 parent = this.ParentForm;
1671 if (parent != null) {
1672 parent.ActiveControl = this;
1675 Activate();
1678 [EditorBrowsable(EditorBrowsableState.Advanced)]
1679 protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
1680 base.SetBoundsCore (x, y, width, height, specified);
1683 [EditorBrowsable(EditorBrowsableState.Advanced)]
1684 protected override void SetClientSizeCore(int x, int y) {
1685 if ((minimum_size.Width != 0) && (x < minimum_size.Width)) {
1686 x = minimum_size.Width;
1687 } else if ((maximum_size.Width != 0) && (x > maximum_size.Width)) {
1688 x = maximum_size.Width;
1691 if ((minimum_size.Height != 0) && (y < minimum_size.Height)) {
1692 y = minimum_size.Height;
1693 } else if ((maximum_size.Height != 0) && (y > maximum_size.Height)) {
1694 y = maximum_size.Height;
1697 Rectangle ClientRect = new Rectangle(0, 0, x, y);
1698 Rectangle WindowRect;
1699 CreateParams cp = this.CreateParams;
1701 clientsize_set = new Size(x, y);
1703 if (!IsMdiChild) {
1704 if (XplatUI.CalculateWindowRect(ref ClientRect, cp.Style, cp.ExStyle, cp.menu, out WindowRect)) {
1705 SetBoundsCore(bounds.X, bounds.Y, WindowRect.Width, WindowRect.Height, BoundsSpecified.Size);
1707 } else {
1708 if (XplatUI.CalculateWindowRect(ref ClientRect, cp.Style, cp.ExStyle, cp.menu, out WindowRect)) {
1709 SetBoundsCore(bounds.X, bounds.Y, WindowRect.Width, WindowRect.Height, BoundsSpecified.Size);
1714 [EditorBrowsable(EditorBrowsableState.Advanced)]
1715 protected override void SetVisibleCore(bool value) {
1716 base.SetVisibleCore (value);
1719 protected override void UpdateDefaultButton() {
1720 base.UpdateDefaultButton ();
1723 [EditorBrowsable(EditorBrowsableState.Advanced)]
1724 protected override void WndProc(ref Message m) {
1726 if (window_manager != null && window_manager.HandleMessage (ref m)) {
1727 return;
1730 bool native_enabled = XplatUI.IsEnabled (Handle);
1732 switch((Msg)m.Msg) {
1733 case Msg.WM_DESTROY: {
1734 base.WndProc(ref m);
1735 if (!is_recreating) {
1736 this.closing = true;
1738 return;
1741 case Msg.WM_CLOSE_INTERNAL: {
1742 DestroyHandle();
1743 break;
1746 case Msg.WM_CLOSE: {
1747 Form act = Form.ActiveForm;
1748 if (act != null && act != this && act.Modal == true) {
1749 return;
1752 CancelEventArgs args = new CancelEventArgs ();
1754 if (mdi_container != null) {
1755 foreach (Form mdi_child in mdi_container.MdiChildren) {
1756 mdi_child.OnClosing (args);
1760 if (!is_modal) {
1761 OnClosing (args);
1762 if (!args.Cancel) {
1763 OnClosed (EventArgs.Empty);
1764 base.Dispose();
1766 return;
1767 } else {
1768 OnClosing (args);
1769 if (!args.Cancel) {
1770 OnClosed (EventArgs.Empty);
1771 closing = true;
1772 } else {
1773 DialogResult = DialogResult.None;
1774 closing = false;
1777 return;
1780 case Msg.WM_WINDOWPOSCHANGED: {
1781 if (WindowState != FormWindowState.Minimized) {
1782 base.WndProc(ref m);
1784 return;
1787 case Msg.WM_ACTIVATE: {
1788 if (m.WParam != (IntPtr)WindowActiveFlags.WA_INACTIVE) {
1789 OnActivated(EventArgs.Empty);
1790 } else {
1791 OnDeactivate(EventArgs.Empty);
1793 return;
1796 case Msg.WM_KILLFOCUS: {
1797 base.WndProc(ref m);
1798 return;
1801 case Msg.WM_SETFOCUS: {
1802 if (ActiveControl != null && ActiveControl != this) {
1803 ActiveControl.Focus();
1804 return; // FIXME - do we need to run base.WndProc, even though we just changed focus?
1806 base.WndProc(ref m);
1807 return;
1810 // Menu drawing
1811 case Msg.WM_NCLBUTTONDOWN: {
1812 if (native_enabled && ActiveMenu != null) {
1813 ActiveMenu.OnMouseDown(this, new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()), mouse_clicks, Control.MousePosition.X, Control.MousePosition.Y, 0));
1816 if (ActiveMaximizedMdiChild != null) {
1817 ActiveMaximizedMdiChild.HandleMenuMouseDown (ActiveMenu,
1818 LowOrder ((int) m.LParam.ToInt32 ()),
1819 HighOrder ((int) m.LParam.ToInt32 ()));
1821 base.WndProc(ref m);
1822 return;
1825 case Msg.WM_NCMOUSEMOVE: {
1826 if (native_enabled && ActiveMenu != null) {
1827 ActiveMenu.OnMouseMove(this, new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()), mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()), 0));
1829 base.WndProc(ref m);
1830 return;
1833 case Msg.WM_NCPAINT: {
1834 if (ActiveMenu != null) {
1835 PaintEventArgs pe;
1836 Point pnt;
1838 pe = XplatUI.PaintEventStart(Handle, false);
1839 pnt = XplatUI.GetMenuOrigin(window.Handle);
1841 ActiveMenu.Draw (pe, new Rectangle (pnt.X, pnt.Y, ClientSize.Width, 0));
1843 if (ActiveMaximizedMdiChild != null) {
1844 ActiveMaximizedMdiChild.DrawMaximizedButtons (ActiveMenu, pe);
1847 XplatUI.PaintEventEnd(Handle, false);
1850 base.WndProc(ref m);
1851 return;
1854 case Msg.WM_NCCALCSIZE: {
1855 XplatUIWin32.NCCALCSIZE_PARAMS ncp;
1857 if ((ActiveMenu != null) && (m.WParam == (IntPtr)1)) {
1858 ncp = (XplatUIWin32.NCCALCSIZE_PARAMS)Marshal.PtrToStructure(m.LParam, typeof(XplatUIWin32.NCCALCSIZE_PARAMS));
1860 // Adjust for menu
1861 ncp.rgrc1.top += ThemeEngine.Current.CalcMenuBarSize (DeviceContext, ActiveMenu, ncp.rgrc1.right - ncp.rgrc1.left);
1862 Marshal.StructureToPtr(ncp, m.LParam, true);
1864 DefWndProc(ref m);
1865 break;
1868 case Msg.WM_MOUSEMOVE: {
1869 if (native_enabled && active_tracker != null) {
1870 MouseEventArgs args;
1872 args = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
1873 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()), 0);
1874 active_tracker.OnMotion(new MouseEventArgs (args.Button, args.Clicks, Control.MousePosition.X, Control.MousePosition.Y, args.Delta));
1875 break;
1877 base.WndProc(ref m);
1878 break;
1881 case Msg.WM_LBUTTONDOWN:
1882 case Msg.WM_MBUTTONDOWN:
1883 case Msg.WM_RBUTTONDOWN: {
1884 if (native_enabled && active_tracker != null) {
1885 MouseEventArgs args;
1887 args = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
1888 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()), 0);
1889 active_tracker.OnMouseDown(new MouseEventArgs (args.Button, args.Clicks, Control.MousePosition.X, Control.MousePosition.Y, args.Delta));
1890 return;
1892 base.WndProc(ref m);
1893 return;
1896 case Msg.WM_LBUTTONUP:
1897 case Msg.WM_MBUTTONUP:
1898 case Msg.WM_RBUTTONUP: {
1899 if (native_enabled && active_tracker != null) {
1900 MouseEventArgs args;
1902 args = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
1903 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()), 0);
1904 active_tracker.OnMouseUp(new MouseEventArgs (args.Button, args.Clicks, Control.MousePosition.X, Control.MousePosition.Y, args.Delta));
1905 mouse_clicks = 1;
1906 return;
1908 base.WndProc(ref m);
1909 return;
1912 case Msg.WM_GETMINMAXINFO: {
1913 MINMAXINFO mmi;
1915 if (m.LParam != IntPtr.Zero) {
1916 mmi = (MINMAXINFO)Marshal.PtrToStructure(m.LParam, typeof(MINMAXINFO));
1918 default_maximized_bounds = new Rectangle(mmi.ptMaxPosition.x, mmi.ptMaxPosition.y, mmi.ptMaxSize.x, mmi.ptMaxSize.y);
1919 if (maximized_bounds != Rectangle.Empty) {
1920 mmi.ptMaxPosition.x = maximized_bounds.Left;
1921 mmi.ptMaxPosition.y = maximized_bounds.Top;
1922 mmi.ptMaxSize.x = maximized_bounds.Width;
1923 mmi.ptMaxSize.y = maximized_bounds.Height;
1926 if (minimum_size != Size.Empty) {
1927 mmi.ptMinTrackSize.x = minimum_size.Width;
1928 mmi.ptMinTrackSize.y = minimum_size.Height;
1931 if (maximum_size != Size.Empty) {
1932 mmi.ptMaxTrackSize.x = maximum_size.Width;
1933 mmi.ptMaxTrackSize.y = maximum_size.Height;
1935 Marshal.StructureToPtr(mmi, m.LParam, false);
1937 break;
1940 default: {
1941 base.WndProc (ref m);
1942 break;
1946 #endregion // Protected Instance Methods
1948 internal void RemoveWindowManager ()
1950 window_manager = null;
1953 internal override void CheckAcceptButton()
1955 if (accept_button != null) {
1956 Button a_button = accept_button as Button;
1958 if (ActiveControl == a_button)
1959 return;
1961 if (ActiveControl is Button) {
1962 a_button.paint_as_acceptbutton = false;
1963 a_button.Redraw();
1964 return;
1965 } else {
1966 a_button.paint_as_acceptbutton = true;
1967 a_button.Redraw();
1972 #region Events
1973 public event EventHandler Activated;
1974 public event EventHandler Closed;
1975 public event CancelEventHandler Closing;
1976 public event EventHandler Deactivate;
1977 public event InputLanguageChangedEventHandler InputLanguageChanged;
1978 public event InputLanguageChangingEventHandler InputLanguageChanging;
1979 public event EventHandler Load;
1980 public event EventHandler MaximizedBoundsChanged;
1981 public event EventHandler MaximumSizeChanged;
1982 public event EventHandler MdiChildActivate;
1983 public event EventHandler MenuComplete;
1984 public event EventHandler MenuStart;
1985 public event EventHandler MinimumSizeChanged;
1987 [Browsable(false)]
1988 [EditorBrowsable(EditorBrowsableState.Never)]
1989 public new event EventHandler TabIndexChanged {
1990 add { base.TabIndexChanged += value; }
1991 remove { base.TabIndexChanged -= value; }
1993 #endregion // Events