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