@@ -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 */
363365public 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