5 // Created by Joseph Spiros on Wed Apr 30 2003.
6 // Copyright (c) 2003 iThink Software. All rights reserved.
9 #import "MenuController.h"
12 @implementation MenuController
16 if ( (self = [super init]) ) {
17 _menuLayout = [[NSMutableArray alloc] initWithCapacity:
24 // dynamically create menu from supplied data and layout information.
26 // right before returning the menu, set the created menu to instance variable _currentMenu.
29 - (void)performMainMenuAction:(id)sender
31 switch ( [sender tag] )
33 case MTMenuPlayPauseItem:
34 NSLog(@"MenuController: Play/Pause");
36 case MTMenuFastForwardItem:
37 NSLog(@"MenuController: Fast Forward");
39 case MTMenuRewindItem:
40 NSLog(@"MenuController: Rewind");
42 case MTMenuPreviousTrackItem:
43 NSLog(@"MenuController: Previous Track");
45 case MTMenuNextTrackItem:
46 NSLog(@"MenuController: Next Track");
48 case MTMenuPreferencesItem:
49 NSLog(@"MenuController: Preferences...");
52 NSLog(@"MenuController: Quit");
55 NSLog(@"MenuController: Unimplemented Menu Item OR Child-bearing Menu Item");
60 - (void)performRatingMenuAction
64 - (void)performPlaylistMenuAction
68 - (void)performEqualizerMenuAction
72 - (void)performUpcomingSongsMenuAction
79 [_currentMenu update];
82 - (BOOL)validateMenuItem:(id <NSMenuItem>)menuItem
86 - (NSString *)systemUIColor
88 NSDictionary *tmpDict;
90 if ( (tmpDict = [NSDictionary dictionaryWithContentsOfFile:[@"~/Library/Preferences/.GlobalPreferences.plist" stringByExpandingTildeInPath]]) ) {
91 if ( (tmpNumber = [tmpDict objectForKey:@"AppleAquaColorVariant"]) ) {
92 if ( ([tmpNumber intValue == 1) ) {
105 - (void)setKeyEquivalentForCode:(short)code andModifiers:(long)modifiers
106 onItem:(NSMenuItem *)item
108 unichar charcode = 'a';
110 long cocoaModifiers = 0;
111 static long carbonToCocoa[6][2] =
113 { cmdKey, NSCommandKeyMask },
114 { optionKey, NSAlternateKeyMask },
115 { controlKey, NSControlKeyMask },
116 { shiftKey, NSShiftKeyMask },
119 for (i = 0; i < 6; i++) {
120 if (modifiers & carbonToCocoa[i][0]) {
121 cocoaModifiers += carbonToCocoa[i][1];
124 [item setKeyEquivalentModifierMask:cocoaModifiers];
126 //Missing key combos for some keys. Must find them later.
140 // Haven't tested this, though it should work.
142 [[NSString stringWithString:@"Space"] getCharacters:&buffer];
144 /*MenuRef menuRef = _NSGetCarbonMenu([item menu]);
145 NSLog(@"%@", menuRef);
146 SetMenuItemCommandKey(menuRef, 0, NO, 49);
147 SetMenuItemModifiers(menuRef, 0, kMenuNoCommandModifier);
148 SetMenuItemKeyGlyph(menuRef, 0, kMenuBlankGlyph);
155 charcode = NSDeleteFunctionKey;
171 charcode = NSF5FunctionKey;
175 charcode = NSF6FunctionKey;
179 charcode = NSF7FunctionKey;
183 charcode = NSF3FunctionKey;
187 charcode = NSF8FunctionKey;
191 charcode = NSF9FunctionKey;
195 charcode = NSF11FunctionKey;
199 charcode = NSF3FunctionKey;
203 charcode = NSF14FunctionKey;
207 charcode = NSF10FunctionKey;
211 charcode = NSF12FunctionKey;
215 charcode = NSF13FunctionKey;
219 charcode = NSInsertFunctionKey;
223 charcode = NSHomeFunctionKey;
227 charcode = NSPageUpFunctionKey;
231 charcode = NSDeleteFunctionKey;
235 charcode = NSF4FunctionKey;
239 charcode = NSEndFunctionKey;
243 charcode = NSF2FunctionKey;
247 charcode = NSPageDownFunctionKey;
251 charcode = NSF1FunctionKey;
255 charcode = NSLeftArrowFunctionKey;
259 charcode = NSRightArrowFunctionKey;
263 charcode = NSDownArrowFunctionKey;
267 charcode = NSUpArrowFunctionKey;
271 if (charcode == 'a') {
277 kchr = (Ptr) GetScriptVariable(smCurrentScript, smKCHRCache);
278 keyTrans = KeyTranslate(kchr, code, &state);
280 [item setKeyEquivalent:[NSString stringWithCString:&charCode length:1]];
281 } else if (charcode != 'b') {
282 [item setKeyEquivalent:[NSString stringWithCharacters:&charcode length:1]];