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