diff options
-rw-r--r-- | AppKit/GTMTheme.h | 15 | ||||
-rw-r--r-- | AppKit/GTMTheme.m | 33 | ||||
-rw-r--r-- | AppKit/GTMThemeTest.m | 12 |
3 files changed, 41 insertions, 19 deletions
diff --git a/AppKit/GTMTheme.h b/AppKit/GTMTheme.h index 787d1f1..62bb1f3 100644 --- a/AppKit/GTMTheme.h +++ b/AppKit/GTMTheme.h @@ -51,7 +51,7 @@ typedef NSUInteger GTMThemeState; @private NSColor *backgroundColor_; // bound to user defaults NSImage *backgroundImage_; // bound to user defaults - NSPoint backgroundImagePhase_; // bound to user defaults + NSPoint backgroundPatternPhase_; // bound to user defaults NSMutableDictionary *values_; // cached values } @@ -74,11 +74,11 @@ typedef NSUInteger GTMThemeState; // set base background image - (void)setBackgroundImage:(NSImage *)value; -// the phase of the background image -- (NSPoint)backgroundImagePhase; +// the phase of the background pattern +- (NSPoint)backgroundPatternPhase; -// set the phase of the background image -- (void)setBackgroundImagePhase:(NSPoint)phase; +// set the phase of the background pattern +- (void)setBackgroundPatternPhase:(NSPoint)phase; // NSImage pattern background - (NSImage *)backgroundImageForStyle:(GTMThemeStyle)style @@ -119,6 +119,11 @@ typedef NSUInteger GTMThemeState; forAttribute:(NSString *)attribute style:(GTMThemeStyle)style state:(GTMThemeState)state; + +// Manually extract a theme value +- (id)valueForAttribute:(NSString *)attribute + style:(GTMThemeStyle)style + state:(GTMThemeState)state; @end // Convenience categories for NSWindow and NSView to access the current theme diff --git a/AppKit/GTMTheme.m b/AppKit/GTMTheme.m index 7162916..cb30bda 100644 --- a/AppKit/GTMTheme.m +++ b/AppKit/GTMTheme.m @@ -89,9 +89,9 @@ NSString *const kGTMThemeBackgroundColorKey = @"GTMThemeBackgroundColor"; NSValueTransformerNameBindingOption, nil]]; - [self bind:@"backgroundImagePhase" + [self bind:@"backgroundPatternPhase" toObject:controller - withKeyPath:@"values.GTMThemeBackgroundImagePhase" + withKeyPath:@"values.GTMThemeBackgroundPatternPhase" options:nil]; } @@ -106,14 +106,14 @@ NSString *const kGTMThemeBackgroundColorKey = @"GTMThemeBackgroundColor"; - (void)finalize { [self unbind:@"backgroundColor"]; [self unbind:@"backgroundImage"]; - [self unbind:@"backgroundImagePhase"]; + [self unbind:@"backgroundPatternPhase"]; [super finalize]; } - (void)dealloc { [self unbind:@"backgroundColor"]; [self unbind:@"backgroundImage"]; - [self unbind:@"backgroundImagePhase"]; + [self unbind:@"backgroundPatternPhase"]; [values_ release]; [super dealloc]; } @@ -150,14 +150,25 @@ NSString *const kGTMThemeBackgroundColorKey = @"GTMThemeBackgroundColor"; forAttribute:(NSString *)attribute style:(GTMThemeStyle)style state:(GTMThemeState)state { - NSString *selector = [NSString stringWithFormat:@"%@ForStyle:state:", - attribute]; + NSString *selectorString = [NSString stringWithFormat:@"%@ForStyle:state:", + attribute]; [self cacheValue:value - forSelector:NSSelectorFromString(selector) + forSelector:NSSelectorFromString(selectorString) style:style state:state]; } +- (id)valueForAttribute:(NSString *)attribute + style:(GTMThemeStyle)style + state:(GTMThemeState)state { + NSString *selectorString = [NSString stringWithFormat:@"%@ForStyle:state:", + attribute]; + id key = [self keyForSelector:NSSelectorFromString(selectorString) + style:style + state:state]; + return [values_ objectForKey:key]; +} + - (void)setBackgroundColor:(NSColor *)value { if (backgroundColor_ != value) { [backgroundColor_ release]; @@ -185,12 +196,12 @@ NSString *const kGTMThemeBackgroundColorKey = @"GTMThemeBackgroundColor"; return backgroundImage_; } -- (NSPoint)backgroundImagePhase { - return backgroundImagePhase_; +- (NSPoint)backgroundPatternPhase { + return backgroundPatternPhase_; } -- (void)setBackgroundImagePhase:(NSPoint)phase { - backgroundImagePhase_ = phase; +- (void)setBackgroundPatternPhase:(NSPoint)phase { + backgroundPatternPhase_ = phase; [self sendChangeNotification]; } diff --git a/AppKit/GTMThemeTest.m b/AppKit/GTMThemeTest.m index ce1b6ad..dd134e1 100644 --- a/AppKit/GTMThemeTest.m +++ b/AppKit/GTMThemeTest.m @@ -26,6 +26,7 @@ @interface GTMThemeTest : GTMTestCase { @private BOOL themeNotificationCalled_; +} @end @implementation GTMThemeTest @@ -69,9 +70,14 @@ @"GTMThemeBackgroundColor"]; } +- (void)themeDidChangeNotification:(NSNotification *)notification { + STAssertEquals(themeNotificationCalled_, NO, nil); + themeNotificationCalled_ = YES; +} + - (void)testPhase { GTMTheme *theme = [GTMTheme defaultTheme]; - STAssertEquals([theme backgroundImagePhase], NSZeroPoint, nil); + STAssertEquals([theme backgroundPatternPhase], NSZeroPoint, nil); NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; [nc addObserver:self @@ -80,10 +86,10 @@ object:theme]; themeNotificationCalled_ = NO; NSPoint newPhase = NSMakePoint(20, 30); - [theme setBackgroundImagePhase:newPhase]; + [theme setBackgroundPatternPhase:newPhase]; STAssertTrue(themeNotificationCalled_, nil); themeNotificationCalled_ = NO; - STAssertEquals([theme backgroundImagePhase], newPhase, nil); + STAssertEquals([theme backgroundPatternPhase], newPhase, nil); [nc removeObserver:self name:kGTMThemeDidChangeNotification object:theme]; } |