From 8f7710166652509d380474ede9759f4fef8b4d4f Mon Sep 17 00:00:00 2001 From: Amartya Parijat Date: Mon, 15 Apr 2024 17:11:48 +0200 Subject: [PATCH] Multi zoom level support for Image for win32 This commit implements the mean to provide different handles for an Image at different zoom levels which can be consumed by the clients. Contributes to #62 and #127 --- .../win32/org/eclipse/swt/dnd/DragSource.java | 2 +- .../org/eclipse/swt/graphics/Cursor.java | 3 +- .../win32/org/eclipse/swt/graphics/GC.java | 34 ++- .../win32/org/eclipse/swt/graphics/Image.java | 233 ++++++++++-------- .../org/eclipse/swt/internal/ImageList.java | 16 +- .../win32/org/eclipse/swt/widgets/Button.java | 4 +- .../win32/org/eclipse/swt/widgets/Caret.java | 4 +- .../org/eclipse/swt/widgets/Control.java | 10 +- .../org/eclipse/swt/widgets/Decorations.java | 8 +- .../org/eclipse/swt/widgets/Display.java | 29 ++- .../win32/org/eclipse/swt/widgets/Label.java | 2 +- .../win32/org/eclipse/swt/widgets/Menu.java | 2 +- .../org/eclipse/swt/widgets/MenuItem.java | 2 +- .../org/eclipse/swt/widgets/TabFolder.java | 4 +- .../win32/org/eclipse/swt/widgets/Table.java | 14 +- .../org/eclipse/swt/widgets/TaskItem.java | 13 +- .../org/eclipse/swt/widgets/ToolBar.java | 6 +- .../org/eclipse/swt/widgets/ToolItem.java | 23 +- .../org/eclipse/swt/widgets/TrayItem.java | 4 +- .../win32/org/eclipse/swt/widgets/Tree.java | 8 +- .../org/eclipse/swt/widgets/TreeColumn.java | 2 +- .../org/eclipse/swt/widgets/TreeItem.java | 8 - 22 files changed, 216 insertions(+), 215 deletions(-) diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/win32/org/eclipse/swt/dnd/DragSource.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/win32/org/eclipse/swt/dnd/DragSource.java index 4f76b745a0e..4de5e1132bc 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/win32/org/eclipse/swt/dnd/DragSource.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/win32/org/eclipse/swt/dnd/DragSource.java @@ -491,7 +491,7 @@ private void drag(Event dragEvent) { hwndDrag = 0; topControl = null; if (image != null) { - imagelist = new ImageList(SWT.NONE); + imagelist = new ImageList(SWT.NONE, DPIUtil.getZoomForAutoscaleProperty(nativeZoom)); imagelist.add(image); topControl = control.getShell(); /* diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Cursor.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Cursor.java index d742fc314bb..acf71bfb770 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Cursor.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Cursor.java @@ -15,6 +15,7 @@ import org.eclipse.swt.*; +import org.eclipse.swt.internal.*; import org.eclipse.swt.internal.win32.*; /** @@ -300,7 +301,7 @@ public Cursor(Device device, ImageData source, int hotspotX, int hotspotY) { if (hMask == 0) SWT.error(SWT.ERROR_NO_HANDLES); } else { ImageData mask = source.getTransparencyMask(); - long [] result = Image.init(this.device, null, source, mask); + long [] result = Image.init(this.device, null, source, mask, DPIUtil.getDeviceZoom()); hBitmap = result[0]; hMask = result[1]; } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/GC.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/GC.java index 682521bf528..7c6d48d8fba 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/GC.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/GC.java @@ -468,7 +468,7 @@ void copyAreaInPixels(Image image, int x, int y) { /* Copy the bitmap area */ Rectangle rect = image.getBoundsInPixels(); long memHdc = OS.CreateCompatibleDC(handle); - long hOldBitmap = OS.SelectObject(memHdc, image.handle); + long hOldBitmap = OS.SelectObject(memHdc, Image.win32_getHandle(image, getDeviceZoom())); OS.BitBlt(memHdc, 0, 0, rect.width, rect.height, handle, x, y, OS.SRCCOPY); OS.SelectObject(memHdc, hOldBitmap); OS.DeleteDC(memHdc); @@ -1000,11 +1000,9 @@ public void drawImage (Image image, int srcX, int srcY, int srcWidth, int srcHei } void drawImage(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple) { - /* Refresh Image as per zoom level, if required. */ - srcImage.handleDPIChange(DPIUtil.getNativeDeviceZoom()); if (data.gdipGraphics != 0) { //TODO - cache bitmap - long [] gdipImage = srcImage.createGdipImage(); + long [] gdipImage = srcImage.createGdipImage(getDeviceZoom()); long img = gdipImage[0]; int imgWidth = Gdip.Image_GetWidth(img); int imgHeight = Gdip.Image_GetHeight(img); @@ -1092,14 +1090,14 @@ void drawIcon(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, i /* Simple case: no stretching, entire icon */ if (simple && technology != OS.DT_RASPRINTER && drawIcon) { if (offsetX != 0 || offsetY != 0) OS.SetWindowOrgEx(handle, 0, 0, null); - OS.DrawIconEx(handle, destX - offsetX, destY - offsetY, srcImage.handle, 0, 0, 0, 0, flags); + OS.DrawIconEx(handle, destX - offsetX, destY - offsetY, Image.win32_getHandle(srcImage, getDeviceZoom()), 0, 0, 0, 0, flags); if (offsetX != 0 || offsetY != 0) OS.SetWindowOrgEx(handle, offsetX, offsetY, null); return; } /* Get the icon info */ ICONINFO srcIconInfo = new ICONINFO(); - OS.GetIconInfo(srcImage.handle, srcIconInfo); + OS.GetIconInfo(Image.win32_getHandle(srcImage, getDeviceZoom()), srcIconInfo); /* Get the icon width and height */ long hBitmap = srcIconInfo.hbmColor; @@ -1125,7 +1123,7 @@ void drawIcon(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, i } else if (simple && technology != OS.DT_RASPRINTER) { /* Simple case: no stretching, entire icon */ if (offsetX != 0 || offsetY != 0) OS.SetWindowOrgEx(handle, 0, 0, null); - OS.DrawIconEx(handle, destX - offsetX, destY - offsetY, srcImage.handle, 0, 0, 0, 0, flags); + OS.DrawIconEx(handle, destX - offsetX, destY - offsetY, Image.win32_getHandle(srcImage, getDeviceZoom()), 0, 0, 0, 0, flags); if (offsetX != 0 || offsetY != 0) OS.SetWindowOrgEx(handle, offsetX, offsetY, null); } else { /* Create the icon info and HDC's */ @@ -1200,7 +1198,7 @@ void drawIcon(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, i void drawBitmap(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple) { BITMAP bm = new BITMAP(); - OS.GetObject(srcImage.handle, BITMAP.sizeof, bm); + OS.GetObject(Image.win32_getHandle(srcImage, getDeviceZoom()), BITMAP.sizeof, bm); int imgWidth = bm.bmWidth; int imgHeight = bm.bmHeight; if (simple) { @@ -1235,7 +1233,7 @@ void drawBitmap(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, drawBitmapColor(srcImage, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple); } if (mustRestore) { - long hOldBitmap = OS.SelectObject(memGC.handle, srcImage.handle); + long hOldBitmap = OS.SelectObject(memGC.handle, Image.win32_getHandle(srcImage, getDeviceZoom())); memGC.data.hNullBitmap = hOldBitmap; } } @@ -1248,7 +1246,7 @@ void drawBitmapAlpha(Image srcImage, int srcX, int srcY, int srcWidth, int srcHe int caps = OS.GetDeviceCaps(handle, OS.SHADEBLENDCAPS); if (caps != 0) { long srcHdc = OS.CreateCompatibleDC(handle); - long oldSrcBitmap = OS.SelectObject(srcHdc, srcImage.handle); + long oldSrcBitmap = OS.SelectObject(srcHdc, Image.win32_getHandle(srcImage, getDeviceZoom())); long memDib = Image.createDIB(srcWidth, srcHeight, 32); if (memDib == 0) SWT.error(SWT.ERROR_NO_HANDLES); long memHdc = OS.CreateCompatibleDC(handle); @@ -1289,7 +1287,7 @@ void drawBitmapAlpha(Image srcImage, int srcX, int srcY, int srcWidth, int srcHe BLENDFUNCTION blend = new BLENDFUNCTION(); blend.BlendOp = OS.AC_SRC_OVER; long srcHdc = OS.CreateCompatibleDC(handle); - long oldSrcBitmap = OS.SelectObject(srcHdc, srcImage.handle); + long oldSrcBitmap = OS.SelectObject(srcHdc, Image.win32_getHandle(srcImage, getDeviceZoom())); blend.SourceConstantAlpha = (byte)sourceAlpha; blend.AlphaFormat = OS.AC_SRC_ALPHA; OS.AlphaBlend(handle, destX, destY, destWidth, destHeight, srcHdc, srcX, srcY, srcWidth, srcHeight, blend); @@ -1322,7 +1320,7 @@ void drawBitmapAlpha(Image srcImage, int srcX, int srcY, int srcWidth, int srcHe /* Create resources */ long srcHdc = OS.CreateCompatibleDC(handle); - long oldSrcBitmap = OS.SelectObject(srcHdc, srcImage.handle); + long oldSrcBitmap = OS.SelectObject(srcHdc, Image.win32_getHandle(srcImage, getDeviceZoom())); long memHdc = OS.CreateCompatibleDC(handle); long memDib = Image.createDIB(Math.max(srcWidth, destWidth), Math.max(srcHeight, destHeight), 32); if (memDib == 0) SWT.error(SWT.ERROR_NO_HANDLES); @@ -1494,7 +1492,7 @@ void drawBitmapTransparent(Image srcImage, int srcX, int srcY, int srcWidth, int /* Find the RGB values for the transparent pixel. */ boolean isDib = bm.bmBits != 0; - long hBitmap = srcImage.handle; + long hBitmap = Image.win32_getHandle(srcImage, getDeviceZoom()); long srcHdc = OS.CreateCompatibleDC(handle); long oldSrcBitmap = OS.SelectObject(srcHdc, hBitmap); byte[] originalColors = null; @@ -1539,7 +1537,7 @@ void drawBitmapTransparent(Image srcImage, int srcX, int srcY, int srcWidth, int bmiHeader.biBitCount = bm.bmBitsPixel; byte[] bmi = new byte[BITMAPINFOHEADER.sizeof + numColors * 4]; OS.MoveMemory(bmi, bmiHeader, BITMAPINFOHEADER.sizeof); - OS.GetDIBits(srcHdc, srcImage.handle, 0, 0, null, bmi, OS.DIB_RGB_COLORS); + OS.GetDIBits(srcHdc, Image.win32_getHandle(srcImage, getDeviceZoom()), 0, 0, null, bmi, OS.DIB_RGB_COLORS); int offset = BITMAPINFOHEADER.sizeof + 4 * srcImage.transparentPixel; transRed = bmi[offset + 2] & 0xFF; transGreen = bmi[offset + 1] & 0xFF; @@ -1612,13 +1610,13 @@ void drawBitmapTransparent(Image srcImage, int srcX, int srcY, int srcWidth, int OS.DeleteObject(maskBitmap); } OS.SelectObject(srcHdc, oldSrcBitmap); - if (hBitmap != srcImage.handle) OS.DeleteObject(hBitmap); + if (hBitmap != Image.win32_getHandle(srcImage, getDeviceZoom())) OS.DeleteObject(hBitmap); OS.DeleteDC(srcHdc); } void drawBitmapColor(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple) { long srcHdc = OS.CreateCompatibleDC(handle); - long oldSrcBitmap = OS.SelectObject(srcHdc, srcImage.handle); + long oldSrcBitmap = OS.SelectObject(srcHdc, Image.win32_getHandle(srcImage, getDeviceZoom())); int dwRop = OS.GetROP2(handle) == OS.R2_XORPEN ? OS.SRCINVERT : OS.SRCCOPY; if (!simple && (srcWidth != destWidth || srcHeight != destHeight)) { int mode = OS.SetStretchBltMode(handle, OS.COLORONCOLOR); @@ -3884,7 +3882,7 @@ long identity() { Image image = data.image; if (image != null) { BITMAP bm = new BITMAP(); - OS.GetObject(image.handle, BITMAP.sizeof, bm); + OS.GetObject(Image.win32_getHandle(image, getDeviceZoom()), BITMAP.sizeof, bm); width = bm.bmWidth; } else { long hwnd = OS.WindowFromDC(handle); @@ -3930,7 +3928,7 @@ void init(Drawable drawable, GCData data, long hDC) { } Image image = data.image; if (image != null) { - data.hNullBitmap = OS.SelectObject(hDC, image.handle); + data.hNullBitmap = OS.SelectObject(hDC, Image.win32_getHandle(image, getDeviceZoom())); image.memGC = this; } int layout = data.layout; diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java index 4930c866fd5..52b81f332e2 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java @@ -139,7 +139,7 @@ public final class Image extends Resource implements Drawable { /** * Attribute to cache current native zoom level */ - private int currentNativeZoom = 100; + private int initialNativeZoom = 100; /** * width of the image @@ -156,12 +156,14 @@ public final class Image extends Resource implements Drawable { */ static final int DEFAULT_SCANLINE_PAD = 4; + private HashMap handleMap = new HashMap<>(); + /** * Prevents uninitialized instances from being created outside the package. */ Image (Device device) { super(device); - currentNativeZoom = DPIUtil.getNativeDeviceZoom(); + initialNativeZoom = DPIUtil.getNativeDeviceZoom(); } /** @@ -201,7 +203,7 @@ public final class Image extends Resource implements Drawable { */ public Image(Device device, int width, int height) { super(device); - currentNativeZoom = DPIUtil.getNativeDeviceZoom(); + initialNativeZoom = DPIUtil.getNativeDeviceZoom(); width = DPIUtil.autoScaleUp (width); height = DPIUtil.autoScaleUp (height); init(width, height); @@ -254,7 +256,7 @@ public Image(Device device, Image srcImage, int flag) { this.imageDataProvider = srcImage.imageDataProvider; this.imageFileNameProvider = srcImage.imageFileNameProvider; this.styleFlag = srcImage.styleFlag | flag; - currentNativeZoom = srcImage.currentNativeZoom; + initialNativeZoom = srcImage.initialNativeZoom; this.dataAtBaseZoom = srcImage.dataAtBaseZoom; switch (flag) { case SWT.IMAGE_COPY: { @@ -269,7 +271,7 @@ public Image(Device device, Image srcImage, int flag) { long hOldSrc = OS.SelectObject(hdcSource, srcImage.handle); BITMAP bm = new BITMAP(); OS.GetObject(srcImage.handle, BITMAP.sizeof, bm); - handle = OS.CreateCompatibleBitmap(hdcSource, rect.width, bm.bmBits != 0 ? -rect.height : rect.height); + setHandleForZoomLevel(OS.CreateCompatibleBitmap(hdcSource, rect.width, bm.bmBits != 0 ? -rect.height : rect.height), this.getZoom()); if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES); long hOldDest = OS.SelectObject(hdcDest, handle); OS.BitBlt(hdcDest, 0, 0, rect.width, rect.height, hdcSource, 0, 0, OS.SRCCOPY); @@ -284,7 +286,7 @@ public Image(Device device, Image srcImage, int flag) { transparentPixel = srcImage.transparentPixel; break; case SWT.ICON: - handle = OS.CopyImage(srcImage.handle, OS.IMAGE_ICON, rect.width, rect.height, 0); + setHandleForZoomLevel(OS.CopyImage(srcImage.handle, OS.IMAGE_ICON, rect.width, rect.height, 0), getZoom()); if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES); break; default: @@ -348,7 +350,7 @@ public Image(Device device, Image srcImage, int flag) { offset++; } } - init (newData); + init (newData, getZoom()); break; } case SWT.IMAGE_GRAY: { @@ -412,7 +414,7 @@ public Image(Device device, Image srcImage, int flag) { } } } - init (newData); + init (newData, getZoom()); break; } default: @@ -459,8 +461,8 @@ public Image(Device device, Image srcImage, int flag) { public Image(Device device, Rectangle bounds) { super(device); if (bounds == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - currentNativeZoom = DPIUtil.getNativeDeviceZoom(); - bounds = DPIUtil.autoScaleUp (bounds); + initialNativeZoom = DPIUtil.getNativeDeviceZoom(); + bounds = DPIUtil.autoScaleUp (bounds, getZoom()); init(bounds.width, bounds.height); init(); } @@ -491,10 +493,10 @@ public Image(Device device, Rectangle bounds) { public Image(Device device, ImageData data) { super(device); if (data == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - currentNativeZoom = DPIUtil.getNativeDeviceZoom(); + initialNativeZoom = DPIUtil.getNativeDeviceZoom(); this.dataAtBaseZoom = new ElementAtZoom<>(data, 100); data = DPIUtil.autoScaleUp(device, this.dataAtBaseZoom); - init(data); + init(data, getZoom()); init(); } @@ -535,12 +537,12 @@ public Image(Device device, ImageData source, ImageData mask) { if (source.width != mask.width || source.height != mask.height) { SWT.error(SWT.ERROR_INVALID_ARGUMENT); } - currentNativeZoom = DPIUtil.getNativeDeviceZoom(); + initialNativeZoom = DPIUtil.getNativeDeviceZoom(); this.dataAtBaseZoom = new ElementAtZoom<>(applyMask(source, ImageData.convertMask(mask)), 100); source = DPIUtil.autoScaleUp(device, source); mask = DPIUtil.autoScaleUp(device, mask); mask = ImageData.convertMask(mask); - init(this.device, this, source, mask); + init(this.device, this, source, mask, getZoom()); init(); } @@ -599,10 +601,10 @@ public Image(Device device, ImageData source, ImageData mask) { */ public Image (Device device, InputStream stream) { super(device); - currentNativeZoom = DPIUtil.getNativeDeviceZoom(); + initialNativeZoom = DPIUtil.getNativeDeviceZoom(); this.dataAtBaseZoom = new ElementAtZoom<>(new ImageData (stream), 100); ImageData data = DPIUtil.autoScaleUp(device, this.dataAtBaseZoom); - init(data); + init(data, getZoom()); init(); } @@ -641,10 +643,10 @@ public Image (Device device, InputStream stream) { public Image (Device device, String filename) { super(device); if (filename == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - currentNativeZoom = DPIUtil.getNativeDeviceZoom(); + initialNativeZoom = DPIUtil.getNativeDeviceZoom(); this.dataAtBaseZoom = new ElementAtZoom<>(new ImageData (filename), 100); ImageData data = DPIUtil.autoScaleUp(device, this.dataAtBaseZoom); - init(data); + init(data, getZoom()); init(); } @@ -680,14 +682,18 @@ public Image (Device device, String filename) { public Image(Device device, ImageFileNameProvider imageFileNameProvider) { super(device); this.imageFileNameProvider = imageFileNameProvider; - currentNativeZoom = DPIUtil.getNativeDeviceZoom(); + initialNativeZoom = DPIUtil.getNativeDeviceZoom(); ElementAtZoom fileName = DPIUtil.validateAndGetImagePathAtZoom (imageFileNameProvider, getZoom()); if (fileName.zoom() == getZoom()) { - initNative (fileName.element()); - if (this.handle == 0) init(new ImageData (fileName.element())); + long handle = initNative (fileName.element(), getZoom()); + if (handle == 0) { + init(new ImageData (fileName.element()), getZoom()); + } else { + setHandleForZoomLevel(handle, getZoom()); + } } else { ImageData resizedData = DPIUtil.autoScaleImageData (device, new ImageData (fileName.element()), fileName.zoom()); - init(resizedData); + init(resizedData, getZoom()); } init(); } @@ -724,69 +730,63 @@ public Image(Device device, ImageFileNameProvider imageFileNameProvider) { public Image(Device device, ImageDataProvider imageDataProvider) { super(device); this.imageDataProvider = imageDataProvider; - currentNativeZoom = DPIUtil.getNativeDeviceZoom(); + initialNativeZoom = DPIUtil.getNativeDeviceZoom(); ElementAtZoom data = DPIUtil.validateAndGetImageDataAtZoom(imageDataProvider, getZoom()); - ImageData resizedData = DPIUtil.autoScaleImageData(device, data.element(), data.zoom()); - init (resizedData); + ImageData resizedData = DPIUtil.autoScaleImageData(device, data.element(), getZoom(), data.zoom()); + init (resizedData, getZoom()); init(); } /** * Update zoom and refresh the Image based on the native zoom level, if required. * - * @param nativeZoom native zoom in % of the monitor on which the image is painted + * @param image the image to get the handle of + * @param deviceZoomLevel device zoom in % of the monitor on which the image is painted * * @return true if image is refreshed + * @since 3.126 */ -boolean handleDPIChange (int nativeZoom) { - int newZoom = DPIUtil.getZoomForAutoscaleProperty(nativeZoom); - int oldZoom = this.getZoom(); - boolean refreshed = false; - if (imageFileNameProvider != null) { - if (newZoom != oldZoom) { - ElementAtZoom filename = DPIUtil.validateAndGetImagePathAtZoom (imageFileNameProvider, newZoom); - if (filename.zoom() == newZoom) { - /* Release current native resources */ - destroy (); - initNative(filename.element()); - if (this.handle == 0) init(new ImageData (filename.element())); - init(); - refreshed = true; - } else { - /* Release current native resources */ - destroy (); - ImageData resizedData = DPIUtil.autoScaleImageData (device, new ImageData (filename.element()), filename.zoom()); - init(resizedData); - init (); - refreshed = true; - } - setCurrentNativeZoom(nativeZoom); - } - } else if (imageDataProvider != null) { - if (newZoom != oldZoom) { - ElementAtZoom data = DPIUtil.validateAndGetImageDataAtZoom (imageDataProvider, newZoom); +public static Long win32_getHandle (Image image, int deviceZoomLevel) { + if(image.isDisposed()) { + return image.handle; + } + if(image.handleMap.get(deviceZoomLevel) != null) { + return image.handleMap.get(deviceZoomLevel); + } + + if (image.imageFileNameProvider != null) { + ElementAtZoom imageCandidate = DPIUtil.validateAndGetImagePathAtZoom (image.imageFileNameProvider, deviceZoomLevel); + if (imageCandidate.zoom() == deviceZoomLevel) { /* Release current native resources */ - destroy (); - ImageData resizedData = DPIUtil.autoScaleImageData (device, data.element(), data.zoom()); - init(resizedData); - init(); - refreshed = true; - setCurrentNativeZoom(nativeZoom); + long handle = image.initNative(imageCandidate.element(), deviceZoomLevel); + if (handle == 0) image.init(new ImageData (imageCandidate.element()), deviceZoomLevel); + image.init(); + } else { + ImageData resizedData = DPIUtil.autoScaleImageData (image.device, new ImageData (imageCandidate.element()), deviceZoomLevel, imageCandidate.zoom()); + image.init(resizedData, deviceZoomLevel); + image.init (); } - } else if (this.dataAtBaseZoom != null) { // Resizing is only possible with a cached base image - if (newZoom != oldZoom) { - ImageData resizedData = getImageData(newZoom); - destroy (); - init(resizedData); - init(); - refreshed = true; - setCurrentNativeZoom(nativeZoom); + } else if (image.imageDataProvider != null) { + ElementAtZoom imageCandidate = DPIUtil.validateAndGetImageDataAtZoom (image.imageDataProvider, deviceZoomLevel); + ImageData resizedData = DPIUtil.autoScaleImageData (image.device, imageCandidate.element(), deviceZoomLevel, imageCandidate.zoom()); + image.init(resizedData, deviceZoomLevel); + image.init(); + } else { + if (image.dataAtBaseZoom == null && image.memGC == null) { + // Cache data at base zoom before refresh. + image.dataAtBaseZoom = new ElementAtZoom<>(image.getImageData(image.getZoom()), image.getZoom()); + } + if (image.dataAtBaseZoom != null) { + ImageData resizedData = image.getImageData(deviceZoomLevel); + image.init(resizedData, deviceZoomLevel); + image.init(); } } - return refreshed; + return image.handleMap.get(deviceZoomLevel); } -void initNative(String filename) { +long initNative(String filename, int zoom) { + long handle = 0; device.checkGDIP(); boolean gdip = true; /* @@ -814,7 +814,7 @@ void initNative(String filename) { this.type = SWT.ICON; long[] hicon = new long[1]; status = Gdip.Bitmap_GetHICON(bitmap, hicon); - this.handle = hicon[0]; + handle = hicon[0]; } else { this.type = SWT.BITMAP; int width = Gdip.Image_GetWidth(bitmap); @@ -823,11 +823,11 @@ void initNative(String filename) { switch (pixelFormat) { case Gdip.PixelFormat16bppRGB555: case Gdip.PixelFormat16bppRGB565: - this.handle = createDIB(width, height, 16); + handle = createDIB(width, height, 16); break; case Gdip.PixelFormat24bppRGB: case Gdip.PixelFormat32bppCMYK: - this.handle = createDIB(width, height, 24); + handle = createDIB(width, height, 24); break; case Gdip.PixelFormat32bppRGB: // These will lose either precision or transparency @@ -836,17 +836,17 @@ void initNative(String filename) { case Gdip.PixelFormat32bppPARGB: case Gdip.PixelFormat64bppARGB: case Gdip.PixelFormat64bppPARGB: - this.handle = createDIB(width, height, 32); + handle = createDIB(width, height, 32); break; } - if (this.handle != 0) { + if (handle != 0) { /* * This performs better than getting the bits with Bitmap.LockBits(), * but it cannot be used when there is transparency. */ long hDC = device.internal_new_GC(null); long srcHDC = OS.CreateCompatibleDC(hDC); - long oldSrcBitmap = OS.SelectObject(srcHDC, this.handle); + long oldSrcBitmap = OS.SelectObject(srcHDC, handle); long graphics = Gdip.Graphics_new(srcHDC); if (graphics != 0) { Rect rect = new Rect(); @@ -856,7 +856,7 @@ void initNative(String filename) { if (status != 0) { error = SWT.ERROR_INVALID_IMAGE; OS.DeleteObject(handle); - this.handle = 0; + handle = 0; } Gdip.Graphics_delete(graphics); } @@ -935,7 +935,8 @@ void initNative(String filename) { ImageData img = new ImageData(width, height, depth, paletteData, scanlinePad, data); img.transparentPixel = transparentPixel; img.alphaData = alphaData; - init(img); + init(img, zoom); + handle = handleMap.get(zoom); } Gdip.Bitmap_UnlockBits(bitmap, lockedBitmapData); } else { @@ -948,13 +949,19 @@ void initNative(String filename) { } Gdip.Bitmap_delete(bitmap); if (status == 0) { - if (this.handle == 0) SWT.error(error); + if (handle == 0) SWT.error(error); } } } + return handle; } long [] createGdipImage() { + return createGdipImage(this.getZoom()); +} + +long [] createGdipImage(Integer zoom) { + long handle = Image.win32_getHandle(this, zoom); switch (type) { case SWT.BITMAP: { BITMAP bm = new BITMAP(); @@ -1124,13 +1131,22 @@ void initNative(String filename) { @Override void destroy () { if (memGC != null) memGC.dispose(); - if (type == SWT.ICON) { - OS.DestroyIcon (handle); - } else { - OS.DeleteObject (handle); + destroyHandle(); + memGC = null; +} + +static int count = 0; + +private void destroyHandle () { + for (Long handle : handleMap.values()) { + if (type == SWT.ICON) { + OS.DestroyIcon (handle); + } else { + OS.DeleteObject (handle); + } } + handleMap.clear(); handle = 0; - memGC = null; } /** @@ -1348,7 +1364,9 @@ public ImageData getImageData() { * @since 3.106 */ public ImageData getImageData (int zoom) { - if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + if (isDisposed()) { + SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + } if (zoom == getZoom()) { return getImageDataAtCurrentZoom(); @@ -1699,7 +1717,7 @@ void init(int width, int height) { } type = SWT.BITMAP; long hDC = device.internal_new_GC(null); - handle = OS.CreateCompatibleBitmap(hDC, width, height); + setHandleForZoomLevel(OS.CreateCompatibleBitmap(hDC, width, height), getZoom()); /* * Feature in Windows. CreateCompatibleBitmap() may fail * for large images. The fix is to create a DIB section @@ -1711,7 +1729,7 @@ void init(int width, int height) { int depth = bits * planes; if (depth < 16) depth = 16; if (depth > 24) depth = 24; - handle = createDIB(width, height, depth); + setHandleForZoomLevel(createDIB(width, height, depth), getZoom()); } if (handle != 0) { long memDC = OS.CreateCompatibleDC(hDC); @@ -1809,7 +1827,7 @@ static ImageData directToDirect(ImageData src, int newDepth, PaletteData newPale return img; } -static long [] init(Device device, Image image, ImageData i) { +static long [] init(Device device, Image image, ImageData i, Integer zoom) { /* Windows does not support 2-bit images. Convert to 4-bit image. */ if (i.depth == 2) { i = indexToIndex(i, 4); @@ -2014,14 +2032,14 @@ else if (i.alphaData != null) { if (hIcon == 0) SWT.error(SWT.ERROR_NO_HANDLES); OS.DeleteObject(hBitmap); OS.DeleteObject(hMask); - image.handle = hIcon; + image.setHandleForZoomLevel(hIcon, zoom); image.type = SWT.ICON; } } else { if (image == null) { result = new long []{hDib}; } else { - image.handle = hDib; + image.setHandleForZoomLevel(hDib, zoom); image.type = SWT.BITMAP; image.transparentPixel = i.transparentPixel; } @@ -2029,9 +2047,18 @@ else if (i.alphaData != null) { return result; } -static long [] init(Device device, Image image, ImageData source, ImageData mask) { +private void setHandleForZoomLevel(long handle, Integer zoom) { + if (this.handle == 0) { + this.handle = handle; // Set handle for default zoom level + } + if (zoom != null && !handleMap.containsKey(zoom)) { + handleMap.put(zoom, handle); + } +} + +static long /*int*/ [] init(Device device, Image image, ImageData source, ImageData mask, int zoom) { ImageData imageData = applyMask(source, mask); - return init(device, image, imageData); + return init(device, image, imageData, zoom); } private static ImageData applyMask(ImageData source, ImageData mask) { @@ -2108,9 +2135,10 @@ private static ImageData applyMask(ImageData source, ImageData mask) { return imageData; } -void init(ImageData i) { + +void init(ImageData i, Integer zoom) { if (i == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - init(device, this, i); + init(device, this, i, zoom); } /** @@ -2154,7 +2182,7 @@ public long internal_new_GC (GCData data) { data.style |= SWT.LEFT_TO_RIGHT; } data.device = device; - data.nativeDeviceZoom = currentNativeZoom; + data.nativeDeviceZoom = initialNativeZoom; data.image = this; data.font = Font.win32_new(device.getSystemFont(), DPIUtil.getNativeDeviceZoom()); } @@ -2259,20 +2287,9 @@ public void setBackground(Color color) { device.internal_dispose_GC(hDC, null); } -private void setCurrentNativeZoom(int newZoom) { - int oldZoom = this.getZoom(); - if (oldZoom != newZoom) { - this.currentNativeZoom = newZoom; - // width and height are tied to the current device zoom - // they must be reset the the zoom factor changes - width = height = -1; - } -} - private int getZoom() { - return DPIUtil.getZoomForAutoscaleProperty(currentNativeZoom); + return DPIUtil.getZoomForAutoscaleProperty(initialNativeZoom); } - /** * Returns a string containing a concise, human-readable * description of the receiver. @@ -2328,8 +2345,8 @@ public static Image win32_new(Device device, int type, long handle) { */ public static Image win32_new(Image image, int targetZoom) { if (targetZoom != image.getZoom()) { - image.handleDPIChange(targetZoom); + Image.win32_getHandle(image, DPIUtil.getZoomForAutoscaleProperty(targetZoom)); } return image; } -} +} \ No newline at end of file diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/ImageList.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/ImageList.java index c5e0fee69fb..519a9335129 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/ImageList.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/ImageList.java @@ -22,17 +22,19 @@ public class ImageList { long handle; int style, refCount; Image [] images; + final int zoom; -public ImageList (int style) { - this (style, 32, 32); +public ImageList (int style, int currentZoomLevel) { + this (style, 32, 32, currentZoomLevel); } -public ImageList (int style, int width, int height) { +public ImageList (int style, int width, int height, int currentZoomLevel) { this.style = style; int flags = OS.ILC_MASK | OS.ILC_COLOR32; if ((style & SWT.RIGHT_TO_LEFT) != 0) flags |= OS.ILC_MIRROR; handle = OS.ImageList_Create (width, height, flags, 16, 16); images = new Image [4]; + this.zoom = currentZoomLevel; } public int add (Image image) { @@ -46,7 +48,7 @@ public int add (Image image) { index++; } if (count == 0) { - Rectangle rect = image.getBoundsInPixels(); + Rectangle rect = DPIUtil.autoScaleBounds(image.getBounds(), zoom, 100); OS.ImageList_SetIconSize (handle, rect.width, rect.height); } set (index, image, count); @@ -360,7 +362,7 @@ public int removeRef() { } void set (int index, Image image, int count) { - long hImage = image.handle; + long hImage = Image.win32_getHandle(image, zoom); int [] cx = new int [1], cy = new int [1]; OS.ImageList_GetIconSize (handle, cx, cy); switch (image.type) { @@ -369,7 +371,7 @@ void set (int index, Image image, int count) { * Note that the image size has to match the image list icon size. */ long hBitmap = 0, hMask = 0; - ImageData data = image.getImageDataAtCurrentZoom(); + ImageData data = image.getImageData(zoom); switch (data.getTransparencyType ()) { case SWT.TRANSPARENCY_ALPHA: /* @@ -443,4 +445,4 @@ public int size () { return result; } -} +} \ No newline at end of file diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Button.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Button.java index d65ad21720c..66203e555a4 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Button.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Button.java @@ -126,7 +126,7 @@ void _setImage (Image image) { if (imageList != null) imageList.dispose (); imageList = null; if (image != null) { - imageList = new ImageList (style & SWT.RIGHT_TO_LEFT); + imageList = new ImageList (style & SWT.RIGHT_TO_LEFT, getZoom()); if (OS.IsWindowEnabled (handle)) { imageList.add (image); } else { @@ -1021,7 +1021,7 @@ void updateImageList () { BUTTON_IMAGELIST buttonImageList = new BUTTON_IMAGELIST (); OS.SendMessage (handle, OS.BCM_GETIMAGELIST, 0, buttonImageList); if (imageList != null) imageList.dispose (); - imageList = new ImageList (style & SWT.RIGHT_TO_LEFT); + imageList = new ImageList (style & SWT.RIGHT_TO_LEFT, getZoom()); if (OS.IsWindowEnabled (handle)) { imageList.add (image); } else { diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Caret.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Caret.java index 10c3df60191..86b85d28cb2 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Caret.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Caret.java @@ -353,7 +353,7 @@ void resize () { resized = false; long hwnd = parent.handle; OS.DestroyCaret (); - long hBitmap = image != null ? image.handle : 0; + long hBitmap = image != null ? Image.win32_getHandle(image, getZoom()) : 0; int width = this.width; if (image == null && width == 0) { int [] buffer = new int [1]; @@ -440,7 +440,7 @@ void setBoundsInPixels (Rectangle rect) { void setFocus () { long hwnd = parent.handle; long hBitmap = 0; - if (image != null) hBitmap = image.handle; + if (image != null) hBitmap = Image.win32_getHandle(image, getZoom()); int width = this.width; if (image == null && width == 0) { int [] buffer = new int [1]; diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java index 0fca587abac..be720f05aec 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java @@ -941,7 +941,7 @@ void fillImageBackground (long hDC, Control control, RECT rect, int tx, int ty) if (control != null) { Image image = control.backgroundImage; if (image != null) { - control.drawImageBackground (hDC, handle, image.handle, rect, tx, ty); + control.drawImageBackground (hDC, handle, Image.win32_getHandle(image, getZoom()), rect, tx, ty); } } } @@ -1742,7 +1742,7 @@ public long internal_new_GC (GCData data) { } } data.device = display; - data.nativeDeviceZoom = getNativeZoom(); + data.nativeDeviceZoom = nativeZoom; int foreground = getForegroundPixel (); if (foreground != OS.GetTextColor (hDC)) data.foreground = foreground; Control control = findBackgroundControl (); @@ -3037,7 +3037,7 @@ void setBackground () { if (control.backgroundImage != null) { Shell shell = getShell (); shell.releaseBrushes (); - setBackgroundImage (control.backgroundImage.handle); + setBackgroundImage (Image.win32_getHandle(control.backgroundImage, getZoom())); } else { setBackgroundPixel (control.background == -1 ? control.defaultBackground() : control.background); } @@ -4559,7 +4559,7 @@ void updateBackgroundColor () { void updateBackgroundImage () { Control control = findBackgroundControl (); Image image = control != null ? control.backgroundImage : backgroundImage; - setBackgroundImage (image != null ? image.handle : 0); + setBackgroundImage (image != null ? Image.win32_getHandle(image, getZoom()) : 0); } void updateBackgroundMode () { @@ -5733,7 +5733,7 @@ LRESULT wmColorChild (long wParam, long lParam) { RECT rect = new RECT (); OS.GetClientRect (handle, rect); long hwnd = control.handle; - long hBitmap = control.backgroundImage.handle; + long hBitmap = Image.win32_getHandle(control.backgroundImage, getZoom()); OS.MapWindowPoints (handle, hwnd, rect, 2); POINT lpPoint = new POINT (); OS.GetWindowOrgEx (wParam, lpPoint); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Decorations.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Decorations.java index 092daff515d..51f97ebe820 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Decorations.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Decorations.java @@ -915,10 +915,10 @@ void setImages (Image image, Image [] images) { switch (smallIcon.type) { case SWT.BITMAP: smallImage = Display.createIcon (smallIcon); - hSmallIcon = smallImage.handle; + hSmallIcon = Image.win32_getHandle(smallImage, getZoom()); break; case SWT.ICON: - hSmallIcon = smallIcon.handle; + hSmallIcon = Image.win32_getHandle(smallIcon, getZoom()); break; } } @@ -927,10 +927,10 @@ void setImages (Image image, Image [] images) { switch (largeIcon.type) { case SWT.BITMAP: largeImage = Display.createIcon (largeIcon); - hLargeIcon = largeImage.handle; + hLargeIcon = Image.win32_getHandle(largeImage, getZoom()); break; case SWT.ICON: - hLargeIcon = largeIcon.handle; + hLargeIcon = Image.win32_getHandle(largeIcon, getZoom()); break; } } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java index c94d7cfd68e..7f34883a56c 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java @@ -942,19 +942,24 @@ void createDisplay (DeviceData data) { } static long create32bitDIB (Image image) { + return create32bitDIB (image, DPIUtil.getDeviceZoom()); +} + +static long create32bitDIB (Image image, int zoomLevel) { + long handle = Image.win32_getHandle(image, zoomLevel); int transparentPixel = -1, alpha = -1; long hMask = 0, hBitmap = 0; byte[] alphaData = null; switch (image.type) { case SWT.ICON: ICONINFO info = new ICONINFO (); - OS.GetIconInfo (image.handle, info); + OS.GetIconInfo (handle, info); hBitmap = info.hbmColor; hMask = info.hbmMask; break; case SWT.BITMAP: - ImageData data = image.getImageData (DPIUtil.getDeviceZoom ()); - hBitmap = image.handle; + ImageData data = image.getImageData (zoomLevel); + hBitmap = handle; alpha = data.alpha; alphaData = data.alphaData; transparentPixel = data.transparentPixel; @@ -1052,7 +1057,7 @@ static long create32bitDIB (Image image) { OS.DeleteObject (srcHdc); OS.DeleteObject (memHdc); OS.ReleaseDC (0, hDC); - if (hBitmap != image.handle && hBitmap != 0) OS.DeleteObject (hBitmap); + if (hBitmap != handle && hBitmap != 0) OS.DeleteObject (hBitmap); if (hMask != 0) OS.DeleteObject (hMask); return memDib; } @@ -1960,7 +1965,7 @@ public int getIconDepth () { }; } -ImageList getImageList (int style, int width, int height) { +ImageList getImageList (int style, int width, int height, int currentZoomLevel) { if (imageList == null) imageList = new ImageList [4]; int i = 0; @@ -1984,13 +1989,13 @@ ImageList getImageList (int style, int width, int height) { imageList = newList; } - ImageList list = new ImageList (style, width, height); + ImageList list = new ImageList (style, width, height, currentZoomLevel); imageList [i] = list; list.addRef(); return list; } -ImageList getImageListToolBar (int style, int width, int height) { +ImageList getImageListToolBar (int style, int width, int height, int currentZoomLevel) { if (toolImageList == null) toolImageList = new ImageList [4]; int i = 0; @@ -2014,13 +2019,13 @@ ImageList getImageListToolBar (int style, int width, int height) { toolImageList = newList; } - ImageList list = new ImageList (style, width, height); + ImageList list = new ImageList (style, width, height, currentZoomLevel); toolImageList [i] = list; list.addRef(); return list; } -ImageList getImageListToolBarDisabled (int style, int width, int height) { +ImageList getImageListToolBarDisabled (int style, int width, int height, int currentZoomLevel) { if (toolDisabledImageList == null) toolDisabledImageList = new ImageList [4]; int i = 0; @@ -2044,13 +2049,13 @@ ImageList getImageListToolBarDisabled (int style, int width, int height) { toolDisabledImageList = newList; } - ImageList list = new ImageList (style, width, height); + ImageList list = new ImageList (style, width, height, currentZoomLevel); toolDisabledImageList [i] = list; list.addRef(); return list; } -ImageList getImageListToolBarHot (int style, int width, int height) { +ImageList getImageListToolBarHot (int style, int width, int height, int currentZoomLevel) { if (toolHotImageList == null) toolHotImageList = new ImageList [4]; int i = 0; @@ -2074,7 +2079,7 @@ ImageList getImageListToolBarHot (int style, int width, int height) { toolHotImageList = newList; } - ImageList list = new ImageList (style, width, height); + ImageList list = new ImageList (style, width, height, currentZoomLevel); toolHotImageList [i] = list; list.addRef(); return list; diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Label.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Label.java index e8039b5a146..eab42539ed2 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Label.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Label.java @@ -563,7 +563,7 @@ void wmDrawChildImage(DRAWITEMSTRUCT struct) { } GCData data = new GCData(); - data.nativeDeviceZoom = getNativeZoom(); + data.nativeDeviceZoom = nativeZoom; data.device = display; GC gc = getNewGC(struct.hDC, data); Image image = getEnabled () ? this.image : new Image (display, this.image, SWT.IMAGE_DISABLE); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Menu.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Menu.java index 1965edc139c..02ab23db0fc 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Menu.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Menu.java @@ -1319,7 +1319,7 @@ void updateBackground () { hBrush = 0; if (backgroundImage != null) - hBrush = OS.CreatePatternBrush (backgroundImage.handle); + hBrush = OS.CreatePatternBrush (Image.win32_getHandle(backgroundImage, getZoom())); else if (background != -1) hBrush = OS.CreateSolidBrush (background); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/MenuItem.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/MenuItem.java index 01260509b94..318c1218b80 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/MenuItem.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/MenuItem.java @@ -785,7 +785,7 @@ public void setImage (Image image) { } else { if (OS.IsAppThemed ()) { if (hBitmap != 0) OS.DeleteObject (hBitmap); - info.hbmpItem = hBitmap = image != null ? Display.create32bitDIB (image) : 0; + info.hbmpItem = hBitmap = image != null ? Display.create32bitDIB (image, getZoom()) : 0; } else { info.hbmpItem = image != null ? OS.HBMMENU_CALLBACK : 0; } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TabFolder.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TabFolder.java index 29cd9b58ea1..5e6233a9d29 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TabFolder.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TabFolder.java @@ -456,7 +456,7 @@ int imageIndex (Image image) { if (image == null) return -1; if (imageList == null) { Rectangle bounds = DPIUtil.autoScaleBounds(image.getBounds(), this.getZoom(), 100); - imageList = display.getImageList (style & SWT.RIGHT_TO_LEFT, bounds.width, bounds.height); + imageList = display.getImageList (style & SWT.RIGHT_TO_LEFT, bounds.width, bounds.height, this.getZoom()); int index = imageList.add (image); long hImageList = imageList.getHandle (); OS.SendMessage (handle, OS.TCM_SETIMAGELIST, 0, hImageList); @@ -838,7 +838,7 @@ void updateOrientation () { if (imageList != null) { Point size = imageList.getImageSize (); display.releaseImageList (imageList); - imageList = display.getImageList (style & SWT.RIGHT_TO_LEFT, size.x, size.y); + imageList = display.getImageList (style & SWT.RIGHT_TO_LEFT, size.x, size.y, this.getZoom()); long hImageList = imageList.getHandle (); OS.SendMessage (handle, OS.TCM_SETIMAGELIST, 0, hImageList); TCITEM tcItem = new TCITEM (); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Table.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Table.java index b3a0ed77b1d..882423fe525 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Table.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Table.java @@ -2849,8 +2849,8 @@ int imageIndex (Image image, int column) { setSubImagesVisible (true); } if (imageList == null) { - Rectangle bounds = image.getBoundsInPixels (); - imageList = display.getImageList (style & SWT.RIGHT_TO_LEFT, bounds.width, bounds.height); + Rectangle bounds = DPIUtil.autoScaleBounds(image.getBounds(), this.getZoom(), 100); + imageList = display.getImageList (style & SWT.RIGHT_TO_LEFT, bounds.width, bounds.height, getZoom()); int index = imageList.indexOf (image); if (index == -1) index = imageList.add (image); long hImageList = imageList.getHandle (); @@ -2889,8 +2889,8 @@ int imageIndex (Image image, int column) { int imageIndexHeader (Image image) { if (image == null) return OS.I_IMAGENONE; if (headerImageList == null) { - Rectangle bounds = image.getBoundsInPixels (); - headerImageList = display.getImageList (style & SWT.RIGHT_TO_LEFT, bounds.width, bounds.height); + Rectangle bounds = DPIUtil.autoScaleBounds(image.getBounds(), this.getZoom(), 100); + headerImageList = display.getImageList (style & SWT.RIGHT_TO_LEFT, bounds.width, bounds.height, getZoom()); int index = headerImageList.indexOf (image); if (index == -1) index = headerImageList.add (image); long hImageList = headerImageList.getHandle (); @@ -5577,7 +5577,7 @@ void updateOrientation () { if (imageList != null) { Point size = imageList.getImageSize (); display.releaseImageList (imageList); - imageList = display.getImageList (style & SWT.RIGHT_TO_LEFT, size.x, size.y); + imageList = display.getImageList (style & SWT.RIGHT_TO_LEFT, size.x, size.y, getZoom()); int count = (int)OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0); for (int i = 0; i < count; i++) { TableItem item = _getItem (i, false); @@ -5596,7 +5596,7 @@ void updateOrientation () { if (headerImageList != null) { Point size = headerImageList.getImageSize (); display.releaseImageList (headerImageList); - headerImageList = display.getImageList (style & SWT.RIGHT_TO_LEFT, size.x, size.y); + headerImageList = display.getImageList (style & SWT.RIGHT_TO_LEFT, size.x, size.y, getZoom()); if (columns != null) { for (int i = 0; i < columns.length; i++) { TableColumn column = columns [i]; @@ -7368,4 +7368,4 @@ private static void handleDPIChange(Widget widget, int newZoom, float scalingFac table.fixCheckboxImageListColor (true); table.settingItemHeight = false; } -} +} \ No newline at end of file diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TaskItem.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TaskItem.java index bffb472388a..8d3f03a163f 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TaskItem.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TaskItem.java @@ -462,12 +462,9 @@ public void setProgressState (int progressState) { void setShell (Shell shell) { this.shell = shell; - shell.addListener (SWT.Dispose, new Listener () { - @Override - public void handleEvent (Event event) { - if (isDisposed ()) return; - dispose (); - } + shell.addListener (SWT.Dispose, event -> { + if (isDisposed ()) return; + dispose (); }); } @@ -477,10 +474,10 @@ void updateImage () { switch (overlayImage.type) { case SWT.BITMAP: image2 = Display.createIcon (overlayImage); - hIcon = image2.handle; + hIcon = Image.win32_getHandle(image2, getZoom()); break; case SWT.ICON: - hIcon = overlayImage.handle; + hIcon = Image.win32_getHandle(overlayImage, getZoom()); break; } parent.mTaskbarList3.SetOverlayIcon(shell.handle, hIcon, 0); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolBar.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolBar.java index a06f58d8f53..5acd6c62d74 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolBar.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolBar.java @@ -1265,9 +1265,9 @@ void updateOrientation () { super.updateOrientation (); if (imageList != null) { Point size = imageList.getImageSize (); - ImageList newImageList = display.getImageListToolBar (style & SWT.RIGHT_TO_LEFT, size.x, size.y); - ImageList newHotImageList = display.getImageListToolBarHot (style & SWT.RIGHT_TO_LEFT, size.x, size.y); - ImageList newDisabledImageList = display.getImageListToolBarDisabled (style & SWT.RIGHT_TO_LEFT, size.x, size.y); + ImageList newImageList = display.getImageListToolBar (style & SWT.RIGHT_TO_LEFT, size.x, size.y, getZoom()); + ImageList newHotImageList = display.getImageListToolBarHot (style & SWT.RIGHT_TO_LEFT, size.x, size.y, getZoom()); + ImageList newDisabledImageList = display.getImageListToolBarDisabled (style & SWT.RIGHT_TO_LEFT, size.x, size.y, getZoom()); TBBUTTONINFO info = new TBBUTTONINFO (); info.cbSize = TBBUTTONINFO.sizeof; info.dwMask = OS.TBIF_IMAGE; diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolItem.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolItem.java index f99adecca7b..c842a60cd52 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolItem.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolItem.java @@ -1110,13 +1110,13 @@ void updateImages (boolean enabled) { Rectangle bounds = DPIUtil.autoScaleBounds(image.getBounds(), getParent().getZoom(), 100); int listStyle = parent.style & SWT.RIGHT_TO_LEFT; if (imageList == null) { - imageList = display.getImageListToolBar (listStyle, bounds.width, bounds.height); + imageList = display.getImageListToolBar (listStyle, bounds.width, bounds.height, getZoom()); } if (disabledImageList == null) { - disabledImageList = display.getImageListToolBarDisabled (listStyle, bounds.width, bounds.height); + disabledImageList = display.getImageListToolBarDisabled (listStyle, bounds.width, bounds.height, getZoom()); } if (hotImageList == null) { - hotImageList = display.getImageListToolBarHot (listStyle, bounds.width, bounds.height); + hotImageList = display.getImageListToolBarHot (listStyle, bounds.width, bounds.height, getZoom()); } Image disabled = disabledImage; if (disabledImage == null) { @@ -1231,24 +1231,13 @@ private static void handleDPIChange(Widget widget, int newZoom, float scalingFac Rectangle bounds = DPIUtil.autoScaleBounds(image.getBounds(), newZoom, 100); if (parent.getImageList() == null) { - parent.setImageList (display.getImageListToolBar (listStyle, bounds.width, bounds.height)); + parent.setImageList (display.getImageListToolBar (listStyle, bounds.width, bounds.height, item.getZoom())); } if (parent.getDisabledImageList() == null) { - parent.setDisabledImageList (display.getImageListToolBarDisabled (listStyle, bounds.width, bounds.height)); + parent.setDisabledImageList (display.getImageListToolBarDisabled (listStyle, bounds.width, bounds.height, item.getZoom())); } if (parent.getHotImageList() == null) { - parent.setHotImageList (display.getImageListToolBarHot (listStyle, bounds.width, bounds.height)); - } - Image.win32_new(image, newZoom); - - Image disabledImage = item.getDisabledImage(); - if (disabledImage != null && !disabledImage.isDisposed()) { - Image.win32_new(disabledImage, newZoom); - } - - Image hotImage = item.getHotImage(); - if (hotImage != null) { - Image.win32_new(hotImage, newZoom); + parent.setHotImageList (display.getImageListToolBarHot (listStyle, bounds.width, bounds.height, item.getZoom())); } } item.setWidthInPixels(0); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TrayItem.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TrayItem.java index 1cb73944e5c..a918fdcea40 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TrayItem.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TrayItem.java @@ -458,10 +458,10 @@ public void setImage (Image image) { switch (icon.type) { case SWT.BITMAP: image2 = Display.createIcon (image); - hIcon = image2.handle; + hIcon = Image.win32_getHandle(image2, getZoom()); break; case SWT.ICON: - hIcon = icon.handle; + hIcon = Image.win32_getHandle(icon, getZoom()); break; } } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Tree.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Tree.java index bf5e671e50f..2c9f2c0e678 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Tree.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Tree.java @@ -3740,7 +3740,7 @@ int imageIndex (Image image, int index) { if (image == null) return OS.I_IMAGENONE; if (imageList == null) { Rectangle bounds = DPIUtil.autoScaleBounds(image.getBounds(), this.getZoom(), 100); - imageList = display.getImageList (style & SWT.RIGHT_TO_LEFT, bounds.width, bounds.height); + imageList = display.getImageList (style & SWT.RIGHT_TO_LEFT, bounds.width, bounds.height, getZoom()); } int imageIndex = imageList.indexOf (image); if (imageIndex == -1) imageIndex = imageList.add (image); @@ -3764,7 +3764,7 @@ int imageIndexHeader (Image image) { if (image == null) return OS.I_IMAGENONE; if (headerImageList == null) { Rectangle bounds = DPIUtil.autoScaleBounds(image.getBounds(), this.getZoom(), 100); - headerImageList = display.getImageList (style & SWT.RIGHT_TO_LEFT, bounds.width, bounds.height); + headerImageList = display.getImageList (style & SWT.RIGHT_TO_LEFT, bounds.width, bounds.height, getZoom()); int index = headerImageList.indexOf (image); if (index == -1) index = headerImageList.add (image); long hImageList = headerImageList.getHandle (); @@ -5791,7 +5791,7 @@ void updateOrientation () { if (imageList != null) { Point size = imageList.getImageSize (); display.releaseImageList (imageList); - imageList = display.getImageList (style & SWT.RIGHT_TO_LEFT, size.x, size.y); + imageList = display.getImageList (style & SWT.RIGHT_TO_LEFT, size.x, size.y, getZoom()); for (TreeItem item : items) { if (item != null) { Image image = item.image; @@ -5808,7 +5808,7 @@ void updateOrientation () { if (headerImageList != null) { Point size = headerImageList.getImageSize (); display.releaseImageList (headerImageList); - headerImageList = display.getImageList (style & SWT.RIGHT_TO_LEFT, size.x, size.y); + headerImageList = display.getImageList (style & SWT.RIGHT_TO_LEFT, size.x, size.y, getZoom()); if (columns != null) { for (int i = 0; i < columns.length; i++) { TreeColumn column = columns[i]; diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TreeColumn.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TreeColumn.java index d5cf637382f..d6eeae1fed5 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TreeColumn.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TreeColumn.java @@ -536,7 +536,7 @@ void setImage (Image image, boolean sort, boolean right) { hdItem.mask &= ~OS.HDI_IMAGE; hdItem.fmt &= ~OS.HDF_IMAGE; hdItem.fmt |= OS.HDF_BITMAP; - hdItem.hbm = image.handle; + hdItem.hbm = Image.win32_getHandle(image, parent.getZoom()); } else { hdItem.mask &= ~OS.HDI_BITMAP; hdItem.fmt &= ~OS.HDF_BITMAP; diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TreeItem.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TreeItem.java index 0138043e362..7afe8d815c3 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TreeItem.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TreeItem.java @@ -1821,14 +1821,6 @@ private static void handleDPIChange(Widget widget, int newZoom, float scalingFac if (!(widget instanceof TreeItem treeItem)) { return; } - Image[] images = treeItem.images; - if (images != null) { - for (Image innerImage : images) { - if (innerImage != null) { - Image.win32_new(innerImage, newZoom); - } - } - } Font font = treeItem.font; if (font != null) { treeItem.setFont(font);