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