comparison mac/dw.m @ 2174:f93d29310b14

Mac: Implemented the required delegate selectors so NSView is now active. Basic functionality is working now, but the NSTableCellView is not being displayed. Commiting and going to try to debug the display issue on 10.11 using the interface inspector which no longer works on later versions of MacOS. This commit and potentially the next few will cause partial breakages on MacOS Yosemite (10.10) and later.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sun, 11 Oct 2020 21:43:41 +0000
parents 8a609f6748e7
children e2c00a7a74a1
comparison
equal deleted inserted replaced
2173:8a609f6748e7 2174:f93d29310b14
2236 -(id)scrollview { return scrollview; } 2236 -(id)scrollview { return scrollview; }
2237 -(void)setScrollview:(id)input { scrollview = input; } 2237 -(void)setScrollview:(id)input { scrollview = input; }
2238 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; } 2238 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; }
2239 @end 2239 @end
2240 2240
2241 #ifndef BUILDING_FOR_YOSEMITE1 2241 #ifndef BUILDING_FOR_YOSEMITE
2242 /* Subclass NSTextFieldCell for displaying image and text */ 2242 /* Subclass NSTextFieldCell for displaying image and text */
2243 @interface DWImageAndTextCell : NSTextFieldCell 2243 @interface DWImageAndTextCell : NSTextFieldCell
2244 { 2244 {
2245 @private 2245 @private
2246 NSImage *image; 2246 NSImage *image;
2389 -(void)setScrollview:(id)input; 2389 -(void)setScrollview:(id)input;
2390 -(void)addColumn:(NSTableColumn *)input andType:(int)type; 2390 -(void)addColumn:(NSTableColumn *)input andType:(int)type;
2391 -(NSTableColumn *)getColumn:(int)col; 2391 -(NSTableColumn *)getColumn:(int)col;
2392 -(int)addRow:(NSArray *)input; 2392 -(int)addRow:(NSArray *)input;
2393 -(int)addRows:(int)number; 2393 -(int)addRows:(int)number;
2394 -(void)tableView:(NSTableView *)tableView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row;
2395 -(void)editCell:(id)input at:(int)row and:(int)col; 2394 -(void)editCell:(id)input at:(int)row and:(int)col;
2396 -(void)removeRow:(int)row; 2395 -(void)removeRow:(int)row;
2397 -(void)setRow:(int)row title:(const char *)input; 2396 -(void)setRow:(int)row title:(const char *)input;
2398 -(void *)getRowTitle:(int)row; 2397 -(void *)getRowTitle:(int)row;
2399 -(id)getRow:(int)row and:(int)col; 2398 -(id)getRow:(int)row and:(int)col;
2409 -(void)doubleClicked:(id)sender; 2408 -(void)doubleClicked:(id)sender;
2410 -(void)keyUp:(NSEvent *)theEvent; 2409 -(void)keyUp:(NSEvent *)theEvent;
2411 -(void)tableView:(NSTableView *)tableView didClickTableColumn:(NSTableColumn *)tableColumn; 2410 -(void)tableView:(NSTableView *)tableView didClickTableColumn:(NSTableColumn *)tableColumn;
2412 -(void)selectionChanged:(id)sender; 2411 -(void)selectionChanged:(id)sender;
2413 -(NSMenu *)menuForEvent:(NSEvent *)event; 2412 -(NSMenu *)menuForEvent:(NSEvent *)event;
2414 #ifdef BUILDING_FOR_LION1 2413 #ifdef BUILDING_FOR_YOSEMITE
2415 -(NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row; 2414 -(NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row;
2415 #else
2416 -(void)tableView:(NSTableView *)tableView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row;
2416 #endif 2417 #endif
2417 @end 2418 @end
2418 2419
2419 @implementation DWContainer 2420 @implementation DWContainer
2420 -(NSInteger)numberOfRowsInTableView:(NSTableView *)aTable 2421 -(NSInteger)numberOfRowsInTableView:(NSTableView *)aTable
2455 } 2456 }
2456 } 2457 }
2457 } 2458 }
2458 return nil; 2459 return nil;
2459 } 2460 }
2460 #ifdef BUILDING_FOR_LION1
2461 -(NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
2462 {
2463 ItemCellView *result = [tableView makeViewWithIdentifier:tableColumn.identifier owner:self];
2464 Item *item = [self.items objectAtIndex:row];
2465 result.imageView.image = item.itemIcon;
2466 result.textField.stringValue = item.itemDisplayName;
2467 result.detailTextField.stringValue = item.itemKind;
2468 return result;
2469 }
2470 #endif
2471 -(BOOL)tableView:(NSTableView *)aTableView shouldEditTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex { return NO; } 2461 -(BOOL)tableView:(NSTableView *)aTableView shouldEditTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex { return NO; }
2472 -(void *)userdata { return userdata; } 2462 -(void *)userdata { return userdata; }
2473 -(void)setUserdata:(void *)input { userdata = input; } 2463 -(void)setUserdata:(void *)input { userdata = input; }
2474 -(void)setFilesystem:(int)input { filesystem = input; } 2464 -(void)setFilesystem:(int)input { filesystem = input; }
2475 -(int)filesystem { return filesystem; } 2465 -(int)filesystem { return filesystem; }
2568 } 2558 }
2569 return (int)[titles count]; 2559 return (int)[titles count];
2570 } 2560 }
2571 return 0; 2561 return 0;
2572 } 2562 }
2563 #ifdef BUILDING_FOR_YOSEMITE
2564 -(NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row;
2565 {
2566 /* Get an existing cell with the MyView identifier if it exists */
2567 NSTableCellView *result = [tableView makeViewWithIdentifier:tableColumn.identifier owner:self];
2568 int index = (int)(row * [tvcols count]);
2569 id celldata = [data objectAtIndex:index];
2570
2571 /* There is no existing cell to reuse so create a new one */
2572 if(result == nil)
2573 {
2574 /* The data is already a NSTableCellView so just return that */
2575 if([celldata isMemberOfClass:[NSTableCellView class]])
2576 result = celldata;
2577 else
2578 {
2579 /* Create the new NSTableCellView with a frame of the {0,0} with the width of the table.
2580 * Note that the height of the frame is not really relevant, because the row height will modify the height.
2581 */
2582 result = [[NSTableCellView alloc] init];
2583
2584 /* The identifier of the NSTextField instance is set to MyView.
2585 * This allows the cell to be reused.
2586 */
2587 [result setIdentifier:tableColumn.identifier];
2588 }
2589 }
2590
2591 /* result is now guaranteed to be valid, either as a reused cell
2592 * or as a new cell, so set the text or image
2593 */
2594 NSTextFieldCell *tcell = [[result textField] cell];
2595
2596 if([celldata isMemberOfClass:[NSImage class]])
2597 [[result imageView] setImage:celldata];
2598 if([celldata isKindOfClass:[NSString class]])
2599 [[result textField] setStringValue:celldata];
2600
2601 /* Handle drawing alternating row colors if enabled */
2602 if ((row % 2) == 0)
2603 {
2604 if(evencolor)
2605 {
2606 [tcell setDrawsBackground:YES];
2607 [tcell setBackgroundColor:evencolor];
2608 }
2609 else
2610 [tcell setDrawsBackground:NO];
2611 }
2612 else
2613 {
2614 if(oddcolor)
2615 {
2616 [tcell setDrawsBackground:YES];
2617 [tcell setBackgroundColor:oddcolor];
2618 }
2619 else
2620 [tcell setDrawsBackground:NO];
2621 }
2622
2623 /* Return the result */
2624 return result;
2625 }
2626 #else
2573 -(void)tableView:(NSTableView *)tableView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row 2627 -(void)tableView:(NSTableView *)tableView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
2574 { 2628 {
2575 #ifdef BUILDING_FOR_YOSEMITE1
2576 NSTableCellView *bcell = cell;
2577 NSTextField *tcell = nil;
2578
2579 /* Handle drawing image and text if necessary */
2580 if([cell isMemberOfClass:[NSTableCellView class]])
2581 {
2582 int index = (int)(row * [tvcols count]);
2583 NSTableCellView *browsercell = [data objectAtIndex:index];
2584 NSImage *img = [[browsercell imageView] image];
2585 [[bcell imageView] setImage:img];
2586 tcell = [bcell textField];
2587 }
2588 #else
2589 DWImageAndTextCell *bcell = cell, *tcell = cell; 2629 DWImageAndTextCell *bcell = cell, *tcell = cell;
2590 2630
2591 /* Handle drawing image and text if necessary */ 2631 /* Handle drawing image and text if necessary */
2592 if([cell isMemberOfClass:[DWImageAndTextCell class]]) 2632 if([cell isMemberOfClass:[DWImageAndTextCell class]])
2593 { 2633 {
2594 int index = (int)(row * [tvcols count]); 2634 int index = (int)(row * [tvcols count]);
2595 DWImageAndTextCell *browsercell = [data objectAtIndex:index]; 2635 DWImageAndTextCell *browsercell = [data objectAtIndex:index];
2596 NSImage *img = [browsercell image]; 2636 NSImage *img = [browsercell image];
2597 [bcell setImage:img]; 2637 [bcell setImage:img];
2598 } 2638 }
2599 #endif
2600 2639
2601 if([tcell isKindOfClass:[NSTextFieldCell class]]) 2640 if([tcell isKindOfClass:[NSTextFieldCell class]])
2602 { 2641 {
2603 /* Handle drawing alternating row colors if enabled */ 2642 /* Handle drawing alternating row colors if enabled */
2604 if ((row % 2) == 0) 2643 if ((row % 2) == 0)
2621 else 2660 else
2622 [tcell setDrawsBackground:NO]; 2661 [tcell setDrawsBackground:NO];
2623 } 2662 }
2624 } 2663 }
2625 } 2664 }
2665 #endif
2626 -(void)editCell:(id)input at:(int)row and:(int)col 2666 -(void)editCell:(id)input at:(int)row and:(int)col
2627 { 2667 {
2628 if(tvcols) 2668 if(tvcols)
2629 { 2669 {
2630 int index = (int)(row * [tvcols count]) + col; 2670 int index = (int)(row * [tvcols count]) + col;
2739 { 2779 {
2740 int x; 2780 int x;
2741 2781
2742 for(x=0;x<rowcount;x++) 2782 for(x=0;x<rowcount;x++)
2743 { 2783 {
2744 #ifdef BUILDING_FOR_YOSEMITE1 2784 #ifdef BUILDING_FOR_YOSEMITE
2745 NSTableCellView *cell = [self viewAtColumn:z row:x makeIfNecessary:YES]; 2785 NSTableCellView *cell = [self viewAtColumn:z row:x makeIfNecessary:YES];
2746 int thiswidth = NSWidth([cell frame]); 2786 int thiswidth = NSWidth([cell frame]);
2747 2787
2748 /* If on the first column... add up the heights */ 2788 /* If on the first column... add up the heights */
2749 if(z == 0) 2789 if(z == 0)
2806 NSCell *colcell = [column headerCell]; 2846 NSCell *colcell = [column headerCell];
2807 int width = [colcell cellSize].width; 2847 int width = [colcell cellSize].width;
2808 2848
2809 for(x=0;x<rowcount;x++) 2849 for(x=0;x<rowcount;x++)
2810 { 2850 {
2811 #ifdef BUILDING_FOR_YOSEMITE1 2851 #ifdef BUILDING_FOR_YOSEMITE
2812 NSTableCellView *cell = [self viewAtColumn:z row:x makeIfNecessary:YES]; 2852 NSTableCellView *cell = [self viewAtColumn:z row:x makeIfNecessary:YES];
2813 int thiswidth = NSWidth([cell frame]); 2853 int thiswidth = NSWidth([cell frame]);
2814 #else 2854 #else
2815 NSCell *cell = [self preparedCellAtColumn:z row:x]; 2855 NSCell *cell = [self preparedCellAtColumn:z row:x];
2816 int thiswidth = [cell cellSize].width; 2856 int thiswidth = [cell cellSize].width;
3014 { 3054 {
3015 self = [super init]; 3055 self = [super init];
3016 3056
3017 if (self) 3057 if (self)
3018 { 3058 {
3019 treecol = [[NSTableColumn alloc] init]; 3059 treecol = [[NSTableColumn alloc] initWithIdentifier:@"_DWTreeColumn"];
3020 #ifndef BUILDING_FOR_YOSEMITE1 3060 #ifndef BUILDING_FOR_YOSEMITE
3021 DWImageAndTextCell *browsercell = [[[DWImageAndTextCell alloc] init] autorelease]; 3061 DWImageAndTextCell *browsercell = [[[DWImageAndTextCell alloc] init] autorelease];
3022 [treecol setDataCell:browsercell]; 3062 [treecol setDataCell:browsercell];
3023 #endif 3063 #endif
3024 [self addTableColumn:treecol]; 3064 [self addTableColumn:treecol];
3025 [self setOutlineTableColumn:treecol]; 3065 [self setOutlineTableColumn:treecol];
3079 } 3119 }
3080 return @"List Root"; 3120 return @"List Root";
3081 } 3121 }
3082 -(void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item 3122 -(void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item
3083 { 3123 {
3084 #ifdef BUILDING_FOR_YOSEMITE1 3124 #ifdef BUILDING_FOR_YOSEMITE
3085 if([cell isMemberOfClass:[NSTableCellView class]]) 3125 if([cell isMemberOfClass:[NSTableCellView class]])
3086 { 3126 {
3087 NSMutableArray *this = (NSMutableArray *)item; 3127 NSMutableArray *this = (NSMutableArray *)item;
3088 NSImage *img = [this objectAtIndex:0]; 3128 NSImage *img = [this objectAtIndex:0];
3089 if([img isKindOfClass:[NSImage class]]) 3129 if([img isKindOfClass:[NSImage class]])
5669 DW_FUNCTION_INIT; 5709 DW_FUNCTION_INIT;
5670 DWContainer *cont = _cont_new(cid, multi); 5710 DWContainer *cont = _cont_new(cid, multi);
5671 [cont setHeaderView:nil]; 5711 [cont setHeaderView:nil];
5672 int type = DW_CFA_STRING; 5712 int type = DW_CFA_STRING;
5673 [cont setup]; 5713 [cont setup];
5674 NSTableColumn *column = [[[NSTableColumn alloc] init] autorelease]; 5714 NSTableColumn *column = [[[NSTableColumn alloc] initWithIdentifier:@"_DWListboxColumn"] autorelease];
5675 [column setEditable:NO]; 5715 [column setEditable:NO];
5676 [cont addTableColumn:column]; 5716 [cont addTableColumn:column];
5677 [cont addColumn:column andType:type]; 5717 [cont addColumn:column andType:type];
5678 DW_FUNCTION_RETURN_THIS(cont) 5718 DW_FUNCTION_RETURN_THIS(cont)
5679 } 5719 }
7427 7467
7428 [cont setup]; 7468 [cont setup];
7429 7469
7430 for(z=0;z<count;z++) 7470 for(z=0;z<count;z++)
7431 { 7471 {
7432 NSTableColumn *column = [[NSTableColumn alloc] init]; 7472 NSString *title = [NSString stringWithUTF8String:titles[z]];
7433 #ifdef BUILDING_FOR_YOSEMITE1 7473 NSTableColumn *column = [[NSTableColumn alloc] initWithIdentifier:title];
7434 [column setTitle:[ NSString stringWithUTF8String:titles[z] ]]; 7474 #ifdef BUILDING_FOR_YOSEMITE
7475 [column setTitle:title];
7435 #else 7476 #else
7436 [[column headerCell] setStringValue:[ NSString stringWithUTF8String:titles[z] ]]; 7477 [[column headerCell] setStringValue:title];
7437 if(flags[z] & DW_CFA_BITMAPORICON) 7478 if(flags[z] & DW_CFA_BITMAPORICON)
7438 { 7479 {
7439 NSImageCell *imagecell = [[NSImageCell alloc] init]; 7480 NSImageCell *imagecell = [[NSImageCell alloc] init];
7440 [column setDataCell:imagecell]; 7481 [column setDataCell:imagecell];
7441 [imagecell release]; 7482 [imagecell release];
7666 DW_FUNCTION_NO_RETURN(dw_filesystem_set_file) 7707 DW_FUNCTION_NO_RETURN(dw_filesystem_set_file)
7667 DW_FUNCTION_RESTORE_PARAM5(handle, HWND, pointer, void *, row, int, filename, char *, icon, HICN) 7708 DW_FUNCTION_RESTORE_PARAM5(handle, HWND, pointer, void *, row, int, filename, char *, icon, HICN)
7668 { 7709 {
7669 DW_FUNCTION_INIT; 7710 DW_FUNCTION_INIT;
7670 DWContainer *cont = handle; 7711 DWContainer *cont = handle;
7671 #ifdef BUILDING_FOR_YOSEMITE1 7712 #ifdef BUILDING_FOR_YOSEMITE
7672 NSTableCellView *browsercell; 7713 NSTableCellView *browsercell;
7673 #else 7714 #else
7674 DWImageAndTextCell *browsercell; 7715 DWImageAndTextCell *browsercell;
7675 #endif 7716 #endif
7676 int lastadd = 0; 7717 int lastadd = 0;
7679 if(pointer) 7720 if(pointer)
7680 { 7721 {
7681 lastadd = [cont lastAddPoint]; 7722 lastadd = [cont lastAddPoint];
7682 } 7723 }
7683 7724
7684 #ifdef BUILDING_FOR_YOSEMITE1 7725 #ifdef BUILDING_FOR_YOSEMITE
7685 browsercell = [[[NSTableCellView alloc] init] autorelease]; 7726 browsercell = [[[NSTableCellView alloc] init] autorelease];
7686 [[browsercell imageView] setImage:icon]; 7727 [[browsercell imageView] setImage:icon];
7687 [[browsercell textField] setStringValue:[ NSString stringWithUTF8String:filename ]]; 7728 [[browsercell textField] setStringValue:[ NSString stringWithUTF8String:filename ]];
7688 #else 7729 #else
7689 browsercell = [[[DWImageAndTextCell alloc] init] autorelease]; 7730 browsercell = [[[DWImageAndTextCell alloc] init] autorelease];