Skip to content

Commit ac7d9d5

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 ac7d9d5

File tree

1 file changed

+17
-4
lines changed
  • bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets

1 file changed

+17
-4
lines changed

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

Lines changed: 17 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], 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], 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], 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], getPrimaryMonitorZoomAtStartup());
458+
widthInPixels = Win32DPIUtils.pointToPixel(width, getNativeZoom());
453459
}
454460
}
455461
OS.CreateCaret (hwnd, hBitmap, widthInPixels, getHeightInPixels());
@@ -646,6 +652,13 @@ public void setVisible (boolean visible) {
646652
}
647653
}
648654

655+
private int getPrimaryMonitorZoomAtStartup() {
656+
long hDC = OS.GetDC(0);
657+
int dpi = OS.GetDeviceCaps(hDC, OS.LOGPIXELSX);
658+
OS.ReleaseDC(0, hDC);
659+
return DPIUtil.mapDPIToZoom(dpi);
660+
}
661+
649662
/**
650663
* <b>IMPORTANT:</b> This method is not part of the public
651664
* API for Image. It is marked public only so that it

0 commit comments

Comments
 (0)