comparison mac/dw.m @ 657:f31a47b055f8

Work (unfinished) on container objects.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Thu, 24 Feb 2011 07:30:41 +0000
parents 6c8b95ca877b
children 0502e5b6743b
comparison
equal deleted inserted replaced
656:6c8b95ca877b 657:f31a47b055f8
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 19
20 unsigned long _colors[] =
21 {
22 0x00000000, /* 0 black */
23 0x00bb0000, /* 1 red */
24 0x0000bb00, /* 2 green */
25 0x00aaaa00, /* 3 yellow */
26 0x000000cc, /* 4 blue */
27 0x00bb00bb, /* 5 magenta */
28 0x0000bbbb, /* 6 cyan */
29 0x00bbbbbb, /* 7 white */
30 0x00777777, /* 8 grey */
31 0x00ff0000, /* 9 bright red */
32 0x0000ff00, /* 10 bright green */
33 0x00eeee00, /* 11 bright yellow */
34 0x000000ff, /* 12 bright blue */
35 0x00ff00ff, /* 13 bright magenta */
36 0x0000eeee, /* 14 bright cyan */
37 0x00ffffff, /* 15 bright white */
38 0xff000000 /* 16 default color */
39 };
40
41 unsigned long _get_color(unsigned long thiscolor)
42 {
43 if(thiscolor & DW_RGB_COLOR)
44 {
45 return thiscolor & ~DW_RGB_COLOR;
46 }
47 else if(thiscolor < 17)
48 {
49 return _colors[thiscolor];
50 }
51 return 0;
52 }
53
20 typedef struct _sighandler 54 typedef struct _sighandler
21 { 55 {
22 struct _sighandler *next; 56 struct _sighandler *next;
23 ULONG message; 57 ULONG message;
24 HWND window; 58 HWND window;
54 88
55 if(handler) 89 if(handler)
56 { 90 {
57 switch(message) 91 switch(message)
58 { 92 {
93 case 0:
94 {
95 int (* API timerfunc)(void *) = (int (* API)(void *))handler->signalfunction;
96
97 if(!timerfunc(handler->data))
98 dw_timer_disconnect(handler->id);
99 return 0;
100 }
59 case 3: 101 case 3:
60 case 4: 102 case 4:
61 { 103 {
62 int (* API buttonfunc)(HWND, int, int, int, void *) = (int (* API)(HWND, int, int, int, void *))handler->signalfunction; 104 int (* API buttonfunc)(HWND, int, int, int, void *) = (int (* API)(HWND, int, int, int, void *))handler->signalfunction;
63 int flags = [object pressedMouseButtons]; 105 int flags = [object pressedMouseButtons];
114 } 156 }
115 } 157 }
116 return -1; 158 return -1;
117 } 159 }
118 160
161 /* Subclass for the Timer type */
162 @interface DWTimerHandler : NSObject { }
163 -(void)runTimer:(id)sender;
164 @end
165
166 @implementation DWTimerHandler
167 -(void)runTimer:(id)sender { _event_handler(self, nil, 0); }
168 @end
169
119 NSApplication *DWApp; 170 NSApplication *DWApp;
120 NSRunLoop *DWRunLoop; 171 NSRunLoop *DWRunLoop;
121 NSMenu *DWMainMenu; 172 NSMenu *DWMainMenu;
173 DWTimerHandler *DWHandler;
122 #if !defined(GARBAGE_COLLECT) 174 #if !defined(GARBAGE_COLLECT)
123 NSAutoreleasePool *pool; 175 NSAutoreleasePool *pool;
124 #endif 176 #endif
125 177
126 /* So basically to implement our event handlers... 178 /* So basically to implement our event handlers...
144 -(void)setUserdata:(void *)input; 196 -(void)setUserdata:(void *)input;
145 -(void)drawRect:(NSRect)rect; 197 -(void)drawRect:(NSRect)rect;
146 -(BOOL)isFlipped; 198 -(BOOL)isFlipped;
147 -(void)mouseDown:(NSEvent *)theEvent; 199 -(void)mouseDown:(NSEvent *)theEvent;
148 -(void)mouseUp:(NSEvent *)theEvent; 200 -(void)mouseUp:(NSEvent *)theEvent;
201 -(void)setColor:(unsigned long)input;
149 @end 202 @end
150 203
151 @implementation DWBox 204 @implementation DWBox
152 -(Box)box { return box; } 205 -(Box)box { return box; }
153 -(void *)userdata { return userdata; } 206 -(void *)userdata { return userdata; }
162 } 215 }
163 } 216 }
164 -(BOOL)isFlipped { return YES; } 217 -(BOOL)isFlipped { return YES; }
165 -(void)mouseDown:(NSEvent *)theEvent { _event_handler(self, theEvent, 3); } 218 -(void)mouseDown:(NSEvent *)theEvent { _event_handler(self, theEvent, 3); }
166 -(void)mouseUp:(NSEvent *)theEvent { _event_handler(self, theEvent, 4); } 219 -(void)mouseUp:(NSEvent *)theEvent { _event_handler(self, theEvent, 4); }
220 -(void)setColor:(unsigned long)input
221 {
222 if(input == _colors[DW_CLR_DEFAULT])
223 {
224 bgcolor = nil;
225 }
226 else
227 {
228 bgcolor = [NSColor colorWithDeviceRed: DW_RED_VALUE(input)/255.0 green: DW_GREEN_VALUE(input)/255.0 blue: DW_BLUE_VALUE(input)/255.0 alpha: 1];
229 }
230 }
167 @end 231 @end
168 232
169 /* Subclass for a top-level window */ 233 /* Subclass for a top-level window */
170 @interface DWView : DWBox 234 @interface DWView : DWBox
171 { 235 {
201 } 265 }
202 -(void)windowDidBecomeMain:(id)sender 266 -(void)windowDidBecomeMain:(id)sender
203 { 267 {
204 if(windowmenu) 268 if(windowmenu)
205 { 269 {
206 NSLog(@"Setting local menu");
207 [DWApp setMainMenu:windowmenu]; 270 [DWApp setMainMenu:windowmenu];
208 } 271 }
209 else 272 else
210 { 273 {
211 NSLog(@"Setting global menu");
212 [DWApp setMainMenu:DWMainMenu]; 274 [DWApp setMainMenu:DWMainMenu];
213 } 275 }
214 276
215 } 277 }
216 -(void)setMenu:(NSMenu *)input { windowmenu = input; NSLog(@"Setting window menu"); } 278 -(void)setMenu:(NSMenu *)input { windowmenu = input; }
217 -(void)menuHandler:(id)sender { _event_handler(sender, nil, 8); } 279 -(void)menuHandler:(id)sender { _event_handler(sender, nil, 8); }
218 @end 280 @end
219 281
220 /* Subclass for a button type */ 282 /* Subclass for a button type */
221 @interface DWButton : NSButton 283 @interface DWButton : NSButton
437 499
438 /* Subclass for a Container/List type */ 500 /* Subclass for a Container/List type */
439 @interface DWContainer : NSTableView 501 @interface DWContainer : NSTableView
440 { 502 {
441 void *userdata; 503 void *userdata;
504 NSMutableArray *tvcols;
505 NSMutableArray *data;
506 NSMutableArray *types;
442 } 507 }
443 -(void *)userdata; 508 -(void *)userdata;
444 -(void)setUserdata:(void *)input; 509 -(void)setUserdata:(void *)input;
510 -(id)tableView:(NSTableView *)aTable objectValueForColumn:(NSTableColumn *)aCol row:(int)aRow;
511 -(int)numberOfRowsInTableView:(NSTableView *)aTable;
512 -(void)addColumn:(NSTableColumn *)input andType:(int)type;
513 -(void)addRow:(NSArray *)input;
514 -(void)addRows:(int)number;
515 -(void)editCell:(id)input at:(int)row and:(int)col;
516 -(int)cellType:(int)col;
517 -(void)clear;
518 -(void)setup;
445 @end 519 @end
446 520
447 @implementation DWContainer 521 @implementation DWContainer
448 -(void *)userdata { return userdata; } 522 -(void *)userdata { return userdata; }
449 -(void)setUserdata:(void *)input { userdata = input; } 523 -(void)setUserdata:(void *)input { userdata = input; }
524 -(id)tableView:(NSTableView *)aTable objectValueForColumn:(NSTableColumn *)aCol row:(int)aRow
525 {
526 if(tvcols)
527 {
528 int z, col = -1;
529 int count = [tvcols count];
530
531 for(z=0;z<count;z++)
532 {
533 if([tvcols objectAtIndex:z] == aCol)
534 {
535 col = z;
536 break;
537 }
538 }
539 if(col != -1)
540 {
541 int index = (aRow * count) + col;
542 return [data objectAtIndex:index];
543 }
544 }
545 return nil;
546 }
547 -(int)numberOfRowsInTableView:(NSTableView *)aTable
548 {
549 if(tvcols && data)
550 {
551 int cols = [tvcols count];
552 if(cols)
553 {
554 return [data count] / cols;
555 }
556 }
557 return 0;
558 }
559 -(void)addColumn:(NSTableColumn *)input andType:(int)type { if(tvcols) { [tvcols addObject:input]; [types addObject:[NSNumber numberWithInt:type]]; } }
560 -(void)addRow:(NSArray *)input { if(data) { [data addObjectsFromArray:input]; } }
561 -(void)addRows:(int)number
562 {
563 if(tvcols)
564 {
565 int count = number * [tvcols count];
566 int z;
567
568 for(z=0;z<count;z++)
569 {
570 [data addObject:[NSNull null]];
571 }
572 }
573 }
574 -(void)editCell:(id)input at:(int)row and:(int)col
575 {
576 if(tvcols && input)
577 {
578 int index = (row * [tvcols count]) + col;
579 [data replaceObjectAtIndex:index withObject:input];
580 }
581 }
582 -(int)cellType:(int)col { return [[types objectAtIndex:col] intValue]; }
583 -(void)clear { if(data) { [data removeAllObjects]; } }
584 -(void)setup { tvcols = [[NSMutableArray alloc] init]; data = [[NSMutableArray alloc] init]; types = [[NSMutableArray alloc] init]; }
450 @end 585 @end
451 586
452 /* Subclass for a Calendar type */ 587 /* Subclass for a Calendar type */
453 @interface DWCalendar : NSDatePicker 588 @interface DWCalendar : NSDatePicker
454 { 589 {
1093 { 1228 {
1094 /* Create the application object */ 1229 /* Create the application object */
1095 DWApp = [NSApplication sharedApplication]; 1230 DWApp = [NSApplication sharedApplication];
1096 /* Create a run loop for doing manual loops */ 1231 /* Create a run loop for doing manual loops */
1097 DWRunLoop = [NSRunLoop alloc]; 1232 DWRunLoop = [NSRunLoop alloc];
1233 /* Create object for handling timers */
1234 DWHandler = [[DWTimerHandler alloc] init];
1098 #if !defined(GARBAGE_COLLECT) 1235 #if !defined(GARBAGE_COLLECT)
1099 pool = [[NSAutoreleasePool alloc] init]; 1236 pool = [[NSAutoreleasePool alloc] init];
1100 #endif 1237 #endif
1101 DWMainMenu = _generate_main_menu(); 1238 DWMainMenu = _generate_main_menu();
1102 [DWApp setMainMenu:DWMainMenu]; 1239 [DWApp setMainMenu:DWMainMenu];
2083 2220
2084 if([object isMemberOfClass:[DWComboBox class]]) 2221 if([object isMemberOfClass:[DWComboBox class]])
2085 { 2222 {
2086 DWComboBox *combo = handle; 2223 DWComboBox *combo = handle;
2087 2224
2088 [combo removeItemAtIndex:pos]; 2225 [combo removeItemAtIndex:index];
2089 [combo insertItemWithObjectValue:[ NSString stringWithUTF8String:bufer ] atIndex:pos]; 2226 [combo insertItemWithObjectValue:[ NSString stringWithUTF8String:buffer ] atIndex:index];
2090 } 2227 }
2091 } 2228 }
2092 2229
2093 /* 2230 /*
2094 * Returns the index to the item in the list currently selected. 2231 * Returns the index to the item in the list currently selected.
2379 * green: green value. 2516 * green: green value.
2380 * blue: blue value. 2517 * blue: blue value.
2381 */ 2518 */
2382 void API dw_color_foreground_set(unsigned long value) 2519 void API dw_color_foreground_set(unsigned long value)
2383 { 2520 {
2384 _foreground = value; 2521 _foreground = _get_color(value);
2385 } 2522 }
2386 2523
2387 /* Sets the current background drawing color. 2524 /* Sets the current background drawing color.
2388 * Parameters: 2525 * Parameters:
2389 * red: red value. 2526 * red: red value.
2390 * green: green value. 2527 * green: green value.
2391 * blue: blue value. 2528 * blue: blue value.
2392 */ 2529 */
2393 void API dw_color_background_set(unsigned long value) 2530 void API dw_color_background_set(unsigned long value)
2394 { 2531 {
2395 _background = value; 2532 _background = _get_color(value);
2396 } 2533 }
2397 2534
2398 /* Allows the user to choose a color using the system's color chooser dialog. 2535 /* Allows the user to choose a color using the system's color chooser dialog.
2399 * Parameters: 2536 * Parameters:
2400 * value: current color 2537 * value: current color
2424 * x: X coordinate. 2561 * x: X coordinate.
2425 * y: Y coordinate. 2562 * y: Y coordinate.
2426 */ 2563 */
2427 void API dw_draw_point(HWND handle, HPIXMAP pixmap, int x, int y) 2564 void API dw_draw_point(HWND handle, HPIXMAP pixmap, int x, int y)
2428 { 2565 {
2566 id image = handle;
2567 if(pixmap)
2568 {
2569 image = (id)pixmap;
2570 }
2571 [image lockFocus];
2429 NSRect rect = NSMakeRect(x, y, x, y); 2572 NSRect rect = NSMakeRect(x, y, x, y);
2430 [[NSColor colorWithDeviceRed: DW_RED_VALUE(_foreground)/255.0 green: DW_GREEN_VALUE(_foreground)/255.0 blue: DW_BLUE_VALUE(_foreground)/255.0 alpha: 1] set]; 2573 [[NSColor colorWithDeviceRed: DW_RED_VALUE(_foreground)/255.0 green: DW_GREEN_VALUE(_foreground)/255.0 blue: DW_BLUE_VALUE(_foreground)/255.0 alpha: 1] set];
2431 NSRectFill(rect); 2574 NSRectFill(rect);
2575 [image unlockFocus];
2432 } 2576 }
2433 2577
2434 /* Draw a line on a window (preferably a render window). 2578 /* Draw a line on a window (preferably a render window).
2435 * Parameters: 2579 * Parameters:
2436 * handle: Handle to the window. 2580 * handle: Handle to the window.
2440 * x2: Second X coordinate. 2584 * x2: Second X coordinate.
2441 * y2: Second Y coordinate. 2585 * y2: Second Y coordinate.
2442 */ 2586 */
2443 void API dw_draw_line(HWND handle, HPIXMAP pixmap, int x1, int y1, int x2, int y2) 2587 void API dw_draw_line(HWND handle, HPIXMAP pixmap, int x1, int y1, int x2, int y2)
2444 { 2588 {
2445 NSLog(@"dw_draw_line() unimplemented\n"); 2589 id image = handle;
2590 if(pixmap)
2591 {
2592 image = (id)pixmap;
2593 }
2594 [image lockFocus];
2595 NSBezierPath* aPath = [NSBezierPath bezierPath];
2596
2597 [aPath moveToPoint:NSMakePoint(x1, y1)];
2598 [aPath lineToPoint:NSMakePoint(x2, y2)];
2599
2600 [image unlockFocus];
2446 } 2601 }
2447 2602
2448 /* Draw text on a window (preferably a render window). 2603 /* Draw text on a window (preferably a render window).
2449 * Parameters: 2604 * Parameters:
2450 * handle: Handle to the window. 2605 * handle: Handle to the window.
2453 * y: Y coordinate. 2608 * y: Y coordinate.
2454 * text: Text to be displayed. 2609 * text: Text to be displayed.
2455 */ 2610 */
2456 void API dw_draw_text(HWND handle, HPIXMAP pixmap, int x, int y, char *text) 2611 void API dw_draw_text(HWND handle, HPIXMAP pixmap, int x, int y, char *text)
2457 { 2612 {
2458 NSLog(@"dw_draw_line() unimplemented\n"); 2613 id image = handle;
2614 NSString *nstr = [ NSString stringWithUTF8String:text ];
2615 if(image)
2616 {
2617 if([image isMemberOfClass:[NSView class]])
2618 {
2619 [image lockFocus];
2620 NSDictionary *dict = [[NSDictionary alloc] init];
2621 [nstr drawAtPoint:NSMakePoint(x, y) withAttributes:dict];
2622 [image unlockFocus];
2623 }
2624 }
2625 if(pixmap)
2626 {
2627 image = (id)pixmap;
2628 /* TODO: Figure out how to write here */
2629 }
2459 } 2630 }
2460 2631
2461 /* Query the width and height of a text string. 2632 /* Query the width and height of a text string.
2462 * Parameters: 2633 * Parameters:
2463 * handle: Handle to the window. 2634 * handle: Handle to the window.
2466 * width: Pointer to a variable to be filled in with the width. 2637 * width: Pointer to a variable to be filled in with the width.
2467 * height Pointer to a variable to be filled in with the height. 2638 * height Pointer to a variable to be filled in with the height.
2468 */ 2639 */
2469 void API dw_font_text_extents_get(HWND handle, HPIXMAP pixmap, char *text, int *width, int *height) 2640 void API dw_font_text_extents_get(HWND handle, HPIXMAP pixmap, char *text, int *width, int *height)
2470 { 2641 {
2642 id image = handle;
2643 if(pixmap)
2644 {
2645 image = (id)pixmap;
2646 }
2471 NSLog(@"dw_font_text_extents_get() unimplemented\n"); 2647 NSLog(@"dw_font_text_extents_get() unimplemented\n");
2472 } 2648 }
2473 2649
2474 /* Draw a polygon on a window (preferably a render window). 2650 /* Draw a polygon on a window (preferably a render window).
2475 * Parameters: 2651 * Parameters:
2481 * width: Width of rectangle. 2657 * width: Width of rectangle.
2482 * height: Height of rectangle. 2658 * height: Height of rectangle.
2483 */ 2659 */
2484 void API dw_draw_polygon( HWND handle, HPIXMAP pixmap, int fill, int npoints, int *x, int *y ) 2660 void API dw_draw_polygon( HWND handle, HPIXMAP pixmap, int fill, int npoints, int *x, int *y )
2485 { 2661 {
2486 NSLog(@"dw_draw_polygon() unimplemented\n"); 2662 id image = handle;
2663 int z;
2664 if(pixmap)
2665 {
2666 image = (id)pixmap;
2667 }
2668 [image lockFocus];
2669 NSBezierPath* aPath = [NSBezierPath bezierPath];
2670
2671 [aPath moveToPoint:NSMakePoint(*x, *y)];
2672 for(z=1;z<npoints;z++)
2673 {
2674 [aPath lineToPoint:NSMakePoint(x[z], y[z])];
2675 }
2676 [aPath closePath];
2677 if(fill)
2678 {
2679 [aPath fill];
2680 }
2681 [image unlockFocus];
2487 } 2682 }
2488 2683
2489 /* Draw a rectangle on a window (preferably a render window). 2684 /* Draw a rectangle on a window (preferably a render window).
2490 * Parameters: 2685 * Parameters:
2491 * handle: Handle to the window. 2686 * handle: Handle to the window.
2496 * width: Width of rectangle. 2691 * width: Width of rectangle.
2497 * height: Height of rectangle. 2692 * height: Height of rectangle.
2498 */ 2693 */
2499 void API dw_draw_rect(HWND handle, HPIXMAP pixmap, int fill, int x, int y, int width, int height) 2694 void API dw_draw_rect(HWND handle, HPIXMAP pixmap, int fill, int x, int y, int width, int height)
2500 { 2695 {
2696 id image = handle;
2697 if(pixmap)
2698 {
2699 image = (id)pixmap;
2700 }
2701 [image lockFocus];
2501 NSRect rect = NSMakeRect(x, y, x + width, y + height); 2702 NSRect rect = NSMakeRect(x, y, x + width, y + height);
2502 [[NSColor colorWithDeviceRed: DW_RED_VALUE(_foreground)/255.0 green: DW_GREEN_VALUE(_foreground)/255.0 blue: DW_BLUE_VALUE(_foreground)/255.0 alpha: 1] set]; 2703 [[NSColor colorWithDeviceRed: DW_RED_VALUE(_foreground)/255.0 green: DW_GREEN_VALUE(_foreground)/255.0 blue: DW_BLUE_VALUE(_foreground)/255.0 alpha: 1] set];
2503 NSRectFill(rect); 2704 NSRectFill(rect);
2705 [image unlockFocus];
2504 } 2706 }
2505 2707
2506 /* 2708 /*
2507 * Create a tree object to be packed. 2709 * Create a tree object to be packed.
2508 * Parameters: 2710 * Parameters:
2676 } 2878 }
2677 else 2879 else
2678 { 2880 {
2679 [cont setAllowsMultipleSelection:NO]; 2881 [cont setAllowsMultipleSelection:NO];
2680 } 2882 }
2883 [cont setDataSource:cont];
2681 return cont; 2884 return cont;
2682 } 2885 }
2683 2886
2684 /* 2887 /*
2685 * Sets up the container columns. 2888 * Sets up the container columns.
2694 int API dw_container_setup(HWND handle, unsigned long *flags, char **titles, int count, int separator) 2897 int API dw_container_setup(HWND handle, unsigned long *flags, char **titles, int count, int separator)
2695 { 2898 {
2696 int z; 2899 int z;
2697 DWContainer *cont = handle; 2900 DWContainer *cont = handle;
2698 2901
2902 [cont setup];
2903
2699 for(z=0;z<count;z++) 2904 for(z=0;z<count;z++)
2700 { 2905 {
2701 NSTableColumn *column = [[NSTableColumn alloc] init]; 2906 NSTableColumn *column = [[NSTableColumn alloc] init];
2702 [[column headerCell] setStringValue:[ NSString stringWithUTF8String:titles[z] ]]; 2907 [[column headerCell] setStringValue:[ NSString stringWithUTF8String:titles[z] ]];
2703 [cont addTableColumn:column]; 2908 [cont addTableColumn:column];
2704 } 2909 [cont addColumn:column andType:flags[z]];
2910 }
2911
2705 return TRUE; 2912 return TRUE;
2706 } 2913 }
2707 2914
2708 /* 2915 /*
2709 * Sets up the filesystem columns, note: filesystem always has an icon/filename field. 2916 * Sets up the filesystem columns, note: filesystem always has an icon/filename field.
2713 * titles: An array of strings with column text titles. 2920 * titles: An array of strings with column text titles.
2714 * count: The number of columns (this should match the arrays). 2921 * count: The number of columns (this should match the arrays).
2715 */ 2922 */
2716 int API dw_filesystem_setup(HWND handle, unsigned long *flags, char **titles, int count) 2923 int API dw_filesystem_setup(HWND handle, unsigned long *flags, char **titles, int count)
2717 { 2924 {
2718 char **newtitles = malloc(sizeof(char *) * (count + 1)); 2925 char **newtitles = malloc(sizeof(char *) * (count + 2));
2719 unsigned long *newflags = malloc(sizeof(unsigned long) * (count + 1)); 2926 unsigned long *newflags = malloc(sizeof(unsigned long) * (count + 2));
2720 2927
2721 newtitles[0] = "Filename"; 2928 newtitles[0] = "Icon";
2722 2929 newtitles[1] = "Filename";
2723 newflags[0] = DW_CFA_STRINGANDICON | DW_CFA_LEFT | DW_CFA_HORZSEPARATOR; 2930
2724 2931 newflags[0] = DW_CFA_BITMAPORICON | DW_CFA_LEFT | DW_CFA_HORZSEPARATOR;
2725 memcpy(&newtitles[1], titles, sizeof(char *) * count); 2932 newflags[1] = DW_CFA_STRING | DW_CFA_LEFT | DW_CFA_HORZSEPARATOR;
2726 memcpy(&newflags[1], flags, sizeof(unsigned long) * count); 2933
2727 2934 memcpy(&newtitles[2], titles, sizeof(char *) * count);
2728 dw_container_setup(handle, newflags, newtitles, count + 1, 0); 2935 memcpy(&newflags[2], flags, sizeof(unsigned long) * count);
2936
2937 dw_container_setup(handle, newflags, newtitles, count + 2, 0);
2729 2938
2730 free(newtitles); 2939 free(newtitles);
2731 free(newflags); 2940 free(newflags);
2732 return TRUE; 2941 return TRUE;
2733 } 2942 }
2738 * handle: Handle to the container window (widget). 2947 * handle: Handle to the container window (widget).
2739 * rowcount: The number of items to be populated. 2948 * rowcount: The number of items to be populated.
2740 */ 2949 */
2741 void * API dw_container_alloc(HWND handle, int rowcount) 2950 void * API dw_container_alloc(HWND handle, int rowcount)
2742 { 2951 {
2743 NSLog(@"dw_container_alloc() unimplemented\n"); 2952 DWContainer *cont = handle;
2744 return NULL; 2953 [cont addRows:rowcount];
2954 return cont;
2745 } 2955 }
2746 2956
2747 /* 2957 /*
2748 * Sets an item in specified row and column to the given data. 2958 * Sets an item in specified row and column to the given data.
2749 * Parameters: 2959 * Parameters:
2753 * row: Zero based row of data being set. 2963 * row: Zero based row of data being set.
2754 * data: Pointer to the data to be added. 2964 * data: Pointer to the data to be added.
2755 */ 2965 */
2756 void API dw_container_set_item(HWND handle, void *pointer, int column, int row, void *data) 2966 void API dw_container_set_item(HWND handle, void *pointer, int column, int row, void *data)
2757 { 2967 {
2758 NSLog(@"dw_container_set_item() unimplemented\n"); 2968 DWContainer *cont = handle;
2969 id object = nil;
2970 int type = [cont cellType:column];
2971
2972 if(type & DW_CFA_BITMAPORICON)
2973 {
2974 /* TODO: Handle image here */
2975 }
2976 else if(type & DW_CFA_STRING)
2977 {
2978 object = [ NSString stringWithUTF8String:data ];
2979 }
2980 else
2981 {
2982 char textbuffer[100];
2983
2984 if(type & DW_CFA_ULONG)
2985 {
2986 ULONG tmp = *((ULONG *)data);
2987
2988 sprintf(textbuffer, "%lu", tmp);
2989 }
2990 else if(type & DW_CFA_DATE)
2991 {
2992 struct tm curtm;
2993 CDATE cdate = *((CDATE *)data);
2994
2995 memset( &curtm, 0, sizeof(curtm) );
2996 curtm.tm_mday = cdate.day;
2997 curtm.tm_mon = cdate.month - 1;
2998 curtm.tm_year = cdate.year - 1900;
2999
3000 strftime(textbuffer, 100, "%x", &curtm);
3001 }
3002 else if(type & DW_CFA_TIME)
3003 {
3004 struct tm curtm;
3005 CTIME ctime = *((CTIME *)data);
3006
3007 memset( &curtm, 0, sizeof(curtm) );
3008 curtm.tm_hour = ctime.hours;
3009 curtm.tm_min = ctime.minutes;
3010 curtm.tm_sec = ctime.seconds;
3011
3012 strftime(textbuffer, 100, "%X", &curtm);
3013 }
3014 else
3015 {
3016 return;
3017 }
3018 object = [ NSString stringWithUTF8String:textbuffer ];
3019 }
3020
3021 [cont editCell:object at:row and:column];
2759 } 3022 }
2760 3023
2761 /* 3024 /*
2762 * Changes an existing item in specified row and column to the given data. 3025 * Changes an existing item in specified row and column to the given data.
2763 * Parameters: 3026 * Parameters:
2766 * row: Zero based row of data being set. 3029 * row: Zero based row of data being set.
2767 * data: Pointer to the data to be added. 3030 * data: Pointer to the data to be added.
2768 */ 3031 */
2769 void API dw_container_change_item(HWND handle, int column, int row, void *data) 3032 void API dw_container_change_item(HWND handle, int column, int row, void *data)
2770 { 3033 {
2771 NSLog(@"dw_container_change_item() unimplemented\n"); 3034 dw_container_set_item(handle, NULL, column, row, data);
2772 } 3035 }
2773 3036
2774 /* 3037 /*
2775 * Changes an existing item in specified row and column to the given data. 3038 * Changes an existing item in specified row and column to the given data.
2776 * Parameters: 3039 * Parameters:
2779 * row: Zero based row of data being set. 3042 * row: Zero based row of data being set.
2780 * data: Pointer to the data to be added. 3043 * data: Pointer to the data to be added.
2781 */ 3044 */
2782 void API dw_filesystem_change_item(HWND handle, int column, int row, void *data) 3045 void API dw_filesystem_change_item(HWND handle, int column, int row, void *data)
2783 { 3046 {
2784 NSLog(@"dw_filesystem_change_item() unimplemented\n"); 3047 dw_container_change_item(handle, column+2, row, data);
2785 } 3048 }
2786 3049
2787 /* 3050 /*
2788 * Changes an item in specified row and column to the given data. 3051 * Changes an item in specified row and column to the given data.
2789 * Parameters: 3052 * Parameters:
2793 * row: Zero based row of data being set. 3056 * row: Zero based row of data being set.
2794 * data: Pointer to the data to be added. 3057 * data: Pointer to the data to be added.
2795 */ 3058 */
2796 void API dw_filesystem_change_file(HWND handle, int row, char *filename, unsigned long icon) 3059 void API dw_filesystem_change_file(HWND handle, int row, char *filename, unsigned long icon)
2797 { 3060 {
2798 NSLog(@"dw_filesystem_change_file() unimplemented\n"); 3061 dw_container_change_item(handle, 0, row, filename);
2799 } 3062 }
2800 3063
2801 /* 3064 /*
2802 * Sets an item in specified row and column to the given data. 3065 * Sets an item in specified row and column to the given data.
2803 * Parameters: 3066 * Parameters:
2807 * row: Zero based row of data being set. 3070 * row: Zero based row of data being set.
2808 * data: Pointer to the data to be added. 3071 * data: Pointer to the data to be added.
2809 */ 3072 */
2810 void API dw_filesystem_set_file(HWND handle, void *pointer, int row, char *filename, unsigned long icon) 3073 void API dw_filesystem_set_file(HWND handle, void *pointer, int row, char *filename, unsigned long icon)
2811 { 3074 {
2812 NSLog(@"dw_filesystem_set_file() unimplemented\n"); 3075 dw_container_set_item(handle, pointer, 0, row, filename);
2813 } 3076 }
2814 3077
2815 /* 3078 /*
2816 * Sets an item in specified row and column to the given data. 3079 * Sets an item in specified row and column to the given data.
2817 * Parameters: 3080 * Parameters:
2821 * row: Zero based row of data being set. 3084 * row: Zero based row of data being set.
2822 * data: Pointer to the data to be added. 3085 * data: Pointer to the data to be added.
2823 */ 3086 */
2824 void API dw_filesystem_set_item(HWND handle, void *pointer, int column, int row, void *data) 3087 void API dw_filesystem_set_item(HWND handle, void *pointer, int column, int row, void *data)
2825 { 3088 {
2826 NSLog(@"dw_filesystem_set_item() unimplemented\n"); 3089 dw_container_set_item(handle, pointer, column+2, row, data);
2827 } 3090 }
2828 3091
2829 /* 3092 /*
2830 * Gets column type for a container column 3093 * Gets column type for a container column
2831 * Parameters: 3094 * Parameters:
2832 * handle: Handle to the container window (widget). 3095 * handle: Handle to the container window (widget).
2833 * column: Zero based column. 3096 * column: Zero based column.
2834 */ 3097 */
2835 int API dw_container_get_column_type(HWND handle, int column) 3098 int API dw_container_get_column_type(HWND handle, int column)
2836 { 3099 {
2837 NSLog(@"dw_container_get_column_type() unimplemented\n"); 3100 DWContainer *cont = handle;
2838 return 0; 3101 return [cont cellType:column];
2839 } 3102 }
2840 3103
2841 /* 3104 /*
2842 * Gets column type for a filesystem container column 3105 * Gets column type for a filesystem container column
2843 * Parameters: 3106 * Parameters:
2844 * handle: Handle to the container window (widget). 3107 * handle: Handle to the container window (widget).
2845 * column: Zero based column. 3108 * column: Zero based column.
2846 */ 3109 */
2847 int API dw_filesystem_get_column_type(HWND handle, int column) 3110 int API dw_filesystem_get_column_type(HWND handle, int column)
2848 { 3111 {
2849 NSLog(@"dw_filesystem_get_column_type() unimplemented\n"); 3112 DWContainer *cont = handle;
2850 return 0; 3113 return [cont cellType:column+2];
2851 } 3114 }
2852 3115
2853 /* 3116 /*
2854 * Sets the width of a column in the container. 3117 * Sets the width of a column in the container.
2855 * Parameters: 3118 * Parameters:
2892 * handle: Handle to the window (widget) to be cleared. 3155 * handle: Handle to the window (widget) to be cleared.
2893 * redraw: TRUE to cause the container to redraw immediately. 3156 * redraw: TRUE to cause the container to redraw immediately.
2894 */ 3157 */
2895 void API dw_container_clear(HWND handle, int redraw) 3158 void API dw_container_clear(HWND handle, int redraw)
2896 { 3159 {
2897 NSLog(@"dw_container_clear() unimplemented\n"); 3160 DWContainer *cont = handle;
3161 return [cont clear];
2898 } 3162 }
2899 3163
2900 /* 3164 /*
2901 * Removes the first x rows from a container. 3165 * Removes the first x rows from a container.
2902 * Parameters: 3166 * Parameters:
3219 * xsrc: X coordinate of source. 3483 * xsrc: X coordinate of source.
3220 * ysrc: Y coordinate of source. 3484 * ysrc: Y coordinate of source.
3221 */ 3485 */
3222 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) 3486 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)
3223 { 3487 {
3488 id bltdest = dest;
3489 id bltsrc = src;
3490 if(destp)
3491 {
3492 bltdest = (id)destp;
3493 }
3494 if(srcp)
3495 {
3496 bltsrc = (id)srcp;
3497 }
3498 [bltdest lockFocus];
3224 NSLog(@"dw_pixmap_bitblt() unimplemented\n"); 3499 NSLog(@"dw_pixmap_bitblt() unimplemented\n");
3500 [bltdest unlockFocus];
3225 } 3501 }
3226 3502
3227 /* 3503 /*
3228 * Create a new static text window (widget) to be packed. 3504 * Create a new static text window (widget) to be packed.
3229 * Not available under OS/2, eCS 3505 * Not available under OS/2, eCS
3373 * x: X coordinate. 3649 * x: X coordinate.
3374 * y: Y coordinate. 3650 * y: Y coordinate.
3375 */ 3651 */
3376 void API dw_pointer_set_pos(long x, long y) 3652 void API dw_pointer_set_pos(long x, long y)
3377 { 3653 {
3378 NSLog(@"dw_pointer_set_pos() unimplemented\n"); 3654 /* From what I have read this isn't possible, agaist human interface rules */
3379 } 3655 }
3380 3656
3381 /* 3657 /*
3382 * Create a menu object to be popped up. 3658 * Create a menu object to be popped up.
3383 * Parameters: 3659 * Parameters:
3821 * back: Background color in DW_RGB format or a default color index. 4097 * back: Background color in DW_RGB format or a default color index.
3822 */ 4098 */
3823 int API dw_window_set_color(HWND handle, ULONG fore, ULONG back) 4099 int API dw_window_set_color(HWND handle, ULONG fore, ULONG back)
3824 { 4100 {
3825 id object = handle; 4101 id object = handle;
4102 unsigned long _fore = _get_color(fore);
4103 unsigned long _back = _get_color(back);
3826 4104
3827 if([object isMemberOfClass:[NSTextFieldCell class]]) 4105 if([object isMemberOfClass:[NSTextFieldCell class]])
3828 { 4106 {
3829 NSTextFieldCell *text = object; 4107 NSTextFieldCell *text = object;
3830 [text setTextColor:[NSColor colorWithDeviceRed: DW_RED_VALUE(_foreground)/255.0 green: DW_GREEN_VALUE(_foreground)/255.0 blue: DW_BLUE_VALUE(_foreground)/255.0 alpha: 1]]; 4108 [text setTextColor:[NSColor colorWithDeviceRed: DW_RED_VALUE(_fore)/255.0 green: DW_GREEN_VALUE(_fore)/255.0 blue: DW_BLUE_VALUE(_fore)/255.0 alpha: 1]];
4109 }
4110 else if([object isMemberOfClass:[DWBox class]])
4111 {
4112 DWBox *box = object;
4113
4114 [box setColor:_back];
3831 } 4115 }
3832 return 0; 4116 return 0;
3833 } 4117 }
3834 4118
3835 /* 4119 /*
3936 * handle: The window (widget) handle. 4220 * handle: The window (widget) handle.
3937 * fontname: Name and size of the font in the form "size.fontname" 4221 * fontname: Name and size of the font in the form "size.fontname"
3938 */ 4222 */
3939 int API dw_window_set_font(HWND handle, char *fontname) 4223 int API dw_window_set_font(HWND handle, char *fontname)
3940 { 4224 {
3941 NSLog(@"dw_window_set_font() unimplemented\n"); 4225 char *fontcopy = strdup(fontname);
4226 char *name = strchr(fontcopy, '.');
4227 if(name)
4228 {
4229 int size = atoi(fontcopy);
4230 *name = 0;
4231 name++;
4232 NSFont *font = [NSFont fontWithName:[ NSString stringWithUTF8String:name ] size:(float)size];
4233 id object = handle;
4234 [object lockFocus];
4235 [font set];
4236 [object unlockFocus];
4237 }
4238 free(fontcopy);
3942 return 0; 4239 return 0;
3943 } 4240 }
3944 4241
3945 /* 4242 /*
3946 * Destroys a window and all of it's children. 4243 * Destroys a window and all of it's children.
4049 * Windows and a pixmap on Unix, pass 4346 * Windows and a pixmap on Unix, pass
4050 * NULL if you use the id param) 4347 * NULL if you use the id param)
4051 */ 4348 */
4052 void API dw_window_set_bitmap_from_data(HWND handle, unsigned long id, char *data, int len) 4349 void API dw_window_set_bitmap_from_data(HWND handle, unsigned long id, char *data, int len)
4053 { 4350 {
4054 NSLog(@"dw_window_set_bitmap_from_data() unimplemented\n"); 4351 NSObject *object = handle;
4352 if([ object isKindOfClass:[ NSImageView class ] ])
4353 {
4354 NSImageView *iv = handle;
4355 NSData *thisdata = [[NSData alloc] dataWithBytes:data length:len];
4356 NSImage *pixmap = [[NSImage alloc] initWithData:thisdata];
4357
4358 [iv setImage:pixmap];
4359 }
4055 } 4360 }
4056 4361
4057 /* 4362 /*
4058 * Sets the bitmap used for a given static window. 4363 * Sets the bitmap used for a given static window.
4059 * Parameters: 4364 * Parameters:
4064 * Windows and a pixmap on Unix, pass 4369 * Windows and a pixmap on Unix, pass
4065 * NULL if you use the id param) 4370 * NULL if you use the id param)
4066 */ 4371 */
4067 void API dw_window_set_bitmap(HWND handle, unsigned long id, char *filename) 4372 void API dw_window_set_bitmap(HWND handle, unsigned long id, char *filename)
4068 { 4373 {
4069 NSLog(@"dw_window_set_bitmap() unimplemented\n"); 4374 NSObject *object = handle;
4375 if([ object isKindOfClass:[ NSImageView class ] ])
4376 {
4377 NSImageView *iv = handle;
4378 NSImage *pixmap = [[NSImage alloc] initWithContentsOfFile:[ NSString stringWithUTF8String:filename ]];
4379
4380 [iv setImage:pixmap];
4381 }
4070 } 4382 }
4071 4383
4072 /* 4384 /*
4073 * Sets the icon used for a given window. 4385 * Sets the icon used for a given window.
4074 * Parameters: 4386 * Parameters:
4265 struct utsname name; 4577 struct utsname name;
4266 char tempbuf[100]; 4578 char tempbuf[100];
4267 int len, z; 4579 int len, z;
4268 4580
4269 uname(&name); 4581 uname(&name);
4270 strcpy(env->osName, name.sysname); 4582 strcpy(env->osName, "MacOS");
4271 strcpy(tempbuf, name.release); 4583 strcpy(tempbuf, name.release);
4272 4584
4273 env->MajorBuild = env->MinorBuild = 0; 4585 env->MajorBuild = env->MinorBuild = 0;
4274 4586
4275 len = strlen(tempbuf); 4587 len = strlen(tempbuf);
4282 4594
4283 for(z=1;z<len;z++) 4595 for(z=1;z<len;z++)
4284 { 4596 {
4285 if(tempbuf[z] == '.') 4597 if(tempbuf[z] == '.')
4286 { 4598 {
4599 int ver = atoi(tempbuf);
4287 tempbuf[z] = '\0'; 4600 tempbuf[z] = '\0';
4288 env->MajorVersion = atoi(&tempbuf[z-1]); 4601 if(ver > 4)
4289 env->MinorVersion = atoi(&tempbuf[z+1]); 4602 {
4603 env->MajorVersion = 10;
4604 env->MinorVersion = ver - 4;
4605 env->MajorBuild = atoi(&tempbuf[z+1]);
4606 }
4607 else
4608 {
4609 env->MajorVersion = ver;
4610 env->MinorVersion = atoi(&tempbuf[z+1]);
4611 }
4612
4290 return; 4613 return;
4291 } 4614 }
4292 } 4615 }
4293 env->MajorVersion = atoi(tempbuf); 4616 env->MajorVersion = atoi(tempbuf);
4294 env->MinorVersion = 0; 4617 env->MinorVersion = 0;
4457 return ud->data; 4780 return ud->data;
4458 } 4781 }
4459 return NULL; 4782 return NULL;
4460 } 4783 }
4461 4784
4785 #define DW_TIMER_MAX 64
4786 NSTimer *DWTimers[DW_TIMER_MAX];
4787
4462 /* 4788 /*
4463 * Add a callback to a timer event. 4789 * Add a callback to a timer event.
4464 * Parameters: 4790 * Parameters:
4465 * interval: Milliseconds to delay between calls. 4791 * interval: Milliseconds to delay between calls.
4466 * sigfunc: The pointer to the function to be used as the callback. 4792 * sigfunc: The pointer to the function to be used as the callback.
4468 * Returns: 4794 * Returns:
4469 * Timer ID for use with dw_timer_disconnect(), 0 on error. 4795 * Timer ID for use with dw_timer_disconnect(), 0 on error.
4470 */ 4796 */
4471 int API dw_timer_connect(int interval, void *sigfunc, void *data) 4797 int API dw_timer_connect(int interval, void *sigfunc, void *data)
4472 { 4798 {
4473 NSLog(@"dw_timer_connect() unimplemented\n"); 4799 int z;
4474 if(sigfunc) 4800
4475 { 4801 for(z=0;z<DW_TIMER_MAX;z++)
4476 int timerid = 0; 4802 {
4477 /* = WinStartTimer(dwhab, NULLHANDLE, 0, interval)*/ 4803 if(!DWTimers[z])
4478
4479 if(timerid)
4480 { 4804 {
4481 _new_signal(0, HWND_DESKTOP, timerid, sigfunc, data); 4805 break;
4482 return timerid;
4483 } 4806 }
4484 } 4807 }
4808
4809 if(sigfunc && !DWTimers[z])
4810 {
4811 NSTimeInterval seconds = (double)interval / 1000.0;
4812 NSTimer *thistimer = DWTimers[z] = [NSTimer timerWithTimeInterval:seconds target:DWHandler selector:@selector(runTimer:) userInfo:nil repeats:YES];
4813 _new_signal(0, thistimer, z+1, sigfunc, data);
4814 return z+1;
4815 }
4485 return 0; 4816 return 0;
4486 } 4817 }
4487 4818
4488 /* 4819 /*
4489 * Removes timer callback. 4820 * Removes timer callback.
4490 * Parameters: 4821 * Parameters:
4491 * id: Timer ID returned by dw_timer_connect(). 4822 * id: Timer ID returned by dw_timer_connect().
4492 */ 4823 */
4493 void API dw_timer_disconnect(int id) 4824 void API dw_timer_disconnect(int timerid)
4494 { 4825 {
4495 SignalHandler *prev = NULL, *tmp = Root; 4826 SignalHandler *prev = NULL, *tmp = Root;
4496 NSLog(@"dw_timer_disconnect() unimplemented\n"); 4827 NSTimer *thistimer;
4497 4828
4498 /* 0 is an invalid timer ID */ 4829 /* 0 is an invalid timer ID */
4499 if(!id) 4830 if(timerid < 1 || !DWTimers[timerid-1])
4500 return; 4831 return;
4501 4832
4502 /*WinStopTimer(dwhab, NULLHANDLE, id);*/ 4833 thistimer = DWTimers[timerid-1];
4834 DWTimers[timerid-1] = nil;
4835
4836 [thistimer release];
4503 4837
4504 while(tmp) 4838 while(tmp)
4505 { 4839 {
4506 if(tmp->id == id) 4840 if(tmp->id == (timerid-1) && tmp->window == thistimer)
4507 { 4841 {
4508 if(prev) 4842 if(prev)
4509 { 4843 {
4510 prev->next = tmp->next; 4844 prev->next = tmp->next;
4511 free(tmp); 4845 free(tmp);
4534 * sigfunc: The pointer to the function to be used as the callback. 4868 * sigfunc: The pointer to the function to be used as the callback.
4535 * data: User data to be passed to the handler function. 4869 * data: User data to be passed to the handler function.
4536 */ 4870 */
4537 void API dw_signal_connect(HWND window, char *signame, void *sigfunc, void *data) 4871 void API dw_signal_connect(HWND window, char *signame, void *sigfunc, void *data)
4538 { 4872 {
4539 ULONG message = 0, id = 0; 4873 ULONG message = 0, msgid = 0;
4540 4874
4541 if(window && signame && sigfunc) 4875 if(window && signame && sigfunc)
4542 { 4876 {
4543 if((message = _findsigmessage(signame)) != 0) 4877 if((message = _findsigmessage(signame)) != 0)
4544 { 4878 {
4545 _new_signal(message, window, id, sigfunc, data); 4879 _new_signal(message, window, msgid, sigfunc, data);
4546 } 4880 }
4547 } 4881 }
4548 } 4882 }
4549 4883
4550 /* 4884 /*