diff --git a/bundles/org.eclipse.swt/Eclipse SWT Program/cocoa/org/eclipse/swt/program/Program.java b/bundles/org.eclipse.swt/Eclipse SWT Program/cocoa/org/eclipse/swt/program/Program.java index fe81c5bbfcb..92c0b080e97 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Program/cocoa/org/eclipse/swt/program/Program.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Program/cocoa/org/eclipse/swt/program/Program.java @@ -333,14 +333,30 @@ public boolean execute (String fileName) { } } + /** - * Returns the receiver's image data. This is the icon - * that is associated with the receiver in the operating - * system. + * Returns the receiver's image data at 100% zoom level. + * This is the icon that is associated with the receiver + * in the operating system. * * @return the image data for the program, may be null */ public ImageData getImageData () { + return getImageData (100); +} + +/** + * Returns the receiver's image data based on the given zoom level. + * This is the icon that is associated with the receiver in the + * operating system. + * + * @param zoom + * The zoom level in % of the standard resolution + * + * @return the image data for the program, may be null + * @since 3.125 + */ +public ImageData getImageData (int zoom) { NSAutoreleasePool pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init(); try { NSWorkspace workspace = NSWorkspace.sharedWorkspace(); @@ -358,7 +374,7 @@ public ImageData getImageData () { nsImage.setSize(size); nsImage.retain(); Image image = Image.cocoa_new(Display.getCurrent(), SWT.BITMAP, nsImage); - ImageData imageData = image.getImageData(); + ImageData imageData = image.getImageData(zoom); image.dispose(); return imageData; } diff --git a/bundles/org.eclipse.swt/Eclipse SWT Program/gtk/org/eclipse/swt/program/Program.java b/bundles/org.eclipse.swt/Eclipse SWT Program/gtk/org/eclipse/swt/program/Program.java index d78ea393793..1e5208a3987 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Program/gtk/org/eclipse/swt/program/Program.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Program/gtk/org/eclipse/swt/program/Program.java @@ -17,7 +17,6 @@ import java.nio.file.*; import java.nio.file.Path; import java.util.*; -import java.util.List; import org.eclipse.swt.*; import org.eclipse.swt.graphics.*; @@ -121,13 +120,30 @@ public static Program findProgram(String extension) { } /** - * Returns the receiver's image data. This is the icon - * that is associated with the receiver in the operating - * system. + * Returns the receiver's image data at 100% zoom level. + * This is the icon that is associated with the receiver + * in the operating system. * * @return the image data for the program, may be null */ public ImageData getImageData() { + return getImageData(100); +} + + + +/** + * Returns the receiver's image data based on the given zoom level. + * This is the icon that is associated with the receiver in the + * operating system. + * + * @param zoom + * The zoom level in % of the standard resolution + * + * @return the image data for the program, may be null + * @since 3.125 + */ +public ImageData getImageData(int zoom) { if (iconPath == null) return null; ImageData data = null; diff --git a/bundles/org.eclipse.swt/Eclipse SWT Program/win32/org/eclipse/swt/program/Program.java b/bundles/org.eclipse.swt/Eclipse SWT Program/win32/org/eclipse/swt/program/Program.java index 6531da28fc9..b5a2b6252a9 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Program/win32/org/eclipse/swt/program/Program.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Program/win32/org/eclipse/swt/program/Program.java @@ -19,7 +19,9 @@ import org.eclipse.swt.*; import org.eclipse.swt.graphics.*; +import org.eclipse.swt.internal.*; import org.eclipse.swt.internal.win32.*; +import org.eclipse.swt.widgets.*; /** * Instances of this class represent programs and @@ -350,14 +352,31 @@ public boolean execute (String fileName) { return success; } + + /** - * Returns the receiver's image data. This is the icon - * that is associated with the receiver in the operating - * system. + * Returns the receiver's image data at 100% zoom level. + * This is the icon that is associated with the receiver + * in the operating system. * * @return the image data for the program, may be null */ public ImageData getImageData () { + return getImageData (100); +} + +/** + * Returns the receiver's image data based on the given zoom level. + * This is the icon that is associated with the receiver in the + * operating system. + * + * @param zoom + * The zoom level in % of the standard resolution + * + * @return the image data for the program, may be null + * @since 3.125 + */ +public ImageData getImageData (int zoom) { int nIconIndex = 0; String fileName = iconName; int index = iconName.indexOf (','); @@ -379,8 +398,10 @@ public ImageData getImageData () { OS.ExtractIconEx (lpszFile, nIconIndex, phiconLarge, phiconSmall, 1); if (phiconSmall [0] == 0) return null; Image image = Image.win32_new (null, SWT.ICON, phiconSmall [0]); - /* Fetch the ImageData at 100% zoom and return */ - ImageData imageData = image.getImageData (); + // Windows API returns image data according to primary monitor zoom factor + // rather than at original scaling + int nativeZoomFactor = 100 * Display.getCurrent().getPrimaryMonitor().getZoom() / DPIUtil.getDeviceZoom(); + ImageData imageData = image.getImageData (100 * zoom / nativeZoomFactor); image.dispose (); return imageData; }