diff --git a/bundles/org.eclipse.swt/Eclipse SWT Program/win32/org/eclipse/swt/program/Program.java b/bundles/org.eclipse.swt/Eclipse SWT Program/win32/org/eclipse/swt/program/Program.java index e1fbb9a343d..03f9b45a851 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Program/win32/org/eclipse/swt/program/Program.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Program/win32/org/eclipse/swt/program/Program.java @@ -417,7 +417,7 @@ private ImageData getImageDataUsingExtension(int zoom) { if (extension != null) { // OS.SHGetFileInfo is System DPI-aware, hence it retrieves the icon with zoom // of primary monitor at the application startup - int initialNativeZoom = getPrimaryMonitorZoomAtStartup(); + int initialNativeZoom = Win32DPIUtils.getPrimaryMonitorZoomAtStartup(); SHFILEINFO shfi = new SHFILEINFO (); int flags = OS.SHGFI_ICON | OS.SHGFI_USEFILEATTRIBUTES; boolean useLargeIcon = 100 * zoom / initialNativeZoom >= 200; @@ -439,13 +439,6 @@ private ImageData getImageDataUsingExtension(int zoom) { return null; } -private int getPrimaryMonitorZoomAtStartup() { - long hDC = OS.GetDC(0); - int dpi = OS.GetDeviceCaps(hDC, OS.LOGPIXELSX); - OS.ReleaseDC(0, hDC); - return DPIUtil.mapDPIToZoom(dpi); -} - /** * Returns the receiver's name. This is as short and * descriptive a name as possible for the program. If diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/Win32DPIUtils.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/Win32DPIUtils.java index a15cf2cecdc..97c0fe56ce6 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/Win32DPIUtils.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/Win32DPIUtils.java @@ -306,6 +306,15 @@ public static boolean isMonitorSpecificScalingActive() { return updateOnRuntimeValue; } + + + public static int getPrimaryMonitorZoomAtStartup() { + long hDC = OS.GetDC(0); + int dpi = OS.GetDeviceCaps(hDC, OS.LOGPIXELSX); + OS.ReleaseDC(0, hDC); + return DPIUtil.mapDPIToZoom(dpi); + } + /** * AutoScale ImageDataProvider. */ diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Caret.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Caret.java index 1a5746e7478..ff453598322 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Caret.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Caret.java @@ -132,7 +132,9 @@ Rectangle getBoundsInPixels () { if (width == 0) { int [] buffer = new int [1]; if (OS.SystemParametersInfo (OS.SPI_GETCARETWIDTH, 0, buffer, 0)) { - return new Rectangle (getXInPixels(), getYInPixels(), buffer [0], getHeightInPixels()); + int width = DPIUtil.pixelToPoint(buffer [0], Win32DPIUtils.getPrimaryMonitorZoomAtStartup()); + int widthInPixels = Win32DPIUtils.pointToPixel(width, getNativeZoom()); + return new Rectangle (getXInPixels(), getYInPixels(), widthInPixels, getHeightInPixels()); } } return new Rectangle (getXInPixels(), getYInPixels(), getWidthInPixels(), getHeightInPixels()); @@ -226,7 +228,9 @@ Point getSizeInPixels () { if (width == 0) { int [] buffer = new int [1]; if (OS.SystemParametersInfo (OS.SPI_GETCARETWIDTH, 0, buffer, 0)) { - return new Point (buffer [0], getHeightInPixels()); + int width = DPIUtil.pixelToPoint(buffer [0], Win32DPIUtils.getPrimaryMonitorZoomAtStartup()); + int widthInPixels = Win32DPIUtils.pointToPixel(width, getNativeZoom()); + return new Point (widthInPixels, getHeightInPixels()); } } return new Point (getWidthInPixels(), getHeightInPixels()); @@ -370,7 +374,8 @@ void resize () { if (image == null && widthInPixels == 0) { int [] buffer = new int [1]; if (OS.SystemParametersInfo (OS.SPI_GETCARETWIDTH, 0, buffer, 0)) { - widthInPixels = buffer [0]; + int width = DPIUtil.pixelToPoint(buffer [0], Win32DPIUtils.getPrimaryMonitorZoomAtStartup()); + widthInPixels = Win32DPIUtils.pointToPixel(width, getNativeZoom()); } } OS.CreateCaret (hwnd, hBitmap, widthInPixels, getHeightInPixels()); @@ -449,7 +454,8 @@ void setFocus () { if (image == null && widthInPixels == 0) { int [] buffer = new int [1]; if (OS.SystemParametersInfo (OS.SPI_GETCARETWIDTH, 0, buffer, 0)) { - widthInPixels = buffer [0]; + int width = DPIUtil.pixelToPoint(buffer [0], Win32DPIUtils.getPrimaryMonitorZoomAtStartup()); + widthInPixels = Win32DPIUtils.pointToPixel(width, getNativeZoom()); } } OS.CreateCaret (hwnd, hBitmap, widthInPixels, getHeightInPixels()); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java index 9d316fe277a..3880361ce6e 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java @@ -2553,6 +2553,13 @@ Font getSystemFont (int zoom) { return systemFont; } +static int getPrimaryMonitorZoomAtStartup() { + long hDC = OS.GetDC(0); + int dpi = OS.GetDeviceCaps(hDC, OS.LOGPIXELSX); + OS.ReleaseDC(0, hDC); + return DPIUtil.mapDPIToZoom(dpi); +} + /** * Returns the matching standard platform image for the given * constant, which should be one of the icon constants 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 50c6e835561..95d99326705 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 @@ -911,7 +911,7 @@ private long getMenuItemIconSelectedBitmapHandle() { } private int adaptZoomForMenuItem(int currentZoom, Image image) { - int primaryMonitorZoomAtAppStartUp = getPrimaryMonitorZoomAtStartup(); + int primaryMonitorZoomAtAppStartUp = Win32DPIUtils.getPrimaryMonitorZoomAtStartup(); /* * Windows has inconsistent behavior when setting the size of MenuItem image and * hence we need to adjust the size of the images as per different kind of zoom @@ -940,13 +940,6 @@ private static boolean isQuarterZoom(int zoom) { return zoom % 10 != 0 && zoom % 25 == 0; } -private static int getPrimaryMonitorZoomAtStartup() { - long hDC = OS.GetDC(0); - int dpi = OS.GetDeviceCaps(hDC, OS.LOGPIXELSX); - OS.ReleaseDC(0, hDC); - return DPIUtil.mapDPIToZoom(dpi); -} - /** * Sets the receiver's pull down menu to the argument. * Only CASCADE menu items can have a