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