-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDIContextualMenu.m
More file actions
101 lines (85 loc) · 2.17 KB
/
DIContextualMenu.m
File metadata and controls
101 lines (85 loc) · 2.17 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// COMMON FILE: Common
//
// DIContextualMenu.m
// MDict
//
// Created by Uncle MiF on 6/28/10.
// Copyright 2010 Deep IT. All rights reserved.
//
#import "DIContextualMenu.h"
#import <Carbon/Carbon.h>
@implementation DIContextualMenu
-(void)dealloc
{
[menu release];
[super dealloc];
}
+(id)contextualMenuWithDelegate:(id)aDelegate
{
return [[[[self class] alloc] initMenuWithDelegate:aDelegate andItems:nil] autorelease];
}
+(id)contextualMenuWithDelegate:(id)aDelegate andItems:(NSArray*)items
{
return [[[[self class] alloc] initMenuWithDelegate:aDelegate andItems:items] autorelease];
}
-(id)init
{
self = [super init];
if (self)
{
menu = [NSMenu new];
}
return self;
}
-(void)addItems:(NSArray*)items
{
if (!items)
return;
for (NSMenuItem * item in items)
[self addItem:item];
}
-(void)addItem:(NSMenuItem*)item
{
[menu addItem:item];
}
-(id)initMenuWithDelegate:(id)aDelegate andItems:(NSArray*)items
{
self = [self init];
if (self)
{
[menu setDelegate:aDelegate];
[self addItems:items];
}
return self;
}
-(void)setSubmenu:(NSMenu*)aMenu forItem:(NSMenuItem*)anItem
{
[menu setSubmenu:aMenu forItem:anItem];
}
-(void)showMenuInWindow:(NSWindow*)window
{
NSPoint mouseLocation = [window mouseLocationOutsideOfEventStream];
NSEvent *event = [NSEvent mouseEventWithType:NSRightMouseDown
location:mouseLocation
modifierFlags:0
timestamp:GetCurrentEventTime()
windowNumber:[window windowNumber]
context:[NSGraphicsContext currentContext]
eventNumber:1
clickCount:1
pressure:0.0];
[NSMenu popUpContextMenu:menu withEvent:event forView:[window contentView]];
}
+(id)itemWithTitle:(NSString *)itemName action:(SEL)anAction keyEquivalent:(NSString *)charCode
{
return [[[NSMenuItem alloc] initWithTitle:itemName action:anAction keyEquivalent:charCode] autorelease];
}
-(NSMenu*)menu
{
return [[menu retain] autorelease];
}
-(NSInteger)numberOfItems
{
return [menu numberOfItems];
}
@end