Skip to content

Commit 208b5dc

Browse files
committed
[Win32] Make ImageList retrieval from Display consider zoom
When requesting an ImageList from a Display, the zoom is currently not considered when scanning through the existing image lists for a matching one. This can lead to an image list with a wrong zoom being used, such that the contained image handles are not properly fitting in size and thus need to be scaled. This changes includes the zoom into the identification of whether one of a Display's image lists fits to the requested properties or not. To this end, the whole validation logic is moved to the ImageList class itself, such that it's style and zoom do not need to be exposed unnecessarily.
1 parent 1fe5903 commit 208b5dc

File tree

2 files changed

+17
-28
lines changed

2 files changed

+17
-28
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -331,10 +331,6 @@ public Image get (int index) {
331331
return images [index];
332332
}
333333

334-
public int getStyle () {
335-
return style;
336-
}
337-
338334
public long getHandle(int targetZoom) {
339335
if (!zoomToHandle.containsKey(targetZoom)) {
340336
int scaledWidth = DPIUtil.pointToPixel(DPIUtil.pixelToPoint(width, this.zoom), targetZoom);
@@ -374,6 +370,11 @@ public Point getImageSize() {
374370
return Win32DPIUtils.pixelToPointAsSize(new Point (cx [0], cy [0]), zoom);
375371
}
376372

373+
public boolean isFittingFor(int style, int width, int height, int zoom) {
374+
Point imageSize = getImageSize();
375+
return this.style == style && imageSize.x == width && imageSize.y == height && this.zoom == zoom;
376+
}
377+
377378
public int indexOf (Image image) {
378379
int count = OS.ImageList_GetImageCount (handle);
379380
for (int i=0; i<count; i++) {

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

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2045,12 +2045,9 @@ ImageList getImageList (int style, int width, int height, int zoom) {
20452045
while (i < length) {
20462046
ImageList list = imageList [i];
20472047
if (list == null) break;
2048-
Point size = list.getImageSize();
2049-
if (size.x == width && size.y == height) {
2050-
if (list.getStyle () == style) {
2051-
list.addRef();
2052-
return list;
2053-
}
2048+
if (list.isFittingFor(style, width, height, zoom)) {
2049+
list.addRef();
2050+
return list;
20542051
}
20552052
i++;
20562053
}
@@ -2075,12 +2072,9 @@ ImageList getImageListToolBar (int style, int width, int height, int zoom) {
20752072
while (i < length) {
20762073
ImageList list = toolImageList [i];
20772074
if (list == null) break;
2078-
Point size = list.getImageSize();
2079-
if (size.x == width && size.y == height) {
2080-
if (list.getStyle () == style) {
2081-
list.addRef();
2082-
return list;
2083-
}
2075+
if (list.isFittingFor(style, width, height, zoom)) {
2076+
list.addRef();
2077+
return list;
20842078
}
20852079
i++;
20862080
}
@@ -2105,12 +2099,9 @@ ImageList getImageListToolBarDisabled (int style, int width, int height, int zoo
21052099
while (i < length) {
21062100
ImageList list = toolDisabledImageList [i];
21072101
if (list == null) break;
2108-
Point size = list.getImageSize();
2109-
if (size.x == width && size.y == height) {
2110-
if (list.getStyle () == style) {
2111-
list.addRef();
2112-
return list;
2113-
}
2102+
if (list.isFittingFor(style, width, height, zoom)) {
2103+
list.addRef();
2104+
return list;
21142105
}
21152106
i++;
21162107
}
@@ -2135,12 +2126,9 @@ ImageList getImageListToolBarHot (int style, int width, int height, int zoom) {
21352126
while (i < length) {
21362127
ImageList list = toolHotImageList [i];
21372128
if (list == null) break;
2138-
Point size = list.getImageSize();
2139-
if (size.x == width && size.y == height) {
2140-
if (list.getStyle () == style) {
2141-
list.addRef();
2142-
return list;
2143-
}
2129+
if (list.isFittingFor(style, width, height, zoom)) {
2130+
list.addRef();
2131+
return list;
21442132
}
21452133
i++;
21462134
}

0 commit comments

Comments
 (0)