/********************************************************************
Filename: ControlWithScheme.m
Date: 14-09-2012
Author: Ben
Description: Work-arround for 10.5
Revisions:
Ben: 14-09-2012 Initial version
********************************************************************/
#import "ControlWithScheme.h"
.......
@implementation TextFieldWithScheme
- (id) init
{
self = [super init];
if (self != nil)
{
[self redrawScheme];
if (!addObserver)
{
[self setBackgroundColor:[NSColor clearColor]];
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:[Preferences pathForKey:kPrefKeyGUIColorScheme] options:0 context: NULL];
addObserver = true;
}
}
return self;
}
- (id)initWithFrame:(NSRect)frameRect
{
self = [super initWithFrame:frameRect];
if (self != nil)
{
[self redrawScheme];
if (!addObserver)
{
[self setBackgroundColor:[NSColor clearColor]];
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:[Preferences pathForKey:kPrefKeyGUIColorScheme] options:0 context: NULL];
addObserver = true;
}
}
return self;
}
- (void)viewDidMoveToWindow
{
[self redrawScheme];
if (!addObserver)
{
[self setBackgroundColor:[NSColor clearColor]];
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:[Preferences pathForKey:kPrefKeyGUIColorScheme] options:0 context: NULL];
addObserver = true;
}
}
- (void) redrawScheme
{
[self setTextColor: [NSColor foregroundColorForControl:nil colorScheme:[Preferences colorScheme]]];
[self setNeedsDisplay: true];
}
- (void) dealloc
{
if (addObserver)
{
[[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:[Preferences pathForKey:kPrefKeyGUIColorScheme]];
}
[super dealloc];
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if ([keyPath isEqualToString:[Preferences pathForKey:kPrefKeyGUIColorScheme]])
{
[self redrawScheme];
}
}
@end
@implementation TextFieldWithBackgroundColorScheme
- (id)initWithFrame:(NSRect)frameRect
{
self = [super initWithFrame:frameRect];
if (self != nil)
{
[self redrawScheme];
if (!addObserver)
{
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:[Preferences pathForKey:kPrefKeyGUIColorScheme] options:0 context: NULL];
addObserver = true;
}
}
return self;
}
- (void)viewDidMoveToWindow
{
[self redrawScheme];
if (!addObserver)
{
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:[Preferences pathForKey:kPrefKeyGUIColorScheme] options:0 context: NULL];
addObserver = true;
}
}
- (void) redrawScheme
{
[self setBackgroundColor:[NSColor backgroundColorForControl:@"TextFieldWithBackgroundColorScheme" colorScheme:[Preferences colorScheme]]];
[self setTextColor: [NSColor foregroundColorForControl:nil colorScheme:[Preferences colorScheme]]];
[self setNeedsDisplay: true];
}
- (void) drawRect:(NSRect)dirtyRect
{
[super drawRect:dirtyRect];
if (([Preferences colorScheme] != (NSUInteger)[NSColor silverSchemeIndex]) && ![self isKindOfClass: [SpinBoxButton class]])
{
[[NSColor foregroundColorForControl:nil colorScheme:[Preferences colorScheme]] set];
NSBezierPath * pathToStroke = [NSBezierPath bezierPathWithRect:[self bounds]];
[pathToStroke setLineWidth:1];
[pathToStroke stroke];
}
}
- (void) dealloc
{
if (addObserver)
{
[[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:[Preferences pathForKey:kPrefKeyGUIColorScheme]];
}
[super dealloc];
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if ([keyPath isEqualToString:[Preferences pathForKey:kPrefKeyGUIColorScheme]])
{
[self redrawScheme];
}
}
@end
@implementation SecureTextFieldWithScheme
- (id)initWithFrame:(NSRect)frameRect
{
self = [super initWithFrame:frameRect];
if (self != nil)
{
[self redrawScheme];
if (!addObserver)
{
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:[Preferences pathForKey:kPrefKeyGUIColorScheme] options:0 context: NULL];
addObserver = true;
}
}
return self;
}
- (void)viewDidMoveToWindow
{
[self redrawScheme];
if (!addObserver)
{
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:[Preferences pathForKey:kPrefKeyGUIColorScheme] options:0 context: NULL];
addObserver = true;
}
}
- (void) redrawScheme
{
[self setBackgroundColor:[NSColor backgroundColorForControl:@"TextFieldWithBackgroundColorScheme" colorScheme:[Preferences colorScheme]]];
[self setTextColor: [NSColor foregroundColorForControl:nil colorScheme:[Preferences colorScheme]]];
[self setNeedsDisplay: true];
}
- (void) dealloc
{
if (addObserver)
{
[[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:[Preferences pathForKey:kPrefKeyGUIColorScheme]];
}
[super dealloc];
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if ([keyPath isEqualToString:[Preferences pathForKey:kPrefKeyGUIColorScheme]])
{
[self redrawScheme];
}
}
@end
@implementation BoxWithScheme
- (id) init
{
self = [super init];
if (self != nil)
{
if (!addObserver)
{
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:[Preferences pathForKey:kPrefKeyGUIColorScheme] options:0 context: NULL];
addObserver = true;
}
}
return self;
}
- (id)initWithFrame:(NSRect)frameRect
{
self = [super initWithFrame:frameRect];
if (self != nil)
{
if (!addObserver)
{
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:[Preferences pathForKey:kPrefKeyGUIColorScheme] options:0 context: NULL];
addObserver = true;
}
}
return self;
}
- (void)viewDidMoveToWindow
{
if (!addObserver)
{
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:[Preferences pathForKey:kPrefKeyGUIColorScheme] options:0 context: NULL];
addObserver = true;
}
}
- (void) drawRect:(NSRect)rect
{
[super drawRect: rect];
if ([Preferences colorScheme] != (NSUInteger)[NSColor silverSchemeIndex])
{
NSFont *font = [self titleFont];
NSDictionary * attrs = [NSDictionary dictionaryWithObjectsAndKeys:
font,
NSFontAttributeName,
[NSColor foregroundColorForControl:nil colorScheme:[Preferences colorScheme]],
NSForegroundColorAttributeName,
nil];
NSAttributedString* attributedString = [[NSAttributedString alloc] initWithString:[self title] attributes:attrs];
[attributedString drawInRect:[self titleRect]];
[attributedString release];
}
}
- (void) dealloc
{
if (addObserver)
{
[[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:[Preferences pathForKey:kPrefKeyGUIColorScheme]];
}
[super dealloc];
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if ([keyPath isEqualToString:[Preferences pathForKey:kPrefKeyGUIColorScheme]])
{
[self setNeedsDisplay:true];
}
}
@end
@implementation ButtonWithScheme
- (id)initWithFrame:(NSRect)frameRect
{
self = [super initWithFrame:frameRect];
if (self != nil)
{
[self redrawScheme];
if (!addObserver)
{
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:[Preferences pathForKey:kPrefKeyGUIColorScheme] options:0 context: NULL];
addObserver = true;
}
}
return self;
}
- (void)viewDidMoveToWindow
{
[self redrawScheme];
if (!addObserver)
{
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:[Preferences pathForKey:kPrefKeyGUIColorScheme] options:0 context: NULL];
addObserver = true;
}
}
- (void) redrawScheme
{
[self setTextColor: [NSColor foregroundColorForControl:nil colorScheme:[Preferences colorScheme]]];
[self setNeedsDisplay: true];
}
- (void) setTextColor: (NSColor *) color
{
[color retain];
[textColor release];
textColor = color;
}
- (void) drawRect:(NSRect) rect
{
switch ([[self cell] bezelStyle])
{
case NSDisclosureBezelStyle:
{
[super drawRect: rect];
if ([Preferences colorScheme] != (NSUInteger)[NSColor silverSchemeIndex])
{
NSRect drawRect = [self bounds];
NSBezierPath* drawPath = [NSBezierPath bezierPath];
if ([self state])
{
if ([[self cell] isHighlighted])
{
[[NSColor foregroundColorForControl:@"HighlightedDisclosureButton" colorScheme:[Preferences colorScheme]] set];
}
else
{
[[NSColor foregroundColorForControl:nil colorScheme:[Preferences colorScheme]] set];
}
drawRect.origin.x += 1;
drawRect.size.width -= 2;
drawRect.origin.y += 3;
drawRect.size.height -= 4;
[drawPath moveToPoint:NSMakePoint(NSMinX(drawRect), NSMinY(drawRect))];
[drawPath lineToPoint:NSMakePoint(NSMaxX(drawRect), NSMinY(drawRect))];
[drawPath lineToPoint:NSMakePoint(NSMidX(drawRect), NSMaxY(drawRect))];
[drawPath lineToPoint:NSMakePoint(NSMinX(drawRect), NSMinY(drawRect))];
}
else
{
if ([[self cell] isHighlighted])
{
[[NSColor foregroundColorForControl:@"HighlightedDisclosureButton" colorScheme:[Preferences colorScheme]] set];
}
else
{
[[NSColor foregroundColorForControl:nil colorScheme:[Preferences colorScheme]] set];
}
drawRect.origin.x += 2;
drawRect.size.width -= 4;
drawRect.origin.y += 1;
drawRect.size.height -= 2;
[drawPath moveToPoint:NSMakePoint(NSMinX(drawRect), NSMinY(drawRect))];
[drawPath lineToPoint:NSMakePoint(NSMinX(drawRect), NSMaxY(drawRect))];
[drawPath lineToPoint:NSMakePoint(NSMaxX(drawRect), NSMidY(drawRect))];
[drawPath lineToPoint:NSMakePoint(NSMinX(drawRect), NSMinY(drawRect))];
}
[drawPath fill];
}
break;
}
default:
{
if ([self attributedTitle])
{
NSMutableAttributedString* attributedString = [[NSMutableAttributedString alloc] initWithAttributedString:[self attributedTitle]];
[attributedString addAttribute:NSForegroundColorAttributeName value:textColor range:NSMakeRange(0, [attributedString length])];
[self setAttributedTitle:attributedString];
[attributedString release];
}
[super drawRect: rect];
break;
}
}
}
- (void) dealloc
{
[textColor release];
if (addObserver)
{
[[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:[Preferences pathForKey:kPrefKeyGUIColorScheme]];
}
[super dealloc];
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if ([keyPath isEqualToString:[Preferences pathForKey:kPrefKeyGUIColorScheme]])
{
[self redrawScheme];
}
}
@end
@implementation ButtonCellWithScheme
- (void) setTitle:(NSString *)aString
{
NSFont *font = [self font];
NSMutableDictionary * attrs = nil;
attrs = [NSMutableDictionary dictionaryWithObjectsAndKeys:
font,
NSFontAttributeName,
[NSColor foregroundColorForControl:nil colorScheme:[Preferences colorScheme]],
NSForegroundColorAttributeName,
nil];
if (([Preferences colorScheme] != (NSUInteger)[NSColor silverSchemeIndex]) && [self isHighlighted])
{
[attrs setObject:[NSColor blackColor] forKey:NSForegroundColorAttributeName];
}
NSAttributedString* attributedString = [[NSAttributedString alloc] initWithString:aString attributes:attrs];
[self setAttributedTitle:attributedString];
[attributedString release];
}
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
{
NSMutableAttributedString* attributedString = [[NSMutableAttributedString alloc] initWithAttributedString:[self attributedTitle]];
[attributedString addAttribute:NSForegroundColorAttributeName
value:[NSColor foregroundColorForControl:nil colorScheme:[Preferences colorScheme]]
range:NSMakeRange(0, [attributedString length])];
[self setAttributedTitle:attributedString];
[attributedString release];
if (([Preferences colorScheme] != (NSUInteger)[NSColor silverSchemeIndex]) && [self isHighlighted])
{
NSMutableAttributedString* attributedString = [[NSMutableAttributedString alloc] initWithAttributedString:[self attributedTitle]];
[attributedString addAttribute:NSForegroundColorAttributeName value:[NSColor blackColor] range:NSMakeRange(0, [attributedString length])];
[self setAttributedTitle:attributedString];
[attributedString release];
}
[super drawWithFrame:cellFrame inView:controlView];
}
@end
@implementation StepperWithScheme
- (void) drawRect:(NSRect) rect
{
[super drawRect: rect];
NSRect cellRect = [self bounds];
if ([Preferences colorScheme] != (NSUInteger)[NSColor silverSchemeIndex])
{
cellRect.origin = NSMakePoint(0, 0);
cellRect.size.width -= 4;
cellRect.origin.x += 2;
cellRect.size.height -= 4;
cellRect.origin.y += 2;
[[NSBezierPath bezierPathWithRoundedRect:cellRect xRadius:4 yRadius:4] addClip];
CGContextRef context = (CGContextRef)[NSGraphicsContext currentContext];
CGContextSetBlendMode(context, kCGBlendModeSourceAtop);
[[NSColor backgroundColorForControl:@"StepperWithScheme" colorScheme:[Preferences colorScheme]] set];
[[NSBezierPath bezierPathWithRoundedRect:cellRect xRadius:4 yRadius:4] fill];
NSSize size = NSMakeSize(4, 4);
NSRect drawRect1 = NSMakeRect(NSMaxX(cellRect)-size.width-3.5, 5.5, size.width, size.height);
NSBezierPath* drawPath1 = [NSBezierPath bezierPath];
[drawPath1 moveToPoint:NSMakePoint(NSMinX(drawRect1), NSMaxY(drawRect1))];
[drawPath1 lineToPoint:NSMakePoint(NSMaxX(drawRect1), NSMaxY(drawRect1))];
[drawPath1 lineToPoint:NSMakePoint(NSMidX(drawRect1), NSMinY(drawRect1))];
[drawPath1 lineToPoint:NSMakePoint(NSMinX(drawRect1), NSMaxY(drawRect1))];
[[NSColor foregroundColorForControl:nil colorScheme:[Preferences colorScheme]] set];
[drawPath1 fill];
NSRect drawRect2 = NSMakeRect(NSMaxX(cellRect)-size.width-3.5, 14, size.width, size.height);
NSBezierPath* drawPath2 = [NSBezierPath bezierPath];
[drawPath2 moveToPoint:NSMakePoint(NSMinX(drawRect2), NSMinY(drawRect2))];
[drawPath2 lineToPoint:NSMakePoint(NSMaxX(drawRect2), NSMinY(drawRect2))];
[drawPath2 lineToPoint:NSMakePoint(NSMidX(drawRect2), NSMaxY(drawRect2))];
[drawPath2 lineToPoint:NSMakePoint(NSMinX(drawRect2), NSMinY(drawRect2))];
[[NSColor foregroundColorForControl:nil colorScheme:[Preferences colorScheme]] set];
[drawPath2 fill];
}
}
@end
@implementation ImageStyleButtonWithScheme
- (id)initWithFrame:(NSRect)frameRect
{
self = [super initWithFrame:frameRect];
if (self != nil)
{
[self redrawScheme];
if (!addObserver)
{
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:[Preferences pathForKey:kPrefKeyGUIColorScheme] options:0 context: NULL];
addObserver = true;
}
}
return self;
}
- (void)viewDidMoveToWindow
{
[self redrawScheme];
if (!addObserver)
{
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:[Preferences pathForKey:kPrefKeyGUIColorScheme] options:0 context: NULL];
addObserver = true;
}
}
- (void) redrawScheme
{
NSString *imageFileName = [NSImageNameTemplatesLoader imageNameWithoutSchemePrefix:[[self image] name]];
if (([[[NSImageNameTemplatesLoader imageNameTemplateDictionary] allKeys] containsObject: imageFileName]) &&
[[[NSImageNameTemplatesLoader imageNameTemplateDictionary] objectForKey:imageFileName] objectForKey:
[NSImageNameTemplatesLoader keyStringForColorScheme:[Preferences colorScheme]]])
{
NSRect buttonRect = [self bounds];
NSString *imageName = nil;
NSString *folderName = nil;
NSString *memoryName = nil;
imageName = [[[NSImageNameTemplatesLoader imageNameTemplateDictionary] objectForKey:imageFileName]
objectForKey:[NSImageNameTemplatesLoader keyStringForColorScheme:[Preferences colorScheme]]];
folderName = [NSImageNameTemplatesLoader imageFolderNameForColorScheme:[Preferences colorScheme]];
memoryName = [NSImageNameTemplatesLoader memoryNameForName:imageName WithSchemePrefix:[Preferences colorScheme]];
NSImage *img = [NSImage imageNamed:imageName orFromBundleDirectory:folderName setMemoryName:memoryName];
if (([imageName isEqualToString:@"Add.icns"] || [imageName isEqualToString:@"Remove.icns"]) && img)
{
[img setSize: NSMakeSize(buttonRect.size.width - 16, buttonRect.size.height-16)];
}
if(img)
{
NSSize imgSize = [img size];
[img setSize: NSMakeSize(MIN(imgSize.width,buttonRect.size.width-8),MIN(imgSize.height,buttonRect.size.height-8))];
[super setImage:img];
}
}
else if ([[NSImageNameTemplatesLoader imagesNeedChangeFolderWithScheme] containsObject:imageFileName])
{
NSRect buttonRect = [self bounds];
NSString *folderName = nil;
NSString *memoryName = nil;
folderName = [NSImageNameTemplatesLoader imageFolderNameForColorScheme:[Preferences colorScheme]];
memoryName = [NSImageNameTemplatesLoader memoryNameForName:imageFileName WithSchemePrefix:[Preferences colorScheme]];
NSImage * img = [NSImage imageNamed:imageFileName orFromBundleDirectory:folderName setMemoryName:memoryName];
if(img)
{
NSSize imgSize = [img size];
[img setSize: NSMakeSize(MIN(imgSize.width,buttonRect.size.width-8),MIN(imgSize.height,buttonRect.size.height-8))];
[super setImage:img];
}
}
if ([self attributedTitle])
{
NSMutableAttributedString* attributedString = [[NSMutableAttributedString alloc] initWithAttributedString:[self attributedTitle]];
[attributedString addAttribute:NSForegroundColorAttributeName value:[NSColor foregroundColorForControl:nil colorScheme:[Preferences colorScheme]] range:NSMakeRange(0, [attributedString length])];
[self setAttributedTitle:attributedString];
[attributedString release];
}
[self setNeedsDisplay: true];
}
- (void) setImage:(NSImage *)image
{
[super setImage:image];
[self redrawScheme];
}
- (void) drawRect:(NSRect)dirtyRect
{
NSString *imageFileName = [NSImageNameTemplatesLoader imageNameWithoutSchemePrefix:[[self image] name]];
BOOL needDrawBlackLayerWithOutSilverScheme = true;
if ([imageFileName isEqualToString:@"ShowHistogram.tiff"] ||
[imageFileName isEqualToString:@"HideHistogram.tiff"] ||
[imageFileName isEqualToString:@"ShowClippingOn.tiff"] ||
[imageFileName isEqualToString:@"ShowClippingOff.tiff"] ||
[imageFileName isEqualToString:@"ShowRepairPreview.tiff"] ||
![[self title] isEqualToString:@""])
{
needDrawBlackLayerWithOutSilverScheme = false;
}
if ([Preferences colorScheme] != (NSUInteger)[NSColor silverSchemeIndex])
{
NSRect cellRect = [self bounds];
cellRect.origin = NSMakePoint(0, 0);
if ([[self title] isEqualToString:@""])
{
cellRect.size.height -= 8;
cellRect.origin.y += 5;
}
[[NSBezierPath bezierPathWithRoundedRect:cellRect xRadius:3 yRadius:3] addClip];
[[NSBezierPath bezierPathWithRect:dirtyRect] addClip];
if ([[self title] isEqualToString:@""])
{
NSGradient* aGradient = nil;
if ([[self cell] isHighlighted])
{
// aGradient = [[[NSGradient alloc] initWithColorsAndLocations:
// [NSColor colorWithDeviceRed:0.23f green:0.23f blue:0.23f alpha:0.7f], (CGFloat)0,
// [NSColor colorWithDeviceRed:0.25 green:0.25 blue:0.25 alpha:0.7f], (CGFloat)0.5,
// [NSColor colorWithDeviceRed:0.7 green:0.7 blue:0.7 alpha:0.7f], (CGFloat)1.0,
// nil] autorelease];
aGradient = [[[NSGradient alloc] initWithColorsAndLocations:
[NSColor backgroundColorForControl:@"Color1ForGradientHighlighted" colorScheme:[Preferences colorScheme]], (CGFloat)0,
[NSColor backgroundColorForControl:@"Color2ForGradientHighlighted" colorScheme:[Preferences colorScheme]], (CGFloat)0.48,
[NSColor backgroundColorForControl:@"Color3ForGradientHighlighted" colorScheme:[Preferences colorScheme]], (CGFloat)0.52,
[NSColor backgroundColorForControl:@"Color4ForGradientHighlighted" colorScheme:[Preferences colorScheme]], (CGFloat)1.0,
nil] autorelease];
}
else
{
// aGradient = [[[NSGradient alloc] initWithColorsAndLocations:
// [NSColor colorWithDeviceRed:0.7 green:0.7 blue:0.7 alpha:0.7f], (CGFloat)0,
// [NSColor colorWithDeviceRed:0.25 green:0.25 blue:0.25 alpha:0.7f], (CGFloat)0.5,
// [NSColor colorWithDeviceRed:0.23f green:0.23f blue:0.23f alpha:0.7f], (CGFloat)1.0,
// nil] autorelease];
aGradient = [[[NSGradient alloc] initWithColorsAndLocations:
[NSColor backgroundColorForControl:@"Color1ForGradientNotHighlighted" colorScheme:[Preferences colorScheme]], (CGFloat)0,
[NSColor backgroundColorForControl:@"Color2ForGradientNotHighlighted" colorScheme:[Preferences colorScheme]], (CGFloat)0.48,
[NSColor backgroundColorForControl:@"Color3ForGradientNotHighlighted" colorScheme:[Preferences colorScheme]], (CGFloat)0.52,
[NSColor backgroundColorForControl:@"Color4ForGradientNotHighlighted" colorScheme:[Preferences colorScheme]], (CGFloat)1.0,
nil] autorelease];
}
[aGradient drawInBezierPath:[NSBezierPath bezierPathWithRoundedRect:cellRect xRadius:3 yRadius:3] angle: 90];
[[NSColor foregroundColorForControl:nil colorScheme:[Preferences colorScheme]] set];
NSBezierPath *pathToStroke = [NSBezierPath bezierPathWithRoundedRect:cellRect xRadius:3 yRadius:3];
[pathToStroke setLineWidth:0.5];
[pathToStroke stroke];
[[self cell] drawInteriorWithFrame:[self bounds] inView:self];
return;
}
if (needDrawBlackLayerWithOutSilverScheme)
{
// Draw gradient background color for reduce the blizzing white on the top
NSGradient* aGradient = [[[NSGradient alloc] initWithColorsAndLocations:
[NSColor colorWithDeviceRed:0 green:0 blue:0 alpha:1.0f], (CGFloat)0,
[NSColor colorWithDeviceRed:0 green:0 blue:0 alpha:1.0f], (CGFloat)0.1,
[NSColor colorWithDeviceRed:0.15f green:0.15f blue:0.15f alpha:1.0f], (CGFloat)1.0,
nil] autorelease];
//[aGradient drawInBezierPath:[NSBezierPath bezierPathWithRoundedRect:cellRect xRadius:5 yRadius:5] angle: 90];
[aGradient drawInBezierPath:[NSBezierPath bezierPathWithRoundedRect:cellRect xRadius:3 yRadius:3] angle: 90];
}
}
[super drawRect: dirtyRect];
if (([Preferences colorScheme] != (NSUInteger)[NSColor silverSchemeIndex]) && ![[self title] isEqualToString:@""])
{
NSRect cellRect = [self bounds];
NSUInteger controlHeight = (NSUInteger)cellRect.size.height;
CGFloat xRad=0, yRad=0;
if (controlHeight == 16)
{
switch ([self bezelStyle])
{
case NSRoundRectBezelStyle:
case NSTexturedRoundedBezelStyle:
case NSShadowlessSquareBezelStyle:
default:
{
cellRect.size.width -= 4;
cellRect.origin.x += 2;
cellRect.size.height -=3;
cellRect.origin.y += 1;
xRad = 2;
yRad = 2;
break;
}
}
}
else
{
switch ([self bezelStyle])
{
case NSRoundRectBezelStyle:
{
xRad = 7;
yRad = cellRect.size.height/2;
break;
}
case NSTexturedRoundedBezelStyle:
{
cellRect.origin.y += 2;
cellRect.size.height -= 4;
xRad = 4;
yRad = 4;
break;
}
case NSShadowlessSquareBezelStyle:
{
xRad = 0;
yRad = 0;
break;
}
case NSTexturedSquareBezelStyle:
{
cellRect.origin.y += 3.5;
cellRect.size.height -= 6;
xRad = 3;
yRad = 3;
break;
}
default:
{
cellRect.size.width -= 11;
cellRect.origin.x += 5.5;
cellRect.size.height -= 11;
cellRect.origin.y += 4.5;
xRad = 3;
yRad = 3;
break;
}
}
}
// Draw a background color on top of everything
CGContextRef context = (CGContextRef)[NSGraphicsContext currentContext];
CGContextSetBlendMode(context, kCGBlendModeNormal);
// [[NSColor backgroundColorForControl:@"ImageStyleButtonWithScheme3" colorScheme:[Preferences colorScheme]] set];
// [[NSBezierPath bezierPathWithRoundedRect:cellRect xRadius:xRad yRadius:yRad] fill];
// Draw gradient background color
if (![[self cell] isHighlighted])
{
NSGradient* aGradient = [[[NSGradient alloc] initWithColorsAndLocations:
[NSColor backgroundColorForControl:@"Color1ForGradientNotHighlighted" colorScheme:[Preferences colorScheme]], (CGFloat)0,
[NSColor backgroundColorForControl:@"Color2ForGradientNotHighlighted" colorScheme:[Preferences colorScheme]], (CGFloat)0.48,
[NSColor backgroundColorForControl:@"Color3ForGradientNotHighlighted" colorScheme:[Preferences colorScheme]], (CGFloat)0.52,
[NSColor backgroundColorForControl:@"Color4ForGradientNotHighlighted" colorScheme:[Preferences colorScheme]], (CGFloat)1.0,
nil] autorelease];
[aGradient drawInBezierPath:[NSBezierPath bezierPathWithRoundedRect:cellRect xRadius:xRad yRadius:yRad] angle: 90];
}
else
{
NSGradient* aGradient = [[[NSGradient alloc] initWithColorsAndLocations:
[NSColor backgroundColorForControl:@"Color1ForGradientHighlighted" colorScheme:[Preferences colorScheme]], (CGFloat)0,
[NSColor backgroundColorForControl:@"Color2ForGradientHighlighted" colorScheme:[Preferences colorScheme]], (CGFloat)0.48,
[NSColor backgroundColorForControl:@"Color3ForGradientHighlighted" colorScheme:[Preferences colorScheme]], (CGFloat)0.52,
[NSColor backgroundColorForControl:@"Color4ForGradientHighlighted" colorScheme:[Preferences colorScheme]], (CGFloat)1.0,
nil] autorelease];
[aGradient drawInBezierPath:[NSBezierPath bezierPathWithRoundedRect:cellRect xRadius:xRad yRadius:yRad] angle: 90];
}
// Draw outline border
[[NSColor foregroundColorForControl:nil colorScheme:[Preferences colorScheme]] set];
NSBezierPath *pathToStroke = [NSBezierPath bezierPathWithRoundedRect:cellRect xRadius:xRad yRadius:yRad];
[pathToStroke setLineWidth:0.5];
[pathToStroke stroke];
if ([self attributedTitle])
{
NSMutableAttributedString* attributedString2 = [[NSMutableAttributedString alloc] initWithAttributedString:[self attributedTitle]];
if ([self isEnabled])
{
NSRect shadowRect = [[self cell] titleRectForBounds:[self bounds]];
shadowRect.origin.y += 1;
NSMutableAttributedString* attributedString = [[NSMutableAttributedString alloc] initWithAttributedString:[self attributedTitle]];
if ([self isEnabled])
{
[attributedString addAttribute:NSForegroundColorAttributeName value:[NSColor blackColor] range:NSMakeRange(0, [attributedString length])];
}
[attributedString drawInRect:shadowRect];
[attributedString release];
[attributedString2 addAttribute:NSForegroundColorAttributeName
value:[NSColor foregroundColorForControl:nil colorScheme:[Preferences colorScheme]]
range:NSMakeRange(0, [attributedString2 length])];
}
else
{
[attributedString2 addAttribute:NSForegroundColorAttributeName
value:[NSColor foregroundColorForControl:@"ButtonDisabledTitleColor" colorScheme:[Preferences colorScheme]]
range:NSMakeRange(0, [attributedString2 length])];
}
[attributedString2 drawInRect:[[self cell] titleRectForBounds:[self bounds]]];
[attributedString2 release];
}
}
}
- (void) dealloc
{
if (addObserver)
{
[[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:[Preferences pathForKey:kPrefKeyGUIColorScheme]];
}
[super dealloc];
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if ([keyPath isEqualToString:[Preferences pathForKey:kPrefKeyGUIColorScheme]])
{
[self redrawScheme];
}
}
@end
@implementation ImageStyleButtonWithScheme2
- (id)initWithFrame:(NSRect)frameRect
{
self = [super initWithFrame:frameRect];
if (self != nil)
{
[self redrawScheme];
if (!addObserver)
{
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:[Preferences pathForKey:kPrefKeyGUIColorScheme] options:0 context: NULL];
addObserver = true;
}
}
return self;
}
- (void)viewDidMoveToWindow
{
[self redrawScheme];
if (!addObserver)
{
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:[Preferences pathForKey:kPrefKeyGUIColorScheme] options:0 context: NULL];
addObserver = true;
}
}
- (void) redrawScheme
{
NSString *imageFileName = [NSImageNameTemplatesLoader imageNameWithoutSchemePrefix:[[self image] name]];
if ([[[NSImageNameTemplatesLoader imageNameTemplateDictionary] allKeys] containsObject: imageFileName])
{
NSRect buttonRect = [self bounds];
NSString *imageName = nil;
NSString *folderName = nil;
NSString *memoryName = nil;
imageName = [[[NSImageNameTemplatesLoader imageNameTemplateDictionary] objectForKey:imageFileName]
objectForKey:[NSImageNameTemplatesLoader keyStringForColorScheme:[Preferences colorScheme]]];
folderName = [NSImageNameTemplatesLoader imageFolderNameForColorScheme:[Preferences colorScheme]];
memoryName = [NSImageNameTemplatesLoader memoryNameForName:imageName WithSchemePrefix:[Preferences colorScheme]];
NSImage *img = [NSImage imageNamed:imageName orFromBundleDirectory:folderName setMemoryName:memoryName];
if(img)
{
NSSize imgSize = [img size];
[img setSize: NSMakeSize(MIN(imgSize.width,buttonRect.size.width-8),MIN(imgSize.height,buttonRect.size.height-8))];
[self setImage:img];
}
[self setNeedsDisplay: true];
}
else if ([[NSImageNameTemplatesLoader imagesNeedChangeFolderWithScheme] containsObject:imageFileName])
{
NSRect buttonRect = [self bounds];
NSString *folderName = nil;
NSString *memoryName = nil;
folderName = [NSImageNameTemplatesLoader imageFolderNameForColorScheme:[Preferences colorScheme]];
memoryName = [NSImageNameTemplatesLoader memoryNameForName:imageFileName WithSchemePrefix:[Preferences colorScheme]];
NSImage * img = [NSImage imageNamed:imageFileName orFromBundleDirectory:folderName setMemoryName:memoryName];
if(img)
{
NSSize imgSize = [img size];
[img setSize: NSMakeSize(MIN(imgSize.width,buttonRect.size.width-8),MIN(imgSize.height,buttonRect.size.height-8))];
[self setImage:img];
}
[self setNeedsDisplay: true];
}
}
- (void) dealloc
{
if (addObserver)
{
[[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:[Preferences pathForKey:kPrefKeyGUIColorScheme]];
}
[super dealloc];
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if ([keyPath isEqualToString:[Preferences pathForKey:kPrefKeyGUIColorScheme]])
{
[self redrawScheme];
}
}
@end
@implementation ImageStyleButtonWithScheme3
- (id)initWithFrame:(NSRect)frameRect
{
self = [super initWithFrame:frameRect];
if (self != nil)
{
if (!addObserver)
{
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:[Preferences pathForKey:kPrefKeyGUIColorScheme] options:0 context: NULL];
addObserver = true;
}
}
return self;
}
- (void)viewDidMoveToWindow
{
if (!addObserver)
{
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:[Preferences pathForKey:kPrefKeyGUIColorScheme] options:0 context: NULL];
addObserver = true;
}
}
- (void) drawRect:(NSRect)dirtyRect
{
if ([Preferences colorScheme] != (NSUInteger)[NSColor silverSchemeIndex])
{
NSRect cellRect = [self bounds];
NSUInteger controlHeight = (NSUInteger)cellRect.size.height;
if (![[self image] name])
{
[super drawRect:dirtyRect];
CGFloat xRad=0, yRad=0;
if (controlHeight == 16)
{
switch ([self bezelStyle])
{
case NSRoundRectBezelStyle:
case NSTexturedRoundedBezelStyle:
case NSShadowlessSquareBezelStyle:
default:
{
cellRect.size.width -= 4;
cellRect.origin.x += 2;
cellRect.size.height -=3;
cellRect.origin.y += 1;
xRad = 2;
yRad = 2;
break;
}
}
}
else
{
switch ([self bezelStyle])
{
case NSRoundRectBezelStyle:
{
xRad = 7;
yRad = cellRect.size.height/2;
break;
}
case NSTexturedRoundedBezelStyle:
{
cellRect.origin.y += 2;
cellRect.size.height -= 4;
xRad = 4;
yRad = 4;
break;
}
case NSShadowlessSquareBezelStyle:
{
xRad = 0;
yRad = 0;
break;
}
default:
{
cellRect.size.width -= 11;
cellRect.origin.x += 5.5;
cellRect.size.height -= 11;
cellRect.origin.y += 4.5;
xRad = 3;
yRad = 3;
break;
}
}
}
// Draw a background color on top of everything
CGContextRef context = (CGContextRef)[NSGraphicsContext currentContext];
CGContextSetBlendMode(context, kCGBlendModeNormal);
// [[NSColor backgroundColorForControl:@"ImageStyleButtonWithScheme3" colorScheme:[Preferences colorScheme]] set];
// [[NSBezierPath bezierPathWithRoundedRect:cellRect xRadius:xRad yRadius:yRad] fill];
// Draw gradient background color
if (![[self cell] isHighlighted])
{
NSGradient* aGradient = [[[NSGradient alloc] initWithColorsAndLocations:
[NSColor backgroundColorForControl:@"Color1ForGradientNotHighlighted" colorScheme:[Preferences colorScheme]], (CGFloat)0,
[NSColor backgroundColorForControl:@"Color2ForGradientNotHighlighted" colorScheme:[Preferences colorScheme]], (CGFloat)0.48,
[NSColor backgroundColorForControl:@"Color3ForGradientNotHighlighted" colorScheme:[Preferences colorScheme]], (CGFloat)0.52,
[NSColor backgroundColorForControl:@"Color4ForGradientNotHighlighted" colorScheme:[Preferences colorScheme]], (CGFloat)1.0,
nil] autorelease];
[aGradient drawInBezierPath:[NSBezierPath bezierPathWithRoundedRect:cellRect xRadius:xRad yRadius:yRad] angle: 90];
}
else
{
NSGradient* aGradient = [[[NSGradient alloc] initWithColorsAndLocations:
[NSColor backgroundColorForControl:@"Color1ForGradientHighlighted" colorScheme:[Preferences colorScheme]], (CGFloat)0,
[NSColor backgroundColorForControl:@"Color2ForGradientHighlighted" colorScheme:[Preferences colorScheme]], (CGFloat)0.48,
[NSColor backgroundColorForControl:@"Color3ForGradientHighlighted" colorScheme:[Preferences colorScheme]], (CGFloat)0.52,
[NSColor backgroundColorForControl:@"Color4ForGradientHighlighted" colorScheme:[Preferences colorScheme]], (CGFloat)1.0,
nil] autorelease];
[aGradient drawInBezierPath:[NSBezierPath bezierPathWithRoundedRect:cellRect xRadius:xRad yRadius:yRad] angle: 90];
}
// Draw outline border
[[NSColor foregroundColorForControl:nil colorScheme:[Preferences colorScheme]] set];
NSBezierPath* pathToStroke = [NSBezierPath bezierPathWithRoundedRect:cellRect xRadius:xRad yRadius:yRad];
[pathToStroke setLineWidth:0.5];
[pathToStroke stroke];
if ([self attributedTitle])
{
NSRect shadowRect = [[self cell] titleRectForBounds:[self bounds]];
shadowRect.origin.y += 1;
NSMutableAttributedString* attributedString = [[NSMutableAttributedString alloc] initWithAttributedString:[self attributedTitle]];
if ([self isEnabled])
{
[attributedString addAttribute:NSForegroundColorAttributeName value:[NSColor blackColor] range:NSMakeRange(0, [attributedString length])];
}
[attributedString drawInRect:shadowRect];
[attributedString release];
NSMutableAttributedString* attributedString2 = [[NSMutableAttributedString alloc] initWithAttributedString:[self attributedTitle]];
if ([self isEnabled])
{
[attributedString2 addAttribute:NSForegroundColorAttributeName
value:[NSColor foregroundColorForControl:nil colorScheme:[Preferences colorScheme]]
range:NSMakeRange(0, [attributedString2 length])];
}
else
{
[attributedString2 addAttribute:NSForegroundColorAttributeName
value:[NSColor foregroundColorForControl:@"ButtonDisabledTitleColor" colorScheme:[Preferences colorScheme]]
range:NSMakeRange(0, [attributedString2 length])];
}
[attributedString2 drawInRect:[[self cell] titleRectForBounds:[self bounds]]];
[attributedString2 release];
}
}
else
{
[super drawRect:dirtyRect];
CGContextRef context = (CGContextRef)[NSGraphicsContext currentContext];
CGContextSetBlendMode(context, kCGBlendModeNormal);
[[NSColor backgroundColorForControl:@"ImageStyleButtonWithScheme3" colorScheme:[Preferences colorScheme]] set];
[[NSBezierPath bezierPathWithRect:dirtyRect] fill];
NSString *imageFileName = [NSImageNameTemplatesLoader imageNameWithoutSchemePrefix:[[self image] name]];
NSImage *imageToDraw = nil;
if ([[[NSImageNameTemplatesLoader imageNameTemplateDictionary] allKeys] containsObject: imageFileName])
{
NSString *imageName = nil;
NSString *folderName = nil;
NSString *memoryName = nil;
imageName = [[[NSImageNameTemplatesLoader imageNameTemplateDictionary] objectForKey:imageFileName]
objectForKey:[NSImageNameTemplatesLoader keyStringForColorScheme:[Preferences colorScheme]]];
folderName = [NSImageNameTemplatesLoader imageFolderNameForColorScheme:[Preferences colorScheme]];
memoryName = [NSImageNameTemplatesLoader memoryNameForName:imageName WithSchemePrefix:[Preferences colorScheme]];
imageToDraw = [[NSImage imageNamed:imageName orFromBundleDirectory:folderName setMemoryName:memoryName] copy];
}
else
{
NSString *imageFileName = [[self image] name];
NSString *folderName = nil;
NSString *memoryName = nil;
folderName = [NSImageNameTemplatesLoader imageFolderNameForColorScheme:[Preferences colorScheme]];
memoryName = [NSImageNameTemplatesLoader memoryNameForName:imageFileName WithSchemePrefix:[Preferences colorScheme]];
imageToDraw = [[NSImage imageNamed:imageFileName orFromBundleDirectory:folderName setMemoryName:memoryName] copy];
}
if(imageToDraw)
{
NSSize imgSize = [imageToDraw size];
NSRect buttonRect = [self bounds];
[imageToDraw setSize: NSMakeSize(MIN(imgSize.width,buttonRect.size.width),MIN(imgSize.height,buttonRect.size.height))];
[[self cell] drawImage:imageToDraw withFrame: [[self cell] imageRectForBounds:buttonRect] inView: self];
[imageToDraw release];
}
}
}
else
{
[super drawRect:dirtyRect];
}
}
- (void) dealloc
{
if (addObserver)
{
[[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:[Preferences pathForKey:kPrefKeyGUIColorScheme]];
}
[super dealloc];
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if ([keyPath isEqualToString:[Preferences pathForKey:kPrefKeyGUIColorScheme]])
{
[self setNeedsDisplay: true];
}
}
@end
@implementation PopUpButtonCellWithScheme
- (void)drawBezelWithFrame: (NSRect)frame inView: (NSView*)inView
{
if ([Preferences colorScheme] != (NSUInteger)[NSColor silverSchemeIndex])
{
NSRect cellFrame = frame;
cellFrame.origin.y += 2;
cellFrame.size.height -= 4;
NSGradient* aGradient = [[[NSGradient alloc] initWithColorsAndLocations:
[NSColor backgroundColorForControl:@"Color1ForGradientNotHighlighted" colorScheme:[Preferences colorScheme]], (CGFloat)0,
[NSColor backgroundColorForControl:@"Color2ForGradientNotHighlighted" colorScheme:[Preferences colorScheme]], (CGFloat)0.48,
[NSColor backgroundColorForControl:@"Color3ForGradientNotHighlighted" colorScheme:[Preferences colorScheme]], (CGFloat)0.52,
[NSColor backgroundColorForControl:@"Color4ForGradientNotHighlighted" colorScheme:[Preferences colorScheme]], (CGFloat)1.0,
nil] autorelease];
[aGradient drawInBezierPath:[NSBezierPath bezierPathWithRoundedRect:cellFrame xRadius:7 yRadius:7] angle: 90];
[[NSColor foregroundColorForControl:nil colorScheme:[Preferences colorScheme]] set];
NSBezierPath *pathToStroke = [NSBezierPath bezierPathWithRoundedRect:cellFrame xRadius:7 yRadius:7];
[pathToStroke setLineWidth:0.5];
[pathToStroke stroke];
// Draw black shadow for title
// NSRect shadowRect = [self titleRectForBounds:frame];
// shadowRect.origin.y += 1;
// NSMutableAttributedString* attributedString = [[NSMutableAttributedString alloc] initWithAttributedString:[self attributedTitle]];
// [attributedString addAttribute:NSForegroundColorAttributeName value:[NSColor blackColor] range:NSMakeRange(0, [attributedString length])];
// [attributedString drawInRect:shadowRect];
// [attributedString release];
NSRect cellRect2 = frame;
NSSize trilSize = NSMakeSize(4,4);
CGFloat xGap = 6, yDownGap = 3, yUpGap = 9;
NSRect drawRect1 = NSMakeRect(NSMaxX(cellRect2)-trilSize.width-xGap, frame.origin.y + yDownGap, trilSize.width, trilSize.height);
NSBezierPath* drawPath1 = [NSBezierPath bezierPath];
[drawPath1 moveToPoint:NSMakePoint(NSMinX(drawRect1), NSMaxY(drawRect1))];
[drawPath1 lineToPoint:NSMakePoint(NSMaxX(drawRect1), NSMaxY(drawRect1))];
[drawPath1 lineToPoint:NSMakePoint(NSMidX(drawRect1), NSMinY(drawRect1))];
[drawPath1 lineToPoint:NSMakePoint(NSMinX(drawRect1), NSMaxY(drawRect1))];
[[NSColor foregroundColorForControl:nil colorScheme:[Preferences colorScheme]] setFill];
[drawPath1 fill];
NSRect drawRect2 = NSMakeRect(NSMaxX(cellRect2)-trilSize.width-xGap, frame.origin.y + yUpGap, trilSize.width, trilSize.height);
NSBezierPath* drawPath2 = [NSBezierPath bezierPath];
[drawPath2 moveToPoint:NSMakePoint(NSMinX(drawRect2), NSMinY(drawRect2))];
[drawPath2 lineToPoint:NSMakePoint(NSMaxX(drawRect2), NSMinY(drawRect2))];
[drawPath2 lineToPoint:NSMakePoint(NSMidX(drawRect2), NSMaxY(drawRect2))];
[drawPath2 lineToPoint:NSMakePoint(NSMinX(drawRect2), NSMinY(drawRect2))];
[[NSColor foregroundColorForControl:nil colorScheme:[Preferences colorScheme]] setFill];
[drawPath2 fill];
}
else
{
[super drawBezelWithFrame:frame inView:inView];
}
}
- (NSRect)drawTitle:(NSAttributedString*)title withFrame:(NSRect)frame inView:(NSView*)controlView
{
NSMutableAttributedString* strTitle = [[[NSMutableAttributedString alloc] initWithAttributedString:title] autorelease];
[strTitle addAttribute:NSForegroundColorAttributeName
value:[NSColor foregroundColorForControl:nil colorScheme:[Preferences colorScheme]]
range:NSMakeRange(0, [strTitle length])];
return [super drawTitle:strTitle withFrame:frame inView:controlView];
}
@end
@implementation PopUpButtonWithScheme
- (id)initWithFrame:(NSRect)frameRect
{
self = [super initWithFrame:frameRect];
if (self != nil)
{
[self redrawScheme];
if (!addObserver)
{
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:[Preferences pathForKey:kPrefKeyGUIColorScheme] options:0 context: NULL];
addObserver = true;
}
}
return self;
}
- (void)viewDidMoveToWindow
{
[self redrawScheme];
if (!addObserver)
{
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:[Preferences pathForKey:kPrefKeyGUIColorScheme] options:0 context: NULL];
addObserver = true;
}
}
- (void) redrawScheme
{
[self setTextColor: [NSColor foregroundColorForControl:nil colorScheme:[Preferences colorScheme]]];
[self setNeedsDisplay: true];
}
- (void) setTextColor: (NSColor *) color
{
[color retain];
[textColor release];
textColor = color;
}
- (void) drawRect:(NSRect) rect
{
[super drawRect: rect];
if ([Preferences colorScheme] != (NSUInteger)[NSColor silverSchemeIndex])
{
NSRect cellRect = [self bounds];
cellRect.origin = NSMakePoint(0, 0);
// cellRect.size.height -= 8;
// cellRect.origin.y += 5;
cellRect.size.height -= 11;
cellRect.origin.y += 6;
if (!atLeastLion())
{
CGContextRef context = (CGContextRef)[NSGraphicsContext currentContext];
CGContextSetBlendMode(context, kCGBlendModeNormal);
[[NSColor backgroundColorForControl:@"NSWindow" colorScheme:[Preferences colorScheme]] set];
[[NSBezierPath bezierPathWithRoundedRect:cellRect xRadius:4 yRadius:4] fill];
}
[[NSBezierPath bezierPathWithRoundedRect:cellRect xRadius:4 yRadius:4] addClip];
[[NSBezierPath bezierPathWithRect:rect] addClip];
// Draw a background color on top of everything
// CGContextRef context = (CGContextRef)[NSGraphicsContext currentContext];
// CGContextSetBlendMode(context, kCGBlendModeNormal);
// [[NSColor backgroundColorForControl:@"PopUpButtonWithScheme" colorScheme:[Preferences colorScheme]] set];
// [[NSBezierPath bezierPathWithRoundedRect:cellRect xRadius:5 yRadius:5] fill];
if (![[self cell] isHighlighted])
{
// NSGradient* aGradient = [[[NSGradient alloc] initWithColorsAndLocations:
// [NSColor colorWithDeviceRed:60.0/255 green:60.0/255 blue:60.0/255 alpha:0.7f], (CGFloat)0,
// [NSColor colorWithDeviceRed:55.0/255 green:55.0/255 blue:55.0/255 alpha:0.7f], (CGFloat)0.48,
// [NSColor colorWithDeviceRed:53.0/255 green:53.0/255 blue:53.0/255 alpha:0.7f], (CGFloat)0.52,
// [NSColor colorWithDeviceRed:48.0/255 green:48.0/255 blue:48.0/255 alpha:0.7f], (CGFloat)1.0,
// nil] autorelease];
// [aGradient drawInBezierPath:[NSBezierPath bezierPathWithRoundedRect:cellRect xRadius:5 yRadius:5] angle: 90];
[[NSColor backgroundColorForControl:@"PopUpButtonWithScheme" colorScheme:[Preferences colorScheme]] set];
[[NSBezierPath bezierPathWithRoundedRect:cellRect xRadius:4 yRadius:4] fill];
}
else
{
NSGradient* aGradient = [[[NSGradient alloc] initWithColorsAndLocations:
[NSColor backgroundColorForControl:@"Color1ForGradientHighlighted" colorScheme:[Preferences colorScheme]], (CGFloat)0,
[NSColor backgroundColorForControl:@"Color2ForGradientHighlighted" colorScheme:[Preferences colorScheme]], (CGFloat)0.48,
[NSColor backgroundColorForControl:@"Color3ForGradientHighlighted" colorScheme:[Preferences colorScheme]], (CGFloat)0.52,
[NSColor backgroundColorForControl:@"Color4ForGradientHighlighted" colorScheme:[Preferences colorScheme]], (CGFloat)1.0,
nil] autorelease];
[aGradient drawInBezierPath:[NSBezierPath bezierPathWithRoundedRect:cellRect xRadius:4 yRadius:4] angle: 90];
}
// Draw outline border
[[NSColor foregroundColorForControl:nil colorScheme:[Preferences colorScheme]] set];
NSBezierPath * pathToStroke = [NSBezierPath bezierPathWithRoundedRect:cellRect xRadius:4 yRadius:4];
[pathToStroke setLineWidth:0.5];
[pathToStroke stroke];
// Draw black shadow for title
NSRect shadowRect = [[self cell] titleRectForBounds:[self bounds]];
shadowRect.origin.y += 1;
NSMutableAttributedString* attributedString = [[NSMutableAttributedString alloc] initWithAttributedString:[self attributedTitle]];
[attributedString addAttribute:NSForegroundColorAttributeName value:[NSColor blackColor] range:NSMakeRange(0, [attributedString length])];
[attributedString drawInRect:shadowRect];
[attributedString release];
NSMutableAttributedString* attributedString2 = [[NSMutableAttributedString alloc] initWithAttributedString:[self attributedTitle]];
[attributedString2 addAttribute:NSForegroundColorAttributeName value:textColor range:NSMakeRange(0, [attributedString2 length])];
[attributedString2 drawInRect:[[self cell] titleRectForBounds:[self bounds]]];
[attributedString2 release];
NSSize size = NSMakeSize(7,6);
NSRect triangleRect = NSMakeRect(NSMaxX(cellRect)-size.width-6.5, 14, size.width, size.height);
NSBezierPath* drawPath = [NSBezierPath bezierPath];
[drawPath moveToPoint:NSMakePoint(NSMinX(triangleRect), NSMinY(triangleRect))];
[drawPath lineToPoint:NSMakePoint(NSMaxX(triangleRect), NSMinY(triangleRect))];
[drawPath lineToPoint:NSMakePoint(NSMidX(triangleRect), NSMaxY(triangleRect))];
[drawPath lineToPoint:NSMakePoint(NSMinX(triangleRect), NSMinY(triangleRect))];
[[NSColor foregroundColorForControl:nil colorScheme:[Preferences colorScheme]] set];
[drawPath fill];
}
}
- (void) dealloc
{
[textColor release];
if (addObserver)
{
[[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:[Preferences pathForKey:kPrefKeyGUIColorScheme]];
}
[super dealloc];
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if ([keyPath isEqualToString:[Preferences pathForKey:kPrefKeyGUIColorScheme]])
{
[self redrawScheme];
}
}
@end
@implementation PopUpButtonWithScheme2
- (id)initWithFrame:(NSRect)frameRect
{
self = [super initWithFrame:frameRect];
if (self != nil)
{
[self redrawScheme];
if (!addObserver)
{
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:[Preferences pathForKey:kPrefKeyGUIColorScheme] options:0 context: NULL];
addObserver = true;
style = 0;
}
}
return self;
}
- (void)viewDidMoveToWindow
{
[self redrawScheme];
if (!addObserver)
{
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:[Preferences pathForKey:kPrefKeyGUIColorScheme] options:0 context: NULL];
addObserver = true;
}
}
- (void) redrawScheme
{
[self setTextColor: [NSColor foregroundColorForControl:nil colorScheme:[Preferences colorScheme]]];
[self setNeedsDisplay: true];
}
- (void) setTextColor: (NSColor *) color
{
[color retain];
[textColor release];
textColor = color;
}
- (void) setStyle:(NSUInteger) num
{
style = num;
}
- (void) drawRect:(NSRect) rect
{
[super drawRect: rect];
NSRect cellRect = [self bounds];
if ([Preferences colorScheme] != (NSUInteger)[NSColor silverSchemeIndex])
{
cellRect.origin = NSMakePoint(0, 0);
CGFloat yUpGap = 0, yDownGap = 0;
switch (style)
{
case 1:
{
cellRect.size.height -= 8;
cellRect.origin.y += 5;
yUpGap = 7;
yDownGap = 14.5;
break;
}
default:
{
yUpGap = 6;
yDownGap = 13.5;
break;
}
}
[[NSBezierPath bezierPathWithRoundedRect:cellRect xRadius:5 yRadius:5] addClip];
[[NSBezierPath bezierPathWithRect:rect] addClip];
// Draw a background color on top of everything
CGContextRef context = (CGContextRef)[NSGraphicsContext currentContext];
CGContextSetBlendMode(context, kCGBlendModeNormal);
switch (style)
{
case 1:
{
NSGradient* aGradient = nil;
if ([[self cell] isHighlighted])
{
aGradient = [[[NSGradient alloc] initWithColorsAndLocations:
[NSColor backgroundColorForControl:@"Color1ForGradientHighlighted" colorScheme:[Preferences colorScheme]], (CGFloat)0,
[NSColor backgroundColorForControl:@"Color2ForGradientHighlighted" colorScheme:[Preferences colorScheme]], (CGFloat)0.48,
[NSColor backgroundColorForControl:@"Color3ForGradientHighlighted" colorScheme:[Preferences colorScheme]], (CGFloat)0.52,
[NSColor backgroundColorForControl:@"Color4ForGradientHighlighted" colorScheme:[Preferences colorScheme]], (CGFloat)1.0,
nil] autorelease];
}
else
{
aGradient = [[[NSGradient alloc] initWithColorsAndLocations:
[NSColor backgroundColorForControl:@"Color1ForGradientNotHighlighted" colorScheme:[Preferences colorScheme]], (CGFloat)0,
[NSColor backgroundColorForControl:@"Color2ForGradientNotHighlighted" colorScheme:[Preferences colorScheme]], (CGFloat)0.48,
[NSColor backgroundColorForControl:@"Color3ForGradientNotHighlighted" colorScheme:[Preferences colorScheme]], (CGFloat)0.52,
[NSColor backgroundColorForControl:@"Color4ForGradientNotHighlighted" colorScheme:[Preferences colorScheme]], (CGFloat)1.0,
nil] autorelease];
}
[aGradient drawInBezierPath:[NSBezierPath bezierPathWithRect:cellRect] angle: 90];
// Draw outline border
[[NSColor foregroundColorForControl:nil colorScheme:[Preferences colorScheme]] set];
NSBezierPath * pathToStroke = [NSBezierPath bezierPathWithRoundedRect:cellRect xRadius:5 yRadius:5];
[pathToStroke setLineWidth:1];
[pathToStroke stroke];
break;
}
default:
{
[[NSColor backgroundColorForControl:@"PopUpButtonWithScheme" colorScheme:[Preferences colorScheme]] set];
[[NSBezierPath bezierPathWithRect:rect] fill];
break;
}
}
// Draw black shadow for title
NSRect shadowRect = [[self cell] titleRectForBounds:[self bounds]];
shadowRect.origin.y += 1;
NSMutableAttributedString* attributedString = [[NSMutableAttributedString alloc] initWithAttributedString:[self attributedTitle]];
[attributedString addAttribute:NSForegroundColorAttributeName value:[NSColor blackColor] range:NSMakeRange(0, [attributedString length])];
[attributedString drawInRect:shadowRect];
[attributedString release];
NSMutableAttributedString* attributedString2 = [[NSMutableAttributedString alloc] initWithAttributedString:[self attributedTitle]];
[attributedString2 addAttribute:NSForegroundColorAttributeName value:textColor range:NSMakeRange(0, [attributedString2 length])];
[attributedString2 drawInRect:[[self cell] titleRectForBounds:[self bounds]]];
[attributedString2 release];
NSSize size = NSMakeSize(4, 4);
NSRect drawRect1 = NSMakeRect(NSMaxX(cellRect)-size.width-6.5, yUpGap, size.width, size.height);
NSBezierPath* drawPath1 = [NSBezierPath bezierPath];
[drawPath1 moveToPoint:NSMakePoint(NSMinX(drawRect1), NSMaxY(drawRect1))];
[drawPath1 lineToPoint:NSMakePoint(NSMaxX(drawRect1), NSMaxY(drawRect1))];
[drawPath1 lineToPoint:NSMakePoint(NSMidX(drawRect1), NSMinY(drawRect1))];
[drawPath1 lineToPoint:NSMakePoint(NSMinX(drawRect1), NSMaxY(drawRect1))];
[[NSColor foregroundColorForControl:nil colorScheme:[Preferences colorScheme]] set];
[drawPath1 fill];
NSRect drawRect2 = NSMakeRect(NSMaxX(cellRect)-size.width-6.5, yDownGap, size.width, size.height);
NSBezierPath* drawPath2 = [NSBezierPath bezierPath];
[drawPath2 moveToPoint:NSMakePoint(NSMinX(drawRect2), NSMinY(drawRect2))];
[drawPath2 lineToPoint:NSMakePoint(NSMaxX(drawRect2), NSMinY(drawRect2))];
[drawPath2 lineToPoint:NSMakePoint(NSMidX(drawRect2), NSMaxY(drawRect2))];
[drawPath2 lineToPoint:NSMakePoint(NSMinX(drawRect2), NSMinY(drawRect2))];
[[NSColor foregroundColorForControl:nil colorScheme:[Preferences colorScheme]] set];
[drawPath2 fill];
}
}
- (void) dealloc
{
[textColor release];
if (addObserver)
{
[[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:[Preferences pathForKey:kPrefKeyGUIColorScheme]];
}
[super dealloc];
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if ([keyPath isEqualToString:[Preferences pathForKey:kPrefKeyGUIColorScheme]])
{
[self redrawScheme];
}
}
@end
@implementation PopUpButtonWithScheme3
- (id)initWithFrame:(NSRect)frameRect
{
self = [super initWithFrame:frameRect];
if (self != nil)
{
if (!addObserver)
{
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:[Preferences pathForKey:kPrefKeyGUIColorScheme] options:0 context: NULL];
addObserver = true;
}
}
return self;
}
- (void)viewDidMoveToWindow
{
if (!addObserver)
{
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:[Preferences pathForKey:kPrefKeyGUIColorScheme] options:0 context: NULL];
addObserver = true;
}
}
- (void) drawRect:(NSRect) rect
{
[super drawRect: rect];
if ([Preferences colorScheme] != (NSUInteger)[NSColor silverSchemeIndex])
{
NSRect cellRect = [self bounds];
NSUInteger controlHeight = (NSUInteger)cellRect.size.height;
NSUInteger xRadius = 0, yRadius = 0;
NSSize trilSize = NSMakeSize(5, 4);
CGFloat xGap = 0, yDownGap = 0, yUpGap = 0;
switch (controlHeight)
{
case 15:
{
cellRect.origin = NSMakePoint(0, 0);
cellRect.origin.x += 1;
cellRect.size.width -= 2;
cellRect.origin.y += 1;
cellRect.size.height -= 2;
xRadius = 4;
yRadius = 4;
xGap = 10;
yDownGap = 3;
yUpGap = 8;
trilSize = NSMakeSize(3, 3);
break;
}
case 21:
{
cellRect.origin = NSMakePoint(0, 0);
cellRect.origin.x += 1;
cellRect.size.width -= 2;
cellRect.origin.y += 2;
cellRect.size.height -= 3;
xRadius = 4;
yRadius = 4;
xGap = 10;
yDownGap = 4.5;
yUpGap = 11.5;
trilSize = NSMakeSize(5, 4);
break;
}
case 28:
{
cellRect.origin = NSMakePoint(0, 0);
cellRect.origin.x += 3;
cellRect.size.width -= 6;
cellRect.origin.y += 4;
cellRect.size.height -=10;
xRadius = 5;
yRadius = 5;
xGap = 10;
yDownGap = 7.5;
yUpGap = 13.5;
trilSize = NSMakeSize(4, 3);
break;
}
case 32:
{
cellRect.origin = NSMakePoint(0, 0);
cellRect.origin.x += 2;
cellRect.size.width -= 5;
cellRect.origin.y += 5;
cellRect.size.height -= 11;
xRadius = 5;
yRadius = 5;
xGap = 10;
yDownGap = 9.5;
yUpGap = 16.5;
trilSize = NSMakeSize(5, 4);
break;
}
default:
{
cellRect.origin = NSMakePoint(0, 0);
cellRect.origin.x += 2;
cellRect.size.width -= 4;
cellRect.origin.y += 1;
cellRect.size.height -= 4;
xRadius = 5;
yRadius = 5;
xGap = 10;
yDownGap = 4.5;
yUpGap = 11.5;
trilSize = NSMakeSize(5, 4);
break;
}
}
[[NSBezierPath bezierPathWithRoundedRect:cellRect xRadius:xRadius yRadius:yRadius] addClip];
[[NSBezierPath bezierPathWithRect:rect] addClip];
// Draw a background color on top of everything
CGContextRef context = (CGContextRef)[NSGraphicsContext currentContext];
CGContextSetBlendMode(context, kCGBlendModeNormal);
// [[NSColor backgroundColorForControl:@"PopUpButtonWithSchemeInPMDPanels" colorScheme:[Preferences colorScheme]] set];
// [[NSBezierPath bezierPathWithRect:rect] fill];
NSGradient* aGradient = [[[NSGradient alloc] initWithColorsAndLocations:
[NSColor backgroundColorForControl:@"Color1ForGradientNotHighlighted" colorScheme:[Preferences colorScheme]], (CGFloat)0,
[NSColor backgroundColorForControl:@"Color2ForGradientNotHighlighted" colorScheme:[Preferences colorScheme]], (CGFloat)0.48,
[NSColor backgroundColorForControl:@"Color3ForGradientNotHighlighted" colorScheme:[Preferences colorScheme]], (CGFloat)0.52,
[NSColor backgroundColorForControl:@"Color4ForGradientNotHighlighted" colorScheme:[Preferences colorScheme]], (CGFloat)1.0,
nil] autorelease];
[aGradient drawInBezierPath:[NSBezierPath bezierPathWithRect:cellRect] angle: 90];
[[NSColor foregroundColorForControl:nil colorScheme:[Preferences colorScheme]] set];
NSBezierPath *pathToStroke = [NSBezierPath bezierPathWithRoundedRect:cellRect xRadius:xRadius yRadius:yRadius];
[pathToStroke setLineWidth:1];
[pathToStroke stroke];
// Draw black shadow for title
NSRect shadowRect = [[self cell] titleRectForBounds:[self bounds]];
shadowRect.origin.y += 1;
NSMutableAttributedString* attributedString = [[NSMutableAttributedString alloc] initWithAttributedString:[self attributedTitle]];
[attributedString addAttribute:NSForegroundColorAttributeName value:[NSColor blackColor] range:NSMakeRange(0, [attributedString length])];
[attributedString drawInRect:shadowRect];
[attributedString release];
if ([self image])
{
NSRect imageRect = [[self cell] imageRectForBounds:[self bounds]];
[[self cell] drawImage:[self image] withFrame:imageRect inView:self];
}
NSMutableAttributedString* attributedString2 = [[NSMutableAttributedString alloc] initWithAttributedString:[self attributedTitle]];
[attributedString2 addAttribute:NSForegroundColorAttributeName value:[NSColor foregroundColorForControl:nil colorScheme:[Preferences colorScheme]] range:NSMakeRange(0, [attributedString2 length])];
[attributedString2 drawInRect:[[self cell] titleRectForBounds:[self bounds]]];
[attributedString2 release];
NSRect cellRect2 = [self bounds];
NSRect drawRect1 = NSMakeRect(NSMaxX(cellRect2)-trilSize.width-xGap, yDownGap, trilSize.width, trilSize.height);
NSBezierPath* drawPath1 = [NSBezierPath bezierPath];
[drawPath1 moveToPoint:NSMakePoint(NSMinX(drawRect1), NSMaxY(drawRect1))];
[drawPath1 lineToPoint:NSMakePoint(NSMaxX(drawRect1), NSMaxY(drawRect1))];
[drawPath1 lineToPoint:NSMakePoint(NSMidX(drawRect1), NSMinY(drawRect1))];
[drawPath1 lineToPoint:NSMakePoint(NSMinX(drawRect1), NSMaxY(drawRect1))];
[[NSColor foregroundColorForControl:nil colorScheme:[Preferences colorScheme]] set];
[drawPath1 fill];
NSRect drawRect2 = NSMakeRect(NSMaxX(cellRect2)-trilSize.width-xGap, yUpGap, trilSize.width, trilSize.height);
NSBezierPath* drawPath2 = [NSBezierPath bezierPath];
[drawPath2 moveToPoint:NSMakePoint(NSMinX(drawRect2), NSMinY(drawRect2))];
[drawPath2 lineToPoint:NSMakePoint(NSMaxX(drawRect2), NSMinY(drawRect2))];
[drawPath2 lineToPoint:NSMakePoint(NSMidX(drawRect2), NSMaxY(drawRect2))];
[drawPath2 lineToPoint:NSMakePoint(NSMinX(drawRect2), NSMinY(drawRect2))];
[[NSColor foregroundColorForControl:nil colorScheme:[Preferences colorScheme]] set];
[drawPath2 fill];
}
}
- (void) dealloc
{
if (addObserver)
{
[[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:[Preferences pathForKey:kPrefKeyGUIColorScheme]];
}
[super dealloc];
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if ([keyPath isEqualToString:[Preferences pathForKey:kPrefKeyGUIColorScheme]])
{
[self setNeedsDisplay:true];
}
}
@end
@implementation ComboBoxWithScheme
- (id)initWithFrame:(NSRect)frameRect
{
self = [super initWithFrame:frameRect];
if (self != nil)
{
if (!addObserver)
{
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:[Preferences pathForKey:kPrefKeyGUIColorScheme] options:0 context: NULL];
addObserver = true;
}
}
return self;
}
- (void)viewDidMoveToWindow
{
if (!addObserver)
{
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:[Preferences pathForKey:kPrefKeyGUIColorScheme] options:0 context: NULL];
addObserver = true;
}
}
- (void) drawRect:(NSRect) rect
{
[self setTextColor:[NSColor foregroundColorForControl:nil colorScheme:[Preferences colorScheme]]];
[self setBackgroundColor:[NSColor backgroundColorForControl:@"ComboBoxWithScheme" colorScheme:[Preferences colorScheme]]];
[self setDrawsBackground:true];
[super drawRect: rect];
if ([Preferences colorScheme] != (NSUInteger)[NSColor silverSchemeIndex])
{
[self setBordered:false];
// NSRect cellRect= [self bounds];
// switch ((NSUInteger)[[[self cell] font] pointSize])
// {
// case 9:
// {
// cellRect.origin.y += 2.5;
// cellRect.size.height -= 7;
// cellRect.size.width -= 16;
// break;
// }
// case 11:
// {
// cellRect.origin.y += 3.5;
// cellRect.size.height -= 7;
// cellRect.size.width -= 18;
// break;
// }
// default:
// {
// break;
// }
// }
//
// [[NSColor foregroundColorForControl:nil colorScheme:[Preferences colorScheme]] set];
// [NSBezierPath setDefaultLineWidth:1];
// [[NSBezierPath bezierPathWithRect: cellRect] stroke];
}
else
{
[self setBordered:true];
}
}
- (void) dealloc
{
if (addObserver)
{
[[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:[Preferences pathForKey:kPrefKeyGUIColorScheme]];
}
[super dealloc];
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if ([keyPath isEqualToString:[Preferences pathForKey:kPrefKeyGUIColorScheme]])
{
[self setNeedsDisplay:true];
}
}
@end
@implementation ImageAndTextCellForGroupItemWithScheme
- (void)drawInteriorWithFrame:(NSRect)bounds inView:(NSView *)controlView
{
NSRect imageRect = [self imageRectForBounds:bounds];
if([self isHighlighted])
{
NSColor * highlighteColor = [self highlightColorWithFrame:bounds inView:controlView];
if(highlighteColor)
{
[highlighteColor set];
NSRectFill(bounds);
}
}else if([self drawsBackground])
{
NSColor * backgroundColor = [self backgroundColor];
if(backgroundColor)
{
[backgroundColor set];
NSRectFill(bounds);
}
}
if (iImage != nil && [controlView needsToDrawRect : imageRect])
{
//NSLog(@"drawInteriorWithFrame %@ drawImage", [self title]);
[iImage setFlipped:[controlView isFlipped]];
[iImage drawInRect:imageRect fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0f];
if (self->iShowPadlock)
{
static NSImage* lockImage = nil;
if (!lockImage)
{
lockImage = [[NSImage imageNamed:@"LockLocked.icns" orFromBundleDirectory:@"images"] copy];
}
[lockImage drawInRect: NSMakeRect(imageRect.origin.x-imageRect.size.width*0.3f, imageRect.origin.y+imageRect.size.height-imageRect.size.height*0.8f, imageRect.size.width*0.8f, imageRect.size.height*0.8f) fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0f];
}
}
NSRect titleRect = [self titleRectForBounds:bounds];
if([controlView needsToDrawRect : titleRect])
{
titleRect = [self titleRectForBounds:bounds];
NSString* stringValue = [self stringValue];
NSAttributedString* placeholderStringValue = nil;
NSAttributedString *title = ((stringValue==nil || [stringValue isEqualToString:@""]) && (placeholderStringValue=[self placeholderAttributedString])) ? placeholderStringValue : [self attributedStringValue];
if ([title length] > 0)
{
//Original Code:
//[title drawInRect:titleRect];
if ([Preferences colorScheme] == (NSUInteger)[NSColor silverSchemeIndex])
{
[title drawInRect:titleRect];
}
else
{
NSMutableAttributedString* titleString = [[NSMutableAttributedString alloc] initWithAttributedString:title];
[titleString addAttribute:NSForegroundColorAttributeName value:[NSColor foregroundColorForControl:nil colorScheme:[Preferences colorScheme]] range:NSMakeRange(0, [title length])];
[titleString drawInRect:titleRect];
[titleString release];
}
//
}
NSAttributedString *attributedSubTitle = [self attributedSubTitle];
if ([attributedSubTitle length] > 0)
{
NSRect attributedSubTitleRect = [self rectForSubTitleBasedOnTitleRect:titleRect inBounds:bounds];
[attributedSubTitle drawInRect:attributedSubTitleRect];
}
if([self hasActionButton])
{
//NSLog(@"drawInteriorWithFrame %@ drawActionButton", [self title]);
NSRect actionButtonRect = [self actionButtonRectForBounds:bounds];
NSImage *image = [self actionButtonImage];
[image drawInRect:actionButtonRect fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0f respectFlipped:YES hints:nil];
}
}
NSRect editorFrame = NSZeroRect;
if ([(NSControl*)[self controlView] currentEditor])
{
editorFrame = [[(NSControl*)[self controlView] currentEditor] frame];
}
if(kIccsNoCount!=[self countStatus])
{
NSBezierPath * countBezierPath = [self countBezierPathForBounds:bounds];
NSRect countBounds = [countBezierPath bounds];
NSRect intersectionRect = NSIntersectionRect(editorFrame,countBounds);
if(countBezierPath && [controlView needsToDrawRect : countBounds] )
{
if (editorFrame.size.width==0 || intersectionRect.size.width==0)
{
if (kIccsHasCountNotVerified==[self countStatus])
{
[[NSColor colorForPrefKey:@"InvalidCounterBackground"] set];//<-very light gray
}else
{
[[NSColor colorForPrefKey:@"ValidCounterBackground"] set];
}
[countBezierPath fill];
static NSDictionary * invalidAttributes = nil;
static NSDictionary * validAttributes = nil;
if(!invalidAttributes)
{
invalidAttributes = [[NSDictionary dictionaryWithObjectsAndKeys:
[NSFont fontWithName:@"Lucida Grande" size:[[self font] pointSize]],NSFontAttributeName,
[NSColor colorForPrefKey:@"InvalidCounterText"], NSForegroundColorAttributeName,
nil] retain];
}
if(!validAttributes)
{
validAttributes = [[NSDictionary dictionaryWithObjectsAndKeys:
[NSFont fontWithName:@"Lucida Grande" size:[[self font] pointSize]],NSFontAttributeName,
[NSColor colorForPrefKey:@"ValidCounterText"], NSForegroundColorAttributeName,
nil] retain];
}
NSSize numberSize = [self countNumberSize];
NSPoint point = NSMakePoint(NSMidX([countBezierPath bounds]) - numberSize.width / 2.0f,
NSMidY([countBezierPath bounds]) - numberSize.height / 2.0f );
[[self countNumberString] drawAtPoint:point withAttributes:(kIccsHasCountNotVerified==[self countStatus])?invalidAttributes:validAttributes];
}else
{
[[NSColor alternateSelectedControlColor] set];
NSRectFill(countBounds);
}
}
}
}
@end
@interface CustomSegmentedCellWithScheme (Private)
- (NSRect)rectForSegment:(NSInteger)arg1 inFrame:(NSRect)arg2;
@end
@implementation CustomSegmentedCellWithScheme
- (void)drawSegment:(NSInteger)segment inFrame:(NSRect)frame withView:(NSView *)controlView
{
[super drawSegment:segment inFrame:frame withView:controlView];
}
- (void)drawWithFrame:(NSRect)frame inView:(id)inView
{
if ([Preferences colorScheme] != (NSUInteger)[NSColor silverSchemeIndex])
{
NSGraphicsContext* gtx = [NSGraphicsContext currentContext];
CGContextRef ctx = [gtx graphicsPort];
CGFloat ORIGINX = frame.origin.x;
CGFloat WIDTH = frame.size.width, HEIGHT = frame.size.height;
CGLayerRef layer = CGLayerCreateWithContext(ctx, CGSizeMake(WIDTH, HEIGHT), NULL);
[NSGraphicsContext saveGraphicsState];
//Create layer with only background drawn
[NSGraphicsContext saveGraphicsState];
[NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithGraphicsPort:CGLayerGetContext(layer) flipped:YES]];
[[NSGraphicsContext currentContext] setShouldAntialias:YES];
[[NSGraphicsContext currentContext] setImageInterpolation:NSImageInterpolationHigh];
[super drawWithFrame:NSMakeRect(ORIGINX, ORIGINX, WIDTH, HEIGHT) inView:inView];
[NSGraphicsContext restoreGraphicsState];
//Draw separately each segment. Selected segments will be drawn with a blend mode to make them darker
for (NSInteger i=0;i<[self segmentCount]; i++)
{
CGContextSaveGState(ctx);
NSRect segmentFrame = [self rectForSegment:i inFrame:frame];
CGContextAddRect(ctx, NSRectToCGRect(segmentFrame));
CGContextClip(ctx);
if ([self isSelectedForSegment:i])
{
CGContextSetBlendMode(ctx, kCGBlendModePlusDarker);
}else
{
//CGContextSetBlendMode(ctx, kCGBlendModePlusLighter);
//CGContextSetBlendMode(ctx, kCGBlendModeSourceAtop);
//CGContextSetBlendMode(ctx, kCGBlendModeLuminosity); ->
//CGContextSetBlendMode(ctx, kCGBlendModeExclusion);
//CGContextSetBlendMode(ctx, kCGBlendModeDifference);
//CGContextSetBlendMode(ctx, kCGBlendModeHardLight);
//CGContextSetBlendMode(ctx, kCGBlendModeSoftLight);
CGContextSetBlendMode(ctx, kCGBlendModeLighten);
}
CGContextDrawLayerInRect(ctx, CGRectMake(ORIGINX, ORIGINX, WIDTH, HEIGHT), layer);
CGContextRestoreGState(ctx);
}
CGLayerRelease(layer);
[NSGraphicsContext restoreGraphicsState];
NSUInteger fontSize = (NSUInteger)[[self font] pointSize];
for (NSInteger i=0;i<[self segmentCount]; i++)
{
NSRect segmentFrame = [self rectForSegment:i inFrame:frame];
NSRect shadowRect = [self titleRectForBounds:segmentFrame];
NSRect titleRect = [self titleRectForBounds:segmentFrame];
switch (fontSize)
{
case 11:
{
shadowRect.origin.x += 7.5;
shadowRect.origin.y += 3.5;
titleRect.origin.x += 7.5;
titleRect.origin.y += 2.5;
break;
}
default:
{
shadowRect.origin.y -= 1;
break;
}
}
if ([self labelForSegment:i])
{
NSMutableAttributedString* attributedString = [[NSMutableAttributedString alloc] initWithString:[self labelForSegment:i]];
[attributedString addAttribute:NSForegroundColorAttributeName
value:[NSColor blackColor]
range:NSMakeRange(0, [attributedString length])];
[attributedString addAttribute:NSFontAttributeName value:[NSFont systemFontOfSize:[[self font] pointSize]] range:NSMakeRange(0, [attributedString length])];
[attributedString drawInRect:shadowRect];
[attributedString release];
NSMutableAttributedString* attributedString2 = [[NSMutableAttributedString alloc] initWithString:[self labelForSegment:i]];
[attributedString2 addAttribute:NSForegroundColorAttributeName
value:[NSColor foregroundColorForControl:nil colorScheme:[Preferences colorScheme]]
range:NSMakeRange(0, [attributedString2 length])];
[attributedString2 addAttribute:NSFontAttributeName value:[NSFont systemFontOfSize:[[self font] pointSize]] range:NSMakeRange(0, [attributedString2 length])];
[attributedString2 drawInRect:titleRect];
[attributedString2 release];
}
}
[[NSColor foregroundColorForControl:nil colorScheme:[Preferences colorScheme]] set];
NSBezierPath * pathToStroke = [NSBezierPath bezierPathWithRoundedRect:frame xRadius:5 yRadius:5];
[pathToStroke setLineWidth:0.5];
[pathToStroke stroke];
}
else
{
[super drawWithFrame:frame inView:inView];
}
//
}
- (NSBackgroundStyle)interiorBackgroundStyleForSegment:(NSInteger)segment
{
NSBackgroundStyle bs = [super interiorBackgroundStyleForSegment:segment];
return bs;
}
@end
@interface CustomSegmentedCellForHistoryBar (Private)
- (NSRect)rectForSegment:(NSInteger)arg1 inFrame:(NSRect)arg2;
@end
@implementation CustomSegmentedCellForHistoryBar
- (void)drawWithFrame:(NSRect)frame inView:(id)inView
{
if ([Preferences colorScheme] != (NSUInteger)[NSColor silverSchemeIndex])
{
NSRect cellRect = frame;
cellRect.origin = NSMakePoint(0, 0);
cellRect.size.height -= 9;
cellRect.origin.y += 5;
[[NSBezierPath bezierPathWithRoundedRect:cellRect xRadius:5 yRadius:5] addClip];
// Draw a background color on top of everything
CGContextRef context = (CGContextRef)[NSGraphicsContext currentContext];
CGContextSetBlendMode(context, kCGBlendModeNormal);
// [[NSColor backgroundColorForControl:@"CustomSegmentedCellForHistoryBar" colorScheme:[Preferences colorScheme]] set];
// [[NSBezierPath bezierPathWithRoundedRect:cellRect xRadius:5 yRadius:5] fill];
// Draw gradient background color for reduce the blizzing white on the top
NSGradient* aGradient = [[[NSGradient alloc] initWithColorsAndLocations:
[NSColor colorWithDeviceRed:0 green:0 blue:0 alpha:1.0f], (CGFloat)0,
[NSColor colorWithDeviceRed:0 green:0 blue:0 alpha:1.0f], (CGFloat)0.1,
[NSColor colorWithDeviceRed:0.15f green:0.15f blue:0.15f alpha:1.0f], (CGFloat)1.0,
nil] autorelease];
[aGradient drawInBezierPath:[NSBezierPath bezierPathWithRoundedRect:cellRect xRadius:5 yRadius:5] angle: 90];
[super drawWithFrame:frame inView:inView];
}
else
{
[super drawWithFrame:frame inView:inView];
}
}
@end
@implementation SplitViewWithScheme
- (id)initWithFrame:(NSRect)frameRect
{
self = [super initWithFrame:frameRect];
if (self != nil)
{
if (!addObserver)
{
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:[Preferences pathForKey:kPrefKeyGUIColorScheme] options:0 context: NULL];
addObserver = true;
}
}
return self;
}
- (void)viewDidMoveToWindow
{
if (!addObserver)
{
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:[Preferences pathForKey:kPrefKeyGUIColorScheme] options:0 context: NULL];
addObserver = true;
}
}
- (void)drawDividerInRect:(NSRect)rect
{
if ([Preferences colorScheme] == (NSUInteger)[NSColor silverSchemeIndex])
{
[super drawDividerInRect:rect];
}
else
{
[[NSColor backgroundColorForControl:nil colorScheme:[Preferences colorScheme]] set];
NSRectFill(rect);
NSRect frame = rect;
frame.origin.x = frame.origin.x + frame.size.width/2 - 2;
frame.origin.y = frame.origin.y + frame.size.height/2 - 2;
frame.size.width = 4;
frame.size.height = 4;
[[NSColor foregroundColorForControl:nil colorScheme:[Preferences colorScheme]] set];
[[NSBezierPath bezierPathWithOvalInRect:frame] fill];
}
}
- (void) dealloc
{
if (addObserver)
{
[[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:[Preferences pathForKey:kPrefKeyGUIColorScheme]];
}
[super dealloc];
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if ([keyPath isEqualToString:[Preferences pathForKey:kPrefKeyGUIColorScheme]])
{
[self setNeedsDisplay: true];
}
}
@end
@implementation ToolbarWithScheme
- (id)init
{
self = [super init];
if (self != nil)
{
if (!addObserver)
{
[self setDisplayMode: [self displayMode]];
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:[Preferences pathForKey:kPrefKeyGUIColorScheme] options:0 context: NULL];
addObserver = true;
}
}
return self;
}
- (id)initWithIdentifier:(NSString *)identifier
{
self = [super initWithIdentifier:identifier];
if (self != nil)
{
if (!addObserver)
{
[self setDisplayMode: [self displayMode]];
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:[Preferences pathForKey:kPrefKeyGUIColorScheme] options:0 context: NULL];
addObserver = true;
}
}
return self;
}
- (void)setDisplayMode:(NSToolbarDisplayMode)displayMode
{
if ([Preferences colorScheme] != (NSUInteger)[NSColor silverSchemeIndex])
{
switch (displayMode)
{
case NSToolbarDisplayModeDefault:
case NSToolbarDisplayModeLabelOnly:
case NSToolbarDisplayModeIconAndLabel:
{
[super setDisplayMode: NSToolbarDisplayModeIconOnly];
break;
}
default:
{
[super setDisplayMode: displayMode];
break;
}
}
[super setAllowsUserCustomization: false];
}
else
{
[super setDisplayMode: displayMode];
[super setAllowsUserCustomization: true];
}
}
- (void) dealloc
{
if (addObserver)
{
[[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:[Preferences pathForKey:kPrefKeyGUIColorScheme]];
}
[super dealloc];
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if ([keyPath isEqualToString:[Preferences pathForKey:kPrefKeyGUIColorScheme]])
{
[self setDisplayMode: [self displayMode]];
}
}
@end
@implementation ToolbarItemViewWithScheme
- (void) drawRect:(NSRect)rect
{
NSRect newRect = rect;
newRect.size.height -= 5;
NSMutableDictionary *titleAttrs = [[[NSMutableDictionary alloc] initWithDictionary:[self titleAttributes]] autorelease];
[titleAttrs setObject:[NSColor foregroundColorForControl:nil colorScheme:[Preferences colorScheme]] forKey: NSForegroundColorAttributeName];
[title drawInRect:newRect withAttributes:titleAttrs];
}
@end
@implementation DatePickerWithScheme
- (id) init
{
self = [super init];
if (self != nil)
{
[self redrawScheme];
if (!addObserver)
{
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:[Preferences pathForKey:kPrefKeyGUIColorScheme] options:0 context: NULL];
addObserver = true;
}
}
return self;
}
- (id)initWithFrame:(NSRect)frameRect
{
self = [super initWithFrame:frameRect];
if (self != nil)
{
[self redrawScheme];
if (!addObserver)
{
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:[Preferences pathForKey:kPrefKeyGUIColorScheme] options:0 context: NULL];
addObserver = true;
}
}
return self;
}
- (void)viewDidMoveToWindow
{
[self redrawScheme];
if (!addObserver)
{
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:[Preferences pathForKey:kPrefKeyGUIColorScheme] options:0 context: NULL];
addObserver = true;
}
}
- (void) redrawScheme
{
[self setTextColor: [NSColor foregroundColorForControl:@"DatePickerWithScheme" colorScheme:[Preferences colorScheme]]];
[self setBackgroundColor: [NSColor backgroundColorForControl:@"DatePickerWithScheme" colorScheme:[Preferences colorScheme]]];
[self setNeedsDisplay: true];
}
- (void) dealloc
{
if (addObserver)
{
[[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:[Preferences pathForKey:kPrefKeyGUIColorScheme]];
}
[super dealloc];
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if ([keyPath isEqualToString:[Preferences pathForKey:kPrefKeyGUIColorScheme]])
{
[self redrawScheme];
}
}
@end
@implementation TokenFieldWithScheme
- (id) init
{
self = [super init];
if (self != nil)
{
[self redrawScheme];
if (!addObserver)
{
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:[Preferences pathForKey:kPrefKeyGUIColorScheme] options:0 context: NULL];
addObserver = true;
}
}
return self;
}
- (id)initWithFrame:(NSRect)frameRect
{
self = [super initWithFrame:frameRect];
if (self != nil)
{
[self redrawScheme];
if (!addObserver)
{
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:[Preferences pathForKey:kPrefKeyGUIColorScheme] options:0 context: NULL];
addObserver = true;
}
}
return self;
}
- (void)viewDidMoveToWindow
{
[self redrawScheme];
if (!addObserver)
{
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:[Preferences pathForKey:kPrefKeyGUIColorScheme] options:0 context: NULL];
addObserver = true;
}
}
- (void) redrawScheme
{
[self setBackgroundColor: [NSColor backgroundColorForControl:@"TokenFieldWithScheme" colorScheme:[Preferences colorScheme]]];
[self setNeedsDisplay: true];
}
- (void) dealloc
{
if (addObserver)
{
[[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:[Preferences pathForKey:kPrefKeyGUIColorScheme]];
}
[super dealloc];
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if ([keyPath isEqualToString:[Preferences pathForKey:kPrefKeyGUIColorScheme]])
{
[self redrawScheme];
}
}
@end
// Code about customise NSTableHeaderCell in some table views
//@implementation NSTableHeaderCell (CustomiseTableHeader)
@implementation TableHeaderCellWithScheme
- (void)drawWithFrame:(CGRect)cellFrame
highlighted:(BOOL)isHighlighted
inView:(NSView *)view
{
CGRect fillRect, borderRect;
CGRectDivide(cellFrame, &borderRect, &fillRect, 1.0, CGRectMaxYEdge);
NSGradient *gradient = [[NSGradient alloc]
initWithStartingColor:[NSColor backgroundColorForControl:@"Color1ForGradientInTableHeaderCell" colorScheme:[Preferences colorScheme]]
endingColor:[NSColor backgroundColorForControl:@"Color2ForGradientInTableHeaderCell" colorScheme:[Preferences colorScheme]]
];
[gradient drawInRect:fillRect angle:90.0];
[gradient release];
if (isHighlighted)
{
[[NSColor colorWithDeviceWhite:1.0 alpha:0.2] set];
NSRectFillUsingOperation(fillRect, NSCompositeSourceOver);
}
//Draw bottom border line
[[NSColor foregroundColorForControl:nil colorScheme:[Preferences colorScheme]] set];
NSRectFill(borderRect);
//Draw top border line
NSBezierPath *topLine = [NSBezierPath bezierPath];
[topLine moveToPoint: NSMakePoint(cellFrame.origin.x, cellFrame.origin.y)];
[topLine lineToPoint: NSMakePoint(cellFrame.origin.x + cellFrame.size.width, cellFrame.origin.y)];
[[NSColor foregroundColorForControl:nil colorScheme:[Preferences colorScheme]] set];
[topLine setLineWidth:1];
[topLine stroke];
//[self drawInteriorWithFrame:CGRectInset(fillRect, 0.0, 1.0) inView:view];
if ([self image])
{
// Draw image in header cell
NSRect imageRect = [self imageRectForBounds:cellFrame];
NSImage *image = [NSImage highlitedImageWithWhite:1.0f andAlpha:1.0f fromImage:[self image]];
[image drawInRect:imageRect fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0f respectFlipped:YES hints:nil];
}
else
{
// Draw title in header cell
NSRect titleRect = [self titleRectForBounds:cellFrame];
titleRect.origin.x += 2;
NSMutableAttributedString *attrString = [[[NSMutableAttributedString alloc] initWithAttributedString:[self attributedStringValue]] autorelease];
if (![[attrString string] isEqualToString:@"Field"])
{
[attrString addAttribute:NSForegroundColorAttributeName value:[NSColor foregroundColorForControl:nil colorScheme:[Preferences colorScheme]] range:NSMakeRange(0, [attrString length])];
[attrString drawInRect: titleRect];
}
}
// Draw vertical seperator line
NSBezierPath *seperatorLine = [NSBezierPath bezierPath];
[seperatorLine moveToPoint: NSMakePoint(cellFrame.origin.x + cellFrame.size.width, cellFrame.origin.y + cellFrame.size.height - 3)];
[seperatorLine lineToPoint: NSMakePoint(cellFrame.origin.x + cellFrame.size.width, cellFrame.origin.y + cellFrame.size.height - 13)];
[[NSColor foregroundColorForControl:nil colorScheme:[Preferences colorScheme]] set];
[seperatorLine setLineWidth:1];
[seperatorLine stroke];
}
- (void)drawWithFrame:(CGRect)cellFrame inView:(NSView *)view
{
if ([Preferences colorScheme] == (NSUInteger)[NSColor silverSchemeIndex])
{
[super drawWithFrame:cellFrame inView:view];
}
else
{
[self drawWithFrame:cellFrame highlighted:NO inView:view];
}
}
- (void)highlight:(BOOL)isHighlighted
withFrame:(NSRect)cellFrame
inView:(NSView *)view
{
if ([Preferences colorScheme] == (NSUInteger)[NSColor silverSchemeIndex])
{
[super highlight:isHighlighted withFrame:cellFrame inView:view];
}
else
{
[self drawWithFrame:cellFrame highlighted:isHighlighted inView:view];
}
}
@end
@implementation TETokenFieldWithScheme
- (id) init
{
self = [super init];
if (self != nil)
{
[self redrawScheme];
if (!addObserver)
{
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:[Preferences pathForKey:kPrefKeyGUIColorScheme] options:0 context: NULL];
addObserver = true;
}
}
return self;
}
- (id)initWithFrame:(NSRect)frameRect
{
self = [super initWithFrame:frameRect];
if (self != nil)
{
[self redrawScheme];
if (!addObserver)
{
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:[Preferences pathForKey:kPrefKeyGUIColorScheme] options:0 context: NULL];
addObserver = true;
}
}
return self;
}
- (void)viewDidMoveToWindow
{
[self redrawScheme];
if (!addObserver)
{
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:[Preferences pathForKey:kPrefKeyGUIColorScheme] options:0 context: NULL];
addObserver = true;
}
}
- (void) redrawScheme
{
[self setBackgroundColor: [NSColor backgroundColorForControl:@"TokenFieldWithScheme" colorScheme:[Preferences colorScheme]]];
[self setNeedsDisplay: true];
}
- (void) dealloc
{
if (addObserver)
{
[[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:[Preferences pathForKey:kPrefKeyGUIColorScheme]];
}
[super dealloc];
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if ([keyPath isEqualToString:[Preferences pathForKey:kPrefKeyGUIColorScheme]])
{
[self redrawScheme];
}
}
@end
@implementation ScrollerWithScheme
- (id) init
{
self = [super init];
if (self != nil)
{
[self redrawScheme];
if (!addObserver)
{
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:[Preferences pathForKey:kPrefKeyGUIColorScheme] options:0 context: NULL];
addObserver = true;
}
}
return self;
}
- (id)initWithFrame:(NSRect)frameRect
{
self = [super initWithFrame:frameRect];
if (self != nil)
{
[self redrawScheme];
if (!addObserver)
{
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:[Preferences pathForKey:kPrefKeyGUIColorScheme] options:0 context: NULL];
addObserver = true;
}
}
return self;
}
- (void)viewDidMoveToWindow
{
[self redrawScheme];
if (!addObserver)
{
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:[Preferences pathForKey:kPrefKeyGUIColorScheme] options:0 context: NULL];
addObserver = true;
}
}
- (void) redrawScheme
{
}
- (void) dealloc
{
if (addObserver)
{
[[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:[Preferences pathForKey:kPrefKeyGUIColorScheme]];
}
[super dealloc];
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if ([keyPath isEqualToString:[Preferences pathForKey:kPrefKeyGUIColorScheme]])
{
[self redrawScheme];
}
}
@end