Skip to content

Commit e55c406

Browse files
authored
Merge branch 'eclipse-platform:master' into master
2 parents 495a557 + 2853d53 commit e55c406

File tree

8 files changed

+68
-18
lines changed

8 files changed

+68
-18
lines changed

bundles/org.eclipse.swt/Eclipse SWT Tests/win32/org/eclipse/swt/widgets/ControlWin32Tests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,11 @@ public void testCorrectScaleUpUsingDifferentSetBoundsMethod() {
100100

101101
button.setBounds(new Rectangle(0, 47, 200, 47));
102102
assertEquals("Control::setBounds(Rectangle) doesn't scale up correctly",
103-
new Rectangle(0, 82, 350, 82), button.getBoundsInPixels());
103+
new Rectangle(0, 82, 350, 83), button.getBoundsInPixels());
104104

105105
button.setBounds(0, 47, 200, 47);
106106
assertEquals("Control::setBounds(int, int, int, int) doesn't scale up correctly",
107-
new Rectangle(0, 82, 350, 82), button.getBoundsInPixels());
107+
new Rectangle(0, 82, 350, 83), button.getBoundsInPixels());
108108
}
109109

110110
record FontComparison(int originalFontHeight, int currentFontHeight) {

bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Image.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1353,7 +1353,7 @@ public ImageData getImageData() {
13531353
* multiple monitors with different DPIs, hence deprecated. Use
13541354
* {@link #getImageData(int)} instead.
13551355
*/
1356-
@Deprecated
1356+
@Deprecated(since = "2025-09", forRemoval = true)
13571357
public ImageData getImageDataAtCurrentZoom() {
13581358
return getImageData(DPIUtil.getDeviceZoom());
13591359
}

bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1064,7 +1064,7 @@ public ImageData getImageData () {
10641064
* multiple monitors with different DPIs, hence deprecated. Use
10651065
* {@link #getImageData(int)} instead.
10661066
*/
1067-
@Deprecated
1067+
@Deprecated(since = "2025-09", forRemoval = true)
10681068
public ImageData getImageDataAtCurrentZoom () {
10691069
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
10701070

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1243,7 +1243,7 @@ public ImageData getImageData (int zoom) {
12431243
* multiple monitors with different DPIs, hence deprecated. Use
12441244
* {@link #getImageData(int)} instead.
12451245
*/
1246-
@Deprecated
1246+
@Deprecated(since = "2025-09", forRemoval = true)
12471247
public ImageData getImageDataAtCurrentZoom() {
12481248
return applyUsingAnyHandle(ImageHandle::getImageData);
12491249
}

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,20 @@ public static Point pixelToPoint(Drawable drawable, Point point, int zoom) {
108108
}
109109

110110
public static Rectangle pixelToPoint(Rectangle rect, int zoom) {
111+
if (zoom == 100 || rect == null) return rect;
112+
if (rect instanceof Rectangle.OfFloat rectOfFloat) return pixelToPoint(rectOfFloat, zoom);
113+
Rectangle scaledRect = new Rectangle.OfFloat (0,0,0,0);
114+
Point scaledTopLeft = pixelToPoint(new Point (rect.x, rect.y), zoom);
115+
Point scaledBottomRight = pixelToPoint(new Point (rect.x + rect.width, rect.y + rect.height), zoom);
116+
117+
scaledRect.x = scaledTopLeft.x;
118+
scaledRect.y = scaledTopLeft.y;
119+
scaledRect.width = scaledBottomRight.x - scaledTopLeft.x;
120+
scaledRect.height = scaledBottomRight.y - scaledTopLeft.y;
121+
return scaledRect;
122+
}
123+
124+
private static Rectangle pixelToPoint(Rectangle.OfFloat rect, int zoom) {
111125
return scaleBounds(rect, 100, zoom);
112126
}
113127

@@ -120,6 +134,21 @@ public static Rectangle pixelToPoint(Drawable drawable, Rectangle rect, int zoom
120134
* Returns a new rectangle as per the scaleFactor.
121135
*/
122136
public static Rectangle scaleBounds (Rectangle rect, int targetZoom, int currentZoom) {
137+
if (rect == null || targetZoom == currentZoom) return rect;
138+
if (rect instanceof Rectangle.OfFloat rectOfFloat) return scaleBounds(rectOfFloat, targetZoom, currentZoom);
139+
float scaleFactor = ((float)targetZoom) / (float)currentZoom;
140+
Rectangle returnRect = new Rectangle.OfFloat (0,0,0,0);
141+
returnRect.x = Math.round (rect.x * scaleFactor);
142+
returnRect.y = Math.round (rect.y * scaleFactor);
143+
returnRect.width = Math.round (rect.width * scaleFactor);
144+
returnRect.height = Math.round (rect.height * scaleFactor);
145+
return returnRect;
146+
}
147+
148+
/**
149+
* Returns a new rectangle as per the scaleFactor.
150+
*/
151+
private static Rectangle scaleBounds (Rectangle.OfFloat rect, int targetZoom, int currentZoom) {
123152
if (rect == null || targetZoom == currentZoom) return rect;
124153
Rectangle.OfFloat fRect = FloatAwareGeometryFactory.createFrom(rect);
125154
float scaleFactor = DPIUtil.getScalingFactor(targetZoom, currentZoom);
@@ -185,6 +214,20 @@ public static Point pointToPixel(Drawable drawable, Point point, int zoom) {
185214
}
186215

187216
public static Rectangle pointToPixel(Rectangle rect, int zoom) {
217+
if (zoom == 100 || rect == null) return rect;
218+
if (rect instanceof Rectangle.OfFloat rectOfFloat) return pointToPixel(rectOfFloat, zoom);
219+
Rectangle scaledRect = new Rectangle.OfFloat(0,0,0,0);
220+
Point scaledTopLeft = pointToPixel (new Point(rect.x, rect.y), zoom);
221+
Point scaledBottomRight = pointToPixel (new Point(rect.x + rect.width, rect.y + rect.height), zoom);
222+
223+
scaledRect.x = scaledTopLeft.x;
224+
scaledRect.y = scaledTopLeft.y;
225+
scaledRect.width = scaledBottomRight.x - scaledTopLeft.x;
226+
scaledRect.height = scaledBottomRight.y - scaledTopLeft.y;
227+
return scaledRect;
228+
}
229+
230+
private static Rectangle pointToPixel(Rectangle.OfFloat rect, int zoom) {
188231
return scaleBounds(rect, zoom, 100);
189232
}
190233

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

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7188,23 +7188,21 @@ private LRESULT positionTooltip(NMHDR hdr, long lParam) {
71887188
if (newFont != 0) oldFont = OS.SelectObject (hDC, newFont);
71897189
long hFont = item.fontHandle (pinfo.iSubItem);
71907190
if (hFont != -1) hFont = OS.SelectObject (hDC, hFont);
7191-
Event event = sendMeasureItemEvent (item, pinfo.iItem, pinfo.iSubItem, hDC);
7192-
if (!isDisposed () && !item.isDisposed ()) {
7193-
RECT itemRect = new RECT ();
7194-
Rectangle boundsInPixels = Win32DPIUtils.pointToPixel(event.getBounds(), getZoom());
7195-
OS.SetRect (itemRect, boundsInPixels.x, boundsInPixels.y, boundsInPixels.x + boundsInPixels.width, boundsInPixels.y + boundsInPixels.height);
7191+
if (!isDisposed() && !item.isDisposed()) {
71967192
if (hdr.code == OS.TTN_SHOW) {
7197-
RECT toolRect = isCustomToolTip() ? toolTipRect (itemRect) : itemRect;
7198-
OS.MapWindowPoints (handle, 0, toolRect, 2);
7199-
long hwndToolTip = OS.SendMessage (handle, OS.LVM_GETTOOLTIPS, 0, 0);
7193+
RECT itemRect = getItemBounds(pinfo, item, hDC);
7194+
RECT toolRect = isCustomToolTip() ? toolTipRect(itemRect) : itemRect;
7195+
OS.MapWindowPoints(handle, 0, toolRect, 2);
7196+
long hwndToolTip = OS.SendMessage(handle, OS.LVM_GETTOOLTIPS, 0, 0);
72007197
int flags = OS.SWP_NOACTIVATE | OS.SWP_NOZORDER;
72017198
Rectangle adjustedTooltipBounds = getDisplay().fitRectangleBoundsIntoMonitorWithCursor(toolRect);
72027199
OS.SetWindowPos(hwndToolTip, 0, adjustedTooltipBounds.x, adjustedTooltipBounds.y,
72037200
adjustedTooltipBounds.width, adjustedTooltipBounds.height, flags);
72047201
result = LRESULT.ONE;
72057202
} else if (isCustomToolTip()) {
7206-
NMTTDISPINFO lpnmtdi = new NMTTDISPINFO ();
7207-
OS.MoveMemory (lpnmtdi, lParam, NMTTDISPINFO.sizeof);
7203+
RECT itemRect = getItemBounds(pinfo, item, hDC);
7204+
NMTTDISPINFO lpnmtdi = new NMTTDISPINFO();
7205+
OS.MoveMemory(lpnmtdi, lParam, NMTTDISPINFO.sizeof);
72087206
if (lpnmtdi.lpszText != 0) {
72097207
OS.MoveMemory (lpnmtdi.lpszText, new char [1], 2);
72107208
OS.MoveMemory (lParam, lpnmtdi, NMTTDISPINFO.sizeof);
@@ -7231,6 +7229,15 @@ private LRESULT positionTooltip(NMHDR hdr, long lParam) {
72317229
return result;
72327230
}
72337231

7232+
private RECT getItemBounds(LVHITTESTINFO pinfo, TableItem item, long hDC) {
7233+
Event event = sendMeasureItemEvent(item, pinfo.iItem, pinfo.iSubItem, hDC);
7234+
RECT itemRect = new RECT();
7235+
Rectangle boundsInPixels = Win32DPIUtils.pointToPixel(event.getBounds(), getZoom());
7236+
OS.SetRect(itemRect, boundsInPixels.x, boundsInPixels.y, boundsInPixels.x + boundsInPixels.width,
7237+
boundsInPixels.y + boundsInPixels.height);
7238+
return itemRect;
7239+
}
7240+
72347241
LRESULT wmNotifyToolTip (NMTTCUSTOMDRAW nmcd, long lParam) {
72357242
switch (nmcd.dwDrawStage) {
72367243
case OS.CDDS_PREPAINT: {

tests/org.eclipse.swt.tests.win32/JUnit Tests/org/eclipse/swt/tests/win32/Win32DPIUtilTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ public void scaleUpPoint() {
202202
@Test
203203
public void scaleUpRectangle() {
204204
Rectangle valueAt200 = new Rectangle(100, 150, 10, 14);
205-
Rectangle valueAt150 = new Rectangle(75, 113, 8, 11);
205+
Rectangle valueAt150 = new Rectangle(75, 113, 8, 10);
206206
Rectangle valueAt100 = new Rectangle(50, 75, 5, 7);
207207

208208
Rectangle scaledValue = Win32DPIUtils.pointToPixel(valueAt100, 200);
@@ -225,7 +225,7 @@ public void scaleDownscaleUpRectangleInvertible() {
225225
for (int zoom1 : zooms) {
226226
for (int zoom2 : zooms) {
227227
for (int i = 1; i <= 10000; i++) {
228-
Rectangle rect = new Rectangle(0, 0, i, i);
228+
Rectangle rect = new Rectangle.OfFloat(0, 0, i, i);
229229
Rectangle scaleDown = Win32DPIUtils.pixelToPoint(rect, zoom1);
230230
Rectangle scaleUp = Win32DPIUtils.pointToPixel(scaleDown, zoom2);
231231
scaleDown = Win32DPIUtils.pixelToPoint(scaleUp, zoom2);

tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_Image.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ public void test_getBoundsInPixels() {
634634
assertEquals("Image.getBoundsInPixels method doesn't return bounds in Pixel values for ImageGcDrawer.", initialBounds, boundsInPixels);
635635
}
636636

637-
@SuppressWarnings("deprecation")
637+
@SuppressWarnings("removal")
638638
@Test
639639
public void test_getImageDataCurrentZoom() {
640640
Rectangle bounds = new Rectangle(0, 0, 10, 20);

0 commit comments

Comments
 (0)