From b0e78c038de36346a727e24fb3436ec2100b8b3d Mon Sep 17 00:00:00 2001 From: Wade Cosgrove Date: Tue, 5 Jul 2011 12:04:47 -0700 Subject: [PATCH] added window menu support and fixed display bugs --- INAppStoreWindow.h | 7 +++--- INAppStoreWindow.m | 61 ++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 55 insertions(+), 13 deletions(-) mode change 100644 => 100755 INAppStoreWindow.h mode change 100644 => 100755 INAppStoreWindow.m diff --git a/INAppStoreWindow.h b/INAppStoreWindow.h old mode 100644 new mode 100755 index fd4c262..e9724f1 --- a/INAppStoreWindow.h +++ b/INAppStoreWindow.h @@ -14,18 +14,19 @@ @interface INTitlebarView : NSView { } -- (NSBezierPath*)clippingPathWithRect:(NSRect)aRect cornerRadius:(float)radius; +- (NSBezierPath*)clippingPathWithRect:(NSRect)aRect cornerRadius:(CGFloat)radius; @end /** @class INAppStoreWindow Creates a window similar to the Mac App Store window, with centered traffic lights and an enlarged title bar. This does not handle creating the toolbar. **/ @interface INAppStoreWindow : NSWindow { - float _titleBarHeight; + CGFloat _titleBarHeight; NSView *_titleBarView; + NSString *_windowMenuTitle; } /** The height of the title bar. By default, this is set to the standard title bar height. **/ -@property (nonatomic, assign) float titleBarHeight; +@property (nonatomic, assign) CGFloat titleBarHeight; /** The title bar view itself. Add subviews to this view that you want to show in the title bar (e.g. buttons, a toolbar, etc.). This view can also be set if you want to use a different styled title bar aside from the default one (textured, etc.). **/ @property (nonatomic, retain) NSView *titleBarView; @end diff --git a/INAppStoreWindow.m b/INAppStoreWindow.m old mode 100644 new mode 100755 index ac1cd68..962edcf --- a/INAppStoreWindow.m +++ b/INAppStoreWindow.m @@ -27,6 +27,7 @@ #define CORNER_CLIP_RADIUS 4.0 @interface INAppStoreWindow () +@property (copy) NSString *windowMenuTitle; - (void)_doInitialWindowSetup; - (void)_createTitlebarView; - (void)_setupTrafficLightsTrackingArea; @@ -62,7 +63,7 @@ - (void)drawRect:(NSRect)dirtyRect // Uses code from NSBezierPath+PXRoundedRectangleAdditions by Andy Matuschak // -- (NSBezierPath*)clippingPathWithRect:(NSRect)aRect cornerRadius:(float)radius +- (NSBezierPath*)clippingPathWithRect:(NSRect)aRect cornerRadius:(CGFloat)radius { NSBezierPath *path = [NSBezierPath bezierPath]; NSRect rect = NSInsetRect(aRect, radius, radius); @@ -80,6 +81,8 @@ - (NSBezierPath*)clippingPathWithRect:(NSRect)aRect cornerRadius:(float)radius @implementation INAppStoreWindow +@synthesize windowMenuTitle = _windowMenuTitle; + #pragma mark - #pragma mark Initialization @@ -104,6 +107,7 @@ - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; [_titleBarView release]; + [_windowMenuTitle release]; [super dealloc]; } @@ -117,11 +121,41 @@ - (NSString*)title return @""; } -- (void)setTitle:(NSString *)aString +- (void)setTitle:(NSString*)title +{ + self.windowMenuTitle = title; + if ( ![self isExcludedFromWindowsMenu] ) + [NSApp changeWindowsItem:self title:self.windowMenuTitle filename:NO]; +} + +- (void)setRepresentedURL:(NSURL *)url +{ + // do nothing, don't want to show document icon in menu bar +} + +- (void)makeKeyAndOrderFront:(id)sender { - return; + [super makeKeyAndOrderFront:sender]; + if ( ![self isExcludedFromWindowsMenu] ) + [NSApp addWindowsItem:self title:self.windowMenuTitle filename:NO]; } + +- (void)orderFront:(id)sender +{ + [super orderFront:sender]; + if ( ![self isExcludedFromWindowsMenu] ) + [NSApp addWindowsItem:self title:self.windowMenuTitle filename:NO]; +} + + +- (void)orderOut:(id)sender +{ + [super orderOut:sender]; + [NSApp removeWindowsItem:self]; +} + + #pragma mark - #pragma mark Accessors @@ -149,19 +183,23 @@ - (NSView*)titleBarView return _titleBarView; } -- (void)setTitleBarHeight:(float)newTitleBarHeight +- (void)setTitleBarHeight:(CGFloat)newTitleBarHeight { float minTitleHeight = [self _minimumTitlebarHeight]; if (newTitleBarHeight < minTitleHeight) { newTitleBarHeight = minTitleHeight; } - _titleBarHeight = newTitleBarHeight; - [self _recalculateFrameForTitleBarView]; - [self _layoutTrafficLightsAndContent]; - [self _displayWindowAndTitlebar]; + + if ( _titleBarHeight != newTitleBarHeight ) + { + _titleBarHeight = newTitleBarHeight; + [self _recalculateFrameForTitleBarView]; + [self _layoutTrafficLightsAndContent]; + [self _displayWindowAndTitlebar]; + } } -- (float)titleBarHeight +- (CGFloat)titleBarHeight { return _titleBarHeight; } @@ -184,6 +222,10 @@ - (void)_doInitialWindowSetup [nc addObserver:self selector:@selector(_displayWindowAndTitlebar) name:NSWindowDidResignKeyNotification object:self]; [nc addObserver:self selector:@selector(_displayWindowAndTitlebar) name:NSWindowDidBecomeKeyNotification object:self]; [nc addObserver:self selector:@selector(_setupTrafficLightsTrackingArea) name:NSWindowDidBecomeKeyNotification object:self]; + + [nc addObserver:self selector:@selector(_displayWindowAndTitlebar) name:NSApplicationDidBecomeActiveNotification object:nil]; + [nc addObserver:self selector:@selector(_displayWindowAndTitlebar) name:NSApplicationDidResignActiveNotification object:nil]; + [self _createTitlebarView]; [self _layoutTrafficLightsAndContent]; [self _setupTrafficLightsTrackingArea]; @@ -264,7 +306,6 @@ - (float)_minimumTitlebarHeight - (void)_displayWindowAndTitlebar { // Redraw the window and titlebar - [self display]; [_titleBarView setNeedsDisplay:YES]; } @end