Mercurial > dwindows
comparison mac/dw.m @ 1821:69f9aa1e1b1e
Added bitmap button support to dw_window_set_bitmap() and added missing extention handling.
Plus added a simple test of the code to dwtest.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Fri, 26 Oct 2012 04:46:13 +0000 |
parents | d784b85b632e |
children | df7f3967c21e |
comparison
equal
deleted
inserted
replaced
1820:ece7befa9f3d | 1821:69f9aa1e1b1e |
---|---|
9134 * Windows and a pixmap on Unix, pass | 9134 * Windows and a pixmap on Unix, pass |
9135 * NULL if you use the id param) | 9135 * NULL if you use the id param) |
9136 */ | 9136 */ |
9137 void API dw_window_set_bitmap_from_data(HWND handle, unsigned long cid, char *data, int len) | 9137 void API dw_window_set_bitmap_from_data(HWND handle, unsigned long cid, char *data, int len) |
9138 { | 9138 { |
9139 NSObject *object = handle; | 9139 id object = handle; |
9140 if([ object isKindOfClass:[ NSImageView class ] ]) | 9140 |
9141 if([ object isKindOfClass:[ NSImageView class ] ] || [ object isKindOfClass:[ NSButton class ]]) | |
9141 { | 9142 { |
9142 if(data) | 9143 if(data) |
9143 { | 9144 { |
9144 DW_LOCAL_POOL_IN; | 9145 DW_LOCAL_POOL_IN; |
9145 NSImageView *iv = handle; | |
9146 NSData *thisdata = [NSData dataWithBytes:data length:len]; | 9146 NSData *thisdata = [NSData dataWithBytes:data length:len]; |
9147 NSImage *pixmap = [[NSImage alloc] initWithData:thisdata]; | 9147 NSImage *pixmap = [[[NSImage alloc] initWithData:thisdata] autorelease]; |
9148 | 9148 |
9149 if(pixmap) | 9149 if(pixmap) |
9150 { | 9150 { |
9151 [iv setImage:pixmap]; | 9151 [object setImage:pixmap]; |
9152 [pixmap release]; | |
9152 } | 9153 } |
9153 [pixmap release]; | 9154 /* If we changed the bitmap... */ |
9154 /* If we changed the text... */ | |
9155 Item *item = _box_item(handle); | 9155 Item *item = _box_item(handle); |
9156 | 9156 |
9157 /* Check to see if any of the sizes need to be recalculated */ | 9157 /* Check to see if any of the sizes need to be recalculated */ |
9158 if(item && (item->origwidth == -1 || item->origheight == -1)) | 9158 if(item && (item->origwidth == -1 || item->origheight == -1)) |
9159 { | 9159 { |
9160 _control_size(handle, item->origwidth == -1 ? &item->width : NULL, item->origheight == -1 ? &item->height : NULL); | 9160 _control_size(handle, item->origwidth == -1 ? &item->width : NULL, item->origheight == -1 ? &item->height : NULL); |
9161 /* Queue a redraw on the top-level window */ | 9161 /* Queue a redraw on the top-level window */ |
9162 _dw_redraw([iv window], TRUE); | 9162 _dw_redraw([object window], TRUE); |
9163 } | 9163 } |
9164 DW_LOCAL_POOL_OUT; | 9164 DW_LOCAL_POOL_OUT; |
9165 } | 9165 } |
9166 else | 9166 else |
9167 dw_window_set_bitmap(handle, cid, NULL); | 9167 dw_window_set_bitmap(handle, cid, NULL); |
9178 * Windows and a pixmap on Unix, pass | 9178 * Windows and a pixmap on Unix, pass |
9179 * NULL if you use the id param) | 9179 * NULL if you use the id param) |
9180 */ | 9180 */ |
9181 void API dw_window_set_bitmap(HWND handle, unsigned long resid, char *filename) | 9181 void API dw_window_set_bitmap(HWND handle, unsigned long resid, char *filename) |
9182 { | 9182 { |
9183 NSObject *object = handle; | 9183 id object = handle; |
9184 DW_LOCAL_POOL_IN; | 9184 DW_LOCAL_POOL_IN; |
9185 | 9185 |
9186 if([ object isKindOfClass:[ NSImageView class ] ]) | 9186 if([ object isKindOfClass:[ NSImageView class ] ] || [ object isKindOfClass:[ NSButton class ]]) |
9187 { | 9187 { |
9188 NSImageView *iv = handle; | |
9189 NSImage *bitmap = nil; | 9188 NSImage *bitmap = nil; |
9190 | 9189 |
9191 if(filename) | 9190 if(filename) |
9192 { | 9191 { |
9193 bitmap = [[[NSImage alloc] initWithContentsOfFile:[ NSString stringWithUTF8String:filename ]] autorelease]; | 9192 char *ext = _dw_get_image_extension( filename ); |
9194 } | 9193 NSString *nstr = [ NSString stringWithUTF8String:filename ]; |
9195 else if(resid > 0 && resid < 65536) | 9194 |
9195 bitmap = [[[NSImage alloc] initWithContentsOfFile:nstr] autorelease]; | |
9196 | |
9197 if(!bitmap && ext) | |
9198 { | |
9199 nstr = [nstr stringByAppendingString: [NSString stringWithUTF8String:ext]]; | |
9200 bitmap = [[[NSImage alloc] initWithContentsOfFile:nstr] autorelease]; | |
9201 } | |
9202 } | |
9203 if(!bitmap && resid > 0 && resid < 65536) | |
9196 { | 9204 { |
9197 bitmap = _dw_icon_load(resid); | 9205 bitmap = _dw_icon_load(resid); |
9198 } | 9206 } |
9199 | 9207 |
9200 if(bitmap) | 9208 if(bitmap) |
9201 { | 9209 { |
9202 [iv setImage:bitmap]; | 9210 [object setImage:bitmap]; |
9203 /* Queue a redraw on the top-level window */ | 9211 |
9204 _dw_redraw([iv window], TRUE); | 9212 /* If we changed the bitmap... */ |
9213 Item *item = _box_item(handle); | |
9214 | |
9215 /* Check to see if any of the sizes need to be recalculated */ | |
9216 if(item && (item->origwidth == -1 || item->origheight == -1)) | |
9217 { | |
9218 _control_size(handle, item->origwidth == -1 ? &item->width : NULL, item->origheight == -1 ? &item->height : NULL); | |
9219 /* Queue a redraw on the top-level window */ | |
9220 _dw_redraw([object window], TRUE); | |
9221 } | |
9222 [bitmap release]; | |
9205 } | 9223 } |
9206 } | 9224 } |
9207 DW_LOCAL_POOL_OUT; | 9225 DW_LOCAL_POOL_OUT; |
9208 } | 9226 } |
9209 | 9227 |