]> git.sesse.net Git - vlc/blob - modules/gui/macosx/prefs_widgets.m
- added macosx version detection at runtime with /System/Library/CoreServices/SystemV...
[vlc] / modules / gui / macosx / prefs_widgets.m
1 /*****************************************************************************
2  * prefs_widgets.m: Preferences controls
3  *****************************************************************************
4  * Copyright (C) 2002-2003 VideoLAN
5  * $Id$
6  *
7  * Authors: Derk-Jan Hartman <hartman at videolan.org>
8  *          Jérôme Decoodt <djc at videolan.org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  * 
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
23  *****************************************************************************/
24
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28 #include <stdlib.h>                                      /* malloc(), free() */
29 #include <string.h>
30
31 #include <vlc/vlc.h>
32 #include "vlc_keys.h"
33
34 #include "intf.h"
35 #include "prefs_widgets.h"
36
37 #define PREFS_WRAP 300
38 #define OFFSET_RIGHT 20
39 #define OFFSET_BETWEEN 2
40
41 #define LEFTMARGIN  18
42 #define RIGHTMARGIN 18
43
44 #define UPWARDS_WHITE_ARROW                 "\xE2\x87\xA7" 
45 #define OPTION_KEY                          "\xE2\x8C\xA5"
46 #define UP_ARROWHEAD                        "\xE2\x8C\x83"
47 #define PLACE_OF_INTEREST_SIGN              "\xE2\x8C\x98"
48
49 #define POPULATE_A_KEY( o_menu, string, value )                             \
50 {                                                                           \
51     NSMenuItem *o_mi;                                                       \
52 /*  Normal */                                                               \
53     o_mi = [[NSMenuItem alloc] initWithTitle:string                         \
54         action:nil keyEquivalent:@""];                                      \
55     [o_mi setKeyEquivalentModifierMask:                                     \
56         0];                                                                 \
57     [o_mi setAlternate: NO];                                                \
58     [o_mi setTag:                                                           \
59         ( value )];                                                         \
60     [o_menu addItem: o_mi];                                                 \
61 if( MACOS_VERSION >= 10.3 )                                                 \
62 {                                                                           \
63 /*  Ctrl */                                                                 \
64     o_mi = [[NSMenuItem alloc] initWithTitle:                               \
65         [[NSString stringWithUTF8String:                                    \
66             UP_ARROWHEAD                                                    \
67         ] stringByAppendingString: string]                                  \
68         action:nil keyEquivalent:@""];                                      \
69     [o_mi setKeyEquivalentModifierMask:                                     \
70         NSControlKeyMask];                                                  \
71     [o_mi setAlternate: YES];                                               \
72     [o_mi setTag:                                                           \
73         KEY_MODIFIER_CTRL | ( value )];                                     \
74     [o_menu addItem: o_mi];                                                 \
75 /* Ctrl+Alt */                                                              \
76     o_mi = [[NSMenuItem alloc] initWithTitle:                               \
77         [[NSString stringWithUTF8String:                                    \
78             UP_ARROWHEAD OPTION_KEY                                         \
79         ] stringByAppendingString: string]                                  \
80         action:nil keyEquivalent:@""];                                      \
81     [o_mi setKeyEquivalentModifierMask:                                     \
82         NSControlKeyMask | NSAlternateKeyMask];                             \
83     [o_mi setAlternate: YES];                                               \
84     [o_mi setTag:                                                           \
85         (KEY_MODIFIER_CTRL | KEY_MODIFIER_ALT) | ( value )];                \
86     [o_menu addItem: o_mi];                                                 \
87 /* Ctrl+Shift */                                                            \
88     o_mi = [[NSMenuItem alloc] initWithTitle:                               \
89         [[NSString stringWithUTF8String:                                    \
90             UP_ARROWHEAD UPWARDS_WHITE_ARROW                                \
91         ] stringByAppendingString: string]                                  \
92         action:nil keyEquivalent:@""];                                      \
93     [o_mi setKeyEquivalentModifierMask:                                     \
94        NSControlKeyMask | NSShiftKeyMask];                                  \
95     [o_mi setAlternate: YES];                                               \
96     [o_mi setTag:                                                           \
97         (KEY_MODIFIER_CTRL | KEY_MODIFIER_SHIFT) | ( value )];              \
98     [o_menu addItem: o_mi];                                                 \
99 /* Ctrl+Apple */                                                            \
100     o_mi = [[NSMenuItem alloc] initWithTitle:                               \
101         [[NSString stringWithUTF8String:                                    \
102             UP_ARROWHEAD PLACE_OF_INTEREST_SIGN                             \
103         ] stringByAppendingString: string]                                  \
104         action:nil keyEquivalent:@""];                                      \
105     [o_mi setKeyEquivalentModifierMask:                                     \
106         NSControlKeyMask | NSCommandKeyMask];                               \
107     [o_mi setAlternate: YES];                                               \
108     [o_mi setTag:                                                           \
109         (KEY_MODIFIER_CTRL | KEY_MODIFIER_COMMAND) | ( value )];            \
110     [o_menu addItem: o_mi];                                                 \
111 /* Ctrl+Alt+Shift */                                                        \
112     o_mi = [[NSMenuItem alloc] initWithTitle:                               \
113         [[NSString stringWithUTF8String:                                    \
114             UP_ARROWHEAD OPTION_KEY UPWARDS_WHITE_ARROW                     \
115         ] stringByAppendingString: string]                                  \
116         action:nil keyEquivalent:@""];                                      \
117     [o_mi setKeyEquivalentModifierMask:                                     \
118         NSControlKeyMask | NSAlternateKeyMask | NSShiftKeyMask];            \
119     [o_mi setAlternate: YES];                                               \
120     [o_mi setTag:                                                           \
121         (KEY_MODIFIER_CTRL | KEY_MODIFIER_ALT | KEY_MODIFIER_SHIFT) |       \
122              ( value )];                                                    \
123     [o_menu addItem: o_mi];                                                 \
124 /* Ctrl+Alt+Apple */                                                        \
125     o_mi = [[NSMenuItem alloc] initWithTitle:                               \
126         [[NSString stringWithUTF8String:                                    \
127             UP_ARROWHEAD OPTION_KEY PLACE_OF_INTEREST_SIGN                  \
128         ] stringByAppendingString: string]                                  \
129         action:nil keyEquivalent:@""];                                      \
130     [o_mi setKeyEquivalentModifierMask:                                     \
131         NSControlKeyMask | NSAlternateKeyMask | NSCommandKeyMask];          \
132     [o_mi setAlternate: YES];                                               \
133     [o_mi setTag:                                                           \
134         (KEY_MODIFIER_CTRL | KEY_MODIFIER_ALT | KEY_MODIFIER_COMMAND) |     \
135             ( value )];                                                     \
136     [o_menu addItem: o_mi];                                                 \
137 /* Ctrl+Shift+Apple */                                                      \
138     o_mi = [[NSMenuItem alloc] initWithTitle:                               \
139         [[NSString stringWithUTF8String:                                    \
140             UP_ARROWHEAD UPWARDS_WHITE_ARROW PLACE_OF_INTEREST_SIGN         \
141         ] stringByAppendingString: string]                                  \
142         action:nil keyEquivalent:@""];                                      \
143     [o_mi setKeyEquivalentModifierMask:                                     \
144         NSControlKeyMask | NSShiftKeyMask | NSCommandKeyMask];              \
145     [o_mi setAlternate: YES];                                               \
146     [o_mi setTag:                                                           \
147         (KEY_MODIFIER_CTRL | KEY_MODIFIER_SHIFT | KEY_MODIFIER_COMMAND) |   \
148             ( value )];                                                     \
149     [o_menu addItem: o_mi];                                                 \
150 /* Ctrl+Alt+Shift+Apple */                                                  \
151     o_mi = [[NSMenuItem alloc] initWithTitle:                               \
152         [[NSString stringWithUTF8String:                                    \
153             UP_ARROWHEAD OPTION_KEY UPWARDS_WHITE_ARROW                     \
154                 PLACE_OF_INTEREST_SIGN                                      \
155         ] stringByAppendingString: string]                                  \
156         action:nil keyEquivalent:@""];                                      \
157     [o_mi setKeyEquivalentModifierMask:                                     \
158         NSControlKeyMask | NSAlternateKeyMask | NSShiftKeyMask |            \
159             NSCommandKeyMask];                                              \
160     [o_mi setAlternate: YES];                                               \
161     [o_mi setTag:                                                           \
162         (KEY_MODIFIER_CTRL | KEY_MODIFIER_ALT | KEY_MODIFIER_SHIFT |        \
163             KEY_MODIFIER_COMMAND) | ( value )];                             \
164     [o_menu addItem: o_mi];                                                 \
165 /* Alt */                                                                   \
166     o_mi = [[NSMenuItem alloc] initWithTitle:                               \
167         [[NSString stringWithUTF8String:                                    \
168             OPTION_KEY                                                      \
169         ] stringByAppendingString: string]                                  \
170         action:nil keyEquivalent:@""];                                      \
171     [o_mi setKeyEquivalentModifierMask:                                     \
172         NSAlternateKeyMask];                                                \
173     [o_mi setAlternate: YES];                                               \
174     [o_mi setTag:                                                           \
175         KEY_MODIFIER_ALT | ( value )];                                      \
176     [o_menu addItem: o_mi];                                                 \
177 /* Alt+Shift */                                                             \
178     o_mi = [[NSMenuItem alloc] initWithTitle:                               \
179         [[NSString stringWithUTF8String:                                    \
180             OPTION_KEY UPWARDS_WHITE_ARROW                                  \
181         ] stringByAppendingString: string]                                  \
182         action:nil keyEquivalent:@""];                                      \
183     [o_mi setKeyEquivalentModifierMask:                                     \
184         NSAlternateKeyMask | NSShiftKeyMask];                               \
185     [o_mi setAlternate: YES];                                               \
186     [o_mi setTag:                                                           \
187         (KEY_MODIFIER_ALT | KEY_MODIFIER_SHIFT) | ( value )];               \
188     [o_menu addItem: o_mi];                                                 \
189 /* Alt+Apple */                                                             \
190     o_mi = [[NSMenuItem alloc] initWithTitle:                               \
191         [[NSString stringWithUTF8String:                                    \
192             OPTION_KEY PLACE_OF_INTEREST_SIGN                               \
193         ] stringByAppendingString: string]                                  \
194         action:nil keyEquivalent:@""];                                      \
195     [o_mi setKeyEquivalentModifierMask:                                     \
196         NSAlternateKeyMask | NSCommandKeyMask];                             \
197     [o_mi setAlternate: YES];                                               \
198     [o_mi setTag:                                                           \
199         (KEY_MODIFIER_ALT | KEY_MODIFIER_COMMAND) | ( value )];             \
200     [o_menu addItem: o_mi];                                                 \
201 /* Alt+Shift+Apple */                                                       \
202     o_mi = [[NSMenuItem alloc] initWithTitle:                               \
203         [[NSString stringWithUTF8String:                                    \
204             OPTION_KEY UPWARDS_WHITE_ARROW PLACE_OF_INTEREST_SIGN           \
205         ] stringByAppendingString: string]                                  \
206         action:nil keyEquivalent:@""];                                      \
207     [o_mi setKeyEquivalentModifierMask:                                     \
208         NSAlternateKeyMask | NSShiftKeyMask | NSCommandKeyMask];            \
209     [o_mi setAlternate: YES];                                               \
210     [o_mi setTag:                                                           \
211         (KEY_MODIFIER_ALT | KEY_MODIFIER_SHIFT | KEY_MODIFIER_COMMAND) |    \
212             ( value )];                                                     \
213     [o_menu addItem: o_mi];                                                 \
214 /* Shift */                                                                 \
215     o_mi = [[NSMenuItem alloc] initWithTitle:                               \
216         [[NSString stringWithUTF8String:                                    \
217             UPWARDS_WHITE_ARROW                                             \
218         ] stringByAppendingString: string]                                  \
219         action:nil keyEquivalent:@""];                                      \
220     [o_mi setKeyEquivalentModifierMask:                                     \
221         NSShiftKeyMask];                                                    \
222     [o_mi setAlternate: YES];                                               \
223     [o_mi setTag:                                                           \
224         KEY_MODIFIER_SHIFT | ( value )];                                    \
225     [o_menu addItem: o_mi];                                                 \
226 /* Shift+Apple */                                                           \
227     o_mi = [[NSMenuItem alloc] initWithTitle:                               \
228         [[NSString stringWithUTF8String:                                    \
229             UPWARDS_WHITE_ARROW PLACE_OF_INTEREST_SIGN                      \
230         ] stringByAppendingString: string]                                  \
231         action:nil keyEquivalent:@""];                                      \
232     [o_mi setKeyEquivalentModifierMask:                                     \
233         NSShiftKeyMask | NSCommandKeyMask];                                 \
234     [o_mi setAlternate: YES];                                               \
235     [o_mi setTag:                                                           \
236         (KEY_MODIFIER_SHIFT | KEY_MODIFIER_COMMAND) | ( value )];           \
237     [o_menu addItem: o_mi];                                                 \
238 /* Apple */                                                                 \
239     o_mi = [[NSMenuItem alloc] initWithTitle:                               \
240         [[NSString stringWithUTF8String:                                    \
241         PLACE_OF_INTEREST_SIGN                                              \
242         ] stringByAppendingString: string]                                  \
243         action:nil keyEquivalent:@""];                                      \
244     [o_mi setKeyEquivalentModifierMask:                                     \
245         NSCommandKeyMask];                                                  \
246     [o_mi setAlternate: YES];                                               \
247     [o_mi setTag:                                                           \
248         KEY_MODIFIER_COMMAND | ( value )];                                  \
249     [o_menu addItem: o_mi];                                                 \
250 }                                                                           \
251 }
252
253 #define ADD_LABEL( o_label, superFrame, x_offset, my_y_offset, label )      \
254 {                                                                           \
255     NSRect s_rc = superFrame;                                               \
256     s_rc.size.height = 17;                                                  \
257     s_rc.origin.x = x_offset - 3;                                           \
258     s_rc.origin.y = superFrame.size.height - 17 + my_y_offset;              \
259     o_label = [[[NSTextField alloc] initWithFrame: s_rc] retain];           \
260     [o_label setDrawsBackground: NO];                                       \
261     [o_label setBordered: NO];                                              \
262     [o_label setEditable: NO];                                              \
263     [o_label setSelectable: NO];                                            \
264     [o_label setStringValue: label];                                        \
265     [o_label setFont:[NSFont systemFontOfSize:0]];                          \
266     [o_label sizeToFit];                                                    \
267 }
268
269 #define ADD_TEXTFIELD( o_textfield, superFrame, x_offset, my_y_offset,      \
270     my_width, tooltip, init_value )                                         \
271 {                                                                           \
272     NSRect s_rc = superFrame;                                               \
273     s_rc.origin.x = x_offset;                                               \
274     s_rc.origin.y = my_y_offset;                                            \
275     s_rc.size.height = 22;                                                  \
276     s_rc.size.width = my_width;                                             \
277     o_textfield = [[[NSTextField alloc] initWithFrame: s_rc] retain];       \
278     [o_textfield setFont:[NSFont systemFontOfSize:0]];                      \
279     [o_textfield setToolTip: tooltip];                                      \
280     [o_textfield setStringValue: init_value];                               \
281 }
282
283 #define ADD_COMBO( o_combo, superFrame, x_offset, my_y_offset, x2_offset,   \
284     tooltip )                                                               \
285 {                                                                           \
286     NSRect s_rc = superFrame;                                               \
287     s_rc.origin.x = x_offset + 2;                                           \
288     s_rc.origin.y = my_y_offset;                                            \
289     s_rc.size.height = 26;                                                  \
290     s_rc.size.width = superFrame.size.width + 2 - s_rc.origin.x -           \
291         (x2_offset);                                                        \
292     o_combo = [[[NSComboBox alloc] initWithFrame: s_rc] retain];            \
293     [o_combo setFont:[NSFont systemFontOfSize:0]];                          \
294     [o_combo setToolTip: tooltip];                                          \
295     [o_combo setUsesDataSource:TRUE];                                       \
296     [o_combo setDataSource:self];                                           \
297     [o_combo setNumberOfVisibleItems:10];                                   \
298     [o_combo setCompletes:YES];                                             \
299 }
300
301 #define ADD_RIGHT_BUTTON( o_button, superFrame, x_offset, my_y_offset,      \
302     tooltip, title )                                                        \
303 {                                                                           \
304     NSRect s_rc = superFrame;                                               \
305     o_button = [[[NSButton alloc] initWithFrame: s_rc] retain];             \
306     [o_button setButtonType: NSMomentaryPushInButton];                      \
307     [o_button setBezelStyle: NSRoundedBezelStyle];                          \
308     [o_button setTitle: title];                                             \
309     [o_button setFont:[NSFont systemFontOfSize:0]];                         \
310     [o_button sizeToFit];                                                   \
311     s_rc = [o_button frame];                                                \
312     s_rc.origin.x = superFrame.size.width - [o_button frame].size.width - 6;\
313     s_rc.origin.y = my_y_offset - 6;                                        \
314     s_rc.size.width += 12;                                                  \
315     [o_button setFrame: s_rc];                                              \
316     [o_button setToolTip: tooltip];                                         \
317     [o_button setTarget: self];                                             \
318     [o_button setAction: @selector(openFileDialog:)];                       \
319 }
320
321 #define ADD_POPUP( o_popup, superFrame, x_offset, my_y_offset, x2_offset,   \
322     tooltip )                                                               \
323 {                                                                           \
324     NSRect s_rc = superFrame;                                               \
325     s_rc.origin.x = x_offset - 1;                                           \
326     s_rc.origin.y = my_y_offset;                                            \
327     s_rc.size.height = 26;                                                  \
328     s_rc.size.width = superFrame.size.width + 2 - s_rc.origin.x -           \
329         (x2_offset);                                                        \
330     o_popup = [[[NSPopUpButton alloc] initWithFrame: s_rc] retain];         \
331     [o_popup setFont:[NSFont systemFontOfSize:0]];                          \
332     [o_popup setToolTip: tooltip];                                          \
333 }
334
335 #define ADD_STEPPER( o_stepper, superFrame, x_offset, my_y_offset, tooltip, \
336     lower, higher )                                                         \
337 {                                                                           \
338     NSRect s_rc = superFrame;                                               \
339     s_rc.origin.x = x_offset;                                               \
340     s_rc.origin.y = my_y_offset;                                            \
341     s_rc.size.height = 23;                                                  \
342     s_rc.size.width = 23;                                                   \
343     o_stepper = [[[NSStepper alloc] initWithFrame: s_rc] retain];           \
344     [o_stepper setFont:[NSFont systemFontOfSize:0]];                        \
345     [o_stepper setToolTip: tooltip];                                        \
346     [o_stepper setMaxValue: higher];                                        \
347     [o_stepper setMinValue: lower];                                         \
348     [o_stepper setTarget: self];                                            \
349     [o_stepper setAction: @selector(stepperChanged:)];                      \
350     [o_stepper sendActionOn:NSLeftMouseUpMask | NSLeftMouseDownMask |       \
351         NSLeftMouseDraggedMask];                                            \
352 }
353
354 #define ADD_SLIDER( o_slider, superFrame, x_offset, my_y_offset, my_width,  \
355     tooltip, lower, higher )                                                \
356 {                                                                           \
357     NSRect s_rc = superFrame;                                               \
358     s_rc.origin.x = x_offset;                                               \
359     s_rc.origin.y = my_y_offset;                                            \
360     s_rc.size.height = 21;                                                  \
361     s_rc.size.width = my_width;                                             \
362     o_slider = [[[NSSlider alloc] initWithFrame: s_rc] retain];             \
363     [o_slider setFont:[NSFont systemFontOfSize:0]];                         \
364     [o_slider setToolTip: tooltip];                                         \
365     [o_slider setMaxValue: higher];                                         \
366     [o_slider setMinValue: lower];                                          \
367 }
368
369 #define ADD_CHECKBOX( o_checkbox, superFrame, x_offset, my_y_offset, label, \
370     tooltip, init_value, position )                                         \
371 {                                                                           \
372     NSRect s_rc = superFrame;                                               \
373     s_rc.size.height = 18;                                                  \
374     s_rc.origin.x = x_offset - 2;                                           \
375     s_rc.origin.y = superFrame.size.height - 18 + my_y_offset;              \
376     o_checkbox = [[[NSButton alloc] initWithFrame: s_rc] retain];           \
377     [o_checkbox setFont:[NSFont systemFontOfSize:0]];                       \
378     [o_checkbox setButtonType: NSSwitchButton];                             \
379     [o_checkbox setImagePosition: position];                                \
380     [o_checkbox setIntValue: init_value];                                   \
381     [o_checkbox setTitle: label];                                           \
382     [o_checkbox setToolTip: tooltip];                                       \
383     [o_checkbox sizeToFit];                                                 \
384 }
385
386 #define ADD_CHECKBOX( o_checkbox, superFrame, x_offset, my_y_offset, label, \
387     tooltip, init_value, position )                                         \
388 {                                                                           \
389     NSRect s_rc = superFrame;                                               \
390     s_rc.size.height = 18;                                                  \
391     s_rc.origin.x = x_offset - 2;                                           \
392     s_rc.origin.y = superFrame.size.height - 18 + my_y_offset;              \
393     o_checkbox = [[[NSButton alloc] initWithFrame: s_rc] retain];           \
394     [o_checkbox setFont:[NSFont systemFontOfSize:0]];                       \
395     [o_checkbox setButtonType: NSSwitchButton];                             \
396     [o_checkbox setImagePosition: position];                                \
397     [o_checkbox setIntValue: init_value];                                   \
398     [o_checkbox setTitle: label];                                           \
399     [o_checkbox setToolTip: tooltip];                                       \
400     [o_checkbox sizeToFit];                                                 \
401 }
402
403 @implementation VLCConfigControl
404 - (id)initWithFrame: (NSRect)frame
405 {
406     return [self initWithFrame: frame
407                     item: nil];
408 }
409
410 - (id)initWithFrame: (NSRect)frame
411         item: (module_config_t *)_p_item
412 {
413     self = [super initWithFrame: frame];
414
415     if( self != nil )
416     {
417         p_item = _p_item;
418         psz_name = strdup( p_item->psz_name );
419         o_label = NULL;
420         i_type = p_item->i_type;
421         b_advanced = p_item->b_advanced;
422         [self setAutoresizingMask:NSViewWidthSizable | NSViewMinYMargin ];
423     }
424     return (self);
425 }
426
427 - (void)dealloc
428 {
429     if( o_label ) [o_label release];
430     if( psz_name ) free( psz_name );
431     [super dealloc];
432 }
433
434 + (int)calcVerticalMargin: (int)i_curItem lastItem: (int)i_lastItem
435 {
436     int i_margin;
437     switch( i_curItem )
438     {
439     case CONFIG_ITEM_STRING:
440         switch( i_lastItem )
441         {
442         case CONFIG_ITEM_STRING:
443             i_margin = 8;
444             break;
445         case CONFIG_ITEM_STRING_LIST:
446             i_margin = 7;
447             break;
448         case CONFIG_ITEM_FILE:
449             i_margin = 8;
450             break;
451         case CONFIG_ITEM_MODULE:
452             i_margin = 4;
453             break;
454         case CONFIG_ITEM_INTEGER:
455             i_margin = 7;
456             break;
457         case CONFIG_ITEM_RANGED_INTEGER:
458             i_margin = 5;
459             break;
460         case CONFIG_ITEM_BOOL:
461             i_margin = 7;
462             break;
463         case CONFIG_ITEM_KEY_BEFORE_10_3:
464             i_margin = 7;
465             break;
466         case CONFIG_ITEM_KEY_AFTER_10_3:
467             i_margin = 6;
468             break;
469         case CONFIG_ITEM_MODULE_LIST:
470             i_margin = 8;
471             break;
472         default:
473             i_margin = 20;
474             break;
475         }
476         break;
477     case CONFIG_ITEM_STRING_LIST:
478         switch( i_lastItem )
479         {
480         case CONFIG_ITEM_STRING:
481             i_margin = 8;
482             break;
483         case CONFIG_ITEM_STRING_LIST:
484             i_margin = 7;
485             break;
486         case CONFIG_ITEM_FILE:
487             i_margin = 6;
488             break;
489         case CONFIG_ITEM_MODULE:
490             i_margin = 4;
491             break;
492         case CONFIG_ITEM_INTEGER:
493             i_margin = 7;
494             break;
495         case CONFIG_ITEM_RANGED_INTEGER:
496             i_margin = 5;
497             break;
498         case CONFIG_ITEM_BOOL:
499             i_margin = 7;
500             break;
501         case CONFIG_ITEM_KEY_BEFORE_10_3:
502             i_margin = 7;
503             break;
504         case CONFIG_ITEM_KEY_AFTER_10_3:
505             i_margin = 6;
506             break;
507         case CONFIG_ITEM_MODULE_LIST:
508             i_margin = 8;
509             break;
510         default:
511             i_margin = 20;
512             break;
513         }
514         break;
515     case CONFIG_ITEM_FILE:
516         switch( i_lastItem )
517         {
518         case CONFIG_ITEM_STRING:
519             i_margin = 13;
520             break;
521         case CONFIG_ITEM_STRING_LIST:
522             i_margin = 10;
523             break;
524         case CONFIG_ITEM_FILE:
525             i_margin = 9;
526             break;
527         case CONFIG_ITEM_MODULE:
528             i_margin = 9;
529             break;
530         case CONFIG_ITEM_INTEGER:
531             i_margin = 10;
532             break;
533         case CONFIG_ITEM_RANGED_INTEGER:
534             i_margin = 8;
535             break;
536         case CONFIG_ITEM_BOOL:
537             i_margin = 10;
538             break;
539         case CONFIG_ITEM_KEY_BEFORE_10_3:
540             i_margin = 10;
541             break;
542         case CONFIG_ITEM_KEY_AFTER_10_3:
543             i_margin = 9;
544             break;
545         case CONFIG_ITEM_MODULE_LIST:
546             i_margin = 11;
547             break;
548         default:
549             i_margin = 23;
550             break;
551         }
552         break;
553     case CONFIG_ITEM_MODULE:
554         switch( i_lastItem )
555         {
556         case CONFIG_ITEM_STRING:
557             i_margin = 8;
558             break;
559         case CONFIG_ITEM_STRING_LIST:
560             i_margin = 7;
561             break;
562         case CONFIG_ITEM_FILE:
563             i_margin = 6;
564             break;
565         case CONFIG_ITEM_MODULE:
566             i_margin = 5;
567             break;
568         case CONFIG_ITEM_INTEGER:
569             i_margin = 7;
570             break;
571         case CONFIG_ITEM_RANGED_INTEGER:
572             i_margin = 6;
573             break;
574         case CONFIG_ITEM_BOOL:
575             i_margin = 8;
576             break;
577         case CONFIG_ITEM_KEY_BEFORE_10_3:
578             i_margin = 8;
579             break;
580         case CONFIG_ITEM_KEY_AFTER_10_3:
581             i_margin = 7;
582             break;
583         case CONFIG_ITEM_MODULE_LIST:
584             i_margin = 9;
585             break;
586         default:
587             i_margin = 20;
588             break;
589         }
590         break;
591     case CONFIG_ITEM_INTEGER:
592         switch( i_lastItem )
593         {
594         case CONFIG_ITEM_STRING:
595             i_margin = 8;
596             break;
597         case CONFIG_ITEM_STRING_LIST:
598             i_margin = 7;
599             break;
600         case CONFIG_ITEM_FILE:
601             i_margin = 6;
602             break;
603         case CONFIG_ITEM_MODULE:
604             i_margin = 4;
605             break;
606         case CONFIG_ITEM_INTEGER:
607             i_margin = 7;
608             break;
609         case CONFIG_ITEM_RANGED_INTEGER:
610             i_margin = 5;
611             break;
612         case CONFIG_ITEM_BOOL:
613             i_margin = 7;
614             break;
615         case CONFIG_ITEM_KEY_BEFORE_10_3:
616             i_margin = 7;
617             break;
618         case CONFIG_ITEM_KEY_AFTER_10_3:
619             i_margin = 6;
620             break;
621         case CONFIG_ITEM_MODULE_LIST:
622             i_margin = 8;
623             break;
624         default:
625             i_margin = 20;
626             break;
627         }
628         break;
629     case CONFIG_ITEM_RANGED_INTEGER:
630         switch( i_lastItem )
631         {
632         case CONFIG_ITEM_STRING:
633             i_margin = 8;
634             break;
635         case CONFIG_ITEM_STRING_LIST:
636             i_margin = 7;
637             break;
638         case CONFIG_ITEM_FILE:
639             i_margin = 8;
640             break;
641         case CONFIG_ITEM_MODULE:
642             i_margin = 4;
643             break;
644         case CONFIG_ITEM_INTEGER:
645             i_margin = 7;
646             break;
647         case CONFIG_ITEM_RANGED_INTEGER:
648             i_margin = 5;
649             break;
650         case CONFIG_ITEM_BOOL:
651             i_margin = 7;
652             break;
653         case CONFIG_ITEM_KEY_BEFORE_10_3:
654             i_margin = 7;
655             break;
656         case CONFIG_ITEM_KEY_AFTER_10_3:
657             i_margin = 6;
658             break;
659         case CONFIG_ITEM_MODULE_LIST:
660             i_margin = 8;
661             break;
662         default:
663             i_margin = 20;
664             break;
665         }
666         break;
667     case CONFIG_ITEM_BOOL:
668         switch( i_lastItem )
669         {
670         case CONFIG_ITEM_STRING:
671             i_margin = 6;
672             break;
673         case CONFIG_ITEM_STRING_LIST:
674             i_margin = 5;
675             break;
676         case CONFIG_ITEM_FILE:
677             i_margin = 4;
678             break;
679         case CONFIG_ITEM_MODULE:
680             i_margin = 2;
681             break;
682         case CONFIG_ITEM_INTEGER:
683             i_margin = 5;
684             break;
685         case CONFIG_ITEM_RANGED_INTEGER:
686             i_margin = 3;
687             break;
688         case CONFIG_ITEM_BOOL:
689             i_margin = 3;
690             break;
691         case CONFIG_ITEM_KEY_BEFORE_10_3:
692             i_margin = 3;
693             break;
694         case CONFIG_ITEM_KEY_AFTER_10_3:
695             i_margin = 2;
696             break;
697         case CONFIG_ITEM_MODULE_LIST:
698             i_margin = 6;
699             break;
700         default:
701             i_margin = 18;
702             break;
703         }
704         break;
705     case CONFIG_ITEM_KEY_BEFORE_10_3:
706         switch( i_lastItem )
707         {
708         case CONFIG_ITEM_STRING:
709             i_margin = 6;
710             break;
711         case CONFIG_ITEM_STRING_LIST:
712             i_margin = 5;
713             break;
714         case CONFIG_ITEM_FILE:
715             i_margin = 4;
716             break;
717         case CONFIG_ITEM_MODULE:
718             i_margin = 2;
719             break;
720         case CONFIG_ITEM_INTEGER:
721             i_margin = 5;
722             break;
723         case CONFIG_ITEM_RANGED_INTEGER:
724             i_margin = 3;
725             break;
726         case CONFIG_ITEM_BOOL:
727             i_margin = 3;
728             break;
729         case CONFIG_ITEM_KEY_BEFORE_10_3:
730             i_margin = 10;
731             break;
732         case CONFIG_ITEM_KEY_AFTER_10_3:
733             i_margin = 6;
734             break;
735         case CONFIG_ITEM_MODULE_LIST:
736             i_margin = 6;
737             break;
738         default:
739             i_margin = 18;
740             break;
741         }
742         break;
743     case CONFIG_ITEM_KEY_AFTER_10_3:
744         switch( i_lastItem )
745         {
746         case CONFIG_ITEM_STRING:
747             i_margin = 8;
748             break;
749         case CONFIG_ITEM_STRING_LIST:
750             i_margin = 7;
751             break;
752         case CONFIG_ITEM_FILE:
753             i_margin = 6;
754             break;
755         case CONFIG_ITEM_MODULE:
756             i_margin = 6;
757             break;
758         case CONFIG_ITEM_INTEGER:
759             i_margin = 7;
760             break;
761         case CONFIG_ITEM_RANGED_INTEGER:
762             i_margin = 5;
763             break;
764         case CONFIG_ITEM_BOOL:
765             i_margin = 7;
766             break;
767         case CONFIG_ITEM_KEY_BEFORE_10_3:
768             i_margin = 7;
769             break;
770         case CONFIG_ITEM_KEY_AFTER_10_3:
771             i_margin = 8;
772             break;
773         case CONFIG_ITEM_MODULE_LIST:
774             i_margin = 10;
775             break;
776         default:
777             i_margin = 20;
778             break;
779         }
780         break;
781     case CONFIG_ITEM_MODULE_LIST:
782         switch( i_lastItem )
783         {
784         case CONFIG_ITEM_STRING:
785             i_margin = 10;
786             break;
787         case CONFIG_ITEM_STRING_LIST:
788             i_margin = 7;
789             break;
790         case CONFIG_ITEM_FILE:
791             i_margin = 6;
792             break;
793         case CONFIG_ITEM_MODULE:
794             i_margin = 6;
795             break;
796         case CONFIG_ITEM_INTEGER:
797             i_margin = 9;
798             break;
799         case CONFIG_ITEM_RANGED_INTEGER:
800             i_margin = 5;
801             break;
802         case CONFIG_ITEM_BOOL:
803             i_margin = 7;
804             break;
805         case CONFIG_ITEM_KEY_BEFORE_10_3:
806             i_margin = 7;
807             break;
808         case CONFIG_ITEM_KEY_AFTER_10_3:
809             i_margin = 5;
810             break;
811         case CONFIG_ITEM_MODULE_LIST:
812             i_margin = 8;
813             break;
814         default:
815             i_margin = 20;
816             break;
817         }
818         break;
819     default:
820         i_margin = 20;
821         break;
822     }
823     return i_margin;
824 }
825
826 + (VLCConfigControl *)newControl: (module_config_t *)_p_item
827                       withView: (NSView *)o_parent_view
828                       yOffset:(int) i_yPos
829                       lastItem: (int) i_lastItem
830 {
831     VLCConfigControl *p_control = NULL;
832     switch( _p_item->i_type )
833     {
834     case CONFIG_ITEM_STRING:
835         if( !_p_item->i_list )
836         {
837             p_control = [[StringConfigControl alloc]
838                     initWithItem: _p_item
839                     withView: o_parent_view
840                     withVerticalOffset: i_yPos
841                     withLastItem: i_lastItem];
842         }
843         else
844         {
845             p_control = [[StringListConfigControl alloc]
846                     initWithItem: _p_item
847                     withView: o_parent_view
848                     withVerticalOffset: i_yPos
849                     withLastItem: i_lastItem];
850         }
851         break;
852     case CONFIG_ITEM_FILE:
853     case CONFIG_ITEM_DIRECTORY:
854         p_control = [[FileConfigControl alloc]
855                     initWithItem: _p_item
856                     withView: o_parent_view
857                     withVerticalOffset: i_yPos
858                     withLastItem: i_lastItem];
859         break;
860     case CONFIG_ITEM_MODULE:
861     case CONFIG_ITEM_MODULE_CAT:
862         p_control = [[ModuleConfigControl alloc]
863                     initWithItem: _p_item
864                     withView: o_parent_view
865                     withVerticalOffset: i_yPos
866                     withLastItem: i_lastItem];
867         break;
868     case CONFIG_ITEM_INTEGER:
869         if( _p_item->i_list )
870         {
871             p_control = [[IntegerListConfigControl alloc]
872                         initWithItem: _p_item
873                         withView: o_parent_view
874                         withVerticalOffset: i_yPos
875                         withLastItem: i_lastItem];
876         }
877         else if( _p_item->i_min != 0 || _p_item->i_max != 0 )
878         {
879             p_control = [[RangedIntegerConfigControl alloc]
880                         initWithItem: _p_item
881                         withView: o_parent_view
882                         withVerticalOffset: i_yPos
883                         withLastItem: i_lastItem];
884         }
885         else
886         {
887             p_control = [[IntegerConfigControl alloc]
888                         initWithItem: _p_item
889                         withView: o_parent_view
890                         withVerticalOffset: i_yPos
891                         withLastItem: i_lastItem];
892         }
893         break;
894     case CONFIG_ITEM_BOOL:
895         p_control = [[BoolConfigControl alloc]
896                     initWithItem: _p_item
897                     withView: o_parent_view
898                     withVerticalOffset: i_yPos
899                     withLastItem: i_lastItem];
900         break;
901     case CONFIG_ITEM_FLOAT:
902         if( _p_item->f_min != 0 || _p_item->f_max != 0 )
903         {
904             p_control = [[RangedFloatConfigControl alloc]
905                         initWithItem: _p_item
906                         withView: o_parent_view
907                         withVerticalOffset: i_yPos
908                         withLastItem: i_lastItem];
909         }
910         else
911         {
912             p_control = [[FloatConfigControl alloc]
913                         initWithItem: _p_item
914                         withView: o_parent_view
915                         withVerticalOffset: i_yPos
916                         withLastItem: i_lastItem];
917         }
918         break;
919     case CONFIG_ITEM_KEY:
920         if( MACOS_VERSION < 10.3 )
921         {
922             p_control = [[KeyConfigControlBefore103 alloc]
923                         initWithItem: _p_item
924                         withView: o_parent_view
925                         withVerticalOffset: i_yPos
926                         withLastItem: i_lastItem];
927         }
928         else
929         {
930             p_control = [[KeyConfigControlAfter103 alloc]
931                         initWithItem: _p_item
932                         withView: o_parent_view
933                         withVerticalOffset: i_yPos
934                         withLastItem: i_lastItem];
935         }
936         break;
937     case CONFIG_ITEM_MODULE_LIST:
938     case CONFIG_ITEM_MODULE_LIST_CAT:
939         p_control = [[ModuleListConfigControl alloc]
940                     initWithItem: _p_item
941                     withView: o_parent_view
942                     withVerticalOffset: i_yPos
943                     withLastItem: i_lastItem];
944         break;
945     default:
946         break;
947     }
948     return p_control;
949 }
950
951 - (NSString *)getName
952 {
953     return [[VLCMain sharedInstance] localizedString: psz_name];
954 }
955
956 - (int)getType
957 {
958     return i_type;
959 }
960
961 - (BOOL)isAdvanced
962 {
963     return b_advanced;
964 }
965
966 - (int)intValue
967 {
968     return 0;
969 }
970
971 - (float)floatValue
972 {
973     return 0;
974 }
975
976 - (char *)stringValue
977 {
978     return NULL;
979 }
980
981 - (void)applyChanges
982 {
983     vlc_value_t val;
984     switch( p_item->i_type )
985     {
986     case CONFIG_ITEM_STRING:
987     case CONFIG_ITEM_FILE:
988     case CONFIG_ITEM_DIRECTORY:
989     case CONFIG_ITEM_MODULE:
990     case CONFIG_ITEM_MODULE_LIST:
991     case CONFIG_ITEM_MODULE_LIST_CAT:
992 fprintf( stderr, "Applying %s to %s\n" , [self stringValue], psz_name );
993         config_PutPsz( VLCIntf, psz_name, [self stringValue] );
994         break;
995     case CONFIG_ITEM_KEY:
996         /* So you don't need to restart to have the changes take effect */
997 fprintf( stderr, "Applying %d to %s\n" , [self intValue], psz_name );
998         val.i_int = [self intValue];
999         var_Set( VLCIntf->p_vlc, psz_name, val );
1000     case CONFIG_ITEM_INTEGER:
1001     case CONFIG_ITEM_BOOL:
1002 fprintf( stderr, "Applying %d to %s\n" , [self intValue], psz_name );
1003         config_PutInt( VLCIntf, psz_name, [self intValue] );
1004         break;
1005     case CONFIG_ITEM_FLOAT:
1006 fprintf( stderr, "Applying %f to %s\n" , [self floatValue], psz_name );
1007         config_PutFloat( VLCIntf, psz_name, [self floatValue] );
1008         break;
1009     }
1010 }
1011 @end
1012
1013 @implementation StringConfigControl
1014 - (id) initWithItem: (module_config_t *)_p_item
1015            withView: (NSView *)o_parent_view
1016            withVerticalOffset: (int)i_yPos
1017            withLastItem: (int)i_lastItem
1018 {
1019     NSRect mainFrame = [o_parent_view frame];
1020     NSString *o_labelString, *o_textfieldString, *o_textfieldTooltip;
1021     mainFrame.size.height = 22;
1022     mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN;
1023     mainFrame.origin.x = LEFTMARGIN;
1024     mainFrame.origin.y = i_yPos;
1025
1026     if( [super initWithFrame: mainFrame item: _p_item] != nil )
1027     {
1028         /* add the label */
1029         if( p_item->psz_text )
1030             o_labelString = [[VLCMain sharedInstance]
1031                                 localizedString: p_item->psz_text];
1032         else
1033             o_labelString = [NSString stringWithString:@""];
1034         ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString )
1035         [o_label setAutoresizingMask:NSViewNotSizable ];
1036         [self addSubview: o_label];
1037
1038         /* build the textfield */
1039         o_textfieldTooltip = [[VLCMain sharedInstance] wrapString:
1040             [[VLCMain sharedInstance] localizedString: p_item->psz_longtext]
1041                                          toWidth: PREFS_WRAP];
1042         if( p_item->psz_value )
1043             o_textfieldString = [[VLCMain sharedInstance]
1044                                     localizedString: p_item->psz_value];
1045         else
1046             o_textfieldString = [NSString stringWithString: @""];
1047         ADD_TEXTFIELD( o_textfield, mainFrame, [o_label frame].size.width + 2,
1048                         0, mainFrame.size.width - [o_label frame].size.width -
1049                         2, o_textfieldTooltip, o_textfieldString )
1050         [o_textfield setAutoresizingMask:NSViewWidthSizable ];
1051         [self addSubview: o_textfield];
1052     }
1053     return self;
1054 }
1055
1056 - (void)dealloc
1057 {
1058     [o_label release];
1059     [o_textfield release];
1060     [super dealloc];
1061 }
1062
1063 - (char *)stringValue
1064 {
1065     return strdup( [[VLCMain sharedInstance] delocalizeString:
1066                         [o_textfield stringValue]] );
1067 }
1068 @end
1069
1070 @implementation StringListConfigControl
1071 - (id) initWithItem: (module_config_t *)_p_item
1072            withView: (NSView *)o_parent_view
1073            withVerticalOffset: (int)i_yPos
1074            withLastItem: (int)i_lastItem
1075 {
1076     NSRect mainFrame = [o_parent_view frame];
1077     NSString *o_labelString, *o_textfieldTooltip;
1078     mainFrame.size.height = 22;
1079     mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN + 1;
1080     mainFrame.origin.x = LEFTMARGIN;
1081     mainFrame.origin.y = i_yPos;
1082
1083     if( [super initWithFrame: mainFrame item: _p_item] != nil )
1084     {
1085         int i_index;
1086         /* add the label */
1087         if( p_item->psz_text )
1088             o_labelString = [[VLCMain sharedInstance]
1089                                 localizedString: p_item->psz_text];
1090         else
1091             o_labelString = [NSString stringWithString:@""];
1092         ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString )
1093         [o_label setAutoresizingMask:NSViewNotSizable ];
1094         [self addSubview: o_label];
1095
1096         /* build the textfield */
1097         o_textfieldTooltip = [[VLCMain sharedInstance] wrapString:
1098             [[VLCMain sharedInstance]
1099                 localizedString: p_item->psz_longtext ] toWidth: PREFS_WRAP];
1100         ADD_COMBO( o_combo, mainFrame, [o_label frame].size.width,
1101             -2, 0, o_textfieldTooltip )
1102         [o_combo setAutoresizingMask:NSViewWidthSizable ];
1103         for( i_index = 0; i_index < p_item->i_list; i_index++ )
1104             if( p_item->psz_value &&
1105                 !strcmp( p_item->psz_value, p_item->ppsz_list[i_index] ) )
1106                 [o_combo selectItemAtIndex: i_index];
1107         [self addSubview: o_combo];
1108     }
1109     return self;
1110 }
1111
1112 - (void)dealloc
1113 {
1114     [o_combo release];
1115     [super dealloc];
1116 }
1117
1118 - (char *)stringValue
1119 {
1120     if( [o_combo indexOfSelectedItem] >= 0 )
1121         return strdup( p_item->ppsz_list[[o_combo indexOfSelectedItem]] );
1122     else
1123         return strdup( [[VLCMain sharedInstance]
1124                             delocalizeString: [o_combo stringValue]] );
1125 }
1126 @end
1127
1128 @implementation StringListConfigControl (NSComboBoxDataSource)
1129 - (int)numberOfItemsInComboBox:(NSComboBox *)aComboBox
1130 {
1131         return p_item->i_list;
1132 }
1133
1134 - (id)comboBox:(NSComboBox *)aComboBox objectValueForItemAtIndex:(int)i_index
1135 {
1136     if( p_item->ppsz_list_text && p_item->ppsz_list_text[i_index] )
1137     {
1138         return [[VLCMain sharedInstance]
1139                     localizedString: p_item->ppsz_list_text[i_index]];
1140     } else return [[VLCMain sharedInstance]
1141                     localizedString: p_item->ppsz_list[i_index]];
1142 }
1143 @end
1144
1145 @implementation FileConfigControl
1146 - (id) initWithItem: (module_config_t *)_p_item
1147            withView: (NSView *)o_parent_view
1148            withVerticalOffset: (int)i_yPos
1149            withLastItem: (int)i_lastItem
1150 {
1151     NSRect mainFrame = [o_parent_view frame];
1152     NSString *o_labelString, *o_buttonTooltip, *o_textfieldString;
1153     NSString *o_textfieldTooltip;
1154     mainFrame.size.height = 46;
1155     mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN;
1156     mainFrame.origin.x = LEFTMARGIN;
1157     mainFrame.origin.y = i_yPos;
1158
1159     if( [super initWithFrame: mainFrame item: _p_item] != nil )
1160     {
1161         /* is it a directory */
1162         b_directory = ( [self getType] == CONFIG_ITEM_DIRECTORY ) ? YES : NO;
1163
1164         /* add the label */
1165         if( p_item->psz_text )
1166             o_labelString = [[VLCMain sharedInstance]
1167                                 localizedString: p_item->psz_text];
1168         else
1169             o_labelString = [NSString stringWithString:@""];
1170         ADD_LABEL( o_label, mainFrame, 0, 3, o_labelString )
1171         [o_label setAutoresizingMask:NSViewNotSizable ];
1172         [self addSubview: o_label];
1173
1174         /* build the button */
1175         o_buttonTooltip = [[VLCMain sharedInstance]
1176                 wrapString: [[VLCMain sharedInstance]
1177                 localizedString: p_item->psz_longtext ] toWidth: PREFS_WRAP];
1178         ADD_RIGHT_BUTTON( o_button, mainFrame, 0, 0, o_buttonTooltip,
1179                             _NS("Browse...") )
1180         [o_button setAutoresizingMask:NSViewMinXMargin ];
1181         [self addSubview: o_button];
1182
1183         /* build the textfield */
1184         o_textfieldTooltip = [[VLCMain sharedInstance] wrapString:
1185             [[VLCMain sharedInstance]
1186                 localizedString: p_item->psz_longtext ] toWidth: PREFS_WRAP];
1187         if( p_item->psz_value )
1188             o_textfieldString = [[VLCMain sharedInstance]
1189                                     localizedString: p_item->psz_value];
1190         else
1191             o_textfieldString = [NSString stringWithString: @""];
1192         ADD_TEXTFIELD( o_textfield, mainFrame, 12, 2, mainFrame.size.width -
1193                         8 - [o_button frame].size.width,
1194                         o_textfieldTooltip, o_textfieldString )
1195         [o_textfield setAutoresizingMask:NSViewWidthSizable ];
1196         [self addSubview: o_textfield];
1197     }
1198     return self;
1199 }
1200
1201 - (void)dealloc
1202 {
1203     [o_textfield release];
1204     [o_button release];
1205     [super dealloc];
1206 }
1207
1208 - (IBAction)openFileDialog: (id)sender
1209 {
1210     NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
1211
1212     [o_open_panel setTitle: (b_directory)?
1213         _NS("Select a directory"):_NS("Select a file")];
1214     [o_open_panel setPrompt: _NS("Select")];
1215     [o_open_panel setAllowsMultipleSelection: NO];
1216     [o_open_panel setCanChooseFiles: !b_directory];
1217     [o_open_panel setCanChooseDirectories: b_directory];
1218     [o_open_panel beginSheetForDirectory:nil
1219         file:nil
1220         types:nil
1221         modalForWindow:[sender window]
1222         modalDelegate: self
1223         didEndSelector: @selector(pathChosenInPanel: 
1224                         withReturn:
1225                         contextInfo:)
1226         contextInfo: nil];
1227 }
1228
1229 - (void)pathChosenInPanel:(NSOpenPanel *)o_sheet
1230     withReturn:(int)i_return_code contextInfo:(void  *)o_context_info
1231 {
1232     if( i_return_code == NSOKButton )
1233     {
1234         NSString *o_path = [[o_sheet filenames] objectAtIndex: 0];
1235         [o_textfield setStringValue: o_path];
1236     }
1237 }
1238
1239 - (char *)stringValue
1240 {
1241     if( [[o_textfield stringValue] length] != 0)
1242         return strdup( [[o_textfield stringValue] fileSystemRepresentation] );
1243     else
1244         return NULL;
1245 }
1246 @end
1247
1248 @implementation ModuleConfigControl
1249 - (id) initWithItem: (module_config_t *)_p_item
1250            withView: (NSView *)o_parent_view
1251            withVerticalOffset: (int)i_yPos
1252            withLastItem: (int)i_lastItem
1253 {
1254     NSRect mainFrame = [o_parent_view frame];
1255     NSString *o_labelString, *o_popupTooltip;
1256     mainFrame.size.height = 22;
1257     mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN + 1;
1258     mainFrame.origin.x = LEFTMARGIN;
1259     mainFrame.origin.y = i_yPos;
1260
1261     if( [super initWithFrame: mainFrame item: _p_item] != nil )
1262     {
1263         int i_index;
1264         vlc_list_t *p_list;
1265         module_t *p_parser;
1266         /* add the label */
1267         if( p_item->psz_text )
1268             o_labelString = [[VLCMain sharedInstance]
1269                                 localizedString: p_item->psz_text];
1270         else
1271             o_labelString = [NSString stringWithString:@""];
1272         ADD_LABEL( o_label, mainFrame, 0, -1, o_labelString )
1273         [o_label setAutoresizingMask:NSViewNotSizable ];
1274         [self addSubview: o_label];
1275
1276         /* build the popup */
1277         o_popupTooltip = [[VLCMain sharedInstance] wrapString:
1278             [[VLCMain sharedInstance]
1279                 localizedString: p_item->psz_longtext ] toWidth: PREFS_WRAP];
1280         ADD_POPUP( o_popup, mainFrame, [o_label frame].size.width,
1281             -2, 0, o_popupTooltip )
1282         [o_popup setAutoresizingMask:NSViewWidthSizable ];
1283         [o_popup addItemWithTitle: _NS("Default")];
1284         [[o_popup lastItem] setTag: -1];
1285         [o_popup selectItem: [o_popup lastItem]];
1286
1287         /* build a list of available modules */
1288         p_list = vlc_list_find( VLCIntf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
1289         for( i_index = 0; i_index < p_list->i_count; i_index++ )
1290         {
1291             p_parser = (module_t *)p_list->p_values[i_index].p_object ;
1292             if( p_item->i_type == CONFIG_ITEM_MODULE )
1293             {
1294                 if( !strcmp( p_parser->psz_capability,
1295                             p_item->psz_type ) )
1296                 {
1297                     NSString *o_description = [[VLCMain sharedInstance]
1298                         localizedString: p_parser->psz_longname];
1299                     [o_popup addItemWithTitle: o_description];
1300
1301                     if( p_item->psz_value &&
1302                 !strcmp( p_item->psz_value, p_parser->psz_object_name ) )
1303                         [o_popup selectItem:[o_popup lastItem]];
1304                 }
1305             }
1306             else
1307             {
1308                 module_config_t *p_config;
1309                 if( !strcmp( p_parser->psz_object_name, "main" ) )
1310                       continue;
1311
1312                 p_config = p_parser->p_config;
1313                 if( p_config ) do
1314                 {
1315                     /* Hack: required subcategory is stored in i_min */
1316                     if( p_config->i_type == CONFIG_SUBCATEGORY &&
1317                         p_config->i_value == p_item->i_min )
1318                     {
1319                         NSString *o_description = [[VLCMain sharedInstance]
1320                             localizedString: p_parser->psz_longname];
1321                         [o_popup addItemWithTitle: o_description];
1322
1323                         if( p_item->psz_value && !strcmp(p_item->psz_value,
1324                                                 p_parser->psz_object_name) )
1325                             [o_popup selectItem:[o_popup lastItem]];
1326                     }
1327                 } while( p_config->i_type != CONFIG_HINT_END && p_config++ );
1328             }
1329         }
1330         vlc_list_release( p_list );
1331         [self addSubview: o_popup];
1332     }
1333     return self;
1334 }
1335
1336 - (void)dealloc
1337 {
1338     [o_popup release];
1339     [super dealloc];
1340 }
1341
1342 - (char *)stringValue
1343 {
1344     NSString *newval = [o_popup titleOfSelectedItem];
1345     char *returnval = NULL;
1346     int i_index;
1347     vlc_list_t *p_list;
1348     module_t *p_parser;
1349
1350     p_list = vlc_list_find( VLCIntf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
1351     for( i_index = 0; i_index < p_list->i_count; i_index++ )
1352     {
1353         p_parser = (module_t *)p_list->p_values[i_index].p_object ;
1354         if( p_item->i_type == CONFIG_ITEM_MODULE )
1355         {
1356             if( !strcmp( p_parser->psz_capability,
1357                     p_item->psz_type ) )
1358             {
1359                 NSString *o_description = [[VLCMain sharedInstance]
1360                     localizedString: p_parser->psz_longname];
1361                 if( [newval isEqualToString: o_description] )
1362                 {
1363                     returnval = strdup(p_parser->psz_object_name);
1364                     break;
1365                 }
1366             }
1367         }
1368         else
1369         {
1370             module_config_t *p_config;
1371             if( !strcmp( p_parser->psz_object_name, "main" ) )
1372                   continue;
1373
1374             p_config = p_parser->p_config;
1375             if( p_config ) do
1376             {
1377                 /* Hack: required subcategory is stored in i_min */
1378                 if( p_config->i_type == CONFIG_SUBCATEGORY &&
1379                     p_config->i_value == p_item->i_min )
1380                 {
1381                     NSString *o_description = [[VLCMain sharedInstance]
1382                         localizedString: p_parser->psz_longname];
1383                     if( [newval isEqualToString: o_description] )
1384                     {
1385                         returnval = strdup(p_parser->psz_object_name);
1386                         break;
1387                     }
1388                 }
1389             } while( p_config->i_type != CONFIG_HINT_END && p_config++ );
1390         }
1391     }
1392     vlc_list_release( p_list );
1393     return returnval;
1394 }
1395 @end
1396
1397 @implementation IntegerConfigControl
1398 - (id) initWithItem: (module_config_t *)_p_item
1399            withView: (NSView *)o_parent_view
1400            withVerticalOffset: (int)i_yPos
1401            withLastItem: (int)i_lastItem
1402 {
1403     NSRect mainFrame = [o_parent_view frame];
1404     NSString *o_labelString, *o_tooltip, *o_textfieldString;
1405     mainFrame.size.height = 23;
1406     mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN + 1;
1407     mainFrame.origin.x = LEFTMARGIN;
1408     mainFrame.origin.y = i_yPos;
1409
1410     if( [super initWithFrame: mainFrame item: _p_item] != nil )
1411     {
1412         o_tooltip = [[VLCMain sharedInstance] wrapString:
1413             [[VLCMain sharedInstance]
1414                 localizedString: p_item->psz_longtext ] toWidth: PREFS_WRAP];
1415
1416         /* add the label */
1417         if( p_item->psz_text )
1418             o_labelString = [[VLCMain sharedInstance]
1419                                 localizedString: p_item->psz_text];
1420         else
1421             o_labelString = [NSString stringWithString:@""];
1422         ADD_LABEL( o_label, mainFrame, 0, -2, o_labelString )
1423         [o_label setAutoresizingMask:NSViewNotSizable ];
1424         [self addSubview: o_label];
1425
1426         /* build the stepper */
1427         ADD_STEPPER( o_stepper, mainFrame, mainFrame.size.width - 19,
1428             0, o_tooltip, -1600, 1600)
1429         [o_stepper setIntValue: p_item->i_value];
1430         [o_stepper setAutoresizingMask:NSViewMinXMargin ];
1431         [self addSubview: o_stepper];
1432
1433         /* build the textfield */
1434         if( p_item->psz_value )
1435             o_textfieldString = [[VLCMain sharedInstance]
1436                                     localizedString: p_item->psz_value];
1437         else
1438             o_textfieldString = [NSString stringWithString: @""];
1439         ADD_TEXTFIELD( o_textfield, mainFrame, mainFrame.size.width - 19 - 52,
1440             1, 49, o_tooltip, @"" )
1441         [o_textfield setIntValue: p_item->i_value];
1442         [o_textfield setDelegate: self];
1443         [[NSNotificationCenter defaultCenter] addObserver: self
1444             selector: @selector(textfieldChanged:)
1445             name: NSControlTextDidChangeNotification
1446             object: o_textfield];
1447         [o_textfield setAutoresizingMask:NSViewMinXMargin ];
1448         [self addSubview: o_textfield];
1449     }
1450     return self;
1451 }
1452
1453 - (void)dealloc
1454 {
1455     [o_stepper release];
1456     [o_textfield release];
1457     [super dealloc];
1458 }
1459
1460 - (IBAction)stepperChanged:(id)sender
1461 {
1462     [o_textfield setIntValue: [o_stepper intValue]];
1463 }
1464
1465 - (void)textfieldChanged:(NSNotification *)o_notification
1466 {
1467     [o_stepper setIntValue: [o_textfield intValue]];
1468 }
1469
1470 - (int)intValue
1471 {
1472     return [o_textfield intValue];
1473 }
1474
1475 @end
1476
1477 @implementation IntegerListConfigControl
1478
1479 - (id) initWithItem: (module_config_t *)_p_item
1480            withView: (NSView *)o_parent_view
1481            withVerticalOffset: (int)i_yPos
1482            withLastItem: (int)i_lastItem
1483 {
1484     NSRect mainFrame = [o_parent_view frame];
1485     NSString *o_labelString, *o_textfieldTooltip;
1486     mainFrame.size.height = 22;
1487     mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN + 1;
1488     mainFrame.origin.x = LEFTMARGIN;
1489     mainFrame.origin.y = i_yPos;
1490
1491     if( [super initWithFrame: mainFrame item: _p_item] != nil )
1492     {
1493         int i_index;
1494         /* add the label */
1495         if( p_item->psz_text )
1496             o_labelString = [[VLCMain sharedInstance]
1497                 localizedString: p_item->psz_text];
1498         else
1499             o_labelString = [NSString stringWithString:@""];
1500         ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString )
1501         [o_label setAutoresizingMask:NSViewNotSizable ];
1502         [self addSubview: o_label];
1503
1504         /* build the textfield */
1505         o_textfieldTooltip = [[VLCMain sharedInstance] wrapString:
1506             [[VLCMain sharedInstance]
1507                 localizedString: p_item->psz_longtext ] toWidth: PREFS_WRAP];
1508         ADD_COMBO( o_combo, mainFrame, [o_label frame].size.width,
1509             -2, 0, o_textfieldTooltip )
1510         [o_combo setAutoresizingMask:NSViewWidthSizable ];
1511         for( i_index = 0; i_index < p_item->i_list; i_index++ )
1512         {
1513             if( p_item->i_value == p_item->pi_list[i_index] )
1514             {
1515                 [o_combo selectItemAtIndex: i_index];
1516             }
1517         }
1518         [self addSubview: o_combo];
1519     }
1520     return self;
1521 }
1522
1523 - (void)dealloc
1524 {
1525     [o_combo release];
1526     [super dealloc];
1527 }
1528
1529 - (int)intValue
1530 {
1531     if( [o_combo indexOfSelectedItem] >= 0 )
1532         return p_item->pi_list[[o_combo indexOfSelectedItem]];
1533     else
1534         return [o_combo intValue];
1535 }
1536 @end
1537
1538 @implementation IntegerListConfigControl (NSComboBoxDataSource)
1539 - (int)numberOfItemsInComboBox:(NSComboBox *)aComboBox
1540 {
1541     return p_item->i_list;
1542 }
1543
1544 - (id)comboBox:(NSComboBox *)aComboBox objectValueForItemAtIndex:(int)i_index
1545 {
1546     if( p_item->ppsz_list_text && p_item->ppsz_list_text[i_index] )
1547         return [[VLCMain sharedInstance]
1548                     localizedString: p_item->ppsz_list_text[i_index]];
1549     else
1550         return [NSString stringWithFormat: @"%i", p_item->pi_list[i_index]];
1551 }
1552 @end
1553
1554 @implementation RangedIntegerConfigControl
1555 - (id) initWithItem: (module_config_t *)_p_item
1556            withView: (NSView *)o_parent_view
1557            withVerticalOffset: (int)i_yPos
1558            withLastItem: (int)i_lastItem
1559 {
1560     NSRect mainFrame = [o_parent_view frame];
1561     NSString *o_labelString, *o_tooltip;
1562     mainFrame.size.height = 50;
1563     mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN;
1564     mainFrame.origin.x = LEFTMARGIN;
1565     mainFrame.origin.y = i_yPos;
1566
1567     if( [super initWithFrame: mainFrame item: _p_item] != nil )
1568     {
1569         /* add the label */
1570         if( p_item->psz_text )
1571             o_labelString = [[VLCMain sharedInstance]
1572                                 localizedString: p_item->psz_text];
1573         else
1574             o_labelString = [NSString stringWithString:@""];
1575         ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString )
1576         [o_label setAutoresizingMask:NSViewNotSizable ];
1577         [self addSubview: o_label];
1578
1579         /* build the textfield */
1580         o_tooltip = [[VLCMain sharedInstance] wrapString:
1581             [[VLCMain sharedInstance]
1582                 localizedString: p_item->psz_longtext ] toWidth: PREFS_WRAP];
1583         ADD_TEXTFIELD( o_textfield, mainFrame, [o_label frame].size.width + 2,
1584             28, 49, o_tooltip, @"" )
1585         [o_textfield setIntValue: p_item->i_value];
1586         [o_textfield setAutoresizingMask:NSViewMaxXMargin ];
1587         [o_textfield setDelegate: self];
1588         [[NSNotificationCenter defaultCenter] addObserver: self
1589             selector: @selector(textfieldChanged:)
1590             name: NSControlTextDidChangeNotification
1591             object: o_textfield];
1592         [self addSubview: o_textfield];
1593
1594         /* build the mintextfield */
1595         ADD_LABEL( o_textfield_min, mainFrame, 12, -30, @"-8888" )
1596         [o_textfield_min setIntValue: p_item->i_min];
1597         [o_textfield_min setAutoresizingMask:NSViewMaxXMargin ];
1598         [self addSubview: o_textfield_min];
1599
1600         /* build the maxtextfield */
1601         ADD_LABEL( o_textfield_max, mainFrame,
1602                     mainFrame.size.width - 31, -30, @"8888" )
1603         [o_textfield_max setIntValue: p_item->i_max];
1604         [o_textfield_max setAutoresizingMask:NSViewMinXMargin ];
1605         [self addSubview: o_textfield_max];
1606
1607         /* build the slider */
1608         ADD_SLIDER( o_slider, mainFrame, [o_textfield_min frame].origin.x +
1609             [o_textfield_min frame].size.width + 6, -1, mainFrame.size.width -
1610             [o_textfield_max frame].size.width -
1611             [o_textfield_max frame].size.width - 14 -
1612             [o_textfield_min frame].origin.x, o_tooltip,
1613             p_item->i_min, p_item->i_max )
1614         [o_slider setIntValue: p_item->i_value];
1615         [o_slider setAutoresizingMask:NSViewWidthSizable ];
1616         [o_slider setTarget: self];
1617         [o_slider setAction: @selector(sliderChanged:)];
1618         [o_slider sendActionOn:NSLeftMouseUpMask | NSLeftMouseDownMask |
1619             NSLeftMouseDraggedMask];
1620         [self addSubview: o_slider];
1621
1622     }
1623     return self;
1624 }
1625
1626 - (void)dealloc
1627 {
1628     [o_textfield release];
1629     [o_textfield_min release];
1630     [o_textfield_max release];
1631     [o_slider release];
1632     [super dealloc];
1633 }
1634
1635 - (IBAction)sliderChanged:(id)sender
1636 {
1637     [o_textfield setIntValue: [o_slider intValue]];
1638 }
1639
1640 - (void)textfieldChanged:(NSNotification *)o_notification
1641 {
1642     [o_slider setIntValue: [o_textfield intValue]];
1643 }
1644
1645 - (int)intValue
1646 {
1647     return [o_slider intValue];
1648 }
1649 @end
1650
1651 @implementation FloatConfigControl
1652 - (id) initWithItem: (module_config_t *)_p_item
1653            withView: (NSView *)o_parent_view
1654            withVerticalOffset: (int)i_yPos
1655            withLastItem: (int)i_lastItem
1656 {
1657     NSRect mainFrame = [o_parent_view frame];
1658     NSString *o_labelString, *o_tooltip, *o_textfieldString;
1659     mainFrame.size.height = 23;
1660     mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN + 1;
1661     mainFrame.origin.x = LEFTMARGIN;
1662     mainFrame.origin.y = i_yPos;
1663
1664     if( [super initWithFrame: mainFrame item: _p_item] != nil )
1665     {
1666         o_tooltip = [[VLCMain sharedInstance] wrapString:
1667             [[VLCMain sharedInstance]
1668                 localizedString: p_item->psz_longtext ] toWidth: PREFS_WRAP];
1669
1670         /* add the label */
1671         if( p_item->psz_text )
1672             o_labelString = [[VLCMain sharedInstance]
1673                                 localizedString: p_item->psz_text];
1674         else
1675             o_labelString = [NSString stringWithString:@""];
1676         ADD_LABEL( o_label, mainFrame, 0, -2, o_labelString )
1677         [o_label setAutoresizingMask:NSViewNotSizable ];
1678         [self addSubview: o_label];
1679
1680         /* build the stepper */
1681         ADD_STEPPER( o_stepper, mainFrame, mainFrame.size.width - 19,
1682             0, o_tooltip, -1600, 1600)
1683         [o_stepper setFloatValue: p_item->f_value];
1684         [o_stepper setAutoresizingMask:NSViewMinXMargin ];
1685         [self addSubview: o_stepper];
1686
1687         /* build the textfield */
1688         if( p_item->psz_value )
1689             o_textfieldString = [[VLCMain sharedInstance]
1690                                     localizedString: p_item->psz_value];
1691         else
1692             o_textfieldString = [NSString stringWithString: @""];
1693         ADD_TEXTFIELD( o_textfield, mainFrame, mainFrame.size.width - 19 - 52,
1694             1, 49, o_tooltip, @"" )
1695         [o_textfield setFloatValue: p_item->f_value];
1696         [o_textfield setDelegate: self];
1697         [[NSNotificationCenter defaultCenter] addObserver: self
1698             selector: @selector(textfieldChanged:)
1699             name: NSControlTextDidChangeNotification
1700             object: o_textfield];
1701         [o_textfield setAutoresizingMask:NSViewMinXMargin ];
1702         [self addSubview: o_textfield];
1703     }
1704     return self;
1705 }
1706
1707 - (void)dealloc
1708 {
1709     [o_stepper release];
1710     [o_textfield release];
1711     [super dealloc];
1712 }
1713
1714 - (IBAction)stepperChanged:(id)sender
1715 {
1716     [o_textfield setFloatValue: [o_stepper floatValue]];
1717 }
1718
1719 - (void)textfieldChanged:(NSNotification *)o_notification
1720 {
1721     [o_stepper setFloatValue: [o_textfield floatValue]];
1722 }
1723
1724 - (int)floatValue
1725 {
1726     return [o_stepper floatValue];
1727 }
1728 @end
1729
1730 @implementation RangedFloatConfigControl
1731 - (id) initWithItem: (module_config_t *)_p_item
1732            withView: (NSView *)o_parent_view
1733            withVerticalOffset: (int)i_yPos
1734            withLastItem: (int)i_lastItem
1735 {
1736     NSRect mainFrame = [o_parent_view frame];
1737     NSString *o_labelString, *o_tooltip;
1738     mainFrame.size.height = 50;
1739     mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN;
1740     mainFrame.origin.x = LEFTMARGIN;
1741     mainFrame.origin.y = i_yPos;
1742
1743     if( [super initWithFrame: mainFrame item: _p_item] != nil )
1744     {
1745         /* add the label */
1746         if( p_item->psz_text )
1747             o_labelString = [[VLCMain sharedInstance]
1748                                 localizedString: p_item->psz_text];
1749         else
1750             o_labelString = [NSString stringWithString:@""];
1751         ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString )
1752         [o_label setAutoresizingMask:NSViewNotSizable ];
1753         [self addSubview: o_label];
1754
1755         /* build the textfield */
1756         o_tooltip = [[VLCMain sharedInstance] wrapString:
1757             [[VLCMain sharedInstance]
1758                 localizedString: p_item->psz_longtext ] toWidth: PREFS_WRAP];
1759         ADD_TEXTFIELD( o_textfield, mainFrame, [o_label frame].size.width + 2,
1760             28, 49, o_tooltip, @"" )
1761         [o_textfield setFloatValue: p_item->f_value];
1762         [o_textfield setAutoresizingMask:NSViewMaxXMargin ];
1763         [o_textfield setDelegate: self];
1764         [[NSNotificationCenter defaultCenter] addObserver: self
1765             selector: @selector(textfieldChanged:)
1766             name: NSControlTextDidChangeNotification
1767             object: o_textfield];
1768         [self addSubview: o_textfield];
1769
1770         /* build the mintextfield */
1771         ADD_LABEL( o_textfield_min, mainFrame, 12, -30, @"-8888" )
1772         [o_textfield_min setFloatValue: p_item->f_min];
1773         [o_textfield_min setAutoresizingMask:NSViewMaxXMargin ];
1774         [self addSubview: o_textfield_min];
1775
1776         /* build the maxtextfield */
1777         ADD_LABEL( o_textfield_max, mainFrame, mainFrame.size.width - 31,
1778             -30, @"8888" )
1779         [o_textfield_max setFloatValue: p_item->f_max];
1780         [o_textfield_max setAutoresizingMask:NSViewMinXMargin ];
1781         [self addSubview: o_textfield_max];
1782
1783         /* build the slider */
1784         ADD_SLIDER( o_slider, mainFrame, [o_textfield_min frame].origin.x +
1785             [o_textfield_min frame].size.width + 6, -1, mainFrame.size.width -
1786             [o_textfield_max frame].size.width -
1787             [o_textfield_max frame].size.width - 14 -
1788             [o_textfield_min frame].origin.x, o_tooltip, p_item->f_min,
1789             p_item->f_max )
1790         [o_slider setFloatValue: p_item->f_value];
1791         [o_slider setAutoresizingMask:NSViewWidthSizable ];
1792         [o_slider setTarget: self];
1793         [o_slider setAction: @selector(sliderChanged:)];
1794         [o_slider sendActionOn:NSLeftMouseUpMask | NSLeftMouseDownMask |
1795             NSLeftMouseDraggedMask];
1796         [self addSubview: o_slider];
1797
1798     }
1799     return self;
1800 }
1801
1802 - (void)dealloc
1803 {
1804     [o_textfield release];
1805     [o_textfield_min release];
1806     [o_textfield_max release];
1807     [o_slider release];
1808     [super dealloc];
1809 }
1810
1811 - (IBAction)sliderChanged:(id)sender
1812 {
1813     [o_textfield setFloatValue: [o_slider floatValue]];
1814 }
1815
1816 - (void)textfieldChanged:(NSNotification *)o_notification
1817 {
1818     [o_slider setFloatValue: [o_textfield floatValue]];
1819 }
1820
1821 - (int)floatValue
1822 {
1823     return [o_slider floatValue];
1824 }
1825
1826 @end
1827
1828 @implementation BoolConfigControl
1829
1830 - (id) initWithItem: (module_config_t *)_p_item
1831            withView: (NSView *)o_parent_view
1832            withVerticalOffset: (int)i_yPos
1833            withLastItem: (int)i_lastItem
1834 {
1835     NSRect mainFrame = [o_parent_view frame];
1836     NSString *o_labelString, *o_tooltip;
1837     mainFrame.size.height = 17;
1838     mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN;
1839     mainFrame.origin.x = LEFTMARGIN;
1840     mainFrame.origin.y = i_yPos;
1841
1842     if( [super initWithFrame: mainFrame item: _p_item] != nil )
1843     {
1844         /* add the checkbox */
1845         if( p_item->psz_text )
1846             o_labelString = [[VLCMain sharedInstance]
1847                                 localizedString: p_item->psz_text];
1848         else
1849             o_labelString = [NSString stringWithString:@""];
1850         o_tooltip = [[VLCMain sharedInstance]
1851             wrapString: [[VLCMain sharedInstance]
1852             localizedString: p_item->psz_longtext ] toWidth: PREFS_WRAP];
1853         ADD_CHECKBOX( o_checkbox, mainFrame, 0, 0, o_labelString,
1854             o_tooltip, p_item->i_value, NSImageRight)
1855         [o_checkbox setAutoresizingMask:NSViewNotSizable ];
1856         [self addSubview: o_checkbox];
1857     }
1858     return self;
1859 }
1860
1861 - (void)dealloc
1862 {
1863     [o_checkbox release];
1864     [super dealloc];
1865 }
1866
1867 - (int)intValue
1868 {
1869     return [o_checkbox intValue];
1870 }
1871
1872 @end
1873
1874 @implementation KeyConfigControlBefore103
1875
1876 - (id) initWithItem: (module_config_t *)_p_item
1877            withView: (NSView *)o_parent_view
1878            withVerticalOffset: (int)i_yPos
1879            withLastItem: (int)i_lastItem
1880 {
1881     NSRect mainFrame = [o_parent_view frame];
1882     NSString *o_labelString, *o_tooltip;
1883     mainFrame.size.height = 37;
1884     mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN + 1;
1885     mainFrame.origin.x = LEFTMARGIN;
1886     mainFrame.origin.y = i_yPos;
1887
1888     if( [super initWithFrame: mainFrame item: _p_item] != nil )
1889     {
1890         /* add the label */
1891         if( p_item->psz_text )
1892             o_labelString = [[VLCMain sharedInstance]
1893                                 localizedString: p_item->psz_text];
1894         else
1895             o_labelString = [NSString stringWithString:@""];
1896         ADD_LABEL( o_label, mainFrame, 0, -10, o_labelString )
1897         [o_label setAutoresizingMask:NSViewNotSizable ];
1898         [self addSubview: o_label];
1899
1900         /* add the checkboxes */
1901         o_tooltip = [[VLCMain sharedInstance] wrapString:
1902             [[VLCMain sharedInstance]
1903                 localizedString: p_item->psz_longtext ] toWidth: PREFS_WRAP];
1904         ADD_CHECKBOX( o_cmd_checkbox, mainFrame,
1905             [o_label frame].size.width + 2, 0,
1906             [NSString stringWithUTF8String:PLACE_OF_INTEREST_SIGN], o_tooltip,
1907             ((((unsigned int)p_item->i_value) & KEY_MODIFIER_COMMAND)?YES:NO),
1908             NSImageLeft )
1909         [o_cmd_checkbox setState: p_item->i_value & KEY_MODIFIER_COMMAND];
1910         ADD_CHECKBOX( o_ctrl_checkbox, mainFrame,
1911             [o_cmd_checkbox frame].size.width +
1912             [o_cmd_checkbox frame].origin.x + 6, 0,
1913             [NSString stringWithUTF8String:UP_ARROWHEAD], o_tooltip,
1914             ((((unsigned int)p_item->i_value) & KEY_MODIFIER_CTRL)?YES:NO),
1915             NSImageLeft )
1916         [o_ctrl_checkbox setState: p_item->i_value & KEY_MODIFIER_CTRL];
1917         ADD_CHECKBOX( o_alt_checkbox, mainFrame, [o_label frame].size.width +
1918             2, -2 - [o_cmd_checkbox frame].size.height,
1919             [NSString stringWithUTF8String:OPTION_KEY], o_tooltip,
1920             ((((unsigned int)p_item->i_value) & KEY_MODIFIER_ALT)?YES:NO),
1921             NSImageLeft )
1922         [o_alt_checkbox setState: p_item->i_value & KEY_MODIFIER_ALT];
1923         ADD_CHECKBOX( o_shift_checkbox, mainFrame,
1924             [o_cmd_checkbox frame].size.width +
1925             [o_cmd_checkbox frame].origin.x + 6, -2 -
1926             [o_cmd_checkbox frame].size.height,
1927             [NSString stringWithUTF8String:UPWARDS_WHITE_ARROW], o_tooltip,
1928             ((((unsigned int)p_item->i_value) & KEY_MODIFIER_SHIFT)?YES:NO),
1929             NSImageLeft )
1930         [o_shift_checkbox setState: p_item->i_value & KEY_MODIFIER_SHIFT];
1931         [self addSubview: o_cmd_checkbox];
1932         [self addSubview: o_ctrl_checkbox];
1933         [self addSubview: o_alt_checkbox];
1934         [self addSubview: o_shift_checkbox];
1935
1936         /* build the popup */
1937         ADD_POPUP( o_popup, mainFrame, [o_shift_checkbox frame].origin.x +
1938             [o_shift_checkbox frame].size.width + 4,
1939             4, 0, o_tooltip )
1940         [o_popup setAutoresizingMask:NSViewWidthSizable ];
1941
1942         if( o_keys_menu == nil )
1943         {
1944             unsigned int i;
1945             o_keys_menu = [[NSMenu alloc] initWithTitle: @"Keys Menu"];
1946             for ( i = 0; i < sizeof(vlc_keys) / sizeof(key_descriptor_t); i++)
1947                 if( vlc_keys[i].psz_key_string && *vlc_keys[i].psz_key_string )
1948                     POPULATE_A_KEY( o_keys_menu,
1949                         [NSString stringWithCString:vlc_keys[i].psz_key_string]
1950                         , vlc_keys[i].i_key_code)
1951         }
1952         [o_popup setMenu:[o_keys_menu copyWithZone:nil]];
1953         [o_popup selectItemWithTitle: [[VLCMain sharedInstance]
1954             localizedString:KeyToString(
1955             (((unsigned int)p_item->i_value) & ~KEY_MODIFIER ))]];
1956         [self addSubview: o_popup];
1957     }
1958     return self;
1959 }
1960
1961 - (void)dealloc
1962 {
1963     [o_cmd_checkbox release];
1964     [o_ctrl_checkbox release];
1965     [o_alt_checkbox release];
1966     [o_shift_checkbox release];
1967     [o_popup release];
1968     [super dealloc];
1969 }
1970
1971 - (int)intValue
1972 {
1973     unsigned int i_new_key = 0;
1974
1975     i_new_key |= ([o_cmd_checkbox state] == NSOnState) ?
1976         KEY_MODIFIER_COMMAND : 0;
1977     i_new_key |= ([o_ctrl_checkbox state] == NSOnState) ?
1978         KEY_MODIFIER_CTRL : 0;
1979     i_new_key |= ([o_alt_checkbox state] == NSOnState) ?
1980         KEY_MODIFIER_ALT : 0;
1981     i_new_key |= ([o_shift_checkbox state] == NSOnState) ?
1982         KEY_MODIFIER_SHIFT : 0;
1983
1984     i_new_key |= StringToKey([[[o_popup selectedItem] title] cString]);
1985     return i_new_key;
1986 }
1987 @end
1988
1989 @implementation KeyConfigControlAfter103
1990 - (id) initWithItem: (module_config_t *)_p_item
1991            withView: (NSView *)o_parent_view
1992            withVerticalOffset: (int)i_yPos
1993            withLastItem: (int)i_lastItem
1994 {
1995     NSRect mainFrame = [o_parent_view frame];
1996     NSString *o_labelString, *o_tooltip;
1997     mainFrame.size.height = 22;
1998     mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN + 1;
1999     mainFrame.origin.x = LEFTMARGIN;
2000     mainFrame.origin.y = i_yPos;
2001
2002     if( [super initWithFrame: mainFrame item: _p_item] != nil )
2003     {
2004         /* add the label */
2005         if( p_item->psz_text )
2006             o_labelString = [[VLCMain sharedInstance]
2007                 localizedString: p_item->psz_text];
2008         else
2009             o_labelString = [NSString stringWithString:@""];
2010         ADD_LABEL( o_label, mainFrame, 0, -1, o_labelString )
2011         [o_label setAutoresizingMask:NSViewNotSizable ];
2012         [self addSubview: o_label];
2013
2014         /* build the popup */
2015         o_tooltip = [[VLCMain sharedInstance] wrapString:
2016             [[VLCMain sharedInstance]
2017                 localizedString: p_item->psz_longtext ] toWidth: PREFS_WRAP];
2018         ADD_POPUP( o_popup, mainFrame, [o_label frame].origin.x +
2019             [o_label frame].size.width + 3,
2020             -2, 0, o_tooltip )
2021         [o_popup setAutoresizingMask:NSViewWidthSizable ];
2022
2023         if( o_keys_menu == nil )
2024         {
2025             unsigned int i;
2026             o_keys_menu = [[NSMenu alloc] initWithTitle: @"Keys Menu"];
2027             for ( i = 0; i < sizeof(vlc_keys) / sizeof(key_descriptor_t); i++)
2028                 if( vlc_keys[i].psz_key_string && *vlc_keys[i].psz_key_string )
2029                     POPULATE_A_KEY( o_keys_menu,
2030                         [NSString stringWithCString:vlc_keys[i].psz_key_string]
2031                         , vlc_keys[i].i_key_code)
2032         }
2033         [o_popup setMenu:[o_keys_menu copyWithZone:nil]];
2034         [o_popup selectItemWithTag: p_item->i_value];
2035         [self addSubview: o_popup];
2036
2037     }
2038     return self;
2039 }
2040
2041 - (void)dealloc
2042 {
2043     [o_popup release];
2044     [super dealloc];
2045 }
2046
2047 - (int)intValue
2048 {
2049     return [o_popup selectedTag];
2050 }
2051 @end
2052
2053 @implementation ModuleListConfigControl
2054 - (id) initWithItem: (module_config_t *)_p_item
2055            withView: (NSView *)o_parent_view
2056            withVerticalOffset: (int)i_yPos
2057            withLastItem: (int)i_lastItem
2058 {
2059 if( _p_item->i_type == CONFIG_ITEM_MODULE_LIST )
2060 //TODO....
2061         return nil;
2062
2063 //Fill our array to know how may items we have...
2064     vlc_list_t *p_list;
2065     module_t *p_parser;
2066     int i_index;
2067     NSRect mainFrame = [o_parent_view frame];
2068     NSString *o_labelString, *o_textfieldString, *o_tooltip;
2069
2070     o_modulearray = [[NSMutableArray alloc] initWithCapacity:10];
2071     /* build a list of available modules */
2072     p_list = vlc_list_find( VLCIntf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
2073     for( i_index = 0; i_index < p_list->i_count; i_index++ )
2074     {
2075         p_parser = (module_t *)p_list->p_values[i_index].p_object ;
2076
2077         if( !strcmp( p_parser->psz_object_name, "main" ) )
2078             continue;
2079
2080         module_config_t *p_config = p_parser->p_config;
2081         if( p_config ) do
2082         {
2083             NSString *o_modulelongname, *o_modulename;
2084             NSNumber *o_moduleenabled = nil;
2085             /* Hack: required subcategory is stored in i_min */
2086             if( p_config->i_type == CONFIG_SUBCATEGORY &&
2087                 p_config->i_value == _p_item->i_min )
2088             {
2089                 o_modulelongname = [NSString stringWithCString:
2090                                         p_parser->psz_longname];
2091                 o_modulename = [NSString stringWithCString:
2092                                         p_parser->psz_object_name];
2093
2094                 if( _p_item->psz_value &&
2095                     strstr( _p_item->psz_value, p_parser->psz_object_name ) )
2096                     o_moduleenabled = [NSNumber numberWithBool:YES];
2097                 else
2098                     o_moduleenabled = [NSNumber numberWithBool:NO];
2099
2100                 [o_modulearray addObject:[NSMutableArray
2101                     arrayWithObjects: o_modulename, o_modulelongname,
2102                     o_moduleenabled, nil]];
2103             }
2104         } while( p_config->i_type != CONFIG_HINT_END && p_config++ );
2105     }
2106     vlc_list_release( p_list );
2107
2108     mainFrame.size.height = 30 + 18 * [o_modulearray count];
2109     mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN;
2110     mainFrame.origin.x = LEFTMARGIN;
2111     mainFrame.origin.y = i_yPos;
2112     if( [super initWithFrame: mainFrame item: _p_item] != nil )
2113     {
2114         /* add the label */
2115         if( p_item->psz_text )
2116             o_labelString = [[VLCMain sharedInstance]
2117                                 localizedString: p_item->psz_text];
2118         else
2119             o_labelString = [NSString stringWithString:@""];
2120         ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString )
2121         [o_label setAutoresizingMask:NSViewNotSizable ];
2122         [self addSubview: o_label];
2123
2124         /* build the textfield */
2125         o_tooltip = [[VLCMain sharedInstance] wrapString:
2126             [[VLCMain sharedInstance]
2127                 localizedString: p_item->psz_longtext ] toWidth: PREFS_WRAP];
2128         if( p_item->psz_value )
2129             o_textfieldString = [[VLCMain sharedInstance]
2130                 localizedString: p_item->psz_value];
2131         else
2132             o_textfieldString = [NSString stringWithString: @""];
2133         ADD_TEXTFIELD( o_textfield, mainFrame, [o_label frame].size.width + 2,
2134             mainFrame.size.height - 22, mainFrame.size.width -
2135             [o_label frame].size.width - 2, o_tooltip, o_textfieldString )
2136         [o_textfield setAutoresizingMask:NSViewWidthSizable ];
2137         [self addSubview: o_textfield];
2138
2139
2140 {
2141     NSRect s_rc = mainFrame;
2142     s_rc.size.height = mainFrame.size.height - 30;
2143     s_rc.size.width = mainFrame.size.width - 12;
2144     s_rc.origin.x = 12;
2145     s_rc.origin.y = 0;
2146     o_scrollview = [[[NSScrollView alloc] initWithFrame: s_rc] retain];
2147     [o_scrollview setDrawsBackground: NO];
2148     [o_scrollview setBorderType: NSBezelBorder];
2149     [o_scrollview setAutohidesScrollers:YES];
2150
2151     NSTableView *o_tableview;
2152     o_tableview = [[NSTableView alloc] initWithFrame : s_rc];
2153     [o_tableview setUsesAlternatingRowBackgroundColors:YES];
2154     [o_tableview setHeaderView:nil];
2155 /* TODO: find a good way to fix the row height and text size*/
2156 /* FIXME: support for multiple selection... */
2157 //    [o_tableview setAllowsMultipleSelection:YES];
2158
2159     NSCell *o_headerCell = [[NSCell alloc] initTextCell:@"Enabled"];
2160     NSCell *o_dataCell = [[NSButtonCell alloc] init];
2161     [(NSButtonCell*)o_dataCell setButtonType:NSSwitchButton];
2162     [o_dataCell setTitle:@""];
2163     [o_dataCell setFont:[NSFont systemFontOfSize:0]];
2164     NSTableColumn *o_tableColumn = [[NSTableColumn alloc]
2165         initWithIdentifier:[NSString stringWithCString: "Enabled"]];
2166     [o_tableColumn setHeaderCell: o_headerCell];
2167     [o_tableColumn setDataCell: o_dataCell];
2168     [o_tableColumn setWidth:17];
2169     [o_tableview addTableColumn: o_tableColumn];
2170
2171     o_headerCell = [[NSCell alloc] initTextCell:@"Module Name"];
2172     o_dataCell = [[NSTextFieldCell alloc] init];
2173     [o_dataCell setFont:[NSFont systemFontOfSize:12]];
2174     o_tableColumn = [[NSTableColumn alloc]
2175         initWithIdentifier:[NSString stringWithCString: "Module"]];
2176     [o_tableColumn setHeaderCell: o_headerCell];
2177     [o_tableColumn setDataCell: o_dataCell];
2178     [o_tableColumn setWidth:388 - 17];
2179     [o_tableview addTableColumn: o_tableColumn];
2180     [o_tableview registerForDraggedTypes:[NSArray arrayWithObjects:
2181             @"VLC media player module", nil]];
2182
2183     [o_tableview setDataSource:self];
2184     [o_tableview setTarget: self];
2185     [o_tableview setAction: @selector(tableChanged:)];
2186     [o_tableview sendActionOn:NSLeftMouseUpMask | NSLeftMouseDownMask |
2187         NSLeftMouseDraggedMask];
2188     [o_scrollview setDocumentView: o_tableview];
2189 }
2190     [o_scrollview setAutoresizingMask:NSViewWidthSizable ];
2191     [self addSubview: o_scrollview];
2192
2193
2194     }
2195     return self;
2196 }
2197
2198 - (IBAction)tableChanged:(id)sender
2199 {
2200     NSString *o_newstring = @"";
2201     unsigned int i;
2202     for( i = 0 ; i < [o_modulearray count] ; i++ )
2203         if( [[[o_modulearray objectAtIndex:i] objectAtIndex:2]
2204             boolValue] != NO )
2205         {
2206             o_newstring = [o_newstring stringByAppendingString:
2207                 [[o_modulearray objectAtIndex:i] objectAtIndex:0]];
2208             o_newstring = [o_newstring stringByAppendingString:@","];
2209         }
2210
2211     [o_textfield setStringValue: [o_newstring
2212         substringToIndex: ([o_newstring length])?[o_newstring length] - 1:0]];
2213 }
2214
2215 - (void)dealloc
2216 {
2217     [o_scrollview release];
2218     [super dealloc];
2219 }
2220
2221
2222 - (char *)stringValue
2223 {
2224     return strdup( [[o_textfield stringValue] cString] );
2225 }
2226
2227 @end
2228
2229 @implementation ModuleListConfigControl (NSTableDataSource)
2230
2231 - (BOOL)tableView:(NSTableView*)table writeRows:(NSArray*)rows
2232     toPasteboard:(NSPasteboard*)pb
2233 {
2234     // We only want to allow dragging of selected rows.
2235     NSEnumerator    *iter = [rows objectEnumerator];
2236     NSNumber        *row;
2237     while ((row = [iter nextObject]) != nil)
2238     {
2239         if (![table isRowSelected:[row intValue]])
2240             return NO;
2241     }
2242
2243     [pb declareTypes:[NSArray
2244         arrayWithObject:@"VLC media player module"] owner:nil];
2245     [pb setPropertyList:rows forType:@"VLC media player module"];
2246     return YES;
2247 }
2248
2249 - (NSDragOperation)tableView:(NSTableView*)table
2250     validateDrop:(id <NSDraggingInfo>)info proposedRow:(int)row
2251     proposedDropOperation:(NSTableViewDropOperation)op
2252 {
2253     // Make drops at the end of the table go to the end.
2254     if (row == -1)
2255     {
2256         row = [table numberOfRows];
2257         op = NSTableViewDropAbove;
2258         [table setDropRow:row dropOperation:op];
2259     }
2260
2261     // We don't ever want to drop onto a row, only between rows.
2262     if (op == NSTableViewDropOn)
2263         [table setDropRow:(row+1) dropOperation:NSTableViewDropAbove];
2264     return NSTableViewDropAbove;
2265 }
2266
2267 - (BOOL)tableView:(NSTableView*)table acceptDrop:(id <NSDraggingInfo>)info
2268     row:(int)dropRow dropOperation:(NSTableViewDropOperation)op;
2269 {
2270     NSPasteboard    *pb = [info draggingPasteboard];
2271     NSDragOperation srcMask = [info draggingSourceOperationMask];
2272     BOOL accepted = NO;
2273
2274     NS_DURING
2275
2276         NSArray *array;
2277
2278         // Intra-table drag - data is the array of rows.
2279         if (!accepted && (array =
2280             [pb propertyListForType:@"VLC media player module"]) != NULL)
2281         {
2282             NSEnumerator *iter = nil;
2283             id val;
2284             BOOL isCopy = (srcMask & NSDragOperationMove) ? NO:YES;
2285             // Move the modules
2286             iter = [array objectEnumerator];
2287             while ((val = [iter nextObject]) != NULL)
2288             {
2289                 NSArray *o_tmp = [[o_modulearray objectAtIndex:
2290                     [val intValue]] mutableCopyWithZone:nil];
2291                 [o_modulearray removeObject:o_tmp];
2292                 [o_modulearray insertObject:o_tmp
2293                     atIndex:(dropRow>[val intValue]) ? dropRow - 1 : dropRow];
2294                 dropRow++;
2295             }
2296
2297             // Select the newly-dragged items.
2298             iter = [array objectEnumerator];
2299 //TODO...
2300             [table deselectAll:self];
2301
2302             [self tableChanged:self];
2303             [table setNeedsDisplay:YES];
2304             // Indicate that we finished the drag.
2305             accepted = YES;
2306         }
2307         [table reloadData];
2308         [table setNeedsDisplay:YES];
2309
2310         NS_HANDLER
2311
2312             // An exception occurred. Uh-oh. Update the track table so that
2313             // it stays consistent, and re-raise the exception.
2314             [table reloadData];
2315             [localException raise];
2316             [table setNeedsDisplay:YES];
2317     NS_ENDHANDLER
2318
2319     return accepted;
2320 }
2321
2322 - (int)numberOfRowsInTableView:(NSTableView *)aTableView
2323 {
2324     return [o_modulearray count];
2325 }
2326
2327 - (id)tableView:(NSTableView *)aTableView
2328     objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex
2329 {
2330     if( [[aTableColumn identifier] isEqualToString:
2331         [NSString stringWithCString:"Enabled"]] )
2332         return [[o_modulearray objectAtIndex:rowIndex] objectAtIndex:2];
2333     if( [[aTableColumn identifier] isEqualToString:
2334         [NSString stringWithCString:"Module"]] )
2335         return [[o_modulearray objectAtIndex:rowIndex] objectAtIndex:1];
2336
2337     return nil;
2338 }
2339
2340 - (void)tableView:(NSTableView *)aTableView setObjectValue:(id)anObject
2341     forTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex
2342 {
2343     [[o_modulearray objectAtIndex:rowIndex] replaceObjectAtIndex:2
2344         withObject: anObject];
2345 }
2346 @end