Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 (',');
Expand All @@ -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;
}
Expand Down