-
Notifications
You must be signed in to change notification settings - Fork 85
Expand file tree
/
Copy pathLCMenuIconView.m
More file actions
77 lines (55 loc) · 1.78 KB
/
LCMenuIconView.m
File metadata and controls
77 lines (55 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//
// LCMenuIconView.m
// Caffeine
//
// Created by Tomas Franzén on 2009-09-04.
// Copyright 2009 Lighthead Software. All rights reserved.
//
#import "LCMenuIconView.h"
@implementation LCMenuIconView
@synthesize isActive, statusItem, menu;
- (id)initWithFrame:(NSRect)r {
[super initWithFrame:r];
activeImage = [[NSImage imageNamed:@"active"] retain];
inactiveImage = [[NSImage imageNamed:@"inactive"] retain];
highlightImage = [[NSImage imageNamed:@"highlighted"] retain];
highlightActiveImage = [[NSImage imageNamed:@"highlightactive"] retain];
return self;
}
- (void)drawRect:(NSRect)r {
NSImage *i = isActive ? activeImage : inactiveImage;
if(menuIsShown) i = isActive ? highlightActiveImage : highlightImage;
NSRect f = [self bounds];
NSPoint p = NSMakePoint(f.size.width/2 - [i size].width/2, f.size.height/2 - [i size].height/2 + 1);
if(menuIsShown) [statusItem drawStatusBarBackgroundInRect:r withHighlight:YES];
[i drawAtPoint:p fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1];
}
- (void)setActive:(BOOL)flag {
isActive = flag;
[self setNeedsDisplay:YES];
}
- (void)rightMouseDown:(NSEvent*)e {
menuIsShown = YES;
[self setNeedsDisplay:YES];
[statusItem popUpStatusItemMenu:menu];
menuIsShown = NO;
[self setNeedsDisplay:YES];
}
- (void)mouseDown:(NSEvent*)e {
if([e modifierFlags] & (NSCommandKeyMask | NSControlKeyMask))
return [self rightMouseDown:e];
[NSApp sendAction:action to:target from:self];
}
- (void)mouseUp:(NSEvent *)theEvent {
if([NSDate timeIntervalSinceReferenceDate] - lastMouseUp < 0.2) {
[NSApp sendAction:@selector(showPreferences:) to:nil from:nil];
lastMouseUp = 0;
} else lastMouseUp = [NSDate timeIntervalSinceReferenceDate];
}
- (void)setAction:(SEL)a {
action = a;
}
- (void)setTarget:(id)t {
target = t;
}
@end