|
14 | 14 | package org.eclipse.swt.widgets;
|
15 | 15 |
|
16 | 16 |
|
| 17 | +import java.util.*; |
| 18 | + |
17 | 19 | import org.eclipse.swt.*;
|
18 | 20 | import org.eclipse.swt.graphics.*;
|
19 | 21 | import org.eclipse.swt.internal.*;
|
@@ -130,14 +132,24 @@ Rectangle getBoundsInPixels () {
|
130 | 132 | return new Rectangle (getXInPixels(), getYInPixels(), rect.width, rect.height);
|
131 | 133 | }
|
132 | 134 | if (width == 0) {
|
133 |
| - int [] buffer = new int [1]; |
134 |
| - if (OS.SystemParametersInfo (OS.SPI_GETCARETWIDTH, 0, buffer, 0)) { |
135 |
| - return new Rectangle (getXInPixels(), getYInPixels(), buffer [0], getHeightInPixels()); |
| 135 | + OptionalInt widthInPixels = getSystemCaretWidthInPixelsForCurrentMonitor(); |
| 136 | + if (widthInPixels.isPresent()) { |
| 137 | + return new Rectangle (getXInPixels(), getYInPixels(), widthInPixels.getAsInt(), getHeightInPixels()); |
136 | 138 | }
|
137 | 139 | }
|
138 | 140 | return new Rectangle (getXInPixels(), getYInPixels(), getWidthInPixels(), getHeightInPixels());
|
139 | 141 | }
|
140 | 142 |
|
| 143 | +private OptionalInt getSystemCaretWidthInPixelsForCurrentMonitor() { |
| 144 | + int [] buffer = new int [1]; |
| 145 | + if (OS.SystemParametersInfo (OS.SPI_GETCARETWIDTH, 0, buffer, 0)) { |
| 146 | + int width = DPIUtil.pixelToPoint(buffer [0], Win32DPIUtils.getPrimaryMonitorZoomAtStartup()); |
| 147 | + int widthInPixels = Win32DPIUtils.pointToPixel(width, getNativeZoom()); |
| 148 | + return OptionalInt.of(widthInPixels); |
| 149 | + } |
| 150 | + return OptionalInt.empty(); |
| 151 | +} |
| 152 | + |
141 | 153 | /**
|
142 | 154 | * Returns the font that the receiver will use to paint textual information.
|
143 | 155 | *
|
@@ -224,9 +236,9 @@ Point getSizeInPixels () {
|
224 | 236 | return new Point (rect.width, rect.height);
|
225 | 237 | }
|
226 | 238 | if (width == 0) {
|
227 |
| - int [] buffer = new int [1]; |
228 |
| - if (OS.SystemParametersInfo (OS.SPI_GETCARETWIDTH, 0, buffer, 0)) { |
229 |
| - return new Point (buffer [0], getHeightInPixels()); |
| 239 | + OptionalInt widthInPixels = getSystemCaretWidthInPixelsForCurrentMonitor(); |
| 240 | + if (widthInPixels.isPresent()) { |
| 241 | + return new Point (widthInPixels.getAsInt(), getHeightInPixels()); |
230 | 242 | }
|
231 | 243 | }
|
232 | 244 | return new Point (getWidthInPixels(), getHeightInPixels());
|
@@ -368,9 +380,9 @@ void resize () {
|
368 | 380 | long hBitmap = image != null ? Image.win32_getHandle(image, getZoom()) : 0;
|
369 | 381 | int widthInPixels = this.getWidthInPixels();
|
370 | 382 | if (image == null && widthInPixels == 0) {
|
371 |
| - int [] buffer = new int [1]; |
372 |
| - if (OS.SystemParametersInfo (OS.SPI_GETCARETWIDTH, 0, buffer, 0)) { |
373 |
| - widthInPixels = buffer [0]; |
| 383 | + OptionalInt systemCaretWidthInPixelsForCurrentMonitor = getSystemCaretWidthInPixelsForCurrentMonitor(); |
| 384 | + if (systemCaretWidthInPixelsForCurrentMonitor.isPresent()) { |
| 385 | + widthInPixels = systemCaretWidthInPixelsForCurrentMonitor.getAsInt(); |
374 | 386 | }
|
375 | 387 | }
|
376 | 388 | OS.CreateCaret (hwnd, hBitmap, widthInPixels, getHeightInPixels());
|
@@ -447,9 +459,9 @@ void setFocus () {
|
447 | 459 | if (image != null) hBitmap = Image.win32_getHandle(image, getZoom());
|
448 | 460 | int widthInPixels = this.getWidthInPixels();
|
449 | 461 | if (image == null && widthInPixels == 0) {
|
450 |
| - int [] buffer = new int [1]; |
451 |
| - if (OS.SystemParametersInfo (OS.SPI_GETCARETWIDTH, 0, buffer, 0)) { |
452 |
| - widthInPixels = buffer [0]; |
| 462 | + OptionalInt systemCaretWidthInPixelsForCurrentMonitor = getSystemCaretWidthInPixelsForCurrentMonitor(); |
| 463 | + if (systemCaretWidthInPixelsForCurrentMonitor.isPresent()) { |
| 464 | + widthInPixels = systemCaretWidthInPixelsForCurrentMonitor.getAsInt(); |
453 | 465 | }
|
454 | 466 | }
|
455 | 467 | OS.CreateCaret (hwnd, hBitmap, widthInPixels, getHeightInPixels());
|
|
0 commit comments