comparison mac/dw.m @ 691:578bbfd8c904

Added initial thread synchronization code to stop the main loop when doing thread unsafe things. Also fixed some memory leaks and double object releases that were causing some instability.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 08 Mar 2011 01:30:04 +0000
parents b93f5cdab37d
children bd909322f40d
comparison
equal deleted inserted replaced
690:b93f5cdab37d 691:578bbfd8c904
14 #include <sys/socket.h> 14 #include <sys/socket.h>
15 #include <sys/un.h> 15 #include <sys/un.h>
16 #include <sys/mman.h> 16 #include <sys/mman.h>
17 #include <sys/time.h> 17 #include <sys/time.h>
18 #include <sys/stat.h> 18 #include <sys/stat.h>
19
20 /* Macros to protect access to thread unsafe classes */
21 #define DW_MUTEX_LOCK { \
22 if(DWThread != (DWTID)-1 && pthread_self() != DWThread && pthread_self() != _dw_mutex_locked) { \
23 dw_mutex_lock(DWThreadMutex); \
24 _dw_mutex_locked = pthread_self(); \
25 dw_mutex_lock(DWThreadMutex2); \
26 /*NSLog(@"Thread %d asking the main thread to stop %x", (int)pthread_self(), (int)DWObj);*/ \
27 [DWObj performSelectorOnMainThread:@selector(synchronizeThread:) withObject:nil waitUntilDone:NO]; \
28 dw_mutex_lock(DWRunMutex); \
29 /*NSLog(@"Thread %d proceeding", (int)pthread_self());*/ \
30 _locked_by_me = TRUE; } }
31 #define DW_MUTEX_UNLOCK { \
32 if(pthread_self() != DWThread && _locked_by_me == TRUE) { \
33 /*NSLog(@"Thread %d releasing", (int)pthread_self());*/ \
34 dw_mutex_unlock(DWRunMutex); \
35 dw_mutex_unlock(DWThreadMutex2); \
36 _dw_mutex_locked = (pthread_t)-1; \
37 dw_mutex_unlock(DWThreadMutex); \
38 _locked_by_me = FALSE; } }
19 39
20 unsigned long _colors[] = 40 unsigned long _colors[] =
21 { 41 {
22 0x00000000, /* 0 black */ 42 0x00000000, /* 0 black */
23 0x00bb0000, /* 1 red */ 43 0x00bb0000, /* 1 red */
212 DWTimerHandler *DWHandler; 232 DWTimerHandler *DWHandler;
213 #if !defined(GARBAGE_COLLECT) 233 #if !defined(GARBAGE_COLLECT)
214 NSAutoreleasePool *pool; 234 NSAutoreleasePool *pool;
215 #endif 235 #endif
216 HWND _DWLastDrawable; 236 HWND _DWLastDrawable;
237 HMTX DWRunMutex;
238 HMTX DWThreadMutex;
239 HMTX DWThreadMutex2;
240 DWTID DWThread = (DWTID)-1;
241 DWTID _dw_mutex_locked = (DWTID)-1;
242
243 /* Subclass for a test object type */
244 @interface DWObject : NSObject {}
245 -(void)uselessThread:(id)sender;
246 -(void)synchronizeThread:(id)param;
247 @end
248
249 @implementation DWObject
250 -(void)uselessThread:(id)sender { /* Thread only to initialize threading */ }
251 -(void)synchronizeThread:(id)param
252 {
253 pthread_mutex_unlock(DWRunMutex);
254 //NSLog(@"Main thread releasing lock");
255 pthread_mutex_lock(DWThreadMutex2);
256 pthread_mutex_unlock(DWThreadMutex2);
257 pthread_mutex_lock(DWRunMutex);
258 //NSLog(@"Main thread reacquiring lock");
259 }
260 @end
261
262 DWObject *DWObj;
217 263
218 /* So basically to implement our event handlers... 264 /* So basically to implement our event handlers...
219 * it looks like we are going to have to subclass 265 * it looks like we are going to have to subclass
220 * basically everything. Was hoping to add methods 266 * basically everything. Was hoping to add methods
221 * to the superclasses but it looks like you can 267 * to the superclasses but it looks like you can
701 [set release]; 747 [set release];
702 return (int)[titles count]; 748 return (int)[titles count];
703 } 749 }
704 return 0; 750 return 0;
705 } 751 }
706 -(int)addRow:(NSArray *)input { if(data) { lastAddPoint = (int)[titles count]; [data addObjectsFromArray:input]; [titles addPointer:NULL]; return (int)[titles count]; } return 0; } 752 -(int)addRow:(NSArray *)input
753 {
754 if(data)
755 {
756 NSLog(@"addRow: titles: %x data %x", (int)titles, (int)data);
757 lastAddPoint = (int)[titles count];
758 [data addObjectsFromArray:input];
759 [titles addPointer:NULL];
760 return (int)[titles count];
761 }
762 return 0;
763 }
707 -(int)addRows:(int)number 764 -(int)addRows:(int)number
708 { 765 {
709 if(tvcols) 766 if(tvcols)
710 { 767 {
711 int count = (int)(number * [tvcols count]); 768 int count = (int)(number * [tvcols count]);
807 else 864 else
808 { 865 {
809 _free_tree_recurse(children, item); 866 _free_tree_recurse(children, item);
810 } 867 }
811 } 868 }
812 if(!item || item == pnt)
813 {
814 [pnt release];
815 }
816 } 869 }
817 } 870 }
818 if(!item) 871 if(!item)
819 { 872 {
820 [node release]; 873 [node release];
1066 */ 1119 */
1067 @interface DWMDI : DWBox {} 1120 @interface DWMDI : DWBox {}
1068 @end 1121 @end
1069 1122
1070 @implementation DWMDI 1123 @implementation DWMDI
1071 @end
1072
1073 /* Subclass for a test object type */
1074 @interface DWObject : NSObject {}
1075 -(void)uselessThread:(id)sender;
1076 @end
1077
1078 @implementation DWObject
1079 -(void)uselessThread:(id)sender { /* Thread only to initialize threading */ }
1080 @end 1124 @end
1081 1125
1082 typedef struct 1126 typedef struct
1083 { 1127 {
1084 ULONG message; 1128 ULONG message;
1632 pool = [[NSAutoreleasePool alloc] init]; 1676 pool = [[NSAutoreleasePool alloc] init];
1633 #endif 1677 #endif
1634 /* Create a default main menu, with just the application menu */ 1678 /* Create a default main menu, with just the application menu */
1635 DWMainMenu = _generate_main_menu(); 1679 DWMainMenu = _generate_main_menu();
1636 [DWApp setMainMenu:DWMainMenu]; 1680 [DWApp setMainMenu:DWMainMenu];
1637 DWObject *test = [[DWObject alloc] init]; 1681 DWObj = [[DWObject alloc] init];
1682 /* Create mutexes for thread safety */
1683 DWRunMutex = dw_mutex_new();
1684 DWThreadMutex = dw_mutex_new();
1685 DWThreadMutex2 = dw_mutex_new();
1638 /* Use NSThread to start a dummy thread to initialize the threading subsystem */ 1686 /* Use NSThread to start a dummy thread to initialize the threading subsystem */
1639 NSThread *thread = [[ NSThread alloc] initWithTarget:test selector:@selector(uselessThread:) object:nil]; 1687 NSThread *thread = [[ NSThread alloc] initWithTarget:DWObj selector:@selector(uselessThread:) object:nil];
1640 [thread start]; 1688 [thread start];
1689 [thread release];
1641 return 0; 1690 return 0;
1642 } 1691 }
1643 1692
1644 /* 1693 /*
1645 * Runs a message loop for Dynamic Windows. 1694 * Runs a message loop for Dynamic Windows.
1646 */ 1695 */
1647 void API dw_main(void) 1696 void API dw_main(void)
1648 { 1697 {
1698 dw_mutex_lock(DWRunMutex);
1699 DWThread = dw_thread_id();
1649 [DWApp run]; 1700 [DWApp run];
1701 DWThread = (DWTID)-1;
1702 dw_mutex_unlock(DWRunMutex);
1650 } 1703 }
1651 1704
1652 /* 1705 /*
1653 * Runs a message loop for Dynamic Windows, for a period of milliseconds. 1706 * Runs a message loop for Dynamic Windows, for a period of milliseconds.
1654 * Parameters: 1707 * Parameters:
1657 void API dw_main_sleep(int milliseconds) 1710 void API dw_main_sleep(int milliseconds)
1658 { 1711 {
1659 double seconds = (double)milliseconds/1000.0; 1712 double seconds = (double)milliseconds/1000.0;
1660 NSDate *time = [[NSDate alloc] initWithTimeIntervalSinceNow:seconds]; 1713 NSDate *time = [[NSDate alloc] initWithTimeIntervalSinceNow:seconds];
1661 [DWRunLoop runUntilDate:time]; 1714 [DWRunLoop runUntilDate:time];
1715 [time release];
1662 } 1716 }
1663 1717
1664 /* 1718 /*
1665 * Processes a single message iteration and returns. 1719 * Processes a single message iteration and returns.
1666 */ 1720 */
1942 * type: Either DW_VERT (vertical) or DW_HORZ (horizontal). 1996 * type: Either DW_VERT (vertical) or DW_HORZ (horizontal).
1943 * pad: Number of pixels to pad around the box. 1997 * pad: Number of pixels to pad around the box.
1944 */ 1998 */
1945 HWND API dw_box_new(int type, int pad) 1999 HWND API dw_box_new(int type, int pad)
1946 { 2000 {
2001 int _locked_by_me = FALSE;
2002 DW_MUTEX_LOCK;
1947 DWBox *view = [[DWBox alloc] init]; 2003 DWBox *view = [[DWBox alloc] init];
1948 Box *newbox = [view box]; 2004 Box *newbox = [view box];
1949 memset(newbox, 0, sizeof(Box)); 2005 memset(newbox, 0, sizeof(Box));
1950 newbox->pad = pad; 2006 newbox->pad = pad;
1951 newbox->type = type; 2007 newbox->type = type;
2008 DW_MUTEX_UNLOCK;
1952 return view; 2009 return view;
1953 } 2010 }
1954 2011
1955 /* 2012 /*
1956 * Create a new Group Box to be packed. 2013 * Create a new Group Box to be packed.
1977 * vsize: TRUE if the window (widget) should expand vertically to fill space given. 2034 * vsize: TRUE if the window (widget) should expand vertically to fill space given.
1978 * pad: Number of pixels of padding around the item. 2035 * pad: Number of pixels of padding around the item.
1979 */ 2036 */
1980 void API dw_box_pack_end(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad) 2037 void API dw_box_pack_end(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad)
1981 { 2038 {
2039 int _locked_by_me = FALSE;
2040 DW_MUTEX_LOCK;
1982 NSObject *object = box; 2041 NSObject *object = box;
1983 DWBox *view = box; 2042 DWBox *view = box;
1984 DWBox *this = item; 2043 DWBox *this = item;
1985 Box *thisbox; 2044 Box *thisbox;
1986 int z; 2045 int z;
2052 [view addSubview:this]; 2111 [view addSubview:this];
2053 2112
2054 /* Free the old data */ 2113 /* Free the old data */
2055 if(thisbox->count) 2114 if(thisbox->count)
2056 free(thisitem); 2115 free(thisitem);
2116 DW_MUTEX_UNLOCK;
2057 } 2117 }
2058 2118
2059 /* 2119 /*
2060 * Pack windows (widgets) into a box from the start (or top). 2120 * Pack windows (widgets) into a box from the start (or top).
2061 * Parameters: 2121 * Parameters:
2067 * vsize: TRUE if the window (widget) should expand vertically to fill space given. 2127 * vsize: TRUE if the window (widget) should expand vertically to fill space given.
2068 * pad: Number of pixels of padding around the item. 2128 * pad: Number of pixels of padding around the item.
2069 */ 2129 */
2070 void API dw_box_pack_start(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad) 2130 void API dw_box_pack_start(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad)
2071 { 2131 {
2132 int _locked_by_me = FALSE;
2133 DW_MUTEX_LOCK;
2072 NSObject *object = box; 2134 NSObject *object = box;
2073 DWBox *view = box; 2135 DWBox *view = box;
2074 DWBox *this = item; 2136 DWBox *this = item;
2075 Box *thisbox; 2137 Box *thisbox;
2076 int z; 2138 int z;
2142 [view addSubview:this]; 2204 [view addSubview:this];
2143 2205
2144 /* Free the old data */ 2206 /* Free the old data */
2145 if(thisbox->count) 2207 if(thisbox->count)
2146 free(thisitem); 2208 free(thisitem);
2209 DW_MUTEX_UNLOCK;
2147 } 2210 }
2148 2211
2149 HWND _button_new(char *text, ULONG cid) 2212 HWND _button_new(char *text, ULONG cid)
2150 { 2213 {
2151 DWButton *button = [[DWButton alloc] init]; 2214 DWButton *button = [[DWButton alloc] init];
2233 DWButton *button = _button_new("", resid); 2296 DWButton *button = _button_new("", resid);
2234 [button setImage:image]; 2297 [button setImage:image];
2235 //[button setBezelStyle:0]; 2298 //[button setBezelStyle:0];
2236 [button setButtonType:NSMomentaryLight]; 2299 [button setButtonType:NSMomentaryLight];
2237 [button setBordered:NO]; 2300 [button setBordered:NO];
2238 [bundle release];
2239 [respath release];
2240 [filepath release];
2241 [image release]; 2301 [image release];
2242 return button; 2302 return button;
2243 } 2303 }
2244 2304
2245 /* 2305 /*
2258 if(!image) 2318 if(!image)
2259 { 2319 {
2260 nstr = [nstr stringByAppendingString:@".png"]; 2320 nstr = [nstr stringByAppendingString:@".png"];
2261 image = [[NSImage alloc] initWithContentsOfFile:nstr]; 2321 image = [[NSImage alloc] initWithContentsOfFile:nstr];
2262 } 2322 }
2263 [nstr release];
2264 DWButton *button = _button_new("", cid); 2323 DWButton *button = _button_new("", cid);
2265 [button setImage:image]; 2324 [button setImage:image];
2325 [image release];
2266 return button; 2326 return button;
2267 } 2327 }
2268 2328
2269 /* 2329 /*
2270 * Create a new bitmap button window (widget) to be packed from data. 2330 * Create a new bitmap button window (widget) to be packed from data.
2279 { 2339 {
2280 NSData *thisdata = [[NSData alloc] dataWithBytes:data length:len]; 2340 NSData *thisdata = [[NSData alloc] dataWithBytes:data length:len];
2281 NSImage *image = [[NSImage alloc] initWithData:thisdata]; 2341 NSImage *image = [[NSImage alloc] initWithData:thisdata];
2282 DWButton *button = _button_new("", cid); 2342 DWButton *button = _button_new("", cid);
2283 [button setImage:image]; 2343 [button setImage:image];
2344 [image release];
2284 return button; 2345 return button;
2285 } 2346 }
2286 2347
2287 /* 2348 /*
2288 * Create a new spinbutton window (widget) to be packed. 2349 * Create a new spinbutton window (widget) to be packed.
2401 * increments: Number of increments available. 2462 * increments: Number of increments available.
2402 * id: An ID to be used with dw_window_from_id() or 0L. 2463 * id: An ID to be used with dw_window_from_id() or 0L.
2403 */ 2464 */
2404 HWND API dw_scrollbar_new(int vertical, ULONG cid) 2465 HWND API dw_scrollbar_new(int vertical, ULONG cid)
2405 { 2466 {
2406 DWScrollbar *scrollbar = [DWScrollbar alloc]; 2467 DWScrollbar *scrollbar;
2407 if(vertical) 2468 if(vertical)
2408 { 2469 {
2409 [scrollbar init]; 2470 scrollbar = [[DWScrollbar alloc] init];
2410 } 2471 }
2411 else 2472 else
2412 { 2473 {
2413 [scrollbar initWithFrame:NSMakeRect(0,0,100,5)]; 2474 scrollbar = [[DWScrollbar alloc] initWithFrame:NSMakeRect(0,0,100,5)];
2414 } 2475 }
2415 [scrollbar setArrowsPosition:NSScrollerArrowsDefaultSetting]; 2476 [scrollbar setArrowsPosition:NSScrollerArrowsDefaultSetting];
2416 [scrollbar setTarget:scrollbar]; 2477 [scrollbar setTarget:scrollbar];
2417 [scrollbar setAction:@selector(changed:)]; 2478 [scrollbar setAction:@selector(changed:)];
2418 [scrollbar setRange:0.0 andVisible:0.0]; 2479 [scrollbar setRange:0.0 andVisible:0.0];
2560 [cont setAllowsMultipleSelection:NO]; 2621 [cont setAllowsMultipleSelection:NO];
2561 } 2622 }
2562 [cont setDataSource:cont]; 2623 [cont setDataSource:cont];
2563 [scrollview setDocumentView:cont]; 2624 [scrollview setDocumentView:cont];
2564 [cont setTag:cid]; 2625 [cont setTag:cid];
2626 [scrollview release];
2565 return cont; 2627 return cont;
2566 } 2628 }
2567 2629
2568 /* 2630 /*
2569 * Create a new listbox window (widget) to be packed. 2631 * Create a new listbox window (widget) to be packed.
2571 * id: An ID to be used with dw_window_from_id() or 0L. 2633 * id: An ID to be used with dw_window_from_id() or 0L.
2572 * multi: Multiple select TRUE or FALSE. 2634 * multi: Multiple select TRUE or FALSE.
2573 */ 2635 */
2574 HWND API dw_listbox_new(ULONG cid, int multi) 2636 HWND API dw_listbox_new(ULONG cid, int multi)
2575 { 2637 {
2638 int _locked_by_me = FALSE;
2639 DW_MUTEX_LOCK;
2576 DWContainer *cont = _cont_new(cid, multi); 2640 DWContainer *cont = _cont_new(cid, multi);
2577 [cont setHeaderView:nil]; 2641 [cont setHeaderView:nil];
2578 int type = DW_CFA_STRING; 2642 int type = DW_CFA_STRING;
2579 [cont setup]; 2643 [cont setup];
2580 NSTableColumn *column = [[NSTableColumn alloc] init]; 2644 NSTableColumn *column = [[NSTableColumn alloc] init];
2581 [cont addTableColumn:column]; 2645 [cont addTableColumn:column];
2582 [cont addColumn:column andType:type]; 2646 [cont addColumn:column andType:type];
2647 [column release];
2648 DW_MUTEX_UNLOCK;
2583 return cont; 2649 return cont;
2584 } 2650 }
2585 2651
2586 /* 2652 /*
2587 * Appends the specified text to the listbox's (or combobox) entry list. 2653 * Appends the specified text to the listbox's (or combobox) entry list.
2589 * handle: Handle to the listbox to be appended to. 2655 * handle: Handle to the listbox to be appended to.
2590 * text: Text to append into listbox. 2656 * text: Text to append into listbox.
2591 */ 2657 */
2592 void API dw_listbox_append(HWND handle, char *text) 2658 void API dw_listbox_append(HWND handle, char *text)
2593 { 2659 {
2660 int _locked_by_me = FALSE;
2661 DW_MUTEX_LOCK;
2594 id object = handle; 2662 id object = handle;
2595 2663
2596 if([object isMemberOfClass:[DWComboBox class]]) 2664 if([object isMemberOfClass:[DWComboBox class]])
2597 { 2665 {
2598 DWComboBox *combo = handle; 2666 DWComboBox *combo = handle;
2608 [cont addRow:newrow]; 2676 [cont addRow:newrow];
2609 /*[cont performSelectorOnMainThread:@selector(addRow:) 2677 /*[cont performSelectorOnMainThread:@selector(addRow:)
2610 withObject:newrow 2678 withObject:newrow
2611 waitUntilDone:YES];*/ 2679 waitUntilDone:YES];*/
2612 [cont reloadData]; 2680 [cont reloadData];
2613
2614 [newrow release];
2615 } 2681 }
2682 DW_MUTEX_UNLOCK;
2616 } 2683 }
2617 2684
2618 /* 2685 /*
2619 * Inserts the specified text into the listbox's (or combobox) entry list. 2686 * Inserts the specified text into the listbox's (or combobox) entry list.
2620 * Parameters: 2687 * Parameters:
2622 * text: Text to insert into listbox. 2689 * text: Text to insert into listbox.
2623 * pos: 0-based position to insert text 2690 * pos: 0-based position to insert text
2624 */ 2691 */
2625 void API dw_listbox_insert(HWND handle, char *text, int pos) 2692 void API dw_listbox_insert(HWND handle, char *text, int pos)
2626 { 2693 {
2694 int _locked_by_me = FALSE;
2695 DW_MUTEX_LOCK;
2627 id object = handle; 2696 id object = handle;
2628 2697
2629 if([object isMemberOfClass:[DWComboBox class]]) 2698 if([object isMemberOfClass:[DWComboBox class]])
2630 { 2699 {
2631 DWComboBox *combo = handle; 2700 DWComboBox *combo = handle;
2638 NSString *nstr = [ NSString stringWithUTF8String:text ]; 2707 NSString *nstr = [ NSString stringWithUTF8String:text ];
2639 NSArray *newrow = [NSArray arrayWithObject:nstr]; 2708 NSArray *newrow = [NSArray arrayWithObject:nstr];
2640 2709
2641 [cont insertRow:newrow at:pos]; 2710 [cont insertRow:newrow at:pos];
2642 [cont reloadData]; 2711 [cont reloadData];
2643
2644 [newrow release];
2645 } 2712 }
2713 DW_MUTEX_UNLOCK;
2646 } 2714 }
2647 2715
2648 /* 2716 /*
2649 * Appends the specified text items to the listbox's (or combobox) entry list. 2717 * Appends the specified text items to the listbox's (or combobox) entry list.
2650 * Parameters: 2718 * Parameters:
2652 * text: Text strings to append into listbox. 2720 * text: Text strings to append into listbox.
2653 * count: Number of text strings to append 2721 * count: Number of text strings to append
2654 */ 2722 */
2655 void API dw_listbox_list_append(HWND handle, char **text, int count) 2723 void API dw_listbox_list_append(HWND handle, char **text, int count)
2656 { 2724 {
2725 int _locked_by_me = FALSE;
2726 DW_MUTEX_LOCK;
2657 id object = handle; 2727 id object = handle;
2658 2728
2659 if([object isMemberOfClass:[DWComboBox class]]) 2729 if([object isMemberOfClass:[DWComboBox class]])
2660 { 2730 {
2661 DWComboBox *combo = handle; 2731 DWComboBox *combo = handle;
2675 { 2745 {
2676 NSString *nstr = [ NSString stringWithUTF8String:text[z] ]; 2746 NSString *nstr = [ NSString stringWithUTF8String:text[z] ];
2677 NSArray *newrow = [[NSArray alloc] arrayWithObject:nstr]; 2747 NSArray *newrow = [[NSArray alloc] arrayWithObject:nstr];
2678 2748
2679 [cont addRow:newrow]; 2749 [cont addRow:newrow];
2680
2681 [newrow release];
2682 } 2750 }
2683 [cont reloadData]; 2751 [cont reloadData];
2684 } 2752 }
2753 DW_MUTEX_UNLOCK;
2685 } 2754 }
2686 2755
2687 /* 2756 /*
2688 * Clears the listbox's (or combobox) list of all entries. 2757 * Clears the listbox's (or combobox) list of all entries.
2689 * Parameters: 2758 * Parameters:
2690 * handle: Handle to the listbox to be cleared. 2759 * handle: Handle to the listbox to be cleared.
2691 */ 2760 */
2692 void API dw_listbox_clear(HWND handle) 2761 void API dw_listbox_clear(HWND handle)
2693 { 2762 {
2763 int _locked_by_me = FALSE;
2764 DW_MUTEX_LOCK;
2694 id object = handle; 2765 id object = handle;
2695 2766
2696 if([object isMemberOfClass:[DWComboBox class]]) 2767 if([object isMemberOfClass:[DWComboBox class]])
2697 { 2768 {
2698 DWComboBox *combo = handle; 2769 DWComboBox *combo = handle;
2704 DWContainer *cont = handle; 2775 DWContainer *cont = handle;
2705 2776
2706 [cont clear]; 2777 [cont clear];
2707 [cont reloadData]; 2778 [cont reloadData];
2708 } 2779 }
2780 DW_MUTEX_UNLOCK;
2709 } 2781 }
2710 2782
2711 /* 2783 /*
2712 * Returns the listbox's item count. 2784 * Returns the listbox's item count.
2713 * Parameters: 2785 * Parameters:
2723 2795
2724 return (int)[combo numberOfItems]; 2796 return (int)[combo numberOfItems];
2725 } 2797 }
2726 else if([object isMemberOfClass:[DWContainer class]]) 2798 else if([object isMemberOfClass:[DWContainer class]])
2727 { 2799 {
2800 int _locked_by_me = FALSE;
2801 DW_MUTEX_LOCK;
2728 DWContainer *cont = handle; 2802 DWContainer *cont = handle;
2729 2803 int result = (int)[cont numberOfRowsInTableView:cont];
2730 return (int)[cont numberOfRowsInTableView:cont]; 2804 DW_MUTEX_UNLOCK;
2805 return result;
2731 } 2806 }
2732 return 0; 2807 return 0;
2733 } 2808 }
2734 2809
2735 /* 2810 /*
2738 * handle: Handle to the listbox to be cleared. 2813 * handle: Handle to the listbox to be cleared.
2739 * top: Index to the top item. 2814 * top: Index to the top item.
2740 */ 2815 */
2741 void API dw_listbox_set_top(HWND handle, int top) 2816 void API dw_listbox_set_top(HWND handle, int top)
2742 { 2817 {
2818 int _locked_by_me = FALSE;
2819 DW_MUTEX_LOCK;
2743 id object = handle; 2820 id object = handle;
2744 2821
2745 if([object isMemberOfClass:[DWComboBox class]]) 2822 if([object isMemberOfClass:[DWComboBox class]])
2746 { 2823 {
2747 DWComboBox *combo = handle; 2824 DWComboBox *combo = handle;
2752 { 2829 {
2753 DWContainer *cont = handle; 2830 DWContainer *cont = handle;
2754 2831
2755 [cont scrollRowToVisible:top]; 2832 [cont scrollRowToVisible:top];
2756 } 2833 }
2834 DW_MUTEX_UNLOCK;
2757 } 2835 }
2758 2836
2759 /* 2837 /*
2760 * Copies the given index item's text into buffer. 2838 * Copies the given index item's text into buffer.
2761 * Parameters: 2839 * Parameters:
2764 * buffer: Buffer where text will be copied. 2842 * buffer: Buffer where text will be copied.
2765 * length: Length of the buffer (including NULL). 2843 * length: Length of the buffer (including NULL).
2766 */ 2844 */
2767 void API dw_listbox_get_text(HWND handle, unsigned int index, char *buffer, unsigned int length) 2845 void API dw_listbox_get_text(HWND handle, unsigned int index, char *buffer, unsigned int length)
2768 { 2846 {
2847 int _locked_by_me = FALSE;
2848 DW_MUTEX_LOCK;
2769 id object = handle; 2849 id object = handle;
2770 2850
2771 if([object isMemberOfClass:[DWComboBox class]]) 2851 if([object isMemberOfClass:[DWComboBox class]])
2772 { 2852 {
2773 DWComboBox *combo = handle; 2853 DWComboBox *combo = handle;
2779 DWContainer *cont = handle; 2859 DWContainer *cont = handle;
2780 NSString *nstr = [cont getRow:index and:0]; 2860 NSString *nstr = [cont getRow:index and:0];
2781 2861
2782 strncpy(buffer, [ nstr UTF8String ], length - 1); 2862 strncpy(buffer, [ nstr UTF8String ], length - 1);
2783 } 2863 }
2864 DW_MUTEX_UNLOCK;
2784 } 2865 }
2785 2866
2786 /* 2867 /*
2787 * Sets the text of a given listbox entry. 2868 * Sets the text of a given listbox entry.
2788 * Parameters: 2869 * Parameters:
2790 * index: Index into the list to be queried. 2871 * index: Index into the list to be queried.
2791 * buffer: Buffer where text will be copied. 2872 * buffer: Buffer where text will be copied.
2792 */ 2873 */
2793 void API dw_listbox_set_text(HWND handle, unsigned int index, char *buffer) 2874 void API dw_listbox_set_text(HWND handle, unsigned int index, char *buffer)
2794 { 2875 {
2876 int _locked_by_me = FALSE;
2877 DW_MUTEX_LOCK;
2795 id object = handle; 2878 id object = handle;
2796 2879
2797 if([object isMemberOfClass:[DWComboBox class]]) 2880 if([object isMemberOfClass:[DWComboBox class]])
2798 { 2881 {
2799 DWComboBox *combo = handle; 2882 DWComboBox *combo = handle;
2807 NSString *nstr = [ NSString stringWithUTF8String:buffer ]; 2890 NSString *nstr = [ NSString stringWithUTF8String:buffer ];
2808 2891
2809 [cont editCell:nstr at:index and:0]; 2892 [cont editCell:nstr at:index and:0];
2810 [cont reloadData]; 2893 [cont reloadData];
2811 } 2894 }
2812 2895 DW_MUTEX_UNLOCK;
2813 } 2896 }
2814 2897
2815 /* 2898 /*
2816 * Returns the index to the item in the list currently selected. 2899 * Returns the index to the item in the list currently selected.
2817 * Parameters: 2900 * Parameters:
2826 DWComboBox *combo = handle; 2909 DWComboBox *combo = handle;
2827 return (int)[combo indexOfSelectedItem]; 2910 return (int)[combo indexOfSelectedItem];
2828 } 2911 }
2829 else if([object isMemberOfClass:[DWContainer class]]) 2912 else if([object isMemberOfClass:[DWContainer class]])
2830 { 2913 {
2914 int _locked_by_me = FALSE;
2915 DW_MUTEX_LOCK;
2831 DWContainer *cont = handle; 2916 DWContainer *cont = handle;
2832 2917 int result = (int)[cont selectedRow];
2833 return (int)[cont selectedRow]; 2918 DW_MUTEX_UNLOCK;
2919 return result;
2834 } 2920 }
2835 return -1; 2921 return -1;
2836 } 2922 }
2837 2923
2838 /* 2924 /*
2841 * handle: Handle to the listbox to be queried. 2927 * handle: Handle to the listbox to be queried.
2842 * where: Either the previous return or -1 to restart. 2928 * where: Either the previous return or -1 to restart.
2843 */ 2929 */
2844 int API dw_listbox_selected_multi(HWND handle, int where) 2930 int API dw_listbox_selected_multi(HWND handle, int where)
2845 { 2931 {
2932 int _locked_by_me = FALSE;
2933 DW_MUTEX_LOCK;
2846 id object = handle; 2934 id object = handle;
2847 int retval = -1; 2935 int retval = -1;
2848 2936
2849 if([object isMemberOfClass:[DWContainer class]]) 2937 if([object isMemberOfClass:[DWContainer class]])
2850 { 2938 {
2854 2942
2855 if(result != NSNotFound) 2943 if(result != NSNotFound)
2856 { 2944 {
2857 retval = (int)result; 2945 retval = (int)result;
2858 } 2946 }
2859 [selected release]; 2947 }
2860 } 2948 DW_MUTEX_UNLOCK;
2861 return retval; 2949 return retval;
2862 } 2950 }
2863 2951
2864 /* 2952 /*
2865 * Sets the selection state of a given index. 2953 * Sets the selection state of a given index.
2868 * index: Item index. 2956 * index: Item index.
2869 * state: TRUE if selected FALSE if unselected. 2957 * state: TRUE if selected FALSE if unselected.
2870 */ 2958 */
2871 void API dw_listbox_select(HWND handle, int index, int state) 2959 void API dw_listbox_select(HWND handle, int index, int state)
2872 { 2960 {
2961 int _locked_by_me = FALSE;
2962 DW_MUTEX_LOCK;
2873 id object = handle; 2963 id object = handle;
2874 2964
2875 if([object isMemberOfClass:[DWComboBox class]]) 2965 if([object isMemberOfClass:[DWComboBox class]])
2876 { 2966 {
2877 DWComboBox *combo = handle; 2967 DWComboBox *combo = handle;
2885 DWContainer *cont = handle; 2975 DWContainer *cont = handle;
2886 NSIndexSet *selected = [[NSIndexSet alloc] initWithIndex:(NSUInteger)index]; 2976 NSIndexSet *selected = [[NSIndexSet alloc] initWithIndex:(NSUInteger)index];
2887 2977
2888 [cont selectRowIndexes:selected byExtendingSelection:YES]; 2978 [cont selectRowIndexes:selected byExtendingSelection:YES];
2889 [selected release]; 2979 [selected release];
2890 } 2980 }
2981 DW_MUTEX_UNLOCK;
2891 } 2982 }
2892 2983
2893 /* 2984 /*
2894 * Deletes the item with given index from the list. 2985 * Deletes the item with given index from the list.
2895 * Parameters: 2986 * Parameters:
2896 * handle: Handle to the listbox to be set. 2987 * handle: Handle to the listbox to be set.
2897 * index: Item index. 2988 * index: Item index.
2898 */ 2989 */
2899 void API dw_listbox_delete(HWND handle, int index) 2990 void API dw_listbox_delete(HWND handle, int index)
2900 { 2991 {
2992 int _locked_by_me = FALSE;
2993 DW_MUTEX_LOCK;
2901 id object = handle; 2994 id object = handle;
2902 2995
2903 if([object isMemberOfClass:[DWComboBox class]]) 2996 if([object isMemberOfClass:[DWComboBox class]])
2904 { 2997 {
2905 DWComboBox *combo = handle; 2998 DWComboBox *combo = handle;
2911 DWContainer *cont = handle; 3004 DWContainer *cont = handle;
2912 3005
2913 [cont removeRow:index]; 3006 [cont removeRow:index];
2914 [cont reloadData]; 3007 [cont reloadData];
2915 } 3008 }
3009 DW_MUTEX_UNLOCK;
2916 } 3010 }
2917 3011
2918 /* 3012 /*
2919 * Create a new Combobox window (widget) to be packed. 3013 * Create a new Combobox window (widget) to be packed.
2920 * Parameters: 3014 * Parameters:
2944 [scrollview setAutohidesScrollers:YES]; 3038 [scrollview setAutohidesScrollers:YES];
2945 [scrollview setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable]; 3039 [scrollview setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
2946 [scrollview setDocumentView:mle]; 3040 [scrollview setDocumentView:mle];
2947 [mle setAutoresizingMask:NSViewWidthSizable]; 3041 [mle setAutoresizingMask:NSViewWidthSizable];
2948 /* [mle setTag:cid]; Why doesn't this work? */ 3042 /* [mle setTag:cid]; Why doesn't this work? */
3043 [mle release];
2949 return scrollview; 3044 return scrollview;
2950 } 3045 }
2951 3046
2952 /* 3047 /*
2953 * Adds text to an MLE box and returns the current point. 3048 * Adds text to an MLE box and returns the current point.
3235 * x: X coordinate. 3330 * x: X coordinate.
3236 * y: Y coordinate. 3331 * y: Y coordinate.
3237 */ 3332 */
3238 void API dw_draw_point(HWND handle, HPIXMAP pixmap, int x, int y) 3333 void API dw_draw_point(HWND handle, HPIXMAP pixmap, int x, int y)
3239 { 3334 {
3335 int _locked_by_me = FALSE;
3336 DW_MUTEX_LOCK;
3240 id image = handle; 3337 id image = handle;
3241 if(pixmap) 3338 if(pixmap)
3242 { 3339 {
3243 image = (id)pixmap->handle; 3340 image = (id)pixmap->handle;
3244 [image lockFocus]; 3341 [image lockFocus];
3250 } 3347 }
3251 NSBezierPath* aPath = [NSBezierPath bezierPath]; 3348 NSBezierPath* aPath = [NSBezierPath bezierPath];
3252 [aPath setLineWidth: 0.5]; 3349 [aPath setLineWidth: 0.5];
3253 NSColor *color = [NSColor colorWithDeviceRed: DW_RED_VALUE(_foreground)/255.0 green: DW_GREEN_VALUE(_foreground)/255.0 blue: DW_BLUE_VALUE(_foreground)/255.0 alpha: 1]; 3350 NSColor *color = [NSColor colorWithDeviceRed: DW_RED_VALUE(_foreground)/255.0 green: DW_GREEN_VALUE(_foreground)/255.0 blue: DW_BLUE_VALUE(_foreground)/255.0 alpha: 1];
3254 [color set]; 3351 [color set];
3255 [color release];
3256 3352
3257 [aPath moveToPoint:NSMakePoint(x, y)]; 3353 [aPath moveToPoint:NSMakePoint(x, y)];
3258 [aPath stroke]; 3354 [aPath stroke];
3259 [aPath release];
3260 [image unlockFocus]; 3355 [image unlockFocus];
3356 DW_MUTEX_UNLOCK;
3261 } 3357 }
3262 3358
3263 /* Draw a line on a window (preferably a render window). 3359 /* Draw a line on a window (preferably a render window).
3264 * Parameters: 3360 * Parameters:
3265 * handle: Handle to the window. 3361 * handle: Handle to the window.
3269 * x2: Second X coordinate. 3365 * x2: Second X coordinate.
3270 * y2: Second Y coordinate. 3366 * y2: Second Y coordinate.
3271 */ 3367 */
3272 void API dw_draw_line(HWND handle, HPIXMAP pixmap, int x1, int y1, int x2, int y2) 3368 void API dw_draw_line(HWND handle, HPIXMAP pixmap, int x1, int y1, int x2, int y2)
3273 { 3369 {
3370 int _locked_by_me = FALSE;
3371 DW_MUTEX_LOCK;
3274 id image = handle; 3372 id image = handle;
3275 if(pixmap) 3373 if(pixmap)
3276 { 3374 {
3277 image = (id)pixmap->handle; 3375 image = (id)pixmap->handle;
3278 [image lockFocus]; 3376 [image lockFocus];
3284 } 3382 }
3285 NSBezierPath* aPath = [NSBezierPath bezierPath]; 3383 NSBezierPath* aPath = [NSBezierPath bezierPath];
3286 [aPath setLineWidth: 0.5]; 3384 [aPath setLineWidth: 0.5];
3287 NSColor *color = [NSColor colorWithDeviceRed: DW_RED_VALUE(_foreground)/255.0 green: DW_GREEN_VALUE(_foreground)/255.0 blue: DW_BLUE_VALUE(_foreground)/255.0 alpha: 1]; 3385 NSColor *color = [NSColor colorWithDeviceRed: DW_RED_VALUE(_foreground)/255.0 green: DW_GREEN_VALUE(_foreground)/255.0 blue: DW_BLUE_VALUE(_foreground)/255.0 alpha: 1];
3288 [color set]; 3386 [color set];
3289 [color release];
3290 3387
3291 [aPath moveToPoint:NSMakePoint(x1, y1)]; 3388 [aPath moveToPoint:NSMakePoint(x1, y1)];
3292 [aPath lineToPoint:NSMakePoint(x2, y2)]; 3389 [aPath lineToPoint:NSMakePoint(x2, y2)];
3293 [aPath stroke]; 3390 [aPath stroke];
3294 [aPath release];
3295 3391
3296 [image unlockFocus]; 3392 [image unlockFocus];
3393 DW_MUTEX_UNLOCK;
3297 } 3394 }
3298 3395
3299 /* Draw text on a window (preferably a render window). 3396 /* Draw text on a window (preferably a render window).
3300 * Parameters: 3397 * Parameters:
3301 * handle: Handle to the window. 3398 * handle: Handle to the window.
3304 * y: Y coordinate. 3401 * y: Y coordinate.
3305 * text: Text to be displayed. 3402 * text: Text to be displayed.
3306 */ 3403 */
3307 void API dw_draw_text(HWND handle, HPIXMAP pixmap, int x, int y, char *text) 3404 void API dw_draw_text(HWND handle, HPIXMAP pixmap, int x, int y, char *text)
3308 { 3405 {
3406 int _locked_by_me = FALSE;
3407 DW_MUTEX_LOCK;
3309 id image = handle; 3408 id image = handle;
3310 NSString *nstr = [ NSString stringWithUTF8String:text ]; 3409 NSString *nstr = [ NSString stringWithUTF8String:text ];
3311 if(image) 3410 if(image)
3312 { 3411 {
3313 if([image isMemberOfClass:[NSView class]]) 3412 if([image isMemberOfClass:[NSView class]])
3317 NSDictionary *dict = [[NSDictionary alloc] initWithObjectsAndKeys: 3416 NSDictionary *dict = [[NSDictionary alloc] initWithObjectsAndKeys:
3318 /*[NSFont fontWithName:@"Helvetica" size:26], NSFontAttributeName,*/ 3417 /*[NSFont fontWithName:@"Helvetica" size:26], NSFontAttributeName,*/
3319 color, NSForegroundColorAttributeName, nil]; 3418 color, NSForegroundColorAttributeName, nil];
3320 [nstr drawAtPoint:NSMakePoint(x, y) withAttributes:dict]; 3419 [nstr drawAtPoint:NSMakePoint(x, y) withAttributes:dict];
3321 [dict release]; 3420 [dict release];
3322 [color release];
3323 [image unlockFocus]; 3421 [image unlockFocus];
3324 } 3422 }
3325 _DWLastDrawable = handle; 3423 _DWLastDrawable = handle;
3326 } 3424 }
3327 if(pixmap) 3425 if(pixmap)
3332 NSDictionary *dict = [[NSDictionary alloc] initWithObjectsAndKeys: 3430 NSDictionary *dict = [[NSDictionary alloc] initWithObjectsAndKeys:
3333 /*[NSFont fontWithName:@"Helvetica" size:26], NSFontAttributeName,*/ 3431 /*[NSFont fontWithName:@"Helvetica" size:26], NSFontAttributeName,*/
3334 color, NSForegroundColorAttributeName, nil]; 3432 color, NSForegroundColorAttributeName, nil];
3335 [nstr drawAtPoint:NSMakePoint(x, y) withAttributes:dict]; 3433 [nstr drawAtPoint:NSMakePoint(x, y) withAttributes:dict];
3336 [dict release]; 3434 [dict release];
3337 [color release];
3338 [image unlockFocus]; 3435 [image unlockFocus];
3339 } 3436 }
3340 [nstr release]; 3437 DW_MUTEX_UNLOCK;
3341 } 3438 }
3342 3439
3343 /* Query the width and height of a text string. 3440 /* Query the width and height of a text string.
3344 * Parameters: 3441 * Parameters:
3345 * handle: Handle to the window. 3442 * handle: Handle to the window.
3348 * width: Pointer to a variable to be filled in with the width. 3445 * width: Pointer to a variable to be filled in with the width.
3349 * height Pointer to a variable to be filled in with the height. 3446 * height Pointer to a variable to be filled in with the height.
3350 */ 3447 */
3351 void API dw_font_text_extents_get(HWND handle, HPIXMAP pixmap, char *text, int *width, int *height) 3448 void API dw_font_text_extents_get(HWND handle, HPIXMAP pixmap, char *text, int *width, int *height)
3352 { 3449 {
3450 int _locked_by_me = FALSE;
3451 DW_MUTEX_LOCK;
3353 id image = handle; 3452 id image = handle;
3354 NSString *nstr = [[ NSString stringWithUTF8String:text ] autorelease]; 3453 NSString *nstr = [NSString stringWithUTF8String:text];
3355 if(pixmap) 3454 if(pixmap)
3356 { 3455 {
3357 image = (id)pixmap->handle; 3456 image = (id)pixmap->handle;
3358 [image lockFocus]; 3457 [image lockFocus];
3359 } 3458 }
3370 } 3469 }
3371 if(height) 3470 if(height)
3372 { 3471 {
3373 *height = size.height; 3472 *height = size.height;
3374 } 3473 }
3375 [nstr release];
3376 [image unlockFocus]; 3474 [image unlockFocus];
3475 DW_MUTEX_UNLOCK;
3377 } 3476 }
3378 3477
3379 /* Draw a polygon on a window (preferably a render window). 3478 /* Draw a polygon on a window (preferably a render window).
3380 * Parameters: 3479 * Parameters:
3381 * handle: Handle to the window. 3480 * handle: Handle to the window.
3386 * width: Width of rectangle. 3485 * width: Width of rectangle.
3387 * height: Height of rectangle. 3486 * height: Height of rectangle.
3388 */ 3487 */
3389 void API dw_draw_polygon( HWND handle, HPIXMAP pixmap, int fill, int npoints, int *x, int *y ) 3488 void API dw_draw_polygon( HWND handle, HPIXMAP pixmap, int fill, int npoints, int *x, int *y )
3390 { 3489 {
3490 int _locked_by_me = FALSE;
3491 DW_MUTEX_LOCK;
3391 id image = handle; 3492 id image = handle;
3392 int z; 3493 int z;
3393 if(pixmap) 3494 if(pixmap)
3394 { 3495 {
3395 image = (id)pixmap->handle; 3496 image = (id)pixmap->handle;
3402 } 3503 }
3403 NSBezierPath* aPath = [NSBezierPath bezierPath]; 3504 NSBezierPath* aPath = [NSBezierPath bezierPath];
3404 [aPath setLineWidth: 0.5]; 3505 [aPath setLineWidth: 0.5];
3405 NSColor *color = [NSColor colorWithDeviceRed: DW_RED_VALUE(_foreground)/255.0 green: DW_GREEN_VALUE(_foreground)/255.0 blue: DW_BLUE_VALUE(_foreground)/255.0 alpha: 1]; 3506 NSColor *color = [NSColor colorWithDeviceRed: DW_RED_VALUE(_foreground)/255.0 green: DW_GREEN_VALUE(_foreground)/255.0 blue: DW_BLUE_VALUE(_foreground)/255.0 alpha: 1];
3406 [color set]; 3507 [color set];
3407 [color release];
3408 3508
3409 [aPath moveToPoint:NSMakePoint(*x, *y)]; 3509 [aPath moveToPoint:NSMakePoint(*x, *y)];
3410 for(z=1;z<npoints;z++) 3510 for(z=1;z<npoints;z++)
3411 { 3511 {
3412 [aPath lineToPoint:NSMakePoint(x[z], y[z])]; 3512 [aPath lineToPoint:NSMakePoint(x[z], y[z])];
3415 if(fill) 3515 if(fill)
3416 { 3516 {
3417 [aPath fill]; 3517 [aPath fill];
3418 } 3518 }
3419 [aPath stroke]; 3519 [aPath stroke];
3420 [aPath release];
3421 [image unlockFocus]; 3520 [image unlockFocus];
3521 DW_MUTEX_UNLOCK;
3422 } 3522 }
3423 3523
3424 /* Draw a rectangle on a window (preferably a render window). 3524 /* Draw a rectangle on a window (preferably a render window).
3425 * Parameters: 3525 * Parameters:
3426 * handle: Handle to the window. 3526 * handle: Handle to the window.
3431 * width: Width of rectangle. 3531 * width: Width of rectangle.
3432 * height: Height of rectangle. 3532 * height: Height of rectangle.
3433 */ 3533 */
3434 void API dw_draw_rect(HWND handle, HPIXMAP pixmap, int fill, int x, int y, int width, int height) 3534 void API dw_draw_rect(HWND handle, HPIXMAP pixmap, int fill, int x, int y, int width, int height)
3435 { 3535 {
3536 int _locked_by_me = FALSE;
3537 DW_MUTEX_LOCK;
3436 id image = handle; 3538 id image = handle;
3437 if(pixmap) 3539 if(pixmap)
3438 { 3540 {
3439 image = (id)pixmap->handle; 3541 image = (id)pixmap->handle;
3440 [image lockFocus]; 3542 [image lockFocus];
3446 } 3548 }
3447 NSBezierPath* aPath = [NSBezierPath bezierPath]; 3549 NSBezierPath* aPath = [NSBezierPath bezierPath];
3448 [aPath setLineWidth: 0.5]; 3550 [aPath setLineWidth: 0.5];
3449 NSColor *color = [NSColor colorWithDeviceRed: DW_RED_VALUE(_foreground)/255.0 green: DW_GREEN_VALUE(_foreground)/255.0 blue: DW_BLUE_VALUE(_foreground)/255.0 alpha: 1]; 3551 NSColor *color = [NSColor colorWithDeviceRed: DW_RED_VALUE(_foreground)/255.0 green: DW_GREEN_VALUE(_foreground)/255.0 blue: DW_BLUE_VALUE(_foreground)/255.0 alpha: 1];
3450 [color set]; 3552 [color set];
3451 [color release];
3452 3553
3453 [aPath moveToPoint:NSMakePoint(x, y)]; 3554 [aPath moveToPoint:NSMakePoint(x, y)];
3454 [aPath lineToPoint:NSMakePoint(x, y + height)]; 3555 [aPath lineToPoint:NSMakePoint(x, y + height)];
3455 [aPath lineToPoint:NSMakePoint(x + width, y + height)]; 3556 [aPath lineToPoint:NSMakePoint(x + width, y + height)];
3456 [aPath lineToPoint:NSMakePoint(x + width, y)]; 3557 [aPath lineToPoint:NSMakePoint(x + width, y)];
3457 [aPath closePath]; 3558 [aPath closePath];
3458 [aPath fill]; 3559 [aPath fill];
3459 [aPath stroke]; 3560 [aPath stroke];
3460 [aPath release];
3461 [image unlockFocus]; 3561 [image unlockFocus];
3562 DW_MUTEX_UNLOCK;
3462 } 3563 }
3463 3564
3464 /* 3565 /*
3465 * Create a tree object to be packed. 3566 * Create a tree object to be packed.
3466 * Parameters: 3567 * Parameters:
3467 * id: An ID to be used for getting the resource from the 3568 * id: An ID to be used for getting the resource from the
3468 * resource file. 3569 * resource file.
3469 */ 3570 */
3470 HWND API dw_tree_new(ULONG cid) 3571 HWND API dw_tree_new(ULONG cid)
3471 { 3572 {
3573 int _locked_by_me = FALSE;
3574 DW_MUTEX_LOCK;
3472 NSScrollView *scrollview = [[NSScrollView alloc] init]; 3575 NSScrollView *scrollview = [[NSScrollView alloc] init];
3473 DWTree *tree = [[DWTree alloc] init]; 3576 DWTree *tree = [[DWTree alloc] init];
3474 3577
3475 [tree setScrollview:scrollview]; 3578 [tree setScrollview:scrollview];
3476 [scrollview setBorderType:NSBezelBorder]; 3579 [scrollview setBorderType:NSBezelBorder];
3480 [tree setAllowsMultipleSelection:NO]; 3583 [tree setAllowsMultipleSelection:NO];
3481 [tree setDataSource:tree]; 3584 [tree setDataSource:tree];
3482 [scrollview setDocumentView:tree]; 3585 [scrollview setDocumentView:tree];
3483 [tree setHeaderView:nil]; 3586 [tree setHeaderView:nil];
3484 [tree setTag:cid]; 3587 [tree setTag:cid];
3588 [scrollview release];
3589 DW_MUTEX_UNLOCK;
3485 return tree; 3590 return tree;
3486 } 3591 }
3487 3592
3488 /* 3593 /*
3489 * Inserts an item into a tree window (widget) after another item. 3594 * Inserts an item into a tree window (widget) after another item.
3495 * parent: Parent handle or 0 if root. 3600 * parent: Parent handle or 0 if root.
3496 * itemdata: Item specific data. 3601 * itemdata: Item specific data.
3497 */ 3602 */
3498 HTREEITEM API dw_tree_insert_after(HWND handle, HTREEITEM item, char *title, HICN icon, HTREEITEM parent, void *itemdata) 3603 HTREEITEM API dw_tree_insert_after(HWND handle, HTREEITEM item, char *title, HICN icon, HTREEITEM parent, void *itemdata)
3499 { 3604 {
3605 int _locked_by_me = FALSE;
3606 DW_MUTEX_LOCK;
3500 DWTree *tree = handle; 3607 DWTree *tree = handle;
3501 NSString *nstr = [NSString stringWithUTF8String:title]; 3608 NSString *nstr = [NSString stringWithUTF8String:title];
3502 NSPointerArray *treenode = [NSPointerArray pointerArrayWithWeakObjects]; 3609 NSPointerArray *treenode = [NSPointerArray pointerArrayWithWeakObjects];
3503 [treenode addPointer:icon]; 3610 [treenode addPointer:icon];
3504 [treenode addPointer:nstr]; 3611 [treenode addPointer:nstr];
3505 [treenode addPointer:itemdata]; 3612 [treenode addPointer:itemdata];
3506 [treenode addPointer:NULL]; 3613 [treenode addPointer:NULL];
3507 [tree addTree:treenode and:parent]; 3614 [tree addTree:treenode and:parent];
3508 [tree reloadData]; 3615 [tree reloadData];
3616 DW_MUTEX_UNLOCK;
3509 return treenode; 3617 return treenode;
3510 } 3618 }
3511 3619
3512 /* 3620 /*
3513 * Inserts an item into a tree window (widget). 3621 * Inserts an item into a tree window (widget).
3529 * handle: Handle to the tree containing the item. 3637 * handle: Handle to the tree containing the item.
3530 * item: Handle of the item to be modified. 3638 * item: Handle of the item to be modified.
3531 */ 3639 */
3532 char * API dw_tree_get_title(HWND handle, HTREEITEM item) 3640 char * API dw_tree_get_title(HWND handle, HTREEITEM item)
3533 { 3641 {
3642 int _locked_by_me = FALSE;
3643 DW_MUTEX_LOCK;
3534 NSPointerArray *array = (NSPointerArray *)item; 3644 NSPointerArray *array = (NSPointerArray *)item;
3535 NSString *nstr = (NSString *)[array pointerAtIndex:1]; 3645 NSString *nstr = (NSString *)[array pointerAtIndex:1];
3646 DW_MUTEX_UNLOCK;
3536 return strdup([nstr UTF8String]); 3647 return strdup([nstr UTF8String]);
3537 } 3648 }
3538 3649
3539 /* 3650 /*
3540 * Gets the text an item in a tree window (widget). 3651 * Gets the text an item in a tree window (widget).
3556 * title: The text title of the entry. 3667 * title: The text title of the entry.
3557 * icon: Handle to coresponding icon. 3668 * icon: Handle to coresponding icon.
3558 */ 3669 */
3559 void API dw_tree_item_change(HWND handle, HTREEITEM item, char *title, HICN icon) 3670 void API dw_tree_item_change(HWND handle, HTREEITEM item, char *title, HICN icon)
3560 { 3671 {
3672 int _locked_by_me = FALSE;
3673 DW_MUTEX_LOCK;
3561 DWTree *tree = handle; 3674 DWTree *tree = handle;
3562 NSPointerArray *array = (NSPointerArray *)item; 3675 NSPointerArray *array = (NSPointerArray *)item;
3563 if(title) 3676 if(title)
3564 { 3677 {
3565 NSString *nstr = [NSString stringWithUTF8String:title]; 3678 NSString *nstr = [NSString stringWithUTF8String:title];
3568 if(icon) 3681 if(icon)
3569 { 3682 {
3570 [array replacePointerAtIndex:0 withPointer:icon]; 3683 [array replacePointerAtIndex:0 withPointer:icon];
3571 } 3684 }
3572 [tree reloadData]; 3685 [tree reloadData];
3686 DW_MUTEX_UNLOCK;
3573 } 3687 }
3574 3688
3575 /* 3689 /*
3576 * Sets the item data of a tree item. 3690 * Sets the item data of a tree item.
3577 * Parameters: 3691 * Parameters:
3579 * item: Handle of the item to be modified. 3693 * item: Handle of the item to be modified.
3580 * itemdata: User defined data to be associated with item. 3694 * itemdata: User defined data to be associated with item.
3581 */ 3695 */
3582 void API dw_tree_item_set_data(HWND handle, HTREEITEM item, void *itemdata) 3696 void API dw_tree_item_set_data(HWND handle, HTREEITEM item, void *itemdata)
3583 { 3697 {
3698 int _locked_by_me = FALSE;
3699 DW_MUTEX_LOCK;
3584 NSPointerArray *array = (NSPointerArray *)item; 3700 NSPointerArray *array = (NSPointerArray *)item;
3585 [array replacePointerAtIndex:2 withPointer:itemdata]; 3701 [array replacePointerAtIndex:2 withPointer:itemdata];
3702 DW_MUTEX_UNLOCK;
3586 } 3703 }
3587 3704
3588 /* 3705 /*
3589 * Gets the item data of a tree item. 3706 * Gets the item data of a tree item.
3590 * Parameters: 3707 * Parameters:
3591 * handle: Handle to the tree containing the item. 3708 * handle: Handle to the tree containing the item.
3592 * item: Handle of the item to be modified. 3709 * item: Handle of the item to be modified.
3593 */ 3710 */
3594 void * API dw_tree_item_get_data(HWND handle, HTREEITEM item) 3711 void * API dw_tree_item_get_data(HWND handle, HTREEITEM item)
3595 { 3712 {
3713 int _locked_by_me = FALSE;
3714 DW_MUTEX_LOCK;
3596 NSPointerArray *array = (NSPointerArray *)item; 3715 NSPointerArray *array = (NSPointerArray *)item;
3597 return [array pointerAtIndex:2]; 3716 void *result = [array pointerAtIndex:2];
3717 DW_MUTEX_UNLOCK;
3718 return result;
3598 } 3719 }
3599 3720
3600 /* 3721 /*
3601 * Sets this item as the active selection. 3722 * Sets this item as the active selection.
3602 * Parameters: 3723 * Parameters:
3603 * handle: Handle to the tree window (widget) to be selected. 3724 * handle: Handle to the tree window (widget) to be selected.
3604 * item: Handle to the item to be selected. 3725 * item: Handle to the item to be selected.
3605 */ 3726 */
3606 void API dw_tree_item_select(HWND handle, HTREEITEM item) 3727 void API dw_tree_item_select(HWND handle, HTREEITEM item)
3607 { 3728 {
3729 int _locked_by_me = FALSE;
3730 DW_MUTEX_LOCK;
3608 DWTree *tree = handle; 3731 DWTree *tree = handle;
3609 NSInteger itemIndex = [tree rowForItem:item]; 3732 NSInteger itemIndex = [tree rowForItem:item];
3610 if(itemIndex > -1) 3733 if(itemIndex > -1)
3611 { 3734 {
3612 [tree selectRowIndexes:[NSIndexSet indexSetWithIndex:itemIndex] byExtendingSelection:NO]; 3735 [tree selectRowIndexes:[NSIndexSet indexSetWithIndex:itemIndex] byExtendingSelection:NO];
3613 } 3736 }
3737 DW_MUTEX_UNLOCK;
3614 } 3738 }
3615 3739
3616 /* 3740 /*
3617 * Removes all nodes from a tree. 3741 * Removes all nodes from a tree.
3618 * Parameters: 3742 * Parameters:
3619 * handle: Handle to the window (widget) to be cleared. 3743 * handle: Handle to the window (widget) to be cleared.
3620 */ 3744 */
3621 void API dw_tree_clear(HWND handle) 3745 void API dw_tree_clear(HWND handle)
3622 { 3746 {
3747 int _locked_by_me = FALSE;
3748 DW_MUTEX_LOCK;
3623 DWTree *tree = handle; 3749 DWTree *tree = handle;
3624 [tree clear]; 3750 [tree clear];
3751 DW_MUTEX_UNLOCK;
3625 } 3752 }
3626 3753
3627 /* 3754 /*
3628 * Expands a node on a tree. 3755 * Expands a node on a tree.
3629 * Parameters: 3756 * Parameters:
3630 * handle: Handle to the tree window (widget). 3757 * handle: Handle to the tree window (widget).
3631 * item: Handle to node to be expanded. 3758 * item: Handle to node to be expanded.
3632 */ 3759 */
3633 void API dw_tree_item_expand(HWND handle, HTREEITEM item) 3760 void API dw_tree_item_expand(HWND handle, HTREEITEM item)
3634 { 3761 {
3762 int _locked_by_me = FALSE;
3763 DW_MUTEX_LOCK;
3635 DWTree *tree = handle; 3764 DWTree *tree = handle;
3636 [tree expandItem:item]; 3765 [tree expandItem:item];
3766 DW_MUTEX_UNLOCK;
3637 } 3767 }
3638 3768
3639 /* 3769 /*
3640 * Collapses a node on a tree. 3770 * Collapses a node on a tree.
3641 * Parameters: 3771 * Parameters:
3642 * handle: Handle to the tree window (widget). 3772 * handle: Handle to the tree window (widget).
3643 * item: Handle to node to be collapsed. 3773 * item: Handle to node to be collapsed.
3644 */ 3774 */
3645 void API dw_tree_item_collapse(HWND handle, HTREEITEM item) 3775 void API dw_tree_item_collapse(HWND handle, HTREEITEM item)
3646 { 3776 {
3777 int _locked_by_me = FALSE;
3778 DW_MUTEX_LOCK;
3647 DWTree *tree = handle; 3779 DWTree *tree = handle;
3648 [tree collapseItem:item]; 3780 [tree collapseItem:item];
3781 DW_MUTEX_UNLOCK;
3649 } 3782 }
3650 3783
3651 /* 3784 /*
3652 * Removes a node from a tree. 3785 * Removes a node from a tree.
3653 * Parameters: 3786 * Parameters:
3654 * handle: Handle to the window (widget) to be cleared. 3787 * handle: Handle to the window (widget) to be cleared.
3655 * item: Handle to node to be deleted. 3788 * item: Handle to node to be deleted.
3656 */ 3789 */
3657 void API dw_tree_item_delete(HWND handle, HTREEITEM item) 3790 void API dw_tree_item_delete(HWND handle, HTREEITEM item)
3658 { 3791 {
3792 int _locked_by_me = FALSE;
3793 DW_MUTEX_LOCK;
3659 DWTree *tree = handle; 3794 DWTree *tree = handle;
3660 [tree deleteNode:item]; 3795 [tree deleteNode:item];
3661 [tree reloadData]; 3796 [tree reloadData];
3797 DW_MUTEX_UNLOCK;
3662 } 3798 }
3663 3799
3664 /* 3800 /*
3665 * Create a container object to be packed. 3801 * Create a container object to be packed.
3666 * Parameters: 3802 * Parameters:
3667 * id: An ID to be used for getting the resource from the 3803 * id: An ID to be used for getting the resource from the
3668 * resource file. 3804 * resource file.
3669 */ 3805 */
3670 HWND API dw_container_new(ULONG cid, int multi) 3806 HWND API dw_container_new(ULONG cid, int multi)
3671 { 3807 {
3808 int _locked_by_me = FALSE;
3809 DW_MUTEX_LOCK;
3672 DWContainer *cont = _cont_new(cid, multi); 3810 DWContainer *cont = _cont_new(cid, multi);
3673 NSScrollView *scrollview = [cont scrollview]; 3811 NSScrollView *scrollview = [cont scrollview];
3674 [scrollview setHasHorizontalScroller:YES]; 3812 [scrollview setHasHorizontalScroller:YES];
3675 NSTableHeaderView *header = [[NSTableHeaderView alloc] init]; 3813 NSTableHeaderView *header = [[NSTableHeaderView alloc] init];
3676 [cont setHeaderView:header]; 3814 [cont setHeaderView:header];
3815 [header release];
3816 DW_MUTEX_UNLOCK;
3677 return cont; 3817 return cont;
3678 } 3818 }
3679 3819
3680 /* 3820 /*
3681 * Sets up the container columns. 3821 * Sets up the container columns.
3687 * separator: The column number that contains the main separator. 3827 * separator: The column number that contains the main separator.
3688 * (this item may only be used in OS/2) 3828 * (this item may only be used in OS/2)
3689 */ 3829 */
3690 int API dw_container_setup(HWND handle, unsigned long *flags, char **titles, int count, int separator) 3830 int API dw_container_setup(HWND handle, unsigned long *flags, char **titles, int count, int separator)
3691 { 3831 {
3832 int _locked_by_me = FALSE;
3833 DW_MUTEX_LOCK;
3692 int z; 3834 int z;
3693 DWContainer *cont = handle; 3835 DWContainer *cont = handle;
3694 3836
3695 [cont setup]; 3837 [cont setup];
3696 3838
3698 { 3840 {
3699 NSTableColumn *column = [[NSTableColumn alloc] init]; 3841 NSTableColumn *column = [[NSTableColumn alloc] init];
3700 [[column headerCell] setStringValue:[ NSString stringWithUTF8String:titles[z] ]]; 3842 [[column headerCell] setStringValue:[ NSString stringWithUTF8String:titles[z] ]];
3701 if(flags[z] & DW_CFA_BITMAPORICON) 3843 if(flags[z] & DW_CFA_BITMAPORICON)
3702 { 3844 {
3703 NSImageCell *imagecell = [[[NSImageCell alloc] init] autorelease]; 3845 NSImageCell *imagecell = [[NSImageCell alloc] init];
3704 [column setDataCell:imagecell]; 3846 [column setDataCell:imagecell];
3705 if(z == 0 && titles[z] && strcmp(titles[z], "Icon") == 0) 3847 if(z == 0 && titles[z] && strcmp(titles[z], "Icon") == 0)
3706 { 3848 {
3707 [column setResizingMask:NSTableColumnNoResizing]; 3849 [column setResizingMask:NSTableColumnNoResizing];
3708 [column setWidth:20]; 3850 [column setWidth:20];
3709 } 3851 }
3852 [imagecell release];
3710 } 3853 }
3711 [cont addTableColumn:column]; 3854 [cont addTableColumn:column];
3712 [cont addColumn:column andType:(int)flags[z]]; 3855 [cont addColumn:column andType:(int)flags[z]];
3856 [column release];
3713 } 3857 }
3714 3858 DW_MUTEX_UNLOCK;
3715 return TRUE; 3859 return TRUE;
3716 } 3860 }
3717 3861
3718 /* 3862 /*
3719 * Sets up the filesystem columns, note: filesystem always has an icon/filename field. 3863 * Sets up the filesystem columns, note: filesystem always has an icon/filename field.
3750 * handle: Handle to the container window (widget). 3894 * handle: Handle to the container window (widget).
3751 * rowcount: The number of items to be populated. 3895 * rowcount: The number of items to be populated.
3752 */ 3896 */
3753 void * API dw_container_alloc(HWND handle, int rowcount) 3897 void * API dw_container_alloc(HWND handle, int rowcount)
3754 { 3898 {
3899 int _locked_by_me = FALSE;
3900 DW_MUTEX_LOCK;
3755 DWContainer *cont = handle; 3901 DWContainer *cont = handle;
3756 [cont addRows:rowcount]; 3902 [cont addRows:rowcount];
3903 DW_MUTEX_UNLOCK;
3757 return cont; 3904 return cont;
3758 } 3905 }
3759 3906
3760 /* 3907 /*
3761 * Sets an item in specified row and column to the given data. 3908 * Sets an item in specified row and column to the given data.
3766 * row: Zero based row of data being set. 3913 * row: Zero based row of data being set.
3767 * data: Pointer to the data to be added. 3914 * data: Pointer to the data to be added.
3768 */ 3915 */
3769 void API dw_container_set_item(HWND handle, void *pointer, int column, int row, void *data) 3916 void API dw_container_set_item(HWND handle, void *pointer, int column, int row, void *data)
3770 { 3917 {
3918 int _locked_by_me = FALSE;
3919 DW_MUTEX_LOCK;
3771 DWContainer *cont = handle; 3920 DWContainer *cont = handle;
3772 id object = nil; 3921 id object = nil;
3773 int type = [cont cellType:column]; 3922 int type = [cont cellType:column];
3774 int lastadd = [cont lastAddPoint]; 3923 int lastadd = [cont lastAddPoint];
3775 3924
3776 if(!data) 3925 if(!data)
3777 { 3926 {
3927 DW_MUTEX_UNLOCK;
3778 return; 3928 return;
3779 } 3929 }
3780 if(type & DW_CFA_BITMAPORICON) 3930 if(type & DW_CFA_BITMAPORICON)
3781 { 3931 {
3782 object = *((NSImage **)data); 3932 object = *((NSImage **)data);
3819 3969
3820 strftime(textbuffer, 100, "%X", &curtm); 3970 strftime(textbuffer, 100, "%X", &curtm);
3821 } 3971 }
3822 else 3972 else
3823 { 3973 {
3974 DW_MUTEX_UNLOCK;
3824 return; 3975 return;
3825 } 3976 }
3826 object = [ NSString stringWithUTF8String:textbuffer ]; 3977 object = [ NSString stringWithUTF8String:textbuffer ];
3827 } 3978 }
3828 3979
3829 [cont editCell:object at:(row+lastadd) and:column]; 3980 [cont editCell:object at:(row+lastadd) and:column];
3981 DW_MUTEX_UNLOCK;
3830 } 3982 }
3831 3983
3832 /* 3984 /*
3833 * Changes an existing item in specified row and column to the given data. 3985 * Changes an existing item in specified row and column to the given data.
3834 * Parameters: 3986 * Parameters:
3905 * handle: Handle to the container window (widget). 4057 * handle: Handle to the container window (widget).
3906 * column: Zero based column. 4058 * column: Zero based column.
3907 */ 4059 */
3908 int API dw_container_get_column_type(HWND handle, int column) 4060 int API dw_container_get_column_type(HWND handle, int column)
3909 { 4061 {
4062 int _locked_by_me = FALSE;
4063 DW_MUTEX_LOCK;
3910 DWContainer *cont = handle; 4064 DWContainer *cont = handle;
3911 return [cont cellType:column]; 4065 int result = [cont cellType:column];
4066 DW_MUTEX_UNLOCK;
4067 return result;
3912 } 4068 }
3913 4069
3914 /* 4070 /*
3915 * Gets column type for a filesystem container column 4071 * Gets column type for a filesystem container column
3916 * Parameters: 4072 * Parameters:
3917 * handle: Handle to the container window (widget). 4073 * handle: Handle to the container window (widget).
3918 * column: Zero based column. 4074 * column: Zero based column.
3919 */ 4075 */
3920 int API dw_filesystem_get_column_type(HWND handle, int column) 4076 int API dw_filesystem_get_column_type(HWND handle, int column)
3921 { 4077 {
4078 int _locked_by_me = FALSE;
4079 DW_MUTEX_LOCK;
3922 DWContainer *cont = handle; 4080 DWContainer *cont = handle;
3923 return [cont cellType:column+2]; 4081 int result = [cont cellType:column+2];
4082 DW_MUTEX_UNLOCK;
4083 return result;
3924 } 4084 }
3925 4085
3926 /* 4086 /*
3927 * Sets the width of a column in the container. 4087 * Sets the width of a column in the container.
3928 * Parameters: 4088 * Parameters:
3930 * column: Zero based column of width being set. 4090 * column: Zero based column of width being set.
3931 * width: Width of column in pixels. 4091 * width: Width of column in pixels.
3932 */ 4092 */
3933 void API dw_container_set_column_width(HWND handle, int column, int width) 4093 void API dw_container_set_column_width(HWND handle, int column, int width)
3934 { 4094 {
4095 int _locked_by_me = FALSE;
4096 DW_MUTEX_LOCK;
3935 DWContainer *cont = handle; 4097 DWContainer *cont = handle;
3936 NSTableColumn *col = [cont getColumn:column]; 4098 NSTableColumn *col = [cont getColumn:column];
3937 4099
3938 [col setWidth:width]; 4100 [col setWidth:width];
4101 DW_MUTEX_UNLOCK;
3939 } 4102 }
3940 4103
3941 /* 4104 /*
3942 * Sets the title of a row in the container. 4105 * Sets the title of a row in the container.
3943 * Parameters: 4106 * Parameters:
3945 * row: Zero based row of data being set. 4108 * row: Zero based row of data being set.
3946 * title: String title of the item. 4109 * title: String title of the item.
3947 */ 4110 */
3948 void API dw_container_set_row_title(void *pointer, int row, char *title) 4111 void API dw_container_set_row_title(void *pointer, int row, char *title)
3949 { 4112 {
4113 int _locked_by_me = FALSE;
4114 DW_MUTEX_LOCK;
3950 DWContainer *cont = pointer; 4115 DWContainer *cont = pointer;
3951 return [cont setRow:row title:title]; 4116 [cont setRow:row title:title];
4117 DW_MUTEX_UNLOCK;
3952 } 4118 }
3953 4119
3954 /* 4120 /*
3955 * Sets the title of a row in the container. 4121 * Sets the title of a row in the container.
3956 * Parameters: 4122 * Parameters:
3958 * pointer: Pointer to the allocated memory in dw_container_alloc(). 4124 * pointer: Pointer to the allocated memory in dw_container_alloc().
3959 * rowcount: The number of rows to be inserted. 4125 * rowcount: The number of rows to be inserted.
3960 */ 4126 */
3961 void API dw_container_insert(HWND handle, void *pointer, int rowcount) 4127 void API dw_container_insert(HWND handle, void *pointer, int rowcount)
3962 { 4128 {
4129 int _locked_by_me = FALSE;
4130 DW_MUTEX_LOCK;
3963 DWContainer *cont = handle; 4131 DWContainer *cont = handle;
3964 return [cont reloadData]; 4132 [cont reloadData];
4133 DW_MUTEX_UNLOCK;
3965 } 4134 }
3966 4135
3967 /* 4136 /*
3968 * Removes all rows from a container. 4137 * Removes all rows from a container.
3969 * Parameters: 4138 * Parameters:
3970 * handle: Handle to the window (widget) to be cleared. 4139 * handle: Handle to the window (widget) to be cleared.
3971 * redraw: TRUE to cause the container to redraw immediately. 4140 * redraw: TRUE to cause the container to redraw immediately.
3972 */ 4141 */
3973 void API dw_container_clear(HWND handle, int redraw) 4142 void API dw_container_clear(HWND handle, int redraw)
3974 { 4143 {
4144 int _locked_by_me = FALSE;
4145 DW_MUTEX_LOCK;
3975 DWContainer *cont = handle; 4146 DWContainer *cont = handle;
3976 [cont clear]; 4147 [cont clear];
3977 if(redraw) 4148 if(redraw)
3978 { 4149 {
3979 [cont reloadData]; 4150 [cont reloadData];
3980 } 4151 }
4152 DW_MUTEX_UNLOCK;
3981 } 4153 }
3982 4154
3983 /* 4155 /*
3984 * Removes the first x rows from a container. 4156 * Removes the first x rows from a container.
3985 * Parameters: 4157 * Parameters:
3986 * handle: Handle to the window (widget) to be deleted from. 4158 * handle: Handle to the window (widget) to be deleted from.
3987 * rowcount: The number of rows to be deleted. 4159 * rowcount: The number of rows to be deleted.
3988 */ 4160 */
3989 void API dw_container_delete(HWND handle, int rowcount) 4161 void API dw_container_delete(HWND handle, int rowcount)
3990 { 4162 {
4163 int _locked_by_me = FALSE;
4164 DW_MUTEX_LOCK;
3991 DWContainer *cont = handle; 4165 DWContainer *cont = handle;
3992 int x; 4166 int x;
3993 4167
3994 for(x=0;x<rowcount;x++) 4168 for(x=0;x<rowcount;x++)
3995 { 4169 {
3996 [cont removeRow:0]; 4170 [cont removeRow:0];
3997 } 4171 }
4172 DW_MUTEX_UNLOCK;
3998 } 4173 }
3999 4174
4000 /* 4175 /*
4001 * Scrolls container up or down. 4176 * Scrolls container up or down.
4002 * Parameters: 4177 * Parameters:
4018 * return items that are currently selected. Otherwise 4193 * return items that are currently selected. Otherwise
4019 * it will return all records in the container. 4194 * it will return all records in the container.
4020 */ 4195 */
4021 char * API dw_container_query_start(HWND handle, unsigned long flags) 4196 char * API dw_container_query_start(HWND handle, unsigned long flags)
4022 { 4197 {
4198 int _locked_by_me = FALSE;
4199 DW_MUTEX_LOCK;
4023 DWContainer *cont = handle; 4200 DWContainer *cont = handle;
4024 NSIndexSet *selected = [cont selectedRowIndexes]; 4201 NSIndexSet *selected = [cont selectedRowIndexes];
4025 NSUInteger result = [selected indexGreaterThanOrEqualToIndex:0]; 4202 NSUInteger result = [selected indexGreaterThanOrEqualToIndex:0];
4026 char *retval = NULL; 4203 char *retval = NULL;
4027 4204
4028 if(result != NSNotFound) 4205 if(result != NSNotFound)
4029 { 4206 {
4030 retval = [cont getRowTitle:(int)result]; 4207 retval = [cont getRowTitle:(int)result];
4031 [cont setLastQueryPoint:(int)result]; 4208 [cont setLastQueryPoint:(int)result];
4032 } 4209 }
4033 [selected release]; 4210 DW_MUTEX_UNLOCK;
4034 return retval; 4211 return retval;
4035 } 4212 }
4036 4213
4037 /* 4214 /*
4038 * Continues an existing query of a container. 4215 * Continues an existing query of a container.
4042 * return items that are currently selected. Otherwise 4219 * return items that are currently selected. Otherwise
4043 * it will return all records in the container. 4220 * it will return all records in the container.
4044 */ 4221 */
4045 char * API dw_container_query_next(HWND handle, unsigned long flags) 4222 char * API dw_container_query_next(HWND handle, unsigned long flags)
4046 { 4223 {
4224 int _locked_by_me = FALSE;
4225 DW_MUTEX_LOCK;
4047 DWContainer *cont = handle; 4226 DWContainer *cont = handle;
4048 int lastQueryPoint = [cont lastQueryPoint]; 4227 int lastQueryPoint = [cont lastQueryPoint];
4049 NSIndexSet *selected = [cont selectedRowIndexes]; 4228 NSIndexSet *selected = [cont selectedRowIndexes];
4050 NSUInteger result = [selected indexGreaterThanIndex:lastQueryPoint]; 4229 NSUInteger result = [selected indexGreaterThanIndex:lastQueryPoint];
4051 char *retval = NULL; 4230 char *retval = NULL;
4053 if(result != NSNotFound) 4232 if(result != NSNotFound)
4054 { 4233 {
4055 retval = [cont getRowTitle:(int)result]; 4234 retval = [cont getRowTitle:(int)result];
4056 [cont setLastQueryPoint:(int)result]; 4235 [cont setLastQueryPoint:(int)result];
4057 } 4236 }
4058 [selected release]; 4237 DW_MUTEX_UNLOCK;
4059 return retval; 4238 return retval;
4060 } 4239 }
4061 4240
4062 /* 4241 /*
4063 * Cursors the item with the text speficied, and scrolls to that item. 4242 * Cursors the item with the text speficied, and scrolls to that item.
4065 * handle: Handle to the window (widget) to be queried. 4244 * handle: Handle to the window (widget) to be queried.
4066 * text: Text usually returned by dw_container_query(). 4245 * text: Text usually returned by dw_container_query().
4067 */ 4246 */
4068 void API dw_container_cursor(HWND handle, char *text) 4247 void API dw_container_cursor(HWND handle, char *text)
4069 { 4248 {
4249 int _locked_by_me = FALSE;
4250 DW_MUTEX_LOCK;
4070 DWContainer *cont = handle; 4251 DWContainer *cont = handle;
4071 char *thistext; 4252 char *thistext;
4072 int x, count = (int)[cont numberOfRowsInTableView:cont]; 4253 int x, count = (int)[cont numberOfRowsInTableView:cont];
4073 4254
4074 for(x=0;x<count;x++) 4255 for(x=0;x<count;x++)
4081 4262
4082 [cont selectRowIndexes:selected byExtendingSelection:YES]; 4263 [cont selectRowIndexes:selected byExtendingSelection:YES];
4083 [selected release]; 4264 [selected release];
4084 } 4265 }
4085 } 4266 }
4267 DW_MUTEX_UNLOCK;
4086 } 4268 }
4087 4269
4088 /* 4270 /*
4089 * Deletes the item with the text speficied. 4271 * Deletes the item with the text speficied.
4090 * Parameters: 4272 * Parameters:
4091 * handle: Handle to the window (widget). 4273 * handle: Handle to the window (widget).
4092 * text: Text usually returned by dw_container_query(). 4274 * text: Text usually returned by dw_container_query().
4093 */ 4275 */
4094 void API dw_container_delete_row(HWND handle, char *text) 4276 void API dw_container_delete_row(HWND handle, char *text)
4095 { 4277 {
4278 int _locked_by_me = FALSE;
4279 DW_MUTEX_LOCK;
4096 DWContainer *cont = handle; 4280 DWContainer *cont = handle;
4097 char *thistext; 4281 char *thistext;
4098 int x, count = (int)[cont numberOfRowsInTableView:cont]; 4282 int x, count = (int)[cont numberOfRowsInTableView:cont];
4099 4283
4100 for(x=0;x<count;x++) 4284 for(x=0;x<count;x++)
4105 { 4289 {
4106 [cont removeRow:x]; 4290 [cont removeRow:x];
4107 return; 4291 return;
4108 } 4292 }
4109 } 4293 }
4294 DW_MUTEX_UNLOCK;
4110 } 4295 }
4111 4296
4112 /* 4297 /*
4113 * Optimizes the column widths so that all data is visible. 4298 * Optimizes the column widths so that all data is visible.
4114 * Parameters: 4299 * Parameters:
4115 * handle: Handle to the window (widget) to be optimized. 4300 * handle: Handle to the window (widget) to be optimized.
4116 */ 4301 */
4117 void API dw_container_optimize(HWND handle) 4302 void API dw_container_optimize(HWND handle)
4118 { 4303 {
4304 int _locked_by_me = FALSE;
4305 DW_MUTEX_LOCK;
4119 DWContainer *cont = handle; 4306 DWContainer *cont = handle;
4120 /*[cont sizeToFit];*/ 4307 /*[cont sizeToFit];*/
4121 [cont setColumnAutoresizingStyle:NSTableViewUniformColumnAutoresizingStyle]; 4308 [cont setColumnAutoresizingStyle:NSTableViewUniformColumnAutoresizingStyle];
4309 DW_MUTEX_UNLOCK;
4122 } 4310 }
4123 4311
4124 /* 4312 /*
4125 * Inserts an icon into the taskbar. 4313 * Inserts an icon into the taskbar.
4126 * Parameters: 4314 * Parameters:
4156 { 4344 {
4157 NSBundle *bundle = [NSBundle mainBundle]; 4345 NSBundle *bundle = [NSBundle mainBundle];
4158 NSString *respath = [bundle resourcePath]; 4346 NSString *respath = [bundle resourcePath];
4159 NSString *filepath = [respath stringByAppendingFormat:@"/%u.png", resid]; 4347 NSString *filepath = [respath stringByAppendingFormat:@"/%u.png", resid];
4160 NSImage *image = [[NSImage alloc] initWithContentsOfFile:filepath]; 4348 NSImage *image = [[NSImage alloc] initWithContentsOfFile:filepath];
4161 [bundle release];
4162 [respath release];
4163 [filepath release];
4164 return image; 4349 return image;
4165 } 4350 }
4166 4351
4167 /* 4352 /*
4168 * Obtains an icon from a file. 4353 * Obtains an icon from a file.
4178 if(!image) 4363 if(!image)
4179 { 4364 {
4180 nstr = [nstr stringByAppendingString:@".png"]; 4365 nstr = [nstr stringByAppendingString:@".png"];
4181 image = [[NSImage alloc] initWithContentsOfFile:nstr]; 4366 image = [[NSImage alloc] initWithContentsOfFile:nstr];
4182 } 4367 }
4183 [nstr release];
4184 return image; 4368 return image;
4185 } 4369 }
4186 4370
4187 /* 4371 /*
4188 * Obtains an icon from data 4372 * Obtains an icon from data
4191 * DW pick the appropriate file extension. 4375 * DW pick the appropriate file extension.
4192 * (ICO on OS/2 or Windows, XPM on Unix) 4376 * (ICO on OS/2 or Windows, XPM on Unix)
4193 */ 4377 */
4194 HICN API dw_icon_load_from_data(char *data, int len) 4378 HICN API dw_icon_load_from_data(char *data, int len)
4195 { 4379 {
4196 NSData *thisdata = [[[NSData alloc] dataWithBytes:data length:len] autorelease]; 4380 NSData *thisdata = [[NSData alloc] dataWithBytes:data length:len];
4197 NSImage *image = [[NSImage alloc] initWithData:thisdata]; 4381 NSImage *image = [[NSImage alloc] initWithData:thisdata];
4198 [thisdata release];
4199 return image; 4382 return image;
4200 } 4383 }
4201 4384
4202 /* 4385 /*
4203 * Frees a loaded resource in OS/2 and Windows. 4386 * Frees a loaded resource in OS/2 and Windows.
4236 * Returns: 4419 * Returns:
4237 * A handle to a splitbar window or NULL on failure. 4420 * A handle to a splitbar window or NULL on failure.
4238 */ 4421 */
4239 HWND API dw_splitbar_new(int type, HWND topleft, HWND bottomright, unsigned long cid) 4422 HWND API dw_splitbar_new(int type, HWND topleft, HWND bottomright, unsigned long cid)
4240 { 4423 {
4424 HWND tmpbox = dw_box_new(DW_VERT, 0);
4425 int _locked_by_me = FALSE;
4426 DW_MUTEX_LOCK;
4241 DWSplitBar *split = [[DWSplitBar alloc] init]; 4427 DWSplitBar *split = [[DWSplitBar alloc] init];
4242 HWND tmpbox = dw_box_new(DW_VERT, 0);
4243 [split setDelegate:split]; 4428 [split setDelegate:split];
4244 dw_box_pack_start(tmpbox, topleft, 0, 0, TRUE, TRUE, 0); 4429 dw_box_pack_start(tmpbox, topleft, 0, 0, TRUE, TRUE, 0);
4245 [split addSubview:tmpbox]; 4430 [split addSubview:tmpbox];
4246 tmpbox = dw_box_new(DW_VERT, 0); 4431 tmpbox = dw_box_new(DW_VERT, 0);
4247 dw_box_pack_start(tmpbox, bottomright, 0, 0, TRUE, TRUE, 0); 4432 dw_box_pack_start(tmpbox, bottomright, 0, 0, TRUE, TRUE, 0);
4253 else 4438 else
4254 { 4439 {
4255 [split setVertical:YES]; 4440 [split setVertical:YES];
4256 } 4441 }
4257 /* [split setTag:cid]; Why doesn't this work? */ 4442 /* [split setTag:cid]; Why doesn't this work? */
4443 DW_MUTEX_UNLOCK;
4258 return split; 4444 return split;
4259 } 4445 }
4260 4446
4261 /* 4447 /*
4262 * Sets the position of a splitbar (pecentage). 4448 * Sets the position of a splitbar (pecentage).
4264 * handle: The handle to the splitbar returned by dw_splitbar_new(). 4450 * handle: The handle to the splitbar returned by dw_splitbar_new().
4265 */ 4451 */
4266 void API dw_splitbar_set(HWND handle, float percent) 4452 void API dw_splitbar_set(HWND handle, float percent)
4267 { 4453 {
4268 DWSplitBar *split = handle; 4454 DWSplitBar *split = handle;
4455 int _locked_by_me = FALSE;
4456 DW_MUTEX_LOCK;
4269 NSRect rect = [split frame]; 4457 NSRect rect = [split frame];
4270 float pos; 4458 float pos;
4271 /* Calculate the position based on the size */ 4459 /* Calculate the position based on the size */
4272 if([split isVertical]) 4460 if([split isVertical])
4273 { 4461 {
4287 * event when we get an actual size to try 4475 * event when we get an actual size to try
4288 * to set the splitbar again. 4476 * to set the splitbar again.
4289 */ 4477 */
4290 [split setPercent:percent]; 4478 [split setPercent:percent];
4291 } 4479 }
4480 DW_MUTEX_UNLOCK;
4292 } 4481 }
4293 4482
4294 /* 4483 /*
4295 * Gets the position of a splitbar (pecentage). 4484 * Gets the position of a splitbar (pecentage).
4296 * Parameters: 4485 * Parameters:
4326 * Parameters: 4515 * Parameters:
4327 * id: An ID to be used with dw_window_from_id() or 0L. 4516 * id: An ID to be used with dw_window_from_id() or 0L.
4328 */ 4517 */
4329 HWND API dw_bitmap_new(ULONG cid) 4518 HWND API dw_bitmap_new(ULONG cid)
4330 { 4519 {
4520 int _locked_by_me = FALSE;
4521 DW_MUTEX_LOCK;
4331 NSImageView *bitmap = [[NSImageView alloc] init]; 4522 NSImageView *bitmap = [[NSImageView alloc] init];
4332 [bitmap setImageFrameStyle:NSImageFrameNone]; 4523 [bitmap setImageFrameStyle:NSImageFrameNone];
4333 [bitmap setEditable:NO]; 4524 [bitmap setEditable:NO];
4334 [bitmap setTag:cid]; 4525 [bitmap setTag:cid];
4526 DW_MUTEX_UNLOCK;
4335 return bitmap; 4527 return bitmap;
4336 } 4528 }
4337 4529
4338 /* 4530 /*
4339 * Creates a pixmap with given parameters. 4531 * Creates a pixmap with given parameters.
4380 if(!image) 4572 if(!image)
4381 { 4573 {
4382 nstr = [nstr stringByAppendingString:@".png"]; 4574 nstr = [nstr stringByAppendingString:@".png"];
4383 image = [[NSImage alloc] initWithContentsOfFile:nstr]; 4575 image = [[NSImage alloc] initWithContentsOfFile:nstr];
4384 } 4576 }
4385 [nstr release];
4386 NSSize size = [image size]; 4577 NSSize size = [image size];
4387 pixmap->width = size.width; 4578 pixmap->width = size.width;
4388 pixmap->height = size.height; 4579 pixmap->height = size.height;
4389 pixmap->handle = image; 4580 pixmap->handle = image;
4390 return pixmap; 4581 return pixmap;
4404 { 4595 {
4405 HPIXMAP pixmap; 4596 HPIXMAP pixmap;
4406 4597
4407 if (!(pixmap = calloc(1,sizeof(struct _hpixmap)))) 4598 if (!(pixmap = calloc(1,sizeof(struct _hpixmap))))
4408 return NULL; 4599 return NULL;
4409 NSData *thisdata = [[[NSData alloc] dataWithBytes:data length:len] autorelease]; 4600 NSData *thisdata = [[NSData alloc] dataWithBytes:data length:len];
4410 NSImage *image = [[NSImage alloc] initWithData:thisdata]; 4601 NSImage *image = [[NSImage alloc] initWithData:thisdata];
4411 NSSize size = [image size]; 4602 NSSize size = [image size];
4412 pixmap->width = size.width; 4603 pixmap->width = size.width;
4413 pixmap->height = size.height; 4604 pixmap->height = size.height;
4414 pixmap->handle = image; 4605 pixmap->handle = image;
4415 [thisdata release];
4416 return pixmap; 4606 return pixmap;
4417 } 4607 }
4418 4608
4419 /* 4609 /*
4420 * Creates a bitmap mask for rendering bitmaps with transparent backgrounds 4610 * Creates a bitmap mask for rendering bitmaps with transparent backgrounds
4445 NSImage *image = [[NSImage alloc] initWithContentsOfFile:filepath]; 4635 NSImage *image = [[NSImage alloc] initWithContentsOfFile:filepath];
4446 NSSize size = [image size]; 4636 NSSize size = [image size];
4447 pixmap->width = size.width; 4637 pixmap->width = size.width;
4448 pixmap->height = size.height; 4638 pixmap->height = size.height;
4449 pixmap->handle = image; 4639 pixmap->handle = image;
4450 [bundle release];
4451 [respath release];
4452 [filepath release];
4453 [image release]; 4640 [image release];
4454 return pixmap; 4641 return pixmap;
4455 } 4642 }
4456 4643
4457 /* 4644 /*
4481 * xsrc: X coordinate of source. 4668 * xsrc: X coordinate of source.
4482 * ysrc: Y coordinate of source. 4669 * ysrc: Y coordinate of source.
4483 */ 4670 */
4484 void API dw_pixmap_bitblt(HWND dest, HPIXMAP destp, int xdest, int ydest, int width, int height, HWND src, HPIXMAP srcp, int xsrc, int ysrc) 4671 void API dw_pixmap_bitblt(HWND dest, HPIXMAP destp, int xdest, int ydest, int width, int height, HWND src, HPIXMAP srcp, int xsrc, int ysrc)
4485 { 4672 {
4673 int _locked_by_me = FALSE;
4674 DW_MUTEX_LOCK;
4486 id bltdest = dest; 4675 id bltdest = dest;
4487 id bltsrc = src; 4676 id bltsrc = src;
4488 if(destp) 4677 if(destp)
4489 { 4678 {
4490 bltdest = (id)destp->handle; 4679 bltdest = (id)destp->handle;
4500 bltsrc = (id)srcp->handle; 4689 bltsrc = (id)srcp->handle;
4501 NSImage *image = bltsrc; 4690 NSImage *image = bltsrc;
4502 [image drawAtPoint:NSMakePoint(xdest, ydest) fromRect:NSMakeRect(xsrc, ysrc, width, height) operation:NSCompositeCopy fraction:1.0]; 4691 [image drawAtPoint:NSMakePoint(xdest, ydest) fromRect:NSMakeRect(xsrc, ysrc, width, height) operation:NSCompositeCopy fraction:1.0];
4503 } 4692 }
4504 [bltdest unlockFocus]; 4693 [bltdest unlockFocus];
4694 DW_MUTEX_UNLOCK;
4505 } 4695 }
4506 4696
4507 /* 4697 /*
4508 * Create a new static text window (widget) to be packed. 4698 * Create a new static text window (widget) to be packed.
4509 * Not available under OS/2, eCS 4699 * Not available under OS/2, eCS
4533 4723
4534 sprintf(buffer, "%04d-%02d-%02d 00:00:00 +0600", year, month, day); 4724 sprintf(buffer, "%04d-%02d-%02d 00:00:00 +0600", year, month, day);
4535 4725
4536 date = [[NSDate alloc] initWithString:[ NSString stringWithUTF8String:buffer ]]; 4726 date = [[NSDate alloc] initWithString:[ NSString stringWithUTF8String:buffer ]];
4537 [calendar setDateValue:date]; 4727 [calendar setDateValue:date];
4728 [date release];
4538 } 4729 }
4539 4730
4540 /* 4731 /*
4541 * Gets the position of a splitbar (pecentage). 4732 * Gets the position of a splitbar (pecentage).
4542 * Parameters: 4733 * Parameters:
4547 DWCalendar *calendar = handle; 4738 DWCalendar *calendar = handle;
4548 NSDate *date = [calendar dateValue]; 4739 NSDate *date = [calendar dateValue];
4549 NSDateFormatter *df = [[NSDateFormatter alloc] init]; 4740 NSDateFormatter *df = [[NSDateFormatter alloc] init];
4550 NSString *nstr = [df stringFromDate:date]; 4741 NSString *nstr = [df stringFromDate:date];
4551 sscanf([ nstr UTF8String ], "%d-%d-%d", year, month, day); 4742 sscanf([ nstr UTF8String ], "%d-%d-%d", year, month, day);
4743 [df release];
4552 } 4744 }
4553 4745
4554 /* 4746 /*
4555 * Causes the embedded HTML widget to take action. 4747 * Causes the embedded HTML widget to take action.
4556 * Parameters: 4748 * Parameters:
4622 * text: The default text to be in the entryfield widget. 4814 * text: The default text to be in the entryfield widget.
4623 * id: An ID to be used with dw_window_from_id() or 0L. 4815 * id: An ID to be used with dw_window_from_id() or 0L.
4624 */ 4816 */
4625 HWND API dw_html_new(unsigned long cid) 4817 HWND API dw_html_new(unsigned long cid)
4626 { 4818 {
4819 int _locked_by_me = FALSE;
4820 DW_MUTEX_LOCK;
4627 WebView *web = [[WebView alloc] init]; 4821 WebView *web = [[WebView alloc] init];
4628 /* [web setTag:cid]; Why doesn't this work? */ 4822 /* [web setTag:cid]; Why doesn't this work? */
4823 DW_MUTEX_UNLOCK;
4629 return web; 4824 return web;
4630 } 4825 }
4631 4826
4632 /* 4827 /*
4633 * Returns the current X and Y coordinates of the mouse pointer. 4828 * Returns the current X and Y coordinates of the mouse pointer.
4908 else 5103 else
4909 { 5104 {
4910 [notebook addTabViewItem:notepage]; 5105 [notebook addTabViewItem:notepage];
4911 } 5106 }
4912 [notebook setPageid:(page+1)]; 5107 [notebook setPageid:(page+1)];
5108 [notepage release];
4913 return (unsigned long)page; 5109 return (unsigned long)page;
4914 } 5110 }
4915 5111
4916 /* 5112 /*
4917 * Remove a page from a notebook. 5113 * Remove a page from a notebook.
5019 * title: The Window title. 5215 * title: The Window title.
5020 * flStyle: Style flags, see the PM reference. 5216 * flStyle: Style flags, see the PM reference.
5021 */ 5217 */
5022 HWND API dw_window_new(HWND hwndOwner, char *title, ULONG flStyle) 5218 HWND API dw_window_new(HWND hwndOwner, char *title, ULONG flStyle)
5023 { 5219 {
5220 int _locked_by_me = FALSE;
5221 DW_MUTEX_LOCK;
5024 NSRect frame = NSMakeRect(1,1,1,1); 5222 NSRect frame = NSMakeRect(1,1,1,1);
5025 NSWindow *window = [[NSWindow alloc] 5223 NSWindow *window = [[NSWindow alloc]
5026 initWithContentRect:frame 5224 initWithContentRect:frame
5027 styleMask:(flStyle | NSTexturedBackgroundWindowMask) 5225 styleMask:(flStyle | NSTexturedBackgroundWindowMask)
5028 backing:NSBackingStoreBuffered 5226 backing:NSBackingStoreBuffered
5034 5232
5035 [window setContentView:view]; 5233 [window setContentView:view];
5036 [window setDelegate:view]; 5234 [window setDelegate:view];
5037 [window makeKeyAndOrderFront:nil]; 5235 [window makeKeyAndOrderFront:nil];
5038 [window setAllowsConcurrentViewDrawing:NO]; 5236 [window setAllowsConcurrentViewDrawing:NO];
5237 [view release];
5039 5238
5040 /* If it isn't a toplevel window... */ 5239 /* If it isn't a toplevel window... */
5041 if(hwndOwner) 5240 if(hwndOwner)
5042 { 5241 {
5043 id object = hwndOwner; 5242 id object = hwndOwner;
5048 /* Set the window level to be floating */ 5247 /* Set the window level to be floating */
5049 [window setLevel:NSFloatingWindowLevel]; 5248 [window setLevel:NSFloatingWindowLevel];
5050 [window setHidesOnDeactivate:YES]; 5249 [window setHidesOnDeactivate:YES];
5051 } 5250 }
5052 } 5251 }
5053 5252 DW_MUTEX_UNLOCK;
5054 return (HWND)window; 5253 return (HWND)window;
5055 } 5254 }
5056 5255
5057 /* 5256 /*
5058 * Call a function from the window (widget)'s context. 5257 * Call a function from the window (widget)'s context.
5350 * Parameters: 5549 * Parameters:
5351 * handle: The window handle to destroy. 5550 * handle: The window handle to destroy.
5352 */ 5551 */
5353 int API dw_window_destroy(HWND handle) 5552 int API dw_window_destroy(HWND handle)
5354 { 5553 {
5554 int _locked_by_me = FALSE;
5555 DW_MUTEX_LOCK;
5355 NSObject *object = handle; 5556 NSObject *object = handle;
5356 5557
5357 if([ object isKindOfClass:[ NSWindow class ] ]) 5558 if([ object isKindOfClass:[ NSWindow class ] ])
5358 { 5559 {
5359 NSWindow *window = handle; 5560 NSWindow *window = handle;
5360 [window close]; 5561 [window close];
5361 } 5562 }
5563 DW_MUTEX_UNLOCK;
5362 return 0; 5564 return 0;
5363 } 5565 }
5364 5566
5365 /* 5567 /*
5366 * Gets the text used for a given window. 5568 * Gets the text used for a given window.
5396 * handle: Handle to the window. 5598 * handle: Handle to the window.
5397 * text: The text associsated with a given window. 5599 * text: The text associsated with a given window.
5398 */ 5600 */
5399 void API dw_window_set_text(HWND handle, char *text) 5601 void API dw_window_set_text(HWND handle, char *text)
5400 { 5602 {
5603 int _locked_by_me = FALSE;
5604 DW_MUTEX_LOCK;
5401 NSObject *object = handle; 5605 NSObject *object = handle;
5402 5606
5403 if([ object isKindOfClass:[ NSControl class ] ]) 5607 if([ object isKindOfClass:[ NSControl class ] ])
5404 { 5608 {
5405 NSControl *control = handle; 5609 NSControl *control = handle;
5408 else if([ object isKindOfClass:[ NSWindow class ] ]) 5612 else if([ object isKindOfClass:[ NSWindow class ] ])
5409 { 5613 {
5410 NSWindow *window = handle; 5614 NSWindow *window = handle;
5411 [window setTitle:[ NSString stringWithUTF8String:text ]]; 5615 [window setTitle:[ NSString stringWithUTF8String:text ]];
5412 } 5616 }
5617 DW_MUTEX_UNLOCK;
5413 } 5618 }
5414 5619
5415 /* 5620 /*
5416 * Disables given window (widget). 5621 * Disables given window (widget).
5417 * Parameters: 5622 * Parameters:
5463 5668
5464 if(pixmap) 5669 if(pixmap)
5465 { 5670 {
5466 [iv setImage:pixmap]; 5671 [iv setImage:pixmap];
5467 } 5672 }
5673 [pixmap release];
5468 } 5674 }
5469 } 5675 }
5470 5676
5471 /* 5677 /*
5472 * Sets the bitmap used for a given static window. 5678 * Sets the bitmap used for a given static window.
5584 * width: New width in pixels. 5790 * width: New width in pixels.
5585 * height: New height in pixels. 5791 * height: New height in pixels.
5586 */ 5792 */
5587 void API dw_window_set_size(HWND handle, ULONG width, ULONG height) 5793 void API dw_window_set_size(HWND handle, ULONG width, ULONG height)
5588 { 5794 {
5795 int _locked_by_me = FALSE;
5796 DW_MUTEX_LOCK;
5589 NSObject *object = handle; 5797 NSObject *object = handle;
5590 NSSize size; 5798 NSSize size;
5591 size.width = width; 5799 size.width = width;
5592 size.height = height; 5800 size.height = height;
5593 5801
5594 if([ object isKindOfClass:[ NSWindow class ] ]) 5802 if([ object isKindOfClass:[ NSWindow class ] ])
5595 { 5803 {
5596 NSWindow *window = handle; 5804 NSWindow *window = handle;
5597 [window setContentSize:size]; 5805 [window setContentSize:size];
5598 } 5806 }
5807 DW_MUTEX_UNLOCK;
5599 } 5808 }
5600 5809
5601 /* 5810 /*
5602 * Sets the position of a given window (widget). 5811 * Sets the position of a given window (widget).
5603 * Parameters: 5812 * Parameters:
5605 * x: X location from the bottom left. 5814 * x: X location from the bottom left.
5606 * y: Y location from the bottom left. 5815 * y: Y location from the bottom left.
5607 */ 5816 */
5608 void API dw_window_set_pos(HWND handle, LONG x, LONG y) 5817 void API dw_window_set_pos(HWND handle, LONG x, LONG y)
5609 { 5818 {
5819 int _locked_by_me = FALSE;
5820 DW_MUTEX_LOCK;
5610 NSObject *object = handle; 5821 NSObject *object = handle;
5611 NSPoint point; 5822 NSPoint point;
5612 point.x = x; 5823 point.x = x;
5613 point.y = y; 5824 point.y = y;
5614 5825
5615 if([ object isKindOfClass:[ NSWindow class ] ]) 5826 if([ object isKindOfClass:[ NSWindow class ] ])
5616 { 5827 {
5617 NSWindow *window = handle; 5828 NSWindow *window = handle;
5618 [window setFrameOrigin:point]; 5829 [window setFrameOrigin:point];
5619 } 5830 }
5831 DW_MUTEX_UNLOCK;
5620 } 5832 }
5621 5833
5622 /* 5834 /*
5623 * Sets the position and size of a given window (widget). 5835 * Sets the position and size of a given window (widget).
5624 * Parameters: 5836 * Parameters:
5755 void API dw_flush(void) 5967 void API dw_flush(void)
5756 { 5968 {
5757 /* This may need to be thread specific */ 5969 /* This may need to be thread specific */
5758 if(_DWLastDrawable) 5970 if(_DWLastDrawable)
5759 { 5971 {
5972 int _locked_by_me = FALSE;
5973 DW_MUTEX_LOCK;
5760 id object = _DWLastDrawable; 5974 id object = _DWLastDrawable;
5761 NSWindow *window = [object window]; 5975 NSWindow *window = [object window];
5762 [window flushWindow]; 5976 [window flushWindow];
5977 DW_MUTEX_UNLOCK;
5763 } 5978 }
5764 } 5979 }
5765 5980
5766 /* Functions for managing the user data lists that are associated with 5981 /* Functions for managing the user data lists that are associated with
5767 * a given window handle. Used in dw_window_set_data() and 5982 * a given window handle. Used in dw_window_set_data() and
6249 * Parameters: 6464 * Parameters:
6250 * mutex: The handle to the mutex returned by dw_mutex_new(). 6465 * mutex: The handle to the mutex returned by dw_mutex_new().
6251 */ 6466 */
6252 void dw_mutex_lock(HMTX mutex) 6467 void dw_mutex_lock(HMTX mutex)
6253 { 6468 {
6254 pthread_mutex_lock(mutex); 6469 DWTID saved = (DWTID)-1;
6470
6471 if(DWThread == pthread_self())
6472 {
6473 saved = DWThread;
6474 DWThread = (DWTID)-1;
6475 pthread_mutex_unlock(DWRunMutex);
6476 }
6477 pthread_mutex_lock(mutex);
6478 if(saved != (DWTID)-1)
6479 {
6480 DWThread = saved;
6481 pthread_mutex_lock(DWRunMutex);
6482 }
6255 } 6483 }
6256 6484
6257 /* 6485 /*
6258 * Reliquishes the access to the semaphore. 6486 * Reliquishes the access to the semaphore.
6259 * Parameters: 6487 * Parameters: