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