Author: jpobst
Date: 2008-01-18 17:42:51 -0500 (Fri, 18 Jan 2008)
New Revision: 93298

Modified:
   trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
   
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ContainerControl.cs
   trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Control.cs
   trunk/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ChangeLog
   trunk/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/FormTest.cs
Log:
2008-01-18  Jonathan Pobst  <[EMAIL PROTECTED]>

        * ContainerControl.cs, Control.cs: Apply patch from James Purcell
        that makes our AutoScale* stuff more tolerant to different orders
        of being set.  [Fixes bug #354669]

2008-01-18  Jonathan Pobst  <[EMAIL PROTECTED]>

        * FormTest.cs: Add test from James Purcell for bug #354669.

Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog        
2008-01-18 22:06:53 UTC (rev 93297)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog        
2008-01-18 22:42:51 UTC (rev 93298)
@@ -1,3 +1,9 @@
+2008-01-18  Jonathan Pobst  <[EMAIL PROTECTED]>
+
+       * ContainerControl.cs, Control.cs: Apply patch from James Purcell
+       that makes our AutoScale* stuff more tolerant to different orders
+       of being set.  [Fixes bug #354669]
+
 2008-01-18  Ivan N. Zlatev  <[EMAIL PROTECTED]>
 
         * PropertyGridView.cs, PropertyGridTextBox.cs: 

Modified: 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ContainerControl.cs
===================================================================
--- 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ContainerControl.cs  
    2008-01-18 22:06:53 UTC (rev 93297)
+++ 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ContainerControl.cs  
    2008-01-18 22:42:51 UTC (rev 93298)
@@ -46,6 +46,8 @@
 #if NET_2_0
                private SizeF           auto_scale_dimensions;
                private AutoScaleMode   auto_scale_mode;
+               private bool            auto_scale_mode_set;
+               private bool            auto_scale_pending;
 #endif
 
                internal bool validation_failed; //track whether validation was 
cancelled by a validating control
@@ -248,17 +250,16 @@
                                if (auto_scale_dimensions != value) {
                                        auto_scale_dimensions = value;
                                        
-                                       if (AutoScaleFactor != new SizeF (1, 1))
-                                               PerformAutoScale ();
+                                       PerformAutoScale ();
                                }
                        }
                }
 
                protected SizeF AutoScaleFactor {
                        get {
-                               if (auto_scale_dimensions.IsEmpty) {
-                                       return new SizeF(1f, 1f);
-                               }
+                               if (auto_scale_dimensions.IsEmpty)
+                                       return new SizeF (1f, 1f);
+
                                return new 
SizeF(CurrentAutoScaleDimensions.Width / auto_scale_dimensions.Width,
                                        CurrentAutoScaleDimensions.Height / 
auto_scale_dimensions.Height);
                        }
@@ -275,7 +276,13 @@
                        set {
                                if (auto_scale_mode != value) {
                                        auto_scale_mode = value;
-                                       auto_scale_dimensions = 
CurrentAutoScaleDimensions;
+
+                                       if (auto_scale_mode_set)
+                                               auto_scale_dimensions = 
SizeF.Empty;
+
+                                       auto_scale_mode_set = true;
+
+                                       PerformAutoScale ();
                                }
                                        
                                if (this is Form)
@@ -351,12 +358,28 @@
 #if NET_2_0
                public void PerformAutoScale ()
                {
-                       SuspendLayout ();
-                       Scale (AutoScaleFactor);
-                       ResumeLayout (false);
-                       
+                       if (layout_suspended > 0) {
+                               auto_scale_pending = true;
+                               return;
+                       }
+                       // Set this first so we don't get called again from
+                       // PerformDelayedAutoScale after ResumeLayout
+                       auto_scale_pending = false;
+
+                       if (AutoScaleFactor != new SizeF(1F, 1F)) {
+                               SuspendLayout ();
+                               Scale (AutoScaleFactor);
+                               ResumeLayout (false);
+                       }
+
                        auto_scale_dimensions = CurrentAutoScaleDimensions;
                }
+
+               internal void PerformDelayedAutoScale ()
+               {
+                       if (auto_scale_pending)
+                               PerformAutoScale ();
+               }
 #endif
 
                [MonoTODO]

Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Control.cs
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Control.cs       
2008-01-18 22:06:53 UTC (rev 93297)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Control.cs       
2008-01-18 22:42:51 UTC (rev 93298)
@@ -113,7 +113,7 @@
                        Dock
                }
                Layout.LayoutEngine layout_engine;
-               int layout_suspended;
+               internal int layout_suspended;
                bool layout_pending; // true if our parent needs to re-layout us
                internal AnchorStyles anchor_style; // anchoring requirements 
for our control
                internal DockStyle dock_style; // docking requirements for our 
control
@@ -4070,6 +4070,11 @@
                        }
 
                        if (layout_suspended == 0) {
+#if NET_2_0
+                               if (this is ContainerControl)
+                                       (this as 
ContainerControl).PerformDelayedAutoScale();
+#endif
+
                                if (!performLayout)
                                        foreach (Control c in 
Controls.GetAllControls ())
                                                c.UpdateDistances ();

Modified: 
trunk/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ChangeLog
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ChangeLog   
2008-01-18 22:06:53 UTC (rev 93297)
+++ trunk/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ChangeLog   
2008-01-18 22:42:51 UTC (rev 93298)
@@ -1,5 +1,9 @@
 2008-01-18  Jonathan Pobst  <[EMAIL PROTECTED]>
 
+       * FormTest.cs: Add test from James Purcell for bug #354669.
+
+2008-01-18  Jonathan Pobst  <[EMAIL PROTECTED]>
+
        * MdiFormTest.cs: Add test for bug #354286.
 
 2008-01-15  Jonathan Pobst  <[EMAIL PROTECTED]>

Modified: 
trunk/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/FormTest.cs
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/FormTest.cs 
2008-01-18 22:06:53 UTC (rev 93297)
+++ trunk/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/FormTest.cs 
2008-01-18 22:42:51 UTC (rev 93298)
@@ -2736,6 +2736,76 @@
                {
                        return new Size ((int)Math.Round (sizef.Width), 
(int)Math.Round (sizef.Height));
                }
+               
+               [Test] // Bug 354669
+               public void AutoScaleDetails ()
+               {
+                       ProtectedForm f = new ProtectedForm ();
+                       f.Show ();
+                       
+                       f.SuspendLayout ();
+                       
+                       // First AutoScaleMode shouldn't reset 
AutoScaleDimensions
+                       f.AutoScaleDimensions = new SizeF (3F, 3F);
+                       f.AutoScaleMode = AutoScaleMode.Font;
+                       Assert.AreEqual (new SizeF (3F, 3F), 
f.AutoScaleDimensions, "A1");
+                       
+                       // Subsequent calls will reset it to 0, 0
+                       f.AutoScaleMode = AutoScaleMode.Dpi;
+                       Assert.AreEqual (SizeF.Empty, f.AutoScaleDimensions, 
"A2");
+
+                       f.ResumeLayout ();
+                       
+                       // CurrentAutoScaleDimensions should be nonzero
+                       Assert.IsFalse (f.CurrentAutoScaleDimensions == 
SizeF.Empty, "A3");
+                       
+                       // AutoScaleDimensions and CurrentAutoScaleDimensions 
should match after ResumeLayout
+                       Assert.AreEqual (f.AutoScaleDimensions, 
f.CurrentAutoScaleDimensions, "A4");
+
+                       // CurrentAutoScaleDimensions should match 
AutoScaleDimensions for AutoScaleMode.None
+                       f.SuspendLayout ();
+                       f.AutoScaleMode = AutoScaleMode.None;
+                       f.AutoScaleDimensions = new SizeF (5F, 5F);
+
+                       Assert.AreEqual (new SizeF (5F, 5F), 
f.AutoScaleDimensions, "A5");
+                       Assert.AreEqual (f.AutoScaleDimensions, 
f.CurrentAutoScaleDimensions, "A6");
+
+                       // ResumeLayout changes nothing
+                       f.ResumeLayout ();
+
+                       Assert.AreEqual (new SizeF (5F, 5F), 
f.AutoScaleDimensions, "A7");
+                       Assert.AreEqual (f.AutoScaleDimensions, 
f.CurrentAutoScaleDimensions, "A8");
+
+                       // AutoScaleFactor should be ~2,2 if PerformAutoScale 
hasn't run
+                       f.ClientSize = new Size (150, 150);
+                       f.SuspendLayout ();
+                       f.AutoScaleMode = AutoScaleMode.Dpi;
+                       f.AutoScaleDimensions = new SizeF 
(f.CurrentAutoScaleDimensions.Width / 2F, f.CurrentAutoScaleDimensions.Height / 
2F);
+                       f.ClientSize = new Size (200, 200);
+
+                       Assert.AreEqual (new Size (2, 2), RoundSizeF 
(f.GetPublicAutoScaleFactor ()), "A9");
+
+                       // AutoScaleFactor should be 1 after ResumeLayout
+                       f.ResumeLayout ();
+
+                       Assert.AreEqual (new SizeF (1F, 1F), 
f.GetPublicAutoScaleFactor (), "A10");
+                       Assert.AreEqual (new Size (400, 400), f.ClientSize, 
"A11");
+                       
+                       // PerformAutoScale happens immediately when layout not 
suspended
+                       f.ClientSize = new Size (125, 125);
+                       f.AutoScaleDimensions = new SizeF 
(f.CurrentAutoScaleDimensions.Width / 2F, f.CurrentAutoScaleDimensions.Height / 
2F);
+                       Assert.AreEqual (new Size (250, 250), f.ClientSize, 
"A12");
+                       
+                       f.Dispose ();
+               }
+               
+               private class ProtectedForm : Form
+               {
+                       public SizeF GetPublicAutoScaleFactor ()
+                       {
+                               return AutoScaleFactor;
+                       }
+               }
 #endif
        }
 

_______________________________________________
Mono-patches maillist  -  Mono-patches@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to