diff --git a/INAppStoreWindow.m b/INAppStoreWindow.m index 2129284..b575603 100644 --- a/INAppStoreWindow.m +++ b/INAppStoreWindow.m @@ -16,6 +16,7 @@ // #import "INAppStoreWindow.h" +#import "NSWindow_Extensions.h" #define IN_RUNNING_LION (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6) #define IN_COMPILING_LION __MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 @@ -230,7 +231,8 @@ - (void)drawRect:(NSRect)dirtyRect NSRect clippingRect = drawingRect; #if IN_COMPILING_LION - if((([window styleMask] & NSFullScreenWindowMask) == NSFullScreenWindowMask)){ + if (window.isFullScreen) + { [[NSColor blackColor] setFill]; [[NSBezierPath bezierPathWithRect:self.bounds] fill]; } @@ -290,12 +292,14 @@ - (void)drawRect:(NSRect)dirtyRect */ } - if ([window showsTitle] && (([window styleMask] & NSFullScreenWindowMask) == 0 || window.showsTitleInFullscreen)) { + if ([window showsTitle] && (window.isFullScreen || window.showsTitleInFullscreen)) + { NSRect titleTextRect; NSDictionary *titleTextStyles = nil; [self getTitleFrame:&titleTextRect textAttributes:&titleTextStyles forWindow:window]; - if (window.verticallyCenterTitle) { + if (window.verticallyCenterTitle) + { titleTextRect.origin.y = floorf(NSMidY(drawingRect) - (NSHeight(titleTextRect) / 2.f)); } @@ -386,7 +390,8 @@ - (void)mouseDragged:(NSEvent *)theEvent NSWindow *window = [self window]; NSPoint where = [window convertBaseToScreen:[theEvent locationInWindow]]; - if ([window isMovableByWindowBackground] || ([window styleMask] & NSFullScreenWindowMask) == NSFullScreenWindowMask) { + if ([window isMovableByWindowBackground] || window.isFullScreen) + { [super mouseDragged: theEvent]; return; } @@ -403,7 +408,8 @@ - (void)mouseDragged:(NSEvent *)theEvent } @end -@implementation INAppStoreWindow{ +@implementation INAppStoreWindow +{ CGFloat _cachedTitleBarHeight; BOOL _setFullScreenButtonRightMargin; BOOL _preventWindowFrameChange; @@ -504,6 +510,7 @@ - (void)becomeMainWindow { [super becomeMainWindow]; [self _updateTitlebarView]; + [self _layoutTrafficLightsAndContent]; } - (void)resignMainWindow @@ -607,7 +614,8 @@ - (CGFloat)trafficLightButtonsLeftMargin - (void)setFullScreenButtonRightMargin:(CGFloat)newFullScreenButtonRightMargin { - if (_fullScreenButtonRightMargin != newFullScreenButtonRightMargin) { + if (_fullScreenButtonRightMargin != newFullScreenButtonRightMargin) + { _setFullScreenButtonRightMargin = YES; _fullScreenButtonRightMargin = newFullScreenButtonRightMargin; [self _layoutTrafficLightsAndContent]; @@ -620,15 +628,19 @@ - (CGFloat)fullScreenButtonRightMargin return _fullScreenButtonRightMargin; } -- (void)setShowsTitle:(BOOL)showsTitle { - if (_showsTitle != showsTitle) { +- (void)setShowsTitle:(BOOL)showsTitle +{ + if (_showsTitle != showsTitle) + { _showsTitle = showsTitle; [self _displayWindowAndTitlebar]; } } -- (void)setCenterFullScreenButton:(BOOL)centerFullScreenButton{ - if( _centerFullScreenButton != centerFullScreenButton ) { +- (void)setCenterFullScreenButton:(BOOL)centerFullScreenButton +{ + if (_centerFullScreenButton != centerFullScreenButton) + { _centerFullScreenButton = centerFullScreenButton; [self _layoutTrafficLightsAndContent]; } @@ -636,7 +648,8 @@ - (void)setCenterFullScreenButton:(BOOL)centerFullScreenButton{ - (void)setCenterTrafficLightButtons:(BOOL)centerTrafficLightButtons { - if ( _centerTrafficLightButtons != centerTrafficLightButtons ) { + if (_centerTrafficLightButtons != centerTrafficLightButtons) + { _centerTrafficLightButtons = centerTrafficLightButtons; [self _layoutTrafficLightsAndContent]; [self _setupTrafficLightsTrackingArea]; @@ -645,7 +658,8 @@ - (void)setCenterTrafficLightButtons:(BOOL)centerTrafficLightButtons - (void)setVerticalTrafficLightButtons:(BOOL)verticalTrafficLightButtons { - if ( _verticalTrafficLightButtons != verticalTrafficLightButtons ) { + if (_verticalTrafficLightButtons != verticalTrafficLightButtons) + { _verticalTrafficLightButtons = verticalTrafficLightButtons; [self _layoutTrafficLightsAndContent]; [self _setupTrafficLightsTrackingArea]; @@ -654,7 +668,8 @@ - (void)setVerticalTrafficLightButtons:(BOOL)verticalTrafficLightButtons - (void)setVerticallyCenterTitle:(BOOL)verticallyCenterTitle { - if ( _verticallyCenterTitle != verticallyCenterTitle ) { + if (_verticallyCenterTitle != verticallyCenterTitle) + { _verticallyCenterTitle = verticallyCenterTitle; [self _displayWindowAndTitlebar]; } @@ -662,7 +677,8 @@ - (void)setVerticallyCenterTitle:(BOOL)verticallyCenterTitle - (void)setTrafficLightSeparation:(CGFloat)trafficLightSeparation { - if (_trafficLightSeparation != trafficLightSeparation) { + if (_trafficLightSeparation != trafficLightSeparation) + { _trafficLightSeparation = trafficLightSeparation; [self _layoutTrafficLightsAndContent]; [self _setupTrafficLightsTrackingArea]; @@ -681,11 +697,14 @@ - (void)setDelegate:(id)anObject return [_delegateProxy secondaryDelegate]; } -- (void)setCloseButton:(INWindowButton *)closeButton { - if (_closeButton != closeButton) { +- (void)setCloseButton:(INWindowButton *)closeButton +{ + if (_closeButton != closeButton) + { [_closeButton removeFromSuperview]; _closeButton = closeButton; - if (_closeButton) { + if (_closeButton) + { _closeButton.target = self; _closeButton.action = @selector(performClose:); [_closeButton setFrameOrigin:[[self standardWindowButton:NSWindowCloseButton] frame].origin]; @@ -694,11 +713,14 @@ - (void)setCloseButton:(INWindowButton *)closeButton { } } -- (void)setMinimizeButton:(INWindowButton *)minimizeButton { - if (_minimizeButton != minimizeButton) { +- (void)setMinimizeButton:(INWindowButton *)minimizeButton +{ + if (_minimizeButton != minimizeButton) + { [_minimizeButton removeFromSuperview]; _minimizeButton = minimizeButton; - if (_minimizeButton) { + if (_minimizeButton) + { _minimizeButton.target = self; _minimizeButton.action = @selector(performMiniaturize:); [_minimizeButton setFrameOrigin:[[self standardWindowButton:NSWindowMiniaturizeButton] frame].origin]; @@ -707,11 +729,14 @@ - (void)setMinimizeButton:(INWindowButton *)minimizeButton { } } -- (void)setZoomButton:(INWindowButton *)zoomButton { - if (_zoomButton != zoomButton) { +- (void)setZoomButton:(INWindowButton *)zoomButton +{ + if (_zoomButton != zoomButton) + { [_zoomButton removeFromSuperview]; _zoomButton = zoomButton; - if (_zoomButton) { + if (_zoomButton) + { _zoomButton.target = self; _zoomButton.action = @selector(performZoom:); [_zoomButton setFrameOrigin:[[self standardWindowButton:NSWindowZoomButton] frame].origin]; @@ -720,11 +745,14 @@ - (void)setZoomButton:(INWindowButton *)zoomButton { } } -- (void)setFullScreenButton:(INWindowButton *)fullScreenButton { - if (_fullScreenButton != fullScreenButton) { +- (void)setFullScreenButton:(INWindowButton *)fullScreenButton +{ + if (_fullScreenButton != fullScreenButton) + { [_fullScreenButton removeFromSuperview]; _fullScreenButton = fullScreenButton; - if (_fullScreenButton) { + if (_fullScreenButton) + { _fullScreenButton.target = self; _fullScreenButton.action = @selector(toggleFullScreen:); [_fullScreenButton setFrameOrigin:[[self standardWindowButton:NSWindowFullScreenButton] frame].origin]; @@ -752,6 +780,7 @@ - (void)setFrame:(NSRect)frameRect display:(BOOL)displayFlag animate:(BOOL)anima [super setFrame:frameRect display:displayFlag animate:animateFlag]; } + #pragma mark - #pragma mark Private @@ -779,13 +808,14 @@ - (void)_doInitialWindowSetup [nc addObserver:self selector:@selector(_updateTitlebarView) name:NSApplicationDidBecomeActiveNotification object:nil]; [nc addObserver:self selector:@selector(_updateTitlebarView) name:NSApplicationDidResignActiveNotification object:nil]; - #if IN_COMPILING_LION - if (IN_RUNNING_LION) { + + if (RUNNING_ON_LION_OR_HIGHER) + { [nc addObserver:self selector:@selector(windowDidExitFullScreen:) name:NSWindowDidExitFullScreenNotification object:nil]; [nc addObserver:self selector:@selector(windowWillEnterFullScreen:) name:NSWindowWillEnterFullScreenNotification object:nil]; [nc addObserver:self selector:@selector(windowWillExitFullScreen:) name:NSWindowWillExitFullScreenNotification object:nil]; } - #endif + [self _createTitlebarView]; [self _layoutTrafficLightsAndContent]; [self _setupTrafficLightsTrackingArea]; @@ -820,6 +850,9 @@ - (NSButton *)_fullScreenButtonToLayout { - (void)_layoutTrafficLightsAndContent { + if (RUNNING_ON_YOSEMITE) + return; + // Reposition/resize the title bar view as needed [self _recalculateFrameForTitleBarContainer]; NSButton *close = [self _closeButtonToLayout]; @@ -831,11 +864,16 @@ - (void)_layoutTrafficLightsAndContent NSRect minimizeFrame = [minimize frame]; NSRect zoomFrame = [zoom frame]; NSRect titleBarFrame = [_titleBarContainer frame]; + CGFloat buttonOrigin = 0.0; - if (!self.verticalTrafficLightButtons) { - if (self.centerTrafficLightButtons) { + if (!self.verticalTrafficLightButtons) + { + if (self.centerTrafficLightButtons) + { buttonOrigin = round(NSMidY(titleBarFrame) - INMidHeight(closeFrame)); - } else { + } + else + { buttonOrigin = NSMaxY(titleBarFrame) - NSHeight(closeFrame) - self.trafficLightButtonsTopMargin; } closeFrame.origin.y = buttonOrigin; @@ -844,11 +882,16 @@ - (void)_layoutTrafficLightsAndContent closeFrame.origin.x = self.trafficLightButtonsLeftMargin; minimizeFrame.origin.x = NSMaxX(closeFrame) + self.trafficLightSeparation; zoomFrame.origin.x = NSMaxX(minimizeFrame) + self.trafficLightSeparation; - } else { + } + else + { CGFloat groupHeight = NSHeight(closeFrame) + NSHeight(minimizeFrame) + NSHeight(zoomFrame) + 2.f * (self.trafficLightSeparation - 2.f); - if (self.centerTrafficLightButtons) { + if (self.centerTrafficLightButtons) + { buttonOrigin = round(NSMidY(titleBarFrame) - groupHeight / 2.f); - } else { + } + else + { buttonOrigin = NSMaxY(titleBarFrame) - groupHeight - self.trafficLightButtonsTopMargin; } closeFrame.origin.x = self.trafficLightButtonsLeftMargin; @@ -858,66 +901,79 @@ - (void)_layoutTrafficLightsAndContent minimizeFrame.origin.y = NSMaxY(zoomFrame) + self.trafficLightSeparation - 2.f; closeFrame.origin.y = NSMaxY(minimizeFrame) + self.trafficLightSeparation - 2.f; } - [close setFrame:closeFrame]; - [minimize setFrame:minimizeFrame]; - [zoom setFrame:zoomFrame]; - #if IN_COMPILING_LION // Set the frame of the FullScreen button in Lion if available - if (IN_RUNNING_LION) { + if (RUNNING_ON_LION_OR_HIGHER) + { NSButton *fullScreen = [self _fullScreenButtonToLayout]; if (fullScreen) { NSRect fullScreenFrame = [fullScreen frame]; - if (!_setFullScreenButtonRightMargin) { + if (!_setFullScreenButtonRightMargin) + { self.fullScreenButtonRightMargin = NSWidth([_titleBarContainer frame]) - NSMaxX(fullScreen.frame); } fullScreenFrame.origin.x = NSWidth(titleBarFrame) - NSWidth(fullScreenFrame) - _fullScreenButtonRightMargin; - if (self.centerFullScreenButton) { + + if (self.centerFullScreenButton) + { fullScreenFrame.origin.y = round(NSMidY(titleBarFrame) - INMidHeight(fullScreenFrame)); - } else { + } + else + { fullScreenFrame.origin.y = NSMaxY(titleBarFrame) - NSHeight(fullScreenFrame) - self.fullScreenButtonTopMargin; } [fullScreen setFrame:fullScreenFrame]; } } - #endif + [self _repositionContentView]; } -- (void)undoManagerDidCloseUndoGroupNotification:(NSNotification *)notification { +- (void)undoManagerDidCloseUndoGroupNotification:(NSNotification *)notification +{ [self _displayWindowAndTitlebar]; } - (void)windowWillEnterFullScreen:(NSNotification *)notification { - if (_hideTitleBarInFullScreen) { + if (RUNNING_ON_YOSEMITE) + return; + + if (_hideTitleBarInFullScreen) + { // Recalculate the views when entering from fullscreen _titleBarHeight = 0.0f; [self _layoutTrafficLightsAndContent]; [self _displayWindowAndTitlebar]; - [self _hideTitleBarView:YES]; } } - (void)windowWillExitFullScreen:(NSNotification *)notification { - if (_hideTitleBarInFullScreen) { + if (RUNNING_ON_YOSEMITE) + return; + + if (_hideTitleBarInFullScreen) + { _titleBarHeight = _cachedTitleBarHeight; [self _layoutTrafficLightsAndContent]; [self _displayWindowAndTitlebar]; - [self _hideTitleBarView:NO]; } } - (void)windowDidExitFullScreen:(NSNotification *)notification { + if (RUNNING_ON_YOSEMITE) + return; + [self _layoutTrafficLightsAndContent]; [self _setupTrafficLightsTrackingArea]; } -- (NSView *)themeFrameView { +- (NSView *)themeFrameView +{ return [[self contentView] superview]; } @@ -946,12 +1002,18 @@ - (void)_hideTitleBarView:(BOOL)hidden // Solution for tracking area issue thanks to @Perspx (Alex Rozanski) - (void)_setupTrafficLightsTrackingArea { + if (RUNNING_ON_YOSEMITE) + return; + [[self themeFrameView] viewWillStartLiveResize]; [[self themeFrameView] viewDidEndLiveResize]; } - (void)_recalculateFrameForTitleBarContainer { + if (RUNNING_ON_YOSEMITE) + return; + NSRect themeFrameRect = [[self themeFrameView] frame]; NSRect titleFrame = NSMakeRect(0.0, NSMaxY(themeFrameRect) - _titleBarHeight, NSWidth(themeFrameRect), _titleBarHeight); [_titleBarContainer setFrame:titleFrame]; @@ -959,6 +1021,9 @@ - (void)_recalculateFrameForTitleBarContainer - (void)_repositionContentView { + if (RUNNING_ON_YOSEMITE) + return; + NSView *contentView = [self contentView]; NSRect windowFrame = [self frame]; NSRect currentContentFrame = [contentView frame]; @@ -1014,6 +1079,9 @@ - (void)_displayWindowAndTitlebar - (void)_updateTitlebarView { + if (RUNNING_ON_YOSEMITE) + return; + [_titleBarView setNeedsDisplay:YES]; // "validate" any controls in the titlebar view