| 1 |
// |
| 2 |
// ColorCell.m |
| 3 |
// |
| 4 |
/* |
| 5 |
Copyright (c) 2000-2011 Toshi Nagata. All rights reserved. |
| 6 |
|
| 7 |
This program is free software; you can redistribute it and/or modify |
| 8 |
it under the terms of the GNU General Public License as published by |
| 9 |
the Free Software Foundation version 2 of the License. |
| 10 |
|
| 11 |
This program is distributed in the hope that it will be useful, |
| 12 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
GNU General Public License for more details. |
| 15 |
*/ |
| 16 |
|
| 17 |
#import "ColorCell.h" |
| 18 |
#include <math.h> |
| 19 |
|
| 20 |
@implementation ColorCell |
| 21 |
|
| 22 |
- (id)copyWithZone: (NSZone *)zone |
| 23 |
{ |
| 24 |
id copiedSelf = [super copyWithZone: zone]; |
| 25 |
if (copiedSelf != nil) { |
| 26 |
id rep = [self representedObject]; |
| 27 |
if (rep != nil && [rep isKindOfClass: [NSColor class]]) |
| 28 |
[copiedSelf setRepresentedObject: rep]; |
| 29 |
} |
| 30 |
return copiedSelf; |
| 31 |
} |
| 32 |
|
| 33 |
- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView |
| 34 |
{ |
| 35 |
id image, rep; |
| 36 |
rep = [self representedObject]; |
| 37 |
if (rep != nil && [rep isKindOfClass: [NSColor class]]) { |
| 38 |
[(NSColor *)rep set]; |
| 39 |
if (!noFillsColor) |
| 40 |
NSRectFill(cellFrame); |
| 41 |
else if (!noStrokesColor) |
| 42 |
NSFrameRect(cellFrame); |
| 43 |
} |
| 44 |
image = [self objectValue]; |
| 45 |
if (image != nil && [image isKindOfClass: [NSImage class]]) { |
| 46 |
NSRect r; |
| 47 |
NSSize sz = [(NSImage *)image size]; |
| 48 |
r.origin.x = cellFrame.origin.x + (CGFloat)floor(cellFrame.size.width / 2 - sz.width / 2); |
| 49 |
r.origin.y = cellFrame.origin.y + (CGFloat)floor(cellFrame.size.height / 2 - sz.height / 2); |
| 50 |
r.size = sz; |
| 51 |
// if ([[NSView focusView] isFlipped]) |
| 52 |
// pt.y += sz.height; |
| 53 |
[(NSImage *)image drawInRect: r fromRect: NSZeroRect operation: NSCompositeSourceAtop fraction: 1.0f respectFlipped:YES hints:nil]; |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
- (BOOL)fillsColor |
| 58 |
{ |
| 59 |
return !noFillsColor; |
| 60 |
} |
| 61 |
|
| 62 |
- (void)setFillsColor: (BOOL)flag |
| 63 |
{ |
| 64 |
noFillsColor = !flag; |
| 65 |
} |
| 66 |
|
| 67 |
- (BOOL)strokesColor |
| 68 |
{ |
| 69 |
return !noStrokesColor; |
| 70 |
} |
| 71 |
|
| 72 |
- (void)setStrokesColor: (BOOL)flag |
| 73 |
{ |
| 74 |
noStrokesColor = !flag; |
| 75 |
} |
| 76 |
|
| 77 |
@end |