From 2ac13c909913a353b1060f4579f2f844bed94781 Mon Sep 17 00:00:00 2001 From: arunjose696 Date: Tue, 15 Jul 2025 16:10:34 +0200 Subject: [PATCH 1/2] create Image with ImageDataProvider instead of ImageData in fillGradientRectangle() This PR refactors the image creation logic in fillGradientRectangle() by using an ImageDataProvider instead of directly creating ImageData. There is no visual impact for the changes the behavior should remain as before. --- .../common/org/eclipse/swt/graphics/ImageData.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageData.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageData.java index 6b74adc9c26..b08e5dcd1c6 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageData.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageData.java @@ -2616,9 +2616,14 @@ static void fillGradientRectangle(GC gc, Device device, RGB fromRGB, RGB toRGB, int redBits, int greenBits, int blueBits, int zoom) { /* Create the bitmap and tile it */ - ImageData band = createGradientBand(width, height, vertical, - fromRGB, toRGB, redBits, greenBits, blueBits); - Image image = new Image(device, band); + ImageDataProvider imageDataProvider = imageZoom -> { + int scaledWidth = Win32DPIUtils.pointToPixel(width, imageZoom); + int scaledHeight = Win32DPIUtils.pointToPixel(height, imageZoom); + return createGradientBand(scaledWidth, scaledHeight, vertical, fromRGB, toRGB, redBits, greenBits, + blueBits); + }; + Image image = new Image(device, imageDataProvider); + ImageData band = image.getImageData(zoom); if ((band.width == 1) || (band.height == 1)) { gc.drawImage(image, 0, 0, DPIUtil.pixelToPoint(band.width, zoom), DPIUtil.pixelToPoint(band.height, zoom), DPIUtil.pixelToPoint(x, zoom), DPIUtil.pixelToPoint(y, zoom), DPIUtil.pixelToPoint(width, zoom), From 77cf2b3d60670b0a137744eacbbbc9b88c026a06 Mon Sep 17 00:00:00 2001 From: arunjose696 Date: Fri, 8 Aug 2025 12:08:00 +0200 Subject: [PATCH 2/2] Using eclipse Automatic refactoring to move Win32DPIUtils.pointToPixel(size,zoom) to DPIUtils --- .../win32/org/eclipse/swt/browser/Edge.java | 4 ++-- .../win32/org/eclipse/swt/dnd/DragSource.java | 4 ++-- .../org/eclipse/swt/graphics/ImageData.java | 4 ++-- .../org/eclipse/swt/internal/DPIUtil.java | 15 +++++++++++++ .../org/eclipse/swt/graphics/Cursor.java | 4 ++-- .../win32/org/eclipse/swt/graphics/Image.java | 8 +++---- .../org/eclipse/swt/graphics/Pattern.java | 8 +++---- .../org/eclipse/swt/graphics/Region.java | 4 ++-- .../org/eclipse/swt/graphics/TextLayout.java | 20 ++++++++--------- .../org/eclipse/swt/graphics/Transform.java | 2 +- .../org/eclipse/swt/internal/ImageList.java | 4 ++-- .../eclipse/swt/internal/Win32DPIUtils.java | 19 ++-------------- .../win32/org/eclipse/swt/widgets/Button.java | 8 +++---- .../win32/org/eclipse/swt/widgets/Canvas.java | 4 ++-- .../win32/org/eclipse/swt/widgets/Caret.java | 8 +++---- .../org/eclipse/swt/widgets/Composite.java | 4 ++-- .../org/eclipse/swt/widgets/Control.java | 22 +++++++++---------- .../org/eclipse/swt/widgets/CoolBar.java | 2 +- .../org/eclipse/swt/widgets/CoolItem.java | 10 ++++----- .../org/eclipse/swt/widgets/Display.java | 2 +- .../org/eclipse/swt/widgets/ExpandBar.java | 2 +- .../org/eclipse/swt/widgets/ExpandItem.java | 12 +++++----- .../org/eclipse/swt/widgets/MenuItem.java | 4 ++-- .../MultiZoomCoordinateSystemMapper.java | 16 +++++++------- .../win32/org/eclipse/swt/widgets/Sash.java | 8 +++---- .../win32/org/eclipse/swt/widgets/Shell.java | 8 +++---- .../SingleZoomCoordinateSystemMapper.java | 14 ++++++------ .../win32/org/eclipse/swt/widgets/Table.java | 2 +- .../org/eclipse/swt/widgets/TableColumn.java | 4 ++-- .../org/eclipse/swt/widgets/ToolItem.java | 2 +- .../org/eclipse/swt/widgets/ToolTip.java | 2 +- .../win32/org/eclipse/swt/widgets/Tree.java | 8 +++---- .../org/eclipse/swt/widgets/TreeColumn.java | 4 ++-- .../swt/tests/win32/Win32DPIUtilTests.java | 13 ++++++----- 34 files changed, 128 insertions(+), 127 deletions(-) diff --git a/bundles/org.eclipse.swt/Eclipse SWT Browser/win32/org/eclipse/swt/browser/Edge.java b/bundles/org.eclipse.swt/Eclipse SWT Browser/win32/org/eclipse/swt/browser/Edge.java index 49cb5e1b926..9088c7f7323 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Browser/win32/org/eclipse/swt/browser/Edge.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Browser/win32/org/eclipse/swt/browser/Edge.java @@ -1256,8 +1256,8 @@ int handleContextMenuRequested(long pView, long pArgs) { // to PIXEL coordinates with the real native zoom value // independent from the swt.autoScale property: Point pt = new Point( // - Win32DPIUtils.pointToPixel(win32Point.x, DPIUtil.getNativeDeviceZoom()), // - Win32DPIUtils.pointToPixel(win32Point.y, DPIUtil.getNativeDeviceZoom())); + DPIUtil.pointToPixel(win32Point.x, DPIUtil.getNativeDeviceZoom()), // + DPIUtil.pointToPixel(win32Point.y, DPIUtil.getNativeDeviceZoom())); // - then, scale back down from PIXEL to DISPLAY coordinates, taking // swt.autoScale property into account // which is also later considered in Menu#setLocation() diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/win32/org/eclipse/swt/dnd/DragSource.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/win32/org/eclipse/swt/dnd/DragSource.java index 73b34ac0b88..d74bd7e9563 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/win32/org/eclipse/swt/dnd/DragSource.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/win32/org/eclipse/swt/dnd/DragSource.java @@ -538,8 +538,8 @@ private void drag(Event dragEvent) { int flags = OS.RDW_UPDATENOW | OS.RDW_ALLCHILDREN; OS.RedrawWindow (topControl.handle, null, 0, flags); POINT pt = new POINT (); - pt.x = Win32DPIUtils.pointToPixel(dragEvent.x, zoom);// To Pixels - pt.y = Win32DPIUtils.pointToPixel(dragEvent.y, zoom);// To Pixels + pt.x = DPIUtil.pointToPixel(dragEvent.x, zoom);// To Pixels + pt.y = DPIUtil.pointToPixel(dragEvent.y, zoom);// To Pixels OS.MapWindowPoints (control.handle, 0, pt, 1); RECT rect = new RECT (); OS.GetWindowRect (hwndDrag, rect); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageData.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageData.java index b08e5dcd1c6..c9f788da54a 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageData.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageData.java @@ -2617,8 +2617,8 @@ static void fillGradientRectangle(GC gc, Device device, int redBits, int greenBits, int blueBits, int zoom) { /* Create the bitmap and tile it */ ImageDataProvider imageDataProvider = imageZoom -> { - int scaledWidth = Win32DPIUtils.pointToPixel(width, imageZoom); - int scaledHeight = Win32DPIUtils.pointToPixel(height, imageZoom); + int scaledWidth = DPIUtil.pointToPixel(width, imageZoom); + int scaledHeight = DPIUtil.pointToPixel(height, imageZoom); return createGradientBand(scaledWidth, scaledHeight, vertical, fromRGB, toRGB, redBits, greenBits, blueBits); }; diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/DPIUtil.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/DPIUtil.java index 6dce4cff809..3f337353ca8 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/DPIUtil.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/DPIUtil.java @@ -223,6 +223,21 @@ public static int mapZoomToDPI (int zoom) { return roundedDpi; } +/** + * Auto-scale up int dimensions to match the given zoom level + */ +public static int pointToPixel(int size, int zoom) { + if (zoom == 100 || size == SWT.DEFAULT) return size; + float scaleFactor = getScalingFactor(zoom); + return Math.round (size * scaleFactor); +} + +public static float pointToPixel(float size, int zoom) { + if (zoom == 100 || size == SWT.DEFAULT) return size; + float scaleFactor = getScalingFactor(zoom); + return (size * scaleFactor); +} + /** * Represents an element, such as some image data, at a specific zoom level. * diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Cursor.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Cursor.java index 72ce9e1a23c..302b5683ecf 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Cursor.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Cursor.java @@ -444,11 +444,11 @@ public static Long win32_getHandle (Cursor cursor, int zoom) { source = DPIUtil.scaleImageData(cursor.device, cursor.source, zoom, DEFAULT_ZOOM); } if (cursor.isIcon) { - long handle = setupCursorFromImageData(cursor.getDevice(), source, Win32DPIUtils.pointToPixel(cursor.hotspotX, zoom), Win32DPIUtils.pointToPixel(cursor.hotspotY, zoom)); + long handle = setupCursorFromImageData(cursor.getDevice(), source, DPIUtil.pointToPixel(cursor.hotspotX, zoom), DPIUtil.pointToPixel(cursor.hotspotY, zoom)); cursor.setHandleForZoomLevel(handle, zoom); } else { ImageData mask = DPIUtil.scaleImageData(cursor.getDevice(), cursor.mask, zoom, DEFAULT_ZOOM); - long handle = setupCursorFromImageData(source, mask, Win32DPIUtils.pointToPixel(cursor.hotspotX, zoom), Win32DPIUtils.pointToPixel(cursor.hotspotY, zoom)); + long handle = setupCursorFromImageData(source, mask, DPIUtil.pointToPixel(cursor.hotspotX, zoom), DPIUtil.pointToPixel(cursor.hotspotY, zoom)); cursor.setHandleForZoomLevel(handle, zoom); } } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java index 5541adfc313..9f3ea058aa7 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java @@ -2199,8 +2199,8 @@ private ImageHandle createHandle(int zoom) { private long initHandle(int zoom) { if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - int scaledWidth = Win32DPIUtils.pointToPixel (width, zoom); - int scaledHeight = Win32DPIUtils.pointToPixel (height, zoom); + int scaledWidth = DPIUtil.pointToPixel (width, zoom); + int scaledHeight = DPIUtil.pointToPixel (height, zoom); long hDC = device.internal_new_GC(null); long newHandle = OS.CreateCompatibleBitmap(hDC, scaledWidth, scaledHeight); /* @@ -2598,8 +2598,8 @@ protected ImageHandle newImageHandle(int zoom) { int gcStyle = drawer.getGcStyle(); Image image; if ((gcStyle & SWT.TRANSPARENT) != 0) { - int scaledHeight = Win32DPIUtils.pointToPixel(height, zoom); - int scaledWidth = Win32DPIUtils.pointToPixel(width, zoom); + int scaledHeight = DPIUtil.pointToPixel(height, zoom); + int scaledWidth = DPIUtil.pointToPixel(width, zoom); /* Create a 24 bit image data with alpha channel */ final ImageData resultData = new ImageData (scaledWidth, scaledHeight, 24, new PaletteData (0xFF, 0xFF00, 0xFF0000)); resultData.alphaData = new byte [scaledWidth * scaledHeight]; diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Pattern.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Pattern.java index e6bf643fa7e..85b2f08ce1a 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Pattern.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Pattern.java @@ -261,10 +261,10 @@ public BasePatternHandle(int zoom) { @Override long createHandle(int zoom) { long handle; - float x1 = Win32DPIUtils.pointToPixel(baseX1, zoom); - float y1 = Win32DPIUtils.pointToPixel(baseY1, zoom); - float x2 = Win32DPIUtils.pointToPixel(baseX2, zoom); - float y2 = Win32DPIUtils.pointToPixel(baseY2, zoom); + float x1 = DPIUtil.pointToPixel(baseX1, zoom); + float y1 = DPIUtil.pointToPixel(baseY1, zoom); + float x2 = DPIUtil.pointToPixel(baseX2, zoom); + float y2 = DPIUtil.pointToPixel(baseY2, zoom); if (color1 == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); if (color1.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); if (color2 == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Region.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Region.java index f13c23db7b3..4677838022e 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Region.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Region.java @@ -202,8 +202,8 @@ public boolean contains (int x, int y) { if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); return applyUsingAnyHandle(regionHandle -> { int zoom = regionHandle.zoom(); - int xInPixels = Win32DPIUtils.pointToPixel(x, zoom); - int yInPixels = Win32DPIUtils.pointToPixel(y, zoom); + int xInPixels = DPIUtil.pointToPixel(x, zoom); + int yInPixels = DPIUtil.pointToPixel(y, zoom); return containsInPixels(regionHandle.handle(), xInPixels, yInPixels); }); } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/TextLayout.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/TextLayout.java index a01a5f881d9..a87477d741f 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/TextLayout.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/TextLayout.java @@ -379,9 +379,9 @@ void computeRuns (GC gc) { } SCRIPT_LOGATTR logAttr = new SCRIPT_LOGATTR(); SCRIPT_PROPERTIES properties = new SCRIPT_PROPERTIES(); - int wrapIndentInPixels = Win32DPIUtils.pointToPixel(wrapIndent, getZoom(gc)); - int indentInPixels = Win32DPIUtils.pointToPixel(indent, getZoom(gc)); - int wrapWidthInPixels = Win32DPIUtils.pointToPixel(wrapWidth, getZoom(gc)); + int wrapIndentInPixels = DPIUtil.pointToPixel(wrapIndent, getZoom(gc)); + int indentInPixels = DPIUtil.pointToPixel(indent, getZoom(gc)); + int wrapWidthInPixels = DPIUtil.pointToPixel(wrapWidth, getZoom(gc)); int[] tabsInPixels = Win32DPIUtils.pointToPixel(tabs, getZoom(gc)); int lineWidth = indentInPixels, lineStart = 0, lineCount = 1; for (int i=0; i { - int scaledIconSize = Win32DPIUtils.pointToPixel(ICON_SIZE_AT_100, zoom); + int scaledIconSize = DPIUtil.pointToPixel(ICON_SIZE_AT_100, zoom); long [] hIcon = new long [1]; OS.LoadIconWithScaleDown(0, iconName, scaledIconSize, scaledIconSize, hIcon); Image image = Image.win32_new (this, SWT.ICON, hIcon[0], zoom); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ExpandBar.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ExpandBar.java index d7511ea77ce..e85abf8af77 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ExpandBar.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ExpandBar.java @@ -561,7 +561,7 @@ void setScrollbar () { */ public void setSpacing (int spacing) { checkWidget (); - setSpacingInPixels(Win32DPIUtils.pointToPixel(spacing, getZoom())); + setSpacingInPixels(DPIUtil.pointToPixel(spacing, getZoom())); } void setSpacingInPixels (int spacing) { diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ExpandItem.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ExpandItem.java index 869b43cbf0e..f674af05c4c 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ExpandItem.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ExpandItem.java @@ -186,8 +186,8 @@ void drawItem (GC gc, long hTheme, RECT clipRect, boolean drawFocus) { long hDC = gc.handle; int headerHeightinPixels = getHeaderHeightInPixels(); int zoom = getZoom(); - int imageHeightInPixels = Win32DPIUtils.pointToPixel(imageHeight, zoom); - int imageWidthInPixels = Win32DPIUtils.pointToPixel(imageWidth, zoom); + int imageHeightInPixels = DPIUtil.pointToPixel(imageHeight, zoom); + int imageWidthInPixels = DPIUtil.pointToPixel(imageWidth, zoom); RECT rect = new RECT (); OS.SetRect (rect, x, y, x + width, y + headerHeightinPixels); @@ -311,7 +311,7 @@ public int getHeaderHeight () { int getHeaderHeightInPixels () { int headerHeightInPixels = parent.getBandHeight(); - int imageHeightInPixels = Win32DPIUtils.pointToPixel(imageHeight, getZoom()); + int imageHeightInPixels = DPIUtil.pointToPixel(imageHeight, getZoom()); int imageHeaderDiff = headerHeightInPixels - imageHeightInPixels; if (imageHeaderDiff < IMAGE_MARGIN) { headerHeightInPixels = imageHeightInPixels + IMAGE_MARGIN; @@ -380,8 +380,8 @@ void redraw (boolean all) { long parentHandle = parent.handle; int headerHeightInPixels = getHeaderHeightInPixels(); int zoom = getZoom(); - int imageHeightInPixels = Win32DPIUtils.pointToPixel(imageHeight, zoom); - int imageWidthInPixels = Win32DPIUtils.pointToPixel(imageWidth, zoom); + int imageHeightInPixels = DPIUtil.pointToPixel(imageHeight, zoom); + int imageWidthInPixels = DPIUtil.pointToPixel(imageWidth, zoom); RECT rect = new RECT (); int left = all ? x : x + width - headerHeightInPixels; OS.SetRect (rect, left, y, x + width, y + headerHeightInPixels); @@ -496,7 +496,7 @@ public void setExpanded (boolean expanded) { */ public void setHeight (int height) { checkWidget (); - setHeightInPixels(Win32DPIUtils.pointToPixel(height, getZoom())); + setHeightInPixels(DPIUtil.pointToPixel(height, getZoom())); } void setHeightInPixels (int height) { diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/MenuItem.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/MenuItem.java index f3196ea5265..5b19abee39d 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/MenuItem.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/MenuItem.java @@ -1370,7 +1370,7 @@ LRESULT wmMeasureChild (long wParam, long lParam) { if (parent.needsMenuCallback()) { Point point = calculateRenderedTextSize(); int menuZoom = getDisplay().isRescalingAtRuntime() ? super.getZoom() : getMonitorZoom(); - struct.itemHeight = Win32DPIUtils.pointToPixel(point.y, menuZoom); + struct.itemHeight = DPIUtil.pointToPixel(point.y, menuZoom); /* * Weirdness in Windows. Setting `HBMMENU_CALLBACK` causes * item sizes to mean something else. It seems that it is @@ -1380,7 +1380,7 @@ LRESULT wmMeasureChild (long wParam, long lParam) { * that value of 5 works well in matching text to mnemonic. */ int horizontalSpaceImage = this.image != null ? this.image.getBounds().width + IMAGE_TEXT_GAP: 0; - struct.itemWidth = Win32DPIUtils.pointToPixel(LEFT_TEXT_MARGIN + point.x - WINDOWS_OVERHEAD + horizontalSpaceImage, menuZoom); + struct.itemWidth = DPIUtil.pointToPixel(LEFT_TEXT_MARGIN + point.x - WINDOWS_OVERHEAD + horizontalSpaceImage, menuZoom); OS.MoveMemory (lParam, struct, MEASUREITEMSTRUCT.sizeof); return null; } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/MultiZoomCoordinateSystemMapper.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/MultiZoomCoordinateSystemMapper.java index 5206458d7b2..73a778dee50 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/MultiZoomCoordinateSystemMapper.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/MultiZoomCoordinateSystemMapper.java @@ -140,8 +140,8 @@ private Rectangle translateRectangleInPointsToPixels(int x, int y, int width, in monitor = getValidMonitorIfApplicable(x, y, width, height, monitor); Point topLeft = getPixelsFromPoint(monitor, x, y); int zoom = getApplicableMonitorZoom(monitor); - int widthInPixels = Win32DPIUtils.pointToPixel(width, zoom); - int heightInPixels = Win32DPIUtils.pointToPixel(height, zoom); + int widthInPixels = DPIUtil.pointToPixel(width, zoom); + int heightInPixels = DPIUtil.pointToPixel(height, zoom); return new Rectangle(topLeft.x, topLeft.y, widthInPixels, heightInPixels); } @@ -201,8 +201,8 @@ private Monitor getContainingMonitorForPoints(int x, int y, int width, int heigh for (Monitor currentMonitor : monitors) { // Obtain the rectangle in pixels per monitor for absolute comparison Point topLeftOfRectangle = getPixelsFromPoint(currentMonitor, x, y); - int widthInPixels = Win32DPIUtils.pointToPixel(width, getApplicableMonitorZoom(currentMonitor)); - int heightInPixels = Win32DPIUtils.pointToPixel(height, getApplicableMonitorZoom(currentMonitor)); + int widthInPixels = DPIUtil.pointToPixel(width, getApplicableMonitorZoom(currentMonitor)); + int heightInPixels = DPIUtil.pointToPixel(height, getApplicableMonitorZoom(currentMonitor)); Rectangle boundsInPixel = new Rectangle(topLeftOfRectangle.x, topLeftOfRectangle.y, widthInPixels, heightInPixels); Rectangle clientArea = getMonitorClientAreaInPixels(currentMonitor); Rectangle intersection = clientArea.intersection(boundsInPixel); @@ -248,15 +248,15 @@ private Monitor getContainingMonitorForPixels(int xInPixels, int yInPixels, int private Rectangle getMonitorClientAreaInPixels(Monitor monitor) { int zoom = getApplicableMonitorZoom(monitor); - int widthInPixels = Win32DPIUtils.pointToPixel(monitor.clientWidth, zoom); - int heightInPixels = Win32DPIUtils.pointToPixel(monitor.clientHeight, zoom); + int widthInPixels = DPIUtil.pointToPixel(monitor.clientWidth, zoom); + int heightInPixels = DPIUtil.pointToPixel(monitor.clientHeight, zoom); return new Rectangle(monitor.clientX, monitor.clientY, widthInPixels, heightInPixels); } private Point getPixelsFromPoint(Monitor monitor, int x, int y) { int zoom = getApplicableMonitorZoom(monitor); - int mappedX = Win32DPIUtils.pointToPixel(x - monitor.clientX, zoom) + monitor.clientX; - int mappedY = Win32DPIUtils.pointToPixel(y - monitor.clientY, zoom) + monitor.clientY; + int mappedX = DPIUtil.pointToPixel(x - monitor.clientX, zoom) + monitor.clientX; + int mappedY = DPIUtil.pointToPixel(y - monitor.clientY, zoom) + monitor.clientY; return new Point(mappedX, mappedY); } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Sash.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Sash.java index 85f2ea48cc6..3acbaedf509 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Sash.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Sash.java @@ -332,8 +332,8 @@ LRESULT WM_LBUTTONUP (long wParam, long lParam) { Rectangle bounds = event.getBounds(); if (event.doit) { if ((style & SWT.SMOOTH) != 0) { - int xInPixels = Win32DPIUtils.pointToPixel(bounds.x, getZoom()); - int yInPixels = Win32DPIUtils.pointToPixel(bounds.y, getZoom()); + int xInPixels = DPIUtil.pointToPixel(bounds.x, getZoom()); + int yInPixels = DPIUtil.pointToPixel(bounds.y, getZoom()); setBoundsInPixels (xInPixels, yInPixels, widthInPixels, heightInPixels); // widget could be disposed at this point } @@ -379,8 +379,8 @@ LRESULT WM_MOUSEMOVE (long wParam, long lParam) { if (isDisposed ()) return LRESULT.ZERO; if (event.doit) { Rectangle bounds = event.getBounds(); - lastX = Win32DPIUtils.pointToPixel(bounds.x, zoom); - lastY = Win32DPIUtils.pointToPixel(bounds.y, zoom); + lastX = DPIUtil.pointToPixel(bounds.x, zoom); + lastY = DPIUtil.pointToPixel(bounds.y, zoom); } int flags = OS.RDW_UPDATENOW | OS.RDW_ALLCHILDREN; OS.RedrawWindow (hwndTrack, null, 0, flags); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Shell.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Shell.java index da1e195fa23..b1fe6415d63 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Shell.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Shell.java @@ -1592,8 +1592,8 @@ public void setBounds(Rectangle rect) { // the WM_DPICHANGED event processing. So to avoid duplicate scaling, we always // have to scale width and height with the zoom of the original monitor (still // returned by getZoom()) here. - setBoundsInPixels(boundsInPixels.x, boundsInPixels.y, Win32DPIUtils.pointToPixel(rect.width, getZoom()), - Win32DPIUtils.pointToPixel(rect.height, getZoom())); + setBoundsInPixels(boundsInPixels.x, boundsInPixels.y, DPIUtil.pointToPixel(rect.width, getZoom()), + DPIUtil.pointToPixel(rect.height, getZoom())); } @Override @@ -1769,7 +1769,7 @@ public void setImeInputMode (int mode) { public void setMaximumSize (int width, int height) { checkWidget (); int zoom = getZoom(); - setMaximumSizeInPixels(Win32DPIUtils.pointToPixel(width, zoom), Win32DPIUtils.pointToPixel(height, zoom)); + setMaximumSizeInPixels(DPIUtil.pointToPixel(width, zoom), DPIUtil.pointToPixel(height, zoom)); } /** @@ -1844,7 +1844,7 @@ void setMaximumSizeInPixels (int width, int height) { public void setMinimumSize (int width, int height) { checkWidget (); int zoom = getZoom(); - setMinimumSizeInPixels(Win32DPIUtils.pointToPixel(width, zoom), Win32DPIUtils.pointToPixel(height, zoom)); + setMinimumSizeInPixels(DPIUtil.pointToPixel(width, zoom), DPIUtil.pointToPixel(height, zoom)); } void setMinimumSizeInPixels (int width, int height) { diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/SingleZoomCoordinateSystemMapper.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/SingleZoomCoordinateSystemMapper.java index 89ee9cfeb77..fc316724fde 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/SingleZoomCoordinateSystemMapper.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/SingleZoomCoordinateSystemMapper.java @@ -55,18 +55,18 @@ public Rectangle map(Control from, Control to, Rectangle rectangle) { @Override public Point map(Control from, Control to, int x, int y) { int zoom = getZoomLevelForMapping(from, to); - x = Win32DPIUtils.pointToPixel(x, zoom); - y = Win32DPIUtils.pointToPixel(y, zoom); + x = DPIUtil.pointToPixel(x, zoom); + y = DPIUtil.pointToPixel(y, zoom); return Win32DPIUtils.pixelToPoint(display.mapInPixels(from, to, x, y), zoom); } @Override public Rectangle map(Control from, Control to, int x, int y, int width, int height) { int zoom = getZoomLevelForMapping(from, to); - x = Win32DPIUtils.pointToPixel(x, zoom); - y = Win32DPIUtils.pointToPixel(y, zoom); - width = Win32DPIUtils.pointToPixel(width, zoom); - height = Win32DPIUtils.pointToPixel(height, zoom); + x = DPIUtil.pointToPixel(x, zoom); + y = DPIUtil.pointToPixel(y, zoom); + width = DPIUtil.pointToPixel(width, zoom); + height = DPIUtil.pointToPixel(height, zoom); return Win32DPIUtils.pixelToPoint(display.mapInPixels(from, to, x, y, width, height), zoom); } @@ -105,7 +105,7 @@ public Point getCursorLocation() { @Override public void setCursorLocation(int x, int y) { int zoom = DPIUtil.getDeviceZoom(); - display.setCursorLocationInPixels(Win32DPIUtils.pointToPixel(x, zoom), Win32DPIUtils.pointToPixel(y, zoom)); + display.setCursorLocationInPixels(DPIUtil.pointToPixel(x, zoom), DPIUtil.pointToPixel(y, zoom)); } @Override diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Table.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Table.java index 59602fcb516..9dfbdea6c3d 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Table.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Table.java @@ -6915,7 +6915,7 @@ LRESULT wmNotifyHeader (NMHDR hdr, long wParam, long lParam) { * Sort indicator size needs to scale as per the Native Windows OS DPI level * when header is custom drawn. For more details refer bug 537097. */ - int leg = Win32DPIUtils.pointToPixel(3, nativeZoom); + int leg = DPIUtil.pointToPixel(3, nativeZoom); if (sortDirection == SWT.UP) { OS.Polyline(nmcd.hdc, new int[] {center-leg, 1+leg, center+1, 0}, 2); OS.Polyline(nmcd.hdc, new int[] {center+leg, 1+leg, center-1, 0}, 2); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TableColumn.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TableColumn.java index b7fae937436..f210b0bdd52 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TableColumn.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TableColumn.java @@ -440,7 +440,7 @@ public void pack () { if (hFont != -1) hFont = OS.SelectObject (hDC, hFont); if (isDisposed () || parent.isDisposed ()) break; Rectangle bounds = event.getBounds(); - columnWidth = Math.max (columnWidth, Win32DPIUtils.pointToPixel(bounds.x + bounds.width, getZoom()) - headerRect.left); + columnWidth = Math.max (columnWidth, DPIUtil.pointToPixel(bounds.x + bounds.width, getZoom()) - headerRect.left); } } if (newFont != 0) OS.SelectObject (hDC, oldFont); @@ -854,7 +854,7 @@ public void setToolTipText (String string) { */ public void setWidth (int width) { checkWidget (); - setWidthInPixels(Win32DPIUtils.pointToPixel(width, getZoom())); + setWidthInPixels(DPIUtil.pointToPixel(width, getZoom())); } void setWidthInPixels (int width) { diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolItem.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolItem.java index 3effd4b3c96..842a151105e 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolItem.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolItem.java @@ -1076,7 +1076,7 @@ public void setToolTipText (String string) { */ public void setWidth (int width) { checkWidget(); - setWidthInPixels(Win32DPIUtils.pointToPixel(width, getZoom())); + setWidthInPixels(DPIUtil.pointToPixel(width, getZoom())); } void setWidthInPixels (int width) { diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolTip.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolTip.java index 84b4e2fe0b8..49d686e4d82 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolTip.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolTip.java @@ -358,7 +358,7 @@ public void setAutoHide (boolean autoHide) { public void setLocation (int x, int y) { checkWidget (); int zoom = getZoom(); - setLocationInPixels(Win32DPIUtils.pointToPixel(x, zoom), Win32DPIUtils.pointToPixel(y, zoom)); + setLocationInPixels(DPIUtil.pointToPixel(x, zoom), DPIUtil.pointToPixel(y, zoom)); } void setLocationInPixels (int x, int y) { diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Tree.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Tree.java index b5d05dcb34f..279a184f1cf 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Tree.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Tree.java @@ -765,7 +765,7 @@ LRESULT CDDS_ITEMPOSTPAINT (NMTVCUSTOMDRAW nmcd, long wParam, long lParam) { if (size == null) size = Win32DPIUtils.pixelToPoint (getImageSize (), zoom); // To Points if (!ignoreDrawForeground) { //int y1 = rect.top + (index == 0 ? (getItemHeight () - size.y) / 2 : 0); - int y1 = rect.top + Win32DPIUtils.pointToPixel((getItemHeight () - size.y) / 2, zoom); + int y1 = rect.top + DPIUtil.pointToPixel((getItemHeight () - size.y) / 2, zoom); int x1 = Math.max (rect.left, rect.left - inset + 1); GCData data = new GCData(); data.device = display; @@ -775,7 +775,7 @@ LRESULT CDDS_ITEMPOSTPAINT (NMTVCUSTOMDRAW nmcd, long wParam, long lParam) { OS.SelectClipRgn (hDC, 0); gc.dispose (); } - OS.SetRect (rect, rect.left + Win32DPIUtils.pointToPixel(size.x, zoom) + offset, rect.top, rect.right - inset, rect.bottom); + OS.SetRect (rect, rect.left + DPIUtil.pointToPixel(size.x, zoom) + offset, rect.top, rect.right - inset, rect.bottom); } else { if (i == 0) { if (OS.SendMessage (handle, OS.TVM_GETIMAGELIST, OS.TVSIL_NORMAL, 0) != 0) { @@ -5371,7 +5371,7 @@ public void setTopItem (TreeItem item) { * In a Tree without imageList, the indent also controls the chevron (glyph) size. */ private void calculateAndApplyIndentSize() { - int indent = Win32DPIUtils.pointToPixel(DEFAULT_INDENT, nativeZoom); + int indent = DPIUtil.pointToPixel(DEFAULT_INDENT, nativeZoom); OS.SendMessage(handle, OS.TVM_SETINDENT, indent, 0); } @@ -7886,7 +7886,7 @@ LRESULT wmNotifyHeader (NMHDR hdr, long wParam, long lParam) { * Sort indicator size needs to scale as per the Native Windows OS DPI level * when header is custom drawn. For more details refer bug 537097. */ - int leg = Win32DPIUtils.pointToPixel(3, nativeZoom); + int leg = DPIUtil.pointToPixel(3, nativeZoom); if (sortDirection == SWT.UP) { OS.Polyline(nmcd.hdc, new int[] {center-leg, 1+leg, center+1, 0}, 2); OS.Polyline(nmcd.hdc, new int[] {center+leg, 1+leg, center-1, 0}, 2); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TreeColumn.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TreeColumn.java index 0e66a543765..967b07d08bd 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TreeColumn.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TreeColumn.java @@ -359,7 +359,7 @@ public void pack () { Event event = parent.sendMeasureItemEvent (item, index, hDC, detail); if (isDisposed () || parent.isDisposed ()) break; Rectangle bounds = event.getBounds(); - itemRight = Win32DPIUtils.pointToPixel(bounds.x + bounds.width, getZoom()); + itemRight = DPIUtil.pointToPixel(bounds.x + bounds.width, getZoom()); } else { long hFont = item.fontHandle (index); if (hFont != -1) hFont = OS.SelectObject (hDC, hFont); @@ -717,7 +717,7 @@ public void setToolTipText (String string) { */ public void setWidth (int width) { checkWidget (); - setWidthInPixels(Win32DPIUtils.pointToPixel(width, getZoom())); + setWidthInPixels(DPIUtil.pointToPixel(width, getZoom())); } void setWidthInPixels (int width) { diff --git a/tests/org.eclipse.swt.tests.win32/JUnit Tests/org/eclipse/swt/tests/win32/Win32DPIUtilTests.java b/tests/org.eclipse.swt.tests.win32/JUnit Tests/org/eclipse/swt/tests/win32/Win32DPIUtilTests.java index d43b793a7b1..581d22db4c6 100644 --- a/tests/org.eclipse.swt.tests.win32/JUnit Tests/org/eclipse/swt/tests/win32/Win32DPIUtilTests.java +++ b/tests/org.eclipse.swt.tests.win32/JUnit Tests/org/eclipse/swt/tests/win32/Win32DPIUtilTests.java @@ -21,6 +21,7 @@ import org.eclipse.swt.graphics.Device; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.internal.DPIUtil; import org.eclipse.swt.internal.Win32DPIUtils; import org.junit.jupiter.api.Test; @@ -146,15 +147,15 @@ public void scaleUpInteger() { int valueAt150 = 8; int valueAt100 = 5; - int scaledValue = Win32DPIUtils.pointToPixel(valueAt100, 200); + int scaledValue = DPIUtil.pointToPixel(valueAt100, 200); assertEquals(valueAt200, scaledValue, "Scaling up integer to 200 failed"); scaledValue = Win32DPIUtils.pointToPixel((Device) null, valueAt100, 200); assertEquals(valueAt200, scaledValue, "Scaling up integer to 200 with device failed"); - scaledValue = Win32DPIUtils.pointToPixel(valueAt100, 150); + scaledValue = DPIUtil.pointToPixel(valueAt100, 150); assertEquals(valueAt150, scaledValue, "Scaling up integer to 150 failed"); scaledValue = Win32DPIUtils.pointToPixel((Device) null, valueAt100, 150); assertEquals(valueAt150, scaledValue, "Scaling up integer to 150 with device failed"); - scaledValue = Win32DPIUtils.pointToPixel(valueAt100, 100); + scaledValue = DPIUtil.pointToPixel(valueAt100, 100); assertSame(valueAt100, scaledValue, "Scaling up integer without zoom change failed"); scaledValue = Win32DPIUtils.pointToPixel((Device) null, valueAt100, 100); assertSame(valueAt100, scaledValue,"Scaling up integer without zoom change with device failed"); @@ -166,15 +167,15 @@ public void scaleUpFloat() { float valueAt150 = 7.5f; float valueAt100 = 5; - float scaledValue = Win32DPIUtils.pointToPixel(valueAt100, 200); + float scaledValue = DPIUtil.pointToPixel(valueAt100, 200); assertEquals(valueAt200, scaledValue, 0.001f, "Scaling up integer to 200 failed"); scaledValue = Win32DPIUtils.pointToPixel((Device) null, valueAt100, 200); assertEquals(valueAt200, scaledValue, 0.001f, "Scaling up integer to 200 with device failed"); - scaledValue = Win32DPIUtils.pointToPixel(valueAt100, 150); + scaledValue = DPIUtil.pointToPixel(valueAt100, 150); assertEquals(valueAt150, scaledValue, 0.001f, "Scaling up integer to 150 failed"); scaledValue = Win32DPIUtils.pointToPixel((Device) null, valueAt100, 150); assertEquals(valueAt150, scaledValue, 0.001f, "Scaling up integer to 150 with device failed"); - scaledValue = Win32DPIUtils.pointToPixel(valueAt100, 100); + scaledValue = DPIUtil.pointToPixel(valueAt100, 100); assertEquals(valueAt100, scaledValue, 0.001f, "Scaling up integer without zoom change failed"); scaledValue = Win32DPIUtils.pointToPixel((Device) null, valueAt100, 100); assertEquals(valueAt100, scaledValue, 0.001f, "Scaling up integer without zoom change with device failed");