| | 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 | |
|---|
| 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); |
|---|
| 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]; |
|---|