comparison mac/dw.m @ 674:78f9aa6d6d89

Fixes or fonts and loading images from files. Added Mac specific settings to dwtest.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Mon, 28 Feb 2011 03:09:50 +0000
parents 6d0f0dc7ff7c
children 48f8efba898f
comparison
equal deleted inserted replaced
673:6d0f0dc7ff7c 674:78f9aa6d6d89
198 @interface DWTimerHandler : NSObject { } 198 @interface DWTimerHandler : NSObject { }
199 -(void)runTimer:(id)sender; 199 -(void)runTimer:(id)sender;
200 @end 200 @end
201 201
202 @implementation DWTimerHandler 202 @implementation DWTimerHandler
203 -(void)runTimer:(id)sender { _event_handler(self, nil, 0); } 203 -(void)runTimer:(id)sender { _event_handler(sender, nil, 0); }
204 @end 204 @end
205 205
206 NSApplication *DWApp; 206 NSApplication *DWApp;
207 NSRunLoop *DWRunLoop; 207 NSRunLoop *DWRunLoop;
208 NSMenu *DWMainMenu; 208 NSMenu *DWMainMenu;
1910 * DW pick the appropriate file extension. 1910 * DW pick the appropriate file extension.
1911 * (BMP on OS/2 or Windows, XPM on Unix) 1911 * (BMP on OS/2 or Windows, XPM on Unix)
1912 */ 1912 */
1913 HWND API dw_bitmapbutton_new_from_file(char *text, unsigned long id, char *filename) 1913 HWND API dw_bitmapbutton_new_from_file(char *text, unsigned long id, char *filename)
1914 { 1914 {
1915 NSImage *image = [[NSImage alloc] initWithContentsOfFile:[ NSString stringWithUTF8String:filename ]]; 1915 NSString *nstr = [ NSString stringWithUTF8String:filename ];
1916 NSImage *image = [[NSImage alloc] initWithContentsOfFile:nstr];
1917 if(!image)
1918 {
1919 nstr = [nstr stringByAppendingString:@".png"];
1920 image = [[NSImage alloc] initWithContentsOfFile:nstr];
1921 }
1922 [nstr release];
1916 DWButton *button = _button_new("", id); 1923 DWButton *button = _button_new("", id);
1917 [button setImage:image]; 1924 [button setImage:image];
1918 return button; 1925 return button;
1919 } 1926 }
1920 1927
3634 * DW pick the appropriate file extension. 3641 * DW pick the appropriate file extension.
3635 * (ICO on OS/2 or Windows, XPM on Unix) 3642 * (ICO on OS/2 or Windows, XPM on Unix)
3636 */ 3643 */
3637 HICN API dw_icon_load_from_file(char *filename) 3644 HICN API dw_icon_load_from_file(char *filename)
3638 { 3645 {
3639 return [[NSImage alloc] initWithContentsOfFile:[ NSString stringWithUTF8String:filename ]]; 3646 NSString *nstr = [ NSString stringWithUTF8String:filename ];
3647 NSImage *image = [[NSImage alloc] initWithContentsOfFile:nstr];
3648 if(!image)
3649 {
3650 nstr = [nstr stringByAppendingString:@".png"];
3651 image = [[NSImage alloc] initWithContentsOfFile:nstr];
3652 }
3653 [nstr release];
3654 return image;
3640 } 3655 }
3641 3656
3642 /* 3657 /*
3643 * Obtains an icon from data 3658 * Obtains an icon from data
3644 * Parameters: 3659 * Parameters:
3779 { 3794 {
3780 HPIXMAP pixmap; 3795 HPIXMAP pixmap;
3781 3796
3782 if (!(pixmap = calloc(1,sizeof(struct _hpixmap)))) 3797 if (!(pixmap = calloc(1,sizeof(struct _hpixmap))))
3783 return NULL; 3798 return NULL;
3784 NSImage *image = [[NSImage alloc] initWithContentsOfFile:[ NSString stringWithUTF8String:filename ]]; 3799 NSString *nstr = [ NSString stringWithUTF8String:filename ];
3800 NSImage *image = [[NSImage alloc] initWithContentsOfFile:nstr];
3801 if(!image)
3802 {
3803 nstr = [nstr stringByAppendingString:@".png"];
3804 image = [[NSImage alloc] initWithContentsOfFile:nstr];
3805 }
3806 [nstr release];
3785 NSSize size = [image size]; 3807 NSSize size = [image size];
3786 pixmap->width = size.width; 3808 pixmap->width = size.width;
3787 pixmap->height = size.height; 3809 pixmap->height = size.height;
3788 pixmap->handle = image; 3810 pixmap->handle = image;
3789 return pixmap; 3811 return pixmap;
4663 { 4685 {
4664 [object lockFocus]; 4686 [object lockFocus];
4665 [font set]; 4687 [font set];
4666 [object unlockFocus]; 4688 [object unlockFocus];
4667 } 4689 }
4668 [object setFont:font]; 4690 if([object isMemberOfClass:[NSControl class]])
4691 {
4692 [object setFont:font];
4693 }
4669 } 4694 }
4670 } 4695 }
4671 free(fontcopy); 4696 free(fontcopy);
4672 return 0; 4697 return 0;
4673 } 4698 }