Skip to content

Commit 4a58a39

Browse files
HeikoKlareakoch-yatta
authored andcommitted
[Win32] Adapt further places to round up when computing control size
Several places in the computations of preferred sizes of controls used commercial rounding instead of rounding up in pixel/point calculations. This change further adapts additional places to ensure that the calculated size will be large enough and and subsequent point-to-pixel calculation when setting the bounds according the computations does not lead to smaller results.
1 parent 9119357 commit 4a58a39

File tree

24 files changed

+56
-38
lines changed

24 files changed

+56
-38
lines changed

bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Rectangle.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ public OfFloat(float x, float y, float width, float height) {
426426
this(x, y, width, height, RoundingMode.ROUND, RoundingMode.ROUND);
427427
}
428428

429-
private OfFloat(float x, float y, float width, float height, RoundingMode locationRounding, RoundingMode sizeRounding) {
429+
public OfFloat(float x, float y, float width, float height, RoundingMode locationRounding, RoundingMode sizeRounding) {
430430
this.locationRounding = locationRounding;
431431
this.sizeRounding = sizeRounding;
432432
setX(x);

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/GC.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ private class CopyAreaOperation extends Operation {
613613
@Override
614614
void apply() {
615615
int zoom = getZoom();
616-
Rectangle sourceRect = Win32DPIUtils.pointToPixel(drawable, source, zoom);
616+
Rectangle sourceRect = Win32DPIUtils.pointToPixelWithSufficientlyLargeSize(source, zoom);
617617
Rectangle destRect = Win32DPIUtils.pointToPixel(drawable, destination, zoom);
618618
copyAreaInPixels(sourceRect.x, sourceRect.y, sourceRect.width, sourceRect.height, destRect.x, destRect.y, paint);
619619
}

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/Win32DPIUtils.java

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public static Point pixelToPointAsLocation(Point point, int zoom) {
131131
return pixelToPoint(point, zoom, RoundingMode.ROUND);
132132
}
133133

134-
public static Point pixelToPointAsConservativeSize(Point point, int zoom) {
134+
public static Point pixelToPointAsSufficientlyLargeSize(Point point, int zoom) {
135135
return pixelToPoint(point, zoom, RoundingMode.UP);
136136
}
137137

@@ -150,16 +150,23 @@ private static Point.OfFloat pixelToPoint(Point.OfFloat point, int zoom) {
150150
}
151151

152152
public static Rectangle pixelToPoint(Rectangle rect, int zoom) {
153+
return pixelToPoint(rect, zoom, RoundingMode.ROUND);
154+
}
155+
156+
public static Rectangle pixelToPointWithSufficientlyLargeSize(Rectangle rect, int zoom) {
157+
return pixelToPoint(rect, zoom, RoundingMode.UP);
158+
}
159+
160+
private static Rectangle pixelToPoint(Rectangle rect, int zoom, RoundingMode sizeRounding) {
153161
if (zoom == 100 || rect == null) return rect;
154162
Rectangle.OfFloat floatRect = Rectangle.OfFloat.from(rect);
155163
Point.OfFloat scaledTopLeft = pixelToPoint(floatRect.getTopLeft(), zoom);
156164
Point.OfFloat scaledBottomRight = pixelToPoint(floatRect.getBottomRight(), zoom);
157-
Rectangle.OfFloat scaledRect = floatRect.clone();
158-
scaledRect.setX(scaledTopLeft.getX());
159-
scaledRect.setY(scaledTopLeft.getY());
160-
scaledRect.setWidth(scaledBottomRight.getX() - scaledTopLeft.getX());
161-
scaledRect.setHeight(scaledBottomRight.getY() - scaledTopLeft.getY());
162-
return scaledRect;
165+
float scaledX = scaledTopLeft.getX();
166+
float scaleyY = scaledTopLeft.getY();
167+
float scaledWidth = scaledBottomRight.getX() - scaledTopLeft.getX();
168+
float scaledHeight = scaledBottomRight.getY() - scaledTopLeft.getY();
169+
return new Rectangle.OfFloat(scaledX, scaleyY, scaledWidth, scaledHeight, RoundingMode.ROUND, sizeRounding);
163170
}
164171

165172
public static Rectangle pixelToPoint(Drawable drawable, Rectangle rect, int zoom) {
@@ -252,6 +259,10 @@ public static Point pointToPixelAsLocation(Drawable drawable, Point point, int z
252259
}
253260

254261
public static Point pointToPixelAsSize(Point point, int zoom) {
262+
return pointToPixel(point, zoom, RoundingMode.ROUND);
263+
}
264+
265+
public static Point pointToPixelAsSufficientlyLargeSize(Point point, int zoom) {
255266
return pointToPixel(point, zoom, RoundingMode.UP);
256267
}
257268

@@ -260,16 +271,23 @@ public static Point pointToPixelAsLocation(Point point, int zoom) {
260271
}
261272

262273
public static Rectangle pointToPixel(Rectangle rect, int zoom) {
274+
return pointToPixel(rect, zoom, RoundingMode.ROUND);
275+
}
276+
277+
public static Rectangle pointToPixelWithSufficientlyLargeSize(Rectangle rect, int zoom) {
278+
return pointToPixel(rect, zoom, RoundingMode.UP);
279+
}
280+
281+
private static Rectangle pointToPixel(Rectangle rect, int zoom, RoundingMode sizeRounding) {
263282
if (zoom == 100 || rect == null) return rect;
264283
Rectangle.OfFloat floatRect = Rectangle.OfFloat.from(rect);
265284
Point.OfFloat scaledTopLeft = pointToPixel(floatRect.getTopLeft(), zoom);
266285
Point.OfFloat scaledBottomRight = pointToPixel(floatRect.getBottomRight(), zoom);
267-
Rectangle.OfFloat scaledRect = floatRect.clone();
268-
scaledRect.setX(scaledTopLeft.getX());
269-
scaledRect.setY(scaledTopLeft.getY());
270-
scaledRect.setWidth(scaledBottomRight.getX() - scaledTopLeft.getX());
271-
scaledRect.setHeight(scaledBottomRight.getY() - scaledTopLeft.getY());
272-
return scaledRect;
286+
float scaledX = scaledTopLeft.getX();
287+
float scaleyY = scaledTopLeft.getY();
288+
float scaledWidth = scaledBottomRight.getX() - scaledTopLeft.getX();
289+
float scaledHeight = scaledBottomRight.getY() - scaledTopLeft.getY();
290+
return new Rectangle.OfFloat(scaledX, scaleyY, scaledWidth, scaledHeight, RoundingMode.ROUND, sizeRounding);
273291
}
274292

275293
public static Rectangle pointToPixel(Drawable drawable, Rectangle rect, int zoom) {

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Button.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ else if ((style & SWT.RIGHT) != 0) {
326326
Point computeSizeInPixels (Point hintInPoints, boolean changed) {
327327
checkWidget ();
328328
int zoom = getZoom();
329-
Point hintInPixels = Win32DPIUtils.pointToPixelAsSize(hintInPoints, zoom);
329+
Point hintInPixels = Win32DPIUtils.pointToPixelAsSufficientlyLargeSize(hintInPoints, zoom);
330330
int width = 0, height = 0, border = getBorderWidthInPixels ();
331331
if ((style & SWT.ARROW) != 0) {
332332
if ((style & (SWT.UP | SWT.DOWN)) != 0) {

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Combo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ public void clearSelection () {
596596
Point computeSizeInPixels (Point hintInPoints, boolean changed) {
597597
checkWidget ();
598598
int zoom = getZoom();
599-
Point hintInPixels = Win32DPIUtils.pointToPixelAsSize(hintInPoints, zoom);
599+
Point hintInPixels = Win32DPIUtils.pointToPixelAsSufficientlyLargeSize(hintInPoints, zoom);
600600
int width = 0, height = 0;
601601
if (hintInPoints.x == SWT.DEFAULT) {
602602
long newFont, oldFont = 0;

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Composite.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ Point computeSizeInPixels (Point hintInPoints, boolean changed) {
229229
* Since computeTrim can be overridden by subclasses, we cannot
230230
* call computeTrimInPixels directly.
231231
*/
232-
Rectangle trim = Win32DPIUtils.pointToPixel(computeTrim (0, 0, sizeInPoints.x, sizeInPoints.y), getZoom());
232+
Rectangle trim = Win32DPIUtils.pointToPixelWithSufficientlyLargeSize(computeTrim (0, 0, sizeInPoints.x, sizeInPoints.y), getZoom());
233233
return new Point (trim.width, trim.height);
234234
}
235235

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -621,14 +621,14 @@ public Point computeSize (int wHint, int hHint, boolean changed){
621621
int zoom = getZoom();
622622
//We should never return a size that is to small, RoundingMode.UP ensures we at worst case report
623623
//a size that is a bit too large by half a point
624-
return Win32DPIUtils.pixelToPointAsConservativeSize(computeSizeInPixels(new Point.OfFloat(wHint, hHint, RoundingMode.UP), changed), zoom);
624+
return Win32DPIUtils.pixelToPointAsSufficientlyLargeSize(computeSizeInPixels(new Point(wHint, hHint), changed), zoom);
625625
}
626626

627627
Point computeSizeInPixels (Point hintInPoints, boolean changed) {
628628
int width = DEFAULT_WIDTH;
629629
int height = DEFAULT_HEIGHT;
630630
int zoom = getZoom();
631-
Point hintInPixels = Win32DPIUtils.pointToPixelAsSize(hintInPoints, zoom);
631+
Point hintInPixels = Win32DPIUtils.pointToPixelAsSufficientlyLargeSize(hintInPoints, zoom);
632632
if (hintInPoints.x != SWT.DEFAULT) width = hintInPixels.x;
633633
if (hintInPoints.y != SWT.DEFAULT) height = hintInPixels.y;
634634
int border = getBorderWidthInPixels ();

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/CoolBar.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ protected void checkSubclass () {
143143
@Override
144144
Point computeSizeInPixels (Point hintInPoints, boolean changed) {
145145
int zoom = getZoom();
146-
Point hintInPixels = Win32DPIUtils.pointToPixelAsSize(hintInPoints, zoom);
146+
Point hintInPixels = Win32DPIUtils.pointToPixelAsSufficientlyLargeSize(hintInPoints, zoom);
147147
int width = 0, height = 0;
148148
int border = getBorderWidthInPixels ();
149149
int newWidth = hintInPoints.x == SWT.DEFAULT ? 0x3FFF : hintInPixels.x + (border * 2);

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/CoolItem.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ public Point computeSize (int wHint, int hHint) {
188188
int zoom = getZoom();
189189
wHint = (wHint != SWT.DEFAULT ? DPIUtil.pointToPixel(wHint, zoom) : wHint);
190190
hHint = (hHint != SWT.DEFAULT ? DPIUtil.pointToPixel(hHint, zoom) : hHint);
191-
return Win32DPIUtils.pixelToPointAsConservativeSize(computeSizeInPixels(wHint, hHint), zoom);
191+
return Win32DPIUtils.pixelToPointAsSufficientlyLargeSize(computeSizeInPixels(wHint, hHint), zoom);
192192
}
193193
Point computeSizeInPixels (int wHint, int hHint) {
194194
int index = parent.indexOf (this);

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/DateTime.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ protected void checkSubclass () {
222222
Point computeSizeInPixels (Point hintInPoints, boolean changed) {
223223
checkWidget ();
224224
int zoom = getZoom();
225-
Point hintInPixels = Win32DPIUtils.pointToPixelAsSize(hintInPoints, zoom);
225+
Point hintInPixels = Win32DPIUtils.pointToPixelAsSufficientlyLargeSize(hintInPoints, zoom);
226226
int width = 0, height = 0;
227227
if (hintInPoints.x == SWT.DEFAULT || hintInPoints.y == SWT.DEFAULT) {
228228
if ((style & SWT.CALENDAR) != 0) {

0 commit comments

Comments
 (0)