From: Matthew Judy Date: Wed, 11 Dec 2002 00:51:51 +0000 (+0000) Subject: Checked in the Kit tester last night, but not this. Now with proper sizing. Still... X-Git-Tag: v0.1~83 X-Git-Url: http://git.ithinksw.org/ITKit.git/commitdiff_plain/0c83fc987c4d639d82d18b6373918b41fafacd3e Checked in the Kit tester last night, but not this. Now with proper sizing. Still has a flicker... not sure how much we can do about that. --- diff --git a/ITStatusItem.h b/ITStatusItem.h index 382b48c..ae4f71a 100755 --- a/ITStatusItem.h +++ b/ITStatusItem.h @@ -13,11 +13,13 @@ */ /* - * This subclass does 3 things: + * This subclass does 4 things to approximate NSMenuExtra's functionality: * * 1. Makes the status item smarter about highlighting. - * 2. Allows you to set an inverted (alternate) image. + * 2. Allows you to set an alternate (inverted) image. * 3. Eliminates the pre-Jaguar shadow behind a normal status item. + * 4. If you use an image AND title, the text will be made slightly smaller + * to resemble the visual interface of an NSMenuExtra. * * Note: In order to have the shadow not overlap the bottom of the * menubar, Apple moves the image up one pixel. Since that shadow is @@ -41,9 +43,4 @@ - (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 5e517a0..d0bcb9f 100755 --- a/ITStatusItem.m +++ b/ITStatusItem.m @@ -12,10 +12,10 @@ @end @interface NSStatusItem (HACKHACKHACKHACK) -- (id) _initInStatusBar:(NSStatusBar*)statusBar +- (id)_initInStatusBar:(NSStatusBar*)statusBar withLength:(float)length withPriority:(int)priority; -- (NSStatusBarButton*) _button; +- (NSStatusBarButton*)_button; @end /*************************************************************************/ @@ -24,7 +24,10 @@ /*************************************************************************/ @interface ITStatusItem (Private) -- (void) setSmallTitle:(NSString*)title; +- (void)setImage:(NSImage*)image; +- (NSString*) title; +- (void)setTitle:(NSString*)title; +- (void)setSmallTitle:(NSString*)title; @end @implementation ITStatusItem @@ -55,45 +58,40 @@ #pragma mark ACCESSOR METHODS /*************************************************************************/ -- (NSImage*) alternateImage { +- (NSImage*)alternateImage { return [[self _button] alternateImage]; } -- (void) setAlternateImage:(NSImage*)image { +- (void)setAlternateImage:(NSImage*)image { [[self _button] setAlternateImage:image]; } -- (void) setImage:(NSImage*)image { +- (void)setImage:(NSImage*)image { [super setImage:image]; - if ([self title]) { - [self setSmallTitle:[self title]]; - } + if ( [self title] ) { + [self setTitle:[self title]]; + } } -- (NSString*) title { - if ([self image]) { - return [[self attributedTitle] string]; +- (void)setTitle:(NSString*)title { + if ( [self image] && (title != nil) ) { + [self setSmallTitle:title]; } else { - [super title]; + [super setTitle: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]]; + + +- (void)setSmallTitle:(NSString*)title { + NSAttributedString *attrTitle = [[[NSAttributedString alloc] initWithString:title attributes:[NSDictionary dictionaryWithObject:[NSFont fontWithName:@"Lucida Grande" size:12.0] forKey:NSFontAttributeName]] autorelease]; [self setAttributedTitle:attrTitle]; - [attrTitle release]; } @end