Skip to content

Commit c852174

Browse files
Image type SWT.ICON loses its type during re-scale
Image initialized as SWT.ICON in org.eclipse.swt.graphics.Image.Image(Device, ImageData, ImageData) loses its "Icon" properties i.e. type, mask etc. when handle for different zoom level is requested. Now implementing correct init method when the handle is requested for image type ICON.
1 parent 4a201e2 commit c852174

File tree

2 files changed

+24
-3
lines changed
  • bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics
  • tests/org.eclipse.swt.tests.win32/JUnit Tests/org/eclipse/swt/graphics

2 files changed

+24
-3
lines changed

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,11 @@ private ImageHandle getImageMetadata(int zoom) {
783783
} else {
784784
ImageData resizedData = getImageData(zoom);
785785
ImageData newData = adaptImageDataIfDisabledOrGray(resizedData);
786-
init(newData, zoom);
786+
if(type == SWT.ICON) {
787+
init(this.device, this, newData, newData.getTransparencyMask(), zoom);
788+
} else {
789+
init(newData, zoom);
790+
}
787791
init();
788792
}
789793
return zoomLevelToImageHandle.get(zoom);

tests/org.eclipse.swt.tests.win32/JUnit Tests/org/eclipse/swt/graphics/ImageWin32Tests.java

+19-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616

1717
import static org.junit.Assert.assertEquals;
1818
import static org.junit.Assert.assertNotEquals;
19+
import static org.junit.Assert.fail;
1920

21+
import org.eclipse.swt.SWT;
2022
import org.eclipse.swt.internal.DPIUtil;
2123
import org.eclipse.swt.widgets.Display;
2224
import org.junit.Before;
@@ -63,5 +65,20 @@ public void testImageShouldHaveDimesionAsPerZoomLevel() {
6365
} finally {
6466
image.dispose();
6567
}
66-
}
67-
}
68+
}
69+
70+
@Test
71+
public void testImageIconTypeShouldNotChangeAfterCallingGetHandleForDifferentZoom() {
72+
Image image = new Image(display, 10, 10);
73+
int iconTypeAfter = SWT.DEFAULT;
74+
try {
75+
ImageData mask = image.getImageData().getTransparencyMask();
76+
Image icon = new Image(display, image.getImageData(), mask);
77+
Image.win32_getHandle(icon, 200);
78+
iconTypeAfter = icon.type;
79+
} catch (Exception e) {
80+
fail("test image could not be initialized: " + e);
81+
}
82+
assertEquals("Image type should stay to SWT.ICON", SWT.ICON, iconTypeAfter);
83+
}
84+
}

0 commit comments

Comments
 (0)