Stripped out lots of menu building code from MainController, on the order
[MenuTunes.git] / MenuController.m
1 //
2 //  MenuController.m
3 //  MenuTunes
4 //
5 //  Created by Joseph Spiros on Wed Apr 30 2003.
6 //  Copyright (c) 2003 iThink Software. All rights reserved.
7 //
8
9 #import "MenuController.h"
10
11
12 @implementation MenuController
13
14 - (id)init
15 {
16     if ( (self = [super init]) ) {
17         _menuLayout = [[NSMutableArray alloc] initWithCapacity:
18     }
19     return self;
20 }
21
22 - (NSMenu *)menu
23 {
24     // dynamically create menu from supplied data and layout information.
25     // ...
26     // right before returning the menu, set the created menu to instance variable _currentMenu.
27 }
28
29 - (void)performMainMenuAction:(id)sender
30 {
31     switch ( [sender tag] )
32     {
33         case MTMenuPlayPauseItem:
34             NSLog(@"MenuController: Play/Pause");
35             break;
36         case MTMenuFastForwardItem:
37             NSLog(@"MenuController: Fast Forward");
38             break;
39         case MTMenuRewindItem:
40             NSLog(@"MenuController: Rewind");
41             break;
42         case MTMenuPreviousTrackItem:
43             NSLog(@"MenuController: Previous Track");
44             break;
45         case MTMenuNextTrackItem:
46             NSLog(@"MenuController: Next Track");
47             break;
48         case MTMenuPreferencesItem:
49             NSLog(@"MenuController: Preferences...");
50             break;
51         case MTMenuQuitItem:
52             NSLog(@"MenuController: Quit");
53             break;
54         default:
55             NSLog(@"MenuController: Unimplemented Menu Item OR Child-bearing Menu Item");
56             break;
57     }
58 }
59
60 - (void)performRatingMenuAction
61 {
62 }
63
64 - (void)performPlaylistMenuAction
65 {
66 }
67
68 - (void)performEqualizerMenuAction
69 {
70 }
71
72 - (void)performUpcomingSongsMenuAction
73 {
74 }
75
76 - (void)updateMenu
77 {
78     
79     [_currentMenu update];
80 }
81
82 - (BOOL)validateMenuItem:(id <NSMenuItem>)menuItem
83 {
84 }
85
86 - (NSString *)systemUIColor
87 {
88     NSDictionary *tmpDict;
89     NSNumber *tmpNumber;
90     if ( (tmpDict = [NSDictionary dictionaryWithContentsOfFile:[@"~/Library/Preferences/.GlobalPreferences.plist" stringByExpandingTildeInPath]]) ) {
91         if ( (tmpNumber = [tmpDict objectForKey:@"AppleAquaColorVariant"]) ) {
92             if ( ([tmpNumber intValue == 1) ) {
93                 return @"Aqua";
94             } else {
95                 return @"Graphite";
96             }
97         } else {
98             return @"Aqua";
99         }
100     } else {
101         return @"Aqua";
102     }
103 }
104
105 - (void)setKeyEquivalentForCode:(short)code andModifiers:(long)modifiers
106         onItem:(NSMenuItem *)item
107 {
108     unichar charcode = 'a';
109     int i;
110     long cocoaModifiers = 0;
111     static long carbonToCocoa[6][2] = 
112     {
113         { cmdKey, NSCommandKeyMask },
114         { optionKey, NSAlternateKeyMask },
115         { controlKey, NSControlKeyMask },
116         { shiftKey, NSShiftKeyMask },
117     };
118     
119     for (i = 0; i < 6; i++) {
120         if (modifiers & carbonToCocoa[i][0]) {
121             cocoaModifiers += carbonToCocoa[i][1];
122         }
123     }
124     [item setKeyEquivalentModifierMask:cocoaModifiers];
125     
126     //Missing key combos for some keys. Must find them later.
127     switch (code)
128     {
129         case 36:
130             charcode = '\r';
131         break;
132         
133         case 48:
134             charcode = '\t';
135         break;
136         
137         //Space -- ARGH!
138         case 49:
139         {
140             // Haven't tested this, though it should work.
141             unichar buffer;
142             [[NSString stringWithString:@"Space"] getCharacters:&buffer];
143             charcode = 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);
149             charcode = 'b';*/
150             
151         }
152         break;
153         
154         case 51:
155             charcode = NSDeleteFunctionKey;
156         break;
157         
158         case 53:
159             charcode = '\e';
160         break;
161         
162         case 71:
163             charcode = '\e';
164         break;
165         
166         case 76:
167             charcode = '\r';
168         break;
169         
170         case 96:
171             charcode = NSF5FunctionKey;
172         break;
173         
174         case 97:
175             charcode = NSF6FunctionKey;
176         break;
177         
178         case 98:
179             charcode = NSF7FunctionKey;
180         break;
181         
182         case 99:
183             charcode = NSF3FunctionKey;
184         break;
185         
186         case 100:
187             charcode = NSF8FunctionKey;
188         break;
189         
190         case 101:
191             charcode = NSF9FunctionKey;
192         break;
193         
194         case 103:
195             charcode = NSF11FunctionKey;
196         break;
197         
198         case 105:
199             charcode = NSF3FunctionKey;
200         break;
201         
202         case 107:
203             charcode = NSF14FunctionKey;
204         break;
205         
206         case 109:
207             charcode = NSF10FunctionKey;
208         break;
209         
210         case 111:
211             charcode = NSF12FunctionKey;
212         break;
213         
214         case 113:
215             charcode = NSF13FunctionKey;
216         break;
217         
218         case 114:
219             charcode = NSInsertFunctionKey;
220         break;
221         
222         case 115:
223             charcode = NSHomeFunctionKey;
224         break;
225         
226         case 116:
227             charcode = NSPageUpFunctionKey;
228         break;
229         
230         case 117:
231             charcode = NSDeleteFunctionKey;
232         break;
233         
234         case 118:
235             charcode = NSF4FunctionKey;
236         break;
237         
238         case 119:
239             charcode = NSEndFunctionKey;
240         break;
241         
242         case 120:
243             charcode = NSF2FunctionKey;
244         break;
245         
246         case 121:
247             charcode = NSPageDownFunctionKey;
248         break;
249         
250         case 122:
251             charcode = NSF1FunctionKey;
252         break;
253         
254         case 123:
255             charcode = NSLeftArrowFunctionKey;
256         break;
257         
258         case 124:
259             charcode = NSRightArrowFunctionKey;
260         break;
261         
262         case 125:
263             charcode = NSDownArrowFunctionKey;
264         break;
265         
266         case 126:
267             charcode = NSUpArrowFunctionKey;
268         break;
269     }
270     
271     if (charcode == 'a') {
272         unsigned long state;
273         long keyTrans;
274         char charCode;
275         Ptr kchr;
276         state = 0;
277         kchr = (Ptr) GetScriptVariable(smCurrentScript, smKCHRCache);
278         keyTrans = KeyTranslate(kchr, code, &state);
279         charCode = keyTrans;
280         [item setKeyEquivalent:[NSString stringWithCString:&charCode length:1]];
281     } else if (charcode != 'b') {
282         [item setKeyEquivalent:[NSString stringWithCharacters:&charcode length:1]];
283     }
284 }
285
286 @end