Permalink
Browse files

Merge pull request #3 from gcamp/master

Enabled property and NSVariableStatusItemLength with text
  • Loading branch information...
2 parents 5a94aa5 + ff34249 commit 161e84e9c46b392cd594a1e39a3602a1f3d5d0e8 @jfro committed Jun 14, 2011
View
@@ -0,0 +1,19 @@
+# Mac OS X
+*.DS_Store
+
+# Xcode
+*.pbxuser
+*.mode1v3
+*.mode2v3
+*.perspectivev3
+*.xcuserstate
+project.xcworkspace/
+xcuserdata/
+
+# Generated files
+build/
+*.[oa]
+*.pyc
+
+# Backup files
+*~.nib
@@ -39,6 +39,7 @@
@property (copy, nonatomic) NSImage *image;
@property (copy, nonatomic) NSImage *alternateImage;
@property (assign, nonatomic) id<BCStatusItemViewDelegate> delegate;
+@property (nonatomic, getter = isEnabled) BOOL enabled;
+ (BCStatusItemView *)viewWithStatusItem:(NSStatusItem *)statusItem;
- (id)initWithStatusItem:(NSStatusItem *)statusItem;
@@ -20,6 +20,7 @@ @implementation BCStatusItemView
@synthesize image;
@synthesize alternateImage;
@synthesize delegate;
+@synthesize enabled;
+ (BCStatusItemView *)viewWithStatusItem:(NSStatusItem *)statusItem
{
@@ -40,6 +41,7 @@ - (id)initWithStatusItem:(NSStatusItem *)statusItem
self.image = nil;
self.alternateImage = nil;
self.delegate = nil;
+ self.enabled = YES;
}
return self;
}
@@ -61,7 +63,8 @@ - (void)_resizeToFitIfNeeded
if([parentStatusItem length] == NSVariableStatusItemLength)
{
NSRect newFrame = [self frame];
- newFrame.size.width = [[self image] size].width + 8; // 12 px padding, 6 on each side maybe? not sure what might be the usual
+ newFrame.size.width = [[self image] size].width + [self.attributedTitle size].width + 8;
+ // 12 px padding, 6 on each side maybe? not sure what might be the usual
[self setFrame:newFrame];
}
}
@@ -113,15 +116,22 @@ - (void)setTitle:(NSString *)newTitle
NSFont *font = [NSFont menuBarFontOfSize:[NSFont systemFontSize] + 2.0f]; // +2 seemed to make it look right, maybe missed a font method for menu?
NSColor *color = [NSColor controlTextColor];
+ NSMutableParagraphStyle *paragraphStyle = [[[NSMutableParagraphStyle alloc] init] autorelease];
+ [paragraphStyle setAlignment:NSCenterTextAlignment];
+
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:
font, NSFontAttributeName,
color, NSForegroundColorAttributeName,
+ paragraphStyle, NSParagraphStyleAttributeName,
nil];
+
NSAttributedString *attrTitle = [[NSAttributedString alloc] initWithString:self.title attributes:attributes];
self.attributedTitle = attrTitle;
[attrTitle release];
[self setNeedsDisplay:YES];
+
+ [self _resizeToFitIfNeeded];
}
}
@@ -157,12 +167,14 @@ - (void)setAttributedTitle:(NSAttributedString *)newTitle
- (void)mouseDown:(NSEvent *)theEvent
{
// TODO: implement other behaviors like support for target/action & doubleAction
- highlighted = YES;
- [self setNeedsDisplay:YES];
- [parentStatusItem popUpStatusItemMenu:[parentStatusItem menu]];
- // apparently the above blocks?
- highlighted = NO;
- [self setNeedsDisplay:YES];
+ if ([parentStatusItem isEnabled]) {
+ highlighted = YES;
+ [self setNeedsDisplay:YES];
+ [parentStatusItem popUpStatusItemMenu:[parentStatusItem menu]];
+ // apparently the above blocks?
+ highlighted = NO;
+ [self setNeedsDisplay:YES];
+ }
}
- (void)mouseUp:(NSEvent *)theEvent
@@ -188,10 +200,8 @@ - (void)menuDidClose:(NSMenu *)menu
#pragma mark -
-- (void)drawRect:(NSRect)dirtyRect
+- (void)drawRect:(NSRect)dirtyRect
{
- [[NSColor redColor] set];
- NSFrameRect([self bounds]);
// TODO: handle image + title, centering the combined rect with image on left
NSImage *drawnImage = nil;
if(highlighted && [self doesHighlight])
@@ -25,7 +25,7 @@
/**
* Convenience method which gets the window frame for the custom NSStatusItem view
*/
-- (NSRect)frame;
+@property (nonatomic, readonly) NSRect frame;
/**
* Sets the view's delegate, convenience method
@@ -86,4 +86,12 @@ - (void)setAttributedTitle:(NSAttributedString *)attrTitle
[(BCStatusItemView *)[self view] setAttributedTitle:attrTitle];
}
+- (BOOL)isEnabled {
+ return [(BCStatusItemView *)[self view] isEnabled];
+}
+
+- (void)setEnabled:(BOOL)enabled {
+ [(BCStatusItemView *)[self view] setEnabled:enabled];
+}
+
@end
File renamed without changes.
@@ -3,29 +3,24 @@
archiveVersion = 1;
classes = {
};
- objectVersion = 45;
+ objectVersion = 46;
objects = {
/* Begin PBXBuildFile section */
02252164115E75CD006F3538 /* status.png in Resources */ = {isa = PBXBuildFile; fileRef = 02252162115E75CD006F3538 /* status.png */; };
02252165115E75CD006F3538 /* status-selected.png in Resources */ = {isa = PBXBuildFile; fileRef = 02252163115E75CD006F3538 /* status-selected.png */; };
- 022B0A461157B3C700385F13 /* NSStatusItem+BCStatusItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 022B0A451157B3C700385F13 /* NSStatusItem+BCStatusItem.m */; };
- 022B0A4B1157B3D400385F13 /* BCStatusItemView.m in Sources */ = {isa = PBXBuildFile; fileRef = 022B0A4A1157B3D400385F13 /* BCStatusItemView.m */; };
1DDD58160DA1D0A300B32029 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 1DDD58140DA1D0A300B32029 /* MainMenu.xib */; };
256AC3DA0F4B6AC300CF3369 /* BCStatusItemAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 256AC3D90F4B6AC300CF3369 /* BCStatusItemAppDelegate.m */; };
8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */; };
8D11072D0486CEB800E47090 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B97316FDCFA39411CA2CEA /* main.m */; settings = {ATTRIBUTES = (); }; };
8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; };
+ B0BD954713A6FD30003B3689 /* BCStatusItemView.m in Sources */ = {isa = PBXBuildFile; fileRef = B0BD954413A6FD30003B3689 /* BCStatusItemView.m */; };
+ B0BD954813A6FD30003B3689 /* NSStatusItem+BCStatusItem.m in Sources */ = {isa = PBXBuildFile; fileRef = B0BD954613A6FD30003B3689 /* NSStatusItem+BCStatusItem.m */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
02252162115E75CD006F3538 /* status.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = status.png; sourceTree = "<group>"; };
02252163115E75CD006F3538 /* status-selected.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "status-selected.png"; sourceTree = "<group>"; };
- 022B0A441157B3C700385F13 /* NSStatusItem+BCStatusItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSStatusItem+BCStatusItem.h"; sourceTree = "<group>"; };
- 022B0A451157B3C700385F13 /* NSStatusItem+BCStatusItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSStatusItem+BCStatusItem.m"; sourceTree = "<group>"; };
- 022B0A491157B3D400385F13 /* BCStatusItemView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BCStatusItemView.h; sourceTree = "<group>"; };
- 022B0A4A1157B3D400385F13 /* BCStatusItemView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BCStatusItemView.m; sourceTree = "<group>"; };
- 02FCFF3611A6051500992919 /* README.markdown */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = README.markdown; sourceTree = "<group>"; };
089C165DFE840E0CC02AAC07 /* English */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = English; path = English.lproj/InfoPlist.strings; sourceTree = "<group>"; };
1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = "<absolute>"; };
13E42FB307B3F0F600E4EEF1 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = /System/Library/Frameworks/CoreData.framework; sourceTree = "<absolute>"; };
@@ -38,6 +33,11 @@
29B97325FDCFA39411CA2CEA /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = "<absolute>"; };
8D1107310486CEB800E47090 /* BCStatusItem-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "BCStatusItem-Info.plist"; sourceTree = "<group>"; };
8D1107320486CEB800E47090 /* BCStatusItem.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = BCStatusItem.app; sourceTree = BUILT_PRODUCTS_DIR; };
+ B0BD953C13A6FCD6003B3689 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = text; name = README.md; path = ../README.md; sourceTree = "<group>"; };
+ B0BD954313A6FD30003B3689 /* BCStatusItemView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BCStatusItemView.h; sourceTree = "<group>"; };
+ B0BD954413A6FD30003B3689 /* BCStatusItemView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BCStatusItemView.m; sourceTree = "<group>"; };
+ B0BD954513A6FD30003B3689 /* NSStatusItem+BCStatusItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSStatusItem+BCStatusItem.h"; sourceTree = "<group>"; };
+ B0BD954613A6FD30003B3689 /* NSStatusItem+BCStatusItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSStatusItem+BCStatusItem.m"; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -61,17 +61,6 @@
name = TestApp;
sourceTree = "<group>";
};
- 080E96DDFE201D6D7F000001 /* Classes */ = {
- isa = PBXGroup;
- children = (
- 022B0A441157B3C700385F13 /* NSStatusItem+BCStatusItem.h */,
- 022B0A451157B3C700385F13 /* NSStatusItem+BCStatusItem.m */,
- 022B0A491157B3D400385F13 /* BCStatusItemView.h */,
- 022B0A4A1157B3D400385F13 /* BCStatusItemView.m */,
- );
- name = Classes;
- sourceTree = "<group>";
- };
1058C7A0FEA54F0111CA2CBB /* Linked Frameworks */ = {
isa = PBXGroup;
children = (
@@ -101,8 +90,8 @@
29B97314FDCFA39411CA2CEA /* BCStatusItem */ = {
isa = PBXGroup;
children = (
- 02FCFF3611A6051500992919 /* README.markdown */,
- 080E96DDFE201D6D7F000001 /* Classes */,
+ B0BD953C13A6FCD6003B3689 /* README.md */,
+ B0BD954213A6FD30003B3689 /* BCStatusItem */,
02FCFEC711A5F68200992919 /* TestApp */,
29B97315FDCFA39411CA2CEA /* Other Sources */,
29B97317FDCFA39411CA2CEA /* Resources */,
@@ -142,6 +131,18 @@
name = Frameworks;
sourceTree = "<group>";
};
+ B0BD954213A6FD30003B3689 /* BCStatusItem */ = {
+ isa = PBXGroup;
+ children = (
+ B0BD954313A6FD30003B3689 /* BCStatusItemView.h */,
+ B0BD954413A6FD30003B3689 /* BCStatusItemView.m */,
+ B0BD954513A6FD30003B3689 /* NSStatusItem+BCStatusItem.h */,
+ B0BD954613A6FD30003B3689 /* NSStatusItem+BCStatusItem.m */,
+ );
+ name = BCStatusItem;
+ path = ../BCStatusItem;
+ sourceTree = "<group>";
+ };
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
@@ -169,10 +170,11 @@
29B97313FDCFA39411CA2CEA /* Project object */ = {
isa = PBXProject;
attributes = {
+ LastUpgradeCheck = 0420;
ORGANIZATIONNAME = "Buttered Cat Software";
};
buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "BCStatusItem" */;
- compatibilityVersion = "Xcode 3.1";
+ compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
hasScannedForEncodings = 1;
knownRegions = (
@@ -208,8 +210,8 @@
files = (
8D11072D0486CEB800E47090 /* main.m in Sources */,
256AC3DA0F4B6AC300CF3369 /* BCStatusItemAppDelegate.m in Sources */,
- 022B0A461157B3C700385F13 /* NSStatusItem+BCStatusItem.m in Sources */,
- 022B0A4B1157B3D400385F13 /* BCStatusItemView.m in Sources */,
+ B0BD954713A6FD30003B3689 /* BCStatusItemView.m in Sources */,
+ B0BD954813A6FD30003B3689 /* NSStatusItem+BCStatusItem.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -241,7 +243,6 @@
ALWAYS_SEARCH_USER_PATHS = NO;
COPY_PHASE_STRIP = NO;
GCC_DYNAMIC_NO_PIC = NO;
- GCC_ENABLE_FIX_AND_CONTINUE = YES;
GCC_MODEL_TUNING = G5;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
@@ -273,11 +274,11 @@
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
+ GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.5;
ONLY_ACTIVE_ARCH = YES;
- PREBINDING = NO;
SDKROOT = macosx;
};
name = Debug;
@@ -288,10 +289,10 @@
ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
+ GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.5;
- PREBINDING = NO;
SDKROOT = macosx;
};
name = Release;
File renamed without changes.
@@ -17,7 +17,7 @@ @implementation BCStatusItemAppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
NSImage *image = [NSImage imageNamed:@"status"];
NSImage *alternateImage = [NSImage imageNamed:@"status-selected"];
- statusItem = [[[NSStatusBar systemStatusBar] statusItemWithLength:[image size].width+40] retain];
+ statusItem = [[[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength] retain];
[statusItem setupView];
File renamed without changes.
File renamed without changes.
View
File renamed without changes.
File renamed without changes
File renamed without changes

0 comments on commit 161e84e

Please sign in to comment.