diff options
author | 2009-10-08 21:30:27 +0000 | |
---|---|---|
committer | 2009-10-08 21:30:27 +0000 | |
commit | 9e318781c61170fc28682d0600cd37e0c8fd5308 (patch) | |
tree | 7edff2585337e1bd9125a83779cd852a7e9775c7 | |
parent | fa88fbb1d4c8e8dd3541f79f5fe406493cd63fa4 (diff) |
[Author: dmaclach]
Add pattern phase the way I really want it (for now).
R=thomasvl,alcor
DELTA=91 (31 added, 52 deleted, 8 changed)
-rw-r--r-- | AppKit/GTMTheme.h | 10 | ||||
-rw-r--r-- | AppKit/GTMTheme.m | 59 | ||||
-rw-r--r-- | AppKit/GTMThemeTest.m | 28 |
3 files changed, 38 insertions, 59 deletions
diff --git a/AppKit/GTMTheme.h b/AppKit/GTMTheme.h index 62bb1f3..a7b0958 100644 --- a/AppKit/GTMTheme.h +++ b/AppKit/GTMTheme.h @@ -51,7 +51,6 @@ typedef NSUInteger GTMThemeState; @private NSColor *backgroundColor_; // bound to user defaults NSImage *backgroundImage_; // bound to user defaults - NSPoint backgroundPatternPhase_; // bound to user defaults NSMutableDictionary *values_; // cached values } @@ -74,12 +73,6 @@ typedef NSUInteger GTMThemeState; // set base background image - (void)setBackgroundImage:(NSImage *)value; -// the phase of the background pattern -- (NSPoint)backgroundPatternPhase; - -// set the phase of the background pattern -- (void)setBackgroundPatternPhase:(NSPoint)phase; - // NSImage pattern background - (NSImage *)backgroundImageForStyle:(GTMThemeStyle)style state:(GTMThemeState)state; @@ -130,14 +123,17 @@ typedef NSUInteger GTMThemeState; // Default implementation polls the window delegate @interface NSWindow (GTMTheme) - (GTMTheme *)gtm_theme; +- (NSPoint)gtm_themePatternPhase; @end @interface NSView (GTMTheme) - (GTMTheme *)gtm_theme; +- (NSPoint)gtm_themePatternPhase; @end @protocol GTMThemeDelegate - (GTMTheme *)gtm_themeForWindow:(NSWindow *)window; +- (NSPoint)gtm_themePatternPhaseForWindow:(NSWindow *)window; @end #endif // MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 diff --git a/AppKit/GTMTheme.m b/AppKit/GTMTheme.m index cb30bda..7b966f9 100644 --- a/AppKit/GTMTheme.m +++ b/AppKit/GTMTheme.m @@ -26,28 +26,53 @@ static GTMTheme *gGTMDefaultTheme = nil; NSString *const kGTMThemeDidChangeNotification = @"GTMThemeDidChangeNotification"; NSString *const kGTMThemeBackgroundColorKey = @"GTMThemeBackgroundColor"; +@interface GTMTheme () +- (void)sendChangeNotification; +@end + @implementation NSWindow (GTMTheme) +- (id<GTMThemeDelegate>)gtm_themeDelegate { + id delegate = nil; + id tempDelegate = [self delegate]; + if ([tempDelegate conformsToProtocol:@protocol(GTMThemeDelegate)]) { + delegate = tempDelegate; + } + if (!delegate) { + tempDelegate = [self windowController]; + if ([tempDelegate conformsToProtocol:@protocol(GTMThemeDelegate)]) { + delegate = tempDelegate; + } + } + return delegate; +} + - (GTMTheme *)gtm_theme { GTMTheme *theme = nil; - if ([[self delegate] conformsToProtocol: - @protocol(GTMThemeDelegate)]) { - theme = [(id <GTMThemeDelegate>)[self delegate] gtm_themeForWindow:self]; - } else if ([[self windowController] conformsToProtocol: - @protocol(GTMThemeDelegate)]) { - theme = [[self windowController] gtm_themeForWindow:self]; + id<GTMThemeDelegate>delegate = [self gtm_themeDelegate]; + if (delegate) { + theme = [delegate gtm_themeForWindow:self]; } return theme; } + +- (NSPoint)gtm_themePatternPhase { + NSPoint phase = NSZeroPoint; + id<GTMThemeDelegate>delegate = [self gtm_themeDelegate]; + if (delegate) { + phase = [delegate gtm_themePatternPhaseForWindow:self]; + } + return phase; +} @end @implementation NSView (GTMTheme) - (GTMTheme *)gtm_theme { return [[self window] gtm_theme]; } -@end -@interface GTMTheme () -- (void)sendChangeNotification; +- (NSPoint)gtm_themePatternPhase { + return [[self window] gtm_themePatternPhase]; +} @end @implementation GTMTheme @@ -88,11 +113,6 @@ NSString *const kGTMThemeBackgroundColorKey = @"GTMThemeBackgroundColor"; NSUnarchiveFromDataTransformerName, NSValueTransformerNameBindingOption, nil]]; - - [self bind:@"backgroundPatternPhase" - toObject:controller - withKeyPath:@"values.GTMThemeBackgroundPatternPhase" - options:nil]; } - (id)init { @@ -106,14 +126,12 @@ NSString *const kGTMThemeBackgroundColorKey = @"GTMThemeBackgroundColor"; - (void)finalize { [self unbind:@"backgroundColor"]; [self unbind:@"backgroundImage"]; - [self unbind:@"backgroundPatternPhase"]; [super finalize]; } - (void)dealloc { [self unbind:@"backgroundColor"]; [self unbind:@"backgroundImage"]; - [self unbind:@"backgroundPatternPhase"]; [values_ release]; [super dealloc]; } @@ -196,15 +214,6 @@ NSString *const kGTMThemeBackgroundColorKey = @"GTMThemeBackgroundColor"; return backgroundImage_; } -- (NSPoint)backgroundPatternPhase { - return backgroundPatternPhase_; -} - -- (void)setBackgroundPatternPhase:(NSPoint)phase { - backgroundPatternPhase_ = phase; - [self sendChangeNotification]; -} - - (NSImage *)backgroundImageForStyle:(GTMThemeStyle)style state:(GTMThemeState)state { id value = [self valueForSelector:_cmd style:style state:state]; diff --git a/AppKit/GTMThemeTest.m b/AppKit/GTMThemeTest.m index dd134e1..0f5c996 100644 --- a/AppKit/GTMThemeTest.m +++ b/AppKit/GTMThemeTest.m @@ -23,10 +23,7 @@ #import "GTMSenTestCase.h" #import "GTMTheme.h" -@interface GTMThemeTest : GTMTestCase { - @private - BOOL themeNotificationCalled_; -} +@interface GTMThemeTest : GTMTestCase @end @implementation GTMThemeTest @@ -70,29 +67,6 @@ @"GTMThemeBackgroundColor"]; } -- (void)themeDidChangeNotification:(NSNotification *)notification { - STAssertEquals(themeNotificationCalled_, NO, nil); - themeNotificationCalled_ = YES; -} - -- (void)testPhase { - GTMTheme *theme = [GTMTheme defaultTheme]; - STAssertEquals([theme backgroundPatternPhase], NSZeroPoint, nil); - - NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; - [nc addObserver:self - selector:@selector(themeDidChangeNotification:) - name:kGTMThemeDidChangeNotification - object:theme]; - themeNotificationCalled_ = NO; - NSPoint newPhase = NSMakePoint(20, 30); - [theme setBackgroundPatternPhase:newPhase]; - STAssertTrue(themeNotificationCalled_, nil); - themeNotificationCalled_ = NO; - STAssertEquals([theme backgroundPatternPhase], newPhase, nil); - [nc removeObserver:self name:kGTMThemeDidChangeNotification object:theme]; -} - @end #endif // MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 |