Author: jpobst
Date: 2008-02-08 14:39:04 -0500 (Fri, 08 Feb 2008)
New Revision: 95295
Modified:
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ComboBox.cs
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/System.Windows.Forms/DataGrid.cs
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridView.cs
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Form.cs
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ListBox.cs
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ListControl.cs
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ListView.cs
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/TextBoxBase.cs
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/TreeView.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-02-08 Jonathan Pobst <[EMAIL PROTECTED]>
Commit patch from James Purcell for better AutoScale implementation:
* ScaleControl should call GetScaledBounds with the control's total
size rather
than client size. GetScaledBounds should handle ignoring the borders
in its
calculations. Cleaned up ScaleControl/GetScaledBounds overrides in
controls
(for the most part they just call the base code now since that is
fixed).
* Added ScaleChildrenInternal to allow controls to disable scaling of
children
without having to override ScaleChildren (since none of .NET's controls
do).
This is required for most controls in Mono that have scrollbars to
prevent the
scrollbars from being moved/resized.
* Nested ContainerControls can have a different scale mode than their
parent.
This is briefly mentioned in MSDN but is buggy in MS.NET (the runtime
and
designer produce different results both of which look incorrect).
* Default AutoScaleMode for ContainerControl should be Inherit.
* Simplified workaround for ComboBox scaling issue.
* 1.0 style auto-scaling now uses its own methods instead of sharing
2.0's.
1.0 style auto scaling should scale the whole control's size instead of
ignoring the borders (except for Form) and the rounding is done
differently to
preserve control alignment.
* ApplyAutoScaling (used for 1.0 style) should use the rounded result of
GetAutoScaleSize.
* Cleaned up fix for "Bug 355703 - Setting AutoScale = true doesn't
stick".
* CurrentAutoScaleDimensions should round the estimated character width
instead
of truncating.
* ListBox's GetScaledBounds should always use the height it was set to
instead
of the height that was passed in. This prevents rounding errors from
accumulating quickly with IntegralHeight.
[Bug #359098]
2008-02-08 Jonathan Pobst <[EMAIL PROTECTED]>
* FormTest.cs: Commit tests from James Purcell for his new
AutoScale implementation. [Bug #359098]
Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
2008-02-08 19:38:26 UTC (rev 95294)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
2008-02-08 19:39:04 UTC (rev 95295)
@@ -1,3 +1,34 @@
+2008-02-08 Jonathan Pobst <[EMAIL PROTECTED]>
+
+ Commit patch from James Purcell for better AutoScale implementation:
+
+ * ScaleControl should call GetScaledBounds with the control's total
size rather
+ than client size. GetScaledBounds should handle ignoring the borders
in its
+ calculations. Cleaned up ScaleControl/GetScaledBounds overrides in
controls
+ (for the most part they just call the base code now since that is
fixed).
+ * Added ScaleChildrenInternal to allow controls to disable scaling of
children
+ without having to override ScaleChildren (since none of .NET's controls
do).
+ This is required for most controls in Mono that have scrollbars to
prevent the
+ scrollbars from being moved/resized.
+ * Nested ContainerControls can have a different scale mode than their
parent.
+ This is briefly mentioned in MSDN but is buggy in MS.NET (the runtime
and
+ designer produce different results both of which look incorrect).
+ * Default AutoScaleMode for ContainerControl should be Inherit.
+ * Simplified workaround for ComboBox scaling issue.
+ * 1.0 style auto-scaling now uses its own methods instead of sharing
2.0's.
+ 1.0 style auto scaling should scale the whole control's size instead of
+ ignoring the borders (except for Form) and the rounding is done
differently to
+ preserve control alignment.
+ * ApplyAutoScaling (used for 1.0 style) should use the rounded result of
+ GetAutoScaleSize.
+ * Cleaned up fix for "Bug 355703 - Setting AutoScale = true doesn't
stick".
+ * CurrentAutoScaleDimensions should round the estimated character width
instead
+ of truncating.
+ * ListBox's GetScaledBounds should always use the height it was set to
instead
+ of the height that was passed in. This prevents rounding errors from
+ accumulating quickly with IntegralHeight.
+ [Bug #359098]
+
2008-02-08 Andreia Gaita <[EMAIL PROTECTED]>
* Form.cs: Add a null check (darn it).
Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ComboBox.cs
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ComboBox.cs
2008-02-08 19:38:26 UTC (rev 95294)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ComboBox.cs
2008-02-08 19:39:04 UTC (rev 95295)
@@ -1231,31 +1231,9 @@
#endif
#if NET_2_0
- private float current_factor_width = 1f;
-
- // WTF? WTF? WTF????
- // I am sure this is tied to something I missed that makes this
make sense.
- // Every time you double the size of the control, subtract 4
pixels from it
protected override void ScaleControl (SizeF factor,
BoundsSpecified specified)
{
- // Never change the ComboBox's height
- specified &= ~BoundsSpecified.Height;
-
- int width = ClientSize.Width;
-
- // Go back to the original (un-4-subtracted) size
- if ((specified & BoundsSpecified.Width) ==
BoundsSpecified.Width)
- width += (int)(((current_factor_width) - 1f) *
4.0f);
-
- Rectangle new_bounds = GetScaledBounds (new Rectangle
(Location, new Size (width, ClientSize.Height)), factor, specified);
-
- // Subtract 4 for every time the control is 'doubled'
- if ((specified & BoundsSpecified.Width) ==
BoundsSpecified.Width) {
- new_bounds.Width += (int)(((factor.Width *
current_factor_width) - 1f) * -4.0f);
- current_factor_width *= factor.Width;
- }
-
- SetBounds (new_bounds.X, new_bounds.Y,
new_bounds.Width, new_bounds.Height, specified);
+ base.ScaleControl (factor, specified);
}
#endif
Modified:
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ContainerControl.cs
===================================================================
---
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ContainerControl.cs
2008-02-08 19:38:26 UTC (rev 95294)
+++
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ContainerControl.cs
2008-02-08 19:39:04 UTC (rev 95295)
@@ -48,6 +48,7 @@
private AutoScaleMode auto_scale_mode;
private bool auto_scale_mode_set;
private bool auto_scale_pending;
+ private bool is_auto_scaling;
#endif
internal bool validation_failed; //track whether validation was
cancelled by a validating control
@@ -59,7 +60,7 @@
ControlRemoved += new
ControlEventHandler(OnControlRemoved);
#if NET_2_0
auto_scale_dimensions = SizeF.Empty;
- auto_scale_mode = AutoScaleMode.None;
+ auto_scale_mode = AutoScaleMode.Inherit;
#endif
}
#endregion // Public Constructors
@@ -274,6 +275,9 @@
return auto_scale_mode;
}
set {
+ if (this is Form)
+ (this as Form).AutoScale = false;
+
if (auto_scale_mode != value) {
auto_scale_mode = value;
@@ -284,9 +288,6 @@
PerformAutoScale ();
}
-
- if (this is Form)
- (this as Form).AutoScale = false;
}
}
#endif // NET_2_0
@@ -316,7 +317,7 @@
case AutoScaleMode.Font:
Size s =
TextRenderer.MeasureText
("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890", Font);
- int width =
(int)((float)s.Width / 62f);
+ int width = (int)Math.Round
((float)s.Width / 62f);
return new SizeF (width,
s.Height);
}
@@ -356,9 +357,12 @@
#region Public Instance Methods
#if NET_2_0
- public void PerformAutoScale ()
+ internal void PerformAutoScale (bool called_by_scale)
{
- if (layout_suspended > 0) {
+ if ((AutoScaleMode == AutoScaleMode.Inherit) &&
!called_by_scale)
+ return;
+
+ if ((layout_suspended > 0) && !called_by_scale) {
auto_scale_pending = true;
return;
}
@@ -366,20 +370,37 @@
// PerformDelayedAutoScale after ResumeLayout
auto_scale_pending = false;
- if (AutoScaleFactor != new SizeF(1F, 1F)) {
+ SizeF factor = AutoScaleFactor;
+ if (AutoScaleMode == AutoScaleMode.Inherit) {
+ ContainerControl cc = FindContainer
(this.Parent);
+ if (cc != null)
+ factor = cc.AutoScaleFactor;
+ }
+ if (factor != new SizeF (1F, 1F)) {
+ is_auto_scaling = true;
SuspendLayout ();
- Scale (AutoScaleFactor);
+ Scale (factor);
ResumeLayout (false);
+ is_auto_scaling = false;
}
auto_scale_dimensions = CurrentAutoScaleDimensions;
}
+ public void PerformAutoScale ()
+ {
+ PerformAutoScale (false);
+ }
+
internal void PerformDelayedAutoScale ()
{
if (auto_scale_pending)
PerformAutoScale ();
}
+
+ internal bool IsAutoScaling {
+ get { return is_auto_scaling; }
+ }
#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-02-08 19:38:26 UTC (rev 95294)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Control.cs
2008-02-08 19:39:04 UTC (rev 95295)
@@ -3562,15 +3562,15 @@
#if NET_2_0
[EditorBrowsable (EditorBrowsableState.Advanced)]
- protected
-#else
- internal
+ protected virtual bool ScaleChildren {
+ get { return ScaleChildrenInternal; }
+ }
#endif
- virtual bool ScaleChildren
- {
+
+ internal virtual bool ScaleChildrenInternal {
get { return true; }
}
-
+
[EditorBrowsable(EditorBrowsableState.Advanced)]
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
@@ -4219,26 +4219,52 @@
ScaleCore(dx, dy);
}
+#if NET_2_0
[EditorBrowsable (EditorBrowsableState.Advanced)]
-#if NET_2_0
- public
-#else
- internal
-#endif
- void Scale (SizeF factor)
+ public void Scale (SizeF factor)
{
+ BoundsSpecified bounds_spec = BoundsSpecified.All;
+
SuspendLayout ();
-
- ScaleControl (factor, BoundsSpecified.All);
+ if (this is ContainerControl) {
+ if ((this as ContainerControl).IsAutoScaling)
+ bounds_spec = BoundsSpecified.Size;
+ else if (IsContainerAutoScaling (this.Parent))
+ bounds_spec = BoundsSpecified.Location;
+ }
+
+ ScaleControl (factor, bounds_spec);
+
// Scale children
- if (ScaleChildren)
- foreach (Control c in Controls.GetAllControls
())
+ if ((bounds_spec != BoundsSpecified.Location) &&
ScaleChildren) {
+ foreach (Control c in Controls.GetAllControls
()) {
c.Scale (factor);
+ if (c is ContainerControl) {
+ ContainerControl cc = c as
ContainerControl;
+ if ((cc.AutoScaleMode ==
AutoScaleMode.Inherit) && IsContainerAutoScaling (this))
+ cc.PerformAutoScale
(true);
+ }
+ }
+ }
ResumeLayout ();
}
+ internal ContainerControl FindContainer (Control c)
+ {
+ while ((c != null) && !(c is ContainerControl))
+ c = c.Parent;
+ return c as ContainerControl;
+ }
+
+ private bool IsContainerAutoScaling (Control c)
+ {
+ ContainerControl cc = FindContainer (c);
+ return (cc != null) && cc.IsAutoScaling;
+ }
+#endif
+
public void Select() {
Select(false, false);
}
@@ -4445,25 +4471,57 @@
}
[EditorBrowsable (EditorBrowsableState.Advanced)]
- protected
-#else
- internal
+ protected virtual Rectangle GetScaledBounds (Rectangle bounds,
SizeF factor, BoundsSpecified specified)
+ {
+ // Top level controls do not scale location
+ if (!is_toplevel) {
+ if ((specified & BoundsSpecified.X) ==
BoundsSpecified.X)
+ bounds.X = (int)Math.Round (bounds.X *
factor.Width);
+ if ((specified & BoundsSpecified.Y) ==
BoundsSpecified.Y)
+ bounds.Y = (int)Math.Round (bounds.Y *
factor.Height);
+ }
+
+ if ((specified & BoundsSpecified.Width) ==
BoundsSpecified.Width && !GetStyle (ControlStyles.FixedWidth)) {
+ int border = (this is ComboBox) ?
(ThemeEngine.Current.Border3DSize.Width * 2) :
+ (this.bounds.Width -
this.client_size.Width);
+ bounds.Width = (int)Math.Round ((bounds.Width -
border) * factor.Width + border);
+ }
+ if ((specified & BoundsSpecified.Height) ==
BoundsSpecified.Height && !GetStyle (ControlStyles.FixedHeight)) {
+ int border = (this is ComboBox) ?
(ThemeEngine.Current.Border3DSize.Height * 2) :
+ (this.bounds.Height -
this.client_size.Height);
+ bounds.Height = (int)Math.Round ((bounds.Height
- border) * factor.Height + border);
+ }
+
+ return bounds;
+ }
#endif
- virtual Rectangle GetScaledBounds (Rectangle bounds, SizeF
factor, BoundsSpecified specified)
+
+ private Rectangle GetScaledBoundsOld (Rectangle bounds, SizeF
factor, BoundsSpecified specified)
{
+ RectangleF new_bounds = new RectangleF(bounds.Location,
bounds.Size);
+
// Top level controls do not scale location
if (!is_toplevel) {
if ((specified & BoundsSpecified.X) ==
BoundsSpecified.X)
- bounds.X = (int)Math.Round (bounds.Left
* factor.Width);
+ new_bounds.X *= factor.Width;
if ((specified & BoundsSpecified.Y) ==
BoundsSpecified.Y)
- bounds.Y = (int)Math.Round (bounds.Top
* factor.Height);
+ new_bounds.Y *= factor.Height;
}
-
- if ((specified & BoundsSpecified.Width) ==
BoundsSpecified.Width && !GetStyle (ControlStyles.FixedWidth))
- bounds.Width = (int)Math.Round (bounds.Width *
factor.Width);
- if ((specified & BoundsSpecified.Height) ==
BoundsSpecified.Height && !GetStyle (ControlStyles.FixedHeight))
- bounds.Height = (int)Math.Round (bounds.Height
* factor.Height);
-
+
+ if ((specified & BoundsSpecified.Width) ==
BoundsSpecified.Width && !GetStyle (ControlStyles.FixedWidth)) {
+ int border = (this is Form) ?
(this.bounds.Width - this.client_size.Width) : 0;
+ new_bounds.Width = ((new_bounds.Width - border)
* factor.Width + border);
+ }
+ if ((specified & BoundsSpecified.Height) ==
BoundsSpecified.Height && !GetStyle (ControlStyles.FixedHeight)) {
+ int border = (this is Form) ?
(this.bounds.Height - this.client_size.Height) : 0;
+ new_bounds.Height = ((new_bounds.Height -
border) * factor.Height + border);
+ }
+
+ bounds.X = (int)Math.Round (new_bounds.X);
+ bounds.Y = (int)Math.Round (new_bounds.Y);
+ bounds.Width = (int)Math.Round (new_bounds.Right) -
bounds.X;
+ bounds.Height = (int)Math.Round (new_bounds.Bottom) -
bounds.Y;
+
return bounds;
}
@@ -4771,48 +4829,32 @@
#if NET_2_0
[EditorBrowsable (EditorBrowsableState.Advanced)]
- protected
-#else
- internal
-#endif
- virtual void ScaleControl (SizeF factor, BoundsSpecified
specified)
+ protected virtual void ScaleControl (SizeF factor,
BoundsSpecified specified)
{
- Rectangle new_bounds = GetScaledBounds (new Rectangle
(Location, ClientSize), factor, specified);
+ Rectangle new_bounds = GetScaledBounds (bounds, factor,
specified);
SetBounds (new_bounds.X, new_bounds.Y,
new_bounds.Width, new_bounds.Height, specified);
}
+#endif
#if NET_2_0
[EditorBrowsable (EditorBrowsableState.Never)]
#else
- [EditorBrowsable(EditorBrowsableState.Advanced)]
+ [EditorBrowsable (EditorBrowsableState.Advanced)]
#endif
- protected virtual void ScaleCore(float dx, float dy) {
- Point location;
- Size size;
+ protected virtual void ScaleCore (float dx, float dy)
+ {
+ Rectangle new_bounds = GetScaledBoundsOld (bounds, new
SizeF (dx, dy), BoundsSpecified.All);
- SuspendLayout();
+ SuspendLayout ();
- location = new Point((int)(Left * dx), (int)(Top * dy));
- size = this.ClientSize;
+ SetBounds (new_bounds.X, new_bounds.Y,
new_bounds.Width, new_bounds.Height, BoundsSpecified.All);
- if (!GetStyle(ControlStyles.FixedWidth)) {
- size.Width = (int)(size.Width * dx);
- }
+ if (ScaleChildrenInternal)
+ foreach (Control c in Controls.GetAllControls
())
+ c.Scale (dx, dy);
- if (!GetStyle(ControlStyles.FixedHeight)) {
- size.Height = (int)(size.Height * dy);
- }
-
- SetBounds(location.X, location.Y, size.Width,
size.Height, BoundsSpecified.All);
-
- /* Now scale our children */
- Control [] controls = child_controls.GetAllControls ();
- for (int i=0; i < controls.Length; i++) {
- controls[i].Scale (new SizeF (dx, dy));
- }
-
- ResumeLayout();
+ ResumeLayout ();
}
protected virtual void Select(bool directed, bool forward) {
Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGrid.cs
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGrid.cs
2008-02-08 19:38:26 UTC (rev 95294)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGrid.cs
2008-02-08 19:39:04 UTC (rev 95295)
@@ -926,6 +926,10 @@
}
}
+ internal override bool ScaleChildrenInternal {
+ get { return false; }
+ }
+
internal bool ShowEditRow {
get {
if (ListManager != null &&
!ListManager.CanAddRows)
Modified:
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridView.cs
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridView.cs
2008-02-08 19:38:26 UTC (rev 95294)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridView.cs
2008-02-08 19:39:04 UTC (rev 95295)
@@ -1016,6 +1016,10 @@
}
}
+ internal override bool ScaleChildrenInternal {
+ get { return false; }
+ }
+
[DefaultValue (ScrollBars.Both)]
[Localizable (true)]
public ScrollBars ScrollBars {
Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Form.cs
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Form.cs
2008-02-08 19:38:26 UTC (rev 95294)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Form.cs
2008-02-08 19:39:04 UTC (rev 95295)
@@ -189,21 +189,15 @@
[EditorBrowsable (EditorBrowsableState.Advanced)]
protected override Rectangle GetScaledBounds (Rectangle bounds,
SizeF factor, BoundsSpecified specified)
{
- // Never change the Form's location
- specified &= ~BoundsSpecified.Location;
+ if ((specified & BoundsSpecified.Width) ==
BoundsSpecified.Width) {
+ int border = Size.Width - ClientSize.Width;
+ bounds.Width = (int)Math.Round ((bounds.Width -
border) * factor.Width) + border;
+ }
+ if ((specified & BoundsSpecified.Height) ==
BoundsSpecified.Height) {
+ int border = Size.Height - ClientSize.Height;
+ bounds.Height = (int)Math.Round ((bounds.Height
- border) * factor.Height) + border;
+ }
- if ((specified & BoundsSpecified.Width) ==
BoundsSpecified.Width && !GetStyle (ControlStyles.FixedWidth))
- bounds.Width = (int)Math.Round (bounds.Width *
factor.Width);
- if ((specified & BoundsSpecified.Height) ==
BoundsSpecified.Height && !GetStyle (ControlStyles.FixedHeight))
- bounds.Height = (int)Math.Round (bounds.Height
* factor.Height);
-
- Size size = ClientSizeFromSize (bounds.Size);
-
- if ((specified & BoundsSpecified.Width) ==
BoundsSpecified.Width && !GetStyle (ControlStyles.FixedWidth))
- bounds.Width -= (int)((bounds.Width -
size.Width) * (factor.Width - 1));
- if ((specified & BoundsSpecified.Height) ==
BoundsSpecified.Height && !GetStyle (ControlStyles.FixedHeight))
- bounds.Height -= (int)((bounds.Height -
size.Height) * (factor.Height - 1));
-
return bounds;
}
@@ -215,9 +209,7 @@
[EditorBrowsable (EditorBrowsableState.Advanced)]
protected override void ScaleControl (SizeF factor,
BoundsSpecified specified)
{
- Rectangle new_bounds = GetScaledBounds (bounds, factor,
specified);
-
- SetBounds (new_bounds.X, new_bounds.Y,
new_bounds.Width, new_bounds.Height, specified);
+ base.ScaleControl (factor, specified);
}
#endif
@@ -513,12 +505,12 @@
}
set {
- autoscale = value;
-
#if NET_2_0
- if (value && AutoScaleMode !=
AutoScaleMode.None)
+ if (value)
AutoScaleMode = AutoScaleMode.None;
#endif
+
+ autoscale = value;
}
}
@@ -1825,19 +1817,19 @@
//
http://blogs.msdn.com/mharsh/archive/2004/01/25/62621.aspx
// but it makes things larger without looking better.
//
- if (current_size_f.Width != AutoScaleBaseSize.Width) {
- dx = current_size_f.Width /
AutoScaleBaseSize.Width + 0.08f;
+ if (current_size.Width != AutoScaleBaseSize.Width) {
+ dx = (float)current_size.Width /
AutoScaleBaseSize.Width + 0.08f;
} else {
dx = 1;
}
- if (current_size_f.Height != AutoScaleBaseSize.Height) {
- dy = current_size_f.Height /
AutoScaleBaseSize.Height + 0.08f;
+ if (current_size.Height != AutoScaleBaseSize.Height) {
+ dy = (float)current_size.Height /
AutoScaleBaseSize.Height + 0.08f;
} else {
dy = 1;
}
- Scale (new SizeF (dx, dy));
+ Scale (dx, dy);
AutoScaleBaseSize = current_size;
}
@@ -2262,42 +2254,13 @@
}
#if NET_2_0
- [EditorBrowsable(EditorBrowsableState.Never)]
+ [EditorBrowsable (EditorBrowsableState.Never)]
#else
- [EditorBrowsable(EditorBrowsableState.Advanced)]
+ [EditorBrowsable (EditorBrowsableState.Advanced)]
#endif
- protected override void ScaleCore(float dx, float dy) {
- try {
- SuspendLayout();
-
- // We can't scale max or min windows
- if (WindowState == FormWindowState.Normal) {
- // We cannot call base since base also
adjusts X/Y, but
- // a form is toplevel and doesn't move
- Size size;
-
- size = ClientSize;
- if
(!GetStyle(ControlStyles.FixedWidth)) {
- size.Width = (int)(size.Width *
dx);
- }
-
- if
(!GetStyle(ControlStyles.FixedHeight)) {
- size.Height = (int)(size.Height
* dy);
- }
-
- ClientSize = size;
- }
-
- /* Now scale our children */
- Control [] controls = Controls.GetAllControls
();
- for (int i=0; i < controls.Length; i++) {
- controls[i].Scale (new SizeF (dx, dy));
- }
- }
-
- finally {
- ResumeLayout();
- }
+ protected override void ScaleCore (float dx, float dy)
+ {
+ base.ScaleCore (dx, dy);
}
protected override void Select(bool directed, bool forward) {
Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ListBox.cs
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ListBox.cs
2008-02-08 19:38:26 UTC (rev 95294)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ListBox.cs
2008-02-08 19:39:04 UTC (rev 95295)
@@ -863,28 +863,9 @@
[EditorBrowsable (EditorBrowsableState.Advanced)]
protected override Rectangle GetScaledBounds (Rectangle bounds,
SizeF factor, BoundsSpecified specified)
{
- // For some reason, it always uses the control's Height
instead of
- // the Height passed in
- bounds.Height = this.bounds.Height;
+ bounds.Height = requested_height;
- if ((specified & BoundsSpecified.X) ==
BoundsSpecified.X)
- bounds.X = (int)Math.Round (bounds.Left *
factor.Width);
- if ((specified & BoundsSpecified.Y) ==
BoundsSpecified.Y)
- bounds.Y = (int)Math.Round (bounds.Top *
factor.Height);
-
- if ((specified & BoundsSpecified.Width) ==
BoundsSpecified.Width && !GetStyle (ControlStyles.FixedWidth))
- bounds.Width = (int)Math.Round (bounds.Width *
factor.Width);
- if ((specified & BoundsSpecified.Height) ==
BoundsSpecified.Height && !GetStyle (ControlStyles.FixedHeight))
- bounds.Height = (int)Math.Round (bounds.Height
* factor.Height);
-
- Size size = ClientSizeFromSize (bounds.Size);
-
- if ((specified & BoundsSpecified.Width) ==
BoundsSpecified.Width && !GetStyle (ControlStyles.FixedWidth))
- bounds.Width -= (int)((bounds.Width -
size.Width) * (factor.Width - 1));
- if ((specified & BoundsSpecified.Height) ==
BoundsSpecified.Height && !GetStyle (ControlStyles.FixedHeight))
- bounds.Height -= (int)((bounds.Height -
size.Height) * (factor.Height - 1));
-
- return bounds;
+ return base.GetScaledBounds (bounds, factor, specified);
}
#endif
@@ -1069,9 +1050,7 @@
protected override void ScaleControl (SizeF factor,
BoundsSpecified specified)
{
- Rectangle new_bounds = GetScaledBounds (new Rectangle
(Location, new Size (Width, Height)), factor, specified);
-
- SetBounds (new_bounds.X, new_bounds.Y,
new_bounds.Width, new_bounds.Height, specified);
+ base.ScaleControl (factor, specified);
}
#endif
@@ -2827,3 +2806,4 @@
}
+
Modified:
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ListControl.cs
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ListControl.cs
2008-02-08 19:38:26 UTC (rev 95294)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ListControl.cs
2008-02-08 19:39:04 UTC (rev 95295)
@@ -278,6 +278,14 @@
#endregion Public Properties
+ #region Private Properties
+
+ internal override bool ScaleChildrenInternal {
+ get { return false; }
+ }
+
+ #endregion Private Properties
+
#region Public Methods
protected object FilterItemOnProperty (object item)
Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ListView.cs
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ListView.cs
2008-02-08 19:38:26 UTC (rev 95294)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ListView.cs
2008-02-08 19:39:04 UTC (rev 95295)
@@ -385,6 +385,10 @@
}
}
+ internal override bool ScaleChildrenInternal {
+ get { return false; }
+ }
+
#endregion // Private Internal Properties
#region Protected Properties
Modified:
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/TextBoxBase.cs
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/TextBoxBase.cs
2008-02-08 19:38:26 UTC (rev 95294)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/TextBoxBase.cs
2008-02-08 19:39:04 UTC (rev 95295)
@@ -1712,6 +1712,10 @@
}
}
+ internal override bool ScaleChildrenInternal {
+ get { return false; }
+ }
+
internal bool ShowSelection {
get {
if (show_selection || !hide_selection) {
Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/TreeView.cs
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/TreeView.cs
2008-02-08 19:38:26 UTC (rev 95294)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/TreeView.cs
2008-02-08 19:39:04 UTC (rev 95295)
@@ -1176,6 +1176,10 @@
#endregion // Protected Instance Methods
#region Internal & Private Methods and Properties
+ internal override bool ScaleChildrenInternal {
+ get { return false; }
+ }
+
internal IntPtr CreateNodeHandle ()
{
return (IntPtr) handle_count++;
@@ -2484,3 +2488,4 @@
}
}
+
Modified:
trunk/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ChangeLog
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ChangeLog
2008-02-08 19:38:26 UTC (rev 95294)
+++ trunk/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ChangeLog
2008-02-08 19:39:04 UTC (rev 95295)
@@ -1,3 +1,8 @@
+2008-02-08 Jonathan Pobst <[EMAIL PROTECTED]>
+
+ * FormTest.cs: Commit tests from James Purcell for his new
+ AutoScale implementation. [Bug #359098]
+
2008-02-07 Jonathan Pobst <[EMAIL PROTECTED]>
* MdiFormTest.cs: Add test for bug #336296.
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-02-08 19:38:26 UTC (rev 95294)
+++ trunk/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/FormTest.cs
2008-02-08 19:39:04 UTC (rev 95295)
@@ -2822,6 +2822,45 @@
Assert.AreEqual (false, f.AutoScale, "A3");
}
#endif
+
+ [Test] // Bug #359098
+ public void AutoScaleBounds ()
+ {
+ AutoScaleForm a = new AutoScaleForm (false);
+ a.Show ();
+ Assert.AreEqual (new Size (213, 121), a.ClientSize,
"A0");
+ Assert.AreEqual (new Rectangle ( 5, 107, 132, 9), new
Rectangle (a.hScrollBar1.Location, a.hScrollBar1.Size), "A1");
+ Assert.AreEqual (new Rectangle (151, 74, 60, 44), new
Rectangle (a.treeView1.Location, a.treeView1.Size), "A2");
+ Assert.AreEqual (new Rectangle (197, 21, 9, 39), new
Rectangle (a.vScrollBar1.Location, a.vScrollBar1.Size), "A3");
+ Assert.AreEqual (new Rectangle (139, 21, 54, 49), new
Rectangle (a.listView1.Location, a.listView1.Size), "A4");
+ Assert.AreEqual (new Rectangle ( 70, 5, 65, 37), new
Rectangle (a.textBox2.Location, a.textBox2.Size), "A5");
+ Assert.AreEqual (new Rectangle (139, 5, 70, 0), new
Rectangle (a.comboBox1.Location, new Size (a.comboBox1.Width, 0)), "A6");
+ Assert.AreEqual (new Rectangle ( 5, 77, 43, 13), new
Rectangle (a.button2.Location, a.button2.Size), "A7");
+ Assert.AreEqual (new Rectangle ( 70, 44, 65, 37), new
Rectangle (a.richTextBox1.Location, a.richTextBox1.Size), "A8");
+ Assert.AreEqual (new Rectangle ( 53, 86, 21, 7), new
Rectangle (a.label1.Location,a.label1.Size), "A9");
+ Assert.AreEqual (new Rectangle ( 65, 84, 58, 0), new
Rectangle (a.textBox1.Location, new Size (a.textBox1.Width, 0)), "A10");
+ Assert.AreEqual (new Rectangle ( 5, 63, 43, 13), new
Rectangle (a.button1.Location, a.button1.Size), "A11");
+ Assert.AreEqual (new Rectangle ( 5, 5, 60, 47), new
Rectangle (a.listBox1.Location, a.listBox1.Size), "A12");
+ a.Dispose ();
+
+#if NET_2_0
+ a = new AutoScaleForm (true);
+ Assert.AreEqual (new Size (184, 104), a.ClientSize,
"B0");
+ Assert.AreEqual (new Rectangle ( 4, 92, 114, 16), new
Rectangle (a.hScrollBar1.Location, a.hScrollBar1.ClientSize), "B1");
+ Assert.AreEqual (new Rectangle (130, 64, 50, 36), new
Rectangle (a.treeView1.Location, a.treeView1.ClientSize), "B2");
+ Assert.AreEqual (new Rectangle (170, 18, 16, 34), new
Rectangle (a.vScrollBar1.Location, a.vScrollBar1.ClientSize), "B3");
+ Assert.AreEqual (new Rectangle (120, 18, 44, 40), new
Rectangle (a.listView1.Location, a.listView1.ClientSize), "B4");
+ Assert.AreEqual (new Rectangle ( 60, 4, 54, 30), new
Rectangle (a.textBox2.Location, a.textBox2.ClientSize), "B5");
+ Assert.AreEqual (new Rectangle (120, 4, 62, 0), new
Rectangle (a.comboBox1.Location, new Size (a.comboBox1.ClientSize.Width, 0)),
"B6");
+ Assert.AreEqual (new Rectangle ( 4, 66, 38, 12), new
Rectangle (a.button2.Location, a.button2.ClientSize), "B7");
+ Assert.AreEqual (new Rectangle ( 60, 38, 54, 30), new
Rectangle (a.richTextBox1.Location, a.richTextBox1.ClientSize), "B8");
+ Assert.AreEqual (new Rectangle ( 46, 74, 18, 6), new
Rectangle (a.label1.Location,a.label1.ClientSize), "B9");
+ Assert.AreEqual (new Rectangle ( 56, 72, 48, 0), new
Rectangle (a.textBox1.Location, new Size (a.textBox1.ClientSize.Width, 0)),
"B10");
+ Assert.AreEqual (new Rectangle ( 4, 54, 38, 12), new
Rectangle (a.button1.Location, a.button1.ClientSize), "B11");
+ Assert.AreEqual (new Rectangle ( 4, 4, 50, 39), new
Rectangle (a.listBox1.Location, a.listBox1.ClientSize), "B12");
+ a.Dispose ();
+#endif
+ }
}
public class TimeBombedForm : Form
@@ -2852,4 +2891,61 @@
}
}
}
+
+ public class AutoScaleForm : Form
+ {
+ public ListBox listBox1 = new ListBox ();
+ public ComboBox comboBox1 = new ComboBox ();
+ public Button button1 = new Button ();
+ public Button button2 = new Button ();
+ public Label label1 = new Label ();
+ public TextBox textBox1 = new TextBox ();
+ public TextBox textBox2 = new TextBox ();
+ public RichTextBox richTextBox1 = new RichTextBox ();
+ public ListView listView1 = new ListView ();
+ public TreeView treeView1 = new TreeView ();
+ public VScrollBar vScrollBar1 = new VScrollBar ();
+ public HScrollBar hScrollBar1 = new HScrollBar ();
+
+ public AutoScaleForm (bool use_new_auto_scale)
+ {
+ SuspendLayout ();
+
+ listBox1.IntegralHeight = false;
+ listBox1.SetBounds (8, 8, 104, 82);
+ comboBox1.SetBounds (240, 8, 121, 21);
+ button1.SetBounds (8, 108, 75, 23);
+ button2.SetBounds (8, 132, 75, 23);
+ label1.SetBounds (92, 148, 35, 13);
+ textBox1.SetBounds (112, 144, 100, 20);
+ textBox2.Multiline = true;
+ textBox2.SetBounds (120, 8, 112, 64);
+ richTextBox1.SetBounds (120, 76, 112, 64);
+ listView1.SetBounds (240, 36, 92, 84);
+ treeView1.SetBounds (260, 128, 104, 76);
+ vScrollBar1.SetBounds (340, 36, 16, 68);
+ hScrollBar1.SetBounds (8, 184, 228, 16);
+
+ ClientSize = new Size (368, 209);
+
+ Controls.AddRange ( new Control [] { listBox1,
comboBox1, button1, button2, label1, textBox1,
+ textBox2, richTextBox1, listView1, treeView1,
vScrollBar1, hScrollBar1 } );
+
+ if (use_new_auto_scale) {
+#if NET_2_0
+ AutoScaleMode = AutoScaleMode.Font;
+ SizeF s = CurrentAutoScaleDimensions;
+ AutoScaleDimensions = new SizeF (s.Width * 2,
s.Height * 2);
+#endif
+ }
+ else {
+ AutoScale = true;
+ SizeF s = Form.GetAutoScaleSize (Font);
+ AutoScaleBaseSize = new Size ((int)Math.Round
(s.Width) * 2, (int)s.Height * 2);
+ }
+
+ ResumeLayout (false);
+ PerformLayout ();
+ }
+ }
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches