Added category on NSMenu which supports indenting items (uses Carbon in
authorJoseph Spiros <joseph.spiros@ithinksw.com>
Sat, 27 Sep 2003 12:29:34 +0000 (12:29 +0000)
committerJoseph Spiros <joseph.spiros@ithinksw.com>
Sat, 27 Sep 2003 12:29:34 +0000 (12:29 +0000)
the backend)

ITCategory-NSMenu.h [new file with mode: 0755]
ITCategory-NSMenu.m [new file with mode: 0755]
ITKit.h

diff --git a/ITCategory-NSMenu.h b/ITCategory-NSMenu.h
new file mode 100755 (executable)
index 0000000..7cdac3d
--- /dev/null
@@ -0,0 +1,16 @@
+//
+//  ITCategory-NSMenu.h
+//  ITKit
+//
+//  Created by Joseph Spiros on Sat Sep 27 2003.
+//  Copyright (c) 2003 __MyCompanyName__. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+#import <Carbon/Carbon.h>
+
+@interface NSMenu (ITCategory)
+
+- (MenuRef)menuRef;
+
+@end
diff --git a/ITCategory-NSMenu.m b/ITCategory-NSMenu.m
new file mode 100755 (executable)
index 0000000..4e94be0
--- /dev/null
@@ -0,0 +1,52 @@
+//
+//  ITCategory-NSMenu.m
+//  ITKit
+//
+//  Created by Joseph Spiros on Sat Sep 27 2003.
+//  Copyright (c) 2003 __MyCompanyName__. All rights reserved.
+//
+
+#import "ITCategory-NSMenu.h"
+
+@interface NSMenu (HACKHACKHACKHACK)
+- (id)_menuImpl;
+@end
+
+extern MenuRef _NSGetCarbonMenu( NSMenu *menu);
+
+@implementation NSMenu (ITCategory)
+
+- (void)indentItem:(NSMenuItem *)item {
+    [self indentItem:item toLevel:2];
+}
+
+- (void)indentItemAtIndex:(int)index {
+    [self indentItemAtIndex:index toLevel:2];
+}
+
+- (void)indentItem:(NSMenuItem *)item toLevel:(int)indentLevel {
+    [self indentItemAtIndex:[self indexOfItem:item] toLevel:indentLevel];
+}
+
+- (void)indentItemAtIndex:(int)index toLevel:(int)indentLevel {
+    MenuRef carbonMenu = [self menuRef];
+    
+    if (carbonMenu) {
+        SetMenuItemIndent(carbonMenu, index, indentLevel);
+    }
+}
+
+- (MenuRef)menuRef {
+    MenuRef carbonMenu;
+    
+    if( [self respondsToSelector:@selector(_menuImpl)] ) {
+        [self _menuImpl];
+    } else {
+        return nil;
+    }
+    
+    carbonMenu = _NSGetCarbonMenu(self);
+    return carbonMenu;
+}
+
+@end
diff --git a/ITKit.h b/ITKit.h
index e76e907..e03aef2 100755 (executable)
--- a/ITKit.h
+++ b/ITKit.h
@@ -29,3 +29,4 @@
 #import <ITKit/ITLED.h>
 
 #import <ITKit/ITCategory-NSView.h>
+#import <ITKit/ITCategory-NSMenu.h>