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