Skip to content

Commit c20e5a0

Browse files
committed
add support for zoom level of program images
Signed-off-by: Patrick Tief <[email protected]>
1 parent 97ca656 commit c20e5a0

File tree

3 files changed

+58
-13
lines changed

3 files changed

+58
-13
lines changed

bundles/org.eclipse.swt/Eclipse SWT Program/cocoa/org/eclipse/swt/program/Program.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -333,14 +333,29 @@ public boolean execute (String fileName) {
333333
}
334334
}
335335

336+
336337
/**
337-
* Returns the receiver's image data. This is the icon
338-
* that is associated with the receiver in the operating
339-
* system.
338+
* Returns the receiver's image data at 100% zoom level.
339+
* This is the icon that is associated with the receiver
340+
* in the operating system.
340341
*
341342
* @return the image data for the program, may be null
342343
*/
343344
public ImageData getImageData () {
345+
return getImageData (100);
346+
}
347+
348+
/**
349+
* Returns the receiver's image data based on the given zoom level.
350+
* This is the icon that is associated with the receiver in the
351+
* operating system.
352+
*
353+
* @param zoom
354+
* The zoom level in % of the standard resolution
355+
*
356+
* @return the image data for the program, may be null
357+
*/
358+
public ImageData getImageData (int zoom) {
344359
NSAutoreleasePool pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
345360
try {
346361
NSWorkspace workspace = NSWorkspace.sharedWorkspace();
@@ -358,7 +373,7 @@ public ImageData getImageData () {
358373
nsImage.setSize(size);
359374
nsImage.retain();
360375
Image image = Image.cocoa_new(Display.getCurrent(), SWT.BITMAP, nsImage);
361-
ImageData imageData = image.getImageData();
376+
ImageData imageData = image.getImageData(zoom);
362377
image.dispose();
363378
return imageData;
364379
}

bundles/org.eclipse.swt/Eclipse SWT Program/gtk/org/eclipse/swt/program/Program.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import java.nio.file.*;
1818
import java.nio.file.Path;
1919
import java.util.*;
20-
import java.util.List;
2120

2221
import org.eclipse.swt.*;
2322
import org.eclipse.swt.graphics.*;
@@ -121,13 +120,29 @@ public static Program findProgram(String extension) {
121120
}
122121

123122
/**
124-
* Returns the receiver's image data. This is the icon
125-
* that is associated with the receiver in the operating
126-
* system.
123+
* Returns the receiver's image data at 100% zoom level.
124+
* This is the icon that is associated with the receiver
125+
* in the operating system.
127126
*
128127
* @return the image data for the program, may be null
129128
*/
130129
public ImageData getImageData() {
130+
return getImageData(100);
131+
}
132+
133+
134+
135+
/**
136+
* Returns the receiver's image data based on the given zoom level.
137+
* This is the icon that is associated with the receiver in the
138+
* operating system.
139+
*
140+
* @param zoom
141+
* The zoom level in % of the standard resolution
142+
*
143+
* @return the image data for the program, may be null
144+
*/
145+
public ImageData getImageData(int zoom) {
131146
if (iconPath == null) return null;
132147
ImageData data = null;
133148

bundles/org.eclipse.swt/Eclipse SWT Program/win32/org/eclipse/swt/program/Program.java

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -350,14 +350,30 @@ public boolean execute (String fileName) {
350350
return success;
351351
}
352352

353+
354+
353355
/**
354-
* Returns the receiver's image data. This is the icon
355-
* that is associated with the receiver in the operating
356-
* system.
356+
* Returns the receiver's image data at 100% zoom level.
357+
* This is the icon that is associated with the receiver
358+
* in the operating system.
357359
*
358360
* @return the image data for the program, may be null
359361
*/
360362
public ImageData getImageData () {
363+
return getImageData (100);
364+
}
365+
366+
/**
367+
* Returns the receiver's image data based on the given zoom level.
368+
* This is the icon that is associated with the receiver in the
369+
* operating system.
370+
*
371+
* @param zoom
372+
* The zoom level in % of the standard resolution
373+
*
374+
* @return the image data for the program, may be null
375+
*/
376+
public ImageData getImageData (int zoom) {
361377
int nIconIndex = 0;
362378
String fileName = iconName;
363379
int index = iconName.indexOf (',');
@@ -379,8 +395,7 @@ public ImageData getImageData () {
379395
OS.ExtractIconEx (lpszFile, nIconIndex, phiconLarge, phiconSmall, 1);
380396
if (phiconSmall [0] == 0) return null;
381397
Image image = Image.win32_new (null, SWT.ICON, phiconSmall [0]);
382-
/* Fetch the ImageData at 100% zoom and return */
383-
ImageData imageData = image.getImageData ();
398+
ImageData imageData = image.getImageData (zoom);
384399
image.dispose ();
385400
return imageData;
386401
}

0 commit comments

Comments
 (0)