MacOS X: fix preferences for ModulesConfig
[vlc.git] / modules / gui / macosx / prefs_widgets.m
blobc1ed0741d1288a092fb98c7723db905a10c4f7c8
1 /*****************************************************************************
2  * prefs_widgets.m: Preferences controls
3  *****************************************************************************
4  * Copyright (C) 2002-2011 VLC authors and VideoLAN
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  *****************************************************************************/
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28 #include <stdlib.h>                                      /* malloc(), free() */
29 #include <string.h>
31 #ifdef HAVE_CONFIG_H
32 # include "config.h"
33 #endif
35 #include <vlc_common.h>
36 #include <vlc_modules.h>
37 #include <vlc_keys.h>
39 #include "intf.h"
40 #include "prefs_widgets.h"
42 #define PREFS_WRAP 300
43 #define OFFSET_RIGHT 20
44 #define OFFSET_BETWEEN 2
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"
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];                                                 \
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];                                                    \
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];                               \
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];                               \
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];                                             \
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:)];                       \
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];                                          \
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];                                            \
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];                                          \
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];                                                 \
401 @implementation VLCConfigControl
402 - (id)initWithFrame: (NSRect)frame
404     return [self initWithFrame: frame
405                     item: nil];
408 - (id)initWithFrame: (NSRect)frame
409         item: (module_config_t *)_p_item
411     self = [super initWithFrame: frame];
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);
426 - (void)setYPos:(int)i_yPos
428     NSRect frame = [self frame];
429     frame.origin.y = i_yPos;
430     [self setFrame:frame];
433 - (void)dealloc
435     if( o_label ) [o_label release];
436     free( psz_name );
437     [super dealloc];
440 + (int)calcVerticalMargin: (int)i_curItem lastItem: (int)i_lastItem
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:
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:
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:
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:
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:
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:
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:
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:
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:
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:
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;
787 + (VLCConfigControl *)newControl: (module_config_t *)_p_item
788                       withView: (NSView *)o_parent_view
790     VLCConfigControl *p_control = NULL;
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) && (_p_item->min.i != INT_MIN || _p_item->max.i != INT_MAX) )
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.i != 0 || _p_item->max.i != 0) && (_p_item->min.i != INT_MIN || _p_item->max.i != INT_MAX) )
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     /* don't display keys in the advanced settings, since the current controls 
862     are broken by design. The user is required to change hotkeys in the sprefs
863     and can only change really advanced stuff here..
864     case CONFIG_ITEM_KEY:
865         p_control = [[KeyConfigControl alloc]
866                         initWithItem: _p_item
867                         withView: o_parent_view];
868         break; */
869     case CONFIG_ITEM_MODULE_LIST:
870     case CONFIG_ITEM_MODULE_LIST_CAT:
871         p_control = [[ModuleListConfigControl alloc]
872                     initWithItem: _p_item
873                     withView: o_parent_view];
874         break;
875     default:
876         break;
877     }
878     return p_control;
881 - (NSString *)name
883     return [[VLCMain sharedInstance] localizedString: psz_name];
886 - (int)type
888     return i_type;
891 - (int)viewType
893     return i_view_type;
896 - (BOOL)isAdvanced
898     return b_advanced;
901 - (int)intValue
903     return 0;
906 - (float)floatValue
908     return 0;
911 - (char *)stringValue
913     return NULL;
916 - (void)applyChanges
918     vlc_value_t val;
919     switch( p_item->i_type )
920     {
921     case CONFIG_ITEM_STRING:
922     case CONFIG_ITEM_PASSWORD:
923     case CONFIG_ITEM_LOADFILE:
924     case CONFIG_ITEM_SAVEFILE:
925     case CONFIG_ITEM_DIRECTORY:
926     case CONFIG_ITEM_MODULE:
927     case CONFIG_ITEM_MODULE_LIST:
928     case CONFIG_ITEM_MODULE_LIST_CAT:
929         config_PutPsz( VLCIntf, psz_name, [self stringValue] );
930         break;
931     case CONFIG_ITEM_KEY:
932         /* So you don't need to restart to have the changes take effect */
933         val.i_int = [self intValue];
934         var_Set( VLCIntf->p_libvlc, psz_name, val );
935     case CONFIG_ITEM_INTEGER:
936     case CONFIG_ITEM_BOOL:
937         config_PutInt( VLCIntf, psz_name, [self intValue] );
938         break;
939     case CONFIG_ITEM_FLOAT:
940         config_PutFloat( VLCIntf, psz_name, [self floatValue] );
941         break;
942     }
945 - (void)resetValues
949 - (int)labelSize
951     return [o_label frame].size.width;
954 - (void) alignWithXPosition:(int)i_xPos;
956     /* FIXME: not implemented atm, but created to shut up the warning
957      * about "method definition not found" -- FK @ 7/24/05 */
959 @end
961 @implementation StringConfigControl
962 - (id) initWithItem: (module_config_t *)_p_item
963            withView: (NSView *)o_parent_view
965     NSRect mainFrame = [o_parent_view frame];
966     NSString *o_labelString, *o_textfieldString, *o_textfieldTooltip;
967     mainFrame.size.height = 22;
968     mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN;
969     mainFrame.origin.x = LEFTMARGIN;
970     mainFrame.origin.y = 0;
972     if( [super initWithFrame: mainFrame item: _p_item] != nil )
973     {
974         if( p_item->i_type == CONFIG_ITEM_PASSWORD )
975             i_view_type = CONFIG_ITEM_PASSWORD;
976         else
977             i_view_type = CONFIG_ITEM_STRING;
979         o_textfieldTooltip = [[VLCMain sharedInstance] wrapString:
980                               [[VLCMain sharedInstance] localizedString: (char *)p_item->psz_longtext]
981                                                           toWidth: PREFS_WRAP];
983         /* add the label */
984         if( p_item->psz_text )
985             o_labelString = [[VLCMain sharedInstance]
986                                 localizedString: (char *)p_item->psz_text];
987         else
988             o_labelString = [NSString stringWithString:@""];
989         ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString, o_textfieldTooltip )
990         [o_label setAutoresizingMask:NSViewNotSizable ];
991         [self addSubview: o_label];
993         /* build the textfield */
994         if( p_item->value.psz )
995             o_textfieldString = [[VLCMain sharedInstance]
996                                     localizedString: (char *)p_item->value.psz];
997         else
998             o_textfieldString = [NSString stringWithString: @""];
999         if( p_item->i_type == CONFIG_ITEM_PASSWORD )
1000         {
1001             ADD_SECURETEXTFIELD( o_textfield, mainFrame, [o_label frame].size.width + 2,
1002                           0, mainFrame.size.width - [o_label frame].size.width -
1003                           2, o_textfieldTooltip, o_textfieldString )
1004         }
1005         else
1006         {
1007             ADD_TEXTFIELD( o_textfield, mainFrame, [o_label frame].size.width + 2,
1008                             0, mainFrame.size.width - [o_label frame].size.width -
1009                             2, o_textfieldTooltip, o_textfieldString )
1010         }
1011         [o_textfield setAutoresizingMask:NSViewWidthSizable ];
1013         [self addSubview: o_textfield];
1014     }
1015     return self;
1018 - (void) alignWithXPosition:(int)i_xPos
1020     NSRect frame;
1021     NSRect superFrame = [self frame];
1022     frame = [o_label frame];
1023     frame.origin.x = i_xPos - frame.size.width - 3;
1024     [o_label setFrame:frame];
1026     frame = [o_textfield frame];
1027     frame.origin.x = i_xPos + 2;
1028     frame.size.width = superFrame.size.width - frame.origin.x - 1;
1029     [o_textfield setFrame:frame];
1032 - (void)dealloc
1034     [o_textfield release];
1035     [super dealloc];
1038 - (char *)stringValue
1040     return [[VLCMain sharedInstance] delocalizeString:
1041                         [o_textfield stringValue]];
1044 - (void)resetValues
1046     NSString *o_textfieldString;
1047     char *psz_value = config_GetPsz( VLCIntf, p_item->psz_name );
1048     if( psz_value )
1049         o_textfieldString = [[VLCMain sharedInstance]
1050                                 localizedString: psz_value];
1051     else
1052         o_textfieldString = [NSString stringWithString: @""];
1053     free( psz_value );
1054     [super resetValues];
1056 @end
1058 @implementation StringListConfigControl
1059 - (id) initWithItem: (module_config_t *)_p_item
1060            withView: (NSView *)o_parent_view
1062     NSRect mainFrame = [o_parent_view frame];
1063     NSString *o_labelString, *o_textfieldTooltip;
1064     mainFrame.size.height = 22;
1065     mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN + 1;
1066     mainFrame.origin.x = LEFTMARGIN;
1067     mainFrame.origin.y = 0;
1069     if( [super initWithFrame: mainFrame item: _p_item] != nil )
1070     {
1071         int i_index;
1072         i_view_type = CONFIG_ITEM_STRING_LIST;
1074         o_textfieldTooltip = [[VLCMain sharedInstance] wrapString:
1075                               [[VLCMain sharedInstance]
1076                                localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
1078         /* add the label */
1079         if( p_item->psz_text )
1080             o_labelString = [[VLCMain sharedInstance]
1081                                 localizedString: (char *)p_item->psz_text];
1082         else
1083             o_labelString = [NSString stringWithString:@""];
1084         ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString, o_textfieldTooltip )
1085         [o_label setAutoresizingMask:NSViewNotSizable ];
1086         [self addSubview: o_label];
1088         /* build the textfield */
1089         ADD_COMBO( o_combo, mainFrame, [o_label frame].size.width,
1090             -2, 0, o_textfieldTooltip )
1091         [o_combo setAutoresizingMask:NSViewWidthSizable ];
1092         for( i_index = 0; i_index < p_item->i_list; i_index++ )
1093         {
1094             if( !p_item->value.psz && !p_item->ppsz_list[i_index] )
1095                 [o_combo selectItemAtIndex: i_index];
1096             else if( p_item->value.psz && p_item->ppsz_list[i_index] &&
1097                 !strcmp( p_item->value.psz, p_item->ppsz_list[i_index] ) )
1098                 [o_combo selectItemAtIndex: i_index];
1099        }
1100         [self addSubview: o_combo];
1101     }
1102     return self;
1105 - (void) alignWithXPosition:(int)i_xPos
1107     NSRect frame;
1108     NSRect superFrame = [self frame];
1109     frame = [o_label frame];
1110     frame.origin.x = i_xPos - frame.size.width - 3;
1111     [o_label setFrame:frame];
1113     frame = [o_combo frame];
1114     frame.origin.x = i_xPos + 2;
1115     frame.size.width = superFrame.size.width - frame.origin.x + 2;
1116     [o_combo setFrame:frame];
1119 - (void)dealloc
1121     [o_combo release];
1122     [super dealloc];
1125 - (char *)stringValue
1127     if( [o_combo indexOfSelectedItem] >= 0 ) {
1128         if( p_item->ppsz_list[[o_combo indexOfSelectedItem]] != NULL )
1129             return strdup( p_item->ppsz_list[[o_combo indexOfSelectedItem]] );
1130     } else {
1131         if( [[VLCMain sharedInstance] delocalizeString: [o_combo stringValue]] != NULL )
1132             return strdup( [[VLCMain sharedInstance] delocalizeString: [o_combo stringValue]] );
1133     }
1134     return NULL;
1137 - (void)resetValues
1139     int i_index;
1140     [o_combo reloadData];
1141     char *psz_value = config_GetPsz( VLCIntf, p_item->psz_name );
1143     for( i_index = 0; i_index < p_item->i_list; i_index++ )
1144     {
1145         if( !psz_value && !p_item->ppsz_list[i_index] )
1146             [o_combo selectItemAtIndex: i_index];
1147         else if( psz_value && p_item->ppsz_list[i_index] &&
1148             !strcmp( psz_value, p_item->ppsz_list[i_index] ) )
1149             [o_combo selectItemAtIndex: i_index];
1150     }
1152     free( psz_value );
1153     [super resetValues];
1155 @end
1157 @implementation StringListConfigControl (NSComboBoxDataSource)
1158 - (NSInteger)numberOfItemsInComboBox:(NSComboBox *)aComboBox
1160         return p_item->i_list;
1163 - (id)comboBox:(NSComboBox *)aComboBox objectValueForItemAtIndex:(NSInteger)i_index
1165     if( p_item->ppsz_list_text && p_item->ppsz_list_text[i_index] )
1166     {
1167         return [[VLCMain sharedInstance]
1168                     localizedString: (char *)p_item->ppsz_list_text[i_index]];
1169     } else return [[VLCMain sharedInstance]
1170                     localizedString: (char *)p_item->ppsz_list[i_index]];
1172 @end
1174 @implementation FileConfigControl
1175 - (id) initWithItem: (module_config_t *)_p_item
1176            withView: (NSView *)o_parent_view
1178     NSRect mainFrame = [o_parent_view frame];
1179     NSString *o_labelString, *o_itemTooltip, *o_textfieldString;
1180     mainFrame.size.height = 46;
1181     mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN;
1182     mainFrame.origin.x = LEFTMARGIN;
1183     mainFrame.origin.y = 0;
1185     if( [super initWithFrame: mainFrame item: _p_item] != nil )
1186     {
1187         i_view_type = CONFIG_ITEM_LOADFILE;
1189         o_itemTooltip = [[VLCMain sharedInstance]
1190                            wrapString: [[VLCMain sharedInstance]
1191                                         localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
1193         /* is it a directory */
1194         b_directory = ( [self type] == CONFIG_ITEM_DIRECTORY ) ? YES : NO;
1196         /* add the label */
1197         if( p_item->psz_text )
1198             o_labelString = [[VLCMain sharedInstance]
1199                                 localizedString: (char *)p_item->psz_text];
1200         else
1201             o_labelString = [NSString stringWithString:@""];
1202         ADD_LABEL( o_label, mainFrame, 0, 3, o_labelString, o_itemTooltip )
1203         [o_label setAutoresizingMask:NSViewNotSizable ];
1204         [self addSubview: o_label];
1206         /* build the button */
1207         ADD_RIGHT_BUTTON( o_button, mainFrame, 0, 0, o_itemTooltip,
1208                             _NS("Browse...") )
1209         [o_button setAutoresizingMask:NSViewMinXMargin ];
1210         [self addSubview: o_button];
1212         /* build the textfield */
1213         if( p_item->value.psz )
1214             o_textfieldString = [NSString stringWithFormat: @"%s", (char *)p_item->value.psz];
1215         else
1216             o_textfieldString = [NSString stringWithString: @""];
1217         ADD_TEXTFIELD( o_textfield, mainFrame, 12, 2, mainFrame.size.width -
1218                         8 - [o_button frame].size.width,
1219                         o_itemTooltip, o_textfieldString )
1220         [o_textfield setAutoresizingMask:NSViewWidthSizable ];
1221         [self addSubview: o_textfield];
1222     }
1223     return self;
1226 - (void) alignWithXPosition:(int)i_xPos
1228     ;
1231 - (void)dealloc
1233     [o_textfield release];
1234     [o_button release];
1235     [super dealloc];
1238 - (IBAction)openFileDialog: (id)sender
1240     NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
1242     [o_open_panel setTitle: (b_directory)?
1243         _NS("Select a directory"):_NS("Select a file")];
1244     [o_open_panel setPrompt: _NS("Select")];
1245     [o_open_panel setAllowsMultipleSelection: NO];
1246     [o_open_panel setCanChooseFiles: !b_directory];
1247     [o_open_panel setCanChooseDirectories: b_directory];
1248     [o_open_panel beginSheetForDirectory:nil
1249         file:nil
1250         types:nil
1251         modalForWindow:[sender window]
1252         modalDelegate: self
1253         didEndSelector: @selector(pathChosenInPanel:
1254                         withReturn:
1255                         contextInfo:)
1256         contextInfo: nil];
1259 - (void)pathChosenInPanel:(NSOpenPanel *)o_sheet
1260     withReturn:(int)i_return_code contextInfo:(void  *)o_context_info
1262     if( i_return_code == NSOKButton )
1263     {
1264         NSString *o_path = [[[o_sheet URLs] objectAtIndex: 0] path];
1265         [o_textfield setStringValue: o_path];
1266     }
1269 - (char *)stringValue
1271     if( [[o_textfield stringValue] length] != 0)
1272         return strdup( [[o_textfield stringValue] fileSystemRepresentation] );
1273     else
1274         return NULL;
1277 -(void)resetValues
1279     NSString *o_textfieldString;
1280     char *psz_value = config_GetPsz( VLCIntf, p_item->psz_name );
1281     if( psz_value )
1282         o_textfieldString = [NSString stringWithFormat: @"%s", psz_value];
1283     else
1284         o_textfieldString = [NSString stringWithString: @""];
1286     free(psz_value);
1287     [super resetValues];
1289 @end
1291 @implementation ModuleConfigControl
1292 - (id) initWithItem: (module_config_t *)_p_item
1293            withView: (NSView *)o_parent_view
1295     NSRect mainFrame = [o_parent_view frame];
1296     NSString *o_labelString, *o_popupTooltip;
1297     mainFrame.size.height = 22;
1298     mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN + 1;
1299     mainFrame.origin.x = LEFTMARGIN;
1300     mainFrame.origin.y = 0;
1302     if( [super initWithFrame: mainFrame item: _p_item] != nil )
1303     {
1304         i_view_type = CONFIG_ITEM_MODULE;
1306         o_popupTooltip = [[VLCMain sharedInstance] wrapString:
1307                           [[VLCMain sharedInstance]
1308                            localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
1310         /* add the label */
1311         if( p_item->psz_text )
1312             o_labelString = [[VLCMain sharedInstance]
1313                                 localizedString: (char *)p_item->psz_text];
1314         else
1315             o_labelString = [NSString stringWithString:@""];
1317         ADD_LABEL( o_label, mainFrame, 0, -1, o_labelString, o_popupTooltip )
1318         [o_label setAutoresizingMask:NSViewNotSizable ];
1319         [self addSubview: o_label];
1321         /* build the popup */
1322         ADD_POPUP( o_popup, mainFrame, [o_label frame].size.width,
1323             -2, 0, o_popupTooltip )
1324         [o_popup setAutoresizingMask:NSViewWidthSizable ];
1325         [o_popup addItemWithTitle: _NS("Default")];
1326         [[o_popup lastItem] setTag: -1];
1327         [o_popup selectItem: [o_popup lastItem]];
1329         [self resetValues];
1330         [self addSubview: o_popup];
1331     }
1332     return self;
1335 - (void) alignWithXPosition:(int)i_xPos
1337     NSRect frame;
1338     NSRect superFrame = [self frame];
1339     frame = [o_label frame];
1340     frame.origin.x = i_xPos - frame.size.width - 3;
1341     [o_label setFrame:frame];
1343     frame = [o_popup frame];
1344     frame.origin.x = i_xPos - 1;
1345     frame.size.width = superFrame.size.width - frame.origin.x + 2;
1346     [o_popup setFrame:frame];
1349 - (void)dealloc
1351     [o_popup release];
1352     [super dealloc];
1355 - (char *)stringValue
1357     NSString *newval = [o_popup titleOfSelectedItem];
1358     char *returnval = NULL;
1359     size_t i_module_index;
1360     module_t *p_parser, **p_list;
1362     p_list = module_list_get( NULL );
1363     for( i_module_index = 0; p_list[i_module_index]; i_module_index++ )
1364     {
1365         p_parser = p_list[i_module_index];
1367         if( p_item->i_type == CONFIG_ITEM_MODULE )
1368         {
1369             if( module_provides( p_parser, p_item->psz_type ) )
1370             {
1371                 NSString *o_description = [[VLCMain sharedInstance]
1372                     localizedString: module_get_name( p_parser, TRUE )];
1373                 if( [newval isEqualToString: o_description] )
1374                 {
1375                     returnval = strdup( module_get_object( p_parser ));
1376                     break;
1377                 }
1378             }
1379         }
1380         else
1381         {
1382             if( module_is_main( p_parser) )
1383                 continue;
1385             unsigned int confsize;
1386             module_config_t *p_config = module_config_get( p_parser, &confsize );
1387             for ( size_t i = 0; i < confsize; i++ )
1388             {
1389                 module_config_t *p_cfg = p_config + i;
1390                 /* Hack: required subcategory is stored in i_min */
1391                 if( p_cfg->i_type == CONFIG_SUBCATEGORY &&
1392                     p_cfg->value.i == p_cfg->min.i )
1393                 {
1394                     NSString *o_description = [[VLCMain sharedInstance]
1395                         localizedString: module_get_name( p_parser, TRUE )];
1396                     if( [newval isEqualToString: o_description] )
1397                     {
1398                         returnval = strdup(module_get_object( p_parser ));
1399                         break;
1400                     }
1401                 }
1402             }
1403             module_config_free( p_config );
1404         }
1405     }
1406     module_list_free( p_list );
1407     return returnval;
1410 -(void)resetValues
1412     /* build a list of available modules */
1413     size_t i_index;
1414     module_t *p_parser, **p_list;
1416     p_list = module_list_get( NULL );
1417     for( i_index = 0; p_list[i_index]; i_index++ )
1418     {
1419         p_parser = p_list[i_index];
1421         if( p_item->i_type == CONFIG_ITEM_MODULE )
1422         {
1423             if( module_provides( p_parser, p_item->psz_type ) )
1424             {
1425                 NSString *o_description = [[VLCMain sharedInstance]
1426                     localizedString: module_get_name( p_parser, TRUE )];
1427                 [o_popup addItemWithTitle: o_description];
1428                 char *psz_value = config_GetPsz( VLCIntf, p_item->psz_name );
1430                 if( psz_value &&
1431                     !strcmp( psz_value, module_get_object( p_parser ) ) )
1432                     [o_popup selectItem:[o_popup lastItem]];
1434                 free(psz_value);
1435             }
1436         }
1437         else
1438         {
1439             if( module_is_main( p_parser ) )
1440                 continue;
1441             unsigned int confsize;
1443             module_config_t *p_configlist = module_config_get( p_parser, &confsize );
1444             for ( size_t i = 0; i < confsize; i++ )
1445             {
1446                 module_config_t *p_config = &p_configlist[i];
1447                 /* Hack: required subcategory is stored in i_min */
1448                 if( p_config->i_type == CONFIG_SUBCATEGORY &&
1449                     p_config->value.i == p_item->min.i )
1450                 {
1451                     NSString *o_description = [[VLCMain sharedInstance]
1452                         localizedString: module_get_name( p_parser, TRUE )];
1453                     [o_popup addItemWithTitle: o_description];
1455                     if( p_item->value.psz && !strcmp(p_item->value.psz,
1456                                             module_get_object( p_parser )) )
1457                         [o_popup selectItem:[o_popup lastItem]];
1458                 }
1459             }
1460             module_config_free( p_configlist );
1461         }
1462     }
1463     module_list_free( p_list );
1464     [super resetValues];
1466 @end
1468 @implementation IntegerConfigControl
1469 - (id) initWithItem: (module_config_t *)_p_item
1470            withView: (NSView *)o_parent_view
1472     NSRect mainFrame = [o_parent_view frame];
1473     NSString *o_labelString, *o_tooltip;
1474     mainFrame.size.height = 23;
1475     mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN + 1;
1476     mainFrame.origin.x = LEFTMARGIN;
1477     mainFrame.origin.y = 0;
1479     if( [super initWithFrame: mainFrame item: _p_item] != nil )
1480     {
1481         i_view_type = CONFIG_ITEM_INTEGER;
1483         o_tooltip = [[VLCMain sharedInstance] wrapString:
1484             [[VLCMain sharedInstance]
1485                 localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
1487         /* add the label */
1488         if( p_item->psz_text )
1489             o_labelString = [[VLCMain sharedInstance]
1490                                 localizedString: (char *)p_item->psz_text];
1491         else
1492             o_labelString = [NSString stringWithString:@""];
1493         ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString, o_tooltip )
1494         [o_label setAutoresizingMask:NSViewNotSizable ];
1495         [self addSubview: o_label];
1497         /* build the stepper */
1498         ADD_STEPPER( o_stepper, mainFrame, mainFrame.size.width - 19,
1499             0, o_tooltip, -100000, 100000)
1500         [o_stepper setIntValue: p_item->value.i];
1501         [o_stepper setAutoresizingMask:NSViewMaxXMargin ];
1502         [self addSubview: o_stepper];
1504         ADD_TEXTFIELD( o_textfield, mainFrame, mainFrame.size.width - 19 - 52,
1505             1, 49, o_tooltip, @"" )
1506         [o_textfield setIntValue: p_item->value.i];
1507         [o_textfield setDelegate: self];
1508         [[NSNotificationCenter defaultCenter] addObserver: self
1509             selector: @selector(textfieldChanged:)
1510             name: NSControlTextDidChangeNotification
1511             object: o_textfield];
1512         [o_textfield setAutoresizingMask:NSViewMaxXMargin ];
1513         [self addSubview: o_textfield];
1514     }
1515     return self;
1518 - (void) alignWithXPosition:(int)i_xPos
1520     NSRect frame;
1521     frame = [o_label frame];
1522     frame.origin.x = i_xPos - frame.size.width - 3;
1523     [o_label setFrame:frame];
1525     frame = [o_textfield frame];
1526     frame.origin.x = i_xPos + 2;
1527     [o_textfield setFrame:frame];
1529     frame = [o_stepper frame];
1530     frame.origin.x = i_xPos + [o_textfield frame].size.width + 5;
1531     [o_stepper setFrame:frame];
1534 - (void)dealloc
1536     [o_stepper release];
1537     [o_textfield release];
1538     [super dealloc];
1541 - (IBAction)stepperChanged:(id)sender
1543     [o_textfield setIntValue: [o_stepper intValue]];
1546 - (void)textfieldChanged:(NSNotification *)o_notification
1548     [o_stepper setIntValue: [o_textfield intValue]];
1551 - (int)intValue
1553     return [o_textfield intValue];
1556 -(void)resetValues
1558     [o_textfield setIntValue: config_GetInt(VLCIntf, p_item->psz_name)];
1559     [super resetValues];
1562 @end
1564 @implementation IntegerListConfigControl
1566 - (id) initWithItem: (module_config_t *)_p_item
1567            withView: (NSView *)o_parent_view
1569     NSRect mainFrame = [o_parent_view frame];
1570     NSString *o_labelString, *o_textfieldTooltip;
1571     mainFrame.size.height = 22;
1572     mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN + 1;
1573     mainFrame.origin.x = LEFTMARGIN;
1574     mainFrame.origin.y = 0;
1576     if( [super initWithFrame: mainFrame item: _p_item] != nil )
1577     {
1578         int i_index;
1579         i_view_type = CONFIG_ITEM_STRING_LIST;
1581         o_textfieldTooltip = [[VLCMain sharedInstance] wrapString:
1582                               [[VLCMain sharedInstance]
1583                                localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];        
1585         /* add the label */
1586         if( p_item->psz_text )
1587             o_labelString = [[VLCMain sharedInstance]
1588                 localizedString: (char *)p_item->psz_text];
1589         else
1590             o_labelString = [NSString stringWithString:@""];
1591         ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString, o_textfieldTooltip )
1592         [o_label setAutoresizingMask:NSViewNotSizable ];
1593         [self addSubview: o_label];
1595         /* build the textfield */
1596         ADD_COMBO( o_combo, mainFrame, [o_label frame].size.width,
1597             -2, 0, o_textfieldTooltip )
1598         [o_combo setAutoresizingMask:NSViewWidthSizable ];
1599         for( i_index = 0; i_index < p_item->i_list; i_index++ )
1600         {
1601             if( p_item->value.i == p_item->pi_list[i_index] )
1602             {
1603                 [o_combo selectItemAtIndex: i_index];
1604             }
1605         }
1606         [self addSubview: o_combo];
1607     }
1608     return self;
1611 - (void) alignWithXPosition:(int)i_xPos
1613     NSRect frame;
1614     NSRect superFrame = [self frame];
1615     frame = [o_label frame];
1616     frame.origin.x = i_xPos - frame.size.width - 3;
1617     [o_label setFrame:frame];
1619     frame = [o_combo frame];
1620     frame.origin.x = i_xPos + 2;
1621     frame.size.width = superFrame.size.width - frame.origin.x + 2;
1622     [o_combo setFrame:frame];
1625 - (void)dealloc
1627     [o_combo release];
1628     [super dealloc];
1631 - (int)intValue
1633     if( [o_combo indexOfSelectedItem] >= 0 )
1634         return p_item->pi_list[[o_combo indexOfSelectedItem]];
1635     else
1636         return [o_combo intValue];
1639 -(void)resetValues
1641     int i_index;
1642     [o_combo reloadData];
1643     for( i_index = 0; i_index < p_item->i_list; i_index++ )
1644     {
1645         if( config_GetInt( VLCIntf, p_item->psz_name) == p_item->pi_list[i_index] )
1646         {
1647             [o_combo selectItemAtIndex: i_index];
1648         }
1649     }
1652 @end
1654 @implementation IntegerListConfigControl (NSComboBoxDataSource)
1655 - (NSInteger)numberOfItemsInComboBox:(NSComboBox *)aComboBox
1657     return p_item->i_list;
1660 - (id)comboBox:(NSComboBox *)aComboBox objectValueForItemAtIndex:(NSInteger)i_index
1662     if( p_item->ppsz_list_text && p_item->ppsz_list_text[i_index] )
1663         return [[VLCMain sharedInstance]
1664                     localizedString: (char *)p_item->ppsz_list_text[i_index]];
1665     else
1666         return [NSString stringWithFormat: @"%i", p_item->pi_list[i_index]];
1668 @end
1670 @implementation RangedIntegerConfigControl
1671 - (id) initWithItem: (module_config_t *)_p_item
1672            withView: (NSView *)o_parent_view
1674     NSRect mainFrame = [o_parent_view frame];
1675     NSString *o_labelString, *o_tooltip;
1676     mainFrame.size.height = 50;
1677     mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN;
1678     mainFrame.origin.x = LEFTMARGIN;
1679     mainFrame.origin.y = 0;
1681     if( [super initWithFrame: mainFrame item: _p_item] != nil )
1682     {
1683         i_view_type = CONFIG_ITEM_RANGED_INTEGER;
1685         o_tooltip = [[VLCMain sharedInstance] wrapString:
1686                      [[VLCMain sharedInstance]
1687                       localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
1689         /* add the label */
1690         if( p_item->psz_text )
1691             o_labelString = [[VLCMain sharedInstance]
1692                                 localizedString: (char *)p_item->psz_text];
1693         else
1694             o_labelString = [NSString stringWithString:@""];
1695         ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString, o_tooltip )
1696         [o_label setAutoresizingMask:NSViewNotSizable ];
1697         [self addSubview: o_label];
1699         /* build the textfield */
1700         ADD_TEXTFIELD( o_textfield, mainFrame, [o_label frame].size.width + 2,
1701             28, 49, o_tooltip, @"" )
1702         [o_textfield setIntValue: p_item->value.i];
1703         [o_textfield setAutoresizingMask:NSViewMaxXMargin ];
1704         [o_textfield setDelegate: self];
1705         [[NSNotificationCenter defaultCenter] addObserver: self
1706             selector: @selector(textfieldChanged:)
1707             name: NSControlTextDidChangeNotification
1708             object: o_textfield];
1709         [self addSubview: o_textfield];
1711         /* build the mintextfield */
1712         ADD_LABEL( o_textfield_min, mainFrame, 12, -30, @"-8888", @"" )
1713         [o_textfield_min setIntValue: p_item->min.i];
1714         [o_textfield_min setAutoresizingMask:NSViewMaxXMargin ];
1715         [o_textfield_min setAlignment:NSRightTextAlignment];
1716         [self addSubview: o_textfield_min];
1718         /* build the maxtextfield */
1719         ADD_LABEL( o_textfield_max, mainFrame,
1720                     mainFrame.size.width - 31, -30, @"8888", @"" )
1721         [o_textfield_max setIntValue: p_item->max.i];
1722         [o_textfield_max setAutoresizingMask:NSViewMinXMargin ];
1723         [self addSubview: o_textfield_max];
1725         /* build the slider */
1726         ADD_SLIDER( o_slider, mainFrame, [o_textfield_min frame].origin.x +
1727             [o_textfield_min frame].size.width + 6, -1, mainFrame.size.width -
1728             [o_textfield_max frame].size.width -
1729             [o_textfield_max frame].size.width - 14 -
1730             [o_textfield_min frame].origin.x, o_tooltip,
1731             p_item->min.i, p_item->max.i )
1732         [o_slider setIntValue: p_item->value.i];
1733         [o_slider setAutoresizingMask:NSViewWidthSizable ];
1734         [o_slider setTarget: self];
1735         [o_slider setAction: @selector(sliderChanged:)];
1736         [o_slider sendActionOn:NSLeftMouseUpMask | NSLeftMouseDownMask |
1737             NSLeftMouseDraggedMask];
1738         [self addSubview: o_slider];
1740     }
1741     return self;
1744 - (void) alignWithXPosition:(int)i_xPos
1746     NSRect frame;
1747     frame = [o_label frame];
1748     frame.origin.x = i_xPos - frame.size.width - 3;
1749     [o_label setFrame:frame];
1751     frame = [o_textfield frame];
1752     frame.origin.x = i_xPos + 2;
1753     [o_textfield setFrame:frame];
1756 - (void)dealloc
1758     [o_textfield release];
1759     [o_textfield_min release];
1760     [o_textfield_max release];
1761     [o_slider release];
1762     [super dealloc];
1765 - (IBAction)sliderChanged:(id)sender
1767     [o_textfield setIntValue: [o_slider intValue]];
1770 - (void)textfieldChanged:(NSNotification *)o_notification
1772     [o_slider setIntValue: [o_textfield intValue]];
1775 - (int)intValue
1777     return [o_slider intValue];
1780 - (void)resetValues
1782     int value = config_GetInt( VLCIntf, p_item->psz_name );
1783     [o_textfield setIntValue:value];
1784     [o_slider setIntValue:value];
1785     [super resetValues];
1787 @end
1789 @implementation FloatConfigControl
1790 - (id) initWithItem: (module_config_t *)_p_item
1791            withView: (NSView *)o_parent_view
1793     NSRect mainFrame = [o_parent_view frame];
1794     NSString *o_labelString, *o_tooltip;
1795     mainFrame.size.height = 23;
1796     mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN + 1;
1797     mainFrame.origin.x = LEFTMARGIN;
1798     mainFrame.origin.y = 0;
1800     if( [super initWithFrame: mainFrame item: _p_item] != nil )
1801     {
1802         i_view_type = CONFIG_ITEM_INTEGER;
1804         o_tooltip = [[VLCMain sharedInstance] wrapString:
1805             [[VLCMain sharedInstance]
1806                 localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
1808         /* add the label */
1809         if( p_item->psz_text )
1810             o_labelString = [[VLCMain sharedInstance]
1811                                 localizedString: (char *)p_item->psz_text];
1812         else
1813             o_labelString = [NSString stringWithString:@""];
1814         ADD_LABEL( o_label, mainFrame, 0, -2, o_labelString, o_tooltip )
1815         [o_label setAutoresizingMask:NSViewNotSizable ];
1816         [self addSubview: o_label];
1818         /* build the stepper */
1819         ADD_STEPPER( o_stepper, mainFrame, mainFrame.size.width - 19,
1820             0, o_tooltip, -100000, 100000)
1821         [o_stepper setFloatValue: p_item->value.f];
1822         [o_stepper setAutoresizingMask:NSViewMaxXMargin ];
1823         [self addSubview: o_stepper];
1825         /* build the textfield */
1826         ADD_TEXTFIELD( o_textfield, mainFrame, mainFrame.size.width - 19 - 52,
1827             1, 49, o_tooltip, @"" )
1828         [o_textfield setFloatValue: p_item->value.f];
1829         [o_textfield setDelegate: self];
1830         [[NSNotificationCenter defaultCenter] addObserver: self
1831             selector: @selector(textfieldChanged:)
1832             name: NSControlTextDidChangeNotification
1833             object: o_textfield];
1834         [o_textfield setAutoresizingMask:NSViewMaxXMargin ];
1835         [self addSubview: o_textfield];
1836     }
1837     return self;
1840 - (void) alignWithXPosition:(int)i_xPos
1842     NSRect frame;
1843     frame = [o_label frame];
1844     frame.origin.x = i_xPos - frame.size.width - 3;
1845     [o_label setFrame:frame];
1847     frame = [o_textfield frame];
1848     frame.origin.x = i_xPos + 2;
1849     [o_textfield setFrame:frame];
1851     frame = [o_stepper frame];
1852     frame.origin.x = i_xPos + [o_textfield frame].size.width + 5;
1853     [o_stepper setFrame:frame];
1856 - (void)dealloc
1858     [o_stepper release];
1859     [o_textfield release];
1860     [super dealloc];
1863 - (IBAction)stepperChanged:(id)sender
1865     [o_textfield setFloatValue: [o_stepper floatValue]];
1868 - (void)textfieldChanged:(NSNotification *)o_notification
1870     [o_stepper setFloatValue: [o_textfield floatValue]];
1873 - (float)floatValue
1875     return [o_stepper floatValue];
1878 - (void)resetValues
1880     [o_textfield setFloatValue: config_GetFloat( VLCIntf, p_item->psz_name)];
1881     [super resetValues];
1883 @end
1885 @implementation RangedFloatConfigControl
1886 - (id) initWithItem: (module_config_t *)_p_item
1887            withView: (NSView *)o_parent_view
1889     NSRect mainFrame = [o_parent_view frame];
1890     NSString *o_labelString, *o_tooltip;
1891     mainFrame.size.height = 50;
1892     mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN;
1893     mainFrame.origin.x = LEFTMARGIN;
1894     mainFrame.origin.y = 0;
1896     if( [super initWithFrame: mainFrame item: _p_item] != nil )
1897     {
1898         i_view_type = CONFIG_ITEM_RANGED_INTEGER;
1900         o_tooltip = [[VLCMain sharedInstance] wrapString:
1901                      [[VLCMain sharedInstance]
1902                       localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];        
1904         /* add the label */
1905         if( p_item->psz_text )
1906             o_labelString = [[VLCMain sharedInstance]
1907                                 localizedString: (char *)p_item->psz_text];
1908         else
1909             o_labelString = [NSString stringWithString:@""];
1910         ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString, o_tooltip )
1911         [o_label setAutoresizingMask:NSViewNotSizable ];
1912         [self addSubview: o_label];
1914         /* build the textfield */
1915         ADD_TEXTFIELD( o_textfield, mainFrame, [o_label frame].size.width + 2,
1916             28, 49, o_tooltip, @"" )
1917         [o_textfield setFloatValue: p_item->value.f];
1918         [o_textfield setAutoresizingMask:NSViewMaxXMargin ];
1919         [o_textfield setDelegate: self];
1920         [[NSNotificationCenter defaultCenter] addObserver: self
1921             selector: @selector(textfieldChanged:)
1922             name: NSControlTextDidChangeNotification
1923             object: o_textfield];
1924         [self addSubview: o_textfield];
1926         /* build the mintextfield */
1927         ADD_LABEL( o_textfield_min, mainFrame, 12, -30, @"-8888", @"" )
1928         [o_textfield_min setFloatValue: p_item->min.f];
1929         [o_textfield_min setAutoresizingMask:NSViewMaxXMargin ];
1930         [o_textfield_min setAlignment:NSRightTextAlignment];
1931         [self addSubview: o_textfield_min];
1933         /* build the maxtextfield */
1934         ADD_LABEL( o_textfield_max, mainFrame, mainFrame.size.width - 31,
1935             -30, @"8888", @"" )
1936         [o_textfield_max setFloatValue: p_item->max.f];
1937         [o_textfield_max setAutoresizingMask:NSViewMinXMargin ];
1938         [self addSubview: o_textfield_max];
1940         /* build the slider */
1941         ADD_SLIDER( o_slider, mainFrame, [o_textfield_min frame].origin.x +
1942             [o_textfield_min frame].size.width + 6, -1, mainFrame.size.width -
1943             [o_textfield_max frame].size.width -
1944             [o_textfield_max frame].size.width - 14 -
1945             [o_textfield_min frame].origin.x, o_tooltip, p_item->min.f,
1946             p_item->max.f )
1947         [o_slider setFloatValue: p_item->value.f];
1948         [o_slider setAutoresizingMask:NSViewWidthSizable ];
1949         [o_slider setTarget: self];
1950         [o_slider setAction: @selector(sliderChanged:)];
1951         [o_slider sendActionOn:NSLeftMouseUpMask | NSLeftMouseDownMask |
1952             NSLeftMouseDraggedMask];
1953         [self addSubview: o_slider];
1955     }
1956     return self;
1959 - (void) alignWithXPosition:(int)i_xPos
1961     NSRect frame;
1962     frame = [o_label frame];
1963     frame.origin.x = i_xPos - frame.size.width - 3;
1964     [o_label setFrame:frame];
1966     frame = [o_textfield frame];
1967     frame.origin.x = i_xPos + 2;
1968     [o_textfield setFrame:frame];
1971 - (void)dealloc
1973     [o_textfield release];
1974     [o_textfield_min release];
1975     [o_textfield_max release];
1976     [o_slider release];
1977     [super dealloc];
1980 - (IBAction)sliderChanged:(id)sender
1982     [o_textfield setFloatValue: [o_slider floatValue]];
1985 - (void)textfieldChanged:(NSNotification *)o_notification
1987     [o_slider setFloatValue: [o_textfield floatValue]];
1990 - (float)floatValue
1992     return [o_slider floatValue];
1995 - (void)resetValues
1997     [o_textfield setFloatValue: config_GetFloat(VLCIntf, p_item->psz_name)];
1998     [o_slider setFloatValue: config_GetFloat(VLCIntf, p_item->psz_name)];
1999     [super resetValues];
2001 @end
2003 @implementation BoolConfigControl
2005 - (id) initWithItem: (module_config_t *)_p_item
2006            withView: (NSView *)o_parent_view
2008     NSRect mainFrame = [o_parent_view frame];
2009     NSString *o_labelString, *o_tooltip;
2010     mainFrame.size.height = 17;
2011     mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN;
2012     mainFrame.origin.x = LEFTMARGIN;
2013     mainFrame.origin.y = 0;
2015     if( [super initWithFrame: mainFrame item: _p_item] != nil )
2016     {
2017         i_view_type = CONFIG_ITEM_BOOL;
2019         /* add the checkbox */
2020         o_tooltip = [[VLCMain sharedInstance]
2021             wrapString: [[VLCMain sharedInstance]
2022             localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
2023         ADD_CHECKBOX( o_checkbox, mainFrame, 0,
2024                         0, @"", o_tooltip, p_item->value.i, NSImageLeft)
2025         [o_checkbox setAutoresizingMask:NSViewNotSizable ];
2026         [self addSubview: o_checkbox];
2027         /* add the label */
2028         if( p_item->psz_text )
2029             o_labelString = [[VLCMain sharedInstance]
2030                                 localizedString: (char *)p_item->psz_text];
2031         else
2032             o_labelString = [NSString stringWithString:@""];
2033         ADD_LABEL( o_label, mainFrame, [o_checkbox frame].size.width, 0, o_labelString, o_tooltip )
2034         [o_label setAutoresizingMask:NSViewNotSizable ];
2035         [self addSubview: o_label];
2036     }
2037     return self;
2040 - (void)dealloc
2042     [o_checkbox release];
2043     [super dealloc];
2046 - (int)intValue
2048     return [o_checkbox intValue];
2051 - (void)resetValues
2053     [o_checkbox setState: config_GetInt( VLCIntf, p_item->psz_name)];
2054     [super resetValues];
2056 @end
2058 @implementation KeyConfigControl
2059 - (id) initWithItem: (module_config_t *)_p_item
2060            withView: (NSView *)o_parent_view
2062     NSRect mainFrame = [o_parent_view frame];
2063     NSString *o_labelString, *o_tooltip;
2064     mainFrame.size.height = 22;
2065     mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN + 1;
2066     mainFrame.origin.x = LEFTMARGIN;
2067     mainFrame.origin.y = 0;
2069     if( [super initWithFrame: mainFrame item: _p_item] != nil )
2070     {
2071         i_view_type = CONFIG_ITEM_KEY;
2073         o_tooltip = [[VLCMain sharedInstance] wrapString:
2074                      [[VLCMain sharedInstance]
2075                       localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
2077         /* add the label */
2078         if( p_item->psz_text )
2079             o_labelString = [[VLCMain sharedInstance]
2080                 localizedString: (char *)p_item->psz_text];
2081         else
2082             o_labelString = [NSString stringWithString:@""];
2083         ADD_LABEL( o_label, mainFrame, 0, -1, o_labelString, o_tooltip )
2084         [o_label setAutoresizingMask:NSViewNotSizable ];
2085         [self addSubview: o_label];
2087         /* build the popup */
2088         ADD_POPUP( o_popup, mainFrame, [o_label frame].origin.x +
2089             [o_label frame].size.width + 3,
2090             -2, 0, o_tooltip )
2091         [o_popup setAutoresizingMask:NSViewWidthSizable ];
2093         if( o_keys_menu == nil )
2094         {
2095             unsigned int i;
2096             o_keys_menu = [[NSMenu alloc] initWithTitle: @"Keys Menu"];
2097 #warning This does not work anymore. FIXME.
2098 #if 0
2099             for ( i = 0; i < sizeof(vlc_key) / sizeof(key_descriptor_t); i++)
2100                 if( vlc_key[i].psz_key_string )
2101                     POPULATE_A_KEY( o_keys_menu,
2102                         [NSString stringWithUTF8String:vlc_key[i].psz_key_string]
2103                         , vlc_key[i].i_key_code)
2104 #endif
2105         }
2106         [o_popup setMenu:[o_keys_menu copyWithZone:nil]];
2107         [o_popup selectItem:[[o_popup menu] itemWithTag:p_item->value.i]];
2108         [self addSubview: o_popup];
2110     }
2111     return self;
2114 - (void) alignWithXPosition:(int)i_xPos
2116     NSRect frame;
2117     NSRect superFrame = [self frame];
2118     frame = [o_label frame];
2119     frame.origin.x = i_xPos - frame.size.width - 3;
2120     [o_label setFrame:frame];
2122     frame = [o_popup frame];
2123     frame.origin.x = i_xPos - 1;
2124     frame.size.width = superFrame.size.width - frame.origin.x + 2;
2125     [o_popup setFrame:frame];
2128 - (void)dealloc
2130     [o_popup release];
2131     [super dealloc];
2134 - (int)intValue
2136     return [o_popup selectedTag];
2139 - (void)resetValues
2141     [o_popup selectItem:[[o_popup menu] itemWithTag:config_GetInt( VLCIntf, p_item->psz_name )]];
2142     [super resetValues];
2144 @end
2146 @implementation ModuleListConfigControl
2147 - (id) initWithItem: (module_config_t *)_p_item
2148            withView: (NSView *)o_parent_view
2150     if( _p_item->i_type == CONFIG_ITEM_MODULE_LIST )
2151         //TODO....
2152         return nil;
2153     
2154     //Fill our array to know how may items we have...
2155     module_t *p_parser, **p_list;
2156     size_t i_module_index;
2157     NSRect mainFrame = [o_parent_view frame];
2158     NSString *o_labelString, *o_textfieldString, *o_tooltip;
2159     
2160     o_modulearray = [[NSMutableArray alloc] initWithCapacity:10];
2161     /* build a list of available modules */
2162     p_list = module_list_get( NULL );
2163     for( i_module_index = 0; p_list[i_module_index]; i_module_index++ )
2164     {
2165         int i;
2166         p_parser = p_list[i_module_index];
2167         
2168         if( module_is_main( p_parser ) )
2169             continue;
2170         
2171         unsigned int confsize;
2172         module_config_t *p_configlist = module_config_get( p_parser, &confsize );
2173         
2174         for ( i = 0; i < confsize; i++ )
2175         {
2176             unsigned int unused;
2177             module_config_t *p_config = &p_configlist[i];
2178             NSString *o_modulelongname, *o_modulename;
2179             NSNumber *o_moduleenabled = nil;
2180             
2181             /* Hack: required subcategory is stored in i_min */
2182             if( p_config->i_type == CONFIG_SUBCATEGORY &&
2183                p_config->value.i == _p_item->min.i )
2184             {
2185                 o_modulelongname = [NSString stringWithUTF8String:
2186                                     module_get_name( p_parser, TRUE )];
2187                 o_modulename = [NSString stringWithUTF8String:
2188                                 module_get_object( p_parser )];
2189                 
2190                 if( _p_item->value.psz &&
2191                    strstr( _p_item->value.psz, module_get_object( p_parser ) ) )
2192                     o_moduleenabled = [NSNumber numberWithBool:YES];
2193                 else
2194                     o_moduleenabled = [NSNumber numberWithBool:NO];
2195                 
2196                 [o_modulearray addObject:[NSMutableArray
2197                                           arrayWithObjects: o_modulename, o_modulelongname,
2198                                           o_moduleenabled, nil]];
2199             }
2200         }
2201         module_config_free( p_configlist );
2202     }
2203     module_list_free( p_list );
2204     
2205     mainFrame.size.height = 30 + 20 * [o_modulearray count];
2206     mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN;
2207     mainFrame.origin.x = LEFTMARGIN;
2208     mainFrame.origin.y = 0;
2209     if( [super initWithFrame: mainFrame item: _p_item] != nil )
2210     {
2211         i_view_type = CONFIG_ITEM_MODULE_LIST;
2212         
2213         o_tooltip = [[VLCMain sharedInstance] wrapString:
2214                      [[VLCMain sharedInstance]
2215                       localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
2216         
2217         /* add the label */
2218         if( p_item->psz_text )
2219             o_labelString = [[VLCMain sharedInstance]
2220                              localizedString: (char *)p_item->psz_text];
2221         else
2222             o_labelString = [NSString stringWithString:@""];
2223         ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString, o_tooltip )
2224         [o_label setAutoresizingMask:NSViewNotSizable ];
2225         [self addSubview: o_label];
2226         
2227         /* build the textfield */
2228         if( p_item->value.psz )
2229             o_textfieldString = [[VLCMain sharedInstance]
2230                                  localizedString: (char *)p_item->value.psz];
2231         else
2232             o_textfieldString = [NSString stringWithString: @""];
2233         ADD_TEXTFIELD( o_textfield, mainFrame, [o_label frame].size.width + 2,
2234                       mainFrame.size.height - 22, mainFrame.size.width -
2235                       [o_label frame].size.width - 2, o_tooltip, o_textfieldString )
2236         [o_textfield setAutoresizingMask:NSViewWidthSizable ];
2237         [self addSubview: o_textfield];
2238         
2239         
2240         {
2241             NSRect s_rc = mainFrame;
2242             s_rc.size.height = mainFrame.size.height - 30;
2243             s_rc.size.width = mainFrame.size.width - 12;
2244             s_rc.origin.x = 12;
2245             s_rc.origin.y = 0;
2246             o_scrollview = [[[NSScrollView alloc] initWithFrame: s_rc] retain];
2247             [o_scrollview setDrawsBackground: NO];
2248             [o_scrollview setBorderType: NSBezelBorder];
2249             [o_scrollview setAutohidesScrollers:YES];
2250             
2251             NSTableView *o_tableview;
2252             o_tableview = [[NSTableView alloc] initWithFrame : s_rc];
2253             [o_tableview setUsesAlternatingRowBackgroundColors:YES];
2254             [o_tableview setHeaderView:nil];
2255             /* TODO: find a good way to fix the row height and text size*/
2256             /* FIXME: support for multiple selection... */
2257             //    [o_tableview setAllowsMultipleSelection:YES];
2258             
2259             NSCell *o_headerCell = [[NSCell alloc] initTextCell:@"Enabled"];
2260             NSCell *o_dataCell = [[NSButtonCell alloc] init];
2261             [(NSButtonCell*)o_dataCell setButtonType:NSSwitchButton];
2262             [o_dataCell setTitle:@""];
2263             [o_dataCell setFont:[NSFont systemFontOfSize:0]];
2264             NSTableColumn *o_tableColumn = [[NSTableColumn alloc]
2265                                             initWithIdentifier:@"Enabled"];
2266             [o_tableColumn setHeaderCell: o_headerCell];
2267             [o_tableColumn setDataCell: o_dataCell];
2268             [o_tableColumn setWidth:17];
2269             [o_tableview addTableColumn: o_tableColumn];
2270             
2271             o_headerCell = [[NSCell alloc] initTextCell:@"Module Name"];
2272             o_dataCell = [[NSTextFieldCell alloc] init];
2273             [o_dataCell setFont:[NSFont systemFontOfSize:12]];
2274             o_tableColumn = [[NSTableColumn alloc]
2275                              initWithIdentifier:@"Module"];
2276             [o_tableColumn setHeaderCell: o_headerCell];
2277             [o_tableColumn setDataCell: o_dataCell];
2278             [o_tableColumn setWidth:s_rc.size.width - 34];
2279             [o_tableview addTableColumn: o_tableColumn];
2280             [o_tableview registerForDraggedTypes:[NSArray arrayWithObjects:
2281                                                   @"VLC media player module", nil]];
2282             
2283             [o_tableview setDataSource:self];
2284             [o_tableview setTarget: self];
2285             [o_tableview setAction: @selector(tableChanged:)];
2286             [o_tableview sendActionOn:NSLeftMouseUpMask | NSLeftMouseDownMask |
2287              NSLeftMouseDraggedMask];
2288             [o_scrollview setDocumentView: o_tableview];
2289         }
2290         [o_scrollview setAutoresizingMask:NSViewWidthSizable ];
2291         [o_scrollview setAutohidesScrollers:YES];
2292         [self addSubview: o_scrollview];
2294     }
2295     return self;
2298 - (void) alignWithXPosition:(int)i_xPos
2300     ;
2303 - (IBAction)tableChanged:(id)sender
2305     NSString *o_newstring = @"";
2306     NSUInteger count = [o_modulearray count];
2307     for( NSUInteger i = 0 ; i < count ; i++ )
2308         if( [[[o_modulearray objectAtIndex:i] objectAtIndex:2]
2309             boolValue] != NO )
2310         {
2311             o_newstring = [o_newstring stringByAppendingString:
2312                 [[o_modulearray objectAtIndex:i] objectAtIndex:0]];
2313             o_newstring = [o_newstring stringByAppendingString:@":"];
2314         }
2316     [o_textfield setStringValue: [o_newstring
2317         substringToIndex: ([o_newstring length])?[o_newstring length] - 1:0]];
2320 - (void)dealloc
2322     [o_scrollview release];
2323     [super dealloc];
2327 - (char *)stringValue
2329     return strdup( [[o_textfield stringValue] UTF8String] );
2332 -(void)resetValues
2334 #warning Reset prefs of the module selector is broken atm. 
2335     NSLog( @"don't forget about modulelistconfig" );
2336     [super resetValues];
2339 @end
2341 @implementation ModuleListConfigControl (NSTableDataSource)
2343 - (BOOL)tableView:(NSTableView*)table writeRows:(NSArray*)rows
2344     toPasteboard:(NSPasteboard*)pb
2346     // We only want to allow dragging of selected rows.
2347     NSEnumerator    *iter = [rows objectEnumerator];
2348     NSNumber        *row;
2349     while ((row = [iter nextObject]) != nil)
2350     {
2351         if (![table isRowSelected:[row intValue]])
2352             return NO;
2353     }
2355     [pb declareTypes:[NSArray
2356         arrayWithObject:@"VLC media player module"] owner:nil];
2357     [pb setPropertyList:rows forType:@"VLC media player module"];
2358     return YES;
2361 - (NSDragOperation)tableView:(NSTableView*)table
2362     validateDrop:(id <NSDraggingInfo>)info proposedRow:(NSInteger)row
2363     proposedDropOperation:(NSTableViewDropOperation)op
2365     // Make drops at the end of the table go to the end.
2366     if (row == -1)
2367     {
2368         row = [table numberOfRows];
2369         op = NSTableViewDropAbove;
2370         [table setDropRow:row dropOperation:op];
2371     }
2373     // We don't ever want to drop onto a row, only between rows.
2374     if (op == NSTableViewDropOn)
2375         [table setDropRow:(row+1) dropOperation:NSTableViewDropAbove];
2376     return NSTableViewDropAbove;
2379 - (BOOL)tableView:(NSTableView*)table acceptDrop:(id <NSDraggingInfo>)info
2380     row:(NSInteger)dropRow dropOperation:(NSTableViewDropOperation)op;
2382     NSPasteboard    *pb = [info draggingPasteboard];
2383     NSDragOperation srcMask = [info draggingSourceOperationMask];
2384     BOOL accepted = NO;
2386     NS_DURING
2388         NSArray *array;
2390         // Intra-table drag - data is the array of rows.
2391         if (!accepted && (array =
2392             [pb propertyListForType:@"VLC media player module"]) != NULL)
2393         {
2394             NSEnumerator *iter = nil;
2395             id val;
2396             BOOL isCopy = (srcMask & NSDragOperationMove) ? NO:YES;
2397             // Move the modules
2398             iter = [array objectEnumerator];
2399             while ((val = [iter nextObject]) != NULL)
2400             {
2401                 NSArray *o_tmp = [[o_modulearray objectAtIndex:
2402                     [val intValue]] mutableCopyWithZone:nil];
2403                 [o_modulearray removeObject:o_tmp];
2404                 [o_modulearray insertObject:o_tmp
2405                     atIndex:(dropRow>[val intValue]) ? dropRow - 1 : dropRow];
2406                 dropRow++;
2407             }
2409             // Select the newly-dragged items.
2410             iter = [array objectEnumerator];
2411 //TODO...
2412             [table deselectAll:self];
2414             [self tableChanged:self];
2415             [table setNeedsDisplay:YES];
2416             // Indicate that we finished the drag.
2417             accepted = YES;
2418         }
2419         [table reloadData];
2420         [table setNeedsDisplay:YES];
2422         NS_HANDLER
2424             // An exception occurred. Uh-oh. Update the track table so that
2425             // it stays consistent, and re-raise the exception.
2426             [table reloadData];
2427             [localException raise];
2428             [table setNeedsDisplay:YES];
2429     NS_ENDHANDLER
2431     return accepted;
2434 - (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView
2436     return [o_modulearray count];
2439 - (id)tableView:(NSTableView *)aTableView
2440     objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
2442     if( [[aTableColumn identifier] isEqualToString: @"Enabled"] )
2443         return [[o_modulearray objectAtIndex:rowIndex] objectAtIndex:2];
2444     if( [[aTableColumn identifier] isEqualToString: @"Module"] )
2445         return [[o_modulearray objectAtIndex:rowIndex] objectAtIndex:1];
2447     return nil;
2450 - (void)tableView:(NSTableView *)aTableView setObjectValue:(id)anObject
2451     forTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
2453     [[o_modulearray objectAtIndex:rowIndex] replaceObjectAtIndex:2
2454         withObject: anObject];
2456 @end