]> git.sesse.net Git - vlc/blob - modules/gui/macosx/prefs_widgets.m
*: fix problems about advanced button
[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         i_view_type = 0;
422         b_advanced = p_item->b_advanced;
423         [self setAutoresizingMask:NSViewWidthSizable | NSViewMinYMargin ];
424     }
425     return (self);
426 }
427
428 - (void)setYPos:(int)i_yPos
429 {
430     NSRect frame = [self frame];
431     frame.origin.y = i_yPos;
432     [self setFrame:frame];
433 }
434
435 - (void)dealloc
436 {
437     if( o_label ) [o_label release];
438     if( psz_name ) free( psz_name );
439     [super dealloc];
440 }
441
442 + (int)calcVerticalMargin: (int)i_curItem lastItem: (int)i_lastItem
443 {
444     int i_margin;
445     switch( i_curItem )
446     {
447     case CONFIG_ITEM_STRING:
448         switch( i_lastItem )
449         {
450         case CONFIG_ITEM_STRING:
451             i_margin = 8;
452             break;
453         case CONFIG_ITEM_STRING_LIST:
454             i_margin = 7;
455             break;
456         case CONFIG_ITEM_FILE:
457             i_margin = 8;
458             break;
459         case CONFIG_ITEM_MODULE:
460             i_margin = 4;
461             break;
462         case CONFIG_ITEM_INTEGER:
463             i_margin = 7;
464             break;
465         case CONFIG_ITEM_RANGED_INTEGER:
466             i_margin = 5;
467             break;
468         case CONFIG_ITEM_BOOL:
469             i_margin = 7;
470             break;
471         case CONFIG_ITEM_KEY_BEFORE_10_3:
472             i_margin = 7;
473             break;
474         case CONFIG_ITEM_KEY_AFTER_10_3:
475             i_margin = 6;
476             break;
477         case CONFIG_ITEM_MODULE_LIST:
478             i_margin = 8;
479             break;
480         default:
481             i_margin = 20;
482             break;
483         }
484         break;
485     case CONFIG_ITEM_STRING_LIST:
486         switch( i_lastItem )
487         {
488         case CONFIG_ITEM_STRING:
489             i_margin = 8;
490             break;
491         case CONFIG_ITEM_STRING_LIST:
492             i_margin = 7;
493             break;
494         case CONFIG_ITEM_FILE:
495             i_margin = 6;
496             break;
497         case CONFIG_ITEM_MODULE:
498             i_margin = 4;
499             break;
500         case CONFIG_ITEM_INTEGER:
501             i_margin = 7;
502             break;
503         case CONFIG_ITEM_RANGED_INTEGER:
504             i_margin = 5;
505             break;
506         case CONFIG_ITEM_BOOL:
507             i_margin = 7;
508             break;
509         case CONFIG_ITEM_KEY_BEFORE_10_3:
510             i_margin = 7;
511             break;
512         case CONFIG_ITEM_KEY_AFTER_10_3:
513             i_margin = 6;
514             break;
515         case CONFIG_ITEM_MODULE_LIST:
516             i_margin = 8;
517             break;
518         default:
519             i_margin = 20;
520             break;
521         }
522         break;
523     case CONFIG_ITEM_FILE:
524         switch( i_lastItem )
525         {
526         case CONFIG_ITEM_STRING:
527             i_margin = 13;
528             break;
529         case CONFIG_ITEM_STRING_LIST:
530             i_margin = 10;
531             break;
532         case CONFIG_ITEM_FILE:
533             i_margin = 9;
534             break;
535         case CONFIG_ITEM_MODULE:
536             i_margin = 9;
537             break;
538         case CONFIG_ITEM_INTEGER:
539             i_margin = 10;
540             break;
541         case CONFIG_ITEM_RANGED_INTEGER:
542             i_margin = 8;
543             break;
544         case CONFIG_ITEM_BOOL:
545             i_margin = 10;
546             break;
547         case CONFIG_ITEM_KEY_BEFORE_10_3:
548             i_margin = 10;
549             break;
550         case CONFIG_ITEM_KEY_AFTER_10_3:
551             i_margin = 9;
552             break;
553         case CONFIG_ITEM_MODULE_LIST:
554             i_margin = 11;
555             break;
556         default:
557             i_margin = 23;
558             break;
559         }
560         break;
561     case CONFIG_ITEM_MODULE:
562         switch( i_lastItem )
563         {
564         case CONFIG_ITEM_STRING:
565             i_margin = 8;
566             break;
567         case CONFIG_ITEM_STRING_LIST:
568             i_margin = 7;
569             break;
570         case CONFIG_ITEM_FILE:
571             i_margin = 6;
572             break;
573         case CONFIG_ITEM_MODULE:
574             i_margin = 5;
575             break;
576         case CONFIG_ITEM_INTEGER:
577             i_margin = 7;
578             break;
579         case CONFIG_ITEM_RANGED_INTEGER:
580             i_margin = 6;
581             break;
582         case CONFIG_ITEM_BOOL:
583             i_margin = 8;
584             break;
585         case CONFIG_ITEM_KEY_BEFORE_10_3:
586             i_margin = 8;
587             break;
588         case CONFIG_ITEM_KEY_AFTER_10_3:
589             i_margin = 7;
590             break;
591         case CONFIG_ITEM_MODULE_LIST:
592             i_margin = 9;
593             break;
594         default:
595             i_margin = 20;
596             break;
597         }
598         break;
599     case CONFIG_ITEM_INTEGER:
600         switch( i_lastItem )
601         {
602         case CONFIG_ITEM_STRING:
603             i_margin = 8;
604             break;
605         case CONFIG_ITEM_STRING_LIST:
606             i_margin = 7;
607             break;
608         case CONFIG_ITEM_FILE:
609             i_margin = 6;
610             break;
611         case CONFIG_ITEM_MODULE:
612             i_margin = 4;
613             break;
614         case CONFIG_ITEM_INTEGER:
615             i_margin = 7;
616             break;
617         case CONFIG_ITEM_RANGED_INTEGER:
618             i_margin = 5;
619             break;
620         case CONFIG_ITEM_BOOL:
621             i_margin = 7;
622             break;
623         case CONFIG_ITEM_KEY_BEFORE_10_3:
624             i_margin = 7;
625             break;
626         case CONFIG_ITEM_KEY_AFTER_10_3:
627             i_margin = 6;
628             break;
629         case CONFIG_ITEM_MODULE_LIST:
630             i_margin = 8;
631             break;
632         default:
633             i_margin = 20;
634             break;
635         }
636         break;
637     case CONFIG_ITEM_RANGED_INTEGER:
638         switch( i_lastItem )
639         {
640         case CONFIG_ITEM_STRING:
641             i_margin = 8;
642             break;
643         case CONFIG_ITEM_STRING_LIST:
644             i_margin = 7;
645             break;
646         case CONFIG_ITEM_FILE:
647             i_margin = 8;
648             break;
649         case CONFIG_ITEM_MODULE:
650             i_margin = 4;
651             break;
652         case CONFIG_ITEM_INTEGER:
653             i_margin = 7;
654             break;
655         case CONFIG_ITEM_RANGED_INTEGER:
656             i_margin = 5;
657             break;
658         case CONFIG_ITEM_BOOL:
659             i_margin = 7;
660             break;
661         case CONFIG_ITEM_KEY_BEFORE_10_3:
662             i_margin = 7;
663             break;
664         case CONFIG_ITEM_KEY_AFTER_10_3:
665             i_margin = 6;
666             break;
667         case CONFIG_ITEM_MODULE_LIST:
668             i_margin = 8;
669             break;
670         default:
671             i_margin = 20;
672             break;
673         }
674         break;
675     case CONFIG_ITEM_BOOL:
676         switch( i_lastItem )
677         {
678         case CONFIG_ITEM_STRING:
679             i_margin = 6;
680             break;
681         case CONFIG_ITEM_STRING_LIST:
682             i_margin = 5;
683             break;
684         case CONFIG_ITEM_FILE:
685             i_margin = 4;
686             break;
687         case CONFIG_ITEM_MODULE:
688             i_margin = 2;
689             break;
690         case CONFIG_ITEM_INTEGER:
691             i_margin = 5;
692             break;
693         case CONFIG_ITEM_RANGED_INTEGER:
694             i_margin = 3;
695             break;
696         case CONFIG_ITEM_BOOL:
697             i_margin = 3;
698             break;
699         case CONFIG_ITEM_KEY_BEFORE_10_3:
700             i_margin = 3;
701             break;
702         case CONFIG_ITEM_KEY_AFTER_10_3:
703             i_margin = 2;
704             break;
705         case CONFIG_ITEM_MODULE_LIST:
706             i_margin = 6;
707             break;
708         default:
709             i_margin = 18;
710             break;
711         }
712         break;
713     case CONFIG_ITEM_KEY_BEFORE_10_3:
714         switch( i_lastItem )
715         {
716         case CONFIG_ITEM_STRING:
717             i_margin = 6;
718             break;
719         case CONFIG_ITEM_STRING_LIST:
720             i_margin = 5;
721             break;
722         case CONFIG_ITEM_FILE:
723             i_margin = 4;
724             break;
725         case CONFIG_ITEM_MODULE:
726             i_margin = 2;
727             break;
728         case CONFIG_ITEM_INTEGER:
729             i_margin = 5;
730             break;
731         case CONFIG_ITEM_RANGED_INTEGER:
732             i_margin = 3;
733             break;
734         case CONFIG_ITEM_BOOL:
735             i_margin = 3;
736             break;
737         case CONFIG_ITEM_KEY_BEFORE_10_3:
738             i_margin = 10;
739             break;
740         case CONFIG_ITEM_KEY_AFTER_10_3:
741             i_margin = 6;
742             break;
743         case CONFIG_ITEM_MODULE_LIST:
744             i_margin = 6;
745             break;
746         default:
747             i_margin = 18;
748             break;
749         }
750         break;
751     case CONFIG_ITEM_KEY_AFTER_10_3:
752         switch( i_lastItem )
753         {
754         case CONFIG_ITEM_STRING:
755             i_margin = 8;
756             break;
757         case CONFIG_ITEM_STRING_LIST:
758             i_margin = 7;
759             break;
760         case CONFIG_ITEM_FILE:
761             i_margin = 6;
762             break;
763         case CONFIG_ITEM_MODULE:
764             i_margin = 6;
765             break;
766         case CONFIG_ITEM_INTEGER:
767             i_margin = 7;
768             break;
769         case CONFIG_ITEM_RANGED_INTEGER:
770             i_margin = 5;
771             break;
772         case CONFIG_ITEM_BOOL:
773             i_margin = 7;
774             break;
775         case CONFIG_ITEM_KEY_BEFORE_10_3:
776             i_margin = 7;
777             break;
778         case CONFIG_ITEM_KEY_AFTER_10_3:
779             i_margin = 8;
780             break;
781         case CONFIG_ITEM_MODULE_LIST:
782             i_margin = 10;
783             break;
784         default:
785             i_margin = 20;
786             break;
787         }
788         break;
789     case CONFIG_ITEM_MODULE_LIST:
790         switch( i_lastItem )
791         {
792         case CONFIG_ITEM_STRING:
793             i_margin = 10;
794             break;
795         case CONFIG_ITEM_STRING_LIST:
796             i_margin = 7;
797             break;
798         case CONFIG_ITEM_FILE:
799             i_margin = 6;
800             break;
801         case CONFIG_ITEM_MODULE:
802             i_margin = 6;
803             break;
804         case CONFIG_ITEM_INTEGER:
805             i_margin = 9;
806             break;
807         case CONFIG_ITEM_RANGED_INTEGER:
808             i_margin = 5;
809             break;
810         case CONFIG_ITEM_BOOL:
811             i_margin = 7;
812             break;
813         case CONFIG_ITEM_KEY_BEFORE_10_3:
814             i_margin = 7;
815             break;
816         case CONFIG_ITEM_KEY_AFTER_10_3:
817             i_margin = 5;
818             break;
819         case CONFIG_ITEM_MODULE_LIST:
820             i_margin = 8;
821             break;
822         default:
823             i_margin = 20;
824             break;
825         }
826         break;
827     default:
828         i_margin = 20;
829         break;
830     }
831     return i_margin;
832 }
833
834 + (VLCConfigControl *)newControl: (module_config_t *)_p_item
835                       withView: (NSView *)o_parent_view
836                       yOffset:(int) i_yPos
837 {
838     VLCConfigControl *p_control = NULL;
839     switch( _p_item->i_type )
840     {
841     case CONFIG_ITEM_STRING:
842         if( !_p_item->i_list )
843         {
844             p_control = [[StringConfigControl alloc]
845                     initWithItem: _p_item
846                     withView: o_parent_view
847                     withVerticalOffset: i_yPos];
848         }
849         else
850         {
851             p_control = [[StringListConfigControl alloc]
852                     initWithItem: _p_item
853                     withView: o_parent_view
854                     withVerticalOffset: i_yPos];
855         }
856         break;
857     case CONFIG_ITEM_FILE:
858     case CONFIG_ITEM_DIRECTORY:
859         p_control = [[FileConfigControl alloc]
860                     initWithItem: _p_item
861                     withView: o_parent_view
862                     withVerticalOffset: i_yPos];
863         break;
864     case CONFIG_ITEM_MODULE:
865     case CONFIG_ITEM_MODULE_CAT:
866         p_control = [[ModuleConfigControl alloc]
867                     initWithItem: _p_item
868                     withView: o_parent_view
869                     withVerticalOffset: i_yPos];
870         break;
871     case CONFIG_ITEM_INTEGER:
872         if( _p_item->i_list )
873         {
874             p_control = [[IntegerListConfigControl alloc]
875                         initWithItem: _p_item
876                         withView: o_parent_view
877                         withVerticalOffset: i_yPos];
878         }
879         else if( _p_item->i_min != 0 || _p_item->i_max != 0 )
880         {
881             p_control = [[RangedIntegerConfigControl alloc]
882                         initWithItem: _p_item
883                         withView: o_parent_view
884                         withVerticalOffset: i_yPos];
885         }
886         else
887         {
888             p_control = [[IntegerConfigControl alloc]
889                         initWithItem: _p_item
890                         withView: o_parent_view
891                         withVerticalOffset: i_yPos];
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         break;
900     case CONFIG_ITEM_FLOAT:
901         if( _p_item->f_min != 0 || _p_item->f_max != 0 )
902         {
903             p_control = [[RangedFloatConfigControl alloc]
904                         initWithItem: _p_item
905                         withView: o_parent_view
906                         withVerticalOffset: i_yPos];
907         }
908         else
909         {
910             p_control = [[FloatConfigControl alloc]
911                         initWithItem: _p_item
912                         withView: o_parent_view
913                         withVerticalOffset: i_yPos];
914         }
915         break;
916     case CONFIG_ITEM_KEY:
917         if( MACOS_VERSION < 10.3 )
918         {
919             p_control = [[KeyConfigControlBefore103 alloc]
920                         initWithItem: _p_item
921                         withView: o_parent_view
922                         withVerticalOffset: i_yPos];
923         }
924         else
925         {
926             p_control = [[KeyConfigControlAfter103 alloc]
927                         initWithItem: _p_item
928                         withView: o_parent_view
929                         withVerticalOffset: i_yPos];
930         }
931         break;
932     case CONFIG_ITEM_MODULE_LIST:
933     case CONFIG_ITEM_MODULE_LIST_CAT:
934         p_control = [[ModuleListConfigControl alloc]
935                     initWithItem: _p_item
936                     withView: o_parent_view
937                     withVerticalOffset: i_yPos];
938         break;
939     default:
940         break;
941     }
942     return p_control;
943 }
944
945 - (NSString *)getName
946 {
947     return [[VLCMain sharedInstance] localizedString: psz_name];
948 }
949
950 - (int)getType
951 {
952     return i_type;
953 }
954
955 - (int)getViewType
956 {
957     return i_view_type;
958 }
959
960 - (BOOL)isAdvanced
961 {
962     return b_advanced;
963 }
964
965 - (int)intValue
966 {
967     return 0;
968 }
969
970 - (float)floatValue
971 {
972     return 0;
973 }
974
975 - (char *)stringValue
976 {
977     return NULL;
978 }
979
980 - (void)applyChanges
981 {
982     vlc_value_t val;
983     switch( p_item->i_type )
984     {
985     case CONFIG_ITEM_STRING:
986     case CONFIG_ITEM_FILE:
987     case CONFIG_ITEM_DIRECTORY:
988     case CONFIG_ITEM_MODULE:
989     case CONFIG_ITEM_MODULE_LIST:
990     case CONFIG_ITEM_MODULE_LIST_CAT:
991 fprintf( stderr, "Applying %s to %s\n" , [self stringValue], psz_name );
992         config_PutPsz( VLCIntf, psz_name, [self stringValue] );
993         break;
994     case CONFIG_ITEM_KEY:
995         /* So you don't need to restart to have the changes take effect */
996 fprintf( stderr, "Applying %d to %s\n" , [self intValue], psz_name );
997         val.i_int = [self intValue];
998         var_Set( VLCIntf->p_vlc, psz_name, val );
999     case CONFIG_ITEM_INTEGER:
1000     case CONFIG_ITEM_BOOL:
1001 fprintf( stderr, "Applying %d to %s\n" , [self intValue], psz_name );
1002         config_PutInt( VLCIntf, psz_name, [self intValue] );
1003         break;
1004     case CONFIG_ITEM_FLOAT:
1005 fprintf( stderr, "Applying %f to %s\n" , [self floatValue], psz_name );
1006         config_PutFloat( VLCIntf, psz_name, [self floatValue] );
1007         break;
1008     }
1009 }
1010 @end
1011
1012 @implementation StringConfigControl
1013 - (id) initWithItem: (module_config_t *)_p_item
1014            withView: (NSView *)o_parent_view
1015            withVerticalOffset: (int)i_yPos
1016 {
1017     NSRect mainFrame = [o_parent_view frame];
1018     NSString *o_labelString, *o_textfieldString, *o_textfieldTooltip;
1019     mainFrame.size.height = 22;
1020     mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN;
1021     mainFrame.origin.x = LEFTMARGIN;
1022     mainFrame.origin.y = i_yPos;
1023
1024     if( [super initWithFrame: mainFrame item: _p_item] != nil )
1025     {
1026         i_view_type = CONFIG_ITEM_STRING;
1027         /* add the label */
1028         if( p_item->psz_text )
1029             o_labelString = [[VLCMain sharedInstance]
1030                                 localizedString: p_item->psz_text];
1031         else
1032             o_labelString = [NSString stringWithString:@""];
1033         ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString )
1034         [o_label setAutoresizingMask:NSViewNotSizable ];
1035         [self addSubview: o_label];
1036
1037         /* build the textfield */
1038         o_textfieldTooltip = [[VLCMain sharedInstance] wrapString:
1039             [[VLCMain sharedInstance] localizedString: p_item->psz_longtext]
1040                                          toWidth: PREFS_WRAP];
1041         if( p_item->psz_value )
1042             o_textfieldString = [[VLCMain sharedInstance]
1043                                     localizedString: p_item->psz_value];
1044         else
1045             o_textfieldString = [NSString stringWithString: @""];
1046         ADD_TEXTFIELD( o_textfield, mainFrame, [o_label frame].size.width + 2,
1047                         0, mainFrame.size.width - [o_label frame].size.width -
1048                         2, o_textfieldTooltip, o_textfieldString )
1049         [o_textfield setAutoresizingMask:NSViewWidthSizable ];
1050         [self addSubview: o_textfield];
1051     }
1052     return self;
1053 }
1054
1055 - (void)dealloc
1056 {
1057     [o_label release];
1058     [o_textfield release];
1059     [super dealloc];
1060 }
1061
1062 - (char *)stringValue
1063 {
1064     return strdup( [[VLCMain sharedInstance] delocalizeString:
1065                         [o_textfield stringValue]] );
1066 }
1067 @end
1068
1069 @implementation StringListConfigControl
1070 - (id) initWithItem: (module_config_t *)_p_item
1071            withView: (NSView *)o_parent_view
1072            withVerticalOffset: (int)i_yPos
1073 {
1074     NSRect mainFrame = [o_parent_view frame];
1075     NSString *o_labelString, *o_textfieldTooltip;
1076     mainFrame.size.height = 22;
1077     mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN + 1;
1078     mainFrame.origin.x = LEFTMARGIN;
1079     mainFrame.origin.y = i_yPos;
1080
1081     if( [super initWithFrame: mainFrame item: _p_item] != nil )
1082     {
1083         int i_index;
1084         i_view_type = CONFIG_ITEM_STRING_LIST;
1085         /* add the label */
1086         if( p_item->psz_text )
1087             o_labelString = [[VLCMain sharedInstance]
1088                                 localizedString: p_item->psz_text];
1089         else
1090             o_labelString = [NSString stringWithString:@""];
1091         ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString )
1092         [o_label setAutoresizingMask:NSViewNotSizable ];
1093         [self addSubview: o_label];
1094
1095         /* build the textfield */
1096         o_textfieldTooltip = [[VLCMain sharedInstance] wrapString:
1097             [[VLCMain sharedInstance]
1098                 localizedString: p_item->psz_longtext ] toWidth: PREFS_WRAP];
1099         ADD_COMBO( o_combo, mainFrame, [o_label frame].size.width,
1100             -2, 0, o_textfieldTooltip )
1101         [o_combo setAutoresizingMask:NSViewWidthSizable ];
1102         for( i_index = 0; i_index < p_item->i_list; i_index++ )
1103             if( p_item->psz_value &&
1104                 !strcmp( p_item->psz_value, p_item->ppsz_list[i_index] ) )
1105                 [o_combo selectItemAtIndex: i_index];
1106         [self addSubview: o_combo];
1107     }
1108     return self;
1109 }
1110
1111 - (void)dealloc
1112 {
1113     [o_combo release];
1114     [super dealloc];
1115 }
1116
1117 - (char *)stringValue
1118 {
1119     if( [o_combo indexOfSelectedItem] >= 0 )
1120         return strdup( p_item->ppsz_list[[o_combo indexOfSelectedItem]] );
1121     else
1122         return strdup( [[VLCMain sharedInstance]
1123                             delocalizeString: [o_combo stringValue]] );
1124 }
1125 @end
1126
1127 @implementation StringListConfigControl (NSComboBoxDataSource)
1128 - (int)numberOfItemsInComboBox:(NSComboBox *)aComboBox
1129 {
1130         return p_item->i_list;
1131 }
1132
1133 - (id)comboBox:(NSComboBox *)aComboBox objectValueForItemAtIndex:(int)i_index
1134 {
1135     if( p_item->ppsz_list_text && p_item->ppsz_list_text[i_index] )
1136     {
1137         return [[VLCMain sharedInstance]
1138                     localizedString: p_item->ppsz_list_text[i_index]];
1139     } else return [[VLCMain sharedInstance]
1140                     localizedString: p_item->ppsz_list[i_index]];
1141 }
1142 @end
1143
1144 @implementation FileConfigControl
1145 - (id) initWithItem: (module_config_t *)_p_item
1146            withView: (NSView *)o_parent_view
1147            withVerticalOffset: (int)i_yPos
1148 {
1149     NSRect mainFrame = [o_parent_view frame];
1150     NSString *o_labelString, *o_buttonTooltip, *o_textfieldString;
1151     NSString *o_textfieldTooltip;
1152     mainFrame.size.height = 46;
1153     mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN;
1154     mainFrame.origin.x = LEFTMARGIN;
1155     mainFrame.origin.y = i_yPos;
1156
1157     if( [super initWithFrame: mainFrame item: _p_item] != nil )
1158     {
1159         i_view_type = CONFIG_ITEM_FILE;
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 {
1253     NSRect mainFrame = [o_parent_view frame];
1254     NSString *o_labelString, *o_popupTooltip;
1255     mainFrame.size.height = 22;
1256     mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN + 1;
1257     mainFrame.origin.x = LEFTMARGIN;
1258     mainFrame.origin.y = i_yPos;
1259
1260     if( [super initWithFrame: mainFrame item: _p_item] != nil )
1261     {
1262         int i_index;
1263         vlc_list_t *p_list;
1264         module_t *p_parser;
1265         i_view_type = CONFIG_ITEM_MODULE;
1266
1267         /* add the label */
1268         if( p_item->psz_text )
1269             o_labelString = [[VLCMain sharedInstance]
1270                                 localizedString: p_item->psz_text];
1271         else
1272             o_labelString = [NSString stringWithString:@""];
1273         ADD_LABEL( o_label, mainFrame, 0, -1, o_labelString )
1274         [o_label setAutoresizingMask:NSViewNotSizable ];
1275         [self addSubview: o_label];
1276
1277         /* build the popup */
1278         o_popupTooltip = [[VLCMain sharedInstance] wrapString:
1279             [[VLCMain sharedInstance]
1280                 localizedString: p_item->psz_longtext ] toWidth: PREFS_WRAP];
1281         ADD_POPUP( o_popup, mainFrame, [o_label frame].size.width,
1282             -2, 0, o_popupTooltip )
1283         [o_popup setAutoresizingMask:NSViewWidthSizable ];
1284         [o_popup addItemWithTitle: _NS("Default")];
1285         [[o_popup lastItem] setTag: -1];
1286         [o_popup selectItem: [o_popup lastItem]];
1287
1288         /* build a list of available modules */
1289         p_list = vlc_list_find( VLCIntf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
1290         for( i_index = 0; i_index < p_list->i_count; i_index++ )
1291         {
1292             p_parser = (module_t *)p_list->p_values[i_index].p_object ;
1293             if( p_item->i_type == CONFIG_ITEM_MODULE )
1294             {
1295                 if( !strcmp( p_parser->psz_capability,
1296                             p_item->psz_type ) )
1297                 {
1298                     NSString *o_description = [[VLCMain sharedInstance]
1299                         localizedString: p_parser->psz_longname];
1300                     [o_popup addItemWithTitle: o_description];
1301
1302                     if( p_item->psz_value &&
1303                 !strcmp( p_item->psz_value, p_parser->psz_object_name ) )
1304                         [o_popup selectItem:[o_popup lastItem]];
1305                 }
1306             }
1307             else
1308             {
1309                 module_config_t *p_config;
1310                 if( !strcmp( p_parser->psz_object_name, "main" ) )
1311                       continue;
1312
1313                 p_config = p_parser->p_config;
1314                 if( p_config ) do
1315                 {
1316                     /* Hack: required subcategory is stored in i_min */
1317                     if( p_config->i_type == CONFIG_SUBCATEGORY &&
1318                         p_config->i_value == p_item->i_min )
1319                     {
1320                         NSString *o_description = [[VLCMain sharedInstance]
1321                             localizedString: p_parser->psz_longname];
1322                         [o_popup addItemWithTitle: o_description];
1323
1324                         if( p_item->psz_value && !strcmp(p_item->psz_value,
1325                                                 p_parser->psz_object_name) )
1326                             [o_popup selectItem:[o_popup lastItem]];
1327                     }
1328                 } while( p_config->i_type != CONFIG_HINT_END && p_config++ );
1329             }
1330         }
1331         vlc_list_release( p_list );
1332         [self addSubview: o_popup];
1333     }
1334     return self;
1335 }
1336
1337 - (void)dealloc
1338 {
1339     [o_popup release];
1340     [super dealloc];
1341 }
1342
1343 - (char *)stringValue
1344 {
1345     NSString *newval = [o_popup titleOfSelectedItem];
1346     char *returnval = NULL;
1347     int i_index;
1348     vlc_list_t *p_list;
1349     module_t *p_parser;
1350
1351     p_list = vlc_list_find( VLCIntf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
1352     for( i_index = 0; i_index < p_list->i_count; i_index++ )
1353     {
1354         p_parser = (module_t *)p_list->p_values[i_index].p_object ;
1355         if( p_item->i_type == CONFIG_ITEM_MODULE )
1356         {
1357             if( !strcmp( p_parser->psz_capability,
1358                     p_item->psz_type ) )
1359             {
1360                 NSString *o_description = [[VLCMain sharedInstance]
1361                     localizedString: p_parser->psz_longname];
1362                 if( [newval isEqualToString: o_description] )
1363                 {
1364                     returnval = strdup(p_parser->psz_object_name);
1365                     break;
1366                 }
1367             }
1368         }
1369         else
1370         {
1371             module_config_t *p_config;
1372             if( !strcmp( p_parser->psz_object_name, "main" ) )
1373                   continue;
1374
1375             p_config = p_parser->p_config;
1376             if( p_config ) do
1377             {
1378                 /* Hack: required subcategory is stored in i_min */
1379                 if( p_config->i_type == CONFIG_SUBCATEGORY &&
1380                     p_config->i_value == p_item->i_min )
1381                 {
1382                     NSString *o_description = [[VLCMain sharedInstance]
1383                         localizedString: p_parser->psz_longname];
1384                     if( [newval isEqualToString: o_description] )
1385                     {
1386                         returnval = strdup(p_parser->psz_object_name);
1387                         break;
1388                     }
1389                 }
1390             } while( p_config->i_type != CONFIG_HINT_END && p_config++ );
1391         }
1392     }
1393     vlc_list_release( p_list );
1394     return returnval;
1395 }
1396 @end
1397
1398 @implementation IntegerConfigControl
1399 - (id) initWithItem: (module_config_t *)_p_item
1400            withView: (NSView *)o_parent_view
1401            withVerticalOffset: (int)i_yPos
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         i_view_type = CONFIG_ITEM_INTEGER;
1413
1414         o_tooltip = [[VLCMain sharedInstance] wrapString:
1415             [[VLCMain sharedInstance]
1416                 localizedString: p_item->psz_longtext ] toWidth: PREFS_WRAP];
1417
1418         /* add the label */
1419         if( p_item->psz_text )
1420             o_labelString = [[VLCMain sharedInstance]
1421                                 localizedString: p_item->psz_text];
1422         else
1423             o_labelString = [NSString stringWithString:@""];
1424         ADD_LABEL( o_label, mainFrame, 0, -2, o_labelString )
1425         [o_label setAutoresizingMask:NSViewNotSizable ];
1426         [self addSubview: o_label];
1427
1428         /* build the stepper */
1429         ADD_STEPPER( o_stepper, mainFrame, mainFrame.size.width - 19,
1430             0, o_tooltip, -1600, 1600)
1431         [o_stepper setIntValue: p_item->i_value];
1432         [o_stepper setAutoresizingMask:NSViewMinXMargin ];
1433         [self addSubview: o_stepper];
1434
1435         /* build the textfield */
1436         if( p_item->psz_value )
1437             o_textfieldString = [[VLCMain sharedInstance]
1438                                     localizedString: p_item->psz_value];
1439         else
1440             o_textfieldString = [NSString stringWithString: @""];
1441         ADD_TEXTFIELD( o_textfield, mainFrame, mainFrame.size.width - 19 - 52,
1442             1, 49, o_tooltip, @"" )
1443         [o_textfield setIntValue: p_item->i_value];
1444         [o_textfield setDelegate: self];
1445         [[NSNotificationCenter defaultCenter] addObserver: self
1446             selector: @selector(textfieldChanged:)
1447             name: NSControlTextDidChangeNotification
1448             object: o_textfield];
1449         [o_textfield setAutoresizingMask:NSViewMinXMargin ];
1450         [self addSubview: o_textfield];
1451     }
1452     return self;
1453 }
1454
1455 - (void)dealloc
1456 {
1457     [o_stepper release];
1458     [o_textfield release];
1459     [super dealloc];
1460 }
1461
1462 - (IBAction)stepperChanged:(id)sender
1463 {
1464     [o_textfield setIntValue: [o_stepper intValue]];
1465 }
1466
1467 - (void)textfieldChanged:(NSNotification *)o_notification
1468 {
1469     [o_stepper setIntValue: [o_textfield intValue]];
1470 }
1471
1472 - (int)intValue
1473 {
1474     return [o_textfield intValue];
1475 }
1476
1477 @end
1478
1479 @implementation IntegerListConfigControl
1480
1481 - (id) initWithItem: (module_config_t *)_p_item
1482            withView: (NSView *)o_parent_view
1483            withVerticalOffset: (int)i_yPos
1484 {
1485     NSRect mainFrame = [o_parent_view frame];
1486     NSString *o_labelString, *o_textfieldTooltip;
1487     mainFrame.size.height = 22;
1488     mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN + 1;
1489     mainFrame.origin.x = LEFTMARGIN;
1490     mainFrame.origin.y = i_yPos;
1491
1492     if( [super initWithFrame: mainFrame item: _p_item] != nil )
1493     {
1494         int i_index;
1495         i_view_type = CONFIG_ITEM_STRING_LIST;
1496
1497         /* add the label */
1498         if( p_item->psz_text )
1499             o_labelString = [[VLCMain sharedInstance]
1500                 localizedString: p_item->psz_text];
1501         else
1502             o_labelString = [NSString stringWithString:@""];
1503         ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString )
1504         [o_label setAutoresizingMask:NSViewNotSizable ];
1505         [self addSubview: o_label];
1506
1507         /* build the textfield */
1508         o_textfieldTooltip = [[VLCMain sharedInstance] wrapString:
1509             [[VLCMain sharedInstance]
1510                 localizedString: p_item->psz_longtext ] toWidth: PREFS_WRAP];
1511         ADD_COMBO( o_combo, mainFrame, [o_label frame].size.width,
1512             -2, 0, o_textfieldTooltip )
1513         [o_combo setAutoresizingMask:NSViewWidthSizable ];
1514         for( i_index = 0; i_index < p_item->i_list; i_index++ )
1515         {
1516             if( p_item->i_value == p_item->pi_list[i_index] )
1517             {
1518                 [o_combo selectItemAtIndex: i_index];
1519             }
1520         }
1521         [self addSubview: o_combo];
1522     }
1523     return self;
1524 }
1525
1526 - (void)dealloc
1527 {
1528     [o_combo release];
1529     [super dealloc];
1530 }
1531
1532 - (int)intValue
1533 {
1534     if( [o_combo indexOfSelectedItem] >= 0 )
1535         return p_item->pi_list[[o_combo indexOfSelectedItem]];
1536     else
1537         return [o_combo intValue];
1538 }
1539 @end
1540
1541 @implementation IntegerListConfigControl (NSComboBoxDataSource)
1542 - (int)numberOfItemsInComboBox:(NSComboBox *)aComboBox
1543 {
1544     return p_item->i_list;
1545 }
1546
1547 - (id)comboBox:(NSComboBox *)aComboBox objectValueForItemAtIndex:(int)i_index
1548 {
1549     if( p_item->ppsz_list_text && p_item->ppsz_list_text[i_index] )
1550         return [[VLCMain sharedInstance]
1551                     localizedString: p_item->ppsz_list_text[i_index]];
1552     else
1553         return [NSString stringWithFormat: @"%i", p_item->pi_list[i_index]];
1554 }
1555 @end
1556
1557 @implementation RangedIntegerConfigControl
1558 - (id) initWithItem: (module_config_t *)_p_item
1559            withView: (NSView *)o_parent_view
1560            withVerticalOffset: (int)i_yPos
1561 {
1562     NSRect mainFrame = [o_parent_view frame];
1563     NSString *o_labelString, *o_tooltip;
1564     mainFrame.size.height = 50;
1565     mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN;
1566     mainFrame.origin.x = LEFTMARGIN;
1567     mainFrame.origin.y = i_yPos;
1568
1569     if( [super initWithFrame: mainFrame item: _p_item] != nil )
1570     {
1571         i_view_type = CONFIG_ITEM_RANGED_INTEGER;
1572
1573         /* add the label */
1574         if( p_item->psz_text )
1575             o_labelString = [[VLCMain sharedInstance]
1576                                 localizedString: p_item->psz_text];
1577         else
1578             o_labelString = [NSString stringWithString:@""];
1579         ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString )
1580         [o_label setAutoresizingMask:NSViewNotSizable ];
1581         [self addSubview: o_label];
1582
1583         /* build the textfield */
1584         o_tooltip = [[VLCMain sharedInstance] wrapString:
1585             [[VLCMain sharedInstance]
1586                 localizedString: p_item->psz_longtext ] toWidth: PREFS_WRAP];
1587         ADD_TEXTFIELD( o_textfield, mainFrame, [o_label frame].size.width + 2,
1588             28, 49, o_tooltip, @"" )
1589         [o_textfield setIntValue: p_item->i_value];
1590         [o_textfield setAutoresizingMask:NSViewMaxXMargin ];
1591         [o_textfield setDelegate: self];
1592         [[NSNotificationCenter defaultCenter] addObserver: self
1593             selector: @selector(textfieldChanged:)
1594             name: NSControlTextDidChangeNotification
1595             object: o_textfield];
1596         [self addSubview: o_textfield];
1597
1598         /* build the mintextfield */
1599         ADD_LABEL( o_textfield_min, mainFrame, 12, -30, @"-8888" )
1600         [o_textfield_min setIntValue: p_item->i_min];
1601         [o_textfield_min setAutoresizingMask:NSViewMaxXMargin ];
1602         [self addSubview: o_textfield_min];
1603
1604         /* build the maxtextfield */
1605         ADD_LABEL( o_textfield_max, mainFrame,
1606                     mainFrame.size.width - 31, -30, @"8888" )
1607         [o_textfield_max setIntValue: p_item->i_max];
1608         [o_textfield_max setAutoresizingMask:NSViewMinXMargin ];
1609         [self addSubview: o_textfield_max];
1610
1611         /* build the slider */
1612         ADD_SLIDER( o_slider, mainFrame, [o_textfield_min frame].origin.x +
1613             [o_textfield_min frame].size.width + 6, -1, mainFrame.size.width -
1614             [o_textfield_max frame].size.width -
1615             [o_textfield_max frame].size.width - 14 -
1616             [o_textfield_min frame].origin.x, o_tooltip,
1617             p_item->i_min, p_item->i_max )
1618         [o_slider setIntValue: p_item->i_value];
1619         [o_slider setAutoresizingMask:NSViewWidthSizable ];
1620         [o_slider setTarget: self];
1621         [o_slider setAction: @selector(sliderChanged:)];
1622         [o_slider sendActionOn:NSLeftMouseUpMask | NSLeftMouseDownMask |
1623             NSLeftMouseDraggedMask];
1624         [self addSubview: o_slider];
1625
1626     }
1627     return self;
1628 }
1629
1630 - (void)dealloc
1631 {
1632     [o_textfield release];
1633     [o_textfield_min release];
1634     [o_textfield_max release];
1635     [o_slider release];
1636     [super dealloc];
1637 }
1638
1639 - (IBAction)sliderChanged:(id)sender
1640 {
1641     [o_textfield setIntValue: [o_slider intValue]];
1642 }
1643
1644 - (void)textfieldChanged:(NSNotification *)o_notification
1645 {
1646     [o_slider setIntValue: [o_textfield intValue]];
1647 }
1648
1649 - (int)intValue
1650 {
1651     return [o_slider intValue];
1652 }
1653 @end
1654
1655 @implementation FloatConfigControl
1656 - (id) initWithItem: (module_config_t *)_p_item
1657            withView: (NSView *)o_parent_view
1658            withVerticalOffset: (int)i_yPos
1659 {
1660     NSRect mainFrame = [o_parent_view frame];
1661     NSString *o_labelString, *o_tooltip, *o_textfieldString;
1662     mainFrame.size.height = 23;
1663     mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN + 1;
1664     mainFrame.origin.x = LEFTMARGIN;
1665     mainFrame.origin.y = i_yPos;
1666
1667     if( [super initWithFrame: mainFrame item: _p_item] != nil )
1668     {
1669         i_view_type = CONFIG_ITEM_INTEGER;
1670
1671         o_tooltip = [[VLCMain sharedInstance] wrapString:
1672             [[VLCMain sharedInstance]
1673                 localizedString: p_item->psz_longtext ] toWidth: PREFS_WRAP];
1674
1675         /* add the label */
1676         if( p_item->psz_text )
1677             o_labelString = [[VLCMain sharedInstance]
1678                                 localizedString: p_item->psz_text];
1679         else
1680             o_labelString = [NSString stringWithString:@""];
1681         ADD_LABEL( o_label, mainFrame, 0, -2, o_labelString )
1682         [o_label setAutoresizingMask:NSViewNotSizable ];
1683         [self addSubview: o_label];
1684
1685         /* build the stepper */
1686         ADD_STEPPER( o_stepper, mainFrame, mainFrame.size.width - 19,
1687             0, o_tooltip, -1600, 1600)
1688         [o_stepper setFloatValue: p_item->f_value];
1689         [o_stepper setAutoresizingMask:NSViewMinXMargin ];
1690         [self addSubview: o_stepper];
1691
1692         /* build the textfield */
1693         if( p_item->psz_value )
1694             o_textfieldString = [[VLCMain sharedInstance]
1695                                     localizedString: p_item->psz_value];
1696         else
1697             o_textfieldString = [NSString stringWithString: @""];
1698         ADD_TEXTFIELD( o_textfield, mainFrame, mainFrame.size.width - 19 - 52,
1699             1, 49, o_tooltip, @"" )
1700         [o_textfield setFloatValue: p_item->f_value];
1701         [o_textfield setDelegate: self];
1702         [[NSNotificationCenter defaultCenter] addObserver: self
1703             selector: @selector(textfieldChanged:)
1704             name: NSControlTextDidChangeNotification
1705             object: o_textfield];
1706         [o_textfield setAutoresizingMask:NSViewMinXMargin ];
1707         [self addSubview: o_textfield];
1708     }
1709     return self;
1710 }
1711
1712 - (void)dealloc
1713 {
1714     [o_stepper release];
1715     [o_textfield release];
1716     [super dealloc];
1717 }
1718
1719 - (IBAction)stepperChanged:(id)sender
1720 {
1721     [o_textfield setFloatValue: [o_stepper floatValue]];
1722 }
1723
1724 - (void)textfieldChanged:(NSNotification *)o_notification
1725 {
1726     [o_stepper setFloatValue: [o_textfield floatValue]];
1727 }
1728
1729 - (int)floatValue
1730 {
1731     return [o_stepper floatValue];
1732 }
1733 @end
1734
1735 @implementation RangedFloatConfigControl
1736 - (id) initWithItem: (module_config_t *)_p_item
1737            withView: (NSView *)o_parent_view
1738            withVerticalOffset: (int)i_yPos
1739 {
1740     NSRect mainFrame = [o_parent_view frame];
1741     NSString *o_labelString, *o_tooltip;
1742     mainFrame.size.height = 50;
1743     mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN;
1744     mainFrame.origin.x = LEFTMARGIN;
1745     mainFrame.origin.y = i_yPos;
1746
1747     if( [super initWithFrame: mainFrame item: _p_item] != nil )
1748     {
1749         i_view_type = CONFIG_ITEM_RANGED_INTEGER;
1750
1751         /* add the label */
1752         if( p_item->psz_text )
1753             o_labelString = [[VLCMain sharedInstance]
1754                                 localizedString: p_item->psz_text];
1755         else
1756             o_labelString = [NSString stringWithString:@""];
1757         ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString )
1758         [o_label setAutoresizingMask:NSViewNotSizable ];
1759         [self addSubview: o_label];
1760
1761         /* build the textfield */
1762         o_tooltip = [[VLCMain sharedInstance] wrapString:
1763             [[VLCMain sharedInstance]
1764                 localizedString: p_item->psz_longtext ] toWidth: PREFS_WRAP];
1765         ADD_TEXTFIELD( o_textfield, mainFrame, [o_label frame].size.width + 2,
1766             28, 49, o_tooltip, @"" )
1767         [o_textfield setFloatValue: p_item->f_value];
1768         [o_textfield setAutoresizingMask:NSViewMaxXMargin ];
1769         [o_textfield setDelegate: self];
1770         [[NSNotificationCenter defaultCenter] addObserver: self
1771             selector: @selector(textfieldChanged:)
1772             name: NSControlTextDidChangeNotification
1773             object: o_textfield];
1774         [self addSubview: o_textfield];
1775
1776         /* build the mintextfield */
1777         ADD_LABEL( o_textfield_min, mainFrame, 12, -30, @"-8888" )
1778         [o_textfield_min setFloatValue: p_item->f_min];
1779         [o_textfield_min setAutoresizingMask:NSViewMaxXMargin ];
1780         [self addSubview: o_textfield_min];
1781
1782         /* build the maxtextfield */
1783         ADD_LABEL( o_textfield_max, mainFrame, mainFrame.size.width - 31,
1784             -30, @"8888" )
1785         [o_textfield_max setFloatValue: p_item->f_max];
1786         [o_textfield_max setAutoresizingMask:NSViewMinXMargin ];
1787         [self addSubview: o_textfield_max];
1788
1789         /* build the slider */
1790         ADD_SLIDER( o_slider, mainFrame, [o_textfield_min frame].origin.x +
1791             [o_textfield_min frame].size.width + 6, -1, mainFrame.size.width -
1792             [o_textfield_max frame].size.width -
1793             [o_textfield_max frame].size.width - 14 -
1794             [o_textfield_min frame].origin.x, o_tooltip, p_item->f_min,
1795             p_item->f_max )
1796         [o_slider setFloatValue: p_item->f_value];
1797         [o_slider setAutoresizingMask:NSViewWidthSizable ];
1798         [o_slider setTarget: self];
1799         [o_slider setAction: @selector(sliderChanged:)];
1800         [o_slider sendActionOn:NSLeftMouseUpMask | NSLeftMouseDownMask |
1801             NSLeftMouseDraggedMask];
1802         [self addSubview: o_slider];
1803
1804     }
1805     return self;
1806 }
1807
1808 - (void)dealloc
1809 {
1810     [o_textfield release];
1811     [o_textfield_min release];
1812     [o_textfield_max release];
1813     [o_slider release];
1814     [super dealloc];
1815 }
1816
1817 - (IBAction)sliderChanged:(id)sender
1818 {
1819     [o_textfield setFloatValue: [o_slider floatValue]];
1820 }
1821
1822 - (void)textfieldChanged:(NSNotification *)o_notification
1823 {
1824     [o_slider setFloatValue: [o_textfield floatValue]];
1825 }
1826
1827 - (int)floatValue
1828 {
1829     return [o_slider floatValue];
1830 }
1831
1832 @end
1833
1834 @implementation BoolConfigControl
1835
1836 - (id) initWithItem: (module_config_t *)_p_item
1837            withView: (NSView *)o_parent_view
1838            withVerticalOffset: (int)i_yPos
1839 {
1840     NSRect mainFrame = [o_parent_view frame];
1841     NSString *o_labelString, *o_tooltip;
1842     mainFrame.size.height = 17;
1843     mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN;
1844     mainFrame.origin.x = LEFTMARGIN;
1845     mainFrame.origin.y = i_yPos;
1846
1847     if( [super initWithFrame: mainFrame item: _p_item] != nil )
1848     {
1849         i_view_type = CONFIG_ITEM_BOOL;
1850
1851         /* add the checkbox */
1852         if( p_item->psz_text )
1853             o_labelString = [[VLCMain sharedInstance]
1854                                 localizedString: p_item->psz_text];
1855         else
1856             o_labelString = [NSString stringWithString:@""];
1857         o_tooltip = [[VLCMain sharedInstance]
1858             wrapString: [[VLCMain sharedInstance]
1859             localizedString: p_item->psz_longtext ] toWidth: PREFS_WRAP];
1860         ADD_CHECKBOX( o_checkbox, mainFrame, 0, 0, o_labelString,
1861             o_tooltip, p_item->i_value, NSImageRight)
1862         [o_checkbox setAutoresizingMask:NSViewNotSizable ];
1863         [self addSubview: o_checkbox];
1864     }
1865     return self;
1866 }
1867
1868 - (void)dealloc
1869 {
1870     [o_checkbox release];
1871     [super dealloc];
1872 }
1873
1874 - (int)intValue
1875 {
1876     return [o_checkbox intValue];
1877 }
1878
1879 @end
1880
1881 @implementation KeyConfigControlBefore103
1882
1883 - (id) initWithItem: (module_config_t *)_p_item
1884            withView: (NSView *)o_parent_view
1885            withVerticalOffset: (int)i_yPos
1886 {
1887     NSRect mainFrame = [o_parent_view frame];
1888     NSString *o_labelString, *o_tooltip;
1889     mainFrame.size.height = 37;
1890     mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN + 1;
1891     mainFrame.origin.x = LEFTMARGIN;
1892     mainFrame.origin.y = i_yPos;
1893
1894     if( [super initWithFrame: mainFrame item: _p_item] != nil )
1895     {
1896         i_view_type = CONFIG_ITEM_KEY_BEFORE_10_3;
1897
1898         /* add the label */
1899         if( p_item->psz_text )
1900             o_labelString = [[VLCMain sharedInstance]
1901                                 localizedString: p_item->psz_text];
1902         else
1903             o_labelString = [NSString stringWithString:@""];
1904         ADD_LABEL( o_label, mainFrame, 0, -10, o_labelString )
1905         [o_label setAutoresizingMask:NSViewNotSizable ];
1906         [self addSubview: o_label];
1907
1908         /* add the checkboxes */
1909         o_tooltip = [[VLCMain sharedInstance] wrapString:
1910             [[VLCMain sharedInstance]
1911                 localizedString: p_item->psz_longtext ] toWidth: PREFS_WRAP];
1912         ADD_CHECKBOX( o_cmd_checkbox, mainFrame,
1913             [o_label frame].size.width + 2, 0,
1914             [NSString stringWithUTF8String:PLACE_OF_INTEREST_SIGN], o_tooltip,
1915             ((((unsigned int)p_item->i_value) & KEY_MODIFIER_COMMAND)?YES:NO),
1916             NSImageLeft )
1917         [o_cmd_checkbox setState: p_item->i_value & KEY_MODIFIER_COMMAND];
1918         ADD_CHECKBOX( o_ctrl_checkbox, mainFrame,
1919             [o_cmd_checkbox frame].size.width +
1920             [o_cmd_checkbox frame].origin.x + 6, 0,
1921             [NSString stringWithUTF8String:UP_ARROWHEAD], o_tooltip,
1922             ((((unsigned int)p_item->i_value) & KEY_MODIFIER_CTRL)?YES:NO),
1923             NSImageLeft )
1924         [o_ctrl_checkbox setState: p_item->i_value & KEY_MODIFIER_CTRL];
1925         ADD_CHECKBOX( o_alt_checkbox, mainFrame, [o_label frame].size.width +
1926             2, -2 - [o_cmd_checkbox frame].size.height,
1927             [NSString stringWithUTF8String:OPTION_KEY], o_tooltip,
1928             ((((unsigned int)p_item->i_value) & KEY_MODIFIER_ALT)?YES:NO),
1929             NSImageLeft )
1930         [o_alt_checkbox setState: p_item->i_value & KEY_MODIFIER_ALT];
1931         ADD_CHECKBOX( o_shift_checkbox, mainFrame,
1932             [o_cmd_checkbox frame].size.width +
1933             [o_cmd_checkbox frame].origin.x + 6, -2 -
1934             [o_cmd_checkbox frame].size.height,
1935             [NSString stringWithUTF8String:UPWARDS_WHITE_ARROW], o_tooltip,
1936             ((((unsigned int)p_item->i_value) & KEY_MODIFIER_SHIFT)?YES:NO),
1937             NSImageLeft )
1938         [o_shift_checkbox setState: p_item->i_value & KEY_MODIFIER_SHIFT];
1939         [self addSubview: o_cmd_checkbox];
1940         [self addSubview: o_ctrl_checkbox];
1941         [self addSubview: o_alt_checkbox];
1942         [self addSubview: o_shift_checkbox];
1943
1944         /* build the popup */
1945         ADD_POPUP( o_popup, mainFrame, [o_shift_checkbox frame].origin.x +
1946             [o_shift_checkbox frame].size.width + 4,
1947             4, 0, o_tooltip )
1948         [o_popup setAutoresizingMask:NSViewWidthSizable ];
1949
1950         if( o_keys_menu == nil )
1951         {
1952             unsigned int i;
1953             o_keys_menu = [[NSMenu alloc] initWithTitle: @"Keys Menu"];
1954             for ( i = 0; i < sizeof(vlc_keys) / sizeof(key_descriptor_t); i++)
1955                 if( vlc_keys[i].psz_key_string && *vlc_keys[i].psz_key_string )
1956                     POPULATE_A_KEY( o_keys_menu,
1957                         [NSString stringWithCString:vlc_keys[i].psz_key_string]
1958                         , vlc_keys[i].i_key_code)
1959         }
1960         [o_popup setMenu:[o_keys_menu copyWithZone:nil]];
1961         [o_popup selectItemWithTitle: [[VLCMain sharedInstance]
1962             localizedString:KeyToString(
1963             (((unsigned int)p_item->i_value) & ~KEY_MODIFIER ))]];
1964         [self addSubview: o_popup];
1965     }
1966     return self;
1967 }
1968
1969 - (void)dealloc
1970 {
1971     [o_cmd_checkbox release];
1972     [o_ctrl_checkbox release];
1973     [o_alt_checkbox release];
1974     [o_shift_checkbox release];
1975     [o_popup release];
1976     [super dealloc];
1977 }
1978
1979 - (int)intValue
1980 {
1981     unsigned int i_new_key = 0;
1982
1983     i_new_key |= ([o_cmd_checkbox state] == NSOnState) ?
1984         KEY_MODIFIER_COMMAND : 0;
1985     i_new_key |= ([o_ctrl_checkbox state] == NSOnState) ?
1986         KEY_MODIFIER_CTRL : 0;
1987     i_new_key |= ([o_alt_checkbox state] == NSOnState) ?
1988         KEY_MODIFIER_ALT : 0;
1989     i_new_key |= ([o_shift_checkbox state] == NSOnState) ?
1990         KEY_MODIFIER_SHIFT : 0;
1991
1992     i_new_key |= StringToKey([[[o_popup selectedItem] title] cString]);
1993     return i_new_key;
1994 }
1995 @end
1996
1997 @implementation KeyConfigControlAfter103
1998 - (id) initWithItem: (module_config_t *)_p_item
1999            withView: (NSView *)o_parent_view
2000            withVerticalOffset: (int)i_yPos
2001 {
2002     NSRect mainFrame = [o_parent_view frame];
2003     NSString *o_labelString, *o_tooltip;
2004     mainFrame.size.height = 22;
2005     mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN + 1;
2006     mainFrame.origin.x = LEFTMARGIN;
2007     mainFrame.origin.y = i_yPos;
2008
2009     if( [super initWithFrame: mainFrame item: _p_item] != nil )
2010     {
2011         i_view_type = CONFIG_ITEM_KEY_AFTER_10_3;
2012
2013         /* add the label */
2014         if( p_item->psz_text )
2015             o_labelString = [[VLCMain sharedInstance]
2016                 localizedString: p_item->psz_text];
2017         else
2018             o_labelString = [NSString stringWithString:@""];
2019         ADD_LABEL( o_label, mainFrame, 0, -1, o_labelString )
2020         [o_label setAutoresizingMask:NSViewNotSizable ];
2021         [self addSubview: o_label];
2022
2023         /* build the popup */
2024         o_tooltip = [[VLCMain sharedInstance] wrapString:
2025             [[VLCMain sharedInstance]
2026                 localizedString: p_item->psz_longtext ] toWidth: PREFS_WRAP];
2027         ADD_POPUP( o_popup, mainFrame, [o_label frame].origin.x +
2028             [o_label frame].size.width + 3,
2029             -2, 0, o_tooltip )
2030         [o_popup setAutoresizingMask:NSViewWidthSizable ];
2031
2032         if( o_keys_menu == nil )
2033         {
2034             unsigned int i;
2035             o_keys_menu = [[NSMenu alloc] initWithTitle: @"Keys Menu"];
2036             for ( i = 0; i < sizeof(vlc_keys) / sizeof(key_descriptor_t); i++)
2037                 if( vlc_keys[i].psz_key_string && *vlc_keys[i].psz_key_string )
2038                     POPULATE_A_KEY( o_keys_menu,
2039                         [NSString stringWithCString:vlc_keys[i].psz_key_string]
2040                         , vlc_keys[i].i_key_code)
2041         }
2042         [o_popup setMenu:[o_keys_menu copyWithZone:nil]];
2043         [o_popup selectItemWithTag: p_item->i_value];
2044         [self addSubview: o_popup];
2045
2046     }
2047     return self;
2048 }
2049
2050 - (void)dealloc
2051 {
2052     [o_popup release];
2053     [super dealloc];
2054 }
2055
2056 - (int)intValue
2057 {
2058     return [o_popup selectedTag];
2059 }
2060 @end
2061
2062 @implementation ModuleListConfigControl
2063 - (id) initWithItem: (module_config_t *)_p_item
2064            withView: (NSView *)o_parent_view
2065            withVerticalOffset: (int)i_yPos
2066 {
2067 if( _p_item->i_type == CONFIG_ITEM_MODULE_LIST )
2068 //TODO....
2069         return nil;
2070
2071 //Fill our array to know how may items we have...
2072     vlc_list_t *p_list;
2073     module_t *p_parser;
2074     int i_index;
2075     NSRect mainFrame = [o_parent_view frame];
2076     NSString *o_labelString, *o_textfieldString, *o_tooltip;
2077
2078     o_modulearray = [[NSMutableArray alloc] initWithCapacity:10];
2079     /* build a list of available modules */
2080     p_list = vlc_list_find( VLCIntf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
2081     for( i_index = 0; i_index < p_list->i_count; i_index++ )
2082     {
2083         p_parser = (module_t *)p_list->p_values[i_index].p_object ;
2084
2085         if( !strcmp( p_parser->psz_object_name, "main" ) )
2086             continue;
2087
2088         module_config_t *p_config = p_parser->p_config;
2089         if( p_config ) do
2090         {
2091             NSString *o_modulelongname, *o_modulename;
2092             NSNumber *o_moduleenabled = nil;
2093             /* Hack: required subcategory is stored in i_min */
2094             if( p_config->i_type == CONFIG_SUBCATEGORY &&
2095                 p_config->i_value == _p_item->i_min )
2096             {
2097                 o_modulelongname = [NSString stringWithCString:
2098                                         p_parser->psz_longname];
2099                 o_modulename = [NSString stringWithCString:
2100                                         p_parser->psz_object_name];
2101
2102                 if( _p_item->psz_value &&
2103                     strstr( _p_item->psz_value, p_parser->psz_object_name ) )
2104                     o_moduleenabled = [NSNumber numberWithBool:YES];
2105                 else
2106                     o_moduleenabled = [NSNumber numberWithBool:NO];
2107
2108                 [o_modulearray addObject:[NSMutableArray
2109                     arrayWithObjects: o_modulename, o_modulelongname,
2110                     o_moduleenabled, nil]];
2111             }
2112         } while( p_config->i_type != CONFIG_HINT_END && p_config++ );
2113     }
2114     vlc_list_release( p_list );
2115
2116     mainFrame.size.height = 30 + 18 * [o_modulearray count];
2117     mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN;
2118     mainFrame.origin.x = LEFTMARGIN;
2119     mainFrame.origin.y = i_yPos;
2120     if( [super initWithFrame: mainFrame item: _p_item] != nil )
2121     {
2122         i_view_type = CONFIG_ITEM_MODULE_LIST;
2123
2124         /* add the label */
2125         if( p_item->psz_text )
2126             o_labelString = [[VLCMain sharedInstance]
2127                                 localizedString: p_item->psz_text];
2128         else
2129             o_labelString = [NSString stringWithString:@""];
2130         ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString )
2131         [o_label setAutoresizingMask:NSViewNotSizable ];
2132         [self addSubview: o_label];
2133
2134         /* build the textfield */
2135         o_tooltip = [[VLCMain sharedInstance] wrapString:
2136             [[VLCMain sharedInstance]
2137                 localizedString: p_item->psz_longtext ] toWidth: PREFS_WRAP];
2138         if( p_item->psz_value )
2139             o_textfieldString = [[VLCMain sharedInstance]
2140                 localizedString: p_item->psz_value];
2141         else
2142             o_textfieldString = [NSString stringWithString: @""];
2143         ADD_TEXTFIELD( o_textfield, mainFrame, [o_label frame].size.width + 2,
2144             mainFrame.size.height - 22, mainFrame.size.width -
2145             [o_label frame].size.width - 2, o_tooltip, o_textfieldString )
2146         [o_textfield setAutoresizingMask:NSViewWidthSizable ];
2147         [self addSubview: o_textfield];
2148
2149
2150 {
2151     NSRect s_rc = mainFrame;
2152     s_rc.size.height = mainFrame.size.height - 30;
2153     s_rc.size.width = mainFrame.size.width - 12;
2154     s_rc.origin.x = 12;
2155     s_rc.origin.y = 0;
2156     o_scrollview = [[[NSScrollView alloc] initWithFrame: s_rc] retain];
2157     [o_scrollview setDrawsBackground: NO];
2158     [o_scrollview setBorderType: NSBezelBorder];
2159     [o_scrollview setAutohidesScrollers:YES];
2160
2161     NSTableView *o_tableview;
2162     o_tableview = [[NSTableView alloc] initWithFrame : s_rc];
2163     [o_tableview setUsesAlternatingRowBackgroundColors:YES];
2164     [o_tableview setHeaderView:nil];
2165 /* TODO: find a good way to fix the row height and text size*/
2166 /* FIXME: support for multiple selection... */
2167 //    [o_tableview setAllowsMultipleSelection:YES];
2168
2169     NSCell *o_headerCell = [[NSCell alloc] initTextCell:@"Enabled"];
2170     NSCell *o_dataCell = [[NSButtonCell alloc] init];
2171     [(NSButtonCell*)o_dataCell setButtonType:NSSwitchButton];
2172     [o_dataCell setTitle:@""];
2173     [o_dataCell setFont:[NSFont systemFontOfSize:0]];
2174     NSTableColumn *o_tableColumn = [[NSTableColumn alloc]
2175         initWithIdentifier:[NSString stringWithCString: "Enabled"]];
2176     [o_tableColumn setHeaderCell: o_headerCell];
2177     [o_tableColumn setDataCell: o_dataCell];
2178     [o_tableColumn setWidth:17];
2179     [o_tableview addTableColumn: o_tableColumn];
2180
2181     o_headerCell = [[NSCell alloc] initTextCell:@"Module Name"];
2182     o_dataCell = [[NSTextFieldCell alloc] init];
2183     [o_dataCell setFont:[NSFont systemFontOfSize:12]];
2184     o_tableColumn = [[NSTableColumn alloc]
2185         initWithIdentifier:[NSString stringWithCString: "Module"]];
2186     [o_tableColumn setHeaderCell: o_headerCell];
2187     [o_tableColumn setDataCell: o_dataCell];
2188     [o_tableColumn setWidth:388 - 17];
2189     [o_tableview addTableColumn: o_tableColumn];
2190     [o_tableview registerForDraggedTypes:[NSArray arrayWithObjects:
2191             @"VLC media player module", nil]];
2192
2193     [o_tableview setDataSource:self];
2194     [o_tableview setTarget: self];
2195     [o_tableview setAction: @selector(tableChanged:)];
2196     [o_tableview sendActionOn:NSLeftMouseUpMask | NSLeftMouseDownMask |
2197         NSLeftMouseDraggedMask];
2198     [o_scrollview setDocumentView: o_tableview];
2199 }
2200     [o_scrollview setAutoresizingMask:NSViewWidthSizable ];
2201     [self addSubview: o_scrollview];
2202
2203
2204     }
2205     return self;
2206 }
2207
2208 - (IBAction)tableChanged:(id)sender
2209 {
2210     NSString *o_newstring = @"";
2211     unsigned int i;
2212     for( i = 0 ; i < [o_modulearray count] ; i++ )
2213         if( [[[o_modulearray objectAtIndex:i] objectAtIndex:2]
2214             boolValue] != NO )
2215         {
2216             o_newstring = [o_newstring stringByAppendingString:
2217                 [[o_modulearray objectAtIndex:i] objectAtIndex:0]];
2218             o_newstring = [o_newstring stringByAppendingString:@","];
2219         }
2220
2221     [o_textfield setStringValue: [o_newstring
2222         substringToIndex: ([o_newstring length])?[o_newstring length] - 1:0]];
2223 }
2224
2225 - (void)dealloc
2226 {
2227     [o_scrollview release];
2228     [super dealloc];
2229 }
2230
2231
2232 - (char *)stringValue
2233 {
2234     return strdup( [[o_textfield stringValue] cString] );
2235 }
2236
2237 @end
2238
2239 @implementation ModuleListConfigControl (NSTableDataSource)
2240
2241 - (BOOL)tableView:(NSTableView*)table writeRows:(NSArray*)rows
2242     toPasteboard:(NSPasteboard*)pb
2243 {
2244     // We only want to allow dragging of selected rows.
2245     NSEnumerator    *iter = [rows objectEnumerator];
2246     NSNumber        *row;
2247     while ((row = [iter nextObject]) != nil)
2248     {
2249         if (![table isRowSelected:[row intValue]])
2250             return NO;
2251     }
2252
2253     [pb declareTypes:[NSArray
2254         arrayWithObject:@"VLC media player module"] owner:nil];
2255     [pb setPropertyList:rows forType:@"VLC media player module"];
2256     return YES;
2257 }
2258
2259 - (NSDragOperation)tableView:(NSTableView*)table
2260     validateDrop:(id <NSDraggingInfo>)info proposedRow:(int)row
2261     proposedDropOperation:(NSTableViewDropOperation)op
2262 {
2263     // Make drops at the end of the table go to the end.
2264     if (row == -1)
2265     {
2266         row = [table numberOfRows];
2267         op = NSTableViewDropAbove;
2268         [table setDropRow:row dropOperation:op];
2269     }
2270
2271     // We don't ever want to drop onto a row, only between rows.
2272     if (op == NSTableViewDropOn)
2273         [table setDropRow:(row+1) dropOperation:NSTableViewDropAbove];
2274     return NSTableViewDropAbove;
2275 }
2276
2277 - (BOOL)tableView:(NSTableView*)table acceptDrop:(id <NSDraggingInfo>)info
2278     row:(int)dropRow dropOperation:(NSTableViewDropOperation)op;
2279 {
2280     NSPasteboard    *pb = [info draggingPasteboard];
2281     NSDragOperation srcMask = [info draggingSourceOperationMask];
2282     BOOL accepted = NO;
2283
2284     NS_DURING
2285
2286         NSArray *array;
2287
2288         // Intra-table drag - data is the array of rows.
2289         if (!accepted && (array =
2290             [pb propertyListForType:@"VLC media player module"]) != NULL)
2291         {
2292             NSEnumerator *iter = nil;
2293             id val;
2294             BOOL isCopy = (srcMask & NSDragOperationMove) ? NO:YES;
2295             // Move the modules
2296             iter = [array objectEnumerator];
2297             while ((val = [iter nextObject]) != NULL)
2298             {
2299                 NSArray *o_tmp = [[o_modulearray objectAtIndex:
2300                     [val intValue]] mutableCopyWithZone:nil];
2301                 [o_modulearray removeObject:o_tmp];
2302                 [o_modulearray insertObject:o_tmp
2303                     atIndex:(dropRow>[val intValue]) ? dropRow - 1 : dropRow];
2304                 dropRow++;
2305             }
2306
2307             // Select the newly-dragged items.
2308             iter = [array objectEnumerator];
2309 //TODO...
2310             [table deselectAll:self];
2311
2312             [self tableChanged:self];
2313             [table setNeedsDisplay:YES];
2314             // Indicate that we finished the drag.
2315             accepted = YES;
2316         }
2317         [table reloadData];
2318         [table setNeedsDisplay:YES];
2319
2320         NS_HANDLER
2321
2322             // An exception occurred. Uh-oh. Update the track table so that
2323             // it stays consistent, and re-raise the exception.
2324             [table reloadData];
2325             [localException raise];
2326             [table setNeedsDisplay:YES];
2327     NS_ENDHANDLER
2328
2329     return accepted;
2330 }
2331
2332 - (int)numberOfRowsInTableView:(NSTableView *)aTableView
2333 {
2334     return [o_modulearray count];
2335 }
2336
2337 - (id)tableView:(NSTableView *)aTableView
2338     objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex
2339 {
2340     if( [[aTableColumn identifier] isEqualToString:
2341         [NSString stringWithCString:"Enabled"]] )
2342         return [[o_modulearray objectAtIndex:rowIndex] objectAtIndex:2];
2343     if( [[aTableColumn identifier] isEqualToString:
2344         [NSString stringWithCString:"Module"]] )
2345         return [[o_modulearray objectAtIndex:rowIndex] objectAtIndex:1];
2346
2347     return nil;
2348 }
2349
2350 - (void)tableView:(NSTableView *)aTableView setObjectValue:(id)anObject
2351     forTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex
2352 {
2353     [[o_modulearray objectAtIndex:rowIndex] replaceObjectAtIndex:2
2354         withObject: anObject];
2355 }
2356 @end