# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1602452621 0 # Node ID f93d29310b147ee2e3b40f7ed15a770200d594aa # Parent 8a609f6748e76558b3def0ef5c8474005652e4d9 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. diff -r 8a609f6748e7 -r f93d29310b14 mac/dw.m --- a/mac/dw.m Sun Oct 11 09:51:45 2020 +0000 +++ b/mac/dw.m Sun Oct 11 21:43:41 2020 +0000 @@ -2238,7 +2238,7 @@ -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; } @end -#ifndef BUILDING_FOR_YOSEMITE1 +#ifndef BUILDING_FOR_YOSEMITE /* Subclass NSTextFieldCell for displaying image and text */ @interface DWImageAndTextCell : NSTextFieldCell { @@ -2391,7 +2391,6 @@ -(NSTableColumn *)getColumn:(int)col; -(int)addRow:(NSArray *)input; -(int)addRows:(int)number; --(void)tableView:(NSTableView *)tableView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row; -(void)editCell:(id)input at:(int)row and:(int)col; -(void)removeRow:(int)row; -(void)setRow:(int)row title:(const char *)input; @@ -2411,8 +2410,10 @@ -(void)tableView:(NSTableView *)tableView didClickTableColumn:(NSTableColumn *)tableColumn; -(void)selectionChanged:(id)sender; -(NSMenu *)menuForEvent:(NSEvent *)event; -#ifdef BUILDING_FOR_LION1 +#ifdef BUILDING_FOR_YOSEMITE -(NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row; +#else +-(void)tableView:(NSTableView *)tableView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row; #endif @end @@ -2457,17 +2458,6 @@ } return nil; } -#ifdef BUILDING_FOR_LION1 --(NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row -{ - ItemCellView *result = [tableView makeViewWithIdentifier:tableColumn.identifier owner:self]; - Item *item = [self.items objectAtIndex:row]; - result.imageView.image = item.itemIcon; - result.textField.stringValue = item.itemDisplayName; - result.detailTextField.stringValue = item.itemKind; - return result; -} -#endif -(BOOL)tableView:(NSTableView *)aTableView shouldEditTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex { return NO; } -(void *)userdata { return userdata; } -(void)setUserdata:(void *)input { userdata = input; } @@ -2570,22 +2560,72 @@ } return 0; } --(void)tableView:(NSTableView *)tableView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row -{ -#ifdef BUILDING_FOR_YOSEMITE1 - NSTableCellView *bcell = cell; - NSTextField *tcell = nil; +#ifdef BUILDING_FOR_YOSEMITE +-(NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row; +{ + /* Get an existing cell with the MyView identifier if it exists */ + NSTableCellView *result = [tableView makeViewWithIdentifier:tableColumn.identifier owner:self]; + int index = (int)(row * [tvcols count]); + id celldata = [data objectAtIndex:index]; + + /* There is no existing cell to reuse so create a new one */ + if(result == nil) + { + /* The data is already a NSTableCellView so just return that */ + if([celldata isMemberOfClass:[NSTableCellView class]]) + result = celldata; + else + { + /* Create the new NSTableCellView with a frame of the {0,0} with the width of the table. + * Note that the height of the frame is not really relevant, because the row height will modify the height. + */ + result = [[NSTableCellView alloc] init]; + + /* The identifier of the NSTextField instance is set to MyView. + * This allows the cell to be reused. + */ + [result setIdentifier:tableColumn.identifier]; + } + } + + /* result is now guaranteed to be valid, either as a reused cell + * or as a new cell, so set the text or image + */ + NSTextFieldCell *tcell = [[result textField] cell]; - /* Handle drawing image and text if necessary */ - if([cell isMemberOfClass:[NSTableCellView class]]) - { - int index = (int)(row * [tvcols count]); - NSTableCellView *browsercell = [data objectAtIndex:index]; - NSImage *img = [[browsercell imageView] image]; - [[bcell imageView] setImage:img]; - tcell = [bcell textField]; - } + if([celldata isMemberOfClass:[NSImage class]]) + [[result imageView] setImage:celldata]; + if([celldata isKindOfClass:[NSString class]]) + [[result textField] setStringValue:celldata]; + + /* Handle drawing alternating row colors if enabled */ + if ((row % 2) == 0) + { + if(evencolor) + { + [tcell setDrawsBackground:YES]; + [tcell setBackgroundColor:evencolor]; + } + else + [tcell setDrawsBackground:NO]; + } + else + { + if(oddcolor) + { + [tcell setDrawsBackground:YES]; + [tcell setBackgroundColor:oddcolor]; + } + else + [tcell setDrawsBackground:NO]; + } + + /* Return the result */ + return result; +} #else +-(void)tableView:(NSTableView *)tableView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row +{ DWImageAndTextCell *bcell = cell, *tcell = cell; /* Handle drawing image and text if necessary */ @@ -2596,7 +2636,6 @@ NSImage *img = [browsercell image]; [bcell setImage:img]; } -#endif if([tcell isKindOfClass:[NSTextFieldCell class]]) { @@ -2623,6 +2662,7 @@ } } } +#endif -(void)editCell:(id)input at:(int)row and:(int)col { if(tvcols) @@ -2741,7 +2781,7 @@ for(x=0;x