forked from ruaridht/Spotify-Menubar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyView.m
36 lines (28 loc) · 853 Bytes
/
MyView.m
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
//
// MyView.m
// Spotify Menubar
//
// http://stackoverflow.com/questions/4565820/cocoa-right-click-nsstatusitem
//
#import "MyView.h"
@implementation MyView
@synthesize image, target, action, rightAction;
- (void)mouseUp:(NSEvent *)event {
if([event modifierFlags] & NSControlKeyMask) {
[NSApp sendAction:self.rightAction to:self.target from:self];
} else {
[NSApp sendAction:self.action to:self.target from:self];
}
}
- (void)rightMouseUp:(NSEvent *)event {
[NSApp sendAction:self.rightAction to:self.target from:self];
}
- (void)dealloc {
self.image = nil;
[super dealloc];
}
- (void)drawRect:(NSRect)rect {
NSRect customRect = NSMakeRect(5, 3, 16, 16); // Haha! Hack :<
[self.image drawInRect:customRect /*self.bounds*/ fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1];
}
@end