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