Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added notification for when a tab is selected #33

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
570 changes: 413 additions & 157 deletions MMTabBarView Demo/MMTabBarView Demo/en.lproj/DemoWindow.xib

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions MMTabBarView/MMTabBarView.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,7 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 0634F0C8160A1F8100A6C86A /* MMTabBarViewFramework-Debug.xcconfig */;
buildSettings = {
CODE_SIGN_IDENTITY = "Developer ID Application: Michael LaMorte (2Z7Z6V9P5M)";
COMBINE_HIDPI_IMAGES = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
Expand All @@ -967,6 +968,7 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 0634F0C9160A1F8100A6C86A /* MMTabBarViewFramework-Release.xcconfig */;
buildSettings = {
CODE_SIGN_IDENTITY = "Developer ID Application: Michael LaMorte (2Z7Z6V9P5M)";
COMBINE_HIDPI_IMAGES = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
Expand Down
30 changes: 14 additions & 16 deletions MMTabBarView/MMTabBarView/MMAttachedTabBarButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,30 @@

@protocol MMTabStyle;

@interface MMAttachedTabBarButton : MMTabBarButton {
@interface MMAttachedTabBarButton : MMTabBarButton

@private
NSTabViewItem *_tabViewItem;
BOOL _isInAnimatedSlide;
BOOL _isInDraggedSlide;
}
// designated initializer
- (instancetype)initWithFrame:(NSRect)frame tabViewItem:(NSTabViewItem *)anItem NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithCoder:(NSCoder *)coder NS_DESIGNATED_INITIALIZER;

- (instancetype)initWithFrame:(NSRect)frame NS_UNAVAILABLE;

// overidden accessors (casting)
@property (strong) MMAttachedTabBarButtonCell *cell;

#pragma mark Properties

@property (retain) NSTabViewItem *tabViewItem;
@property (strong) NSTabViewItem *tabViewItem;
@property (assign) NSRect slidingFrame;
@property (readonly) BOOL isInAnimatedSlide;
@property (assign) BOOL isInDraggedSlide;
@property (readonly) BOOL isSliding;
@property (assign) BOOL isOverflowButton;

// designated initializer
- (id)initWithFrame:(NSRect)frame tabViewItem:(NSTabViewItem *)anItem;

// overidden accessors (casting)
- (MMAttachedTabBarButtonCell *)cell;
- (void)setCell:(MMAttachedTabBarButtonCell *)aCell;

#pragma mark Drag Support

- (NSRect)draggingRect;
- (NSImage *)dragImage;
@property (readonly) NSRect draggingRect;
@property (readonly) NSImage *dragImage;

#pragma mark -
#pragma mark Animation Support
Expand Down
48 changes: 33 additions & 15 deletions MMTabBarView/MMTabBarView/MMAttachedTabBarButton.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#import "MMTabStyle.h"
#import "NSView+MMTabBarViewExtensions.h"

#define MMTabBarViewDidSelectTab @"MMTabBarViewDidSelectTab"

@interface MMAttachedTabBarButton (/*Private*/)

- (MMAttachedTabBarButton *)_selectedAttachedTabBarButton;
Expand All @@ -37,32 +39,25 @@ + (Class)cellClass {
return [MMAttachedTabBarButtonCell class];
}

- (id)initWithFrame:(NSRect)frame tabViewItem:(NSTabViewItem *)anItem {
- (instancetype)initWithFrame:(NSRect)frame tabViewItem:(NSTabViewItem *)anItem {

self = [super initWithFrame:frame];
if (self) {
_tabViewItem = [anItem retain];
_tabViewItem = anItem;
_isInAnimatedSlide = NO;
_isInDraggedSlide = NO;
}

return self;
}

- (id)initWithFrame:(NSRect)frame {
- (instancetype)initWithFrame:(NSRect)frame {

NSAssert(FALSE,@"please use designated initializer -initWithFrame:tabViewItem:");

[self release];
return nil;
}

- (void)dealloc
{
[_tabViewItem release], _tabViewItem = nil;
[super dealloc];
}

- (void)drawRect:(NSRect)dirtyRect {
[super drawRect:dirtyRect];
}
Expand All @@ -84,7 +79,7 @@ -(void)viewWillDraw {
}

#pragma mark -
#pragma mark Accessors
#pragma mark Properties

- (NSRect)slidingFrame {
@synchronized(self) {
Expand Down Expand Up @@ -166,6 +161,10 @@ - (void)mouseDown:(NSEvent *)theEvent {
if ([tabBarView shouldStartDraggingAttachedTabBarButton:self withMouseDownEvent:theEvent]) {
[tabBarView startDraggingAttachedTabBarButton:self withMouseDownEvent:theEvent];
}

[[NSNotificationCenter defaultCenter] postNotificationName:MMTabBarViewDidSelectTab
object:self];

}

- (void)mouseUp:(NSEvent *)theEvent {
Expand Down Expand Up @@ -215,11 +214,11 @@ - (NSImage *)dragImage {

[tabBarView lockFocus];
[tabBarView display]; // forces update to ensure that we get current state
NSBitmapImageRep *rep = [[[NSBitmapImageRep alloc] initWithFocusedViewRect:draggingRect] autorelease];
NSBitmapImageRep *rep = [[NSBitmapImageRep alloc] initWithFocusedViewRect:draggingRect];
[tabBarView unlockFocus];
NSImage *image = [[[NSImage alloc] initWithSize:[rep size]] autorelease];
NSImage *image = [[NSImage alloc] initWithSize:[rep size]];
[image addRepresentation:rep];
NSImage *returnImage = [[[NSImage alloc] initWithSize:[rep size]] autorelease];
NSImage *returnImage = [[NSImage alloc] initWithSize:[rep size]];
[returnImage lockFocus];
[image drawAtPoint:NSMakePoint(0.0, 0.0) fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];
[returnImage unlockFocus];
Expand All @@ -229,7 +228,6 @@ - (NSImage *)dragImage {
NSPoint indicatorPoint = NSMakePoint([self frame].size.width - MARGIN_X - kMMTabBarIndicatorWidth, MARGIN_Y);
[pi drawAtPoint:indicatorPoint fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];
[returnImage unlockFocus];
[pi release];
}
return returnImage;
}
Expand All @@ -245,6 +243,26 @@ - (void)slideAnimationDidEnd {
_isInAnimatedSlide = NO;
}

#pragma mark -
#pragma mark NSCoding

- (instancetype)initWithCoder:(NSCoder *)coder {

self = [super initWithCoder:coder];
if (self) {
_tabViewItem = nil;
_isInAnimatedSlide = NO;
_isInDraggedSlide = NO;
}

return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder
{
[super encodeWithCoder:aCoder];
}

#pragma mark -
#pragma mark Private Methods

Expand Down
11 changes: 3 additions & 8 deletions MMTabBarView/MMTabBarView/MMAttachedTabBarButtonCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,13 @@
//

#import "MMTabBarButtonCell.h"
#import "MMTabBarView.h"

@class MMAttachedTabBarButton;
#import "MMAttachedTabBarButton.h"

@interface MMAttachedTabBarButtonCell : MMTabBarButtonCell {

BOOL _isOverflowButton;
}
@interface MMAttachedTabBarButtonCell : MMTabBarButtonCell

@property (assign) BOOL isOverflowButton;

- (MMAttachedTabBarButton *)controlView;
- (void)setControlView:(MMAttachedTabBarButton *)aView;
@property (assign) MMAttachedTabBarButton *controlView;

@end
13 changes: 5 additions & 8 deletions MMTabBarView/MMTabBarView/MMAttachedTabBarButtonCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,15 @@

@implementation MMAttachedTabBarButtonCell

@synthesize isOverflowButton = _isOverflowButton;

- (id)init {
- (instancetype)init {
if ((self = [super init])) {
_isOverflowButton = NO;
}
return self;
}

- (void)dealloc {
[super dealloc];
}
#pragma mark -
#pragma mark Properties

- (MMAttachedTabBarButton *)controlView {
return (MMAttachedTabBarButton *)[super controlView];
Expand All @@ -36,7 +33,7 @@ - (void)setControlView:(MMAttachedTabBarButton *)aView {
#pragma mark -
#pragma mark NSCopying

- (id)copyWithZone:(NSZone *)zone {
- (instancetype)copyWithZone:(NSZone *)zone {

MMAttachedTabBarButtonCell *cellCopy = [super copyWithZone:zone];
if (cellCopy) {
Expand All @@ -57,7 +54,7 @@ - (void)encodeWithCoder:(NSCoder *)aCoder {
}
}

- (id)initWithCoder:(NSCoder *)aDecoder {
- (instancetype)initWithCoder:(NSCoder *)aDecoder {
if ((self = [super initWithCoder:aDecoder])) {
if ([aDecoder allowsKeyedCoding]) {

Expand Down
23 changes: 9 additions & 14 deletions MMTabBarView/MMTabBarView/MMOverflowPopUpButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,16 @@

typedef void (^MMCellBezelDrawingBlock)(NSCell *cell, NSRect frame, NSView *controlView);

@interface MMOverflowPopUpButton : NSPopUpButton {
@interface MMOverflowPopUpButton : NSPopUpButton

BOOL _isAnimating; // pulsating animation of image and second image
}
/**
* Second image
*/
@property (strong) NSImage *secondImage;

// accessors
- (NSImage *)secondImage;
- (void)setSecondImage:(NSImage *)anImage;

// archiving
- (void)encodeWithCoder:(NSCoder *)aCoder;
- (id)initWithCoder:(NSCoder *)aDecoder;

// bezel drawing
- (MMCellBezelDrawingBlock)bezelDrawingBlock;
- (void)setBezelDrawingBlock:(MMCellBezelDrawingBlock)aBlock;
/**
* Block to be used for drawing the bezel
*/
@property (copy) MMCellBezelDrawingBlock bezelDrawingBlock;

@end
25 changes: 4 additions & 21 deletions MMTabBarView/MMTabBarView/MMOverflowPopUpButton.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,11 @@
return image; \
}

@interface MMOverflowPopUpButton (/*Private*/)
@interface MMOverflowPopUpButton ()

@property (assign) CGFloat secondImageAlpha;

- (BOOL)isAnimating;
- (void)setIsAnimating:(BOOL)newState;

- (void)_startCellAnimationIfNeeded;
- (void)_startCellAnimation;
- (void)_stopCellAnimationIfNeeded;
- (void)_stopCellAnimation;
@property (assign) BOOL isAnimating; // pulsating animation of image and second image

@end

Expand All @@ -48,7 +42,7 @@ + (Class)cellClass {
return [MMOverflowPopUpButtonCell class];
}

- (id)initWithFrame:(NSRect)frameRect pullsDown:(BOOL)flag {
- (instancetype)initWithFrame:(NSRect)frameRect pullsDown:(BOOL)flag {
if (self = [super initWithFrame:frameRect pullsDown:YES]) {

_isAnimating = NO;
Expand All @@ -67,9 +61,6 @@ - (id)initWithFrame:(NSRect)frameRect pullsDown:(BOOL)flag {
return self;
}

- (void)dealloc {
[super dealloc];
}

- (void)viewWillMoveToSuperview:(NSView *)newSuperview {
[super viewWillMoveToSuperview:newSuperview];
Expand Down Expand Up @@ -194,7 +185,7 @@ - (void)encodeWithCoder:(NSCoder *)aCoder {
[super encodeWithCoder:aCoder];
}

- (id)initWithCoder:(NSCoder *)aDecoder {
- (instancetype)initWithCoder:(NSCoder *)aDecoder {
if ((self = [super initWithCoder:aDecoder])) {
}
return self;
Expand All @@ -203,14 +194,6 @@ - (id)initWithCoder:(NSCoder *)aDecoder {
#pragma mark -
#pragma mark Private Methods

- (BOOL)isAnimating {
return _isAnimating;
}

- (void)setIsAnimating:(BOOL)newState {
_isAnimating = newState;
}

- (void)_startCellAnimationIfNeeded {

if ([self window] == nil || [self isHidden] || NSEqualRects(NSZeroRect, [self frame]))
Expand Down
15 changes: 4 additions & 11 deletions MMTabBarView/MMTabBarView/MMOverflowPopUpButtonCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// MMTabBarView
//
// Created by Michael Monscheuer on 9/24/12.
// Copyright (c) 2012 Michael Monscheuer. All rights reserved.
// Copyright (c) 2016 Michael Monscheuer. All rights reserved.
//

#import <Cocoa/Cocoa.h>
Expand All @@ -12,18 +12,11 @@

@class MMImageTransitionAnimation;

@interface MMOverflowPopUpButtonCell : NSPopUpButtonCell <NSAnimationDelegate> {

@private
MMCellBezelDrawingBlock _bezelDrawingBlock;
NSImage *_image;
NSImage *_secondImage;
CGFloat _secondImageAlpha;
}
@interface MMOverflowPopUpButtonCell : NSPopUpButtonCell <NSAnimationDelegate>

@property (copy) MMCellBezelDrawingBlock bezelDrawingBlock;
@property (retain) NSImage *image;
@property (retain) NSImage *secondImage;
@property (strong) NSImage *image;
@property (strong) NSImage *secondImage;
@property (assign) CGFloat secondImageAlpha;

- (void)drawImage:(NSImage *)image withFrame:(NSRect)frame inView:(NSView *)controlView alpha:(CGFloat)alpha;
Expand Down
Loading