From e0ff475c0cf545fdd75a7b094ec0c5ffcd5a5578 Mon Sep 17 00:00:00 2001 From: Andreas Koch Date: Tue, 17 Dec 2024 14:54:52 +0100 Subject: [PATCH] [win32] fix invalid icon bounds This commit fixes an issue in the win32 implementation that returned invalid bounds for an icon in some scenarios. --- .../win32/org/eclipse/swt/graphics/Image.java | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) 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 bb55941f0ce..4415c3ab832 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 @@ -1772,16 +1772,16 @@ else if (i.alphaData != null) { if (hIcon == 0) SWT.error(SWT.ERROR_NO_HANDLES); OS.DeleteObject(hBitmap); OS.DeleteObject(hMask); - image.new ImageHandle(hIcon, zoom); image.type = SWT.ICON; + image.new ImageHandle(hIcon, zoom); } } else { if (image == null) { result = new long []{hDib}; } else { - image.new ImageHandle(hDib, zoom); image.type = SWT.BITMAP; image.transparentPixel = i.transparentPixel; + image.new ImageHandle(hDib, zoom); } } return result; @@ -2089,26 +2089,26 @@ public void close() { } private class ImageHandle { - final long handle; - final int zoom; - int height; - int width; + private final long handle; + private final int zoom; + private int height; + private int width; public ImageHandle(long handle, int zoom) { - Rectangle bounds = getBoundsInPixelsFromNative(handle); this.handle = handle; this.zoom = zoom; - this.height = bounds.height; - this.width = bounds.width; + updateBoundsInPixelsFromNative(); setImageMetadataForHandle(this, zoom); } - private Rectangle getBoundsInPixelsFromNative(long handle) { + private void updateBoundsInPixelsFromNative() { switch (type) { case SWT.BITMAP: BITMAP bm = new BITMAP(); OS.GetObject(handle, BITMAP.sizeof, bm); - return new Rectangle(0, 0, width = bm.bmWidth, height = bm.bmHeight); + width = bm.bmWidth; + height = bm.bmHeight; + return; case SWT.ICON: ICONINFO info = new ICONINFO(); OS.GetIconInfo(handle, info); @@ -2119,10 +2119,11 @@ private Rectangle getBoundsInPixelsFromNative(long handle) { if (hBitmap == info.hbmMask) bm.bmHeight /= 2; if (info.hbmColor != 0) OS.DeleteObject(info.hbmColor); if (info.hbmMask != 0) OS.DeleteObject(info.hbmMask); - return new Rectangle(0, 0, width = bm.bmWidth, height = bm.bmHeight); + width = bm.bmWidth; + height = bm.bmHeight; + return; default: SWT.error(SWT.ERROR_INVALID_IMAGE); - return null; } }