comparison mac/dw.m @ 2178:2fa38504803e

Mac: Transitioned DWTree to using NSTableCellView as well.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 13 Oct 2020 00:03:45 +0000
parents 7213842143f5
children bd6146d4bdbc
comparison
equal deleted inserted replaced
2177:7213842143f5 2178:2fa38504803e
2384 [tf setBezeled:NO]; 2384 [tf setBezeled:NO];
2385 [tf setBordered:NO]; 2385 [tf setBordered:NO];
2386 } 2386 }
2387 return browsercell; 2387 return browsercell;
2388 } 2388 }
2389
2390 void _dw_table_cell_view_layout(NSTableCellView *result)
2391 {
2392 /* Adjust the frames of the textField and imageView */
2393 if([result imageView])
2394 {
2395 NSRect rect = NSMakeRect((_DW_CONTAINER_ROW_HEIGHT - _DW_CONTAINER_ICON_WIDTH) / 2,
2396 (_DW_CONTAINER_ROW_HEIGHT - _DW_CONTAINER_ICON_HEIGHT) / 2,
2397 _DW_CONTAINER_ICON_WIDTH,_DW_CONTAINER_ICON_HEIGHT);
2398 [[result imageView] setFrame:rect];
2399 }
2400 if([result textField])
2401 {
2402 NSRect rect = result.frame;
2403
2404 /* Adjust the rect to allow space for the image */
2405 if([result imageView])
2406 {
2407 rect.origin.x += _DW_CONTAINER_ICON_WIDTH;
2408 rect.size.width -= _DW_CONTAINER_ICON_WIDTH;
2409 }
2410 [[result textField] setFrame:rect];
2411 }
2412 }
2389 #endif 2413 #endif
2390 2414
2391 /* Subclass for a Container/List type */ 2415 /* Subclass for a Container/List type */
2392 @interface DWContainer : NSTableView 2416 @interface DWContainer : NSTableView
2393 #ifdef BUILDING_FOR_SNOW_LEOPARD 2417 #ifdef BUILDING_FOR_SNOW_LEOPARD
2620 */ 2644 */
2621 [result setIdentifier:tableColumn.identifier]; 2645 [result setIdentifier:tableColumn.identifier];
2622 } 2646 }
2623 } 2647 }
2624 2648
2625 /* Adjust the frames of the textField and imageView */ 2649 _dw_table_cell_view_layout(result);
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 }
2645 2650
2646 /*NSLog(@"viewForTableColumn:%@ row:%d textField:%@ celldata class:%@\n", tableColumn.identifier, (int)row, [[result textField] stringValue], [celldata className]);*/ 2651 /*NSLog(@"viewForTableColumn:%@ row:%d textField:%@ celldata class:%@\n", tableColumn.identifier, (int)row, [[result textField] stringValue], [celldata className]);*/
2647 2652
2648 tcell = [[result textField] cell]; 2653 tcell = [[result textField] cell];
2649 2654
3081 NSColor *fgcolor; 3086 NSColor *fgcolor;
3082 } 3087 }
3083 -(id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item; 3088 -(id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item;
3084 -(BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item; 3089 -(BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item;
3085 -(int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item; 3090 -(int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item;
3091 #ifdef BUILDING_FOR_YOSEMITE
3092 -(NSView *)outlineView:(NSOutlineView *)outlineView viewForTableColumn:(NSTableColumn *)tableColumn item:(id)item;
3093 #else
3086 -(id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item; 3094 -(id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item;
3087 -(void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item; 3095 -(void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item;
3096 #endif
3088 -(BOOL)outlineView:(NSOutlineView *)outlineView shouldEditTableColumn:(NSTableColumn *)tableColumn item:(id)item; 3097 -(BOOL)outlineView:(NSOutlineView *)outlineView shouldEditTableColumn:(NSTableColumn *)tableColumn item:(id)item;
3089 -(void)addTree:(NSMutableArray *)item and:(NSMutableArray *)parent after:(NSMutableArray *)after; 3098 -(void)addTree:(NSMutableArray *)item and:(NSMutableArray *)parent after:(NSMutableArray *)after;
3090 -(void *)userdata; 3099 -(void *)userdata;
3091 -(void)setUserdata:(void *)input; 3100 -(void)setUserdata:(void *)input;
3092 -(void)treeSelectionChanged:(id)sender; 3101 -(void)treeSelectionChanged:(id)sender;
3150 else 3159 else
3151 { 3160 {
3152 return data ? (int)[data count] : 0; 3161 return data ? (int)[data count] : 0;
3153 } 3162 }
3154 } 3163 }
3164 #ifdef BUILDING_FOR_YOSEMITE
3165 -(NSView *)outlineView:(NSOutlineView *)outlineView viewForTableColumn:(NSTableColumn *)tableColumn item:(id)item
3166 {
3167 NSTableCellView *view = [outlineView makeViewWithIdentifier:[tableColumn identifier] owner:self];
3168
3169 if([item isKindOfClass:[NSMutableArray class]])
3170 {
3171 NSMutableArray *this = (NSMutableArray *)item;
3172 NSImage *icon = [this objectAtIndex:0];
3173 NSString *text = [this objectAtIndex:1];
3174 if(![icon isKindOfClass:[NSImage class]])
3175 icon = nil;
3176 if(view)
3177 {
3178 [[view textField] setStringValue: text];
3179 [[view imageView] setImage:icon];
3180 }
3181 else
3182 view = _dw_table_cell_view_new(icon, text);
3183 }
3184 [view setFrame:NSMakeRect(0,0,tableColumn.width,_DW_CONTAINER_ROW_HEIGHT)];
3185 [[view textField] setFrame:view.frame];
3186 _dw_table_cell_view_layout(view);
3187 return view;
3188 }
3189 #else
3155 -(id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item 3190 -(id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
3156 { 3191 {
3157 if(item) 3192 if(item)
3158 { 3193 {
3159 if([item isKindOfClass:[NSMutableArray class]]) 3194 if([item isKindOfClass:[NSMutableArray class]])
3168 } 3203 }
3169 return @"List Root"; 3204 return @"List Root";
3170 } 3205 }
3171 -(void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item 3206 -(void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item
3172 { 3207 {
3173 #ifdef BUILDING_FOR_YOSEMITE
3174 if([cell isMemberOfClass:[NSTableCellView class]])
3175 {
3176 NSMutableArray *this = (NSMutableArray *)item;
3177 NSImage *img = [this objectAtIndex:0];
3178 if([img isKindOfClass:[NSImage class]])
3179 [[(NSTableCellView*)cell imageView] setImage:img];
3180 }
3181 #else
3182 if([cell isMemberOfClass:[DWImageAndTextCell class]]) 3208 if([cell isMemberOfClass:[DWImageAndTextCell class]])
3183 { 3209 {
3184 NSMutableArray *this = (NSMutableArray *)item; 3210 NSMutableArray *this = (NSMutableArray *)item;
3185 NSImage *img = [this objectAtIndex:0]; 3211 NSImage *img = [this objectAtIndex:0];
3186 if([img isKindOfClass:[NSImage class]]) 3212 if([img isKindOfClass:[NSImage class]])
3187 [(DWImageAndTextCell*)cell setImage:img]; 3213 [(DWImageAndTextCell*)cell setImage:img];
3188 } 3214 }
3215 }
3189 #endif 3216 #endif
3190 }
3191 -(BOOL)outlineView:(NSOutlineView *)outlineView shouldEditTableColumn:(NSTableColumn *)tableColumn item:(id)item { return NO; } 3217 -(BOOL)outlineView:(NSOutlineView *)outlineView shouldEditTableColumn:(NSTableColumn *)tableColumn item:(id)item { return NO; }
3192 -(void)addTree:(NSMutableArray *)item and:(NSMutableArray *)parent after:(NSMutableArray *)after 3218 -(void)addTree:(NSMutableArray *)item and:(NSMutableArray *)parent after:(NSMutableArray *)after
3193 { 3219 {
3194 NSMutableArray *children = data; 3220 NSMutableArray *children = data;
3195 if(parent) 3221 if(parent)