1#import "PXColorWell.h" 2 3@implementation PXColorWell 4 5- initWithFrame:(NSRect)frameRect 6{ 7 [super initWithFrame:frameRect]; 8 [self setColor:[NSColor clearColor]]; 9 return self; 10} 11 12- (void)leftSelect 13{ 14 [[NSNotificationCenter defaultCenter] postNotificationName:@"PXColorWellLeftSelected" object:self userInfo:nil]; 15 [self setNeedsDisplay:YES]; 16} 17 18- (void)rightSelect 19{ 20 [[NSNotificationCenter defaultCenter] postNotificationName:@"PXColorWellRightSelected" object:self userInfo:nil]; 21 [self setNeedsDisplay:YES]; 22} 23 24- (void)mouseDown:event 25{ 26 if ([event clickCount] == 2) { 27 [self activate:YES]; 28 return; 29 } 30 if([event modifierFlags] & NSControlKeyMask) 31 { 32 [self rightSelect]; 33 } 34 else 35 { 36 [self leftSelect]; 37 } 38 [super mouseDown:event]; 39} 40 41- (void)rightMouseDown:event 42{ 43 if ([event clickCount] == 2) { 44 [self activate:YES]; 45 return; 46 } 47 [self rightSelect]; 48} 49 50- (void)deactivate 51{ 52 [super deactivate]; 53 [self setNeedsDisplay:YES]; 54} 55 56- (void)_setColorNoVerify:aColor 57{ 58 id newColor = (aColor != nil ? aColor : [NSColor clearColor]); 59 [super setColor:newColor]; 60} 61 62- (void)drawRect:(NSRect)rect 63{ 64 NSImage *background = [NSImage imageNamed:@"colorWellBackground"]; 65 [background drawInRect:[self bounds] fromRect:NSMakeRect(0, 0, [background size].width, [background size].height) operation:NSCompositeCopy fraction:1]; 66 67 [[self color] set]; 68 NSRectFillUsingOperation(rect, NSCompositeSourceAtop); 69} 70 71- (void)setColor:aColor 72{ 73 id newColor = (aColor != nil ? aColor : [NSColor clearColor]); 74 id old = [[[self color] retain] autorelease]; 75 [super setColor:newColor]; 76 if([old isEqual:newColor] || (old == nil)) { return; } 77 [[NSNotificationCenter defaultCenter] postNotificationName:@"PXColorWellColorChanged" object:self userInfo:[NSDictionary dictionaryWithObjectsAndKeys:old, @"oldColor", nil]]; 78} 79 80- copyWithZone:(NSZone *)zone 81{ 82 return [[NSKeyedUnarchiver unarchiveObjectWithData:[NSKeyedArchiver archivedDataWithRootObject:self]] retain]; 83} 84 85@end 86