changeset 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
files mac/dw.m
diffstat 1 files changed, 24 insertions(+), 48 deletions(-) [+]
line wrap: on
line diff
--- a/mac/dw.m	Tue Oct 13 01:51:40 2020 +0000
+++ b/mac/dw.m	Tue Oct 13 05:58:09 2020 +0000
@@ -2465,6 +2465,7 @@
 -(void)selectionChanged:(id)sender;
 -(NSMenu *)menuForEvent:(NSEvent *)event;
 #ifdef BUILDING_FOR_YOSEMITE
+-(void)tableView:(NSTableView *)tableView didAddRowView:(NSTableRowView *)rowView forRow:(NSInteger)row;
 -(NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row;
 #else
 -(void)tableView:(NSTableView *)tableView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row;
@@ -2615,62 +2616,37 @@
     return 0;
 }
 #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]) + (int)[tvcols indexOfObject:tableColumn];
-    id celldata = [data objectAtIndex:index];
-    NSTextFieldCell *tcell = nil;
-    
-    /* 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];
-        }
-    }
-
-    _dw_table_cell_view_layout(result);
-    
-    tcell = [[result textField] cell];
-    
+-(void)tableView:(NSTableView *)tableView didAddRowView:(NSTableRowView *)rowView forRow:(NSInteger)row
+{
     /* Handle drawing alternating row colors if enabled */
     if ((row % 2) == 0)
     {
         if(evencolor)
-        {
-            [tcell setDrawsBackground:YES];
-            [tcell setBackgroundColor:evencolor];
-        }
-        else
-            [tcell setDrawsBackground:NO];
+            [rowView setBackgroundColor:evencolor];
     }
     else
     {
         if(oddcolor)
-        {
-            [tcell setDrawsBackground:YES];
-            [tcell setBackgroundColor:oddcolor];
-        }
-        else
-            [tcell setDrawsBackground:NO];
-    }
-    
-    /* Return the result */
-    return result;
+            [rowView setBackgroundColor:oddcolor];
+    }
+}
+-(NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row;
+{
+    /* Get an existing cell with the MyView identifier if it exists */
+    int index = (int)(row * [tvcols count]) + (int)[tvcols indexOfObject:tableColumn];
+    id celldata = [data objectAtIndex:index];
+
+    /* The data is already a NSTableCellView so just return that */
+    if([celldata isMemberOfClass:[NSTableCellView class]])
+    {
+        NSTableCellView *result = celldata;
+
+        _dw_table_cell_view_layout(result);
+            
+        /* Return the result */
+        return result;
+    }
+    return nil;
 }
 #else
 -(void)tableView:(NSTableView *)tableView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row