* MdiClient.cs:
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / MdiClient.cs
index 438a253725e1e51eca6d82e9487a35695d219a8f..248d05b777e92691252aecea90db346d9e90a8ca 100644 (file)
@@ -45,12 +45,11 @@ namespace System.Windows.Forms {
                private bool lock_sizing;
                private bool initializing_scrollbars;
                private int prev_bottom;
-               private LayoutEventHandler initial_layout_handler;
                private bool setting_windowstates = false;
                internal ArrayList mdi_child_list;
                private string form_text;
                private bool setting_form_text;
-               internal ArrayList original_order = new ArrayList (); // The order the child forms are added (used by the main menu to show the window menu)
+               private Form active_child;
 
                #endregion      // Local Variables
 
@@ -61,7 +60,6 @@ namespace System.Windows.Forms {
                        
                        public ControlCollection(MdiClient owner) : base(owner) {
                                this.owner = owner;
-                               owner.mdi_child_list = new ArrayList ();
                        }
 
                        public override void Add(Control value) {
@@ -95,6 +93,7 @@ namespace System.Windows.Forms {
                #region Public Constructors
                public MdiClient()
                {
+                       mdi_child_list = new ArrayList ();
                        BackColor = SystemColors.AppWorkspace;
                        Dock = DockStyle.Fill;
                        SetStyle (ControlStyles.Selectable, false);
@@ -491,11 +490,6 @@ namespace System.Windows.Forms {
                        prev_bottom = Bottom;
                }
 
-               private void FormLocationChanged (object sender, EventArgs e)
-               {
-                       SizeScrollBars ();
-               }
-
                internal void ArrangeIconicWindows ()
                {
                        int xspacing = 160;
@@ -556,7 +550,6 @@ namespace System.Windows.Forms {
                                                } 
                                        }
                                } while (!success);
-                               Console.WriteLine("IconicBounds = {0}", rect);
                                wm.IconicBounds = rect;
                                form.Bounds = wm.IconicBounds;
                        }
@@ -574,6 +567,14 @@ namespace System.Windows.Forms {
 
                        Controls.Remove (form);
                        form.Close ();
+
+                       XplatUI.RequestNCRecalc (Handle);
+                       if (Controls.Count == 0) {
+                               XplatUI.RequestNCRecalc (Parent.Handle);
+                               ParentForm.PerformLayout ();
+                       }
+                       SizeScrollBars ();
+                       SetParentText (false);
                }
 
                internal void ActivateNextChild ()
@@ -594,7 +595,10 @@ namespace System.Windows.Forms {
                {
                        if (Controls.Count < 1)
                                return;
-
+                       
+                       if (ParentForm.is_changing_visible_state)
+                               return;
+                               
                        Form current = (Form) Controls [0];
                        form.SuspendLayout ();
                        form.BringToFront ();
@@ -605,9 +609,11 @@ namespace System.Windows.Forms {
                        SetWindowStates ((MdiWindowManager) form.window_manager);
                        form.ResumeLayout (false);
                        if (current != form) {
+                               form.has_focus = false;
                                XplatUI.InvalidateNC (current.Handle);
                                XplatUI.InvalidateNC (form.Handle);
                        }
+                       active_child = (Form) Controls [0];
                }
                
                internal bool SetWindowStates (MdiWindowManager wm)
@@ -675,14 +681,48 @@ namespace System.Windows.Forms {
 
                internal Form ActiveMdiChild {
                        get {
+#if NET_2_0
+                               if (!ParentForm.Visible)
+                                       return null;
+#endif
                                if (Controls.Count < 1)
                                        return null;
-                               return (Form) Controls [0];
+                                       
+                               if (!ParentForm.IsHandleCreated)
+                                       return null;
+                               
+                               if (!ParentForm.has_been_visible)
+                                       return null;
+                                       
+                               if (!ParentForm.Visible)
+                                       return active_child;
+                               
+                               active_child = null;
+                               for (int i = 0; i < Controls.Count; i++) {
+                                       if (Controls [i].Visible) {
+                                               active_child = (Form) Controls [i];
+                                               break;
+                                       }
+                               }
+                               return active_child;
                        }
                        set {
                                ActivateChild (value);
                        }
                }
+               
+               internal void ActivateActiveMdiChild ()
+               {
+                       if (ParentForm.is_changing_visible_state)
+                               return;
+                               
+                       for (int i = 0; i < Controls.Count; i++) {
+                               if (Controls [i].Visible) {
+                                       ActivateChild ((Form) Controls [i]);
+                                       return;
+                               }
+                       }
+               }
        }
 }