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