Mercurial > dwindows
comparison mac/dw.m @ 2176:288416bd6d3e
Mac: Fixes for display using NSView based NSTableView.
Not perfect yet, seems to be issues with the caching of the
NSTableCellViews and the visuals are not quite what they should be... the
NSTextFields are styled not how I expected. Also I fixed the display by
forcing the layout of the NSTableCellView using 16x16 icon size and 20 pixel
row heights. There may be a better way to calculate things automatically.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Mon, 12 Oct 2020 09:17:14 +0000 |
parents | e2c00a7a74a1 |
children | 7213842143f5 |
comparison
equal
deleted
inserted
replaced
2175:e2c00a7a74a1 | 2176:288416bd6d3e |
---|---|
2357 return cellSize; | 2357 return cellSize; |
2358 } | 2358 } |
2359 @end | 2359 @end |
2360 #endif | 2360 #endif |
2361 | 2361 |
2362 #define _DW_CONTAINER_ICON_WIDTH 16 | |
2363 #define _DW_CONTAINER_ICON_HEIGHT 16 | |
2364 #define _DW_CONTAINER_ROW_HEIGHT 20 | |
2365 | |
2362 /* Subclass for a Container/List type */ | 2366 /* Subclass for a Container/List type */ |
2363 @interface DWContainer : NSTableView | 2367 @interface DWContainer : NSTableView |
2364 #ifdef BUILDING_FOR_SNOW_LEOPARD | 2368 #ifdef BUILDING_FOR_SNOW_LEOPARD |
2365 <NSTableViewDataSource,NSTableViewDelegate> | 2369 <NSTableViewDataSource,NSTableViewDelegate> |
2366 #endif | 2370 #endif |
2563 #ifdef BUILDING_FOR_YOSEMITE | 2567 #ifdef BUILDING_FOR_YOSEMITE |
2564 -(NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row; | 2568 -(NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row; |
2565 { | 2569 { |
2566 /* Get an existing cell with the MyView identifier if it exists */ | 2570 /* Get an existing cell with the MyView identifier if it exists */ |
2567 NSTableCellView *result = [tableView makeViewWithIdentifier:tableColumn.identifier owner:self]; | 2571 NSTableCellView *result = [tableView makeViewWithIdentifier:tableColumn.identifier owner:self]; |
2568 int index = (int)(row * [tvcols count]); | 2572 int index = (int)(row * [tvcols count]) + (int)[tvcols indexOfObject:tableColumn]; |
2569 id celldata = [data objectAtIndex:index]; | 2573 id celldata = [data objectAtIndex:index]; |
2570 NSTextFieldCell *tcell = nil; | 2574 NSTextFieldCell *tcell = nil; |
2571 | 2575 |
2572 /* There is no existing cell to reuse so create a new one */ | 2576 /* There is no existing cell to reuse so create a new one */ |
2573 if(result == nil) | 2577 if(result == nil) |
2574 { | 2578 { |
2575 /* The data is already a NSTableCellView so just return that */ | 2579 /* The data is already a NSTableCellView so just return that */ |
2576 if([celldata isMemberOfClass:[NSTableCellView class]]) | 2580 if([celldata isMemberOfClass:[NSTableCellView class]]) |
2577 { | 2581 { |
2578 result = celldata; | 2582 result = celldata; |
2579 [result setFrame:NSMakeRect(0,0,tableColumn.width,0)]; | 2583 [result setFrame:NSMakeRect(0,0,tableColumn.width,_DW_CONTAINER_ROW_HEIGHT)]; |
2580 [[result textField] setFrame:result.frame]; | 2584 [[result textField] setFrame:result.frame]; |
2581 } | 2585 } |
2582 else | 2586 else |
2583 { | 2587 { |
2584 /* Create the new NSTableCellView with a frame of the {0,0} with the width of the table. | 2588 /* Create the new NSTableCellView with a frame of the {0,0} with the width of the table. |
2585 * Note that the height of the frame is not really relevant, because the row height will modify the height. | 2589 * Note that the height of the frame is not really relevant, because the row height will modify the height. |
2586 */ | 2590 */ |
2587 result = [[NSTableCellView alloc] initWithFrame:NSMakeRect(0,0,tableColumn.width,0)]; | 2591 result = [[NSTableCellView alloc] initWithFrame:NSMakeRect(0,0,tableColumn.width,_DW_CONTAINER_ROW_HEIGHT)]; |
2588 | 2592 |
2589 /* The identifier of the NSTextField instance is set to MyView. | 2593 /* The identifier of the NSTextField instance is set to MyView. |
2590 * This allows the cell to be reused. | 2594 * This allows the cell to be reused. |
2591 */ | 2595 */ |
2592 [result setIdentifier:tableColumn.identifier]; | 2596 [result setIdentifier:tableColumn.identifier]; |
2599 if([celldata isMemberOfClass:[NSImage class]]) | 2603 if([celldata isMemberOfClass:[NSImage class]]) |
2600 { | 2604 { |
2601 NSImageView *iv = [result imageView]; | 2605 NSImageView *iv = [result imageView]; |
2602 if(!iv) | 2606 if(!iv) |
2603 { | 2607 { |
2604 iv = [[[NSImageView alloc] initWithFrame:result.frame] autorelease]; | 2608 iv = [[[NSImageView alloc] init] autorelease]; |
2605 [result setImageView:iv]; | 2609 [result setImageView:iv]; |
2606 [result addSubview:iv]; | 2610 [result addSubview:iv]; |
2607 } | 2611 } |
2608 [iv setImage:celldata]; | 2612 [iv setImage:celldata]; |
2609 } | 2613 } |
2610 if([celldata isKindOfClass:[NSString class]]) | 2614 if([celldata isKindOfClass:[NSString class]]) |
2611 { | 2615 { |
2612 NSTextField *tf = [result textField]; | 2616 NSTextField *tf = [result textField]; |
2613 if(!tf) | 2617 if(!tf) |
2614 { | 2618 { |
2615 tf = [[[NSTextField alloc] initWithFrame:result.frame] autorelease]; | 2619 tf = [[[NSTextField alloc] init] autorelease]; |
2616 [result setTextField:tf]; | 2620 [result setTextField:tf]; |
2617 [result addSubview:tf]; | 2621 [result addSubview:tf]; |
2618 } | 2622 } |
2619 [tf setStringValue:celldata]; | 2623 [tf setStringValue:celldata]; |
2620 } | 2624 } |
2625 /* Adjust the frames of the textField and imageView */ | |
2626 if([result imageView]) | |
2627 { | |
2628 NSRect rect = NSMakeRect((_DW_CONTAINER_ROW_HEIGHT - _DW_CONTAINER_ICON_WIDTH) / 2, | |
2629 (_DW_CONTAINER_ROW_HEIGHT - _DW_CONTAINER_ICON_HEIGHT) / 2, | |
2630 _DW_CONTAINER_ICON_WIDTH,_DW_CONTAINER_ICON_HEIGHT); | |
2631 [[result imageView] setFrame:rect]; | |
2632 } | |
2633 if([result textField]) | |
2634 { | |
2635 NSRect rect = result.frame; | |
2636 | |
2637 /* Adjust the rect to allow space for the image */ | |
2638 if([result imageView]) | |
2639 { | |
2640 rect.origin.x += _DW_CONTAINER_ICON_WIDTH; | |
2641 rect.size.width -= _DW_CONTAINER_ICON_WIDTH; | |
2642 } | |
2643 [[result textField] setFrame:rect]; | |
2644 } | |
2621 | 2645 |
2646 /*NSLog(@"viewForTableColumn:%@ row:%d textField:%@ celldata class:%@\n", tableColumn.identifier, (int)row, [[result textField] stringValue], [celldata className]);*/ | |
2647 | |
2622 tcell = [[result textField] cell]; | 2648 tcell = [[result textField] cell]; |
2623 | 2649 |
2624 /* Handle drawing alternating row colors if enabled */ | 2650 /* Handle drawing alternating row colors if enabled */ |
2625 if ((row % 2) == 0) | 2651 if ((row % 2) == 0) |
2626 { | 2652 { |