Skip to content

Commit 1143bb0

Browse files
Refactor: Move Win32-specific DPI logic to Win32DPIUtils
This commit introduces a dedicated Win32DPIUtils class to isolate Win32-specific DPI logic, improving platform separation and maintainability. Refactored moving with eclipse refactoring tool.
1 parent 115bd83 commit 1143bb0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+838
-798
lines changed

bundles/org.eclipse.swt/Eclipse SWT AWT/win32/org/eclipse/swt/awt/SWT_AWT.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ public static Frame new_Frame (final Composite parent) {
250250

251251
parent.getDisplay().asyncExec(() -> {
252252
if (parent.isDisposed()) return;
253-
final Rectangle clientArea = DPIUtil.scaleUp(parent.getClientArea(), DPIUtil.getZoomForAutoscaleProperty(parent.nativeZoom)); // To Pixels
253+
final Rectangle clientArea = Win32DPIUtils.scaleUp(parent.getClientArea(), DPIUtil.getZoomForAutoscaleProperty(parent.nativeZoom)); // To Pixels
254254
EventQueue.invokeLater(() -> {
255255
frame.setSize (clientArea.width, clientArea.height);
256256
frame.validate ();
@@ -286,15 +286,14 @@ public static Shell new_Shell (final Display display, final Canvas parent) {
286286
SWT.error (SWT.ERROR_NOT_IMPLEMENTED, e);
287287
}
288288
if (handle == 0) SWT.error (SWT.ERROR_INVALID_ARGUMENT, null, " [peer not created]");
289-
290289
final Shell shell = Shell.win32_new (display, handle);
291290
final ComponentListener listener = new ComponentAdapter () {
292291
@Override
293292
public void componentResized (ComponentEvent e) {
294293
display.syncExec (() -> {
295294
if (shell.isDisposed()) return;
296295
Dimension dim = parent.getSize ();
297-
shell.setSize(DPIUtil.scaleDown(new Point(dim.width, dim.height), DPIUtil.getDeviceZoom())); // To Points
296+
shell.setSize(Win32DPIUtils.scaleDown(new Point(dim.width, dim.height), DPIUtil.getDeviceZoom())); // To Points
298297
});
299298
}
300299
};

bundles/org.eclipse.swt/Eclipse SWT Browser/win32/org/eclipse/swt/browser/Edge.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,8 +1254,8 @@ int handleContextMenuRequested(long pView, long pArgs) {
12541254
// to PIXEL coordinates with the real native zoom value
12551255
// independent from the swt.autoScale property:
12561256
Point pt = new Point( //
1257-
DPIUtil.scaleUp(win32Point.x, DPIUtil.getNativeDeviceZoom()), //
1258-
DPIUtil.scaleUp(win32Point.y, DPIUtil.getNativeDeviceZoom()));
1257+
Win32DPIUtils.scaleUp(win32Point.x, DPIUtil.getNativeDeviceZoom()), //
1258+
Win32DPIUtils.scaleUp(win32Point.y, DPIUtil.getNativeDeviceZoom()));
12591259
// - then, scale back down from PIXEL to DISPLAY coordinates, taking
12601260
// swt.autoScale property into account
12611261
// which is also later considered in Menu#setLocation()

bundles/org.eclipse.swt/Eclipse SWT Browser/win32/org/eclipse/swt/browser/IE.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1880,7 +1880,7 @@ void handleDOMEvent (OleEvent e) {
18801880
int screenY = pVarResult.getInt();
18811881
pVarResult.dispose();
18821882

1883-
Point position = DPIUtil.scaleDown(new Point(screenX, screenY), DPIUtil.getDeviceZoom()); // To Points
1883+
Point position = Win32DPIUtils.scaleDown(new Point(screenX, screenY), DPIUtil.getDeviceZoom()); // To Points
18841884
position = browser.getDisplay().map(null, browser, position);
18851885
newEvent.x = position.x; newEvent.y = position.y;
18861886

bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/win32/org/eclipse/swt/dnd/DragSource.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ private void drag(Event dragEvent) {
510510
int offsetX = event.offsetX;
511511
hwndDrag = topControl.handle;
512512
if ((topControl.getStyle() & SWT.RIGHT_TO_LEFT) != 0) {
513-
offsetX = DPIUtil.scaleUp(image.getBounds(), zoom).width - offsetX;
513+
offsetX = Win32DPIUtils.scaleUp(image.getBounds(), zoom).width - offsetX;
514514
RECT rect = new RECT ();
515515
OS.GetClientRect (topControl.handle, rect);
516516
hwndDrag = OS.CreateWindowEx (
@@ -538,8 +538,8 @@ private void drag(Event dragEvent) {
538538
int flags = OS.RDW_UPDATENOW | OS.RDW_ALLCHILDREN;
539539
OS.RedrawWindow (topControl.handle, null, 0, flags);
540540
POINT pt = new POINT ();
541-
pt.x = DPIUtil.scaleUp(dragEvent.x, zoom);// To Pixels
542-
pt.y = DPIUtil.scaleUp(dragEvent.y, zoom);// To Pixels
541+
pt.x = Win32DPIUtils.scaleUp(dragEvent.x, zoom);// To Pixels
542+
pt.y = Win32DPIUtils.scaleUp(dragEvent.y, zoom);// To Pixels
543543
OS.MapWindowPoints (control.handle, 0, pt, 1);
544544
RECT rect = new RECT ();
545545
OS.GetWindowRect (hwndDrag, rect);

bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/win32/org/eclipse/swt/dnd/DropTarget.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ private Point convertPixelToPoint(int xInPixels, int yInPixels) {
410410
if (this.control == null) {
411411
// If there is no control for context, the behavior remains as before
412412
int zoom = DPIUtil.getZoomForAutoscaleProperty(this.nativeZoom);
413-
return DPIUtil.scaleDown(new Point(xInPixels, yInPixels), zoom);
413+
return Win32DPIUtils.scaleDown(new Point(xInPixels, yInPixels), zoom);
414414
}
415415
int zoom = DPIUtil.getZoomForAutoscaleProperty(this.control.nativeZoom);
416416
// There is no API to convert absolute values in pixels to display relative
@@ -419,7 +419,7 @@ private Point convertPixelToPoint(int xInPixels, int yInPixels) {
419419
POINT pt = new POINT ();
420420
pt.x = xInPixels; pt.y = yInPixels;
421421
OS.ScreenToClient (this.control.handle, pt);
422-
Point p = DPIUtil.scaleDown(new Point (pt.x, pt.y), zoom);
422+
Point p = Win32DPIUtils.scaleDown(new Point (pt.x, pt.y), zoom);
423423
return this.control.toDisplay(p);
424424
}
425425

bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/win32/org/eclipse/swt/dnd/TableDragSourceEffect.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import org.eclipse.swt.*;
1717
import org.eclipse.swt.graphics.*;
1818
import org.eclipse.swt.internal.*;
19-
import org.eclipse.swt.internal.DPIUtil.*;
2019
import org.eclipse.swt.internal.win32.*;
2120
import org.eclipse.swt.widgets.*;
2221

@@ -147,7 +146,7 @@ Image getDragSourceImage(DragSourceEvent event) {
147146
data.transparentPixel = shdi.crColorKey << 8;
148147
}
149148
Display display = control.getDisplay();
150-
dragSourceImage = new Image(display, new AutoScaleImageDataProvider(display, data, DPIUtil.getZoomForAutoscaleProperty(control.nativeZoom)));
149+
dragSourceImage = new Image(display, new Win32DPIUtils.AutoScaleImageDataProvider(display, data, DPIUtil.getZoomForAutoscaleProperty(control.nativeZoom)));
151150
OS.SelectObject (memHdc, oldMemBitmap);
152151
OS.DeleteDC (memHdc);
153152
OS.DeleteObject (memDib);

bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/win32/org/eclipse/swt/dnd/TableDropTargetEffect.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public void dragOver(DropTargetEvent event) {
151151
int effect = checkEffect(event.feedback);
152152
long handle = table.handle;
153153
Point coordinates = new Point(event.x, event.y);
154-
coordinates = DPIUtil.scaleUp(table.toControl(coordinates), DPIUtil.getZoomForAutoscaleProperty(table.nativeZoom)); // To Pixels
154+
coordinates = Win32DPIUtils.scaleUp(table.toControl(coordinates), DPIUtil.getZoomForAutoscaleProperty(table.nativeZoom)); // To Pixels
155155
LVHITTESTINFO pinfo = new LVHITTESTINFO();
156156
pinfo.x = coordinates.x;
157157
pinfo.y = coordinates.y;

bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/win32/org/eclipse/swt/dnd/TreeDragSourceEffect.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import org.eclipse.swt.*;
1717
import org.eclipse.swt.graphics.*;
1818
import org.eclipse.swt.internal.*;
19-
import org.eclipse.swt.internal.DPIUtil.*;
2019
import org.eclipse.swt.internal.win32.*;
2120
import org.eclipse.swt.widgets.*;
2221

@@ -146,7 +145,7 @@ Image getDragSourceImage(DragSourceEvent event) {
146145
data.transparentPixel = shdi.crColorKey << 8;
147146
}
148147
Display display = control.getDisplay ();
149-
dragSourceImage = new Image (display, new AutoScaleImageDataProvider(display, data, DPIUtil.getZoomForAutoscaleProperty(control.nativeZoom)));
148+
dragSourceImage = new Image (display, new Win32DPIUtils.AutoScaleImageDataProvider(display, data, DPIUtil.getZoomForAutoscaleProperty(control.nativeZoom)));
150149
OS.SelectObject (memHdc, oldMemBitmap);
151150
OS.DeleteDC (memHdc);
152151
OS.DeleteObject (memDib);

bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/win32/org/eclipse/swt/dnd/TreeDropTargetEffect.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public void dragOver(DropTargetEvent event) {
165165
int effect = checkEffect(event.feedback);
166166
long handle = tree.handle;
167167
Point coordinates = new Point(event.x, event.y);
168-
coordinates = DPIUtil.scaleUp(tree.toControl(coordinates), DPIUtil.getZoomForAutoscaleProperty(tree.nativeZoom)); // To Pixels
168+
coordinates = Win32DPIUtils.scaleUp(tree.toControl(coordinates), DPIUtil.getZoomForAutoscaleProperty(tree.nativeZoom)); // To Pixels
169169
TVHITTESTINFO lpht = new TVHITTESTINFO ();
170170
lpht.x = coordinates.x;
171171
lpht.y = coordinates.y;

bundles/org.eclipse.swt/Eclipse SWT OLE Win32/win32/org/eclipse/swt/ole/win32/OleClientSite.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,7 @@ protected int GetWindow(long phwnd) {
810810
return COM.S_OK;
811811
}
812812
RECT getRect() {
813-
Rectangle area = DPIUtil.scaleUp(getClientArea(), DPIUtil.getZoomForAutoscaleProperty(nativeZoom)); // To Pixels
813+
Rectangle area = Win32DPIUtils.scaleUp(getClientArea(), DPIUtil.getZoomForAutoscaleProperty(nativeZoom)); // To Pixels
814814
RECT rect = new RECT();
815815
rect.left = area.x;
816816
rect.top = area.y;
@@ -987,14 +987,14 @@ private int OnInPlaceDeactivate() {
987987
return COM.S_OK;
988988
}
989989
private int OnPosRectChange(long lprcPosRect) {
990-
Point size = DPIUtil.scaleUp(getSize(), DPIUtil.getZoomForAutoscaleProperty(nativeZoom)); // To Pixels
990+
Point size = Win32DPIUtils.scaleUp(getSize(), DPIUtil.getZoomForAutoscaleProperty(nativeZoom)); // To Pixels
991991
setExtent(size.x, size.y);
992992
return COM.S_OK;
993993
}
994994
private void onPaint(Event e) {
995995
if (state == STATE_RUNNING || state == STATE_INPLACEACTIVE) {
996996
SIZE size = getExtent();
997-
Rectangle area = DPIUtil.scaleUp(getClientArea(), DPIUtil.getZoomForAutoscaleProperty(nativeZoom)); // To Pixels
997+
Rectangle area = Win32DPIUtils.scaleUp(getClientArea(), DPIUtil.getZoomForAutoscaleProperty(nativeZoom)); // To Pixels
998998
RECT rect = new RECT();
999999
if (getProgramID().startsWith("Excel.Sheet")) { //$NON-NLS-1$
10001000
rect.left = area.x; rect.right = area.x + (area.height * size.cx / size.cy);
@@ -1370,7 +1370,7 @@ void setBorderSpace(RECT newBorderwidth) {
13701370
}
13711371
void setBounds() {
13721372
int zoom = DPIUtil.getZoomForAutoscaleProperty(nativeZoom);
1373-
Rectangle area = DPIUtil.scaleUp(frame.getClientArea(), zoom); // To Pixels
1373+
Rectangle area = Win32DPIUtils.scaleUp(frame.getClientArea(), zoom); // To Pixels
13741374
setBounds(DPIUtil.scaleDown(borderWidths.left, zoom),
13751375
DPIUtil.scaleDown(borderWidths.top, zoom),
13761376
DPIUtil.scaleDown(area.width - borderWidths.left - borderWidths.right, zoom),

0 commit comments

Comments
 (0)