Moved MacVim project to src/MacVim and removed runtime folder
[MacVim.git] / src / MacVim / PSMTabBarControl / source / PSMOverflowPopUpButton.m
blobd3623f1edc57b67b5059fbb559a212cb4252ac40
1 //
2 //  PSMOverflowPopUpButton.m
3 //  PSMTabBarControl
4 //
5 //  Created by John Pannell on 11/4/05.
6 //  Copyright 2005 Positive Spin Media. All rights reserved.
7 //
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];
17     if (self) {
18         [self setBezelStyle:NSRegularSquareBezelStyle];
19         [self setBordered:NO];
20         [self setTitle:@""];
21         [self setPreferredEdge:NSMaxXEdge];
22         _PSMTabBarOverflowPopUpImage = [[NSImage alloc] initByReferencingFile:[[PSMTabBarControl bundle] pathForImageResource:@"overflowImage"]];
23                 _PSMTabBarOverflowDownPopUpImage = [[NSImage alloc] initByReferencingFile:[[PSMTabBarControl bundle] pathForImageResource:@"overflowImagePressed"]];
24     }
25     return self;
28 - (void)dealloc
30     [_PSMTabBarOverflowPopUpImage release];
31         [_PSMTabBarOverflowDownPopUpImage release];
32     [super dealloc];
35 - (void)drawRect:(NSRect)rect
37     if(_PSMTabBarOverflowPopUpImage == nil){
38         [super drawRect:rect];
39         return;
40     }
41         
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;
48     }
49     [image compositeToPoint:rect.origin operation:NSCompositeSourceOver];
52 - (void)mouseDown:(NSEvent *)event
54         _down = YES;
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
62         _down = NO;
63         [self setNeedsDisplay:YES];
64         [[NSNotificationCenter defaultCenter] removeObserver:self];
67 #pragma mark -
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"];
75     }
78 - (id)initWithCoder:(NSCoder *)aDecoder {
79     self = [super initWithCoder:aDecoder];
80     if (self) {
81         if ([aDecoder allowsKeyedCoding]) {
82             _PSMTabBarOverflowPopUpImage = [[aDecoder decodeObjectForKey:@"PSMTabBarOverflowPopUpImage"] retain];
83             _PSMTabBarOverflowDownPopUpImage = [[aDecoder decodeObjectForKey:@"PSMTabBarOverflowDownPopUpImage"] retain];
84         }
85     }
86     return self;
89 @end