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