2006-12-01 Rolf Bjarne Kvinge <RKvinge@novell.com>
authorRolf Bjarne Kvinge <RKvinge@novell.com>
Fri, 1 Dec 2006 18:05:04 +0000 (18:05 -0000)
committerRolf Bjarne Kvinge <RKvinge@novell.com>
Fri, 1 Dec 2006 18:05:04 +0000 (18:05 -0000)
* MdiWindowManager.cs:
- Set form to active mdi child if shown,
and update the active mdi child to the next
remaining child in the z-order if the form is hidden.

* Form.cs:
- Track if the form has been visible and if its
visibility is beeing changed, so that the MdiClient
can properly decide the ActiveMdiChild. The MdiClient
cannot track this since the form can change visibility
before MdiClient is created.

* MdiClient.cs:
- Don't activate anything of the parent form is changing
its visibility.
- Rework ActiveMdiChild to only return visible mdi
children and take into account several other corner
cases.

svn path=/trunk/mcs/; revision=68836

mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
mcs/class/Managed.Windows.Forms/System.Windows.Forms/Form.cs
mcs/class/Managed.Windows.Forms/System.Windows.Forms/MdiClient.cs
mcs/class/Managed.Windows.Forms/System.Windows.Forms/MdiWindowManager.cs

index f3ef9e71b42f2f91a8b79f8cca8456664341bc9a..298bb099b384331ba8a82512ddad8d4ec7efb256 100644 (file)
@@ -1,3 +1,24 @@
+2006-12-01  Rolf Bjarne Kvinge  <RKvinge@novell.com>
+
+       * MdiWindowManager.cs:
+       - Set form to active mdi child if shown,
+       and update the active mdi child to the next 
+       remaining child in the z-order if the form is hidden.
+
+       * Form.cs: 
+       - Track if the form has been visible and if its 
+       visibility is beeing changed, so that the MdiClient
+       can properly decide the ActiveMdiChild. The MdiClient 
+       cannot track this since the form can change visibility 
+       before MdiClient is created.
+
+       * MdiClient.cs:
+       - Don't activate anything of the parent form is changing
+       its visibility.
+       - Rework ActiveMdiChild to only return visible mdi 
+       children and take into account several other corner 
+       cases.
+
 2006-12-01  Chris Toshok  <toshok@ximian.com>
 
        * IBindableComponent.cs: new 2.0 interface.
index fd2c51e661d25747153c8740606d17279aa391db..6c326537d02a8c7a59b8aad2ce78e01e48cac412 100644 (file)
@@ -79,6 +79,8 @@ namespace System.Windows.Forms {
                Color                           transparency_key;
                internal MenuTracker            active_tracker;
                private bool                    is_loaded;
+               internal bool                   is_changing_visible_state;
+               internal bool                   has_been_visible;
 
                #endregion      // Local Variables
 
@@ -458,6 +460,7 @@ namespace System.Windows.Forms {
                                        Controls.Add(mdi_container);
                                        ControlAdded += new ControlEventHandler (ControlAddedHandler);
                                        mdi_container.SendToBack ();
+                                       mdi_container.SetParentText (true);
                                } else if (!value && mdi_container != null) {
                                        Controls.Remove(mdi_container);
                                        mdi_container = null;
@@ -1624,8 +1627,8 @@ namespace System.Windows.Forms {
                protected override void OnTextChanged(EventArgs e) {
                        base.OnTextChanged (e);
 
-            if (mdi_container != null)
-                mdi_container.SetParentText(true);
+                       if (mdi_container != null)
+                               mdi_container.SetParentText(true);
                }
 
                [EditorBrowsable(EditorBrowsableState.Advanced)]
@@ -1773,7 +1776,10 @@ namespace System.Windows.Forms {
 
                [EditorBrowsable(EditorBrowsableState.Advanced)]
                protected override void SetVisibleCore(bool value) {
+                       is_changing_visible_state = true;
+                       has_been_visible = value || has_been_visible;
                        base.SetVisibleCore (value);
+                       is_changing_visible_state = false;
                }
 
                protected override void UpdateDefaultButton() {
index 438a253725e1e51eca6d82e9487a35695d219a8f..8198578465eff5aa0d5b6db8089db2c3419e3d2d 100644 (file)
@@ -51,6 +51,7 @@ namespace System.Windows.Forms {
                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
 
@@ -556,7 +557,6 @@ namespace System.Windows.Forms {
                                                } 
                                        }
                                } while (!success);
-                               Console.WriteLine("IconicBounds = {0}", rect);
                                wm.IconicBounds = rect;
                                form.Bounds = wm.IconicBounds;
                        }
@@ -574,6 +574,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 +602,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 +616,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 +688,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;
+                               }
+                       }
+               }
        }
 }
 
index 5d6eb39a18e6a6b94033c4857a38d50ac0400db6..f17877a0daeccef5c3c14d5d84f3ae5830fa9649 100644 (file)
@@ -64,10 +64,23 @@ namespace System.Windows.Forms {
                        form.TextChanged += new EventHandler (FormTextChangedHandler);
                        form.SizeChanged += new EventHandler (FormSizeChangedHandler);
                        form.LocationChanged += new EventHandler (FormLocationChangedHandler);
+                       form.VisibleChanged += new EventHandler (FormVisibleChangedHandler);
                        draw_maximized_buttons = new PaintEventHandler (DrawMaximizedButtons);
                        CreateIconMenus ();
                }
 
+               private void FormVisibleChangedHandler (object sender, EventArgs e)
+               {
+                       if (mdi_container == null)
+                               return;
+                               
+                       if (form.Visible) {
+                               mdi_container.ActivateChild (form);
+                       } else if (mdi_container.Controls.Count > 1) {
+                               mdi_container.ActivateActiveMdiChild ();
+                       }
+               }
+
                private void FormTextChangedHandler (object sender, EventArgs e)
                {
                        mdi_container.SetParentText (false);
@@ -282,6 +295,8 @@ namespace System.Windows.Forms {
                                MaximizedMenu.Paint -= draw_maximized_buttons;
                                break;
                        case FormWindowState.Maximized:
+                               if (mdi_container.ActiveMdiChild != form)
+                                       mdi_container.ActivateChild (form);
                                CreateButtons ();
                                maximize_button.Caption = CaptionButton.Restore;
                                minimize_button.Caption = CaptionButton.Minimize;
@@ -335,9 +350,6 @@ namespace System.Windows.Forms {
                private void FormClosed (object sender, EventArgs e)
                {
                        mdi_container.CloseChildForm (form);
-                       XplatUI.RequestNCRecalc (mdi_container.Parent.Handle);
-                       mdi_container.SizeScrollBars ();
-                       mdi_container.SetParentText (false);
                }
 
                /*