Switch to compiler-tester
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / Form.cs
index 8a4c36c9b78620d79ba615785c0804611de379d1..44d171f1aaf127b52f193646096e17f032221cd8 100644 (file)
 // Authors:
 //     Peter Bartok    pbartok@novell.com
 //
-//
-// $Revision: 1.22 $
-// $Modtime: $
-// $Log: Form.cs,v $
-// Revision 1.22  2004/11/08 20:50:29  pbartok
-// - Fixed arguments for updated SetTopmost method
-//
-// Revision 1.21  2004/11/04 14:47:58  jordi
-// collection completion, drawing issues, missing features
-//
-// Revision 1.20  2004/10/29 15:55:26  jordi
-// Menu key navigation, itemcollection completion, menu fixes
-//
-// Revision 1.19  2004/10/20 03:56:23  pbartok
-// - Added private FormParentWindow class which acts as the container for
-//   our form and as the non-client area where menus are drawn
-// - Added/Moved required tie-ins to Jordi's menus
-// - Fixed/Implemented the FormStartPosition functionality
-//
-// Revision 1.18  2004/10/18 04:47:09  pbartok
-// - Fixed Form.ControlCollection to handle owner relations
-// - Added Owner/OwnedForms handling
-// - Implemented Z-Ordering for owned forms
-// - Removed unneeded private overload of ShowDialog
-// - Fixed ShowDialog, added the X11 incarnation of modal handling (or so I
-//   hope)
-// - Fixed Close(), had wrong default
-// - Added firing of OnLoad event
-// - Added some commented out debug code for Ownership handling
-//
-// Revision 1.17  2004/10/15 12:43:19  jordi
-// menu work, mainmenu, subitems, etc
-//
-// Revision 1.16  2004/10/14 06:17:58  ravindra
-// Fixed class signature. ShowDialog (Control) is not a public method.
-//
-// Revision 1.15  2004/10/08 08:50:29  jordi
-// more menu work
-//
-// Revision 1.14  2004/10/02 19:05:52  pbartok
-// - Added KeyPreview property
-// - Added Menu property (still incomplete, pending Jordi's menu work)
-// - Implemented ProcessCmdKey
-// - Implemented ProcessDialogKey
-// - Implemented ProcessKeyPreview
-//
-// Revision 1.13  2004/10/01 17:53:26  jackson
-// Implement the Close method so work on MessageBox can continue.
-//
-// Revision 1.12  2004/09/23 19:08:59  jackson
-// Temp build fixage
-//
-// Revision 1.11  2004/09/22 20:09:44  pbartok
-// - Added Form.ControllCollection class
-// - Added handling for Form owners: Owner, OwnedForms, AddOwnedForm,
-//   RemoveOwnedForm (still incomplete, missing on-top and common
-//   minimize/maximize behaviour)
-// - Added StartPosition property (still incomplete, does not use when
-//   creating the form)
-// - Added ShowDialog() methods (still incomplete, missing forcing the dialog
-//   modal)
-//
-// Revision 1.10  2004/09/13 16:56:04  pbartok
-// - Fixed #region names
-// - Moved properties and methods into their proper #regions
-//
-// Revision 1.9  2004/09/13 16:51:29  pbartok
-// - Added Accept and CancelButton properties
-// - Added ProcessDialogKey() method
-//
-// Revision 1.8  2004/09/01 02:05:18  pbartok
-// - Added (partial) implementation of DialogResult; rest needs to be
-//   implemented when the modal loop code is done
-//
-// Revision 1.7  2004/08/23 22:10:02  pbartok
-// - Fixed handling of WM_CLOSE message
-// - Removed debug output
-//
-// Revision 1.6  2004/08/22 21:10:30  pbartok
-// - Removed OverlappedWindow style from Control, instead it's default
-//   now is child
-// - Made form windows OverlappedWindow by default
-//
-// Revision 1.5  2004/08/19 21:30:37  pbartok
-// - Added handling of WM_CLOSE
-//
-// Revision 1.4  2004/08/11 22:20:59  pbartok
-// - Signature fixes
-//
-// Revision 1.3  2004/08/04 21:13:47  pbartok
-// - Added AutoScale properties
-//
-// Revision 1.2  2004/07/13 15:31:45  jordi
-// commit: new properties and fixes form size problems
-//
-// Revision 1.1  2004/07/09 05:21:25  pbartok
-// - Initial check-in
-//
-//
 
 // NOT COMPLETE
 
 using System;
 using System.Drawing;
 using System.ComponentModel;
+using System.ComponentModel.Design;
+using System.ComponentModel.Design.Serialization;
 using System.Collections;
 using System.Runtime.InteropServices;
 using System.Threading;
 
 namespace System.Windows.Forms {
+       [DesignerCategory("Form")]
+       [DesignTimeVisible(false)]
+       [Designer("System.Windows.Forms.Design.FormDocumentDesigner, " + Consts.AssemblySystem_Design, typeof(IRootDesigner))]
+       [DefaultEvent("Load")]
+       [ToolboxItem(false)]
        public class Form : ContainerControl {
                #region Local Variables
+               internal static Form            active_form;
                internal bool                   closing;
-
+               FormBorderStyle                 formBorderStyle;
                private static bool             autoscale;
                private static Size             autoscale_base_size;
-               private bool                    is_modal;
+               internal bool                   is_modal;
                internal bool                   end_modal;                      // This var is being monitored by the application modal loop
+               private bool                    control_box;
+               private bool                    minimize_box;
+               private bool                    maximize_box;
+               private bool                    help_button;
+               private bool                    show_in_taskbar;
+               private bool                    topmost;
                private IButtonControl          accept_button;
                private IButtonControl          cancel_button;
                private DialogResult            dialog_result;
                private FormStartPosition       start_position;
                private Form                    owner;
                private Form.ControlCollection  owned_forms;
+               private MdiClient               mdi_container;
+               private MdiChildContext         mdi_child_context;
+               private Form                    mdi_parent;
                private bool                    key_preview;
                private MainMenu                menu;
-               internal FormParentWindow       form_parent_window;
-               #endregion      // Local Variables
-
-               #region Private Classes
-
-               // This class will take over for the client area
-               internal class FormParentWindow : Control {
-                       #region FormParentWindow Class Local Variables
-                       internal Form   owner;
-                       #endregion      // FormParentWindow Class Local Variables
-
-                       #region FormParentWindow Class Constructor
-                       internal FormParentWindow(Form owner) : base() {
-                               this.owner = owner;
-
-                               this.Width = 250;
-                               this.Height = 250;
-
-                               BackColor = owner.BackColor;
-                               Text = "FormParent";
-                               this.Location = new Point(0, 0);
-                               this.Dock = DockStyle.Fill;
-
-                               MouseDown += new MouseEventHandler (OnMouseDownForm); 
-                               MouseMove += new MouseEventHandler (OnMouseMoveForm); 
-                               owner.TextChanged += new EventHandler(OnFormTextChanged);
-                       }
-                       #endregion      // FormParentWindow Class Constructor
-\r
-                       #region FormParentWindow Class Protected Instance Methods\r
-                       protected override CreateParams CreateParams {\r
-                               get {\r
-                                       CreateParams cp;\r
-\r
-                                       cp = base.CreateParams;\r
-\r
-                                       cp.Style = (int)(WindowStyles.WS_OVERLAPPEDWINDOW | 
-                                                        WindowStyles.WS_VISIBLE | 
-                                                        WindowStyles.WS_CLIPSIBLINGS | 
-                                                        WindowStyles.WS_CLIPCHILDREN);
-
-                                       cp.Width = 250;
-                                       cp.Height = 250;
-\r
-#if later\r
-                                       if (this.IsHandleCreated) {\r
-                                               int     x;\r
-                                               int     y;\r
-                                               int     width;\r
-                                               int     height;\r
-                                               int     cwidth;\r
-                                               int     cheight;\r
-\r
-                                               XplatUI.GetWindowPos(this.window.Handle, out x, out y, out width, out height, out cwidth, out cheight);\r
-                                               UpdateBounds(x, y, width, height);\r
-                                               owner.UpdateBounds(x, y, width, height);\r
-                                       }\r
-\r
-#endif\r
-                                       return cp;\r
-                               }\r
-                       }\r
-\r
-                       protected override void OnResize(EventArgs e) {\r
-                               base.OnResize(e);
-                               //owner.SetBoundsCore(owner.Bounds.X, owner.Bounds.Y, ClientSize.Width, ClientSize.Height, BoundsSpecified.All);
-                               if (owner.menu == null) {
-                                       owner.SetBoundsCore(0, 0, ClientSize.Width, ClientSize.Height, BoundsSpecified.All);
-                               } else {
-                                       int menu_height;
+               private Icon                    icon;
+               private Size                    maximum_size;
+               private Size                    minimum_size;
+               private SizeGripStyle           size_grip_style;
+               private Rectangle               maximized_bounds;
+               private Rectangle               default_maximized_bounds;
+               Color                           transparency_key;\r
 
-                                       menu_height = MenuAPI.MenuBarCalcSize(DeviceContext, owner.Menu.menu_handle, ClientSize.Width);
-                                       Invalidate (new Rectangle (0, 0, ClientSize.Width, menu_height));                                       
-                                       owner.SetBoundsCore(0, menu_height, ClientSize.Width, ClientSize.Height-menu_height, BoundsSpecified.All);
-                               }
-                       }\r
-\r
-                       protected override void OnPaint(PaintEventArgs pevent) {\r
-                               OnDrawMenu (pevent.Graphics);
-                       }\r
-\r
-                       protected override void WndProc(ref Message m) {\r
-                               switch((Msg)m.Msg) {\r
-                                       case Msg.WM_CLOSE: {\r
-                                               CancelEventArgs args = new CancelEventArgs();\r
-\r
-                                               owner.OnClosing(args);\r
-\r
-                                               if (!args.Cancel) {\r
-                                                       owner.OnClosed(EventArgs.Empty);\r
-                                                       owner.closing = true;\r
-                                                       base.WndProc(ref m);\r
-                                                       break;\r
-                                               }\r
-                                               break;\r
-                                       }\r
-\r
-                                       default: {\r
-                                               base.WndProc (ref m);\r
-                                               break;\r
-                                       }\r
-                               }\r
-                       }\r
-                       #endregion      // FormParentWindow Class Protected Instance Methods\r
-\r
-                       #region FormParentWindow Class Private Methods\r
-                       private void OnMouseDownForm (object sender, MouseEventArgs e) {                        
-                               if (owner.menu != null)
-                                       owner.menu.OnMouseDown (owner, e);
-                       }
+               #endregion      // Local Variables
 
-                       private void OnMouseMoveForm (object sender, MouseEventArgs e) {                        
-                               if (owner.menu != null)
-                                       owner.menu.OnMouseMove (owner, e);
-                       }
-               
-               
-                       private void OnDrawMenu (Graphics dc) {
-                               if (owner.menu != null) {                                                                                                       
-                                       Rectangle rect = new Rectangle (0,0, Width, 0);                 
-                                       MenuAPI.DrawMenuBar (dc, owner.menu.Handle, rect);
-                               }                       
-                       }
-                       private void OnFormTextChanged(object sender, EventArgs e) {\r
-                               this.Text = ((Control)sender).Text;\r
-                       }\r
-                       #endregion      // FormParentWindow Class Private Methods
-               }
-               #endregion      // Private Classes
+               #region Private & Internal Methods
+               #endregion      // Private & Internal Methods
 
                #region Public Classes
-               public class ControlCollection : Control.ControlCollection {
+               public new class ControlCollection : Control.ControlCollection {
                        Form    form_owner;
 
                        public ControlCollection(Form owner) : base(owner) {
@@ -297,13 +98,13 @@ namespace System.Windows.Forms {
                                ((Form)value).owner=(Form)owner;
                        }
 
-                       public override void Remove(Control value) {\r
-                               ((Form)value).owner = null;\r
-                               base.Remove (value);\r
-                       }\r
+                       public override void Remove(Control value) {
+                               ((Form)value).owner = null;
+                               base.Remove (value);
+                       }
                }
                #endregion      // Public Classes
-                       
+
                #region Public Constructor & Destructor
                public Form() {
                        closing = false;
@@ -311,18 +112,59 @@ namespace System.Windows.Forms {
                        end_modal = false;
                        dialog_result = DialogResult.None;
                        start_position = FormStartPosition.WindowsDefaultLocation;
+                       formBorderStyle = FormBorderStyle.Sizable;
                        key_preview = false;
                        menu = null;
-
+                       icon = null;
+                       minimum_size = new Size(0, 0);
+                       maximum_size = new Size(0, 0);
+                       control_box = true;
+                       minimize_box = true;
+                       maximize_box = true;
+                       help_button = false;
+                       show_in_taskbar = true;
+                       ime_mode = ImeMode.NoControl;
+                       is_visible = false;
+                       is_toplevel = true;
+                       size_grip_style = SizeGripStyle.Auto;
+                       maximized_bounds = Rectangle.Empty;
+                       default_maximized_bounds = Rectangle.Empty;
                        owned_forms = new Form.ControlCollection(this);
+                       transparency_key = Color.Empty;
                }
                #endregion      // Public Constructor & Destructor
 
-
                #region Public Static Properties
+
+               public static Form ActiveForm {
+                       get {
+                               Control active;
+
+                               active = FromHandle(XplatUI.GetActive());
+
+                               if (active != null) {
+                                       if ( !(active is Form)) {
+                                               Control parent;
+
+                                               parent = active.Parent;
+                                               while (parent != null) {
+                                                       if (parent is Form) {
+                                                               return (Form)parent;
+                                                       }
+                                                       parent = parent.Parent;
+                                               }
+                                       } else {
+                                               return (Form)active;
+                                       }
+                               }
+                               return null;
+                       }
+               }
+
                #endregion      // Public Static Properties
 
                #region Public Instance Properties
+               [DefaultValue(null)]
                public IButtonControl AcceptButton {
                        get {
                                return accept_button;
@@ -332,7 +174,20 @@ namespace System.Windows.Forms {
                                accept_button = value;
                        }
                }
+
+               [MonoTODO("Figure out a way for transparency support in windows")]
+               [Browsable(false)]
+               [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
+               public bool AllowTransparency {
+                       get {
+                               return false;
+                       }
+
+                       set {
+                       }
+               }
                        
+               [DefaultValue(true)]
                public bool AutoScale {
                        get {
                                return autoscale;
@@ -343,6 +198,9 @@ namespace System.Windows.Forms {
                        }
                }
 
+               [Localizable(true)]
+               [Browsable(false)]
+               [EditorBrowsable(EditorBrowsableState.Advanced)]
                public virtual Size AutoScaleBaseSize {
                        get {
                                return autoscale_base_size;
@@ -353,6 +211,26 @@ namespace System.Windows.Forms {
                        }
                }
 
+               [Localizable(true)]
+               public override bool AutoScroll {
+                       get {
+                               return base.AutoScroll;
+                       }
+                       set {
+                               base.AutoScroll = value;
+                       }
+               }
+
+               public override Color BackColor {
+                       get {
+                               return base.BackColor;
+                       }
+                       set {
+                               base.BackColor = value;
+                       }
+               }
+
+               [DefaultValue(null)]
                public IButtonControl CancelButton {
                        get {
                                return cancel_button;
@@ -363,6 +241,58 @@ namespace System.Windows.Forms {
                        }
                }
 
+               [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
+               [Localizable(true)]
+               public Size ClientSize {
+                       get {
+                               return base.ClientSize;
+                       }
+
+                       set {
+                               base.ClientSize = value;
+                       }
+               }
+
+               [DefaultValue(true)]
+               public bool ControlBox {
+                       get {
+                               return control_box;
+                       }
+
+                       set {
+                               if (control_box != value) {
+                                       control_box = value;
+                                       UpdateStyles();
+                               }
+                       }
+               }
+
+               [Browsable(false)]
+               [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
+               public Rectangle DesktopBounds {
+                       get {
+                               return new Rectangle(Location, Size);
+                       }
+
+                       set {
+                               Bounds = value;
+                       }
+               }
+
+               [Browsable(false)]
+               [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
+               public Point DesktopLocation {
+                       get {
+                               return Location;
+                       }
+
+                       set {
+                               Location = value;
+                       }
+               }
+
+               [Browsable(false)]
+               [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
                public DialogResult DialogResult {
                        get {
                                return dialog_result;
@@ -377,6 +307,82 @@ namespace System.Windows.Forms {
                        }
                }
 
+               [DefaultValue(FormBorderStyle.Sizable)]
+               [DispId(-504)]
+               public FormBorderStyle FormBorderStyle {
+                       get {
+                               return formBorderStyle;
+                       }
+                       set {
+                               formBorderStyle = value;
+                               UpdateStyles();
+                       }
+               }
+
+               [DefaultValue(false)]
+               public bool HelpButton {
+                       get {
+                               return help_button;
+                       }
+
+                       set {
+                               if (help_button != value) {
+                                       help_button = value;
+                                       UpdateStyles();
+                               }
+                       }
+               }
+
+               [Localizable(true)]
+               [AmbientValue(null)]
+               public Icon Icon {
+                       get {
+                               return icon;
+                       }
+
+                       set {
+                               if (icon != value) {
+                                       icon = value;
+
+                                       XplatUI.SetIcon(Handle, icon);
+                               }
+                       }
+               }
+
+               [Browsable(false)]
+               [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
+               public bool IsMdiChild {
+                       get {
+                               return mdi_parent != null;
+                       }
+               }
+
+               [DefaultValue(false)]
+               public bool IsMdiContainer {
+                       get {
+                               return mdi_container != null;
+                       }
+
+                       set {
+                               if (value && mdi_container == null) {
+                                       mdi_container = new MdiClient();
+                                       Controls.Add(mdi_container);
+                               } else if (!value && mdi_container != null) {
+                                       Controls.Remove(mdi_container);
+                                       mdi_container.Dispose();
+                               }
+                       }
+               }
+
+               [Browsable(false)]
+               [EditorBrowsable(EditorBrowsableState.Advanced)]
+               public bool IsRestrictedWindow {
+                       get {
+                               return false;
+                       }
+               }
+
+               [DefaultValue(false)]
                public bool KeyPreview {
                        get {
                                return key_preview;
@@ -387,39 +393,151 @@ namespace System.Windows.Forms {
                        }
                }
 
-               public MainMenu Menu {
+               [DefaultValue(true)]
+               public bool MaximizeBox {
                        get {
-                               return menu;
+                               return maximize_box;
+                       }
+                       set {
+                               if (maximize_box != value) {
+                                       maximize_box = value;
+                                       UpdateStyles();
+                               }
+                       }
+               }
+
+               [DefaultValue("{Width=0, Height=0}")]
+               [Localizable(true)]
+               [RefreshProperties(RefreshProperties.Repaint)]
+               public Size MaximumSize {
+                       get {
+                               return maximum_size;
                        }
 
                        set {
-                               if (menu != value) {
-                                       if (value == null) {
-                                               form_parent_window.Width = form_parent_window.Width;    // Trigger a resize
+                               if (maximum_size != value) {
+                                       maximum_size = value;
+                                       OnMaximumSizeChanged(EventArgs.Empty);
+                               }
+                       }
+               }
+
+               [Browsable(false)]
+               [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
+               public Form[] MdiChildren {
+                       get {
+                               if (mdi_container != null) {
+                                       Form[] form_list;
+
+                                       form_list = new Form[mdi_container.Controls.Count];
+                                       for (int i = 0; i < mdi_container.Controls.Count; i++) {
+                                               form_list[i] = (Form)mdi_container.Controls[i];
                                        }
+                                       return form_list;
+                               } else {
+                                       return new Form[0];
+                               }
+                       }
+               }
+
+               [MonoTODO("Finish setter")]
+               [Browsable(false)]
+               [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
+               public Form MdiParent {
+                       get {
+                               return mdi_parent;
+                       }
+
+                       set {
+                               SuspendLayout ();
+
+                               // TopLevel = true;
+
+                               if (!value.IsMdiContainer)
+                                       throw new ArgumentException ();
 
+                               if (mdi_parent != null) {
+                                       mdi_parent.MdiContainer.Controls.Remove (this);
+                               }
+
+                               mdi_parent = value;
+                               if (mdi_parent != null) {
+                                       mdi_child_context = new MdiChildContext (this);
+                                       mdi_parent.MdiContainer.Controls.Add (this);
+                               }
+
+                               ResumeLayout ();
+                       }
+               }
+
+               internal MdiClient MdiContainer {
+                       get { return mdi_container; }
+               }
+
+               [DefaultValue(null)]
+               public MainMenu Menu {
+                       get {
+                               return menu;
+                       }
+
+                       set {                           
+                               if (menu != value) {                                    
                                        menu = value;
 
-                                       // To simulate the non-client are for menus we create a 
-                                       // new control as the 'client area' of our form.  This
-                                       // way, the origin stays 0,0 and we don't have to fiddle with
-                                       // coordinates. The menu area is part of the original container
-                                       if (menu != null) {
-                                               form_parent_window.Width = form_parent_window.Width;    // Trigger a resize
+                                       menu.SetForm (this);
+                                       MenuAPI.SetMenuBarWindow (menu.Handle, this);
+                               
+                                       if (IsHandleCreated && menu != null) {  
+                                               XplatUI.SetMenu(window.Handle, menu.Handle);
                                        }
 
-                                       menu.SetForm (this);
-                                       MenuAPI.SetMenuBarWindow (menu.Handle, form_parent_window);
+                                       // FIXME - Do we still need this?
+                                       this.SetBoundsCore(0, 0, 0, 0, BoundsSpecified.None);
+
+                                       ThemeEngine.Current.CalcMenuBarSize (DeviceContext, menu.Handle, ClientSize.Width);
+                               }
+                       }
+               }
+
+               [DefaultValue(true)]
+               public bool MinimizeBox {
+                       get {
+                               return minimize_box;
+                       }
+                       set {
+                               if (minimize_box != value) {
+                                       minimize_box = value;
+                                       UpdateStyles();
+                               }
+                       }
+               }
+
+               [DefaultValue("{Width=0, Height=0}")]
+               [Localizable(true)]
+               [RefreshProperties(RefreshProperties.Repaint)]
+               public Size MinimumSize {
+                       get {
+                               return minimum_size;
+                       }
+
+                       set {
+                               if (minimum_size != value) {
+                                       minimum_size = value;
+                                       OnMinimumSizeChanged(EventArgs.Empty);
                                }
                        }
                }
 
+               [Browsable(false)]
+               [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
                public bool Modal  {
                        get {
                                return is_modal;
                        }
                }
 
+               [Browsable(false)]
+               [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
                public Form[] OwnedForms {
                        get {
                                Form[] form_list;
@@ -434,6 +552,8 @@ namespace System.Windows.Forms {
                        }
                }
 
+               [Browsable(false)]
+               [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
                public Form Owner {
                        get {
                                return owner;
@@ -455,6 +575,45 @@ namespace System.Windows.Forms {
                        }
                }
 
+               [DefaultValue(true)]
+               public bool ShowInTaskbar {
+                       get {
+                               return show_in_taskbar;
+                       }
+                       set {
+                               if (show_in_taskbar != value) {
+                                       show_in_taskbar = value;
+                                       UpdateStyles();
+                               }
+                       }
+               }
+
+               [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
+               [Localizable(false)]
+               public Size Size {
+                       get {
+                               return base.Size;
+                       }
+
+                       set {
+                               base.Size = value;
+                       }
+               }
+
+               [MonoTODO("Trigger something when GripStyle is set")]
+               [DefaultValue(SizeGripStyle.Auto)]
+               public SizeGripStyle SizeGripStyle {
+                       get {
+                               return size_grip_style;
+                       }
+
+                       set {
+                               size_grip_style = value;
+                       }
+               }
+
+               [DefaultValue(FormStartPosition.WindowsDefaultLocation)]
+               [Localizable(true)]
                public FormStartPosition StartPosition {
                        get {
                                return start_position;
@@ -463,22 +622,15 @@ namespace System.Windows.Forms {
                        set {
                                if (start_position == FormStartPosition.WindowsDefaultLocation) {               // Only do this if it's not set yet
                                        start_position = value;
-                                       if (form_parent_window.IsHandleCreated) {
+                                       if (IsHandleCreated) {
                                                switch(start_position) {
                                                        case FormStartPosition.CenterParent: {
-                                                               if (Parent!=null && Width>0 && Height>0) {
-                                                                       this.Location = new Point(Parent.Size.Width/2-Width/2, Parent.Size.Height/2-Height/2);
-                                                               }
+                                                               CenterToParent();
                                                                break;
                                                        }
 
                                                        case FormStartPosition.CenterScreen: {
-                                                               if (Width>0 && Height>0) {
-                                                                       Size    DisplaySize;
-
-                                                                       XplatUI.GetDisplaySize(out DisplaySize);
-                                                                       this.Location = new Point(DisplaySize.Width/2-Width/2, DisplaySize.Height/2-Height/2);
-                                                               }
+                                                               CenterToScreen();
                                                                break;
                                                        }
 
@@ -490,74 +642,258 @@ namespace System.Windows.Forms {
                                }
                        }
                }
-               #endregion      // Public Instance Properties
 
-               #region Protected Instance Properties
-               [MonoTODO("Need to add MDI support")]
-               protected override CreateParams CreateParams {
+               [Browsable(false)]
+               [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
+               [EditorBrowsable(EditorBrowsableState.Never)]
+               public int TabIndex {
                        get {
-                               CreateParams cp = new CreateParams();
+                               return base.TabIndex;
+                       }
 
-                               if (this.form_parent_window == null) {
-                                       form_parent_window = new FormParentWindow(this);
-                               }
+                       set {
+                               base.TabIndex = value;
+                       }
+               }
 
-                               cp.Caption = "ClientArea";
-                               cp.ClassName=XplatUI.DefaultClassName;
+               [Browsable(false)]
+               [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
+               [EditorBrowsable(EditorBrowsableState.Advanced)]
+               public bool TopLevel {
+                       get {
+                               return GetTopLevel();
+                       }
+
+                       set {
+                               if (!value && IsMdiContainer)
+                                       throw new ArgumentException ("MDI Container forms must be top level.");
+                               SetTopLevel(value);
+                       }
+               }
+
+               [DefaultValue(false)]
+               public bool TopMost {
+                       get {
+                               return topmost;
+                       }
+
+                       set {
+                               if (topmost != value) {
+                                       topmost = value;
+                                       XplatUI.SetTopmost(window.Handle, owner != null ? owner.window.Handle : IntPtr.Zero, value);
+                               }
+                       }
+               }
+
+               public Color TransparencyKey {\r
+                       get {\r
+                               return transparency_key;\r
+                       }\r
+\r
+                       set {\r
+                               AllowTransparency = true;\r
+                               transparency_key = value;\r
+                               // TODO: change window attributes; a new driver call\r
+                       }\r
+               }\r
+
+               [DefaultValue(FormWindowState.Normal)]
+               public FormWindowState WindowState {
+                       get {
+                               return XplatUI.GetWindowState(window.Handle);
+                       }
+
+                       set {
+                               XplatUI.SetWindowState(window.Handle, value);
+                       }
+               }
+
+               #endregion      // Public Instance Properties
+
+               #region Protected Instance Properties
+               [MonoTODO("Need to add MDI support")]
+               protected override CreateParams CreateParams {
+                       get {
+                               CreateParams cp;
+
+                               cp = new CreateParams();
+
+                               cp.Caption = "FormWindow";
+                               cp.ClassName = XplatUI.DefaultClassName;
                                cp.ClassStyle = 0;
-                               cp.ExStyle=0;
-                               cp.Param=0;
-                               cp.Parent = this.form_parent_window.window.Handle;
-                               cp.X = Left;
-                               cp.Y = Top;
+                               cp.ExStyle = 0;
+                               cp.Param = 0;
+                               cp.Parent = IntPtr.Zero;
+//                             if (start_position == FormStartPosition.WindowsDefaultLocation) {
+                                       cp.X = unchecked((int)0x80000000);
+                                       cp.Y = unchecked((int)0x80000000);
+//                             } else {
+//                                     cp.X = Left;
+//                                     cp.Y = Top;
+//                             }
                                cp.Width = Width;
                                cp.Height = Height;
                                
-                               cp.Style = (int)WindowStyles.WS_CHILD;
-                               cp.Style |= (int)WindowStyles.WS_VISIBLE;
-                               cp.Style |= (int)WindowStyles.WS_CLIPSIBLINGS;
-                               cp.Style |= (int)WindowStyles.WS_CLIPCHILDREN;
+                               cp.Style = (int)(WindowStyles.WS_CLIPSIBLINGS | WindowStyles.WS_CLIPCHILDREN);
+
+                               switch (FormBorderStyle) {
+                                       case FormBorderStyle.Fixed3D: {
+                                               cp.Style |= (int)WindowStyles.WS_CAPTION;
+                                               cp.ExStyle |= (int)WindowStyles.WS_EX_OVERLAPPEDWINDOW;
+                                               break;
+                                       }
+
+                                       case FormBorderStyle.FixedDialog: {
+                                               cp.Style |= (int)WindowStyles.WS_CAPTION;
+                                               cp.ExStyle |= (int)(WindowStyles.WS_EX_DLGMODALFRAME | WindowStyles.WS_EX_WINDOWEDGE);
+                                               break;
+                                       }
+
+                                       case FormBorderStyle.FixedSingle: {
+                                               cp.Style |= (int)WindowStyles.WS_CAPTION;
+                                               cp.ExStyle |= (int)(WindowStyles.WS_EX_WINDOWEDGE);
+                                               break;
+                                       }
+
+                                       case FormBorderStyle.FixedToolWindow: {
+                                               cp.Style |= (int)WindowStyles.WS_CAPTION;
+                                               cp.ExStyle |= (int)(WindowStyles.WS_EX_WINDOWEDGE | WindowStyles.WS_EX_TOOLWINDOW);
+                                               break;
+                                       }
+
+                                       case FormBorderStyle.Sizable: {
+                                               cp.Style |= (int)WindowStyles.WS_OVERLAPPEDWINDOW;
+                                               cp.ExStyle |= (int)(WindowStyles.WS_EX_WINDOWEDGE);
+                                               break;
+                                       }
+
+                                       case FormBorderStyle.SizableToolWindow: {
+                                               cp.Style |= (int)WindowStyles.WS_OVERLAPPEDWINDOW;
+                                               cp.ExStyle |= (int)(WindowStyles.WS_EX_WINDOWEDGE | WindowStyles.WS_EX_TOOLWINDOW);
+                                               break;
+                                       }
+                               }
+
+                               if (ShowInTaskbar) {
+                                       cp.ExStyle |= (int)WindowStyles.WS_EX_APPWINDOW;
+                               }
+
+                               if (MaximizeBox) {
+                                       cp.Style |= (int)WindowStyles.WS_MAXIMIZEBOX;
+                               }
+
+                               if (MinimizeBox) {
+                                       cp.Style |= (int)WindowStyles.WS_MINIMIZEBOX;
+                               }
+
+                               if (ControlBox) {
+                                       cp.Style |= (int)WindowStyles.WS_SYSMENU;
+                               }
 
+                               if (HelpButton) {
+                                       cp.ExStyle |= (int)WindowStyles.WS_EX_CONTEXTHELP;
+                               }
                                return cp;
                        }
                }
 
+               protected override ImeMode DefaultImeMode {
+                       get {
+                               return ImeMode.NoControl;
+                       }
+               }
+
                protected override Size DefaultSize {
                        get {
                                return new Size (250, 250);
                        }
                }               
 
-               protected override void OnPaint (PaintEventArgs pevent)
-               {
-                       base.OnPaint (pevent);
-               }               
-               
-               #endregion      // Protected Instance Properties
+               protected Rectangle MaximizedBounds {
+                       get {
+                               if (maximized_bounds != Rectangle.Empty) {
+                                       return maximized_bounds;
+                               }
+                               return default_maximized_bounds;
+                       }
 
+                       set {
+                               maximized_bounds = value;
+                               OnMaximizedBoundsChanged(EventArgs.Empty);
+                       }
+               }
+               #endregion      // Protected Instance Properties
 
                #region Public Static Methods
+               [MonoTODO("Figure out the math")]
+               [EditorBrowsable(EditorBrowsableState.Advanced)]
+               public static SizeF GetAutoScaleSize(Font font) {
+                       SizeF   result;
+
+                       result = new SizeF(250, 250);
+                       result.Width *= font.SizeInPoints / 12;
+                       result.Height *= font.SizeInPoints / 12;
+                       return result;
+               }
                #endregion      // Public Static Methods
 
                #region Public Instance Methods
+               public void Activate() {
+                       Form    active;
+
+                       // The docs say activate only activates if our app is already active
+                       active = ActiveForm;
+                       if ((active != null) && (this != active)) {
+                               XplatUI.Activate(window.Handle);
+                       }
+               }
+
                public void AddOwnedForm(Form ownedForm) {
                        owned_forms.Add(ownedForm);
                }
 
+               public void Close () {
+                       CancelEventArgs args = new CancelEventArgs ();
+                       OnClosing (args);
+                       if (!args.Cancel) {
+                               OnClosed (EventArgs.Empty);
+                               closing = true;
+                               return;
+                       }
+               }
+
+               public void LayoutMdi(MdiLayout value) {
+                       if (mdi_container != null) {
+                               mdi_container.LayoutMdi(value);
+                       }
+               }
+
                public void RemoveOwnedForm(Form ownedForm) {
                        owned_forms.Remove(ownedForm);
                }
 
+               public void SetDesktopBounds(int x, int y, int width, int height) {
+                       DesktopBounds = new Rectangle(x, y, width, height);
+               }
+
+               public void SetDesktopLocation(int x, int y) {
+                       DesktopLocation = new Point(x, y);
+               }
+
                public DialogResult ShowDialog() {
                        return ShowDialog(null);
                }
 
                public DialogResult ShowDialog(IWin32Window ownerWin32) {
+                       Form            previous;
+
+                       #if broken
                        Control         owner = null;
 
                        if (ownerWin32 != null) {
                                owner = Control.FromHandle(ownerWin32.Handle);
                        }
+                       #endif
 
                        if (is_modal) {
                                return DialogResult.None;
@@ -567,6 +903,13 @@ namespace System.Windows.Forms {
                                throw new InvalidOperationException("Already visible forms cannot be displayed as a modal dialog. Set the Visible property to 'false' prior to calling Form.ShowDialog.");
                        }
 
+                       #if broken
+                       // Can't do this, will screw us in the modal loop
+                       form_parent_window.Parent = owner;
+                       #endif
+
+                       previous = Form.ActiveForm;
+
                        if (!IsHandleCreated) {
                                CreateControl();
                        }
@@ -574,6 +917,7 @@ namespace System.Windows.Forms {
                        XplatUI.SetModal(window.Handle, true);
 
                        Show();
+                       PerformLayout();
 
                        is_modal = true;
                        Application.ModalRun(this);
@@ -582,189 +926,476 @@ namespace System.Windows.Forms {
 
                        XplatUI.SetModal(window.Handle, false);
 
+                       if (previous != null) {
+                               // Cannot use Activate(), it has a check for the current active window...
+                               XplatUI.Activate(previous.window.Handle);
+                       }
+
                        return DialogResult;
                }
 
-               public void Close ()
-               {
-                       CancelEventArgs args = new CancelEventArgs ();
-                       OnClosing (args);
-                       if (!args.Cancel) {
-                               OnClosed (EventArgs.Empty);
-                               closing = true;
-                               return;
-                       }
+               public override string ToString() {
+                       return GetType().FullName.ToString() + ", Text: " + Text;
                }
-
                #endregion      // Public Instance Methods
 
                #region Protected Instance Methods
-               protected override void CreateHandle() {\r
-                       base.CreateHandle ();\r
-               }\r
+               [MonoTODO("Finish when MDI is more complete")]
+               protected void ActivateMdiChild(Form form) {
+                       OnMdiChildActivate(EventArgs.Empty);
+                       throw new NotImplementedException();
+               }
 
-               protected override void OnCreateControl() {\r
-                       base.OnCreateControl ();\r
-                       OnLoad(EventArgs.Empty);\r
-               }\r
+               [EditorBrowsable(EditorBrowsableState.Advanced)]
+               protected override void AdjustFormScrollbars(bool displayScrollbars) {
+                       base.AdjustFormScrollbars (displayScrollbars);
+               }
 
-               protected override void OnHandleCreated(EventArgs e) {\r
-                       base.OnHandleCreated (e);\r
-               }\r
+               [EditorBrowsable(EditorBrowsableState.Advanced)]
+               protected void ApplyAutoScaling() {
+                       // Hm, not sure what this does
+               }
 
-               protected override void OnHandleDestroyed(EventArgs e) {\r
-                       base.OnHandleDestroyed (e);\r
-               }\r
+               protected void CenterToParent() {
+                       Control ctl;
+                       int     w;
+                       int     h;
 
+                       if (Width > 0) {
+                               w = Width;
+                       } else {
+                               w = DefaultSize.Width;
+                       }
 
-               protected override void OnResize(EventArgs e) {
-                       base.OnResize(e);
+                       if (Height > 0) {
+                               h = Height;
+                       } else {
+                               h = DefaultSize.Height;
+                       }
+
+                       ctl = null;
+                       if (parent != null) {
+                               ctl = parent;
+                       } else if (owner != null) {
+                               ctl = owner;
+                       }
+
+                       if (owner != null) {
+                               this.Location = new Point(ctl.Left + ctl.Width / 2 - w /2, ctl.Top + ctl.Height / 2 - h / 2);
+                       }
                }
-\r
-               protected override bool ProcessCmdKey(ref Message msg, Keys keyData) {\r
-                       if (base.ProcessCmdKey (ref msg, keyData)) {\r
-                               return true;\r
-                       }\r
-\r
-                       // Give our menu a shot\r
-                       if (menu != null) {\r
-                               return menu.ProcessCmdKey(ref msg, keyData);\r
-                       }\r
-\r
-                       return false;\r
-               }\r
 
-               protected override bool ProcessDialogKey(Keys keyData) {
-                       if (keyData == Keys.Enter && accept_button != null) {
-                               accept_button.PerformClick();
-                               return true;
-                       } else if (keyData == Keys.Enter && cancel_button != null) {
-                               cancel_button.PerformClick();
-                               return true;
+               protected void CenterToScreen() {
+                       Size    DisplaySize;
+                       int     w;
+                       int     h;
+
+                       if (Width > 0) {
+                               w = Width;
+                       } else {
+                               w = DefaultSize.Width;
                        }
-                       return base.ProcessDialogKey(keyData);
+
+                       if (Height > 0) {
+                               h = Height;
+                       } else {
+                               h = DefaultSize.Height;
+                       }
+
+                       XplatUI.GetDisplaySize(out DisplaySize);
+                       this.Location = new Point(DisplaySize.Width / 2 - w / 2, DisplaySize.Height / 2 - h / 2);
                }
 
-               protected override bool ProcessKeyPreview(ref Message msg) {\r
-                       if (key_preview) {\r
-                               if (ProcessKeyEventArgs(ref msg)) {\r
-                                       return true;\r
-                               }\r
-                       }\r
-                       return base.ProcessKeyPreview (ref msg);\r
-               }\r
+               [EditorBrowsable(EditorBrowsableState.Advanced)]
+               protected override Control.ControlCollection CreateControlsInstance() {
+                       return base.CreateControlsInstance ();
+               }
 
-               protected override void WndProc(ref Message m) {\r
-                       switch((Msg)m.Msg) {\r
-                               case Msg.WM_CLOSE: {\r
-                                       CancelEventArgs args = new CancelEventArgs();\r
-\r
-                                       OnClosing(args);\r
-\r
-                                       if (!args.Cancel) {\r
-                                               OnClosed(EventArgs.Empty);\r
-                                               closing = true;\r
-                                               base.WndProc(ref m);\r
-                                               break;\r
-                                       }\r
-                                       break;\r
-                               }\r
-\r
-#if topmost_workaround
-                               case Msg.WM_ACTIVATE: {\r
-                                       if (this.OwnedForms.Length>0) {
-                                               XplatUI.SetZOrder(this.OwnedForms[0].window.Handle, this.window.Handle, false, false);
-                                       }
-                                       break;\r
-                               }\r
-#endif\r
-                               default: {\r
-                                       base.WndProc (ref m);\r
-                                       break;\r
-                               }\r
-                       }\r
-               }\r
-               #endregion      // Protected Instance Methods
+               [EditorBrowsable(EditorBrowsableState.Advanced)]
+               protected override void CreateHandle() {
+                       base.CreateHandle ();
+               }
 
-               #region Events
+               [EditorBrowsable(EditorBrowsableState.Advanced)]
+               protected override void DefWndProc(ref Message m) {
+                       base.DefWndProc (ref m);
+               }
+
+               protected override void Dispose(bool disposing) {
+                       base.Dispose (disposing);
+               }
+
+               [EditorBrowsable(EditorBrowsableState.Advanced)]
                protected virtual void OnActivated(EventArgs e) {
                        if (Activated != null) {
                                Activated(this, e);
                        }
                }
 
+               [EditorBrowsable(EditorBrowsableState.Advanced)]
                protected virtual void OnClosed(EventArgs e) {
                        if (Closed != null) {
                                Closed(this, e);
                        }
                }
 
+               [EditorBrowsable(EditorBrowsableState.Advanced)]
                protected virtual void OnClosing(System.ComponentModel.CancelEventArgs e) {
                        if (Closing != null) {
                                Closing(this, e);
                        }
                }
 
+               [EditorBrowsable(EditorBrowsableState.Advanced)]
+               protected override void OnCreateControl() {
+                       base.OnCreateControl ();
+                       if (this.ActiveControl == null) {
+                               bool visible;
+
+                               // This visible hack is to work around CanSelect always being false if one of the parents
+                               // is not visible; and we by default create Form invisible...
+                               visible = this.is_visible;
+                               this.is_visible = true;
+
+                               if (SelectNextControl(this, true, true, true, true) == false) {
+                                       Select(this);
+                               }
+
+                               this.is_visible = visible;
+                       }
+                       
+                       if (menu != null) {
+                               XplatUI.SetMenu(window.Handle, menu.Handle);
+                       }
+                       
+                       OnLoad(EventArgs.Empty);
+
+                       // Send initial location
+                       OnLocationChanged(EventArgs.Empty);
+               }
+
+               [EditorBrowsable(EditorBrowsableState.Advanced)]
                protected virtual void OnDeactivate(EventArgs e) {
                        if (Deactivate != null) {
                                Deactivate(this, e);
                        }
                }
 
+               [EditorBrowsable(EditorBrowsableState.Advanced)]
+               protected override void OnFontChanged(EventArgs e) {
+                       base.OnFontChanged (e);
+               }
+
+               [EditorBrowsable(EditorBrowsableState.Advanced)]
+               protected override void OnHandleCreated(EventArgs e) {
+                       base.OnHandleCreated (e);
+               }
+
+               [EditorBrowsable(EditorBrowsableState.Advanced)]
+               protected override void OnHandleDestroyed(EventArgs e) {
+                       base.OnHandleDestroyed (e);
+               }
+
+               [EditorBrowsable(EditorBrowsableState.Advanced)]
                protected virtual void OnInputLanguageChanged(InputLanguageChangedEventArgs e) {
                        if (InputLanguageChanged!=null) {
                                InputLanguageChanged(this, e);
                        }
                }
 
+               [EditorBrowsable(EditorBrowsableState.Advanced)]
                protected virtual void OnInputLanguageChanging(InputLanguageChangingEventArgs e) {
                        if (InputLanguageChanging!=null) {
                                InputLanguageChanging(this, e);
                        }
                }
 
+               [EditorBrowsable(EditorBrowsableState.Advanced)]
                protected virtual void OnLoad(EventArgs e) {
                        if (Load != null) {
                                Load(this, e);
                        }
                }
 
+               [EditorBrowsable(EditorBrowsableState.Advanced)]
                protected virtual void OnMaximizedBoundsChanged(EventArgs e) {
                        if (MaximizedBoundsChanged != null) {
                                MaximizedBoundsChanged(this, e);
                        }
                }
 
+               [EditorBrowsable(EditorBrowsableState.Advanced)]
                protected virtual void OnMaximumSizeChanged(EventArgs e) {
                        if (MaximumSizeChanged != null) {
                                MaximumSizeChanged(this, e);
                        }
                }
 
+               [EditorBrowsable(EditorBrowsableState.Advanced)]
                protected virtual void OnMdiChildActivate(EventArgs e) {
                        if (MdiChildActivate != null) {
                                MdiChildActivate(this, e);
                        }
                }
 
+               [EditorBrowsable(EditorBrowsableState.Advanced)]
                protected virtual void OnMenuComplete(EventArgs e) {
                        if (MenuComplete != null) {
                                MenuComplete(this, e);
                        }
                }
 
+               [EditorBrowsable(EditorBrowsableState.Advanced)]
                protected virtual void OnMenuStart(EventArgs e) {
                        if (MenuStart != null) {
                                MenuStart(this, e);
                        }
                }
 
+               [EditorBrowsable(EditorBrowsableState.Advanced)]
                protected virtual void OnMinimumSizeChanged(EventArgs e) {
                        if (MinimumSizeChanged != null) {
                                MinimumSizeChanged(this, e);
                        }
                }
 
+               [EditorBrowsable(EditorBrowsableState.Advanced)]
+               protected override void OnPaint (PaintEventArgs pevent) {
+                       base.OnPaint (pevent);
+               }               
+               
+               [EditorBrowsable(EditorBrowsableState.Advanced)]
+               protected override void OnResize(EventArgs e) {
+                       base.OnResize(e);
+               }
+
+               [EditorBrowsable(EditorBrowsableState.Advanced)]
+               protected override void OnStyleChanged(EventArgs e) {
+                       base.OnStyleChanged (e);
+               }
+
+               [EditorBrowsable(EditorBrowsableState.Advanced)]
+               protected override void OnTextChanged(EventArgs e) {
+                       base.OnTextChanged (e);
+               }
+
+               [EditorBrowsable(EditorBrowsableState.Advanced)]
+               protected override void OnVisibleChanged(EventArgs e) {
+                       base.OnVisibleChanged (e);
+               }
+
+               protected override bool ProcessCmdKey(ref Message msg, Keys keyData) {
+                       if (base.ProcessCmdKey (ref msg, keyData)) {
+                               return true;
+                       }
+
+                       // Give our menu a shot
+                       if (menu != null) {
+                               return menu.ProcessCmdKey(ref msg, keyData);
+                       }
+
+                       return false;
+               }
+
+               // LAMESPEC - Not documented that Form overrides ProcessDialogChar; class-status showed
+               [EditorBrowsable (EditorBrowsableState.Advanced)]
+               protected override bool ProcessDialogChar(char charCode) {
+                       return base.ProcessDialogChar (charCode);
+               }
+
+               protected override bool ProcessDialogKey(Keys keyData) {
+                       if ((keyData & Keys.Modifiers) == 0) {
+                               if (keyData == Keys.Enter && accept_button != null) {
+                                       accept_button.PerformClick();
+                                       return true;
+                               } else if (keyData == Keys.Escape && cancel_button != null) {
+                                       cancel_button.PerformClick();
+                                       return true;
+                               }
+                       }
+                       return base.ProcessDialogKey(keyData);
+               }
+
+               protected override bool ProcessKeyPreview(ref Message msg) {
+                       if (key_preview) {
+                               if (ProcessKeyEventArgs(ref msg)) {
+                                       return true;
+                               }
+                       }
+                       return base.ProcessKeyPreview (ref msg);
+               }
+
+               protected override bool ProcessTabKey(bool forward) {
+                       return SelectNextControl(ActiveControl, forward, true, true, true);
+               }
+
+               [EditorBrowsable(EditorBrowsableState.Advanced)]
+               protected override void ScaleCore(float dx, float dy) {
+                       base.ScaleCore (dx, dy);
+               }
+
+               protected override void Select(bool directed, bool forward) {
+                       Form    parent;
+
+                       if (directed) {
+                               base.SelectNextControl(null, forward, true, true, true);
+                       }
+
+                       parent = this.ParentForm;
+                       if (parent != null) {
+                               parent.ActiveControl = this;
+                       }
+
+                       Activate();
+               }
+
+               [EditorBrowsable(EditorBrowsableState.Advanced)]
+               protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
+                       base.SetBoundsCore (x, y, width, height, specified);
+               }
+
+               [EditorBrowsable(EditorBrowsableState.Advanced)]
+               protected override void SetClientSizeCore(int x, int y) {
+                       if ((minimum_size.Width != 0) && (x < minimum_size.Width)) {
+                               x = minimum_size.Width;
+                       } else if ((maximum_size.Width != 0) && (x > maximum_size.Width)) {
+                               x = maximum_size.Width;
+                       }
+
+                       if ((minimum_size.Height != 0) && (y < minimum_size.Height)) {
+                               y = minimum_size.Height;
+                       } else if ((maximum_size.Height != 0) && (y > maximum_size.Height)) {
+                               y = maximum_size.Height;
+                       }
+
+                       base.SetClientSizeCore (x, y);
+               }
+
+               [EditorBrowsable(EditorBrowsableState.Advanced)]
+               protected override void SetVisibleCore(bool value) {
+                       base.SetVisibleCore (value);
+               }
+
+               protected override void UpdateDefaultButton() {
+                       base.UpdateDefaultButton ();
+               }
+
+               [EditorBrowsable(EditorBrowsableState.Advanced)]
+               protected override void WndProc(ref Message m) {
+
+                       if (IsMdiChild && mdi_child_context.HandleMessage (ref m)) {
+                               return;
+                       }
+
+                       switch((Msg)m.Msg) {
+                               case Msg.WM_CLOSE: {
+                                       CancelEventArgs args = new CancelEventArgs();
+
+                                       OnClosing(args);
+
+                                       if (!args.Cancel) {
+                                               OnClosed(EventArgs.Empty);
+                                               closing = true;
+                                               base.WndProc(ref m);
+                                               break;
+                                       }
+                                       break;
+                               }
+
+                               case Msg.WM_ACTIVATE: {
+                                       if (m.WParam != (IntPtr)WindowActiveFlags.WA_INACTIVE) {
+                                               OnActivated(EventArgs.Empty);
+                                       } else {
+                                               OnDeactivate(EventArgs.Empty);
+                                       }
+                                       return;
+                               }
+
+                               case Msg.WM_KILLFOCUS: {
+                                       base.WndProc(ref m);
+                                       return;
+                               }
+
+                               case Msg.WM_SETFOCUS: {
+#if not
+                                       if (this.ActiveControl != null) {
+                                               ActiveControl.Focus();
+                                       }
+#endif
+                                       base.WndProc(ref m);
+                                       return;
+                               }
+
+                               // Menu drawing
+                               case Msg.WM_NCLBUTTONDOWN: {
+                                       if (this.menu != null) {
+                                               int x = LowOrder ((int) m.LParam.ToInt32 ()) ;
+                                               int y = HighOrder ((int) m.LParam.ToInt32 ());                                          
+                                               menu.OnMouseDown(this, new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()), mouse_clicks, x, y, 0));
+                                       }
+                                       base.WndProc(ref m);
+                                       return;
+                               }
+
+                               case Msg.WM_NCMOUSEMOVE: {
+                                       if (this.menu != null) {
+                                               menu.OnMouseMove(this, new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()), 
+                                                       mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()), 0));
+                                       }
+                                       base.WndProc(ref m);
+                                       return;
+                               }
+
+                               case Msg.WM_NCPAINT: {
+                                       if (this.menu != null) {
+                                               Point pnt = XplatUI.GetMenuOrigin(window.Handle);
+                                               MenuAPI.DrawMenuBar (menu.Handle, new Rectangle (pnt.X, pnt.Y, ClientSize.Width, 0));
+                                       }
+
+                                       base.WndProc(ref m);
+                                       return;
+                               }
+
+                               // This message is only received under Win32
+                               case Msg.WM_NCCALCSIZE: {
+                                       XplatUIWin32.NCCALCSIZE_PARAMS  ncp;
+
+                                       if ((menu != null) && (m.WParam == (IntPtr)1)) {
+                                               ncp = (XplatUIWin32.NCCALCSIZE_PARAMS)Marshal.PtrToStructure(m.LParam, typeof(XplatUIWin32.NCCALCSIZE_PARAMS));
+
+                                               // Adjust for menu
+                                               ncp.rgrc1.top += ThemeEngine.Current.CalcMenuBarSize (DeviceContext, menu.menu_handle, ClientSize.Width);
+                                               Marshal.StructureToPtr(ncp, m.LParam, true);
+                                       }
+                                       DefWndProc(ref m);
+                                       break;
+                               }
+
+                               case Msg.WM_GETMINMAXINFO: {
+                                       XplatUIWin32.MINMAXINFO mmi;
+
+                                       if (m.LParam != IntPtr.Zero) {
+                                               mmi = (XplatUIWin32.MINMAXINFO)Marshal.PtrToStructure(m.LParam, typeof(XplatUIWin32.MINMAXINFO));
+                                               default_maximized_bounds = new Rectangle(mmi.ptMaxPosition.x, mmi.ptMaxPosition.y, mmi.ptMaxSize.x, mmi.ptMaxSize.y);
+                                               if (maximized_bounds != Rectangle.Empty) {
+                                                       mmi.ptMaxSize.x = maximized_bounds.Width;
+                                                       mmi.ptMaxSize.y = maximized_bounds.Height;
+                                               }
+
+                                               Marshal.StructureToPtr(mmi, m.LParam, false);
+                                       }
+                                       break;
+                               }
+
+                               default: {
+                                       base.WndProc (ref m);
+                                       break;
+                               }
+                       }
+               }
+               #endregion      // Protected Instance Methods
+
+               #region Events
                public event EventHandler Activated;
                public event EventHandler Closed;
                public event CancelEventHandler Closing;
@@ -778,6 +1409,10 @@ namespace System.Windows.Forms {
                public event EventHandler MenuComplete;
                public event EventHandler MenuStart;
                public event EventHandler MinimumSizeChanged;
+
+               [Browsable(false)]
+               [EditorBrowsable(EditorBrowsableState.Never)]
+               public new event EventHandler TabIndexChanged;
                #endregion      // Events
        }
 }