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