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