-
Notifications
You must be signed in to change notification settings - Fork 0
/
ITCategory-NSMenu.m
66 lines (52 loc) · 1.59 KB
/
ITCategory-NSMenu.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
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
#import "ITCategory-NSMenu.h"
extern void _NSGetMenuItemForCommandKeyEvent(NSMenu *menu, void *chicken, void *taco, void *food);
extern MenuRef _NSGetCarbonMenu(NSMenu *menu);
@interface NSMenu (ITKitCategoryHacks)
- (id)_menuImpl;
@end
@protocol _ITKitCategoryNSMenuItemPantherCompatability <NSMenuItem>
- (int)indentationLevel;
- (void)setIndentationLevel:(int)indentationLevel;
@end
@implementation NSMenu (ITKitCategory)
- (void)indentItem:(id <NSMenuItem>)item {
[self indentItem:item toLevel:1];
}
- (void)indentItemAtIndex:(int)index {
[self indentItemAtIndex:index toLevel:1];
}
- (void)indentItem:(id <NSMenuItem>)item toLevel:(int)indentLevel {
[self indentItemAtIndex:[self indexOfItem:item] toLevel:indentLevel];
}
- (void)indentItemAtIndex:(int)index toLevel:(int)indentLevel {
id <NSMenuItem> theItem = [self itemAtIndex:index];
if ([theItem respondsToSelector:@selector(setIndentationLevel:)]) {
[(id <_ITKitCategoryNSMenuItemPantherCompatability>)theItem setIndentationLevel:indentLevel];
} else {
MenuRef carbonMenu = [self menuRef];
if (carbonMenu) {
SetMenuItemIndent(carbonMenu, index + 1, indentLevel);
}
}
}
- (MenuRef)menuRef {
MenuRef carbonMenu;
int w00t, m00f;
if ([self respondsToSelector:@selector(_menuImpl)]) {
(void)[self _menuImpl];
} else {
return nil;
}
_NSGetMenuItemForCommandKeyEvent(self, NULL, &w00t, &m00f);
carbonMenu = _NSGetCarbonMenu(self);
return carbonMenu;
}
- (void)removeAllItems {
int numOfItems = [self numberOfItems];
int i = numOfItems;
while (i != 0) {
[self removeItemAtIndex:(i-1)];
i--;
}
}
@end