diff --git a/src/MacVim/MMFullScreenWindow.m b/src/MacVim/MMFullScreenWindow.m index f9e2acac66..ed6bd970af 100644 --- a/src/MacVim/MMFullScreenWindow.m +++ b/src/MacVim/MMFullScreenWindow.m @@ -155,7 +155,14 @@ enum { [[target windowController] setWindow:self]; oldTabBarStyle = [[view tabBarControl] styleName]; - [[view tabBarControl] setStyleNamed:@"Unified"]; + + NSString *style; +#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_10 + style = @"Yosemite"; +#else + style = @"Unified"; +#endif + [[view tabBarControl] setStyleNamed:style]; // add text view oldPosition = [view frame].origin; diff --git a/src/MacVim/MMVimView.m b/src/MacVim/MMVimView.m index 3dee3aa989..693723eb74 100644 --- a/src/MacVim/MMVimView.m +++ b/src/MacVim/MMVimView.m @@ -115,8 +115,8 @@ enum { // Create the tab bar control (which is responsible for actually // drawing the tabline and tabs). - NSRect tabFrame = { { 0, frame.size.height - 22 }, - { frame.size.width, 22 } }; + NSRect tabFrame = { { 0, frame.size.height - kPSMTabBarControlHeight }, + { frame.size.width, kPSMTabBarControlHeight } }; tabBarControl = [[PSMTabBarControl alloc] initWithFrame:tabFrame]; [tabView setDelegate:tabBarControl]; @@ -125,10 +125,18 @@ enum { [tabBarControl setDelegate:self]; [tabBarControl setHidden:YES]; +#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_10 + CGFloat screenWidth = [[NSScreen mainScreen] frame].size.width; + [tabBarControl setStyleNamed:@"Yosemite"]; + [tabBarControl setCellMinWidth:120]; + [tabBarControl setCellMaxWidth:screenWidth]; + [tabBarControl setCellOptimumWidth:screenWidth]; +#else [tabBarControl setCellMinWidth:[ud integerForKey:MMTabMinWidthKey]]; [tabBarControl setCellMaxWidth:[ud integerForKey:MMTabMaxWidthKey]]; [tabBarControl setCellOptimumWidth: [ud integerForKey:MMTabOptimumWidthKey]]; +#endif [tabBarControl setShowAddTabButton:[ud boolForKey:MMShowAddTabButtonKey]]; [[tabBarControl addTabButton] setTarget:self]; diff --git a/src/MacVim/MMWindowController.m b/src/MacVim/MMWindowController.m index ba29399c45..02a103353f 100644 --- a/src/MacVim/MMWindowController.m +++ b/src/MacVim/MMWindowController.m @@ -80,6 +80,14 @@ #define FUOPT_BGCOLOR_HLGROUP 0x004 +#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_10 +# define TABBAR_STYLE_UNIFINED @"Yosemite" +# define TABBAR_STYLE_METAL @"Yosemite" +#else +# define TABBAR_STYLE_UNIFINED @"Unified" +# define TABBAR_STYLE_METAL @"Metal" +#endif + @interface MMWindowController (Private) - (NSSize)contentSize; @@ -1173,7 +1181,7 @@ [[window animator] setAlphaValue:0]; } completionHandler:^{ [window setStyleMask:([window styleMask] | NSFullScreenWindowMask)]; - [[vimView tabBarControl] setStyleNamed:@"Unified"]; + [[vimView tabBarControl] setStyleNamed:TABBAR_STYLE_UNIFINED]; [self updateTablineSeparator]; // Stay dark for some time to wait for things to sync, then do the full screen operation @@ -1234,7 +1242,7 @@ fullScreenEnabled = NO; [window setAlphaValue:1]; [window setStyleMask:([window styleMask] & ~NSFullScreenWindowMask)]; - [[vimView tabBarControl] setStyleNamed:@"Metal"]; + [[vimView tabBarControl] setStyleNamed:TABBAR_STYLE_METAL]; [self updateTablineSeparator]; [window setFrame:preFullScreenFrame display:YES]; } @@ -1264,7 +1272,7 @@ [[window animator] setAlphaValue:0]; } completionHandler:^{ [window setStyleMask:([window styleMask] & ~NSFullScreenWindowMask)]; - [[vimView tabBarControl] setStyleNamed:@"Metal"]; + [[vimView tabBarControl] setStyleNamed:TABBAR_STYLE_METAL]; [self updateTablineSeparator]; [window setFrame:preFullScreenFrame display:YES]; @@ -1309,7 +1317,7 @@ fullScreenEnabled = YES; [window setAlphaValue:1]; [window setStyleMask:([window styleMask] | NSFullScreenWindowMask)]; - [[vimView tabBarControl] setStyleNamed:@"Unified"]; + [[vimView tabBarControl] setStyleNamed:TABBAR_STYLE_UNIFINED]; [self updateTablineSeparator]; [self maximizeWindow:fullScreenOptions]; } diff --git a/src/MacVim/PSMTabBarControl/PSMTabBarControl.xcodeproj/project.pbxproj b/src/MacVim/PSMTabBarControl/PSMTabBarControl.xcodeproj/project.pbxproj index 2b8d554314..399882d5f0 100644 --- a/src/MacVim/PSMTabBarControl/PSMTabBarControl.xcodeproj/project.pbxproj +++ b/src/MacVim/PSMTabBarControl/PSMTabBarControl.xcodeproj/project.pbxproj @@ -35,6 +35,10 @@ 52C0B9B515BDB7A9000C268F /* overflowImagePressed@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 52C0B9B315BDB7A9000C268F /* overflowImagePressed@2x.png */; }; 52C268D015BDB72B0012FECA /* overflowImage.png in Resources */ = {isa = PBXBuildFile; fileRef = 52C268CE15BDB72B0012FECA /* overflowImage.png */; }; 52C268D115BDB72B0012FECA /* overflowImagePressed.png in Resources */ = {isa = PBXBuildFile; fileRef = 52C268CF15BDB72B0012FECA /* overflowImagePressed.png */; }; + 52FAFCCF1C30F4B500C6E613 /* TabNewYosemite.png in Resources */ = {isa = PBXBuildFile; fileRef = 52FAFCCD1C30F4B500C6E613 /* TabNewYosemite.png */; }; + 52FAFCD01C30F4B500C6E613 /* TabNewYosemite@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 52FAFCCE1C30F4B500C6E613 /* TabNewYosemite@2x.png */; }; + 52FAFCD31C30F4DF00C6E613 /* PSMYosemiteTabStyle.h in Headers */ = {isa = PBXBuildFile; fileRef = 52FAFCD11C30F4DF00C6E613 /* PSMYosemiteTabStyle.h */; }; + 52FAFCD41C30F4DF00C6E613 /* PSMYosemiteTabStyle.m in Sources */ = {isa = PBXBuildFile; fileRef = 52FAFCD21C30F4DF00C6E613 /* PSMYosemiteTabStyle.m */; }; 546DEAF1067F63070098DCC4 /* PSMTabBarControl.m in Sources */ = {isa = PBXBuildFile; fileRef = 0259C576FE90428111CA0C5A /* PSMTabBarControl.m */; }; 546DEAF2067F630E0098DCC4 /* PSMTabBarControl.h in Headers */ = {isa = PBXBuildFile; fileRef = 0259C57AFE90428111CA0C5A /* PSMTabBarControl.h */; settings = {ATTRIBUTES = (Public, ); }; }; A2082A9009EAEB34009AC8BE /* PSMTabDragAssistant.h in Headers */ = {isa = PBXBuildFile; fileRef = A2082A8D09EAEB33009AC8BE /* PSMTabDragAssistant.h */; }; @@ -111,6 +115,10 @@ 52C0B9B315BDB7A9000C268F /* overflowImagePressed@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "overflowImagePressed@2x.png"; path = "images/overflowImagePressed@2x.png"; sourceTree = ""; }; 52C268CE15BDB72B0012FECA /* overflowImage.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = overflowImage.png; path = images/overflowImage.png; sourceTree = ""; }; 52C268CF15BDB72B0012FECA /* overflowImagePressed.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = overflowImagePressed.png; path = images/overflowImagePressed.png; sourceTree = ""; }; + 52FAFCCD1C30F4B500C6E613 /* TabNewYosemite.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = TabNewYosemite.png; path = images/TabNewYosemite.png; sourceTree = ""; }; + 52FAFCCE1C30F4B500C6E613 /* TabNewYosemite@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "TabNewYosemite@2x.png"; path = "images/TabNewYosemite@2x.png"; sourceTree = ""; }; + 52FAFCD11C30F4DF00C6E613 /* PSMYosemiteTabStyle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PSMYosemiteTabStyle.h; path = source/PSMYosemiteTabStyle.h; sourceTree = ""; }; + 52FAFCD21C30F4DF00C6E613 /* PSMYosemiteTabStyle.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = PSMYosemiteTabStyle.m; path = source/PSMYosemiteTabStyle.m; sourceTree = ""; }; 53DF68FD067E5B5A0090B5B0 /* PSMTabBarControl.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = PSMTabBarControl.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 53DF68FE067E5B5A0090B5B0 /* PSMTabBarControlFramework-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "PSMTabBarControlFramework-Info.plist"; sourceTree = ""; }; 54D33B2806778E3300C9C163 /* PSMTabBarControl.ibclassdescription */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = PSMTabBarControl.ibclassdescription; sourceTree = ""; }; @@ -309,6 +317,8 @@ A2D32EFF09A63D7A00EC8662 /* PSMMetalTabStyle.m */, A2D98B070A2B432C0064C6F8 /* PSMUnifiedTabStyle.h */, A2D98B080A2B432C0064C6F8 /* PSMUnifiedTabStyle.m */, + 52FAFCD11C30F4DF00C6E613 /* PSMYosemiteTabStyle.h */, + 52FAFCD21C30F4DF00C6E613 /* PSMYosemiteTabStyle.m */, A268EA5F09A9831800E082AA /* PSMRolloverButton.h */, A268EA6009A9831800E082AA /* PSMRolloverButton.m */, A251BE810959A1B90058BC7F /* PSMOverflowPopUpButton.h */, @@ -382,6 +392,8 @@ 523897EE15BDA9AC00498A53 /* TabClose_Front_Pressed@2x.png */, 52A57C0E15BBA230003EC59C /* TabClose_Front_Rollover.png */, 523897EF15BDA9AC00498A53 /* TabClose_Front_Rollover@2x.png */, + 52FAFCCD1C30F4B500C6E613 /* TabNewYosemite.png */, + 52FAFCCE1C30F4B500C6E613 /* TabNewYosemite@2x.png */, ); name = Images; sourceTree = ""; @@ -396,6 +408,7 @@ 546DEAF2067F630E0098DCC4 /* PSMTabBarControl.h in Headers */, A251BE850959A1B90058BC7F /* PSMOverflowPopUpButton.h in Headers */, A251BE870959A1B90058BC7F /* PSMTabBarCell.h in Headers */, + 52FAFCD31C30F4DF00C6E613 /* PSMYosemiteTabStyle.h in Headers */, A2D32EDC09A634C900EC8662 /* PSMTabStyle.h in Headers */, A2D32F0009A63D7A00EC8662 /* PSMMetalTabStyle.h in Headers */, A268EA6209A9831800E082AA /* PSMRolloverButton.h in Headers */, @@ -478,8 +491,10 @@ 52A57C0F15BBA230003EC59C /* TabClose_Front.png in Resources */, 52A57C1015BBA230003EC59C /* TabClose_Front_Pressed.png in Resources */, 52A57C1115BBA230003EC59C /* TabClose_Front_Rollover.png in Resources */, + 52FAFCCF1C30F4B500C6E613 /* TabNewYosemite.png in Resources */, 523897F415BDA9AC00498A53 /* TabClose_Front_Pressed@2x.png in Resources */, 523897F515BDA9AC00498A53 /* TabClose_Front_Rollover@2x.png in Resources */, + 52FAFCD01C30F4B500C6E613 /* TabNewYosemite@2x.png in Resources */, 523897F615BDA9AC00498A53 /* TabClose_Front@2x.png in Resources */, 523897F715BDA9AC00498A53 /* TabNewMetal@2x.png in Resources */, 523897F815BDA9AC00498A53 /* TabNewMetalPressed@2x.png in Resources */, @@ -505,6 +520,7 @@ A268EA6309A9831800E082AA /* PSMRolloverButton.m in Sources */, A2129BB309AEB58F00724E6C /* PSMProgressIndicator.m in Sources */, A2082A9109EAEB34009AC8BE /* PSMTabDragAssistant.m in Sources */, + 52FAFCD41C30F4DF00C6E613 /* PSMYosemiteTabStyle.m in Sources */, A2D98B0B0A2B432C0064C6F8 /* PSMUnifiedTabStyle.m in Sources */, A2D98B130A2B43FA0064C6F8 /* NSBezierPath_AMShading.m in Sources */, ); diff --git a/src/MacVim/PSMTabBarControl/images/TabNewYosemite.png b/src/MacVim/PSMTabBarControl/images/TabNewYosemite.png new file mode 100644 index 0000000000..a85cf21369 Binary files /dev/null and b/src/MacVim/PSMTabBarControl/images/TabNewYosemite.png differ diff --git a/src/MacVim/PSMTabBarControl/images/TabNewYosemite@2x.png b/src/MacVim/PSMTabBarControl/images/TabNewYosemite@2x.png new file mode 100644 index 0000000000..9f2b024011 Binary files /dev/null and b/src/MacVim/PSMTabBarControl/images/TabNewYosemite@2x.png differ diff --git a/src/MacVim/PSMTabBarControl/source/PSMMetalTabStyle.m b/src/MacVim/PSMTabBarControl/source/PSMMetalTabStyle.m index bb760f653c..f74d6b925a 100644 --- a/src/MacVim/PSMTabBarControl/source/PSMMetalTabStyle.m +++ b/src/MacVim/PSMTabBarControl/source/PSMMetalTabStyle.m @@ -393,12 +393,7 @@ void MyNSDrawWindowBackground(NSRect rect) if ([cell closeButtonPressed]) closeButton = metalCloseButtonDown; closeButtonSize = [closeButton size]; -#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_6 [closeButton drawInRect:closeButtonRect fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0 respectFlipped:YES hints:nil]; -#else - [closeButton setFlipped:YES]; - [closeButton drawAtPoint:closeButtonRect.origin fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0]; -#endif // scoot label over labelPosition += closeButtonSize.width + kPSMTabBarCellPadding; diff --git a/src/MacVim/PSMTabBarControl/source/PSMOverflowPopUpButton.m b/src/MacVim/PSMTabBarControl/source/PSMOverflowPopUpButton.m index 21727eafa3..b991740cdb 100644 --- a/src/MacVim/PSMTabBarControl/source/PSMOverflowPopUpButton.m +++ b/src/MacVim/PSMTabBarControl/source/PSMOverflowPopUpButton.m @@ -40,15 +40,14 @@ } NSImage *image = (_down) ? _PSMTabBarOverflowDownPopUpImage : _PSMTabBarOverflowPopUpImage; - NSSize imageSize = [image size]; - rect.origin.x = NSMidX(rect) - (imageSize.width * 0.5); - rect.origin.y = NSMidY(rect) - (imageSize.height * 0.5); -#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_6 - [image drawInRect:rect fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0 respectFlipped:YES hints:nil]; -#else - [image setFlipped:YES]; - [image drawAtPoint:rect.origin fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0]; -#endif + NSSize imageSize = [image size]; + NSRect bounds = [self bounds]; + NSPoint drawPoint = NSMakePoint(NSMidX(bounds) - (imageSize.width * 0.5f), + NSMidY(bounds) - (imageSize.height * 0.5f)); + [image drawAtPoint:drawPoint + fromRect:NSZeroRect + operation:NSCompositeSourceOver + fraction:1.0f]; } - (void)mouseDown:(NSEvent *)event diff --git a/src/MacVim/PSMTabBarControl/source/PSMTabBarControl.h b/src/MacVim/PSMTabBarControl/source/PSMTabBarControl.h index ba25998b9e..174dbe2754 100644 --- a/src/MacVim/PSMTabBarControl/source/PSMTabBarControl.h +++ b/src/MacVim/PSMTabBarControl/source/PSMTabBarControl.h @@ -12,26 +12,18 @@ #import -#ifndef NSINTEGER_DEFINED -// NSInteger was introduced in 10.5 -# if __LP64__ || NS_BUILD_32_LIKE_64 -typedef long NSInteger; -typedef unsigned long NSUInteger; -# else -typedef int NSInteger; -typedef unsigned int NSUInteger; -# endif -# define NSINTEGER_DEFINED 1 +#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_10 +# define kPSMTabBarControlHeight 25 +#else +# define kPSMTabBarControlHeight 22 #endif - -#ifndef MAC_OS_X_VERSION_10_6 -# define MAC_OS_X_VERSION_10_6 1060 -#endif - -#define kPSMTabBarControlHeight 22 // internal cell border #define MARGIN_X 6 -#define MARGIN_Y 3 +#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_10 +# define MARGIN_Y 5 +#else +# define MARGIN_Y 3 +#endif // padding between objects #define kPSMTabBarCellPadding 4 // fixed size objects diff --git a/src/MacVim/PSMTabBarControl/source/PSMTabBarControl.m b/src/MacVim/PSMTabBarControl/source/PSMTabBarControl.m index d0ec3817df..8a04234814 100644 --- a/src/MacVim/PSMTabBarControl/source/PSMTabBarControl.m +++ b/src/MacVim/PSMTabBarControl/source/PSMTabBarControl.m @@ -13,6 +13,7 @@ #import "PSMTabStyle.h" #import "PSMMetalTabStyle.h" #import "PSMUnifiedTabStyle.h" +#import "PSMYosemiteTabStyle.h" #import "PSMTabDragAssistant.h" @interface PSMTabBarControl (Private) @@ -254,10 +255,11 @@ - (void)setStyleNamed:(NSString *)name { [style release]; - if ([name isEqualToString:@"Unified"]){ - style = [[PSMUnifiedTabStyle alloc] init]; - } - else { + if([name isEqualToString:@"Unified"]){ + style = [[PSMUnifiedTabStyle alloc] init]; + } else if([name isEqualToString:@"Yosemite"]){ + style = [[PSMYosemiteTabStyle alloc] init]; + } else { style = [[PSMMetalTabStyle alloc] init]; } diff --git a/src/MacVim/PSMTabBarControl/source/PSMUnifiedTabStyle.m b/src/MacVim/PSMTabBarControl/source/PSMUnifiedTabStyle.m index 19f82f2d00..bc6e38e549 100644 --- a/src/MacVim/PSMTabBarControl/source/PSMUnifiedTabStyle.m +++ b/src/MacVim/PSMTabBarControl/source/PSMUnifiedTabStyle.m @@ -389,13 +389,8 @@ if ([cell closeButtonPressed]) closeButton = unifiedCloseButtonDown; closeButtonSize = [closeButton size]; -#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_6 [closeButton drawInRect:closeButtonRect fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0 respectFlipped:YES hints:nil]; -#else - [closeButton setFlipped:YES]; - [closeButton drawAtPoint:closeButtonRect.origin fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0]; -#endif - + // scoot label over labelPosition += closeButtonSize.width + kPSMTabBarCellPadding; } diff --git a/src/MacVim/PSMTabBarControl/source/PSMYosemiteTabStyle.h b/src/MacVim/PSMTabBarControl/source/PSMYosemiteTabStyle.h new file mode 100644 index 0000000000..2f3581132f --- /dev/null +++ b/src/MacVim/PSMTabBarControl/source/PSMYosemiteTabStyle.h @@ -0,0 +1,28 @@ +// +// PSMYosemiteTabStyle.h +// PSMTabBarControl +// +// Created by Christoffer Winterkvist on 25/08/14. +// +// + +#import +#import "PSMTabStyle.h" + +@interface PSMYosemiteTabStyle : NSObject { + NSImage *closeButton; + NSImage *closeButtonDown; + NSImage *closeButtonOver; + NSImage *_addTabButtonImage; + NSImage *_addTabButtonPressedImage; + NSImage *_addTabButtonRolloverImage; + NSMutableParagraphStyle *truncatingTailParagraphStyle; + NSMutableParagraphStyle *centeredParagraphStyle; +} + +- (void)drawInteriorWithTabCell:(PSMTabBarCell *)cell inView:(NSView*)controlView; + +- (void)encodeWithCoder:(NSCoder *)aCoder; +- (id)initWithCoder:(NSCoder *)aDecoder; + +@end diff --git a/src/MacVim/PSMTabBarControl/source/PSMYosemiteTabStyle.m b/src/MacVim/PSMTabBarControl/source/PSMYosemiteTabStyle.m new file mode 100644 index 0000000000..054c4158aa --- /dev/null +++ b/src/MacVim/PSMTabBarControl/source/PSMYosemiteTabStyle.m @@ -0,0 +1,498 @@ +// +// PSMYosemiteTabStyle.m +// PSMTabBarControl +// +// Created by Christoffer Winterkvist on 25/08/14. +// +// + +#import "PSMYosemiteTabStyle.h" + +#define kPSMMetalObjectCounterRadius 7.0 +#define kPSMMetalCounterMinWidth 20 + +void YosemiteNSDrawWindowBackground(NSRect rect, NSColor *color) +{ + [color set]; + NSRectFill( rect ); +} + +@implementation PSMYosemiteTabStyle + +- (void)dealloc +{ + [closeButton release]; + [closeButtonDown release]; + [closeButtonOver release]; + [_addTabButtonImage release]; + [_addTabButtonPressedImage release]; + [_addTabButtonRolloverImage release]; + + [truncatingTailParagraphStyle release]; + [centeredParagraphStyle release]; + + [super dealloc]; +} + +#pragma mark - +#pragma mark Initializers + +- (id)init +{ + self = [super init]; + if (!self) return nil; + + closeButton = [[NSImage alloc] initByReferencingFile:[[PSMTabBarControl bundle] pathForImageResource:@"TabClose_Front"]]; + //NSLog(@"closeButton=%@ path=%@", metalCloseButton, + // [[PSMTabBarControl bundle] pathForImageResource:@"TabClose_Front"]); + closeButtonDown = [[NSImage alloc] initByReferencingFile:[[PSMTabBarControl bundle] pathForImageResource:@"TabClose_Front_Pressed"]]; + closeButtonOver = [[NSImage alloc] initByReferencingFile:[[PSMTabBarControl bundle] pathForImageResource:@"TabClose_Front_Rollover"]]; + + _addTabButtonImage = [[NSImage alloc] initByReferencingFile:[[PSMTabBarControl bundle] pathForImageResource:@"TabNewMetal"]]; + _addTabButtonPressedImage = [[NSImage alloc] initByReferencingFile:[[PSMTabBarControl bundle] pathForImageResource:@"TabNewMetalPressed"]]; + _addTabButtonRolloverImage = [[NSImage alloc] initByReferencingFile:[[PSMTabBarControl bundle] pathForImageResource:@"TabNewMetalRollover"]]; + + return self; +} + +- (NSString *)name +{ + return @"Yosemite"; +} + +#pragma mark - +#pragma mark Control Specific + +- (float)leftMarginForTabBarControl +{ + return -1.0f; +} + +- (float)rightMarginForTabBarControl +{ + return 24.0f; +} + +#pragma mark - +#pragma mark Add Tab Button + +- (NSImage *)addTabButtonImage +{ + return _addTabButtonImage; +} + +- (NSImage *)addTabButtonPressedImage +{ + return _addTabButtonPressedImage; +} + +- (NSImage *)addTabButtonRolloverImage +{ + return _addTabButtonRolloverImage; +} + +- (NSColor *)backgroundColor:(BOOL)isKeyWindow +{ + NSColor *backgroundColor; + if (isKeyWindow) { + backgroundColor = [NSColor colorWithCalibratedHue:0.000 saturation:0.000 brightness:0.875 alpha:1]; + } else { + backgroundColor = [NSColor colorWithCalibratedHue:0.000 saturation:0.000 brightness:0.957 alpha:1]; + } + + return backgroundColor; +} + +- (NSColor *)borderColor +{ + return [NSColor colorWithCalibratedHue:0.000 saturation:0.000 brightness:0.678 alpha:1]; +} + +#pragma mark - +#pragma mark Cell Specific + +- (NSRect) closeButtonRectForTabCell:(PSMTabBarCell *)cell +{ + NSRect cellFrame = [cell frame]; + + if ([cell hasCloseButton] == NO) { + return NSZeroRect; + } + + NSRect result; + result.size = [closeButton size]; + result.origin.x = cellFrame.origin.x + MARGIN_X; + result.origin.y = cellFrame.origin.y + MARGIN_Y + 2.0; + + return result; +} + +- (NSRect)iconRectForTabCell:(PSMTabBarCell *)cell +{ + NSRect cellFrame = [cell frame]; + + if ([cell hasIcon] == NO) { + return NSZeroRect; + } + + NSRect result; + result.size = NSMakeSize(kPSMTabBarIconWidth, kPSMTabBarIconWidth); + result.origin.x = cellFrame.origin.x + MARGIN_X; + result.origin.y = cellFrame.origin.y + MARGIN_Y; + + if([cell hasCloseButton] && ![cell isCloseButtonSuppressed]) + result.origin.x += [closeButton size].width + kPSMTabBarCellPadding; + + if([cell state] == NSOnState){ + result.origin.y += 1; + } + + return result; +} + +- (NSRect)indicatorRectForTabCell:(PSMTabBarCell *)cell +{ + NSRect cellFrame = [cell frame]; + + if ([[cell indicator] isHidden]) { + return NSZeroRect; + } + + NSRect result; + result.size = NSMakeSize(kPSMTabBarIndicatorWidth, kPSMTabBarIndicatorWidth); + result.origin.x = cellFrame.origin.x + cellFrame.size.width - MARGIN_X - kPSMTabBarIndicatorWidth; + result.origin.y = cellFrame.origin.y + MARGIN_Y; + + if([cell state] == NSOnState){ + result.origin.y -= 1; + } + + return result; +} + +- (NSRect)objectCounterRectForTabCell:(PSMTabBarCell *)cell +{ + NSRect cellFrame = [cell frame]; + + if ([cell count] == 0) { + return NSZeroRect; + } + + float countWidth = [[self attributedObjectCountValueForTabCell:cell] size].width; + countWidth += (2 * kPSMMetalObjectCounterRadius - 6.0); + if(countWidth < kPSMMetalCounterMinWidth) + countWidth = kPSMMetalCounterMinWidth; + + NSRect result; + result.size = NSMakeSize(countWidth, 2 * kPSMMetalObjectCounterRadius); // temp + result.origin.x = cellFrame.origin.x + cellFrame.size.width - MARGIN_X - result.size.width; + result.origin.y = cellFrame.origin.y + MARGIN_Y + 1.0; + + if(![[cell indicator] isHidden]) + result.origin.x -= kPSMTabBarIndicatorWidth + kPSMTabBarCellPadding; + + return result; +} + + +- (float)minimumWidthOfTabCell:(PSMTabBarCell *)cell +{ + float resultWidth = 0.0; + + // left margin + resultWidth = MARGIN_X; + + // close button? + if([cell hasCloseButton] && ![cell isCloseButtonSuppressed]) + resultWidth += [closeButton size].width + kPSMTabBarCellPadding; + + // icon? + if([cell hasIcon]) + resultWidth += kPSMTabBarIconWidth + kPSMTabBarCellPadding; + + // the label + resultWidth += kPSMMinimumTitleWidth; + + // object counter? + if([cell count] > 0) + resultWidth += [self objectCounterRectForTabCell:cell].size.width + kPSMTabBarCellPadding; + + // indicator? + if ([[cell indicator] isHidden] == NO) + resultWidth += kPSMTabBarCellPadding + kPSMTabBarIndicatorWidth; + + // right margin + resultWidth += MARGIN_X; + + return ceil(resultWidth); +} + +- (float)desiredWidthOfTabCell:(PSMTabBarCell *)cell +{ + float resultWidth = 0.0; + + // left margin + resultWidth = MARGIN_X; + + // close button? + if ([cell hasCloseButton] && ![cell isCloseButtonSuppressed]) + resultWidth += [closeButton size].width + kPSMTabBarCellPadding; + + // icon? + if([cell hasIcon]) + resultWidth += kPSMTabBarIconWidth + kPSMTabBarCellPadding; + + // the label + resultWidth += [[cell attributedStringValue] size].width; + + // object counter? + if([cell count] > 0) + resultWidth += [self objectCounterRectForTabCell:cell].size.width + kPSMTabBarCellPadding; + + // indicator? + if ([[cell indicator] isHidden] == NO) + resultWidth += kPSMTabBarCellPadding + kPSMTabBarIndicatorWidth; + + // right margin + resultWidth += MARGIN_X; + + return ceil(resultWidth); +} + +#pragma mark - +#pragma mark Cell Values + +- (NSAttributedString *)attributedObjectCountValueForTabCell:(PSMTabBarCell *)cell +{ + NSMutableAttributedString *attrStr; + NSFontManager *fm = [NSFontManager sharedFontManager]; + NSNumberFormatter *nf = [[[NSNumberFormatter alloc] init] autorelease]; + [nf setLocalizesFormat:YES]; + [nf setFormat:@"0"]; + [nf setHasThousandSeparators:YES]; + NSString *contents = [nf stringFromNumber:[NSNumber numberWithInt:[cell count]]]; + attrStr = [[[NSMutableAttributedString alloc] initWithString:contents] autorelease]; + NSRange range = NSMakeRange(0, [contents length]); + + // Add font attribute + [attrStr addAttribute:NSFontAttributeName value:[fm convertFont:[NSFont fontWithName:@"Helvetica" size:11.0] toHaveTrait:NSBoldFontMask] range:range]; + [attrStr addAttribute:NSForegroundColorAttributeName value:[[NSColor whiteColor] colorWithAlphaComponent:0.85] range:range]; + + return attrStr; +} + +- (NSAttributedString *)attributedStringValueForTabCell:(PSMTabBarCell *)cell +{ + NSMutableAttributedString *attrStr; + NSString *contents = [cell stringValue]; + attrStr = [[[NSMutableAttributedString alloc] initWithString:contents] autorelease]; + NSRange range = NSMakeRange(0, [contents length]); + + // Add font attribute + [attrStr addAttribute:NSFontAttributeName value:[NSFont systemFontOfSize:11.0] range:range]; + + PSMTabBarControl *bar = (PSMTabBarControl *)cell.controlView; + BOOL isKeyWindow = [bar.window isKeyWindow]; + + CGFloat textAlpha; + if ([cell state] == NSOnState) { + textAlpha = (isKeyWindow) ? 1.0f : 0.5f; + } else { + textAlpha = (isKeyWindow) ? 0.5f : 0.25f; + } + NSColor *textColor = [[NSColor textColor] colorWithAlphaComponent:textAlpha]; + + [attrStr addAttribute:NSForegroundColorAttributeName value:textColor range:range]; + + // Paragraph Style for Truncating Long Text + if (!truncatingTailParagraphStyle) { + truncatingTailParagraphStyle = [[[NSParagraphStyle defaultParagraphStyle] mutableCopy] retain]; + [truncatingTailParagraphStyle setLineBreakMode:NSLineBreakByTruncatingHead]; + [truncatingTailParagraphStyle setAlignment:NSCenterTextAlignment]; + } + [attrStr addAttribute:NSParagraphStyleAttributeName value:truncatingTailParagraphStyle range:range]; + + return attrStr; +} + +#pragma mark - +#pragma mark ---- drawing ---- + +- (void)drawTabCell:(PSMTabBarCell *)cell +{ + NSRect cellFrame = [cell frame]; + NSColor * lineColor = nil; + NSBezierPath* bezier = [NSBezierPath bezierPath]; + lineColor = [self borderColor]; + + if ([cell state] == NSOnState) { + // selected tab + NSRect aRect = NSMakeRect(cellFrame.origin.x, cellFrame.origin.y, cellFrame.size.width, cellFrame.size.height); + + PSMTabBarControl *bar = (PSMTabBarControl *)cell.controlView; + BOOL isKeyWindow = [bar.window isKeyWindow]; + + // background + YosemiteNSDrawWindowBackground(aRect, [self backgroundColor:isKeyWindow]); + + aRect.size.height -= 1.0f; + aRect.origin.y += 0.5f; + // frame + [lineColor set]; + [bezier moveToPoint:NSMakePoint(aRect.origin.x, aRect.origin.y)]; + [bezier lineToPoint:NSMakePoint(aRect.origin.x, aRect.origin.y+aRect.size.height)]; + [bezier lineToPoint:NSMakePoint(aRect.origin.x+aRect.size.width, aRect.origin.y+aRect.size.height)]; + [bezier lineToPoint:NSMakePoint(aRect.origin.x+aRect.size.width, aRect.origin.y)]; + [bezier lineToPoint:NSMakePoint(aRect.origin.x, aRect.origin.y)]; + [bezier stroke]; + } else { + + // unselected tab + NSRect aRect = NSMakeRect(cellFrame.origin.x, cellFrame.origin.y, cellFrame.size.width, cellFrame.size.height); + + aRect.origin.x += 0.5; + + [[NSColor colorWithCalibratedWhite:0.0 alpha:0.1] set]; + NSRectFillUsingOperation(aRect, NSCompositeSourceAtop); + + // frame + [lineColor set]; + [bezier moveToPoint:NSMakePoint(aRect.origin.x, aRect.origin.y)]; + [bezier lineToPoint:NSMakePoint(aRect.origin.x + aRect.size.width, aRect.origin.y)]; + if(!([cell tabState] & PSMTab_RightIsSelectedMask)){ + [bezier lineToPoint:NSMakePoint(aRect.origin.x + aRect.size.width, aRect.origin.y + aRect.size.height)]; + } + [bezier stroke]; + } + + [self drawInteriorWithTabCell:cell inView:[cell controlView]]; +} + + + +- (void)drawInteriorWithTabCell:(PSMTabBarCell *)cell inView:(NSView*)controlView +{ + NSRect cellFrame = [cell frame]; + float labelPosition = cellFrame.origin.x + MARGIN_X; + + // close button + if ([cell hasCloseButton] && ![cell isCloseButtonSuppressed]) { + NSSize closeButtonSize = NSZeroSize; + NSRect closeButtonRect = [cell closeButtonRectForFrame:cellFrame]; + NSImage *button = nil; + + if ([cell closeButtonOver]) button = closeButtonOver; + if ([cell closeButtonPressed]) button = closeButtonDown; + + closeButtonSize = [button size]; + [button drawInRect:closeButtonRect fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0 respectFlipped:YES hints:nil]; + } + + // object counter + if([cell count] > 0){ + [[NSColor colorWithCalibratedWhite:0.3 alpha:0.6] set]; + NSBezierPath *path = [NSBezierPath bezierPath]; + NSRect myRect = [self objectCounterRectForTabCell:cell]; + [path moveToPoint:NSMakePoint(myRect.origin.x + kPSMMetalObjectCounterRadius, myRect.origin.y)]; + [path lineToPoint:NSMakePoint(myRect.origin.x + myRect.size.width - kPSMMetalObjectCounterRadius, myRect.origin.y)]; + [path appendBezierPathWithArcWithCenter:NSMakePoint(myRect.origin.x + myRect.size.width - kPSMMetalObjectCounterRadius, myRect.origin.y + kPSMMetalObjectCounterRadius) radius:kPSMMetalObjectCounterRadius startAngle:270.0 endAngle:90.0]; + [path lineToPoint:NSMakePoint(myRect.origin.x + kPSMMetalObjectCounterRadius, myRect.origin.y + myRect.size.height)]; + [path appendBezierPathWithArcWithCenter:NSMakePoint(myRect.origin.x + kPSMMetalObjectCounterRadius, myRect.origin.y + kPSMMetalObjectCounterRadius) radius:kPSMMetalObjectCounterRadius startAngle:90.0 endAngle:270.0]; + [path fill]; + + // draw attributed string centered in area + NSRect counterStringRect; + NSAttributedString *counterString = [self attributedObjectCountValueForTabCell:cell]; + counterStringRect.size = [counterString size]; + counterStringRect.origin.x = myRect.origin.x + ((myRect.size.width - counterStringRect.size.width) / 2.0) + 0.25; + counterStringRect.origin.y = myRect.origin.y + ((myRect.size.height - counterStringRect.size.height) / 2.0) + 0.5; + [counterString drawInRect:counterStringRect]; + } + + // label rect + NSRect labelRect; + labelRect.origin.x = labelPosition; + labelRect.size.width = cellFrame.size.width - (labelRect.origin.x - cellFrame.origin.x) - kPSMTabBarCellPadding; + labelRect.size.height = cellFrame.size.height; + labelRect.origin.y = cellFrame.origin.y + MARGIN_Y + 1.0; + + if(![[cell indicator] isHidden]) + labelRect.size.width -= (kPSMTabBarIndicatorWidth + kPSMTabBarCellPadding); + + if([cell count] > 0) + labelRect.size.width -= ([self objectCounterRectForTabCell:cell].size.width + kPSMTabBarCellPadding); + + // label + [[cell attributedStringValue] drawInRect:labelRect]; +} + +- (void)drawTabBar:(PSMTabBarControl *)bar inRect:(NSRect)rect +{ + BOOL isKeyWindow = [bar.window isKeyWindow]; + YosemiteNSDrawWindowBackground(rect, [self backgroundColor:isKeyWindow]); + + [[NSColor colorWithCalibratedWhite:0.0 alpha:0.0] set]; + NSRectFillUsingOperation(rect, NSCompositeSourceAtop); + [[self borderColor] set]; + [NSBezierPath strokeLineFromPoint:NSMakePoint(rect.origin.x,rect.origin.y+0.5) toPoint:NSMakePoint(rect.origin.x+rect.size.width,rect.origin.y+0.5)]; + [NSBezierPath strokeLineFromPoint:NSMakePoint(rect.origin.x,rect.origin.y+rect.size.height-0.5) toPoint:NSMakePoint(rect.origin.x+rect.size.width,rect.origin.y+rect.size.height-0.5)]; + + // no tab view == not connected + if(![bar tabView]){ + NSRect labelRect = rect; + labelRect.size.height -= 4.0; + labelRect.origin.y += 4.0; + NSMutableAttributedString *attrStr; + NSString *contents = @"PSMTabBarControl"; + attrStr = [[[NSMutableAttributedString alloc] initWithString:contents] autorelease]; + NSRange range = NSMakeRange(0, [contents length]); + [attrStr addAttribute:NSFontAttributeName value:[NSFont systemFontOfSize:11.0] range:range]; + if (!centeredParagraphStyle) { + centeredParagraphStyle = [[[NSParagraphStyle defaultParagraphStyle] mutableCopy] retain]; + [centeredParagraphStyle setAlignment:NSCenterTextAlignment]; + } + [attrStr addAttribute:NSParagraphStyleAttributeName value:centeredParagraphStyle range:range]; + [attrStr drawInRect:labelRect]; + return; + } + + // draw cells + NSEnumerator *e = [[bar cells] objectEnumerator]; + PSMTabBarCell *cell; + while(cell = [e nextObject]){ + if(![cell isInOverflowMenu]){ + [cell drawWithFrame:[cell frame] inView:bar]; + } + } +} + +#pragma mark - +#pragma mark Archiving + +- (void)encodeWithCoder:(NSCoder *)aCoder +{ + if ([aCoder allowsKeyedCoding]) { + [aCoder encodeObject:closeButton forKey:@"metalCloseButton"]; + [aCoder encodeObject:closeButtonDown forKey:@"metalCloseButtonDown"]; + [aCoder encodeObject:closeButtonOver forKey:@"metalCloseButtonOver"]; + [aCoder encodeObject:_addTabButtonImage forKey:@"addTabButtonImage"]; + [aCoder encodeObject:_addTabButtonPressedImage forKey:@"addTabButtonPressedImage"]; + [aCoder encodeObject:_addTabButtonRolloverImage forKey:@"addTabButtonRolloverImage"]; + } +} + +- (id)initWithCoder:(NSCoder *)aDecoder +{ + if ([aDecoder allowsKeyedCoding]) { + closeButton = [[aDecoder decodeObjectForKey:@"metalCloseButton"] retain]; + closeButtonDown = [[aDecoder decodeObjectForKey:@"metalCloseButtonDown"] retain]; + closeButtonOver = [[aDecoder decodeObjectForKey:@"metalCloseButtonOver"] retain]; + _addTabButtonImage = [[aDecoder decodeObjectForKey:@"addTabButtonImage"] retain]; + _addTabButtonPressedImage = [[aDecoder decodeObjectForKey:@"addTabButtonPressedImage"] retain]; + _addTabButtonRolloverImage = [[aDecoder decodeObjectForKey:@"addTabButtonRolloverImage"] retain]; + } + + return self; +} + +@end