]> git.sesse.net Git - vlc/blob - modules/gui/macosx/prefs_widgets.m
* collection of various fixes and edits
[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 = [[VLCMain sharedInstance]
1190                                     localizedString: (char *)p_item->value.psz];
1191         else
1192             o_textfieldString = [NSString stringWithString: @""];
1193         ADD_TEXTFIELD( o_textfield, mainFrame, 12, 2, mainFrame.size.width -
1194                         8 - [o_button frame].size.width,
1195                         o_textfieldTooltip, o_textfieldString )
1196         [o_textfield setAutoresizingMask:NSViewWidthSizable ];
1197         [self addSubview: o_textfield];
1198     }
1199     return self;
1200 }
1201
1202 - (void) alignWithXPosition:(int)i_xPos
1203 {
1204     ;
1205 }
1206
1207 - (void)dealloc
1208 {
1209     [o_textfield release];
1210     [o_button release];
1211     [super dealloc];
1212 }
1213
1214 - (IBAction)openFileDialog: (id)sender
1215 {
1216     NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
1217
1218     [o_open_panel setTitle: (b_directory)?
1219         _NS("Select a directory"):_NS("Select a file")];
1220     [o_open_panel setPrompt: _NS("Select")];
1221     [o_open_panel setAllowsMultipleSelection: NO];
1222     [o_open_panel setCanChooseFiles: !b_directory];
1223     [o_open_panel setCanChooseDirectories: b_directory];
1224     [o_open_panel beginSheetForDirectory:nil
1225         file:nil
1226         types:nil
1227         modalForWindow:[sender window]
1228         modalDelegate: self
1229         didEndSelector: @selector(pathChosenInPanel: 
1230                         withReturn:
1231                         contextInfo:)
1232         contextInfo: nil];
1233 }
1234
1235 - (void)pathChosenInPanel:(NSOpenPanel *)o_sheet
1236     withReturn:(int)i_return_code contextInfo:(void  *)o_context_info
1237 {
1238     if( i_return_code == NSOKButton )
1239     {
1240         NSString *o_path = [[o_sheet filenames] objectAtIndex: 0];
1241         [o_textfield setStringValue: o_path];
1242     }
1243 }
1244
1245 - (char *)stringValue
1246 {
1247     if( [[o_textfield stringValue] length] != 0)
1248         return strdup( [[o_textfield stringValue] fileSystemRepresentation] );
1249     else
1250         return NULL;
1251 }
1252 @end
1253
1254 @implementation ModuleConfigControl
1255 - (id) initWithItem: (module_config_t *)_p_item
1256            withView: (NSView *)o_parent_view
1257 {
1258     NSRect mainFrame = [o_parent_view frame];
1259     NSString *o_labelString, *o_popupTooltip;
1260     mainFrame.size.height = 22;
1261     mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN + 1;
1262     mainFrame.origin.x = LEFTMARGIN;
1263     mainFrame.origin.y = 0;
1264
1265     if( [super initWithFrame: mainFrame item: _p_item] != nil )
1266     {
1267         int i_index;
1268         vlc_list_t *p_list;
1269         module_t *p_parser;
1270         module_config_t *p_end;
1271         i_view_type = CONFIG_ITEM_MODULE;
1272
1273         /* add the label */
1274         if( p_item->psz_text )
1275             o_labelString = [[VLCMain sharedInstance]
1276                                 localizedString: (char *)p_item->psz_text];
1277         else
1278             o_labelString = [NSString stringWithString:@""];
1279         ADD_LABEL( o_label, mainFrame, 0, -1, o_labelString )
1280         [o_label setAutoresizingMask:NSViewNotSizable ];
1281         [self addSubview: o_label];
1282
1283         /* build the popup */
1284         o_popupTooltip = [[VLCMain sharedInstance] wrapString:
1285             [[VLCMain sharedInstance]
1286                 localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
1287         ADD_POPUP( o_popup, mainFrame, [o_label frame].size.width,
1288             -2, 0, o_popupTooltip )
1289         [o_popup setAutoresizingMask:NSViewWidthSizable ];
1290         [o_popup addItemWithTitle: _NS("Default")];
1291         [[o_popup lastItem] setTag: -1];
1292         [o_popup selectItem: [o_popup lastItem]];
1293
1294         /* build a list of available modules */
1295         p_list = vlc_list_find( VLCIntf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
1296         for( i_index = 0; i_index < p_list->i_count; i_index++ )
1297         {
1298             p_parser = (module_t *)p_list->p_values[i_index].p_object;
1299             p_end = p_item + p_parser->confsize;
1300             if( p_item->i_type == CONFIG_ITEM_MODULE )
1301             {
1302                 if( !strcmp( p_parser->psz_capability,
1303                             p_item->psz_type ) )
1304                 {
1305                     NSString *o_description = [[VLCMain sharedInstance]
1306                         localizedString: (char *)p_parser->psz_longname];
1307                     [o_popup addItemWithTitle: o_description];
1308
1309                     if( p_item->value.psz &&
1310                 !strcmp( p_item->value.psz, p_parser->psz_object_name ) )
1311                         [o_popup selectItem:[o_popup lastItem]];
1312                 }
1313             }
1314             else
1315             {
1316                 module_config_t *p_config;
1317                 if( !strcmp( p_parser->psz_object_name, "main" ) )
1318                       continue;
1319
1320                 p_config = p_parser->p_config;
1321                 if( p_config ) do
1322                 {
1323                     /* Hack: required subcategory is stored in i_min */
1324                     if( p_config->i_type == CONFIG_SUBCATEGORY &&
1325                         p_config->value.i == p_item->min.i )
1326                     {
1327                         NSString *o_description = [[VLCMain sharedInstance]
1328                             localizedString: (char *)p_parser->psz_longname];
1329                         [o_popup addItemWithTitle: o_description];
1330
1331                         if( p_item->value.psz && !strcmp(p_item->value.psz,
1332                                                 p_parser->psz_object_name) )
1333                             [o_popup selectItem:[o_popup lastItem]];
1334                     }
1335                 } while( p_item < p_end && p_config++ );
1336             }
1337         }
1338         vlc_list_release( p_list );
1339         [self addSubview: o_popup];
1340     }
1341     return self;
1342 }
1343
1344 - (void) alignWithXPosition:(int)i_xPos
1345 {
1346     NSRect frame;
1347     NSRect superFrame = [self frame];
1348     frame = [o_label frame];
1349     frame.origin.x = i_xPos - frame.size.width - 3;
1350     [o_label setFrame:frame];
1351
1352     frame = [o_popup frame];
1353     frame.origin.x = i_xPos - 1;
1354     frame.size.width = superFrame.size.width - frame.origin.x + 2;
1355     [o_popup setFrame:frame];
1356 }
1357
1358 - (void)dealloc
1359 {
1360     [o_popup release];
1361     [super dealloc];
1362 }
1363
1364 - (char *)stringValue
1365 {
1366     NSString *newval = [o_popup titleOfSelectedItem];
1367     char *returnval = NULL;
1368     int i_index;
1369     vlc_list_t *p_list;
1370     module_t *p_parser;
1371     module_config_t *p_end;
1372
1373     p_list = vlc_list_find( VLCIntf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
1374     for( i_index = 0; i_index < p_list->i_count; i_index++ )
1375     {
1376         p_parser = (module_t *)p_list->p_values[i_index].p_object;
1377          p_end = p_item + p_parser->confsize;
1378         if( p_item->i_type == CONFIG_ITEM_MODULE )
1379         {
1380             if( !strcmp( p_parser->psz_capability,
1381                     p_item->psz_type ) )
1382             {
1383                 NSString *o_description = [[VLCMain sharedInstance]
1384                     localizedString: (char *)p_parser->psz_longname];
1385                 if( [newval isEqualToString: o_description] )
1386                 {
1387                     returnval = strdup(p_parser->psz_object_name);
1388                     break;
1389                 }
1390             }
1391         }
1392         else
1393         {
1394             module_config_t *p_config;
1395             if( !strcmp( p_parser->psz_object_name, "main" ) )
1396                   continue;
1397
1398             p_config = p_parser->p_config;
1399             if( p_config ) do
1400             {
1401                 /* Hack: required subcategory is stored in i_min */
1402                 if( p_config->i_type == CONFIG_SUBCATEGORY &&
1403                     p_config->value.i == p_item->min.i )
1404                 {
1405                     NSString *o_description = [[VLCMain sharedInstance]
1406                         localizedString: (char *)p_parser->psz_longname];
1407                     if( [newval isEqualToString: o_description] )
1408                     {
1409                         returnval = strdup(p_parser->psz_object_name);
1410                         break;
1411                     }
1412                 }
1413             } while( p_item < p_end && p_config++ );
1414         }
1415     }
1416     vlc_list_release( p_list );
1417     return returnval;
1418 }
1419 @end
1420
1421 @implementation IntegerConfigControl
1422 - (id) initWithItem: (module_config_t *)_p_item
1423            withView: (NSView *)o_parent_view
1424 {
1425     NSRect mainFrame = [o_parent_view frame];
1426     NSString *o_labelString, *o_tooltip, *o_textfieldString;
1427     mainFrame.size.height = 23;
1428     mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN + 1;
1429     mainFrame.origin.x = LEFTMARGIN;
1430     mainFrame.origin.y = 0;
1431
1432     if( [super initWithFrame: mainFrame item: _p_item] != nil )
1433     {
1434         i_view_type = CONFIG_ITEM_INTEGER;
1435
1436         o_tooltip = [[VLCMain sharedInstance] wrapString:
1437             [[VLCMain sharedInstance]
1438                 localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
1439
1440         /* add the label */
1441         if( p_item->psz_text )
1442             o_labelString = [[VLCMain sharedInstance]
1443                                 localizedString: (char *)p_item->psz_text];
1444         else
1445             o_labelString = [NSString stringWithString:@""];
1446         ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString )
1447         [o_label setAutoresizingMask:NSViewNotSizable ];
1448         [self addSubview: o_label];
1449
1450         /* build the stepper */
1451         ADD_STEPPER( o_stepper, mainFrame, mainFrame.size.width - 19,
1452             0, o_tooltip, -1600, 1600)
1453         [o_stepper setIntValue: p_item->value.i];
1454         [o_stepper setAutoresizingMask:NSViewMaxXMargin ];
1455         [self addSubview: o_stepper];
1456
1457         /* build the textfield */
1458         if( p_item->value.psz )
1459             o_textfieldString = [[VLCMain sharedInstance]
1460                                     localizedString: (char *)p_item->value.psz];
1461         else
1462             o_textfieldString = [NSString stringWithString: @""];
1463         ADD_TEXTFIELD( o_textfield, mainFrame, mainFrame.size.width - 19 - 52,
1464             1, 49, o_tooltip, @"" )
1465         [o_textfield setIntValue: p_item->value.i];
1466         [o_textfield setDelegate: self];
1467         [[NSNotificationCenter defaultCenter] addObserver: self
1468             selector: @selector(textfieldChanged:)
1469             name: NSControlTextDidChangeNotification
1470             object: o_textfield];
1471         [o_textfield setAutoresizingMask:NSViewMaxXMargin ];
1472         [self addSubview: o_textfield];
1473     }
1474     return self;
1475 }
1476
1477 - (void) alignWithXPosition:(int)i_xPos
1478 {
1479     NSRect frame;
1480     frame = [o_label frame];
1481     frame.origin.x = i_xPos - frame.size.width - 3;
1482     [o_label setFrame:frame];
1483
1484     frame = [o_textfield frame];
1485     frame.origin.x = i_xPos + 2;
1486     [o_textfield setFrame:frame];
1487
1488     frame = [o_stepper frame];
1489     frame.origin.x = i_xPos + [o_textfield frame].size.width + 5;
1490     [o_stepper setFrame:frame];
1491 }
1492
1493 - (void)dealloc
1494 {
1495     [o_stepper release];
1496     [o_textfield release];
1497     [super dealloc];
1498 }
1499
1500 - (IBAction)stepperChanged:(id)sender
1501 {
1502     [o_textfield setIntValue: [o_stepper intValue]];
1503 }
1504
1505 - (void)textfieldChanged:(NSNotification *)o_notification
1506 {
1507     [o_stepper setIntValue: [o_textfield intValue]];
1508 }
1509
1510 - (int)intValue
1511 {
1512     return [o_textfield intValue];
1513 }
1514
1515 @end
1516
1517 @implementation IntegerListConfigControl
1518
1519 - (id) initWithItem: (module_config_t *)_p_item
1520            withView: (NSView *)o_parent_view
1521 {
1522     NSRect mainFrame = [o_parent_view frame];
1523     NSString *o_labelString, *o_textfieldTooltip;
1524     mainFrame.size.height = 22;
1525     mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN + 1;
1526     mainFrame.origin.x = LEFTMARGIN;
1527     mainFrame.origin.y = 0;
1528
1529     if( [super initWithFrame: mainFrame item: _p_item] != nil )
1530     {
1531         int i_index;
1532         i_view_type = CONFIG_ITEM_STRING_LIST;
1533
1534         /* add the label */
1535         if( p_item->psz_text )
1536             o_labelString = [[VLCMain sharedInstance]
1537                 localizedString: (char *)p_item->psz_text];
1538         else
1539             o_labelString = [NSString stringWithString:@""];
1540         ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString )
1541         [o_label setAutoresizingMask:NSViewNotSizable ];
1542         [self addSubview: o_label];
1543
1544         /* build the textfield */
1545         o_textfieldTooltip = [[VLCMain sharedInstance] wrapString:
1546             [[VLCMain sharedInstance]
1547                 localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
1548         ADD_COMBO( o_combo, mainFrame, [o_label frame].size.width,
1549             -2, 0, o_textfieldTooltip )
1550         [o_combo setAutoresizingMask:NSViewWidthSizable ];
1551         for( i_index = 0; i_index < p_item->i_list; i_index++ )
1552         {
1553             if( p_item->value.i == p_item->pi_list[i_index] )
1554             {
1555                 [o_combo selectItemAtIndex: i_index];
1556             }
1557         }
1558         [self addSubview: o_combo];
1559     }
1560     return self;
1561 }
1562
1563 - (void) alignWithXPosition:(int)i_xPos
1564 {
1565     NSRect frame;
1566     NSRect superFrame = [self frame];
1567     frame = [o_label frame];
1568     frame.origin.x = i_xPos - frame.size.width - 3;
1569     [o_label setFrame:frame];
1570
1571     frame = [o_combo frame];
1572     frame.origin.x = i_xPos + 2;
1573     frame.size.width = superFrame.size.width - frame.origin.x + 2;
1574     [o_combo setFrame:frame];
1575 }
1576
1577 - (void)dealloc
1578 {
1579     [o_combo release];
1580     [super dealloc];
1581 }
1582
1583 - (int)intValue
1584 {
1585     if( [o_combo indexOfSelectedItem] >= 0 )
1586         return p_item->pi_list[[o_combo indexOfSelectedItem]];
1587     else
1588         return [o_combo intValue];
1589 }
1590 @end
1591
1592 @implementation IntegerListConfigControl (NSComboBoxDataSource)
1593 - (int)numberOfItemsInComboBox:(NSComboBox *)aComboBox
1594 {
1595     return p_item->i_list;
1596 }
1597
1598 - (id)comboBox:(NSComboBox *)aComboBox objectValueForItemAtIndex:(int)i_index
1599 {
1600     if( p_item->ppsz_list_text && p_item->ppsz_list_text[i_index] )
1601         return [[VLCMain sharedInstance]
1602                     localizedString: (char *)p_item->ppsz_list_text[i_index]];
1603     else
1604         return [NSString stringWithFormat: @"%i", p_item->pi_list[i_index]];
1605 }
1606 @end
1607
1608 @implementation RangedIntegerConfigControl
1609 - (id) initWithItem: (module_config_t *)_p_item
1610            withView: (NSView *)o_parent_view
1611 {
1612     NSRect mainFrame = [o_parent_view frame];
1613     NSString *o_labelString, *o_tooltip;
1614     mainFrame.size.height = 50;
1615     mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN;
1616     mainFrame.origin.x = LEFTMARGIN;
1617     mainFrame.origin.y = 0;
1618
1619     if( [super initWithFrame: mainFrame item: _p_item] != nil )
1620     {
1621         i_view_type = CONFIG_ITEM_RANGED_INTEGER;
1622
1623         /* add the label */
1624         if( p_item->psz_text )
1625             o_labelString = [[VLCMain sharedInstance]
1626                                 localizedString: (char *)p_item->psz_text];
1627         else
1628             o_labelString = [NSString stringWithString:@""];
1629         ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString )
1630         [o_label setAutoresizingMask:NSViewNotSizable ];
1631         [self addSubview: o_label];
1632
1633         /* build the textfield */
1634         o_tooltip = [[VLCMain sharedInstance] wrapString:
1635             [[VLCMain sharedInstance]
1636                 localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
1637         ADD_TEXTFIELD( o_textfield, mainFrame, [o_label frame].size.width + 2,
1638             28, 49, o_tooltip, @"" )
1639         [o_textfield setIntValue: p_item->value.i];
1640         [o_textfield setAutoresizingMask:NSViewMaxXMargin ];
1641         [o_textfield setDelegate: self];
1642         [[NSNotificationCenter defaultCenter] addObserver: self
1643             selector: @selector(textfieldChanged:)
1644             name: NSControlTextDidChangeNotification
1645             object: o_textfield];
1646         [self addSubview: o_textfield];
1647
1648         /* build the mintextfield */
1649         ADD_LABEL( o_textfield_min, mainFrame, 12, -30, @"-8888" )
1650         [o_textfield_min setIntValue: p_item->min.i];
1651         [o_textfield_min setAutoresizingMask:NSViewMaxXMargin ];
1652         [o_textfield_min setAlignment:NSRightTextAlignment];
1653         [self addSubview: o_textfield_min];
1654
1655         /* build the maxtextfield */
1656         ADD_LABEL( o_textfield_max, mainFrame,
1657                     mainFrame.size.width - 31, -30, @"8888" )
1658         [o_textfield_max setIntValue: p_item->max.i];
1659         [o_textfield_max setAutoresizingMask:NSViewMinXMargin ];
1660         [self addSubview: o_textfield_max];
1661
1662         /* build the slider */
1663         ADD_SLIDER( o_slider, mainFrame, [o_textfield_min frame].origin.x +
1664             [o_textfield_min frame].size.width + 6, -1, mainFrame.size.width -
1665             [o_textfield_max frame].size.width -
1666             [o_textfield_max frame].size.width - 14 -
1667             [o_textfield_min frame].origin.x, o_tooltip,
1668             p_item->min.i, p_item->max.i )
1669         [o_slider setIntValue: p_item->value.i];
1670         [o_slider setAutoresizingMask:NSViewWidthSizable ];
1671         [o_slider setTarget: self];
1672         [o_slider setAction: @selector(sliderChanged:)];
1673         [o_slider sendActionOn:NSLeftMouseUpMask | NSLeftMouseDownMask |
1674             NSLeftMouseDraggedMask];
1675         [self addSubview: o_slider];
1676
1677     }
1678     return self;
1679 }
1680
1681 - (void) alignWithXPosition:(int)i_xPos
1682 {
1683     NSRect frame;
1684     frame = [o_label frame];
1685     frame.origin.x = i_xPos - frame.size.width - 3;
1686     [o_label setFrame:frame];
1687
1688     frame = [o_textfield frame];
1689     frame.origin.x = i_xPos + 2;
1690     [o_textfield setFrame:frame];
1691 }
1692
1693 - (void)dealloc
1694 {
1695     [o_textfield release];
1696     [o_textfield_min release];
1697     [o_textfield_max release];
1698     [o_slider release];
1699     [super dealloc];
1700 }
1701
1702 - (IBAction)sliderChanged:(id)sender
1703 {
1704     [o_textfield setIntValue: [o_slider intValue]];
1705 }
1706
1707 - (void)textfieldChanged:(NSNotification *)o_notification
1708 {
1709     [o_slider setIntValue: [o_textfield intValue]];
1710 }
1711
1712 - (int)intValue
1713 {
1714     return [o_slider intValue];
1715 }
1716 @end
1717
1718 @implementation FloatConfigControl
1719 - (id) initWithItem: (module_config_t *)_p_item
1720            withView: (NSView *)o_parent_view
1721 {
1722     NSRect mainFrame = [o_parent_view frame];
1723     NSString *o_labelString, *o_tooltip, *o_textfieldString;
1724     mainFrame.size.height = 23;
1725     mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN + 1;
1726     mainFrame.origin.x = LEFTMARGIN;
1727     mainFrame.origin.y = 0;
1728
1729     if( [super initWithFrame: mainFrame item: _p_item] != nil )
1730     {
1731         i_view_type = CONFIG_ITEM_INTEGER;
1732
1733         o_tooltip = [[VLCMain sharedInstance] wrapString:
1734             [[VLCMain sharedInstance]
1735                 localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
1736
1737         /* add the label */
1738         if( p_item->psz_text )
1739             o_labelString = [[VLCMain sharedInstance]
1740                                 localizedString: (char *)p_item->psz_text];
1741         else
1742             o_labelString = [NSString stringWithString:@""];
1743         ADD_LABEL( o_label, mainFrame, 0, -2, o_labelString )
1744         [o_label setAutoresizingMask:NSViewNotSizable ];
1745         [self addSubview: o_label];
1746
1747         /* build the stepper */
1748         ADD_STEPPER( o_stepper, mainFrame, mainFrame.size.width - 19,
1749             0, o_tooltip, -1600, 1600)
1750         [o_stepper setFloatValue: p_item->value.f];
1751         [o_stepper setAutoresizingMask:NSViewMaxXMargin ];
1752         [self addSubview: o_stepper];
1753
1754         /* build the textfield */
1755         if( p_item->value.psz )
1756             o_textfieldString = [[VLCMain sharedInstance]
1757                                     localizedString: (char *)p_item->value.psz];
1758         else
1759             o_textfieldString = [NSString stringWithString: @""];
1760         ADD_TEXTFIELD( o_textfield, mainFrame, mainFrame.size.width - 19 - 52,
1761             1, 49, o_tooltip, @"" )
1762         [o_textfield setFloatValue: p_item->value.f];
1763         [o_textfield setDelegate: self];
1764         [[NSNotificationCenter defaultCenter] addObserver: self
1765             selector: @selector(textfieldChanged:)
1766             name: NSControlTextDidChangeNotification
1767             object: o_textfield];
1768         [o_textfield setAutoresizingMask:NSViewMaxXMargin ];
1769         [self addSubview: o_textfield];
1770     }
1771     return self;
1772 }
1773
1774 - (void) alignWithXPosition:(int)i_xPos
1775 {
1776     NSRect frame;
1777     frame = [o_label frame];
1778     frame.origin.x = i_xPos - frame.size.width - 3;
1779     [o_label setFrame:frame];
1780
1781     frame = [o_textfield frame];
1782     frame.origin.x = i_xPos + 2;
1783     [o_textfield setFrame:frame];
1784
1785     frame = [o_stepper frame];
1786     frame.origin.x = i_xPos + [o_textfield frame].size.width + 5;
1787     [o_stepper setFrame:frame];
1788 }
1789
1790 - (void)dealloc
1791 {
1792     [o_stepper release];
1793     [o_textfield release];
1794     [super dealloc];
1795 }
1796
1797 - (IBAction)stepperChanged:(id)sender
1798 {
1799     [o_textfield setFloatValue: [o_stepper floatValue]];
1800 }
1801
1802 - (void)textfieldChanged:(NSNotification *)o_notification
1803 {
1804     [o_stepper setFloatValue: [o_textfield floatValue]];
1805 }
1806
1807 - (float)floatValue
1808 {
1809     return [o_stepper floatValue];
1810 }
1811 @end
1812
1813 @implementation RangedFloatConfigControl
1814 - (id) initWithItem: (module_config_t *)_p_item
1815            withView: (NSView *)o_parent_view
1816 {
1817     NSRect mainFrame = [o_parent_view frame];
1818     NSString *o_labelString, *o_tooltip;
1819     mainFrame.size.height = 50;
1820     mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN;
1821     mainFrame.origin.x = LEFTMARGIN;
1822     mainFrame.origin.y = 0;
1823
1824     if( [super initWithFrame: mainFrame item: _p_item] != nil )
1825     {
1826         i_view_type = CONFIG_ITEM_RANGED_INTEGER;
1827
1828         /* add the label */
1829         if( p_item->psz_text )
1830             o_labelString = [[VLCMain sharedInstance]
1831                                 localizedString: (char *)p_item->psz_text];
1832         else
1833             o_labelString = [NSString stringWithString:@""];
1834         ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString )
1835         [o_label setAutoresizingMask:NSViewNotSizable ];
1836         [self addSubview: o_label];
1837
1838         /* build the textfield */
1839         o_tooltip = [[VLCMain sharedInstance] wrapString:
1840             [[VLCMain sharedInstance]
1841                 localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
1842         ADD_TEXTFIELD( o_textfield, mainFrame, [o_label frame].size.width + 2,
1843             28, 49, o_tooltip, @"" )
1844         [o_textfield setFloatValue: p_item->value.f];
1845         [o_textfield setAutoresizingMask:NSViewMaxXMargin ];
1846         [o_textfield setDelegate: self];
1847         [[NSNotificationCenter defaultCenter] addObserver: self
1848             selector: @selector(textfieldChanged:)
1849             name: NSControlTextDidChangeNotification
1850             object: o_textfield];
1851         [self addSubview: o_textfield];
1852
1853         /* build the mintextfield */
1854         ADD_LABEL( o_textfield_min, mainFrame, 12, -30, @"-8888" )
1855         [o_textfield_min setFloatValue: p_item->min.f];
1856         [o_textfield_min setAutoresizingMask:NSViewMaxXMargin ];
1857         [o_textfield_min setAlignment:NSRightTextAlignment];
1858         [self addSubview: o_textfield_min];
1859
1860         /* build the maxtextfield */
1861         ADD_LABEL( o_textfield_max, mainFrame, mainFrame.size.width - 31,
1862             -30, @"8888" )
1863         [o_textfield_max setFloatValue: p_item->max.f];
1864         [o_textfield_max setAutoresizingMask:NSViewMinXMargin ];
1865         [self addSubview: o_textfield_max];
1866
1867         /* build the slider */
1868         ADD_SLIDER( o_slider, mainFrame, [o_textfield_min frame].origin.x +
1869             [o_textfield_min frame].size.width + 6, -1, mainFrame.size.width -
1870             [o_textfield_max frame].size.width -
1871             [o_textfield_max frame].size.width - 14 -
1872             [o_textfield_min frame].origin.x, o_tooltip, p_item->min.f,
1873             p_item->max.f )
1874         [o_slider setFloatValue: p_item->value.f];
1875         [o_slider setAutoresizingMask:NSViewWidthSizable ];
1876         [o_slider setTarget: self];
1877         [o_slider setAction: @selector(sliderChanged:)];
1878         [o_slider sendActionOn:NSLeftMouseUpMask | NSLeftMouseDownMask |
1879             NSLeftMouseDraggedMask];
1880         [self addSubview: o_slider];
1881
1882     }
1883     return self;
1884 }
1885
1886 - (void) alignWithXPosition:(int)i_xPos
1887 {
1888     NSRect frame;
1889     frame = [o_label frame];
1890     frame.origin.x = i_xPos - frame.size.width - 3;
1891     [o_label setFrame:frame];
1892
1893     frame = [o_textfield frame];
1894     frame.origin.x = i_xPos + 2;
1895     [o_textfield setFrame:frame];
1896 }
1897
1898 - (void)dealloc
1899 {
1900     [o_textfield release];
1901     [o_textfield_min release];
1902     [o_textfield_max release];
1903     [o_slider release];
1904     [super dealloc];
1905 }
1906
1907 - (IBAction)sliderChanged:(id)sender
1908 {
1909     [o_textfield setFloatValue: [o_slider floatValue]];
1910 }
1911
1912 - (void)textfieldChanged:(NSNotification *)o_notification
1913 {
1914     [o_slider setFloatValue: [o_textfield floatValue]];
1915 }
1916
1917 - (float)floatValue
1918 {
1919     return [o_slider floatValue];
1920 }
1921
1922 @end
1923
1924 @implementation BoolConfigControl
1925
1926 - (id) initWithItem: (module_config_t *)_p_item
1927            withView: (NSView *)o_parent_view
1928 {
1929     NSRect mainFrame = [o_parent_view frame];
1930     NSString *o_labelString, *o_tooltip;
1931     mainFrame.size.height = 17;
1932     mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN;
1933     mainFrame.origin.x = LEFTMARGIN;
1934     mainFrame.origin.y = 0;
1935
1936     if( [super initWithFrame: mainFrame item: _p_item] != nil )
1937     {
1938         i_view_type = CONFIG_ITEM_BOOL;
1939
1940         /* add the checkbox */
1941         o_tooltip = [[VLCMain sharedInstance]
1942             wrapString: [[VLCMain sharedInstance]
1943             localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
1944         ADD_CHECKBOX( o_checkbox, mainFrame, 0,
1945                         0, @"", o_tooltip, p_item->value.i, NSImageLeft)
1946         [o_checkbox setAutoresizingMask:NSViewNotSizable ];
1947         [self addSubview: o_checkbox];
1948         /* add the label */
1949         if( p_item->psz_text )
1950             o_labelString = [[VLCMain sharedInstance]
1951                                 localizedString: (char *)p_item->psz_text];
1952         else
1953             o_labelString = [NSString stringWithString:@""];
1954         ADD_LABEL( o_label, mainFrame, [o_checkbox frame].size.width, 0, o_labelString )
1955         [o_label setAutoresizingMask:NSViewNotSizable ];
1956         [self addSubview: o_label];
1957     }
1958     return self;
1959 }
1960
1961 - (void)dealloc
1962 {
1963     [o_checkbox release];
1964     [super dealloc];
1965 }
1966
1967 - (int)intValue
1968 {
1969     return [o_checkbox intValue];
1970 }
1971
1972 @end
1973
1974 @implementation KeyConfigControl
1975 - (id) initWithItem: (module_config_t *)_p_item
1976            withView: (NSView *)o_parent_view
1977 {
1978     NSRect mainFrame = [o_parent_view frame];
1979     NSString *o_labelString, *o_tooltip;
1980     mainFrame.size.height = 22;
1981     mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN + 1;
1982     mainFrame.origin.x = LEFTMARGIN;
1983     mainFrame.origin.y = 0;
1984
1985     if( [super initWithFrame: mainFrame item: _p_item] != nil )
1986     {
1987         i_view_type = CONFIG_ITEM_KEY_AFTER_10_3;
1988
1989         /* add the label */
1990         if( p_item->psz_text )
1991             o_labelString = [[VLCMain sharedInstance]
1992                 localizedString: (char *)p_item->psz_text];
1993         else
1994             o_labelString = [NSString stringWithString:@""];
1995         ADD_LABEL( o_label, mainFrame, 0, -1, o_labelString )
1996         [o_label setAutoresizingMask:NSViewNotSizable ];
1997         [self addSubview: o_label];
1998
1999         /* build the popup */
2000         o_tooltip = [[VLCMain sharedInstance] wrapString:
2001             [[VLCMain sharedInstance]
2002                 localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
2003         ADD_POPUP( o_popup, mainFrame, [o_label frame].origin.x +
2004             [o_label frame].size.width + 3,
2005             -2, 0, o_tooltip )
2006         [o_popup setAutoresizingMask:NSViewWidthSizable ];
2007
2008         if( o_keys_menu == nil )
2009         {
2010             unsigned int i;
2011             o_keys_menu = [[NSMenu alloc] initWithTitle: @"Keys Menu"];
2012             for ( i = 0; i < sizeof(vlc_keys) / sizeof(key_descriptor_t); i++)
2013                 if( vlc_keys[i].psz_key_string && *vlc_keys[i].psz_key_string )
2014                     POPULATE_A_KEY( o_keys_menu,
2015                         [NSString stringWithCString:vlc_keys[i].psz_key_string]
2016                         , vlc_keys[i].i_key_code)
2017         }
2018         [o_popup setMenu:[o_keys_menu copyWithZone:nil]];
2019         [o_popup selectItem:[[o_popup menu] itemWithTag:p_item->value.i]];
2020         [self addSubview: o_popup];
2021
2022     }
2023     return self;
2024 }
2025
2026 - (void) alignWithXPosition:(int)i_xPos
2027 {
2028     NSRect frame;
2029     NSRect superFrame = [self frame];
2030     frame = [o_label frame];
2031     frame.origin.x = i_xPos - frame.size.width - 3;
2032     [o_label setFrame:frame];
2033
2034     frame = [o_popup frame];
2035     frame.origin.x = i_xPos - 1;
2036     frame.size.width = superFrame.size.width - frame.origin.x + 2;
2037     [o_popup setFrame:frame];
2038 }
2039
2040 - (void)dealloc
2041 {
2042     [o_popup release];
2043     [super dealloc];
2044 }
2045
2046 - (int)intValue
2047 {
2048     return [o_popup selectedTag];
2049 }
2050 @end
2051
2052 @implementation ModuleListConfigControl
2053 - (id) initWithItem: (module_config_t *)_p_item
2054            withView: (NSView *)o_parent_view
2055 {
2056 if( _p_item->i_type == CONFIG_ITEM_MODULE_LIST )
2057 //TODO....
2058         return nil;
2059
2060 //Fill our array to know how may items we have...
2061     vlc_list_t *p_list;
2062     module_t *p_parser;
2063     module_config_t *p_end;
2064     int i_index;
2065     NSRect mainFrame = [o_parent_view frame];
2066     NSString *o_labelString, *o_textfieldString, *o_tooltip;
2067
2068     o_modulearray = [[NSMutableArray alloc] initWithCapacity:10];
2069     /* build a list of available modules */
2070     p_list = vlc_list_find( VLCIntf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
2071     for( i_index = 0; i_index < p_list->i_count; i_index++ )
2072     {
2073         p_parser = (module_t *)p_list->p_values[i_index].p_object;
2074         p_end = p_item + p_parser->confsize;
2075
2076         if( !strcmp( p_parser->psz_object_name, "main" ) )
2077             continue;
2078
2079         module_config_t *p_config = p_parser->p_config;
2080         if( p_config ) do
2081         {
2082             NSString *o_modulelongname, *o_modulename;
2083             NSNumber *o_moduleenabled = nil;
2084             /* Hack: required subcategory is stored in i_min */
2085             if( p_config->i_type == CONFIG_SUBCATEGORY &&
2086                 p_config->value.i == _p_item->min.i )
2087             {
2088                 o_modulelongname = [NSString stringWithUTF8String:
2089                                         p_parser->psz_longname];
2090                 o_modulename = [NSString stringWithUTF8String:
2091                                         p_parser->psz_object_name];
2092
2093                 if( _p_item->value.psz &&
2094                     strstr( _p_item->value.psz, p_parser->psz_object_name ) )
2095                     o_moduleenabled = [NSNumber numberWithBool:YES];
2096                 else
2097                     o_moduleenabled = [NSNumber numberWithBool:NO];
2098
2099                 [o_modulearray addObject:[NSMutableArray
2100                     arrayWithObjects: o_modulename, o_modulelongname,
2101                     o_moduleenabled, nil]];
2102             }
2103         } while( p_item < p_end && p_config++ );
2104     }
2105     vlc_list_release( p_list );
2106
2107     mainFrame.size.height = 30 + 18 * [o_modulearray count];
2108     mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN;
2109     mainFrame.origin.x = LEFTMARGIN;
2110     mainFrame.origin.y = 0;
2111     if( [super initWithFrame: mainFrame item: _p_item] != nil )
2112     {
2113         i_view_type = CONFIG_ITEM_MODULE_LIST;
2114
2115         /* add the label */
2116         if( p_item->psz_text )
2117             o_labelString = [[VLCMain sharedInstance]
2118                                 localizedString: (char *)p_item->psz_text];
2119         else
2120             o_labelString = [NSString stringWithString:@""];
2121         ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString )
2122         [o_label setAutoresizingMask:NSViewNotSizable ];
2123         [self addSubview: o_label];
2124
2125         /* build the textfield */
2126         o_tooltip = [[VLCMain sharedInstance] wrapString:
2127             [[VLCMain sharedInstance]
2128                 localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
2129         if( p_item->value.psz )
2130             o_textfieldString = [[VLCMain sharedInstance]
2131                 localizedString: (char *)p_item->value.psz];
2132         else
2133             o_textfieldString = [NSString stringWithString: @""];
2134         ADD_TEXTFIELD( o_textfield, mainFrame, [o_label frame].size.width + 2,
2135             mainFrame.size.height - 22, mainFrame.size.width -
2136             [o_label frame].size.width - 2, o_tooltip, o_textfieldString )
2137         [o_textfield setAutoresizingMask:NSViewWidthSizable ];
2138         [self addSubview: o_textfield];
2139
2140
2141 {
2142     NSRect s_rc = mainFrame;
2143     s_rc.size.height = mainFrame.size.height - 30;
2144     s_rc.size.width = mainFrame.size.width - 12;
2145     s_rc.origin.x = 12;
2146     s_rc.origin.y = 0;
2147     o_scrollview = [[[NSScrollView alloc] initWithFrame: s_rc] retain];
2148     [o_scrollview setDrawsBackground: NO];
2149     [o_scrollview setBorderType: NSBezelBorder];
2150     [o_scrollview setAutohidesScrollers:YES];
2151
2152     NSTableView *o_tableview;
2153     o_tableview = [[NSTableView alloc] initWithFrame : s_rc];
2154     [o_tableview setUsesAlternatingRowBackgroundColors:YES];
2155     [o_tableview setHeaderView:nil];
2156 /* TODO: find a good way to fix the row height and text size*/
2157 /* FIXME: support for multiple selection... */
2158 //    [o_tableview setAllowsMultipleSelection:YES];
2159
2160     NSCell *o_headerCell = [[NSCell alloc] initTextCell:@"Enabled"];
2161     NSCell *o_dataCell = [[NSButtonCell alloc] init];
2162     [(NSButtonCell*)o_dataCell setButtonType:NSSwitchButton];
2163     [o_dataCell setTitle:@""];
2164     [o_dataCell setFont:[NSFont systemFontOfSize:0]];
2165     NSTableColumn *o_tableColumn = [[NSTableColumn alloc]
2166         initWithIdentifier:[NSString stringWithCString: "Enabled"]];
2167     [o_tableColumn setHeaderCell: o_headerCell];
2168     [o_tableColumn setDataCell: o_dataCell];
2169     [o_tableColumn setWidth:17];
2170     [o_tableview addTableColumn: o_tableColumn];
2171
2172     o_headerCell = [[NSCell alloc] initTextCell:@"Module Name"];
2173     o_dataCell = [[NSTextFieldCell alloc] init];
2174     [o_dataCell setFont:[NSFont systemFontOfSize:12]];
2175     o_tableColumn = [[NSTableColumn alloc]
2176         initWithIdentifier:[NSString stringWithCString: "Module"]];
2177     [o_tableColumn setHeaderCell: o_headerCell];
2178     [o_tableColumn setDataCell: o_dataCell];
2179     [o_tableColumn setWidth:388 - 17];
2180     [o_tableview addTableColumn: o_tableColumn];
2181     [o_tableview registerForDraggedTypes:[NSArray arrayWithObjects:
2182             @"VLC media player module", nil]];
2183
2184     [o_tableview setDataSource:self];
2185     [o_tableview setTarget: self];
2186     [o_tableview setAction: @selector(tableChanged:)];
2187     [o_tableview sendActionOn:NSLeftMouseUpMask | NSLeftMouseDownMask |
2188         NSLeftMouseDraggedMask];
2189     [o_scrollview setDocumentView: o_tableview];
2190 }
2191     [o_scrollview setAutoresizingMask:NSViewWidthSizable ];
2192     [self addSubview: o_scrollview];
2193
2194
2195     }
2196     return self;
2197 }
2198
2199 - (void) alignWithXPosition:(int)i_xPos
2200 {
2201     ;
2202 }
2203
2204 - (IBAction)tableChanged:(id)sender
2205 {
2206     NSString *o_newstring = @"";
2207     unsigned int i;
2208     for( i = 0 ; i < [o_modulearray count] ; i++ )
2209         if( [[[o_modulearray objectAtIndex:i] objectAtIndex:2]
2210             boolValue] != NO )
2211         {
2212             o_newstring = [o_newstring stringByAppendingString:
2213                 [[o_modulearray objectAtIndex:i] objectAtIndex:0]];
2214             o_newstring = [o_newstring stringByAppendingString:@":"];
2215         }
2216
2217     [o_textfield setStringValue: [o_newstring
2218         substringToIndex: ([o_newstring length])?[o_newstring length] - 1:0]];
2219 }
2220
2221 - (void)dealloc
2222 {
2223     [o_scrollview release];
2224     [super dealloc];
2225 }
2226
2227
2228 - (char *)stringValue
2229 {
2230     return strdup( [[o_textfield stringValue] cString] );
2231 }
2232
2233 @end
2234
2235 @implementation ModuleListConfigControl (NSTableDataSource)
2236
2237 - (BOOL)tableView:(NSTableView*)table writeRows:(NSArray*)rows
2238     toPasteboard:(NSPasteboard*)pb
2239 {
2240     // We only want to allow dragging of selected rows.
2241     NSEnumerator    *iter = [rows objectEnumerator];
2242     NSNumber        *row;
2243     while ((row = [iter nextObject]) != nil)
2244     {
2245         if (![table isRowSelected:[row intValue]])
2246             return NO;
2247     }
2248
2249     [pb declareTypes:[NSArray
2250         arrayWithObject:@"VLC media player module"] owner:nil];
2251     [pb setPropertyList:rows forType:@"VLC media player module"];
2252     return YES;
2253 }
2254
2255 - (NSDragOperation)tableView:(NSTableView*)table
2256     validateDrop:(id <NSDraggingInfo>)info proposedRow:(int)row
2257     proposedDropOperation:(NSTableViewDropOperation)op
2258 {
2259     // Make drops at the end of the table go to the end.
2260     if (row == -1)
2261     {
2262         row = [table numberOfRows];
2263         op = NSTableViewDropAbove;
2264         [table setDropRow:row dropOperation:op];
2265     }
2266
2267     // We don't ever want to drop onto a row, only between rows.
2268     if (op == NSTableViewDropOn)
2269         [table setDropRow:(row+1) dropOperation:NSTableViewDropAbove];
2270     return NSTableViewDropAbove;
2271 }
2272
2273 - (BOOL)tableView:(NSTableView*)table acceptDrop:(id <NSDraggingInfo>)info
2274     row:(int)dropRow dropOperation:(NSTableViewDropOperation)op;
2275 {
2276     NSPasteboard    *pb = [info draggingPasteboard];
2277     NSDragOperation srcMask = [info draggingSourceOperationMask];
2278     BOOL accepted = NO;
2279
2280     NS_DURING
2281
2282         NSArray *array;
2283
2284         // Intra-table drag - data is the array of rows.
2285         if (!accepted && (array =
2286             [pb propertyListForType:@"VLC media player module"]) != NULL)
2287         {
2288             NSEnumerator *iter = nil;
2289             id val;
2290             BOOL isCopy = (srcMask & NSDragOperationMove) ? NO:YES;
2291             // Move the modules
2292             iter = [array objectEnumerator];
2293             while ((val = [iter nextObject]) != NULL)
2294             {
2295                 NSArray *o_tmp = [[o_modulearray objectAtIndex:
2296                     [val intValue]] mutableCopyWithZone:nil];
2297                 [o_modulearray removeObject:o_tmp];
2298                 [o_modulearray insertObject:o_tmp
2299                     atIndex:(dropRow>[val intValue]) ? dropRow - 1 : dropRow];
2300                 dropRow++;
2301             }
2302
2303             // Select the newly-dragged items.
2304             iter = [array objectEnumerator];
2305 //TODO...
2306             [table deselectAll:self];
2307
2308             [self tableChanged:self];
2309             [table setNeedsDisplay:YES];
2310             // Indicate that we finished the drag.
2311             accepted = YES;
2312         }
2313         [table reloadData];
2314         [table setNeedsDisplay:YES];
2315
2316         NS_HANDLER
2317
2318             // An exception occurred. Uh-oh. Update the track table so that
2319             // it stays consistent, and re-raise the exception.
2320             [table reloadData];
2321             [localException raise];
2322             [table setNeedsDisplay:YES];
2323     NS_ENDHANDLER
2324
2325     return accepted;
2326 }
2327
2328 - (int)numberOfRowsInTableView:(NSTableView *)aTableView
2329 {
2330     return [o_modulearray count];
2331 }
2332
2333 - (id)tableView:(NSTableView *)aTableView
2334     objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex
2335 {
2336     if( [[aTableColumn identifier] isEqualToString:
2337         [NSString stringWithCString:"Enabled"]] )
2338         return [[o_modulearray objectAtIndex:rowIndex] objectAtIndex:2];
2339     if( [[aTableColumn identifier] isEqualToString:
2340         [NSString stringWithCString:"Module"]] )
2341         return [[o_modulearray objectAtIndex:rowIndex] objectAtIndex:1];
2342
2343     return nil;
2344 }
2345
2346 - (void)tableView:(NSTableView *)aTableView setObjectValue:(id)anObject
2347     forTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex
2348 {
2349     [[o_modulearray objectAtIndex:rowIndex] replaceObjectAtIndex:2
2350         withObject: anObject];
2351 }
2352 @end