Skip to content

Commit ff7496a

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.
1 parent 3d93396 commit ff7496a

Some content is hidden

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

60 files changed

+847
-1043
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.autoScaleDown(new Point(dim.width, dim.height))); // 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.autoScaleDown(new Point(screenX, screenY)); // 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 Browser/win32/org/eclipse/swt/browser/WebSite.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,8 @@ int ShowContextMenu(int dwID, long ppt, long pcmdtReserved, long pdispReserved)
320320
Event event = new Event();
321321
POINT pt = new POINT();
322322
OS.MoveMemory(pt, ppt, POINT.sizeof);
323-
pt.x = DPIUtil.autoScaleDown(pt.x); // To Points
324-
pt.y = DPIUtil.autoScaleDown(pt.y); // To Points
323+
pt.x = DPIUtil.scaleDown(pt.x, DPIUtil.getDeviceZoom()); // To Points
324+
pt.y = DPIUtil.scaleDown(pt.y, DPIUtil.getDeviceZoom()); // To Points
325325
event.x = pt.x;
326326
event.y = pt.y;
327327
browser.notifyListeners(SWT.MenuDetect, event);

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;

0 commit comments

Comments
 (0)