*/
/*
- * 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
- (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
@end
@interface NSStatusItem (HACKHACKHACKHACK)
-- (id) _initInStatusBar:(NSStatusBar*)statusBar
+- (id)_initInStatusBar:(NSStatusBar*)statusBar
withLength:(float)length
withPriority:(int)priority;
-- (NSStatusBarButton*) _button;
+- (NSStatusBarButton*)_button;
@end
/*************************************************************************/
/*************************************************************************/
@interface ITStatusItem (Private)
-- (void) setSmallTitle:(NSString*)title;
+- (void)setImage:(NSImage*)image;
+- (NSString*) title;
+- (void)setTitle:(NSString*)title;
+- (void)setSmallTitle:(NSString*)title;
@end
@implementation ITStatusItem
#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