diff --git a/src/MacVim/MMFullScreenWindow.m b/src/MacVim/MMFullScreenWindow.m index 658c24ac92..c41ba00998 100644 --- a/src/MacVim/MMFullScreenWindow.m +++ b/src/MacVim/MMFullScreenWindow.m @@ -55,7 +55,7 @@ - (void)resizeVimView; @implementation MMFullScreenWindow -- (MMFullScreenWindow *)initWithWindow:(NSWindow *)t view:(MMVimView *)v +- (MMFullScreenWindow *)initWithWindow:(NSWindow *)t view:(MMVimView *)v backgroundColor:(NSColor *)back { NSScreen* screen = [t screen]; @@ -65,7 +65,7 @@ - (MMFullScreenWindow *)initWithWindow:(NSWindow *)t view:(MMVimView *)v // you can't change the style of an existing window in cocoa. create a new // window and move the MMTextView into it. // (another way would be to make the existing window large enough that the - // title bar is off screen. but that doesn't work with multiple screens). + // title bar is off screen. but that doesn't work with multiple screens). self = [super initWithContentRect:[screen frame] styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered @@ -74,7 +74,7 @@ - (MMFullScreenWindow *)initWithWindow:(NSWindow *)t view:(MMVimView *)v // we want the content rect to be relative to // the main screen (ie, pass nil for screen). screen:nil]; - + if (self == nil) return nil; @@ -150,12 +150,20 @@ - (void)enterFullScreen // fool delegate id delegate = [target delegate]; [target setDelegate:nil]; - + // make target's window controller believe that it's now controlling us [[target windowController] setWindow:self]; + NSString *style; + +#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_10 + style = @"Yosemite"; +#else + style = @"Unified"; +#endif + oldTabBarStyle = [[view tabBarControl] styleName]; - [[view tabBarControl] setStyleNamed:@"Unified"]; + [[view tabBarControl] setStyleNamed:style]; // add text view oldPosition = [view frame].origin; @@ -163,7 +171,7 @@ - (void)enterFullScreen [view removeFromSuperviewWithoutNeedingDisplay]; [[self contentView] addSubview:view]; [self setInitialFirstResponder:[view textView]]; - + // NOTE: Calling setTitle:nil causes an exception to be raised (and it is // possible that 'target' has no title when we get here). if ([target title]) { @@ -177,7 +185,7 @@ - (void)enterFullScreen [self setOpaque:[target isOpaque]]; // don't set this sooner, so we don't get an additional - // focus gained message + // focus gained message [self setDelegate:delegate]; // Store view dimension used before entering full-screen, then resize the @@ -265,7 +273,7 @@ - (void)leaveFullScreen // fix delegate id delegate = [self delegate]; [self setDelegate:nil]; - + // move text view back to original window, hide fullScreen window, // show original window // do this _after_ resetting delegate and window controller, so the @@ -317,13 +325,13 @@ - (void)leaveFullScreen // sooner [target setDelegate:delegate]; - // fade back in + // fade back in if (didBlend) { CGDisplayFade(token, .25, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, .0, .0, .0, false); CGReleaseDisplayFadeReservation(token); } - + [self autorelease]; // Balance the above retain state = LeftFullScreen; diff --git a/src/MacVim/MMVimView.m b/src/MacVim/MMVimView.m index f2fb979f7c..5d40b63340 100644 --- a/src/MacVim/MMVimView.m +++ b/src/MacVim/MMVimView.m @@ -85,7 +85,7 @@ - (MMVimView *)initWithFrame:(NSRect)frame { if (!(self = [super initWithFrame:frame])) return nil; - + vimController = controller; scrollbars = [[NSMutableArray alloc] init]; @@ -122,15 +122,23 @@ - (MMVimView *)initWithFrame:(NSRect)frame [textView setAutoresizingMask:NSViewNotSizable]; [self addSubview:textView]; - + // Create the tab view (which is never visible, but the tab bar control // needs it to function). tabView = [[NSTabView alloc] initWithFrame:NSZeroRect]; // 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 } }; + + CGFloat tabBarHeight; +#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_10 + tabBarHeight = 25; +#else + tabBarHeight = 22; +#endif + + NSRect tabFrame = { { 0, frame.size.height - tabBarHeight }, + { frame.size.width, tabBarHeight } }; tabBarControl = [[PSMTabBarControl alloc] initWithFrame:tabFrame]; [tabView setDelegate:tabBarControl]; @@ -139,10 +147,17 @@ - (MMVimView *)initWithFrame:(NSRect)frame [tabBarControl setDelegate:self]; [tabBarControl setHidden:YES]; +#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_10 + [tabBarControl setStyleNamed:@"Yosemite"]; + [tabBarControl setCellMinWidth:120]; + [tabBarControl setCellMaxWidth:[[NSScreen mainScreen] frame].size.width]; + [tabBarControl setCellOptimumWidth:[[NSScreen mainScreen] frame].size.width]; +#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]; @@ -152,9 +167,9 @@ - (MMVimView *)initWithFrame:(NSRect)frame [NSArray arrayWithObject:NSFilenamesPboardType]]; [tabBarControl setAutoresizingMask:NSViewWidthSizable|NSViewMinYMargin]; - + //[tabBarControl setPartnerView:textView]; - + // tab bar resizing only works if awakeFromNib is called (that's where // the NSViewFrameDidChangeNotification callback is installed). Sounds like // a PSMTabBarControl bug, let's live with it for now. @@ -247,7 +262,7 @@ - (PSMTabBarControl *)tabBarControl - (void)cleanup { vimController = nil; - + // NOTE! There is a bug in PSMTabBarControl in that it retains the delegate // so reset the delegate here, otherwise the delegate may never get // released. diff --git a/src/MacVim/MMWindowController.m b/src/MacVim/MMWindowController.m index b6c6786bf1..ed2d345321 100644 --- a/src/MacVim/MMWindowController.m +++ b/src/MacVim/MMWindowController.m @@ -58,7 +58,7 @@ * * The window is always kept centered and resizing works more or less the same * way as in windowed mode. - * + * */ #import "MMAppController.h" @@ -170,7 +170,7 @@ - (id)initWithVimController:(MMVimController *)controller [win setDelegate:self]; [win setInitialFirstResponder:[vimView textView]]; - + if ([win styleMask] & NSTexturedBackgroundWindowMask) { // On Leopard, we want to have a textured window to have nice // looking tabs. But the textured window look implies rounded @@ -479,7 +479,7 @@ - (void)createScrollbarWithIdentifier:(int32_t)ident type:(int)type - (BOOL)destroyScrollbarWithIdentifier:(int32_t)ident { - BOOL scrollbarHidden = [vimView destroyScrollbarWithIdentifier:ident]; + BOOL scrollbarHidden = [vimView destroyScrollbarWithIdentifier:ident]; shouldResizeVimView = shouldResizeVimView || scrollbarHidden; shouldMaximizeWindow = shouldMaximizeWindow || scrollbarHidden; @@ -1135,7 +1135,14 @@ - (void)window:(NSWindow *)window [[window animator] setAlphaValue:0]; } completionHandler:^{ [window setStyleMask:([window styleMask] | NSFullScreenWindowMask)]; - [[vimView tabBarControl] setStyleNamed:@"Unified"]; + NSString *style; +#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_10 + style = @"Yosemite"; +#else + style = @"Unified"; +#endif + + [[vimView tabBarControl] setStyleNamed:style]; [self updateTablineSeparator]; [self maximizeWindow:fullScreenOptions]; @@ -1179,7 +1186,15 @@ - (void)windowDidFailToEnterFullScreen:(NSWindow *)window fullScreenEnabled = NO; [window setAlphaValue:1]; [window setStyleMask:([window styleMask] & ~NSFullScreenWindowMask)]; - [[vimView tabBarControl] setStyleNamed:@"Metal"]; + + NSString *tabStyle; +#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_10 + tabStyle = @"Yosemite"; +#else + tabStyle = @"Metal"; +#endif + + [[vimView tabBarControl] setStyleNamed:tabStyle]; [self updateTablineSeparator]; [window setFrame:preFullScreenFrame display:YES]; } @@ -1208,8 +1223,15 @@ - (void)window:(NSWindow *)window [context setDuration:0.5*duration]; [[window animator] setAlphaValue:0]; } completionHandler:^{ + NSString *tabStyle; +#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_10 + tabStyle = @"Yosemite"; +#else + tabStyle = @"Metal"; +#endif + NSLog(@"tabStyle: %@", tabStyle); [window setStyleMask:([window styleMask] & ~NSFullScreenWindowMask)]; - [[vimView tabBarControl] setStyleNamed:@"Metal"]; + [[vimView tabBarControl] setStyleNamed:tabStyle]; [self updateTablineSeparator]; [window setFrame:preFullScreenFrame display:YES]; @@ -1245,7 +1267,13 @@ - (void)windowDidFailToExitFullScreen:(NSWindow *)window fullScreenEnabled = YES; [window setAlphaValue:1]; [window setStyleMask:([window styleMask] | NSFullScreenWindowMask)]; - [[vimView tabBarControl] setStyleNamed:@"Unified"]; + NSString *style; +#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_10 + style = @"Yosemite"; +#else + style = @"Unified"; +#endif + [[vimView tabBarControl] setStyleNamed:style]; [self updateTablineSeparator]; [self maximizeWindow:fullScreenOptions]; } @@ -1397,7 +1425,7 @@ - (NSTabViewItem *)addNewTabViewItem } - (BOOL)askBackendForStarRegister:(NSPasteboard *)pb -{ +{ // TODO: Can this be done with evaluateExpression: instead? BOOL reply = NO; id backendProxy = [vimController backendProxy]; @@ -1479,7 +1507,7 @@ - (void)doFindNext:(BOOL)next input = [NSString stringWithFormat:@":let @/='%@'%c", query, next ? 'n' : 'N']; } else { - input = next ? @"n" : @"N"; + input = next ? @"n" : @"N"; } [vimController addVimInput:input]; diff --git a/src/MacVim/PSMTabBarControl/PSMTabBarControl.xcodeproj/project.pbxproj b/src/MacVim/PSMTabBarControl/PSMTabBarControl.xcodeproj/project.pbxproj index cc503a2624..4b75923644 100644 --- a/src/MacVim/PSMTabBarControl/PSMTabBarControl.xcodeproj/project.pbxproj +++ b/src/MacVim/PSMTabBarControl/PSMTabBarControl.xcodeproj/project.pbxproj @@ -74,6 +74,10 @@ A2D98B0B0A2B432C0064C6F8 /* PSMUnifiedTabStyle.m in Sources */ = {isa = PBXBuildFile; fileRef = A2D98B080A2B432C0064C6F8 /* PSMUnifiedTabStyle.m */; }; A2D98B120A2B43FA0064C6F8 /* NSBezierPath_AMShading.h in Headers */ = {isa = PBXBuildFile; fileRef = A2D98B0F0A2B43FA0064C6F8 /* NSBezierPath_AMShading.h */; }; A2D98B130A2B43FA0064C6F8 /* NSBezierPath_AMShading.m in Sources */ = {isa = PBXBuildFile; fileRef = A2D98B100A2B43FA0064C6F8 /* NSBezierPath_AMShading.m */; }; + BD13A64219AB98E900C641C3 /* PSMYosemiteTabStyle.h in Headers */ = {isa = PBXBuildFile; fileRef = BD13A64019AB98E900C641C3 /* PSMYosemiteTabStyle.h */; }; + BD13A64319AB98E900C641C3 /* PSMYosemiteTabStyle.m in Sources */ = {isa = PBXBuildFile; fileRef = BD13A64119AB98E900C641C3 /* PSMYosemiteTabStyle.m */; }; + BD4C36AB19ABC9E600B38C9D /* TabNewYosemite.png in Resources */ = {isa = PBXBuildFile; fileRef = BD4C36A919ABC9E600B38C9D /* TabNewYosemite.png */; }; + BD4C36AC19ABC9E600B38C9D /* TabNewYosemite@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = BD4C36AA19ABC9E600B38C9D /* TabNewYosemite@2x.png */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -172,6 +176,10 @@ A2D98B080A2B432C0064C6F8 /* PSMUnifiedTabStyle.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; name = PSMUnifiedTabStyle.m; path = source/PSMUnifiedTabStyle.m; sourceTree = ""; }; A2D98B0F0A2B43FA0064C6F8 /* NSBezierPath_AMShading.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = NSBezierPath_AMShading.h; path = source/NSBezierPath_AMShading.h; sourceTree = ""; }; A2D98B100A2B43FA0064C6F8 /* NSBezierPath_AMShading.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; name = NSBezierPath_AMShading.m; path = source/NSBezierPath_AMShading.m; sourceTree = ""; }; + BD13A64019AB98E900C641C3 /* PSMYosemiteTabStyle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PSMYosemiteTabStyle.h; path = source/PSMYosemiteTabStyle.h; sourceTree = ""; }; + BD13A64119AB98E900C641C3 /* PSMYosemiteTabStyle.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = PSMYosemiteTabStyle.m; path = source/PSMYosemiteTabStyle.m; sourceTree = ""; }; + BD4C36A919ABC9E600B38C9D /* TabNewYosemite.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = TabNewYosemite.png; path = images/TabNewYosemite.png; sourceTree = ""; }; + BD4C36AA19ABC9E600B38C9D /* TabNewYosemite@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "TabNewYosemite@2x.png"; path = "images/TabNewYosemite@2x.png"; sourceTree = ""; }; DD92D38A0106425D02CA0E72 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = ""; }; /* End PBXFileReference section */ @@ -304,27 +312,29 @@ 54D33B2C06778E4400C9C163 /* Framework */ = { isa = PBXGroup; children = ( - 0259C57AFE90428111CA0C5A /* PSMTabBarControl.h */, - 0259C576FE90428111CA0C5A /* PSMTabBarControl.m */, - A251BE830959A1B90058BC7F /* PSMTabBarCell.h */, - A251BE840959A1B90058BC7F /* PSMTabBarCell.m */, - A2D32EDA09A634C900EC8662 /* PSMTabStyle.h */, + A2D98B0F0A2B43FA0064C6F8 /* NSBezierPath_AMShading.h */, + A2D98B100A2B43FA0064C6F8 /* NSBezierPath_AMShading.m */, A2D32EE609A6399300EC8662 /* PSMAquaTabStyle.h */, A2D32EE709A6399300EC8662 /* PSMAquaTabStyle.m */, A2D32EFE09A63D7A00EC8662 /* PSMMetalTabStyle.h */, A2D32EFF09A63D7A00EC8662 /* PSMMetalTabStyle.m */, - A2D98B070A2B432C0064C6F8 /* PSMUnifiedTabStyle.h */, - A2D98B080A2B432C0064C6F8 /* PSMUnifiedTabStyle.m */, - A268EA5F09A9831800E082AA /* PSMRolloverButton.h */, - A268EA6009A9831800E082AA /* PSMRolloverButton.m */, A251BE810959A1B90058BC7F /* PSMOverflowPopUpButton.h */, A251BE820959A1B90058BC7F /* PSMOverflowPopUpButton.m */, A2129BAF09AEB58F00724E6C /* PSMProgressIndicator.h */, A2129BB009AEB58F00724E6C /* PSMProgressIndicator.m */, + A268EA5F09A9831800E082AA /* PSMRolloverButton.h */, + A268EA6009A9831800E082AA /* PSMRolloverButton.m */, + A251BE830959A1B90058BC7F /* PSMTabBarCell.h */, + A251BE840959A1B90058BC7F /* PSMTabBarCell.m */, + 0259C57AFE90428111CA0C5A /* PSMTabBarControl.h */, + 0259C576FE90428111CA0C5A /* PSMTabBarControl.m */, A2082A8D09EAEB33009AC8BE /* PSMTabDragAssistant.h */, A2082A8E09EAEB33009AC8BE /* PSMTabDragAssistant.m */, - A2D98B0F0A2B43FA0064C6F8 /* NSBezierPath_AMShading.h */, - A2D98B100A2B43FA0064C6F8 /* NSBezierPath_AMShading.m */, + A2D32EDA09A634C900EC8662 /* PSMTabStyle.h */, + A2D98B070A2B432C0064C6F8 /* PSMUnifiedTabStyle.h */, + A2D98B080A2B432C0064C6F8 /* PSMUnifiedTabStyle.m */, + BD13A64019AB98E900C641C3 /* PSMYosemiteTabStyle.h */, + BD13A64119AB98E900C641C3 /* PSMYosemiteTabStyle.m */, ); name = Framework; sourceTree = ""; @@ -354,6 +364,8 @@ A251BE8E0959A21A0058BC7F /* Images */ = { isa = PBXGroup; children = ( + BD4C36A919ABC9E600B38C9D /* TabNewYosemite.png */, + BD4C36AA19ABC9E600B38C9D /* TabNewYosemite@2x.png */, A2C0D99309AF870000ED379C /* pi.png */, A2072B5C09AC1FA500304BCB /* Warning.png */, A2072A2409ABD88600304BCB /* Folder.tif */, @@ -401,6 +413,7 @@ files = ( 546DEAF2067F630E0098DCC4 /* PSMTabBarControl.h in Headers */, A251BE850959A1B90058BC7F /* PSMOverflowPopUpButton.h in Headers */, + BD13A64219AB98E900C641C3 /* PSMYosemiteTabStyle.h in Headers */, A251BE870959A1B90058BC7F /* PSMTabBarCell.h in Headers */, A2D32EDC09A634C900EC8662 /* PSMTabStyle.h in Headers */, A2D32EE809A6399300EC8662 /* PSMAquaTabStyle.h in Headers */, @@ -439,6 +452,8 @@ /* Begin PBXProject section */ 0259C573FE90428111CA0C5A /* Project object */ = { isa = PBXProject; + attributes = { + }; buildConfigurationList = C056398B08A954F8003078D8 /* Build configuration list for PBXProject "PSMTabBarControl" */; compatibilityVersion = "Xcode 2.4"; developmentRegion = English; @@ -482,8 +497,10 @@ 52A57C0F15BBA230003EC59C /* TabClose_Front.png in Resources */, 52A57C1015BBA230003EC59C /* TabClose_Front_Pressed.png in Resources */, 52A57C1115BBA230003EC59C /* TabClose_Front_Rollover.png in Resources */, + BD4C36AB19ABC9E600B38C9D /* TabNewYosemite.png in Resources */, 523897F415BDA9AC00498A53 /* TabClose_Front_Pressed@2x.png in Resources */, 523897F515BDA9AC00498A53 /* TabClose_Front_Rollover@2x.png in Resources */, + BD4C36AC19ABC9E600B38C9D /* TabNewYosemite@2x.png in Resources */, 523897F615BDA9AC00498A53 /* TabClose_Front@2x.png in Resources */, 523897F715BDA9AC00498A53 /* TabNewMetal@2x.png in Resources */, 523897F815BDA9AC00498A53 /* TabNewMetalPressed@2x.png in Resources */, @@ -509,6 +526,7 @@ A2D32F0109A63D7A00EC8662 /* PSMMetalTabStyle.m in Sources */, A268EA6309A9831800E082AA /* PSMRolloverButton.m in Sources */, A2129BB309AEB58F00724E6C /* PSMProgressIndicator.m in Sources */, + BD13A64319AB98E900C641C3 /* PSMYosemiteTabStyle.m in Sources */, A2082A9109EAEB34009AC8BE /* PSMTabDragAssistant.m in Sources */, A2D98B0B0A2B432C0064C6F8 /* PSMUnifiedTabStyle.m in Sources */, A2D98B130A2B43FA0064C6F8 /* NSBezierPath_AMShading.m in Sources */, diff --git a/src/MacVim/PSMTabBarControl/PSMTabBarControl.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/src/MacVim/PSMTabBarControl/PSMTabBarControl.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000000..67a153148e --- /dev/null +++ b/src/MacVim/PSMTabBarControl/PSMTabBarControl.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + 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/PSMTabBarControl.h b/src/MacVim/PSMTabBarControl/source/PSMTabBarControl.h index f797804afe..ddd07651c1 100644 --- a/src/MacVim/PSMTabBarControl/source/PSMTabBarControl.h +++ b/src/MacVim/PSMTabBarControl/source/PSMTabBarControl.h @@ -24,10 +24,16 @@ typedef unsigned int NSUInteger; # define NSINTEGER_DEFINED 1 #endif +#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_10 +#define kPSMTabBarControlHeight 25 +#define MARGIN_Y 5 +#else #define kPSMTabBarControlHeight 22 +#define MARGIN_Y 3 +#endif // internal cell border #define MARGIN_X 6 -#define MARGIN_Y 3 + // 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 05ed3b4700..5c72e400be 100644 --- a/src/MacVim/PSMTabBarControl/source/PSMTabBarControl.m +++ b/src/MacVim/PSMTabBarControl/source/PSMTabBarControl.m @@ -14,6 +14,7 @@ #import "PSMMetalTabStyle.h" #import "PSMAquaTabStyle.h" #import "PSMUnifiedTabStyle.h" +#import "PSMYosemiteTabStyle.h" #import "PSMTabDragAssistant.h" @interface PSMTabBarControl (Private) @@ -260,8 +261,9 @@ - (void)setStyleNamed:(NSString *)name } else if ([name isEqualToString:@"Unified"]){ style = [[PSMUnifiedTabStyle alloc] init]; - } - else { + } else if ([name isEqualToString:@"Yosemite"]) { + style = [[PSMYosemiteTabStyle alloc] init]; + } else { style = [[PSMMetalTabStyle alloc] init]; } 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..370425cad8 --- /dev/null +++ b/src/MacVim/PSMTabBarControl/source/PSMYosemiteTabStyle.m @@ -0,0 +1,501 @@ +// +// 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 * closeButton = nil; + + closeButton = nil; + if ([cell closeButtonOver]) closeButton = closeButtonOver; + if ([cell closeButtonPressed]) closeButton = closeButtonDown; + + closeButtonSize = [closeButton size]; + [closeButton setFlipped:YES]; + [closeButton drawAtPoint:closeButtonRect.origin fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0]; + + } + + // 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