5 // Created by Joseph Spiros on Wed Apr 30 2003.
6 // Copyright (c) 2003 iThink Software. All rights reserved.
9 #import "MenuController.h"
10 #import "MainController.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");
35 [[MainController sharedController] playPause];
36 //We're gonna have to change the Play menu item to Pause here too.
38 case MTMenuFastForwardItem:
39 NSLog(@"MenuController: Fast Forward");
40 [[MainController sharedController] fastForward];
41 //make sure play/pause item says sane through this
43 case MTMenuRewindItem:
44 NSLog(@"MenuController: Rewind");
45 [[MainController sharedController] rewind];
46 //make sure play/pause item says sane through this
48 case MTMenuPreviousTrackItem:
49 NSLog(@"MenuController: Previous Track");
50 [[MainController sharedController] prevSong];
52 case MTMenuNextTrackItem:
53 NSLog(@"MenuController: Next Track");
54 [[MainController sharedController] nextSong];
56 case MTMenuPreferencesItem:
57 NSLog(@"MenuController: Preferences...");
58 [[MainController sharedController] showPreferences];
61 NSLog(@"MenuController: Quit");
62 [[MainController sharedController] quitMenuTunes];
65 NSLog(@"MenuController: Unimplemented Menu Item OR Child-bearing Menu Item");
70 - (void)performRatingMenuAction:(id)sender
72 [[MainController sharedController] selectSongRating:[sender tag]];
75 - (void)performPlaylistMenuAction:(id)sender
77 [[MainController sharedController] selectPlaylistAtIndex:[sender tag]];
80 - (void)performEqualizerMenuAction:(id)sender
82 [[MainController sharedController] selectEQItemAtIndex:[sender tag]]
85 - (void)performUpcomingSongsMenuAction:(id)sender
87 [[MainController sharedController] selectSongAtIndex:[sender tag]]
93 [_currentMenu update];
96 - (BOOL)validateMenuItem:(id <NSMenuItem>)menuItem
100 - (NSString *)systemUIColor
102 NSDictionary *tmpDict;
104 if ( (tmpDict = [NSDictionary dictionaryWithContentsOfFile:[@"~/Library/Preferences/.GlobalPreferences.plist" stringByExpandingTildeInPath]]) ) {
105 if ( (tmpNumber = [tmpDict objectForKey:@"AppleAquaColorVariant"]) ) {
106 if ( ([tmpNumber intValue == 1) ) {
119 - (void)setKeyEquivalentForCode:(short)code andModifiers:(long)modifiers
120 onItem:(NSMenuItem *)item
122 unichar charcode = 'a';
124 long cocoaModifiers = 0;
125 static long carbonToCocoa[6][2] =
127 { cmdKey, NSCommandKeyMask },
128 { optionKey, NSAlternateKeyMask },
129 { controlKey, NSControlKeyMask },
130 { shiftKey, NSShiftKeyMask },
133 for (i = 0; i < 6; i++) {
134 if (modifiers & carbonToCocoa[i][0]) {
135 cocoaModifiers += carbonToCocoa[i][1];
138 [item setKeyEquivalentModifierMask:cocoaModifiers];
140 //Missing key combos for some keys. Must find them later.
154 // Haven't tested this, though it should work.
156 [[NSString stringWithString:@"Space"] getCharacters:&buffer];
158 /*MenuRef menuRef = _NSGetCarbonMenu([item menu]);
159 NSLog(@"%@", menuRef);
160 SetMenuItemCommandKey(menuRef, 0, NO, 49);
161 SetMenuItemModifiers(menuRef, 0, kMenuNoCommandModifier);
162 SetMenuItemKeyGlyph(menuRef, 0, kMenuBlankGlyph);
169 charcode = NSDeleteFunctionKey;
185 charcode = NSF5FunctionKey;
189 charcode = NSF6FunctionKey;
193 charcode = NSF7FunctionKey;
197 charcode = NSF3FunctionKey;
201 charcode = NSF8FunctionKey;
205 charcode = NSF9FunctionKey;
209 charcode = NSF11FunctionKey;
213 charcode = NSF3FunctionKey;
217 charcode = NSF14FunctionKey;
221 charcode = NSF10FunctionKey;
225 charcode = NSF12FunctionKey;
229 charcode = NSF13FunctionKey;
233 charcode = NSInsertFunctionKey;
237 charcode = NSHomeFunctionKey;
241 charcode = NSPageUpFunctionKey;
245 charcode = NSDeleteFunctionKey;
249 charcode = NSF4FunctionKey;
253 charcode = NSEndFunctionKey;
257 charcode = NSF2FunctionKey;
261 charcode = NSPageDownFunctionKey;
265 charcode = NSF1FunctionKey;
269 charcode = NSLeftArrowFunctionKey;
273 charcode = NSRightArrowFunctionKey;
277 charcode = NSDownArrowFunctionKey;
281 charcode = NSUpArrowFunctionKey;
285 if (charcode == 'a') {
291 kchr = (Ptr) GetScriptVariable(smCurrentScript, smKCHRCache);
292 keyTrans = KeyTranslate(kchr, code, &state);
294 [item setKeyEquivalent:[NSString stringWithCString:&charCode length:1]];
295 } else if (charcode != 'b') {
296 [item setKeyEquivalent:[NSString stringWithCharacters:&charcode length:1]];