Mercurial > dwindows
comparison mac/dw.m @ 2180:bfc089ab053b
Mac: Simplify the code to return NSTableCellView since we aren't using the
built in caching mechanism. Move the row background color code for striping
into the NSTableRowView instead of using the NSTextFields built into
NSTableCellView.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Tue, 13 Oct 2020 05:58:09 +0000 |
parents | bd6146d4bdbc |
children | fe54e67cec3b |
comparison
equal
deleted
inserted
replaced
2179:bd6146d4bdbc | 2180:bfc089ab053b |
---|---|
2463 -(void)keyUp:(NSEvent *)theEvent; | 2463 -(void)keyUp:(NSEvent *)theEvent; |
2464 -(void)tableView:(NSTableView *)tableView didClickTableColumn:(NSTableColumn *)tableColumn; | 2464 -(void)tableView:(NSTableView *)tableView didClickTableColumn:(NSTableColumn *)tableColumn; |
2465 -(void)selectionChanged:(id)sender; | 2465 -(void)selectionChanged:(id)sender; |
2466 -(NSMenu *)menuForEvent:(NSEvent *)event; | 2466 -(NSMenu *)menuForEvent:(NSEvent *)event; |
2467 #ifdef BUILDING_FOR_YOSEMITE | 2467 #ifdef BUILDING_FOR_YOSEMITE |
2468 -(void)tableView:(NSTableView *)tableView didAddRowView:(NSTableRowView *)rowView forRow:(NSInteger)row; | |
2468 -(NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row; | 2469 -(NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row; |
2469 #else | 2470 #else |
2470 -(void)tableView:(NSTableView *)tableView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row; | 2471 -(void)tableView:(NSTableView *)tableView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row; |
2471 #endif | 2472 #endif |
2472 @end | 2473 @end |
2613 return (int)[titles count]; | 2614 return (int)[titles count]; |
2614 } | 2615 } |
2615 return 0; | 2616 return 0; |
2616 } | 2617 } |
2617 #ifdef BUILDING_FOR_YOSEMITE | 2618 #ifdef BUILDING_FOR_YOSEMITE |
2619 -(void)tableView:(NSTableView *)tableView didAddRowView:(NSTableRowView *)rowView forRow:(NSInteger)row | |
2620 { | |
2621 /* Handle drawing alternating row colors if enabled */ | |
2622 if ((row % 2) == 0) | |
2623 { | |
2624 if(evencolor) | |
2625 [rowView setBackgroundColor:evencolor]; | |
2626 } | |
2627 else | |
2628 { | |
2629 if(oddcolor) | |
2630 [rowView setBackgroundColor:oddcolor]; | |
2631 } | |
2632 } | |
2618 -(NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row; | 2633 -(NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row; |
2619 { | 2634 { |
2620 /* Get an existing cell with the MyView identifier if it exists */ | 2635 /* Get an existing cell with the MyView identifier if it exists */ |
2621 NSTableCellView *result = [tableView makeViewWithIdentifier:tableColumn.identifier owner:self]; | |
2622 int index = (int)(row * [tvcols count]) + (int)[tvcols indexOfObject:tableColumn]; | 2636 int index = (int)(row * [tvcols count]) + (int)[tvcols indexOfObject:tableColumn]; |
2623 id celldata = [data objectAtIndex:index]; | 2637 id celldata = [data objectAtIndex:index]; |
2624 NSTextFieldCell *tcell = nil; | 2638 |
2625 | 2639 /* The data is already a NSTableCellView so just return that */ |
2626 /* There is no existing cell to reuse so create a new one */ | 2640 if([celldata isMemberOfClass:[NSTableCellView class]]) |
2627 if(result == nil) | 2641 { |
2628 { | 2642 NSTableCellView *result = celldata; |
2629 /* The data is already a NSTableCellView so just return that */ | 2643 |
2630 if([celldata isMemberOfClass:[NSTableCellView class]]) | 2644 _dw_table_cell_view_layout(result); |
2631 result = celldata; | 2645 |
2632 else | 2646 /* Return the result */ |
2633 { | 2647 return result; |
2634 /* Create the new NSTableCellView with a frame of the {0,0} with the width of the table. | 2648 } |
2635 * Note that the height of the frame is not really relevant, because the row height will modify the height. | 2649 return nil; |
2636 */ | |
2637 result = [[NSTableCellView alloc] init]; | |
2638 | |
2639 /* The identifier of the NSTextField instance is set to MyView. | |
2640 * This allows the cell to be reused. | |
2641 */ | |
2642 [result setIdentifier:tableColumn.identifier]; | |
2643 } | |
2644 } | |
2645 | |
2646 _dw_table_cell_view_layout(result); | |
2647 | |
2648 tcell = [[result textField] cell]; | |
2649 | |
2650 /* Handle drawing alternating row colors if enabled */ | |
2651 if ((row % 2) == 0) | |
2652 { | |
2653 if(evencolor) | |
2654 { | |
2655 [tcell setDrawsBackground:YES]; | |
2656 [tcell setBackgroundColor:evencolor]; | |
2657 } | |
2658 else | |
2659 [tcell setDrawsBackground:NO]; | |
2660 } | |
2661 else | |
2662 { | |
2663 if(oddcolor) | |
2664 { | |
2665 [tcell setDrawsBackground:YES]; | |
2666 [tcell setBackgroundColor:oddcolor]; | |
2667 } | |
2668 else | |
2669 [tcell setDrawsBackground:NO]; | |
2670 } | |
2671 | |
2672 /* Return the result */ | |
2673 return result; | |
2674 } | 2650 } |
2675 #else | 2651 #else |
2676 -(void)tableView:(NSTableView *)tableView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row | 2652 -(void)tableView:(NSTableView *)tableView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row |
2677 { | 2653 { |
2678 DWImageAndTextCell *bcell = cell, *tcell = cell; | 2654 DWImageAndTextCell *bcell = cell, *tcell = cell; |