Changeset 4975

Show
Ignore:
Timestamp:
10/18/07 21:56:39 (9 months ago)
Author:
morris
Message:

Do it like WIIconCell

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • Footagehead/trunk/FHBrowserController.m

    r4912 r4975  
    529529 
    530530- (void)windowDidLoad { 
     531        FHFileCell              *cell; 
     532         
    531533        [[self window] setToolbar:[self _toolbar]]; 
    532534         
     
    534536        [self setWindowFrameAutosaveName:@"Footagehead"]; 
    535537         
    536         [_fileTableColumn setDataCell:[[[FHFileCell alloc] init] autorelease]]; 
     538        cell = [[FHFileCell alloc] init]; 
     539        [cell setAlignment:NSCenterTextAlignment]; 
     540        [cell setFont:[NSFont systemFontOfSize:9.0]]; 
     541        [_fileTableColumn setDataCell:cell]; 
     542        [cell release]; 
     543         
    537544        [_tableView setDoubleAction:@selector(openFile:)]; 
    538545        [_tableView setForwardAction:@selector(openDirectory:)]; 
     
    13611368 
    13621369- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row { 
     1370        return [[self fileAtIndex:row] name]; 
     1371} 
     1372 
     1373 
     1374 
     1375- (void)tableView:(NSTableView *)tableView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row { 
    13631376        FHFile          *file; 
    13641377        FHImage         *icon; 
    1365          
     1378 
    13661379        file = [self fileAtIndex:row]; 
    13671380        icon = [file thumbnail]; 
     
    13691382        if(!icon) 
    13701383                icon = [file icon]; 
    1371          
    1372         return [NSDictionary dictionaryWithObjectsAndKeys: 
    1373                 [file name],    FHFileCellNameKey, 
    1374                 icon,                   FHFileCellIconKey, 
    1375                 NULL]; 
    1376 
    1377  
     1384 
     1385        [(FHFileCell *) cell setImage:icon]; 
     1386
    13781387 
    13791388 
  • Footagehead/trunk/FHFileCell.h

    r4706 r4975  
    2626 * POSSIBILITY OF SUCH DAMAGE. 
    2727 */ 
    28  
     28/* 
    2929@interface FHFileCell : NSCell { 
    3030        NSCell                                          *_nameCell; 
     
    3838 
    3939@end 
     40*/ 
     41 
     42@class FHImage; 
     43 
     44@interface FHFileCell : NSTextFieldCell { 
     45        FHImage                                         *_image; 
     46} 
     47 
     48- (void)setImage:(FHImage *)image; 
     49- (FHImage *)image; 
     50 
     51@end 
  • Footagehead/trunk/FHFileCell.m

    r4902 r4975  
    3232@implementation FHFileCell 
    3333 
    34 - (id)init
    35        NSMutableParagraphStyle         *style
     34- (id)copyWithZone:(NSZone *)zone
     35    FHFileCell         *cell
    3636         
    37         self = [super init]; 
     37        cell = [super copyWithZone:zone]; 
     38    cell->_image = [_image retain]; 
    3839         
    39         _nameCell = [[NSCell alloc] init]; 
    40  
    41         style = [[[NSMutableParagraphStyle alloc] init] autorelease]; 
    42         [style setAlignment:NSCenterTextAlignment]; 
    43          
    44         _attributes = [[NSDictionary alloc] initWithObjectsAndKeys: 
    45                 [NSFont systemFontOfSize:9.0],          NSFontAttributeName, 
    46                 style,                                                          NSParagraphStyleAttributeName, 
    47                 NULL]; 
    48          
    49         return self; 
     40        return cell; 
    5041} 
    5142 
     
    5344 
    5445- (void)dealloc { 
    55         [_nameCell release]; 
    56          
    57         [_attributes release]; 
    58          
     46        [_image release]; 
     47 
    5948        [super dealloc]; 
    6049} 
     
    6453#pragma mark - 
    6554 
    66 - (id)copyWithZone:(NSZone *)zone { 
    67         FHFileCell      *cell; 
     55- (void)setImage:(FHImage *)image { 
     56        [image retain]; 
     57        [_image release]; 
    6858         
    69         cell = [super copyWithZone:zone]; 
    70         cell->_nameCell = [_nameCell retain]; 
    71         cell->_attributes = [_attributes retain]; 
    72          
    73         return cell; 
     59        _image = image; 
     60
     61 
     62 
     63 
     64- (FHImage *)image { 
     65        return _image; 
    7466} 
    7567 
     
    7870#pragma mark - 
    7971 
     72- (void)editWithFrame:(NSRect)frame inView:(NSView *)view editor:(NSText *)editor delegate:(id)object event:(NSEvent *)event { 
     73        NSRect          textFrame, imageFrame; 
     74         
     75        NSDivideRect(frame, &textFrame, &imageFrame, 26.0, NSMaxYEdge); 
     76 
     77        [super editWithFrame:textFrame inView:view editor:editor delegate:object event:event]; 
     78} 
     79 
     80 
     81 
     82- (void)selectWithFrame:(NSRect)frame inView:(NSView *)view editor:(NSText *)editor delegate:(id)delegate start:(NSInteger)start length:(NSInteger)length { 
     83        NSRect          textFrame, imageFrame; 
     84         
     85        NSDivideRect(frame, &textFrame, &imageFrame, 26.0, NSMaxYEdge); 
     86 
     87        [super selectWithFrame:textFrame inView:view editor:editor delegate:delegate start:start length:length]; 
     88} 
     89 
     90 
     91 
    8092- (void)drawWithFrame:(NSRect)frame inView:(NSView *)view { 
    81         NSAttributedString      *string; 
    82         NSString                        *name; 
    83         FHImage                         *icon; 
    8493        CGContextRef            context; 
    85         NSRect                          rect, imageRect; 
    8694        NSSize                          size; 
     95        NSRect                          imageFrame, rect; 
    8796        CGFloat                         dx, dy, d, angle; 
    8897         
    89         name = [(NSDictionary *) [self objectValue] objectForKey:FHFileCellNameKey]; 
    90         icon = [(NSDictionary *) [self objectValue] objectForKey:FHFileCellIconKey]; 
    91          
    92         rect = NSMakeRect(frame.origin.x, frame.origin.y + frame.size.height - 26.0, frame.size.width, 24.0); 
    93         string = [[NSAttributedString alloc] initWithString:name attributes:_attributes]; 
    94         [_nameCell setAttributedStringValue:string]; 
    95         [_nameCell setHighlighted:[self isHighlighted]]; 
    96         [_nameCell drawWithFrame:rect inView:view]; 
    97         [string release]; 
    98          
    99         rect                            = NSMakeRect(frame.origin.x, frame.origin.y + 2.0, frame.size.width, frame.size.height - 28.0); 
    100         size                            = [icon size]; 
    101         angle                           = [icon orientation]; 
    102         imageRect.origin        = rect.origin; 
    103         imageRect.size          = size; 
    104          
    105         if(angle == 0.0 || angle == 180.0) { 
    106                 dx = rect.size.width  / imageRect.size.width; 
    107                 dy = rect.size.height / imageRect.size.height; 
    108         } else { 
    109                 dx = rect.size.width  / imageRect.size.height; 
    110                 dy = rect.size.height / imageRect.size.width; 
    111         } 
    112          
    113         d = dx < dy ? dx : dy; 
    114          
    115         if(d < 1.0) { 
    116                 imageRect.size.width    = floorf(imageRect.size.width  * d); 
    117                 imageRect.size.height   = floorf(imageRect.size.height * d); 
     98        if(_image) { 
     99                NSDivideRect(frame, &frame, &rect, 26.0, NSMaxYEdge); 
     100 
     101                size                            = [_image size]; 
     102                angle                           = [_image orientation]; 
     103                imageFrame.origin       = rect.origin; 
     104                imageFrame.size         = size; 
     105                 
     106                if(angle == 0.0 || angle == 180.0) { 
     107                        dx = rect.size.width  / imageFrame.size.width; 
     108                        dy = rect.size.height / imageFrame.size.height; 
     109                } else { 
     110                        dx = rect.size.width  / imageFrame.size.height; 
     111                        dy = rect.size.height / imageFrame.size.width; 
     112                } 
     113                 
     114                d = dx < dy ? dx : dy; 
     115                 
     116                if(d < 1.0) { 
     117                        imageFrame.size.width   = floorf(imageFrame.size.width  * d); 
     118                        imageFrame.size.height  = floorf(imageFrame.size.height * d); 
     119                } 
     120                 
     121                if(angle == 0.0 || angle == 180.0) { 
     122                        imageFrame.origin.x += floorf((rect.size.width  - imageFrame.size.width)  / 2.0); 
     123                        imageFrame.origin.y += floorf((rect.size.height - imageFrame.size.height) / 2.0); 
     124                } else { 
     125                        imageFrame.origin.x += floorf((rect.size.width  - imageFrame.size.height) / 2.0); 
     126                        imageFrame.origin.y += floorf((rect.size.height - imageFrame.size.width)  / 2.0); 
     127                } 
     128                 
     129                if(angle == 90.0) { 
     130                        imageFrame.origin.y -= imageFrame.size.height; 
     131                } 
     132                else if(angle == 180.0) { 
     133                        imageFrame.origin.x += imageFrame.size.width; 
     134                        imageFrame.origin.y += imageFrame.size.height; 
     135                } 
     136                else if(angle == 270.0) { 
     137                        imageFrame.origin.x += imageFrame.size.height; 
     138                } 
     139                 
     140                context = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort]; 
     141                CGContextSaveGState(context); 
     142                 
     143                if(angle == 90.0) { 
     144                        CGContextTranslateCTM(context, 0.0, imageFrame.origin.y + imageFrame.origin.y + imageFrame.size.height); 
     145                        CGContextScaleCTM(context, 1.0, -1.0); 
     146                } 
     147                 
     148                if(angle == 90.0 || angle == 180.0 || angle == 270.0) { 
     149                        CGContextTranslateCTM(context, imageFrame.origin.x, imageFrame.origin.y); 
     150                        CGContextRotateCTM(context, -angle * M_PI / 180.0); 
     151                        CGContextTranslateCTM(context, -imageFrame.origin.x, -imageFrame.origin.y); 
     152                } 
     153                 
     154                if(angle == 0.0 || angle == 180.0 || angle == 270.0) { 
     155                        CGContextTranslateCTM(context, 0.0, imageFrame.origin.y + imageFrame.origin.y + imageFrame.size.height); 
     156                        CGContextScaleCTM(context, 1.0, -1.0); 
     157                } 
     158                 
     159                [_image drawInRect:imageFrame]; 
     160                 
     161                CGContextRestoreGState(context); 
    118162        } 
    119163 
    120         if(angle == 0.0 || angle == 180.0) { 
    121                 imageRect.origin.x += floorf((rect.size.width  - imageRect.size.width)  / 2.0); 
    122                 imageRect.origin.y += floorf((rect.size.height - imageRect.size.height) / 2.0); 
    123         } else { 
    124                 imageRect.origin.x += floorf((rect.size.width  - imageRect.size.height) / 2.0); 
    125                 imageRect.origin.y += floorf((rect.size.height - imageRect.size.width)  / 2.0); 
    126         } 
    127          
    128         if(angle == 90.0) { 
    129                 imageRect.origin.y -= imageRect.size.height; 
    130         } 
    131         else if(angle == 180.0) { 
    132                 imageRect.origin.x += imageRect.size.width; 
    133                 imageRect.origin.y += imageRect.size.height; 
    134         } 
    135         else if(angle == 270.0) { 
    136                 imageRect.origin.x += imageRect.size.height; 
    137         } 
    138          
    139         context = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort]; 
    140         CGContextSaveGState(context); 
    141  
    142         if(angle == 90.0) { 
    143                 CGContextTranslateCTM(context, 0.0, imageRect.origin.y + imageRect.origin.y + imageRect.size.height); 
    144                 CGContextScaleCTM(context, 1.0, -1.0); 
    145         } 
    146          
    147         if(angle == 90.0 || angle == 180.0 || angle == 270.0) { 
    148                 CGContextTranslateCTM(context, imageRect.origin.x, imageRect.origin.y); 
    149                 CGContextRotateCTM(context, -angle * M_PI / 180.0); 
    150                 CGContextTranslateCTM(context, -imageRect.origin.x, -imageRect.origin.y); 
    151         } 
    152          
    153         if(angle == 0.0 || angle == 180.0 || angle == 270.0) { 
    154                 CGContextTranslateCTM(context, 0.0, imageRect.origin.y + imageRect.origin.y + imageRect.size.height); 
    155                 CGContextScaleCTM(context, 1.0, -1.0); 
    156         } 
    157          
    158         [icon drawInRect:imageRect]; 
    159          
    160         CGContextRestoreGState(context); 
     164        [super drawWithFrame:frame inView:view]; 
    161165} 
    162166