Added category on NSMenu which supports indenting items (uses Carbon in
[ITKit.git] / ITCategory-NSMenu.m
1 //
2 //  ITCategory-NSMenu.m
3 //  ITKit
4 //
5 //  Created by Joseph Spiros on Sat Sep 27 2003.
6 //  Copyright (c) 2003 __MyCompanyName__. All rights reserved.
7 //
8
9 #import "ITCategory-NSMenu.h"
10
11 @interface NSMenu (HACKHACKHACKHACK)
12 - (id)_menuImpl;
13 @end
14
15 extern MenuRef _NSGetCarbonMenu( NSMenu *menu);
16
17 @implementation NSMenu (ITCategory)
18
19 - (void)indentItem:(NSMenuItem *)item {
20     [self indentItem:item toLevel:2];
21 }
22
23 - (void)indentItemAtIndex:(int)index {
24     [self indentItemAtIndex:index toLevel:2];
25 }
26
27 - (void)indentItem:(NSMenuItem *)item toLevel:(int)indentLevel {
28     [self indentItemAtIndex:[self indexOfItem:item] toLevel:indentLevel];
29 }
30
31 - (void)indentItemAtIndex:(int)index toLevel:(int)indentLevel {
32     MenuRef carbonMenu = [self menuRef];
33     
34     if (carbonMenu) {
35         SetMenuItemIndent(carbonMenu, index, indentLevel);
36     }
37 }
38
39 - (MenuRef)menuRef {
40     MenuRef carbonMenu;
41     
42     if( [self respondsToSelector:@selector(_menuImpl)] ) {
43         [self _menuImpl];
44     } else {
45         return nil;
46     }
47     
48     carbonMenu = _NSGetCarbonMenu(self);
49     return carbonMenu;
50 }
51
52 @end