Updating NSMenu category so that indentation methods use the
[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 void _NSGetMenuItemForCommandKeyEvent (NSMenu *menu, void *chicken, void *taco, void *food); 
16 extern MenuRef _NSGetCarbonMenu( NSMenu *menu);
17
18 @implementation NSMenu (ITCategory)
19
20 - (void)indentItem:(NSMenuItem *)item {
21     [self indentItem:item toLevel:1];
22 }
23
24 - (void)indentItemAtIndex:(int)index {
25     [self indentItemAtIndex:index toLevel:1];
26 }
27
28 - (void)indentItem:(NSMenuItem *)item toLevel:(int)indentLevel {
29     [self indentItemAtIndex:[self indexOfItem:item] toLevel:indentLevel];
30 }
31
32 - (void)indentItemAtIndex:(int)index toLevel:(int)indentLevel {
33     if ([NSMenuItem respondsToSelector:@selector(setIndentationLevel:)]) {
34         [[self itemAtIndex:index] setIndentationLevel:indentLevel];
35     } else {
36         MenuRef carbonMenu = [self menuRef];
37         if (carbonMenu) {
38             SetMenuItemIndent(carbonMenu, index + 1, indentLevel);
39         }
40     }
41 }
42
43 - (MenuRef)menuRef {
44     MenuRef carbonMenu;
45     int w00t, m00f;
46     
47     if( [self respondsToSelector:@selector(_menuImpl)] ) {
48         [self _menuImpl];
49     } else {
50         return nil;
51     }
52     
53     _NSGetMenuItemForCommandKeyEvent(self, NULL, &w00t, &m00f); 
54     carbonMenu = _NSGetCarbonMenu(self);
55     return carbonMenu;
56 }
57
58 @end