Skip to content

Commit c909b05

Browse files
ptiefakurtakov
authored andcommitted
add support for zoom level of program images
Signed-off-by: Patrick Tief <[email protected]>
1 parent 961810f commit c909b05

File tree

3 files changed

+93
-49
lines changed

3 files changed

+93
-49
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: 55 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -353,52 +353,66 @@ public boolean execute (String fileName) {
353353
return success;
354354
}
355355

356+
357+
356358
/**
357-
* Returns the receiver's image data. This is the icon
358-
* that is associated with the receiver in the operating
359-
* system.
359+
* Returns the receiver's image data at 100% zoom level.
360+
* This is the icon that is associated with the receiver
361+
* in the operating system.
360362
*
361363
* @return the image data for the program, may be null
362364
*/
363365
public ImageData getImageData () {
364-
if (extension != null) {
365-
SHFILEINFO shfi = new SHFILEINFO ();
366-
int flags = OS.SHGFI_ICON | OS.SHGFI_SMALLICON | OS.SHGFI_USEFILEATTRIBUTES;
367-
TCHAR pszPath = new TCHAR (0, extension, true);
368-
OS.SHGetFileInfo (pszPath.chars, OS.FILE_ATTRIBUTE_NORMAL, shfi, SHFILEINFO.sizeof, flags);
369-
if (shfi.hIcon != 0) {
370-
Image image = Image.win32_new (null, SWT.ICON, shfi.hIcon);
371-
/* Fetch the ImageData at 100% zoom and return */
372-
ImageData imageData = image.getImageData ();
373-
image.dispose ();
374-
return imageData;
375-
}
376-
}
377-
int nIconIndex = 0;
378-
String fileName = iconName;
379-
int index = iconName.indexOf (',');
380-
if (index != -1) {
381-
fileName = iconName.substring (0, index);
382-
String iconIndex = iconName.substring (index + 1, iconName.length ()).trim ();
383-
try {
384-
nIconIndex = Integer.parseInt (iconIndex);
385-
} catch (NumberFormatException e) {}
386-
}
387-
int length = fileName.length ();
388-
if (length > 1 && fileName.charAt (0) == '\"') {
389-
if (fileName.charAt (length - 1) == '\"') {
390-
fileName = fileName.substring (1, length - 1);
391-
}
392-
}
393-
TCHAR lpszFile = new TCHAR (0, fileName, true);
394-
long [] phiconSmall = new long[1], phiconLarge = null;
395-
OS.ExtractIconEx (lpszFile, nIconIndex, phiconLarge, phiconSmall, 1);
396-
if (phiconSmall [0] == 0) return null;
397-
Image image = Image.win32_new (null, SWT.ICON, phiconSmall [0]);
398-
/* Fetch the ImageData at 100% zoom and return */
399-
ImageData imageData = image.getImageData ();
400-
image.dispose ();
401-
return imageData;
366+
return getImageData (100);
367+
}
368+
369+
/**
370+
* Returns the receiver's image data based on the given zoom level.
371+
* This is the icon that is associated with the receiver in the
372+
* operating system.
373+
*
374+
* @param zoom
375+
* The zoom level in % of the standard resolution
376+
*
377+
* @return the image data for the program, may be null
378+
*/
379+
public ImageData getImageData (int zoom) {
380+
if (extension != null) {
381+
SHFILEINFO shfi = new SHFILEINFO ();
382+
int flags = OS.SHGFI_ICON | OS.SHGFI_SMALLICON | OS.SHGFI_USEFILEATTRIBUTES;
383+
TCHAR pszPath = new TCHAR (0, extension, true);
384+
OS.SHGetFileInfo (pszPath.chars, OS.FILE_ATTRIBUTE_NORMAL, shfi, SHFILEINFO.sizeof, flags);
385+
if (shfi.hIcon != 0) {
386+
Image image = Image.win32_new (null, SWT.ICON, shfi.hIcon);
387+
ImageData imageData = image.getImageData (zoom);
388+
image.dispose ();
389+
return imageData;
390+
}
391+
}
392+
int nIconIndex = 0;
393+
String fileName = iconName;
394+
int index = iconName.indexOf (',');
395+
if (index != -1) {
396+
fileName = iconName.substring (0, index);
397+
String iconIndex = iconName.substring (index + 1, iconName.length ()).trim ();
398+
try {
399+
nIconIndex = Integer.parseInt (iconIndex);
400+
} catch (NumberFormatException e) {}
401+
}
402+
int length = fileName.length ();
403+
if (length > 1 && fileName.charAt (0) == '\"') {
404+
if (fileName.charAt (length - 1) == '\"') {
405+
fileName = fileName.substring (1, length - 1);
406+
}
407+
}
408+
TCHAR lpszFile = new TCHAR (0, fileName, true);
409+
long [] phiconSmall = new long[1], phiconLarge = null;
410+
OS.ExtractIconEx (lpszFile, nIconIndex, phiconLarge, phiconSmall, 1);
411+
if (phiconSmall [0] == 0) return null;
412+
Image image = Image.win32_new (null, SWT.ICON, phiconSmall [0]);
413+
ImageData imageData = image.getImageData (zoom);
414+
image.dispose ();
415+
return imageData;
402416
}
403417

404418
/**

0 commit comments

Comments
 (0)