X-Git-Url: http://git.ithinksw.org/ITKit.git/blobdiff_plain/671a785b0d869478451bc428ac4e4bf3415253b4..079b33aed3d1c849f1f46022040813d6394100f2:/ITStatusItem.m diff --git a/ITStatusItem.m b/ITStatusItem.m index 3e2ce57..31ff2e3 100755 --- a/ITStatusItem.m +++ b/ITStatusItem.m @@ -1,33 +1,98 @@ -// -// ITStatusItem.m -// iThinkAppKit -// -// Created by Joseph Spiros on Fri Dec 06 2002. -// Copyright (c) 2002 iThink Software. All rights reserved. -// - #import "ITStatusItem.h" +/*************************************************************************/ +#pragma mark - +#pragma mark EVIL HACKERY +/*************************************************************************/ + +// This stuff is actually implemented by the AppKit. +// We declare it here to cancel out warnings. + +@interface NSStatusBarButton : NSButton +@end + +@interface NSStatusItem (HACKHACKHACKHACK) +- (id)_initInStatusBar:(NSStatusBar*)statusBar + withLength:(float)length + withPriority:(int)priority; +- (NSStatusBarButton*)_button; +@end + + +/*************************************************************************/ +#pragma mark - +#pragma mark PRIVATE METHOD DECLARATIONS +/*************************************************************************/ + +@interface ITStatusItem (Private) +- (void)setImage:(NSImage*)image; +- (NSString*) title; +- (void)setTitle:(NSString*)title; +- (void)setSmallTitle:(NSString*)title; +@end + @implementation ITStatusItem -- (id)initWithStatusBar:(NSStatusBar*)statusBar withLength:(float)length { - statusItem = [statusBar statusItemWithLength:length]; +/*************************************************************************/ +#pragma mark - +#pragma mark INITIALIZATION METHODS +/*************************************************************************/ + +- (id)initWithStatusBar:(NSStatusBar*)statusBar withLength:(float)length +{ + if ( ( self = [super _initInStatusBar:statusBar + withLength:length + withPriority:1000] ) ) { + + //Eliminate the fucking shadow... + [[[self _button] cell] setType:NSNullCellType]; + + //Be something other than a dumbshit about highlighting... + [self setHighlightMode:YES]; + } + return self; +} + + +/*************************************************************************/ +#pragma mark - +#pragma mark ACCESSOR METHODS +/*************************************************************************/ + +- (NSImage*)alternateImage { + return [[self _button] alternateImage]; } -- (NSStatusItem*) statusItem { - return statusItem; +- (void)setAlternateImage:(NSImage*)image { + [[self _button] setAlternateImage:image]; } -- (NSImage*) alternateImage { - return [[statusItem _button] alternateImage]; +- (void)setImage:(NSImage*)image { + [super setImage:image]; + if ( [self title] ) { + [self setTitle:[self title]]; + } } -- (void) setAlternateImage:(NSImage*)image { - if ([[[[statusItem _button] cell] super] type] != 0) { - [[[statusItem _button] cell] setType:0]; +- (void)setTitle:(NSString*)title { + if ( [self image] && (title != nil) ) { + [self setSmallTitle:title]; + } else { + [super setTitle:title]; } - [[statusItem _button] setAlternateImage:image]; } + +/*************************************************************************/ +#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]] autorelease]; + [self setAttributedTitle:attrTitle]; +} + + @end