summaryrefslogtreecommitdiff
path: root/cocoa/PSMTabBarControl/PSMOverflowPopUpButton.m
diff options
context:
space:
mode:
authorSven Weidauer <sven.weidauer@gmail.com>2011-01-26 10:52:13 +0000
committerSven Weidauer <sven.weidauer@gmail.com>2011-01-26 10:52:13 +0000
commit7b2694e9f6c35d9f50c3fb3cf38b0fc766478162 (patch)
treec4e3d07a6bb51de884f53312a96d05849f072db1 /cocoa/PSMTabBarControl/PSMOverflowPopUpButton.m
parenta663cf8f84942e1147d1d2f3db292308639c7fa5 (diff)
downloadnetsurf-7b2694e9f6c35d9f50c3fb3cf38b0fc766478162.tar.gz
netsurf-7b2694e9f6c35d9f50c3fb3cf38b0fc766478162.tar.bz2
Updated PSMTabBarControl source code to version from https://github.com/dergraf83/PSMTabBarControl
svn path=/trunk/netsurf/; revision=11490
Diffstat (limited to 'cocoa/PSMTabBarControl/PSMOverflowPopUpButton.m')
-rw-r--r--cocoa/PSMTabBarControl/PSMOverflowPopUpButton.m127
1 files changed, 59 insertions, 68 deletions
diff --git a/cocoa/PSMTabBarControl/PSMOverflowPopUpButton.m b/cocoa/PSMTabBarControl/PSMOverflowPopUpButton.m
index 4ac70451b..c316f6973 100644
--- a/cocoa/PSMTabBarControl/PSMOverflowPopUpButton.m
+++ b/cocoa/PSMTabBarControl/PSMOverflowPopUpButton.m
@@ -14,102 +14,94 @@
@implementation PSMOverflowPopUpButton
-- (id)initWithFrame:(NSRect)frameRect pullsDown:(BOOL)flag
-{
- if ((self = [super initWithFrame:frameRect pullsDown:YES]) != nil) {
- [self setBezelStyle:NSRegularSquareBezelStyle];
- [self setBordered:NO];
- [self setTitle:@""];
- [self setPreferredEdge:NSMaxXEdge];
- _PSMTabBarOverflowPopUpImage = [[NSImage alloc] initByReferencingFile:[[PSMTabBarControl bundle] pathForImageResource:@"overflowImage"]];
+- (id)initWithFrame:(NSRect)frameRect pullsDown:(BOOL)flag {
+ if ((self = [super initWithFrame:frameRect pullsDown:YES]) != nil) {
+ [self setBezelStyle:NSRegularSquareBezelStyle];
+ [self setBordered:NO];
+ [self setTitle:@""];
+ [self setPreferredEdge:NSMaxXEdge];
+ _PSMTabBarOverflowPopUpImage = [[NSImage alloc] initByReferencingFile:[[PSMTabBarControl bundle] pathForImageResource:@"overflowImage"]];
_PSMTabBarOverflowDownPopUpImage = [[NSImage alloc] initByReferencingFile:[[PSMTabBarControl bundle] pathForImageResource:@"overflowImagePressed"]];
_animatingAlternateImage = NO;
- }
- return self;
+ }
+ return self;
}
-- (void)dealloc
-{
- [_PSMTabBarOverflowPopUpImage release];
+- (void)dealloc {
+ [_PSMTabBarOverflowPopUpImage release];
[_PSMTabBarOverflowDownPopUpImage release];
- [super dealloc];
+ [super dealloc];
}
-- (void)drawRect:(NSRect)rect
-{
- if(_PSMTabBarOverflowPopUpImage == nil){
- [super drawRect:rect];
- return;
- }
-
- NSImage *image = (_down) ? _PSMTabBarOverflowDownPopUpImage : _PSMTabBarOverflowPopUpImage;
+- (void)drawRect:(NSRect)rect {
+ if(_PSMTabBarOverflowPopUpImage == nil) {
+ [super drawRect:rect];
+ return;
+ }
+
+ NSImage *image = (_down) ? _PSMTabBarOverflowDownPopUpImage : _PSMTabBarOverflowPopUpImage;
NSSize imageSize = [image size];
NSRect bounds = [self bounds];
-
+
NSPoint drawPoint = NSMakePoint(NSMidX(bounds) - (imageSize.width * 0.5f), NSMidY(bounds) - (imageSize.height * 0.5f));
-
- if ([self isFlipped]) {
- drawPoint.y += imageSize.height;
- }
-
- [image compositeToPoint:drawPoint operation:NSCompositeSourceOver fraction:(_animatingAlternateImage ? 0.7f : 1.0f)];
-
- if (_animatingAlternateImage) {
+
+ if([self isFlipped]) {
+ drawPoint.y += imageSize.height;
+ }
+
+ [image compositeToPoint:drawPoint operation:NSCompositeSourceOver fraction:(_animatingAlternateImage ? 0.7f : 1.0f)];
+
+ if(_animatingAlternateImage) {
NSImage *alternateImage = [self alternateImage];
NSSize altImageSize = [alternateImage size];
drawPoint = NSMakePoint(NSMidX(bounds) - (altImageSize.width * 0.5f), NSMidY(bounds) - (altImageSize.height * 0.5f));
-
- if ([self isFlipped]) {
+
+ if([self isFlipped]) {
drawPoint.y += altImageSize.height;
}
-
+
[[self alternateImage] compositeToPoint:drawPoint operation:NSCompositeSourceOver fraction:sin(_animationValue * M_PI)];
}
}
-- (void)mouseDown:(NSEvent *)event
-{
+- (void)mouseDown:(NSEvent *)event {
_down = YES;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationReceived:) name:NSMenuDidEndTrackingNotification object:[self menu]];
[self setNeedsDisplay:YES];
[super mouseDown:event];
}
-- (void)setHidden:(BOOL)value
-{
- if ([self isHidden] != value) {
- if (value) {
+- (void)setHidden:(BOOL)value {
+ if([self isHidden] != value) {
+ if(value) {
// Stop any animating alternate image if we hide
[_animationTimer invalidate], _animationTimer = nil;
- } else if (_animatingAlternateImage) {
+ } else if(_animatingAlternateImage) {
// Restart any animating alternate image if we unhide
_animationValue = ANIMATION_STEP;
_animationTimer = [NSTimer scheduledTimerWithTimeInterval:TIMER_INTERVAL target:self selector:@selector(animateStep:) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:_animationTimer forMode:NSEventTrackingRunLoopMode];
}
}
-
+
[super setHidden:value];
}
-- (void)notificationReceived:(NSNotification *)notification
-{
+- (void)notificationReceived:(NSNotification *)notification {
_down = NO;
[self setNeedsDisplay:YES];
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
-- (void)setAnimatingAlternateImage:(BOOL)flag
-{
- if (_animatingAlternateImage != flag) {
+- (void)setAnimatingAlternateImage:(BOOL)flag {
+ if(_animatingAlternateImage != flag) {
_animatingAlternateImage = flag;
-
- if (![self isHidden]) {
- if (flag) {
+
+ if(![self isHidden]) {
+ if(flag) {
_animationValue = ANIMATION_STEP;
_animationTimer = [NSTimer scheduledTimerWithTimeInterval:TIMER_INTERVAL target:self selector:@selector(animateStep:) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:_animationTimer forMode:NSEventTrackingRunLoopMode];
-
} else {
[_animationTimer invalidate], _animationTimer = nil;
}
@@ -124,14 +116,13 @@
return _animatingAlternateImage;
}
-- (void)animateStep:(NSTimer *)timer
-{
+- (void)animateStep:(NSTimer *)timer {
_animationValue += ANIMATION_STEP;
-
- if (_animationValue >= 1) {
+
+ if(_animationValue >= 1) {
_animationValue = ANIMATION_STEP;
}
-
+
[self setNeedsDisplay:YES];
}
@@ -139,23 +130,23 @@
#pragma mark Archiving
- (void)encodeWithCoder:(NSCoder *)aCoder {
- [super encodeWithCoder:aCoder];
- if ([aCoder allowsKeyedCoding]) {
- [aCoder encodeObject:_PSMTabBarOverflowPopUpImage forKey:@"PSMTabBarOverflowPopUpImage"];
- [aCoder encodeObject:_PSMTabBarOverflowDownPopUpImage forKey:@"PSMTabBarOverflowDownPopUpImage"];
+ [super encodeWithCoder:aCoder];
+ if([aCoder allowsKeyedCoding]) {
+ [aCoder encodeObject:_PSMTabBarOverflowPopUpImage forKey:@"PSMTabBarOverflowPopUpImage"];
+ [aCoder encodeObject:_PSMTabBarOverflowDownPopUpImage forKey:@"PSMTabBarOverflowDownPopUpImage"];
[aCoder encodeBool:_animatingAlternateImage forKey:@"PSMTabBarOverflowAnimatingAlternateImage"];
- }
+ }
}
- (id)initWithCoder:(NSCoder *)aDecoder {
- if ( (self = [super initWithCoder:aDecoder]) ) {
- if ([aDecoder allowsKeyedCoding]) {
- _PSMTabBarOverflowPopUpImage = [[aDecoder decodeObjectForKey:@"PSMTabBarOverflowPopUpImage"] retain];
- _PSMTabBarOverflowDownPopUpImage = [[aDecoder decodeObjectForKey:@"PSMTabBarOverflowDownPopUpImage"] retain];
+ if((self = [super initWithCoder:aDecoder])) {
+ if([aDecoder allowsKeyedCoding]) {
+ _PSMTabBarOverflowPopUpImage = [[aDecoder decodeObjectForKey:@"PSMTabBarOverflowPopUpImage"] retain];
+ _PSMTabBarOverflowDownPopUpImage = [[aDecoder decodeObjectForKey:@"PSMTabBarOverflowDownPopUpImage"] retain];
[self setAnimatingAlternateImage:[aDecoder decodeBoolForKey:@"PSMTabBarOverflowAnimatingAlternateImage"]];
- }
- }
- return self;
+ }
+ }
+ return self;
}
@end