Skip to content

Commit 8bd73bc

Browse files
committed
Adapt calls for image bounds to consider the actual zoom of the widget
This contribution replaces calls to Image::getBoundsInPixels in the widgets in the win32 implementation with calls to consider the actual zoom of the affected widget. Contributes to #62 and #127
1 parent 3ed8a21 commit 8bd73bc

File tree

7 files changed

+20
-18
lines changed

7 files changed

+20
-18
lines changed

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/ImageList.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public int add (Image image) {
4646
index++;
4747
}
4848
if (count == 0) {
49-
Rectangle rect = image.getBoundsInPixels ();
49+
Rectangle rect = image.getBoundsInPixels();
5050
OS.ImageList_SetIconSize (handle, rect.width, rect.height);
5151
}
5252
set (index, image, count);
@@ -369,7 +369,7 @@ void set (int index, Image image, int count) {
369369
* Note that the image size has to match the image list icon size.
370370
*/
371371
long hBitmap = 0, hMask = 0;
372-
ImageData data = image.getImageData (DPIUtil.getDeviceZoom ());
372+
ImageData data = image.getImageDataAtCurrentZoom();
373373
switch (data.getTransparencyType ()) {
374374
case SWT.TRANSPARENCY_ALPHA:
375375
/*

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ int computeLeftMargin () {
283283
if ((style & (SWT.PUSH | SWT.TOGGLE)) == 0) return MARGIN;
284284
int margin = 0;
285285
if (image != null && text.length () != 0) {
286-
Rectangle bounds = image.getBoundsInPixels ();
286+
Rectangle bounds = DPIUtil.autoScaleBounds(image.getBounds(), this.getZoom(), 100);
287287
margin += bounds.width + MARGIN * 2;
288288
long oldFont = 0;
289289
long hDC = OS.GetDC (handle);
@@ -345,7 +345,7 @@ else if ((style & SWT.RIGHT) != 0) {
345345
boolean hasImage = image != null, hasText = true;
346346
if (hasImage) {
347347
if (image != null) {
348-
Rectangle rect = image.getBoundsInPixels ();
348+
Rectangle rect = DPIUtil.autoScaleBounds(image.getBounds(), this.getZoom(), 100);
349349
width = rect.width;
350350
if (hasText && text.length () != 0) {
351351
width += MARGIN * 2;
@@ -1378,11 +1378,12 @@ LRESULT wmNotifyChild (NMHDR hdr, long wParam, long lParam) {
13781378
GC gc = GC.win32_new (nmcd.hdc, data);
13791379

13801380
int margin = computeLeftMargin();
1381-
int imageWidth = image.getBoundsInPixels().width;
1381+
Rectangle imageBounds = DPIUtil.autoScaleBounds(image.getBounds(), this.getZoom(), 100);
1382+
int imageWidth = imageBounds.width;
13821383
left += (imageWidth + (isRadioOrCheck() ? 2 * MARGIN : MARGIN)); // for SWT.RIGHT_TO_LEFT right and left are inverted
13831384

13841385
int x = margin + (isRadioOrCheck() ? radioOrCheckTextPadding : 3);
1385-
int y = Math.max (0, (nmcd.bottom - image.getBoundsInPixels().height) / 2);
1386+
int y = Math.max (0, (nmcd.bottom - imageBounds.height) / 2);
13861387
gc.drawImage (image, DPIUtil.autoScaleDown(x), DPIUtil.autoScaleDown(y));
13871388
gc.dispose ();
13881389
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,7 +1160,7 @@ static long create32bitDIB (long hBitmap, int alpha, byte [] alphaData, int tran
11601160

11611161
static Image createIcon (Image image) {
11621162
Device device = image.getDevice ();
1163-
ImageData data = image.getImageData (DPIUtil.getDeviceZoom ());
1163+
ImageData data = image.getImageDataAtCurrentZoom();
11641164
if (data.alpha == -1 && data.alphaData == null) {
11651165
ImageData mask = data.getTransparencyMask ();
11661166
return new Image (device, data, mask);
@@ -2463,7 +2463,7 @@ Font getSystemFont (int zoom) {
24632463
this.systemFont = systemFont;
24642464
if (systemFont != null) {
24652465
this.lfSystemFont = systemFont.getFontData()[0].data;
2466-
}
2466+
}
24672467
}
24682468

24692469
return systemFont;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ static int checkStyle (int style) {
147147
return new Point (width, height);
148148
}
149149
if (isImageMode) {
150-
Rectangle rect = image.getBoundsInPixels();
150+
Rectangle rect = DPIUtil.autoScaleBounds(image.getBounds(), this.getZoom(), 100);
151151
width += rect.width;
152152
height += rect.height;
153153
} else {
@@ -553,7 +553,7 @@ void wmDrawChildImage(DRAWITEMSTRUCT struct) {
553553
int height = struct.bottom - struct.top;
554554
if (width == 0 || height == 0) return;
555555

556-
Rectangle imageRect = image.getBoundsInPixels ();
556+
Rectangle imageRect = DPIUtil.autoScaleBounds(image.getBounds(), getZoom(), 100);
557557

558558
int x = 0;
559559
if ((style & SWT.CENTER) != 0) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ int imageIndex (Image image) {
455455
*/
456456
if (image == null) return -1;
457457
if (imageList == null) {
458-
Rectangle bounds = image.getBoundsInPixels ();
458+
Rectangle bounds = DPIUtil.autoScaleBounds(image.getBounds(), this.getZoom(), 100);
459459
imageList = display.getImageList (style & SWT.RIGHT_TO_LEFT, bounds.width, bounds.height);
460460
int index = imageList.add (image);
461461
long hImageList = imageList.getHandle ();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,7 +1107,7 @@ void updateImages (boolean enabled) {
11071107
ImageList hotImageList = parent.getHotImageList ();
11081108
ImageList disabledImageList = parent.getDisabledImageList();
11091109
if (info.iImage == OS.I_IMAGENONE) {
1110-
Rectangle bounds = DPIUtil.autoScaleBounds(image.getBounds(), 100, getParent().getZoom());
1110+
Rectangle bounds = DPIUtil.autoScaleBounds(image.getBounds(), getParent().getZoom(), 100);
11111111
int listStyle = parent.style & SWT.RIGHT_TO_LEFT;
11121112
if (imageList == null) {
11131113
imageList = display.getImageListToolBar (listStyle, bounds.width, bounds.height);
@@ -1229,7 +1229,7 @@ private static void handleDPIChange(Widget widget, int newZoom, float scalingFac
12291229
Display display = item.getDisplay();
12301230
int listStyle = parent.style & SWT.RIGHT_TO_LEFT;
12311231

1232-
Rectangle bounds = DPIUtil.autoScaleBounds(image.getBounds(), 100, newZoom);
1232+
Rectangle bounds = DPIUtil.autoScaleBounds(image.getBounds(), newZoom, 100);
12331233
if (parent.getImageList() == null) {
12341234
parent.setImageList (display.getImageListToolBar (listStyle, bounds.width, bounds.height));
12351235
}

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3739,7 +3739,7 @@ boolean hitTestSelection (long hItem, int x, int y) {
37393739
int imageIndex (Image image, int index) {
37403740
if (image == null) return OS.I_IMAGENONE;
37413741
if (imageList == null) {
3742-
Rectangle bounds = image.getBoundsInPixels ();
3742+
Rectangle bounds = DPIUtil.autoScaleBounds(image.getBounds(), this.getZoom(), 100);
37433743
imageList = display.getImageList (style & SWT.RIGHT_TO_LEFT, bounds.width, bounds.height);
37443744
}
37453745
int imageIndex = imageList.indexOf (image);
@@ -3763,7 +3763,7 @@ int imageIndex (Image image, int index) {
37633763
int imageIndexHeader (Image image) {
37643764
if (image == null) return OS.I_IMAGENONE;
37653765
if (headerImageList == null) {
3766-
Rectangle bounds = image.getBoundsInPixels ();
3766+
Rectangle bounds = DPIUtil.autoScaleBounds(image.getBounds(), this.getZoom(), 100);
37673767
headerImageList = display.getImageList (style & SWT.RIGHT_TO_LEFT, bounds.width, bounds.height);
37683768
int index = headerImageList.indexOf (image);
37693769
if (index == -1) index = headerImageList.add (image);
@@ -7540,7 +7540,7 @@ LRESULT wmNotifyChild (NMHDR hdr, long wParam, long lParam) {
75407540
}
75417541
case OS.NM_CUSTOMDRAW: {
75427542
if (hdr.hwndFrom == hwndHeader) break;
7543-
if (hooks (SWT.MeasureItem)) {
7543+
if (hooks (SWT.MeasureItem)) {
75447544
if (hwndHeader == 0) createParent ();
75457545
}
75467546
if (!customDraw && findImageControl () == null) {
@@ -7926,9 +7926,10 @@ LRESULT wmNotifyHeader (NMHDR hdr, long wParam, long lParam) {
79267926
GCData data = new GCData();
79277927
data.device = display;
79287928
GC gc = GC.win32_new (nmcd.hdc, data);
7929-
int y = Math.max (0, (nmcd.bottom - columns[i].image.getBoundsInPixels().height) / 2);
7929+
Rectangle imageBounds = DPIUtil.autoScaleBounds(columns[i].image.getBounds(), this.getZoom(), 100);
7930+
int y = Math.max (0, (nmcd.bottom - imageBounds.height) / 2);
79307931
gc.drawImage (columns[i].image, DPIUtil.autoScaleDown(x), DPIUtil.autoScaleDown(y));
7931-
x += columns[i].image.getBoundsInPixels().width + 12;
7932+
x += imageBounds.width + 12;
79327933
gc.dispose ();
79337934
}
79347935

0 commit comments

Comments
 (0)