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