comparison mac/dw.m @ 2173:8a609f6748e7

Mac: Initial code to transition from NSCell based container/tree controls. Been getting deprecation warnings about this since Yosemite 10.10 but the code has been functional so I had been ignoring it. In Big Sur 11.0 the cell based version is displaying incorrectly, instead of spending effort to fix the deprecated cell based version, investing time switching to the View based version using NSTableCellView. This code semi-works, displays briefly before getting an invalid instruction in the message loop. Committing as BUILDING_FOR_YOSEMITE1 instead of BUILDING_FOR_YOSEMITE so the code is currently disabled.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sun, 11 Oct 2020 09:51:45 +0000
parents a1bf891d5990
children f93d29310b14
comparison
equal deleted inserted replaced
2172:81c50388851d 2173:8a609f6748e7
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 /* Subclass NSTextFieldCell for displaying image and text */ 2242 /* Subclass NSTextFieldCell for displaying image and text */
2242 @interface DWImageAndTextCell : NSTextFieldCell 2243 @interface DWImageAndTextCell : NSTextFieldCell
2243 { 2244 {
2244 @private 2245 @private
2245 NSImage *image; 2246 NSImage *image;
2354 NSSize cellSize = [super cellSize]; 2355 NSSize cellSize = [super cellSize];
2355 cellSize.width += (image ? [image size].width : 0) + 3; 2356 cellSize.width += (image ? [image size].width : 0) + 3;
2356 return cellSize; 2357 return cellSize;
2357 } 2358 }
2358 @end 2359 @end
2360 #endif
2359 2361
2360 /* Subclass for a Container/List type */ 2362 /* Subclass for a Container/List type */
2361 @interface DWContainer : NSTableView 2363 @interface DWContainer : NSTableView
2362 #ifdef BUILDING_FOR_SNOW_LEOPARD 2364 #ifdef BUILDING_FOR_SNOW_LEOPARD
2363 <NSTableViewDataSource,NSTableViewDelegate> 2365 <NSTableViewDataSource,NSTableViewDelegate>
2568 } 2570 }
2569 return 0; 2571 return 0;
2570 } 2572 }
2571 -(void)tableView:(NSTableView *)tableView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row 2573 -(void)tableView:(NSTableView *)tableView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
2572 { 2574 {
2573 DWImageAndTextCell *bcell = cell; 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;
2574 2590
2575 /* Handle drawing image and text if necessary */ 2591 /* Handle drawing image and text if necessary */
2576 if([cell isMemberOfClass:[DWImageAndTextCell class]]) 2592 if([cell isMemberOfClass:[DWImageAndTextCell class]])
2577 { 2593 {
2578 int index = (int)(row * [tvcols count]); 2594 int index = (int)(row * [tvcols count]);
2579 DWImageAndTextCell *browsercell = [data objectAtIndex:index]; 2595 DWImageAndTextCell *browsercell = [data objectAtIndex:index];
2580 NSImage *img = [browsercell image]; 2596 NSImage *img = [browsercell image];
2581 [bcell setImage:img]; 2597 [bcell setImage:img];
2582 } 2598 }
2583 if([cell isKindOfClass:[NSTextFieldCell class]]) 2599 #endif
2600
2601 if([tcell isKindOfClass:[NSTextFieldCell class]])
2584 { 2602 {
2585 /* Handle drawing alternating row colors if enabled */ 2603 /* Handle drawing alternating row colors if enabled */
2586 if ((row % 2) == 0) 2604 if ((row % 2) == 0)
2587 { 2605 {
2588 if(evencolor) 2606 if(evencolor)
2589 { 2607 {
2590 [bcell setDrawsBackground:YES]; 2608 [tcell setDrawsBackground:YES];
2591 [bcell setBackgroundColor:evencolor]; 2609 [tcell setBackgroundColor:evencolor];
2592 } 2610 }
2593 else 2611 else
2594 [bcell setDrawsBackground:NO]; 2612 [tcell setDrawsBackground:NO];
2595 } 2613 }
2596 else 2614 else
2597 { 2615 {
2598 if(oddcolor) 2616 if(oddcolor)
2599 { 2617 {
2600 [bcell setDrawsBackground:YES]; 2618 [tcell setDrawsBackground:YES];
2601 [bcell setBackgroundColor:oddcolor]; 2619 [tcell setBackgroundColor:oddcolor];
2602 } 2620 }
2603 else 2621 else
2604 [bcell setDrawsBackground:NO]; 2622 [tcell setDrawsBackground:NO];
2605 } 2623 }
2606 } 2624 }
2607 } 2625 }
2608 -(void)editCell:(id)input at:(int)row and:(int)col 2626 -(void)editCell:(id)input at:(int)row and:(int)col
2609 { 2627 {
2721 { 2739 {
2722 int x; 2740 int x;
2723 2741
2724 for(x=0;x<rowcount;x++) 2742 for(x=0;x<rowcount;x++)
2725 { 2743 {
2744 #ifdef BUILDING_FOR_YOSEMITE1
2745 NSTableCellView *cell = [self viewAtColumn:z row:x makeIfNecessary:YES];
2746 int thiswidth = NSWidth([cell frame]);
2747
2748 /* If on the first column... add up the heights */
2749 if(z == 0)
2750 cheight += NSHeight([cell frame]);
2751 #else
2726 NSCell *cell = [self preparedCellAtColumn:z row:x]; 2752 NSCell *cell = [self preparedCellAtColumn:z row:x];
2727 int thiswidth = [cell cellSize].width; 2753 int thiswidth = [cell cellSize].width;
2728 2754
2729 /* If on the first column... add up the heights */ 2755 /* If on the first column... add up the heights */
2730 if(z == 0) 2756 if(z == 0)
2738 if([image isMemberOfClass:[NSImage class]]) 2764 if([image isMemberOfClass:[NSImage class]])
2739 { 2765 {
2740 thiswidth = [image size].width; 2766 thiswidth = [image size].width;
2741 } 2767 }
2742 } 2768 }
2743 2769 #endif
2770
2744 if(thiswidth > width) 2771 if(thiswidth > width)
2745 { 2772 {
2746 width = thiswidth; 2773 width = thiswidth;
2747 } 2774 }
2748 } 2775 }
2779 NSCell *colcell = [column headerCell]; 2806 NSCell *colcell = [column headerCell];
2780 int width = [colcell cellSize].width; 2807 int width = [colcell cellSize].width;
2781 2808
2782 for(x=0;x<rowcount;x++) 2809 for(x=0;x<rowcount;x++)
2783 { 2810 {
2811 #ifdef BUILDING_FOR_YOSEMITE1
2812 NSTableCellView *cell = [self viewAtColumn:z row:x makeIfNecessary:YES];
2813 int thiswidth = NSWidth([cell frame]);
2814 #else
2784 NSCell *cell = [self preparedCellAtColumn:z row:x]; 2815 NSCell *cell = [self preparedCellAtColumn:z row:x];
2785 int thiswidth = [cell cellSize].width; 2816 int thiswidth = [cell cellSize].width;
2786 2817
2787 /* Check the image inside the cell to get its width */ 2818 /* Check the image inside the cell to get its width */
2788 if([cell isMemberOfClass:[NSImageCell class]]) 2819 if([cell isMemberOfClass:[NSImageCell class]])
2792 if([image isMemberOfClass:[NSImage class]]) 2823 if([image isMemberOfClass:[NSImage class]])
2793 { 2824 {
2794 thiswidth = [image size].width; 2825 thiswidth = [image size].width;
2795 } 2826 }
2796 } 2827 }
2797 2828 #endif
2829
2798 if(thiswidth > width) 2830 if(thiswidth > width)
2799 { 2831 {
2800 width = thiswidth; 2832 width = thiswidth;
2801 } 2833 }
2802 } 2834 }
2983 self = [super init]; 3015 self = [super init];
2984 3016
2985 if (self) 3017 if (self)
2986 { 3018 {
2987 treecol = [[NSTableColumn alloc] init]; 3019 treecol = [[NSTableColumn alloc] init];
3020 #ifndef BUILDING_FOR_YOSEMITE1
2988 DWImageAndTextCell *browsercell = [[[DWImageAndTextCell alloc] init] autorelease]; 3021 DWImageAndTextCell *browsercell = [[[DWImageAndTextCell alloc] init] autorelease];
2989 [treecol setDataCell:browsercell]; 3022 [treecol setDataCell:browsercell];
3023 #endif
2990 [self addTableColumn:treecol]; 3024 [self addTableColumn:treecol];
2991 [self setOutlineTableColumn:treecol]; 3025 [self setOutlineTableColumn:treecol];
2992 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(treeSelectionChanged:) name:NSOutlineViewSelectionDidChangeNotification object:self]; 3026 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(treeSelectionChanged:) name:NSOutlineViewSelectionDidChangeNotification object:self];
2993 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(treeItemExpanded:) name:NSOutlineViewItemDidExpandNotification object:self]; 3027 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(treeItemExpanded:) name:NSOutlineViewItemDidExpandNotification object:self];
2994 } 3028 }
3045 } 3079 }
3046 return @"List Root"; 3080 return @"List Root";
3047 } 3081 }
3048 -(void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item 3082 -(void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item
3049 { 3083 {
3084 #ifdef BUILDING_FOR_YOSEMITE1
3085 if([cell isMemberOfClass:[NSTableCellView class]])
3086 {
3087 NSMutableArray *this = (NSMutableArray *)item;
3088 NSImage *img = [this objectAtIndex:0];
3089 if([img isKindOfClass:[NSImage class]])
3090 [[(NSTableCellView*)cell imageView] setImage:img];
3091 }
3092 #else
3050 if([cell isMemberOfClass:[DWImageAndTextCell class]]) 3093 if([cell isMemberOfClass:[DWImageAndTextCell class]])
3051 { 3094 {
3052 NSMutableArray *this = (NSMutableArray *)item; 3095 NSMutableArray *this = (NSMutableArray *)item;
3053 NSImage *img = [this objectAtIndex:0]; 3096 NSImage *img = [this objectAtIndex:0];
3054 if([img isKindOfClass:[NSImage class]]) 3097 if([img isKindOfClass:[NSImage class]])
3055 [(DWImageAndTextCell*)cell setImage:img]; 3098 [(DWImageAndTextCell*)cell setImage:img];
3056 } 3099 }
3100 #endif
3057 } 3101 }
3058 -(BOOL)outlineView:(NSOutlineView *)outlineView shouldEditTableColumn:(NSTableColumn *)tableColumn item:(id)item { return NO; } 3102 -(BOOL)outlineView:(NSOutlineView *)outlineView shouldEditTableColumn:(NSTableColumn *)tableColumn item:(id)item { return NO; }
3059 -(void)addTree:(NSMutableArray *)item and:(NSMutableArray *)parent after:(NSMutableArray *)after 3103 -(void)addTree:(NSMutableArray *)item and:(NSMutableArray *)parent after:(NSMutableArray *)after
3060 { 3104 {
3061 NSMutableArray *children = data; 3105 NSMutableArray *children = data;
7384 [cont setup]; 7428 [cont setup];
7385 7429
7386 for(z=0;z<count;z++) 7430 for(z=0;z<count;z++)
7387 { 7431 {
7388 NSTableColumn *column = [[NSTableColumn alloc] init]; 7432 NSTableColumn *column = [[NSTableColumn alloc] init];
7433 #ifdef BUILDING_FOR_YOSEMITE1
7434 [column setTitle:[ NSString stringWithUTF8String:titles[z] ]];
7435 #else
7389 [[column headerCell] setStringValue:[ NSString stringWithUTF8String:titles[z] ]]; 7436 [[column headerCell] setStringValue:[ NSString stringWithUTF8String:titles[z] ]];
7390 if(flags[z] & DW_CFA_BITMAPORICON) 7437 if(flags[z] & DW_CFA_BITMAPORICON)
7391 { 7438 {
7392 NSImageCell *imagecell = [[NSImageCell alloc] init]; 7439 NSImageCell *imagecell = [[NSImageCell alloc] init];
7393 [column setDataCell:imagecell]; 7440 [column setDataCell:imagecell];
7397 { 7444 {
7398 DWImageAndTextCell *browsercell = [[DWImageAndTextCell alloc] init]; 7445 DWImageAndTextCell *browsercell = [[DWImageAndTextCell alloc] init];
7399 [column setDataCell:browsercell]; 7446 [column setDataCell:browsercell];
7400 [browsercell release]; 7447 [browsercell release];
7401 } 7448 }
7449 #endif
7402 /* Defaults to left justified so just handle right and center */ 7450 /* Defaults to left justified so just handle right and center */
7403 if(flags[z] & DW_CFA_RIGHT) 7451 if(flags[z] & DW_CFA_RIGHT)
7404 { 7452 {
7405 [(NSCell *)[column dataCell] setAlignment:DWTextAlignmentRight]; 7453 [(NSCell *)[column dataCell] setAlignment:DWTextAlignmentRight];
7406 [(NSCell *)[column headerCell] setAlignment:DWTextAlignmentRight]; 7454 [(NSCell *)[column headerCell] setAlignment:DWTextAlignmentRight];
7618 DW_FUNCTION_NO_RETURN(dw_filesystem_set_file) 7666 DW_FUNCTION_NO_RETURN(dw_filesystem_set_file)
7619 DW_FUNCTION_RESTORE_PARAM5(handle, HWND, pointer, void *, row, int, filename, char *, icon, HICN) 7667 DW_FUNCTION_RESTORE_PARAM5(handle, HWND, pointer, void *, row, int, filename, char *, icon, HICN)
7620 { 7668 {
7621 DW_FUNCTION_INIT; 7669 DW_FUNCTION_INIT;
7622 DWContainer *cont = handle; 7670 DWContainer *cont = handle;
7671 #ifdef BUILDING_FOR_YOSEMITE1
7672 NSTableCellView *browsercell;
7673 #else
7623 DWImageAndTextCell *browsercell; 7674 DWImageAndTextCell *browsercell;
7675 #endif
7624 int lastadd = 0; 7676 int lastadd = 0;
7625 7677
7626 /* If pointer is NULL we are getting a change request instead of set */ 7678 /* If pointer is NULL we are getting a change request instead of set */
7627 if(pointer) 7679 if(pointer)
7628 { 7680 {
7629 lastadd = [cont lastAddPoint]; 7681 lastadd = [cont lastAddPoint];
7630 } 7682 }
7631 7683
7684 #ifdef BUILDING_FOR_YOSEMITE1
7685 browsercell = [[[NSTableCellView alloc] init] autorelease];
7686 [[browsercell imageView] setImage:icon];
7687 [[browsercell textField] setStringValue:[ NSString stringWithUTF8String:filename ]];
7688 #else
7632 browsercell = [[[DWImageAndTextCell alloc] init] autorelease]; 7689 browsercell = [[[DWImageAndTextCell alloc] init] autorelease];
7633 [browsercell setImage:icon]; 7690 [browsercell setImage:icon];
7634 [browsercell setStringValue:[ NSString stringWithUTF8String:filename ]]; 7691 [browsercell setStringValue:[ NSString stringWithUTF8String:filename ]];
7692 #endif
7635 [cont editCell:browsercell at:(row+lastadd) and:0]; 7693 [cont editCell:browsercell at:(row+lastadd) and:0];
7636 [cont setNeedsDisplay:YES]; 7694 [cont setNeedsDisplay:YES];
7637 DW_FUNCTION_RETURN_NOTHING; 7695 DW_FUNCTION_RETURN_NOTHING;
7638 } 7696 }
7639 7697