Switch to compiler-tester
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / Form.cs
index 1ef5d27f051fe5cc4cd50254586ecdbe97bd9d5a..44d171f1aaf127b52f193646096e17f032221cd8 100644 (file)
@@ -62,6 +62,7 @@ namespace System.Windows.Forms {
                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;
@@ -71,6 +72,8 @@ namespace System.Windows.Forms {
                private SizeGripStyle           size_grip_style;
                private Rectangle               maximized_bounds;
                private Rectangle               default_maximized_bounds;
+               Color                           transparency_key;\r
+
                #endregion      // Local Variables
 
                #region Private & Internal Methods
@@ -127,6 +130,7 @@ namespace System.Windows.Forms {
                        maximized_bounds = Rectangle.Empty;
                        default_maximized_bounds = Rectangle.Empty;
                        owned_forms = new Form.ControlCollection(this);
+                       transparency_key = Color.Empty;
                }
                #endregion      // Public Constructor & Destructor
 
@@ -340,7 +344,7 @@ namespace System.Windows.Forms {
                                if (icon != value) {
                                        icon = value;
 
-                                       XplatUI.SetIcon(window.Handle, icon);
+                                       XplatUI.SetIcon(Handle, icon);
                                }
                        }
                }
@@ -402,7 +406,7 @@ namespace System.Windows.Forms {
                        }
                }
 
-               [DefaultValue(typeof(Size), "{Width=0, Height=0}")]
+               [DefaultValue("{Width=0, Height=0}")]
                [Localizable(true)]
                [RefreshProperties(RefreshProperties.Repaint)]
                public Size MaximumSize {
@@ -445,17 +449,31 @@ namespace System.Windows.Forms {
                        }
 
                        set {
+                               SuspendLayout ();
+
+                               // TopLevel = true;
+
+                               if (!value.IsMdiContainer)
+                                       throw new ArgumentException ();
+
                                if (mdi_parent != null) {
-                                       mdi_parent.Controls.Remove(this);
+                                       mdi_parent.MdiContainer.Controls.Remove (this);
                                }
 
                                mdi_parent = value;
                                if (mdi_parent != null) {
-                                       mdi_parent.Controls.Add(this);
+                                       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 {
@@ -468,8 +486,10 @@ namespace System.Windows.Forms {
 
                                        menu.SetForm (this);
                                        MenuAPI.SetMenuBarWindow (menu.Handle, this);
-                                       
-                                       XplatUI.SetMenu(window.Handle, menu.Handle);
+                               
+                                       if (IsHandleCreated && menu != null) {  
+                                               XplatUI.SetMenu(window.Handle, menu.Handle);
+                                       }
 
                                        // FIXME - Do we still need this?
                                        this.SetBoundsCore(0, 0, 0, 0, BoundsSpecified.None);
@@ -492,7 +512,7 @@ namespace System.Windows.Forms {
                        }
                }
 
-               [DefaultValue(typeof(Size), "{Width=0, Height=0}")]
+               [DefaultValue("{Width=0, Height=0}")]
                [Localizable(true)]
                [RefreshProperties(RefreshProperties.Repaint)]
                public Size MinimumSize {
@@ -572,7 +592,7 @@ namespace System.Windows.Forms {
                [Localizable(false)]
                public Size Size {
                        get {
-                               return Size;
+                               return base.Size;
                        }
 
                        set {
@@ -645,6 +665,8 @@ namespace System.Windows.Forms {
                        }
 
                        set {
+                               if (!value && IsMdiContainer)
+                                       throw new ArgumentException ("MDI Container forms must be top level.");
                                SetTopLevel(value);
                        }
                }
@@ -663,6 +685,18 @@ namespace System.Windows.Forms {
                        }
                }
 
+               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 {
@@ -1016,10 +1050,24 @@ namespace System.Windows.Forms {
                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
@@ -1234,6 +1282,11 @@ namespace System.Windows.Forms {
 
                [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();
@@ -1259,13 +1312,17 @@ namespace System.Windows.Forms {
                                }
 
                                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;
                                }