comparison ios/dw.m @ 2387:deb2345f4518

iOS: Implement the UITableViewDataSource protocol so DWContainer doesn't crash. Remove the old NSTableView code that was there for reference.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 23 Mar 2021 22:03:09 +0000
parents a126b04b9996
children d84cd4227b21
comparison
equal deleted inserted replaced
2386:47b214db2465 2387:deb2345f4518
1459 unsigned long _DW_COLOR_ROW_ODD, _DW_COLOR_ROW_EVEN; 1459 unsigned long _DW_COLOR_ROW_ODD, _DW_COLOR_ROW_EVEN;
1460 int lastAddPoint, lastQueryPoint; 1460 int lastAddPoint, lastQueryPoint;
1461 id scrollview; 1461 id scrollview;
1462 int filesystem; 1462 int filesystem;
1463 } 1463 }
1464 -(NSInteger)numberOfRowsInTableView:(UITableView *)aTable; 1464 -(NSInteger)tableView:(UITableView *)aTable numberOfRowsInSection:(NSInteger)section;
1465 #if 0 /* TODO: Switch to columnless versions */ 1465 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
1466 -(id)tableView:(UITableView *)aTable objectValueForTableColumn:(NSTableColumn *)aCol row:(NSInteger)aRow; 1466 -(void)tableView: (UITableView*)tableView willDisplayCell: (UITableViewCell*)cell forRowAtIndexPath: (NSIndexPath*)indexPath;
1467 -(BOOL)tableView:(UITableView *)aTableView shouldEditTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex; 1467 -(void)addColumn:(NSString *)input andType:(int)type;
1468 -(void)tableView:(UITableView *)tableView didAddRowView:(UITableRowView *)rowView forRow:(NSInteger)row; 1468 -(NSString *)getColumn:(int)col;
1469 -(UIView *)tableView:(UITableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row;
1470 #endif
1471 -(void *)userdata; 1469 -(void *)userdata;
1472 -(void)setUserdata:(void *)input; 1470 -(void)setUserdata:(void *)input;
1473 -(void)setFilesystem:(int)input; 1471 -(void)setFilesystem:(int)input;
1474 -(int)filesystem; 1472 -(int)filesystem;
1475 -(id)scrollview; 1473 -(id)scrollview;
1493 -(void)selectionChanged:(id)sender; 1491 -(void)selectionChanged:(id)sender;
1494 -(DWMenu *)menuForEvent:(UIEvent *)event; 1492 -(DWMenu *)menuForEvent:(UIEvent *)event;
1495 @end 1493 @end
1496 1494
1497 @implementation DWContainer 1495 @implementation DWContainer
1498 -(NSInteger)numberOfRowsInTableView:(UITableView *)aTable 1496 -(NSInteger)tableView:(UITableView *)aTable numberOfRowsInSection:(NSInteger)section
1499 { 1497 {
1498 /* Ignoring section for now, everything in one section */
1500 if(tvcols && data) 1499 if(tvcols && data)
1501 { 1500 {
1502 int cols = (int)[tvcols count]; 1501 int cols = (int)[tvcols count];
1503 int total = (int)[data count]; 1502 int total = (int)[data count];
1504 if(cols && total) 1503 if(cols && total)
1506 return total / cols; 1505 return total / cols;
1507 } 1506 }
1508 } 1507 }
1509 return 0; 1508 return 0;
1510 } 1509 }
1511 #if 0 /* TODO: Switch to columnless versions */ 1510 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
1512 -(id)tableView:(UITableView *)aTable objectValueForTableColumn:(NSTableColumn *)aCol row:(NSInteger)aRow
1513 {
1514 if(tvcols && data)
1515 {
1516 int z, col = -1;
1517 int count = (int)[tvcols count];
1518
1519 for(z=0;z<count;z++)
1520 {
1521 if([tvcols objectAtIndex:z] == aCol)
1522 {
1523 col = z;
1524 break;
1525 }
1526 }
1527 if(col != -1)
1528 {
1529 int index = (int)(aRow * count) + col;
1530 if(index < [data count])
1531 {
1532 id this = [data objectAtIndex:index];
1533 return ([this isKindOfClass:[NSNull class]]) ? nil : this;
1534 }
1535 }
1536 }
1537 return nil;
1538 }
1539 -(BOOL)tableView:(UITableView *)aTableView shouldEditTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex { return NO; }
1540 -(void)tableView:(UITableView *)tableView didAddRowView:(UITableRowView *)rowView forRow:(NSInteger)row
1541 {
1542 /* Handle drawing alternating row colors if enabled */
1543 if ((row % 2) == 0)
1544 {
1545 if(evencolor)
1546 [rowView setBackgroundColor:evencolor];
1547 }
1548 else
1549 {
1550 if(oddcolor)
1551 [rowView setBackgroundColor:oddcolor];
1552 }
1553 }
1554 -(UIView *)tableView:(UITableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row;
1555 { 1511 {
1556 /* Not reusing cell views, so get the cell from our array */ 1512 /* Not reusing cell views, so get the cell from our array */
1557 int index = (int)(row * [tvcols count]) + (int)[tvcols indexOfObject:tableColumn]; 1513 int index = (int)(indexPath.row * [tvcols count]);
1558 id celldata = [data objectAtIndex:index]; 1514 id celldata = [data objectAtIndex:index];
1559 1515
1560 /* The data is already a NSTableCellView so just return that */ 1516 /* The data is already a NSTableCellView so just return that */
1561 if([celldata isMemberOfClass:[UITableViewCell class]]) 1517 if([celldata isMemberOfClass:[UITableViewCell class]])
1562 { 1518 {
1580 /* Return the result */ 1536 /* Return the result */
1581 return result; 1537 return result;
1582 } 1538 }
1583 return nil; 1539 return nil;
1584 } 1540 }
1585 -(void)tableView:(NSTableView *)tableView didClickTableColumn:(NSTableColumn *)tableColumn 1541 -(void)tableView: (UITableView*)tableView willDisplayCell: (UITableViewCell*)cell forRowAtIndexPath: (NSIndexPath*)indexPath
1586 { 1542 {
1587 NSUInteger index = [tvcols indexOfObject:tableColumn]; 1543 if(indexPath.row % 2 == 0)
1588 1544 {
1589 /* Handler for column click class */ 1545 if(evencolor)
1590 _event_handler(self, (UIEvent *)index, 17); 1546 [cell setBackgroundColor:evencolor];
1591 } 1547 }
1592 #endif 1548 else
1549 {
1550 if(oddcolor)
1551 [cell setBackgroundColor:oddcolor];
1552 }
1553 }
1554 -(void)addColumn:(NSString *)input andType:(int)type { if(tvcols) { [tvcols addObject:input]; [types addObject:[NSNumber numberWithInt:type]]; } }
1555 -(NSString *)getColumn:(int)col { if(tvcols) { return [tvcols objectAtIndex:col]; } return nil; }
1593 -(void *)userdata { return userdata; } 1556 -(void *)userdata { return userdata; }
1594 -(void)setUserdata:(void *)input { userdata = input; } 1557 -(void)setUserdata:(void *)input { userdata = input; }
1595 -(void)setFilesystem:(int)input { filesystem = input; } 1558 -(void)setFilesystem:(int)input { filesystem = input; }
1596 -(int)filesystem { return filesystem; } 1559 -(int)filesystem { return filesystem; }
1597 -(id)scrollview { return scrollview; } 1560 -(id)scrollview { return scrollview; }
1737 } 1700 }
1738 } 1701 }
1739 -(void)setRowData:(int)row title:(void *)input { if(rowdatas && input) { [rowdatas replacePointerAtIndex:row withPointer:input]; } } 1702 -(void)setRowData:(int)row title:(void *)input { if(rowdatas && input) { [rowdatas replacePointerAtIndex:row withPointer:input]; } }
1740 -(void *)getRowTitle:(int)row { if(titles && row > -1) { return [titles pointerAtIndex:row]; } return NULL; } 1703 -(void *)getRowTitle:(int)row { if(titles && row > -1) { return [titles pointerAtIndex:row]; } return NULL; }
1741 -(void *)getRowData:(int)row { if(rowdatas && row > -1) { return [rowdatas pointerAtIndex:row]; } return NULL; } 1704 -(void *)getRowData:(int)row { if(rowdatas && row > -1) { return [rowdatas pointerAtIndex:row]; } return NULL; }
1742 -(id)getRow:(int)row and:(int)col { if(data) { int index = (int)(row * [tvcols count]) + col; return [data objectAtIndex:index]; } return nil; } 1705 -(id)getRow:(int)row and:(int)col { if(data && [data count]) { int index = (int)(row * [tvcols count]) + col; return [data objectAtIndex:index]; } return nil; }
1743 -(int)cellType:(int)col { return [[types objectAtIndex:col] intValue]; } 1706 -(int)cellType:(int)col { return [[types objectAtIndex:col] intValue]; }
1744 -(int)lastAddPoint { return lastAddPoint; } 1707 -(int)lastAddPoint { return lastAddPoint; }
1745 -(int)lastQueryPoint { return lastQueryPoint; } 1708 -(int)lastQueryPoint { return lastQueryPoint; }
1746 -(void)setLastQueryPoint:(int)input { lastQueryPoint = input; } 1709 -(void)setLastQueryPoint:(int)input { lastQueryPoint = input; }
1747 -(void)clear 1710 -(void)clear
5298 5261
5299 [cont setup]; 5262 [cont setup];
5300 5263
5301 for(z=0;z<count;z++) 5264 for(z=0;z<count;z++)
5302 { 5265 {
5303 #if 0 /* TODO: Convert this to simulate columns */ 5266 /* Even though we don't have columns on iOS, we save the data...
5267 * So we can simulate columns when displaying the data in the list.
5268 */
5304 NSString *title = [NSString stringWithUTF8String:titles[z]]; 5269 NSString *title = [NSString stringWithUTF8String:titles[z]];
5305 /* Defaults to left justified so just handle right and center */ 5270
5306 #endif 5271 [cont addColumn:title andType:(int)flags[z]];
5307 } 5272 }
5308 DW_FUNCTION_RETURN_THIS(retval); 5273 DW_FUNCTION_RETURN_THIS(retval);
5309 } 5274 }
5310 5275
5311 /* 5276 /*