Skip to content

Commit

Permalink
added window menu support and fixed display bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Wade Cosgrove authored and Wade Cosgrove committed Jul 5, 2011
1 parent 5acf06a commit b0e78c0
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 13 deletions.
7 changes: 4 additions & 3 deletions INAppStoreWindow.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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
61 changes: 51 additions & 10 deletions INAppStoreWindow.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#define CORNER_CLIP_RADIUS 4.0

@interface INAppStoreWindow ()
@property (copy) NSString *windowMenuTitle;
- (void)_doInitialWindowSetup;
- (void)_createTitlebarView;
- (void)_setupTrafficLightsTrackingArea;
Expand Down Expand Up @@ -62,7 +63,7 @@ - (void)drawRect:(NSRect)dirtyRect
// Uses code from NSBezierPath+PXRoundedRectangleAdditions by Andy Matuschak
// <http://code.andymatuschak.org/pixen/trunk/NSBezierPath+PXRoundedRectangleAdditions.m>

- (NSBezierPath*)clippingPathWithRect:(NSRect)aRect cornerRadius:(float)radius
- (NSBezierPath*)clippingPathWithRect:(NSRect)aRect cornerRadius:(CGFloat)radius
{
NSBezierPath *path = [NSBezierPath bezierPath];
NSRect rect = NSInsetRect(aRect, radius, radius);
Expand All @@ -80,6 +81,8 @@ - (NSBezierPath*)clippingPathWithRect:(NSRect)aRect cornerRadius:(float)radius

@implementation INAppStoreWindow

@synthesize windowMenuTitle = _windowMenuTitle;

#pragma mark -
#pragma mark Initialization

Expand All @@ -104,6 +107,7 @@ - (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
[_titleBarView release];
[_windowMenuTitle release];
[super dealloc];
}

Expand All @@ -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];

This comment has been minimized.

Copy link
@Kentzo

Kentzo May 18, 2012

Isn't it a default behavior?

This comment has been minimized.

Copy link
@kgn

kgn May 18, 2012

Contributor

I believe the reason for this code is that - (NSString*)title always returns an empty string so it doesn't draw so we need to manage the window list ourselves. I'd have to test this but we might be able to draw over the title, if this is the case then this code could be removed.

}

- (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

Expand Down Expand Up @@ -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;
}
Expand All @@ -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];
Expand Down Expand Up @@ -264,7 +306,6 @@ - (float)_minimumTitlebarHeight
- (void)_displayWindowAndTitlebar
{
// Redraw the window and titlebar
[self display];
[_titleBarView setNeedsDisplay:YES];
}
@end

0 comments on commit b0e78c0

Please sign in to comment.