Mercurial > dwindows
comparison mac/dw.m @ 671:c60a4f6cfae8
Implemented icon support on the Mac. In the process created a new HICN type.
The existing implementation works well on OS/2 but it is kind of bad on the
other platforms. I should revisit the Windows and GTK implementations.
The typedef currently in use should be backwards compatible for now.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Sun, 27 Feb 2011 19:01:40 +0000 |
parents | 0b920d0dc13e |
children | 388f2a48aaae |
comparison
equal
deleted
inserted
replaced
670:0b920d0dc13e | 671:c60a4f6cfae8 |
---|---|
3 * A GTK like implementation of the MacOS GUI using Cocoa | 3 * A GTK like implementation of the MacOS GUI using Cocoa |
4 * | 4 * |
5 * (C) 2011 Brian Smith <brian@dbsoft.org> | 5 * (C) 2011 Brian Smith <brian@dbsoft.org> |
6 * | 6 * |
7 * Using garbage collection so requires 10.5 or later. | 7 * Using garbage collection so requires 10.5 or later. |
8 * clang -std=c99 -g -o dwtest -D__MAC__ -I. mac/dw.m -framework Cocoa -fobjc-gc-only | 8 * clang -std=c99 -g -o dwtest -D__MAC__ -I. dwtest.c mac/dw.m -framework Cocoa -framework WebKit -fobjc-gc-only |
9 */ | 9 */ |
10 #import <Cocoa/Cocoa.h> | 10 #import <Cocoa/Cocoa.h> |
11 #import <WebKit/WebKit.h> | 11 #import <WebKit/WebKit.h> |
12 #include "dw.h" | 12 #include "dw.h" |
13 #include <sys/utsname.h> | 13 #include <sys/utsname.h> |
121 { | 121 { |
122 int (* API buttonfunc)(HWND, int, int, int, void *) = (int (* API)(HWND, int, int, int, void *))handler->signalfunction; | 122 int (* API buttonfunc)(HWND, int, int, int, void *) = (int (* API)(HWND, int, int, int, void *))handler->signalfunction; |
123 int flags = (int)[object pressedMouseButtons]; | 123 int flags = (int)[object pressedMouseButtons]; |
124 NSPoint point = [object mouseLocation]; | 124 NSPoint point = [object mouseLocation]; |
125 int button = 0; | 125 int button = 0; |
126 char *which = "pressed"; | |
127 | |
128 if(message == 4) | |
129 { | |
130 which = "released"; | |
131 } | |
132 | 126 |
133 if(flags & 1) | 127 if(flags & 1) |
134 { | 128 { |
135 button = 1; | 129 button = 1; |
136 } | 130 } |
141 else if(flags & (1 << 2)) | 135 else if(flags & (1 << 2)) |
142 { | 136 { |
143 button = 3; | 137 button = 3; |
144 } | 138 } |
145 | 139 |
146 NSLog(@"Button %s x:%d y:%d button:%d\n", which, (int)point.x, (int)point.y, (int)button); | |
147 return buttonfunc(object, point.x, point.y, button, handler->data); | 140 return buttonfunc(object, point.x, point.y, button, handler->data); |
148 } | 141 } |
149 case 6: | 142 case 6: |
150 { | 143 { |
151 int (* API closefunc)(HWND, void *) = (int (* API)(HWND, void *))handler->signalfunction; | 144 int (* API closefunc)(HWND, void *) = (int (* API)(HWND, void *))handler->signalfunction; |
857 } | 850 } |
858 return 0L; | 851 return 0L; |
859 } | 852 } |
860 | 853 |
861 unsigned long _foreground = 0xAAAAAA, _background = 0; | 854 unsigned long _foreground = 0xAAAAAA, _background = 0; |
862 | |
863 /* This function will recursively search a box and add up the total height of it */ | |
864 static void _count_size(HWND thisbox, int type, int *xsize, int *xorigsize) | |
865 { | |
866 int size = 0, origsize = 0, z; | |
867 DWBox *box = thisbox; | |
868 Box *tmp = [box box]; | |
869 | |
870 if(!tmp) | |
871 { | |
872 *xsize = *xorigsize = 0; | |
873 return; | |
874 } | |
875 | |
876 if(type == tmp->type) | |
877 { | |
878 /* If the box is going in the direction we want, then we | |
879 * return the entire sum of the items. | |
880 */ | |
881 for(z=0;z<tmp->count;z++) | |
882 { | |
883 if(tmp->items[z].type == TYPEBOX) | |
884 { | |
885 int s, os; | |
886 | |
887 _count_size(tmp->items[z].hwnd, type, &s, &os); | |
888 size += s; | |
889 origsize += os; | |
890 } | |
891 else | |
892 { | |
893 size += (type == DW_HORZ ? tmp->items[z].width : tmp->items[z].height); | |
894 origsize += (type == DW_HORZ ? tmp->items[z].origwidth : tmp->items[z].origheight); | |
895 } | |
896 } | |
897 } | |
898 else | |
899 { | |
900 /* If the box is not going in the direction we want, then we only | |
901 * want to return the maximum value. | |
902 */ | |
903 int tmpsize = 0, tmporigsize = 0; | |
904 | |
905 for(z=0;z<tmp->count;z++) | |
906 { | |
907 if(tmp->items[z].type == TYPEBOX) | |
908 _count_size(tmp->items[z].hwnd, type, &tmpsize, &tmporigsize); | |
909 else | |
910 { | |
911 tmpsize = (type == DW_HORZ ? tmp->items[z].width : tmp->items[z].height); | |
912 tmporigsize = (type == DW_HORZ ? tmp->items[z].origwidth : tmp->items[z].origheight); | |
913 } | |
914 | |
915 if(tmpsize > size) | |
916 size = tmpsize; | |
917 } | |
918 } | |
919 | |
920 *xsize = size; | |
921 *xorigsize = origsize; | |
922 } | |
923 | 855 |
924 /* This function calculates how much space the widgets and boxes require | 856 /* This function calculates how much space the widgets and boxes require |
925 * and does expansion as necessary. | 857 * and does expansion as necessary. |
926 */ | 858 */ |
927 static int _resize_box(Box *thisbox, int *depth, int x, int y, int *usedx, int *usedy, | 859 static int _resize_box(Box *thisbox, int *depth, int x, int y, int *usedx, int *usedy, |
1280 _resize_box(thisbox, &depth, x, y, &usedx, &usedy, 2, &usedpadx, &usedpady); | 1212 _resize_box(thisbox, &depth, x, y, &usedx, &usedy, 2, &usedpadx, &usedpady); |
1281 } | 1213 } |
1282 } | 1214 } |
1283 } | 1215 } |
1284 | 1216 |
1285 static void _changebox(Box *thisbox, int percent, int type) | |
1286 { | |
1287 int z; | |
1288 | |
1289 for(z=0;z<thisbox->count;z++) | |
1290 { | |
1291 if(thisbox->items[z].type == TYPEBOX) | |
1292 { | |
1293 DWBox *box = thisbox->items[z].hwnd; | |
1294 Box *tmp = [box box]; | |
1295 _changebox(tmp, percent, type); | |
1296 } | |
1297 else | |
1298 { | |
1299 if(type == DW_HORZ) | |
1300 { | |
1301 if(thisbox->items[z].hsize == SIZEEXPAND) | |
1302 thisbox->items[z].width = (int)(((float)thisbox->items[z].origwidth) * (((float)percent)/((float)100.0))); | |
1303 } | |
1304 else | |
1305 { | |
1306 if(thisbox->items[z].vsize == SIZEEXPAND) | |
1307 thisbox->items[z].height = (int)(((float)thisbox->items[z].origheight) * (((float)percent)/((float)100.0))); | |
1308 } | |
1309 } | |
1310 } | |
1311 } | |
1312 | |
1313 NSMenu *_generate_main_menu() | 1217 NSMenu *_generate_main_menu() |
1314 { | 1218 { |
1315 /* This only works on 10.6 so we have a backup method */ | 1219 /* This only works on 10.6 so we have a backup method */ |
1316 NSString * applicationName = [[NSRunningApplication currentApplication] localizedName]; | 1220 NSString * applicationName = [[NSRunningApplication currentApplication] localizedName]; |
1317 if(applicationName == nil) | 1221 if(applicationName == nil) |
1390 DWApp = [NSApplication sharedApplication]; | 1294 DWApp = [NSApplication sharedApplication]; |
1391 /* Create a run loop for doing manual loops */ | 1295 /* Create a run loop for doing manual loops */ |
1392 DWRunLoop = [NSRunLoop alloc]; | 1296 DWRunLoop = [NSRunLoop alloc]; |
1393 /* Create object for handling timers */ | 1297 /* Create object for handling timers */ |
1394 DWHandler = [[DWTimerHandler alloc] init]; | 1298 DWHandler = [[DWTimerHandler alloc] init]; |
1299 /* If we aren't using garbage collection we need autorelease pools */ | |
1395 #if !defined(GARBAGE_COLLECT) | 1300 #if !defined(GARBAGE_COLLECT) |
1396 pool = [[NSAutoreleasePool alloc] init]; | 1301 pool = [[NSAutoreleasePool alloc] init]; |
1397 #endif | 1302 #endif |
1303 /* Create a default main menu, with just the application menu */ | |
1398 DWMainMenu = _generate_main_menu(); | 1304 DWMainMenu = _generate_main_menu(); |
1399 [DWApp setMainMenu:DWMainMenu]; | 1305 [DWApp setMainMenu:DWMainMenu]; |
1400 /*DWObject *test = [[DWObject alloc] init]; | 1306 DWObject *test = [[DWObject alloc] init]; |
1307 /* Use NSThread to start a dummy thread to initialize the threading subsystem */ | |
1401 NSThread *thread = [[ NSThread alloc] initWithTarget:test selector:@selector(uselessThread:) object:nil]; | 1308 NSThread *thread = [[ NSThread alloc] initWithTarget:test selector:@selector(uselessThread:) object:nil]; |
1402 [thread start];*/ | 1309 [thread start]; |
1403 return 0; | 1310 return 0; |
1404 } | 1311 } |
1405 | 1312 |
1406 /* | 1313 /* |
1407 * Runs a message loop for Dynamic Windows. | 1314 * Runs a message loop for Dynamic Windows. |
1975 * text: Bubble help text to be displayed. | 1882 * text: Bubble help text to be displayed. |
1976 * id: An ID of a bitmap in the resource file. | 1883 * id: An ID of a bitmap in the resource file. |
1977 */ | 1884 */ |
1978 HWND API dw_bitmapbutton_new(char *text, ULONG resid) | 1885 HWND API dw_bitmapbutton_new(char *text, ULONG resid) |
1979 { | 1886 { |
1887 /* TODO: Implement tooltips */ | |
1980 NSBundle *bundle = [NSBundle mainBundle]; | 1888 NSBundle *bundle = [NSBundle mainBundle]; |
1981 NSString *respath = [bundle resourcePath]; | 1889 NSString *respath = [bundle resourcePath]; |
1982 NSString *filepath = [respath stringByAppendingFormat:@"/%u.png", resid]; | 1890 NSString *filepath = [respath stringByAppendingFormat:@"/%u.png", resid]; |
1983 NSImage *image = [[NSImage alloc] initWithContentsOfFile:filepath]; | 1891 NSImage *image = [[NSImage alloc] initWithContentsOfFile:filepath]; |
1984 DWButton *button = _button_new("", resid); | 1892 DWButton *button = _button_new("", resid); |
2846 * green: green value. | 2754 * green: green value. |
2847 * blue: blue value. | 2755 * blue: blue value. |
2848 */ | 2756 */ |
2849 void API dw_color_foreground_set(unsigned long value) | 2757 void API dw_color_foreground_set(unsigned long value) |
2850 { | 2758 { |
2759 /* This may need to be thread specific */ | |
2851 _foreground = _get_color(value); | 2760 _foreground = _get_color(value); |
2852 } | 2761 } |
2853 | 2762 |
2854 /* Sets the current background drawing color. | 2763 /* Sets the current background drawing color. |
2855 * Parameters: | 2764 * Parameters: |
2857 * green: green value. | 2766 * green: green value. |
2858 * blue: blue value. | 2767 * blue: blue value. |
2859 */ | 2768 */ |
2860 void API dw_color_background_set(unsigned long value) | 2769 void API dw_color_background_set(unsigned long value) |
2861 { | 2770 { |
2771 /* This may need to be thread specific */ | |
2862 _background = _get_color(value); | 2772 _background = _get_color(value); |
2863 } | 2773 } |
2864 | 2774 |
2865 /* Allows the user to choose a color using the system's color chooser dialog. | 2775 /* Allows the user to choose a color using the system's color chooser dialog. |
2866 * Parameters: | 2776 * Parameters: |
3137 * title: The text title of the entry. | 3047 * title: The text title of the entry. |
3138 * icon: Handle to coresponding icon. | 3048 * icon: Handle to coresponding icon. |
3139 * parent: Parent handle or 0 if root. | 3049 * parent: Parent handle or 0 if root. |
3140 * itemdata: Item specific data. | 3050 * itemdata: Item specific data. |
3141 */ | 3051 */ |
3142 HTREEITEM API dw_tree_insert_after(HWND handle, HTREEITEM item, char *title, unsigned long icon, HTREEITEM parent, void *itemdata) | 3052 HTREEITEM API dw_tree_insert_after(HWND handle, HTREEITEM item, char *title, HICN icon, HTREEITEM parent, void *itemdata) |
3143 { | 3053 { |
3144 NSLog(@"dw_tree_insert_item_after() unimplemented\n"); | 3054 NSLog(@"dw_tree_insert_item_after() unimplemented\n"); |
3145 return HWND_DESKTOP; | 3055 return HWND_DESKTOP; |
3146 } | 3056 } |
3147 | 3057 |
3152 * title: The text title of the entry. | 3062 * title: The text title of the entry. |
3153 * icon: Handle to coresponding icon. | 3063 * icon: Handle to coresponding icon. |
3154 * parent: Parent handle or 0 if root. | 3064 * parent: Parent handle or 0 if root. |
3155 * itemdata: Item specific data. | 3065 * itemdata: Item specific data. |
3156 */ | 3066 */ |
3157 HTREEITEM API dw_tree_insert(HWND handle, char *title, unsigned long icon, HTREEITEM parent, void *itemdata) | 3067 HTREEITEM API dw_tree_insert(HWND handle, char *title, HICN icon, HTREEITEM parent, void *itemdata) |
3158 { | 3068 { |
3159 NSLog(@"dw_tree_insert_item() unimplemented\n"); | 3069 NSLog(@"dw_tree_insert_item() unimplemented\n"); |
3160 return HWND_DESKTOP; | 3070 return HWND_DESKTOP; |
3161 } | 3071 } |
3162 | 3072 |
3190 * handle: Handle to the tree containing the item. | 3100 * handle: Handle to the tree containing the item. |
3191 * item: Handle of the item to be modified. | 3101 * item: Handle of the item to be modified. |
3192 * title: The text title of the entry. | 3102 * title: The text title of the entry. |
3193 * icon: Handle to coresponding icon. | 3103 * icon: Handle to coresponding icon. |
3194 */ | 3104 */ |
3195 void API dw_tree_item_change(HWND handle, HTREEITEM item, char *title, unsigned long icon) | 3105 void API dw_tree_item_change(HWND handle, HTREEITEM item, char *title, HICN icon) |
3196 { | 3106 { |
3197 NSLog(@"dw_tree_item_change() unimplemented\n"); | 3107 NSLog(@"dw_tree_item_change() unimplemented\n"); |
3198 } | 3108 } |
3199 | 3109 |
3200 /* | 3110 /* |
3310 | 3220 |
3311 for(z=0;z<count;z++) | 3221 for(z=0;z<count;z++) |
3312 { | 3222 { |
3313 NSTableColumn *column = [[NSTableColumn alloc] init]; | 3223 NSTableColumn *column = [[NSTableColumn alloc] init]; |
3314 [[column headerCell] setStringValue:[ NSString stringWithUTF8String:titles[z] ]]; | 3224 [[column headerCell] setStringValue:[ NSString stringWithUTF8String:titles[z] ]]; |
3225 if(flags[z] & DW_CFA_BITMAPORICON) | |
3226 { | |
3227 NSImageCell *imagecell = [[[NSImageCell alloc] init] autorelease]; | |
3228 [column setDataCell:imagecell]; | |
3229 } | |
3315 [cont addTableColumn:column]; | 3230 [cont addTableColumn:column]; |
3316 [cont addColumn:column andType:(int)flags[z]]; | 3231 [cont addColumn:column andType:(int)flags[z]]; |
3317 } | 3232 } |
3318 | 3233 |
3319 return TRUE; | 3234 return TRUE; |
3374 { | 3289 { |
3375 DWContainer *cont = handle; | 3290 DWContainer *cont = handle; |
3376 id object = nil; | 3291 id object = nil; |
3377 int type = [cont cellType:column]; | 3292 int type = [cont cellType:column]; |
3378 int lastadd = [cont lastAddPoint]; | 3293 int lastadd = [cont lastAddPoint]; |
3379 | 3294 |
3295 if(!data) | |
3296 { | |
3297 return; | |
3298 } | |
3380 if(type & DW_CFA_BITMAPORICON) | 3299 if(type & DW_CFA_BITMAPORICON) |
3381 { | 3300 { |
3382 /* TODO: Handle image here */ | 3301 object = *((NSImage **)data); |
3383 } | 3302 } |
3384 else if(type & DW_CFA_STRING) | 3303 else if(type & DW_CFA_STRING) |
3385 { | 3304 { |
3386 object = [ NSString stringWithUTF8String:data ]; | 3305 object = [ NSString stringWithUTF8String:data ]; |
3387 } | 3306 } |
3462 * pointer: Pointer to the allocated memory in dw_container_alloc(). | 3381 * pointer: Pointer to the allocated memory in dw_container_alloc(). |
3463 * column: Zero based column of data being set. | 3382 * column: Zero based column of data being set. |
3464 * row: Zero based row of data being set. | 3383 * row: Zero based row of data being set. |
3465 * data: Pointer to the data to be added. | 3384 * data: Pointer to the data to be added. |
3466 */ | 3385 */ |
3467 void API dw_filesystem_change_file(HWND handle, int row, char *filename, unsigned long icon) | 3386 void API dw_filesystem_change_file(HWND handle, int row, char *filename, HICN icon) |
3468 { | 3387 { |
3388 dw_container_change_item(handle, 0, row, &icon); | |
3469 dw_container_change_item(handle, 1, row, filename); | 3389 dw_container_change_item(handle, 1, row, filename); |
3470 } | 3390 } |
3471 | 3391 |
3472 /* | 3392 /* |
3473 * Sets an item in specified row and column to the given data. | 3393 * Sets an item in specified row and column to the given data. |
3476 * pointer: Pointer to the allocated memory in dw_container_alloc(). | 3396 * pointer: Pointer to the allocated memory in dw_container_alloc(). |
3477 * column: Zero based column of data being set. | 3397 * column: Zero based column of data being set. |
3478 * row: Zero based row of data being set. | 3398 * row: Zero based row of data being set. |
3479 * data: Pointer to the data to be added. | 3399 * data: Pointer to the data to be added. |
3480 */ | 3400 */ |
3481 void API dw_filesystem_set_file(HWND handle, void *pointer, int row, char *filename, unsigned long icon) | 3401 void API dw_filesystem_set_file(HWND handle, void *pointer, int row, char *filename, HICN icon) |
3482 { | 3402 { |
3403 dw_container_set_item(handle, pointer, 0, row, &icon); | |
3483 dw_container_set_item(handle, pointer, 1, row, filename); | 3404 dw_container_set_item(handle, pointer, 1, row, filename); |
3484 } | 3405 } |
3485 | 3406 |
3486 /* | 3407 /* |
3487 * Sets an item in specified row and column to the given data. | 3408 * Sets an item in specified row and column to the given data. |
3666 * Parameters: | 3587 * Parameters: |
3667 * handle: Window handle that will handle taskbar icon messages. | 3588 * handle: Window handle that will handle taskbar icon messages. |
3668 * icon: Icon handle to display in the taskbar. | 3589 * icon: Icon handle to display in the taskbar. |
3669 * bubbletext: Text to show when the mouse is above the icon. | 3590 * bubbletext: Text to show when the mouse is above the icon. |
3670 */ | 3591 */ |
3671 void API dw_taskbar_insert(HWND handle, unsigned long icon, char *bubbletext) | 3592 void API dw_taskbar_insert(HWND handle, HICN icon, char *bubbletext) |
3672 { | 3593 { |
3673 NSLog(@"dw_taskbar_insert() unimplemented\n"); | 3594 NSLog(@"dw_taskbar_insert() unimplemented\n"); |
3674 } | 3595 } |
3675 | 3596 |
3676 /* | 3597 /* |
3677 * Deletes an icon from the taskbar. | 3598 * Deletes an icon from the taskbar. |
3678 * Parameters: | 3599 * Parameters: |
3679 * handle: Window handle that was used with dw_taskbar_insert(). | 3600 * handle: Window handle that was used with dw_taskbar_insert(). |
3680 * icon: Icon handle that was used with dw_taskbar_insert(). | 3601 * icon: Icon handle that was used with dw_taskbar_insert(). |
3681 */ | 3602 */ |
3682 void API dw_taskbar_delete(HWND handle, unsigned long icon) | 3603 void API dw_taskbar_delete(HWND handle, HICN icon) |
3683 { | 3604 { |
3684 NSLog(@"dw_taskbar_delete() unimplemented\n"); | 3605 NSLog(@"dw_taskbar_delete() unimplemented\n"); |
3685 } | 3606 } |
3686 | 3607 |
3687 /* | 3608 /* |
3690 * module: Handle to module (DLL) in OS/2 and Windows. | 3611 * module: Handle to module (DLL) in OS/2 and Windows. |
3691 * id: A unsigned long id int the resources on OS/2 and | 3612 * id: A unsigned long id int the resources on OS/2 and |
3692 * Windows, on GTK this is converted to a pointer | 3613 * Windows, on GTK this is converted to a pointer |
3693 * to an embedded XPM. | 3614 * to an embedded XPM. |
3694 */ | 3615 */ |
3695 unsigned long API dw_icon_load(unsigned long module, unsigned long id) | 3616 HICN API dw_icon_load(unsigned long module, unsigned long resid) |
3696 { | 3617 { |
3697 NSLog(@"dw_icon_load() unimplemented\n"); | 3618 NSBundle *bundle = [NSBundle mainBundle]; |
3698 return 0; | 3619 NSString *respath = [bundle resourcePath]; |
3620 NSString *filepath = [respath stringByAppendingFormat:@"/%u.png", resid]; | |
3621 NSImage *image = [[NSImage alloc] initWithContentsOfFile:filepath]; | |
3622 [bundle release]; | |
3623 [respath release]; | |
3624 [filepath release]; | |
3625 return image; | |
3699 } | 3626 } |
3700 | 3627 |
3701 /* | 3628 /* |
3702 * Obtains an icon from a file. | 3629 * Obtains an icon from a file. |
3703 * Parameters: | 3630 * Parameters: |
3704 * filename: Name of the file, omit extention to have | 3631 * filename: Name of the file, omit extention to have |
3705 * DW pick the appropriate file extension. | 3632 * DW pick the appropriate file extension. |
3706 * (ICO on OS/2 or Windows, XPM on Unix) | 3633 * (ICO on OS/2 or Windows, XPM on Unix) |
3707 */ | 3634 */ |
3708 unsigned long API dw_icon_load_from_file(char *filename) | 3635 HICN API dw_icon_load_from_file(char *filename) |
3709 { | 3636 { |
3710 NSLog(@"dw_icon_load_from_file() unimplemented\n"); | 3637 return [[NSImage alloc] initWithContentsOfFile:[ NSString stringWithUTF8String:filename ]]; |
3711 return 0; | |
3712 } | 3638 } |
3713 | 3639 |
3714 /* | 3640 /* |
3715 * Obtains an icon from data | 3641 * Obtains an icon from data |
3716 * Parameters: | 3642 * Parameters: |
3717 * filename: Name of the file, omit extention to have | 3643 * filename: Name of the file, omit extention to have |
3718 * DW pick the appropriate file extension. | 3644 * DW pick the appropriate file extension. |
3719 * (ICO on OS/2 or Windows, XPM on Unix) | 3645 * (ICO on OS/2 or Windows, XPM on Unix) |
3720 */ | 3646 */ |
3721 unsigned long API dw_icon_load_from_data(char *data, int len) | 3647 HICN API dw_icon_load_from_data(char *data, int len) |
3722 { | 3648 { |
3723 NSLog(@"dw_icon_load_from_data() unimplemented\n"); | 3649 NSData *thisdata = [[[NSData alloc] dataWithBytes:data length:len] autorelease]; |
3724 return 0; | 3650 NSImage *image = [[NSImage alloc] initWithData:thisdata]; |
3651 [thisdata release]; | |
3652 return image; | |
3725 } | 3653 } |
3726 | 3654 |
3727 /* | 3655 /* |
3728 * Frees a loaded resource in OS/2 and Windows. | 3656 * Frees a loaded resource in OS/2 and Windows. |
3729 * Parameters: | 3657 * Parameters: |
3730 * handle: Handle to icon returned by dw_icon_load(). | 3658 * handle: Handle to icon returned by dw_icon_load(). |
3731 */ | 3659 */ |
3732 void API dw_icon_free(unsigned long handle) | 3660 void API dw_icon_free(HICN handle) |
3733 { | 3661 { |
3734 NSLog(@"dw_icon_free() unimplemented\n"); | 3662 NSImage *image = handle; |
3663 [image release]; | |
3735 } | 3664 } |
3736 | 3665 |
3737 /* | 3666 /* |
3738 * Create a new MDI Frame to be packed. | 3667 * Create a new MDI Frame to be packed. |
3739 * Parameters: | 3668 * Parameters: |
3878 NSImage *image = [[NSImage alloc] initWithData:thisdata]; | 3807 NSImage *image = [[NSImage alloc] initWithData:thisdata]; |
3879 NSSize size = [image size]; | 3808 NSSize size = [image size]; |
3880 pixmap->width = size.width; | 3809 pixmap->width = size.width; |
3881 pixmap->height = size.height; | 3810 pixmap->height = size.height; |
3882 pixmap->handle = image; | 3811 pixmap->handle = image; |
3812 [thisdata release]; | |
3883 return pixmap; | 3813 return pixmap; |
3884 } | 3814 } |
3885 | 3815 |
3886 /* | 3816 /* |
3887 * Creates a bitmap mask for rendering bitmaps with transparent backgrounds | 3817 * Creates a bitmap mask for rendering bitmaps with transparent backgrounds |
5125 /* Call this after drawing to the screen to make sure | 5055 /* Call this after drawing to the screen to make sure |
5126 * anything you have drawn is visible. | 5056 * anything you have drawn is visible. |
5127 */ | 5057 */ |
5128 void API dw_flush(void) | 5058 void API dw_flush(void) |
5129 { | 5059 { |
5060 /* This may need to be thread specific */ | |
5130 if(_DWLastDrawable) | 5061 if(_DWLastDrawable) |
5131 { | 5062 { |
5132 id object = _DWLastDrawable; | 5063 id object = _DWLastDrawable; |
5133 NSWindow *window = [object window]; | 5064 NSWindow *window = [object window]; |
5134 [window flushWindow]; | 5065 [window flushWindow]; |
6091 */ | 6022 */ |
6092 void _dwthreadstart(void *data) | 6023 void _dwthreadstart(void *data) |
6093 { | 6024 { |
6094 void (*threadfunc)(void *) = NULL; | 6025 void (*threadfunc)(void *) = NULL; |
6095 void **tmp = (void **)data; | 6026 void **tmp = (void **)data; |
6027 /* If we aren't using garbage collection we need autorelease pools */ | |
6096 #if !defined(GARBAGE_COLLECT) | 6028 #if !defined(GARBAGE_COLLECT) |
6097 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | 6029 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
6098 #endif | 6030 #endif |
6099 | 6031 |
6100 threadfunc = (void (*)(void *))tmp[0]; | 6032 threadfunc = (void (*)(void *))tmp[0]; |
6101 | 6033 |
6102 threadfunc(tmp[1]); | 6034 threadfunc(tmp[1]); |
6035 /* Release the pool when we are done so we don't leak */ | |
6103 #if !defined(GARBAGE_COLLECT) | 6036 #if !defined(GARBAGE_COLLECT) |
6104 [pool release]; | 6037 [pool release]; |
6105 #endif | 6038 #endif |
6106 free(tmp); | 6039 free(tmp); |
6107 } | 6040 } |
6325 execargs[1] = url; | 6258 execargs[1] = url; |
6326 execargs[2] = NULL; | 6259 execargs[2] = NULL; |
6327 | 6260 |
6328 return dw_exec(browser, DW_EXEC_GUI, execargs); | 6261 return dw_exec(browser, DW_EXEC_GUI, execargs); |
6329 } | 6262 } |
6330 | |
6331 #ifdef DWTEST | |
6332 int main(int argc, char *argv[]) | |
6333 { | |
6334 HWND window, box, vbox, hbox, button, text, checkbox, html; | |
6335 LONG x, y; | |
6336 ULONG width, height; | |
6337 | |
6338 dw_init(TRUE, argc, argv); | |
6339 | |
6340 window = dw_window_new(HWND_DESKTOP, "Dynamic Windows Test", DW_FCF_TITLEBAR | DW_FCF_SYSMENU | DW_FCF_MINMAX | DW_FCF_SIZEBORDER); | |
6341 box = dw_box_new(DW_VERT, 0); | |
6342 vbox = dw_groupbox_new(DW_VERT, 4, "Checks"); | |
6343 checkbox = dw_checkbox_new("Checkbox 1", 0); | |
6344 dw_box_pack_start(vbox, checkbox, 100, 25, TRUE, FALSE, 2); | |
6345 checkbox = dw_checkbox_new("Checkbox 2", 0); | |
6346 dw_box_pack_start(vbox, checkbox, 100, 25, TRUE, FALSE, 2); | |
6347 checkbox = dw_checkbox_new("Checkbox 3", 0); | |
6348 dw_box_pack_start(vbox, checkbox, 100, 25, TRUE, FALSE, 2); | |
6349 hbox = dw_box_new(DW_HORZ, 0); | |
6350 button = dw_button_new("Test Button", 0); | |
6351 /*dw_window_disable(button);*/ | |
6352 text = dw_entryfield_new("Entry", 0); | |
6353 dw_box_pack_start(hbox, button, 100, 40, TRUE, FALSE, 2); | |
6354 dw_box_pack_start(hbox, text, 100, 40, TRUE, FALSE, 2); | |
6355 dw_box_pack_start(vbox, hbox, 0, 0, TRUE, FALSE, 0); | |
6356 html = dw_html_new(0); | |
6357 dw_html_url(html, "http://dbsoft.org"); | |
6358 dw_box_pack_start(vbox, html, 0, 0, TRUE, TRUE, 0); | |
6359 dw_box_pack_start(box, vbox, 0, 0, TRUE, TRUE, 0); | |
6360 dw_box_pack_start(window, box, 0, 0, TRUE, TRUE, 0); | |
6361 dw_window_show(window); | |
6362 dw_window_set_pos_size(window, 400, 400, 500, 500); | |
6363 dw_window_get_pos_size(window, &x, &y, &width, &height); | |
6364 dw_messagebox("Dynamic Windows Information", DW_MB_OK | DW_MB_INFORMATION, "%d %d %d %d %d %d %d\n", (int)x, (int)y, (int)width, (int)height, (int)dw_screen_width(), (int)dw_screen_height(), (int)dw_color_depth_get()); | |
6365 dw_messagebox("File selection", DW_MB_OK | DW_MB_INFORMATION, "%s", dw_file_browse("Choose file", "", "", DW_FILE_OPEN)); | |
6366 dw_main(); | |
6367 | |
6368 return 0; | |
6369 } | |
6370 #endif |