2005-06-21 Peter Bartok <pbartok@novell.com>
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / Form.cs
index 7057bfa471c27c654099de863aff39b493d704f0..d2b04135eb3eca5de7e8a668cd4d47b1277c0ff7 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
 
@@ -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 {
@@ -494,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 {
@@ -574,7 +592,7 @@ namespace System.Windows.Forms {
                [Localizable(false)]
                public Size Size {
                        get {
-                               return Size;
+                               return base.Size;
                        }
 
                        set {
@@ -647,6 +665,8 @@ namespace System.Windows.Forms {
                        }
 
                        set {
+                               if (!value && IsMdiContainer)
+                                       throw new ArgumentException ("MDI Container forms must be top level.");
                                SetTopLevel(value);
                        }
                }
@@ -665,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 {
@@ -1250,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();
@@ -1280,11 +1317,10 @@ namespace System.Windows.Forms {
                                }
 
                                case Msg.WM_SETFOCUS: {
-#if not
                                        if (this.ActiveControl != null) {
                                                ActiveControl.Focus();
+                                               return; // FIXME - do we need to run base.WndProc, even though we just changed focus?
                                        }
-#endif
                                        base.WndProc(ref m);
                                        return;
                                }