Skip to content

Commit 2e13c10

Browse files
committed
[win32] ImageList#getImageSize should always return value in points
This commit clarifies the contract of ImageList#getImageSize in the windows implementation to always return a value in points. Historically it returned values in pixel. This worked until recent changes in ImageList to support and handle multiple OS image list handles to support monitor specific scaling. Because of the change the ImageList size in pixels depends on the target zoom the ImageList will be used with. Because of this the method is adapted to return a value in points. All callers of this method are adapted accordingly to scale the value to pixels matching the zoom of the Widget if necessary.
1 parent 15f6cc4 commit 2e13c10

File tree

7 files changed

+39
-35
lines changed

7 files changed

+39
-35
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,10 +359,14 @@ private void addPlaceholderImageToImageList(long imageListHandle, int bitmapWidt
359359
OS.ReleaseDC(0, hDC);
360360
}
361361

362+
/**
363+
*
364+
* {@return size of Images in the ImageList in points}
365+
*/
362366
public Point getImageSize() {
363367
int [] cx = new int [1], cy = new int [1];
364368
OS.ImageList_GetIconSize (handle, cx, cy);
365-
return new Point (cx [0], cy [0]);
369+
return Win32DPIUtils.pixelToPoint(new Point (cx [0], cy [0]), zoom);
366370
}
367371

368372
public int indexOf (Image image) {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2062,7 +2062,7 @@ ImageList getImageList (int style, int width, int height, int zoom) {
20622062
imageList = newList;
20632063
}
20642064

2065-
ImageList list = new ImageList (style, width, height, zoom);
2065+
ImageList list = new ImageList (style, Win32DPIUtils.pointToPixel(width, zoom), Win32DPIUtils.pointToPixel(height, zoom), zoom);
20662066
imageList [i] = list;
20672067
list.addRef();
20682068
return list;
@@ -2092,7 +2092,7 @@ ImageList getImageListToolBar (int style, int width, int height, int zoom) {
20922092
toolImageList = newList;
20932093
}
20942094

2095-
ImageList list = new ImageList (style, width, height, zoom);
2095+
ImageList list = new ImageList (style, Win32DPIUtils.pointToPixel(width, zoom), Win32DPIUtils.pointToPixel(height, zoom), zoom);
20962096
toolImageList [i] = list;
20972097
list.addRef();
20982098
return list;
@@ -2122,7 +2122,7 @@ ImageList getImageListToolBarDisabled (int style, int width, int height, int zoo
21222122
toolDisabledImageList = newList;
21232123
}
21242124

2125-
ImageList list = new ImageList (style, width, height, zoom);
2125+
ImageList list = new ImageList (style, Win32DPIUtils.pointToPixel(width, zoom), Win32DPIUtils.pointToPixel(height, zoom), zoom);
21262126
toolDisabledImageList [i] = list;
21272127
list.addRef();
21282128
return list;
@@ -2152,7 +2152,7 @@ ImageList getImageListToolBarHot (int style, int width, int height, int zoom) {
21522152
toolHotImageList = newList;
21532153
}
21542154

2155-
ImageList list = new ImageList (style, width, height, zoom);
2155+
ImageList list = new ImageList (style, Win32DPIUtils.pointToPixel(width, zoom), Win32DPIUtils.pointToPixel(height, zoom), zoom);
21562156
toolHotImageList [i] = list;
21572157
list.addRef();
21582158
return list;

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -455,8 +455,8 @@ int imageIndex (Image image) {
455455
*/
456456
if (image == null) return -1;
457457
if (imageList == null) {
458-
Rectangle bounds = Win32DPIUtils.scaleBounds(image.getBounds(), this.getZoom(), 100);
459-
imageList = display.getImageList (style & SWT.RIGHT_TO_LEFT, bounds.width, bounds.height, this.getZoom());
458+
Rectangle boundsInPoints = image.getBounds();
459+
imageList = display.getImageList (style & SWT.RIGHT_TO_LEFT, boundsInPoints.width, boundsInPoints.height, getZoom());
460460
int index = imageList.add (image);
461461
long hImageList = imageList.getHandle(getZoom());
462462
OS.SendMessage (handle, OS.TCM_SETIMAGELIST, 0, hImageList);
@@ -837,9 +837,9 @@ void updateOrientation () {
837837
OS.SetWindowPos (handle, 0, 0, 0, width - 1, height - 1, OS.SWP_NOMOVE | OS.SWP_NOZORDER);
838838
OS.SetWindowPos (handle, 0, 0, 0, width, height, OS.SWP_NOMOVE | OS.SWP_NOZORDER);
839839
if (imageList != null) {
840-
Point size = imageList.getImageSize ();
840+
Point sizeInPoints = imageList.getImageSize();
841841
display.releaseImageList (imageList);
842-
imageList = display.getImageList (style & SWT.RIGHT_TO_LEFT, size.x, size.y, this.getZoom());
842+
imageList = display.getImageList (style & SWT.RIGHT_TO_LEFT, sizeInPoints.x, sizeInPoints.y, this.getZoom());
843843
long hImageList = imageList.getHandle(getZoom());
844844
OS.SendMessage (handle, OS.TCM_SETIMAGELIST, 0, hImageList);
845845
TCITEM tcItem = new TCITEM ();

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2849,8 +2849,8 @@ int imageIndex (Image image, int column) {
28492849
setSubImagesVisible (true);
28502850
}
28512851
if (imageList == null) {
2852-
Rectangle bounds = Win32DPIUtils.scaleBounds(image.getBounds(), this.getZoom(), 100);
2853-
imageList = display.getImageList (style & SWT.RIGHT_TO_LEFT, bounds.width, bounds.height, getZoom());
2852+
Rectangle boundsInPoints = image.getBounds();
2853+
imageList = display.getImageList (style & SWT.RIGHT_TO_LEFT, boundsInPoints.width, boundsInPoints.height, getZoom());
28542854
int index = imageList.indexOf (image);
28552855
if (index == -1) index = imageList.add (image);
28562856
long hImageList = imageList.getHandle(getZoom());
@@ -2889,8 +2889,8 @@ int imageIndex (Image image, int column) {
28892889
int imageIndexHeader (Image image) {
28902890
if (image == null) return OS.I_IMAGENONE;
28912891
if (headerImageList == null) {
2892-
Rectangle bounds = Win32DPIUtils.scaleBounds(image.getBounds(), this.getZoom(), 100);
2893-
headerImageList = display.getImageList (style & SWT.RIGHT_TO_LEFT, bounds.width, bounds.height, getZoom());
2892+
Rectangle boundsInPoints = image.getBounds();
2893+
headerImageList = display.getImageList (style & SWT.RIGHT_TO_LEFT, boundsInPoints.width, boundsInPoints.height, getZoom());
28942894
int index = headerImageList.indexOf (image);
28952895
if (index == -1) index = headerImageList.add (image);
28962896
long hImageList = headerImageList.getHandle(getZoom());
@@ -5576,9 +5576,9 @@ void updateOrientation () {
55765576
}
55775577
if ((style & SWT.CHECK) != 0) fixCheckboxImageListColor (false);
55785578
if (imageList != null) {
5579-
Point size = imageList.getImageSize ();
5579+
Point sizeInPoints = imageList.getImageSize();
55805580
display.releaseImageList (imageList);
5581-
imageList = display.getImageList (style & SWT.RIGHT_TO_LEFT, size.x, size.y, getZoom());
5581+
imageList = display.getImageList (style & SWT.RIGHT_TO_LEFT, sizeInPoints.x, sizeInPoints.y, getZoom());
55825582
int count = (int)OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
55835583
for (int i = 0; i < count; i++) {
55845584
TableItem item = _getItem (i, false);
@@ -5595,9 +5595,9 @@ void updateOrientation () {
55955595
}
55965596
if (hwndHeader != 0) {
55975597
if (headerImageList != null) {
5598-
Point size = headerImageList.getImageSize ();
5598+
Point sizeInPoints = headerImageList.getImageSize();
55995599
display.releaseImageList (headerImageList);
5600-
headerImageList = display.getImageList (style & SWT.RIGHT_TO_LEFT, size.x, size.y, getZoom());
5600+
headerImageList = display.getImageList (style & SWT.RIGHT_TO_LEFT, sizeInPoints.x, sizeInPoints.y, getZoom());
56015601
if (columns != null) {
56025602
for (int i = 0; i < columns.length; i++) {
56035603
TableColumn column = columns [i];
@@ -7297,7 +7297,7 @@ LRESULT wmNotifyToolTip (NMTTCUSTOMDRAW nmcd, long lParam) {
72977297
if (image != null) {
72987298
Rectangle rect = Win32DPIUtils.pointToPixel(image.getBounds(), getZoom());
72997299
RECT imageRect = item.getBounds (pinfo.iItem, pinfo.iSubItem, false, true, false, false, hDC);
7300-
Point size = imageList == null ? new Point (rect.width, rect.height) : imageList.getImageSize ();
7300+
Point size = imageList == null ? new Point (rect.width, rect.height) : Win32DPIUtils.pointToPixel(imageList.getImageSize(), getZoom());
73017301
int y = imageRect.top + Math.max (0, (imageRect.bottom - imageRect.top - size.y) / 2);
73027302
int zoom = getZoom();
73037303
rect = Win32DPIUtils.pixelToPoint(rect, zoom);

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,10 +1272,10 @@ String toolTipText (NMTTDISPINFO hdr) {
12721272
void updateOrientation () {
12731273
super.updateOrientation ();
12741274
if (imageList != null) {
1275-
Point size = imageList.getImageSize ();
1276-
ImageList newImageList = display.getImageListToolBar (style & SWT.RIGHT_TO_LEFT, size.x, size.y, getZoom());
1277-
ImageList newHotImageList = display.getImageListToolBarHot (style & SWT.RIGHT_TO_LEFT, size.x, size.y, getZoom());
1278-
ImageList newDisabledImageList = display.getImageListToolBarDisabled (style & SWT.RIGHT_TO_LEFT, size.x, size.y, getZoom());
1275+
Point sizeInPoints = imageList.getImageSize();
1276+
ImageList newImageList = display.getImageListToolBar (style & SWT.RIGHT_TO_LEFT, sizeInPoints.x, sizeInPoints.y, getZoom());
1277+
ImageList newHotImageList = display.getImageListToolBarHot (style & SWT.RIGHT_TO_LEFT, sizeInPoints.x, sizeInPoints.y, getZoom());
1278+
ImageList newDisabledImageList = display.getImageListToolBarDisabled (style & SWT.RIGHT_TO_LEFT, sizeInPoints.x, sizeInPoints.y, getZoom());
12791279
TBBUTTONINFO info = new TBBUTTONINFO ();
12801280
info.cbSize = TBBUTTONINFO.sizeof;
12811281
info.dwMask = OS.TBIF_IMAGE;

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,16 +1103,16 @@ void updateImages (boolean enabled) {
11031103
ImageList hotImageList = parent.getHotImageList ();
11041104
ImageList disabledImageList = parent.getDisabledImageList();
11051105
if (info.iImage == OS.I_IMAGENONE) {
1106-
Rectangle bounds = Win32DPIUtils.scaleBounds(image.getBounds(), getParent().getZoom(), 100);
1106+
Rectangle boundsInPoints = image.getBounds();
11071107
int listStyle = parent.style & SWT.RIGHT_TO_LEFT;
11081108
if (imageList == null) {
1109-
imageList = display.getImageListToolBar (listStyle, bounds.width, bounds.height, getZoom());
1109+
imageList = display.getImageListToolBar (listStyle, boundsInPoints.width, boundsInPoints.height, getZoom());
11101110
}
11111111
if (disabledImageList == null) {
1112-
disabledImageList = display.getImageListToolBarDisabled (listStyle, bounds.width, bounds.height, getZoom());
1112+
disabledImageList = display.getImageListToolBarDisabled (listStyle, boundsInPoints.width, boundsInPoints.height, getZoom());
11131113
}
11141114
if (hotImageList == null) {
1115-
hotImageList = display.getImageListToolBarHot (listStyle, bounds.width, bounds.height, getZoom());
1115+
hotImageList = display.getImageListToolBarHot (listStyle, boundsInPoints.width, boundsInPoints.height, getZoom());
11161116
}
11171117
Image disabled = disabledImage;
11181118
if (disabledImage == null) {

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3058,7 +3058,7 @@ public boolean getHeaderVisible () {
30583058
}
30593059

30603060
Point getImageSize () {
3061-
if (imageList != null) return imageList.getImageSize ();
3061+
if (imageList != null) return Win32DPIUtils.pointToPixel(imageList.getImageSize(), getZoom());
30623062
return new Point (0, getItemHeightInPixels ());
30633063
}
30643064

@@ -3740,8 +3740,8 @@ boolean hitTestSelection (long hItem, int x, int y) {
37403740
int imageIndex (Image image, int index) {
37413741
if (image == null) return OS.I_IMAGENONE;
37423742
if (imageList == null) {
3743-
Rectangle bounds = Win32DPIUtils.scaleBounds(image.getBounds(), this.getZoom(), 100);
3744-
imageList = display.getImageList (style & SWT.RIGHT_TO_LEFT, bounds.width, bounds.height, getZoom());
3743+
Rectangle boundsInPoints = image.getBounds();
3744+
imageList = display.getImageList (style & SWT.RIGHT_TO_LEFT, boundsInPoints.width, boundsInPoints.height, getZoom());
37453745
}
37463746
int imageIndex = imageList.indexOf (image);
37473747
if (imageIndex == -1) imageIndex = imageList.add (image);
@@ -3764,8 +3764,8 @@ int imageIndex (Image image, int index) {
37643764
int imageIndexHeader (Image image) {
37653765
if (image == null) return OS.I_IMAGENONE;
37663766
if (headerImageList == null) {
3767-
Rectangle bounds = Win32DPIUtils.scaleBounds(image.getBounds(), this.getZoom(), 100);
3768-
headerImageList = display.getImageList (style & SWT.RIGHT_TO_LEFT, bounds.width, bounds.height, getZoom());
3767+
Rectangle boundsInPoints = image.getBounds();
3768+
headerImageList = display.getImageList (style & SWT.RIGHT_TO_LEFT, boundsInPoints.width, boundsInPoints.height, getZoom());
37693769
int index = headerImageList.indexOf (image);
37703770
if (index == -1) index = headerImageList.add (image);
37713771
long hImageList = headerImageList.getHandle(getZoom());
@@ -5791,9 +5791,9 @@ void updateOrientation () {
57915791
}
57925792
if ((style & SWT.CHECK) != 0) setCheckboxImageList ();
57935793
if (imageList != null) {
5794-
Point size = imageList.getImageSize ();
5794+
Point sizeInPoints = imageList.getImageSize();
57955795
display.releaseImageList (imageList);
5796-
imageList = display.getImageList (style & SWT.RIGHT_TO_LEFT, size.x, size.y, getZoom());
5796+
imageList = display.getImageList (style & SWT.RIGHT_TO_LEFT, sizeInPoints.x, sizeInPoints.y, getZoom());
57975797
for (TreeItem item : items) {
57985798
if (item != null) {
57995799
Image image = item.image;
@@ -5808,9 +5808,9 @@ void updateOrientation () {
58085808
}
58095809
if (hwndHeader != 0) {
58105810
if (headerImageList != null) {
5811-
Point size = headerImageList.getImageSize ();
5811+
Point sizeInPoints = headerImageList.getImageSize();
58125812
display.releaseImageList (headerImageList);
5813-
headerImageList = display.getImageList (style & SWT.RIGHT_TO_LEFT, size.x, size.y, getZoom());
5813+
headerImageList = display.getImageList (style & SWT.RIGHT_TO_LEFT, sizeInPoints.x, sizeInPoints.y, getZoom());
58145814
if (columns != null) {
58155815
for (int i = 0; i < columns.length; i++) {
58165816
TreeColumn column = columns[i];

0 commit comments

Comments
 (0)