From 32440a12defde03dcc52e42cff4aa6300d7d96fb Mon Sep 17 00:00:00 2001 From: Joseph Spiros Date: Tue, 10 Dec 2002 11:56:11 +0000 Subject: [PATCH] Added functionality to make ITStatusItems which have both an image and a title defined comply with the psuedo-guidelines created by Apple's PPP.menu --- ITStatusItem.h | 5 +++++ ITStatusItem.m | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/ITStatusItem.h b/ITStatusItem.h index 218926d..382b48c 100755 --- a/ITStatusItem.h +++ b/ITStatusItem.h @@ -41,4 +41,9 @@ - (NSImage*) alternateImage; - (void) setAlternateImage:(NSImage*)image; +// The following have been redefined as to supply compliance with Jaguar (10.2)'s MenuExtras that have both titles and images. Continue to use them as though you would on a NSStatusItem, everything will be done for you automatically. +- (void) setImage:(NSImage*)image; +- (NSString*) title; +- (void) setTitle:(NSString*)title; + @end diff --git a/ITStatusItem.m b/ITStatusItem.m index 1b51ca2..5e517a0 100755 --- a/ITStatusItem.m +++ b/ITStatusItem.m @@ -18,6 +18,14 @@ - (NSStatusBarButton*) _button; @end +/*************************************************************************/ +#pragma mark - +#pragma mark PRIVATE METHOD DECLARATIONS +/*************************************************************************/ + +@interface ITStatusItem (Private) +- (void) setSmallTitle:(NSString*)title; +@end @implementation ITStatusItem @@ -55,4 +63,37 @@ [[self _button] setAlternateImage:image]; } +- (void) setImage:(NSImage*)image { + [super setImage:image]; + if ([self title]) { + [self setSmallTitle:[self title]]; + } +} + +- (NSString*) title { + if ([self image]) { + return [[self attributedTitle] string]; + } else { + [super title]; + } +} + +- (void) setTitle:(NSString*)title { + [super setTitle:title]; + if ([self image]) { + [self setSmallTitle:[self title]]; + } +} + +/*************************************************************************/ +#pragma mark - +#pragma mark PRIVATE METHODS +/*************************************************************************/ + +- (void) setSmallTitle:(NSString*)title { + NSAttributedString *attrTitle = [[NSAttributedString alloc] initWithString:title attributes:[NSDictionary dictionaryWithObject:[NSFont fontWithName:@"Lucida Grande" size:12.0] forKey:NSFontAttributeName]]; + [self setAttributedTitle:attrTitle]; + [attrTitle release]; +} + @end -- 2.20.1