Mercurial > dwindows
comparison mac/dw.m @ 658:0502e5b6743b
Haven't finished but the basics of the container/listbox are now working.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Thu, 24 Feb 2011 14:29:23 +0000 |
parents | f31a47b055f8 |
children | 756015085da7 |
comparison
equal
deleted
inserted
replaced
657:f31a47b055f8 | 658:0502e5b6743b |
---|---|
182 * only add methods and no variables, which isn't | 182 * only add methods and no variables, which isn't |
183 * going to work. -Brian | 183 * going to work. -Brian |
184 */ | 184 */ |
185 | 185 |
186 /* Subclass for a box type */ | 186 /* Subclass for a box type */ |
187 @interface DWBox : NSView | 187 @interface DWBox : NSView <NSWindowDelegate> |
188 { | 188 { |
189 Box box; | 189 Box box; |
190 void *userdata; | 190 void *userdata; |
191 NSColor *bgcolor; | 191 NSColor *bgcolor; |
192 } | 192 } |
336 -(void *)userdata { return userdata; } | 336 -(void *)userdata { return userdata; } |
337 -(void)setUserdata:(void *)input { userdata = input; } | 337 -(void)setUserdata:(void *)input { userdata = input; } |
338 @end | 338 @end |
339 | 339 |
340 /* Subclass for a Notebook control type */ | 340 /* Subclass for a Notebook control type */ |
341 @interface DWNotebook : NSTabView | 341 @interface DWNotebook : NSTabView <NSTabViewDelegate> |
342 { | 342 { |
343 void *userdata; | 343 void *userdata; |
344 int pageid; | 344 int pageid; |
345 } | 345 } |
346 -(void *)userdata; | 346 -(void *)userdata; |
496 -(void *)userdata { return userdata; } | 496 -(void *)userdata { return userdata; } |
497 -(void)setUserdata:(void *)input { userdata = input; } | 497 -(void)setUserdata:(void *)input { userdata = input; } |
498 @end | 498 @end |
499 | 499 |
500 /* Subclass for a Container/List type */ | 500 /* Subclass for a Container/List type */ |
501 @interface DWContainer : NSTableView | 501 @interface DWContainer : NSTableView <NSTableViewDataSource> |
502 { | 502 { |
503 void *userdata; | 503 void *userdata; |
504 NSMutableArray *tvcols; | 504 NSMutableArray *tvcols; |
505 NSMutableArray *data; | 505 NSMutableArray *data; |
506 NSMutableArray *types; | 506 NSMutableArray *types; |
507 } | 507 NSMutableArray *titles; |
508 int lastAddPoint; | |
509 } | |
510 -(NSInteger)numberOfRowsInTableView:(NSTableView *)aTable; | |
511 -(id)tableView:(NSTableView *)aTable objectValueForTableColumn:(NSTableColumn *)aCol row:(NSInteger)aRow; | |
512 -(void)tableView:(NSTableView *)aTableView setObjectValue:(id)anObject forTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex; | |
508 -(void *)userdata; | 513 -(void *)userdata; |
509 -(void)setUserdata:(void *)input; | 514 -(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; | 515 -(void)addColumn:(NSTableColumn *)input andType:(int)type; |
513 -(void)addRow:(NSArray *)input; | 516 -(int)addRow:(NSArray *)input; |
514 -(void)addRows:(int)number; | 517 -(int)addRows:(int)number; |
515 -(void)editCell:(id)input at:(int)row and:(int)col; | 518 -(void)editCell:(id)input at:(int)row and:(int)col; |
516 -(int)cellType:(int)col; | 519 -(int)cellType:(int)col; |
520 -(int)lastAddPoint; | |
517 -(void)clear; | 521 -(void)clear; |
518 -(void)setup; | 522 -(void)setup; |
519 @end | 523 @end |
520 | 524 |
521 @implementation DWContainer | 525 @implementation DWContainer |
522 -(void *)userdata { return userdata; } | 526 -(NSInteger)numberOfRowsInTableView:(NSTableView *)aTable |
523 -(void)setUserdata:(void *)input { userdata = input; } | 527 { |
524 -(id)tableView:(NSTableView *)aTable objectValueForColumn:(NSTableColumn *)aCol row:(int)aRow | 528 if(tvcols && data) |
529 { | |
530 int cols = [tvcols count]; | |
531 if(cols) | |
532 { | |
533 return [data count] / cols; | |
534 } | |
535 } | |
536 return 0; | |
537 } | |
538 -(id)tableView:(NSTableView *)aTable objectValueForTableColumn:(NSTableColumn *)aCol row:(NSInteger)aRow | |
525 { | 539 { |
526 if(tvcols) | 540 if(tvcols) |
527 { | 541 { |
528 int z, col = -1; | 542 int z, col = -1; |
529 int count = [tvcols count]; | 543 int count = [tvcols count]; |
542 return [data objectAtIndex:index]; | 556 return [data objectAtIndex:index]; |
543 } | 557 } |
544 } | 558 } |
545 return nil; | 559 return nil; |
546 } | 560 } |
547 -(int)numberOfRowsInTableView:(NSTableView *)aTable | 561 -(void)tableView:(NSTableView *)aTableView setObjectValue:(id)anObject forTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex |
548 { | 562 { |
549 if(tvcols && data) | 563 if(tvcols) |
550 { | 564 { |
551 int cols = [tvcols count]; | 565 int z, col = -1; |
552 if(cols) | 566 int count = [tvcols count]; |
567 | |
568 for(z=0;z<count;z++) | |
553 { | 569 { |
554 return [data count] / cols; | 570 if([tvcols objectAtIndex:z] == aTableColumn) |
571 { | |
572 col = z; | |
573 break; | |
574 } | |
555 } | 575 } |
556 } | 576 if(col != -1) |
557 return 0; | 577 { |
558 } | 578 int index = (rowIndex * count) + col; |
579 [data replaceObjectAtIndex:index withObject:anObject]; | |
580 } | |
581 } | |
582 } | |
583 -(void *)userdata { return userdata; } | |
584 -(void)setUserdata:(void *)input { userdata = input; } | |
559 -(void)addColumn:(NSTableColumn *)input andType:(int)type { if(tvcols) { [tvcols addObject:input]; [types addObject:[NSNumber numberWithInt:type]]; } } | 585 -(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]; } } | 586 -(int)addRow:(NSArray *)input { if(data) { [data addObjectsFromArray:input]; [titles addObject:[NSNull null]]; return [titles count]; } return 0; } |
561 -(void)addRows:(int)number | 587 -(int)addRows:(int)number |
562 { | 588 { |
563 if(tvcols) | 589 if(tvcols) |
564 { | 590 { |
565 int count = number * [tvcols count]; | 591 int count = number * [tvcols count]; |
566 int z; | 592 int z; |
593 | |
594 lastAddPoint = [titles count]; | |
567 | 595 |
568 for(z=0;z<count;z++) | 596 for(z=0;z<count;z++) |
569 { | 597 { |
570 [data addObject:[NSNull null]]; | 598 [data addObject:[NSNull null]]; |
571 } | 599 } |
572 } | 600 for(z=0;z<number;z++) |
601 { | |
602 [titles addObject:[NSNull null]]; | |
603 } | |
604 return [titles count]; | |
605 } | |
606 return 0; | |
573 } | 607 } |
574 -(void)editCell:(id)input at:(int)row and:(int)col | 608 -(void)editCell:(id)input at:(int)row and:(int)col |
575 { | 609 { |
576 if(tvcols && input) | 610 if(tvcols && input) |
577 { | 611 { |
578 int index = (row * [tvcols count]) + col; | 612 int index = (row * [tvcols count]) + col; |
579 [data replaceObjectAtIndex:index withObject:input]; | 613 [data replaceObjectAtIndex:index withObject:input]; |
580 } | 614 } |
581 } | 615 } |
582 -(int)cellType:(int)col { return [[types objectAtIndex:col] intValue]; } | 616 -(int)cellType:(int)col { return [[types objectAtIndex:col] intValue]; } |
617 -(int)lastAddPoint { return lastAddPoint; } | |
583 -(void)clear { if(data) { [data removeAllObjects]; } } | 618 -(void)clear { if(data) { [data removeAllObjects]; } } |
584 -(void)setup { tvcols = [[NSMutableArray alloc] init]; data = [[NSMutableArray alloc] init]; types = [[NSMutableArray alloc] init]; } | 619 -(void)setup { tvcols = [[NSMutableArray alloc] init]; data = [[NSMutableArray alloc] init]; types = [[NSMutableArray alloc] init]; titles = [[NSMutableArray alloc] init];} |
585 @end | 620 @end |
586 | 621 |
587 /* Subclass for a Calendar type */ | 622 /* Subclass for a Calendar type */ |
588 @interface DWCalendar : NSDatePicker | 623 @interface DWCalendar : NSDatePicker |
589 { | 624 { |
2060 [button setState:NSOffState]; | 2095 [button setState:NSOffState]; |
2061 } | 2096 } |
2062 | 2097 |
2063 } | 2098 } |
2064 | 2099 |
2100 /* Common code for containers and listboxes */ | |
2101 HWND _cont_new(ULONG id, int multi) | |
2102 { | |
2103 DWContainer *cont = [[DWContainer alloc] init]; | |
2104 if(multi) | |
2105 { | |
2106 [cont setAllowsMultipleSelection:YES]; | |
2107 } | |
2108 else | |
2109 { | |
2110 [cont setAllowsMultipleSelection:NO]; | |
2111 } | |
2112 [cont setDataSource:cont]; | |
2113 return cont; | |
2114 } | |
2115 | |
2065 /* | 2116 /* |
2066 * Create a new listbox window (widget) to be packed. | 2117 * Create a new listbox window (widget) to be packed. |
2067 * Parameters: | 2118 * Parameters: |
2068 * id: An ID to be used with dw_window_from_id() or 0L. | 2119 * id: An ID to be used with dw_window_from_id() or 0L. |
2069 * multi: Multiple select TRUE or FALSE. | 2120 * multi: Multiple select TRUE or FALSE. |
2070 */ | 2121 */ |
2071 HWND API dw_listbox_new(ULONG id, int multi) | 2122 HWND API dw_listbox_new(ULONG id, int multi) |
2072 { | 2123 { |
2073 NSLog(@"dw_listbox_new() unimplemented\n"); | 2124 DWContainer *cont = _cont_new(id, multi); |
2074 return HWND_DESKTOP; | 2125 int type = DW_CFA_STRING; |
2126 [cont setup]; | |
2127 NSTableColumn *column = [[NSTableColumn alloc] init]; | |
2128 [cont addTableColumn:column]; | |
2129 [cont addColumn:column andType:type]; | |
2130 return cont; | |
2075 } | 2131 } |
2076 | 2132 |
2077 /* | 2133 /* |
2078 * Appends the specified text to the listbox's (or combobox) entry list. | 2134 * Appends the specified text to the listbox's (or combobox) entry list. |
2079 * Parameters: | 2135 * Parameters: |
2869 * id: An ID to be used for getting the resource from the | 2925 * id: An ID to be used for getting the resource from the |
2870 * resource file. | 2926 * resource file. |
2871 */ | 2927 */ |
2872 HWND API dw_container_new(ULONG id, int multi) | 2928 HWND API dw_container_new(ULONG id, int multi) |
2873 { | 2929 { |
2874 DWContainer *cont = [[DWContainer alloc] init]; | 2930 DWContainer *cont = _cont_new(id, multi); |
2875 if(multi) | 2931 NSTableHeaderView *header = [[NSTableHeaderView alloc] init]; |
2876 { | 2932 [cont setHeaderView:header]; |
2877 [cont setAllowsMultipleSelection:YES]; | |
2878 } | |
2879 else | |
2880 { | |
2881 [cont setAllowsMultipleSelection:NO]; | |
2882 } | |
2883 [cont setDataSource:cont]; | |
2884 return cont; | 2933 return cont; |
2885 } | 2934 } |
2886 | 2935 |
2887 /* | 2936 /* |
2888 * Sets up the container columns. | 2937 * Sets up the container columns. |
2966 void API dw_container_set_item(HWND handle, void *pointer, int column, int row, void *data) | 3015 void API dw_container_set_item(HWND handle, void *pointer, int column, int row, void *data) |
2967 { | 3016 { |
2968 DWContainer *cont = handle; | 3017 DWContainer *cont = handle; |
2969 id object = nil; | 3018 id object = nil; |
2970 int type = [cont cellType:column]; | 3019 int type = [cont cellType:column]; |
3020 int lastadd = [cont lastAddPoint]; | |
2971 | 3021 |
2972 if(type & DW_CFA_BITMAPORICON) | 3022 if(type & DW_CFA_BITMAPORICON) |
2973 { | 3023 { |
2974 /* TODO: Handle image here */ | 3024 /* TODO: Handle image here */ |
2975 } | 3025 } |
3016 return; | 3066 return; |
3017 } | 3067 } |
3018 object = [ NSString stringWithUTF8String:textbuffer ]; | 3068 object = [ NSString stringWithUTF8String:textbuffer ]; |
3019 } | 3069 } |
3020 | 3070 |
3021 [cont editCell:object at:row and:column]; | 3071 [cont editCell:object at:(row+lastadd) and:column]; |
3022 } | 3072 } |
3023 | 3073 |
3024 /* | 3074 /* |
3025 * Changes an existing item in specified row and column to the given data. | 3075 * Changes an existing item in specified row and column to the given data. |
3026 * Parameters: | 3076 * Parameters: |
3056 * row: Zero based row of data being set. | 3106 * row: Zero based row of data being set. |
3057 * data: Pointer to the data to be added. | 3107 * data: Pointer to the data to be added. |
3058 */ | 3108 */ |
3059 void API dw_filesystem_change_file(HWND handle, int row, char *filename, unsigned long icon) | 3109 void API dw_filesystem_change_file(HWND handle, int row, char *filename, unsigned long icon) |
3060 { | 3110 { |
3061 dw_container_change_item(handle, 0, row, filename); | 3111 dw_container_change_item(handle, 1, row, filename); |
3062 } | 3112 } |
3063 | 3113 |
3064 /* | 3114 /* |
3065 * Sets an item in specified row and column to the given data. | 3115 * Sets an item in specified row and column to the given data. |
3066 * Parameters: | 3116 * Parameters: |
3070 * row: Zero based row of data being set. | 3120 * row: Zero based row of data being set. |
3071 * data: Pointer to the data to be added. | 3121 * data: Pointer to the data to be added. |
3072 */ | 3122 */ |
3073 void API dw_filesystem_set_file(HWND handle, void *pointer, int row, char *filename, unsigned long icon) | 3123 void API dw_filesystem_set_file(HWND handle, void *pointer, int row, char *filename, unsigned long icon) |
3074 { | 3124 { |
3075 dw_container_set_item(handle, pointer, 0, row, filename); | 3125 dw_container_set_item(handle, pointer, 1, row, filename); |
3076 } | 3126 } |
3077 | 3127 |
3078 /* | 3128 /* |
3079 * Sets an item in specified row and column to the given data. | 3129 * Sets an item in specified row and column to the given data. |
3080 * Parameters: | 3130 * Parameters: |
3144 * pointer: Pointer to the allocated memory in dw_container_alloc(). | 3194 * pointer: Pointer to the allocated memory in dw_container_alloc(). |
3145 * rowcount: The number of rows to be inserted. | 3195 * rowcount: The number of rows to be inserted. |
3146 */ | 3196 */ |
3147 void API dw_container_insert(HWND handle, void *pointer, int rowcount) | 3197 void API dw_container_insert(HWND handle, void *pointer, int rowcount) |
3148 { | 3198 { |
3149 NSLog(@"dw_container_insert() unimplemented\n"); | 3199 DWContainer *cont = handle; |
3200 return [cont reloadData]; | |
3150 } | 3201 } |
3151 | 3202 |
3152 /* | 3203 /* |
3153 * Removes all rows from a container. | 3204 * Removes all rows from a container. |
3154 * Parameters: | 3205 * Parameters: |
3240 * Parameters: | 3291 * Parameters: |
3241 * handle: Handle to the window (widget) to be optimized. | 3292 * handle: Handle to the window (widget) to be optimized. |
3242 */ | 3293 */ |
3243 void API dw_container_optimize(HWND handle) | 3294 void API dw_container_optimize(HWND handle) |
3244 { | 3295 { |
3245 NSLog(@"dw_container_optimize() unimplemented\n"); | 3296 DWContainer *cont = handle; |
3297 /*[cont sizeToFit];*/ | |
3298 [cont setColumnAutoresizingStyle:NSTableViewUniformColumnAutoresizingStyle]; | |
3246 } | 3299 } |
3247 | 3300 |
3248 /* | 3301 /* |
3249 * Inserts an icon into the taskbar. | 3302 * Inserts an icon into the taskbar. |
3250 * Parameters: | 3303 * Parameters: |
3489 id bltsrc = src; | 3542 id bltsrc = src; |
3490 if(destp) | 3543 if(destp) |
3491 { | 3544 { |
3492 bltdest = (id)destp; | 3545 bltdest = (id)destp; |
3493 } | 3546 } |
3547 [bltdest lockFocus]; | |
3494 if(srcp) | 3548 if(srcp) |
3495 { | 3549 { |
3496 bltsrc = (id)srcp; | 3550 bltsrc = (id)srcp; |
3497 } | 3551 NSImage *image = bltsrc; |
3498 [bltdest lockFocus]; | 3552 [image drawAtPoint:NSMakePoint(xdest, ydest) fromRect:NSMakeRect(xsrc, ysrc, width, height) operation:NSCompositeCopy fraction:1.0]; |
3499 NSLog(@"dw_pixmap_bitblt() unimplemented\n"); | 3553 } |
3500 [bltdest unlockFocus]; | 3554 [bltdest unlockFocus]; |
3501 } | 3555 } |
3502 | 3556 |
3503 /* | 3557 /* |
3504 * Create a new static text window (widget) to be packed. | 3558 * Create a new static text window (widget) to be packed. |
3686 * menu: Handle of a menu. | 3740 * menu: Handle of a menu. |
3687 */ | 3741 */ |
3688 void API dw_menu_destroy(HMENUI *menu) | 3742 void API dw_menu_destroy(HMENUI *menu) |
3689 { | 3743 { |
3690 NSMenu *thismenu = *menu; | 3744 NSMenu *thismenu = *menu; |
3691 [thismenu dealloc]; | 3745 [thismenu release]; |
3692 } | 3746 } |
3693 | 3747 |
3694 /* | 3748 /* |
3695 * Pops up a context menu at given x and y coordinates. | 3749 * Pops up a context menu at given x and y coordinates. |
3696 * Parameters: | 3750 * Parameters: |