comparison mac/dw.m @ 1708:cc10082567ed

Similar code for Mac to keep HICNs from getting too big.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sat, 05 May 2012 21:32:50 +0000
parents 3fa0448d3a7e
children de49c1f284b2
comparison
equal deleted inserted replaced
1707:0b1be0a99f59 1708:cc10082567ed
6814 DW_LOCAL_POOL_IN; 6814 DW_LOCAL_POOL_IN;
6815 [item release]; 6815 [item release];
6816 DW_LOCAL_POOL_OUT; 6816 DW_LOCAL_POOL_OUT;
6817 } 6817 }
6818 6818
6819 /* Internal function to keep HICNs from getting too big */
6820 void _icon_resize(NSImage *image)
6821 {
6822 NSSize size = [image size];
6823 if(size.width > 24 || size.height > 24)
6824 {
6825 if(size.width > 24)
6826 size.width = 24;
6827 if(size.height > 24)
6828 size.height = 24;
6829 [image setSize:size];
6830 }
6831 }
6832
6819 /* 6833 /*
6820 * Obtains an icon from a module (or header in GTK). 6834 * Obtains an icon from a module (or header in GTK).
6821 * Parameters: 6835 * Parameters:
6822 * module: Handle to module (DLL) in OS/2 and Windows. 6836 * module: Handle to module (DLL) in OS/2 and Windows.
6823 * id: A unsigned long id int the resources on OS/2 and 6837 * id: A unsigned long id int the resources on OS/2 and
6828 { 6842 {
6829 NSBundle *bundle = [NSBundle mainBundle]; 6843 NSBundle *bundle = [NSBundle mainBundle];
6830 NSString *respath = [bundle resourcePath]; 6844 NSString *respath = [bundle resourcePath];
6831 NSString *filepath = [respath stringByAppendingFormat:@"/%u.png", resid]; 6845 NSString *filepath = [respath stringByAppendingFormat:@"/%u.png", resid];
6832 NSImage *image = [[NSImage alloc] initWithContentsOfFile:filepath]; 6846 NSImage *image = [[NSImage alloc] initWithContentsOfFile:filepath];
6847 _icon_resize(image);
6833 return image; 6848 return image;
6834 } 6849 }
6835 6850
6836 /* 6851 /*
6837 * Obtains an icon from a file. 6852 * Obtains an icon from a file.
6849 if(!image && ext) 6864 if(!image && ext)
6850 { 6865 {
6851 nstr = [nstr stringByAppendingString: [NSString stringWithUTF8String:ext]]; 6866 nstr = [nstr stringByAppendingString: [NSString stringWithUTF8String:ext]];
6852 image = [[NSImage alloc] initWithContentsOfFile:nstr]; 6867 image = [[NSImage alloc] initWithContentsOfFile:nstr];
6853 } 6868 }
6869 _icon_resize(image);
6854 return image; 6870 return image;
6855 } 6871 }
6856 6872
6857 /* 6873 /*
6858 * Obtains an icon from data 6874 * Obtains an icon from data
6863 */ 6879 */
6864 HICN API dw_icon_load_from_data(char *data, int len) 6880 HICN API dw_icon_load_from_data(char *data, int len)
6865 { 6881 {
6866 NSData *thisdata = [NSData dataWithBytes:data length:len]; 6882 NSData *thisdata = [NSData dataWithBytes:data length:len];
6867 NSImage *image = [[NSImage alloc] initWithData:thisdata]; 6883 NSImage *image = [[NSImage alloc] initWithData:thisdata];
6884 _icon_resize(image);
6868 return image; 6885 return image;
6869 } 6886 }
6870 6887
6871 /* 6888 /*
6872 * Frees a loaded resource in OS/2 and Windows. 6889 * Frees a loaded resource in OS/2 and Windows.