Mercurial > dwindows
comparison mac/dw.m @ 1580:a51397ea24bf
Added local auto-release macros on Mac to allow us to prevent leaks
on secondary threads without calling _dw_pool_drain().
Macros should be added to any funtions that allocate temporary objects.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Wed, 25 Jan 2012 03:17:36 +0000 |
parents | ae5e322584cd |
children | 728778634933 |
comparison
equal
deleted
inserted
replaced
1579:245e6bf51317 | 1580:a51397ea24bf |
---|---|
38 dw_mutex_unlock(DWRunMutex); \ | 38 dw_mutex_unlock(DWRunMutex); \ |
39 dw_mutex_unlock(DWThreadMutex2); \ | 39 dw_mutex_unlock(DWThreadMutex2); \ |
40 _dw_mutex_locked = (pthread_t)-1; \ | 40 _dw_mutex_locked = (pthread_t)-1; \ |
41 dw_mutex_unlock(DWThreadMutex); \ | 41 dw_mutex_unlock(DWThreadMutex); \ |
42 _locked_by_me = FALSE; } } | 42 _locked_by_me = FALSE; } } |
43 | |
44 /* Macros to handle local auto-release pools */ | |
45 #define DW_LOCAL_POOL_IN NSAutoreleasePool *localpool = nil; \ | |
46 if(DWThread != (DWTID)-1 && pthread_self() != DWThread) \ | |
47 localpool = [[NSAutoreleasePool alloc] init]; | |
48 #define DW_LOCAL_POOL_OUT if(localpool) [localpool drain]; | |
43 | 49 |
44 unsigned long _colors[] = | 50 unsigned long _colors[] = |
45 { | 51 { |
46 0x00000000, /* 0 black */ | 52 0x00000000, /* 0 black */ |
47 0x000000bb, /* 1 red */ | 53 0x000000bb, /* 1 red */ |
3159 */ | 3165 */ |
3160 char * API dw_file_browse(char *title, char *defpath, char *ext, int flags) | 3166 char * API dw_file_browse(char *title, char *defpath, char *ext, int flags) |
3161 { | 3167 { |
3162 char temp[PATH_MAX+1]; | 3168 char temp[PATH_MAX+1]; |
3163 char *file = NULL, *path = NULL; | 3169 char *file = NULL, *path = NULL; |
3170 DW_LOCAL_POOL_IN; | |
3164 | 3171 |
3165 /* Figure out path information... | 3172 /* Figure out path information... |
3166 * These functions are only support in Snow Leopard and later... | 3173 * These functions are only support in Snow Leopard and later... |
3167 */ | 3174 */ |
3168 if(defpath && DWOSMinor > 5) | 3175 if(defpath && DWOSMinor > 5) |
3248 * files and directories selected. | 3255 * files and directories selected. |
3249 */ | 3256 */ |
3250 NSArray *files = [openDlg URLs]; | 3257 NSArray *files = [openDlg URLs]; |
3251 NSString *fileName = [[files objectAtIndex:0] path]; | 3258 NSString *fileName = [[files objectAtIndex:0] path]; |
3252 if(fileName) | 3259 if(fileName) |
3253 return strdup([ fileName UTF8String ]); | 3260 { |
3261 char *ret = strdup([ fileName UTF8String ]); | |
3262 DW_LOCAL_POOL_OUT; | |
3263 return ret; | |
3264 } | |
3254 } | 3265 } |
3255 } | 3266 } |
3256 else | 3267 else |
3257 { | 3268 { |
3258 /* Create the File Save Dialog class. */ | 3269 /* Create the File Save Dialog class. */ |
3281 /* Get an array containing the full filenames of all | 3292 /* Get an array containing the full filenames of all |
3282 * files and directories selected. | 3293 * files and directories selected. |
3283 */ | 3294 */ |
3284 NSString* fileName = [[saveDlg URL] path]; | 3295 NSString* fileName = [[saveDlg URL] path]; |
3285 if(fileName) | 3296 if(fileName) |
3286 return strdup([ fileName UTF8String ]); | 3297 { |
3287 } | 3298 char *ret = strdup([ fileName UTF8String ]); |
3288 } | 3299 DW_LOCAL_POOL_OUT; |
3289 | 3300 return ret; |
3301 } | |
3302 } | |
3303 } | |
3304 DW_LOCAL_POOL_OUT; | |
3290 return NULL; | 3305 return NULL; |
3291 } | 3306 } |
3292 | 3307 |
3293 /* | 3308 /* |
3294 * Gets the contents of the default clipboard as text. | 3309 * Gets the contents of the default clipboard as text. |
5161 */ | 5176 */ |
5162 void API dw_color_foreground_set(unsigned long value) | 5177 void API dw_color_foreground_set(unsigned long value) |
5163 { | 5178 { |
5164 NSColor *oldcolor = pthread_getspecific(_dw_fg_color_key); | 5179 NSColor *oldcolor = pthread_getspecific(_dw_fg_color_key); |
5165 NSColor *newcolor; | 5180 NSColor *newcolor; |
5181 DW_LOCAL_POOL_IN; | |
5166 | 5182 |
5167 _foreground = _get_color(value); | 5183 _foreground = _get_color(value); |
5168 | 5184 |
5169 newcolor = [[NSColor colorWithDeviceRed: DW_RED_VALUE(_foreground)/255.0 green: | 5185 newcolor = [[NSColor colorWithDeviceRed: DW_RED_VALUE(_foreground)/255.0 green: |
5170 DW_GREEN_VALUE(_foreground)/255.0 blue: | 5186 DW_GREEN_VALUE(_foreground)/255.0 blue: |
5171 DW_BLUE_VALUE(_foreground)/255.0 alpha: 1] retain]; | 5187 DW_BLUE_VALUE(_foreground)/255.0 alpha: 1] retain]; |
5172 pthread_setspecific(_dw_fg_color_key, newcolor); | 5188 pthread_setspecific(_dw_fg_color_key, newcolor); |
5173 [oldcolor release]; | 5189 [oldcolor release]; |
5190 DW_LOCAL_POOL_OUT; | |
5174 } | 5191 } |
5175 | 5192 |
5176 /* Sets the current background drawing color. | 5193 /* Sets the current background drawing color. |
5177 * Parameters: | 5194 * Parameters: |
5178 * red: red value. | 5195 * red: red value. |
5181 */ | 5198 */ |
5182 void API dw_color_background_set(unsigned long value) | 5199 void API dw_color_background_set(unsigned long value) |
5183 { | 5200 { |
5184 NSColor *oldcolor = pthread_getspecific(_dw_bg_color_key); | 5201 NSColor *oldcolor = pthread_getspecific(_dw_bg_color_key); |
5185 NSColor *newcolor; | 5202 NSColor *newcolor; |
5203 DW_LOCAL_POOL_IN; | |
5186 | 5204 |
5187 if(value == DW_CLR_DEFAULT) | 5205 if(value == DW_CLR_DEFAULT) |
5188 { | 5206 { |
5189 pthread_setspecific(_dw_bg_color_key, NULL); | 5207 pthread_setspecific(_dw_bg_color_key, NULL); |
5190 } | 5208 } |
5196 DW_GREEN_VALUE(_background)/255.0 blue: | 5214 DW_GREEN_VALUE(_background)/255.0 blue: |
5197 DW_BLUE_VALUE(_background)/255.0 alpha: 1] retain]; | 5215 DW_BLUE_VALUE(_background)/255.0 alpha: 1] retain]; |
5198 pthread_setspecific(_dw_bg_color_key, newcolor); | 5216 pthread_setspecific(_dw_bg_color_key, newcolor); |
5199 } | 5217 } |
5200 [oldcolor release]; | 5218 [oldcolor release]; |
5219 DW_LOCAL_POOL_OUT; | |
5201 } | 5220 } |
5202 | 5221 |
5203 /* Allows the user to choose a color using the system's color chooser dialog. | 5222 /* Allows the user to choose a color using the system's color chooser dialog. |
5204 * Parameters: | 5223 * Parameters: |
5205 * value: current color | 5224 * value: current color |
5255 * y: Y coordinate. | 5274 * y: Y coordinate. |
5256 */ | 5275 */ |
5257 void API dw_draw_point(HWND handle, HPIXMAP pixmap, int x, int y) | 5276 void API dw_draw_point(HWND handle, HPIXMAP pixmap, int x, int y) |
5258 { | 5277 { |
5259 int _locked_by_me = FALSE; | 5278 int _locked_by_me = FALSE; |
5279 DW_LOCAL_POOL_IN; | |
5260 DW_MUTEX_LOCK; | 5280 DW_MUTEX_LOCK; |
5261 id image = handle; | 5281 id image = handle; |
5262 if(pixmap) | 5282 if(pixmap) |
5263 { | 5283 { |
5264 image = (id)pixmap->image; | 5284 image = (id)pixmap->image; |
5269 else | 5289 else |
5270 { | 5290 { |
5271 if([image lockFocusIfCanDraw] == NO) | 5291 if([image lockFocusIfCanDraw] == NO) |
5272 { | 5292 { |
5273 DW_MUTEX_UNLOCK; | 5293 DW_MUTEX_UNLOCK; |
5294 DW_LOCAL_POOL_OUT; | |
5274 return; | 5295 return; |
5275 } | 5296 } |
5276 _DWLastDrawable = handle; | 5297 _DWLastDrawable = handle; |
5277 } | 5298 } |
5278 NSBezierPath* aPath = [NSBezierPath bezierPath]; | 5299 NSBezierPath* aPath = [NSBezierPath bezierPath]; |
5289 else | 5310 else |
5290 { | 5311 { |
5291 [image unlockFocus]; | 5312 [image unlockFocus]; |
5292 } | 5313 } |
5293 DW_MUTEX_UNLOCK; | 5314 DW_MUTEX_UNLOCK; |
5315 DW_LOCAL_POOL_OUT; | |
5294 } | 5316 } |
5295 | 5317 |
5296 /* Draw a line on a window (preferably a render window). | 5318 /* Draw a line on a window (preferably a render window). |
5297 * Parameters: | 5319 * Parameters: |
5298 * handle: Handle to the window. | 5320 * handle: Handle to the window. |
5303 * y2: Second Y coordinate. | 5325 * y2: Second Y coordinate. |
5304 */ | 5326 */ |
5305 void API dw_draw_line(HWND handle, HPIXMAP pixmap, int x1, int y1, int x2, int y2) | 5327 void API dw_draw_line(HWND handle, HPIXMAP pixmap, int x1, int y1, int x2, int y2) |
5306 { | 5328 { |
5307 int _locked_by_me = FALSE; | 5329 int _locked_by_me = FALSE; |
5330 DW_LOCAL_POOL_IN; | |
5308 DW_MUTEX_LOCK; | 5331 DW_MUTEX_LOCK; |
5309 id image = handle; | 5332 id image = handle; |
5310 if(pixmap) | 5333 if(pixmap) |
5311 { | 5334 { |
5312 image = (id)pixmap->image; | 5335 image = (id)pixmap->image; |
5317 else | 5340 else |
5318 { | 5341 { |
5319 if([image lockFocusIfCanDraw] == NO) | 5342 if([image lockFocusIfCanDraw] == NO) |
5320 { | 5343 { |
5321 DW_MUTEX_UNLOCK; | 5344 DW_MUTEX_UNLOCK; |
5345 DW_LOCAL_POOL_OUT; | |
5322 return; | 5346 return; |
5323 } | 5347 } |
5324 _DWLastDrawable = handle; | 5348 _DWLastDrawable = handle; |
5325 } | 5349 } |
5326 NSBezierPath* aPath = [NSBezierPath bezierPath]; | 5350 NSBezierPath* aPath = [NSBezierPath bezierPath]; |
5338 else | 5362 else |
5339 { | 5363 { |
5340 [image unlockFocus]; | 5364 [image unlockFocus]; |
5341 } | 5365 } |
5342 DW_MUTEX_UNLOCK; | 5366 DW_MUTEX_UNLOCK; |
5367 DW_LOCAL_POOL_OUT; | |
5343 } | 5368 } |
5344 | 5369 |
5345 /* Draw text on a window (preferably a render window). | 5370 /* Draw text on a window (preferably a render window). |
5346 * Parameters: | 5371 * Parameters: |
5347 * handle: Handle to the window. | 5372 * handle: Handle to the window. |
5351 * text: Text to be displayed. | 5376 * text: Text to be displayed. |
5352 */ | 5377 */ |
5353 void API dw_draw_text(HWND handle, HPIXMAP pixmap, int x, int y, char *text) | 5378 void API dw_draw_text(HWND handle, HPIXMAP pixmap, int x, int y, char *text) |
5354 { | 5379 { |
5355 int _locked_by_me = FALSE; | 5380 int _locked_by_me = FALSE; |
5381 DW_LOCAL_POOL_IN; | |
5356 DW_MUTEX_LOCK; | 5382 DW_MUTEX_LOCK; |
5357 id image = handle; | 5383 id image = handle; |
5358 NSString *nstr = [ NSString stringWithUTF8String:text ]; | 5384 NSString *nstr = [ NSString stringWithUTF8String:text ]; |
5359 if(image) | 5385 if(image) |
5360 { | 5386 { |
5363 DWRender *render = handle; | 5389 DWRender *render = handle; |
5364 NSFont *font = [render font]; | 5390 NSFont *font = [render font]; |
5365 if([image lockFocusIfCanDraw] == NO) | 5391 if([image lockFocusIfCanDraw] == NO) |
5366 { | 5392 { |
5367 DW_MUTEX_UNLOCK; | 5393 DW_MUTEX_UNLOCK; |
5394 DW_LOCAL_POOL_OUT; | |
5368 return; | 5395 return; |
5369 } | 5396 } |
5370 NSColor *fgcolor = pthread_getspecific(_dw_fg_color_key); | 5397 NSColor *fgcolor = pthread_getspecific(_dw_fg_color_key); |
5371 NSColor *bgcolor = pthread_getspecific(_dw_bg_color_key); | 5398 NSColor *bgcolor = pthread_getspecific(_dw_bg_color_key); |
5372 NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:fgcolor, NSForegroundColorAttributeName, nil]; | 5399 NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:fgcolor, NSForegroundColorAttributeName, nil]; |
5410 [nstr drawAtPoint:NSMakePoint(x, y) withAttributes:dict]; | 5437 [nstr drawAtPoint:NSMakePoint(x, y) withAttributes:dict]; |
5411 [NSGraphicsContext restoreGraphicsState]; | 5438 [NSGraphicsContext restoreGraphicsState]; |
5412 [dict release]; | 5439 [dict release]; |
5413 } | 5440 } |
5414 DW_MUTEX_UNLOCK; | 5441 DW_MUTEX_UNLOCK; |
5442 DW_LOCAL_POOL_OUT; | |
5415 } | 5443 } |
5416 | 5444 |
5417 /* Query the width and height of a text string. | 5445 /* Query the width and height of a text string. |
5418 * Parameters: | 5446 * Parameters: |
5419 * handle: Handle to the window. | 5447 * handle: Handle to the window. |
5423 * height Pointer to a variable to be filled in with the height. | 5451 * height Pointer to a variable to be filled in with the height. |
5424 */ | 5452 */ |
5425 void API dw_font_text_extents_get(HWND handle, HPIXMAP pixmap, char *text, int *width, int *height) | 5453 void API dw_font_text_extents_get(HWND handle, HPIXMAP pixmap, char *text, int *width, int *height) |
5426 { | 5454 { |
5427 id object = handle; | 5455 id object = handle; |
5428 NSString *nstr = [NSString stringWithUTF8String:text]; | 5456 NSString *nstr; |
5429 NSFont *font = nil; | 5457 NSFont *font = nil; |
5458 DW_LOCAL_POOL_IN; | |
5459 | |
5460 nstr = [NSString stringWithUTF8String:text]; | |
5461 | |
5430 /* Check the pixmap for associated object or font */ | 5462 /* Check the pixmap for associated object or font */ |
5431 if(pixmap) | 5463 if(pixmap) |
5432 { | 5464 { |
5433 object = pixmap->handle; | 5465 object = pixmap->handle; |
5434 font = pixmap->font; | 5466 font = pixmap->font; |
5454 } | 5486 } |
5455 if(height) | 5487 if(height) |
5456 { | 5488 { |
5457 *height = size.height; | 5489 *height = size.height; |
5458 } | 5490 } |
5491 DW_LOCAL_POOL_OUT; | |
5459 } | 5492 } |
5460 | 5493 |
5461 /* Internal function to create an image graphics context... | 5494 /* Internal function to create an image graphics context... |
5462 * with or without antialiasing enabled. | 5495 * with or without antialiasing enabled. |
5463 */ | 5496 */ |
5481 * height: Height of rectangle. | 5514 * height: Height of rectangle. |
5482 */ | 5515 */ |
5483 void API dw_draw_polygon( HWND handle, HPIXMAP pixmap, int flags, int npoints, int *x, int *y ) | 5516 void API dw_draw_polygon( HWND handle, HPIXMAP pixmap, int flags, int npoints, int *x, int *y ) |
5484 { | 5517 { |
5485 int _locked_by_me = FALSE; | 5518 int _locked_by_me = FALSE; |
5519 DW_LOCAL_POOL_IN; | |
5486 DW_MUTEX_LOCK; | 5520 DW_MUTEX_LOCK; |
5487 id image = handle; | 5521 id image = handle; |
5488 int z; | 5522 int z; |
5489 if(pixmap) | 5523 if(pixmap) |
5490 { | 5524 { |
5496 else | 5530 else |
5497 { | 5531 { |
5498 if([image lockFocusIfCanDraw] == NO) | 5532 if([image lockFocusIfCanDraw] == NO) |
5499 { | 5533 { |
5500 DW_MUTEX_UNLOCK; | 5534 DW_MUTEX_UNLOCK; |
5535 DW_LOCAL_POOL_OUT; | |
5501 return; | 5536 return; |
5502 } | 5537 } |
5503 [[NSGraphicsContext currentContext] setShouldAntialias:(flags & DW_DRAW_NOAA ? NO : YES)]; | 5538 [[NSGraphicsContext currentContext] setShouldAntialias:(flags & DW_DRAW_NOAA ? NO : YES)]; |
5504 _DWLastDrawable = handle; | 5539 _DWLastDrawable = handle; |
5505 } | 5540 } |
5525 else | 5560 else |
5526 { | 5561 { |
5527 [image unlockFocus]; | 5562 [image unlockFocus]; |
5528 } | 5563 } |
5529 DW_MUTEX_UNLOCK; | 5564 DW_MUTEX_UNLOCK; |
5565 DW_LOCAL_POOL_OUT; | |
5530 } | 5566 } |
5531 | 5567 |
5532 /* Draw a rectangle on a window (preferably a render window). | 5568 /* Draw a rectangle on a window (preferably a render window). |
5533 * Parameters: | 5569 * Parameters: |
5534 * handle: Handle to the window. | 5570 * handle: Handle to the window. |
5540 * height: Height of rectangle. | 5576 * height: Height of rectangle. |
5541 */ | 5577 */ |
5542 void API dw_draw_rect(HWND handle, HPIXMAP pixmap, int flags, int x, int y, int width, int height) | 5578 void API dw_draw_rect(HWND handle, HPIXMAP pixmap, int flags, int x, int y, int width, int height) |
5543 { | 5579 { |
5544 int _locked_by_me = FALSE; | 5580 int _locked_by_me = FALSE; |
5581 DW_LOCAL_POOL_IN; | |
5545 DW_MUTEX_LOCK; | 5582 DW_MUTEX_LOCK; |
5546 id image = handle; | 5583 id image = handle; |
5547 if(pixmap) | 5584 if(pixmap) |
5548 { | 5585 { |
5549 image = (id)pixmap->image; | 5586 image = (id)pixmap->image; |
5554 else | 5591 else |
5555 { | 5592 { |
5556 if([image lockFocusIfCanDraw] == NO) | 5593 if([image lockFocusIfCanDraw] == NO) |
5557 { | 5594 { |
5558 DW_MUTEX_UNLOCK; | 5595 DW_MUTEX_UNLOCK; |
5596 DW_LOCAL_POOL_OUT; | |
5559 return; | 5597 return; |
5560 } | 5598 } |
5561 [[NSGraphicsContext currentContext] setShouldAntialias:(flags & DW_DRAW_NOAA ? NO : YES)]; | 5599 [[NSGraphicsContext currentContext] setShouldAntialias:(flags & DW_DRAW_NOAA ? NO : YES)]; |
5562 _DWLastDrawable = handle; | 5600 _DWLastDrawable = handle; |
5563 } | 5601 } |
5575 else | 5613 else |
5576 { | 5614 { |
5577 [image unlockFocus]; | 5615 [image unlockFocus]; |
5578 } | 5616 } |
5579 DW_MUTEX_UNLOCK; | 5617 DW_MUTEX_UNLOCK; |
5618 DW_LOCAL_POOL_OUT; | |
5580 } | 5619 } |
5581 | 5620 |
5582 /* Draw an arc on a window (preferably a render window). | 5621 /* Draw an arc on a window (preferably a render window). |
5583 * Parameters: | 5622 * Parameters: |
5584 * handle: Handle to the window. | 5623 * handle: Handle to the window. |
5593 * y2: Y coordinate of second segment of arc. | 5632 * y2: Y coordinate of second segment of arc. |
5594 */ | 5633 */ |
5595 void API dw_draw_arc(HWND handle, HPIXMAP pixmap, int flags, int xorigin, int yorigin, int x1, int y1, int x2, int y2) | 5634 void API dw_draw_arc(HWND handle, HPIXMAP pixmap, int flags, int xorigin, int yorigin, int x1, int y1, int x2, int y2) |
5596 { | 5635 { |
5597 int _locked_by_me = FALSE; | 5636 int _locked_by_me = FALSE; |
5637 DW_LOCAL_POOL_IN; | |
5598 DW_MUTEX_LOCK; | 5638 DW_MUTEX_LOCK; |
5599 id image = handle; | 5639 id image = handle; |
5600 double r, a1, a2, a; | 5640 double r, a1, a2, a; |
5601 | 5641 |
5602 if(pixmap) | 5642 if(pixmap) |
5609 else | 5649 else |
5610 { | 5650 { |
5611 if([image lockFocusIfCanDraw] == NO) | 5651 if([image lockFocusIfCanDraw] == NO) |
5612 { | 5652 { |
5613 DW_MUTEX_UNLOCK; | 5653 DW_MUTEX_UNLOCK; |
5654 DW_LOCAL_POOL_OUT; | |
5614 return; | 5655 return; |
5615 } | 5656 } |
5616 [[NSGraphicsContext currentContext] setShouldAntialias:(flags & DW_DRAW_NOAA ? NO : YES)]; | 5657 [[NSGraphicsContext currentContext] setShouldAntialias:(flags & DW_DRAW_NOAA ? NO : YES)]; |
5617 _DWLastDrawable = handle; | 5658 _DWLastDrawable = handle; |
5618 } | 5659 } |
5654 else | 5695 else |
5655 { | 5696 { |
5656 [image unlockFocus]; | 5697 [image unlockFocus]; |
5657 } | 5698 } |
5658 DW_MUTEX_UNLOCK; | 5699 DW_MUTEX_UNLOCK; |
5700 DW_LOCAL_POOL_OUT; | |
5659 } | 5701 } |
5660 | 5702 |
5661 /* | 5703 /* |
5662 * Create a tree object to be packed. | 5704 * Create a tree object to be packed. |
5663 * Parameters: | 5705 * Parameters: |
6880 * A handle to a pixmap or NULL on failure. | 6922 * A handle to a pixmap or NULL on failure. |
6881 */ | 6923 */ |
6882 HPIXMAP API dw_pixmap_new_from_file(HWND handle, char *filename) | 6924 HPIXMAP API dw_pixmap_new_from_file(HWND handle, char *filename) |
6883 { | 6925 { |
6884 HPIXMAP pixmap; | 6926 HPIXMAP pixmap; |
6927 DW_LOCAL_POOL_IN; | |
6885 char *ext = _dw_get_image_extension( filename ); | 6928 char *ext = _dw_get_image_extension( filename ); |
6886 | 6929 |
6887 if(!(pixmap = calloc(1,sizeof(struct _hpixmap)))) | 6930 if(!(pixmap = calloc(1,sizeof(struct _hpixmap)))) |
6931 { | |
6932 DW_LOCAL_POOL_OUT; | |
6888 return NULL; | 6933 return NULL; |
6934 } | |
6889 NSString *nstr = [ NSString stringWithUTF8String:filename ]; | 6935 NSString *nstr = [ NSString stringWithUTF8String:filename ]; |
6890 NSImage *tmpimage = [[[NSImage alloc] initWithContentsOfFile:nstr] autorelease]; | 6936 NSImage *tmpimage = [[[NSImage alloc] initWithContentsOfFile:nstr] autorelease]; |
6891 if(!tmpimage && ext) | 6937 if(!tmpimage && ext) |
6892 { | 6938 { |
6893 nstr = [nstr stringByAppendingString: [NSString stringWithUTF8String:ext]]; | 6939 nstr = [nstr stringByAppendingString: [NSString stringWithUTF8String:ext]]; |
6894 tmpimage = [[[NSImage alloc] initWithContentsOfFile:nstr] autorelease]; | 6940 tmpimage = [[[NSImage alloc] initWithContentsOfFile:nstr] autorelease]; |
6895 } | 6941 } |
6896 if(!tmpimage) | 6942 if(!tmpimage) |
6943 { | |
6944 DW_LOCAL_POOL_OUT; | |
6897 return NULL; | 6945 return NULL; |
6946 } | |
6898 NSSize size = [tmpimage size]; | 6947 NSSize size = [tmpimage size]; |
6899 NSBitmapImageRep *image = [[NSBitmapImageRep alloc] | 6948 NSBitmapImageRep *image = [[NSBitmapImageRep alloc] |
6900 initWithBitmapDataPlanes:NULL | 6949 initWithBitmapDataPlanes:NULL |
6901 pixelsWide:size.width | 6950 pixelsWide:size.width |
6902 pixelsHigh:size.height | 6951 pixelsHigh:size.height |
6910 _flip_image(tmpimage, image, size); | 6959 _flip_image(tmpimage, image, size); |
6911 pixmap->width = size.width; | 6960 pixmap->width = size.width; |
6912 pixmap->height = size.height; | 6961 pixmap->height = size.height; |
6913 pixmap->image = image; | 6962 pixmap->image = image; |
6914 pixmap->handle = handle; | 6963 pixmap->handle = handle; |
6964 DW_LOCAL_POOL_OUT; | |
6915 return pixmap; | 6965 return pixmap; |
6916 } | 6966 } |
6917 | 6967 |
6918 /* | 6968 /* |
6919 * Creates a pixmap from memory. | 6969 * Creates a pixmap from memory. |
6926 * A handle to a pixmap or NULL on failure. | 6976 * A handle to a pixmap or NULL on failure. |
6927 */ | 6977 */ |
6928 HPIXMAP API dw_pixmap_new_from_data(HWND handle, char *data, int len) | 6978 HPIXMAP API dw_pixmap_new_from_data(HWND handle, char *data, int len) |
6929 { | 6979 { |
6930 HPIXMAP pixmap; | 6980 HPIXMAP pixmap; |
6981 DW_LOCAL_POOL_IN; | |
6931 | 6982 |
6932 if(!(pixmap = calloc(1,sizeof(struct _hpixmap)))) | 6983 if(!(pixmap = calloc(1,sizeof(struct _hpixmap)))) |
6984 { | |
6985 DW_LOCAL_POOL_OUT; | |
6933 return NULL; | 6986 return NULL; |
6987 } | |
6934 NSData *thisdata = [NSData dataWithBytes:data length:len]; | 6988 NSData *thisdata = [NSData dataWithBytes:data length:len]; |
6935 NSImage *tmpimage = [[[NSImage alloc] initWithData:thisdata] autorelease]; | 6989 NSImage *tmpimage = [[[NSImage alloc] initWithData:thisdata] autorelease]; |
6936 if(!tmpimage) | 6990 if(!tmpimage) |
6991 { | |
6992 DW_LOCAL_POOL_OUT; | |
6937 return NULL; | 6993 return NULL; |
6994 } | |
6938 NSSize size = [tmpimage size]; | 6995 NSSize size = [tmpimage size]; |
6939 NSBitmapImageRep *image = [[NSBitmapImageRep alloc] | 6996 NSBitmapImageRep *image = [[NSBitmapImageRep alloc] |
6940 initWithBitmapDataPlanes:NULL | 6997 initWithBitmapDataPlanes:NULL |
6941 pixelsWide:size.width | 6998 pixelsWide:size.width |
6942 pixelsHigh:size.height | 6999 pixelsHigh:size.height |
6950 _flip_image(tmpimage, image, size); | 7007 _flip_image(tmpimage, image, size); |
6951 pixmap->width = size.width; | 7008 pixmap->width = size.width; |
6952 pixmap->height = size.height; | 7009 pixmap->height = size.height; |
6953 pixmap->image = image; | 7010 pixmap->image = image; |
6954 pixmap->handle = handle; | 7011 pixmap->handle = handle; |
7012 DW_LOCAL_POOL_OUT; | |
6955 return pixmap; | 7013 return pixmap; |
6956 } | 7014 } |
6957 | 7015 |
6958 /* | 7016 /* |
6959 * Sets the transparent color for a pixmap | 7017 * Sets the transparent color for a pixmap |
6978 * A handle to a pixmap or NULL on failure. | 7036 * A handle to a pixmap or NULL on failure. |
6979 */ | 7037 */ |
6980 HPIXMAP API dw_pixmap_grab(HWND handle, ULONG resid) | 7038 HPIXMAP API dw_pixmap_grab(HWND handle, ULONG resid) |
6981 { | 7039 { |
6982 HPIXMAP pixmap; | 7040 HPIXMAP pixmap; |
7041 DW_LOCAL_POOL_IN; | |
6983 | 7042 |
6984 if(!(pixmap = calloc(1,sizeof(struct _hpixmap)))) | 7043 if(!(pixmap = calloc(1,sizeof(struct _hpixmap)))) |
7044 { | |
7045 DW_LOCAL_POOL_OUT; | |
6985 return NULL; | 7046 return NULL; |
7047 } | |
6986 | 7048 |
6987 NSBundle *bundle = [NSBundle mainBundle]; | 7049 NSBundle *bundle = [NSBundle mainBundle]; |
6988 NSString *respath = [bundle resourcePath]; | 7050 NSString *respath = [bundle resourcePath]; |
6989 NSString *filepath = [respath stringByAppendingFormat:@"/%u.png", resid]; | 7051 NSString *filepath = [respath stringByAppendingFormat:@"/%u.png", resid]; |
6990 NSImage *temp = [[NSImage alloc] initWithContentsOfFile:filepath]; | 7052 NSImage *temp = [[NSImage alloc] initWithContentsOfFile:filepath]; |
7010 pixmap->handle = handle; | 7072 pixmap->handle = handle; |
7011 [temp release]; | 7073 [temp release]; |
7012 return pixmap; | 7074 return pixmap; |
7013 } | 7075 } |
7014 free(pixmap); | 7076 free(pixmap); |
7077 DW_LOCAL_POOL_OUT; | |
7015 return NULL; | 7078 return NULL; |
7016 } | 7079 } |
7017 | 7080 |
7018 /* | 7081 /* |
7019 * Sets the font used by a specified pixmap. | 7082 * Sets the font used by a specified pixmap. |
7101 * DW_ERROR_NONE on success and DW_ERROR_GENERAL on failure. | 7164 * DW_ERROR_NONE on success and DW_ERROR_GENERAL on failure. |
7102 */ | 7165 */ |
7103 int API dw_pixmap_stretch_bitblt(HWND dest, HPIXMAP destp, int xdest, int ydest, int width, int height, HWND src, HPIXMAP srcp, int xsrc, int ysrc, int srcwidth, int srcheight) | 7166 int API dw_pixmap_stretch_bitblt(HWND dest, HPIXMAP destp, int xdest, int ydest, int width, int height, HWND src, HPIXMAP srcp, int xsrc, int ysrc, int srcwidth, int srcheight) |
7104 { | 7167 { |
7105 DWBitBlt *bltinfo = calloc(1, sizeof(DWBitBlt)); | 7168 DWBitBlt *bltinfo = calloc(1, sizeof(DWBitBlt)); |
7106 NSValue* bi = [NSValue valueWithPointer:bltinfo]; | 7169 NSValue* bi; |
7170 DW_LOCAL_POOL_IN; | |
7171 | |
7172 bi = [NSValue valueWithPointer:bltinfo]; | |
7107 | 7173 |
7108 /* Sanity checks */ | 7174 /* Sanity checks */ |
7109 if((!dest && !destp) || (!src && !srcp) || | 7175 if((!dest && !destp) || (!src && !srcp) || |
7110 ((srcwidth == -1 || srcheight == -1) && srcwidth != srcheight)) | 7176 ((srcwidth == -1 || srcheight == -1) && srcwidth != srcheight)) |
7177 { | |
7178 DW_LOCAL_POOL_OUT; | |
7111 return DW_ERROR_GENERAL; | 7179 return DW_ERROR_GENERAL; |
7180 } | |
7112 | 7181 |
7113 /* Fill in the information */ | 7182 /* Fill in the information */ |
7114 bltinfo->dest = dest; | 7183 bltinfo->dest = dest; |
7115 bltinfo->src = src; | 7184 bltinfo->src = src; |
7116 bltinfo->xdest = xdest; | 7185 bltinfo->xdest = xdest; |
7129 if(srcp) | 7198 if(srcp) |
7130 { | 7199 { |
7131 id object = bltinfo->src = (id)srcp->image; | 7200 id object = bltinfo->src = (id)srcp->image; |
7132 [object retain]; | 7201 [object retain]; |
7133 } | 7202 } |
7134 [DWObj performSelectorOnMainThread:@selector(doBitBlt:) withObject:bi waitUntilDone:YES]; | 7203 if(DWThread == (DWTID)-1) |
7204 [DWObj doBitBlt:bi]; | |
7205 else | |
7206 [DWObj performSelectorOnMainThread:@selector(doBitBlt:) withObject:bi waitUntilDone:YES]; | |
7207 DW_LOCAL_POOL_OUT; | |
7135 return DW_ERROR_NONE; | 7208 return DW_ERROR_NONE; |
7136 } | 7209 } |
7137 | 7210 |
7138 /* | 7211 /* |
7139 * Create a new static text window (widget) to be packed. | 7212 * Create a new static text window (widget) to be packed. |
7746 * data: Pointer to the data to be passed to the function. | 7819 * data: Pointer to the data to be passed to the function. |
7747 */ | 7820 */ |
7748 void API dw_window_function(HWND handle, void *function, void *data) | 7821 void API dw_window_function(HWND handle, void *function, void *data) |
7749 { | 7822 { |
7750 void **params = calloc(2, sizeof(void *)); | 7823 void **params = calloc(2, sizeof(void *)); |
7751 NSValue *v = [NSValue valueWithPointer:params]; | 7824 NSValue *v; |
7825 DW_LOCAL_POOL_IN; | |
7826 v = [NSValue valueWithPointer:params]; | |
7752 params[0] = function; | 7827 params[0] = function; |
7753 params[1] = data; | 7828 params[1] = data; |
7754 [DWObj performSelectorOnMainThread:@selector(doWindowFunc:) withObject:v waitUntilDone:YES]; | 7829 [DWObj performSelectorOnMainThread:@selector(doWindowFunc:) withObject:v waitUntilDone:YES]; |
7755 free(params); | 7830 free(params); |
7831 DW_LOCAL_POOL_OUT; | |
7756 } | 7832 } |
7757 | 7833 |
7758 | 7834 |
7759 /* | 7835 /* |
7760 * Changes the appearance of the mouse pointer. | 7836 * Changes the appearance of the mouse pointer. |
8572 * NULL if you use the id param) | 8648 * NULL if you use the id param) |
8573 */ | 8649 */ |
8574 void API dw_window_set_bitmap(HWND handle, unsigned long resid, char *filename) | 8650 void API dw_window_set_bitmap(HWND handle, unsigned long resid, char *filename) |
8575 { | 8651 { |
8576 NSObject *object = handle; | 8652 NSObject *object = handle; |
8653 DW_LOCAL_POOL_IN; | |
8654 | |
8577 if([ object isKindOfClass:[ NSImageView class ] ]) | 8655 if([ object isKindOfClass:[ NSImageView class ] ]) |
8578 { | 8656 { |
8579 NSImageView *iv = handle; | 8657 NSImageView *iv = handle; |
8580 NSImage *bitmap = nil; | 8658 NSImage *bitmap = nil; |
8581 | 8659 |
8593 [iv setImage:bitmap]; | 8671 [iv setImage:bitmap]; |
8594 /* Queue a redraw on the top-level window */ | 8672 /* Queue a redraw on the top-level window */ |
8595 _dw_redraw([iv window], TRUE); | 8673 _dw_redraw([iv window], TRUE); |
8596 } | 8674 } |
8597 } | 8675 } |
8676 DW_LOCAL_POOL_OUT; | |
8598 } | 8677 } |
8599 | 8678 |
8600 /* | 8679 /* |
8601 * Sets the icon used for a given window. | 8680 * Sets the icon used for a given window. |
8602 * Parameters: | 8681 * Parameters: |