# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1660736194 0 # Node ID 69e144d81f19a39dcff624b3b679e2ffc2cfee27 # Parent 22327163b35c274ec18f3ae482ca447de44c1fdf iOS: Rewrite DWContainer to use a single DWTableViewCell per row. Previously a cell was allocated for each row's column. Instead save an array of NSString and UIImages which can be displayed in the custom UITableViewCell based on the DW_FEATURE_CONTAINER_MODE setting. diff -r 22327163b35c -r 69e144d81f19 ios/dw.m --- a/ios/dw.m Tue Aug 16 17:24:29 2022 +0000 +++ b/ios/dw.m Wed Aug 17 11:36:34 2022 +0000 @@ -2333,15 +2333,22 @@ /* Subclass UITableViewCell so we can support multiple columns... * Enabled via the DW_FEATURE_CONTAINER_MODE feature setting. */ -@interface DWTableViewCell : UITableViewCell {} +@interface DWTableViewCell : UITableViewCell +{ + NSMutableArray *columndata; +} +-(void)setColumnData:(NSMutableArray *)input; +-(NSMutableArray *)columnData; @end @implementation DWTableViewCell --(void)dealloc { [super dealloc]; } +-(void)setColumnData:(NSMutableArray *)input { [columndata release]; columndata = input; [columndata retain]; } +-(NSMutableArray *)columnData { return columndata; } +-(void)dealloc { [columndata release]; [super dealloc]; } @end /* Create a tableview cell for containers using DW_CONTAINER_MODE_* or listboxes */ -DWTableViewCell *_dw_table_cell_view_new(UIImage *icon, NSString *text) +DWTableViewCell *_dw_table_cell_view_new(UIImage *icon, NSString *text, NSMutableArray *columndata) { DWTableViewCell *browsercell = [[DWTableViewCell alloc] init]; [browsercell setAutoresizesSubviews:YES]; @@ -2350,6 +2357,8 @@ [[browsercell imageView] setImage:icon]; if(text) [[browsercell textLabel] setText:text]; + if(columndata) + [browsercell setColumnData:columndata]; return browsercell; } @@ -2380,13 +2389,14 @@ -(void)setUserdata:(void *)input; -(void)setFilesystem:(int)input; -(int)filesystem; --(int)addRow:(NSArray *)input; +-(int)addRow:(DWTableViewCell *)input; -(int)addRows:(int)number; --(void)editCell:(id)input at:(int)row and:(int)col; +-(void)editCell:(id)input at:(int)row; -(void)removeRow:(int)row; -(void)setRow:(int)row title:(const char *)input; -(void *)getRowTitle:(int)row; --(id)getRow:(int)row and:(int)col; +-(id)getRow:(int)row; +-(NSMutableArray *)getColumns; -(int)cellType:(int)col; -(int)lastAddPoint; -(int)lastQueryPoint; @@ -2402,18 +2412,13 @@ { /* Ignoring section for now, everything in one section */ if(tvcols && data) - { - int cols = (int)[tvcols count]; - int total = (int)[data count]; - if(cols && total) - return total / cols; - } + return [data count]; return 0; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { /* Not reusing cell views, so get the cell from our array */ - int index = (int)(indexPath.row * [tvcols count]); + int index = (int)indexPath.row; id celldata = [data objectAtIndex:index]; /* The data is already a NSTableCellView so just return that */ @@ -2520,30 +2525,27 @@ [self refreshColors]; } -(void)viewDidChangeEffectiveAppearance { [self checkDark]; } --(int)insertRow:(NSArray *)input at:(int)index +-(int)insertRow:(DWTableViewCell *)input at:(int)index { if(data) { - unsigned long start = [tvcols count] * index; - NSIndexSet *set = [[NSIndexSet alloc] initWithIndexesInRange:NSMakeRange(start, start + [tvcols count])]; if(index < iLastAddPoint) { iLastAddPoint++; } - [data insertObjects:input atIndexes:set]; + [data insertObject:input atIndex:index]; [titles insertPointer:NULL atIndex:index]; [rowdatas insertPointer:NULL atIndex:index]; - [set release]; return (int)[titles count]; } return 0; } --(int)addRow:(NSArray *)input +-(int)addRow:(DWTableViewCell *)input { if(data) { iLastAddPoint = (int)[titles count]; - [data addObjectsFromArray:input]; + [data addObject:input]; [titles addPointer:NULL]; [rowdatas addPointer:NULL]; return (int)[titles count]; @@ -2554,17 +2556,13 @@ { if(tvcols) { - int count = (int)(number * [tvcols count]); int z; iLastAddPoint = (int)[titles count]; - for(z=0;z -1) { return [titles pointerAtIndex:row]; } return NULL; } -(void *)getRowData:(int)row { if(rowdatas && row > -1) { return [rowdatas pointerAtIndex:row]; } return NULL; } --(id)getRow:(int)row and:(int)col { if(data && [data count]) { int index = (int)(row * [tvcols count]) + col; return [data objectAtIndex:index]; } return nil; } +-(id)getRow:(int)row { if(data && [data count]) { return [data objectAtIndex:row]; } return nil; } +-(NSMutableArray *)getColumns { return tvcols; } -(int)cellType:(int)col { return [[types objectAtIndex:col] intValue]; } -(int)lastAddPoint { return iLastAddPoint; } -(int)lastQueryPoint { return iLastQueryPoint; } @@ -5544,9 +5534,8 @@ { DWContainer *cont = handle; NSString *nstr = [NSString stringWithUTF8String:text]; - NSArray *newrow = [NSArray arrayWithObject:_dw_table_cell_view_new(nil, nstr)]; - - [cont addRow:newrow]; + + [cont addRow:_dw_table_cell_view_new(nil, nstr, nil)]; [cont reloadData]; [cont setNeedsDisplay]; } @@ -5578,9 +5567,8 @@ { DWContainer *cont = handle; NSString *nstr = [NSString stringWithUTF8String:text]; - NSArray *newrow = [NSArray arrayWithObject:_dw_table_cell_view_new(nil, nstr)]; - - [cont insertRow:newrow at:pos]; + + [cont insertRow:_dw_table_cell_view_new(nil, nstr, nil) at:pos]; [cont reloadData]; [cont setNeedsDisplay]; } @@ -5622,9 +5610,8 @@ for(z=0;z= capacity) + capacity = column + 1; + + if(!cd) + { + cd = [NSMutableArray arrayWithCapacity:capacity]; + [cell setColumnData:cd]; + } + if(cd) + { + while([cd count] <= column) + [cd addObject:[NSNull null]]; + [cd replaceObjectAtIndex:column withObject:(text ? text : icon)]; + } + } + } + else + { + NSMutableArray *cd = [NSMutableArray arrayWithCapacity:(capacity > column ? capacity : column + 1)]; + if(cd) + [cd replaceObjectAtIndex:column withObject:(text ? text : icon)]; + /* Otherwise replace it with a new cell */ + [cont editCell:_dw_table_cell_view_new(icon, text, cd) at:(row+lastadd)]; + } [cont setNeedsDisplay]; DW_FUNCTION_RETURN_NOTHING; } @@ -7304,7 +7320,7 @@ if(pointer) lastadd = [cont lastAddPoint]; - id object = [cont getRow:(row+lastadd) and:0]; + id object = [cont getRow:(row+lastadd)]; /* If it is a cell, change the content of the cell */ if([object isMemberOfClass:[DWTableViewCell class]]) @@ -7317,7 +7333,7 @@ [[cell textLabel] setText:text]; } else /* Otherwise replace it with a new cell */ - [cont editCell:_dw_table_cell_view_new(icon, text) at:(row+lastadd) and:0]; + [cont editCell:_dw_table_cell_view_new(icon, text, nil) at:(row+lastadd)]; [cont setNeedsDisplay]; DW_FUNCTION_RETURN_NOTHING; }