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