Skip to content

Commit 476a5bd

Browse files
committed
Use width scaled for the nativeZoom in Caret win32
This commit adapts the retrieval of width of Caret SystemParametersInfo to be scaled as per the natie zoom as SystemParametersInfo retrieves value for the primary zoom at startup.
1 parent f6de513 commit 476a5bd

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,9 @@ Rectangle getBoundsInPixels () {
132132
if (width == 0) {
133133
int [] buffer = new int [1];
134134
if (OS.SystemParametersInfo (OS.SPI_GETCARETWIDTH, 0, buffer, 0)) {
135-
return new Rectangle (getXInPixels(), getYInPixels(), buffer [0], getHeightInPixels());
135+
int width = DPIUtil.pixelToPoint(buffer [0], Display.getPrimaryMonitorZoomAtStartup());
136+
int widthInPixels = Win32DPIUtils.pointToPixel(width, getNativeZoom());
137+
return new Rectangle (getXInPixels(), getYInPixels(), widthInPixels, getHeightInPixels());
136138
}
137139
}
138140
return new Rectangle (getXInPixels(), getYInPixels(), getWidthInPixels(), getHeightInPixels());
@@ -226,7 +228,9 @@ Point getSizeInPixels () {
226228
if (width == 0) {
227229
int [] buffer = new int [1];
228230
if (OS.SystemParametersInfo (OS.SPI_GETCARETWIDTH, 0, buffer, 0)) {
229-
return new Point (buffer [0], getHeightInPixels());
231+
int width = DPIUtil.pixelToPoint(buffer [0], Display.getPrimaryMonitorZoomAtStartup());
232+
int widthInPixels = Win32DPIUtils.pointToPixel(width, getNativeZoom());
233+
return new Point (widthInPixels, getHeightInPixels());
230234
}
231235
}
232236
return new Point (getWidthInPixels(), getHeightInPixels());
@@ -370,7 +374,8 @@ void resize () {
370374
if (image == null && widthInPixels == 0) {
371375
int [] buffer = new int [1];
372376
if (OS.SystemParametersInfo (OS.SPI_GETCARETWIDTH, 0, buffer, 0)) {
373-
widthInPixels = buffer [0];
377+
int width = DPIUtil.pixelToPoint(buffer [0], Display.getPrimaryMonitorZoomAtStartup());
378+
widthInPixels = Win32DPIUtils.pointToPixel(width, getNativeZoom());
374379
}
375380
}
376381
OS.CreateCaret (hwnd, hBitmap, widthInPixels, getHeightInPixels());
@@ -449,7 +454,8 @@ void setFocus () {
449454
if (image == null && widthInPixels == 0) {
450455
int [] buffer = new int [1];
451456
if (OS.SystemParametersInfo (OS.SPI_GETCARETWIDTH, 0, buffer, 0)) {
452-
widthInPixels = buffer [0];
457+
int width = DPIUtil.pixelToPoint(buffer [0], Display.getPrimaryMonitorZoomAtStartup());
458+
widthInPixels = Win32DPIUtils.pointToPixel(width, getNativeZoom());
453459
}
454460
}
455461
OS.CreateCaret (hwnd, hBitmap, widthInPixels, getHeightInPixels());

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2553,6 +2553,13 @@ Font getSystemFont (int zoom) {
25532553
return systemFont;
25542554
}
25552555

2556+
static int getPrimaryMonitorZoomAtStartup() {
2557+
long hDC = OS.GetDC(0);
2558+
int dpi = OS.GetDeviceCaps(hDC, OS.LOGPIXELSX);
2559+
OS.ReleaseDC(0, hDC);
2560+
return DPIUtil.mapDPIToZoom(dpi);
2561+
}
2562+
25562563
/**
25572564
* Returns the matching standard platform image for the given
25582565
* constant, which should be one of the icon constants

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,7 @@ private long getMenuItemIconSelectedBitmapHandle() {
911911
}
912912

913913
private int adaptZoomForMenuItem(int currentZoom, Image image) {
914-
int primaryMonitorZoomAtAppStartUp = getPrimaryMonitorZoomAtStartup();
914+
int primaryMonitorZoomAtAppStartUp = Display.getPrimaryMonitorZoomAtStartup();
915915
/*
916916
* Windows has inconsistent behavior when setting the size of MenuItem image and
917917
* 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) {
940940
return zoom % 10 != 0 && zoom % 25 == 0;
941941
}
942942

943-
private static int getPrimaryMonitorZoomAtStartup() {
944-
long hDC = OS.GetDC(0);
945-
int dpi = OS.GetDeviceCaps(hDC, OS.LOGPIXELSX);
946-
OS.ReleaseDC(0, hDC);
947-
return DPIUtil.mapDPIToZoom(dpi);
948-
}
949-
950943
/**
951944
* Sets the receiver's pull down menu to the argument.
952945
* Only <code>CASCADE</code> menu items can have a

0 commit comments

Comments
 (0)