2 // PSMOverflowPopUpButton.m
5 // Created by John Pannell on 11/4/05.
6 // Copyright 2005 Positive Spin Media. All rights reserved.
9 #import "PSMOverflowPopUpButton.h"
10 #import "PSMTabBarControl.h"
12 @implementation PSMOverflowPopUpButton
14 - (id)initWithFrame:(NSRect)frameRect pullsDown:(BOOL)flag
16 self=[super initWithFrame:frameRect pullsDown:YES];
18 [self setBezelStyle:NSRegularSquareBezelStyle];
19 [self setBordered:NO];
21 [self setPreferredEdge:NSMaxXEdge];
22 _PSMTabBarOverflowPopUpImage = [[NSImage alloc] initByReferencingFile:[[PSMTabBarControl bundle] pathForImageResource:@"overflowImage"]];
23 _PSMTabBarOverflowDownPopUpImage = [[NSImage alloc] initByReferencingFile:[[PSMTabBarControl bundle] pathForImageResource:@"overflowImagePressed"]];
30 [_PSMTabBarOverflowPopUpImage release];
31 [_PSMTabBarOverflowDownPopUpImage release];
35 - (void)drawRect:(NSRect)rect
37 if(_PSMTabBarOverflowPopUpImage == nil){
38 [super drawRect:rect];
42 NSImage *image = (_down) ? _PSMTabBarOverflowDownPopUpImage : _PSMTabBarOverflowPopUpImage;
43 NSSize imageSize = [image size];
44 rect.origin.x = NSMidX(rect) - (imageSize.width * 0.5);
45 rect.origin.y = NSMidY(rect) - (imageSize.height * 0.5);
46 if([self isFlipped]) {
47 rect.origin.y += imageSize.height;
49 [image compositeToPoint:rect.origin operation:NSCompositeSourceOver];
52 - (void)mouseDown:(NSEvent *)event
55 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationReceived:) name:NSMenuDidEndTrackingNotification object:[self menu]];
56 [self setNeedsDisplay:YES];
57 [super mouseDown:event];
60 - (void)notificationReceived:(NSNotification *)notification
63 [self setNeedsDisplay:YES];
64 [[NSNotificationCenter defaultCenter] removeObserver:self];
68 #pragma mark Archiving
70 - (void)encodeWithCoder:(NSCoder *)aCoder {
71 [super encodeWithCoder:aCoder];
72 if ([aCoder allowsKeyedCoding]) {
73 [aCoder encodeObject:_PSMTabBarOverflowPopUpImage forKey:@"PSMTabBarOverflowPopUpImage"];
74 [aCoder encodeObject:_PSMTabBarOverflowDownPopUpImage forKey:@"PSMTabBarOverflowDownPopUpImage"];
78 - (id)initWithCoder:(NSCoder *)aDecoder {
79 self = [super initWithCoder:aDecoder];
81 if ([aDecoder allowsKeyedCoding]) {
82 _PSMTabBarOverflowPopUpImage = [[aDecoder decodeObjectForKey:@"PSMTabBarOverflowPopUpImage"] retain];
83 _PSMTabBarOverflowDownPopUpImage = [[aDecoder decodeObjectForKey:@"PSMTabBarOverflowDownPopUpImage"] retain];