diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Point.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Point.java index b1a026ca92c..9bb910b7197 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Point.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Point.java @@ -158,6 +158,13 @@ public void setY(float y) { this.y = Math.round(y); this.residualY = y - this.y; } + + public static Point.OfFloat from(Point point) { + if (point instanceof Point.OfFloat pointOfFloat) { + return new Point.OfFloat(pointOfFloat.getX(), pointOfFloat.getY()); + } + return new Point.OfFloat(point.x, point.y); + } } /** diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/GridData.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/GridData.java index 3ecff268ff1..a52c8d60d59 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/GridData.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/GridData.java @@ -398,9 +398,11 @@ public final class GridData { */ public static final int FILL_BOTH = FILL_VERTICAL | FILL_HORIZONTAL; - int cacheWidth = -1, cacheHeight = -1; - int defaultWhint, defaultHhint, defaultWidth = -1, defaultHeight = -1; - int currentWhint, currentHhint, currentWidth = -1, currentHeight = -1; + Point.OfFloat cacheSize = new Point.OfFloat(SWT.DEFAULT, SWT.DEFAULT); + Point.OfFloat defaultHint = new Point.OfFloat(SWT.DEFAULT, SWT.DEFAULT); + Point.OfFloat defaultSize = new Point.OfFloat(SWT.DEFAULT, SWT.DEFAULT); + Point.OfFloat currentHint = new Point.OfFloat(SWT.DEFAULT, SWT.DEFAULT); + Point.OfFloat currentSize = new Point.OfFloat(SWT.DEFAULT, SWT.DEFAULT); /** * Constructs a new instance of GridData using @@ -487,34 +489,28 @@ public GridData (int width, int height) { } void computeSize (Control control, int wHint, int hHint, boolean flushCache) { - if (cacheWidth != -1 && cacheHeight != -1) return; + if (cacheSize.x != -1 && cacheSize.y != -1) return; if (wHint == this.widthHint && hHint == this.heightHint) { - if (defaultWidth == -1 || defaultHeight == -1 || wHint != defaultWhint || hHint != defaultHhint) { + if (defaultSize.x == -1 || defaultSize.y == -1 || wHint != defaultHint.x || hHint != defaultHint.y) { Point size = control.computeSize (wHint, hHint, flushCache); - defaultWhint = wHint; - defaultHhint = hHint; - defaultWidth = size.x; - defaultHeight = size.y; + defaultHint = new Point.OfFloat(wHint, hHint); + defaultSize = Point.OfFloat.from(size); } - cacheWidth = defaultWidth; - cacheHeight = defaultHeight; + cacheSize = Point.OfFloat.from(defaultSize); return; } - if (currentWidth == -1 || currentHeight == -1 || wHint != currentWhint || hHint != currentHhint) { + if (currentSize.x == -1 || currentSize.y == -1 || wHint != currentHint.x || hHint != currentHint.y) { Point size = control.computeSize (wHint, hHint, flushCache); - currentWhint = wHint; - currentHhint = hHint; - currentWidth = size.x; - currentHeight = size.y; + currentHint = new Point.OfFloat(wHint, hHint); + currentSize = Point.OfFloat.from(size); } - cacheWidth = currentWidth; - cacheHeight = currentHeight; + cacheSize = Point.OfFloat.from(currentSize); } void flushCache () { - cacheWidth = cacheHeight = -1; - defaultWidth = defaultHeight = -1; - currentWidth = currentHeight = -1; + cacheSize = new Point.OfFloat(-1, -1); + defaultSize = new Point.OfFloat(-1, -1); + currentSize = new Point.OfFloat(-1, -1); } String getName () { diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/GridLayout.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/GridLayout.java index d0bb2c6f422..05097361d9a 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/GridLayout.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/GridLayout.java @@ -224,7 +224,7 @@ Point layout (Composite composite, boolean move, int x, int y, int width, int he if (flushCache) data.flushCache (); data.computeSize (child, data.widthHint, data.heightHint, flushCache); if (data.grabExcessHorizontalSpace && data.minimumWidth > 0) { - if (data.cacheWidth < data.minimumWidth) { + if (data.cacheSize.getX() < data.minimumWidth) { int trim = 0; //TEMPORARY CODE if (child instanceof Scrollable) { @@ -233,12 +233,12 @@ Point layout (Composite composite, boolean move, int x, int y, int width, int he } else { trim = child.getBorderWidth () * 2; } - data.cacheWidth = data.cacheHeight = SWT.DEFAULT; + data.cacheSize = new Point.OfFloat(SWT.DEFAULT, SWT.DEFAULT); data.computeSize (child, Math.max (0, data.minimumWidth - trim), data.heightHint, false); } } if (data.grabExcessVerticalSpace && data.minimumHeight > 0) { - data.cacheHeight = Math.max (data.cacheHeight, data.minimumHeight); + data.cacheSize.setY(Math.max (data.cacheSize.getY(), data.minimumHeight)); } } @@ -292,8 +292,8 @@ Point layout (Composite composite, boolean move, int x, int y, int width, int he /* Column widths */ int availableWidth = width - horizontalSpacing * (columnCount - 1) - (marginLeft + marginWidth * 2 + marginRight); int expandCount = 0; - int [] widths = new int [columnCount]; - int [] minWidths = new int [columnCount]; + float [] widths = new float [columnCount]; + float [] minWidths = new float [columnCount]; boolean [] expandColumn = new boolean [columnCount]; for (int j=0; j 0) { if (makeColumnsEqualWidth) { - int equalWidth = (w + spanWidth) / hSpan; - int remainder = (w + spanWidth) % hSpan, last = -1; + float equalWidth = (w + spanWidth) / hSpan; + float remainder = (w + spanWidth) % hSpan; + int last = -1; for (int k = 0; k < hSpan; k++) { widths [last=j-k] = Math.max (equalWidth, widths [j-k]); } @@ -343,8 +344,9 @@ Point layout (Composite composite, boolean move, int x, int y, int width, int he if (spanExpandCount == 0) { widths [j] += w; } else { - int delta = w / spanExpandCount; - int remainder = w % spanExpandCount, last = -1; + float delta = w / spanExpandCount; + float remainder = w % spanExpandCount; + int last = -1; for (int k = 0; k < hSpan; k++) { if (expandColumn [j-k]) { widths [last=j-k] += delta; @@ -355,14 +357,15 @@ Point layout (Composite composite, boolean move, int x, int y, int width, int he } } if (!data.grabExcessHorizontalSpace || data.minimumWidth != 0) { - w = !data.grabExcessHorizontalSpace || data.minimumWidth == SWT.DEFAULT ? data.cacheWidth : data.minimumWidth; + w = !data.grabExcessHorizontalSpace || data.minimumWidth == SWT.DEFAULT ? data.cacheSize.getX() : data.minimumWidth; w += data.horizontalIndent - spanMinWidth - (hSpan - 1) * horizontalSpacing; if (w > 0) { if (spanExpandCount == 0) { minWidths [j] += w; } else { - int delta = w / spanExpandCount; - int remainder = w % spanExpandCount, last = -1; + float delta = w / spanExpandCount; + float remainder = w % spanExpandCount; + int last = -1; for (int k = 0; k < hSpan; k++) { if (expandColumn [j-k]) { minWidths [last=j-k] += delta; @@ -377,8 +380,8 @@ Point layout (Composite composite, boolean move, int x, int y, int width, int he } } if (makeColumnsEqualWidth) { - int minColumnWidth = 0; - int columnWidth = 0; + float minColumnWidth = 0; + float columnWidth = 0; for (int i=0; i 0) { if (spanExpandCount == 0) { widths [j] += w; } else { - int delta2 = w / spanExpandCount; - int remainder2 = w % spanExpandCount, last2 = -1; + float delta2 = w / spanExpandCount; + float remainder2 = w % spanExpandCount; + int last2 = -1; for (int k = 0; k < hSpan; k++) { if (expandColumn [j-k]) { widths [last2=j-k] += delta2; @@ -474,7 +478,7 @@ Point layout (Composite composite, boolean move, int x, int y, int width, int he currentWidth += widths [j-k]; } currentWidth += (hSpan - 1) * horizontalSpacing - data.horizontalIndent; - if ((currentWidth != data.cacheWidth && data.horizontalAlignment == SWT.FILL) || (data.cacheWidth > currentWidth)) { + if ((currentWidth != data.cacheSize.getX() && data.horizontalAlignment == SWT.FILL) || (data.cacheSize.getX() > currentWidth)) { int trim = 0; if (child instanceof Scrollable) { Rectangle rect = ((Scrollable) child).computeTrim (0, 0, 0, 0); @@ -482,10 +486,10 @@ Point layout (Composite composite, boolean move, int x, int y, int width, int he } else { trim = child.getBorderWidth () * 2; } - data.cacheWidth = data.cacheHeight = SWT.DEFAULT; + data.cacheSize = new Point.OfFloat(SWT.DEFAULT, SWT.DEFAULT); data.computeSize (child, Math.max (0, currentWidth - trim), data.heightHint, false); if (data.grabExcessVerticalSpace && data.minimumHeight > 0) { - data.cacheHeight = Math.max (data.cacheHeight, data.minimumHeight); + data.cacheSize.setY(Math.max (data.cacheSize.getY(), data.minimumHeight)); } if (flush == null) flush = new GridData [count]; flush [flushLength++] = data; @@ -499,8 +503,8 @@ Point layout (Composite composite, boolean move, int x, int y, int width, int he /* Row heights */ int availableHeight = height - verticalSpacing * (rowCount - 1) - (marginTop + marginHeight * 2 + marginBottom); expandCount = 0; - int [] heights = new int [rowCount]; - int [] minHeights = new int [rowCount]; + float [] heights = new float [rowCount]; + float [] minHeights = new float [rowCount]; boolean [] expandRow = new boolean [rowCount]; for (int i=0; i 0) { if (spanExpandCount == 0) { heights [i] += h; } else { - int delta = h / spanExpandCount; - int remainder = h % spanExpandCount, last = -1; + float delta = h / spanExpandCount; + float remainder = h % spanExpandCount; + int last = -1; for (int k = 0; k < vSpan; k++) { if (expandRow [i-k]) { heights [last=i-k] += delta; @@ -553,14 +558,15 @@ Point layout (Composite composite, boolean move, int x, int y, int width, int he } } if (!data.grabExcessVerticalSpace || data.minimumHeight != 0) { - h = !data.grabExcessVerticalSpace || data.minimumHeight == SWT.DEFAULT ? data.cacheHeight : data.minimumHeight; + h = !data.grabExcessVerticalSpace || data.minimumHeight == SWT.DEFAULT ? data.cacheSize.getY() : data.minimumHeight; h += data.verticalIndent - spanMinHeight - (vSpan - 1) * verticalSpacing; if (h > 0) { if (spanExpandCount == 0) { minHeights [i] += h; } else { - int delta = h / spanExpandCount; - int remainder = h % spanExpandCount, last = -1; + float delta = h / spanExpandCount; + float remainder = h % spanExpandCount; + int last = -1; for (int k = 0; k < vSpan; k++) { if (expandRow [i-k]) { minHeights [last=i-k] += delta; @@ -609,14 +615,15 @@ Point layout (Composite composite, boolean move, int x, int y, int width, int he spanHeight += heights [i-k]; if (expandRow [i-k]) spanExpandCount++; } - int h = !data.grabExcessVerticalSpace || data.minimumHeight == SWT.DEFAULT ? data.cacheHeight : data.minimumHeight; + float h = !data.grabExcessVerticalSpace || data.minimumHeight == SWT.DEFAULT ? data.cacheSize.getY() : data.minimumHeight; h += data.verticalIndent - spanHeight - (vSpan - 1) * verticalSpacing; if (h > 0) { if (spanExpandCount == 0) { heights [i] += h; } else { - int delta2 = h / spanExpandCount; - int remainder2 = h % spanExpandCount, last2 = -1; + float delta2 = h / spanExpandCount; + float remainder2 = h % spanExpandCount; + int last2 = -1; for (int k = 0; k < vSpan; k++) { if (expandRow [i-k]) { heights [last2=i-k] += delta2; @@ -660,7 +667,7 @@ Point layout (Composite composite, boolean move, int x, int y, int width, int he } cellWidth += horizontalSpacing * (hSpan - 1); int childX = gridX + data.horizontalIndent; - int childWidth = Math.min (data.cacheWidth, cellWidth); + float childWidth = Math.min (data.cacheSize.getX(), cellWidth); switch (data.horizontalAlignment) { case SWT.CENTER: case GridData.CENTER: @@ -677,7 +684,7 @@ Point layout (Composite composite, boolean move, int x, int y, int width, int he } cellHeight += verticalSpacing * (vSpan - 1); int childY = gridY + data.verticalIndent; - int childHeight = Math.min (data.cacheHeight, cellHeight); + float childHeight = Math.min (data.cacheSize.getY(), cellHeight); switch (data.verticalAlignment) { case SWT.CENTER: case GridData.CENTER: @@ -694,7 +701,7 @@ Point layout (Composite composite, boolean move, int x, int y, int width, int he } Control child = grid [i][j]; if (child != null) { - child.setBounds (childX, childY, childWidth, childHeight); + child.setBounds (new Rectangle.OfFloat(childX, childY, childWidth, childHeight)); } } gridX += widths [j] + horizontalSpacing; @@ -705,7 +712,7 @@ Point layout (Composite composite, boolean move, int x, int y, int width, int he // clean up cache for (int i = 0; i < flushLength; i++) { - flush [i].cacheWidth = flush [i].cacheHeight = -1; + flush [i].cacheSize = new Point.OfFloat(SWT.DEFAULT, SWT.DEFAULT); } int totalDefaultWidth = 0; diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Label.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Label.java index f23863896fb..d9c8dfb4c3d 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Label.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Label.java @@ -179,7 +179,7 @@ static int checkStyle (int style) { if (hHint != SWT.DEFAULT) height = hHint; width += border * 2; height += border * 2; - return new Point (width, height); + return new Point.OfFloat (width, height); } @Override